Documentation

CslibFrontier.Algorithms.LinearAlgebra.SparseLDLCertificate

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 #

Main results #

Sparse rows #

def Cslib.LinearAlgebra.sparseGet {α : Type u_1} [Add α] [Zero α] :
List (ℕ × α) → ℕ → α

The value of a sparse row at column j: the sum of the values stored at j.

@[simp]
theorem Cslib.LinearAlgebra.sparseGet_nil {α : Type u_1} [Add α] [Zero α] (j : ℕ) :
theorem Cslib.LinearAlgebra.sparseGet_cons {α : Type u_1} [Add α] [Zero α] (e : ℕ × α) (r : List (ℕ × α)) (j : ℕ) :
sparseGet (e :: r) j = if e.1 = j then e.2 + sparseGet r j else sparseGet r j
theorem Cslib.LinearAlgebra.sparseGet_append {α : Type u_1} [AddMonoid α] (r s : List (ℕ × α)) (j : ℕ) :
sparseGet (r ++ s) j = sparseGet r j + sparseGet s j
theorem Cslib.LinearAlgebra.sparseGet_eq_zero {α : Type u_1} [AddMonoid α] {r : List (ℕ × α)} {j : ℕ} (h : ∀ e ∈ r, e.1 = j → e.2 = 0) :
sparseGet r j = 0

A column at which every stored value is zero has value zero.

def Cslib.LinearAlgebra.ofSparse {α : Type u_1} [Add α] [Zero α] (m n : ℕ) (rows : List (List (ℕ × α))) :
Matrix (Fin m) (Fin n) α

The matrix of a list of sparse rows: entry (i, j) is sparseGet of row i at j, and a missing row is zero.

theorem Cslib.LinearAlgebra.ofSparse_apply {α : Type u_1} [Add α] [Zero α] (m n : ℕ) (rows : List (List (ℕ × α))) (i : Fin m) (j : Fin n) :
ofSparse m n rows i j = sparseGet (rows.getD ↑i []) ↑j
def Cslib.LinearAlgebra.colsAbove {α : Type u_1} (n : ℕ) :
ℕ → List (ℕ × α) → Bool

Whether the columns of a sparse row strictly increase from at least c and stay below n.

def Cslib.LinearAlgebra.isSparseShape {α : Type u_1} (m n : ℕ) (rows : List (List (ℕ × α))) :

Whether rows has exactly m rows, each with strictly increasing columns below n.

theorem Cslib.LinearAlgebra.length_of_isSparseShape {α : Type u_1} {m n : ℕ} {rows : List (List (ℕ × α))} (h : isSparseShape m n rows = true) :
rows.length = m
def Cslib.LinearAlgebra.toSparseFrom {α : Type u_1} :
ℕ → List α → List (ℕ × α)

The sparse form of a dense row, starting at column k.

theorem Cslib.LinearAlgebra.sparseGet_toSparseFrom {α : Type u_1} [AddMonoid α] (k : ℕ) (r : List α) (j : ℕ) :
sparseGet (toSparseFrom k r) j = if k ≤ j then r.getD (j - k) 0 else 0
theorem Cslib.LinearAlgebra.ofSparse_toSparse {α : Type u_1} [AddMonoid α] (m n : ℕ) (rows : List (List α)) :

The sparse form of dense rows reads as the same matrix as ofLists.

Zipper access to rows #

def Cslib.LinearAlgebra.zget {α : Type u_1} (past future : List (List (ℕ × α))) (i k : ℕ) :
List (ℕ × α)

Row k of a list of rows whose rows 0, …, i - 1 are past, reversed, and whose rows from i on are future. It costs |i - k| steps.

theorem Cslib.LinearAlgebra.zget_eq {α : Type u_1} (past future : List (List (ℕ × α))) (i k : ℕ) :
zget past future i k = if k < i then past.getD (i - 1 - k) [] else future.getD (k - i) []
theorem Cslib.LinearAlgebra.zget_nil {α : Type u_1} (rows : List (List (ℕ × α))) (k : ℕ) :
zget [] rows 0 k = rows.getD k []
theorem Cslib.LinearAlgebra.zget_step {α : Type u_1} {past future rows : List (List (ℕ × α))} {i : ℕ} (h : ∀ (k : ℕ), zget past future i k = rows.getD k []) (k : ℕ) :
zget (future.headD [] :: past) future.tail (i + 1) k = rows.getD k []

Moving the zipper one row forward.

Products #

def Cslib.LinearAlgebra.sparseScale {α : Type u_1} [Mul α] (c : α) (r : List (ℕ × α)) :
List (ℕ × α)

A sparse row scaled by c.

