Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Random ReLU networks at a single input (Lecture 5)

Definition
LesHouchesWidth_ReLUNet

by LG · Sep 23, 2026 · Mathlib 0df444a (Lean v4.33.1)

machine-learningneural-networksprobability

Random ReLU networks at a single input, following Section 5.3 of the lectures.

Fix a depth LLL and widths n0,…,nL+1n_0,\dots,n_{L+1}n0​,…,nL+1​ (a sequence n:N→Nn:\mathbb N\to\mathbb Nn:N→N of which only the first L+2L+2L+2 values are used), and a probability measure μ\muμ on R\mathbb RR.

  1. Weights. The normalized weights W^ij(ℓ)\widehat W^{(\ell)}_{ij}Wij(ℓ)​, 1≤ℓ≤L+11\le\ell\le L+11≤ℓ≤L+1, i≤nℓi\le n_\elli≤nℓ​, j≤nℓ−1j\le n_{\ell-1}j≤nℓ−1​, are i.i.d. with law μ\muμ (weightLaw). The actual weights are Wij(ℓ)=(2/nℓ−1)1/2 W^ij(ℓ)W^{(\ell)}_{ij}=(2/n_{\ell-1})^{1/2}\,\widehat W^{(\ell)}_{ij}Wij(ℓ)​=(2/nℓ−1​)1/2Wij(ℓ)​ (weight). All biases are 000.
  2. Network. z(1)=W(1)xz^{(1)}=W^{(1)}xz(1)=W(1)x and z(ℓ+1)=W(ℓ+1) ReLU(z(ℓ))z^{(\ell+1)}=W^{(\ell+1)}\,\mathrm{ReLU}(z^{(\ell)})z(ℓ+1)=W(ℓ+1)ReLU(z(ℓ)) for 1≤ℓ≤L1\le\ell\le L1≤ℓ≤L, with ReLU(t)=max⁡(t,0)\mathrm{ReLU}(t)=\max(t,0)ReLU(t)=max(t,0) (netZ, output=z(L+1)=z^{(L+1)}=z(L+1)).
  3. Jacobian. ∂zq(L+1)/∂xp\partial z^{(L+1)}_q/\partial x_p∂zq(L+1)​/∂xp​ is the derivative of y↦zq(L+1)(y)y\mapsto z^{(L+1)}_q(y)y↦zq(L+1)​(y) at xxx in direction epe_pep​ (jacobianEntry).
  4. Paths. Γ=[n0]×⋯×[nL+1]\Gamma=[n_0]\times\cdots\times[n_{L+1}]Γ=[n0​]×⋯×[nL+1​] (NetPath), and Γp,q\Gamma_{p,q}Γp,q​ is the set of paths from input neuron ppp to output neuron qqq (pathsFromTo). Along a path, the weight product is ∏ℓ=1L+1Wγ(ℓ)γ(ℓ−1)(ℓ)\prod_{\ell=1}^{L+1}W^{(\ell)}_{\gamma(\ell)\gamma(\ell-1)}∏ℓ=1L+1​Wγ(ℓ)γ(ℓ−1)(ℓ)​ (pathWeight) and the activation product is ∏ℓ=1L1{zγ(ℓ)(ℓ)(x)>0}\prod_{\ell=1}^{L}\mathbf 1\{z^{(\ell)}_{\gamma(\ell)}(x)>0\}∏ℓ=1L​1{zγ(ℓ)(ℓ)​(x)>0} (pathActivation).
  5. Dropout model. The masks ξi(ℓ)\xi^{(\ell)}_iξi(ℓ)​, 1≤ℓ≤L1\le\ell\le L1≤ℓ≤L, are i.i.d. Bernoulli(1/2)(1/2)(1/2) (maskLaw), D(ℓ)=diag(ξ(ℓ))D^{(\ell)}=\mathrm{diag}(\xi^{(\ell)})D(ℓ)=diag(ξ(ℓ)), and the deep linear network with dropout has output W(L+1)D(L)W(L)⋯D(1)W(1)xW^{(L+1)}D^{(L)}W^{(L)}\cdots D^{(1)}W^{(1)}xW(L+1)D(L)W(L)⋯D(1)W(1)x (dropoutOutput).

