Mode of #cas

eigenvalues

The exact eigenvalues of a square matrix with rational entries, with their multiplicities and a theorem that there are no others.

#cas [eigenvalues] A
gives the eigenvalues of the square matrix A with rational entries, each as often as its algebraic multiplicity, and proves that there are no others.

eigenvalues gives you the eigenvalues exactly. They come back as rational numbers, quadratic surds such as 12+52, complex numbers, or roots of a factor of higher degree, and a root of that last kind is named by an interval that contains it. I reach for this mode when the eigenvalues have to go into a proof, because the theorem doesn’t stop at saying that each number is an eigenvalue. It says the list is the whole spectrum. When every eigenvalue is rational, that theorem is a factorization of the characteristic polynomial over ℚ. Otherwise it is a statement about Mathlib’s spectrum over ℝ or ℂ, together with the roots of A.charpoly and their multiplicities.

Details and Options

  • A is a square matrix literal !![a, b; c, d] or a list of rows [[a, b], [c, d]]. The entries are closed rational expressions such as -3/2, 0.25 or 1/10^15.
  • When every eigenvalue is rational, the theorem is A.charpoly = (X - λ₁) ^ m₁ * ⋯ * (X - λₖ) ^ mₖ in ℚ[X]. An eigenvalue that is not an integer is written as a constant polynomial, such as Polynomial.C (1 / 4).
  • Otherwise let M be the matrix with the entries of A over K=ℝ when every eigenvalue is real, and over K=ℂ when one is not. The theorem is spectrum K M = {μ₁, …, μₛ}, each eigenvalue once, and M.charpoly.roots = {μ₁, …}, the multiset with the multiplicities.
  • A root of a factor R of degree 3 or more is named in the theorem by let r₁ := CAS.AlgRoot.real R lo hi, with r₁ ∈ Set.Ioo lo hi and R(r1)=0, or by CAS.AlgRoot.complex R u v ρ, with intervals for its real and imaginary parts. The report prints the intervals.
  • The kernel checks that the factors multiply to the characteristic polynomial (CAS.Analysis.Matrix.eigenCheck).
  • A factor of higher degree comes from the squarefree decomposition of the characteristic polynomial and need not be irreducible, and each of its roots gets its own interval.
  • There is no limit on the size of A. The search for the eigenvalues runs before the proof, and the proof runs with maxHeartbeats, Lean’s limit on the work of a command, raised to at least one million. So a large matrix can take long, and its proof can still run out of heartbeats.
  • There are no options.
  • With CASOracle.Numeric imported, #cas [eigenvalues, oracle := sympy] A asks an external system for the real eigenvalues as decimals. sage, pari and flint work the same way. Lean proves that an eigenvalue lies within 10−d of each decimal with d places, and does not check that the list is complete. See oracle.

Examples (12)#

Basic Examples (2)

Rational eigenvalues. The theorem factors the characteristic polynomial over ℚ:

In[1]:=
#cas [eigenvalues] !![2, 0, 0; 0, 3, 4; 0, 4, 9]
Out[1]=

eigenvalues with multiplicity

[1, 2, 11]
[1, 2, 11]
Domain
ℚ^(3×3)
Input (matrix)
!![2, 0, 0; 0, 3, 4; 0, 4, 9]

Checked by Lean’s kernel: Characteristic polynomial factored over ℚ

!![2, 0, 0; 0, 3, 4; 0, 4, 9].charpoly =
  (Polynomial.X - 1) * (Polynomial.X - 2) * (Polynomial.X - 11)
The certificate: 1 checked step
  1. Characteristic polynomial factored over ℚ

    !![2, 0, 0; 0, 3, 4; 0, 4, 9].charpoly =
      (Polynomial.X - 1) * (Polynomial.X - 2) * (Polynomial.X - 11)

    Checked by Lean’s kernel


The golden ratio and its conjugate. The theorem is about spectrum ℝ:

In[2]:=
#cas [eigenvalues] !![0, 1; 1, 1]
Out[2]=

eigenvalues with multiplicity

[12−52, 12+52]
[1/2 - √5/2, 1/2 + √5/2]
Domain
ℚ^(2×2)
Input (matrix)
!![0, 1; 1, 1]

