AFTD Auto-Formalizing Theoretical Domains

relu_network_eval_continuous

theoremverified

For every natural number $k$ and every feedforward ReLU neural network net of width $k$ with rational weights and biases, the evaluation function evalNetwork net : ℝ → ℝ is continuous.

Statement

theorem relu_network_eval_continuous {k : ℕ} (net : ReLUNetwork k) :
  Continuous (evalNetwork net)
Source
arXiv:2610.06092 Section 2.1
Verified
25 Oct 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 5
  • evalNetworkEvaluation of a feedforward ReLU neural network of hidden layer width $k$ on a real input $x$, which forms an initial width-$k$ vector by…
  • reluThe rectified linear unit (ReLU) activation function maps each real number x to max(x, 0).
  • ReLUNetworkA feedforward ReLU neural network from the real line to the real line with hidden layers of width k, specified by rational affine input…
  • evalHiddenLayerEvaluation of a hidden layer of width $k$ on an input vector $x \in \mathbb{R}^k$, computing for each neuron $i$ the rectified linear unit…
  • ReLUHiddenLayerA hidden layer of width k consists of a k-by-k rational weight matrix and a rational bias vector of length k.
Used by 1
  • relu_network_zero_of_ivtIf a feedforward ReLU neural network of width $k$ evaluates to a non-positive value at 0 and a non-negative value at 1, then by the…

Read back from the Lean

For every natural number $k$ and every ReLU network net of width $k$ (with rational weights and biases, taking a scalar real input and producing a scalar real output), the evaluation function evalNetwork net : ℝ → ℝ is continuous.

Written by a model that saw only the Lean, never the English above. If the two disagree, that is worth a challenge.

The proof, explained

The proof establishes that feedforward ReLU neural network evaluation is continuous by composing continuous layer operations. First, the ReLU activation is continuous as the maximum of the identity and zero functions, which implies each hidden layer map is continuous coordinatewise and thus continuous into $\mathbb{R}^k$. By structural induction on the list of hidden layers, folding hidden layers over any continuous map preserves continuity. Finally, the network's input and output maps are affine transformations, so their composition with the folded hidden layers is continuous.

  1. The ReLU activation function $\operatorname{relu} : \mathbb{R} \to \mathbb{R}$ is continuous.

    By definition, $\operatorname{relu}(x) = \max(x, 0)$. The identity function and the constant zero function are continuous, so their pointwise maximum is continuous.

    lines 4–6

    uses continuous_id, continuous_const

      have hrelu : Continuous relu := by
        unfold relu
        simpa using (continuous_id.max continuous_const : Continuous fun x : ℝ => max x 0)
  2. For any hidden layer $l$ and coordinate index $i$, the $i$-th component function $v \mapsto \operatorname{evalHiddenLayer}(l, v)_i$ is continuous.

    The $i$-th coordinate of a hidden layer evaluation is the composition of the ReLU activation with an affine map $\sum_j w_{ij} v_j + b_i$. The affine combination is continuous by standard continuity rules (discharged by the `continuity` tactic), and composing it with the continuous ReLU function yields continuity.

    lines 7–11

      have hlayer : ∀ (l : ReLUHiddenLayer k) (i : Fin k),
          Continuous fun v : Fin k → ℝ => evalHiddenLayer l v i := by
        intro l i
        unfold evalHiddenLayer
        exact hrelu.comp (by continuity)
  3. For any hidden layer $l$, the layer evaluation function $v \mapsto \operatorname{evalHiddenLayer}(l, v)$ from $\mathbb{R}^k$ to $\mathbb{R}^k$ is continuous.

    By `continuous_pi`, a function into the product space $\mathbb{R}^k$ is continuous if each coordinate component is continuous, which was established in the previous step.

    lines 12–15

    uses continuous_pi

      have hlayer_full : ∀ l : ReLUHiddenLayer k,
          Continuous fun v : Fin k → ℝ => evalHiddenLayer l v := by
        intro l
        exact continuous_pi (hlayer l)
  4. Folding any list of hidden layers over a continuous feature map preserves continuity.

    We proceed by induction on the list of hidden layers. In the base case of an empty list, `List.foldl` returns the initial feature map, which is continuous by hypothesis. In the inductive step for a layer list $l :: ls$, `List.foldl_cons` rewrites the fold into a fold of $ls$ applied to the intermediate map $x \mapsto \operatorname{evalHiddenLayer}(l, f(x))$. This intermediate map is continuous as the composition of the continuous layer evaluation with $f$, allowing the induction hypothesis to close the goal.

    lines 16–26

    uses List.foldl_cons

      have hfold : ∀ (layers : List (ReLUHiddenLayer k)) (f : ℝ → Fin k → ℝ),
          Continuous f →
          Continuous fun x => List.foldl (fun v l => evalHiddenLayer l v) (f x) layers := by
        intro layers
        induction layers with
        | nil => intro f hf; simpa using hf
        | cons l ls ih =>
          intro f hf
          simp only [List.foldl_cons]
          have hc : Continuous fun x => evalHiddenLayer l (f x) := (hlayer_full l).comp hf
          exact ih (fun x => evalHiddenLayer l (f x)) hc
  5. The input layer mapping $x \mapsto (i \mapsto w_i^{\mathrm{in}} x + b_i^{\mathrm{in}})$ from $\mathbb{R}$ to $\mathbb{R}^k$ is continuous.

    By `continuous_pi`, it suffices to verify continuity for each coordinate. Each coordinate function $x \mapsto w_i^{\mathrm{in}} x + b_i^{\mathrm{in}}$ is continuous as the sum of a constant multiple of the identity function and a constant bias.

    lines 27–30

    uses continuous_pi, continuous_const, continuous_id

      have hinit : Continuous fun x : ℝ => fun i : Fin k => (net.in_weight i : ℝ) * x + (net.in_bias i : ℝ) := by
        apply continuous_pi
        intro i
        exact (continuous_const.mul continuous_id).add continuous_const
  6. The feature representation after passing through all hidden layers is continuous with respect to the network input.

    Applying `hfold` to the network's list of hidden layers and the continuous input map `hinit` proves that the hidden representation $x \mapsto \operatorname{net.layers.foldl} \dots x_0$ is continuous. We then unfold the definition of `evalNetwork`.

    lines 31–32

      have hhidden := hfold net.layers _ hinit
      unfold evalNetwork
  7. The weighted sum of the hidden layer activations in the output layer is continuous.

    The output sum is a finite sum over the $k$ hidden units. By `continuous_finsetSum`, it suffices to show each term is continuous. Each term multiplies a constant output weight by the $i$-th coordinate of the hidden representation, which is continuous by composing the coordinate projection `continuous_apply` with the continuous hidden representation `hhidden`.

    lines 33–38

    uses continuous_finsetSum, continuous_const, continuous_apply

      have hsum : Continuous fun x : ℝ =>
          ∑ i, (net.out_weight i : ℝ) * (List.foldl (fun v l => evalHiddenLayer l v)
            (fun i => (net.in_weight i : ℝ) * x + (net.in_bias i : ℝ)) net.layers) i := by
        apply continuous_finsetSum
        intro i _
        exact continuous_const.mul ((continuous_apply i).comp hhidden)
  8. The evaluation function $\operatorname{evalNetwork}(\mathrm{net}) : \mathbb{R} \to \mathbb{R}$ is continuous.

    The full network evaluation adds the constant output bias `net.out_bias` to the continuous weighted sum `hsum`. The sum of a continuous function and a constant is continuous.

    line 39

    uses continuous_const

      exact hsum.add continuous_const
