Mode of #cas
det
The determinant of a square matrix with rational entries, with a theorem about Mathlib’s Matrix.det.
#cas [det] AA.det = d for Mathlib’s Matrix.det.det evaluates the determinant of a matrix over . You write the matrix as a Mathlib literal, the report prints the number, and the theorem under it is A.det = d for Mathlib’s Matrix.det over . Because it is a statement about the same matrix you would write in a proof, it can go straight into one.
Examples (14)#
Basic Examples (2)
The determinant of a matrix:
#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
The entries can be fractions:
#cas [det] !![1/2, 1; 3, 4]
determinant
-1- Domain
ℚ^(2×2)- Input (matrix)
!![1/2, 1; 3, 4]
Checked by Lean’s kernel: Determinant
!![1 / 2, 1; 3, 4].det = -1
The certificate: 1 checked step
Determinant
!![1 / 2, 1; 3, 4].det = -1
Scope (3)
A matrix, tridiagonal except for its two corners:
#cas [det] !![2, -1, 0, 0, 1; -1, 2, -1, 0, 0; 0, -1, 2, -1, 0; 0, 0, -1, 2, -1; 1, 0, 0, -1, 2]
determinant
4- Domain
ℚ^(5×5)- Input (matrix)
!![2, -1, 0, 0, 1; -1, 2, -1, 0, 0; 0, -1, 2, -1, 0; 0, 0, -1, 2, -1; 1, 0, 0, -1, 2]
Checked by Lean’s kernel: Determinant
!![2, -1, 0, 0, 1; -1, 2, -1, 0, 0; 0, -1, 2, -1, 0; 0, 0, -1, 2, -1; 1, 0, 0, -1, 2].det = 4
The certificate: 1 checked step
Determinant
!![2, -1, 0, 0, 1; -1, 2, -1, 0, 0; 0, -1, 2, -1, 0; 0, 0, -1, 2, -1; 1, 0, 0, -1, 2].det = 4
A list of rows works as well as a matrix literal:
#cas [det] [[1, 2], [3, 4]]
determinant
-2- Domain
ℚ^(2×2)- Input (matrix)
!![1, 2; 3, 4]
Checked by Lean’s kernel: Determinant
!![1, 2; 3, 4].det = -2
The certificate: 1 checked step
Determinant
!![1, 2; 3, 4].det = -2
The smallest case, a matrix:
#cas [det] !![0]
determinant
0- Domain
ℚ^(1×1)- Input (matrix)
!![0]
Checked by Lean’s kernel: Determinant
!![0].det = 0
The certificate: 1 checked step
Determinant
!![0].det = 0
Applications (3)
The determinant as a theorem. Only the three standard axioms are used:
theorem det_three : Matrix.det !![(1 : ℚ), 2, 3; 4, 5, 6; 7, 8, 10] = -3 := by cas #print axioms det_three
det_three depends on the axioms propext, Classical.choice, Quot.sound.
In a proof, cas also evaluates a determinant with variables. The Vandermonde determinant becomes a polynomial identity:
example (a b c : ℝ) : Matrix.det !![1, a, a ^ 2; 1, b, b ^ 2; 1, c, c ^ 2] = (b - a) * (c - a) * (c - b) := by cas
Lean accepts the proof.
A determinant over the integers:
example : Matrix.det !![(-1 : ℤ), -1, -2, 3, 0; -2, 4, 0, -5, 1; -4, 1, -2, -1, 0; -1, 4, -1, 4, 0; -5, 4, 1, -5, -3] = 228 := by cas
Lean accepts the proof.
Properties and Relations (2)
The constant term of the characteristic polynomial is . For the first matrix on this page that is :
#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
A matrix with determinant 0 has no inverse, and inverse proves that its determinant is 0:
#cas [inverse] !![1, 2; 2, 4]
no inverse
the matrix is singular (determinant 0); Mathlib's A⁻¹ is 0- Domain
ℚ^(2×2)- Input (matrix)
!![1, 2; 2, 4]
Checked by Lean’s kernel: The determinant vanishes
!![1, 2; 2, 4].det = 0
The certificate: 1 checked step
The determinant vanishes
!![1, 2; 2, 4].det = 0
Possible Issues (3)
The matrix has to be square:
#cas [det] !![1, 2, 3; 4, 5, 6]
Error
det: the matrix must be square
The entries have to be rational numbers. For a determinant with variables, state it as a goal for cas, as in the Vandermonde example:
#cas [det] !![x, 1; 1, 1]
Error
expected a rational number, such as -3/2, 0.25 or 1/10^15
cas refuses a wrong value. The message shows the goal after the determinant was evaluated:
example : Matrix.det !![(2 : ℤ), 1, 1; 1, 2, 1; 1, 1, 2] = 5 := by cas
Error
cas evaluated the determinant with `norm_det`; the goal became 4 = 5 which is false, so the stated value is not the determinant. cas could not prove this arithmetic relation. The statement may be false, or it may lie outside the supported normalization and arithmetic fragment
The rest of the message
Polynomial equation route:
`grind` failed
case grind
⊢ False
[grind] Goal diagnostics
[facts] Asserted facts
[limits] Thresholds reached
[limit] maximum number of E-matching rounds has been reached, threshold: `(ematch := 0)`
[limit] maximum number of case-splits has been reached, threshold: `(splits := 0)`
Checked identity route:
cas proves checked identities between real numbers; this equality is in
ℤ
Grind fallback:
`grind` failed (`set_option trace.cas.fallback true` shows its diagnostics)Neat Examples (1)
The Hilbert matrix, with entries , has determinant :
#cas [det] !![1, 1/2, 1/3; 1/2, 1/3, 1/4; 1/3, 1/4, 1/5]
determinant
1/2160- Domain
ℚ^(3×3)- Input (matrix)
!![1, 1/2, 1/3; 1/2, 1/3, 1/4; 1/3, 1/4, 1/5]
Checked by Lean’s kernel: Determinant
!![1, 1 / 2, 1 / 3; 1 / 2, 1 / 3, 1 / 4; 1 / 3, 1 / 4, 1 / 5].det = 1 / 2160
The certificate: 1 checked step
Determinant
!![1, 1 / 2, 1 / 3; 1 / 2, 1 / 3, 1 / 4; 1 / 3, 1 / 4, 1 / 5].det = 1 / 2160