def Cslib.LinearAlgebra.mulGo {α : Type u_1} [Mul α] :
ℕ → List (List (ℕ × α)) → List (List (ℕ × α)) → List (List (ℕ × α)) → List (List (ℕ × α))

The rows of B * C, with the rows of C reached through a zipper at row i of B.

def Cslib.LinearAlgebra.sparseMul {α : Type u_1} [Mul α] (B C : List (List (ℕ × α))) :
List (List (ℕ × α))

The sparse product B * C: row i lists B i k • (row k of C) for the entries (k, B i k) of row i of B, without merging repeated columns.

theorem Cslib.LinearAlgebra.length_sparseMul {α : Type u_1} [Mul α] (B C : List (List (ℕ × α))) :
theorem Cslib.LinearAlgebra.ofSparse_sparseMul {α : Type u_1} [NonUnitalNonAssocSemiring α] {l m n : ℕ} (B C : List (List (ℕ × α))) (hC : C.length ≤ m) :
ofSparse l n (sparseMul B C) = ofSparse l m B * ofSparse m n C

sparseMul computes the matrix product when C has at most m rows.

Transposes #

def Cslib.LinearAlgebra.transGo {α : Type u_1} [Add α] [Zero α] [BEq α] :
ℕ → List (List (ℕ × α)) → List (List (ℕ × α)) → List (List (ℕ × α)) → Bool

Whether every stored entry (k, x) of row i + p of rs agrees with row k of the matrix behind the zipper at column i + p.

def Cslib.LinearAlgebra.isTransposeOf {α : Type u_1} [Add α] [Zero α] [BEq α] (A B : List (List (ℕ × α))) :

Whether B is the transpose of A: every stored entry of either agrees with the other.

theorem Cslib.LinearAlgebra.sparseGet_eq_of_isTransposeOf {α : Type u_1} [AddMonoid α] [BEq α] [LawfulBEq α] {A B : List (List (ℕ × α))} (h : isTransposeOf A B = true) (i j : ℕ) :
sparseGet (A.getD i []) j = sparseGet (B.getD j []) i

An accepted transpose check relates every entry of A to the transposed entry of B.

theorem Cslib.LinearAlgebra.ofSparse_eq_transpose_of_isTransposeOf {α : Type u_1} [AddMonoid α] [BEq α] [LawfulBEq α] {m n : ℕ} {A B : List (List (ℕ × α))} (h : isTransposeOf A B = true) :

An accepted transpose check gives the transposed matrix.

def Cslib.LinearAlgebra.isSymm {α : Type u_1} [Add α] [Zero α] [BEq α] (A : List (List (ℕ × α))) :

Whether A is symmetric: every stored entry agrees with the transposed entry. It is isTransposeOf A A in one pass instead of two.

theorem Cslib.LinearAlgebra.isTransposeOf_self {α : Type u_1} [Add α] [Zero α] [BEq α] (A : List (List (ℕ × α))) :
theorem Cslib.LinearAlgebra.ofSparse_eq_transpose_of_isSymm {α : Type u_1} [AddMonoid α] [BEq α] [LawfulBEq α] {n : ℕ} {A : List (List (ℕ × α))} (h : isSymm A = true) :

An accepted symmetry check gives a symmetric matrix.

Normalization #

def Cslib.LinearAlgebra.insertAdd {α : Type u_1} [Add α] (e : ℕ × α) :
List (ℕ × α) → List (ℕ × α)

Insert an entry into a row sorted by column, adding it to an entry of the same column.

def Cslib.LinearAlgebra.sparseNormalize {α : Type u_1} [Add α] (r : List (ℕ × α)) :
List (ℕ × α)

A row with its entries sorted by column and repeated columns merged.

Integer scaling of sparse rows #

The integer row s * q for the stored values q of r, exact when every q.den divides s.

The lcm of the denominators of all values stored in rows.

theorem Cslib.LinearAlgebra.map_ofSparse_scaleSparse {m n s : ℕ} {rows : List (List (ℕ × ℚ))} (hs : ∀ e ∈ rows.flatten, e.2.den ∣ s) :
(ofSparse m n (List.map (scaleSparse s) rows)).map Int.cast = ↑s • ofSparse m n rows

Scaling every row by a common multiple s of the denominators scales the matrix.

Envelope LDLᵀ certificates #

def Cslib.LinearAlgebra.envRow {α : Type u_1} [Zero α] (fr : ℕ × List α) :
List α

A row given by its first column f and its entries from f on, as a dense row.

theorem Cslib.LinearAlgebra.getD_envRow {α : Type u_1} [Zero α] (f : ℕ) (r : List α) (k : ℕ) :
(envRow (f, r)).getD k 0 = if f ≤ k then r.getD (k - f) 0 else 0
def Cslib.LinearAlgebra.alignDot (f : ℕ) (u : List ℤ) (g : ℕ) (a : List ℤ) :

