% Copyright 2026 Arthur Freitas Ramos, David Barros Hulak, % and Ruy J. G. B. de Queiroz. Licensed CC BY 4.0. % https://creativecommons.org/licenses/by/4.0/ \documentclass[11pt]{amsart} \usepackage[T1]{fontenc} \usepackage{lmodern} \usepackage[a4paper,margin=29mm]{geometry} \usepackage{amsmath,amssymb,amsthm} \usepackage{microtype} \usepackage{booktabs} \usepackage{needspace} \PassOptionsToPackage{obeyspaces,spaces}{url} \usepackage{xurl} \usepackage[hidelinks]{hyperref} \hypersetup{pdftitle={An Executable Stallings Recognizer for Finite Generating Lists in Lean}, pdfauthor={Arthur Freitas Ramos; David Barros Hulak; Ruy J. G. B. de Queiroz}, pdfsubject={Finite inverse automata and subgroup membership in the rank two free group}, pdfkeywords={Stallings folding, free groups, inverse automata, Lean 4, Mathlib}} \newtheorem{theorem}{Theorem}[section] \newtheorem{proposition}[theorem]{Proposition} \newtheorem{lemma}[theorem]{Lemma} \theoremstyle{definition} \newtheorem{definition}[theorem]{Definition} \theoremstyle{remark} \newtheorem{remark}[theorem]{Remark} \newcommand{\F}{F_2} \newcommand{\A}{\mathcal A} \newcommand{\ev}[1]{\lbrack #1\rbrack} \newcommand{\rep}{\operatorname{rep}} \newcommand{\run}{\operatorname{run}} \newcommand{\decl}[1]{{\small\nolinkurl{#1}}} \newcommand{\source}[2]{\href{https://github.com/Arthur742Ramos/stallings-folding/blob/117dde0a8415d3da1787e15ad22a6223a744432d/#1}{#2}} \title[An executable Stallings recognizer in Lean]{An Executable Stallings Recognizer for Finite Generating Lists in Lean} \author{Arthur Freitas Ramos} \author{David Barros Hulak} \author{Ruy J. G. B. de Queiroz} \thanks{Author ORCID identifiers: Arthur Freitas Ramos, \href{https://orcid.org/0009-0003-3568-0325}{0009-0003-3568-0325}; David Barros Hulak, \href{https://orcid.org/0009-0002-8056-1774}{0009-0002-8056-1774}; Ruy J. G. B. de Queiroz, \href{https://orcid.org/0000-0003-1482-0977}{0000-0003-1482-0977}.} \thanks{Copyright 2026 the authors. Licensed under \href{https://creativecommons.org/licenses/by/4.0/}{Creative Commons Attribution 4.0 International (CC BY 4.0)}.} \date{October 1, 2026} \subjclass[2020]{20E05, 68Q45, 03B35} \keywords{Stallings folding, free groups, finite inverse automata, subgroup membership, Lean 4, Mathlib} \begin{document} \begin{abstract} We explain a Lean 4 construction of a finite inverse automaton recognizing the subgroup of the rank-two free group generated by any finite list of signed words. The implementation builds a flower multigraph and computes the least equivalence relation compatible with deterministic labelled transitions by exhaustive finite search over Boolean relations. Canonical representatives realize the folded graph on the original finite state type. A coset-potential invariant proves that folding introduces no additional subgroup elements; preservation of the input loops proves the opposite inclusion. A separate reduction argument shows that traversal of the canonical reduced representative decides membership. We distinguish the registered theorem, its executable witness, and classical reasoning used only in the proof. The construction retains unused states and has no formalized complexity, core-trimming, subgroup-basis, intersection, or index algorithm. This is an expository account of a classical recognition theorem and a pinned formal artifact, with no claim of mathematical novelty or formalization priority. \end{abstract} \maketitle \enlargethispage{2pt} \raggedbottom \section{The recognition theorem and its scope} A finite labelled graph can encode an infinite subgroup of a free group. The based loops supply group elements, while deterministic transitions make the reduced-word membership question a finite traversal. This is the recognition aspect of Stallings' finite-graph method \cite{Stallings1983}. Kapovich and Myasnikov give a later combinatorial and computational treatment \cite{KapovichMyasnikov2002}. The present article explains a deliberately limited formal implementation of that recognition result. It does not formalize the full range of applications of subgroup graphs developed in those works. All implementation claims below refer to the repository \emph{stallings-folding} at commit \nolinkurl{117dde0a8415d3da1787e15ad22a6223a744432d} \cite{StallingsArtifact}. This is the commit recorded by \href{https://palomar-registry.org/entry?id=PALOMAR-2026-09-23-000004\&version=1}{PALOMAR-2026-09-23-000004, version 1} \cite{PalomarRecord}. The public record selects \decl{Stallings.folded_recognizer_exists} and the closed statement definition \decl{Stallings.completeStatement}. The construction and intermediate correctness results are in the implementation modules; the final interface is in \source{Solution.lean}{\texttt{Solution.lean}}. \subsection{Words and the generated subgroup} Write $\A=\{a,a^{-1},b,b^{-1}\}$ and let $x\mapsto\bar x$ exchange a letter with its inverse. A word is a finite list of letters. Its evaluation in $\F=F(a,b)$ is denoted by $\ev{w}$. If $w=x_1\cdots x_k$, its inverse word is $\bar x_k\cdots\bar x_1$. In Lean these data are \decl{Fin 2} $\times$ \decl{Bool}, lists of these pairs, and \decl{FreeGroup (Fin 2)}; the Boolean value \texttt{true} denotes the positive orientation. The definitions \decl{letterInv}, \decl{wordInv}, and \decl{wordEval} implement inversion and evaluation. For a finite list $S=(s_0,\ldots,s_{m-1})$ of words, set \begin{equation}\label{eq:H} H_S=\left\langle\ev{s_i}\mid 0\leq i