Checked by Lean’s kernel: The spectrum with algebraic multiplicities

spectrum ℝ !![0, 1; 1, 1] = {1 / 2 - 1 / 2 * √5, 1 / 2 + 1 / 2 * √5} ∧
  !![0, 1; 1, 1].charpoly.roots = {1 / 2 - 1 / 2 * √5, 1 / 2 + 1 / 2 * √5}
The certificate: 1 checked step
  1. The spectrum with algebraic multiplicities

    spectrum ℝ !![0, 1; 1, 1] = {1 / 2 - 1 / 2 * √5, 1 / 2 + 1 / 2 * √5} ∧
      !![0, 1; 1, 1].charpoly.roots = {1 / 2 - 1 / 2 * √5, 1 / 2 + 1 / 2 * √5}

    Checked by Lean’s kernel

Scope (5)

A rotation by a right angle has the eigenvalues ±i, and the theorem is about spectrum ℂ:

In[3]:=
#cas [eigenvalues] !![0, -1; 1, 0]
Out[3]=

eigenvalues with multiplicity

[i, −i]
[i, -i]
Domain
ℚ^(2×2)
Input (matrix)
!![0, -1; 1, 0]

Checked by Lean’s kernel: The spectrum with algebraic multiplicities

spectrum ℂ !![0, -1; 1, 0] = {Complex.I, -Complex.I} ∧
  !![0, -1; 1, 0].charpoly.roots = {Complex.I, -Complex.I}
The certificate: 1 checked step
  1. The spectrum with algebraic multiplicities

    spectrum ℂ !![0, -1; 1, 0] = {Complex.I, -Complex.I} ∧
      !![0, -1; 1, 0].charpoly.roots = {Complex.I, -Complex.I}

    Checked by Lean’s kernel


Complex eigenvalues with a nonzero real part:

In[4]:=
#cas [eigenvalues] !![1, 2; -2, 1]
Out[4]=

eigenvalues with multiplicity

[1+2i, 1−2i]
[1 + 2i, 1 - 2i]
Domain
ℚ^(2×2)
Input (matrix)
!![1, 2; -2, 1]

Checked by Lean’s kernel: The spectrum with algebraic multiplicities

spectrum ℂ !![1, 2; -2, 1] = {1 + 2 * Complex.I, 1 - 2 * Complex.I} ∧
  !![1, 2; -2, 1].charpoly.roots = {1 + 2 * Complex.I, 1 - 2 * Complex.I}
The certificate: 1 checked step
  1. The spectrum with algebraic multiplicities

    spectrum ℂ !![1, 2; -2, 1] = {1 + 2 * Complex.I, 1 - 2 * Complex.I} ∧
      !![1, 2; -2, 1].charpoly.roots = {1 + 2 * Complex.I, 1 - 2 * Complex.I}

    Checked by Lean’s kernel


A real and two complex eigenvalues together:

In[5]:=
#cas [eigenvalues] !![2, 0, 0; 0, 0, -1; 0, 1, 0]
Out[5]=

eigenvalues with multiplicity

[2, i, −i]
[2, i, -i]
Domain
ℚ^(3×3)
Input (matrix)
!![2, 0, 0; 0, 0, -1; 0, 1, 0]

Checked by Lean’s kernel: The spectrum with algebraic multiplicities

spectrum ℂ !![2, 0, 0; 0, 0, -1; 0, 1, 0] = {2, Complex.I, -Complex.I} ∧
  !![2, 0, 0; 0, 0, -1; 0, 1, 0].charpoly.roots = {2, Complex.I, -Complex.I}
The certificate: 1 checked step
  1. The spectrum with algebraic multiplicities

    spectrum ℂ !![2, 0, 0; 0, 0, -1; 0, 1, 0] = {2, Complex.I, -Complex.I} ∧
      !![2, 0, 0; 0, 0, -1; 0, 1, 0].charpoly.roots = {2, Complex.I, -Complex.I}

    Checked by Lean’s kernel


Each eigenvalue appears as often as its multiplicity:

