Modules over Q[x]
A matrix is a way for the variable x to act on vectors. Seen like that, the classification of matrices up to similarity is the same theorem as the classification of abelian groups, with polynomials in place of whole numbers.
A matrix as a module
A module over a ring is like a vector space whose scalars come from the ring. Abelian groups are the modules over . A square matrix over makes a module over the polynomial ring : a polynomial acts on a vector as .
has division with remainder, just like , so the same Smith normal form works over it, and the same structure theorem holds. The relations of this module are the columns of (they say that acting on is the -th column of ), so
where the are the monic non-constant diagonal entries of the Smith form of : the invariant factors of . Their product is the characteristic polynomial and the last one is the minimal polynomial.
import { matrixModule } from "@ratmath/structures";
const M = matrixModule([[2, 1, 0, 0], [0, 2, 0, 0], [0, 0, 2, 0], [0, 0, 0, 3]]);
String(M); // "Q[x]/(x − 2) ⊕ Q[x]/(x³ − 7x² + 16x − 12)"
String(M.minimalPolynomial); // "x³ − 7x² + 16x − 12"
String(M.characteristicPolynomial); // "x⁴ − 9x³ + 30x² − 44x + 24"
M.elementaryDivisors.map((e) => String(e.divisor)); // ["x − 2", "x − 3", "x² − 4x + 4"]
M.isCyclic; // false: two summands
The rational canonical form
On with , the basis is moved by as . That is the companion matrix of : ones below the diagonal and down the last column. Putting the companion blocks of the invariant factors together gives the rational canonical form of : two matrices are similar over exactly when they have the same one. It needs no eigenvalues, so it works when the characteristic polynomial does not factor. The elementary divisors (the prime-power parts of the invariant factors) give the finer primary decomposition; when they are all powers of linear factors they are the Jordan blocks.
import { matrixModule } from "@ratmath/structures";
const M = matrixModule([[0, -1, 0], [1, 0, 0], [0, 0, 2]]); // a quarter turn, and a stretch
String(M); // "Q[x]/(x³ − 2x² + x − 2)": cyclic
M.elementaryDivisors.map((e) => String(e.divisor)); // ["x − 2", "x² + 1"]
M.rationalCanonical.map((r) => r.map(String).join(" ")); // ["0 0 2", "1 0 -1", "0 1 2"]
matrixModule([[2, 0], [0, 2]]).isCyclic; // false: Q[x]/(x − 2) ⊕ Q[x]/(x − 2)
matrixModule([[1, 1], [0, 1]]).isCyclic; // true: Q[x]/((x − 1)²)
This is the same computation as @ratmath/linalg's similarity(A), done a second way: the tests compare the invariant factors, minimal polynomials and rational canonical forms of the two on many matrices. The Smith form itself is available over any Euclidean domain as smithForm(A, domain), with ZZ and polynomialDomain("x") built in.
import { smithForm, polynomialDomain } from "@ratmath/structures";
const Qx = polynomialDomain("x");
smithForm([["x^2 - 1", "x - 1"], ["x + 1", "x^2 + x"]], Qx).diagonal.map(String);
// ["1", "x⁴ + x³ − 2x² − x + 1"]
@ratmath/structures and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.