Skip to content

Commit 956b26f

Browse files
committed
Progress Ochmanski's Theorem
1 parent 3521f98 commit 956b26f

2 files changed

Lines changed: 297 additions & 2 deletions

File tree

TraceTheory/TraceTheory/Language.lean

Lines changed: 120 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Mathlib.Algebra.BigOperators.Group.Finset.Defs
1+
import Mathlib.Algebra.BigOperators.Group.Finset.Basic
22
import Mathlib.Computability.DFA
33
import Mathlib.Computability.Language
44
import TraceTheory.Basic
@@ -171,6 +171,125 @@ theorem isRegular_lexNf : Language.IsRegular (LexNfLanguage I) := by
171171
apply Language.IsRegular.compl
172172
apply isRegular_allForbiddenPatterns
173173

174+
omit [LinearOrder α] [Fintype α] in
175+
lemma mem_sigma (x : List α) : x ∈ (Sigma : Language α)∗ := by
176+
rw [Language.mem_kstar]
177+
use [x]
178+
simp only [List.flatten_cons, List.flatten_nil, List.append_nil, List.mem_cons,
179+
List.not_mem_nil, or_false, Sigma, forall_eq, true_and]
180+
apply Set.mem_univ
181+
182+
omit [Fintype α] [LinearOrder α] in
183+
lemma mem_sum_language
184+
{ι : Type*} [DecidableEq ι] {S : Finset ι} {f : ι → Language α} {x : List α} :
185+
x ∈ ∑ i ∈ S, f i ↔ ∃ i ∈ S, x ∈ f i := by
186+
induction S using Finset.induction_on with
187+
| empty => simp
188+
| insert i S hi ih =>
189+
simp only [Finset.sum_insert hi, Language.mem_add]
190+
rw [ih]
191+
constructor
192+
· rintro (hx | ⟨j, hj, hxj⟩)
193+
· exact ⟨i, Finset.mem_insert_self i S, hx⟩
194+
· exact ⟨j, Finset.mem_insert_of_mem hj, hxj⟩
195+
· rintro ⟨j, hj, hxj⟩
196+
simp only [Finset.mem_insert] at hj
197+
rcases hj with (rfl | hj)
198+
· left
199+
exact hxj
200+
· right
201+
exact ⟨j, hj, hxj⟩
202+
203+
lemma mem_forbiddenPattern_iff {x : List α} {a b : α} :
204+
x ∈ ForbiddenPattern I a b ↔
205+
∃ y u z : List α, x = y ++ [b] ++ u ++ [a] ++ z ∧ (∀ c ∈ u, I.rel a c) := by
206+
unfold ForbiddenPattern IndependentLetters
207+
constructor
208+
· intro h
209+
simp [Language.mem_mul] at h
210+
rcases h with ⟨a1, b1, b2, b3, ⟨⟨ha1, hb1, hb2⟩, hb3⟩, ⟨x, hx, rfl⟩⟩
211+
use a1, b2, x
212+
constructor
213+
· simp only [Letter] at hb3 hb1
214+
rw [Set.mem_singleton_iff] at hb3 hb1
215+
subst hb3 hb1
216+
simp
217+
· intro c hc
218+
rw [Language.mem_kstar] at hb2
219+
rcases hb2 with ⟨L, rfl, hL⟩
220+
unfold Letter at hL
221+
simp only [List.mem_flatten] at hc
222+
rcases hc with ⟨y, hy, hcy⟩
223+
have hy_indep := hL y hy
224+
rw [mem_sum_language] at hy_indep
225+
simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hy_indep
226+
rcases hy_indep with ⟨c', hc'_rel, hc'_eq⟩
227+
rw [Set.mem_singleton_iff] at hc'_eq
228+
subst hc'_eq
229+
simp only [List.mem_singleton] at hcy
230+
subst hcy
231+
exact hc'_rel
232+
· intro h
233+
rcases h with ⟨y, u, z, rfl, h_indep⟩
234+
simp [Language.mem_mul]
235+
use y, [b], u, [a]
236+
unfold Letter
237+
and_intros
238+
· apply mem_sigma
239+
· rfl
240+
· rw [Language.mem_kstar]
241+
use u.map (fun c => [c])
242+
constructor
243+
· induction u with
244+
| nil => rfl
245+
| cons hd tl ih =>
246+
simp only [List.map_cons, List.flatten_cons, List.cons_append, List.nil_append,
247+
List.cons.injEq, true_and]
248+
simp only [List.mem_cons, forall_eq_or_imp] at h_indep
249+
rw [← ih h_indep.right]
250+
· intro y hy
251+
simp only [List.mem_map] at hy
252+
rcases hy with ⟨c, hc, rfl⟩
253+
rw [mem_sum_language]
254+
simp only [Finset.mem_filter, Finset.mem_univ, true_and]
255+
use c, h_indep c hc
256+
rfl
257+
· rfl
258+
· use z
259+
constructor
260+
· apply mem_sigma
261+
· simp
262+
263+
lemma mem_allForbiddenPatterns_iff {x : List α} :
264+
x ∈ AllForbiddenPatterns I ↔
265+
∃ a b, a < b ∧ I.rel a b ∧ x ∈ ForbiddenPattern I a b := by
266+
unfold AllForbiddenPatterns
267+
rw [mem_sum_language]
268+
simp only [Finset.mem_filter, Finset.mem_univ, true_and, Prod.exists, and_assoc]
269+
270+
/-- The language LexNfLanguage contains exactly the strings satisfying the factor condition. -/
271+
theorem mem_lexNfLanguage_iff_factorCondition (x : List α) :
272+
x ∈ LexNfLanguage I ↔ SatisfiesFactorCondition I x := by
273+
unfold LexNfLanguage SatisfiesFactorCondition
274+
rw [Set.mem_compl_iff, mem_allForbiddenPatterns_iff]
275+
push_neg
276+
constructor
277+
· intro h y u z a b hx h_indep hlt
278+
by_contra h_all_indep
279+
push_neg at h_all_indep
280+
have h_in_pattern : x ∈ ForbiddenPattern I a b := by
281+
rw [mem_forbiddenPattern_iff]
282+
exact ⟨y, u, z, hx, h_all_indep⟩
283+
exact h a b hlt h_indep h_in_pattern
284+
· intro h a b hlt h_indep h_in_pattern
285+
rw [mem_forbiddenPattern_iff] at h_in_pattern
286+
rcases h_in_pattern with ⟨y, u, z, hx, h_all_indep⟩
287+
rcases h y u z a b hx h_indep hlt with ⟨c, hc_mem, hc_not_indep⟩
288+
exact hc_not_indep (h_all_indep c hc_mem)
289+
290+
theorem exists_lexNf_rep (t : Trace I) : ∃ s : List α, ⟦s⟧ = t ∧ s ∈ LexNfLanguage I := by
291+
sorry
292+
174293
end LexNf
175294

