betaFeedback

WorksEngineering

From Pen-and-Paper to Machine-Checked Proofs: Lean for System Identification

Abstract

Mathematical proofs in scientific papers are often long and intricate, relying on chains of references to earlier results. This makes it difficult for readers and reviewers to verify each and every step. Interactive theorem proving offers a complement: the theorem and its proof are written as code, and every inference is checked by a small, trusted piece of software called the kernel. This paper serves as an introduction to the Lean 4 proof assistant for a system identification and control audience, assuming no prior exposure to formal methods. We first show how a Lean proof is read using two elementary examples: the first on identifiability, the second on set invariance. We then illustrate how Lean can be used to analyse results from the literature, taking as example a classic lemma on the inversion of the noise filter in prediction-error identification (Ljung, 1999, Lemma 3.1). Since in Lean every step must be justified, the formalization brings to light a subtle point: the original claim of that lemma holds almost surely, although not for every realisation, as its statement may suggest. A simple counterexample makes this concrete. Finally, the paper discusses guidelines and perspectives on the use of Lean in system identification research.

Introduction

Theoretical results in system identification and control often come with intricate proofs built on, e.g., pages of matrix inequalities, probabilistic arguments, and asymptotic analyses. Delicate steps involving limits, expectations, or modes of convergence are sometimes condensed or omitted, often for readability, for lack of space, to suit a mixed audience of engineers and mathematicians, or simply by oversight. Refereeing such proofs in detail is demanding, thus, implicit assumptions, gaps, imprecisions, and occasionally outright errors still reach the published literature.

Interactive theorem provers (proof assistants) offer a complement. The authors write the proof in a formal language, and a small, trusted program, the so-called kernel, checks every step. Landmark results in mathematics have been verified this way, including the Kepler conjecture, implemented in HOL Light and Isabelle [10], and, more recently, the polynomial Freiman–Ruzsa conjecture [9], whose proof was formalized in Lean within weeks of its announcement. In September 2026, OpenAI announced an AI-generated proof, formalized in Lean, of finite-time blow-up for a forced three-dimensional incompressible Navier–Stokes system [12], at the time of writing of this paper, the result has not been independently reviewed.

These tools have also been explored in the control community. Examples include proofs, in Coq (now Rocq), of a swing-up controller for the inverted pendulum [13] and of LaSalle’s invariance principle [3], a tutorial-style Lyapunov stability proof in KeYmaera X aimed at control engineers [7], a Lean library for stability and small-gain theory [5] and recent Lean for Control [8] and Control Theory in Lean [6] repositories containing control theoretic proofs in Lean. Despite these efforts, proof assistants are not yet widely adopted in the control community. In system identification, to the best of our knowledge, no such effort has been reported to date.

This paper serves as an introduction to Lean 4 [4] and Mathlib [1], its library of standard mathematical definitions and theorems on which new proofs can be built conveniently. It is intended for readers with a background in system identification and control, without assuming any prior exposure to proof assistants or formal verification methods.

Our contributions are threefold. First, § 2 walks the reader through a warm-up proof and two elementary examples, on identifiability under persistent excitation and on the invariance of an interval for a linear system, each shown side by side with its pen-and-paper proof. Second, § 3 illustrates the use of Lean to analyse published results, taking as example Ljung [11] on the inversion of the noise filter. As is common in textbooks, Ljung’s proof condenses some routine steps, however, formalizing it in Lean requires each of them to be justified. One step in particular, the interchange of an infinite double sum, needs a technical condition that is not automatic, and we provide a counterexample showing that it cannot be dropped. The condition is satisfied for bounded noise, for which the original claim holds unchanged. For white noise with finite variance, the standing assumption of the book, the condition, and hence the claim, holds almost surely, not for all realisations; the lemma omits this detail. Third, § 4 proposes a four-step template and guidelines for writing Lean code in system identification, illustrated on the identifiability of ARX models.

Writing and reading Lean proofs requires practice, and AI agents built on large language models (LLMs) increasingly assist with both Yang et al. [14]. The agent itself need not be trusted: whoever, or whatever, wrote a proof, Lean accepts it only after its kernel checks every step. Consequently, the user only needs to trust this kernel, which is widely scrutinised and has independent implementations, and to make sure that the statement formalized in Lean faithfully expresses the intended claim (see § 5).

The paper is accompanied by Lean code1 that compiles with Lean 4 and the matching Mathlib release. Every theorem, including the Mathlib results it builds on, relies only on the standard axioms of classical mathematics built into Lean’s logic, with no unproved steps and no additional axioms. All hypotheses are stated explicitly in each theorem (see § 2).

Lean in a nutshell

What is Lean?

Lean 4 is an interactive theorem prover based on dependent type theory, in which statements and proofs are written in a functional programming language and checked by the computer. Three ideas are central: (i) statements are types and proofs are terms: just as a real number ρ\rho has type R\mathbb{R} (written ρ:R\rho: \mathbb{R}), a proof h of ρ<1\rho< 1 has type ρ<1\rho< 1 (written h : ρ<1\rho< 1); checking a proof thus amounts to checking that a term has the claimed type, a mechanical task performed by the kernel; (ii) proofs are usually written in tactic mode: as a sequence of commands (tactics) that transform the current goal, initially the statement itself and then whatever remains to be proved, until Lean reports No goals, which means that the original statement is proven; (iii) proofs typically build on established results: instead of re-deriving known facts, one invokes theorems already proved, for instance in Mathlib, on linear algebra, analysis, or probability, much as one would cite a textbook.

