Skip to content

Commit d2e10ff

Browse files
authored
refactor: provide a properly encapsulated implementation of OmegaLanguage (#485)
This PR provides a properly encapsulated implementation of OmegaLanguage, using a one-field `structure`. It is influenced and will be affected by mathlib#36934, but it is not dependent on it.
1 parent 1a7d871 commit d2e10ff

8 files changed

Lines changed: 179 additions & 122 deletions

File tree

Cslib/Computability/Automata/DA/Buchi.lean

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@ open scoped FinAcc Buchi
2121

2222
variable {State Symbol : Type*}
2323

24-
open Acceptor ωAcceptor in
24+
open Acceptor ωAcceptor ωLanguage in
2525
/-- The ω-language accepted by a deterministic Buchi automaton is the ω-limit
26-
of the language accepted by the same automaton.
27-
-/
26+
of the language accepted by the same automaton. -/
2827
@[scoped grind =]
2928
theorem buchi_eq_finAcc_omegaLim {da : DA State Symbol} {acc : Set State} :
3029
language (Buchi.mk da acc) = (language (FinAcc.mk da acc))↗ω := by
31-
ext xs
32-
simp +instances
30+
apply mem_ext
31+
grind [ωAcceptor.Accepts, Acceptor.Accepts]
3332

3433
end Cslib.Automata.DA

Cslib/Computability/Automata/NA/BuchiEquiv.lean

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ public import Cslib.Computability.Automata.NA.Basic
1212

1313
/-! # Equivalence of nondeterministic Buchi automata (NBAs). -/
1414

15-
open Set Function Filter Cslib.ωSequence
16-
open scoped Cslib.LTS
17-
1815
universe u v w
1916

2017
namespace Cslib.Automata.NA.Buchi
2118

22-
open ωAcceptor
19+
open Set Function Filter ωSequence ωLanguage ωAcceptor
20+
open scoped LTS
2321

2422
variable {Symbol : Type u} {State : Type v} {State' : Type w}
2523

@@ -57,7 +55,8 @@ theorem reindex_run_iff' {f : State ≃ State'} {nba : Buchi State Symbol}
5755
@[simp, scoped grind =]
5856
theorem reindex_language_eq {f : State ≃ State'} {nba : Buchi State Symbol} :
5957
language (nba.reindex f) = language nba := by
60-
ext xs
58+
apply mem_ext
59+
intro xs
6160
constructor
6261
· rintro ⟨ss', h_run', h_acc'⟩
6362
#adaptation_note

Cslib/Computability/Automata/NA/BuchiInter.lean

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ simply because toggling can be easily modeled by the boolean operation `not`.
2626

2727
namespace Cslib.Automata.NA.Buchi
2828

29-
open Set Prod Filter ωSequence ωAcceptor
29+
open Set Prod Filter ωSequence ωLanguage ωAcceptor
3030
open scoped LTS
3131

3232
variable {Symbol : Type*} {State : Bool → Type*}
@@ -93,16 +93,15 @@ lemma inter_freq_comp_acc_freq_acc {xs : ωSequence Symbol} {ss : ωSequence ((
9393
apply leadsTo_cases_or (q := {⟨_, b⟩ | b = false}) <;>
9494
grind [until_frequently_leadsTo_and, univ_inter]
9595

96-
-- TODO: fix proof to work with backward.isDefEq.respectTransparency
97-
set_option backward.isDefEq.respectTransparency false in
9896
/-- The language accepted by the intersection automaton is the intersection of
9997
the languages accepted by the two component automata. -/
10098
@[simp, scoped grind =]
10199
theorem inter_language_eq :
102100
language (Buchi.mk (interNA na acc) (interAccept acc)) =
103-
⋂ i, language (Buchi.mk (na i) (acc i)) := by
104-
ext xs
105-
rw [mem_iInter]
101+
⨅ i, language (Buchi.mk (na i) (acc i)) := by
102+
apply mem_ext
103+
intro xs
104+
simp only [ωLanguage.mem_iInf]
106105
constructor
107106
· intro ⟨ss, h_run, h_inf⟩ i
108107
use ss.map (fun s ↦ s.fst i)

Cslib/Computability/Automata/NA/Pair.lean

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ of the form `L * M^ω`, where all `L`s and `M`s are regular languages. -/
104104
theorem language_eq_fin_iSup_hmul_omegaPow
105105
[Inhabited Symbol] [Finite State] (na : Buchi State Symbol) :
106106
language na = ⨆ s ∈ na.start, ⨆ t ∈ na.accept, (na.pairLang s t) * (na.pairLang t t)^ω := by
107-
ext xs
107+
apply mem_ext
108+
intro xs
108109
simp only [ωAcceptor.mem_language, ωLanguage.mem_iSup, ωLanguage.mem_hmul, LTS.mem_pairLang]
109110
constructor
110111
· rintro ⟨ss, h_run, h_inf⟩

Cslib/Computability/Automata/NA/Sum.lean

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ public import Cslib.Computability.Automata.NA.Basic
1212

1313
/-! # Sum of nondeterministic automata. -/
1414

15-
open Set Function Filter Cslib.ωSequence
16-
open scoped Cslib.LTS
17-
1815
namespace Cslib.Automata.NA
1916

17+
open Set Function ωSequence ωLanguage
18+
open scoped Cslib.LTS
19+
2020
variable {Symbol I : Type*} {State : I → Type*}
2121

2222
/-- The sum of an indexed family of nondeterministic automata. -/
@@ -58,16 +58,15 @@ namespace Buchi
5858

5959
open ωAcceptor
6060

61-
-- TODO: fix proof to work with backward.isDefEq.respectTransparency
62-
set_option backward.isDefEq.respectTransparency false in
6361
/-- The ω-language accepted by the Buchi sum automata is the union of the ω-languages accepted
6462
by its component automata. -/
6563
@[simp]
6664
theorem iSum_language_eq {na : (i : I) → NA (State i) Symbol} {acc : (i : I) → Set (State i)} :
6765
language (Buchi.mk (iSum na) (⋃ i, Sigma.mk i '' (acc i))) =
68-
⋃ i, language (Buchi.mk (na i) (acc i)) := by
69-
ext xs
70-
rw [mem_iUnion]
66+
⨆ i, language (Buchi.mk (na i) (acc i)) := by
67+
apply mem_ext
68+
intro xs
69+
simp only [mem_language, mem_iSup]
7170
constructor
7271
· rintro ⟨ss, h_run, h_acc⟩
7372
simp only [mem_iUnion] at h_acc

Cslib/Computability/Languages/Congruences/BuchiCongruence.lean

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ This theorem uses the Ramsey theorem for infinite graphs and does not depend on
115115
of `na.BuchiCongruence` other than that it is of finite index. -/
116116
theorem buchiFamily_cover [Inhabited Symbol] [Finite State] :
117117
⨆ i, na.buchiFamily i = ⊤ := by
118-
ext xs
118+
apply mem_ext
119+
intro xs
119120
have : Finite (Quotient na.BuchiCongruence.eq) := buchiCongruence_fin_index
120121
let color (t : Finset ℕ) : Quotient na.BuchiCongruence.eq :=
121122
if h : t.Nonempty then ⟦ xs.extract (t.min' h) (t.max' h) ⟧ else ⟦ [] ⟧
@@ -175,7 +176,8 @@ private lemma frequently_via_accept [Inhabited Symbol]
175176
· grind only [!List.take_append_drop]
176177

177178
/-- `na.buchiFamily` saturates the ω-language accepted by `na`. -/
178-
theorem buchiFamily_saturation [Inhabited Symbol] : Saturates na.buchiFamily (language na) := by
179+
theorem buchiFamily_saturation [Inhabited Symbol] :
180+
Saturates (fun i ↦ (na.buchiFamily i).toSet) (language na).toSet := by
179181
rintro ⟨a, b⟩ ⟨xs, h_xs, h_lang⟩ ys h_ys
180182
obtain ⟨xl, xls, h_xl_c, h_xls_c, rfl⟩ := mem_buchiFamily.mp h_xs
181183
obtain ⟨yl, yls, h_yl_c, h_yls_c, rfl⟩ := mem_buchiFamily.mp h_ys

0 commit comments

Comments
 (0)