Sparse and envelope LDLᵀ certificates, checked by the kernel #
The dense checker Cslib.LinearAlgebra.LDLCert costs about n³ / 6 integer products for an
n × n matrix, whatever its sparsity, and the dense Lyapunov residual about 2 n³. The state
matrix of a circuit has a few entries per row, and a Lyapunov matrix P can often be chosen
banded. This module checks such certificates at a cost governed by the envelope of the factor
instead of by n. Its soundness theorems are about the same real matrices as those of the dense
checker (Matrix.PosDef and Matrix.PosSemidef of a rational matrix cast to ℝ), so the
stability and impulse-response theorems built on them apply unchanged.
Sparse rows #
A sparse matrix is a list of rows, each a list of (column, value) pairs, read by
Cslib.LinearAlgebra.ofSparse m n rows: entry (i, j) is the sum of the values that row i
stores at column j (Cslib.LinearAlgebra.sparseGet), and a missing row is zero. The reading
does not depend on the order of the pairs or on repeated columns, so the soundness proofs assume
nothing about them; the checkers nevertheless reject an input matrix whose rows do not have
strictly increasing columns below n, or that does not have n rows
(Cslib.LinearAlgebra.isSparseShape), as the dense checkers reject a ragged matrix.
Cslib.LinearAlgebra.ofSparse_toSparse reads the sparse form of dense rows as ofLists.
Rows are reached through a zipper (Cslib.LinearAlgebra.zget): while row i is processed, the
rows before it are kept reversed and the rows from it on in order, so that reaching row k
costs |i - k| steps instead of k. The sparse product Cslib.LinearAlgebra.sparseMul and
the transpose check Cslib.LinearAlgebra.isTransposeOf thus cost about the number of stored
entries times their distance from the diagonal. A symmetry check needs one of the two passes of
isTransposeOf A A (Cslib.LinearAlgebra.isSymm). The module
CslibFrontier.Algorithms.LinearAlgebra.SparseLDLRowRanges splits these checks by ranges of rows,
so that the kernel can check a large certificate in several declarations.
Envelope certificates with a remainder #
A certificate Cslib.LinearAlgebra.EnvLDLCert for a symmetric M gives a unit lower-triangular
L by envelope, a diagonal d and a sparse symmetric remainder R with
M = L * diagonal d * Lᵀ + R. Row i of L is its first column fᵢ and its entries
L i fᵢ, …, L i i, ending in 1; the entries left of fᵢ are zero. The factors are the
dense certificate EnvLDLCert.toLDLCert, with the rows padded by zeros, so L and d are the
matrices LDLCert.L and LDLCert.d of the dense checker. R must be diagonally dominant,
∑_{j ≠ i} |R i j| ≤ R i i (Cslib.LinearAlgebra.ddGo), hence positive semidefinite
(Matrix.posSemidef_of_diagDominant); with positive pivots M ≻ 0 follows.
The remainder keeps the certificate small. The exact factor of a banded matrix stays in the
band, but its entries grow by a few bits per row: about 10⁴ bits, and megabytes of source, for a
512-state ladder. An untrusted tool instead factors M - ε • 1 in floating point, rounds L
and d to a dyadic grid, and lists the exact R = M - L * diagonal d * Lᵀ, which is about
ε • 1 plus rounding errors, diagonally dominant once the grid is fine enough; its entries have
a bounded number of bits whatever n is. An exact factorization is the certificate with
R = 0 (rem = []), and EnvLDLCert.eq_of_factors then states the factorization.
The check (EnvLDLCert.factorsLower, applied to M - R) compares, on the envelope, the entries
of M - R with those of L * diagonal d * Lᵀ, in integers: row i of L is scaled by the lcm
sᵢ of its denominators, and the row uᵢ = (L i k * d k)ₖ of L * diagonal d by its own lcm
tᵢ, so that entry (i, j) is checked as num x * (tᵢ * sⱼ) = (∑ₖ ûᵢₖ âⱼₖ) * den x, a dot
product over the overlap of the two rows' envelopes (Cslib.LinearAlgebra.alignDot). The
common scale of all of d that the dense checker uses would, for an exact factor, be the lcm of
all pivots' denominators, which grows quadratically in n, while each tᵢ involves only the
pivots in one row's envelope. The data of the rows above row i are kept in a reversed list,
of which row i reads the first i - fᵢ. Left of the envelope the check asks that M - R
store only zeros; there L * diagonal d * Lᵀ vanishes by construction. The cost is about
∑ᵢ ∑_{j ∈ [fᵢ, i]} (j - max fᵢ fⱼ + 1) products, which is O(n w²) for bandwidth w.
The Lyapunov residual #
Cslib.LinearAlgebra.SparseLyapunovCert.check recomputes -(Aᵀ * P + P * A) from sparse A
and P. The certificate carries the rows of Aᵀ, which the checker verifies against A, so
that both products Aᵀ * P and P * A take rows from rows. As in the dense checker, A, Aᵀ
and P are scaled to integers by the lcm of their denominators for the products
(Cslib.LinearAlgebra.sparseScaledResidual), each row of the residual is normalized by merging
repeated columns (Cslib.LinearAlgebra.sparseNormalize), and the residual's symmetry is proved
from that of the accepted P, not checked.
Certificate layout #
A certificate is Lean source. Write every rational entry of a sparse row, of lower and of
diag as mkRat (.ofNat p) q or mkRat (.negSucc p) q, and give each field its own
definition with its type. Numerals of ℤ or ℚ inside the pairs of a long list literal make
elaboration superlinear (typeclass inference dominates; a list of 2000 such pairs exceeds the
default heartbeat limit), while natural-number literals and explicit constructors elaborate in
linear time. The kernel evaluates mkRat like the division it replaces.
Main definitions #
Cslib.LinearAlgebra.sparseGet,Cslib.LinearAlgebra.ofSparse,Cslib.LinearAlgebra.isSparseShape: the sparse format.Cslib.LinearAlgebra.sparseMul,Cslib.LinearAlgebra.isTransposeOf,Cslib.LinearAlgebra.isSymm,Cslib.LinearAlgebra.sparseNormalize,Cslib.LinearAlgebra.subRows,Cslib.LinearAlgebra.ddGo: operations that the kernel evaluates.Cslib.LinearAlgebra.EnvLDLCert,EnvLDLCert.factors,EnvLDLCert.checkPosDef,EnvLDLCert.checkPosSemidef: envelope certificates for sparse symmetric matrices.Cslib.LinearAlgebra.sparseResidual,Cslib.LinearAlgebra.SparseLyapunovCert,SparseLyapunovCert.check.Cslib.LinearAlgebra.sparseShift,Cslib.LinearAlgebra.sparseQuadForm,Cslib.LinearAlgebra.SparseInstabilityCert,SparseInstabilityCert.check: the sparse form of the instability certificateCslib.LinearAlgebra.InstabilityCert.
Main results #
Cslib.LinearAlgebra.ofSparse_toSparse,Cslib.LinearAlgebra.ofSparse_sparseMul,Cslib.LinearAlgebra.ofSparse_eq_transpose_of_isTransposeOf,Cslib.LinearAlgebra.ofSparse_sparseResidual: the operations compute the matrix ones.Cslib.LinearAlgebra.EnvLDLCert.eq_add_of_factorsWith: an accepted certificate writesMasL * diagonal d * Lᵀ + R.Cslib.LinearAlgebra.EnvLDLCert.posDef_of_checkPosDef,Cslib.LinearAlgebra.EnvLDLCert.posSemidef_of_checkPosSemidef: soundness overℝ.Cslib.LinearAlgebra.EnvLDLCert.posDef_of_factorsSparseResidual,Cslib.LinearAlgebra.EnvLDLCert.posSemidef_of_factorsSparseResidual: residual soundness for a symmetricP, shared by both sparse certificates.Cslib.LinearAlgebra.SparseLyapunovCert.posDef_of_check:P ≻ 0and-(Aᵀ * P + P * A) ≻ 0overℝ, with the statement of the denseCslib.LinearAlgebra.LyapunovCert.posDef_of_check.Cslib.LinearAlgebra.SparseInstabilityCert.sound_of_check: the statement of the denseCslib.LinearAlgebra.InstabilityCert.sound_of_check.
Sparse rows #
Zipper access to rows #
Products #
Transposes #
Normalization #
Integer scaling of sparse rows #
Envelope LDLᵀ certificates #
Differences and diagonal dominance of sparse rows #
Envelope LDLᵀ certificates #
An LDLᵀ witness for an n × n rational matrix M, by envelope, with a remainder: row i
of lower is the first column fᵢ of row i of L and its entries L i fᵢ, …, L i i,
ending in 1, and rem lists the sparse rows of a symmetric, diagonally dominant R with
M = L * diagonal d * Lᵀ + R. An exact factorization has rem = [].
Row
iis(fᵢ, [L i fᵢ, …, L i i]).The diagonal
d 0, …, d (n - 1).The sparse rows of the remainder
R.
The factors as a dense certificate: the rows of L padded with zeros on the left.
The check of row i, with data rd, entries r of L and stored row mrow of M, given
the data prev of the rows above, nearest first. The window win is the data of the rows
fᵢ, …, i - 1, u is row i of L * diagonal d on the envelope, scaled to integers b by
its lcm t; entry (i, fᵢ + p) is checked against the row fᵢ + p of the window.
Whether c factors, exactly and on and below the diagonal, the n × n matrix with sparse
rows rows: c.lower and c.diag have n entries, row i of L reaches the diagonal and
ends in 1, rows has n rows and stores only zeros left of the envelope, and the envelope
entries agree with L * diagonal d * Lᵀ. Neither symmetry nor c.rem is used here.
Whether M = L * diagonal d * Lᵀ + R for the symmetric n × n matrix M with sparse rows
rows: R (c.rem) is symmetric and diagonally dominant, and c factors M - R exactly.
The symmetry of M is not checked here.
Whether c is a certificate for the n × n matrix with sparse rows rows: they have the
shape of an n × n matrix and are symmetric, and factorsWith accepts.
Soundness of the envelope check #
An accepted exact check factors every symmetric matrix that the rows give.
An accepted factorsWith writes the symmetric matrix as L * diagonal d * Lᵀ + R.
The remainder of an accepted factorsWith is positive semidefinite over ℝ.
An accepted factorsWith with positive pivots proves the symmetric matrix positive definite
over ℝ.
An accepted factorsWith with nonnegative pivots proves the symmetric matrix positive
semidefinite over ℝ.
Soundness for ⪰ 0. An accepted certificate proves the matrix positive semidefinite
over ℝ.
Sparse Lyapunov residuals #
The common scale sparseDenLcm (A ++ At) * sparseDenLcm P of the sparse residual.
Sparse residual soundness for ≻ 0. For a symmetric P and At the transpose of A,
an accepted factorsWith on sparseResidual A At P with positive pivots proves
-(Aᵀ * P + P * A) ≻ 0 over ℝ.
Sparse residual soundness for ⪰ 0. For a symmetric P and At the transpose of A,
an accepted factorsWith on sparseResidual A At P with nonnegative pivots proves
-(Aᵀ * P + P * A) ⪰ 0 over ℝ.
Witnesses for a sparse quadratic Lyapunov certificate for ẋ = A x: the rows of Aᵀ, and
envelope certificates for P ≻ 0 and -(Aᵀ * P + P * A) ≻ 0.
The sparse rows of
Aᵀ, checked againstA.- P : EnvLDLCert
An envelope certificate for
P. - Q : EnvLDLCert
Whether c certifies P ≻ 0 and -(Aᵀ * P + P * A) ≻ 0 for the sparse n × n matrices
A and P. The residual is recomputed from A, Aᵀ and P, and its symmetry follows from
that of the accepted P.
Sparse instability certificates #
sparseQuadForm computes x ⬝ᵥ P *ᵥ x when x has exactly n entries.
A sparse instability certificate for ẋ = A x with the symmetric sparse matrix P, which
need not be definite: a rational rate ε of either sign, a dense initial vector x₀ with
x₀ᵀ P x₀ < 0, the sparse rows of (A - ε • 1)ᵀ, and an envelope certificate for
-((A - ε • 1)ᵀ * P + P * (A - ε • 1)) ⪰ 0. It is the sparse form of InstabilityCert.
- rate : ℚ
The certified rate
ε. The sparse rows of
(A - ε • 1)ᵀ, checked againstA.- Q : EnvLDLCert
Whether c certifies, for the sparse n × n matrices 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 by sparseResidual from sparseShift ε A, c.At and P, and checked
by EnvLDLCert.factorsWith, as in SparseLyapunovCert.check.
Soundness. An accepted sparse instability certificate proves, over ℝ, the hypotheses
of InstabilityCert.sound_of_check for the matrices ofSparse n n A and ofSparse n n P.