Mode of #cas
nullSpace
A basis of the null space of a matrix with rational entries, with a theorem that it spans every solution.
#cas [nullSpace] AnullSpace gives a basis for the solutions of , and applied to it gives an eigenspace. The theorem says three things about the printed vectors , over : each one solves , they are linearly independent, and every solution is a combination of them. You could check the first by multiplying. The other two are what make the list a basis and not only a list of solutions, and they are the ones I want a proof of.
Examples (12)#
Basic Examples (2)
The two rows say the same thing, , so the solutions form a plane:
#cas [nullSpace] !![1, 2, 3; 2, 4, 6]
basis of the null space, dimension 2
[![-2, 1, 0], ![-3, 0, 1]]- Domain
ℚ^(2×3)- Input (matrix)
!![1, 2, 3; 2, 4, 6]
Checked by Lean’s kernel: Basis of the null space
(∀ (i : Fin (Nat.succ 1)), !![1, 2, 3; 2, 4, 6].mulVec (![![-2, 1, 0], ![-3, 0, 1]] i) = 0) ∧ LinearIndependent ℚ ![![-2, 1, 0], ![-3, 0, 1]] ∧ ∀ (x : Fin 3 → ℚ), !![1, 2, 3; 2, 4, 6].mulVec x = 0 → ∃ c, x = ∑ i, c i • ![![-2, 1, 0], ![-3, 0, 1]] i
The certificate: 1 checked step
Basis of the null space
(∀ (i : Fin (Nat.succ 1)), !![1, 2, 3; 2, 4, 6].mulVec (![![-2, 1, 0], ![-3, 0, 1]] i) = 0) ∧ LinearIndependent ℚ ![![-2, 1, 0], ![-3, 0, 1]] ∧ ∀ (x : Fin 3 → ℚ), !![1, 2, 3; 2, 4, 6].mulVec x = 0 → ∃ c, x = ∑ i, c i • ![![-2, 1, 0], ![-3, 0, 1]] i
Only the zero vector solves for an invertible :
#cas [nullSpace] !![1, 2; 3, 4]
basis of the null space, dimension 0
[] (only the zero vector)- Domain
ℚ^(2×2)- Input (matrix)
!![1, 2; 3, 4]
Checked by Lean’s kernel: Basis of the null space
∀ (x : Fin 2 → ℚ), !![1, 2; 3, 4].mulVec x = 0 → x = 0
The certificate: 1 checked step
Basis of the null space
∀ (x : Fin 2 → ℚ), !![1, 2; 3, 4].mulVec x = 0 → x = 0
Scope (3)
A single nonzero column:
#cas [nullSpace] !![1; 2; 3]
basis of the null space, dimension 0
[] (only the zero vector)- Domain
ℚ^(3×1)- Input (matrix)
!![1; 2; 3]
Checked by Lean’s kernel: Basis of the null space
∀ (x : Fin 1 → ℚ), !![1; 2; 3].mulVec x = 0 → x = 0
The certificate: 1 checked step
Basis of the null space
∀ (x : Fin 1 → ℚ), !![1; 2; 3].mulVec x = 0 → x = 0
A singular square matrix has a null space of dimension at least 1:
#cas [nullSpace] !![1, 2, 3; 4, 5, 6; 7, 8, 9]
basis of the null space, dimension 1
[![1, -2, 1]]- Domain
ℚ^(3×3)- Input (matrix)
!![1, 2, 3; 4, 5, 6; 7, 8, 9]
Checked by Lean’s kernel: Basis of the null space
(∀ (i : Fin (Nat.succ 0)), !![1, 2, 3; 4, 5, 6; 7, 8, 9].mulVec (![![1, -2, 1]] i) = 0) ∧ LinearIndependent ℚ ![![1, -2, 1]] ∧ ∀ (x : Fin 3 → ℚ), !![1, 2, 3; 4, 5, 6; 7, 8, 9].mulVec x = 0 → ∃ c, x = ∑ i, c i • ![![1, -2, 1]] i
The certificate: 1 checked step
Basis of the null space
(∀ (i : Fin (Nat.succ 0)), !![1, 2, 3; 4, 5, 6; 7, 8, 9].mulVec (![![1, -2, 1]] i) = 0) ∧ LinearIndependent ℚ ![![1, -2, 1]] ∧ ∀ (x : Fin 3 → ℚ), !![1, 2, 3; 4, 5, 6; 7, 8, 9].mulVec x = 0 → ∃ c, x = ∑ i, c i • ![![1, -2, 1]] i
A row with fractions, written as a list of rows:
#cas [nullSpace] [[1/2, 1/3, 1/6]]
basis of the null space, dimension 2
[![-2/3, 1, 0], ![-1/3, 0, 1]]- Domain
ℚ^(1×3)- Input (matrix)
!![1/2, 1/3, 1/6]
Checked by Lean’s kernel: Basis of the null space
(∀ (i : Fin (Nat.succ 1)), !![1 / 2, 1 / 3, 1 / 6].mulVec (![![-(2 / 3), 1, 0], ![-(1 / 3), 0, 1]] i) = 0) ∧ LinearIndependent ℚ ![![-(2 / 3), 1, 0], ![-(1 / 3), 0, 1]] ∧ ∀ (x : Fin 3 → ℚ), !![1 / 2, 1 / 3, 1 / 6].mulVec x = 0 → ∃ c, x = ∑ i, c i • ![![-(2 / 3), 1, 0], ![-(1 / 3), 0, 1]] i
The certificate: 1 checked step
Basis of the null space
(∀ (i : Fin (Nat.succ 1)), !![1 / 2, 1 / 3, 1 / 6].mulVec (![![-(2 / 3), 1, 0], ![-(1 / 3), 0, 1]] i) = 0) ∧ LinearIndependent ℚ ![![-(2 / 3), 1, 0], ![-(1 / 3), 0, 1]] ∧ ∀ (x : Fin 3 → ℚ), !![1 / 2, 1 / 3, 1 / 6].mulVec x = 0 → ∃ c, x = ∑ i, c i • ![![-(2 / 3), 1, 0], ![-(1 / 3), 0, 1]] i
Applications (3)
A vector of the null space as a theorem. Only the three standard axioms are used:
theorem nullSpace_vector : !![(1 : ℚ), 2, 3; 2, 4, 6].mulVec ![-2, 1, 0] = 0 := by cas #print axioms nullSpace_vector
nullSpace_vector depends on the axioms propext, Classical.choice, Quot.sound.
The eigenvectors of for the eigenvalue 2 form the null space of . eigenvectors gives the same vector:
#cas [nullSpace] !![2, 1; 2, 1]
basis of the null space, dimension 1
[![-1/2, 1]]- Domain
ℚ^(2×2)- Input (matrix)
!![2, 1; 2, 1]
Checked by Lean’s kernel: Basis of the null space
(∀ (i : Fin (Nat.succ 0)), !![2, 1; 2, 1].mulVec (![![-(1 / 2), 1]] i) = 0) ∧ LinearIndependent ℚ ![![-(1 / 2), 1]] ∧ ∀ (x : Fin 2 → ℚ), !![2, 1; 2, 1].mulVec x = 0 → ∃ c, x = ∑ i, c i • ![![-(1 / 2), 1]] i
The certificate: 1 checked step
Basis of the null space
(∀ (i : Fin (Nat.succ 0)), !![2, 1; 2, 1].mulVec (![![-(1 / 2), 1]] i) = 0) ∧ LinearIndependent ℚ ![![-(1 / 2), 1]] ∧ ∀ (x : Fin 2 → ℚ), !![2, 1; 2, 1].mulVec x = 0 → ∃ c, x = ∑ i, c i • ![![-(1 / 2), 1]] i
#cas [eigenvectors] !![4, 1; 2, 3]
eigenvalue ↦ basis of its eigenspace
[2 ↦ [![-1/2, 1]], 5 ↦ [![1, 1]]]- Domain
ℚ^(2×2)- Input (matrix)
!![4, 1; 2, 3]
Checked by Lean’s kernel: Characteristic polynomial factored over ℚ, eigenspaces
((∀ (i : Fin (Nat.succ 0)), (!![4, 1; 2, 3] - 2 • 1).mulVec (![![-(1 / 2), 1]] i) = 0) ∧ LinearIndependent ℚ ![![-(1 / 2), 1]] ∧ ∀ (x : Fin 2 → ℚ), (!![4, 1; 2, 3] - 2 • 1).mulVec x = 0 → ∃ c, x = ∑ i, c i • ![![-(1 / 2), 1]] i) ∧ ((∀ (i : Fin (Nat.succ 0)), (!![4, 1; 2, 3] - 5 • 1).mulVec (![![1, 1]] i) = 0) ∧ LinearIndependent ℚ ![![1, 1]] ∧ ∀ (x : Fin 2 → ℚ), (!![4, 1; 2, 3] - 5 • 1).mulVec x = 0 → ∃ c, x = ∑ i, c i • ![![1, 1]] i) ∧ !![4, 1; 2, 3].charpoly = (Polynomial.X - 2) * (Polynomial.X - 5)
The certificate: 1 checked step
Characteristic polynomial factored over ℚ, eigenspaces
((∀ (i : Fin (Nat.succ 0)), (!![4, 1; 2, 3] - 2 • 1).mulVec (![![-(1 / 2), 1]] i) = 0) ∧ LinearIndependent ℚ ![![-(1 / 2), 1]] ∧ ∀ (x : Fin 2 → ℚ), (!![4, 1; 2, 3] - 2 • 1).mulVec x = 0 → ∃ c, x = ∑ i, c i • ![![-(1 / 2), 1]] i) ∧ ((∀ (i : Fin (Nat.succ 0)), (!![4, 1; 2, 3] - 5 • 1).mulVec (![![1, 1]] i) = 0) ∧ LinearIndependent ℚ ![![1, 1]] ∧ ∀ (x : Fin 2 → ℚ), (!![4, 1; 2, 3] - 5 • 1).mulVec x = 0 → ∃ c, x = ∑ i, c i • ![![1, 1]] i) ∧ !![4, 1; 2, 3].charpoly = (Polynomial.X - 2) * (Polynomial.X - 5)
To balance , I count each element on both sides: carbon gives , hydrogen and oxygen . Twice the null vector is the balanced equation :
#cas [nullSpace] !![1, 0, -1, 0; 4, 0, 0, -2; 0, 2, -2, -1]
basis of the null space, dimension 1
[![1/2, 1, 1/2, 1]]- Domain
ℚ^(3×4)- Input (matrix)
!![1, 0, -1, 0; 4, 0, 0, -2; 0, 2, -2, -1]
Checked by Lean’s kernel: Basis of the null space
(∀ (i : Fin (Nat.succ 0)), !![1, 0, -1, 0; 4, 0, 0, -2; 0, 2, -2, -1].mulVec (![![1 / 2, 1, 1 / 2, 1]] i) = 0) ∧ LinearIndependent ℚ ![![1 / 2, 1, 1 / 2, 1]] ∧ ∀ (x : Fin 4 → ℚ), !![1, 0, -1, 0; 4, 0, 0, -2; 0, 2, -2, -1].mulVec x = 0 → ∃ c, x = ∑ i, c i • ![![1 / 2, 1, 1 / 2, 1]] i
The certificate: 1 checked step
Basis of the null space
(∀ (i : Fin (Nat.succ 0)), !![1, 0, -1, 0; 4, 0, 0, -2; 0, 2, -2, -1].mulVec (![![1 / 2, 1, 1 / 2, 1]] i) = 0) ∧ LinearIndependent ℚ ![![1 / 2, 1, 1 / 2, 1]] ∧ ∀ (x : Fin 4 → ℚ), !![1, 0, -1, 0; 4, 0, 0, -2; 0, 2, -2, -1].mulVec x = 0 → ∃ c, x = ∑ i, c i • ![![1 / 2, 1, 1 / 2, 1]] i
Properties and Relations (2)
The dimension is the number of columns minus the rank. For the singular matrix in Scope it is :
#cas [matrixRank] !![1, 2, 3; 4, 5, 6; 7, 8, 9]
rank
2- Domain
ℚ^(3×3)- Input (matrix)
!![1, 2, 3; 4, 5, 6; 7, 8, 9]
Checked by Lean’s kernel: Rank from a factorization and a nonsingular minor
!![1, 2, 3; 4, 5, 6; 7, 8, 9].rank = 2
The certificate: 1 checked step
Rank from a factorization and a nonsingular minor
!![1, 2, 3; 4, 5, 6; 7, 8, 9].rank = 2
Every solution of is one solution plus a vector of the null space. linearSolve prints the same basis:
#cas [linearSolve] (!![1, 2, 3; 2, 4, 6], ![1, 2])
all solutions
![1, 0, 0] + span of [![-2, 1, 0], ![-3, 0, 1]]- Domain
ℚ^(2×3)- Input (linear system)
!![1, 2, 3; 2, 4, 6] . x = ![1, 2]
Checked by Lean’s kernel: Solution set
!![1, 2, 3; 2, 4, 6].mulVec ![1, 0, 0] = ![1, 2] ∧ LinearIndependent ℚ ![![-2, 1, 0], ![-3, 0, 1]] ∧ ∀ (x : Fin 3 → ℚ), !![1, 2, 3; 2, 4, 6].mulVec x = ![1, 2] ↔ ∃ c, x = ![1, 0, 0] + ∑ i, c i • ![![-2, 1, 0], ![-3, 0, 1]] i
The certificate: 1 checked step
Solution set
!![1, 2, 3; 2, 4, 6].mulVec ![1, 0, 0] = ![1, 2] ∧ LinearIndependent ℚ ![![-2, 1, 0], ![-3, 0, 1]] ∧ ∀ (x : Fin 3 → ℚ), !![1, 2, 3; 2, 4, 6].mulVec x = ![1, 2] ↔ ∃ c, x = ![1, 0, 0] + ∑ i, c i • ![![-2, 1, 0], ![-3, 0, 1]] i
Possible Issues (1)
The mode takes the matrix alone. For a right side, use linearSolve:
#cas [nullSpace] (!![1, 2; 3, 4], ![0, 0])
Error
expected a matrix `!![a, b; c, d]` or `[[a, b], [c, d]]`
Neat Examples (1)
The rows hold the values of , and at . The null space is spanned by the third difference , so for every polynomial of degree at most 2:
#cas [nullSpace] !![1, 1, 1, 1; 1, 2, 3, 4; 1, 4, 9, 16]
basis of the null space, dimension 1
[![-1, 3, -3, 1]]- Domain
ℚ^(3×4)- Input (matrix)
!![1, 1, 1, 1; 1, 2, 3, 4; 1, 4, 9, 16]
Checked by Lean’s kernel: Basis of the null space
(∀ (i : Fin (Nat.succ 0)), !![1, 1, 1, 1; 1, 2, 3, 4; 1, 4, 9, 16].mulVec (![![-1, 3, -3, 1]] i) = 0) ∧ LinearIndependent ℚ ![![-1, 3, -3, 1]] ∧ ∀ (x : Fin 4 → ℚ), !![1, 1, 1, 1; 1, 2, 3, 4; 1, 4, 9, 16].mulVec x = 0 → ∃ c, x = ∑ i, c i • ![![-1, 3, -3, 1]] i
The certificate: 1 checked step
Basis of the null space
(∀ (i : Fin (Nat.succ 0)), !![1, 1, 1, 1; 1, 2, 3, 4; 1, 4, 9, 16].mulVec (![![-1, 3, -3, 1]] i) = 0) ∧ LinearIndependent ℚ ![![-1, 3, -3, 1]] ∧ ∀ (x : Fin 4 → ℚ), !![1, 1, 1, 1; 1, 2, 3, 4; 1, 4, 9, 16].mulVec x = 0 → ∃ c, x = ∑ i, c i • ![![-1, 3, -3, 1]] i