These are the objects in terms of which Proposition 5.2, eq. (123), the exercises of Section 5.4 and the moment computations of Section 5.5 are stated.

Formalization Note The derivative is Mathlib's fderiv, which is 000 where the map is not differentiable. Weights at layer indices beyond L+1L+1L+1 and masks beyond layer LLL are set to harmless placeholder values and are never used.

Definition code
import Mathlib

/-!
# Random ReLU networks at a single input (Les Houches lectures, Lecture 5)

Definitions for the random ReLU network model of Section 5.3 of
Bahri–Hanin–Brossollet–Erba–Keup–Pacelli–Simon,
*Les Houches Lectures on Deep Learning at Large & Infinite Width*, arXiv:2309.01592v3.

Widths are a sequence `n : ℕ → ℕ`; only `n 0, …, n (L+1)` are used.
Layer `ℓ + 1` (paper indexing) has weight matrix `W^{(ℓ+1)} ∈ ℝ^{n_{ℓ+1} × n_ℓ}` with
`W^{(ℓ+1)}_{ij} = (2 / n_ℓ)^{1/2} \hat W^{(ℓ+1)}_{ij}`, the `\hat W` i.i.d. with law `μ`,
and all biases are `0`.
-/

namespace LesHouchesWidth

open MeasureTheory

/-- Index set of the normalized weights `\hat W^{(ℓ+1)}_{ij}` of a network of depth `L`
with widths `n 0, …, n (L+1)`: triples `(ℓ, i, j)` with `ℓ ≤ L`, `i < n (ℓ+1)`, `j < n ℓ`. -/
abbrev WeightIndex (n : ℕ → ℕ) (L : ℕ) : Type :=
  Σ ℓ : Fin (L + 1), Fin (n (ℓ.val + 1)) × Fin (n ℓ.val)

/-- A configuration of all normalized weights `\hat W`. -/
abbrev Weights (n : ℕ → ℕ) (L : ℕ) : Type := WeightIndex n L → ℝ

/-- The law of the normalized weights: i.i.d. with common law `μ`. -/
noncomputable def weightLaw (n : ℕ → ℕ) (L : ℕ) (μ : Measure ℝ) : Measure (Weights n L) :=
  Measure.pi fun _ => μ

instance (n : ℕ → ℕ) (L : ℕ) (μ : Measure ℝ) [IsProbabilityMeasure μ] :
    IsProbabilityMeasure (weightLaw n L μ) := by
  unfold weightLaw; infer_instance

/-- The actual weight `W^{(ℓ+1)}_{ij} = (2 / n_ℓ)^{1/2} \hat W^{(ℓ+1)}_{ij}` connecting neuron
`j` of layer `ℓ` to neuron `i` of layer `ℓ + 1` (and `0` for `ℓ > L`, never used). -/
noncomputable def weight {n : ℕ → ℕ} {L : ℕ} (ω : Weights n L) (ℓ : ℕ)
    (i : Fin (n (ℓ + 1))) (j : Fin (n ℓ)) : ℝ :=
  if h : ℓ < L + 1 then Real.sqrt (2 / (n ℓ : ℝ)) * ω ⟨⟨ℓ, h⟩, (i, j)⟩ else 0

/-- The ReLU nonlinearity `σ(t) = t · 1_{t > 0} = max(t, 0)`. -/
noncomputable def relu (t : ℝ) : ℝ := max t 0

/-- Preactivations in the indexing of Lecture 5: `netZ ω x 0 = x` (the input) and
`netZ ω x (ℓ+1) = z^{(ℓ+1)}(x)`, where `z^{(1)} = W^{(1)} x` and
`z^{(ℓ+1)} = W^{(ℓ+1)} σ(z^{(ℓ)})` for `ℓ ≥ 1` (zero biases, `σ = ReLU`). -/
noncomputable def netZ {n : ℕ → ℕ} {L : ℕ} (ω : Weights n L) (x : Fin (n 0) → ℝ) :
    (ℓ : ℕ) → Fin (n ℓ) → ℝ
  | 0 => x
  | ℓ + 1 => fun i => ∑ j, weight ω ℓ i j * (if ℓ = 0 then netZ ω x ℓ j else relu (netZ ω x ℓ j))

