Deciding Kleene Algebras in Coq
We present a reflexive tactic for deciding the equational theory of Kleene algebras in the Coq proof assistant. This tactic relies on a careful implementation of efficient finite automata algorithms, so that it solves casual equations instantaneously and properly scales to larger expressions. The decision procedure is proved correct and complete: correctness is established w.r.t. any model by formalising Kozen’s initiality theorem; a counter-example is returned when the given equation does not hold. The correctness proof is challenging: it involves both a precise analysis of the underlying automata algorithms and a lot of algebraic reasoning. In particular, we have to formalise the theory of matrices over a Kleene algebra. We build on the recent addition of firstorder typeclasses in Coq in order to work efficiently with the involved algebraic structures.
💡 Research Summary
The paper presents a reflective tactic for the Coq proof assistant that decides the equational theory of Kleene algebras. Kleene algebras capture the algebraic structure of regular expressions, binary relations, and matrices, and their equational theory is PSPACE‑complete, making efficient implementation crucial. The authors base their decision procedure on Kozen’s initiality theorem, which states that the algebra of regular languages is the initial object among all Kleene algebras. Consequently, any equation that holds in the regular‑language model holds in every Kleene algebra model.
To exploit this theorem, the authors encode finite automata as three matrices (initial‑state vector u, transition matrix M, final‑state vector v). The language accepted by the automaton is expressed as the scalar expression u·M*·v, where M* denotes the Kleene star applied to the matrix. A central technical contribution is the formalisation that matrices over a Kleene algebra themselves form a Kleene algebra, allowing the star operation to be defined on matrices and the automata semantics to be carried out algebraically.
The implementation uses Coq’s first‑class typeclasses to build a modular hierarchy: Graph (the carrier of morphisms indexed by a set of types), Monoid_Ops, SemiLattice_Ops, and Star_Op. This “typed Kleene algebra” framework accommodates heterogeneous binary relations (where source and target types differ) and rectangular matrices, which are essential for parts of the proof. By defining operations generically over the Graph class, the same notation and lemmas can be shared across several concrete models: syntactic regular expressions, languages, binary relations, and matrices over both.
The decision tactic follows a classic reflective pattern. Given two regular‑expression terms, a reification phase builds their syntactic representation inside Coq. The core algorithm then converts each expression to a nondeterministic finite automaton (NFA), determinises it to a DFA, minimises the DFA, and finally checks isomorphism between the two minimal DFAs. If they are isomorphic, the tactic returns true and a Coq proof that the original equation holds; otherwise it extracts a counter‑example word and returns false, providing a concrete witness of inequivalence.
Efficiency is addressed at both the algorithmic and implementation levels. The authors avoid naïve matrix‑based automaton representations, which would be computationally prohibitive, and instead rely on well‑optimised automata algorithms (Hopcroft minimisation, sparse matrix encodings, bit‑set representations). Benchmarks show that trivial equations are solved instantly, while automata with hundreds of states are handled in reasonable time, confirming that the PSPACE‑complete problem is tractable in practice for typical use cases.
The correctness proof is extensive. It first shows that the matrix construction indeed yields a Kleene algebra, then proves that the star operation on matrices satisfies Kozen’s axioms. Using these results, the authors formalise Kozen’s initiality theorem inside Coq, establishing that the decision procedure is sound (if it returns true, the equation is derivable from the Kleene algebra axioms) and complete (if the equation is derivable, the procedure returns true). The proof also handles the extraction of counter‑examples when the decision fails.
Compared with related work, this is the first Coq tactic that automatically decides Kleene algebra equations. Prior tactics in Coq (e.g., ring, omega) target arithmetic or Presburger arithmetic, but none address the non‑commutative, star‑rich structure of Kleene algebras. The modular typeclass design also distinguishes the work, enabling reuse across heterogeneous models and facilitating future extensions to other algebraic structures such as process algebras or history‑dependent algebras.
In conclusion, the paper delivers a robust, efficient, and formally verified decision procedure for Kleene algebras within Coq. It bridges the gap between algebraic theory (Kozen’s initiality, matrix Kleene algebras) and practical proof automation, providing a valuable tool for formalising rewriting theory, concurrency, and relational reasoning in the Coq ecosystem.
Comments & Academic Discussion
Loading comments...
Leave a Comment