Mode of #cas
inverse
The inverse of a square matrix with rational entries, or a proof that its determinant is 0.
#cas [inverse] AA⁻¹ = B, or proves A.det = 0 when A has no inverse.inverse computes the entries of over . The theorem is about Mathlib’s A⁻¹, and here a Mathlib convention matters. That inverse is total, and for a singular matrix it is the zero matrix. A statement A⁻¹ = 0 would then be true and still tell you nothing about an inverse, which is the kind of statement I don’t want a tool to print. So for a singular matrix the report proves A.det = 0 instead.
Examples (14)#
Basic Examples (2)
The inverse of a matrix:
#cas [inverse] !![1, 2; 3, 4]
inverse
!![-2, 1; 3/2, -1/2]- Domain
ℚ^(2×2)- Input (matrix)
!![1, 2; 3, 4]
Checked by Lean’s kernel: Inverse from the product B * A = 1
!![1, 2; 3, 4]⁻¹ = !![-2, 1; 3 / 2, -(1 / 2)]
The certificate: 1 checked step
Inverse from the product B * A = 1
!![1, 2; 3, 4]⁻¹ = !![-2, 1; 3 / 2, -(1 / 2)]
This matrix has determinant 1, so its inverse has integer entries:
#cas [inverse] !![1, 2, 3; 0, 1, 4; 5, 6, 0]
inverse
!![-24, 18, 5; 20, -15, -4; -5, 4, 1]- Domain
ℚ^(3×3)- Input (matrix)
!![1, 2, 3; 0, 1, 4; 5, 6, 0]
Checked by Lean’s kernel: Inverse from the product B * A = 1
!![1, 2, 3; 0, 1, 4; 5, 6, 0]⁻¹ = !![-24, 18, 5; 20, -15, -4; -5, 4, 1]
The certificate: 1 checked step
Inverse from the product B * A = 1
!![1, 2, 3; 0, 1, 4; 5, 6, 0]⁻¹ = !![-24, 18, 5; 20, -15, -4; -5, 4, 1]
Scope (3)
A matrix:
#cas [inverse] !![5]
inverse
!![1/5]- Domain
ℚ^(1×1)- Input (matrix)
!![5]
Checked by Lean’s kernel: Inverse from the product B * A = 1
!![5]⁻¹ = !![1 / 5]
The certificate: 1 checked step
Inverse from the product B * A = 1
!![5]⁻¹ = !![1 / 5]
Entries can be fractions:
#cas [inverse] !![1/2, 1; 3, 4]
inverse
!![-4, 1; 3, -1/2]- Domain
ℚ^(2×2)- Input (matrix)
!![1/2, 1; 3, 4]
Checked by Lean’s kernel: Inverse from the product B * A = 1
!![1 / 2, 1; 3, 4]⁻¹ = !![-4, 1; 3, -(1 / 2)]
The certificate: 1 checked step
Inverse from the product B * A = 1
!![1 / 2, 1; 3, 4]⁻¹ = !![-4, 1; 3, -(1 / 2)]
A singular matrix has no inverse. The report 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
Applications (2)
The inverse as a theorem. Only the three standard axioms are used:
theorem inverse_two : (!![(1 : ℚ), 2; 3, 4])⁻¹ = !![-2, 1; 3 / 2, -1 / 2] := by cas #print axioms inverse_two
inverse_two depends on the axioms propext, Classical.choice, Quot.sound.
The inverse solves as . Multiplying by the inverse gives the same solution that linearSolve finds:
#cas [dot] (!![-2, 1; 3/2, -1/2], ![5, 6])
product
![-4, 9/2]- Domain
ℚ^(2×2)- Input (product)
!![-2, 1; 3/2, -1/2] . ![5, 6]
Checked by Lean’s kernel: Decided by kernel evaluation
!![-2, 1; 3 / 2, -(1 / 2)].mulVec ![5, 6] = ![-4, 9 / 2]
The certificate: 1 checked step
Decided by kernel evaluation
!![-2, 1; 3 / 2, -(1 / 2)].mulVec ![5, 6] = ![-4, 9 / 2]
#cas [linearSolve] (!![1, 2; 3, 4], ![5, 6])
all solutions
![-4, 9/2]- Domain
ℚ^(2×2)- Input (linear system)
!![1, 2; 3, 4] . x = ![5, 6]
Checked by Lean’s kernel: Solution set
∀ (x : Fin 2 → ℚ), !![1, 2; 3, 4].mulVec x = ![5, 6] ↔ x = ![-4, 9 / 2]
The certificate: 1 checked step
Solution set
∀ (x : Fin 2 → ℚ), !![1, 2; 3, 4].mulVec x = ![5, 6] ↔ x = ![-4, 9 / 2]
Properties and Relations (3)
The product of the inverse and the matrix is the identity:
#cas [dot] (!![-2, 1; 3/2, -1/2], !![1, 2; 3, 4])
product
!![1, 0; 0, 1]- Domain
ℚ^(2×2)- Input (product)
!![-2, 1; 3/2, -1/2] . !![1, 2; 3, 4]
Checked by Lean’s kernel: Decided by kernel evaluation
!![-2, 1; 3 / 2, -(1 / 2)] * !![1, 2; 3, 4] = !![1, 0; 0, 1]
The certificate: 1 checked step
Decided by kernel evaluation
!![-2, 1; 3 / 2, -(1 / 2)] * !![1, 2; 3, 4] = !![1, 0; 0, 1]
The determinant of is . Here :
#cas [det] !![-2, 1; 3/2, -1/2]
determinant
-1/2- Domain
ℚ^(2×2)- Input (matrix)
!![-2, 1; 3/2, -1/2]
Checked by Lean’s kernel: Determinant
!![-2, 1; 3 / 2, -(1 / 2)].det = -(1 / 2)
The certificate: 1 checked step
Determinant
!![-2, 1; 3 / 2, -(1 / 2)].det = -(1 / 2)
Mathlib’s inverse of a singular matrix is the zero matrix, a fact any proof can use:
example : (!![(1 : ℚ), 2; 2, 4])⁻¹ = 0 := Matrix.nonsing_inv_apply_not_isUnit _ (by simp only [norm_det]; norm_num)
Lean accepts the proof.
Possible Issues (3)
The matrix has to be square:
#cas [inverse] !![1, 2, 3; 4, 5, 6]
Error
inverse: the matrix must be square
Every row needs the same number of entries:
#cas [inverse] !![1, 2; 3]
Error
the rows of the matrix have different lengths
cas refuses a wrong inverse. Here one sign is wrong:
example : (!![(1 : ℚ), 2; 3, 4])⁻¹ = !![-2, 1; 3 / 2, 1 / 2] := by cas
Error
cas: the inverse is !![-2, 1; 3/2, -1/2], not !![-2, 1; 3/2, 1/2]
Neat Examples (1)
The Hilbert matrix, with entries , has fractions as entries, and its inverse has integers:
#cas [inverse] !![1, 1/2, 1/3; 1/2, 1/3, 1/4; 1/3, 1/4, 1/5]
inverse
!![9, -36, 30; -36, 192, -180; 30, -180, 180]- 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: Inverse from the product B * A = 1
!![1, 1 / 2, 1 / 3; 1 / 2, 1 / 3, 1 / 4; 1 / 3, 1 / 4, 1 / 5]⁻¹ = !![9, -36, 30; -36, 192, -180; 30, -180, 180]
The certificate: 1 checked step
Inverse from the product B * A = 1
!![1, 1 / 2, 1 / 3; 1 / 2, 1 / 3, 1 / 4; 1 / 3, 1 / 4, 1 / 5]⁻¹ = !![9, -36, 30; -36, 192, -180; 30, -180, 180]
See Also
det · linearSolve · dot · matrixPower · rowReduce
