149
|
1 |
theory Myhill_2
|
|
2 |
imports Myhill_1 Prefix_subtract
|
|
3 |
"~~/src/HOL/Library/List_Prefix"
|
|
4 |
begin
|
|
5 |
|
|
6 |
section {* Direction @{text "regular language \<Rightarrow>finite partition"} *}
|
|
7 |
|
|
8 |
definition
|
|
9 |
str_eq :: "string \<Rightarrow> lang \<Rightarrow> string \<Rightarrow> bool" ("_ \<approx>_ _")
|
|
10 |
where
|
|
11 |
"x \<approx>A y \<equiv> (x, y) \<in> (\<approx>A)"
|
|
12 |
|
|
13 |
definition
|
|
14 |
tag_eq_rel :: "(string \<Rightarrow> 'b) \<Rightarrow> (string \<times> string) set" ("=_=")
|
|
15 |
where
|
|
16 |
"=tag= \<equiv> {(x, y) | x y. tag x = tag y}"
|
|
17 |
|
|
18 |
lemma finite_eq_tag_rel:
|
|
19 |
assumes rng_fnt: "finite (range tag)"
|
|
20 |
shows "finite (UNIV // =tag=)"
|
|
21 |
proof -
|
|
22 |
let "?f" = "\<lambda>X. tag ` X" and ?A = "(UNIV // =tag=)"
|
|
23 |
have "finite (?f ` ?A)"
|
|
24 |
proof -
|
|
25 |
have "range ?f \<subseteq> (Pow (range tag))" unfolding Pow_def by auto
|
|
26 |
moreover
|
|
27 |
have "finite (Pow (range tag))" using rng_fnt by simp
|
|
28 |
ultimately
|
|
29 |
have "finite (range ?f)" unfolding image_def by (blast intro: finite_subset)
|
|
30 |
moreover
|
|
31 |
have "?f ` ?A \<subseteq> range ?f" by auto
|
|
32 |
ultimately show "finite (?f ` ?A)" by (rule rev_finite_subset)
|
|
33 |
qed
|
|
34 |
moreover
|
|
35 |
have "inj_on ?f ?A"
|
|
36 |
proof -
|
|
37 |
{ fix X Y
|
|
38 |
assume X_in: "X \<in> ?A"
|
|
39 |
and Y_in: "Y \<in> ?A"
|
|
40 |
and tag_eq: "?f X = ?f Y"
|
|
41 |
then obtain x y
|
|
42 |
where "x \<in> X" "y \<in> Y" "tag x = tag y"
|
|
43 |
unfolding quotient_def Image_def image_def tag_eq_rel_def
|
|
44 |
by (simp) (blast)
|
|
45 |
with X_in Y_in
|
|
46 |
have "X = Y"
|
|
47 |
unfolding quotient_def tag_eq_rel_def by auto
|
|
48 |
}
|
|
49 |
then show "inj_on ?f ?A" unfolding inj_on_def by auto
|
|
50 |
qed
|
|
51 |
ultimately show "finite (UNIV // =tag=)" by (rule finite_imageD)
|
|
52 |
qed
|
|
53 |
|
|
54 |
lemma refined_partition_finite:
|
|
55 |
assumes fnt: "finite (UNIV // R1)"
|
|
56 |
and refined: "R1 \<subseteq> R2"
|
|
57 |
and eq1: "equiv UNIV R1" and eq2: "equiv UNIV R2"
|
|
58 |
shows "finite (UNIV // R2)"
|
|
59 |
proof -
|
|
60 |
let ?f = "\<lambda>X. {R1 `` {x} | x. x \<in> X}"
|
|
61 |
and ?A = "UNIV // R2" and ?B = "UNIV // R1"
|
|
62 |
have "?f ` ?A \<subseteq> Pow ?B"
|
|
63 |
unfolding image_def Pow_def quotient_def by auto
|
|
64 |
moreover
|
|
65 |
have "finite (Pow ?B)" using fnt by simp
|
|
66 |
ultimately
|
|
67 |
have "finite (?f ` ?A)" by (rule finite_subset)
|
|
68 |
moreover
|
|
69 |
have "inj_on ?f ?A"
|
|
70 |
proof -
|
|
71 |
{ fix X Y
|
|
72 |
assume X_in: "X \<in> ?A" and Y_in: "Y \<in> ?A" and eq_f: "?f X = ?f Y"
|
|
73 |
from quotientE [OF X_in]
|
|
74 |
obtain x where "X = R2 `` {x}" by blast
|
|
75 |
with equiv_class_self[OF eq2] have x_in: "x \<in> X" by simp
|
|
76 |
then have "R1 ``{x} \<in> ?f X" by auto
|
|
77 |
with eq_f have "R1 `` {x} \<in> ?f Y" by simp
|
|
78 |
then obtain y
|
|
79 |
where y_in: "y \<in> Y" and eq_r1_xy: "R1 `` {x} = R1 `` {y}" by auto
|
|
80 |
with eq_equiv_class[OF _ eq1]
|
|
81 |
have "(x, y) \<in> R1" by blast
|
|
82 |
with refined have "(x, y) \<in> R2" by auto
|
|
83 |
with quotient_eqI [OF eq2 X_in Y_in x_in y_in]
|
|
84 |
have "X = Y" .
|
|
85 |
}
|
|
86 |
then show "inj_on ?f ?A" unfolding inj_on_def by blast
|
|
87 |
qed
|
|
88 |
ultimately show "finite (UNIV // R2)" by (rule finite_imageD)
|
|
89 |
qed
|
|
90 |
|
|
91 |
lemma tag_finite_imageD:
|
|
92 |
assumes rng_fnt: "finite (range tag)"
|
|
93 |
and same_tag_eqvt: "\<And>m n. tag m = tag n \<Longrightarrow> m \<approx>A n"
|
|
94 |
shows "finite (UNIV // \<approx>A)"
|
|
95 |
proof (rule_tac refined_partition_finite [of "=tag="])
|
|
96 |
show "finite (UNIV // =tag=)" by (rule finite_eq_tag_rel[OF rng_fnt])
|
|
97 |
next
|
|
98 |
from same_tag_eqvt
|
|
99 |
show "=tag= \<subseteq> \<approx>A" unfolding tag_eq_rel_def str_eq_def
|
|
100 |
by auto
|
|
101 |
next
|
|
102 |
show "equiv UNIV =tag="
|
|
103 |
unfolding equiv_def tag_eq_rel_def refl_on_def sym_def trans_def
|
|
104 |
by auto
|
|
105 |
next
|
|
106 |
show "equiv UNIV (\<approx>A)"
|
|
107 |
unfolding equiv_def str_eq_rel_def sym_def refl_on_def trans_def
|
|
108 |
by blast
|
|
109 |
qed
|
|
110 |
|
|
111 |
|
|
112 |
subsection {* The proof *}
|
|
113 |
|
|
114 |
subsubsection {* The base case for @{const "NULL"} *}
|
|
115 |
|
|
116 |
lemma quot_null_eq:
|
|
117 |
shows "UNIV // \<approx>{} = {UNIV}"
|
|
118 |
unfolding quotient_def Image_def str_eq_rel_def by auto
|
|
119 |
|
|
120 |
lemma quot_null_finiteI [intro]:
|
|
121 |
shows "finite (UNIV // \<approx>{})"
|
|
122 |
unfolding quot_null_eq by simp
|
|
123 |
|
|
124 |
|
|
125 |
subsubsection {* The base case for @{const "EMPTY"} *}
|
|
126 |
|
|
127 |
lemma quot_empty_subset:
|
|
128 |
shows "UNIV // \<approx>{[]} \<subseteq> {{[]}, UNIV - {[]}}"
|
|
129 |
proof
|
|
130 |
fix x
|
|
131 |
assume "x \<in> UNIV // \<approx>{[]}"
|
|
132 |
then obtain y where h: "x = {z. (y, z) \<in> \<approx>{[]}}"
|
|
133 |
unfolding quotient_def Image_def by blast
|
|
134 |
show "x \<in> {{[]}, UNIV - {[]}}"
|
|
135 |
proof (cases "y = []")
|
|
136 |
case True with h
|
|
137 |
have "x = {[]}" by (auto simp: str_eq_rel_def)
|
|
138 |
thus ?thesis by simp
|
|
139 |
next
|
|
140 |
case False with h
|
|
141 |
have "x = UNIV - {[]}" by (auto simp: str_eq_rel_def)
|
|
142 |
thus ?thesis by simp
|
|
143 |
qed
|
|
144 |
qed
|
|
145 |
|
|
146 |
lemma quot_empty_finiteI [intro]:
|
|
147 |
shows "finite (UNIV // \<approx>{[]})"
|
|
148 |
by (rule finite_subset[OF quot_empty_subset]) (simp)
|
|
149 |
|
|
150 |
|
|
151 |
subsubsection {* The base case for @{const "CHAR"} *}
|
|
152 |
|
|
153 |
lemma quot_char_subset:
|
|
154 |
"UNIV // (\<approx>{[c]}) \<subseteq> {{[]},{[c]}, UNIV - {[], [c]}}"
|
|
155 |
proof
|
|
156 |
fix x
|
|
157 |
assume "x \<in> UNIV // \<approx>{[c]}"
|
|
158 |
then obtain y where h: "x = {z. (y, z) \<in> \<approx>{[c]}}"
|
|
159 |
unfolding quotient_def Image_def by blast
|
|
160 |
show "x \<in> {{[]},{[c]}, UNIV - {[], [c]}}"
|
|
161 |
proof -
|
|
162 |
{ assume "y = []" hence "x = {[]}" using h
|
|
163 |
by (auto simp:str_eq_rel_def) }
|
|
164 |
moreover
|
|
165 |
{ assume "y = [c]" hence "x = {[c]}" using h
|
|
166 |
by (auto dest!:spec[where x = "[]"] simp:str_eq_rel_def) }
|
|
167 |
moreover
|
|
168 |
{ assume "y \<noteq> []" and "y \<noteq> [c]"
|
|
169 |
hence "\<forall> z. (y @ z) \<noteq> [c]" by (case_tac y, auto)
|
|
170 |
moreover have "\<And> p. (p \<noteq> [] \<and> p \<noteq> [c]) = (\<forall> q. p @ q \<noteq> [c])"
|
|
171 |
by (case_tac p, auto)
|
|
172 |
ultimately have "x = UNIV - {[],[c]}" using h
|
|
173 |
by (auto simp add:str_eq_rel_def)
|
|
174 |
}
|
|
175 |
ultimately show ?thesis by blast
|
|
176 |
qed
|
|
177 |
qed
|
|
178 |
|
|
179 |
lemma quot_char_finiteI [intro]:
|
|
180 |
shows "finite (UNIV // \<approx>{[c]})"
|
|
181 |
by (rule finite_subset[OF quot_char_subset]) (simp)
|
|
182 |
|
|
183 |
|
|
184 |
subsubsection {* The inductive case for @{const ALT} *}
|
|
185 |
|
|
186 |
definition
|
|
187 |
tag_str_ALT :: "lang \<Rightarrow> lang \<Rightarrow> string \<Rightarrow> (lang \<times> lang)"
|
|
188 |
where
|
|
189 |
"tag_str_ALT A B \<equiv> (\<lambda>x. (\<approx>A `` {x}, \<approx>B `` {x}))"
|
|
190 |
|
|
191 |
lemma quot_union_finiteI [intro]:
|
|
192 |
fixes L1 L2::"lang"
|
|
193 |
assumes finite1: "finite (UNIV // \<approx>A)"
|
|
194 |
and finite2: "finite (UNIV // \<approx>B)"
|
|
195 |
shows "finite (UNIV // \<approx>(A \<union> B))"
|
|
196 |
proof (rule_tac tag = "tag_str_ALT A B" in tag_finite_imageD)
|
|
197 |
have "finite ((UNIV // \<approx>A) \<times> (UNIV // \<approx>B))"
|
|
198 |
using finite1 finite2 by auto
|
|
199 |
then show "finite (range (tag_str_ALT A B))"
|
|
200 |
unfolding tag_str_ALT_def quotient_def
|
|
201 |
by (rule rev_finite_subset) (auto)
|
|
202 |
next
|
|
203 |
show "\<And>x y. tag_str_ALT A B x = tag_str_ALT A B y \<Longrightarrow> x \<approx>(A \<union> B) y"
|
|
204 |
unfolding tag_str_ALT_def
|
|
205 |
unfolding str_eq_def
|
|
206 |
unfolding str_eq_rel_def
|
|
207 |
by auto
|
|
208 |
qed
|
|
209 |
|
|
210 |
|
|
211 |
subsubsection {* The inductive case for @{text "SEQ"}*}
|
|
212 |
|
|
213 |
definition
|
|
214 |
tag_str_SEQ :: "lang \<Rightarrow> lang \<Rightarrow> string \<Rightarrow> (lang \<times> lang set)"
|
|
215 |
where
|
|
216 |
"tag_str_SEQ L1 L2 \<equiv>
|
|
217 |
(\<lambda>x. (\<approx>L1 `` {x}, {(\<approx>L2 `` {x - xa}) | xa. xa \<le> x \<and> xa \<in> L1}))"
|
|
218 |
|
|
219 |
lemma Seq_in_cases:
|
|
220 |
assumes "x @ z \<in> A ;; B"
|
|
221 |
shows "(\<exists> x' \<le> x. x' \<in> A \<and> (x - x') @ z \<in> B) \<or>
|
|
222 |
(\<exists> z' \<le> z. (x @ z') \<in> A \<and> (z - z') \<in> B)"
|
|
223 |
using assms
|
|
224 |
unfolding Seq_def prefix_def
|
|
225 |
by (auto simp add: append_eq_append_conv2)
|
|
226 |
|
|
227 |
lemma tag_str_SEQ_injI:
|
|
228 |
assumes eq_tag: "tag_str_SEQ A B x = tag_str_SEQ A B y"
|
|
229 |
shows "x \<approx>(A ;; B) y"
|
|
230 |
proof -
|
|
231 |
{ fix x y z
|
|
232 |
assume xz_in_seq: "x @ z \<in> A ;; B"
|
|
233 |
and tag_xy: "tag_str_SEQ A B x = tag_str_SEQ A B y"
|
|
234 |
have"y @ z \<in> A ;; B"
|
|
235 |
proof -
|
|
236 |
{ (* first case with x' in A and (x - x') @ z in B *)
|
|
237 |
fix x'
|
|
238 |
assume h1: "x' \<le> x" and h2: "x' \<in> A" and h3: "(x - x') @ z \<in> B"
|
|
239 |
obtain y'
|
|
240 |
where "y' \<le> y"
|
|
241 |
and "y' \<in> A"
|
|
242 |
and "(y - y') @ z \<in> B"
|
|
243 |
proof -
|
|
244 |
have "{\<approx>B `` {x - x'} |x'. x' \<le> x \<and> x' \<in> A} =
|
|
245 |
{\<approx>B `` {y - y'} |y'. y' \<le> y \<and> y' \<in> A}" (is "?Left = ?Right")
|
|
246 |
using tag_xy unfolding tag_str_SEQ_def by simp
|
|
247 |
moreover
|
|
248 |
have "\<approx>B `` {x - x'} \<in> ?Left" using h1 h2 by auto
|
|
249 |
ultimately
|
|
250 |
have "\<approx>B `` {x - x'} \<in> ?Right" by simp
|
|
251 |
then obtain y'
|
|
252 |
where eq_xy': "\<approx>B `` {x - x'} = \<approx>B `` {y - y'}"
|
|
253 |
and pref_y': "y' \<le> y" and y'_in: "y' \<in> A"
|
|
254 |
by simp blast
|
|
255 |
|
|
256 |
have "(x - x') \<approx>B (y - y')" using eq_xy'
|
|
257 |
unfolding Image_def str_eq_rel_def str_eq_def by auto
|
|
258 |
with h3 have "(y - y') @ z \<in> B"
|
|
259 |
unfolding str_eq_rel_def str_eq_def by simp
|
|
260 |
with pref_y' y'_in
|
|
261 |
show ?thesis using that by blast
|
|
262 |
qed
|
|
263 |
then have "y @ z \<in> A ;; B" by (erule_tac prefixE) (auto simp: Seq_def)
|
|
264 |
}
|
|
265 |
moreover
|
|
266 |
{ (* second case with x @ z' in A and z - z' in B *)
|
|
267 |
fix z'
|
|
268 |
assume h1: "z' \<le> z" and h2: "(x @ z') \<in> A" and h3: "z - z' \<in> B"
|
|
269 |
have "\<approx>A `` {x} = \<approx>A `` {y}"
|
|
270 |
using tag_xy unfolding tag_str_SEQ_def by simp
|
|
271 |
with h2 have "y @ z' \<in> A"
|
|
272 |
unfolding Image_def str_eq_rel_def str_eq_def by auto
|
|
273 |
with h1 h3 have "y @ z \<in> A ;; B"
|
|
274 |
unfolding prefix_def Seq_def
|
|
275 |
by (auto) (metis append_assoc)
|
|
276 |
}
|
|
277 |
ultimately show "y @ z \<in> A ;; B"
|
|
278 |
using Seq_in_cases [OF xz_in_seq] by blast
|
|
279 |
qed
|
|
280 |
}
|
|
281 |
from this [OF _ eq_tag] and this [OF _ eq_tag [THEN sym]]
|
|
282 |
show "x \<approx>(A ;; B) y" unfolding str_eq_def str_eq_rel_def by blast
|
|
283 |
qed
|
|
284 |
|
|
285 |
lemma quot_seq_finiteI [intro]:
|
|
286 |
fixes L1 L2::"lang"
|
|
287 |
assumes fin1: "finite (UNIV // \<approx>L1)"
|
|
288 |
and fin2: "finite (UNIV // \<approx>L2)"
|
|
289 |
shows "finite (UNIV // \<approx>(L1 ;; L2))"
|
|
290 |
proof (rule_tac tag = "tag_str_SEQ L1 L2" in tag_finite_imageD)
|
|
291 |
show "\<And>x y. tag_str_SEQ L1 L2 x = tag_str_SEQ L1 L2 y \<Longrightarrow> x \<approx>(L1 ;; L2) y"
|
|
292 |
by (rule tag_str_SEQ_injI)
|
|
293 |
next
|
|
294 |
have *: "finite ((UNIV // \<approx>L1) \<times> (Pow (UNIV // \<approx>L2)))"
|
|
295 |
using fin1 fin2 by auto
|
|
296 |
show "finite (range (tag_str_SEQ L1 L2))"
|
|
297 |
unfolding tag_str_SEQ_def
|
|
298 |
apply(rule finite_subset[OF _ *])
|
|
299 |
unfolding quotient_def
|
|
300 |
by auto
|
|
301 |
qed
|
|
302 |
|
|
303 |
|
|
304 |
subsubsection {* The inductive case for @{const "STAR"} *}
|
|
305 |
|
|
306 |
definition
|
|
307 |
tag_str_STAR :: "lang \<Rightarrow> string \<Rightarrow> lang set"
|
|
308 |
where
|
|
309 |
"tag_str_STAR L1 \<equiv> (\<lambda>x. {\<approx>L1 `` {x - xa} | xa. xa < x \<and> xa \<in> L1\<star>})"
|
|
310 |
|
|
311 |
text {* A technical lemma. *}
|
|
312 |
lemma finite_set_has_max: "\<lbrakk>finite A; A \<noteq> {}\<rbrakk> \<Longrightarrow>
|
|
313 |
(\<exists> max \<in> A. \<forall> a \<in> A. f a <= (f max :: nat))"
|
|
314 |
proof (induct rule:finite.induct)
|
|
315 |
case emptyI thus ?case by simp
|
|
316 |
next
|
|
317 |
case (insertI A a)
|
|
318 |
show ?case
|
|
319 |
proof (cases "A = {}")
|
|
320 |
case True thus ?thesis by (rule_tac x = a in bexI, auto)
|
|
321 |
next
|
|
322 |
case False
|
|
323 |
with insertI.hyps and False
|
|
324 |
obtain max
|
|
325 |
where h1: "max \<in> A"
|
|
326 |
and h2: "\<forall>a\<in>A. f a \<le> f max" by blast
|
|
327 |
show ?thesis
|
|
328 |
proof (cases "f a \<le> f max")
|
|
329 |
assume "f a \<le> f max"
|
|
330 |
with h1 h2 show ?thesis by (rule_tac x = max in bexI, auto)
|
|
331 |
next
|
|
332 |
assume "\<not> (f a \<le> f max)"
|
|
333 |
thus ?thesis using h2 by (rule_tac x = a in bexI, auto)
|
|
334 |
qed
|
|
335 |
qed
|
|
336 |
qed
|
|
337 |
|
|
338 |
|
|
339 |
text {* The following is a technical lemma, which helps to show the range finiteness of tag function. *}
|
|
340 |
|
|
341 |
lemma finite_strict_prefix_set: "finite {xa. xa < (x::string)}"
|
|
342 |
apply (induct x rule:rev_induct, simp)
|
|
343 |
apply (subgoal_tac "{xa. xa < xs @ [x]} = {xa. xa < xs} \<union> {xs}")
|
|
344 |
by (auto simp:strict_prefix_def)
|
|
345 |
|
|
346 |
|
|
347 |
lemma tag_str_STAR_injI:
|
|
348 |
assumes eq_tag: "tag_str_STAR L\<^isub>1 v = tag_str_STAR L\<^isub>1 w"
|
|
349 |
shows "v \<approx>(L\<^isub>1\<star>) w"
|
|
350 |
proof-
|
|
351 |
{ fix x y z
|
|
352 |
assume xz_in_star: "x @ z \<in> L\<^isub>1\<star>"
|
|
353 |
and tag_xy: "tag_str_STAR L\<^isub>1 x = tag_str_STAR L\<^isub>1 y"
|
|
354 |
have "y @ z \<in> L\<^isub>1\<star>"
|
|
355 |
proof(cases "x = []")
|
|
356 |
case True
|
|
357 |
with tag_xy have "y = []"
|
|
358 |
by (auto simp add: tag_str_STAR_def strict_prefix_def)
|
|
359 |
thus ?thesis using xz_in_star True by simp
|
|
360 |
next
|
|
361 |
case False
|
|
362 |
let ?S = "{xa. xa < x \<and> xa \<in> L\<^isub>1\<star> \<and> (x - xa) @ z \<in> L\<^isub>1\<star>}"
|
|
363 |
have "finite ?S"
|
|
364 |
by (rule_tac B = "{xa. xa < x}" in finite_subset,
|
|
365 |
auto simp:finite_strict_prefix_set)
|
|
366 |
moreover have "?S \<noteq> {}" using False xz_in_star
|
|
367 |
by (simp, rule_tac x = "[]" in exI, auto simp:strict_prefix_def)
|
|
368 |
ultimately have "\<exists> xa_max \<in> ?S. \<forall> xa \<in> ?S. length xa \<le> length xa_max"
|
|
369 |
using finite_set_has_max by blast
|
|
370 |
then obtain xa_max
|
|
371 |
where h1: "xa_max < x"
|
|
372 |
and h2: "xa_max \<in> L\<^isub>1\<star>"
|
|
373 |
and h3: "(x - xa_max) @ z \<in> L\<^isub>1\<star>"
|
|
374 |
and h4:"\<forall> xa < x. xa \<in> L\<^isub>1\<star> \<and> (x - xa) @ z \<in> L\<^isub>1\<star>
|
|
375 |
\<longrightarrow> length xa \<le> length xa_max"
|
|
376 |
by blast
|
|
377 |
obtain ya
|
|
378 |
where h5: "ya < y" and h6: "ya \<in> L\<^isub>1\<star>"
|
|
379 |
and eq_xya: "(x - xa_max) \<approx>L\<^isub>1 (y - ya)"
|
|
380 |
proof-
|
|
381 |
from tag_xy have "{\<approx>L\<^isub>1 `` {x - xa} |xa. xa < x \<and> xa \<in> L\<^isub>1\<star>} =
|
|
382 |
{\<approx>L\<^isub>1 `` {y - xa} |xa. xa < y \<and> xa \<in> L\<^isub>1\<star>}" (is "?left = ?right")
|
|
383 |
by (auto simp:tag_str_STAR_def)
|
|
384 |
moreover have "\<approx>L\<^isub>1 `` {x - xa_max} \<in> ?left" using h1 h2 by auto
|
|
385 |
ultimately have "\<approx>L\<^isub>1 `` {x - xa_max} \<in> ?right" by simp
|
|
386 |
thus ?thesis using that
|
|
387 |
apply (simp add:Image_def str_eq_rel_def str_eq_def) by blast
|
|
388 |
qed
|
|
389 |
have "(y - ya) @ z \<in> L\<^isub>1\<star>"
|
|
390 |
proof-
|
|
391 |
obtain za zb where eq_zab: "z = za @ zb"
|
|
392 |
and l_za: "(y - ya)@za \<in> L\<^isub>1" and ls_zb: "zb \<in> L\<^isub>1\<star>"
|
|
393 |
proof -
|
|
394 |
from h1 have "(x - xa_max) @ z \<noteq> []"
|
|
395 |
by (auto simp:strict_prefix_def elim:prefixE)
|
|
396 |
from star_decom [OF h3 this]
|
|
397 |
obtain a b where a_in: "a \<in> L\<^isub>1"
|
|
398 |
and a_neq: "a \<noteq> []" and b_in: "b \<in> L\<^isub>1\<star>"
|
|
399 |
and ab_max: "(x - xa_max) @ z = a @ b" by blast
|
|
400 |
let ?za = "a - (x - xa_max)" and ?zb = "b"
|
|
401 |
have pfx: "(x - xa_max) \<le> a" (is "?P1")
|
|
402 |
and eq_z: "z = ?za @ ?zb" (is "?P2")
|
|
403 |
proof -
|
|
404 |
have "((x - xa_max) \<le> a \<and> (a - (x - xa_max)) @ b = z) \<or>
|
|
405 |
(a < (x - xa_max) \<and> ((x - xa_max) - a) @ z = b)"
|
|
406 |
using append_eq_dest[OF ab_max] by (auto simp:strict_prefix_def)
|
|
407 |
moreover {
|
|
408 |
assume np: "a < (x - xa_max)"
|
|
409 |
and b_eqs: "((x - xa_max) - a) @ z = b"
|
|
410 |
have "False"
|
|
411 |
proof -
|
|
412 |
let ?xa_max' = "xa_max @ a"
|
|
413 |
have "?xa_max' < x"
|
|
414 |
using np h1 by (clarsimp simp:strict_prefix_def diff_prefix)
|
|
415 |
moreover have "?xa_max' \<in> L\<^isub>1\<star>"
|
|
416 |
using a_in h2 by (simp add:star_intro3)
|
|
417 |
moreover have "(x - ?xa_max') @ z \<in> L\<^isub>1\<star>"
|
|
418 |
using b_eqs b_in np h1 by (simp add:diff_diff_append)
|
|
419 |
moreover have "\<not> (length ?xa_max' \<le> length xa_max)"
|
|
420 |
using a_neq by simp
|
|
421 |
ultimately show ?thesis using h4 by blast
|
|
422 |
qed }
|
|
423 |
ultimately show ?P1 and ?P2 by auto
|
|
424 |
qed
|
|
425 |
hence "(x - xa_max)@?za \<in> L\<^isub>1" using a_in by (auto elim:prefixE)
|
|
426 |
with eq_xya have "(y - ya) @ ?za \<in> L\<^isub>1"
|
|
427 |
by (auto simp:str_eq_def str_eq_rel_def)
|
|
428 |
with eq_z and b_in
|
|
429 |
show ?thesis using that by blast
|
|
430 |
qed
|
|
431 |
have "((y - ya) @ za) @ zb \<in> L\<^isub>1\<star>" using l_za ls_zb by blast
|
|
432 |
with eq_zab show ?thesis by simp
|
|
433 |
qed
|
|
434 |
with h5 h6 show ?thesis
|
|
435 |
by (drule_tac star_intro1, auto simp:strict_prefix_def elim:prefixE)
|
|
436 |
qed
|
|
437 |
}
|
|
438 |
from this [OF _ eq_tag] and this [OF _ eq_tag [THEN sym]]
|
|
439 |
show ?thesis unfolding str_eq_def str_eq_rel_def by blast
|
|
440 |
qed
|
|
441 |
|
|
442 |
lemma quot_star_finiteI [intro]:
|
|
443 |
assumes finite1: "finite (UNIV // \<approx>L1)"
|
|
444 |
shows "finite (UNIV // \<approx>(L1\<star>))"
|
|
445 |
proof (rule_tac tag = "tag_str_STAR L1" in tag_finite_imageD)
|
|
446 |
show "\<And>x y. tag_str_STAR L1 x = tag_str_STAR L1 y \<Longrightarrow> x \<approx>(L1\<star>) y"
|
|
447 |
by (rule tag_str_STAR_injI)
|
|
448 |
next
|
|
449 |
have *: "finite (Pow (UNIV // \<approx>L1))"
|
|
450 |
using finite1 by auto
|
|
451 |
show "finite (range (tag_str_STAR L1))"
|
|
452 |
unfolding tag_str_STAR_def
|
|
453 |
apply(rule finite_subset[OF _ *])
|
|
454 |
unfolding quotient_def
|
|
455 |
by auto
|
|
456 |
qed
|
|
457 |
|
|
458 |
subsubsection{* The conclusion *}
|
|
459 |
|
|
460 |
lemma Myhill_Nerode2:
|
|
461 |
fixes r::"rexp"
|
|
462 |
shows "finite (UNIV // \<approx>(L r))"
|
|
463 |
by (induct r) (auto)
|
|
464 |
|
|
465 |
|
|
466 |
theorem Myhill_Nerode:
|
|
467 |
shows "(\<exists>r::rexp. A = L r) \<longleftrightarrow> finite (UNIV // \<approx>A)"
|
|
468 |
using Myhill_Nerode1 Myhill_Nerode2 by auto
|
|
469 |
|
|
470 |
end
|