Skip to content

Commit fb66362

Browse files
committed
feat: prove that omega-regular languages are closed under complementation
1 parent 5d26870 commit fb66362

3 files changed

Lines changed: 56 additions & 4 deletions

File tree

Cslib/Computability/Languages/Congruences/BuchiCongruence.lean

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ Authors: Ching-Tsun Chou
77
module
88

99
public import Cslib.Computability.Automata.NA.Pair
10-
public import Cslib.Computability.Languages.Congruences.RightCongruence
11-
public import Cslib.Computability.Languages.OmegaLanguage
10+
public import Cslib.Foundations.Combinatorics.InfiniteGraphRamsey
1211
public import Cslib.Foundations.Data.Set.Saturation
1312

1413
@[expose] public section
@@ -104,6 +103,38 @@ theorem mem_buchiFamily [Inhabited Symbol]
104103
xl ++ω xls.flatten = xs := by
105104
grind [buchiFamily]
106105

106+
/-- `na.buchiFamily` is a cover if `na` has only finitely many states.
107+
This theorem uses the Ramsey theorem for infinite graphs and does not depend on any details
108+
of `na.BuchiCongruence` other than that it is of finite index. -/
109+
theorem buchiFamily_cover [Inhabited Symbol] [Finite State] :
110+
⨆ i, na.buchiFamily i = ⊤ := by
111+
ext xs
112+
simp only [ωLanguage.mem_iSup, Prod.exists, ωLanguage.mem_top, iff_true]
113+
have : Finite (Quotient na.BuchiCongruence.eq) := buchiCongruence_fin_index
114+
let color (t : Finset ℕ) : Quotient na.BuchiCongruence.eq :=
115+
if h : t.Nonempty then ⟦ xs.extract (t.min' h) (t.max' h) ⟧ else ⟦ [] ⟧
116+
obtain ⟨b, ns, h_ns, h_color⟩ := infinite_graph_ramsey color
117+
obtain ⟨f, h_mono, rfl⟩ := strictMono_of_infinite h_ns
118+
let a : Quotient na.BuchiCongruence.eq := ⟦ xs.take (f 0) ⟧
119+
use a, b
120+
apply mem_buchiFamily.mpr
121+
let ys := xs.drop (f 0)
122+
let g := (f · - f 0)
123+
have h_mono' : StrictMono g := Nat.base_zero_strictMono h_mono
124+
use xs.take (f 0), ys.toSegs g, by grind, ?_, by grind
125+
intro k
126+
simp only [toSegs_def, Language.mem_sub_one]
127+
split_ands
128+
· have := h_mono.monotone (show 0 ≤ k by grind)
129+
have := h_mono.monotone (show 0 ≤ k + 1 by grind)
130+
simp [ys, g, extract_drop, show f 0 + (f k - f 0) = f k by grind,
131+
show f 0 + (f (k + 1) - f 0) = f (k + 1) by grind]
132+
have := h_mono (show k < k + 1 by grind)
133+
specialize h_color ({f k, f (k + 1)} : Finset ℕ) (by grind) (by grind)
134+
simp [color] at h_color
135+
grind
136+
· grind [h_mono' (show k < k + 1 by grind)]
137+
107138
-- This intermediate result is split out of the proof of `buchiCongruence_saturation` below
108139
-- because that proof was too big and kept exceeding the default `maxHeartbeats`.
109140
private lemma frequently_via_accept [Inhabited Symbol]

Cslib/Computability/Languages/OmegaRegularLanguage.lean

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ module
99
public import Cslib.Computability.Automata.DA.Buchi
1010
public import Cslib.Computability.Automata.NA.BuchiEquiv
1111
public import Cslib.Computability.Automata.NA.BuchiInter
12-
public import Cslib.Computability.Automata.NA.Pair
1312
public import Cslib.Computability.Automata.NA.Sum
13+
public import Cslib.Computability.Languages.Congruences.BuchiCongruence
1414
public import Cslib.Computability.Languages.ExampleEventuallyZero
15-
public import Cslib.Foundations.Data.Set.Saturation
1615
public import Mathlib.Data.Finite.Card
1716
public import Mathlib.Data.Finite.Sigma
1817
public import Mathlib.Logic.Equiv.Fin.Basic
@@ -234,6 +233,19 @@ theorem IsRegular.fin_cover_saturates_compl {I : Type*} [Finite I]
234233
(hs : Saturates p q) (hc : ⨆ i, p i = ⊤) (hr : ∀ i, (p i).IsRegular) : (qᶜ).IsRegular :=
235234
IsRegular.fin_cover_saturates (saturates_compl hs) hc hr
236235

236+
open NA.Buchi in
237+
/-- The complementation of an ω-regular language is ω-regular. -/
238+
@[simp]
239+
theorem IsRegular.compl {Symbol : Type} [Inhabited Symbol] {p : ωLanguage Symbol}
240+
(h : p.IsRegular) : (pᶜ).IsRegular := by
241+
obtain ⟨State, h_fin, na, rfl⟩ := h
242+
have : Finite (Quotient na.BuchiCongruence.eq) := buchiCongruence_fin_index
243+
have h_sat := buchiFamily_saturation (na := na)
244+
have h_cov := buchiFamily_cover (na := na)
245+
apply IsRegular.fin_cover_saturates_compl h_sat h_cov
246+
have := Language.IsRegular.congr_fin_index (c := na.BuchiCongruence)
247+
grind [buchiFamily, IsRegular.hmul, IsRegular.omegaPow]
248+
237249
/-- McNaughton's Theorem. -/
238250
proof_wanted IsRegular.iff_da_muller {p : ωLanguage Symbol} :
239251
p.IsRegular ↔

Cslib/Foundations/Data/OmegaSequence/InfOcc.lean

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ theorem frequently_in_strictMono {p : ℕ → Prop} {f : ℕ → ℕ}
7777
· use k - f (segment f k)
7878
grind [segment_lower_bound' hm h0, segment_upper_bound' hm h0]
7979

80+
open Nat in
81+
/-- Every infinite subset of ℕ is the range of a strictly monotonic function from ℕ to ℕ. -/
82+
theorem strictMono_of_infinite {ns : Set ℕ} (h : ns.Infinite) :
83+
∃ φ : ℕ → ℕ, StrictMono φ ∧ range φ = ns := by
84+
use (nth (· ∈ ns))
85+
split_ands
86+
· exact nth_strictMono h
87+
· exact range_nth_of_infinite h
88+
8089
end ωSequence
8190

8291
end Cslib

0 commit comments

Comments
 (0)