176295
section rank

TraceTheory/TraceTheory/Ochmanski.lean

Lines changed: 177 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1+
import Mathlib.Algebra.Group.PUnit
2+
import TraceTheory.Language
13
import TraceTheory.Lemmas
24
import TraceTheory.MyhillNerode
35
import TraceTheory.RegularExpressions
46

57
namespace TraceTheory
68

9+
open scoped Pointwise
10+
711
open RegularExpression
812

9-
variable {α : Type*} {I : Independence α}
13+
variable {α : Type} {I : Independence α}
1014

1115
/-- Main component of Theorem 4.1 (ii) => (iii).
1216
@@ -120,4 +124,176 @@ theorem cRational_of_isStarConnected (X : RegularExpression α) (h : IsStarConne
120124
rw [connectedComponents_of_connected _ hP_conn]
121125
rw [kstar_eq_minusEps_trace]
122126

127+
lemma recognizable_zero : IsRecognizable (∅ : Set (Trace I)) :=
128+
⟨PUnit, inferInstance, inferInstance, inferInstance, 1, by simp⟩
129+
130+
lemma recognizable_epsilon : IsRecognizable ({ 1 } : Set (Trace I)) := by
131+
sorry
132+
133+
lemma recognizable_char (a : α) : IsRecognizable ({ ⟦[a]⟧ } : Set (Trace I)) := by
134+
sorry
135+
136+
lemma recognizable_union {M : Type} [Monoid M] {P Q : Set M}
137+
(hP : IsRecognizable P) (hQ : IsRecognizable Q) : IsRecognizable (P ∪ Q) := by
138+
sorry
139+
140+
lemma recognizable_mul {P Q : Set (Trace I)}
141+
(hP : IsRecognizable P) (hQ : IsRecognizable Q) : IsRecognizable (P * Q) := by
142+
sorry
143+
144+
lemma recognizable_cstar {P : Set (Trace I)}
145+
(hP : IsRecognizable P) : IsRecognizable (kstar (connectedComponents P)) := by
146+
sorry
147+
148+
/-- Theorem 4.1 (iv) => (i) -/
149+
theorem recognizable_of_cRational (X : RegularExpression α) :
150+
IsRecognizable (matches_cstar_trace I X) := by
151+
induction X with
152+
| zero => exact recognizable_zero
153+
| epsilon => exact recognizable_epsilon
154+
| char a => exact recognizable_char a
155+
| plus P Q ihP ihQ => exact recognizable_union ihP ihQ
156+
| comp P Q ihP ihQ => exact recognizable_mul ihP ihQ
157+
| star P ih => exact recognizable_cstar ih
158+
159+
variable [Fintype α] [LinearOrder α] [DecidableRel I.rel]
160+
161+
lemma connected_of_lexNf_sq {w : List α}
162+
(hw : w ∈ LexNfLanguage I)
163+
(hww : w ++ w ∈ LexNfLanguage I) :
164+
IsConnected I ⟦w⟧ := by
165+
sorry
166+
167+
omit [Fintype α] [LinearOrder α] in
168+
lemma mem_sigma (x : List α) : x ∈ KStar.kstar (Sigma : Language α) := by
169+
rw [Language.mem_kstar]
170+
use [x]
171+
simp only [List.flatten_cons, List.flatten_nil, List.append_nil, List.mem_cons,
172+
List.not_mem_nil, or_false, Sigma, forall_eq, true_and]
173+
apply Set.mem_univ
174+
175+
omit [LinearOrder α] in
176+
lemma forbidden_of_subword {u w v : List α} {a b : α}
177+
(hw : w ∈ ForbiddenPattern I a b) :
178+
u ++ w ++ v ∈ ForbiddenPattern I a b := by
179+
unfold ForbiddenPattern at *
180+
simp [Language.mem_mul] at hw
181+
rcases hw with ⟨a1, b1, b2, b3, ⟨⟨ha1, hb1, hb2⟩, hb3⟩, ⟨x, hx, rfl⟩⟩
182+
simp [Language.mem_mul]
183+
use u ++ a1, b1, b2, b3
184+
and_intros
185+
· apply mem_sigma
186+
· exact hb1
187+
· exact hb2
188+
· exact hb3
189+
· use x ++ v
190+
simp [mem_sigma]
191+
192+
lemma sum_forbidden_of_subword {S : Finset (α × α)} {u w v : List α}
193+
(hw : w ∈ ∑ p ∈ S, ForbiddenPattern I p.1 p.2) :
194+
u ++ w ++ v ∈ ∑ p ∈ S, ForbiddenPattern I p.1 p.2 := by
195+
induction S using Finset.induction_on generalizing w with
196+
| empty =>
197+
simp only [Finset.sum_empty] at hw
198+
contradiction
199+
| insert p' S' hp ih =>
200+
rw [Finset.sum_insert hp] at hw ⊢
201+
cases hw with
202+
| inl h_left =>
203+
left
204+
exact forbidden_of_subword h_left
205+
| inr h_right =>
206+
right
207+
exact ih h_right
208+
209+
lemma lexNf_of_subword {u w v : List α} (h : u ++ w ++ v ∈ LexNfLanguage I) :
210+
w ∈ LexNfLanguage I := by
211+
unfold LexNfLanguage at h ⊢
212+
rw [Set.mem_compl_iff] at h ⊢
213+
unfold AllForbiddenPatterns at h ⊢
214+
contrapose! h
215+
exact sum_forbidden_of_subword h
216+
217+
lemma connected_iterativeFactor_of_subset_lexNf {X : Language α}
218+
(hX : X ≤ LexNfLanguage I) {w : List α}
219+
(hw : IsIterativeFactor X w) :
220+
IsConnected I ⟦w⟧ := by
221+
rcases hw with ⟨u, v, hw⟩
222+
have h_lex1 : u ++ w ++ v ∈ LexNfLanguage I := hX (hw 1)
223+
have h_lex2 : u ++ (w ++ w) ++ v ∈ LexNfLanguage I := hX (hw 2)
224+
have h_w_lex : w ∈ LexNfLanguage I := lexNf_of_subword h_lex1
225+
have h_ww_lex : w ++ w ∈ LexNfLanguage I := lexNf_of_subword h_lex2
226+
exact connected_of_lexNf_sq h_w_lex h_ww_lex
227+
228+
omit [Fintype α] [LinearOrder α] in
229+
lemma isRegular_of_recognizable {L : Language α} (h : IsRecognizable L) :
230+
L.IsRegular := by
231+
rcases recognizable_is_recognizableDFMA L h with ⟨σ, h_fin, h_decide, M, hM⟩
232+
rw [Language.isRegular_iff]
233+
let M_DFA : DFA α σ := {
234+
step := fun q a => M.step q [a]
235+
start := M.start
236+
accept := M.accept
237+
}
238+
use σ, h_fin, M_DFA
239+
rw [hM]
240+
ext w
241+
simp [DFA.accepts, DFA.acceptsFrom, DFA.evalFrom]
242+
unfold DFMA.accepts DFMA.eval
243+
rw [Set.mem_setOf, Set.mem_setOf]
244+
have h_eval : ∀ q, List.foldl M_DFA.step q w = M.step q w := by
245+
induction w with
246+
| nil =>
247+
intro q
248+
simp only [List.foldl_nil]
249+
exact (M.idempotent q).symm
250+
| cons a ws ih =>
251+
intro q
252+
simp only [List.foldl_cons]
253+
rw [ih (M.step q [a])]
254+
exact (M.composition q [a] ws)
255+
rw [h_eval M_DFA.start]
256+
257+
/-- Theorem 4.1 (i) => (ii) -/
258+
theorem connectedIterativeFactors_of_recognizable {T : Set (Trace I)}
259+
(hT : IsRecognizable T) :
260+
∃ X : RegularExpression α,
261+
(∀ s, IsIterativeFactor X.matches' s → IsConnected I ⟦s⟧) ∧
262+
toTrace I X.matches' = T := by
263+
let L : Language α := (mk' (I := I) ⁻¹' T) ⊓ LexNfLanguage I
264+
have hL_reg : L.IsRegular := by
265+
apply Language.IsRegular.inf
266+
· apply isRegular_of_recognizable
267+
apply recognizable_has_recognizablePreImage
268+
exact hT
269+
· apply isRegular_lexNf
270+
have ⟨R, hR_matches⟩ : ∃ R : RegularExpression α, R.matches' = L := by
271+
classical
272+
have ⟨σ, h_fin, M, hL⟩ : ∃ (σ : Type) (_ : Fintype σ) (M : DFA α σ), M.accepts = L :=
273+
Language.isRegular_iff.mp hL_reg
274+
haveI : FinEnum σ := FinEnum.ofEquiv (Fin (Fintype.card σ)) (Fintype.equivFin σ)
275+
use M.toNFA.toεNFA.toRegex
276+
rw [← hL, εNFA.accepts_toRegex, NFA.toεNFA_correct, DFA.toNFA_correct]
277+
use R
278+
constructor
279+
· intro s hs
280+
have h_subset : R.matches' ≤ LexNfLanguage I := by
281+
simp_all only [inf_le_right, L]
282+
exact connected_iterativeFactor_of_subset_lexNf h_subset hs
283+
· rw [hR_matches]
284+
ext t
285+
constructor
286+
· rintro ⟨s, hs, rfl⟩
287+
exact hs.left
288+
· intro ht
289+
rcases exists_lexNf_rep I t with ⟨s, hs_eq, hs_lex⟩
290+
refine ⟨s, ?_, hs_eq⟩
291+
unfold L
292+
change s ∈ ⇑mk' ⁻¹' T ∩ LexNfLanguage I
293+
constructor
294+
· rw [Set.mem_preimage]
295+
subst hs_eq
296+
exact ht
297+
· exact hs_lex
298+
123299
end TraceTheory

0 commit comments

Comments
 (0)