/-- The network output `z^{(L+1)}(x) ∈ ℝ^{n_{L+1}}`. -/
noncomputable def output {n : ℕ → ℕ} {L : ℕ} (ω : Weights n L) (x : Fin (n 0) → ℝ) :
    Fin (n (L + 1)) → ℝ :=
  netZ ω x (L + 1)

/-- Entry `∂ z^{(L+1)}_q / ∂ x_p` of the input–output Jacobian at the input `x`, defined as the
Fréchet derivative of `y ↦ z^{(L+1)}_q(y)` at `x` applied to the `p`-th basis vector
(Mathlib convention: `0` where the map is not differentiable). -/
noncomputable def jacobianEntry {n : ℕ → ℕ} {L : ℕ} (ω : Weights n L) (x : Fin (n 0) → ℝ)
    (p : Fin (n 0)) (q : Fin (n (L + 1))) : ℝ :=
  fderiv ℝ (fun y : Fin (n 0) → ℝ => output ω y q) x (Pi.single p 1)

/-- Paths `γ = (γ(0), …, γ(L+1)) ∈ Γ = [n_0] × ⋯ × [n_{L+1}]` through the network. -/
abbrev NetPath (n : ℕ → ℕ) (L : ℕ) : Type := (ℓ : Fin (L + 2)) → Fin (n ℓ.val)

open Classical in
/-- `Γ_{p,q}`: the paths starting at input neuron `p` and ending at output neuron `q`. -/
noncomputable def pathsFromTo (n : ℕ → ℕ) (L : ℕ) (p : Fin (n 0)) (q : Fin (n (L + 1))) :
    Finset (NetPath n L) :=
  Finset.univ.filter fun γ => γ 0 = p ∧ γ (Fin.last (L + 1)) = q

/-- The product of weights along a path: `∏_{ℓ=1}^{L+1} W^{(ℓ)}_γ`, where
`W^{(ℓ)}_γ = W^{(ℓ)}_{γ(ℓ) γ(ℓ-1)}`. -/
noncomputable def pathWeight {n : ℕ → ℕ} {L : ℕ} (ω : Weights n L) (γ : NetPath n L) : ℝ :=
  ∏ ℓ : Fin (L + 1), weight ω ℓ.val (γ ℓ.succ) (γ ℓ.castSucc)

/-- The ReLU activation pattern along a path at input `x`:
`∏_{ℓ=1}^{L} ξ^{(ℓ)}_{γ;x}` with `ξ^{(ℓ)}_{γ;x} = 1{z^{(ℓ)}_{γ(ℓ)}(x) > 0}`. -/
noncomputable def pathActivation {n : ℕ → ℕ} {L : ℕ} (ω : Weights n L) (x : Fin (n 0) → ℝ)
    (γ : NetPath n L) : ℝ :=
  ∏ ℓ : Fin L, if 0 < netZ ω x (ℓ.val + 1) (γ ⟨ℓ.val + 1, by omega⟩) then 1 else 0

/-- Index set of the dropout masks `ξ^{(ℓ+1)}_i`, `ℓ < L`, `i < n (ℓ+1)` (hidden layers
`1, …, L`). -/
abbrev MaskIndex (n : ℕ → ℕ) (L : ℕ) : Type := Σ ℓ : Fin L, Fin (n (ℓ.val + 1))

/-- The law of the dropout masks: i.i.d. Bernoulli(1/2), i.e. uniform on `Bool`. -/
noncomputable def maskLaw (n : ℕ → ℕ) (L : ℕ) : Measure (MaskIndex n L → Bool) :=
  Measure.pi fun _ => (PMF.uniformOfFintype Bool).toMeasure

/-- The `0/1` value of the dropout mask of neuron `i` in hidden layer `ℓ + 1`
(and `1` for `ℓ ≥ L`, never used). -/
def maskValue {n : ℕ → ℕ} {L : ℕ} (ξ : MaskIndex n L → Bool) (ℓ : ℕ) (i : Fin (n (ℓ + 1))) :
    ℝ :=
  if h : ℓ < L then (if ξ ⟨⟨ℓ, h⟩, i⟩ then 1 else 0) else 1

