Exact LDLᵀ certificates for rational matrices, checked by the kernel #
A symmetric rational matrix M is positive definite when it factors as M = L * diagonal d * Lᵀ
with L unit lower triangular and every d i > 0, and positive semidefinite when every
d i ≥ 0 (Matrix.posDef_mul_diagonal_mul_conjTranspose_iff). An external tool, such as SymPy's
LDLdecomposition, finds L and d; this module checks them exactly, by a Boolean function
that the kernel evaluates (decide +kernel), and turns acceptance into Mathlib's
Matrix.PosDef or Matrix.PosSemidef of M cast to ℝ. A singular positive semidefinite M
has a witness with some d i = 0, and the checker never divides.
The checkers are also complete: a matrix given by n rows of n entries has an accepted witness
exactly when it is positive (semi)definite over ℝ. Symmetric elimination without pivoting
(Matrix.exists_LDL_of_posSemidef, Matrix.exists_LDL_of_posDef) stays in ℚ and supplies one.
A rejected witness says nothing about the matrix, but the absence of any accepted witness refutes
⪰ 0 (≻ 0).
Representation #
A matrix is given by its list of rows and read as Mathlib.Tactic.Matrix.ofLists m n rows, the
m × n matrix of the first m rows and their first n entries, padded with zeros; for a list
literal this is the !![…] matrix up to definitional unfolding. The dimensions are explicit, so
the theorems concern Matrix (Fin m) (Fin n) ℚ and their casts to ℝ. The checkers do not rely
on the padding: Cslib.LinearAlgebra.LDLCert.factors rejects a matrix unless it has exactly n
rows of exactly n entries (Cslib.LinearAlgebra.isShape).
Matrices are combined on rows by Mathlib.Tactic.Matrix.ListMatrix.transpose,
Cslib.LinearAlgebra.rowsMul (a product the kernel evaluates; Mathlib's ListMatrix.mul seals
its dot product), Cslib.LinearAlgebra.rowsMap₂ (entrywise sums, differences, negations and
scalings) and Cslib.LinearAlgebra.rowsTrace, each interpreted by an ofLists lemma without any
shape hypothesis. A trace of a product, such as the Gramian energy tr (Bᵀ * W * B) of #8322, is
rowsTrace of rowsMul (Cslib.LinearAlgebra.trace_mul_ofLists). A positive
semidefinite residual N - M ⪰ 0 is checked on rowsMap₂ (· - ·) n n N M, and the Lyapunov
client Cslib.LinearAlgebra.LyapunovCert recomputes -(Aᵀ * P + P * A) from A and P
instead of taking it as input, in integers (Cslib.LinearAlgebra.scaledLyapunovResidual, which
agrees with Cslib.LinearAlgebra.lyapunovResidual by
Cslib.LinearAlgebra.map_ofLists_scaledLyapunovResidual).
A certificate Cslib.LinearAlgebra.LDLCert lists the rows of L and the entries of d. Row i
of lower holds L i 0, …, L i i, so triangularity is the length i + 1 of the row and the unit
diagonal is its last entry 1. A certificate for n × n matrices is rejected unless lower has
exactly n rows of these lengths, each ending in 1, and diag has exactly n entries. The
empty dimension n = 0 has the empty certificate, and the empty matrix is positive definite.
Certificate layout #
A certificate is ordinary Lean source: the rows of M (or A and P), lower and diag as list
literals of rational literals. Write every non-integer entry with its type, as (5/4 : ℚ).
Bare 5/4 entries are elaborated as untyped binop% trees whose type is settled only when the
whole literal is, and elaborating a 48 × 48 matrix of them did not finish in 20 minutes; with
the ascription elaboration is linear in the size of the literal (about 5 s for a 48 × 48
certificate). The ascribed and the bare literal elaborate to the same term, so the kernel cost is
unchanged.
Kernel cost #
The identity M = L * diagonal d * Lᵀ is checked in integer arithmetic. Row i of L is
scaled to integers by the least common multiple sᵢ of its denominators, and d by t
(Cslib.LinearAlgebra.denLcm, Cslib.LinearAlgebra.scaleRow), and entry (i, j) is checked as
M i j * (sᵢ * sⱼ * t) = ∑ₖ aᵢₖ eₖ aⱼₖ for the scaled rows a and e, with the rational
M i j compared through its numerator and denominator. Rational + and * normalize by a gcd
at every step; in the kernel the integer form is the faster one on the benchmarks of #8319,
increasingly so as the coefficients grow. Only the entries on and below the diagonal are checked
(Cslib.LinearAlgebra.LDLCert.scaledLowerCheck), at j + 1 integer products for entry
(i, j), and the rest follow from the symmetry of M, which factors checks by comparing the
rows with their transpose. The Lyapunov residual is computed from A and P scaled by the lcm
of all their denominators, so its two products are integer products, and its symmetry is not
checked but proved from that of the accepted P. All recursion is structural, on lists or on
the dimensions, and the kernel's GMP-accelerated Nat operations do the arithmetic.
Main definitions #
Cslib.LinearAlgebra.rowDot,Cslib.LinearAlgebra.rowsMul,Cslib.LinearAlgebra.rowsMap₂,Cslib.LinearAlgebra.rowsTrace: operations on lists of rows that the kernel evaluates.Cslib.LinearAlgebra.LDLCert: anLDLᵀwitness, with its factorsLDLCert.LandLDLCert.d.Cslib.LinearAlgebra.LDLCert.factors,LDLCert.checkPosDef,LDLCert.checkPosSemidef: the checkers, built on the lower-triangle checkLDLCert.factorsLower.Cslib.LinearAlgebra.scaledLyapunovResidual,Cslib.LinearAlgebra.lyapunovScale: the fraction-free Lyapunov residual.Cslib.LinearAlgebra.LDLCert.factorsLyapunovResidual: the integer check of a witness for the recomputed residual-(Aᵀ * P + P * A), shared by both certificates below.Cslib.LinearAlgebra.LyapunovCert,LyapunovCert.check: witnesses forP ≻ 0and-(Aᵀ * P + P * A) ≻ 0.Cslib.LinearAlgebra.InstabilityCert,InstabilityCert.check: a rateε, a vectorx₀withx₀ᵀ P x₀ < 0and a witness for-((A - ε • 1)ᵀ * P + P * (A - ε • 1)) ⪰ 0, for a symmetric, possibly indefiniteP(Cslib.LinearAlgebra.shiftRows,Cslib.LinearAlgebra.quadForm).
Main results #
Cslib.LinearAlgebra.ofLists_rowsMul,Cslib.LinearAlgebra.ofLists_rowsMap₂,Cslib.LinearAlgebra.trace_ofLists,Cslib.LinearAlgebra.trace_mul_ofLists,Cslib.LinearAlgebra.ofLists_lyapunovResidual: the row operations compute the matrix ones.Cslib.LinearAlgebra.map_ofLists_scaleRow,Cslib.LinearAlgebra.map_ofLists_scaledLyapunovResidual: integer scaling agrees with the rational matrices.Cslib.LinearAlgebra.LDLCert.eq_of_factors: an accepted witness factorsM.Cslib.LinearAlgebra.LDLCert.posDef_of_checkPosDef,Cslib.LinearAlgebra.LDLCert.posSemidef_of_checkPosSemidef: soundness overℝ.Cslib.LinearAlgebra.LDLCert.exists_checkPosDef_iff,Cslib.LinearAlgebra.LDLCert.exists_checkPosSemidef_iff: soundness and completeness, for matrices ofnrows ofnentries.Cslib.LinearAlgebra.LyapunovCert.posDef_of_check: an accepted Lyapunov witness givesP ≻ 0and-(Aᵀ * P + P * A) ≻ 0overℝ.Cslib.LinearAlgebra.LDLCert.posDef_of_factorsLyapunovResidual,Cslib.LinearAlgebra.LDLCert.posSemidef_of_factorsLyapunovResidual: residual soundness for a symmetricP.Cslib.LinearAlgebra.InstabilityCert.sound_of_check: an accepted instability certificate gives its two conditions overℝ.Cslib.LinearAlgebra.map_ratCast_sub_smul_one,Cslib.LinearAlgebra.dotProduct_mulVec_ratCast_neg: the shiftM - ε • 1and a negative quadratic form keep their meaning overℝ.
Kernel-reducible operations on lists of rows #
The sum of the products of corresponding entries of two lists, over the positions where both
have one. Unlike Mathlib's sealed Mathlib.Tactic.Matrix.ListMatrix.dotProduct, the kernel
evaluates it.
rowDot r s is the dot product of the length-n vectors read from r and s, padded with
zeros, whenever r has at most n entries.
The product of A, read as l × m, and B, read as m × n, as l rows of n entries:
Mathlib's Mathlib.Tactic.Matrix.ListMatrix.mul with rowDot in place of its sealed dot
product, so that the kernel evaluates it.
rowsMul computes the matrix product, with no shape hypothesis on A or B.
rowsMap₂ f computes f entrywise, with no shape hypothesis on A or B.
rowsTrace computes the trace, with no shape hypothesis on rows.
The trace of a product computed on rows, such as tr (Bᵀ * W * B): rowsTrace of
rowsMul.
List.zipWith (· * ·), read entrywise with zero padding.
Integer scaling of rational rows #
The least common multiple of the denominators of a list of rationals.
Scaling every row of A by a common multiple s of its denominators scales its matrix.
LDLᵀ certificates #
Whether v = L * diagonal d * Lᵀ holds on and below the diagonal, for v given by rows of
entries x standing for num x / den x, checked in integers: row i of L is scaled by
sᵢ = denLcm (row i) and d by t = denLcm d, and entry (i, j) with j ≤ i is checked as
num x * (sᵢ * sⱼ * t) = (∑ₖ aᵢₖ eₖ aⱼₖ) * den x for the scaled rows a and e. Row i of
L has i + 1 entries, so the zip with the first i + 1 entries of row i of v stops at the
diagonal.
Whether c factors a symmetric n × n matrix given by rows of entries x standing for
num x / den x, on and below the diagonal: rows has n rows of n entries, c.lower has n
rows, row i with i + 1 entries ending in 1, c.diag has n entries, and
scaledLowerCheck accepts. Symmetry is not checked here.
Whether c is an LDLᵀ factorization of the n × n matrix with rows rows: rows is
symmetric, it has n rows of n entries, c.lower has n rows, row i with i + 1 entries
ending in 1, c.diag has n entries, and ofLists n n rows = c.L n * diagonal (c.d n) * (c.L n)ᵀ on and below the diagonal, hence everywhere.
The real form of a factorization by a well-formed witness, with L unit lower
triangular.
A well-formed witness with positive diagonal proves the matrix it factors positive
definite over ℝ.
A well-formed witness with nonnegative diagonal proves the matrix it factors positive
semidefinite over ℝ.
Soundness for ≻ 0. An accepted witness proves the matrix positive definite over
ℝ.
Soundness for ⪰ 0. An accepted witness proves the matrix positive semidefinite over
ℝ, including a singular one, whose witnesses have some d i = 0.
Completeness #
Completeness for ⪰ 0. Some witness is accepted exactly when rows lists n rows of
n entries and the matrix is positive semidefinite over ℝ, singular or not
(Matrix.exists_LDL_of_posSemidef). A rejected witness therefore says nothing about the matrix,
but the absence of any accepted witness for a well-shaped rows refutes ⪰ 0.
Completeness for ≻ 0. Some witness is accepted exactly when rows lists n rows of
n entries and the matrix is positive definite over ℝ (Matrix.exists_LDL_of_posDef).
Lyapunov residuals #
lyapunovResidual computes -(Aᵀ * P + P * A).
The fraction-free Lyapunov residual: -(Âᵀ * P̂ + P̂ * Â) in integers, for  and P̂ the
rows of A and P scaled by the lcm of all their denominators. It is
lyapunovScale A P • -(Aᵀ * P + P * A) (map_ofLists_scaledLyapunovResidual).
The fraction-free residual agrees with lyapunovResidual.
Whether c factors the recomputed residual -(Aᵀ * P + P * A) of the n × n matrices with
rows A and P, on and below the diagonal and in integers (scaledLyapunovResidual). The
residual's symmetry is not checked: it follows from that of P
(LDLCert.eq_of_factorsLyapunovResidual).
For a symmetric P, an accepted residual check factors -(Aᵀ * P + P * A) over ℚ, and
c is well formed.
Residual soundness for ≻ 0. For a symmetric P, an accepted residual check with
positive diagonal proves -(Aᵀ * P + P * A) ≻ 0 over ℝ.
Residual soundness for ⪰ 0. For a symmetric P, an accepted residual check with
nonnegative diagonal proves -(Aᵀ * P + P * A) ⪰ 0 over ℝ.
Soundness. An accepted Lyapunov witness proves P ≻ 0 and -(Aᵀ * P + P * A) ≻ 0 for
the real matrices A and P.
Instability certificates #
Whether c certifies, for the n × n matrices with rows A and P, that P is symmetric,
c.x₀ ⬝ᵥ P *ᵥ c.x₀ < 0 and -((A - ε • 1)ᵀ * P + P * (A - ε • 1)) ⪰ 0 for
ε = c.rate. The residual is recomputed from shiftRows n ε A and P, in integers.
Soundness. An accepted instability certificate proves, over ℝ, that
x₀ ⬝ᵥ P *ᵥ x₀ < 0 and -((A - ε • 1)ᵀ * P + P * (A - ε • 1)) ⪰ 0 for ε = c.rate.