Documentation

LeanMlir.Proofs.Float.FloatBridge

ℝ → Float32 bridge, Tier 1: standard-model rounding bounds #

Every theorem in LeanMlir/Proofs/ is over exact reals; the executed kernels are binary32. This file is the first bite at that gap, for the toy nets only (linear, MLP — the Tier-1 ladder): a standard-model formalization of rounded arithmetic and forward error bounds for the same dense/relu compositions the train-step proofs certify.

The model is hypothesis-style, like the suite's 0 < ε / off-the-kink hypotheses: a FloatModel is any rounding operator rnd with relative error u (|rnd x − x| ≤ u·|x|). No project axioms — IEEE-754 binary32 round-to-nearest satisfies the interface with u = 2⁻²⁴ in the normal range (Higham, Accuracy and Stability, §2.2; the standard model without underflow — the subnormal absolute-error term is future work, as is the gradient half). exactModel (rnd = id, u = 0) shows the interface is inhabited and collapses every bound to 0.

Design notes, in suite style:

The standard model of rounded arithmetic. Any rounding operator with relative error u. binary32 round-to-nearest instantiates this with u = 2⁻²⁴ on the normal range.

Instances For
    noncomputable def Proofs.u32 :

    The unit roundoff of IEEE-754 binary32 (round-to-nearest-even).

    Equations
    Instances For
      noncomputable def Proofs.u_e4m3 :

      The normal-range unit roundoff of fp8 E4M3 (1-4-3, 3 mantissa bits): 2⁻⁴ = 1/16 (6.25%) — the leaf precision of the §3c E4M3 MNIST demo (scripts/mnist_e4m3_demo.py). Outside the normal range (subnormals, near the 448 max) the relative model degrades; see §2/§5 of the plan.

      Equations
      Instances For
        noncomputable def Proofs.FloatModel.add (M : FloatModel) (x y : ) :

        Rounded addition: fl(x + y).

        Equations
        Instances For
          noncomputable def Proofs.FloatModel.mul (M : FloatModel) (x y : ) :

          Rounded multiplication: fl(x · y).

          Equations
          Instances For
            noncomputable def Proofs.FloatModel.dot (M : FloatModel) {n : } :
            Vec nVec n

            Rounded dot product, left-fold association (((x₀y₀ + x₁y₁) + …)). The bound below is association-independent, so the choice is immaterial.

            Equations
            Instances For
              theorem Proofs.FloatModel.dot_zero (M : FloatModel) (x y : Vec 0) :
              M.dot x y = 0
              theorem Proofs.FloatModel.dot_succ (M : FloatModel) {n : } (x y : Vec (n + 1)) :
              M.dot x y = M.add (M.dot (fun (i : Fin n) => x i.castSucc) fun (i : Fin n) => y i.castSucc) (M.mul (x (Fin.last n)) (y (Fin.last n)))
              noncomputable def Proofs.FloatModel.dense (M : FloatModel) {m n : } (W : Mat m n) (b : Vec n) (x : Vec m) :
              Vec n

              Rounded dense layer — the float peer of Proofs.dense (fl(Σᵢ xᵢ·Wᵢⱼ) ⊕ bⱼ, every +/· rounded).

              Equations
              Instances For
                noncomputable def Proofs.FloatModel.mlpF (M : FloatModel) {d₀ d₁ d₂ d₃ : } (W₀ : Mat d₀ d₁) (b₀ : Vec d₁) (W₁ : Mat d₁ d₂) (b₁ : Vec d₂) (W₂ : Mat d₂ d₃) (b₂ : Vec d₃) (x : Vec d₀) :
                Vec d₃

                Rounded MLP forward — the float peer of the Tier-1 dense W₂ b₂ ∘ relu ∘ dense W₁ b₁ ∘ relu ∘ dense W₀ b₀ composition (MlpTrainStep.lean). relu appears bare: max-with-0 is exact in floating point.

                Equations
                Instances For
                  theorem Proofs.FloatModel.pow_one_add_sub_one_le (u : ) (hu : 0 u) (k : ) :
                  (1 + u) ^ k - 1 k * u * (1 + u) ^ k

                  (1+u)^k − 1 ≤ k·u·(1+u)^k — the reading key from the compounded form back to the familiar first-order "≈ k·u" bound.

                  theorem Proofs.FloatModel.dot_close (M : FloatModel) {n : } (x y : Vec n) :
                  |M.dot x y - i : Fin n, x i * y i| ((1 + M.u) ^ (n + 1) - 1) * i : Fin n, |x i * y i|

                  Rounded dot product forward error|fl(x·y) − x·y| ≤ ((1+u)^(n+1) − 1)·Σᵢ|xᵢyᵢ|.

                  The classical bound (Higham §3.1), in the exact compounded form (no n·u < 1 side condition); valid for every association of the sum, not just the left fold dot fixes. The exponent is n+1 rather than the optimal n because dot rounds the seed addition with 0 too.

                  theorem Proofs.FloatModel.dot_close_linear (M : FloatModel) {n : } (x y : Vec n) :
                  |M.dot x y - i : Fin n, x i * y i| (n + 1) * M.u * (1 + M.u) ^ (n + 1) * i : Fin n, |x i * y i|

                  dot_close in the first-order shape: ≤ (n+1)·u·(1+u)^(n+1)·Σ|xᵢyᵢ|.

                  noncomputable def Proofs.FloatModel.dotMixed (M L : FloatModel) {n : } (x y : Vec n) :

                  Mixed-precision dot product. The matmul inputs are first rounded by a leaf model L (low precision, u_leaf — e.g. bf16 2⁻⁸ or fp8-E4M3 2⁻⁴); the accumulation M.dot then rounds every +/· at the accumulate precision M.u (u_acc, typically fp32 2⁻²⁴). This is the deployed bf16-mixed kernel shape: bf16 leaf compute, fp32 accumulate.

                  Equations
                  Instances For
                    theorem Proofs.FloatModel.dot_close_mixed (M L : FloatModel) {n : } (x y : Vec n) :
                    |M.dotMixed L x y - i : Fin n, x i * y i| ((1 + M.u) ^ (n + 1) - 1) * i : Fin n, |L.rnd (x i) * L.rnd (y i)| + (2 * L.u + L.u ^ 2) * i : Fin n, |x i * y i|

                    Mixed-precision dot forward error, decomposed. The leaf precision contributes only a flat per-leaf term (2·u_leaf + u_leaf²)·Σ|xᵢyᵢ| (NOT fan-in amplified); the fan-in amplification rides entirely on the accumulate precision as the Higham γ-factor ((1+u_acc)^(n+1) − 1). That separation is exactly why bf16-mixed is non-vacuous where pure bf16 is not: the 1/u fan-in wall sits at u_acc = 2⁻²⁴, not at the leaf precision.

                    theorem Proofs.FloatModel.dot_close_mixed_uniform (M L : FloatModel) {n : } (x y : Vec n) :
                    |M.dotMixed L x y - i : Fin n, x i * y i| (((1 + M.u) ^ (n + 1) - 1) * (1 + L.u) ^ 2 + (2 * L.u + L.u ^ 2)) * i : Fin n, |x i * y i|

                    dot_close_mixed folded to a single Σ|xᵢyᵢ| factor — the directly instantiable form. Bounds the leaf-rounded magnitudes by (1+u_leaf)², so the whole error is [γ_acc·(1+u_leaf)² + (2u_leaf + u_leaf²)]·Σ|xᵢyᵢ|. At bf16 leaf / fp32 accumulate (u_leaf = 2⁻⁸, u_acc = 2⁻²⁴, fan-in a few hundred) the bracket is ≈ the flat 2·2⁻⁸ ≈ 0.8% leaf term plus a negligible accumulate γ — the shipped-artifact budget.

                    noncomputable def Proofs.FloatModel.denseMixed (M L : FloatModel) {m n : } (W : Mat m n) (b : Vec n) (x : Vec m) :
                    Vec n

                    Mixed-precision dense layer — leaf precision L on the matmul (the dotMixed), accumulate precision M on the bias add. The deployed bf16-mixed dense layer (fp32 master/accumulate, bf16 leaf compute).

                    Equations
                    Instances For
                      theorem Proofs.FloatModel.dense_close_mixed (M L : FloatModel) {m n : } (W : Mat m n) (b : Vec n) (x : Vec m) (j : Fin n) :
                      |M.denseMixed L W b x j - Proofs.dense W b x j| M.u * (i : Fin m, |x i * W i j| + |b j|) + (1 + M.u) * ((((1 + M.u) ^ (m + 1) - 1) * (1 + L.u) ^ 2 + (2 * L.u + L.u ^ 2)) * i : Fin m, |x i * W i j|)

                      Mixed-precision dense forward error. The leaf precision enters only through the flat dotMixed term; the accumulate precision rides the bias add and the fan-in γ. The bf16-mixed / fp8 dense layer falls out by setting L.u.

                      noncomputable def Proofs.FloatModel.denseErr (M : FloatModel) {m n : } (W : Mat m n) (b : Vec n) (xa : Vec m) (e : ) (j : Fin n) :

                      The per-coordinate error budget of one rounded dense layer evaluated at an input within e of the real activation xa: the layer's own rounding (compounded (1+u)^(m+2) − 1, on magnitudes inflated by e) plus the Lipschitz pass-through (Σᵢ|Wᵢⱼ|)·e of the inherited error. e = 0 specializes to the fresh-input bound.

                      Equations
                      Instances For
                        theorem Proofs.FloatModel.dense_close (M : FloatModel) {m n : } (W : Mat m n) (b : Vec n) (xt xa : Vec m) (e : ) (he : 0 e) (hx : ∀ (i : Fin m), |xt i - xa i| e) (j : Fin n) :
                        |M.dense W b xt j - Proofs.dense W b xa j| M.denseErr W b xa e j

                        Rounded dense layer forward error, with inherited input error. If xt is within e of the real activation xa coordinatewise, then |M.dense W b xt j − dense W b xa j| ≤ denseErr W b xa e j.

                        theorem Proofs.FloatModel.dense_close_fresh (M : FloatModel) {m n : } (W : Mat m n) (b : Vec n) (x : Vec m) (j : Fin n) :
                        |M.dense W b x j - Proofs.dense W b x j| M.denseErr W b x 0 j

                        dense_close at a fresh (unperturbed) input — the e = 0 face.

                        theorem Proofs.FloatModel.relu_close {n : } (xt xa : Vec n) (e : ) (hx : ∀ (i : Fin n), |xt i - xa i| e) (i : Fin n) :
                        |relu n xt i - relu n xa i| e

                        ReLU propagates error without amplification. No rounding term: max with 0 is exact in floating point, so the float net applies relu bare and the bridge only needs 1-Lipschitz-ness.

                        theorem Proofs.FloatModel.linear_float_close (M : FloatModel) {m n : } (W : Mat m n) (b : Vec n) (x : Vec m) (j : Fin n) :
                        |M.dense W b x j - mnistLinear W b x j| M.denseErr W b x 0 j

                        Linear-net forward extraction (Chapter 1). The rounded mnistLinear is within the explicit denseErr budget of the real one, per logit. With u = 2⁻²⁴ this is the binary32 forward-error bound for the certified linear classifier.

                        theorem Proofs.FloatModel.mlp_float_close (M : FloatModel) {d₀ d₁ d₂ d₃ : } (W₀ : Mat d₀ d₁) (b₀ : Vec d₁) (W₁ : Mat d₁ d₂) (b₁ : Vec d₂) (W₂ : Mat d₂ d₃) (b₂ : Vec d₃) (x : Vec d₀) (e₀ e₁ : ) (he₀ : 0 e₀) (he₁ : 0 e₁) (h₀ : ∀ (j : Fin d₁), M.denseErr W₀ b₀ x 0 j e₀) (h₁ : ∀ (j : Fin d₂), M.denseErr W₁ b₁ (relu d₁ (Proofs.dense W₀ b₀ x)) e₀ j e₁) (k : Fin d₃) :
                        |M.mlpF W₀ b₀ W₁ b₁ W₂ b₂ x k - Proofs.dense W₂ b₂ (relu d₂ (Proofs.dense W₁ b₁ (relu d₁ (Proofs.dense W₀ b₀ x)))) k| M.denseErr W₂ b₂ (relu d₂ (Proofs.dense W₁ b₁ (relu d₁ (Proofs.dense W₀ b₀ x)))) e₁ k

                        MLP forward extraction (Chapter 2). The rounded 3-layer MLP is within the layer-2 denseErr budget (at inherited error e₁) of the real MLP — the same dense/relu composition whose train step is certified in MlpTrainStep.lean. The hypotheses h₀/h₁ uniformize the per-coordinate layer-0/1 budgets into e₀/e₁; at any concrete net they are discharged by finite max over the d₁ (resp. d₂) coordinates.

                        theorem Proofs.FloatModel.pow_gamma_bound (u : ) (hu : 0 u) (k : ) (hk : k * u < 1) :
                        (1 + u) ^ k - 1 k * u / (1 - k * u)

                        The classical γₖ bound: for k·u < 1, (1+u)^k − 1 ≤ k·u/(1 − k·u). Turns the compounded budgets into plain rational arithmetic at a concrete u (e.g. u32) — norm_num country, no big-power evaluation.

                        noncomputable def Proofs.FloatModel.layerAct (m : ) (w β A : ) :

                        Worst-case output magnitude of one real layer under uniform magnitude bounds: |denseⱼ| ≤ m·w·A + β (and relu only shrinks).

                        Equations
                        Instances For
                          noncomputable def Proofs.FloatModel.layerBudget (u : ) (m : ) (w β A E : ) :

                          The uniform-magnitude form of denseErr: every |Wᵢⱼ| ≤ w, |bⱼ| ≤ β, real activation magnitude ≤ A, inherited error ≤ E.

                          Equations
                          Instances For
                            theorem Proofs.FloatModel.layerAct_nonneg {m : } {w β A : } (hw : 0 w) ( : 0 β) (hA : 0 A) :
                            0 layerAct m w β A
                            theorem Proofs.FloatModel.layerBudget_nonneg {u : } {m : } {w β A E : } (hu : 0 u) (hw : 0 w) ( : 0 β) (hA : 0 A) (hE : 0 E) :
                            0 layerBudget u m w β A E
                            theorem Proofs.FloatModel.relu_abs_le {n : } (z : Vec n) (i : Fin n) :
                            |relu n z i| |z i|

                            ReLU never grows magnitudes.

                            theorem Proofs.FloatModel.dense_abs_le {m n : } {W : Mat m n} {b : Vec n} {x : Vec m} {w β a : } (ha : 0 a) (hW : ∀ (i : Fin m) (j : Fin n), |W i j| w) (hb : ∀ (j : Fin n), |b j| β) (hx : ∀ (i : Fin m), |x i| a) (j : Fin n) :
                            |Proofs.dense W b x j| layerAct m w β a

                            Real dense-layer magnitude bound: |denseⱼ| ≤ layerAct m w β a.

                            theorem Proofs.FloatModel.denseErr_le_uniform (M : FloatModel) {m n : } {W : Mat m n} {b : Vec n} {xa : Vec m} {w β a e : } (hw : 0 w) (he : 0 e) (hW : ∀ (i : Fin m) (j : Fin n), |W i j| w) (hb : ∀ (j : Fin n), |b j| β) (hxa : ∀ (i : Fin m), |xa i| a) (j : Fin n) :
                            M.denseErr W b xa e j layerBudget M.u m w β a e

                            denseErr under uniform magnitude bounds is at most the closed-form layerBudget.

                            theorem Proofs.FloatModel.mlp_float_close_uniform (M : FloatModel) {d₀ d₁ d₂ d₃ : } {W₀ : Mat d₀ d₁} {b₀ : Vec d₁} {W₁ : Mat d₁ d₂} {b₁ : Vec d₂} {W₂ : Mat d₂ d₃} {b₂ : Vec d₃} {x : Vec d₀} {w₀ β₀ w₁ β₁ w₂ β₂ a : } (hw₀ : 0 w₀) (hβ₀ : 0 β₀) (hw₁ : 0 w₁) (hβ₁ : 0 β₁) (hw₂ : 0 w₂) (ha : 0 a) (hW₀ : ∀ (i : Fin d₀) (j : Fin d₁), |W₀ i j| w₀) (hb₀ : ∀ (j : Fin d₁), |b₀ j| β₀) (hW₁ : ∀ (i : Fin d₁) (j : Fin d₂), |W₁ i j| w₁) (hb₁ : ∀ (j : Fin d₂), |b₁ j| β₁) (hW₂ : ∀ (i : Fin d₂) (j : Fin d₃), |W₂ i j| w₂) (hb₂ : ∀ (j : Fin d₃), |b₂ j| β₂) (hx : ∀ (i : Fin d₀), |x i| a) (k : Fin d₃) :
                            |M.mlpF W₀ b₀ W₁ b₁ W₂ b₂ x k - Proofs.dense W₂ b₂ (relu d₂ (Proofs.dense W₁ b₁ (relu d₁ (Proofs.dense W₀ b₀ x)))) k| layerBudget M.u d₂ w₂ β₂ (layerAct d₁ w₁ β₁ (layerAct d₀ w₀ β₀ a)) (layerBudget M.u d₁ w₁ β₁ (layerAct d₀ w₀ β₀ a) (layerBudget M.u d₀ w₀ β₀ a 0))

                            MLP forward extraction, uniform-magnitude budgets. mlp_float_close with the e₀/e₁ uniformization discharged once and for all from coordinatewise magnitude bounds |Wᵢ| ≤ wᵢ, |bᵢ| ≤ βᵢ, |x| ≤ a. The budget is a closed form in the dims and magnitudes — evaluable by norm_num at a concrete net.

                            theorem Proofs.FloatModel.gamma_num (M : FloatModel) (hMu : M.u u32) {k : } {q : } (hk : k * u32 < 1) (hq : k * u32 / (1 - k * u32) q) :
                            (1 + M.u) ^ k - 1 q

                            γ-form at a concrete exponent and target, monotone through uu32.

                            theorem Proofs.FloatModel.mnist_mlp_float_budget (M : FloatModel) (hMu : M.u u32) (W₀ : Mat 784 512) (b₀ : Vec 512) (W₁ : Mat 512 512) (b₁ : Vec 512) (W₂ : Mat 512 10) (b₂ : Vec 10) (x : Vec 784) (hW₀ : ∀ (i : Fin 784) (j : Fin 512), |W₀ i j| 3 / 5) (hb₀ : ∀ (j : Fin 512), |b₀ j| 1) (hW₁ : ∀ (i j : Fin 512), |W₁ i j| 3 / 5) (hb₁ : ∀ (j : Fin 512), |b₁ j| 1) (hW₂ : ∀ (i : Fin 512) (j : Fin 10), |W₂ i j| 3 / 5) (hb₂ : ∀ (j : Fin 10), |b₂ j| 1) (hx : ∀ (i : Fin 784), |x i| 1) (k : Fin 10) :
                            |M.mlpF W₀ b₀ W₁ b₁ W₂ b₂ x k - Proofs.dense W₂ b₂ (relu 512 (Proofs.dense W₁ b₁ (relu 512 (Proofs.dense W₀ b₀ x)))) k| 5100

                            Numeric capstone at the committed MNIST-MLP dims and TRAINED magnitudes (the MainMnistMlpVerified.lean net: 784→512→512→10; |W| ≤ 3/5 covers the measured max|W| = 0.52 of a real 12-epoch 97.8% run — He init already exceeds the prettier 1/32 in its tails). For any rounding model at binary32 accuracy (u ≤ 2⁻²⁴), every rounded logit is within 5100 of the exact-real logit — the worst-case logit magnitude at these bounds is ≈4.5·10⁷, so ≈10⁻⁴ relative, the same relative scale as at small weights. All three layer budgets discharge by norm_num through the γ-form; no big-power evaluation.

                            Measured on the live run (scripts/margin_probe.py): actual logit drift ≤ 1.6·10⁻⁵ — the ≈3·10⁸ gap between the worst-case bound and reality is the worst-case-composition blow-up (307·e Lipschitz amplification per layer at these magnitudes), the quantitative case for a-posteriori certificates past toy depth.

                            noncomputable def Proofs.FloatModel.sub (M : FloatModel) (x y : ) :

                            Rounded subtraction: fl(x − y).

                            Equations
                            Instances For
                              noncomputable def Proofs.FloatModel.mulErr (u A C ea ec : ) :

                              Budget of one rounded product of two inherited-error operands: |fl(xt·yt) − x·y| with |xt−x| ≤ ea, |yt−y| ≤ ec, |x| ≤ A, |y| ≤ C.

                              Equations
                              Instances For
                                noncomputable def Proofs.FloatModel.sgdErr (u lr Θ G eg : ) :

                                Budget of one rounded SGD update fl(θ − fl(lr·gt)) against θ − lr·g, with |gt−g| ≤ eg, |g| ≤ G.

                                Equations
                                Instances For
                                  theorem Proofs.FloatModel.mul_close (M : FloatModel) {xt x yt y ea ec A C : } (hx : |xt - x| ea) (hy : |yt - y| ec) (hA : |x| A) (hC : |y| C) :
                                  |M.mul xt yt - x * y| mulErr M.u A C ea ec

                                  Rounded product with inherited operand errors.

                                  theorem Proofs.FloatModel.sgd_step_close (M : FloatModel) (θ : ) {gt g lr G eg : } (hg : |gt - g| eg) (hG : |g| G) (hlr : 0 lr) :
                                  |M.sub θ (M.mul lr gt) - (θ - lr * g)| sgdErr M.u lr |θ| G eg

                                  Rounded SGD update: fl(θ − fl(lr·gt)) is within sgdErr of the real step θ − lr·g. Two roundings plus the inherited gradient error.

                                  theorem Proofs.FloatModel.sgdErr_mono {u u' lr Θ Θ' G eg eg' : } (hu : 0 u) (huu : u u') (hlr : 0 lr) (hΘ0 : 0 Θ) ( : Θ Θ') (hG : 0 G) (heg0 : 0 eg) (heg : eg eg') :
                                  sgdErr u lr Θ G eg sgdErr u' lr Θ' G eg'
                                  noncomputable def Proofs.FloatModel.reluMask {n : } (z v : Vec n) :
                                  Vec n

                                  ReLU backward mask — if z > 0 then v else 0. Compare + select: exact in floating point, so the float chain applies it bare (the rendered trainer's relu-back compare reads the rendered pre-activation, exactly the zt here).

                                  Equations
                                  Instances For
                                    theorem Proofs.FloatModel.reluMask_abs_le {n : } (z v : Vec n) (i : Fin n) :
                                    |reluMask z v i| |v i|
                                    theorem Proofs.FloatModel.reluMask_close {n : } {zt z vt v : Vec n} {ez ev : } (hz : ∀ (i : Fin n), |zt i - z i| ez) (hm : ∀ (i : Fin n), ez < |z i|) (hv : ∀ (i : Fin n), |vt i - v i| ev) (hev : 0 ev) (i : Fin n) :
                                    |reluMask zt vt i - reluMask z v i| ev

                                    The float-side kink condition. If the pre-activation error ez cannot flip any sign — ez < |zᵢ|, a quantitative margin, the float analogue of the suite's x k ≠ 0 off-the-kink hypotheses — then the float and real masks agree and the mask is 1-Lipschitz in the value.

                                    theorem Proofs.FloatModel.cot_step_close (M : FloatModel) {m n : } (W : Mat m n) (zt z : Vec m) (ct c : Vec n) {w C ec ez : } (hw : 0 w) (hC0 : 0 C) (hec : 0 ec) (hW : ∀ (i : Fin m) (j : Fin n), |W i j| w) (hC : ∀ (j : Fin n), |c j| C) (hc : ∀ (j : Fin n), |ct j - c j| ec) (hz : ∀ (i : Fin m), |zt i - z i| ez) (hm : ∀ (i : Fin m), ez < |z i|) (i : Fin m) :
                                    |reluMask zt (M.dense (fun (j : Fin n) (i' : Fin m) => W i' j) (fun (x : Fin m) => 0) ct) i - reluMask z (Proofs.dense (fun (j : Fin n) (i' : Fin m) => W i' j) (fun (x : Fin m) => 0) c) i| layerBudget M.u n w 0 C ec

                                    Cotangent through one layermask(z, Wᵀ·c), float vs real. The transposed matvec is dense with zero bias, so the dot machinery is reused wholesale; under the quantitative margin the mask passes the layerBudget through unchanged.

                                    theorem Proofs.FloatModel.mlp_w2_step_float_close (M : FloatModel) {d₀ d₁ d₂ d₃ : } {W₀ : Mat d₀ d₁} {b₀ : Vec d₁} {W₁ : Mat d₁ d₂} {b₁ : Vec d₂} (W₂ : Mat d₂ d₃) {x : Vec d₀} {gt g : Vec d₃} {lr w₀ β₀ w₁ β₁ a G eg : } (hw₀ : 0 w₀) (hβ₀ : 0 β₀) (hw₁ : 0 w₁) (hβ₁ : 0 β₁) (ha : 0 a) (hlr : 0 lr) (hW₀ : ∀ (i : Fin d₀) (j : Fin d₁), |W₀ i j| w₀) (hb₀ : ∀ (j : Fin d₁), |b₀ j| β₀) (hW₁ : ∀ (i : Fin d₁) (j : Fin d₂), |W₁ i j| w₁) (hb₁ : ∀ (j : Fin d₂), |b₁ j| β₁) (hx : ∀ (i : Fin d₀), |x i| a) (hG : ∀ (j : Fin d₃), |g j| G) (hg : ∀ (j : Fin d₃), |gt j - g j| eg) (i : Fin d₂) (j : Fin d₃) :
                                    |M.sub (W₂ i j) (M.mul lr (M.mul (relu d₂ (M.dense W₁ b₁ (relu d₁ (M.dense W₀ b₀ x))) i) (gt j))) - (W₂ i j - lr * (relu d₂ (Proofs.dense W₁ b₁ (relu d₁ (Proofs.dense W₀ b₀ x))) i * g j))| sgdErr M.u lr |W₂ i j| (layerAct d₁ w₁ β₁ (layerAct d₀ w₀ β₀ a) * G) (mulErr M.u (layerAct d₁ w₁ β₁ (layerAct d₀ w₀ β₀ a)) G (layerBudget M.u d₁ w₁ β₁ (layerAct d₀ w₀ β₀ a) (layerBudget M.u d₀ w₀ β₀ a 0)) eg)

                                    Rounded output-layer weight update (W₂). The float update fl(W₂ᵢⱼ − fl(lr·fl(ã₂ᵢ·gtⱼ))) — outer-product gradient from the stored float forward activation, as the rendered trainer computes it — is within an explicit budget of the real step W₂ᵢⱼ − lr·(a₂ᵢ·gⱼ). The real target is Mat.outer a₂ g i j = emitWeightGrad's entry, the quantity mlp_render_W2_certified proves equal to the pdiv-Jacobian contraction — so this chains the float step to the certified gradient. Takes the output cotangent gt ≈ g as a hypothesis (the softmax−onehot head needs an exp accuracy axiom — future rung).

                                    theorem Proofs.FloatModel.mlp_b2_step_float_close (M : FloatModel) {d₃ : } (b₂ : Vec d₃) {gt g : Vec d₃} {lr G eg : } (hlr : 0 lr) (hG : ∀ (j : Fin d₃), |g j| G) (hg : ∀ (j : Fin d₃), |gt j - g j| eg) (j : Fin d₃) :
                                    |M.sub (b₂ j) (M.mul lr (gt j)) - (b₂ j - lr * g j)| sgdErr M.u lr |b₂ j| G eg

                                    Rounded output-layer bias update (b₂) — the bias gradient is the cotangent (emitBiasGrad), so this is sgd_step_close directly.

                                    theorem Proofs.FloatModel.mlp_w1_step_float_close (M : FloatModel) {d₀ d₁ d₂ d₃ : } {W₀ : Mat d₀ d₁} {b₀ : Vec d₁} (W₁ : Mat d₁ d₂) {b₁ : Vec d₂} {W₂ : Mat d₂ d₃} {x : Vec d₀} {gt g : Vec d₃} {lr w₀ β₀ w₁ β₁ w₂ a G eg : } (hw₀ : 0 w₀) (hβ₀ : 0 β₀) (hw₁ : 0 w₁) (hw₂ : 0 w₂) (ha : 0 a) (hlr : 0 lr) (hG0 : 0 G) (heg : 0 eg) (hW₀ : ∀ (i : Fin d₀) (j : Fin d₁), |W₀ i j| w₀) (hb₀ : ∀ (j : Fin d₁), |b₀ j| β₀) (hW₁ : ∀ (i : Fin d₁) (j : Fin d₂), |W₁ i j| w₁) (hb₁ : ∀ (j : Fin d₂), |b₁ j| β₁) (hW₂ : ∀ (i : Fin d₂) (j : Fin d₃), |W₂ i j| w₂) (hx : ∀ (i : Fin d₀), |x i| a) (hG : ∀ (j : Fin d₃), |g j| G) (hg : ∀ (j : Fin d₃), |gt j - g j| eg) (hmargin : ∀ (i' : Fin d₂), layerBudget M.u d₁ w₁ β₁ (layerAct d₀ w₀ β₀ a) (layerBudget M.u d₀ w₀ β₀ a 0) < |Proofs.dense W₁ b₁ (relu d₁ (Proofs.dense W₀ b₀ x)) i'|) (i : Fin d₁) (j : Fin d₂) :
                                    |M.sub (W₁ i j) (M.mul lr (M.mul (relu d₁ (M.dense W₀ b₀ x) i) (reluMask (M.dense W₁ b₁ (relu d₁ (M.dense W₀ b₀ x))) (M.dense (fun (j' : Fin d₃) (i' : Fin d₂) => W₂ i' j') (fun (x : Fin d₂) => 0) gt) j))) - (W₁ i j - lr * (relu d₁ (Proofs.dense W₀ b₀ x) i * reluMask (Proofs.dense W₁ b₁ (relu d₁ (Proofs.dense W₀ b₀ x))) (Proofs.dense (fun (j' : Fin d₃) (i' : Fin d₂) => W₂ i' j') (fun (x : Fin d₂) => 0) g) j))| sgdErr M.u lr |W₁ i j| (layerAct d₀ w₀ β₀ a * layerAct d₃ w₂ 0 G) (mulErr M.u (layerAct d₀ w₀ β₀ a) (layerAct d₃ w₂ 0 G) (layerBudget M.u d₀ w₀ β₀ a 0) (layerBudget M.u d₃ w₂ 0 G eg))

                                    Rounded hidden-layer weight update (W₁), through the backward chain. The float cotangent ct₁ = mask(pt₁, W₂ᵀ·gt) — computed from the rendered pre-activation and the rounded transposed matvec, exactly the structure of the rendered backward — is within layerBudget of the real c₁ = mask(p₁, W₂ᵀ·g) (the mlpCotOut1 closed form), given the quantitative margin E₁ < |p₁ᵢ| at every layer-1 pre-activation: the forward rounding error must not flip a ReLU. Then the update is within sgdErr of the real W₁ᵢⱼ − lr·(a₁ᵢ·c₁ⱼ), the quantity mlp_render_W1_certified certifies. W₀/b₁/b₀ are the same instantiation one mask deeper.

                                    theorem Proofs.FloatModel.mlp_b1_step_float_close (M : FloatModel) {d₀ d₁ d₂ d₃ : } {W₀ : Mat d₀ d₁} {b₀ : Vec d₁} {W₁ : Mat d₁ d₂} (b₁ : Vec d₂) {W₂ : Mat d₂ d₃} {x : Vec d₀} {gt g : Vec d₃} {lr w₀ β₀ w₁ β₁ w₂ a G eg : } (hw₀ : 0 w₀) (hβ₀ : 0 β₀) (hw₁ : 0 w₁) (hw₂ : 0 w₂) (ha : 0 a) (hlr : 0 lr) (hG0 : 0 G) (heg : 0 eg) (hW₀ : ∀ (i : Fin d₀) (j : Fin d₁), |W₀ i j| w₀) (hb₀ : ∀ (j : Fin d₁), |b₀ j| β₀) (hW₁ : ∀ (i : Fin d₁) (j : Fin d₂), |W₁ i j| w₁) (hb₁ : ∀ (j : Fin d₂), |b₁ j| β₁) (hW₂ : ∀ (i : Fin d₂) (j : Fin d₃), |W₂ i j| w₂) (hx : ∀ (i : Fin d₀), |x i| a) (hG : ∀ (j : Fin d₃), |g j| G) (hg : ∀ (j : Fin d₃), |gt j - g j| eg) (hmargin : ∀ (i' : Fin d₂), layerBudget M.u d₁ w₁ β₁ (layerAct d₀ w₀ β₀ a) (layerBudget M.u d₀ w₀ β₀ a 0) < |Proofs.dense W₁ b₁ (relu d₁ (Proofs.dense W₀ b₀ x)) i'|) (j : Fin d₂) :
                                    |M.sub (b₁ j) (M.mul lr (reluMask (M.dense W₁ b₁ (relu d₁ (M.dense W₀ b₀ x))) (M.dense (fun (j' : Fin d₃) (i' : Fin d₂) => W₂ i' j') (fun (x : Fin d₂) => 0) gt) j)) - (b₁ j - lr * reluMask (Proofs.dense W₁ b₁ (relu d₁ (Proofs.dense W₀ b₀ x))) (Proofs.dense (fun (j' : Fin d₃) (i' : Fin d₂) => W₂ i' j') (fun (x : Fin d₂) => 0) g) j)| sgdErr M.u lr |b₁ j| (layerAct d₃ w₂ 0 G) (layerBudget M.u d₃ w₂ 0 G eg)

                                    Rounded hidden bias update (b₁) — the gradient is the layer-1 cotangent itself (emitBiasGrad), so this is the cotangent chain followed by sgd_step_close.

                                    theorem Proofs.FloatModel.mlp_w0_step_float_close (M : FloatModel) {d₀ d₁ d₂ d₃ : } (W₀ : Mat d₀ d₁) {b₀ : Vec d₁} {W₁ : Mat d₁ d₂} {b₁ : Vec d₂} {W₂ : Mat d₂ d₃} {x : Vec d₀} {gt g : Vec d₃} {lr w₀ β₀ w₁ β₁ w₂ a G eg : } (hw₀ : 0 w₀) (hβ₀ : 0 β₀) (hw₁ : 0 w₁) (hw₂ : 0 w₂) (ha : 0 a) (hlr : 0 lr) (hG0 : 0 G) (heg : 0 eg) (hW₀ : ∀ (i : Fin d₀) (j : Fin d₁), |W₀ i j| w₀) (hb₀ : ∀ (j : Fin d₁), |b₀ j| β₀) (hW₁ : ∀ (i : Fin d₁) (j : Fin d₂), |W₁ i j| w₁) (hb₁ : ∀ (j : Fin d₂), |b₁ j| β₁) (hW₂ : ∀ (i : Fin d₂) (j : Fin d₃), |W₂ i j| w₂) (hx : ∀ (i : Fin d₀), |x i| a) (hG : ∀ (j : Fin d₃), |g j| G) (hg : ∀ (j : Fin d₃), |gt j - g j| eg) (hmargin₁ : ∀ (i' : Fin d₂), layerBudget M.u d₁ w₁ β₁ (layerAct d₀ w₀ β₀ a) (layerBudget M.u d₀ w₀ β₀ a 0) < |Proofs.dense W₁ b₁ (relu d₁ (Proofs.dense W₀ b₀ x)) i'|) (hmargin₀ : ∀ (i' : Fin d₁), layerBudget M.u d₀ w₀ β₀ a 0 < |Proofs.dense W₀ b₀ x i'|) (i : Fin d₀) (j : Fin d₁) :
                                    |M.sub (W₀ i j) (M.mul lr (M.mul (x i) (reluMask (M.dense W₀ b₀ x) (M.dense (fun (j' : Fin d₂) (i' : Fin d₁) => W₁ i' j') (fun (x : Fin d₁) => 0) (reluMask (M.dense W₁ b₁ (relu d₁ (M.dense W₀ b₀ x))) (M.dense (fun (j' : Fin d₃) (i' : Fin d₂) => W₂ i' j') (fun (x : Fin d₂) => 0) gt))) j))) - (W₀ i j - lr * (x i * reluMask (Proofs.dense W₀ b₀ x) (Proofs.dense (fun (j' : Fin d₂) (i' : Fin d₁) => W₁ i' j') (fun (x : Fin d₁) => 0) (reluMask (Proofs.dense W₁ b₁ (relu d₁ (Proofs.dense W₀ b₀ x))) (Proofs.dense (fun (j' : Fin d₃) (i' : Fin d₂) => W₂ i' j') (fun (x : Fin d₂) => 0) g))) j))| sgdErr M.u lr |W₀ i j| (a * layerAct d₂ w₁ 0 (layerAct d₃ w₂ 0 G)) (mulErr M.u a (layerAct d₂ w₁ 0 (layerAct d₃ w₂ 0 G)) 0 (layerBudget M.u d₂ w₁ 0 (layerAct d₃ w₂ 0 G) (layerBudget M.u d₃ w₂ 0 G eg)))

                                    Rounded input-layer weight update (W₀) — the cotangent crosses BOTH masks, so both quantitative margins are required; the activation operand is the raw input x, identical in both nets (zero inherited error). The real target W₀ᵢⱼ − lr·(xᵢ·c₀ⱼ) is the mlp_render_W0_certified quantity.

                                    theorem Proofs.FloatModel.mlp_b0_step_float_close (M : FloatModel) {d₀ d₁ d₂ d₃ : } {W₀ : Mat d₀ d₁} (b₀ : Vec d₁) {W₁ : Mat d₁ d₂} {b₁ : Vec d₂} {W₂ : Mat d₂ d₃} {x : Vec d₀} {gt g : Vec d₃} {lr w₀ β₀ w₁ β₁ w₂ a G eg : } (hw₀ : 0 w₀) (hβ₀ : 0 β₀) (hw₁ : 0 w₁) (hw₂ : 0 w₂) (ha : 0 a) (hlr : 0 lr) (hG0 : 0 G) (heg : 0 eg) (hW₀ : ∀ (i : Fin d₀) (j : Fin d₁), |W₀ i j| w₀) (hb₀ : ∀ (j : Fin d₁), |b₀ j| β₀) (hW₁ : ∀ (i : Fin d₁) (j : Fin d₂), |W₁ i j| w₁) (hb₁ : ∀ (j : Fin d₂), |b₁ j| β₁) (hW₂ : ∀ (i : Fin d₂) (j : Fin d₃), |W₂ i j| w₂) (hx : ∀ (i : Fin d₀), |x i| a) (hG : ∀ (j : Fin d₃), |g j| G) (hg : ∀ (j : Fin d₃), |gt j - g j| eg) (hmargin₁ : ∀ (i' : Fin d₂), layerBudget M.u d₁ w₁ β₁ (layerAct d₀ w₀ β₀ a) (layerBudget M.u d₀ w₀ β₀ a 0) < |Proofs.dense W₁ b₁ (relu d₁ (Proofs.dense W₀ b₀ x)) i'|) (hmargin₀ : ∀ (i' : Fin d₁), layerBudget M.u d₀ w₀ β₀ a 0 < |Proofs.dense W₀ b₀ x i'|) (j : Fin d₁) :
                                    |M.sub (b₀ j) (M.mul lr (reluMask (M.dense W₀ b₀ x) (M.dense (fun (j' : Fin d₂) (i' : Fin d₁) => W₁ i' j') (fun (x : Fin d₁) => 0) (reluMask (M.dense W₁ b₁ (relu d₁ (M.dense W₀ b₀ x))) (M.dense (fun (j' : Fin d₃) (i' : Fin d₂) => W₂ i' j') (fun (x : Fin d₂) => 0) gt))) j)) - (b₀ j - lr * reluMask (Proofs.dense W₀ b₀ x) (Proofs.dense (fun (j' : Fin d₂) (i' : Fin d₁) => W₁ i' j') (fun (x : Fin d₁) => 0) (reluMask (Proofs.dense W₁ b₁ (relu d₁ (Proofs.dense W₀ b₀ x))) (Proofs.dense (fun (j' : Fin d₃) (i' : Fin d₂) => W₂ i' j') (fun (x : Fin d₂) => 0) g))) j)| sgdErr M.u lr |b₀ j| (layerAct d₂ w₁ 0 (layerAct d₃ w₂ 0 G)) (layerBudget M.u d₂ w₁ 0 (layerAct d₃ w₂ 0 G) (layerBudget M.u d₃ w₂ 0 G eg))

                                    Rounded input bias update (b₀) — the layer-0 cotangent directly.

                                    theorem Proofs.FloatModel.mnist_w2_step_float_budget (M : FloatModel) (hMu : M.u u32) (W₀ : Mat 784 512) (b₀ : Vec 512) (W₁ : Mat 512 512) (b₁ : Vec 512) (W₂ : Mat 512 10) (x : Vec 784) (g : Vec 10) (hW₀ : ∀ (i : Fin 784) (j : Fin 512), |W₀ i j| 3 / 5) (hb₀ : ∀ (j : Fin 512), |b₀ j| 1) (hW₁ : ∀ (i j : Fin 512), |W₁ i j| 3 / 5) (hb₁ : ∀ (j : Fin 512), |b₁ j| 1) (hW₂ : ∀ (i : Fin 512) (j : Fin 10), |W₂ i j| 3 / 5) (hx : ∀ (i : Fin 784), |x i| 1) (hG : ∀ (j : Fin 10), |g j| 1) (i : Fin 512) (j : Fin 10) :
                                    |M.sub (W₂ i j) (M.mul (1 / 10) (M.mul (relu 512 (M.dense W₁ b₁ (relu 512 (M.dense W₀ b₀ x))) i) (g j))) - (W₂ i j - 1 / 10 * (relu 512 (Proofs.dense W₁ b₁ (relu 512 (Proofs.dense W₀ b₀ x))) i * g j))| 5 / 4

                                    Numeric gradient capstone at the committed dims and TRAINED magnitudes (784→512→512→10, |W| ≤ 3/5 covering the measured max|W| = 0.52): binary32 accuracy (u ≤ 2⁻²⁴), lr = 1/10, |b|, |x| ≤ 1, |g| ≤ 1 (a softmax−onehot cotangent is always in [−1,1]), cotangent taken exact — then every rounded W₂ SGD entry is within 5/4 of the certified real step.

                                    The budget decomposes honestly: ~1.2 of it is lr·E₁·|g| — the forward budget riding through the gradient at learning-rate scale — while fresh backward rounding contributes only ~2·10⁻³. The gradient step is as accurate as the forward pass, no worse. Measured on the live run (scripts/margin_probe.py): actual W₂ step deviation ≤ 7.5·10⁻⁹ — the worst-case-vs-measured gap is the a-posteriori case in numbers.

                                    noncomputable def Proofs.FloatModel.div (M : FloatModel) (x y : ) :

                                    Rounded division: fl(x / y).

                                    Equations
                                    Instances For
                                      noncomputable def Proofs.FloatModel.sum (M : FloatModel) {n : } :
                                      Vec n

                                      Rounded sum, left-fold association. Like dot, the bound below holds for every association.

                                      Equations
                                      Instances For
                                        theorem Proofs.FloatModel.sum_succ (M : FloatModel) {n : } (x : Vec (n + 1)) :
                                        M.sum x = M.add (M.sum fun (i : Fin n) => x i.castSucc) (x (Fin.last n))
                                        theorem Proofs.FloatModel.sum_close (M : FloatModel) {n : } (x : Vec n) :
                                        |M.sum x - i : Fin n, x i| ((1 + M.u) ^ (n + 1) - 1) * i : Fin n, |x i|

                                        Rounded sum forward error((1+u)^(n+1) − 1)·Σ|xᵢ|, association- independent (exponent n+1 because the seed addition with 0 rounds).

                                        theorem Proofs.FloatModel.dotSgd_step_close (M : FloatModel) (θ : ) {n : } (p q : Vec n) {lr G : } (hG : |i : Fin n, p i * q i| G) (hlr : 0 lr) :
                                        |M.sub θ (M.mul lr (M.dot p q)) - (θ - lr * i : Fin n, p i * q i)| sgdErr M.u lr |θ| G (((1 + M.u) ^ (n + 1) - 1) * i : Fin n, |p i * q i|)

                                        SGD step whose gradient is a rounded dot product. When the gradient is a correlation g = Σ pᵢqᵢ computed in float as M.dot p q — the shape of a conv weight gradient (Σ_{hi,wi} convPad · cot) and of any dense weight gradient — the rounded update fl(θ − fl(lr·fl(p·q))) is within sgdErr of the real step θ − lr·g, with the dot's Higham γ as the gradient-error slot eg. This is dot_close feeding sgd_step_close.

                                        theorem Proofs.FloatModel.sumSgd_step_close (M : FloatModel) (θ : ) {n : } (x : Vec n) {lr G : } (hG : |i : Fin n, x i| G) (hlr : 0 lr) :
                                        |M.sub θ (M.mul lr (M.sum x)) - (θ - lr * i : Fin n, x i)| sgdErr M.u lr |θ| G (((1 + M.u) ^ (n + 1) - 1) * i : Fin n, |x i|)

                                        SGD step whose gradient is a rounded sum. When the gradient is a plain reduction g = Σ xᵢ computed in float as M.sum x — the shape of a conv bias gradient (Σ_{hi,wi} cot) — the rounded update is within sgdErr of the real step, with the sum's Higham γ as the eg slot.

                                        noncomputable def Proofs.FloatModel.softmaxF (M : FloatModel) (fexp : ) {n : } (z : Vec n) :
                                        Vec n

                                        The float softmax: rounded exp, rounded sum, rounded division — the structure of the rendered loss head. fexp is hypothesis-supplied (GPU exp has no IEEE spec; its accuracy constant is exactly what the repo's vjp_oracle harness validates empirically).

                                        Equations
                                        Instances For
                                          noncomputable def Proofs.FloatModel.softmaxCECotF (M : FloatModel) (fexp : ) {n : } (z : Vec n) (label : Fin n) :
                                          Vec n

                                          The float softmax−onehot cotangent (one final rounded subtract; the onehot operand is exact).

                                          Equations
                                          Instances For
                                            theorem Proofs.FloatModel.softmax_perturb {n : } (zt z : Vec n) {δ : } ( : ∀ (k' : Fin n), |zt k' - z k'| δ) (k : Fin n) :
                                            |softmax n zt k - softmax n z k| Real.exp (2 * δ) - 1

                                            Softmax perturbation, elementary ratio form: a coordinatewise logit error δ moves every softmax output by at most e^(2δ) − 1. Proved by sandwiching softmax(z̃) ∈ [e^(−2δ), e^(2δ)]·softmax(z) with bare exp monotonicity — no mean-value theorem.

                                            noncomputable def Proofs.FloatModel.smRho (u eexp : ) (n : ) :

                                            Denominator perturbation of the float softmax: rounded-sum compounding on exp-inaccurate terms.

                                            Equations
                                            Instances For
                                              noncomputable def Proofs.FloatModel.smKappa (u eexp : ) (n : ) :

                                              Relative budget of the pre-rounding float softmax against the real softmax at the same logits.

                                              Equations
                                              Instances For
                                                noncomputable def Proofs.FloatModel.smErr (u eexp δ : ) (n : ) :

                                                Absolute budget of the float softmax against the real softmax at the REAL logits: head rounding + the e^(2δ) − 1 logit-perturbation term.

                                                Equations
                                                Instances For
                                                  noncomputable def Proofs.FloatModel.cotErr (u eexp δ : ) (n : ) :

                                                  Budget of the full rounded softmax−onehot cotangent against the certified real gradient.

                                                  Equations
                                                  Instances For
                                                    theorem Proofs.FloatModel.cotErr_nonneg (M : FloatModel) {eexp δ : } {n : } (heexp : 0 eexp) (hδ0 : 0 δ) (hρ1 : smRho M.u eexp n < 1) :
                                                    0 cotErr M.u eexp δ n

                                                    cotErr is nonnegative (it bounds an absolute value) — under eexp ≥ 0, δ ≥ 0, and the denominator condition smRho < 1. The cot_step_close precondition for any backward grad-close that runs the softmax−onehot head (e.g. the per-layer η-composition rungs).

                                                    theorem Proofs.FloatModel.softmaxF_close (M : FloatModel) (fexp : ) {eexp : } {n : } (z : Vec n) (heexp0 : 0 eexp) (heexp1 : eexp 1) (hfexp : ∀ (t : ), |fexp t - Real.exp t| eexp * Real.exp t) (hρ1 : smRho M.u eexp n < 1) (k : Fin n) :
                                                    |M.softmaxF fexp z k - softmax n z k| M.u * (1 + smKappa M.u eexp n) + smKappa M.u eexp n

                                                    Float softmax vs real softmax at the same logits (part A): the rounded exp/sum/div head is within u·(1+κ) + κ absolutely, where κ = (eexp + ρ)/(1 − ρ) compounds the exp accuracy and the sum rounding. The sandwich is the same ratio argument as softmax_perturb — division-perturbation never appears.

                                                    theorem Proofs.FloatModel.softmax_ce_cot_close (M : FloatModel) (fexp : ) {eexp δ : } {n : } (zt z : Vec n) (label : Fin n) (heexp0 : 0 eexp) (heexp1 : eexp 1) (hfexp : ∀ (t : ), |fexp t - Real.exp t| eexp * Real.exp t) (hρ1 : smRho M.u eexp n < 1) ( : ∀ (k' : Fin n), |zt k' - z k'| δ) (k : Fin n) :
                                                    |M.softmaxCECotF fexp zt label k - (softmax n z k - oneHot n label k)| cotErr M.u eexp δ n

                                                    The rounded softmax−onehot cotangent is within cotErr of the certified real gradient softmax(z) − onehot — the pdiv-certified ∂(crossEntropy)/∂logits (softmaxCE_grad). This discharges the g̃ ≈ g hypothesis of the mlp_*_step_float_close capstones: eg := cotErr u eexp δ n, where δ bounds the float-vs-real logits (worst case: the forward layerBudget; in practice: an a-posteriori measured value, since e^(2δ) − 1 is only sharp for small δ).

                                                    theorem Proofs.FloatModel.softmax_abs_le_one {n : } (z : Vec n) (k : Fin n) :
                                                    |softmax n z k| 1

                                                    |softmax z k| ≤ 1 — the real softmax is a probability (public face of the softmax_nonneg/softmax_le_one pair, the magnitude attention's output matmul needs).

                                                    theorem Proofs.FloatModel.smErr_nonneg (M : FloatModel) {eexp δ : } {n : } (heexp0 : 0 eexp) (hδ0 : 0 δ) (hρ1 : smRho M.u eexp n < 1) :
                                                    0 smErr M.u eexp δ n

                                                    smErr is nonnegative under eexp ≥ 0, δ ≥ 0, and smRho < 1 — the absolute softmax-vs-softmax budget bounds an absolute value, so it is itself ≥ 0. (Extracted from softmax_ce_cot_close's internal hsm0; needed as the 0 ≤ eweight precondition of any downstream dot at perturbed softmax weights, e.g. attention's output matmul.)

                                                    theorem Proofs.FloatModel.softmaxF_close_at (M : FloatModel) (fexp : ) {eexp δ : } {n : } (zt z : Vec n) (heexp0 : 0 eexp) (heexp1 : eexp 1) (hfexp : ∀ (t : ), |fexp t - Real.exp t| eexp * Real.exp t) (hρ1 : smRho M.u eexp n < 1) ( : ∀ (k' : Fin n), |zt k' - z k'| δ) (k : Fin n) :
                                                    |M.softmaxF fexp zt k - softmax n z k| smErr M.u eexp δ n

                                                    Float softmax at float logits vs real softmax at real logits — within smErr. The rounding half (softmaxF_close, float-vs-real at the same logits) plus the logit-perturbation half (softmax_perturb, real-vs-real under a coordinatewise logit error δ), assembled by the triangle inequality. This is the per-row engine for attention's softmax (each row's logits are the float scores, off the real scores by δ); extracted from softmax_ce_cot_close's internal hsm (here without the onehot subtraction, so it applies to any softmax position, not just the loss head).

                                                    theorem Proofs.FloatModel.exp_sub_one_le {x : } (hx1 : x < 1) :
                                                    Real.exp x - 1 x / (1 - x)

                                                    e^x − 1 ≤ x/(1−x) for 0 ≤ x < 1 — the exp analogue of the γ-form, from 1 − x ≤ e^(−x) alone; keeps the numeric head budget in norm_num country.

                                                    theorem Proofs.FloatModel.mnist_cot_budget (M : FloatModel) (hMu : M.u u32) (fexp : ) {eexp : } (heexp0 : 0 eexp) (heexp : eexp 1 / 1000000) (hfexp : ∀ (t : ), |fexp t - Real.exp t| eexp * Real.exp t) (zt z : Vec 10) (label : Fin 10) (hz : ∀ (k' : Fin 10), |zt k' - z k'| 1 / 100) (k : Fin 10) :
                                                    |M.softmaxCECotF fexp zt label k - (softmax 10 z k - oneHot 10 label k)| 21 / 1000

                                                    Numeric head budget at the committed MNIST output (n = 10): for any model at binary32 accuracy, exp accurate to eexp ≤ 10⁻⁶ (GPU exp is ~1–2 ULP; the constant is what vjp_oracle validates), and float logits within δ = 1/100 of real, the rounded softmax−onehot cotangent is within 21/1000 of the certified gradient — almost all of it the e^(2δ) − 1 ≈ 2δ logit-perturbation term; the head's own rounding contributes < 4·10⁻⁶.

                                                    δ = 1/100 is an a-posteriori-style hypothesis: the worst-case forward logit budget (≈5100 at trained magnitudes) makes e^(2δ) − 1 vacuous, so a useful head budget needs the measured logit error — exactly the hand-off point from worst-case to a-posteriori analysis. Empirically validated (scripts/margin_probe.py): measured drift on a real 12-epoch run is ≤ 1.6·10⁻⁵, 600× inside the 1/100 hypothesis.

                                                    theorem Proofs.FloatModel.argmax_preserved {n : } {z z' : Vec n} {k : Fin n} {B : } (hB : ∀ (i : Fin n), |z' i - z i| B) (hmargin : ∀ (i : Fin n), i k2 * B < z k - z i) (i : Fin n) :
                                                    i kz' i < z' k

                                                    Argmax preservation under a bounded logit perturbation (planning §3c). If every coordinate of the perturbed logits z' is within B of the reference logits z, and z's strict top-1 margin at k exceeds 2B (z k − z i > 2B for every other class i), then k is still the strict argmax of z'. The depth-1 honest fp8 claim: a B-accurate matmul cannot flip the prediction on a >2B-margin input. B is a hypothesis, so the statement holds both for the proven worst-case bound (dense_close_mixed) and for any measured a-posteriori drift — the demo's empirical B = max|Δlogit| plugs into the same theorem. Conditional like the suite's quantitative ReLU margins.

                                                    noncomputable def Proofs.FloatModel.denseMixedBudget (uacc uleaf : ) (m : ) (w β a : ) :

                                                    Uniform (magnitude-bounded) per-logit budget of the mixed-precision dense layer — dense_close_mixed specialized by ∑ᵢ|xᵢWᵢⱼ| ≤ m·w·a, |bⱼ| ≤ β, so it is one constant B over all outputs j (the input argmax_preserved needs). The accumulate u_acc rides the bias add and the fan-in γ-factor (1+u_acc)^(m+1); the leaf u_leaf enters only via the flat (2·u_leaf + u_leaf²) term — the two-roundoff separation of §1c.

                                                    Equations
                                                    Instances For
                                                      theorem Proofs.FloatModel.dense_close_mixed_uniform_budget (M L : FloatModel) {m n : } {W : Mat m n} {b : Vec n} {x : Vec m} {w β a : } (ha : 0 a) (hW : ∀ (i : Fin m) (j : Fin n), |W i j| w) (hb : ∀ (j : Fin n), |b j| β) (hx : ∀ (i : Fin m), |x i| a) (j : Fin n) :
                                                      |M.denseMixed L W b x j - Proofs.dense W b x j| denseMixedBudget M.u L.u m w β a

                                                      Mixed-precision dense forward error, uniform-magnitude budget. Under |Wᵢⱼ| ≤ w, |bⱼ| ≤ β, |xᵢ| ≤ a, every E4M3-mixed logit is within the closed-form denseMixedBudget of the exact-ℝ logit — evaluable by norm_num at a concrete net.

                                                      theorem Proofs.FloatModel.denseMixedBudget_le_of {uacc uleaf : } {m : } {w β a g P Q U : } (hU : 0 U) (huacc0 : 0 uacc) (huleaf0 : 0 uleaf) (huacc : uacc U) (hw : 0 w) ( : 0 β) (ha : 0 a) (hg0 : 0 g) (hg : (1 + uacc) ^ (m + 1) - 1 g) (hP : (1 + uleaf) ^ 2 P) (hQ : 2 * uleaf + uleaf ^ 2 Q) :
                                                      denseMixedBudget uacc uleaf m w β a U * (m * w * a + β) + (1 + U) * ((g * P + Q) * (m * w * a))

                                                      Monotone upper bound for denseMixedBudget, keeping the (1+uacc)^(m+1) power abstract: replace the accumulate by U ≥ uacc, the fan-in γ-factor by g ≥ (1+uacc)^(m+1)−1, and the two leaf pieces by P ≥ (1+uleaf)², Q ≥ 2·uleaf+uleaf². The result has no power left, so a concrete instance (e.g. m = 784) evaluates by norm_num without unfolding the 785-fold npow — the layerBudget_le_of analogue for the two-roundoff budget.

                                                      theorem Proofs.FloatModel.linear_e4m3_logit_budget (M L : FloatModel) (hMu : M.u u32) (hLu : L.u u_e4m3) :
                                                      denseMixedBudget M.u L.u 784 (3 / 5) 1 1 61

                                                      The worst-case E4M3 per-logit budget at the MNIST-linear dims (784→n; E4M3 leaf u_leaf ≤ 2⁻⁴, fp32 accumulate u_acc ≤ 2⁻²⁴; pixels |x| ≤ 1, trained |W| ≤ 3/5, |b| ≤ 1): every E4M3-mixed logit is within 61 of the exact-ℝ logit. The leaf term (2·2⁻⁴ ≈ 12.5%)·∑|xW| dominates (the fp32 fan-in γ at 784 is ≈5·10⁻⁵, negligible) — this is the worst-case, all-errors- aligned figure. The demo (scripts/mnist_e4m3_demo.py) measures the actual drift at max|Δlogit| = 0.38 (errors cancel), the a-posteriori B; both feed argmax_preserved.

                                                      theorem Proofs.FloatModel.linear_e4m3_argmax_preserved (M L : FloatModel) (hMu : M.u u32) (hLu : L.u u_e4m3) {n : } {W : Mat 784 n} {b : Vec n} {x : Vec 784} (hW : ∀ (i : Fin 784) (j : Fin n), |W i j| 3 / 5) (hb : ∀ (j : Fin n), |b j| 1) (hx : ∀ (i : Fin 784), |x i| 1) (k : Fin n) (hmargin : ∀ (i : Fin n), i k122 < Proofs.dense W b x k - Proofs.dense W b x i) (i : Fin n) :
                                                      i kM.denseMixed L W b x i < M.denseMixed L W b x k

                                                      Verified E4M3 MNIST-linear argmax preservation (planning §3c capstone). For the certified linear classifier at E4M3 leaf precision / fp32 accumulate, pixels |x| ≤ 1, trained |W| ≤ 3/5, |b| ≤ 1: whenever the exact-ℝ logit margin at the top class k exceeds 2·61 = 122, the E4M3-mixed forward keeps k as the strict argmax — provably the same prediction. Depth-1 makes the single-matmul bound the end-to-end bound, so this is the one realistic fp8 case with an honest accuracy guarantee (no vacuous depth compounding). The 122 is the worst-case threshold; with the demo's measured B = 0.38 the same argmax_preserved covers the >0.76-margin inputs — empirically 92.89% of the MNIST test set (scripts/mnist_e4m3_demo.py). fp32 ≈ exact-ℝ (within u_acc), so the demo's fp32 margins are the relevant quantity.

                                                      The exact-arithmetic model: rnd = id, u = 0. Inhabits the interface (the standard model isn't vacuous) and collapses every budget to 0.

                                                      Equations
                                                      Instances For
                                                        @[simp]
                                                        theorem Proofs.FloatModel.exactModel_dot {n : } (x y : Vec n) :
                                                        exactModel.dot x y = i : Fin n, x i * y i
                                                        @[simp]
                                                        theorem Proofs.FloatModel.exactModel_denseErr {m n : } (W : Mat m n) (b : Vec n) (xa : Vec m) (j : Fin n) :
                                                        exactModel.denseErr W b xa 0 j = 0
                                                        @[simp]
                                                        theorem Proofs.FloatModel.dotMixed_exact_leaf (M : FloatModel) {n : } (x y : Vec n) :
                                                        M.dotMixed exactModel x y = M.dot x y

                                                        dotMixed with an exact leaf (u_leaf = 0) is the plain rounded dot. The fp32 specialization: no input rounding ⇒ dot_close_mixed collapses to dot_close (the leaf term 2·0 + 0² = 0 vanishes, the leaf-rounded magnitudes become the real ones). Confirms the two-roundoff budget is a genuine generalization of the single-u budget, not a reparametrization.