Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
dc83a75
feat: LTS.IsExecution
fmontesi Jan 11, 2026
2e66740
simplify a proof
fmontesi Jan 12, 2026
d5cee8f
add start and final states to IsExecution
fmontesi Jan 15, 2026
b99ac09
feat: prove that an omega-language is regular iff it is a finite unio…
ctchou Jan 6, 2026
932efb6
feat: define right congruence and prove its basic properties
ctchou Jan 12, 2026
84d9c5f
incorporate Chris Henson's comments
ctchou Jan 17, 2026
10086c2
Merge remote-tracking branch 'upstream/main' into na-pair
ctchou Jan 17, 2026
7669328
incorporate Chris Henson's comments
ctchou Jan 17, 2026
7626d21
Merge remote-tracking branch 'upstream/main' into congr-basic
ctchou Jan 17, 2026
9ced6e8
right_congr definition
chenson2018 Jan 17, 2026
57918b6
fix a typo
ctchou Jan 18, 2026
77e4fc9
minor modification
ctchou Jan 18, 2026
ce7c5fb
Merge remote-tracking branch 'upstream/main' into lts-execution-prop-…
ctchou Jan 19, 2026
715a371
fix CslibTests.GrindLint errors
ctchou Jan 19, 2026
fc07700
minor modification
ctchou Jan 20, 2026
491d10a
Merge remote-tracking branch 'upstream/main' into na-pair
ctchou Jan 20, 2026
eed3933
Merge remote-tracking branch 'upstream/main' into congr-basic
ctchou Jan 21, 2026
df58e8b
Merge remote-tracking branch 'origin/lts-execution-prop-ctchou' into …
ctchou Jan 21, 2026
fa3f9b4
Merge remote-tracking branch 'upstream/main' into na-pair-TEST
ctchou Jan 22, 2026
8db3c76
Merge remote-tracking branch 'origin/congr-basic' into congr-buchi
ctchou Jan 22, 2026
6fe866f
feat: define BuchiCongruence and prove that it is a right congruence …
ctchou Jan 18, 2026
67ef16d
use CovariantClass to define RightCongruence
chenson2018 Jan 22, 2026
49c3770
linter
chenson2018 Jan 22, 2026
e66469e
give the name right_cov to the CovariantClass field of RightCongruence
ctchou Jan 23, 2026
0281b4d
Merge remote-tracking branch 'upstream/main' into na-pair
ctchou Jan 26, 2026
dbbafdc
Merge remote-tracking branch 'upstream/main' into na-pair
ctchou Jan 26, 2026
5ad2fc9
Merge remote-tracking branch 'origin/na-pair' into congr-buchi
ctchou Jan 26, 2026
642a546
Fix a name conflict with the new IsRegular in Mathlib.Algebra.Regular…
ctchou Jan 26, 2026
0653a66
Merge remote-tracking branch 'upstream/main' into congr-buchi
ctchou Jan 27, 2026
51edb63
introduce LTS.IsExecution.flatten and prove LTS.ωTr.flatten as a coro…
ctchou Jan 28, 2026
c1eab79
Merge remote-tracking branch 'upstream/main' into congr-buchi
ctchou Jan 28, 2026
96971b2
get rid of the abbrev `c.QuotType` and use `Quotient c.eq` instead
ctchou Jan 29, 2026
fcac542
Merge remote-tracking branch 'upstream/main' into congr-buchi
ctchou Jan 29, 2026
965c7ab
Merge remote-tracking branch 'upstream/main' into congr-buchi
ctchou Jan 29, 2026
b38da0d
Merge remote-tracking branch 'upstream/main' into congr-buchi
ctchou Jan 31, 2026
b668788
Merge remote-tracking branch 'upstream/main' into congr-buchi
ctchou Feb 3, 2026
6cdd514
Merge remote-tracking branch 'upstream/main' into congr-buchi
ctchou Feb 4, 2026
16d3b3f
incorporate Chris Henson's comments
ctchou Feb 4, 2026
47c356a
Merge remote-tracking branch 'upstream/main' into congr-buchi
ctchou Feb 4, 2026
a9bc936
Merge remote-tracking branch 'upstream/main' into congr-buchi
ctchou Feb 6, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cslib.lean
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public import Cslib.Computability.Automata.Acceptors.Acceptor
public import Cslib.Computability.Automata.Acceptors.OmegaAcceptor
public import Cslib.Computability.Automata.DA.Basic
public import Cslib.Computability.Automata.DA.Buchi
public import Cslib.Computability.Automata.DA.Congr
public import Cslib.Computability.Automata.DA.Prod
public import Cslib.Computability.Automata.DA.ToNA
public import Cslib.Computability.Automata.EpsilonNA.Basic
Expand All @@ -21,6 +22,8 @@ public import Cslib.Computability.Automata.NA.Prod
public import Cslib.Computability.Automata.NA.Sum
public import Cslib.Computability.Automata.NA.ToDA
public import Cslib.Computability.Automata.NA.Total
public import Cslib.Computability.Languages.Congruences.BuchiCongruence
public import Cslib.Computability.Languages.Congruences.RightCongruence
public import Cslib.Computability.Languages.ExampleEventuallyZero
public import Cslib.Computability.Languages.Language
public import Cslib.Computability.Languages.OmegaLanguage
Expand Down
67 changes: 67 additions & 0 deletions Cslib/Computability/Automata/DA/Congr.lean
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
61 changes: 61 additions & 0 deletions Cslib/Computability/Automata/NA/Pair.lean
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,67 @@ theorem LTS.pairLang_regular [Finite State] {lts : LTS State Symbol} {s t : Stat
ext
simp

/-- `LTS.pairViaLang via s t` is the language of finite words that can take the LTS
from state `s` to state `t` via a state in `via`. -/
def LTS.pairViaLang (lts : LTS State Symbol) (via : Set State) (s t : State) : Language Symbol :=
⨆ r ∈ via, lts.pairLang s r * lts.pairLang r t

@[simp, scoped grind =]
theorem LTS.mem_pairViaLang {lts : LTS State Symbol} {via : Set State}
{s t : State} {xs : List Symbol} : xs ∈ lts.pairViaLang via s t ↔
∃ r ∈ via, ∃ xs1 xs2, lts.MTr s xs1 r ∧ lts.MTr r xs2 t ∧ xs1 ++ xs2 = xs := by
simp [LTS.pairViaLang, Language.mem_mul]

/-- `LTS.pairViaLang via s t` is a regular language if there are only finitely many states. -/
@[simp]
theorem LTS.pairViaLang_regular [Inhabited Symbol] [Finite State] {lts : LTS State Symbol}
{via : Set State} {s t : State} : (lts.pairViaLang via s t).IsRegular := by
apply IsRegular.iSup
grind [Language.IsRegular.mul, LTS.pairLang_regular]

theorem LTS.pairLang_append {lts : LTS State Symbol} {s0 s1 s2 : State} {xs1 xs2 : List Symbol}
(h1 : xs1 ∈ lts.pairLang s0 s1) (h2 : xs2 ∈ lts.pairLang s1 s2) :
xs1 ++ xs2 ∈ lts.pairLang s0 s2 := by
grind [<= LTS.MTr.comp]

theorem LTS.pairLang_split {lts : LTS State Symbol} {s0 s2 : State} {xs1 xs2 : List Symbol}
(h : xs1 ++ xs2 ∈ lts.pairLang s0 s2) :
∃ s1, xs1 ∈ lts.pairLang s0 s1 ∧ xs2 ∈ lts.pairLang s1 s2 := by
obtain ⟨r, _, _⟩ := LTS.MTr.split <| LTS.mem_pairLang.mp h
use r
grind

theorem LTS.pairViaLang_append_pairLang {lts : LTS State Symbol}
{s0 s1 s2 : State} {xs1 xs2 : List Symbol} {via : Set State}
(h1 : xs1 ∈ lts.pairViaLang via s0 s1) (h2 : xs2 ∈ lts.pairLang s1 s2) :
xs1 ++ xs2 ∈ lts.pairViaLang via s0 s2 := by
obtain ⟨r, _, _, _, _, _, rfl⟩ := LTS.mem_pairViaLang.mp h1
apply LTS.mem_pairViaLang.mpr
use r
grind [<= LTS.MTr.comp]

theorem LTS.pairLang_append_pairViaLang {lts : LTS State Symbol}
{s0 s1 s2 : State} {xs1 xs2 : List Symbol} {via : Set State}
(h1 : xs1 ∈ lts.pairLang s0 s1) (h2 : xs2 ∈ lts.pairViaLang via s1 s2) :
xs1 ++ xs2 ∈ lts.pairViaLang via s0 s2 := by
obtain ⟨r, _, _, _, _, _, rfl⟩ := LTS.mem_pairViaLang.mp h2
apply LTS.mem_pairViaLang.mpr
use r
grind [<= LTS.MTr.comp]

theorem LTS.pairViaLang_split {lts : LTS State Symbol} {s0 s2 : State} {xs1 xs2 : List Symbol}
{via : Set State} (h : xs1 ++ xs2 ∈ lts.pairViaLang via s0 s2) :
∃ s1, xs1 ∈ lts.pairViaLang via s0 s1 ∧ xs2 ∈ lts.pairLang s1 s2 ∨
xs1 ∈ lts.pairLang s0 s1 ∧ xs2 ∈ lts.pairViaLang via s1 s2 := by
obtain ⟨r, h_r, ys1, ys2, h_ys1, h_ys2, h_eq⟩ := LTS.mem_pairViaLang.mp h
obtain ⟨zs1, rfl, rfl⟩ | ⟨zs2, rfl, rfl⟩ := List.append_eq_append_iff.mp h_eq
· obtain ⟨s1, _, _⟩ := LTS.MTr.split h_ys2
use s1
grind
· obtain ⟨s1, _, _⟩ := LTS.MTr.split h_ys1
use s1
grind

namespace Automata.NA.Buchi

open Set Filter ωSequence ωLanguage ωAcceptor
Expand Down
75 changes: 75 additions & 0 deletions Cslib/Computability/Languages/Congruences/BuchiCongruence.lean
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 Cslib/Computability/Languages/Congruences/RightCongruence.lean
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
Copy link
Collaborator

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.

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
12 changes: 11 additions & 1 deletion Cslib/Computability/Languages/RegularLanguage.lean
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Authors: Ching-Tsun Chou

module

public import Cslib.Computability.Automata.DA.Congr
public import Cslib.Computability.Automata.DA.Prod
public import Cslib.Computability.Automata.DA.ToNA
public import Cslib.Computability.Automata.NA.Concat
Expand All @@ -24,7 +25,7 @@ public import Mathlib.Tactic.Common

namespace Cslib.Language

open Set List Prod Automata Acceptor
open Set List Prod Automata Acceptor RightCongruence
open scoped Computability FLTS DA NA DA.FinAcc NA.FinAcc

variable {Symbol : Type*}
Expand Down Expand Up @@ -159,4 +160,13 @@ theorem IsRegular.kstar [Inhabited Symbol] {l : Language Symbol}
obtain ⟨State, h_fin, nfa, rfl⟩ := h
use Unit ⊕ (State ⊕ Unit), inferInstance, ⟨finLoop nfa, {inl ()}⟩, loop_language_eq h_l

/-- If a right congruence is of finite index, then each of its equivalence classes is regular. -/
@[simp]
theorem IsRegular.congr_fin_index {Symbol : Type}
[c : RightCongruence Symbol] [Finite (Quotient c.eq)]
(a : Quotient c.eq) : (eqvCls a).IsRegular := by
rw [IsRegular.iff_dfa]
use Quotient c.eq, inferInstance, ⟨c.toDA, {a}⟩
exact DA.FinAcc.congr_language_eq

end Cslib.Language
7 changes: 6 additions & 1 deletion Cslib/Foundations/Semantics/FLTS/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ from the left (instead of the right), in order to match the way lists are constr
@[scoped grind =]
def mtr (flts : FLTS State Label) (s : State) (μs : List Label) := μs.foldl flts.tr s

@[scoped grind =]
@[simp, scoped grind =]
theorem mtr_nil_eq {flts : FLTS State Label} {s : State} : flts.mtr s [] = s := rfl

@[simp, scoped grind =]
theorem mtr_concat_eq {flts : FLTS State Label} {s : State} {μs : List Label} {μ : Label} :
flts.mtr s (μs ++ [μ]) = flts.tr (flts.mtr s μs) μ := by
grind

end FLTS

end Cslib
Loading