CMAT is a matrix calculator program, written in C.

Calculations can be performed on matrices with complex rational coefficients using exact arithmetic routines, as well as on matrices with elements mod p. There are Unix, DOS and Windows XP versions.
To run under windows2000+ from a dos window, the user should first download a dos emulator from

The Unix, DOS and Windows XP versions, together with the C source, can be downloaded.
People using the UNIX version have to create a .cmatrc file in the working directory, consisting of the two lines


(Also see cmat_bugfix.html for bug reports.)

There are three calculator programs within CMAT: CMATR, CMATCR and CMATM.
CMATR works over the rationals, CMATCR works the field of complex rationals and CMATM works over the field of p elements, where p is any prime less than 216 = 65536.

The programs use multiple precision arithmetic routines based on those in [Fla][342-357,175-185]. (See documentation.)

Up to M0 (=30) objects of each type can be created and stored for use in future sessions.
(rational) numbers: R[0],…,R[M0-1];
(rational) matrices: RM[0],…,RM[M0-1];
polynomials (rational): PR[0],…,PR[M0-1];
polynomial (rational) matrices: PRM[0],…,PRM[M0-1];

(complex rational) numbers CR[0],…,CR[M0-1];
(complex rational) matrices CRM[0],…,CRM[M0-1];
polynomials (complex rational): PCR[0],…,PCR[M0-1];
polynomial (complex rational) matrices: PCRM[0],…,PCRM[M0-1];

(mod p) matrices: mM[0],…,mM[M0-1];
polynomials (mod p): Pm[0],…,Pm[M0-1];
polynomial (mod p) matrices: PmM[0],…,PmM[M0-1].

The program can handle integers of arbitrary size. Matrix size is restricted only by the time taken to create the matrix in question and to compute with it. Execution times are much less when calculating with matrices mod p.


Conjugation, addition, subtraction, multiplication, exponentiation, ratio and inverse. Also the m-th root of rational can be computed to a given number of decimal places.


Addition, subtraction, multiplication, scalar-multiplication, exponentiation, derivative, evaluation, quotient, remainder, greatest common divisor, expressing the gcd as a linear combination of the polynomials involved, square-free decomposition. The resultant of two polynomials over ℤ[x] and the discriminant of a polynomial over ℤ[x] can be found. There is modular exponentiation for polynomials mod p.

The Berlekamp matrix of a squarefree polynomial mod p. (Our Berlekamp matrix is the transpose of the usual Berlekamp matrix.) Factorization of polynomials with rational, complex rational or mod p coefficients into irreducibles. Finding an irreducible polynomial of given degree mod p. Finding the nth cyclotomic polynomial. (mod p)


  1. Addition, negation, complex-conjugate transpose, multiplication by a scalar, matrix multiplication, exponentiation, Kronecker product, evaluating matrix polynomials at a square matrix.
  2. The standard elementary row and column operations can be performed on all types of matrices.
  3. The entries of a stored matrix can be changed, either individually, or by row or column. A single row or column can be deleted.
  4. A single row or column vector can be selected from a stored matrix. More generally, a submatrix of a stored matrix can be formed by selecting a subfamily of rows or columns, respectively.
  5. Two matrices can be joined by rows or columns. The partitioned matrix [A|I] can be formed from A. A matrix can be unwrapped into a column vector (a process useful for finding the minimum polynomial of a matrix).
  6. Forming the matrix A-tI, for use in eigenvector calculations.
  7. Creating special matrices such as the identity matrix, elementary Jordan matrices and companion matrices as well as band matrices.
  8. Creating matrices of scalars whose (i-j)th element is given by simple arithmetical expressions such as i + j – i^2 + 3*j for the numerators and denominators, may be created wholly within CMAT.
  9. Finding the inverse, adjoint, determinant, characteristic polynomial and minimum polynomial of a matrix of scalars, P-1AP. The Cholesky decomposition of a positive definite matrix is found: A=L*DL, where L is upper unit triangular and D is a diagonal matrix. The output has the diagonal elements of D on its diagonal and its above diagonal elements are those of L.
    The inverse of a matrix M of integers mod m can be found, when m > 1 is a positive integer which is coprime to the determinant of M.
  10. Finding the reduced row-echelon form, solving linear equations, finding bases for the null-space N(A) and column-space C(A) of a matrix A. These procedures are very useful in algorithms for finding the Jordan canonical form, or more generally, the rational canonical form of a square matrix. (See [paper].)
  11. Calculating dot product, length and using the Gram-Schmidt process to find an orthogonal basis for the column-space of a matrix. Finding the cross-product of the row vectors of an (n – 1) x n matrix.
  12. Finding the determinant and adjoint of a matrix with polynomial entries.
  13. Finding the Smith canonical form of a matrix B with polynomial entries. (e.g. when applied to the matrix B = xI – A, where A is a matrix with rational or complex rational entries, this gives the similarity invariants of A, in particular we get the minimum polynomial of A as the invariant of highest degree.)
    We also get polynomial matrices P and Q, whose determinants are constant polynomials, with the property that PBQ is in Smith canonical form.
  14. Elementary row/column operations for matrices with polynomial entries.
  15. Printing matrices of rationals to a file or the screen, accurate to a given number of decimals.
  16. Sending data to the line-printer.
  17. A file of r (≤ M0-j) prepared matrices of the same type (rational, floating point, complex rational or modular) can be entered into array positions j,…j+r-1.


