Skip to content

Commit 2462682

Browse files
committed
Update concat and kstar lemmas
1 parent a362101 commit 2462682

1 file changed

Lines changed: 41 additions & 13 deletions

File tree

TraceTheory/TraceTheory/Computability.lean

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def concat (εM₁ : εNFA α σ₁) (εM₂ : εNFA α σ₂) : εNFA α (σ₁
2626
start := εM₁.start.image Sum.inl
2727
accept := εM₂.accept.image Sum.inr
2828

29-
lemma IsPath.lift_inl {εM₁ : εNFA α σ₁} {εM₂ : εNFA α σ₂} {s t : σ₁} {x : List (Option α)}
29+
lemma IsPath.concat_lift_inl {εM₁ : εNFA α σ₁} {εM₂ : εNFA α σ₂} {s t : σ₁} {x : List (Option α)}
3030
(h : εM₁.IsPath s t x) : (concat εM₁ εM₂).IsPath (Sum.inl s) (Sum.inl t) x := by
3131
induction h with
3232
| nil _ =>
@@ -41,7 +41,7 @@ lemma IsPath.lift_inl {εM₁ : εNFA α σ₁} {εM₂ : εNFA α σ₂} {s t :
4141
by_cases h_mem : s' ∈ εM₁.accept <;> simp [h_mem, h_step]
4242
· exact ih
4343

44-
lemma IsPath.lift_inr {εM₁ : εNFA α σ₁} {εM₂ : εNFA α σ₂} {s t : σ₂} {x : List (Option α)}
44+
lemma IsPath.concat_lift_inr {εM₁ : εNFA α σ₁} {εM₂ : εNFA α σ₂} {s t : σ₂} {x : List (Option α)}
4545
(h : εM₂.IsPath s t x) : (concat εM₁ εM₂).IsPath (Sum.inr s) (Sum.inr t) x := by
4646
induction h with
4747
| nil _ =>
@@ -52,7 +52,7 @@ lemma IsPath.lift_inr {εM₁ : εNFA α σ₁} {εM₂ : εNFA α σ₂} {s t :
5252
exact h_step
5353
· exact ih
5454

55-
lemma IsPath.proj_inr {εM₁ : εNFA α σ₁} {εM₂ : εNFA α σ₂} {s t : σ₂} {x : List (Option α)}
55+
lemma IsPath.concat_proj_inr {εM₁ : εNFA α σ₁} {εM₂ : εNFA α σ₂} {s t : σ₂} {x : List (Option α)}
5656
(h : (concat εM₁ εM₂).IsPath (Sum.inr s) (Sum.inr t) x) : εM₂.IsPath s t x := by
5757
generalize hs' : Sum.inr s = s' at h
5858
generalize ht' : Sum.inr t = t' at h
@@ -70,7 +70,7 @@ lemma IsPath.proj_inr {εM₁ : εNFA α σ₁} {εM₂ : εNFA α σ₂} {s t
7070
· exact hq
7171
· simp [ih]
7272

73-
lemma IsPath.split_inl_inr
73+
lemma IsPath.concat_split_inl_inr
7474
{εM₁ : εNFA α σ₁} {εM₂ : εNFA α σ₂} {s : σ₁} {t : σ₂} {x : List (Option α)}
7575
(h : (concat εM₁ εM₂).IsPath (Sum.inl s) (Sum.inr t) x) :
7676
∃ u v s_acc s_start, x = u ++ [none] ++ v ∧
@@ -116,7 +116,7 @@ lemma IsPath.split_inl_inr
116116
· exact (εNFA.isPath_nil εM₁).mpr rfl
117117
· exact h_mem
118118
· exact hq
119-
· exact IsPath.proj_inr h_path
119+
· exact IsPath.concat_proj_inr h_path
120120
· simp [concat, h_mem] at h_step
121121
rcases h_step with ⟨q, hq, rfl⟩
122122
have ⟨u, v, s_acc, s_start, hx', h_path_rest, h_acc, h_bridge, h_path_M₂⟩ :=
@@ -129,7 +129,7 @@ lemma IsPath.split_inl_inr
129129
· exact h_bridge
130130
· exact h_path_M₂
131131

132-
theorem accepts_concat (εM₁ : εNFA α σ₁) (εM₂ : εNFA α σ₂) :
132+
theorem accepts_concat {εM₁ : εNFA α σ₁} {εM₂ : εNFA α σ₂} :
133133
(concat εM₁ εM₂).accepts = εM₁.accepts * εM₂.accepts := by
134134
ext x
135135
constructor
@@ -140,7 +140,7 @@ theorem accepts_concat (εM₁ : εNFA α σ₁) (εM₂ : εNFA α σ₂) :
140140
rcases hq₁ with ⟨s, hs, rfl⟩
141141
rcases hq₂ with ⟨t, ht, rfl⟩
142142
have ⟨u', v', s_acc, s_start, hx, h_path_M₁, h_acc_M₁, h_start_M₂, h_path_M₂⟩ :=
143-
IsPath.split_inl_inr hεM
143+
IsPath.concat_split_inl_inr hεM
144144
apply Language.mem_mul.mpr
145145
use u'.reduceOption
146146
constructor
@@ -170,15 +170,35 @@ theorem accepts_concat (εM₁ : εNFA α σ₁) (εM₂ : εNFA α σ₂) :
170170
constructor
171171
· use (Sum.inl uq₂)
172172
constructor
173-
· exact IsPath.lift_inl hεM₁
173+
· exact IsPath.concat_lift_inl hεM₁
174174
· simp [concat, huq₂, hvq₁]
175-
· exact IsPath.lift_inr hεM₂
175+
· exact IsPath.concat_lift_inr hεM₂
176176

177177
end concat
178178

179179
section kstar
180180

181+
variable {σ : Type*}
181182

183+
def kstar (εM : εNFA α σ) : εNFA α (Unit ⊕ σ) where
184+
step q oa := match q, oa with
185+
| Sum.inl _, some _ =>
186+
{}
187+
| Sum.inl _, none =>
188+
εM.start.image Sum.inr
189+
| Sum.inr s, some a =>
190+
(εM.step s (some a)).image Sum.inr
191+
| Sum.inr s, none =>
192+
let internal := (εM.step s none).image Sum.inr
193+
if s ∈ εM.accept then
194+
internal ∪ (εM.start.image Sum.inr)
195+
else
196+
internal
197+
start := { Sum.inl () }
198+
accept := { Sum.inl () } ∪ (εM.accept.image Sum.inr)
199+
200+
theorem accepts_kstar {εM : εNFA α σ} : (kstar εM).accepts = (εM.accepts)∗ := by
201+
sorry
182202

183203
end kstar
184204

@@ -198,7 +218,7 @@ def char (a : α) [DecidableEq α] : DFA α (Fin 3) where
198218
start := 0
199219
accept := {1}
200220

201-
theorem accepts_char (a : α) : (char a).accepts = { [a] } := by
221+
theorem accepts_char {a : α} : (char a).accepts = { [a] } := by
202222
ext x
203223
simp [DFA.accepts, DFA.acceptsFrom, DFA.evalFrom]
204224
constructor
@@ -289,15 +309,23 @@ theorem IsRegular.mul {L₁ L₂ : Language α} [DecidableEq α]
289309
rw [NFA.toDFA_correct, εNFA.toNFA_correct]
290310
rw [← DFA.toNFA_correct, ← NFA.toεNFA_correct]
291311
rw [← DFA.toNFA_correct, ← NFA.toεNFA_correct]
292-
exact εNFA.accepts_concat εM₁ εM₂
312+
exact εNFA.accepts_concat
293313

294314
theorem IsRegular.kstar {L : Language α} (h : IsRegular L) : IsRegular (L∗) := by
295-
sorry
315+
have ⟨σ, _, M, hM⟩ := h
316+
let εM := M.toNFA.toεNFA
317+
let εM_kstar := εNFA.kstar εM
318+
apply isRegular_iff.mpr
319+
use Set (Unit ⊕ σ), inferInstance, εM_kstar.toNFA.toDFA
320+
subst hM
321+
rw [NFA.toDFA_correct, εNFA.toNFA_correct]
322+
rw [← DFA.toNFA_correct, ← NFA.toεNFA_correct]
323+
exact εNFA.accepts_kstar
296324

297325
theorem IsRegular.singleton {a : α} : IsRegular ({ [a] }) := by
298326
apply isRegular_iff.mpr
299327
let M := DFA.char a
300328
use Fin 3, inferInstance, M
301-
exact DFA.accepts_char a
329+
exact DFA.accepts_char
302330

303331
end Language

0 commit comments

Comments
 (0)