Modules

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 Z\mathbb Z. A square matrix AA over Q\mathbb Q makes Qn\mathbb Q^n a module over the polynomial ring Q[x]\mathbb Q[x]: a polynomial ff acts on a vector vv as f(A)vf(A)v.

Q[x]\mathbb Q[x] has division with remainder, just like Z\mathbb Z, so the same Smith normal form works over it, and the same structure theorem holds. The relations of this module are the columns of xI−AxI - A (they say that xx acting on eje_j is the jj-th column of AA), so

Qn≅Q[x]/(f1)⊕⋯⊕Q[x]/(fk),f1∣f2∣⋯∣fk, \mathbb Q^n \cong \mathbb Q[x]/(f_1) \oplus \cdots \oplus \mathbb Q[x]/(f_k), \qquad f_1 \mid f_2 \mid \cdots \mid f_k,

where the fif_i are the monic non-constant diagonal entries of the Smith form of xI−AxI - A: the invariant factors of AA. 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 Q[x]/(f)\mathbb Q[x]/(f) with f=xd+cd−1xd−1+⋯+c0f = x^d + c_{d-1}x^{d-1} + \dots + c_0, the basis 1,x,…,xd−11, x, \dots, x^{d-1} is moved by xx as 1↦x↦x2↦⋯↦xd=−c0−c1x−⋯1 \mapsto x \mapsto x^2 \mapsto \cdots \mapsto x^d = -c_0 - c_1x - \cdots. That is the companion matrix of ff: ones below the diagonal and −c0,…,−cd−1-c_0, \dots, -c_{d-1} down the last column. Putting the companion blocks of the invariant factors together gives the rational canonical form of AA: two matrices are similar over Q\mathbb Q 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"]
Try itEdit the code and run it with @ratmath/structures and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.
Ctrl/⌘ + Enter runs