continuous_id
The identity function on any topological space is continuous.
continuous_const
Any constant function into a topological space is continuous.
continuous_pi
A function into a product space is continuous if and only if each of its coordinate projection components is continuous.
List.foldl_cons
Folding a list `a :: l` with an operation `f` and initial accumulator `b` is equal to folding `l` starting from the updated accumulator `f b a`.
continuous_finsetSum
A finite sum of continuous functions into a topological additive monoid is continuous.
continuous_apply
The coordinate projection map taking an element of a product space to its value at index `i` is continuous.

Written by a model (gemini-3.8-flash) from the Lean proof and the goal states Lean reported at each step. Lean verified the proof; this explanation is a reading aid and is not itself machine-checked.

Lean source view module on GitHub

/-- Continuity of feedforward ReLU neural network evaluation. -/theorem relu_network_eval_continuous {k : ℕ} (net : ReLUNetwork k) :  Continuous (evalNetwork net) := by  have hrelu : Continuous relu := by    unfold relu    simpa using (continuous_id.max continuous_const : Continuous fun x : ℝ => max x 0)  have hlayer : ∀ (l : ReLUHiddenLayer k) (i : Fin k),      Continuous fun v : Fin k → ℝ => evalHiddenLayer l v i := by    intro l i    unfold evalHiddenLayer    exact hrelu.comp (by continuity)  have hlayer_full : ∀ l : ReLUHiddenLayer k,      Continuous fun v : Fin k → ℝ => evalHiddenLayer l v := by    intro l    exact continuous_pi (hlayer l)  have hfold : ∀ (layers : List (ReLUHiddenLayer k)) (f : ℝ → Fin k → ℝ),      Continuous f →      Continuous fun x => List.foldl (fun v l => evalHiddenLayer l v) (f x) layers := by    intro layers    induction layers with    | nil => intro f hf; simpa using hf    | cons l ls ih =>      intro f hf      simp only [List.foldl_cons]      have hc : Continuous fun x => evalHiddenLayer l (f x) := (hlayer_full l).comp hf      exact ih (fun x => evalHiddenLayer l (f x)) hc  have hinit : Continuous fun x : ℝ => fun i : Fin k => (net.in_weight i : ℝ) * x + (net.in_bias i : ℝ) := by    apply continuous_pi    intro i    exact (continuous_const.mul continuous_id).add continuous_const  have hhidden := hfold net.layers _ hinit  unfold evalNetwork  have hsum : Continuous fun x : ℝ =>      ∑ i, (net.out_weight i : ℝ) * (List.foldl (fun v l => evalHiddenLayer l v)        (fun i => (net.in_weight i : ℝ) * x + (net.in_bias i : ℝ)) net.layers) i := by    apply continuous_finsetSum    intro i _    exact continuous_const.mul ((continuous_apply i).comp hhidden)  exact hsum.add continuous_const
See it in the graphDiscuss this resultChallenge it