feat(Automata): Thompson's construction #1148
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.45) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 414 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.361
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1148"
general
weight: 0.35
Lsonic233
This PR adds Thompson's construction, which converts regular expressions to ε-NAs:
RegularExpression.toEpsilonNA r : εNA.FinAcc r.State α, withRegularExpression.language_toEpsilonNA : language r.toEpsilonNA = r.matches'. It then uses the construction to proveIsRegular.char,IsRegular.mul,IsRegular.kstarandIsRegular.regex.LTS/Simulation.lean:IsSimulationMap(a map of states that sends transitions to transitions) andIsSimulationMap.sim_trace(it sends runs to runs), as a special case of simulation throughIsSimulationMap.isSimulation.LTS/Union.lean: the transitions and runs ofLTS.unionSum(unionSum_tr_inl_inl,unionSum_mTr_inl_iff, …).LTS/HasTau.lean:τSTr_iff_exists_mTr_replicateandsMTr_iff_exists_mTr_filter(a saturated run along a τ-free list is a plain run whose labels, once the τs are dropped, are that list).Languages/LanguageHom.lean:Language.Hom.reduceOption, dropping thenones of a list as a language homomorphism.EpsilonNA/Basic.lean:εNA.FinAcc.mem_language_iff(acceptance through plain runs) andDecidableEqTau (Option α).EpsilonNA/ToSingleStartAccept.lean(formerlyToSingleAccept.lean):toSingleStartAcceptadds a start state without incoming transitions and an accept state without outgoing transitions, onBool ⊕ State. It replacestoSingleAccept.NA/ToEpsilonNA.lean:NA.toEpsilonNAthroughLTS.mapHomandLanguage.Hom.reduceOption, so its ε-transitions are self-loops, andNA.FinAcc.toEpsilonNAFinAcc, with the same language.EpsilonNA/ThompsonConstruction.lean: the building blocks and their languages:-
zero,epsilonandchar;-
sum, both automata side by side throughLTS.unionSum;-
union := (sum a b).toSingleStartAccept;-
concat, with ε-transitions from the accepting states of the first automaton to the initial states of the second;-
star, with a fresh hub state that is both initial and accepting.EpsilonNA/OfRegularExpression.lean:RegularExpression.State(with aFiniteinstance),toEpsilonNAandlanguage_toEpsilonNA.Languages/RegularLanguage.lean:IsRegular.iff_epsilon_nfa.IsRegular.char,IsRegular.mulandIsRegular.kstarnow come from the blocks above, without a case split on an empty alphabet, andIsRegular.regexfromlanguage_toEpsilonNA.Relation to existing code: CSLib has concatenation and star for ε-free
NA(NA.FinAcc.finConcat,NA.FinAcc.finLoop), which need[Inhabited Symbol]. Thompson's construction is a specific ε-NA instead: everyr.toEpsilonNAhas one initial state and at most one accepting state, and each constructor ofradds at most two states. NFA-simulation algorithms work on exactly this automaton. Following the discussion on Zulip, the union is built ontoSingleStartAccept. This complements #887 (Kleene's algorithm, the converse direction), and #625 named the construction as a target.AI disclosure: written with Anthropic's Claude Code Opus 5.5, which drafted the Lean code under my direction. I chose the design, reviewed every definition and proof, and ran the checks.