Mode of #cas
trace
The trace of a square matrix with rational entries, with a theorem about Mathlib’s Matrix.trace.
#cas [trace] AA.trace = t.The trace is the sum of the diagonal entries. It is also the sum of the eigenvalues, and minus the second coefficient of the characteristic polynomial, so it makes a quick check on both. trace prints it with a theorem about Mathlib’s Matrix.trace.
Examples (11)#
Basic Examples (2)
The trace of a matrix:
#cas [trace] !![1, 2; 3, 4]
trace
5- Domain
ℚ^(2×2)- Input (matrix)
!![1, 2; 3, 4]
Checked by Lean’s kernel: Decided by kernel evaluation
!![1, 2; 3, 4].trace = 5
The certificate: 1 checked step
Decided by kernel evaluation
!![1, 2; 3, 4].trace = 5
Fractions on the diagonal:
#cas [trace] !![1/2, 7; 0, 1/3]
trace
5/6- Domain
ℚ^(2×2)- Input (matrix)
!![1/2, 7; 0, 1/3]
Checked by Lean’s kernel: Decided by kernel evaluation
!![1 / 2, 7; 0, 1 / 3].trace = 5 / 6
The certificate: 1 checked step
Decided by kernel evaluation
!![1 / 2, 7; 0, 1 / 3].trace = 5 / 6
Scope (2)
A list of rows works as well as a matrix literal:
#cas [trace] [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
trace
15- Domain
ℚ^(3×3)- Input (matrix)
!![1, 2, 3; 4, 5, 6; 7, 8, 9]
Checked by Lean’s kernel: Decided by kernel evaluation
!![1, 2, 3; 4, 5, 6; 7, 8, 9].trace = 15
The certificate: 1 checked step
Decided by kernel evaluation
!![1, 2, 3; 4, 5, 6; 7, 8, 9].trace = 15
The trace of the identity is its size:
#cas [trace] !![1, 0, 0, 0; 0, 1, 0, 0; 0, 0, 1, 0; 0, 0, 0, 1]
trace
4- Domain
ℚ^(4×4)- Input (matrix)
!![1, 0, 0, 0; 0, 1, 0, 0; 0, 0, 1, 0; 0, 0, 0, 1]
Checked by Lean’s kernel: Decided by kernel evaluation
!![1, 0, 0, 0; 0, 1, 0, 0; 0, 0, 1, 0; 0, 0, 0, 1].trace = 4
The certificate: 1 checked step
Decided by kernel evaluation
!![1, 0, 0, 0; 0, 1, 0, 0; 0, 0, 1, 0; 0, 0, 0, 1].trace = 4
Applications (1)
The trace as a theorem. cas proves it, and only the three standard axioms are used:
theorem trace_two : Matrix.trace !![(1 : ℚ), 2; 3, 4] = 5 := by cas #print axioms trace_two
trace_two depends on the axioms propext, Classical.choice, Quot.sound.
Properties and Relations (3)
The trace is the sum of the eigenvalues. Here they are , and , and the trace is :
#cas [eigenvalues] !![2, 0, 0; 0, 3, 4; 0, 4, 9]
eigenvalues with multiplicity
[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
Characteristic polynomial factored over ℚ
!![2, 0, 0; 0, 3, 4; 0, 4, 9].charpoly = (Polynomial.X - 1) * (Polynomial.X - 2) * (Polynomial.X - 11)
#cas [trace] !![2, 0, 0; 0, 3, 4; 0, 4, 9]
trace
14- Domain
ℚ^(3×3)- Input (matrix)
!![2, 0, 0; 0, 3, 4; 0, 4, 9]
Checked by Lean’s kernel: Decided by kernel evaluation
!![2, 0, 0; 0, 3, 4; 0, 4, 9].trace = 14
The certificate: 1 checked step
Decided by kernel evaluation
!![2, 0, 0; 0, 3, 4; 0, 4, 9].trace = 14
The coefficient of in the characteristic polynomial is minus the trace:
#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
The eigenvalues of the same matrix are irrational, and they add up to :
#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}
Possible Issues (2)
The matrix has to be square:
#cas [trace] !![1, 2, 3; 4, 5, 6]
Error
trace: the matrix must be square
The entries have to be rational numbers:
#cas [trace] !![a, b; c, d]
Error
expected a rational number, such as -3/2, 0.25 or 1/10^15
For a literal with variables, Mathlib has the formula:
example (a b c d : ℝ) : Matrix.trace !![a, b; c, d] = a + d := Matrix.trace_fin_two_of a b c d
Lean accepts the proof.
Neat Examples (1)
The powers of hold the Fibonacci numbers, and their traces are the Lucas numbers. The trace of the tenth power is :
#cas [matrixPower 10] !![1, 1; 1, 0]
power
!![89, 55; 55, 34]- Domain
ℚ^(2×2)- Input (matrix)
!![1, 1; 1, 0]
Checked by Lean’s kernel: Decided by kernel evaluation
!![1, 1; 1, 0] ^ 10 = !![89, 55; 55, 34]
The certificate: 1 checked step
Decided by kernel evaluation
!![1, 1; 1, 0] ^ 10 = !![89, 55; 55, 34]
#cas [trace] !![89, 55; 55, 34]
trace
123- Domain
ℚ^(2×2)- Input (matrix)
!![89, 55; 55, 34]
Checked by Lean’s kernel: Decided by kernel evaluation
!![89, 55; 55, 34].trace = 123
The certificate: 1 checked step
Decided by kernel evaluation
!![89, 55; 55, 34].trace = 123
See Also
det · characteristicPolynomial · eigenvalues · transpose · matrixPower