/-- Hidden states of the deep linear network with dropout:
`v^{(0)} = x`, `v^{(ℓ+1)} = D^{(ℓ+1)} W^{(ℓ+1)} v^{(ℓ)}` with `D^{(ℓ+1)} = diag(ξ^{(ℓ+1)})`. -/
noncomputable def dropoutHidden {n : ℕ → ℕ} {L : ℕ} (ω : Weights n L)
    (ξ : MaskIndex n L → Bool) (x : Fin (n 0) → ℝ) : (ℓ : ℕ) → Fin (n ℓ) → ℝ
  | 0 => x
  | ℓ + 1 => fun i => maskValue ξ ℓ i * ∑ j, weight ω ℓ i j * dropoutHidden ω ξ x ℓ j

/-- Output of the deep linear network with dropout:
`W^{(L+1)} D^{(L)} W^{(L)} ⋯ D^{(1)} W^{(1)} x`. -/
noncomputable def dropoutOutput {n : ℕ → ℕ} {L : ℕ} (ω : Weights n L)
    (ξ : MaskIndex n L → Bool) (x : Fin (n 0) → ℝ) : Fin (n (L + 1)) → ℝ :=
  fun q => ∑ j, weight ω L q j * dropoutHidden ω ξ x L j

end LesHouchesWidth
Source
Bahri, Hanin, Brossollet, Erba, Keup, Pacelli, Simon, *Les Houches Lectures on Deep Learning at Large & Infinite Width*, arXiv:2309.01592v3 (https://arxiv.org/abs/2309.01592), pp. 38–40, Sections 5.1–5.3 (weights, network recursion, Definition 2 of paths), Proposition 5.2 (dropout model).
Read-back

What the Lean code literally says, in plain math · Aristotle (Harmonic) - non-blind, same agent as drafter

Non-blind read-back. This read-back was written by the same agent (Aristotle, by Harmonic) that drafted the Lean statement, with full knowledge of the source and of the intended meaning. It is not independent testimony and should not be treated as a blind audit; an independent read-back is still recommended before launch.

The file introduces, inside the namespace LesHouchesWidth, the following objects for a depth L∈NL\in\mathbb NL∈N and a width sequence n:N→Nn:\mathbb N\to\mathbb Nn:N→N.

  • Weight index set and configurations. The index set consists of triples (ℓ,i,j)(\ell,i,j)(ℓ,i,j) with 0≤ℓ≤L0\le\ell\le L0≤ℓ≤L, i<nℓ+1i<n_{\ell+1}i<nℓ+1​, j<nℓj<n_\ellj<nℓ​. A configuration ω\omegaω assigns a real number ωℓ,i,j\omega_{\ell,i,j}ωℓ,i,j​ to each triple. The measure weightLaw n L μ is the product measure μ⊗\mu^{\otimes}μ⊗ over all triples, so the coordinates are independent with common law μ\muμ. For an arbitrary measure μ\muμ this is just the product measure. When μ\muμ is a probability measure, a registered instance makes it a probability measure.
  • Weights. For ℓ≤L\ell\le Lℓ≤L, weight ω ℓ i j =2/nℓ  ωℓ,i,j=\sqrt{2/n_\ell}\;\omega_{\ell,i,j}=2/nℓ​​ωℓ,i,j​, the weight from neuron jjj of layer ℓ\ellℓ to neuron iii of layer ℓ+1\ell+1ℓ+1. For ℓ>L\ell>Lℓ>L it is 000. If nℓ=0n_\ell=0nℓ​=0 then 2/nℓ2/n_\ell2/nℓ​ is read as 000, but then there are no such jjj.
  • ReLU. relu(t)=max⁡(t,0)\mathrm{relu}(t)=\max(t,0)relu(t)=max(t,0).
  • Preactivations. netZ ω x is defined recursively: layer 000 is the input x∈Rn0x\in\mathbb R^{n_0}x∈Rn0​. Layer ℓ+1\ell+1ℓ+1 has coordinates ∑j<nℓweight(ω,ℓ,i,j) hj\sum_{j<n_\ell}\mathrm{weight}(\omega,\ell,i,j)\,h_j∑j<nℓ​​weight(ω,ℓ,i,j)hj​, where hj=xjh_j=x_jhj​=xj​ if ℓ=0\ell=0ℓ=0 and hj=max⁡(netZ(ω,x,ℓ)j,0)h_j=\max(\mathrm{netZ}(\omega,x,\ell)_j,0)hj​=max(netZ(ω,x,ℓ)j​,0) if ℓ≥1\ell\ge1ℓ≥1. There are no biases. output ω x is layer L+1L+1L+1.
  • Jacobian entry. jacobianEntry ω x p q is the Fréchet derivative at xxx of y↦output(ω,y)qy\mapsto\mathrm{output}(\omega,y)_qy↦output(ω,y)q​, applied to the standard basis vector epe_pep​. If that map is not differentiable at xxx, the value is 000 by convention.
  • Paths. A path is a function γ\gammaγ assigning to each ℓ∈{0,…,L+1}\ell\in\{0,\dots,L+1\}ℓ∈{0,…,L+1} an index γ(ℓ)<nℓ\gamma(\ell)<n_\ellγ(ℓ)<nℓ​. pathsFromTo n L p q is the finite set of paths with γ(0)=p\gamma(0)=pγ(0)=p and γ(L+1)=q\gamma(L+1)=qγ(L+1)=q. pathWeight ω γ =∏ℓ=0Lweight(ω,ℓ,γ(ℓ+1),γ(ℓ))=\prod_{\ell=0}^{L}\mathrm{weight}(\omega,\ell,\gamma(\ell+1),\gamma(\ell))=∏ℓ=0L​weight(ω,ℓ,γ(ℓ+1),γ(ℓ)). pathActivation ω x γ =∏ℓ=0L−11{netZ(ω,x,ℓ+1)γ(ℓ+1)>0}=\prod_{\ell=0}^{L-1}\mathbf 1\{\mathrm{netZ}(\omega,x,\ell+1)_{\gamma(\ell+1)}>0\}=∏ℓ=0L−1​1{netZ(ω,x,ℓ+1)γ(ℓ+1)​>0}, which is an empty product equal to 111 when L=0L=0L=0.
  • Masks. The mask index set consists of pairs (ℓ,i)(\ell,i)(ℓ,i) with ℓ<L\ell<Lℓ<L, i<nℓ+1i<n_{\ell+1}i<nℓ+1​. maskLaw n L is the product of uniform measures on {false,true}\{\text{false},\text{true}\}{false,true}, so the masks are i.i.d. fair coins. maskValue ξ ℓ i is 111 if the coin is true and 000 if false for ℓ<L\ell<Lℓ<L, and is 111 for ℓ≥L\ell\ge Lℓ≥L.
  • Dropout network. dropoutHidden ω ξ x has layer 000 equal to xxx and layer ℓ+1\ell+1ℓ+1 with coordinates maskValue(ξ,ℓ,i)⋅∑jweight(ω,ℓ,i,j) dropoutHidden(ω,ξ,x,ℓ)j\mathrm{maskValue}(\xi,\ell,i)\cdot\sum_j\mathrm{weight}(\omega,\ell,i,j)\,\mathrm{dropoutHidden}(\omega,\xi,x,\ell)_jmaskValue(ξ,ℓ,i)⋅∑j​weight(ω,ℓ,i,j)dropoutHidden(ω,ξ,x,ℓ)j​. dropoutOutput ω ξ x has coordinates q↦∑jweight(ω,L,q,j) dropoutHidden(ω,ξ,x,L)jq\mapsto\sum_j\mathrm{weight}(\omega,L,q,j)\,\mathrm{dropoutHidden}(\omega,\xi,x,L)_jq↦∑j​weight(ω,L,q,j)dropoutHidden(ω,ξ,x,L)j​, with no mask on the output layer.

Nothing in the file imposes hypotheses on μ\muμ or on the widths; all hypotheses appear in the theorems.

Human review
  • Endorsed by Shuze Chen · Sep 24, 2026

    Confirmed by the moderator at approval.

  • Endorsed by LG · Sep 24, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me