Skip to content

feat(Automata, LTS, TM): Introduce LTS.SMTr and LTS.mapLabel, generalise TM tapes to arbitrary universes, fix EpsilonNA, and introduce their single-accept transformation#625

Open
fmontesi wants to merge 27 commits into
mainfrom
fmontesi/ena

Conversation

@fmontesi

@fmontesi fmontesi commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

This PR:

  • Fixes a bug in the formulation of EpsilonNA by adopting a new saturated multistep transition LTS.SMTr for LTS, which correctly invokes tau-closure for empty strings.
  • Introduces a mapLabel operation for LTS and its properties.
  • Introduces a new transformation toSingleAccept for EpsilonNA.FinAcc, which transforms the automaton into an equivalent one that has a single accept state with no outgoing transitions.
  • Generalises TM tapes/symbols to arbitrary universes.

@fmontesi fmontesi requested a review from chenson2018 as a code owner June 10, 2026 12:10
@fmontesi fmontesi changed the title feat(Automata): Introduce LTS.SMTr, fix EpsilonNA, and introduce their single-accept transformation feat(Automata): Introduce LTS.SMTr and LTS.mapLabel, fix EpsilonNA, and introduce their single-accept transformation Jun 10, 2026
@fmontesi fmontesi changed the title feat(Automata): Introduce LTS.SMTr and LTS.mapLabel, fix EpsilonNA, and introduce their single-accept transformation feat(Automata, LTS, TM): Introduce LTS.SMTr and LTS.mapLabel, generalise TM tapes to arbitrary universes, fix EpsilonNA, and introduce their single-accept transformation Jun 10, 2026

@ctchou ctchou left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall comment: I think the changes related to Turing machines and their tapes should be separated out to a different PR. Currently they are indpendent of the changes related to LTS and EpsilonNA.

Comment on lines +65 to +70
/-- Extensional equality for LTS. -/
theorem ext {lts₁ lts₂ : LTS State Label}
(h : ∀ s μ s', lts₁.Tr s μ s' ↔ lts₂.Tr s μ s') : lts₁ = lts₂ := by
rcases lts₁ with ⟨Tr₁⟩
rcases lts₂ with ⟨Tr₂⟩
grind only [mk.injEq]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to prove this theorem yourself. Adding the @[ext] attribute to the definition of LTS suffices.

Comment on lines +138 to +144
/-- `setImage` on `HasTau.τ` preserves membership. -/
@[scoped grind .]
lemma mem_saturate_setImage_τ [HasTau Label] (lts : LTS State Label) (h : s ∈ S) :
s ∈ lts.saturate.setImage S HasTau.τ := by
simp only [setImage, Set.mem_iUnion, exists_prop]
exists s
grind

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the theorem subset_saturate_setImage_τ below, do we really need this lemma? They are practically identical.

Comment on lines +164 to +167
/-- `τClosure` preserves membership. -/
@[scoped grind .]
lemma τClosure_mem [HasTau Label] (lts : LTS State Label) (h : s ∈ S) :
s ∈ lts.τClosure S := by grind [= τClosure]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Comment on lines +218 to +219
theorem saturate_mTr_sMTr_not_nil_iff [HasTau Label] {lts : LTS State Label}
(hμs : μs ≠ []) : lts.saturate.MTr s μs s' ↔ lts.SMTr s μs s' := by

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not take this as the definition of LTS.SMTr? I think the properties of LTS.SMTr proved above are all easy consequences of this alternative definition.



/-!
# Map operation for LTS.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless you plan to add other kinds of map operations in the future, I think this file should be renamed to MapLabel.lean and this comment should be more specific.

Comment on lines +49 to +50
Accepts (a : FinAcc State Symbol) (xs : List Symbol) :=
∃ s ∈ a.start, ∃ s' ∈ a.accept, a.SMTr s (xs.map Option.some) s'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the old indentation pattern is the correct one.

end Automata.εNA.FinAcc

end Cslib
apply Iff.intro <;> intro h <;> rcases h with ⟨s, hs, s', hs', h⟩

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intro and rcases can be merged into rintro.

Comment on lines +11 to +15
/-! # Translation of εNA into εNA with a single accept state

Defines the transformation `toSingleAccept` for `εNA.FinAcc` and proves correctness
results in terms of language equivalence and correspondences between the two transition systems.
-/

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file necessary for this PR? Its contents don't seem to be used anywhere else now.

Also, the stand construction in textbooks:
https://en.wikipedia.org/wiki/Thompson%27s_construction
uses EpsilonNA with a single start state and a single accept state. Perhaps they should be the target of formalization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants