Topic

Eigenvalues and eigenvectors

λ is an eigenvalue of A when A − λI is singular, that is, when λ is a root of the characteristic polynomial det(λI − A). Its roots are usually irrational, so an exact library has to decide what an exact irrational answer is.

The characteristic polynomial

The library reduces A to Hessenberg form (zeros below the first subdiagonal) by similarity transforms, which keeps the eigenvalues, and reads the polynomial off with a short recurrence. It does this modulo primes and joins the results, like the modular determinant, so the polynomial is exact and the work is fast.

Exact irrational numbers

Repeated roots are split off with gcd(p, p′). For each remaining square-free factor, Sturm's theorem counts its real roots in any interval exactly. Bisecting until each interval holds one root gives an AlgebraicReal: the polynomial plus an interval. That pair is the exact number. Refining it is bisection, one bit per step, so you can ask for as many digits as you like, and the library also decides exactly whether the root is rational.

Complex eigenvalues

Sturm's count also tells how many roots are not real. Floating-point root finding locates them; then the Krawczyk test, applied to p(x + iy) = 0 as two real equations, proves each small box holds exactly one root. Checking that the boxes do not overlap accounts for every root. Try a rotation such as 0 −1 / 1 0 in the demo above.

Sturm sequences, step by step

Start with p and p′, then keep taking negated remainders: p₂ = −rem(p, p′), p₃ = −rem(p′, p₂), and so on. At any x, count the sign changes along the sequence. Sturm's theorem: the number of real roots in (a, b] is the count at a minus the count at b. So roots can be counted exactly, without finding them, and bisection pins each one into its own interval.

Eigenvectors over Q(λ)

For a rational eigenvalue the eigenvectors are the null space of A − λI, computed exactly. For an irrational one, the columns of the adjugate of λI − A are eigenvectors, and the adjugate of xI − A is a polynomial in x with rational matrix coefficients (Faddeev–LeVerrier). So each entry of an eigenvector is a polynomial in λ: an exact element of Q(λ). Reduce it modulo λ's polynomial and it has low degree.

In code

import { eigenvalues, eigenvectors, symmetricEigen, definiteness, algebraic } from "@ratmath/linalg";

const A = [[1, 1], [1, 0]];
eigenvalues(A).exact().real.map((e) => e.value.toString(12));
// ["-0.618033988749…", "1.618033988749…"], each an exact root of x² − x − 1

const [small] = eigenvectors(A).exact();
small.basis[0].toStrings();   // ["λ", "1"], exact in terms of the eigenvalue λ

// A symmetric matrix has an exact orthonormal eigenbasis
const s = symmetricEigen([[2, 1], [1, 2]]).exact();
s.values.map(algebraic.format);                        // ["1", "3"]
s.Q.map((row) => row.map(algebraic.format));           // [["−√2/2", "√2/2"], ["√2/2", "√2/2"]]
definiteness([[2, 1], [1, 2]]).exact().kind;           // "positive-definite"
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.
Ctrl/⌘ + Enter runs