Mode of #cas
positiveDefinite
Whether a square matrix with rational entries is positive definite, with a theorem about Mathlib’s Matrix.PosDef either way.
#cas [positiveDefinite] AFor a symmetric matrix, positive definiteness means for every nonzero . It is the condition behind the second-derivative test and many quadratic-form estimates. positiveDefinite proves its answer either way, and the two proofs are of quite different kinds. True comes with an exact factorization over with positive pivots. False comes with a rational vector such that , which you can check by hand, or with an entry that breaks the symmetry.
Examples (14)#
Basic Examples (2)
A symmetric matrix with the pivots 2 and :
#cas [positiveDefinite] !![2, 1; 1, 2]
Boolean
True- Domain
2 × 2 real matrix- Input (matrix)
!![2, 1; 1, 2]
Checked by Lean’s kernel: The matrix is positive definite
!![2, 1; 1, 2].PosDef
The certificate: 1 checked step
The matrix is positive definite
!![2, 1; 1, 2].PosDef
The computation
Certificate
A = L D Lᵀ over ℚ with pivots D = [2, 3/2], all positive
For this one the vector gives :
#cas [positiveDefinite] !![1, 2; 2, 1]
Boolean
False (xᵀAx ≤ 0 for x = [-2, 1])- Domain
2 × 2 real matrix- Input (matrix)
!![1, 2; 2, 1]
Checked by Lean’s kernel: A vector with a nonpositive quadratic form
¬!![1, 2; 2, 1].PosDef
The certificate: 1 checked step
A vector with a nonpositive quadratic form
¬!![1, 2; 2, 1].PosDef
Scope (4)
Mathlib’s PosDef includes symmetry, so a matrix that is not symmetric is never positive definite:
#cas [positiveDefinite] !![1, 2; 3, 4]
Boolean
False (not symmetric)- Domain
2 × 2 real matrix- Input (matrix)
!![1, 2; 3, 4]
Checked by Lean’s kernel: The matrix is not Hermitian
¬!![1, 2; 3, 4].PosDef
The certificate: 1 checked step
The matrix is not Hermitian
¬!![1, 2; 3, 4].PosDef
The matrix has the pivots 1 and :
#cas [positiveDefinite] !![1, 1; 1, 1000000000001/1000000000000]
Boolean
True- Domain
2 × 2 real matrix- Input (matrix)
!![1, 1; 1, 1000000000001/1000000000000]
Checked by Lean’s kernel: The matrix is positive definite
!![1, 1; 1, 1000000000001 / 1000000000000].PosDef
The certificate: 1 checked step
The matrix is positive definite
!![1, 1; 1, 1000000000001 / 1000000000000].PosDef
The computation
Certificate
A = L D Lᵀ over ℚ with pivots D = [1, 1/1000000000000], all positive
Tiny entries are fine:
#cas [positiveDefinite] !![1/10^15, 0; 0, 1/10^15]
Boolean
True- Domain
2 × 2 real matrix- Input (matrix)
!![1/10^15, 0; 0, 1/10^15]
Checked by Lean’s kernel: The matrix is positive definite
!![1 / 1000000000000000, 0; 0, 1 / 1000000000000000].PosDef
The certificate: 1 checked step
The matrix is positive definite
!![1 / 1000000000000000, 0; 0, 1 / 1000000000000000].PosDef
The computation
Certificate
A = L D Lᵀ over ℚ with pivots D = [1/1000000000000000, 1/1000000000000000], all positive
A list of rows with fractions:
#cas [positiveDefinite] [[1, 1/2], [1/2, 1/3]]
Boolean
True- Domain
2 × 2 real matrix- Input (matrix)
[[1, 1/2], [1/2, 1/3]]
Checked by Lean’s kernel: The matrix is positive definite
!![1, 1 / 2; 1 / 2, 1 / 3].PosDef
The certificate: 1 checked step
The matrix is positive definite
!![1, 1 / 2; 1 / 2, 1 / 3].PosDef
The computation
Certificate
A = L D Lᵀ over ℚ with pivots D = [1, 1/12], all positive
Applications (2)
A proof can take the printed theorem as a hypothesis and use Mathlib’s consequences of positive definiteness, here Matrix.PosDef.det_pos:
theorem posDef_det_pos (h : (!![2, 1; 1, 2] : Matrix (Fin 2) (Fin 2) ℝ).PosDef) : 0 < (!![2, 1; 1, 2] : Matrix (Fin 2) (Fin 2) ℝ).det := h.det_pos #print axioms posDef_det_pos
posDef_det_pos depends on the axioms propext, Classical.choice, Quot.sound.
The quadratic form has this Hessian. It is positive definite, so is positive away from 0 and has a strict minimum there:
#cas [positiveDefinite] !![4, 1, 0; 1, 3, 1; 0, 1, 2]
Boolean
True- Domain
3 × 3 real matrix- Input (matrix)
!![4, 1, 0; 1, 3, 1; 0, 1, 2]
Checked by Lean’s kernel: The matrix is positive definite
!![4, 1, 0; 1, 3, 1; 0, 1, 2].PosDef
The certificate: 1 checked step
The matrix is positive definite
!![4, 1, 0; 1, 3, 1; 0, 1, 2].PosDef
The computation
Certificate
A = L D Lᵀ over ℚ with pivots D = [4, 11/4, 18/11], all positive
Properties and Relations (2)
A symmetric matrix is positive definite exactly when its smallest eigenvalue is positive. For the Hessian above it is , and eigenvalueBounds proves the lower bound :
#cas [eigenvalueBounds] !![4, 1, 0; 1, 3, 1; 0, 1, 2]
Rayleigh bounds
1.267949 ≤ λ_min, λ_max ≤ 4.732051- Domain
3 × 3 symmetric real matrix- Input (matrix)
!![4, 1, 0; 1, 3, 1; 0, 1, 2]
Checked by Lean’s kernel: Rayleigh bounds, sharp to 10^-6
(∀ (x : Fin 3 → ℝ), 1.267949 * ∑ i, x i ^ 2 ≤ ∑ i, ∑ j, !![4, 1, 0; 1, 3, 1; 0, 1, 2] i j * x i * x j ∧ ∑ i, ∑ j, !![4, 1, 0; 1, 3, 1; 0, 1, 2] i j * x i * x j ≤ 4.732051 * ∑ i, x i ^ 2) ∧ (∃ x, ∑ i, ∑ j, !![4, 1, 0; 1, 3, 1; 0, 1, 2] i j * x i * x j < 1.267950 * ∑ i, x i ^ 2) ∧ ∃ x, 4.732050 * ∑ i, x i ^ 2 < ∑ i, ∑ j, !![4, 1, 0; 1, 3, 1; 0, 1, 2] i j * x i * x j
The certificate: 1 checked step
Rayleigh bounds, sharp to 10^-6
(∀ (x : Fin 3 → ℝ), 1.267949 * ∑ i, x i ^ 2 ≤ ∑ i, ∑ j, !![4, 1, 0; 1, 3, 1; 0, 1, 2] i j * x i * x j ∧ ∑ i, ∑ j, !![4, 1, 0; 1, 3, 1; 0, 1, 2] i j * x i * x j ≤ 4.732051 * ∑ i, x i ^ 2) ∧ (∃ x, ∑ i, ∑ j, !![4, 1, 0; 1, 3, 1; 0, 1, 2] i j * x i * x j < 1.267950 * ∑ i, x i ^ 2) ∧ ∃ x, 4.732050 * ∑ i, x i ^ 2 < ∑ i, ∑ j, !![4, 1, 0; 1, 3, 1; 0, 1, 2] i j * x i * x j
The computation
Certificate
A - cI = L D Lᵀ and μI - A = L' D' L'ᵀ over ℚ, with nonnegative pivots x, y over ℚ with xᵀAx < (c + 10^-6) |x|² and yᵀAy > (μ - 10^-6) |y|²
The pivots are the ratios of the leading principal minors, so they are all positive exactly when the minors are (Sylvester’s criterion). For the Hessian the pivots are , and , and the minors are 4, 11 and the determinant 18:
#cas [det] !![4, 1, 0; 1, 3, 1; 0, 1, 2]
determinant
18- Domain
ℚ^(3×3)- Input (matrix)
!![4, 1, 0; 1, 3, 1; 0, 1, 2]
Checked by Lean’s kernel: Determinant
!![4, 1, 0; 1, 3, 1; 0, 1, 2].det = 18
The certificate: 1 checked step
Determinant
!![4, 1, 0; 1, 3, 1; 0, 1, 2].det = 18
Possible Issues (3)
A positive semidefinite matrix that is singular is not positive definite. The vector has :
#cas [positiveDefinite] !![1, 1; 1, 1]
Boolean
False (xᵀAx ≤ 0 for x = [-1, 1])- Domain
2 × 2 real matrix- Input (matrix)
!![1, 1; 1, 1]
Checked by Lean’s kernel: A vector with a nonpositive quadratic form
¬!![1, 1; 1, 1].PosDef
The certificate: 1 checked step
A vector with a nonpositive quadratic form
¬!![1, 1; 1, 1].PosDef
The quadratic form of the first matrix is , positive for every , but the matrix is not symmetric, so it is not PosDef. Its symmetric part has the same quadratic form, and here it is the identity:
#cas [positiveDefinite] !![1, 1; -1, 1]
Boolean
False (not symmetric)- Domain
2 × 2 real matrix- Input (matrix)
!![1, 1; -1, 1]
Checked by Lean’s kernel: The matrix is not Hermitian
¬!![1, 1; -1, 1].PosDef
The certificate: 1 checked step
The matrix is not Hermitian
¬!![1, 1; -1, 1].PosDef
#cas [positiveDefinite] !![1, 0; 0, 1]
Boolean
True- Domain
2 × 2 real matrix- Input (matrix)
!![1, 0; 0, 1]
Checked by Lean’s kernel: The matrix is positive definite
!![1, 0; 0, 1].PosDef
The certificate: 1 checked step
The matrix is positive definite
!![1, 0; 0, 1].PosDef
The computation
Certificate
A = L D Lᵀ over ℚ with pivots D = [1, 1], all positive
The matrix has to be square:
#cas [positiveDefinite] !![1, 2, 3; 4, 5, 6]
Error
positiveDefinite: the matrix must be square
Neat Examples (1)
The Hilbert matrix is the Gram matrix of on , so it is positive definite, and it is close to singular. Its last pivot is about , and the exact elimination proves it positive all the same:
#cas [positiveDefinite] !![1, 1/2, 1/3, 1/4, 1/5, 1/6, 1/7, 1/8, 1/9, 1/10; 1/2, 1/3, 1/4, 1/5, 1/6, 1/7, 1/8, 1/9, 1/10, 1/11; 1/3, 1/4, 1/5, 1/6, 1/7, 1/8, 1/9, 1/10, 1/11, 1/12; 1/4, 1/5, 1/6, 1/7, 1/8, 1/9, 1/10, 1/11, 1/12, 1/13; 1/5, 1/6, 1/7, 1/8, 1/9, 1/10, 1/11, 1/12, 1/13, 1/14; 1/6, 1/7, 1/8, 1/9, 1/10, 1/11, 1/12, 1/13, 1/14, 1/15; 1/7, 1/8, 1/9, 1/10, 1/11, 1/12, 1/13, 1/14, 1/15, 1/16; 1/8, 1/9, 1/10, 1/11, 1/12, 1/13, 1/14, 1/15, 1/16, 1/17; 1/9, 1/10, 1/11, 1/12, 1/13, 1/14, 1/15, 1/16, 1/17, 1/18; 1/10, 1/11, 1/12, 1/13, 1/14, 1/15, 1/16, 1/17, 1/18, 1/19]
Boolean
True- Domain
10 × 10 real matrix- Input (matrix)
!![1, 1/2, 1/3, 1/4, 1/5, 1/6, 1/7, 1/8, 1/9, 1/10; 1/2, 1/3, 1/4, 1/5, 1/6, 1/7, 1/8, 1/9, 1/10, 1/11; 1/3, 1/4, 1/5, 1/6, 1/7, 1/8, 1/9, 1/10, 1/11, 1/12; 1/4, 1/5, 1/6, 1/7, 1/8, 1/9, 1/10, 1/11, 1/12, 1/13; 1/5, 1/6, 1/7, 1/8, 1/9, 1/10, 1/11, 1/12, 1/13, 1/14; 1/6, 1/7, 1/8, 1/9, 1/10, 1/11, 1/12, 1/13, 1/14, 1/15; 1/7, 1/8, 1/9, 1/10, 1/11, 1/12, 1/13, 1/14, 1/15, 1/16; 1/8, 1/9, 1/10, 1/11, 1/12, 1/13, 1/14, 1/15, 1/16, 1/17; 1/9, 1/10, 1/11, 1/12, 1/13, 1/14, 1/15, 1/16, 1/17, 1/18; 1/10, 1/11, 1/12, 1/13, 1/14, 1/15, 1/16, 1/17, 1/18, 1/19]
Checked by Lean’s kernel: The matrix is positive definite
!![1, 1 / 2, 1 / 3, 1 / 4, 1 / 5, 1 / 6, 1 / 7, 1 / 8, 1 / 9, 1 / 10; 1 / 2, 1 / 3, 1 / 4, 1 / 5, 1 / 6, 1 / 7, 1 / 8, 1 / 9, 1 / 10, 1 / 11; 1 / 3, 1 / 4, 1 / 5, 1 / 6, 1 / 7, 1 / 8, 1 / 9, 1 / 10, 1 / 11, 1 / 12; 1 / 4, 1 / 5, 1 / 6, 1 / 7, 1 / 8, 1 / 9, 1 / 10, 1 / 11, 1 / 12, 1 / 13; 1 / 5, 1 / 6, 1 / 7, 1 / 8, 1 / 9, 1 / 10, 1 / 11, 1 / 12, 1 / 13, 1 / 14; 1 / 6, 1 / 7, 1 / 8, 1 / 9, 1 / 10, 1 / 11, 1 / 12, 1 / 13, 1 / 14, 1 / 15; 1 / 7, 1 / 8, 1 / 9, 1 / 10, 1 / 11, 1 / 12, 1 / 13, 1 / 14, 1 / 15, 1 / 16; 1 / 8, 1 / 9, 1 / 10, 1 / 11, 1 / 12, 1 / 13, 1 / 14, 1 / 15, 1 / 16, 1 / 17; 1 / 9, 1 / 10, 1 / 11, 1 / 12, 1 / 13, 1 / 14, 1 / 15, 1 / 16, 1 / 17, 1 / 18; 1 / 10, 1 / 11, 1 / 12, 1 / 13, 1 / 14, 1 / 15, 1 / 16, 1 / 17, 1 / 18, 1 / 19].PosDef
The certificate: 1 checked step
The matrix is positive definite
!![1, 1 / 2, 1 / 3, 1 / 4, 1 / 5, 1 / 6, 1 / 7, 1 / 8, 1 / 9, 1 / 10; 1 / 2, 1 / 3, 1 / 4, 1 / 5, 1 / 6, 1 / 7, 1 / 8, 1 / 9, 1 / 10, 1 / 11; 1 / 3, 1 / 4, 1 / 5, 1 / 6, 1 / 7, 1 / 8, 1 / 9, 1 / 10, 1 / 11, 1 / 12; 1 / 4, 1 / 5, 1 / 6, 1 / 7, 1 / 8, 1 / 9, 1 / 10, 1 / 11, 1 / 12, 1 / 13; 1 / 5, 1 / 6, 1 / 7, 1 / 8, 1 / 9, 1 / 10, 1 / 11, 1 / 12, 1 / 13, 1 / 14; 1 / 6, 1 / 7, 1 / 8, 1 / 9, 1 / 10, 1 / 11, 1 / 12, 1 / 13, 1 / 14, 1 / 15; 1 / 7, 1 / 8, 1 / 9, 1 / 10, 1 / 11, 1 / 12, 1 / 13, 1 / 14, 1 / 15, 1 / 16; 1 / 8, 1 / 9, 1 / 10, 1 / 11, 1 / 12, 1 / 13, 1 / 14, 1 / 15, 1 / 16, 1 / 17; 1 / 9, 1 / 10, 1 / 11, 1 / 12, 1 / 13, 1 / 14, 1 / 15, 1 / 16, 1 / 17, 1 / 18; 1 / 10, 1 / 11, 1 / 12, 1 / 13, 1 / 14, 1 / 15, 1 / 16, 1 / 17, 1 / 18, 1 / 19].PosDef
The computation
Certificate
A = L D Lᵀ over ℚ with pivots D = [1, 1/12, 1/180, 1/2800, 1/44100, 1/698544, 1/11099088, 1/176679360, 1/2815827300, 1/44914183600], all positive
