@@ -124,6 +124,7 @@ theorem cRational_of_isStarConnected (X : RegularExpression α) (h : IsStarConne
124124 rw [connectedComponents_of_connected _ hP_conn]
125125 rw [kstar_eq_minusEps_trace]
126126
127+ /-- Hashiguchi's Theorem. -/
127128theorem recognizable_image_of_regular_finite_rank {X : Language α}
128129 (hX_reg : X.IsRegular)
129130 (hX_rank : HasFiniteRank I X) :
@@ -147,12 +148,132 @@ instance : Monoid EpsMonoid where
147148 one_mul x := by cases x <;> rfl
148149 mul_assoc x y z := by cases x <;> cases y <;> cases z <;> rfl
149150
151+ def eps_map_aux : List α → EpsMonoid
152+ | [] => .one
153+ | _ :: _ => .dead
154+
155+ lemma eps_map_aux_append (x y : List α) :
156+ eps_map_aux (x ++ y) = eps_map_aux x * eps_map_aux y := by
157+ cases x <;> cases y <;> rfl
158+
159+ def eps_map : Trace I →* EpsMonoid where
160+ toFun := Quotient.lift
161+ eps_map_aux
162+ (by
163+ intro a b
164+ cases a <;> cases b
165+ · simp
166+ · intro heqv
167+ apply length_eq_of_eqv at heqv
168+ simp at heqv
169+ · intro heqv
170+ apply length_eq_of_eqv at heqv
171+ simp at heqv
172+ · simp [eps_map_aux]
173+ )
174+ map_one' := rfl
175+ map_mul' := by
176+ rintro ⟨x⟩ ⟨y⟩
177+ exact eps_map_aux_append x y
178+
150179lemma recognizable_epsilon : IsRecognizable ({ 1 } : Set (Trace I)) := by
151- use EpsMonoid, inferInstance, inferInstance, inferInstance
152- sorry
180+ use EpsMonoid, inferInstance, inferInstance, inferInstance, eps_map
181+ simp only [Set.image_singleton, map_one]
182+ ext t
183+ rcases t with ⟨w⟩
184+ change ⟦w⟧ ∈ {1 } ↔ ⟦w⟧ ∈ ⇑eps_map ⁻¹' {1 }
185+ constructor
186+ · intro h
187+ rw [h, Set.mem_preimage, map_one, Set.mem_singleton_iff]
188+ · intro h
189+ cases w with
190+ | nil =>
191+ rw [Set.mem_singleton_iff]
192+ rfl
193+ | cons a w' =>
194+ have h_map : eps_map (I := I) ⟦a :: w'⟧ = eps_map (I := I) ⟦[a]⟧ * eps_map (I := I) ⟦w'⟧ := rfl
195+ simp only [Set.mem_preimage, Set.mem_singleton_iff] at h
196+ rw [h_map] at h
197+ have h_dead : eps_map (I := I) ⟦[a]⟧ = EpsMonoid.dead := rfl
198+ rw [h_dead] at h
199+ contradiction
153200
154- lemma recognizable_char (a : α) : IsRecognizable ({ ⟦[a]⟧ } : Set (Trace I)) := by
155- sorry
201+ inductive CharMonoid
202+ | one
203+ | saw_a
204+ | dead
205+ deriving DecidableEq, Fintype
206+
207+ instance : Monoid CharMonoid where
208+ one := .one
209+ mul
210+ | .one, x => x
211+ | x, .one => x
212+ | _, _ => .dead
213+ mul_one x := by cases x <;> rfl
214+ one_mul x := by cases x <;> rfl
215+ mul_assoc x y z := by cases x <;> cases y <;> cases z <;> rfl
216+
217+ def char_map_aux [DecidableEq α] (a : α) : List α → CharMonoid
218+ | [] => .one
219+ | c :: w => (if c = a then .saw_a else .dead) * char_map_aux a w
220+
221+ lemma char_map_aux_append [DecidableEq α] (a : α) (x y : List α) :
222+ char_map_aux a (x ++ y) = char_map_aux a x * char_map_aux a y := by
223+ induction x with
224+ | nil =>
225+ simp only [char_map_aux]
226+ rfl
227+ | cons b x' ih => simp [char_map_aux, ih, mul_assoc]
228+
229+ def char_map [DecidableEq α] (a : α) : Trace I →* CharMonoid where
230+ toFun := Quotient.lift
231+ (char_map_aux a)
232+ (by
233+ intro b c heqv
234+ induction heqv with
235+ | swap e f hrel =>
236+ by_cases hea : e = a <;> by_cases hfa : f = a
237+ · subst hea hfa
238+ rfl
239+ · subst hea
240+ simp only [char_map_aux, ↓reduceIte, hfa]
241+ rfl
242+ · subst hfa
243+ simp only [char_map_aux, ↓reduceIte, hea]
244+ rfl
245+ · simp only [char_map_aux, ↓reduceIte, hea, hfa]
246+ | refl => rfl
247+ | symm _ ih => exact ih.symm
248+ | trans _ _ ih₁ ih₂ => exact ih₁.trans ih₂
249+ | compat _ _ ih₁ ih₂ => rw [char_map_aux_append, char_map_aux_append, ih₁, ih₂]
250+ )
251+ map_one' := rfl
252+ map_mul' := by
253+ rintro ⟨x⟩ ⟨y⟩
254+ exact char_map_aux_append a x y
255+
256+ lemma recognizable_char [DecidableEq α] (a : α) : IsRecognizable ({ ⟦[a]⟧ } : Set (Trace I)) := by
257+ use CharMonoid, inferInstance, inferInstance, inferInstance, char_map a
258+ simp only [Set.image_singleton]
259+ ext t
260+ rcases t with ⟨w⟩
261+ change ⟦w⟧ ∈ {⟦[a]⟧} ↔ ⟦w⟧ ∈ ⇑(char_map a) ⁻¹' {(char_map a) ⟦[a]⟧}
262+ simp only [Set.mem_singleton_iff, Set.mem_preimage]
263+ constructor
264+ · intro h
265+ rw [h]
266+ · intro h
267+ rcases w with _ | ⟨b, _ | ⟨c, w'⟩⟩
268+ · simp [char_map, char_map_aux] at h
269+ · simp_all [char_map, char_map_aux]
270+ · simp [char_map, char_map_aux] at h
271+ split_ifs at h
272+ all_goals (
273+ generalize hw' : char_map_aux a w' = x at h
274+ cases x
275+ all_goals (simp at h)
276+ )
156277
157278lemma recognizable_union {M : Type } [Monoid M] {P Q : Set M}
158279 (hP : IsRecognizable P) (hQ : IsRecognizable Q) : IsRecognizable (P ∪ Q) := by
@@ -167,7 +288,7 @@ lemma recognizable_cstar {P : Set (Trace I)}
167288 sorry
168289
169290/-- Theorem 4.1 (iv) => (i) -/
170- theorem recognizable_of_cRational (X : RegularExpression α) :
291+ theorem recognizable_of_cRational [DecidableEq α] (X : RegularExpression α) :
171292 IsRecognizable (matches_cstar_trace I X) := by
172293 induction X with
173294 | zero => exact recognizable_zero
0 commit comments