CharacteristicPolynomial - Maple Help

LinearAlgebra[Modular]

 CharacteristicPolynomial
 Compute the characteristic polynomial of a square matrix mod p

 Calling Sequence CharacteristicPolynomial(m, A, lambda)

Parameters

 m - modulus A - square matrix lambda - variable name to use for characteristic polynomial

Description

 • 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](..).

Examples

 > $\mathrm{with}\left(\mathrm{LinearAlgebra}\left[\mathrm{Modular}\right]\right):$
 > $A≔\mathrm{Matrix}\left(30,30,\left(i,j\right)↦\mathrm{rand}\left(\right)\right)$
 ${A}{≔}\begin{array}{c}\left[\begin{array}{ccccccccccc}{395718860534}& {193139816415}& {22424170465}& {800187484459}& {427552056869}& {842622684442}& {412286285840}& {996417214180}& {386408307450}& {694607189265}& {\dots }\\ {759661297346}& {430137169252}& {867557918169}& {866818474138}& {966905297479}& {497201520366}& {556157845064}& {363627416872}& {988383200003}& {735342248716}& {\dots }\\ {419107017642}& {224017151548}& {200840106267}& {868571906562}& {570413466477}& {992088146026}& {44377527460}& {478029137226}& {12943051994}& {640883156519}& {\dots }\\ {147692311310}& {660252243043}& {504180068247}& {583804136382}& {332585592470}& {642614553072}& {683413251297}& {36386777396}& {10051167073}& {294333430140}& {\dots }\\ {447247812388}& {876097567582}& {580230132315}& {557495823712}& {185016698632}& {127248646797}& {463891231054}& {311530870548}& {332596541488}& {494513950222}& {\dots }\\ {517501904412}& {145835371329}& {737239591739}& {905196585503}& {362646618851}& {290137415540}& {799092205607}& {873263534186}& {942337219622}& {622376983290}& {\dots }\\ {663115419126}& {875615784786}& {783233932834}& {308881669470}& {543501506147}& {537472825200}& {782542495312}& {377914644627}& {65455627792}& {837589578089}& {\dots }\\ {137619574565}& {729274125784}& {825353367469}& {836793693604}& {383647797102}& {187500146941}& {422711497108}& {312595919547}& {155104980896}& {974929808017}& {\dots }\\ {878676634544}& {230926879906}& {542573759977}& {241072503530}& {735693369635}& {463199808910}& {675300990991}& {938458834097}& {373669017697}& {966421495350}& {\dots }\\ {475006451891}& {486663414315}& {769797297906}& {37567667507}& {654220297503}& {542532675934}& {571026519308}& {964369283707}& {351636725595}& {15750135057}& {\dots }\\ {⋮}& {⋮}& {⋮}& {⋮}& {⋮}& {⋮}& {⋮}& {⋮}& {⋮}& {⋮}& {}\end{array}\right]\\ \hfill {\text{30 × 30 Matrix}}\end{array}$ (1)
 > $\mathrm{t0}≔\mathrm{time}\left(\right):$
 > $\mathrm{p0}≔\mathrm{LinearAlgebra}:-\mathrm{CharacteristicPolynomial}\left(A,x\right):$
 > $\mathrm{t0}≔\mathrm{time}\left(\right)-\mathrm{t0}$
 ${\mathrm{t0}}{≔}{0.067}$ (2)

Compute the characteristic polynomial using external Hessenberg and Berkowitz, and compare the timings.