In[6]:=
#cas [eigenvalues] !![0, 1, 0, 0; 1, 1, 0, 0; 0, 0, 0, 1; 0, 0, 1, 1]
Out[6]=

eigenvalues with multiplicity

[12−52, 12−52, 12+52, 12+52]
[1/2 - √5/2, 1/2 - √5/2, 1/2 + √5/2, 1/2 + √5/2]
Domain
ℚ^(4×4)
Input (matrix)
!![0, 1, 0, 0; 1, 1, 0, 0; 0, 0, 0, 1; 0, 0, 1, 1]

Checked by Lean’s kernel: The spectrum with algebraic multiplicities

spectrum ℝ !![0, 1, 0, 0; 1, 1, 0, 0; 0, 0, 0, 1; 0, 0, 1, 1] =
    {1 / 2 - 1 / 2 * √5, 1 / 2 + 1 / 2 * √5} ∧
  !![0, 1, 0, 0; 1, 1, 0, 0; 0, 0, 0, 1; 0, 0, 1, 1].charpoly.roots =
    {1 / 2 - 1 / 2 * √5, 1 / 2 - 1 / 2 * √5, 1 / 2 + 1 / 2 * √5, 1 / 2 + 1 / 2 * √5}
The certificate: 1 checked step
  1. The spectrum with algebraic multiplicities

    spectrum ℝ !![0, 1, 0, 0; 1, 1, 0, 0; 0, 0, 0, 1; 0, 0, 1, 1] =
        {1 / 2 - 1 / 2 * √5, 1 / 2 + 1 / 2 * √5} ∧
      !![0, 1, 0, 0; 1, 1, 0, 0; 0, 0, 0, 1; 0, 0, 1, 1].charpoly.roots =
        {1 / 2 - 1 / 2 * √5, 1 / 2 - 1 / 2 * √5, 1 / 2 + 1 / 2 * √5, 1 / 2 + 1 / 2 * √5}

    Checked by Lean’s kernel


The roots of x3−2 are named by intervals: the real root 23 and two complex roots α±iβ:

In[7]:=
#cas [eigenvalues] !![0, 0, 2; 1, 0, 0; 0, 1, 0]
Out[7]=

eigenvalues with multiplicity

[r₁, z₁, conj z₁]; r₁ ∈ (1.25992104, 1.25992106), z₁, conj z₁ = α ± iβ, α ∈ [-0.62996054, -0.62996050], β ∈ [1.09112362, 1.09112366]
Domain
ℚ^(3×3)
Input (matrix)
!![0, 0, 2; 1, 0, 0; 0, 1, 0]

Checked by Lean’s kernel: The spectrum with algebraic multiplicities

let r₁ := CAS.AlgRoot.real [-2, 0, 0, 1] 1.25992104 1.25992106;
let z₁ := CAS.AlgRoot.complex [-2, 0, 0, 1] (-0.62996052) 1.09112364 2e-8;
(r₁ ∈ Set.Ioo 1.25992104 1.25992106 ∧ r₁ ^ 3 - 2 = 0) ∧
  (z₁.re ∈ Set.Icc (-0.62996054) (-0.62996050) ∧ z₁.im ∈ Set.Icc 1.09112362 1.09112366 ∧ z₁ ^ 3 - 2 = 0) ∧
    spectrum ℂ !![0, 0, 2; 1, 0, 0; 0, 1, 0] = {↑r₁, z₁, (starRingEnd ℂ) z₁} ∧
      !![0, 0, 2; 1, 0, 0; 0, 1, 0].charpoly.roots = {↑r₁, z₁, (starRingEnd ℂ) z₁}
The certificate: 1 checked step
  1. The spectrum with algebraic multiplicities

    let r₁ := CAS.AlgRoot.real [-2, 0, 0, 1] 1.25992104 1.25992106;
    let z₁ := CAS.AlgRoot.complex [-2, 0, 0, 1] (-0.62996052) 1.09112364 2e-8;
    (r₁ ∈ Set.Ioo 1.25992104 1.25992106 ∧ r₁ ^ 3 - 2 = 0) ∧
      (z₁.re ∈ Set.Icc (-0.62996054) (-0.62996050) ∧ z₁.im ∈ Set.Icc 1.09112362 1.09112366 ∧ z₁ ^ 3 - 2 = 0) ∧
        spectrum ℂ !![0, 0, 2; 1, 0, 0; 0, 1, 0] = {↑r₁, z₁, (starRingEnd ℂ) z₁} ∧
          !![0, 0, 2; 1, 0, 0; 0, 1, 0].charpoly.roots = {↑r₁, z₁, (starRingEnd ℂ) z₁}

    Checked by Lean’s kernel

