Suppose we want a ReLU network to represent a function f on an interval. An approximation theorem
may tell us that suitable weights exist. Once we choose weights, a verifier can try to enclose
that particular network's values on an input box, and to say what its binary32 execution does we
also need to account for rounding. Writing out the quantifiers shows why these are separate claims:
Only the first line is universal approximation. It doesn't certify a trained checkpoint, choose the
parameters for an optimizer, or prove that floating-point evaluation is close to the real network.
TorchLean keeps these statements near one another because they have to be composed, but it doesn't
identify them.
Where \exists\theta sits is doing real work. We choose the target and tolerance first, then
obtain one parameter vector that works for every input in the domain. Moving the existential inside
the final input quantifier would permit a different network at every point, which would say very
little about representation. For a trained model, by contrast, the parameters have already been
fixed. So the useful question becomes whether those parameters satisfy an approximation bound, or
whether their outputs stay in an acceptable range. That's why a theorem about the network family
and a certificate for one checkpoint can both be useful without answering the same question.
Each term changes the slope at one knot t_i. With knots on a sufficiently fine mesh and each
c_i chosen from changes in the piecewise-linear slope, H interpolates a Lipschitz target. And
the same expression is a one-hidden-layer network: the first linear layer computes x-t_i, ReLU
applies the hinges, and the second linear layer forms their weighted sum.
For an exact example, take two hinges at the same knot t_0=0, one reading x and one reading
-x (both with coefficient one). Their sum is the absolute value:
-- Split at zero, where the active hinge changes. Either-- branch leaves one copy of the magnitude.example(x:ℝ):|x|=maxx0+max(-x)0:=x:ℝ⊢ |x|=maxx0+max(-x)0x:ℝh:0≤x⊢ |x|=maxx0+max(-x)0x:ℝh:x≤0⊢ |x|=maxx0+max(-x)0x:ℝh:0≤x⊢ |x|=maxx0+max(-x)0All goals completed! 🐙·inrx:ℝh:x≤0⊢ |x|=maxx0+max(-x)0rw[abs_of_nonposh,inrx:ℝh:x≤0⊢ -x=maxx0+max(-x)0max_eq_righth,inrx:ℝh:x≤0⊢ -x=0+max(-x)0max_eq_left(neg_nonneg.mprh),inrx:ℝh:x≤0⊢ -x=0+-xzero_addinrx:ℝh:x≤0⊢ -x=-x]All goals completed! 🐙
Here max y 0 is ReLU. So the right-hand side is a width-two ReLU network (first-layer weights
+1 and -1, zero biases, and second-layer weights both 1). This example allows a hinge
facing each direction, while the interpolation formula above uses hinges facing right. Either way,
the proof splits at the knot: on one side of t_i the hinge is inert, and on the other it
contributes its slope. The general theorem also uses the Lipschitz bound to choose a mesh and
control the interpolation error uniformly.
The theorem relu_Icc makes precisely that conversion. Its signature is:
-- Expose the interval and Lipschitz premises before the-- existential choice of network layers.@relu_Icc : ∀{f:ℝ→ℝ}{abL:ℝ},a<b→0<L→(∀x∈Set.Iccab,∀y∈Set.Iccab,|fx-fy|≤L*|x-y|)→∀ε>0,∃hidDiml1l2,∀x∈Set.Iccab,|fx-mlpEvalScalarhidDiml1l2x|<ε#check@relu_Icc
Here a<b gives an interval with positive length. L>0 and h_lip provide a quantitative
continuity bound, and \varepsilon>0 is needed before a finite mesh can be chosen. From the
conclusion you get two TorchLean Linear values: the input-to-hidden layer and the
hidden-to-output layer used by mlpEvalScalar.
In the printed signature, ∀ x ∈ Set.Icc a b abbreviates two arguments: an input x and a proof
that a\leq x\leq b. Likewise, each arrow before the existential introduces a premise the caller
must supply. Braces around {f : ℝ → ℝ} mark an implicit parameter that Lean can infer from those
premises. Once hidDim is obtained, the types of l1 and l2 depend on that dimension, so their
hidden coordinates must agree. That dependency ties the analytic construction to a well-shaped
model. Strict positivity of L is harmless for a constant target: any positive upper bound is also
a Lipschitz bound for that target (even though its smallest Lipschitz constant is zero).
In Lean this is width. It's the witness in the qualitative theorem, and
relu_Icc_rate names the same hidden dimension in its statement.
Underneath, the arithmetic lemma proves
\frac{2L(b-a)}{N}<\varepsilon.
This bound is conservative. It establishes a construction with a stated size. It doesn't say that
the width is minimal, or that gradient descent will discover these hinge parameters.
Each #check below displays a declaration behind the width formula and is checked when the page
builds. The width takes four real arguments and returns a natural number:
-- The width is a natural count computed from four-- real-valued specification parameters.width : ℝ→ℝ→ℝ→ℝ→ℕ#check@width
width : ℝ→ℝ→ℝ→ℝ→ℕ
By the arithmetic lemma, this choice of width makes the mesh error smaller than the requested
tolerance:
-- Inspect the strict mesh estimate obtained by adding one-- after the ceiling.@div_width_lt : ∀{Labε:ℝ},0<ε→2*L*(b-a)/↑(widthLabε)<ε#check@div_width_lt
So the rate theorem has the same hypotheses as before, with the existential over hidDim
discharged by that formula:
-- The hidden dimension is fixed here, and only the two-- layer parameter records remain existential.@relu_Icc_rate : ∀{f:ℝ→ℝ}{abL:ℝ},a<b→0<L→(∀x∈Set.Iccab,∀y∈Set.Iccab,|fx-fy|≤L*|x-y|)→∀ε>0,∃l1l2,∀x∈Set.Iccab,|fx-mlpEvalScalar(widthLabε)l1l2x|<ε#check@relu_Icc_rate
You can't evaluate the same definition with #eval:
-- This deliberately asks the compiler to execute a width-- defined using mathematical reals.failed to compile definition, consider marking it as 'noncomputable' because it depends on 'width', which is 'noncomputable'#evalwidth101(1/10)
failed to compile definition, consider marking it as 'noncomputable' because it depends on 'width', which is 'noncomputable'
Because the width applies Nat.ceil to mathematical real numbers, it's a proof-level construction,
not a compiled numerical routine. That compiler error marks the boundary between an existence proof
over exact reals and an executable parameter-selection program. A runtime tool could compute the
same formula from rational inputs, but that would be a separate executable definition with a
refinement theorem.
But Lean can prove the value for specific inputs. For a 1-Lipschitz target on [0,1] at
\varepsilon=1/10, the width is twenty-one hidden units:
-- Prove the real ceiling calculation for this tolerance-- without compiling it as a numerical-- routine.example:width101(1/10)=21:=by⊢ width101(1/10)=21norm_num[width]All goals completed! 🐙
That is \lceil 2\cdot 1\cdot 1/(1/10)\rceil+1=21, and norm_num proves the arithmetic
(including the ceiling). Halving \varepsilon approximately doubles the width, so this
construction is linear in 1/\varepsilon.
Adding one after the ceiling makes the mesh estimate strict, even when the ratio is an integer. In
the signature, ↑ casts the positive natural width to a real denominator.
To construct concrete parameters, use four hinges on [0,1] for the target f(x)=x^2. The
following code computes the knots and chord slopes in Float, converts the knots and slope
increments to FloatLib binary32, and prints the resulting parameters. We evaluate their hinge sum
in binary32 arithmetic in the next example.
-- Each coefficient records a slope increment, so active-- hinges reconstruct the chord slope.defmeshN:Nat:=4defmeshStep:Float:=1.0/4.0deftarget(x:Float):Float:=x*xdefknot(i:FinmeshN):(ExecFloat.Binary823):=(ExecFloat.Binary.ofFloat32∘Float.toFloat32)(Nat.toFloati.val*meshStep)-- Slope of the chord of `target` over subinterval `i`.defchordSlope(i:Nat):Float:=(target(Nat.toFloat(i+1)*meshStep)-target(Nat.toFloati*meshStep))/meshStepdefcoeff(i:FinmeshN):(ExecFloat.Binary823):=(ExecFloat.Binary.ofFloat32∘Float.toFloat32)(ifi.val=0thenchordSlope0elsechordSlopei.val-chordSlope(i.val-1))knots [0.000000, 0.250000, 0.500000, 0.750000]
slopes [0.250000, 0.750000, 1.250000, 1.750000]
coeffs [0.250000, 0.500000, 0.500000, 0.500000]
#evaldoletts:=(List.finRangemeshN).map(knot·|>ExecFloat.Binary.toFloat32|>.toFloat)letcs:=(List.finRangemeshN).map(coeff·|>ExecFloat.Binary.toFloat32|>.toFloat)letss:=(List.rangemeshN).mapchordSlopeIO.printlns!"knots {ts}"IO.printlns!"slopes {ss}"IO.printlns!"coeffs {cs}"
A hinge
c_i\operatorname{ReLU}(x-t_i) is inert to the left of its knot and contributes slope c_i to
the right, so between knots the sum has slope \sum_{t_i\leq x} c_i. For that running total to
match the chord slopes s_0,\dots,s_{N-1} printed above, the coefficients have to be the
increments: c_0=s_0 and c_i=s_i-s_{i-1}. Slopes 0.25,0.75,1.25,1.75 therefore give
coefficients 0.25,0.5,0.5,0.5. For example, after the second knot the first two hinges are
active: their coefficients add to the second chord's slope. This cumulative addition is why
coeff stores differences of slopes.
At x=3/8, only the knots at zero and one quarter contribute. Their terms are (1/4)(3/8)=3/32
and (1/2)(1/8)=1/16, giving H(x)=5/32. Since the target is 9/64, the difference is 1/64
(the 0.015625 in the table below). This also explains the tensor layout in the PyTorch
transcription below: each hidden coordinate stores one distance from a knot, and the output weight
on that coordinate stores a slope change. So the four coefficients aren't four independent chord
slopes. Copying the printed slope list into the output layer would change the function, even though
all layer dimensions would still match.
Evaluate the network on a grid twice as fine as its own mesh, so that both the knots and the points
between them appear:
At every knot the hinge sum agrees with x^2, because its slopes match the chords. Between knots
the real chord interpolant lies above the curve, since the target is convex. In the displayed
calculation the overshoot is 0.015625 at every midpoint: the midpoint error of a chord
interpolant of this quadratic is \tfrac18 f''h^2=\tfrac18\cdot 2\cdot(1/4)^2.
Compare that with what the rate theorem certifies at this width. Since x^2 is 2-Lipschitz on
[0,1], the formula reaches four or fewer hidden units only once \varepsilon is at least
4/3:
-- Compare the prescribed widths for the same Lipschitz-- bound at three tolerances.example:width201(4/3)=4:=by⊢ width201(4/3)=4norm_num[width]All goals completed! 🐙example:width201(1/10)=41:=by⊢ width201(1/10)=41norm_num[width]All goals completed! 🐙example:width201(1/20)=81:=by⊢ width201(1/20)=81norm_num[width]All goals completed! 🐙
Here the rate theorem supplies a real network with error below 4/3, while the displayed binary32
mesh has sampled error 0.015625. To apply the theorem to these particular parameters, you have
to identify its real construction with this mesh and then bound conversion and execution error. And
the width calculation alone doesn't discharge those obligations. A sharper interpolation bound can
also use the second derivative of this smooth target (information absent from the Lipschitz
hypotheses). So the sampled error and the existence guarantee describe different claims.
Convexity explains the one-sided interpolation error for x^2 and the increasing chord slopes,
but the hinge construction itself only needs the slopes and their differences. Apply it to eight
hinges on [0,1] for f(x)=\sin(2\pi x):
-- Allow signed slope increments so the interpolant can-- follow both halves of the wave.defwaveN:Nat:=8defwaveStep:Float:=1.0/8.0defwave(x:Float):Float:=Float.sin(2.0*3.141592653589793*x)defwaveKnot(i:FinwaveN):(ExecFloat.Binary823):=(ExecFloat.Binary.ofFloat32∘Float.toFloat32)(Nat.toFloati.val*waveStep)defwaveChord(i:Nat):Float:=(wave(Nat.toFloat(i+1)*waveStep)-wave(Nat.toFloati*waveStep))/waveStepdefwaveCoeff(i:FinwaveN):(ExecFloat.Binary823):=(ExecFloat.Binary.ofFloat32∘Float.toFloat32)(ifi.val=0thenwaveChord0elsewaveChordi.val-waveChord(i.val-1))defwaveHinge(x:Float):Float:=(ExecFloat.Binary.toFloat32(hingeFunwaveKnotwaveCoeff0((ExecFloat.Binary.ofFloat32∘Float.toFloat32)x))).toFloatcoeffs [5.656854, -3.313709, -4.686292, -3.313709, -0.000000, 3.313709, 4.686292, 3.313709]
x=0.062500 f=0.382683 H-f=-0.029130
x=0.187500 f=0.923880 H-f=-0.070326
x=0.562500 f=-0.382683 H-f=0.029130
x=0.687500 f=-0.923880 H-f=0.070326
worst on this grid = 0.070326
#evaldoletcs:=(List.finRangewaveN).map(waveCoeff·|>ExecFloat.Binary.toFloat32|>.toFloat)IO.printlns!"coeffs {cs}"-- Signed error at four midpoints, two per half.forkin[1,3,9,11]doletx:=Nat.toFloatk*0.0625IO.printlns!"x={x} f={wavex} H-f={waveHingex-wavex}"letmutworst:=0.0forkin[0:17]doletx:=Nat.toFloatk*0.0625worst:=maxworst(waveHingex-wavex).absIO.printlns!"worst on this grid = {worst}"
Here the coefficients change sign because the chord slopes decrease as well as increase, so a hinge
can cancel the slope its predecessors added, not only steepen the curve. And the midpoint errors
have both signs: the interpolant sits below f where f is concave and above it where f is
convex, so no one-sided statement of the kind that held for x^2 is available. In both cases the
Lipschitz error bound controls the absolute error.
The rate formula reacts to this target the way a worst-case bound has to. Since \sin(2\pi x) is
2\pi-Lipschitz, take L=7 as a rational upper bound and ask what eight hidden units certify:
-- Use the rational Lipschitz upper bound seven in the same-- width formula.example:width7012=8:=by⊢ width7012=8norm_num[width]All goals completed! 🐙
So the formula assigns width eight to \varepsilon=2. For this particular f (its range is
[-1,1]), that tolerance is loose: even the constant zero function has error at most one. On the
sampled grid, the displayed mesh's measured error is about 0.07. Because the rate theorem uses
only the supplied Lipschitz constant, it covers every 7-Lipschitz target with the same width. It
doesn't use the sine function's curvature. And the grid measurement doesn't establish a uniform
bound between samples.
Both signs in H-f are useful here. A positive number means the approximation lies above the
target, and taking an absolute value too early would hide the change in curvature between the two
halves of the wave. worst ends up as a maximum over seventeen evaluated inputs, whereas the
analytic error statement quantifies over an interval. To turn such a grid into a regional bound,
you'd also need to control how the error varies between adjacent inputs. In the Lipschitz
construction, that control comes from its hypotheses and mesh argument. Instead, the printed table
helps you inspect whether the chosen slope increments behave as intended.
We can place the same knots and slope increments in two torch.nn linear layers. In the first
layer the weights are all ones and the biases are -t_i, and the second layer weights the
resulting hinges:
# Place each knot in the first-layer bias and each slope
# increment in the output weight.
import torch, torch.nn as nn
knots = torch.tensor([0.0, 0.25, 0.50, 0.75])
coeff = torch.tensor([[0.25, 0.5, 0.5, 0.5]])
net = nn.Sequential(nn.Linear(1, 4), nn.ReLU(), nn.Linear(4, 1))
with torch.no_grad():
net[0].weight.copy_(torch.ones(4, 1))
net[0].bias.copy_(-knots)
net[2].weight.copy_(coeff)
net[2].bias.zero_()
xs = torch.arange(0, 9, dtype=torch.float32).mul(0.125).unsqueeze(1)
with torch.no_grad():
ys = net(xs).squeeze(1)
On CPU, the PyTorch transcription produces the nine H values printed above. Every input,
parameter, product, and partial sum on this grid is exactly representable in binary32. This check
covers these inputs on one backend, not every input or backend (Paszke et al., 2019).
Lean's table evaluates hingeFun at binary32 values, the evaluation used in the three-term
executable approximation theorem below. Applying that theorem to these parameters still requires
proofs of its approximation, quantization, and finiteness premises. A transcription into another
framework is a claim that has to be checked separately, which is what the
roundtrip chapter is for.
In the quadratic example, the hinge sum agrees with the target at the knots down to the last bit.
Both the knots and the chord slopes are multiples of 1/4, and on this small grid the products
and partial sums are also exactly representable in binary32. To expose differences hidden by
decimal formatting, the comparison below subtracts the bit patterns of the two positive outputs:
-- Compare stored encodings at interior dyadic knots, where-- decimal output could hide a difference.knot 1: 0 ulp
knot 2: 0 ulp
knot 3: 0 ulp
#evaldoforkin[1,2,3]doletx:=Nat.toFloatk*meshStepletxe:=(ExecFloat.Binary.ofFloat32∘Float.toFloat32)xlethx:=hingeFunknotcoeff0xeletfx:=(ExecFloat.Binary.ofFloat32∘Float.toFloat32)(targetx)letdistance:=ExecFloat.Binary.toBits32hx-ExecFloat.Binary.toBits32fxIO.printlns!"knot {k}: {distance} ulp"
knot 1: 0 ulp
knot 2: 0 ulp
knot 3: 0 ulp
Move the same construction onto a mesh of three and the knots become multiples of 1/3, which
binary32 cannot represent:
-- Convert the thirds-based construction to binary32 before-- comparing its interior-knot outputs.defthirds:Float:=1.0/3.0defknot3(i:Fin3):(ExecFloat.Binary823):=(ExecFloat.Binary.ofFloat32∘Float.toFloat32)(Nat.toFloati.val*thirds)defchord3(i:Nat):Float:=(target(Nat.toFloat(i+1)*thirds)-target(Nat.toFloati*thirds))/thirdsdefcoeff3(i:Fin3):(ExecFloat.Binary823):=(ExecFloat.Binary.ofFloat32∘Float.toFloat32)(ifi.val=0thenchord30elsechord3i.val-chord3(i.val-1))knot 1: 1 ulp
knot 2: 1 ulp
#evaldoforkin[1,2]doletx:=Nat.toFloatk*thirdsletxe:=(ExecFloat.Binary.ofFloat32∘Float.toFloat32)xlethx:=hingeFunknot3coeff30xeletfx:=(ExecFloat.Binary.ofFloat32∘Float.toFloat32)(targetx)letdistance:=ExecFloat.Binary.toBits32hx-ExecFloat.Binary.toBits32fxIO.printlns!"knot {k}: {distance} ulp"
knot 1: 1 ulp
knot 2: 1 ulp
At each interior knot the outputs are adjacent positive binary32 values, one ULP apart.
Float's six-digit rendering shows 0.111111 for both outputs at the first knot and 0.444444
for both at the second, hiding the discrepancy. This is an example of the distinction between a
stored value and its decimal display discussed by Goldberg (Goldberg, 1991).
This comparison includes several rounding steps: conversion of the input and coefficients,
evaluation of the hinge sum, and conversion of the reference target value. The theorems below
separate parameter conversion from evaluation error, and they require finite executable
intermediates so that each arithmetic step can be related to a real-valued expression.
Our worked examples use binary32, but the proof takes the format as a parameter. An executable
value also specifies its storage plan and a FloatLib codec relating stored values to the model. The
arithmetic refinement assumes format.isIEEE = true, so binary16, binary32, binary64, and
binary128 can use the same theorem. Once knots, coefficients, and the bias are stored in the chosen
format, the total error naturally splits into
You can see the distinction in
the
three-term approximation theorem. It takes real hinge parameters tR and cR, executable
parameters t, c, and b0 in that format, and separate assumptions for the real approximation
and quantization terms. It also requires finiteness witnesses for the intermediate hinge sum and
output. Its conclusion adds hingeFunErrorBound to the two supplied tolerances.
To use this theorem, conversion and evaluation must satisfy its finiteness assumptions. Its
dyadic specialization starts from dyadic parameters and uses a half-ULP
rounding bound, but it still asks for finite evaluation witnesses.
The full signature exposes the obligations needed to connect the real approximant to executable
arithmetic:
-- Inspect the separate approximation,-- parameter-quantization, and finite-execution obligations.@relu_Icc_binary_three_term : ∀{format:FloatFormat}{plan:FloatLib.Floats.Formats.BinaryInterchange.Configured.StoragePlanformat}{code:Type}[inst:ExecFloat.ModelCodecplan(Modelformat)code],format.isIEEE=true→∀{f:ℝ→ℝ}{ab:ℝ}{hidDim:ℕ}(tRcR:FinhidDim→ℝ)(tc:FinhidDim→ExecFloat(FloatLib.Floats.Formats.BinaryInterchange.Configured.Familyformatcodeplan))(b0:ExecFloat(FloatLib.Floats.Formats.BinaryInterchange.Configured.Familyformatcodeplan))(εApproxεQ:ℝ),(∀(x:ExecFloat(FloatLib.Floats.Formats.BinaryInterchange.Configured.Familyformatcodeplan)),ExecFloat.Binary.isFinitex=true→(ExecFloat.Binary.toModelx).toReal∈Set.Iccab→HingeSumFinitetcx0(List.finRangehidDim)∧(hingeFuntcb0x).isFinite=true)→(∀(x:ExecFloat(FloatLib.Floats.Formats.BinaryInterchange.Configured.Familyformatcodeplan)),ExecFloat.Binary.isFinitex=true→(ExecFloat.Binary.toModelx).toReal∈Set.Iccab→|f(ExecFloat.Binary.toModelx).toReal-hingeFuntRcR(fa)(ExecFloat.Binary.toModelx).toReal|<εApprox)→(∀(x:ExecFloat(FloatLib.Floats.Formats.BinaryInterchange.Configured.Familyformatcodeplan)),ExecFloat.Binary.isFinitex=true→(ExecFloat.Binary.toModelx).toReal∈Set.Iccab→|hingeFuntRcR(fa)(ExecFloat.Binary.toModelx).toReal-Rounded.hingeFunRealformat(toRoundedVect)(toRoundedVecc)(toRoundedb0)(toRoundedx)|≤εQ)→∀(x:ExecFloat(FloatLib.Floats.Formats.BinaryInterchange.Configured.Familyformatcodeplan)),ExecFloat.Binary.isFinitex=true→(ExecFloat.Binary.toModelx).toReal∈Set.Iccab→|f(ExecFloat.Binary.toModelx).toReal-(hingeFuntcb0x).toModel.toReal|<εApprox+εQ+Rounded.hingeFunErrorBoundformat(toRoundedVect)(toRoundedVecc)(toRoundedb0)(toRoundedx)#check@relu_Icc_binary_three_term
Read the signature from the top. Parameter vectors come in pairs, tR cR over the reals and t c
over the configured format, because the theorem has to talk about both to relate them. Notice the
HingeSumFinite conjunct: it demands that every intermediate of the fold stay finite, not merely
the result. At each arithmetic step the proof uses finite real embeddings, so an overflowing
intermediate breaks that argument. That same conjunct rules out NaN and infinite parameters (a
condition a real-valued statement couldn't even express): a non-finite knot or coefficient makes
its subtraction or product non-finite, so t and c need no isFinite hypotheses of their own.
Next come the \varepsilon_{\mathrm{Approx}} and \varepsilon_Q budgets from the three-term
split, two hypotheses that are supplied, not derived. And the conclusion adds hingeFunErrorBound
(the rounding of the evaluation itself) to their sum.
For a particular checkpoint, each premise must be proved for its stored parameters and the stated
input domain. instDecHingeSumFinite makes the HingeSumFinite predicate decidable for a fixed
input and concrete parameters. After installing it with haveI, decide can prove a true concrete
instance, but a premise quantified over all inputs in an interval still needs an argument covering
that whole domain.
Notice that the final input is a stored value in the chosen format, and interval membership is
tested on its decoded real value Model.toReal (ExecFloat.Binary.toModel x), so the target is
evaluated at the real number that stored input represents. If an application starts with an ideal
real measurement and rounds it before model evaluation, its input-conversion error is an additional
question. A Lipschitz bound on the target can help relate those two inputs, but that step isn't
hidden inside εQ: the quantization premise shown here compares two parameterizations at the same
embedded input. Keeping that input fixed makes the three terms correspond to three identifiable
functions.
A companion theorem for dyadic parameters replaces the supplied \varepsilon_Q with a half-ULP
bound derived from dyadic parameters. It's the more usable form when reference parameters are given
as dyadics. It assumes knots in [a,b] and finite rounded parameters, and it propagates the
per-parameter half-ULP errors through the hinge sensitivities (including the interval length
|b-a|). Finite-evaluation witnesses remain necessary, because finite stored parameters can still
produce an overflowing intermediate.
The dyadic specialization exposes those witnesses in its signature:
-- Dyadic reference parameters supply the quantization-- estimate, but finite evaluation is still required.@relu_Icc_binary_dyadic : ∀{format:FloatFormat}{plan:FloatLib.Floats.Formats.BinaryInterchange.Configured.StoragePlanformat}{code:Type}[inst:ExecFloat.ModelCodecplan(Modelformat)code],format.isIEEE=true→∀{f:ℝ→ℝ}{ab:ℝ}{hidDim:ℕ}(tDcD:FinhidDim→FloatLib.Numerics.Dyadic)(bD:FloatLib.Numerics.Dyadic),(∀(i:FinhidDim),(tDi).toReal∈Set.Iccab)→(∀(i:FinhidDim),(ExecFloat.Binary.ofModel(Model.roundDyadicformat(tDi))).isFinite=true)→(∀(i:FinhidDim),(ExecFloat.Binary.ofModel(Model.roundDyadicformat(cDi))).isFinite=true)→(ExecFloat.Binary.ofModel(Model.roundDyadicformatbD)).isFinite=true→∀(εApprox:ℝ),(∀(x:ExecFloat(FloatLib.Floats.Formats.BinaryInterchange.Configured.Familyformatcodeplan)),ExecFloat.Binary.isFinitex=true→(ExecFloat.Binary.toModelx).toReal∈Set.Iccab→HingeSumFinite(funi=>ExecFloat.Binary.ofModel(Model.roundDyadicformat(tDi)))(funi=>ExecFloat.Binary.ofModel(Model.roundDyadicformat(cDi)))x0(List.finRangehidDim)∧(hingeFun(funi=>ExecFloat.Binary.ofModel(Model.roundDyadicformat(tDi)))(funi=>ExecFloat.Binary.ofModel(Model.roundDyadicformat(cDi)))(ExecFloat.Binary.ofModel(Model.roundDyadicformatbD))x).isFinite=true)→(∀(x:ExecFloat(FloatLib.Floats.Formats.BinaryInterchange.Configured.Familyformatcodeplan)),ExecFloat.Binary.isFinitex=true→(ExecFloat.Binary.toModelx).toReal∈Set.Iccab→|f(ExecFloat.Binary.toModelx).toReal-hingeFun(funi=>(tDi).toReal)(funi=>(cDi).toReal)bD.toReal(ExecFloat.Binary.toModelx).toReal|<εApprox)→∀(x:ExecFloat(FloatLib.Floats.Formats.BinaryInterchange.Configured.Familyformatcodeplan)),ExecFloat.Binary.isFinitex=true→(ExecFloat.Binary.toModelx).toReal∈Set.Iccab→|f(ExecFloat.Binary.toModelx).toReal-(hingeFun(funi=>ExecFloat.Binary.ofModel(Model.roundDyadicformat(tDi)))(funi=>ExecFloat.Binary.ofModel(Model.roundDyadicformat(cDi)))(ExecFloat.Binary.ofModel(Model.roundDyadicformatbD))x).toModel.toReal|<εApprox+(FloatLib.Floats.Formats.Flocq.ulpFloatLib.Numerics.binaryRadix(Model.fexpOfformat)bD.toReal/2+∑i,(FloatLib.Floats.Formats.Flocq.ulpFloatLib.Numerics.binaryRadix(Model.fexpOfformat)(cDi).toReal/2*|b-a|+|(ExecFloat.Binary.ofModel(Model.roundDyadicformat(cDi))).toModel.toReal|*(FloatLib.Floats.Formats.Flocq.ulpFloatLib.Numerics.binaryRadix(Model.fexpOfformat)(tDi).toReal/2)))+Rounded.hingeFunErrorBoundformat(toRoundedVecfuni=>ExecFloat.Binary.ofModel(Model.roundDyadicformat(tDi)))(toRoundedVecfuni=>ExecFloat.Binary.ofModel(Model.roundDyadicformat(cDi)))(toRounded(ExecFloat.Binary.ofModel(Model.roundDyadicformatbD)))(toRoundedx)#check@relu_Icc_binary_dyadic
TorchLean also has an intermediate
rounded-real theorem.
Rounded.relu_Icc format evaluates the hinge construction with
rounding at each operation and proves a pointwise bound of the form
-- This bound concerns the rounded-real carrier and reads-- its result through the val field.Rounded.relu_Icc : ∀(format:FloatFormat){f:ℝ→ℝ}{abL:ℝ},a<b→0<L→(∀x∈Set.Iccab,∀y∈Set.Iccab,|fx-fy|≤L*|x-y|)→∀ε>0,∃hidDimtcb0,∀x∈Set.Iccab,|fx-(hingeFuntcb0{val:=x}).val|<ε+Rounded.hingeFunErrorBoundformattcb0{val:=x}#check@Rounded.relu_Icc
Compare that conclusion with the real one printed earlier: the hypotheses are identical, the
existential produces hinge parameters in place of a Linear pair, and the bound has grown a
second summand. That summand bounds evaluation in this model, and it doesn't include a separate
conversion of arbitrary real parameters into finite storage.
Rounded format values carry arbitrary reals, and each primitive operation rounds its result to
the format's precision and underflow grid (with no upper exponent cutoff). This carrier is
FloatLib's NF, specialized by the format descriptor. Under the IEEE-format and
finite-intermediate hypotheses, the executable bridge connects it to stored values. Changing
format changes the grid and the error bounds without selecting a different proof file.
Our one-dimensional hinge proof is constructive and quantitative. For higher dimensions, the
development takes a different route. In
StoneWeierstrass,
Tensor ℝ [n] is identified with Fin n → ℝ by a homeomorphism. Coordinate functions generate a
subalgebra of continuous functions, and the proof establishes that this subalgebra separates
points: distinct tensors differ in at least one coordinate, and the corresponding coordinate
function distinguishes them. Mathlib's Stone-Weierstrass theorem (Community, 2020)
then supplies density on compact domains. TorchLean's own part establishes the homeomorphism and
checks the subalgebra hypotheses that theorem needs.
Here the approximating objects are coordinate-polynomial expressions. A subalgebra contains
constants and is closed under addition, multiplication, and scalar multiplication, so starting from
coordinate projections permits expressions such as a coordinate squared or a product of two
coordinates. Point separation says this class can distinguish any two different tensor inputs.
Compactness is what lets density be stated using uniform error over the whole domain. In the
source, the conclusion ∃ g : coordSubalg, ‖(g : C(K, ℝ)) - f‖ < ε chooses one such continuous
function (C(K, ℝ) bundles continuity with the function, and its norm measures the largest
absolute error). A neural construction built on this result still has to represent or approximate
that polynomial expression.
That topological argument answers a broad representation question, but it doesn't produce a width
formula like the one from the one-dimensional Lipschitz construction. So the two proofs are
complementary:
the hinge mesh exposes parameters and a rate on [a,b], and
the coordinate-subalgebra proof handles compact multidimensional domains at a more abstract
level.
For the corresponding two-layer network, the scalar hinge construction also has a theorem. In the
two-layer configured binary approximation API, relu_mlp_binary_three_term packages
representation, parameter-rounding, and executable-rounding error. Unlike the hinge theorem, this
one takes all three budgets (including the execution bound) as hypotheses and composes them by the
triangle inequality.
The theorem is checked as this page builds. Hovering over it shows its hypotheses:
-- The network theorem takes all three error budgets as-- hypotheses.@relu_mlp_binary_three_term : ∀{format:FloatFormat}{plan:FloatLib.Floats.Formats.BinaryInterchange.Configured.StoragePlanformat}{code:Type}[inst:ExecFloat.ModelCodecplan(Modelformat)code]{nhidDim:ℕ}(D:Set(TorchLean.Tensor(ExecFloat(FloatLib.Floats.Formats.BinaryInterchange.Configured.Familyformatcodeplan))[n]))(f:TorchLean.Tensorℝ[n]→ℝ)(l1R:TorchLean.LinearℝnhidDim)(l2R:TorchLean.LinearℝhidDim1)(l1I:TorchLean.Linear(ExecFloat(FloatLib.Floats.Formats.BinaryInterchange.Configured.Familyformatcodeplan))nhidDim)(l2I:TorchLean.Linear(ExecFloat(FloatLib.Floats.Formats.BinaryInterchange.Configured.Familyformatcodeplan))hidDim1)(εApproxεQεR:ℝ),(∀xI∈D,havexR:=tensorToRealxI;|fxR-mlpEvall1Rl2RxR|≤εApprox)→(∀xI∈D,havexR:=tensorToRealxI;|mlpEvall1Rl2RxR-mlpEval(linearToReall1I)(linearToReall2I)xR|≤εQ)→(∀xI∈D,havexR:=tensorToRealxI;|(mlpEvall1Il2IxI).toModel.toReal-mlpEval(linearToReall1I)(linearToReall2I)xR|≤εR)→∀xI∈D,havexR:=tensorToRealxI;|fxR-(mlpEvall1Il2IxI).toModel.toReal|≤εApprox+εQ+εR#check@relu_mlp_binary_three_term
For the quantitative two-layer approximation theorem introduced earlier, the error budgets give:
Those three terms come from representation, parameter conversion, and executable arithmetic, and
writing the sum out lets an application decide where to spend its error budget. Separately, a CROWN
or interval certificate can supply a sound enclosure over an input region for the chosen network.
That enclosure is a regional property, not automatically another additive error term in this
inequality.
The constructions follow the classical universal-approximation tradition.
Cybenko (1989) proved density for superpositions of a sigmoidal function, and
Hornik (1991) removed the sigmoid-specific hypothesis for multilayer feedforward
networks. Both are density results: they say an approximant exists and are silent about its size.
The explicit ReLU construction obtains a width formula by choosing a mesh and computing its
slope increments.