After entering cmat, the user can now descend through various levels by selecting from the displayed screen options. To ascend through the various levels, type q when this is an option. When leaving the program, the user is given the option of saving data for reuse in future sessions.


To enter a rational number and store the number as R[0] for example, select the appropriate menu and type n 0.

NOTE: Use CONTROL-H, not the backspace key, to backspace over characters.

Integers are entered as usual, while non-integer rationals are entered with a slash as integer/positive integer: e.g. 1/2, while complex numbers with non-zero imaginary part must end with an i: e.g. 1/2i represents (1/2)i. No brackets are to be used when entering numbers. Rational numbers are outputted in ‘lowest terms’ with positive denominator.

Some latitude is allowed as regards spacing. For example, the expressions 1-i, 1- i, 1 – i represent the same complex rational, while 1 -i represents the two numbers 1 and -i.

Maatriksid on sisestatud rea rea lõpuni rida on märgitud vedu tagasi. Ruumid eraldi kirjeid rida. Sisenes maatriksite RM[0] ja RM[1], RM[0] * RM[1] on saadetud RM[2] (öelda) või RM[0], RM[1]), valides korrutamine valik t menüüst alla kirjutades t 0 1 2.

Rational Matrix Arithmetic
	a j k l : RM[j] + RM[k] -> RM[l]
	t j k l : RM[j] * RM[k] -> RM[l]
	s j k l : RM[j] - RM[k] -> RM[l]
	m j k   :       -RM[j]  -> RM[k]
	f j k l :  R[j](RM[k])  -> RM[l] (scalar multiple)
	* j k   :     (RM[j])*  -> RM[k] (transpose)
	e n j k : RM[j] ^  n    -> RM[k] (exponentiation)
	z j k l : RM[j] - R[k]I -> RM[l]
	p       : print numbers and matrices
	x       : to enter data
	q       : to exit

Lõpetada sisenevad polünoomi või maatriks klaviatuuri tüüp q või mis tahes mitte-tähtnumbriline märk, kui sisenevad koefitsient. Vaikimisi polünoomi või maatriks on siis salvestatud.

Selleks, et arvutada 10. võimu RM[0], valige exponentiation valik e alates eespool menüü, kirjutades e 10 0 3 saatmiseks väljundi RM[3]. Olukord on mõnevõrra lihtsam modulaarse teheteks. Siin ei ole numbrid on salvestatud ja mitte-negatiivsed arvud vähem kui asjaomane moodul on sisestatud otse, selle asemel, et ladustada. Näiteks korrutada maatriks mM[0] 5 (mod 7) ja salvestada tulemus nagu mM[1], valige sobiv menüü menüü line