Applications (2)

A proof can take the first part of the printed theorem as a hypothesis and read an eigenvalue off it, here the golden ratio:

In[8]:=
theorem golden_ratio_mem_spectrum
    (h : spectrum ℝ !![(0 : ℝ), 1; 1, 1] = {1 / 2 - 1 / 2 * √5, 1 / 2 + 1 / 2 * √5}) :
    1 / 2 + 1 / 2 * √5 ∈ spectrum ℝ !![(0 : ℝ), 1; 1, 1] := by
  rw [h]
  exact Set.mem_insert_of_mem _ (Set.mem_singleton _)
Out[8]=

Lean accepts the proof.


A transition matrix of a Markov chain has the eigenvalue 1. The other eigenvalue, 14, says how fast the chain forgets where it started:

In[9]:=
#cas [eigenvalues] !![1/2, 1/2; 1/4, 3/4]
Out[9]=

eigenvalues with multiplicity

[14, 1]
[1/4, 1]
Domain
ℚ^(2×2)
Input (matrix)
!![1/2, 1/2; 1/4, 3/4]

Checked by Lean’s kernel: Characteristic polynomial factored over ℚ

!![1 / 2, 1 / 2; 1 / 4, 3 / 4].charpoly =
  (Polynomial.X - Polynomial.C (1 / 4)) * (Polynomial.X - 1)
The certificate: 1 checked step
  1. Characteristic polynomial factored over ℚ

    !![1 / 2, 1 / 2; 1 / 4, 3 / 4].charpoly =
      (Polynomial.X - Polynomial.C (1 / 4)) * (Polynomial.X - 1)

    Checked by Lean’s kernel

Properties and Relations (2)

The eigenvalues are the roots of the characteristic polynomial. Here their sum is the trace 5 and their product is the determinant −2:

In[10]:=
#cas [eigenvalues] !![1, 2; 3, 4]
Out[10]=

eigenvalues with multiplicity

[52−332, 52+332]
[5/2 - √33/2, 5/2 + √33/2]
Domain
ℚ^(2×2)
Input (matrix)
!![1, 2; 3, 4]

Checked by Lean’s kernel: The spectrum with algebraic multiplicities

spectrum ℝ !![1, 2; 3, 4] = {5 / 2 - 1 / 2 * √33, 5 / 2 + 1 / 2 * √33} ∧
  !![1, 2; 3, 4].charpoly.roots = {5 / 2 - 1 / 2 * √33, 5 / 2 + 1 / 2 * √33}
The certificate: 1 checked step
  1. The spectrum with algebraic multiplicities

    spectrum ℝ !![1, 2; 3, 4] = {5 / 2 - 1 / 2 * √33, 5 / 2 + 1 / 2 * √33} ∧
      !![1, 2; 3, 4].charpoly.roots = {5 / 2 - 1 / 2 * √33, 5 / 2 + 1 / 2 * √33}

    Checked by Lean’s kernel

In[11]:=
#cas [characteristicPolynomial] !![1, 2; 3, 4]
Out[11]=

det (x I - A)

x2−5x−2
x^2 - 5*x - 2
Domain
ℚ^(2×2)
Input (matrix)
!![1, 2; 3, 4]

Checked by Lean’s kernel: Characteristic polynomial in ℚ[X]

!![1, 2; 3, 4].charpoly = Polynomial.X ^ 2 - 5 * Polynomial.X - 2
The certificate: 1 checked step
  1. Characteristic polynomial in ℚ[X]

    !![1, 2; 3, 4].charpoly = Polynomial.X ^ 2 - 5 * Polynomial.X - 2

    Checked by Lean’s kernel


