Documentation

LeanMlir.Proofs.Float.FloatBridge

ℝ → Float32 bridge: standard-model rounding bounds (the float tier's root) #

Every theorem in LeanMlir/Proofs/ is over exact reals; the executed kernels are binary32. This file is the root of the float tier: a standard-model formalization of rounded arithmetic, forward error bounds for the dense/relu compositions the train-step proofs certify, and the backward-op and softmax-cotangent bounds. The chains that assemble them for the MNIST MLP and the E4M3 linear net are MlpFloatBridge.

The tier, in import order: this file (FloatModel, per-op *_close) → FloatComposeBridge (FloatClose, the one closeness form, and .comp) → the per-layer bridges (BnFloatBridge, ConvMixedFloatBridge, DepthwiseFloatBridge) → RndP / Binary32Instance (binary32 and fp8E4M3 as named FloatModels; rndP is the grid rounding operator behind them and behind the bf16 sharding lemmas).

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 floor is outside the model; no subnormal-aware model is stated). 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.uE4M3 :

      The normal-range unit roundoff of fp8 E4M3 (1-4-3, 3 mantissa bits): 2⁻⁴ = 1/16 (6.25%) — the leaf precision of the E4M3 MNIST demo (scripts/demos/mnist_e4m3_demo.py). Outside the normal range (subnormals, near the 448 max) the relative model does not hold.

      Equations
      Instances For

        The unit roundoff is nonnegative: err 1 gives |rnd 1 − 1| ≤ u.

        @[simp]

        The rounding of 0 is 0 (forced by the relative-error model at x = 0).

        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 n → Vec n → ℝ

            Rounded dot product, left-fold association (((x₀y₀ + x₁y₁) + …)). dot_close is stated for this fold.

            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)))
              theorem Proofs.FloatModel.dot_right_zero (M : FloatModel) {k : ℕ} (x : Vec k) :
              (M.dot x fun (x : Fin k) => 0) = 0

              A rounded dot product against the all-zero vector is 0.

              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
                theorem Proofs.FloatModel.rnd_close (M : FloatModel) {a b A e : ℝ} (hab : |a - b| ≤ e) (hA : |a| ≤ A) :
                |M.rnd a - b| ≤ M.u * A + e

                One rounding on top of an inherited error. If the operand a is within e of the exact b and |a| ≤ A, then fl(a) is within u·A + e of b — the step every rounded add/sub/mul/div close takes (each is M.rnd of the exact operation).

                theorem Proofs.FloatModel.abs_rnd_le (M : FloatModel) (x : ℝ) :
                |M.rnd x| ≤ (1 + M.u) * |x|

                Rounding grows a magnitude by at most the factor 1 + u.

                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), for the left fold M.dot. (The classical bound holds for every summation order; only the left fold is formalized here.) The exponent is n+1 rather than the optimal n because dot rounds the seed addition with 0 too.

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

                      theorem Proofs.FloatModel.div_one_sub_mono {x y : ℝ} (hxy : x ≤ y) (hy : y < 1) :
                      x / (1 - x) ≤ y / (1 - y)

                      x ↦ x/(1−x) is monotone on [0, 1) — lets a u ≤ u32 hypothesis ride through the γ-form.

                      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) (hβ : 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) (hβ : 0 ≤ β) (hA : 0 ≤ A) (hE : 0 ≤ E) :
                          0 ≤ layerBudget u m w β A E
                          theorem Proofs.FloatModel.layerBudget_le_of {u : ℝ} {m : ℕ} {w β A E g Ē : ℝ} (hu : 0 ≤ u) (hw : 0 ≤ w) (hβ : 0 ≤ β) (hA : 0 ≤ A) (hG : (1 + u) ^ (m + 2) - 1 ≤ g) (hE0 : 0 ≤ E) (hE : E ≤ Ē) :
                          layerBudget u m w β A E ≤ g * (↑m * w * (A + Ē) + β) + ↑m * w * Ē

                          Replacing the power term and the inherited error in layerBudget by upper bounds gives an upper bound — the monotonicity step the numeric instantiations chain through.

                          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.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 u ≤ u32.

                          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.add_close (M : FloatModel) {xt x yt y ex ey : ℝ} (hx : |xt - x| ≤ ex) (hy : |yt - y| ≤ ey) :
                                |M.add xt yt - (x + y)| ≤ M.u * (|x| + ex + |y| + ey) + (ex + ey)

                                Rounded addition with inherited operand errors. fl(xt ⊕ yt) is within u·(|x| + ex + |y| + ey) + (ex + ey) of the exact x + y, given |xt − x| ≤ ex and |yt − y| ≤ ey. The additive peer of mul_close; the residual fan-in's float budget.

                                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.mulErr_nonneg {u A C ea ec : ℝ} (hu : 0 ≤ u) (hA : 0 ≤ A) (hC : 0 ≤ C) (hea : 0 ≤ ea) (hec : 0 ≤ ec) :
                                0 ≤ mulErr u A C ea ec
                                theorem Proofs.FloatModel.mulErr_mono {u u' A C ea ea' ec : ℝ} (hu : 0 ≤ u) (huu : u ≤ u') (hA : 0 ≤ A) (hC : 0 ≤ C) (hea0 : 0 ≤ ea) (hea : ea ≤ ea') (hec : 0 ≤ ec) :
                                mulErr u A C ea ec ≤ mulErr u' A C ea' ec
                                theorem Proofs.FloatModel.sgdErr_mono {u u' lr Θ Θ' G eg eg' : ℝ} (hu : 0 ≤ u) (huu : u ≤ u') (hlr : 0 ≤ lr) (hΘ0 : 0 ≤ Θ) (hΘ : Θ ≤ Θ') (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 layer — mask(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.

                                  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. sum_close is stated for this fold.

                                    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ᵢ| for the left fold M.sum (exponent n+1 because the seed addition with 0 rounds).

                                      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 relative accuracy eexp is assumed by the theorems that use it, not measured by any harness in the repo.

                                      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.abs_softmax_sub_oneHot_le_one {n : ℕ} (z : Vec n) (label k : Fin n) :
                                          |softmax n z k - oneHot n label k| ≤ 1

                                          |softmax − oneHot| ≤ 1 — the magnitude of every softmax-CE head cotangent: softmax lies in [0, 1] and a one-hot entry is 0 or 1.

                                          theorem Proofs.FloatModel.softmax_perturb {n : ℕ} (zt z : Vec n) {δ : ℝ} (hδ : ∀ (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.smRho_nonneg (M : FloatModel) {eexp : ℝ} {n : ℕ} (heexp : 0 ≤ eexp) :
                                                  0 ≤ smRho M.u eexp n
                                                  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.

                                                  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) (hδ : ∀ (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.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 ≠ k → 2 * B < z k - z i) (i : Fin n) :
                                                  i ≠ k → z' i < z' k

                                                  Argmax preservation under a bounded logit perturbation. 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 (leaf and accumulate roundoffs kept separate).

                                                  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) (hβ : 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.

                                                    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.

                                                      theorem Proofs.abs_le_of_close {a b e C : ℝ} (h1 : |a - b| ≤ e) (h2 : |b| ≤ C) :
                                                      |a| ≤ C + e

                                                      |a| ≤ C + e from |a − b| ≤ e and |b| ≤ C — lifts a closeness + a base magnitude to a float magnitude (the float cotangent bound from the real bound plus the drift).

                                                      theorem Proofs.FloatModel.dot_perturbed_close {n : ℕ} (M : FloatModel) (A Bt B : Vec n) {a Ct eB : ℝ} (ha : 0 ≤ a) (hA : ∀ (i : Fin n), |A i| ≤ a) (hBt : ∀ (i : Fin n), |Bt i| ≤ Ct) (hB : ∀ (i : Fin n), |Bt i - B i| ≤ eB) :
                                                      |M.dot A Bt - ∑ i : Fin n, A i * B i| ≤ ((1 + M.u) ^ (n + 1) - 1) * (↑n * (a * Ct)) + ↑n * (a * eB)

                                                      Float dot against a perturbed cotangent — the conv-2 grad-close's final contraction (the conv peer of the MLP's scalar mul_close: a dot, because of weight sharing). M.dot A B̃ (exact left operand A, float cotangent B̃) vs the certified ∑ Aᵢ·Bᵢ splits into the Higham dot rounding on A·B̃ (dot_close, fan-in n) plus the per-entry cotangent drift |B̃ᵢ − Bᵢ| ≤ eB. With |Aᵢ| ≤ a and |B̃ᵢ| ≤ Ct, the bound is closed-form and norm_num-evaluable.

                                                      theorem Proofs.FloatModel.sum_perturbed_close {n : ℕ} (M : FloatModel) (Bt B : Vec n) {Ct eB : ℝ} (hBt : ∀ (i : Fin n), |Bt i| ≤ Ct) (hB : ∀ (i : Fin n), |Bt i - B i| ≤ eB) :
                                                      |M.sum Bt - ∑ i : Fin n, B i| ≤ ((1 + M.u) ^ (n + 1) - 1) * (↑n * Ct) + ↑n * eB

                                                      Float sum against a perturbed summand — the conv-BIAS grad-close's final reduction, the M.sum peer of dot_perturbed_close (no left operand A: the bias Jacobian is the bare channel indicator, so the contraction is a plain reduction, not a dot). M.sum B̃ vs the certified ∑ Bᵢ splits into the Higham sum rounding on B̃ (sum_close, fan-in n) plus the per-entry drift |B̃ᵢ − Bᵢ| ≤ eB. With |B̃ᵢ| ≤ Ct the bound is closed-form.