A first example

Suppose we want to prove the following trivial fact:

Lemma 1 (example). Let ρ∈R\rho\in\mathbb{R} satisfy the assumption ρ<1\rho< 1. Then 0<1−ρ0 < 1 - \rho.

Proof. By simple algebraic manipulation, we have ρ<1⇒ρ−1<0⇒0<1−ρ\rho< 1 \Rightarrow\rho- 1 < 0 \Rightarrow0 < 1 - \rho.

Lean proof: A Lean proof starts with the claim to be proved (the current goal), which is progressively reduced to simpler goals until each can be closed by a known fact or a hypothesis. In Lean, the statement of Lemma 1 and its proof are written as

1 import Mathlib
2 example (ρ : ℝ) (h : ρ < 1) : 0 < 1 − ρ := by
3   linarith

The code mirrors Lemma 1, piece by piece. After example (an unnamed theorem) are the arguments: a real number ρ\rho and a hypothesis h stating ρ<1\rho< 1; after the colon comes the statement to be proved, namely 0<1−ρ0 < 1 - \rho; finally, := by opens the proof in tactic mode, here a single tactic is written on line 3. The editor (VS Code, or the browser at https://live.lean-lang.org, opened with its code by the button ▶Open in Lean Web on each listing) shows the goal state next to the cursor. With the cursor at the end of line 2, the tactic state on the right panel shows the following:

Tactic state
1 goal
ρ : ℝ
h : ρ < 1
⊢ 0 < 1 − ρ

Here, the Tactic state shows 1 goal. A goal consists of assumptions and a conclusion, separated by the turnstile symbol ⊢\vdash. The assumptions, listed above ⊢\vdash, are the objects and facts the proof may currently use: arbitrary elements of some type, such as the real number ρ\rho, statements taken as true, such as the hypothesis h : ρ < 1, and intermediate results proved earlier. The conclusion, after ⊢\vdash, is the statement that remains to be proved. The tactic linarith (short for linear arithmetic, line 3) is a Mathlib automation that proves goals following from linear equalities and inequalities among the assumptions; it closes this goal in a single step, and the tactic state becomes No goals.

The same lemma can also be proved without linarith, using two basic mechanisms of Lean: (i) rewriting the goal with a known equivalence, (ii) closing it with an assumption.

1 import Mathlib
2 example (ρ : ℝ) (h : ρ < 1) : 0 < 1 − ρ := by
3   rw [sub_pos]  -- rewrite the goal 0 < 1 − ρ into ρ < 1
4   exact h       -- this is exactly the hypothesis h: no goals left

Here, line 3 uses the Mathlib lemma sub_pos, which is a proof of the equivalence

0<a−b⟺b<a,∀a,b∈R.(1)0 < a - b \Longleftrightarrow b < a,\qquad\forall a,b \in\mathbb{R}. \tag*{(1)}

The rw (rewrite) tactic uses the equivalence sub_pos in (1) from left to right to rewrite the goal 0<1−ρ0 < 1 - \rho into ρ<1\rho< 1. We do not need to specify aa and bb, Lean matches the left-hand side of (1) against the goal and finds a=1a = 1 and b=ρb = \rho. This turns the goal exactly into hypothesis h (ρ<1\rho< 1) as specified explicitly in line 4, after which the tactic state becomes No goals and the theorem is proved.

Remark 1. A way to reach No goals without providing a full proof is the placeholder sorry, which closes any goal. Lean then warns declaration uses ‘sorry’ and #print axioms lists sorryAx among the axioms the theorem depends on. For all theorems in this paper, #print axioms reports only Lean’s three standard axioms (propext, Classical.choice, Quot.sound). This is the expected set of axioms for a sound proof. It indicates that there are no incomplete steps or custom, user-defined axioms.

We now illustrate, through two toy examples from system identification and control, how results in these fields can be formalized in Lean. A table of the Lean notation and tactics used in this paper is available in the accompanying GitHub repository.

Identifiability and persistent excitation

Parametric identification aims to recover unknown system parameters from observed input-output data. This relies on persistent excitation (PE), i.e., the input must be sufficiently rich. Without sufficient excitation, the data do not determine the parameters uniquely, and the system is unidentifiable. We formalize these concepts in the following lemma for a scalar system.

Lemma 2. Consider a scalar data-generating system yk=φkθy_k = \varphi_k\theta, where θ∈R\theta\in\mathbb{R} represents the unknown true system parameter, φk∈R\varphi_k \in\mathbb{R} is the regressor, yk∈Ry_k \in\mathbb{R} is the measured output at time kk. Let D≜{φ1,y1}\mathcal{D} \triangleq\{\varphi_1,y_1\} be the data collected at a single step from this system, and let θ^≜y1/φ1\hat{\theta} \triangleq y_1/\varphi_1 be the single-step algebraic estimator for the parameter θ\theta. Then, the true parameter θ\theta is identifiable from D\mathcal{D}, i.e.,

φ1θ1=φ1θ2⇒θ1=θ2, ∀θ1,θ2∈R,\varphi_1\theta_1 = \varphi_1\theta_2 \Rightarrow\theta_1 = \theta_2,\ \forall\theta_1,\theta_2 \in\mathbb{R},

if and only if the regressor satisfies the single-step persistent excitation (PE) condition

φ1≠0,(2)\varphi_1 \ne0, \tag*{(2)}

under which the estimator is exact, θ^=θ\hat{\theta} = \theta.

Proof. We prove both directions of the equivalence.

(Only if) Identifiability implies φ1≠0\varphi_1 \ne0: Suppose that θ\theta is identifiable from D\mathcal{D}, i.e., φ1θ1=φ1θ2⇒θ1=θ2\varphi_1\theta_1 = \varphi_1\theta_2 \Rightarrow\theta_1 = \theta_2 for all θ1,θ2∈R\theta_1,\theta_2 \in\mathbb{R}. If φ1=0\varphi_1 = 0, then φ1θ1=φ1θ2=0\varphi_1\theta_1 = \varphi_1\theta_2 = 0 for any θ1,θ2∈R\theta_1,\theta_2 \in\mathbb{R}, including θ1≠θ2\theta_1 \ne\theta_2, contradicting identifiability. Hence, φ1≠0\varphi_1 \ne0.

(If) φ1≠0\varphi_1 \ne0 implies identifiability: Suppose that φ1≠0\varphi_1 \ne0 and φ1θ1=φ1θ2\varphi_1\theta_1 = \varphi_1\theta_2. Dividing both sides by φ1\varphi_1 yields θ1=θ2\theta_1 = \theta_2. Therefore, θ\theta is identifiable from D\mathcal{D}.

Finally, since the data are generated as y1=φ1θy_1 = \varphi_1\theta, whenever φ1≠0\varphi_1 \ne0, the estimator satisfies

θ^=y1φ1=φ1θφ1=θ.\hat{\theta} = \frac{y_1}{\varphi_1} = \frac{\varphi_1\theta}{\varphi_1} = \theta.

Thus, the estimator recovers the true parameter. □

Lean proof: Box 1 proves Lemma 2 in Lean, together with an explanation in the left panel. We first state the identifiability condition as a proposition in Identifiable. Then, the theorem identifiable_iff_PE proves the necessary and sufficient condition that θ\theta is identifiable if and only if φ1≠0\varphi_1 \ne0 stated as Identifiable φ₁ ↔ φ₁ ≠ 0. The theorem is proved with a constructor tactic, which splits the equivalence into its two directions.

Next, in estimator_exact, it is proved that the algebraic estimator is the true parameter θ^=θ=y1φ1\hat{\theta} = \theta= \frac{y_1}{\varphi_1}, under the PE condition. Note that Lean needs hφh_\varphi (i.e., PE condition φ1≠0\varphi_1 \ne0) explicitly as a hypothesis in estimator_exact to prove that θ=y1φ1\theta= \frac{y_1}{\varphi_1}. In Lean, division is defined for every real number, with y/0=0y/0 = 0 (the Mathlib lemma div_zero). Without the hypothesis hφh_\varphi the claim would be false, since under zero excitation the “estimate” y1/φ1=0/0y_1/\varphi_1 = 0/0 equals 00. Thus, Lean forces us to state the PE condition, and the “only if” part of Lemma 2 shows that it cannot be dropped.

Invariant set of a linear dynamical system

Invariant sets are powerful tools for analysing safety in control systems ([2]). A set is invariant for a system if every trajectory that starts in the set remains in it for all future time. Next, we state and prove the following lemma, which gives a sufficient condition for the invariance of an interval.

Lemma 3. For a scalar discrete-time system xk+1=axkx_{k+1} = ax_k, if ∣a∣≤1\lvert a\rvert\le1 then any interval set R:=[−r,r]\mathcal{R} := [-r,r] is invariant, i.e., x0∈R⇒xk∈Rx_0 \in\mathcal{R} \Rightarrow x_k \in\mathcal{R} for all k∈Nk \in\mathbb{N}.

Proof. We prove the result by mathematical induction. Base case (k=0k = 0): By assumption, x0∈Rx_0 \in\mathcal{R}. Hence, ∣x0∣≤r\lvert x_0\rvert\le r. Inductive step: Suppose that xk∈Rx_k \in\mathcal{R} for some k∈Nk \in\mathbb{N}, i.e., ∣xk∣≤r\lvert x_k\rvert\le r. From the system dynamics xk+1=axkx_{k+1} = ax_k, we obtain ∣xk+1∣=∣axk∣=∣a∣∣xk∣\lvert x_{k+1}\rvert= \lvert ax_k\rvert= \lvert a\rvert\lvert x_k\rvert. Since ∣a∣≤1\lvert a\rvert\le1, it follows that ∣xk+1∣≤∣xk∣≤r\lvert x_{k+1}\rvert\le\lvert x_k\rvert\le r. Thus, xk+1∈Rx_{k+1} \in\mathcal{R}. By mathematical induction, xk∈Rx_k \in\mathcal{R} for all k∈Nk \in\mathbb{N}. Hence, R\mathcal{R} is invariant. □

Box 1: Identifiability from one step: Lemma 2 (left) and Identification.lean (right)

Definition (L1–3). θ\theta is identifiable from D\mathcal{D} if different parameters give different data: φ1θ1=φ1θ2\varphi_1\theta_1 = \varphi_1\theta_2 implies θ1=θ2\theta_1 = \theta_2. The def gives this proposition (a Prop) the name Identifiable φ1\varphi_1.

Identifiability (L5–6): Identifiable φ1↔φ1≠0\varphi_1 \leftrightarrow\varphi_1 \ne0.

Proof. constructor (L7) splits the equivalence into its two implications, one bullet · each (L8, L11).

  • Only if (L8–10): since φ1≠0\varphi_1 \ne0 means “φ1=0\varphi_1 = 0 implies False”, intro adds to the assumptions both hid : Identifiable φ1\varphi_1 and hφ\varphi : φ1=0\varphi_1 = 0, and the goal becomes ⊢\vdash False. With φ1=0\varphi_1 = 0, θ1=0\theta_1 = 0 and θ2=1\theta_2 = 1 give the same output (checked by simp): zero excitation cannot tell them apart. So identifiability yields h01 : 0=10 = 1 (L9), which norm_num refutes (L10).

  • If (L11–12): intro adds hφ\varphi : φ1≠0\varphi_1 \ne0, θ1\theta_1, θ2\theta_2 and hy : φ1∗θ1=φ1∗θ2\varphi_1 * \theta_1 = \varphi_1 * \theta_2 to the assumptions; cancelling φ1\varphi_1 (Mathlib lemma mul_left_cancel0) gives θ1=θ2\theta_1 = \theta_2.

Estimator (L14–16). If y1=φ1θy_1 = \varphi_1\theta and φ1≠0\varphi_1 \ne0, then θ^=y1/φ1=θ\hat{\theta} = y_1/\varphi_1 = \theta.

Proof. Substitute the data (L17); the goal becomes ⊢φ1∗θ/φ1=θ\vdash\varphi_1 * \theta/ \varphi_1 = \theta. Cancel φ1\varphi_1 (L18). The tactic field_simp simplifies and clears denominators, and it may cancel φ1\varphi_1 only because the hypothesis hφ\varphi : φ1≠0\varphi_1 \ne0 is in the context.

-- θ is identifiable from D = {φ₁, y₁}: equal outputs force equal θ.
def Identifiable (φ₁ : R) : Prop :=
  ∀ θ₁ θ₂ : R, φ₁ * θ₁ = φ₁ * θ₂ → θ₁ = θ₂

-- Lemma 1: θ is identifiable from D if and only if φ₁ ≠ 0 (PE).
theorem identifiable_iff_PE (φ₁ : R) : Identifiable φ₁ ↔ φ₁ ≠ 0 := by
  constructor

· intro hid hφ
  have h01 := hid 0 1 (by simp [hφ])
  norm_num at h01

· intro hφ θ₁ θ₂ hy
  exact mul_left_cancel₀ hφ hy

-- Lemma 1 (estimator): under PE the estimate θ̂ = y₁ / φ₁ is the true θ.
theorem estimator_exact (θ φ₁ y₁ : R) (hdata : y₁ = φ₁ * θ)
    (hφ : φ₁ ≠ 0) : y₁ / φ₁ = θ := by
  rw [hdata]
  field_simp

Lean proof: In Box 2, we provide the proof of Lemma 3 with Lean code. In particular, we first prove the one-step statement (Claim 1) as a chain of inequalities, written with Lean’s calc construct, which mirrors the theoretical proof line by line, and then the invariance condition for all k∈Nk \in\mathbb{N} (Claim 2), proved by induction on kk, as in the definition of an invariant set. The proof ends in the state No goals, proving Lemma 3.

Prediction: inverting the noise filter

An instructive use case for Lean is the analysis of existing results from the literature. In this section we illustrate this on a classic lemma from prediction-error identification, Ljung [11], on the inversion of the noise filter. We first report the lemma and its proof as given in the book. The Lean formalization brings out a delicate point, the interchange of an infinite double sum, which the proof takes for granted. Justifying it requires either a stronger hypothesis or a weaker conclusion: for bounded noise the original claim holds for every realisation, whereas for white noise with finite variance it holds instead almost surely, but not for all realisations. We discuss both options, and state the resulting lemma certified in Lean.

Box 2: Invariance of an interval: Lemma 3 (left) and Tutorial.lean (right)

Claim 1. If ∣a∣≤1|a| \le1 and ∣x∣≤r|x| \le r, then ∣ax∣≤r|ax| \le r (L2–3).

Proof.

∣ax∣=∣a∣ ∣x∣(L4)≤1⋅∣x∣(L5–6)=∣x∣(L7)≤r(L8)\begin{aligned} |ax| &= |a|\,|x| &&\text{(L4)}\\ &\le1\cdot|x| &&\text{(L5–6)}\\ &= |x| &&\text{(L7)}\\ &\le r &&\text{(L8)} \end{aligned}

After L4 the goal reads ⊢∣a∣∗∣x∣≤r\vdash|a| * |x| \le r; the calc chain then proves the updated goal state: the first two steps use library lemmas (mul_le_mul_of_nonneg_right, one_mul) and the last the hypothesis (hx).

Claim 2. For xk+1=axkx_{k+1} = ax_k with ∣a∣≤1|a| \le1 and ∣x0∣≤r|x_0| \le r, ∣xk∣≤r|x_k| \le r for all kk (L14–16). The dynamics xk+1=axkx_{k+1} = ax_k from the initial state x0x_0 is implemented by the traj function (L9–12).

Proof. By mathematical induction on kk (L17–18). Base k=0k = 0: x0x_0 satisfies the bound by assumption (L19–21).

Step: assume ∣xk∣≤r|x_k| \le r (the induction hypothesis ih). Then xk+1=axkx_{k+1} = ax_k satisfies ∣xk+1∣≤r|x_{k+1}| \le r by Claim 1 (L22–24). Note that a proved theorem is used like a function: interval_invariant a r (traj a x0 k) ha ih (L24) applies Claim 1 to aa, rr, xkx_k and to the proofs ha, ih of its hypotheses. In the step case, Lean displays the goal state

ih : |traj a x0 k| ≤ r ⊢ |traj a x0 (k + 1)| ≤ r

and after unfolding traj (L23) the goal becomes ∣a∗traj⁡ax0k∣≤r|a * \operatorname{traj} a x_0 k| \le r, which is exactly Claim 1.

The original lemma

Consider the disturbance

v(t)=H(q)e(t)=∑k=0∞h(k)e(t−k),(3)v(t) = H(q)e(t) = \sum_{k=0}^{\infty} h(k)e(t-k), \tag*{(3)}

where the white noise {e(t)}\{e(t)\} is a sequence of independent random variables with zero mean and variance λ\lambda, qq denotes the forward time-shift operator, qe(t)=e(t+1)qe(t) = e(t+1), and H(q):=∑k=0∞h(k)q−kH(q) := \sum_{k=0}^{\infty} h(k)q^{-k} is stable, i.e., ∑k=0∞∣h(k)∣<∞\sum_{k=0}^{\infty} |h(k)| < \infty.

The noise model is invertible [11 Sec. 3.2] if for known v(s)v(s), s≤ts \le t, e(t)e(t) can be computed as

e(t)=H~(q)v(t)=∑k=0∞h~(k)v(t−k),(4)e(t) = \widetilde{H}(q)v(t) = \sum_{k=0}^{\infty} \widetilde{h}(k)v(t-k), \tag*{(4)}

with ∑k=0∞∣h~(k)∣<∞\sum_{k=0}^{\infty} |\widetilde{h}(k)| < \infty. The following lemma characterizes the inverse noise filter H~(q)\widetilde{H}(q) in terms of H(q)H(q). Lemma 4, Remark 2 and the proof below are reproduced almost verbatim from Ljung [11].

Lemma 4 (Ljung, [11]). Consider {v(t)}\{v(t)\} defined as in (3) and assume that HH is stable.

Let

H(z)=∑k=0∞h(k)z−k(5)H(z) = \sum_{k=0}^{\infty} h(k)z^{-k} \tag*{(5)}

and assume that the function 1/H(z)1/H(z) is analytic in ∣z∣≥1|z| \ge1:

1H(z)=∑k=0∞h~(k)z−k(6)\frac{1}{H(z)} = \sum_{k=0}^{\infty} \tilde{h}(k)z^{-k} \tag*{(6)}

Define the filter H−1(q)H^{-1}(q) by H−1(q)=∑k=0∞h~(k)q−kH^{-1}(q) = \sum_{k=0}^{\infty} \tilde{h}(k)q^{-k}. Then, H~(q)=H−1(q)\widetilde{H}(q) = H^{-1}(q) satisfies (4).

Remark 2 (Ljung, [11]). That (6) exists for ∣z∣≥1|z| \ge1 also means that H−1(q)H^{-1}(q) is stable: ∑k∣h~(k)∣<∞\sum_k |\tilde{h}(k)| < \infty.

Proof. Step A. For ∣z∣≥1|z| \ge1, multiplying (5) by (6) and collecting the powers by substituting ℓ=k+s\ell= k+s we get,

1=∑k=0∞∑s=0∞h(k)h~(s)z−(k+s)=∑ℓ=0∞(∑k=0ℓh(k)h~(ℓ−k))z−ℓ,1 = \sum_{k=0}^{\infty}\sum_{s=0}^{\infty} h(k)\tilde{h}(s)z^{-(k+s)} = \sum_{\ell=0}^{\infty}\left(\sum_{k=0}^{\ell}h(k)\tilde{h}(\ell-k)\right)z^{-\ell},

which implies that

∑k=0ℓh(k)h~(ℓ−k)=δ(ℓ)={1if ℓ=00if ℓ≠0(7)\sum_{k=0}^{\ell}h(k)\tilde{h}(\ell-k)=\delta(\ell)= \begin{cases} 1 & \text{if }\ell=0\\ 0 & \text{if }\ell\ne0 \end{cases} \tag*{(7)}

Step B. Now let {v(t)}\{v(t)\} be defined by (3) and consider:

∑k=0∞h~(k)v(t−k)=∑k=0∞∑s=0∞h~(k)h(s)e(t−k−s)=∑ℓ=0∞(∑k=0ℓh~(k)h(ℓ−k))e(t−ℓ)=e(t),\begin{aligned} \sum_{k=0}^{\infty}\tilde{h}(k)v(t-k) = \sum_{k=0}^{\infty}\sum_{s=0}^{\infty}\tilde{h}(k)h(s)e(t-k-s) \\ &= \sum_{\ell=0}^{\infty}\left(\sum_{k=0}^{\ell}\tilde{h}(k)h(\ell-k)\right)e(t-\ell)=e(t), \end{aligned}

where the second equality uses ℓ=k+s\ell= k+s and the last equality uses (7).

The interchange of the infinite double sum

In Step B, the second equality swaps the summation order of an infinite double sum. The original sum adds the terms h~(k)h(s)e(t−k−s)\tilde{h}(k)h(s)e(t-k-s) row by row (over ss, then over kk), but the rearranged sum is along the antidiagonals k+s=ℓk+s=\ell. Such a swap requires a justification; without one, equality can fail, as Example 1 below illustrates.

Example 1 (counterexample to Step B). Let H(q)=1−12q−1H(q)=1-\frac{1}{2}q^{-1}, which satisfies every hypothesis of Lemma 4, with h~(k)=2−k\tilde{h}(k)=2^{-k}. For e(t)=2−te(t)=2^{-t}, t∈Zt\in\mathbb{Z}, we get v(t)≡0v(t)\equiv0. Hence H−1(q)v(t)=∑kh~(k)v(t−k)=0≠e(t)H^{-1}(q)v(t)=\sum_k\tilde{h}(k)v(t-k)=0\ne e(t), whereas summing the same terms along the antidiagonals, as in Step B, gives e(t)e(t).

Note that the counterexample involves a particular sequence ee, which one would hardly call noise. It grows into the past exactly as fast as h~\tilde{h} decays, so that the terms do not decay in kk. Such a sequence is however not excluded by Lemma 4, hence the stated identity does not hold for every possible realisation. We remark that Lean did not discover the counterexample by itself. Rather, it refused to verify the interchange until a justification was supplied.

Justifying the interchange

We present two ways to justify the interchange in the summation: restrict the noise to a bounded range, so that the original claim holds for every realisation, or allow unbounded random noise and weaken the conclusion to hold almost surely.

Bounded noise. By Fubini’s theorem for series, the swap is valid if the double series converges absolutely:

Xt:=∑k,s≥0∣h~(k)∣∣h(s)∣∣e(t−k−s)∣<∞.(8)X_t := \sum_{k,s\geq0} \lvert\tilde{h}(k)\rvert\lvert h(s)\rvert\lvert e(t-k-s)\rvert< \infty. \tag*{(8)}

If ee is bounded, ∣e(t)∣≤M\lvert e(t)\rvert\leq M, then Xt≤M∥h~∥1∥h∥1<∞X_t \leq M\lVert\tilde{h}\rVert_1\lVert h\rVert_1 < \infty, and the identity holds for every realisation.

Unbounded noise. The bounded-noise hypothesis can be too restrictive. If ee is assumed to be a white noise with finite variance λ\lambda as in the book, its realisations may be unbounded. Nonetheless, condition (8) still holds almost surely: by Tonelli’s theorem, EXt≤sup⁡sE∣e(s)∣∥h~∥1∥h∥1≤λ∥h~∥1∥h∥1<∞\mathbb{E}X_t \leq\sup_s \mathbb{E}\lvert e(s)\rvert\lVert\tilde{h}\rVert_1\lVert h\rVert_1 \leq\sqrt{\lambda}\lVert\tilde{h}\rVert_1\lVert h\rVert_1 < \infty, since E∣e(s)∣≤(Ee2(s))1/2=λ\mathbb{E}\lvert e(s)\rvert\leq\left(\mathbb{E}e^2(s)\right)^{1/2} = \sqrt{\lambda}; hence Xt<∞X_t < \infty with probability one, for all t∈Zt \in\mathbb{Z}. On each such realisation Fubini’s theorem applies, so the lemma holds with probability one, although not for each and every realisation.

The precise statement

We now state the lemma in precise form for possibly unbounded random noise. The bounded case follows from the same proof, with (8) holding for every realisation.

Lemma 5 (precise form). Consider {v(t)}\{v(t)\}, H(z)H(z), h~(k)\tilde{h}(k) and H−1(q)H^{-1}(q) as in Lemma 4, and assume:

(A1)(A1) the filters HH and H−1H^{-1} are stable: ∑k∣h(k)∣<∞\sum_k \lvert h(k)\rvert< \infty and ∑k∣h~(k)∣<∞\sum_k \lvert\tilde{h}(k)\rvert< \infty;

(A2)(A2) (6) holds, with a convergent series, for every ∣z∣≥1\lvert z\rvert\geq1;

(A3)(A3) sup⁡tE∣e(t)∣<∞\sup_t \mathbb{E}\lvert e(t)\rvert< \infty.

Then, with probability one, for every t∈Zt \in\mathbb{Z}, the series defining v(t)v(t) converges absolutely and H−1(q)v(t)=e(t)H^{-1}(q)v(t) = e(t), that is, H~(q)=H−1(q)\tilde{H}(q) = H^{-1}(q) satisfies (4).

(A1)(A1)–(A2)(A2) are the parts of Ljung’s hypotheses on HH that the proof uses, and they follow from those hypotheses when $1/H$ is analytic on a neighbourhood of ∣z∣≥1(xref‘Remark2‘).\lvert z\rvert\geq1 ({xref}`Remark 2`).(A3)$ holds for zero-mean white noise with finite variance λ\lambda, since E∣e(t)∣≤λ\mathbb{E}\lvert e(t)\rvert\leq\sqrt{\lambda}.

The Lean proof of Lemma 5 is provided in our repository (Lemma_3_1_Ljung.lean). It follows Steps A and B of the proof of Lemma 4; the only addition is that (8) is first established almost surely (§ 3.3), which justifies the interchange in Step B.

In summary, because Lean accepts no step without justification, formalizing Lemma 4 makes explicit that its conclusion holds almost surely, although not for every realisation. The interchange of summations in Step B requires a specific condition: the first-moment bound (A3), which white noise with finite variance satisfies. For bounded noise, the original claim holds for every realisation.

Template Lean code for system identification

This section presents a code template, so that readers can start formalizations of their own system identification results in Lean.

A four-step template

  1. Parameters and data. Declare them as Lean types: a scalar parameter with type R\mathbb{R} (e.g., Box 1), a parameter vector as a structure or Fin⁡d→R\operatorname{Fin} d \to\mathbb{R}, a signal as Z→R\mathbb{Z} \to\mathbb{R}, and a random signal as Z→Ω→R\mathbb{Z} \to\Omega\to\mathbb{R} on a probability space (Ω,μ)(\Omega,\mu).

  1. Model structure. Define the model, or its predictor, with def as a function of the parameter, e.g., traj in Box 2, or the filter H(q)e(t)H(q)e(t) of (3), filt (see Lemma_3_1_Ljung.lean).

  1. Claim. State the property as a theorem whose proof is stated as sorry initially, and every assumption is a named hypothesis, such as hA1, hA2, hA3 for (A1)–(A3) of Lemma 5. Lean checks that the statement is well formed, and one can compare it, symbol by symbol, with the theoretical statement.

  1. Proof. Replace sorry one tactic at a time, reading the goal state; move intermediate claims into separate lemmas, such as Claim 1 of Box 2, or Steps A and B of the proof of Lemma 4.

Three definitions given in Template.lean can set the stage:

-- a signal u(t), t ∈ ℤ
abbrev Signal := ℤ → ℝ
-- a model structure (Def. 4.3): M θ u y t is the prediction ŷ(t|θ)
abbrev ModelStructure (Θ : Type) := Θ → Signal → Signal → Signal
variable {Θ : Type}
-- global identifiability (Defs. 4.6–4.7)
def IsIdentifiable (M : ModelStructure Θ) : Prop :=
  ∀ θ₁ θ₂ : Θ, M θ₁ = M θ₂ → θ₁ = θ₂

Here, ModelStructure(Θ):=Θ→(Z→R)u→(Z→R)y→(Z→R)y^(\Theta) := \Theta\to(\mathbb{Z} \to\mathbb{R})_u \to(\mathbb{Z} \to\mathbb{R})_y \to(\mathbb{Z} \to\mathbb{R})_{\hat{y}} denotes the predictor in curried form: it takes the parameter θ\theta, the input uu and the output yy, one at a time, and returns the predicted signal y^(t∣θ)\hat{y}(t|\theta).

The following listing applies the template to the ARX structure and proves that it is strictly globally identifiable, as stated in Ljung [11]:

-- Step 1: ARX model parameters. See Ljung's (4.8).
@[ext] structure ARXParams (na nb : ℕ) where
  a : Fin na → ℝ   -- a i is the coefficient of y(t-1-i)
  b : Fin nb → ℝ   -- b j is the coefficient of u(t-1-j)

-- Step 2: the model structure, given by its predictor (4.10)–(4.12).
def arx (na nb : ℕ) : ModelStructure (ARXParams na nb) :=
  fun θ u y t =>
    ∑ i, θ.a i * y (t - 1 - i.val) + ∑ j, θ.b j * u (t - 1 - j.val)

-- A unit pulse at time s: the test signal of the proof.
def pulse (s : ℤ) : Signal := fun t => if t = s then 1 else 0

-- Step 3: the claim, first stated with `sorry` as its proof.
theorem arx_isIdentifiable (na nb : ℕ) :
    IsIdentifiable (arx na nb) := by
  -- Step 4: the proof. A pulse in y (or u) isolates one coefficient.
  intro θ₁ θ₂ h                  -- h : arx θ₁ = arx θ₂
  have hM : ∀ u y t, arx na nb θ₁ u y t = arx na nb θ₂ u y t := by
    intro u y t; rw [h]          -- equal predictions everywhere
  ext i                           -- compare a i, then b i
  · -- u = 0, y = pulse at time −1−i: ŷ(0|θ) = −a i
    simpa [arx, pulse, Fin.val_inj] using hM 0 (pulse (−1 − i.val)) 0
  · -- u = pulse at time −1−i, y = 0: ŷ(0|θ) = b i
    simpa [arx, pulse, Fin.val_inj] using hM (pulse (−1 − i.val)) 0 0

Discussion on Lean proofs

A potential concern is that checking a Lean proof may be more tedious than reviewing and understanding a conventional one. In practice, however, step-by-step verification is handled entirely by Lean’s kernel, while LLMs can assist in reading and writing the code. Crucially, the kernel only checks proofs, not statements. A proof may be formally valid, yet verify a statement that differs from the intended theoretical claim. It is important to ensure that the formal statement in Lean, i.e., its assumptions and conclusion, faithfully represents the intended claim. Once the statement is verified, the correctness of the proof rests solely on the small Lean kernel. The effort saved on line-by-line verification can then go to what matters most: judging whether the result is significant and its proof insightful.

In this paper, the Lean code was written with the help of the Claude Code AI assistant, and the authors reviewed the statements and their match with the original results.

Conclusions

This paper presented a first perspective on the use of Lean in system identification. Through a series of illustrative examples, we showed how conventional mathematical arguments can be complemented by formal, machine-checkable proofs. More generally, accompanying theoretical results with Lean proofs could increase the reliability, transparency, and reproducibility of research. Formal proofs may help authors detect missing assumptions, allow reviewers and readers to verify results without manually checking every algebraic step, and provide reusable libraries of certified results on which more advanced contributions can be built.

LLMs can substantially reduce the effort required to produce such formalizations by translating mathematical arguments into Lean code, searching existing libraries, and proposing intermediate lemmas. Importantly, regardless of whether a proof is written by a human or generated by an AI system, every accepted proof is checked by Lean’s kernel. Human supervision nevertheless remains essential to ensure that the formal statement faithfully represents the intended mathematical result and that its assumptions and conclusions are scientifically meaningful.

We therefore envision Lean not as a replacement for conventional mathematical reasoning, but as a companion to it. Pen-and-paper proofs provide intuition and explanation, while formal proofs provide an additional layer of and reproducible verification. Developing this combination further may contribute to stronger and more verifiable theoretical foundations for system identification and control.

Acknowledgments

The activities of Marco Forgione have been supported by the HASLER STIFTUNG under the project ARCADE: Agentic Research for Controller Architecture Discovery and Evaluation.

References

  1. [1]Jeremy Avigad and Patrick Massot. Mathematics in Lean. Online textbook, https://leanprover-community.github.io/mathematics_in_lean/, 2025.
  2. [2]F. Blanchini. Set invariance in control. Automatica, 35(11):1747–1767, 1999.DOI
  3. [3]Cyril Cohen and Damien Rouhling. A formal proof in Coq of LaSalle’s invariance principle. In Interactive Theorem Proving (ITP 2017), pages 148–163. Springer, 2017.DOI
  4. [4]Leonardo de Moura and Sebastian Ullrich. The Lean 4 theorem prover and programming language. In Automated Deduction – CADE 28, pages 625–635. Springer, 2021.DOI
  5. [5]Moritz Doll and Iman Shames. Foundations of machine-checked control theory in Lean, 2026. arXiv:2607.19727.arxiv.org/abs/2607.19727
  6. [6]M. Forgione. control-theory-in-lean. https://github.com/forgi86/control-theory-in-lean, 2026. Accessed: 2026-11-03.
  7. [7]Mario Gleirscher, Rehab Massoud, Dieter Hutter, and Christoph Lüth. How deduction systems can help you to verify stability properties. In 2024 IEEE 63rd Conference on Decision and Control (CDC), pages 5218–5224. IEEE, 2024.DOI
  8. [8]A. Gokhale and F. Bullo. LeanForControl. https://anandgokhale.github.io/LeanForControl/, 2026. Accessed: 2026-11-03.
  9. [9]W. T. Gowers, Ben Green, Freddie Manners, and Terence Tao. On a conjecture of Marton. Annals of Mathematics, 201(2):515–549, 2025. doi: 10.4007/annals.2025.201.2.5.DOI
  10. [10]Thomas Hales et al. A formal proof of the Kepler conjecture. Forum of Mathematics, Pi, 5:e2, 2017.
  11. [11]Lennart Ljung. System Identification: Theory for the User. Prentice Hall PTR, Upper Saddle River, NJ, 2nd edition, 1999. ISBN 0-13-656695-2.
  12. [12]OpenAI. Finite time blowup for Navier–Stokes. https://cdn.openai.com/pdf/32d9f210-8b73-45e0-91bc-82a30aef8a9a/navier-stokes.pdf, September 2026.
  13. [13]Damien Rouhling. A formal proof in Coq of a control function for the inverted pendulum. In Proc. Certified Programs and Proofs (CPP 2018), pages 28–41. ACM, 2018.
  14. [14]Kaiyu Yang et al. LeanDojo: Theorem proving with retrieval-augmented language models. In Proc. NeurIPS 2023, 2023.arxiv.org/abs/2306.15626

Paper details

vlnc:W_s7p3nkjd
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 1

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Engineering

Not recorded for this paper

View statement
Looking for related papers…
Contents