Documentation

LeanMlir.Proofs.Nets.Small.LinearFold

PoC: the MNIST-linear train step, proof-tied to the certified SGD step #

Companion to planning/archive/verified_faithful_sweep.md. MainMnistLinearVerified trains on verified_mlir/linear_train_step.mlir, which is written by Proofs.StableHLO.linTrainStepFaithfulV (the #eval writer at the end of StableHLO.lean). This file certifies that renderer: every value the emitted module produces is the certified (Mathlib-fderiv-derived) softmax-CE loss-descent SGD step.

(Namespace/name lengths are kept short on purpose: tests/AuditAxioms.lean's three-axiom closure check greps #print axioms output per line, which Lean wraps past ~120 cols — long qualified names would split the benign triple across lines and false-fail the check. Keep future per-chapter capstone names short.)

What is closed here (kernel, [propext, Classical.choice, Quot.sound]) #

The committed-bytes tie (verified_mlir/linear_train_step.mlir == linTrainStepFaithfulV(…)) is enforced in CI (regenerate + git diff, the "Verified-render drift guard" step in proofs.yml), not here.

Honest residual (the boundary shared with the forward SHlo den) #

Forward eval — end-to-end tied #

theorem Proofs.LinPoC.poc_fwd_is_render {m n : } (W : Mat m n) (b : Vec n) (x : Vec m) (B : ) :
∃ (argSig : String), StableHLO.linearFwdModuleV B m n W b x = StableHLO.renderModule "linear_fwd" argSig B n (StableHLO.fwdGraph W b x)

The committed linear_fwd.mlir generator linearFwdModuleV is renderModule applied to the proven fwdGraph — the emitted bytes are literally the print of the graph fwdGraph_faithful is about.

The tail fold (closed) — the emitted tail ops are pretty(provenNode) #

StableHLO.linTrainStepFaithfulV (what generates verified_mlir/linear_train_step.mlir) renders the whole module as pretty of SHlo nodes, fully tied: each of SHlo.weightSgd / SHlo.biasSgd consumes the proven lossCotGraph node DIRECTLY (not a .operand %dy <placeholder> name-pin), so the forward = the proven fwdGraph (nested inside lossCotGraph) and den(output) = certified is one composed theorem below — no trusted SSA-name linkage between the cotangent and the SGD ops. The shared cotangent is rendered once per output (2×); iree CSEs the duplicate. (lr/W,b,x values are skel-erased, so the render is value-independent — the placeholders linTrainStepFaithfulV passes print the same text as the live graph here.)

theorem Proofs.LinPoC.poc_weightSgd_den_eq {m n : } (W : Mat m n) (b : Vec n) (x : Vec m) (lrStr : String) (lr : ) (label : Fin n) :
StableHLO.den (StableHLO.SHlo.weightSgd "%x" "%W0" lrStr x W lr (StableHLO.lossCotGraph W b x (oneHot n label))) = StableHLO.linWeightDen W b x lr label

The emitted weightSgd op — consuming the proven lossCotGraph node DIRECTLY (the fully-tied render) — denotes linWeightDen (the certified sgdW step).

theorem Proofs.LinPoC.poc_biasSgd_den_eq {m n : } (W : Mat m n) (b : Vec n) (x : Vec m) (lrStr : String) (lr : ) (label : Fin n) :
StableHLO.den (StableHLO.SHlo.biasSgd "%b0" lrStr b lr (StableHLO.lossCotGraph W b x (oneHot n label))) = StableHLO.linBiasDen W b x lr label

The emitted biasSgd op — consuming the proven lossCotGraph node DIRECTLY — denotes linBiasDen (the certified bias step).

theorem Proofs.LinPoC.poc_train_step_tail_certified {m n : } (W : Mat m n) (b : Vec n) (x : Vec m) (lrStr : String) (lr : ) (label : Fin n) :
(∀ (i : Fin m) (j : Fin n), StableHLO.den (StableHLO.SHlo.weightSgd "%x" "%W0" lrStr x W lr (StableHLO.lossCotGraph W b x (oneHot n label))) (finProdFinEquiv (i, j)) = W i j - lr * pdiv (fun (v : Vec (m * n)) (x_1 : Fin 1) => crossEntropy n (dense (Mat.unflatten v) b x) label) W.flatten (finProdFinEquiv (i, j)) 0) ∀ (j : Fin n), StableHLO.den (StableHLO.SHlo.biasSgd "%b0" lrStr b lr (StableHLO.lossCotGraph W b x (oneHot n label))) j = b j - lr * i : Fin n, pdiv (fun (b' : Vec n) => dense W b' x) b j i * (softmax n (mnistLinear W b x) i - oneHot n label i)

Tail fold (in-kernel, closed). The two emitted tail ops weightSgd/biasSgd — the actual SHlo nodes linTrainStepFaithfulV prints — denote the certified fderiv-derived loss-descent SGD step. The tail's meaning is now a property of the emitted node (via den), proven — not a separately-supplied model.