A Verified Implementation of the L*-Algorithm in Lean
Dominik Mascherbauer, Bernhard K. Aichernig
cs.FL
Nov 26, 2026 · v1
cs.LO
TL;DR
Implements Angluin's L* automata-learning algorithm in Lean 4, building on Mathlib DFAs, and proves termination, minimality, and correctness directly about the executable code.
Abstract
Angluin's L*-algorithm learns the minimal deterministic finite automaton (DFA) of an unknown regular language from membership and equivalence queries to a teacher. It underpins active automata learning, yet its correctness guarantees have so far rested on pen-and-paper proofs, separate from the implementations in use. We close this gap for L* using Lean 4, which is both a functional programming language and an interactive theorem prover: we implement L* in the Minimally Adequate Teacher framework and prove its properties directly about the executable code. We establish two results: (1) Termination: for every teacher that answers consistently with a regular language and returns only genuine counterexamples, learning terminates. (2) Minimality and correctness: the learned DFA is never larger than the minimal DFA of that language, and if the teacher answers equivalence queries truthfully, it is isomorphic to that minimal DFA. The result is a single artifact that is both a mechanically checked proof and an executable learner. To the best of our knowledge, this is the first mechanized correctness proof of the classical L*-algorithm.
Problem
Angluin's L* algorithm for learning minimal DFAs from membership and equivalence queries underpins active automata learning. Its correctness has rested on pen-and-paper proofs that are separate from the implementations in use.
Approach
L* is implemented in Lean 4 within the Minimally Adequate Teacher framework. Computable data structures (lists, AList) are used and connected to Mathlib's DFA and regular-language definitions. A Teacher structure bundles the membership and equivalence queries with proof obligations: the target language is regular and every counterexample is genuine. The learning loop is reordered so that each recursive call starts from a closed and consistent observation table, which simplifies the termination proof.
Results
Termination is proved for every teacher that is consistent with a regular language and returns genuine counterexamples. The learned DFA is proved never larger than the minimal DFA, and for a complete teacher it is isomorphic to the minimal DFA. The roughly 2,400-line artifact uses only Lean's standard axioms, is executable (shown with a random-word teacher), and is claimed as the first mechanized correctness proof of classical L*.