 LinearAlgebra[Modular] - Maple Programming Help

# Online Help

###### All Products    Maple    MapleSim

Home : Support : Online Help : Mathematics : Linear Algebra : LinearAlgebra Package : Modular Subpackage : LinearAlgebra/Modular/CharacteristicPolynomial

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), 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)$
  (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.035}$ (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.013}$ (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.125}$ (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}}$
 ${9.615384615}$ (11)