The row-proof arithmetic layer, deep-embedded #
This is step A of the proof-data source: affine forms, contexts, and the
entailment checker of the format spec §4.1 / §13.4, as Bool functions over
List ℤ, proved sound once.
Representation discipline #
Everything generated is List ℤ addressed with List.getD. No ![…], no
Fin-indexed functions, no Matrix.cons. This is not a style preference:
the accompanying analysis §5 measured 198 s of kernel
type-checking for one rfl through ![…] at a Fin numeral against 15 ms
for the same goal by decide, and the accompanying analysis records 189,527
unfoldings of instDecidableEqSum.decEq from the same family of mistake.
The one design decision worth recording #
A form c + Σ aᵢ xᵢ is stored as the single list c :: a, and evaluated as
dot g (1 :: x) — the constant is just the coefficient of a leading 1
coordinate. Evaluation is then literally a dot product, so it is additive
and homogeneous in the form by two three-line inductions, and every soundness
step downstream is linear algebra rather than case analysis on the head.
Out-of-range certificate indices need no bounds check. List.getD returns
[] there, eval [] x = 0, and a zero row is harmless on both sides: with a
nonnegative multiplier it contributes 0 ≥ 0 to the inequality part, and any
multiplier contributes 0 to the equality part. So the checker is
fail-closed on malformed indices without spending a comparison on them.
Dot product, truncating at the shorter list.
Equations
- Utilities.Subdivision.ClosedRowProof.dot [] x✝ = 0
- Utilities.Subdivision.ClosedRowProof.dot x✝ [] = 0
- Utilities.Subdivision.ClosedRowProof.dot (a :: as) (b :: bs) = a * b + Utilities.Subdivision.ClosedRowProof.dot as bs
Instances For
Evaluate a form at a point. The constant term is the coefficient of the
leading 1, which makes eval a dot product and hence linear in the form.
Equations
Instances For
Sum of two forms, aligned at the constant term.
Equations
- Utilities.Subdivision.ClosedRowProof.addForm [] x✝ = x✝
- Utilities.Subdivision.ClosedRowProof.addForm x✝ [] = x✝
- Utilities.Subdivision.ClosedRowProof.addForm (a :: as) (b :: bs) = (a + b) :: Utilities.Subdivision.ClosedRowProof.addForm as bs
Instances For
Scalar multiple of a form.
Equations
- Utilities.Subdivision.ClosedRowProof.smulForm k f = List.map (fun (a : ℤ) => k * a) f
Instances For
Difference of two forms.
Equations
Instances For
Syntactic equality of forms, up to padding: their difference is zero in every coordinate.
Equations
- Utilities.Subdivision.ClosedRowProof.formEq f g = List.all (Utilities.Subdivision.ClosedRowProof.subForm f g) fun (a : ℤ) => a == 0
Instances For
Contexts #
Entailment certificates #
A certificate for Γ ⊢ g ≥ 0 is (k; λ; μ; c) with k ≥ 1, λ sparse
nonnegative weights into Γ.ge, μ sparse weights into Γ.eq, c ≥ 0, and
k · g = Σ λᵢ Γ.geᵢ + Σ μⱼ Γ.eqⱼ + c
as an identity of forms. Nothing searches for λ; the generator supplies it.
The checker of spec §4.1. One pass over the sparse lists and one vector comparison; no rounding, deliberately (§13.4).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Soundness of the entailment layer.
If the checker accepts, the form really is nonnegative everywhere on the context. This is the only thing the rest of the lowering may assume about certificates.