ℝ → 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:
- Summation order.
FloatModel.dotandFloatModel.sumfix one association (the left fold), anddot_close/sum_closeare stated for that fold only. The classical bound((1+u)^(n+1) − 1)·Σ|xᵢyᵢ|holds for every summation order, but only the left fold is formalized here; the order-parametric form, which takes any rounded sum meeting a fan-in bound, isFloatModel.bnMean_close_of(BnFloatBridge). A backend such as XLA may reassociate reductions. - ReLU is exact in floating point — comparison/selection rounds nothing,
which is why
MlpFloatBridge'smlpFinterleaves barereluwith norndand the bridge only needsrelu's 1-Lipschitz error propagation (relu_close). The op that forced the kink hypotheses on theℝside is the free op here. - Error shapes are
denseErr, one def reused at every layer: the rounded layer at a perturbed input vs the real layer at the real input. The MLP capstone (MlpFloatBridge'smlp_float_close) threads it three times; itse₀/e₁hypotheses are uniformizations of the per-coordinate layer bounds, dischargeable at any concrete instance by finite max.
The unit roundoff of IEEE-754 binary32 (round-to-nearest-even).
Equations
- Proofs.u32 = (2 ^ 24)⁻¹
Instances For
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
- Proofs.uE4M3 = (2 ^ 4)⁻¹
Instances For
The rounding of 0 is 0 (forced by the relative-error model at x = 0).
Rounded addition: fl(x + y).
Instances For
Rounded multiplication: fl(x · y).
Instances For
Rounded dot product, left-fold association (((x₀y₀ + x₁y₁) + …)).
dot_close is stated for this fold.
Equations
Instances For
A rounded dot product against the all-zero vector is 0.
Rounded dense layer — the float peer of Proofs.dense
(fl(Σᵢ xᵢ·Wᵢⱼ) ⊕ bⱼ, every +/· rounded).
Instances For
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).
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.
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.
Instances For
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.
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.
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
- M.denseMixed L W b x j = M.add (M.dotMixed L x fun (i : Fin m) => W i j) (b j)
Instances For
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.
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
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.
dense_close at a fresh (unperturbed) input — the e = 0 face.
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.
Worst-case output magnitude of one real layer under uniform magnitude
bounds: |denseⱼ| ≤ m·w·A + β (and relu only shrinks).
Equations
- Proofs.FloatModel.layerAct m w β A = ↑m * w * A + β
Instances For
The uniform-magnitude form of denseErr: every |Wᵢⱼ| ≤ w, |bⱼ| ≤ β,
real activation magnitude ≤ A, inherited error ≤ E.
Equations
Instances For
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.
denseErr under uniform magnitude bounds is at most the closed-form
layerBudget.
Rounded subtraction: fl(x − y).
Instances For
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
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.
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).
Instances For
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.
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.
Rounded division: fl(x / y).
Instances For
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.
Instances For
The float softmax−onehot cotangent (one final rounded subtract; the onehot operand is exact).
Equations
- M.softmaxCECotF fexp z label k = M.sub (M.softmaxF fexp z k) (Proofs.oneHot n label k)
Instances For
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.
Relative budget of the pre-rounding float softmax against the real softmax at the same logits.
Equations
- Proofs.FloatModel.smKappa u eexp n = (eexp + Proofs.FloatModel.smRho u eexp n) / (1 - Proofs.FloatModel.smRho u eexp n)
Instances For
Absolute budget of the float softmax against the real softmax at the
REAL logits: head rounding + the e^(2δ) − 1 logit-perturbation term.
Equations
- Proofs.FloatModel.smErr u eexp δ n = u * (1 + Proofs.FloatModel.smKappa u eexp n) + Proofs.FloatModel.smKappa u eexp n + (Real.exp (2 * δ) - 1)
Instances For
Budget of the full rounded softmax−onehot cotangent against the certified real gradient.
Equations
- Proofs.FloatModel.cotErr u eexp δ n = u * (1 + Proofs.FloatModel.smErr u eexp δ n) + Proofs.FloatModel.smErr u eexp δ n
Instances For
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.
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.
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 δ).
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.
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
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.
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
- Proofs.FloatModel.exactModel = { rnd := id, u := 0, err := Proofs.FloatModel.exactModel._proof_1 }
Instances For
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.
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.
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.