LinearAlgebra[Modular]
CharacteristicPolynomial
Compute the characteristic polynomial of a square matrix mod p
Calling Sequence
Parameters
Description
Examples
CharacteristicPolynomial(m, A, lambda)
m
-
modulus
A
square matrix
lambda
variable name to use for characteristic polynomial
The CharacteristicPolynomial function computes the characteristic polynomial of a matrix mod m. Note that the matrix A need not have entries in the positive range 0..m−1, as the routine needs to make a copy of the matrix for the computation, and does so using Mod. Upon successful completion, the characteristic polynomial of A mod m in lambda is returned.
A number of different algorithms and implementations are in use, each with significantly different efficiency, so it is important to describe these here.
If m is a prime number with fewer than 100 digits (the digit limitation is present only to guarantee that the primality check is not too expensive) then the Hessenberg algorithm is used. This is a reduction-like routine, in which the matrix is 'reduced' to Hessenberg form, and the characteristic polynomial is computed from this form.
Furthermore, if the prime is sufficiently small so that the Modular package can work with a hardware datatype (either integer[] or float[8]), then an efficient external routine is used for the computation, making it quite fast.
In the event that the modulus m is not prime, or greater than 100 digits in length, the Berkowitz algorithm is used. Unlike the Hessenberg implementation, the Berkowitz implementation uses no external code, so it is noticeably slower for comparable problems, as demonstrated in the examples.
This command is part of the LinearAlgebra[Modular] package, so it can be used in the form CharacteristicPolynomial(..) only after executing the command with(LinearAlgebra[Modular]). However, it can always be used in the form LinearAlgebra[Modular][CharacteristicPolynomial](..).
with⁡LinearAlgebraModular:
A≔Matrix⁡30,30,i,j↦rand⁡
t0≔time⁡:
p0≔LinearAlgebra:-CharacteristicPolynomial⁡A,x:
t0≔time⁡−t0
t0≔0.031
Compute the characteristic polynomial using external Hessenberg and Berkowitz, and compare the timings.
First Hessenberg with prime modulus
m1≔ithprime⁡4600
m1≔44201
tH≔time⁡:
p1≔CharacteristicPolynomial⁡m1,A,x
p1≔x30+2002⁢x29+26760⁢x28+39582⁢x27+40328⁢x26+17238⁢x25+38348⁢x24+11836⁢x23+15733⁢x22+29600⁢x21+29719⁢x20+9058⁢x19+29063⁢x18+33642⁢x17+28407⁢x16+27842⁢x15+14164⁢x14+18577⁢x13+28084⁢x12+2630⁢x11+19981⁢x10+32617⁢x9+29073⁢x8+7564⁢x7+6983⁢x6+4578⁢x5+22718⁢x4+10812⁢x3+41753⁢x2+36640⁢x+43117
tH≔time⁡−tH
tH≔0.010
modp⁡Expand⁡p0−p1,m1
0
Next Berkowitz with composite modulus
m2≔m1−1
m2≔44200
tB≔time⁡:
p2≔CharacteristicPolynomial⁡m2,A,x
p2≔x30+37365⁢x29+4931⁢x28+43039⁢x27+35328⁢x26+26584⁢x25+23190⁢x24+27442⁢x23+41208⁢x22+38734⁢x21+19681⁢x20+7132⁢x19+14062⁢x18+31571⁢x17+43180⁢x16+6873⁢x15+2753⁢x14+18263⁢x13+9875⁢x12+13378⁢x11+29095⁢x10+20935⁢x9+2151⁢x8+1739⁢x7+6988⁢x6+26015⁢x5+15981⁢x4+38044⁢x3+4421⁢x2+12865⁢x+30584
tB≔time⁡−tB
tB≔0.091
modp⁡Expand⁡p0−p2,m2
Factor of time faster for Hessenberg
tBtH
9.100000000
See Also
LinearAlgebra/Details
LinearAlgebra[Modular][IntegerCharacteristicPolynomial]
LinearAlgebra[Modular][Mod]
Download Help Document