-
Notifications
You must be signed in to change notification settings - Fork 59
feat: define BuchiCongruence and prove that it is a right congruence of finite index #278
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
40
commits into
leanprover:main
Choose a base branch
from
ctchou:congr-buchi
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
40 commits
Select commit
Hold shift + click to select a range
dc83a75
feat: LTS.IsExecution
fmontesi 2e66740
simplify a proof
fmontesi d5cee8f
add start and final states to IsExecution
fmontesi b99ac09
feat: prove that an omega-language is regular iff it is a finite unio…
ctchou 932efb6
feat: define right congruence and prove its basic properties
ctchou 84d9c5f
incorporate Chris Henson's comments
ctchou 10086c2
Merge remote-tracking branch 'upstream/main' into na-pair
ctchou 7669328
incorporate Chris Henson's comments
ctchou 7626d21
Merge remote-tracking branch 'upstream/main' into congr-basic
ctchou 9ced6e8
right_congr definition
chenson2018 57918b6
fix a typo
ctchou 77e4fc9
minor modification
ctchou ce7c5fb
Merge remote-tracking branch 'upstream/main' into lts-execution-prop-…
ctchou 715a371
fix CslibTests.GrindLint errors
ctchou fc07700
minor modification
ctchou 491d10a
Merge remote-tracking branch 'upstream/main' into na-pair
ctchou eed3933
Merge remote-tracking branch 'upstream/main' into congr-basic
ctchou df58e8b
Merge remote-tracking branch 'origin/lts-execution-prop-ctchou' into …
ctchou fa3f9b4
Merge remote-tracking branch 'upstream/main' into na-pair-TEST
ctchou 8db3c76
Merge remote-tracking branch 'origin/congr-basic' into congr-buchi
ctchou 6fe866f
feat: define BuchiCongruence and prove that it is a right congruence …
ctchou 67ef16d
use CovariantClass to define RightCongruence
chenson2018 49c3770
linter
chenson2018 e66469e
give the name right_cov to the CovariantClass field of RightCongruence
ctchou 0281b4d
Merge remote-tracking branch 'upstream/main' into na-pair
ctchou dbbafdc
Merge remote-tracking branch 'upstream/main' into na-pair
ctchou 5ad2fc9
Merge remote-tracking branch 'origin/na-pair' into congr-buchi
ctchou 642a546
Fix a name conflict with the new IsRegular in Mathlib.Algebra.Regular…
ctchou 0653a66
Merge remote-tracking branch 'upstream/main' into congr-buchi
ctchou 51edb63
introduce LTS.IsExecution.flatten and prove LTS.ωTr.flatten as a coro…
ctchou c1eab79
Merge remote-tracking branch 'upstream/main' into congr-buchi
ctchou 96971b2
get rid of the abbrev `c.QuotType` and use `Quotient c.eq` instead
ctchou fcac542
Merge remote-tracking branch 'upstream/main' into congr-buchi
ctchou 965c7ab
Merge remote-tracking branch 'upstream/main' into congr-buchi
ctchou b38da0d
Merge remote-tracking branch 'upstream/main' into congr-buchi
ctchou b668788
Merge remote-tracking branch 'upstream/main' into congr-buchi
ctchou 6cdd514
Merge remote-tracking branch 'upstream/main' into congr-buchi
ctchou 16d3b3f
incorporate Chris Henson's comments
ctchou 47c356a
Merge remote-tracking branch 'upstream/main' into congr-buchi
ctchou a9bc936
Merge remote-tracking branch 'upstream/main' into congr-buchi
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /- | ||
| Copyright (c) 2026 Ching-Tsun Chou. All rights reserved. | ||
| Released under Apache 2.0 license as described in the file LICENSE. | ||
| Authors: Ching-Tsun Chou | ||
| -/ | ||
|
|
||
| module | ||
|
|
||
| public import Cslib.Computability.Automata.DA.Basic | ||
| public import Cslib.Computability.Languages.Congruences.RightCongruence | ||
|
|
||
| @[expose] public section | ||
|
|
||
| /-! # Deterministic automaton corresponding to a right congruence. -/ | ||
|
|
||
| namespace Cslib | ||
|
|
||
| open scoped FLTS RightCongruence | ||
|
|
||
| variable {Symbol : Type*} | ||
|
|
||
| /-- Every right congruence gives rise to a DA whose states are the equivalence classes of | ||
| the right congruence, whose start state is the empty word, and whose transition functiuon | ||
| is concatenation on the right of the input symbol. Note that the transition function is | ||
| well-defined only because `c` is a right congruence. -/ | ||
| @[scoped grind =] | ||
| def RightCongruence.toDA [c : RightCongruence Symbol] : Automata.DA (Quotient c.eq) Symbol where | ||
| tr s x := Quotient.lift (fun u ↦ ⟦ u ++ [x] ⟧) (by | ||
| intro u v h_eq | ||
| apply Quotient.sound | ||
| exact right_cov.elim [x] h_eq | ||
| ) s | ||
| start := ⟦ [] ⟧ | ||
|
|
||
| namespace Automata.DA | ||
|
|
||
| variable [c : RightCongruence Symbol] | ||
|
|
||
| /-- After consuming a finite word `xs`, `c.toDA` reaches the state `⟦ xs ⟧` which is | ||
| the equivalence class of `xs`. -/ | ||
| @[simp, scoped grind =] | ||
| theorem congr_mtr_eq {xs : List Symbol} : | ||
| c.toDA.mtr c.toDA.start xs = ⟦ xs ⟧ := by | ||
| generalize h_rev : xs.reverse = ys | ||
| induction ys generalizing xs | ||
| case nil => grind [List.reverse_eq_nil_iff] | ||
| case cons y ys h_ind => | ||
| obtain ⟨rfl⟩ := List.reverse_eq_cons_iff.mp h_rev | ||
| specialize h_ind (xs := ys.reverse) (by grind) | ||
| grind [Quotient.lift_mk] | ||
|
|
||
| namespace FinAcc | ||
|
|
||
| open Acceptor RightCongruence | ||
|
|
||
| /-- The language of `c.toDA` with a single accepting state `s` is exactly | ||
| the equivalence class corresponding to `s`. -/ | ||
| @[simp] | ||
| theorem congr_language_eq {a : Quotient c.eq} : language (FinAcc.mk c.toDA {a}) = eqvCls a := by | ||
| ext | ||
| grind | ||
|
|
||
| end FinAcc | ||
|
|
||
| end Automata.DA | ||
|
|
||
| end Cslib |
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
75 changes: 75 additions & 0 deletions
75
Cslib/Computability/Languages/Congruences/BuchiCongruence.lean
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,75 @@ | ||
| /- | ||
| Copyright (c) 2026 Ching-Tsun Chou. All rights reserved. | ||
| Released under Apache 2.0 license as described in the file LICENSE. | ||
| Authors: Ching-Tsun Chou | ||
| -/ | ||
|
|
||
| module | ||
|
|
||
| public import Cslib.Computability.Automata.NA.Pair | ||
| public import Cslib.Computability.Languages.Congruences.RightCongruence | ||
|
|
||
| @[expose] public section | ||
|
|
||
| /-! | ||
| # Buchi Congruence | ||
|
|
||
| A special type of right congruences used by J.R. Büchi to prove the closure | ||
| of ω-regular languages under complementation. | ||
| -/ | ||
|
|
||
| namespace Cslib.Automata.NA.Buchi | ||
|
|
||
| open Function | ||
|
|
||
| variable {Symbol : Type*} {State : Type} | ||
|
|
||
| /-- Given a Buchi automaton `na`, two finite words `u` and `v` are Buchi-congruent | ||
| according to `na` iff for every pair of states `s` and `t` of `na`, both of the | ||
| following two conditions hold: | ||
| (1) `u` can move `na` from `s` to `t` iff `v` can move `na` from `s` to `t`; | ||
| (2) `u` can move `na` from `s` to `t` via an acceptingg states iff `v` can move `na` | ||
| from `s` to `t` via an acceptingg states. -/ | ||
| def BuchiCongruence (na : Buchi State Symbol) : RightCongruence Symbol where | ||
| eq.r u v := | ||
| ∀ {s t}, (u ∈ na.pairLang s t ↔ v ∈ na.pairLang s t) ∧ | ||
| (u ∈ na.pairViaLang na.accept s t ↔ v ∈ na.pairViaLang na.accept s t) | ||
| eq.iseqv.refl := by grind | ||
| eq.iseqv.symm := by grind | ||
| eq.iseqv.trans := by grind | ||
| right_cov.elim := by | ||
| grind [Covariant, → LTS.pairLang_split, <= LTS.pairLang_append, → LTS.pairViaLang_split, | ||
| <= LTS.pairViaLang_append_pairLang, <= LTS.pairLang_append_pairViaLang] | ||
|
|
||
| open scoped Classical in | ||
| /-- `BuchiCongrParam` is a parameterization of the equivalence classes of `na.BuchiCongruence` | ||
| using the type `State → State → Prop × Prop`, which is finite if `State` is. -/ | ||
| noncomputable def BuchiCongrParam (na : Buchi State Symbol) | ||
| (f : State → State → Prop × Prop) : Quotient na.BuchiCongruence.eq := | ||
| if h : ∃ u, ∀ s t, ((f s t).1 ↔ u ∈ na.pairLang s t) ∧ | ||
| ((f s t).2 ↔ u ∈ na.pairViaLang na.accept s t) | ||
| then ⟦ Classical.choose h ⟧ | ||
| else ⟦ [] ⟧ | ||
|
|
||
| variable {na : Buchi State Symbol} | ||
|
|
||
| /-- `BuchiCongrParam` is surjective. -/ | ||
| lemma buchiCongrParam_surjective : Surjective na.BuchiCongrParam := by | ||
| intro q | ||
| let f s t := (q.out ∈ na.pairLang s t, q.out ∈ na.pairViaLang na.accept s t) | ||
| have h : ∃ u, ∀ s t, ((f s t).1 ↔ u ∈ na.pairLang s t) ∧ | ||
| ((f s t).2 ↔ u ∈ na.pairViaLang na.accept s t) := by | ||
| use q.out | ||
| grind | ||
| use f | ||
| simp only [BuchiCongrParam, h, ↓reduceDIte] | ||
| rw [← Quotient.out_eq q] | ||
| apply Quotient.sound | ||
| intro s t | ||
| grind | ||
|
|
||
| /-- `na.BuchiCongruence` is of finite index if `na` has only finitely many states. -/ | ||
| theorem buchiCongruence_fin_index [Finite State] : Finite (Quotient na.BuchiCongruence.eq) := | ||
| Finite.of_surjective na.BuchiCongrParam buchiCongrParam_surjective | ||
|
|
||
| end Cslib.Automata.NA.Buchi |
41 changes: 41 additions & 0 deletions
41
Cslib/Computability/Languages/Congruences/RightCongruence.lean
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,41 @@ | ||
| /- | ||
| Copyright (c) 2026 Ching-Tsun Chou. All rights reserved. | ||
| Released under Apache 2.0 license as described in the file LICENSE. | ||
| Authors: Ching-Tsun Chou | ||
| -/ | ||
|
|
||
| module | ||
|
|
||
| public import Cslib.Init | ||
| public import Mathlib.Computability.Language | ||
|
|
||
| @[expose] public section | ||
|
|
||
| /-! | ||
| # Right Congruence | ||
|
|
||
| This file contains basic definitions about right congruences on finite sequences. | ||
|
|
||
| NOTE: Left congruences and two-sided congruences can be similarly defined. | ||
| But they are left to future work because they are not needed for now. | ||
| -/ | ||
|
|
||
| namespace Cslib | ||
|
|
||
| /-- A right congruence is an equivalence relation on finite sequences (represented by lists) | ||
| that is preserved by concatenation on the right. The equivalence relation is represented | ||
| by a setoid to to enable ready access to the quotient construction. -/ | ||
| class RightCongruence (α : Type*) extends eq : Setoid (List α) where | ||
| right_cov : CovariantClass _ _ (fun x y => y ++ x) eq | ||
|
|
||
| namespace RightCongruence | ||
|
|
||
| variable {α : Type*} | ||
|
|
||
| /-- The equivalence class (as a language) corresponding to an element of the quotient type. -/ | ||
| abbrev eqvCls [c : RightCongruence α] (a : Quotient c.eq) : Language α := | ||
| (Quotient.mk c.eq) ⁻¹' {a} | ||
|
|
||
| end RightCongruence | ||
|
|
||
| end Cslib | ||
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
Oops, something went wrong.
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.
I don't understand why your last commit changed this, can you explain? It seems better to me as it was with it extending both classes.