Skip to content

Commit 590d1b3

Browse files
committed
feat: prove the existence of an omega-regular language not accepted by any deterministic Buchi automaton
1 parent b2593ce commit 590d1b3

File tree

10 files changed

+210
-20
lines changed

10 files changed

+210
-20
lines changed

Cslib.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Cslib.Computability.Automata.OmegaAcceptor
1010
import Cslib.Computability.Automata.Prod
1111
import Cslib.Computability.Languages.Language
1212
import Cslib.Computability.Languages.OmegaLanguage
13+
import Cslib.Computability.Languages.OmegaLanguageExamples
1314
import Cslib.Computability.Languages.OmegaRegularLanguage
1415
import Cslib.Computability.Languages.RegularLanguage
1516
import Cslib.Foundations.Control.Monad.Free
@@ -20,6 +21,7 @@ import Cslib.Foundations.Data.HasFresh
2021
import Cslib.Foundations.Data.Nat.Segment
2122
import Cslib.Foundations.Data.OmegaSequence.Defs
2223
import Cslib.Foundations.Data.OmegaSequence.Flatten
24+
import Cslib.Foundations.Data.OmegaSequence.InfOcc
2325
import Cslib.Foundations.Data.OmegaSequence.Init
2426
import Cslib.Foundations.Data.Relation
2527
import Cslib.Foundations.Lint.Basic

Cslib/Computability/Automata/DA.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Fabrizio Montesi, Ching-Tsun Chou
55
-/
66

7-
import Cslib.Foundations.Semantics.LTS.FLTS
87
import Cslib.Computability.Automata.Acceptor
98
import Cslib.Computability.Automata.OmegaAcceptor
10-
import Cslib.Computability.Languages.OmegaLanguage
9+
import Cslib.Foundations.Data.OmegaSequence.InfOcc
10+
import Cslib.Foundations.Semantics.LTS.FLTS
1111

1212
/-! # Deterministic Automata
1313

Cslib/Computability/Automata/DABuchi.lean

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Authors: Ching-Tsun Chou
55
-/
66

77
import Cslib.Computability.Automata.DA
8-
import Cslib.Computability.Automata.NA
98

109
/-! # Deterministic Buchi automata.
1110
-/

Cslib/Computability/Automata/NA.lean

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Fabrizio Montesi, Ching-Tsun Chou
55
-/
66

7-
import Cslib.Computability.Languages.OmegaLanguage
7+
import Cslib.Foundations.Data.OmegaSequence.InfOcc
88
import Cslib.Foundations.Semantics.LTS.Basic
9-
import Cslib.Foundations.Semantics.LTS.FLTS
109
import Cslib.Computability.Automata.Acceptor
1110
import Cslib.Computability.Automata.OmegaAcceptor
1211

Cslib/Computability/Languages/OmegaLanguage.lean

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ theorem flatten_mem_omegaPow [Inhabited α] {xs : ωSequence (List α)}
210210
(h_xs : ∀ k, xs k ∈ l - 1) : xs.flatten ∈ l^ω :=
211211
⟨xs, rfl, h_xs⟩
212212

213+
@[simp, scoped grind =]
214+
theorem mem_omegaLim :
215+
s ∈ l↗ω ↔ ∃ᶠ m in atTop, s.extract 0 m ∈ l :=
216+
Iff.rfl
217+
213218
theorem mul_hmul : (l * m) * p = l * (m * p) :=
214219
image2_assoc append_append_ωSequence
215220

@@ -377,6 +382,10 @@ theorem kstar_hmul_omegaPow_eq_omegaPow [Inhabited α] (l : Language α) : l∗
377382
_ = (l∗)^ω := by rw [hmul_omegaPow_eq_omegaPow]
378383
_ = _ := by simp
379384

