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

Manas Mejari, Dario Piga, Marco ForgionearXiv 2026 · arXiv

TL;DR

This paper introduces the Lean 4 proof assistant to the system identification and control community, demonstrating how "coding" mathematical proofs can eliminate human error. By formalizing a classic lemma from Lennart Ljung’s seminal textbook, the authors discovered that a long-accepted result actually requires a subtle "almost surely" qualification that was missing from the original pen-and-paper statement.

What Problem Does This Paper Address?

Theoretical results in system identification—the field of building mathematical models of dynamical systems from data—often rely on incredibly dense proofs involving matrix inequalities, stochastic processes, and asymptotic limits. Because these proofs are long and space is limited in journals, authors frequently skip "routine" steps or leave assumptions implicit.

This creates a reliability gap: reviewers may struggle to verify every line, and subtle errors or missing conditions can persist in the literature for decades. The authors propose Interactive Theorem Proving (ITP) as a solution. In ITP, proofs are written in a formal programming language and checked by a "kernel"—a small, highly scrutinized piece of software that ensures every single logical inference follows strictly from established axioms.

Methods

The authors utilize Lean 4, a modern functional programming language and theorem prover, along with Mathlib, Lean’s massive library of formalized mathematics.

The paper follows a pedagogical approach:

  1. Warm-up: They demonstrate basic Lean syntax using "tactic mode," where a user issues commands to transform a mathematical goal until no goals remain.
  2. Elementary Examples: They formalize two foundational concepts: identifiability (whether a model's parameters can be uniquely determined) and set invariance (whether a system stays within safe bounds).
  3. The Deep Dive: They attempt to formalize Lemma 3.1 from Ljung (1999), which concerns the inversion of noise filters.
  4. Template Creation: They provide a four-step workflow (Parameters $\rightarrow$ Model Structure $\rightarrow$ Claim $\rightarrow$ Proof) to help other researchers begin formalizing their own work.

Datasets

Not discussed in the paper. As a theoretical paper focused on formal logic and verification, it does not use empirical datasets or benchmarks in the traditional machine learning sense.

Key Insights and Ideas

  • Lean as a "Strict Teacher": The most significant insight came when Lean "refused" to verify a step in Ljung’s proof involving the interchange of an infinite double sum. While a human reader might gloss over this as "obvious," Lean required a formal justification (like Fubini’s theorem).
  • The "Almost Surely" Catch: This refusal led the authors to realize that the original lemma statement was technically incomplete. For the proof to hold for white noise, one must assume a first-moment bound. Without it, the identity only holds "almost surely" (with probability one) rather than for every possible realization of noise. They even provided a specific counterexample where the original claim fails.
  • AI-Assisted Formalization: Interestingly, the authors noted that they used Claude Code (an AI assistant) to help write the Lean code. This suggests a future where researchers use LLMs to draft formal proofs, while the Lean kernel provides the absolute guarantee of correctness that LLMs currently lack.

Key Results

  • Verification of ARX Identifiability: The authors successfully produced a machine-checked proof that Auto-Regressive with Exogenous variables (ARX) models are strictly globally identifiable.
  • Correction of the Record: The paper provides a "precise form" of Ljung’s Lemma 3.1 (labeled Lemma 5 in this paper), explicitly stating the three necessary assumptions ($A1$–$A3$) required for the result to be mathematically sound.
  • Code Repository: The authors released a GitHub repository containing the Lean code for all examples, providing a foundation for a "Lean for System Identification" library.

Limitations and Future Work

  • Learning Curve: The authors acknowledge that Lean is difficult to master for those without a background in formal methods or functional programming.
  • Library Gaps: While Mathlib is vast, many specific tools for control theory (like complex frequency-domain analysis or specific stochastic calculus results) are still being built out.
  • Future Directions: The authors envision Lean not as a replacement for human intuition, but as a "companion." Future work involves expanding the formalized library to cover more advanced topics like closed-loop identification and nonlinear system analysis.

Summary updated

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.
BibTeX
@misc{mejari2026from,
  author = {Manas Mejari and Dario Piga and Marco Forgione},
  title = {{From Pen-and-Paper to Machine-Checked Proofs: Lean for System Identification}},
  year = {2026},
  eprint = {2611.18220},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.18220},
}
Figure