-
Notifications
You must be signed in to change notification settings - Fork 44
feat: prove that regular languages are closed under concatenation #239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ctchou
wants to merge
3
commits into
leanprover:main
Choose a base branch
from
ctchou:na-total
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /- | ||
| Copyright (c) 2025 Ching-Tsun Chou. All rights reserved. | ||
| Released under Apache 2.0 license as described in the file LICENSE. | ||
| Authors: Ching-Tsun Chou | ||
| -/ | ||
|
|
||
| import Cslib.Computability.Automata.NA.Basic | ||
|
|
||
| /-! # Making a nondeterministic automaton total. | ||
| -/ | ||
|
|
||
| namespace Cslib.Automata.NA | ||
|
|
||
| open Sum ωSequence Acceptor | ||
|
|
||
| variable {Symbol State : Type*} | ||
|
|
||
| /-- `NA.totalize` makes the original NA total by replacing its LTS with `LTS.totalize` | ||
| and its starting states with their lifted non-sink versions. -/ | ||
| def totalize (na : NA State Symbol) : NA (State ⊕ Unit) Symbol where | ||
| toLTS := na.toLTS.totalize | ||
| start := inl '' na.start | ||
|
|
||
| variable {na : NA State Symbol} | ||
|
|
||
| /-- In an infinite execution of `NA.totalize`, as long as the NA stays in a non-sink state, | ||
| the execution so far corresponds to a finite execution of the original NA. -/ | ||
| theorem totalize_run_mtr {xs : ωSequence Symbol} {ss : ωSequence (State ⊕ Unit)} {n : ℕ} | ||
| (h : na.totalize.Run xs ss) (hl : (ss n).isLeft) : | ||
| ∃ s t, na.MTr s (xs.take n) t ∧ s ∈ na.start ∧ ss 0 = inl s ∧ ss n = inl t := by | ||
| obtain ⟨s, _, eq₁⟩ := h.start | ||
| obtain ⟨t, eq₂⟩ := isLeft_iff.mp hl | ||
| use s, t | ||
| refine ⟨?_, by grind⟩ | ||
| -- TODO: `grind` does not use congruence relations with `na.totalize.MTr` | ||
| rw [← LTS.totalize.mtr_left_iff, ← extract_eq_take, eq₁, ← eq₂] | ||
| exact LTS.ωTr_mTr h.trans (by grind) | ||
|
|
||
| /-- Any finite execution of the original NA can be extended to an infinite execution of | ||
| `NA.totalize`, provided that the alphabet is inbabited. -/ | ||
| theorem totalize_mtr_run [Inhabited Symbol] {xl : List Symbol} {s t : State} | ||
| (hs : s ∈ na.start) (hm : na.MTr s xl t) : | ||
| ∃ xs ss, na.totalize.Run (xl ++ω xs) ss ∧ ss 0 = inl s ∧ ss xl.length = inl t := by | ||
| grind [totalize, Run, (LTS.totalize.total na.toLTS).mTr_ωTr, =_ LTS.totalize.mtr_left_iff] | ||
|
|
||
| namespace FinAcc | ||
|
|
||
| /-- `NA.totalize` and the original NA accept the same language of finite words, | ||
| as long as the accepting states are also lifted in the obvious way. -/ | ||
| theorem totalize_language_eq {na : FinAcc State Symbol} : | ||
| language (FinAcc.mk na.totalize (inl '' na.accept)) = language na := by | ||
| ext xl | ||
| simp [totalize] | ||
|
|
||
| end FinAcc | ||
|
|
||
| end Cslib.Automata.NA |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.