The dot product of two rows given by their first columns, over the overlap.

theorem Cslib.LinearAlgebra.alignDot_eq (f : ℕ) (u : List ℤ) (g : ℕ) (a : List ℤ) :
alignDot f u g a = rowDot (envRow (f, u)) (envRow (g, a))

Differences and diagonal dominance of sparse rows #

def Cslib.LinearAlgebra.sparseMap {α : Type u_1} {β : Type u_2} (f : α → β) (r : List (ℕ × α)) :
List (ℕ × β)

A sparse row with f applied to every stored value.

theorem Cslib.LinearAlgebra.sparseGet_sparseMap {α : Type u_1} {β : Type u_2} [AddMonoid α] [AddMonoid β] {f : α → β} (hf0 : f 0 = 0) (hf : ∀ (a b : α), f (a + b) = f a + f b) (r : List (ℕ × α)) (j : ℕ) :
sparseGet (sparseMap f r) j = f (sparseGet r j)

rows - rem, row by row, with repeated columns merged. A row of rows with no row of rem is kept.

theorem Cslib.LinearAlgebra.sparseGet_subRows (rows rem : List (List (ℕ × ℚ))) (i j : ℕ) :
i < rows.length → sparseGet ((subRows rows rem).getD i []) j = sparseGet (rows.getD i []) j - sparseGet (rem.getD i []) j
theorem Cslib.LinearAlgebra.length_subRows (rows rem : List (List (ℕ × ℚ))) :
(subRows rows rem).length = rows.length

The sum of |x| over the stored entries (k, x) of a row with k ≠ i.

Whether row i + k of rows is diagonally dominant by its stored entries, for every k: offAbs is at most the diagonal entry.

theorem Cslib.LinearAlgebra.diagDominant_of_ddGo {n : ℕ} {rows : List (List (ℕ × ℚ))} (h : ddGo 0 rows = true) (i : Fin n) :
(∑ j : Fin n, if i = j then 0 else |ofSparse n n rows i j|) ≤ ofSparse n n rows i i

Accepted rows are diagonally dominant: ∑_{j ≠ i} |R i j| ≤ R i i.

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 = [].

The factors as a dense certificate: the rows of L padded with zeros on the left.

Whether row k of rows reaches column i + k and ends in 1, for every k.

What is kept of a row above the current one.

  • first : ℕ

    The first column of the row's envelope.

  • scaled : List ℤ

    The row's entries of L, scaled to integers.

  • scale : ℕ

    Their scale, the lcm of the denominators.

  • pivot : ℚ

    The pivot d i.

The data kept of row (f, r) with pivot di.

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.

The check of every row, keeping the data of the rows above.

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.

Whether c certifies ofSparse n n rows ≻ 0: it factors the matrix and every d i is positive.

Whether c certifies ofSparse n n rows ⪰ 0: it factors the matrix and every d i is nonnegative.

Soundness of the envelope check #

theorem Cslib.LinearAlgebra.EnvLDLCert.eq_of_factorsLower (c : EnvLDLCert) {n : ℕ} {rows : List (List (ℕ × ℚ))} (hsymm : (ofSparse n n rows).transpose = ofSparse n n rows) (h : c.factorsLower n rows = true) :

An accepted exact check factors every symmetric matrix that the rows give.

theorem Cslib.LinearAlgebra.EnvLDLCert.eq_add_of_factorsWith (c : EnvLDLCert) {n : ℕ} {rows : List (List (ℕ × ℚ))} (hlen : rows.length = n) (hsymm : (ofSparse n n rows).transpose = ofSparse n n rows) (h : c.factorsWith n rows = true) :

An accepted factorsWith writes the symmetric matrix as L * diagonal d * Lᵀ + R.

The remainder of an accepted factorsWith is positive semidefinite over ℝ.

theorem Cslib.LinearAlgebra.EnvLDLCert.posDef_of_factorsWith (c : EnvLDLCert) {n : ℕ} {rows : List (List (ℕ × ℚ))} (hlen : rows.length = n) (hsymm : (ofSparse n n rows).transpose = ofSparse n n rows) (h : c.factorsWith n rows = true) (hd : (c.diag.all fun (x : ℚ) => decide (0 < x)) = true) :

An accepted factorsWith with positive pivots proves the symmetric matrix positive definite over ℝ.

theorem Cslib.LinearAlgebra.EnvLDLCert.posSemidef_of_factorsWith (c : EnvLDLCert) {n : ℕ} {rows : List (List (ℕ × ℚ))} (hlen : rows.length = n) (hsymm : (ofSparse n n rows).transpose = ofSparse n n rows) (h : c.factorsWith n rows = true) (hd : (c.diag.all fun (x : ℚ) => decide (0 ≤ x)) = true) :

An accepted factorsWith with nonnegative pivots proves the symmetric matrix positive semidefinite over ℝ.

Soundness for ≻ 0. An accepted certificate proves the matrix positive definite over ℝ.

Soundness for ⪰ 0. An accepted certificate proves the matrix positive semidefinite over ℝ.

theorem Cslib.LinearAlgebra.EnvLDLCert.eq_of_factors (c : EnvLDLCert) {n : ℕ} {rows : List (List (ℕ × ℚ))} (h : c.factors n rows = true) (hrem : c.rem = []) :

An exact certificate (rem = []) factors the matrix.

Sparse Lyapunov residuals #

The common scale sparseDenLcm (A ++ At) * sparseDenLcm P of the sparse residual.

The fraction-free sparse residual -(Âᵀ * P̂ + P̂ * Â), row by row with repeated columns merged, for Âᵀ, P̂ and  the rows of At, P and A scaled to integers by the lcm of their denominators.

The sparse residual -(Aᵀ * P + P * A) over ℚ, when At is the transpose of A (ofSparse_sparseResidual): the fraction-free residual divided by its scale.

The sparse residual has a row for each row of At and of P, as many as the shorter of the two has.

theorem Cslib.LinearAlgebra.ofSparse_sparseResidual {n : ℕ} {A At P : List (List (ℕ × ℚ))} (hAl : A.length = n) (hAtl : At.length = n) (hPl : P.length = n) (hT : isTransposeOf A At = true) :
ofSparse n n (sparseResidual A At P) = -((ofSparse n n A).transpose * ofSparse n n P + ofSparse n n P * ofSparse n n A)

The rational sparse residual reads as -(Aᵀ * P + P * A).

theorem Cslib.LinearAlgebra.EnvLDLCert.posDef_of_factorsSparseResidual {c : EnvLDLCert} {n : ℕ} {A At P : List (List (ℕ × ℚ))} (hAl : A.length = n) (hAtl : At.length = n) (hPl : P.length = n) (hT : isTransposeOf A At = true) (hPs : (ofSparse n n P).transpose = ofSparse n n P) (h : c.factorsWith n (sparseResidual A At P) = true) (hd : (c.diag.all fun (x : ℚ) => decide (0 < x)) = true) :

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 ℝ.

theorem Cslib.LinearAlgebra.EnvLDLCert.posSemidef_of_factorsSparseResidual {c : EnvLDLCert} {n : ℕ} {A At P : List (List (ℕ × ℚ))} (hAl : A.length = n) (hAtl : At.length = n) (hPl : P.length = n) (hT : isTransposeOf A At = true) (hPs : (ofSparse n n P).transpose = ofSparse n n P) (h : c.factorsWith n (sparseResidual A At P) = true) (hd : (c.diag.all fun (x : ℚ) => decide (0 ≤ x)) = true) :

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.

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.

Soundness. An accepted sparse Lyapunov certificate proves P ≻ 0 and -(Aᵀ * P + P * A) ≻ 0 for the real matrices A and P.

Sparse instability certificates #

Rows k, k + 1, … of A - ε • 1: the entry (k + i, -ε) appended to row i of rs.

The sparse rows of A - ε • 1.

theorem Cslib.LinearAlgebra.ofSparse_sparseShift {n : ℕ} (ε : ℚ) {A : List (List (ℕ × ℚ))} (hA : A.length = n) :
ofSparse n n (sparseShift ε A) = ofSparse n n A - ε • 1

sparseShift computes A - ε • 1 for n rows.

The sum ∑ (j, p) ∈ r, p * x j of a sparse row against a dense vector.

theorem Cslib.LinearAlgebra.sparseDotDense_eq {n : ℕ} {x : List ℚ} (hx : x.length ≤ n) (r : List (ℕ × ℚ)) :
sparseDotDense r x = ∑ j : Fin n, sparseGet r ↑j * x.getD (↑j) 0

sparseDotDense is the dot product with the vector padded by zeros, when x has at most n entries.

The quadratic form xᵀ P x of the sparse rows P at the dense vector x.

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 ε.

  • x₀ : List ℚ

    An initial vector of negative energy x₀ᵀ P x₀ < 0, as a dense list.

  • At : List (List (ℕ × ℚ))

    The sparse rows of (A - ε • 1)ᵀ, checked against A.

  • An envelope certificate for -((A - ε • 1)ᵀ * P + P * (A - ε • 1)), with d ≥ 0.

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.