@@ -197,8 +197,89 @@ def kstar (εM : εNFA α σ) : εNFA α (Unit ⊕ σ) where
197197 start := { Sum.inl () }
198198 accept := { Sum.inl () } ∪ (εM.accept.image Sum.inr)
199199
200+ lemma IsPath.kstar_lift_inr {εM : εNFA α σ} {s t : σ} {x : List (Option α)}
201+ (h : εM.IsPath s t x) :
202+ εM.kstar.IsPath (Sum.inr s) (Sum.inr t) x := by
203+ induction h with
204+ | nil _ =>
205+ exact (isPath_nil εM.kstar).mpr rfl
206+ | cons t' s' u oa x' h_step h_path ih =>
207+ apply εNFA.IsPath.cons (Sum.inr t') (Sum.inr s') (Sum.inr u)
208+ · simp [kstar]
209+ cases oa with
210+ | some a =>
211+ simp [h_step]
212+ | none =>
213+ by_cases h_mem : s' ∈ εM.accept <;> simp [h_mem, h_step]
214+ · exact ih
215+
216+ lemma exists_path_inr_of_flatten {εM : εNFA α σ}
217+ (L : List (List α)) (h_nonempty : L ≠ []) (h_all : ∀ y ∈ L, y ∈ εM.accepts) :
218+ ∃ (s : σ) (q : Unit ⊕ σ) (x : List (Option α)),
219+ s ∈ εM.start ∧
220+ q ∈ εM.kstar.accept ∧
221+ x.reduceOption = L.flatten ∧
222+ εM.kstar.IsPath (Sum.inr s) q x := by
223+ induction L with
224+ | nil =>
225+ contradiction
226+ | cons y L' ih =>
227+ have hy := h_all y List.mem_cons_self
228+ have ⟨s, t, x, hs, ht, hy', hx⟩ := (εNFA.mem_accepts_iff_exists_path εM).mp hy
229+ subst hy'
230+ cases L' with
231+ | nil =>
232+ use s, Sum.inr t, x
233+ and_intros
234+ · exact hs
235+ · simp [kstar]
236+ exact ht
237+ · simp
238+ · exact IsPath.kstar_lift_inr hx
239+ | cons z L'' =>
240+ have h_nonempty' : z :: L'' ≠ [] := by simp
241+ have h_all' : ∀ y ∈ z :: L'', y ∈ εM.accepts := by
242+ intro y hy
243+ exact h_all y (by simp [hy])
244+ have ⟨s', q, x', hs', hq, hL'', hx'⟩:= ih h_nonempty' h_all'
245+ use s, q, x ++ [none] ++ x'
246+ and_intros
247+ · exact hs
248+ · exact hq
249+ · simp [hL'', List.reduceOption_append]
250+ · rw [List.append_assoc, isPath_append]
251+ use Sum.inr t
252+ constructor
253+ · exact IsPath.kstar_lift_inr hx
254+ · apply IsPath.cons (Sum.inr s')
255+ · simp [kstar, ht, hs']
256+ · simp [hx']
257+
200258theorem accepts_kstar {εM : εNFA α σ} : (kstar εM).accepts = (εM.accepts)∗ := by
201- sorry
259+ ext x
260+ constructor
261+ · sorry
262+ · intro h
263+ rw [Language.kstar_def, Set.mem_setOf_eq] at h
264+ rcases h with ⟨L, hx, hL⟩
265+ apply (mem_accepts_iff_exists_path εM.kstar).mpr
266+ cases L with
267+ | nil =>
268+ use Sum.inl (), Sum.inl (), []
269+ simp [kstar, hx]
270+ | cons l L' =>
271+ expose_names
272+ have h_nonempty : l :: L' ≠ [] := by simp
273+ have ⟨s, q, x', hs, hq, hL', hx'⟩ := exists_path_inr_of_flatten (l :: L') h_nonempty hL
274+ use Sum.inl (), q, none :: x'
275+ and_intros
276+ · simp [kstar]
277+ · exact hq
278+ · simp [hx, hL']
279+ · apply IsPath.cons (Sum.inr s)
280+ · simp [kstar]
281+ exact hs
282+ · exact hx'
202283
203284end kstar
204285
0 commit comments