385+
@[simp]
386+
theorem omegaLim_zero : (0 : Language α)↗ω = ⊥ := by
387+
ext xs ; simp
388+
380389
@[simp, scoped grind =]
381390
theorem map_id (p : ωLanguage α) : map id p = p :=
382391
by simp [map]
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/-
2+
Copyright (c) 2025 Ching-Tsun Chou. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Ching-Tsun Chou
5+
-/
6+
7+
import Cslib.Computability.Automata.DA
8+
import Cslib.Computability.Automata.NA
9+
import Cslib.Foundations.Data.OmegaSequence.InfOcc
10+
import Mathlib.Tactic
11+
12+
/-!
13+
# ω-Regular languages
14+
15+
This file defines ω-regular languages and proves some properties of them.
16+
-/
17+
18+
open Set Function Filter Cslib.ωSequence Cslib.Automata ωAcceptor
19+
open scoped Computability
20+
21+
namespace Cslib.ωLanguage.Example
22+
23+
section EventuallyZero
24+
25+
/-- A sequence `xs` is in `eventually_zero` iff `xs k = 0` for all large `k`. -/
26+
@[scoped grind =]
27+
def eventually_zero : ωLanguage (Fin 2) :=
28+
{ xs : ωSequence (Fin 2) | ∀ᶠ k in atTop, xs k = 0 }
29+
30+
/-- `eventually_zero` is accepted by a 2-state nondeterministic Buchi automaton. -/
31+
theorem eventually_zero_accepted_by_na_buchi :
32+
∃ a : NA.Buchi (Fin 2) (Fin 2), language a = eventually_zero := by
33+
let a : NA.Buchi (Fin 2) (Fin 2) := {
34+
-- Once state 1 is reached, only symbol 0 is accepted and the next state is still 1
35+
Tr s x s' := s = 1 → x = 0 ∧ s' = 1
36+
start := {0}
37+
accept := {1} }
38+
use a ; ext xs ; constructor
39+
· rintro ⟨ss, h_run, h_acc⟩
40+
obtain ⟨m, h_m⟩ := Frequently.exists h_acc
41+
apply eventually_atTop.mpr
42+
use m ; intro n h_n
43+
obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le h_n
44+
suffices h1 : xs (m + k) = 0 ∧ ss (m + k) = 1 by grind
45+
induction k
46+
case zero =>
47+
have := h_run.2 m
48+
grind
49+
case succ k h_ind =>
50+
have := h_run.2 (m + k)
51+
have := h_run.2 (m + k + 1)
52+
grind
53+
· intro h
54+
obtain ⟨m, h_m⟩ := eventually_atTop.mp h
55+
let ss : ωSequence (Fin 2) := fun k ↦ if k ≤ m then (0 : Fin 2) else 1
56+
refine ⟨ss, ?_, ?_⟩
57+
· simp [a, ss, NA.Run]
58+
grind
59+
· apply Eventually.frequently
60+
apply eventually_atTop.mpr
61+
use (m + 1) ; intro k _
62+
simp [a, ss, show m < k by omega]
63+
64+
private lemma extend_by_zero (u : List (Fin 2)) :
65+
u ++ω const 0 ∈ eventually_zero := by
66+
apply eventually_atTop.mpr
67+
use u.length
68+
intro k h_k
69+
rw [get_append_right' h_k]
70+
simp
71+
72+
private lemma extend_by_one (u : List (Fin 2)) :
73+
∃ v, 1 ∈ v ∧ u ++ v ++ω const 0 ∈ eventually_zero := by
74+
refine ⟨[1], ?_, ?_⟩
75+
· simp
76+
· apply extend_by_zero
77+
78+
private lemma extend_by_hyp {l : Language (Fin 2)} (h : l↗ω = eventually_zero)
79+
(u : List (Fin 2)) : ∃ v, 1 ∈ v ∧ u ++ v ∈ l := by
80+
obtain ⟨v, _, h_pfx⟩ := extend_by_one u
81+
rw [← h] at h_pfx
82+
obtain ⟨m, h_m, h_uv⟩ := frequently_atTop.mp h_pfx (u ++ v).length
83+
use (v ++ω ωSequence.const 0).extract 0 (m - u.length)
84+
rw [extract_append_zero_right (show v.length ≤ m - u.length by grind)]
85+
constructor
86+
· simp_all
87+
· rw [extract_append_zero_right h_m] at h_uv
88+
grind
89+
90+
private noncomputable def oneSegs {l : Language (Fin 2)} (h : l↗ω = eventually_zero) (n : ℕ) :=
91+
Classical.choose <| extend_by_hyp h (List.ofFn (fun k : Fin n ↦ oneSegs h k)).flatten
92+
93+
private lemma oneSegs_lemma {l : Language (Fin 2)} (h : l↗ω = eventually_zero) (n : ℕ) :
94+
1 ∈ oneSegs h n ∧ (List.ofFn (fun k : Fin (n + 1) ↦ oneSegs h k)).flatten ∈ l := by
95+
let P u v := 1 ∈ v ∧ u ++ v ∈ l
96+
have : P ((List.ofFn (fun k : Fin n ↦ oneSegs h k)).flatten) (oneSegs h n) := by
97+
unfold oneSegs
98+
exact Classical.choose_spec <| extend_by_hyp h (List.ofFn (fun k : Fin n ↦ oneSegs h k)).flatten
99+
obtain ⟨h1, h2⟩ := this
100+
refine ⟨h1, ?_⟩
101+
rw [List.ofFn_succ_last]
102+
simpa
103+
104+
theorem eventually_zero_not_omegaLim :
105+
¬ ∃ l : Language (Fin 2), l↗ω = eventually_zero := by
106+
rintro ⟨l, h⟩
107+
let ls := ωSequence.mk (oneSegs h)
108+
have h_segs := oneSegs_lemma h
109+
have h_pos : ∀ k, (ls k).length > 0 := by grind
110+
have h_ev : ls.flatten ∈ eventually_zero := by
111+
rw [← h, mem_omegaLim, frequently_iff_strictMono]
112+
use (fun k ↦ ls.cumLen (k + 1))
113+
constructor
114+
· intro j k h_jk
115+
have := cumLen_strictMono h_pos (show j + 1 < k + 1 by omega)
116+
grind
117+
· intro n
118+
rw [extract_eq_take, ← flatten_take h_pos]
119+
suffices _ : ls.take (n + 1) = List.ofFn (fun k : Fin (n + 1) ↦ oneSegs h k) by grind
120+
simp [← extract_eq_take, extract_eq_ofFn, ls]
121+
obtain ⟨m, _⟩ := eventually_atTop.mp h_ev
122+
have h_inf : ∃ᶠ n in atTop, n ∈ range ls.cumLen := by
123+
apply frequently_iff_strictMono.mpr
124+
have := cumLen_strictMono h_pos
125+
grind
126+
obtain ⟨n, h_n, k, rfl⟩ := frequently_atTop.mp h_inf m
127+
have h_k : 1 ∈ ls k := by grind
128+
simp only [← extract_flatten h_pos k, List.mem_iff_getElem, length_extract] at h_k
129+
grind
130+
131+
end EventuallyZero
132+
133+
end Cslib.ωLanguage.Example

Cslib/Computability/Languages/OmegaRegularLanguage.lean

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Cslib.Computability.Automata.NA
99
import Cslib.Computability.Automata.DAToNA
1010
import Cslib.Computability.Automata.DABuchi
1111
import Cslib.Computability.Languages.RegularLanguage
12+
import Cslib.Computability.Languages.OmegaLanguageExamples
1213
import Mathlib.Tactic
1314

1415
/-!
@@ -17,9 +18,8 @@ import Mathlib.Tactic
1718
This file defines ω-regular languages and proves some properties of them.
1819
-/
1920

20-
open Set Function Cslib.Automata.ωAcceptor
21+
open Set Function Filter Cslib.ωSequence Cslib.Automata ωAcceptor
2122
open scoped Computability
22-
open Cslib.Automata
2323

2424
namespace Cslib.ωLanguage
2525

@@ -36,18 +36,26 @@ theorem IsRegular.of_da_buchi {State : Type} [Finite State] (da : DA.Buchi State
3636
use State, inferInstance, da.toNABuchi
3737
simp
3838

39+
/-- There is an ω-regular language that is not accepted by any deterministic Buchi automaton,
40+
where the automaton is not even required to be finite-state. -/
41+
theorem IsRegular.not_da_buchi :
42+
∃ Symbol : Type, ∃ p : ωLanguage Symbol, p.IsRegular ∧
43+
¬ ∃ State : Type, ∃ da : DA.Buchi State Symbol, language da = p := by
44+
refine ⟨Fin 2, Example.eventually_zero, ?_, ?_⟩
45+
· obtain ⟨a, _⟩ := Example.eventually_zero_accepted_by_na_buchi
46+
use Fin 2, inferInstance, a
47+
· rintro ⟨State, ⟨da, acc⟩, h⟩
48+
simp [DA.buchi_eq_finAcc_omegaLim] at h
49+
have := Example.eventually_zero_not_omegaLim
50+
grind
51+
3952
/-- The ω-limit of a regular language is ω-regular. -/
4053
theorem IsRegular.regular_omegaLim {l : Language Symbol}
4154
(h : l.IsRegular) : (l↗ω).IsRegular := by
4255
obtain ⟨State, _, ⟨da, acc⟩, rfl⟩ := Language.IsRegular.iff_cslib_dfa.mp h
4356
rw [← DA.buchi_eq_finAcc_omegaLim]
4457
apply IsRegular.of_da_buchi
4558

46-
/-- There is an ω-regular language that is not accepted by any deterministic Buchi automaton. -/
47-
proof_wanted IsRegular.not_da_buchi :
48-
∃ p : ωLanguage Symbol, p.IsRegular ∧
49-
¬ ∃ State : Type, ∃ _ : Finite State, ∃ da : DA.Buchi State Symbol, language da = p
50-
5159
/-- McNaughton's Theorem. -/
5260
proof_wanted IsRegular.iff_da_muller {p : ωLanguage Symbol} :
5361
p.IsRegular ↔

Cslib/Foundations/Data/OmegaSequence/Defs.lean

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Ching-Tsun Chou, Fabrizio Montesi
55
-/
66
import Cslib.Init
7-
import Mathlib.Data.Nat.Notation
87
import Mathlib.Data.FunLike.Basic
98
import Mathlib.Logic.Function.Iterate
10-
import Mathlib.Order.Filter.AtTopBot.Defs
119

1210
/-!
1311
# Definition of `ωSequence` and functions on infinite sequences
@@ -24,8 +22,6 @@ Most code below is adapted from Mathlib.Data.Stream.Defs.
2422

2523
namespace Cslib
2624

27-
open Filter
28-
2925
universe u v w
3026
variable {α : Type u} {β : Type v} {δ : Type w}
3127

@@ -88,10 +84,6 @@ def zip (f : α → β → δ) (s₁ : ωSequence α) (s₂ : ωSequence β) :
8884
/-- Iterates of a function as an ω-sequence. -/
8985
def iterate (f : α → α) (a : α) : ωSequence α := fun n => f^[n] a
9086

91-
/-- The set of elements that appear infinitely often in an ω-sequence. -/
92-
def infOcc (xs : ωSequence α) : Set α :=
93-
{ x | ∃ᶠ k in atTop, xs k = x }
94-
9587
end ωSequence
9688

9789
end Cslib
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/-
2+
Copyright (c) 2025 Ching-Tsun Chou. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Ching-Tsun Chou
5+
-/
6+
7+
import Cslib.Foundations.Data.OmegaSequence.Defs
8+
import Mathlib.Order.Filter.AtTopBot.Defs
9+
import Mathlib.Tactic
10+
11+
/-!
12+
# Infinite occurrences
13+
-/
14+
15+
namespace Cslib
16+
17+
open Function Set Filter
18+
19+
namespace ωSequence
20+
21+
universe u v w
22+
variable {α : Type u} {β : Type v} {δ : Type w}
23+
24+
/-- The set of elements that appear infinitely often in an ω-sequence. -/
25+
def infOcc (xs : ωSequence α) : Set α :=
26+
{ x | ∃ᶠ k in atTop, xs k = x }
27+
28+
/-- An alternative characterization of "infinitely often". -/
29+
theorem frequently_iff_strictMono {p : ℕ → Prop} :
30+
(∃ᶠ n in atTop, p n) ↔ ∃ f : ℕ → ℕ, StrictMono f ∧ ∀ m, p (f m) := by
31+
constructor
32+
· intro h
33+
exact extraction_of_frequently_atTop h
34+
· rintro ⟨f, h_mono, h_p⟩
35+
rw [Nat.frequently_atTop_iff_infinite]
36+
have h_range : range f ⊆ {n | p n} := by
37+
rintro k ⟨m, rfl⟩
38+
simp_all only [mem_setOf_eq]
39+
apply Infinite.mono h_range
40+
exact infinite_range_of_injective h_mono.injective
41+
42+
end ωSequence
43+
44+
end Cslib

Cslib/Foundations/Data/OmegaSequence/Init.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ alias cons_head_tail := ωSequence.eta
4040
protected theorem ext {s₁ s₂ : ωSequence α} : (∀ n, s₁ n = s₂ n) → s₁ = s₂ := by
4141
apply DFunLike.ext
4242

43+
@[simp, scoped grind =]
44+
theorem get_fun (f : ℕ → α) (n : ℕ) : ωSequence.mk f n = f n :=
45+
rfl
46+
4347
@[simp, scoped grind =]
4448
theorem get_zero_cons (a : α) (s : ωSequence α) : (a ::ω s) 0 = a :=
4549
rfl

0 commit comments

Comments
 (0)