First Hessenberg with prime modulus

 > $\mathrm{m1}≔\mathrm{ithprime}\left(4600\right)$
 ${\mathrm{m1}}{≔}{44201}$ (3)
 > $\mathrm{tH}≔\mathrm{time}\left(\right):$
 > $\mathrm{p1}≔\mathrm{CharacteristicPolynomial}\left(\mathrm{m1},A,x\right)$
 ${\mathrm{p1}}{≔}{{x}}^{{30}}{+}{2002}{}{{x}}^{{29}}{+}{26760}{}{{x}}^{{28}}{+}{39582}{}{{x}}^{{27}}{+}{40328}{}{{x}}^{{26}}{+}{17238}{}{{x}}^{{25}}{+}{38348}{}{{x}}^{{24}}{+}{11836}{}{{x}}^{{23}}{+}{15733}{}{{x}}^{{22}}{+}{29600}{}{{x}}^{{21}}{+}{29719}{}{{x}}^{{20}}{+}{9058}{}{{x}}^{{19}}{+}{29063}{}{{x}}^{{18}}{+}{33642}{}{{x}}^{{17}}{+}{28407}{}{{x}}^{{16}}{+}{27842}{}{{x}}^{{15}}{+}{14164}{}{{x}}^{{14}}{+}{18577}{}{{x}}^{{13}}{+}{28084}{}{{x}}^{{12}}{+}{2630}{}{{x}}^{{11}}{+}{19981}{}{{x}}^{{10}}{+}{32617}{}{{x}}^{{9}}{+}{29073}{}{{x}}^{{8}}{+}{7564}{}{{x}}^{{7}}{+}{6983}{}{{x}}^{{6}}{+}{4578}{}{{x}}^{{5}}{+}{22718}{}{{x}}^{{4}}{+}{10812}{}{{x}}^{{3}}{+}{41753}{}{{x}}^{{2}}{+}{36640}{}{x}{+}{43117}$ (4)
 > $\mathrm{tH}≔\mathrm{time}\left(\right)-\mathrm{tH}$
 ${\mathrm{tH}}{≔}{0.016}$ (5)
 > $\mathrm{modp}\left(\mathrm{Expand}\left(\mathrm{p0}-\mathrm{p1}\right),\mathrm{m1}\right)$
 ${0}$ (6)

Next Berkowitz with composite modulus

 > $\mathrm{m2}≔\mathrm{m1}-1$
 ${\mathrm{m2}}{≔}{44200}$ (7)
 > $\mathrm{tB}≔\mathrm{time}\left(\right):$
 > $\mathrm{p2}≔\mathrm{CharacteristicPolynomial}\left(\mathrm{m2},A,x\right)$
 ${\mathrm{p2}}{≔}{{x}}^{{30}}{+}{37365}{}{{x}}^{{29}}{+}{4931}{}{{x}}^{{28}}{+}{43039}{}{{x}}^{{27}}{+}{35328}{}{{x}}^{{26}}{+}{26584}{}{{x}}^{{25}}{+}{23190}{}{{x}}^{{24}}{+}{27442}{}{{x}}^{{23}}{+}{41208}{}{{x}}^{{22}}{+}{38734}{}{{x}}^{{21}}{+}{19681}{}{{x}}^{{20}}{+}{7132}{}{{x}}^{{19}}{+}{14062}{}{{x}}^{{18}}{+}{31571}{}{{x}}^{{17}}{+}{43180}{}{{x}}^{{16}}{+}{6873}{}{{x}}^{{15}}{+}{2753}{}{{x}}^{{14}}{+}{18263}{}{{x}}^{{13}}{+}{9875}{}{{x}}^{{12}}{+}{13378}{}{{x}}^{{11}}{+}{29095}{}{{x}}^{{10}}{+}{20935}{}{{x}}^{{9}}{+}{2151}{}{{x}}^{{8}}{+}{1739}{}{{x}}^{{7}}{+}{6988}{}{{x}}^{{6}}{+}{26015}{}{{x}}^{{5}}{+}{15981}{}{{x}}^{{4}}{+}{38044}{}{{x}}^{{3}}{+}{4421}{}{{x}}^{{2}}{+}{12865}{}{x}{+}{30584}$ (8)
 > $\mathrm{tB}≔\mathrm{time}\left(\right)-\mathrm{tB}$
 ${\mathrm{tB}}{≔}{0.133}$ (9)
 > $\mathrm{modp}\left(\mathrm{Expand}\left(\mathrm{p0}-\mathrm{p2}\right),\mathrm{m2}\right)$
 ${0}$ (10)

Factor of time faster for Hessenberg

 > $\frac{\mathrm{tB}}{\mathrm{tH}}$
 ${8.312500000}$ (11)