For a symmetric matrix, eigenvalueBounds bounds the smallest and the largest eigenvalue in decimals. Here they are 3∓3:

In[12]:=
#cas [eigenvalues] !![4, 1, 0; 1, 3, 1; 0, 1, 2]
Out[12]=

eigenvalues with multiplicity

[3, 3−3, 3+3]
[3, 3 - √3, 3 + √3]
Domain
ℚ^(3×3)
Input (matrix)
!![4, 1, 0; 1, 3, 1; 0, 1, 2]

Checked by Lean’s kernel: The spectrum with algebraic multiplicities

spectrum ℝ !![4, 1, 0; 1, 3, 1; 0, 1, 2] = {3, 3 - √3, 3 + √3} ∧
  !![4, 1, 0; 1, 3, 1; 0, 1, 2].charpoly.roots = {3, 3 - √3, 3 + √3}
The certificate: 1 checked step
  1. The spectrum with algebraic multiplicities

    spectrum ℝ !![4, 1, 0; 1, 3, 1; 0, 1, 2] = {3, 3 - √3, 3 + √3} ∧
      !![4, 1, 0; 1, 3, 1; 0, 1, 2].charpoly.roots = {3, 3 - √3, 3 + √3}

    Checked by Lean’s kernel

In[13]:=
#cas [eigenvalueBounds] !![4, 1, 0; 1, 3, 1; 0, 1, 2]
Out[13]=

Rayleigh bounds

1.267949≤λmin,λmax≤4.732051
1.267949 ≤ λ_min, λ_max ≤ 4.732051
Domain
3 × 3 symmetric real matrix
Input (matrix)
!![4, 1, 0; 1, 3, 1; 0, 1, 2]

Checked by Lean’s kernel: Rayleigh bounds, sharp to 10^-6

(∀ (x : Fin 3 → ℝ),
    1.267949 * ∑ i, x i ^ 2 ≤ ∑ i, ∑ j, !![4, 1, 0; 1, 3, 1; 0, 1, 2] i j * x i * x j ∧
      ∑ i, ∑ j, !![4, 1, 0; 1, 3, 1; 0, 1, 2] i j * x i * x j ≤ 4.732051 * ∑ i, x i ^ 2) ∧
  (∃ x, ∑ i, ∑ j, !![4, 1, 0; 1, 3, 1; 0, 1, 2] i j * x i * x j < 1.267950 * ∑ i, x i ^ 2) ∧
    ∃ x, 4.732050 * ∑ i, x i ^ 2 < ∑ i, ∑ j, !![4, 1, 0; 1, 3, 1; 0, 1, 2] i j * x i * x j
The certificate: 1 checked step
  1. Rayleigh bounds, sharp to 10^-6

    (∀ (x : Fin 3 → ℝ),
        1.267949 * ∑ i, x i ^ 2 ≤ ∑ i, ∑ j, !![4, 1, 0; 1, 3, 1; 0, 1, 2] i j * x i * x j ∧
          ∑ i, ∑ j, !![4, 1, 0; 1, 3, 1; 0, 1, 2] i j * x i * x j ≤ 4.732051 * ∑ i, x i ^ 2) ∧
      (∃ x, ∑ i, ∑ j, !![4, 1, 0; 1, 3, 1; 0, 1, 2] i j * x i * x j < 1.267950 * ∑ i, x i ^ 2) ∧
        ∃ x, 4.732050 * ∑ i, x i ^ 2 < ∑ i, ∑ j, !![4, 1, 0; 1, 3, 1; 0, 1, 2] i j * x i * x j

    Checked by Lean’s kernel

The computation
  • Certificate

    A - cI = L D Lᵀ and μI - A = L' D' L'ᵀ over ℚ, with nonnegative pivots
    x, y over ℚ with xᵀAx < (c + 10^-6) |x|² and yᵀAy > (μ - 10^-6) |y|²

Possible Issues (1)

The matrix has to be square. matrixRank and nullSpace describe a matrix of any shape:

In[14]:=
#cas [eigenvalues] !![1, 2, 3; 4, 5, 6]
Out[14]=

Error

eigenvalues: the matrix must be square

See Also

characteristicPolynomial · eigenvectors · eigenvalueBounds · roots