Topic
Jordan and canonical forms
Two matrices are similar (B = P⁻¹AP) when they describe the same map in different coordinates. The eigenvalues do not settle similarity, because a repeated eigenvalue can come with fewer independent eigenvectors than its multiplicity. The complete answer is the list of invariant factors: the Smith normal form of xI − A over the polynomials with rational coefficients.
- The last invariant factor is the minimal polynomial, the lowest-degree polynomial that sends A to 0.
- Putting the companion matrix of each invariant factor on the diagonal gives the rational canonical form. It is always rational, whatever the eigenvalues.
- Splitting each invariant factor into square-free parts gives the Jordan block sizes of every eigenvalue, irrational and complex ones included.
Blocks from kernel dimensions
For a single eigenvalue λ, let N = A − λI. The number of Jordan blocks of size at least k equals dim ker Nᵏ − dim ker Nᵏ⁻¹. When λ is rational the library also builds Jordan chains (v, Nv, N²v, …) and from them the matrix P with A = PJP⁻¹, checked exactly.
In code
import { jordan, algebraic } from "@ratmath/linalg";
const j = jordan([[2, 1, 0], [0, 2, 0], [0, 0, 3]]).exact();
j.jordan; // eigenvalue 2 with one block of size 2, eigenvalue 3 with one of size 1
j.J.toStrings(); // [["2","1","0"], ["0","2","0"], ["0","0","3"]]
// Irrational eigenvalues: J and P as exact algebraic numbers
const k = jordan([[0, 2], [1, 0]]).exact();
k.J; // null, because ±√2 are not rational
const { J, P } = k.algebraicForm();
J.map((row) => row.map(algebraic.format)); // [["−√2", "0"], ["0", "√2"]]
P.map((row) => row.map(algebraic.format)); // [["−√2", "√2"], ["1", "1"]]
Try itEdit the code and run it with
@ratmath/linalg and Core's Rational, RationalInterval in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.