f,j k l p :j * (mM[k]) -> mM[l](mod p)(scalar multiple)

ja tüüp f 5 0 1 7.

See on oluline meeles pidada, et kui kasutate modulaarne aritmeetiline osa CMAT, tegevused peavad olema teostatud ainult salvestatud objektid, millel on sama moodul.

Lõpetada sisend enneaegselt pärast sisenemist esimene täht menüüvalik, type q järgneb TAGASI.

Lõpuks, sisend faili r (≤ M0-j), mis on valmistatud maatriksid, mis on sama tüüpi (ratsionaalne, murdarvud, keeruline ratsionaalne või modulaarne) arvesse array positsioonide j…j+r-1, esimene rida fail peaks sisaldama arv maatriksid; järgmine rida koosneb rea ja veeru number esimese maatriksi, millele järgneb vastav rida maatriks. Näiteks, järgmine fail kujutab kaks maatriksit, rationals, a 3 × 3 maatriks, millele järgneb 2 × 2 maatriks:

/* ratsionaalne maatriks faili */
3 3
2/3 5 -7/8
1/2 12 -5
7 6 4
2 2
1 0
0 1


Märkused algoritmid CMAT

  • trikke Lk Henrici mainitud [Buc][200-201] kasutatakse, et kiirendada liitmine ja korrutamine, rationals.
  • Gauss-Jordani meetod on kasutada, et leida vähendatud real-echelon vormi ja lahendada süsteemi lineaarvõrrandid üle kõigi kolme väljad.
  • adjoint, pöördvõrdeline, mõjutegur ja iseloomulik polünoomi, maatriks rationals või keeruline rationals on leitud Faddeeva-Leverrier meetod. (Vt [Fad][177-181].)
    Eest maatriksite üle ℤp, me kasutame muutmine algoritmi tõttu Frobenius (vt [McW][168-175]), et leida iseloomulik polünoomi.
    Üle ℤp, Gauss-Jordan algoritmi kasutatakse, et leida pöördvõrdeline ja mõjutegur, mis on maatriks. Kui adjoint on leitud, kasutades asjaolu, et adj(A)=0, kui rank(A) ≤ n-2, auaste(adj)=1, kui rank(A)=n-1 ja adj(A)=(det(A))-1 teisiti.
  • inversne element täisarv, maatriksi mod m on leitud, kasutades adjoint maatriks ja korrutades mod m poolt inversne element määraja mod m.
  • minimaalne polünoomi m(x) nxn maatriks A on leitud, leides vähim positiivne täisarv m nii, et Am on expressible nagu lineaarne kombinatsioon maatriksite In,…,m-1.
    See on tehtud lahtipakkimine maatriksite In,…,r sisse veeru vektorid 1 ≤ r ≤ m ja lahendada võrrand
    a[0]I+···+a[r-1]r-1 = r
    kui süsteem n2 võrrandid r tundmatuga. Süsteem on vastuoluline, 1 ≤ r ≤ m, kuid on unikaalne lahendus, kui r = m, andes minimaalne polünoomi m(x) = xm-a[m-1], xm-1-···-a[0].
  • Smith kanooniline vorm on leida algoritm [Har][111-113]. Kiiremini algoritmid on olemas (vt [Lu2]).
  • Factorization, polynomials aastal ℤp[x] on saavutatud kasutades meetod leida mitte-triviaalne faktori tõttu P. Veoauto (vt [Cam]). Seda kasutatakse koos Berlekamp maatriks a polünoomi. Teavet selle maatriksi vt [Knu][420-429]. (Meie Berlekamp maatriks on üle võtma ning Knuth on.)
  • Factorization on polünoomi puhul ℤ[x] on saavutatud kasutades algoritmi kirjeldatud [Mus]. Algoritm kasutab aste-set testimise protseduur, mis mõnikord paljastab irreducibility enne keerulisem testid töötavad. Kui Hensel-Zassenhaus kvadraat ja lineaarne liftings kasutatakse, et saada factorization f(x) mooduli võtmine kõrge võimsus peaminister. Aste-määrata testi ka mõju vähendada katsete arv rajoonides vaja, et kindlaks teha võimalikke tegureid üle ℤ[x] pärast liftings on lõppenud.
  • Factorization on polünoomi puhul ℚ(i)) [x] on saavutatud kasutades algoritmi kirjeldatud [Tra].
  • A squarefree lagunemine algoritm polynomials tõttu D. Y. Y. Yun-ja kirjeldatud [Knu][631-632] on kasutatud.
  • Irreducible polynomials antud aste (mod p) on ehitatud kasutades tõenäosuslik algoritm [Lu2][145-149].
  • algoritmi arvutamiseks kasutatud ja sellest tulenevalt kahe polynomials koos integer koefitsiendid on toodud artikli R. Loos [Buc][130].
  • cyclotomic polünoomi Φn(x) arvutatakse algoritmi abil [Lu2][354-356], mis omakorda põhineb konto funktsioonis [Lu1][58-63]. Faktooring Φpn-1(x) üle ℤp[x] annab {φ(pn-1)}/n monic primitiivne polynomials aste on n üle ℤp.
  • m-nda juure ratsionaalne number on arvutatud kasutades algoritmi [Ma1].


  • [Buc] B. Buchberger, G. E. Collins ja R. Loos (Toimetajad)
    Computer Algebra, Sümboolne ja Algebraline Arvutusvõimsus.
    1972, Springer-Verlag Wien, New York.
  • [Cam] P. Veoauto. Deterministlik Algoritm Factorizing Polynomials Fq[x].
    Annals of Diskreetne Matemaatika 17 (1983) 149-157.
  • [Fad] V. N. Faddeeva. arvutusmeetodid, Lineaarne Algebra.
    1959, Dover, New York.
  • [Fla] H. Flandria. Teaduslik Pascal.
    1984, Reston Kirjastus, Reston, Virginia. (Second Edition Birkhäuser, 1995).
  • [Har] B. Hartley ja T. O. Hawkes. Rõngad, Moodulite ja Lineaarne Algebra.
    1970, Chapman ja Hall, London.
  • [Knu] D. E. Knuth. Art of Computer Programming, Köide 2.
    Teine Trükk 1981, Addison-Wesley Publishing Company, Lugemine, Massachusettsis.
  • [Lu1] H. Lüneburg. Galoisfelder, Kreisteilungskörper und Schieberegisterfolgen.
    1979, B. I. Wissenschaftsverlag, Mannheim/Wien/Zürich.
  • [Lu2] H. Lüneburg. Ratsionaalne Normaalne Vorm Endomorphisms.
    1987, B. I. Wissenschaftsverlag, Mannheim/Wien/Zürich.
  • [Ma1] K. R. Matthews. Arvutid mth juured.
    Kolledži Matemaatika Teataja 19 (1988) 174-176.
  • [Ma2] K. R. Matthews. Ratsionaalne Kanooniline Vorm Algoritm.
    Mathematica Bohemica 117 (1992) 315-324 (pdf fail)
  • [McW] W. A. McWorter, Jr Algoritm Iseloomulik Polünoomi.
    Matemaatika Ajakiri, 56 (1983) 168-175.
  • [Mus] D. R. Musser. mitme muutujaga Polünoomi Factorization.
    J. A. C. M. 22 (1975) 291-308.
  • [Tra] B. M. Trager. Algebraline Faktooring ja Ratsionaalne Funktsioon Integratsiooni.
    Menetluse 1976. aasta ACM Sümpoosion Sümboolne ja Algebraline Arvutustehnika, 219-226.

Leave a Reply

Your email address will not be published. Required fields are marked *