Mode of #cas
characteristicPolynomial
The characteristic polynomial of a square matrix with rational entries, with a theorem about Mathlib’s Matrix.charpoly.
#cas [characteristicPolynomial] AA.charpoly = p in ℚ[X].The characteristic polynomial holds a lot of a matrix at once: its roots are the eigenvalues, and the trace and the determinant can be read off its coefficients. It also appears in the Cayley-Hamilton theorem and in formulas for linear recurrences. characteristicPolynomial computes it, with a theorem about Mathlib’s Matrix.charpoly, the monic polynomial . If you are coming from Mathematica, watch the sign. Mathematica’s CharacteristicPolynomial is , which is times this one.
Examples (13)#
Basic Examples (2)
For a matrix the polynomial is :
#cas [characteristicPolynomial] !![1, 2; 3, 4]
det (x I - A)
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
Characteristic polynomial in ℚ[X]
!![1, 2; 3, 4].charpoly = Polynomial.X ^ 2 - 5 * Polynomial.X - 2
A matrix:
#cas [characteristicPolynomial] !![1, 2, 3; 4, 5, 6; 7, 8, 10]
det (x I - A)
x^3 - 16*x^2 - 12*x + 3- Domain
ℚ^(3×3)- Input (matrix)
!![1, 2, 3; 4, 5, 6; 7, 8, 10]
Checked by Lean’s kernel: Characteristic polynomial in ℚ[X]
!![1, 2, 3; 4, 5, 6; 7, 8, 10].charpoly = Polynomial.X ^ 3 - 16 * Polynomial.X ^ 2 - 12 * Polynomial.X + 3
The certificate: 1 checked step
Characteristic polynomial in ℚ[X]
!![1, 2, 3; 4, 5, 6; 7, 8, 10].charpoly = Polynomial.X ^ 3 - 16 * Polynomial.X ^ 2 - 12 * Polynomial.X + 3
Scope (3)
The matrix of second differences of size 4:
#cas [characteristicPolynomial] !![2, -1, 0, 0; -1, 2, -1, 0; 0, -1, 2, -1; 0, 0, -1, 2]
det (x I - A)
x^4 - 8*x^3 + 21*x^2 - 20*x + 5- Domain
ℚ^(4×4)- Input (matrix)
!![2, -1, 0, 0; -1, 2, -1, 0; 0, -1, 2, -1; 0, 0, -1, 2]
Checked by Lean’s kernel: Characteristic polynomial in ℚ[X]
!![2, -1, 0, 0; -1, 2, -1, 0; 0, -1, 2, -1; 0, 0, -1, 2].charpoly = Polynomial.X ^ 4 - 8 * Polynomial.X ^ 3 + 21 * Polynomial.X ^ 2 - 20 * Polynomial.X + 5
The certificate: 1 checked step
Characteristic polynomial in ℚ[X]
!![2, -1, 0, 0; -1, 2, -1, 0; 0, -1, 2, -1; 0, 0, -1, 2].charpoly = Polynomial.X ^ 4 - 8 * Polynomial.X ^ 3 + 21 * Polynomial.X ^ 2 - 20 * Polynomial.X + 5
Fractions give rational coefficients:
#cas [characteristicPolynomial] !![1/2, 1/3; 1/4, 1/5]
det (x I - A)
x^2 - 7/10*x + 1/60- Domain
ℚ^(2×2)- Input (matrix)
!![1/2, 1/3; 1/4, 1/5]
Checked by Lean’s kernel: Characteristic polynomial in ℚ[X]
!![1 / 2, 1 / 3; 1 / 4, 1 / 5].charpoly = Polynomial.X ^ 2 - Polynomial.C (7 / 10) * Polynomial.X + Polynomial.C (1 / 60)
The certificate: 1 checked step
Characteristic polynomial in ℚ[X]
!![1 / 2, 1 / 3; 1 / 4, 1 / 5].charpoly = Polynomial.X ^ 2 - Polynomial.C (7 / 10) * Polynomial.X + Polynomial.C (1 / 60)
A rotation by a right angle, written as a list of rows. Its polynomial has no real roots:
#cas [characteristicPolynomial] [[0, -1], [1, 0]]
det (x I - A)
x^2 + 1- Domain
ℚ^(2×2)- Input (matrix)
!![0, -1; 1, 0]
Checked by Lean’s kernel: Characteristic polynomial in ℚ[X]
!![0, -1; 1, 0].charpoly = Polynomial.X ^ 2 + 1
The certificate: 1 checked step
Characteristic polynomial in ℚ[X]
!![0, -1; 1, 0].charpoly = Polynomial.X ^ 2 + 1
Applications (3)
The polynomial as a theorem. Only the three standard axioms are used:
theorem charpoly_two : Matrix.charpoly !![(1 : ℚ), 2; 3, 4] = Polynomial.X ^ 2 - 5 * Polynomial.X - 2 := by cas #print axioms charpoly_two
charpoly_two depends on the axioms propext, Classical.choice, Quot.sound.
With the theorem above, Mathlib’s Cayley-Hamilton theorem Matrix.aeval_self_charpoly says that the matrix is a root of the printed polynomial, :
example : Polynomial.aeval !![(1 : ℚ), 2; 3, 4] (Polynomial.X ^ 2 - 5 * Polynomial.X - 2 : Polynomial ℚ) = 0 := by rw [← charpoly_two] exact Matrix.aeval_self_charpoly _
Lean accepts the proof.
Every monic polynomial is the characteristic polynomial of its companion matrix. This one belongs to :
#cas [characteristicPolynomial] !![0, 0, 2; 1, 0, 0; 0, 1, 0]
det (x I - A)
x^3 - 2- Domain
ℚ^(3×3)- Input (matrix)
!![0, 0, 2; 1, 0, 0; 0, 1, 0]
Checked by Lean’s kernel: Characteristic polynomial in ℚ[X]
!![0, 0, 2; 1, 0, 0; 0, 1, 0].charpoly = Polynomial.X ^ 3 - 2
The certificate: 1 checked step
Characteristic polynomial in ℚ[X]
!![0, 0, 2; 1, 0, 0; 0, 1, 0].charpoly = Polynomial.X ^ 3 - 2
Properties and Relations (3)
The roots of the polynomial are the eigenvalues. For the first example they are :
#cas [eigenvalues] !![1, 2; 3, 4]
eigenvalues with multiplicity
[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
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 trace and the determinant are coefficients. For the second example the trace is 16 and the determinant is , so the polynomial is :
#cas [trace] !![1, 2, 3; 4, 5, 6; 7, 8, 10]
trace
16- Domain
ℚ^(3×3)- Input (matrix)
!![1, 2, 3; 4, 5, 6; 7, 8, 10]
Checked by Lean’s kernel: Decided by kernel evaluation
!![1, 2, 3; 4, 5, 6; 7, 8, 10].trace = 16
The certificate: 1 checked step
Decided by kernel evaluation
!![1, 2, 3; 4, 5, 6; 7, 8, 10].trace = 16
#cas [det] !![1, 2, 3; 4, 5, 6; 7, 8, 10]
determinant
-3- Domain
ℚ^(3×3)- Input (matrix)
!![1, 2, 3; 4, 5, 6; 7, 8, 10]
Checked by Lean’s kernel: Determinant
!![1, 2, 3; 4, 5, 6; 7, 8, 10].det = -3
The certificate: 1 checked step
Determinant
!![1, 2, 3; 4, 5, 6; 7, 8, 10].det = -3
A matrix and its transpose have the same characteristic polynomial. This is the transpose of the first example:
#cas [characteristicPolynomial] !![1, 3; 2, 4]
det (x I - A)
x^2 - 5*x - 2- Domain
ℚ^(2×2)- Input (matrix)
!![1, 3; 2, 4]
Checked by Lean’s kernel: Characteristic polynomial in ℚ[X]
!![1, 3; 2, 4].charpoly = Polynomial.X ^ 2 - 5 * Polynomial.X - 2
The certificate: 1 checked step
Characteristic polynomial in ℚ[X]
!![1, 3; 2, 4].charpoly = Polynomial.X ^ 2 - 5 * Polynomial.X - 2
Possible Issues (1)
The matrix has to be square:
#cas [characteristicPolynomial] !![1, 2, 3; 4, 5, 6]
Error
characteristicPolynomial: the matrix must be square
Neat Examples (1)
The companion matrix of , whose roots are the four numbers . Their eigenvalue report is on the eigenvalues page:
#cas [characteristicPolynomial] !![0, 0, 0, -1; 1, 0, 0, 0; 0, 1, 0, 10; 0, 0, 1, 0]
det (x I - A)
x^4 - 10*x^2 + 1- Domain
ℚ^(4×4)- Input (matrix)
!![0, 0, 0, -1; 1, 0, 0, 0; 0, 1, 0, 10; 0, 0, 1, 0]
Checked by Lean’s kernel: Characteristic polynomial in ℚ[X]
!![0, 0, 0, -1; 1, 0, 0, 0; 0, 1, 0, 10; 0, 0, 1, 0].charpoly = Polynomial.X ^ 4 - 10 * Polynomial.X ^ 2 + 1
The certificate: 1 checked step
Characteristic polynomial in ℚ[X]
!![0, 0, 0, -1; 1, 0, 0, 0; 0, 1, 0, 10; 0, 0, 1, 0].charpoly = Polynomial.X ^ 4 - 10 * Polynomial.X ^ 2 + 1
See Also
eigenvalues · eigenvectors · det · trace · matrixPower
