-
Notifications
You must be signed in to change notification settings - Fork 170
feat: prove that omega-regularity is closed under union and is universe-polymorphic #168
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3436861
feat: prove that omega-regularity is closed under union and is univer…
ctchou 17a1f92
Fix a linter error
ctchou e524213
Merge remote-tracking branch 'upstream/main' into na-sum
ctchou 08af832
Fix an import error casued by merging in the new upstream/main
ctchou 40e3bf7
Incorporate Chris Henson's comments
ctchou 717c7f7
golf iSum_language_eq by removing NA.Run grind annotation locally
chenson2018 2f52a9c
experiment removing NA.Run annotation
chenson2018 97db3b5
minor modification
ctchou 9709baa
minor modification
ctchou 0efad79
minor modification
ctchou 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
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,64 @@ | ||
| /- | ||
| Copyright (c) 2025 Ching-Tsun Chou. All rights reserved. | ||
| Relexsed under Apache 2.0 license xs described in the file LICENSE. | ||
| Authors: Ching-Tsun Chou | ||
| -/ | ||
|
|
||
| import Cslib.Computability.Automata.NA | ||
|
|
||
| /-! # Equivalence of nondeterministic Buchi automata (NBAs). -/ | ||
|
|
||
| open Set Function Filter Cslib.ωSequence | ||
| open scoped Cslib.LTS | ||
|
|
||
| universe u v w | ||
|
|
||
| namespace Cslib.Automata.NA.Buchi | ||
|
|
||
| open ωAcceptor | ||
|
|
||
| variable {Symbol : Type u} {State : Type v} {State' : Type w} | ||
|
|
||
| /-- Lifts an equivalence on states to an equivalence on NBAs. -/ | ||
| @[scoped grind =] | ||
| def reindex (f : State ≃ State') : Buchi State Symbol ≃ Buchi State' Symbol where | ||
| toFun nba := { | ||
| Tr s x t := nba.Tr (f.symm s) x (f.symm t) | ||
| start := f '' nba.start | ||
| accept := f.symm ⁻¹' nba.accept | ||
| } | ||
| invFun nba' := { | ||
| Tr s x t := nba'.Tr (f s) x (f t) | ||
| start := f.symm '' nba'.start | ||
| accept := f ⁻¹' nba'.accept | ||
| } | ||
| left_inv nba := by simp | ||
| right_inv nba' := by simp | ||
|
|
||
| theorem reindex_run_iff {f : State ≃ State'} {nba : Buchi State Symbol} | ||
| {xs : ωSequence Symbol} {ss' : ωSequence State'} : | ||
| (nba.reindex f).Run xs ss' ↔ nba.Run xs (ss'.map f.symm) := by | ||
| constructor <;> | ||
| { rintro ⟨h_init, h_next⟩ | ||
| constructor | ||
| · grind | ||
| · exact fun n ↦ h_next n } | ||
|
|
||
| @[simp] | ||
| theorem reindex_run_iff' {f : State ≃ State'} {nba : Buchi State Symbol} | ||
| {xs : ωSequence Symbol} {ss : ωSequence State} : | ||
| (nba.reindex f).Run xs (ss.map f) ↔ nba.Run xs ss := by | ||
| simp [reindex_run_iff] | ||
|
|
||
| @[simp, scoped grind =] | ||
| theorem reindex_language_eq {f : State ≃ State'} {nba : Buchi State Symbol} : | ||
| language (nba.reindex f) = language nba := by | ||
| ext xs | ||
| constructor | ||
| · rintro ⟨ss', h_run', h_acc'⟩ | ||
| grind [reindex_run_iff] | ||
| · rintro ⟨ss, h_run, h_acc⟩ | ||
| use ss.map f | ||
| constructor <;> grind [reindex_run_iff'] | ||
|
|
||
| end Cslib.Automata.NA.Buchi | ||
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,74 @@ | ||
| /- | ||
| Copyright (c) 2025 Ching-Tsun Chou. All rights reserved. | ||
| Relexsed under Apache 2.0 license xs described in the file LICENSE. | ||
| Authors: Ching-Tsun Chou | ||
| -/ | ||
|
|
||
| import Cslib.Computability.Automata.NA | ||
|
|
||
| /-! # Sum of automata. -/ | ||
|
|
||
| open Set Function Filter Cslib.ωSequence | ||
| open scoped Cslib.LTS | ||
|
|
||
| namespace Cslib.Automata.NA | ||
| open scoped Run | ||
|
|
||
| variable {Symbol I : Type*} {State : I → Type*} | ||
|
|
||
| @[scoped grind =] | ||
| def iSum (na : (i : I) → NA (State i) Symbol) : NA (Σ i, State i) Symbol where | ||
| start := ⋃ i, Sigma.mk i '' (na i).start | ||
|
ctchou marked this conversation as resolved.
|
||
| Tr s x t := ∃ i s_i t_i, (na i).Tr s_i x t_i ∧ ⟨i, s_i⟩ = s ∧ ⟨i, t_i⟩ = t | ||
|
|
||
| @[simp, scoped grind =] | ||
| theorem iSum_run_iff {na : (i : I) → NA (State i) Symbol} | ||
| {xs : ωSequence Symbol} {ss : ωSequence (Σ i, State i)} : | ||
| (iSum na).Run xs ss ↔ ∃ i ss_i, (na i).Run xs ss_i ∧ ss_i.map (Sigma.mk i) = ss := by | ||
| constructor | ||
| · rintro ⟨h_init, h_next⟩ | ||
| obtain ⟨i, s0, h_s0, h_ss0⟩ := mem_iUnion.mp h_init | ||
| have h_exists n : ∃ s_i, ⟨i, s_i⟩ = ss n := by | ||
| induction n | ||
| case zero => use s0 | ||
| case succ n h_ind => | ||
| obtain ⟨j, s_j, t_j, _⟩ := h_next n | ||
| grind | ||
| choose ss_i h_ss_i using h_exists | ||
| use i, ss_i | ||
| refine ⟨⟨?_, ?_⟩, ?_⟩ | ||
| · grind | ||
| · intro n | ||
| obtain ⟨j, _⟩ := h_next n | ||
| grind | ||
| · ext <;> grind | ||
| · rintro ⟨i, ss, h_run, rfl⟩ | ||
| constructor | ||
| · simp only [iSum, get_map, mem_iUnion, mem_image, Sigma.mk.injEq] | ||
| grind | ||
| · intro n | ||
| use i | ||
| grind [Run] | ||
|
|
||
| namespace Buchi | ||
|
|
||
| open ωAcceptor | ||
|
|
||
| @[simp] | ||
| theorem iSum_language_eq {na : (i : I) → NA (State i) Symbol} {acc : (i : I) → Set (State i)} : | ||
| language (Buchi.mk (iSum na) (⋃ i, Sigma.mk i '' (acc i))) = | ||
| ⋃ i, language (Buchi.mk (na i) (acc i)) := by | ||
| ext xs | ||
| rw [mem_iUnion] | ||
| constructor | ||
| · rintro ⟨ss, h_run, h_acc⟩ | ||
| simp only [mem_iUnion] at h_acc | ||
| grind | ||
| · rintro ⟨i, ss_i, _⟩ | ||
| use ss_i.map (Sigma.mk i) | ||
| simp only [mem_iUnion] | ||
| grind | ||
|
|
||
| end Buchi | ||
|
|
||
| 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needing to explicitly split this conjunction a single time to make
grindwork seems like an indicator that the annotations need some refinement.I think the problem is that the
=annotation onNA.Runeagerly splits it into the underlying conjunction, so then further API aroundNA.Runis not useful. I'm not sure, but could you try removing that annotation and seeing if that's an improvement?A theorem (does this exist already?)
with maybe annotation
[grind =>]or[grind <=]could be helpful.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you take a look at the commit I just pushed? (Not meant to be the final word, just experimenting). Regardless of
grind, I think that if you are defining a typeRun, it is good to have API theorems that construct and deconstruct it.Adding
grindannotations to these happens to help a little bit as a replacement for the annotation onNA.Run, but is still not perfect. The tradeoff is there are a few places where you need to know to specifygrind [NA.Run], and I don't understand yet why this is the case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reorganized the code a little bit: renaming
Run.tracetoRun.transand putting the grind lemmas in asectionwith a comment. We should get more data as I develop the theory of NA.Buchi more.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also did some comparisons of the old and the new grind annotations. It seems that the new annotations sped up
Sum.leanby quite a bit, although both runs are on the new version ofSum.lean.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm interesting. Soon we should have some benchmarking in place that makes these performance aspects easier to identify.