63
|
1 |
theory Myhill_2
|
75
|
2 |
imports Myhill_1 List_Prefix Prefix_subtract
|
63
|
3 |
begin
|
|
4 |
|
|
5 |
section {* Direction @{text "regular language \<Rightarrow>finite partition"} *}
|
|
6 |
|
|
7 |
subsection {* The scheme*}
|
|
8 |
|
|
9 |
text {*
|
75
|
10 |
The following convenient notation @{text "x \<approx>A y"} means:
|
63
|
11 |
string @{text "x"} and @{text "y"} are equivalent with respect to
|
75
|
12 |
language @{text "A"}.
|
63
|
13 |
*}
|
|
14 |
|
|
15 |
definition
|
|
16 |
str_eq :: "string \<Rightarrow> lang \<Rightarrow> string \<Rightarrow> bool" ("_ \<approx>_ _")
|
|
17 |
where
|
75
|
18 |
"x \<approx>A y \<equiv> (x, y) \<in> (\<approx>A)"
|
63
|
19 |
|
|
20 |
text {*
|
109
|
21 |
The main lemma (@{text "rexp_imp_finite"}) is proved by a structural
|
|
22 |
induction over regular expressions. where base cases (cases for @{const
|
|
23 |
"NULL"}, @{const "EMPTY"}, @{const "CHAR"}) are quite straightforward to
|
|
24 |
proof. Real difficulty lies in inductive cases. By inductive hypothesis,
|
|
25 |
languages defined by sub-expressions induce finite partitiions. Under such
|
|
26 |
hypothsis, we need to prove that the language defined by the composite
|
|
27 |
regular expression gives rise to finite partion. The basic idea is to
|
|
28 |
attach a tag @{text "tag(x)"} to every string @{text "x"}. The tagging
|
|
29 |
fuction @{text "tag"} is carefully devised, which returns tags made of
|
|
30 |
equivalent classes of the partitions induced by subexpressoins, and
|
|
31 |
therefore has a finite range. Let @{text "Lang"} be the composite language,
|
|
32 |
it is proved that:
|
99
|
33 |
\begin{quote}
|
|
34 |
If strings with the same tag are equivalent with respect to @{text "Lang"}, expressed as:
|
63
|
35 |
\[
|
|
36 |
@{text "tag(x) = tag(y) \<Longrightarrow> x \<approx>Lang y"}
|
|
37 |
\]
|
99
|
38 |
then the partition induced by @{text "Lang"} must be finite.
|
|
39 |
\end{quote}
|
|
40 |
There are two arguments for this. The first goes as the following:
|
63
|
41 |
\begin{enumerate}
|
|
42 |
\item First, the tagging function @{text "tag"} induces an equivalent relation @{text "(=tag=)"}
|
|
43 |
(defiintion of @{text "f_eq_rel"} and lemma @{text "equiv_f_eq_rel"}).
|
|
44 |
\item It is shown that: if the range of @{text "tag"} (denoted @{text "range(tag)"}) is finite,
|
|
45 |
the partition given rise by @{text "(=tag=)"} is finite (lemma @{text "finite_eq_f_rel"}).
|
|
46 |
Since tags are made from equivalent classes from component partitions, and the inductive
|
|
47 |
hypothesis ensures the finiteness of these partitions, it is not difficult to prove
|
|
48 |
the finiteness of @{text "range(tag)"}.
|
|
49 |
\item It is proved that if equivalent relation @{text "R1"} is more refined than @{text "R2"}
|
|
50 |
(expressed as @{text "R1 \<subseteq> R2"}),
|
|
51 |
and the partition induced by @{text "R1"} is finite, then the partition induced by @{text "R2"}
|
|
52 |
is finite as well (lemma @{text "refined_partition_finite"}).
|
|
53 |
\item The injectivity assumption @{text "tag(x) = tag(y) \<Longrightarrow> x \<approx>Lang y"} implies that
|
|
54 |
@{text "(=tag=)"} is more refined than @{text "(\<approx>Lang)"}.
|
|
55 |
\item Combining the points above, we have: the partition induced by language @{text "Lang"}
|
|
56 |
is finite (lemma @{text "tag_finite_imageD"}).
|
|
57 |
\end{enumerate}
|
|
58 |
*}
|
|
59 |
|
|
60 |
definition
|
|
61 |
f_eq_rel ("=_=")
|
|
62 |
where
|
109
|
63 |
"=f= \<equiv> {(x, y) | x y. f x = f y}"
|
63
|
64 |
|
|
65 |
lemma equiv_f_eq_rel:"equiv UNIV (=f=)"
|
|
66 |
by (auto simp:equiv_def f_eq_rel_def refl_on_def sym_def trans_def)
|
|
67 |
|
109
|
68 |
lemma finite_range_image:
|
|
69 |
assumes "finite (range f)"
|
|
70 |
shows "finite (f ` A)"
|
|
71 |
using assms unfolding image_def
|
|
72 |
by (rule_tac finite_subset) (auto)
|
63
|
73 |
|
|
74 |
lemma finite_eq_f_rel:
|
|
75 |
assumes rng_fnt: "finite (range tag)"
|
109
|
76 |
shows "finite (UNIV // =tag=)"
|
63
|
77 |
proof -
|
109
|
78 |
let "?f" = "op ` tag" and ?A = "(UNIV // =tag=)"
|
63
|
79 |
show ?thesis
|
|
80 |
proof (rule_tac f = "?f" and A = ?A in finite_imageD)
|
|
81 |
-- {*
|
|
82 |
The finiteness of @{text "f"}-image is a simple consequence of assumption @{text "rng_fnt"}:
|
|
83 |
*}
|
|
84 |
show "finite (?f ` ?A)"
|
|
85 |
proof -
|
|
86 |
have "\<forall> X. ?f X \<in> (Pow (range tag))" by (auto simp:image_def Pow_def)
|
|
87 |
moreover from rng_fnt have "finite (Pow (range tag))" by simp
|
|
88 |
ultimately have "finite (range ?f)"
|
|
89 |
by (auto simp only:image_def intro:finite_subset)
|
|
90 |
from finite_range_image [OF this] show ?thesis .
|
|
91 |
qed
|
|
92 |
next
|
|
93 |
-- {*
|
|
94 |
The injectivity of @{text "f"}-image is a consequence of the definition of @{text "(=tag=)"}:
|
|
95 |
*}
|
|
96 |
show "inj_on ?f ?A"
|
|
97 |
proof-
|
|
98 |
{ fix X Y
|
|
99 |
assume X_in: "X \<in> ?A"
|
|
100 |
and Y_in: "Y \<in> ?A"
|
|
101 |
and tag_eq: "?f X = ?f Y"
|
|
102 |
have "X = Y"
|
|
103 |
proof -
|
|
104 |
from X_in Y_in tag_eq
|
|
105 |
obtain x y
|
|
106 |
where x_in: "x \<in> X" and y_in: "y \<in> Y" and eq_tg: "tag x = tag y"
|
|
107 |
unfolding quotient_def Image_def str_eq_rel_def
|
|
108 |
str_eq_def image_def f_eq_rel_def
|
|
109 |
apply simp by blast
|
|
110 |
with X_in Y_in show ?thesis
|
|
111 |
by (auto simp:quotient_def str_eq_rel_def str_eq_def f_eq_rel_def)
|
|
112 |
qed
|
|
113 |
} thus ?thesis unfolding inj_on_def by auto
|
|
114 |
qed
|
|
115 |
qed
|
|
116 |
qed
|
|
117 |
|
109
|
118 |
lemma finite_image_finite:
|
|
119 |
"\<lbrakk>\<forall> x \<in> A. f x \<in> B; finite B\<rbrakk> \<Longrightarrow> finite (f ` A)"
|
63
|
120 |
by (rule finite_subset [of _ B], auto)
|
|
121 |
|
|
122 |
lemma refined_partition_finite:
|
|
123 |
fixes R1 R2 A
|
|
124 |
assumes fnt: "finite (A // R1)"
|
|
125 |
and refined: "R1 \<subseteq> R2"
|
|
126 |
and eq1: "equiv A R1" and eq2: "equiv A R2"
|
|
127 |
shows "finite (A // R2)"
|
|
128 |
proof -
|
|
129 |
let ?f = "\<lambda> X. {R1 `` {x} | x. x \<in> X}"
|
|
130 |
and ?A = "(A // R2)" and ?B = "(A // R1)"
|
|
131 |
show ?thesis
|
|
132 |
proof(rule_tac f = ?f and A = ?A in finite_imageD)
|
|
133 |
show "finite (?f ` ?A)"
|
|
134 |
proof(rule finite_subset [of _ "Pow ?B"])
|
|
135 |
from fnt show "finite (Pow (A // R1))" by simp
|
|
136 |
next
|
|
137 |
from eq2
|
|
138 |
show " ?f ` A // R2 \<subseteq> Pow ?B"
|
|
139 |
unfolding image_def Pow_def quotient_def
|
|
140 |
apply auto
|
|
141 |
by (rule_tac x = xb in bexI, simp,
|
|
142 |
unfold equiv_def sym_def refl_on_def, blast)
|
|
143 |
qed
|
|
144 |
next
|
|
145 |
show "inj_on ?f ?A"
|
|
146 |
proof -
|
|
147 |
{ fix X Y
|
|
148 |
assume X_in: "X \<in> ?A" and Y_in: "Y \<in> ?A"
|
|
149 |
and eq_f: "?f X = ?f Y" (is "?L = ?R")
|
|
150 |
have "X = Y" using X_in
|
|
151 |
proof(rule quotientE)
|
|
152 |
fix x
|
|
153 |
assume "X = R2 `` {x}" and "x \<in> A" with eq2
|
|
154 |
have x_in: "x \<in> X"
|
|
155 |
unfolding equiv_def quotient_def refl_on_def by auto
|
|
156 |
with eq_f have "R1 `` {x} \<in> ?R" by auto
|
|
157 |
then obtain y where
|
|
158 |
y_in: "y \<in> Y" and eq_r: "R1 `` {x} = R1 ``{y}" by auto
|
|
159 |
have "(x, y) \<in> R1"
|
|
160 |
proof -
|
|
161 |
from x_in X_in y_in Y_in eq2
|
|
162 |
have "x \<in> A" and "y \<in> A"
|
|
163 |
unfolding equiv_def quotient_def refl_on_def by auto
|
|
164 |
from eq_equiv_class_iff [OF eq1 this] and eq_r
|
|
165 |
show ?thesis by simp
|
|
166 |
qed
|
|
167 |
with refined have xy_r2: "(x, y) \<in> R2" by auto
|
|
168 |
from quotient_eqI [OF eq2 X_in Y_in x_in y_in this]
|
|
169 |
show ?thesis .
|
|
170 |
qed
|
|
171 |
} thus ?thesis by (auto simp:inj_on_def)
|
|
172 |
qed
|
|
173 |
qed
|
|
174 |
qed
|
|
175 |
|
|
176 |
lemma equiv_lang_eq: "equiv UNIV (\<approx>Lang)"
|
|
177 |
unfolding equiv_def str_eq_rel_def sym_def refl_on_def trans_def
|
|
178 |
by blast
|
|
179 |
|
|
180 |
lemma tag_finite_imageD:
|
|
181 |
fixes tag
|
|
182 |
assumes rng_fnt: "finite (range tag)"
|
|
183 |
-- {* Suppose the rang of tagging fucntion @{text "tag"} is finite. *}
|
|
184 |
and same_tag_eqvt: "\<And> m n. tag m = tag (n::string) \<Longrightarrow> m \<approx>Lang n"
|
|
185 |
-- {* And strings with same tag are equivalent *}
|
|
186 |
shows "finite (UNIV // (\<approx>Lang))"
|
|
187 |
proof -
|
|
188 |
let ?R1 = "(=tag=)"
|
|
189 |
show ?thesis
|
|
190 |
proof(rule_tac refined_partition_finite [of _ ?R1])
|
|
191 |
from finite_eq_f_rel [OF rng_fnt]
|
|
192 |
show "finite (UNIV // =tag=)" .
|
|
193 |
next
|
|
194 |
from same_tag_eqvt
|
|
195 |
show "(=tag=) \<subseteq> (\<approx>Lang)"
|
|
196 |
by (auto simp:f_eq_rel_def str_eq_def)
|
|
197 |
next
|
|
198 |
from equiv_f_eq_rel
|
|
199 |
show "equiv UNIV (=tag=)" by blast
|
|
200 |
next
|
|
201 |
from equiv_lang_eq
|
|
202 |
show "equiv UNIV (\<approx>Lang)" by blast
|
|
203 |
qed
|
|
204 |
qed
|
|
205 |
|
|
206 |
text {*
|
|
207 |
A more concise, but less intelligible argument for @{text "tag_finite_imageD"}
|
|
208 |
is given as the following. The basic idea is still using standard library
|
|
209 |
lemma @{thm [source] "finite_imageD"}:
|
|
210 |
\[
|
|
211 |
@{thm "finite_imageD" [no_vars]}
|
|
212 |
\]
|
|
213 |
which says: if the image of injective function @{text "f"} over set @{text "A"} is
|
|
214 |
finite, then @{text "A"} must be finte, as we did in the lemmas above.
|
|
215 |
*}
|
|
216 |
|
|
217 |
lemma
|
|
218 |
fixes tag
|
|
219 |
assumes rng_fnt: "finite (range tag)"
|
|
220 |
-- {* Suppose the rang of tagging fucntion @{text "tag"} is finite. *}
|
|
221 |
and same_tag_eqvt: "\<And> m n. tag m = tag (n::string) \<Longrightarrow> m \<approx>Lang n"
|
|
222 |
-- {* And strings with same tag are equivalent *}
|
|
223 |
shows "finite (UNIV // (\<approx>Lang))"
|
|
224 |
-- {* Then the partition generated by @{text "(\<approx>Lang)"} is finite. *}
|
|
225 |
proof -
|
|
226 |
-- {* The particular @{text "f"} and @{text "A"} used in @{thm [source] "finite_imageD"} are:*}
|
|
227 |
let "?f" = "op ` tag" and ?A = "(UNIV // \<approx>Lang)"
|
|
228 |
show ?thesis
|
|
229 |
proof (rule_tac f = "?f" and A = ?A in finite_imageD)
|
|
230 |
-- {*
|
|
231 |
The finiteness of @{text "f"}-image is a simple consequence of assumption @{text "rng_fnt"}:
|
|
232 |
*}
|
|
233 |
show "finite (?f ` ?A)"
|
|
234 |
proof -
|
|
235 |
have "\<forall> X. ?f X \<in> (Pow (range tag))" by (auto simp:image_def Pow_def)
|
|
236 |
moreover from rng_fnt have "finite (Pow (range tag))" by simp
|
|
237 |
ultimately have "finite (range ?f)"
|
|
238 |
by (auto simp only:image_def intro:finite_subset)
|
|
239 |
from finite_range_image [OF this] show ?thesis .
|
|
240 |
qed
|
|
241 |
next
|
|
242 |
-- {*
|
|
243 |
The injectivity of @{text "f"} is the consequence of assumption @{text "same_tag_eqvt"}:
|
|
244 |
*}
|
|
245 |
show "inj_on ?f ?A"
|
|
246 |
proof-
|
|
247 |
{ fix X Y
|
|
248 |
assume X_in: "X \<in> ?A"
|
|
249 |
and Y_in: "Y \<in> ?A"
|
|
250 |
and tag_eq: "?f X = ?f Y"
|
|
251 |
have "X = Y"
|
|
252 |
proof -
|
|
253 |
from X_in Y_in tag_eq
|
|
254 |
obtain x y where x_in: "x \<in> X" and y_in: "y \<in> Y" and eq_tg: "tag x = tag y"
|
|
255 |
unfolding quotient_def Image_def str_eq_rel_def str_eq_def image_def
|
|
256 |
apply simp by blast
|
|
257 |
from same_tag_eqvt [OF eq_tg] have "x \<approx>Lang y" .
|
|
258 |
with X_in Y_in x_in y_in
|
|
259 |
show ?thesis by (auto simp:quotient_def str_eq_rel_def str_eq_def)
|
|
260 |
qed
|
|
261 |
} thus ?thesis unfolding inj_on_def by auto
|
|
262 |
qed
|
|
263 |
qed
|
|
264 |
qed
|
|
265 |
|
|
266 |
subsection {* The proof*}
|
|
267 |
|
|
268 |
text {*
|
|
269 |
Each case is given in a separate section, as well as the final main lemma. Detailed explainations accompanied by
|
|
270 |
illustrations are given for non-trivial cases.
|
|
271 |
|
|
272 |
For ever inductive case, there are two tasks, the easier one is to show the range finiteness of
|
|
273 |
of the tagging function based on the finiteness of component partitions, the
|
|
274 |
difficult one is to show that strings with the same tag are equivalent with respect to the
|
|
275 |
composite language. Suppose the composite language be @{text "Lang"}, tagging function be
|
|
276 |
@{text "tag"}, it amounts to show:
|
|
277 |
\[
|
|
278 |
@{text "tag(x) = tag(y) \<Longrightarrow> x \<approx>Lang y"}
|
|
279 |
\]
|
|
280 |
expanding the definition of @{text "\<approx>Lang"}, it amounts to show:
|
|
281 |
\[
|
|
282 |
@{text "tag(x) = tag(y) \<Longrightarrow> (\<forall> z. x@z \<in> Lang \<longleftrightarrow> y@z \<in> Lang)"}
|
|
283 |
\]
|
|
284 |
Because the assumed tag equlity @{text "tag(x) = tag(y)"} is symmetric,
|
|
285 |
it is suffcient to show just one direction:
|
|
286 |
\[
|
|
287 |
@{text "\<And> x y z. \<lbrakk>tag(x) = tag(y); x@z \<in> Lang\<rbrakk> \<Longrightarrow> y@z \<in> Lang"}
|
|
288 |
\]
|
|
289 |
This is the pattern followed by every inductive case.
|
|
290 |
*}
|
|
291 |
|
|
292 |
subsubsection {* The base case for @{const "NULL"} *}
|
|
293 |
|
|
294 |
lemma quot_null_eq:
|
|
295 |
shows "(UNIV // \<approx>{}) = ({UNIV}::lang set)"
|
|
296 |
unfolding quotient_def Image_def str_eq_rel_def by auto
|
|
297 |
|
|
298 |
lemma quot_null_finiteI [intro]:
|
|
299 |
shows "finite ((UNIV // \<approx>{})::lang set)"
|
|
300 |
unfolding quot_null_eq by simp
|
|
301 |
|
|
302 |
|
|
303 |
subsubsection {* The base case for @{const "EMPTY"} *}
|
|
304 |
|
|
305 |
|
|
306 |
lemma quot_empty_subset:
|
|
307 |
"UNIV // (\<approx>{[]}) \<subseteq> {{[]}, UNIV - {[]}}"
|
|
308 |
proof
|
|
309 |
fix x
|
|
310 |
assume "x \<in> UNIV // \<approx>{[]}"
|
|
311 |
then obtain y where h: "x = {z. (y, z) \<in> \<approx>{[]}}"
|
|
312 |
unfolding quotient_def Image_def by blast
|
|
313 |
show "x \<in> {{[]}, UNIV - {[]}}"
|
|
314 |
proof (cases "y = []")
|
|
315 |
case True with h
|
|
316 |
have "x = {[]}" by (auto simp: str_eq_rel_def)
|
|
317 |
thus ?thesis by simp
|
|
318 |
next
|
|
319 |
case False with h
|
|
320 |
have "x = UNIV - {[]}" by (auto simp: str_eq_rel_def)
|
|
321 |
thus ?thesis by simp
|
|
322 |
qed
|
|
323 |
qed
|
|
324 |
|
|
325 |
lemma quot_empty_finiteI [intro]:
|
|
326 |
shows "finite (UNIV // (\<approx>{[]}))"
|
|
327 |
by (rule finite_subset[OF quot_empty_subset]) (simp)
|
|
328 |
|
|
329 |
|
|
330 |
subsubsection {* The base case for @{const "CHAR"} *}
|
|
331 |
|
|
332 |
lemma quot_char_subset:
|
|
333 |
"UNIV // (\<approx>{[c]}) \<subseteq> {{[]},{[c]}, UNIV - {[], [c]}}"
|
|
334 |
proof
|
|
335 |
fix x
|
|
336 |
assume "x \<in> UNIV // \<approx>{[c]}"
|
|
337 |
then obtain y where h: "x = {z. (y, z) \<in> \<approx>{[c]}}"
|
|
338 |
unfolding quotient_def Image_def by blast
|
|
339 |
show "x \<in> {{[]},{[c]}, UNIV - {[], [c]}}"
|
|
340 |
proof -
|
|
341 |
{ assume "y = []" hence "x = {[]}" using h
|
|
342 |
by (auto simp:str_eq_rel_def)
|
|
343 |
} moreover {
|
|
344 |
assume "y = [c]" hence "x = {[c]}" using h
|
|
345 |
by (auto dest!:spec[where x = "[]"] simp:str_eq_rel_def)
|
|
346 |
} moreover {
|
|
347 |
assume "y \<noteq> []" and "y \<noteq> [c]"
|
|
348 |
hence "\<forall> z. (y @ z) \<noteq> [c]" by (case_tac y, auto)
|
|
349 |
moreover have "\<And> p. (p \<noteq> [] \<and> p \<noteq> [c]) = (\<forall> q. p @ q \<noteq> [c])"
|
|
350 |
by (case_tac p, auto)
|
|
351 |
ultimately have "x = UNIV - {[],[c]}" using h
|
|
352 |
by (auto simp add:str_eq_rel_def)
|
|
353 |
} ultimately show ?thesis by blast
|
|
354 |
qed
|
|
355 |
qed
|
|
356 |
|
|
357 |
lemma quot_char_finiteI [intro]:
|
|
358 |
shows "finite (UNIV // (\<approx>{[c]}))"
|
|
359 |
by (rule finite_subset[OF quot_char_subset]) (simp)
|
|
360 |
|
|
361 |
|
|
362 |
subsubsection {* The inductive case for @{const ALT} *}
|
|
363 |
|
|
364 |
definition
|
|
365 |
tag_str_ALT :: "lang \<Rightarrow> lang \<Rightarrow> string \<Rightarrow> (lang \<times> lang)"
|
|
366 |
where
|
109
|
367 |
"tag_str_ALT L1 L2 \<equiv> (\<lambda>x. (\<approx>L1 `` {x}, \<approx>L2 `` {x}))"
|
63
|
368 |
|
|
369 |
lemma quot_union_finiteI [intro]:
|
|
370 |
fixes L1 L2::"lang"
|
|
371 |
assumes finite1: "finite (UNIV // \<approx>L1)"
|
|
372 |
and finite2: "finite (UNIV // \<approx>L2)"
|
|
373 |
shows "finite (UNIV // \<approx>(L1 \<union> L2))"
|
|
374 |
proof (rule_tac tag = "tag_str_ALT L1 L2" in tag_finite_imageD)
|
|
375 |
show "\<And>x y. tag_str_ALT L1 L2 x = tag_str_ALT L1 L2 y \<Longrightarrow> x \<approx>(L1 \<union> L2) y"
|
|
376 |
unfolding tag_str_ALT_def
|
|
377 |
unfolding str_eq_def
|
|
378 |
unfolding Image_def
|
|
379 |
unfolding str_eq_rel_def
|
|
380 |
by auto
|
|
381 |
next
|
|
382 |
have *: "finite ((UNIV // \<approx>L1) \<times> (UNIV // \<approx>L2))"
|
|
383 |
using finite1 finite2 by auto
|
|
384 |
show "finite (range (tag_str_ALT L1 L2))"
|
|
385 |
unfolding tag_str_ALT_def
|
|
386 |
apply(rule finite_subset[OF _ *])
|
|
387 |
unfolding quotient_def
|
|
388 |
by auto
|
|
389 |
qed
|
|
390 |
|
|
391 |
subsubsection {* The inductive case for @{text "SEQ"}*}
|
|
392 |
|
|
393 |
text {*
|
|
394 |
For case @{const "SEQ"}, the language @{text "L"} is @{text "L\<^isub>1 ;; L\<^isub>2"}.
|
|
395 |
Given @{text "x @ z \<in> L\<^isub>1 ;; L\<^isub>2"}, according to the defintion of @{text " L\<^isub>1 ;; L\<^isub>2"},
|
|
396 |
string @{text "x @ z"} can be splitted with the prefix in @{text "L\<^isub>1"} and suffix in @{text "L\<^isub>2"}.
|
|
397 |
The split point can either be in @{text "x"} (as shown in Fig. \ref{seq_first_split}),
|
|
398 |
or in @{text "z"} (as shown in Fig. \ref{seq_snd_split}). Whichever way it goes, the structure
|
|
399 |
on @{text "x @ z"} cn be transfered faithfully onto @{text "y @ z"}
|
|
400 |
(as shown in Fig. \ref{seq_trans_first_split} and \ref{seq_trans_snd_split}) with the the help of the assumed
|
|
401 |
tag equality. The following tag function @{text "tag_str_SEQ"} is such designed to facilitate
|
|
402 |
such transfers and lemma @{text "tag_str_SEQ_injI"} formalizes the informal argument above. The details
|
|
403 |
of structure transfer will be given their.
|
|
404 |
\input{fig_seq}
|
|
405 |
|
|
406 |
*}
|
|
407 |
|
|
408 |
definition
|
|
409 |
tag_str_SEQ :: "lang \<Rightarrow> lang \<Rightarrow> string \<Rightarrow> (lang \<times> lang set)"
|
|
410 |
where
|
109
|
411 |
"tag_str_SEQ L1 L2 \<equiv>
|
63
|
412 |
(\<lambda>x. (\<approx>L1 `` {x}, {(\<approx>L2 `` {x - xa}) | xa. xa \<le> x \<and> xa \<in> L1}))"
|
|
413 |
|
|
414 |
text {* The following is a techical lemma which helps to split the @{text "x @ z \<in> L\<^isub>1 ;; L\<^isub>2"} mentioned above.*}
|
|
415 |
|
|
416 |
lemma append_seq_elim:
|
|
417 |
assumes "x @ y \<in> L\<^isub>1 ;; L\<^isub>2"
|
|
418 |
shows "(\<exists> xa \<le> x. xa \<in> L\<^isub>1 \<and> (x - xa) @ y \<in> L\<^isub>2) \<or>
|
|
419 |
(\<exists> ya \<le> y. (x @ ya) \<in> L\<^isub>1 \<and> (y - ya) \<in> L\<^isub>2)"
|
|
420 |
proof-
|
|
421 |
from assms obtain s\<^isub>1 s\<^isub>2
|
|
422 |
where eq_xys: "x @ y = s\<^isub>1 @ s\<^isub>2"
|
|
423 |
and in_seq: "s\<^isub>1 \<in> L\<^isub>1 \<and> s\<^isub>2 \<in> L\<^isub>2"
|
|
424 |
by (auto simp:Seq_def)
|
|
425 |
from app_eq_dest [OF eq_xys]
|
|
426 |
have
|
|
427 |
"(x \<le> s\<^isub>1 \<and> (s\<^isub>1 - x) @ s\<^isub>2 = y) \<or> (s\<^isub>1 \<le> x \<and> (x - s\<^isub>1) @ y = s\<^isub>2)"
|
|
428 |
(is "?Split1 \<or> ?Split2") .
|
|
429 |
moreover have "?Split1 \<Longrightarrow> \<exists> ya \<le> y. (x @ ya) \<in> L\<^isub>1 \<and> (y - ya) \<in> L\<^isub>2"
|
|
430 |
using in_seq by (rule_tac x = "s\<^isub>1 - x" in exI, auto elim:prefixE)
|
|
431 |
moreover have "?Split2 \<Longrightarrow> \<exists> xa \<le> x. xa \<in> L\<^isub>1 \<and> (x - xa) @ y \<in> L\<^isub>2"
|
|
432 |
using in_seq by (rule_tac x = s\<^isub>1 in exI, auto)
|
|
433 |
ultimately show ?thesis by blast
|
|
434 |
qed
|
|
435 |
|
|
436 |
|
|
437 |
lemma tag_str_SEQ_injI:
|
|
438 |
fixes v w
|
|
439 |
assumes eq_tag: "tag_str_SEQ L\<^isub>1 L\<^isub>2 v = tag_str_SEQ L\<^isub>1 L\<^isub>2 w"
|
|
440 |
shows "v \<approx>(L\<^isub>1 ;; L\<^isub>2) w"
|
|
441 |
proof-
|
|
442 |
-- {* As explained before, a pattern for just one direction needs to be dealt with:*}
|
|
443 |
{ fix x y z
|
|
444 |
assume xz_in_seq: "x @ z \<in> L\<^isub>1 ;; L\<^isub>2"
|
|
445 |
and tag_xy: "tag_str_SEQ L\<^isub>1 L\<^isub>2 x = tag_str_SEQ L\<^isub>1 L\<^isub>2 y"
|
|
446 |
have"y @ z \<in> L\<^isub>1 ;; L\<^isub>2"
|
|
447 |
proof-
|
|
448 |
-- {* There are two ways to split @{text "x@z"}: *}
|
|
449 |
from append_seq_elim [OF xz_in_seq]
|
|
450 |
have "(\<exists> xa \<le> x. xa \<in> L\<^isub>1 \<and> (x - xa) @ z \<in> L\<^isub>2) \<or>
|
|
451 |
(\<exists> za \<le> z. (x @ za) \<in> L\<^isub>1 \<and> (z - za) \<in> L\<^isub>2)" .
|
|
452 |
-- {* It can be shown that @{text "?thesis"} holds in either case: *}
|
|
453 |
moreover {
|
|
454 |
-- {* The case for the first split:*}
|
|
455 |
fix xa
|
|
456 |
assume h1: "xa \<le> x" and h2: "xa \<in> L\<^isub>1" and h3: "(x - xa) @ z \<in> L\<^isub>2"
|
|
457 |
-- {* The following subgoal implements the structure transfer:*}
|
|
458 |
obtain ya
|
|
459 |
where "ya \<le> y"
|
|
460 |
and "ya \<in> L\<^isub>1"
|
|
461 |
and "(y - ya) @ z \<in> L\<^isub>2"
|
|
462 |
proof -
|
|
463 |
-- {*
|
|
464 |
\begin{minipage}{0.8\textwidth}
|
|
465 |
By expanding the definition of
|
|
466 |
@{thm [display] "tag_xy"}
|
|
467 |
and extracting the second compoent, we get:
|
|
468 |
\end{minipage}
|
|
469 |
*}
|
|
470 |
have "{\<approx>L\<^isub>2 `` {x - xa} |xa. xa \<le> x \<and> xa \<in> L\<^isub>1} =
|
|
471 |
{\<approx>L\<^isub>2 `` {y - ya} |ya. ya \<le> y \<and> ya \<in> L\<^isub>1}" (is "?Left = ?Right")
|
|
472 |
using tag_xy unfolding tag_str_SEQ_def by simp
|
|
473 |
-- {* Since @{thm "h1"} and @{thm "h2"} hold, it is not difficult to show: *}
|
|
474 |
moreover have "\<approx>L\<^isub>2 `` {x - xa} \<in> ?Left" using h1 h2 by auto
|
|
475 |
-- {*
|
|
476 |
\begin{minipage}{0.7\textwidth}
|
|
477 |
Through tag equality, equivalent class @{term "\<approx>L\<^isub>2 `` {x - xa}"} also
|
|
478 |
belongs to the @{text "?Right"}:
|
|
479 |
\end{minipage}
|
|
480 |
*}
|
|
481 |
ultimately have "\<approx>L\<^isub>2 `` {x - xa} \<in> ?Right" by simp
|
|
482 |
-- {* From this, the counterpart of @{text "xa"} in @{text "y"} is obtained:*}
|
|
483 |
then obtain ya
|
|
484 |
where eq_xya: "\<approx>L\<^isub>2 `` {x - xa} = \<approx>L\<^isub>2 `` {y - ya}"
|
|
485 |
and pref_ya: "ya \<le> y" and ya_in: "ya \<in> L\<^isub>1"
|
|
486 |
by simp blast
|
|
487 |
-- {* It can be proved that @{text "ya"} has the desired property:*}
|
|
488 |
have "(y - ya)@z \<in> L\<^isub>2"
|
|
489 |
proof -
|
|
490 |
from eq_xya have "(x - xa) \<approx>L\<^isub>2 (y - ya)"
|
|
491 |
unfolding Image_def str_eq_rel_def str_eq_def by auto
|
|
492 |
with h3 show ?thesis unfolding str_eq_rel_def str_eq_def by simp
|
|
493 |
qed
|
|
494 |
-- {* Now, @{text "ya"} has all properties to be a qualified candidate:*}
|
|
495 |
with pref_ya ya_in
|
|
496 |
show ?thesis using that by blast
|
|
497 |
qed
|
|
498 |
-- {* From the properties of @{text "ya"}, @{text "y @ z \<in> L\<^isub>1 ;; L\<^isub>2"} is derived easily.*}
|
|
499 |
hence "y @ z \<in> L\<^isub>1 ;; L\<^isub>2" by (erule_tac prefixE, auto simp:Seq_def)
|
|
500 |
} moreover {
|
|
501 |
-- {* The other case is even more simpler: *}
|
|
502 |
fix za
|
|
503 |
assume h1: "za \<le> z" and h2: "(x @ za) \<in> L\<^isub>1" and h3: "z - za \<in> L\<^isub>2"
|
|
504 |
have "y @ za \<in> L\<^isub>1"
|
|
505 |
proof-
|
|
506 |
have "\<approx>L\<^isub>1 `` {x} = \<approx>L\<^isub>1 `` {y}"
|
|
507 |
using tag_xy unfolding tag_str_SEQ_def by simp
|
|
508 |
with h2 show ?thesis
|
|
509 |
unfolding Image_def str_eq_rel_def str_eq_def by auto
|
|
510 |
qed
|
|
511 |
with h1 h3 have "y @ z \<in> L\<^isub>1 ;; L\<^isub>2"
|
|
512 |
by (drule_tac A = L\<^isub>1 in seq_intro, auto elim:prefixE)
|
|
513 |
}
|
|
514 |
ultimately show ?thesis by blast
|
|
515 |
qed
|
|
516 |
}
|
|
517 |
-- {*
|
|
518 |
\begin{minipage}{0.8\textwidth}
|
|
519 |
@{text "?thesis"} is proved by exploiting the symmetry of
|
|
520 |
@{thm [source] "eq_tag"}:
|
|
521 |
\end{minipage}
|
|
522 |
*}
|
|
523 |
from this [OF _ eq_tag] and this [OF _ eq_tag [THEN sym]]
|
|
524 |
show ?thesis unfolding str_eq_def str_eq_rel_def by blast
|
|
525 |
qed
|
|
526 |
|
|
527 |
lemma quot_seq_finiteI [intro]:
|
|
528 |
fixes L1 L2::"lang"
|
|
529 |
assumes fin1: "finite (UNIV // \<approx>L1)"
|
|
530 |
and fin2: "finite (UNIV // \<approx>L2)"
|
|
531 |
shows "finite (UNIV // \<approx>(L1 ;; L2))"
|
|
532 |
proof (rule_tac tag = "tag_str_SEQ L1 L2" in tag_finite_imageD)
|
|
533 |
show "\<And>x y. tag_str_SEQ L1 L2 x = tag_str_SEQ L1 L2 y \<Longrightarrow> x \<approx>(L1 ;; L2) y"
|
|
534 |
by (rule tag_str_SEQ_injI)
|
|
535 |
next
|
|
536 |
have *: "finite ((UNIV // \<approx>L1) \<times> (Pow (UNIV // \<approx>L2)))"
|
|
537 |
using fin1 fin2 by auto
|
|
538 |
show "finite (range (tag_str_SEQ L1 L2))"
|
|
539 |
unfolding tag_str_SEQ_def
|
|
540 |
apply(rule finite_subset[OF _ *])
|
|
541 |
unfolding quotient_def
|
|
542 |
by auto
|
|
543 |
qed
|
|
544 |
|
|
545 |
subsubsection {* The inductive case for @{const "STAR"} *}
|
|
546 |
|
|
547 |
text {*
|
|
548 |
This turned out to be the trickiest case. The essential goal is
|
|
549 |
to proved @{text "y @ z \<in> L\<^isub>1*"} under the assumptions that @{text "x @ z \<in> L\<^isub>1*"}
|
|
550 |
and that @{text "x"} and @{text "y"} have the same tag. The reasoning goes as the following:
|
|
551 |
\begin{enumerate}
|
|
552 |
\item Since @{text "x @ z \<in> L\<^isub>1*"} holds, a prefix @{text "xa"} of @{text "x"} can be found
|
|
553 |
such that @{text "xa \<in> L\<^isub>1*"} and @{text "(x - xa)@z \<in> L\<^isub>1*"}, as shown in Fig. \ref{first_split}.
|
|
554 |
Such a prefix always exists, @{text "xa = []"}, for example, is one.
|
|
555 |
\item There could be many but fintie many of such @{text "xa"}, from which we can find the longest
|
|
556 |
and name it @{text "xa_max"}, as shown in Fig. \ref{max_split}.
|
|
557 |
\item The next step is to split @{text "z"} into @{text "za"} and @{text "zb"} such that
|
|
558 |
@{text "(x - xa_max) @ za \<in> L\<^isub>1"} and @{text "zb \<in> L\<^isub>1*"} as shown in Fig. \ref{last_split}.
|
|
559 |
Such a split always exists because:
|
|
560 |
\begin{enumerate}
|
|
561 |
\item Because @{text "(x - x_max) @ z \<in> L\<^isub>1*"}, it can always be splitted into prefix @{text "a"}
|
|
562 |
and suffix @{text "b"}, such that @{text "a \<in> L\<^isub>1"} and @{text "b \<in> L\<^isub>1*"},
|
|
563 |
as shown in Fig. \ref{ab_split}.
|
|
564 |
\item But the prefix @{text "a"} CANNOT be shorter than @{text "x - xa_max"}
|
|
565 |
(as shown in Fig. \ref{ab_split_wrong}), becasue otherwise,
|
|
566 |
@{text "ma_max@a"} would be in the same kind as @{text "xa_max"} but with
|
|
567 |
a larger size, conflicting with the fact that @{text "xa_max"} is the longest.
|
|
568 |
\end{enumerate}
|
|
569 |
\item \label{tansfer_step}
|
|
570 |
By the assumption that @{text "x"} and @{text "y"} have the same tag, the structure on @{text "x @ z"}
|
|
571 |
can be transferred to @{text "y @ z"} as shown in Fig. \ref{trans_split}. The detailed steps are:
|
|
572 |
\begin{enumerate}
|
|
573 |
\item A @{text "y"}-prefix @{text "ya"} corresponding to @{text "xa"} can be found,
|
|
574 |
which satisfies conditions: @{text "ya \<in> L\<^isub>1*"} and @{text "(y - ya)@za \<in> L\<^isub>1"}.
|
|
575 |
\item Since we already know @{text "zb \<in> L\<^isub>1*"}, we get @{text "(y - ya)@za@zb \<in> L\<^isub>1*"},
|
|
576 |
and this is just @{text "(y - ya)@z \<in> L\<^isub>1*"}.
|
|
577 |
\item With fact @{text "ya \<in> L\<^isub>1*"}, we finally get @{text "y@z \<in> L\<^isub>1*"}.
|
|
578 |
\end{enumerate}
|
|
579 |
\end{enumerate}
|
|
580 |
|
|
581 |
The formal proof of lemma @{text "tag_str_STAR_injI"} faithfully follows this informal argument
|
|
582 |
while the tagging function @{text "tag_str_STAR"} is defined to make the transfer in step
|
|
583 |
\ref{ansfer_step} feasible.
|
|
584 |
|
|
585 |
\input{fig_star}
|
|
586 |
*}
|
|
587 |
|
|
588 |
definition
|
|
589 |
tag_str_STAR :: "lang \<Rightarrow> string \<Rightarrow> lang set"
|
|
590 |
where
|
109
|
591 |
"tag_str_STAR L1 \<equiv> (\<lambda>x. {\<approx>L1 `` {x - xa} | xa. xa < x \<and> xa \<in> L1\<star>})"
|
63
|
592 |
|
|
593 |
text {* A technical lemma. *}
|
|
594 |
lemma finite_set_has_max: "\<lbrakk>finite A; A \<noteq> {}\<rbrakk> \<Longrightarrow>
|
|
595 |
(\<exists> max \<in> A. \<forall> a \<in> A. f a <= (f max :: nat))"
|
|
596 |
proof (induct rule:finite.induct)
|
|
597 |
case emptyI thus ?case by simp
|
|
598 |
next
|
|
599 |
case (insertI A a)
|
|
600 |
show ?case
|
|
601 |
proof (cases "A = {}")
|
|
602 |
case True thus ?thesis by (rule_tac x = a in bexI, auto)
|
|
603 |
next
|
|
604 |
case False
|
|
605 |
with insertI.hyps and False
|
|
606 |
obtain max
|
|
607 |
where h1: "max \<in> A"
|
|
608 |
and h2: "\<forall>a\<in>A. f a \<le> f max" by blast
|
|
609 |
show ?thesis
|
|
610 |
proof (cases "f a \<le> f max")
|
|
611 |
assume "f a \<le> f max"
|
|
612 |
with h1 h2 show ?thesis by (rule_tac x = max in bexI, auto)
|
|
613 |
next
|
|
614 |
assume "\<not> (f a \<le> f max)"
|
|
615 |
thus ?thesis using h2 by (rule_tac x = a in bexI, auto)
|
|
616 |
qed
|
|
617 |
qed
|
|
618 |
qed
|
|
619 |
|
|
620 |
|
|
621 |
text {* The following is a technical lemma.which helps to show the range finiteness of tag function. *}
|
|
622 |
lemma finite_strict_prefix_set: "finite {xa. xa < (x::string)}"
|
|
623 |
apply (induct x rule:rev_induct, simp)
|
|
624 |
apply (subgoal_tac "{xa. xa < xs @ [x]} = {xa. xa < xs} \<union> {xs}")
|
|
625 |
by (auto simp:strict_prefix_def)
|
|
626 |
|
|
627 |
|
|
628 |
lemma tag_str_STAR_injI:
|
|
629 |
fixes v w
|
|
630 |
assumes eq_tag: "tag_str_STAR L\<^isub>1 v = tag_str_STAR L\<^isub>1 w"
|
|
631 |
shows "(v::string) \<approx>(L\<^isub>1\<star>) w"
|
|
632 |
proof-
|
|
633 |
-- {* As explained before, a pattern for just one direction needs to be dealt with:*}
|
|
634 |
{ fix x y z
|
|
635 |
assume xz_in_star: "x @ z \<in> L\<^isub>1\<star>"
|
|
636 |
and tag_xy: "tag_str_STAR L\<^isub>1 x = tag_str_STAR L\<^isub>1 y"
|
|
637 |
have "y @ z \<in> L\<^isub>1\<star>"
|
|
638 |
proof(cases "x = []")
|
|
639 |
-- {*
|
|
640 |
The degenerated case when @{text "x"} is a null string is easy to prove:
|
|
641 |
*}
|
|
642 |
case True
|
|
643 |
with tag_xy have "y = []"
|
|
644 |
by (auto simp add: tag_str_STAR_def strict_prefix_def)
|
|
645 |
thus ?thesis using xz_in_star True by simp
|
|
646 |
next
|
|
647 |
-- {* The nontrival case:
|
|
648 |
*}
|
|
649 |
case False
|
|
650 |
-- {*
|
|
651 |
\begin{minipage}{0.8\textwidth}
|
|
652 |
Since @{text "x @ z \<in> L\<^isub>1\<star>"}, @{text "x"} can always be splitted
|
|
653 |
by a prefix @{text "xa"} together with its suffix @{text "x - xa"}, such
|
|
654 |
that both @{text "xa"} and @{text "(x - xa) @ z"} are in @{text "L\<^isub>1\<star>"},
|
|
655 |
and there could be many such splittings.Therefore, the following set @{text "?S"}
|
|
656 |
is nonempty, and finite as well:
|
|
657 |
\end{minipage}
|
|
658 |
*}
|
|
659 |
let ?S = "{xa. xa < x \<and> xa \<in> L\<^isub>1\<star> \<and> (x - xa) @ z \<in> L\<^isub>1\<star>}"
|
|
660 |
have "finite ?S"
|
|
661 |
by (rule_tac B = "{xa. xa < x}" in finite_subset,
|
|
662 |
auto simp:finite_strict_prefix_set)
|
|
663 |
moreover have "?S \<noteq> {}" using False xz_in_star
|
|
664 |
by (simp, rule_tac x = "[]" in exI, auto simp:strict_prefix_def)
|
|
665 |
-- {* \begin{minipage}{0.7\textwidth}
|
|
666 |
Since @{text "?S"} is finite, we can always single out the longest and name it @{text "xa_max"}:
|
|
667 |
\end{minipage}
|
|
668 |
*}
|
|
669 |
ultimately have "\<exists> xa_max \<in> ?S. \<forall> xa \<in> ?S. length xa \<le> length xa_max"
|
|
670 |
using finite_set_has_max by blast
|
|
671 |
then obtain xa_max
|
|
672 |
where h1: "xa_max < x"
|
|
673 |
and h2: "xa_max \<in> L\<^isub>1\<star>"
|
|
674 |
and h3: "(x - xa_max) @ z \<in> L\<^isub>1\<star>"
|
|
675 |
and h4:"\<forall> xa < x. xa \<in> L\<^isub>1\<star> \<and> (x - xa) @ z \<in> L\<^isub>1\<star>
|
|
676 |
\<longrightarrow> length xa \<le> length xa_max"
|
|
677 |
by blast
|
|
678 |
-- {*
|
|
679 |
\begin{minipage}{0.8\textwidth}
|
|
680 |
By the equality of tags, the counterpart of @{text "xa_max"} among
|
|
681 |
@{text "y"}-prefixes, named @{text "ya"}, can be found:
|
|
682 |
\end{minipage}
|
|
683 |
*}
|
|
684 |
obtain ya
|
|
685 |
where h5: "ya < y" and h6: "ya \<in> L\<^isub>1\<star>"
|
|
686 |
and eq_xya: "(x - xa_max) \<approx>L\<^isub>1 (y - ya)"
|
|
687 |
proof-
|
|
688 |
from tag_xy have "{\<approx>L\<^isub>1 `` {x - xa} |xa. xa < x \<and> xa \<in> L\<^isub>1\<star>} =
|
|
689 |
{\<approx>L\<^isub>1 `` {y - xa} |xa. xa < y \<and> xa \<in> L\<^isub>1\<star>}" (is "?left = ?right")
|
|
690 |
by (auto simp:tag_str_STAR_def)
|
|
691 |
moreover have "\<approx>L\<^isub>1 `` {x - xa_max} \<in> ?left" using h1 h2 by auto
|
|
692 |
ultimately have "\<approx>L\<^isub>1 `` {x - xa_max} \<in> ?right" by simp
|
|
693 |
thus ?thesis using that
|
|
694 |
apply (simp add:Image_def str_eq_rel_def str_eq_def) by blast
|
|
695 |
qed
|
|
696 |
-- {*
|
|
697 |
\begin{minipage}{0.8\textwidth}
|
|
698 |
The @{text "?thesis"}, @{prop "y @ z \<in> L\<^isub>1\<star>"}, is a simple consequence
|
|
699 |
of the following proposition:
|
|
700 |
\end{minipage}
|
|
701 |
*}
|
|
702 |
have "(y - ya) @ z \<in> L\<^isub>1\<star>"
|
|
703 |
proof-
|
|
704 |
-- {* The idea is to split the suffix @{text "z"} into @{text "za"} and @{text "zb"},
|
|
705 |
such that: *}
|
|
706 |
obtain za zb where eq_zab: "z = za @ zb"
|
|
707 |
and l_za: "(y - ya)@za \<in> L\<^isub>1" and ls_zb: "zb \<in> L\<^isub>1\<star>"
|
|
708 |
proof -
|
|
709 |
-- {*
|
|
710 |
\begin{minipage}{0.8\textwidth}
|
|
711 |
Since @{thm "h1"}, @{text "x"} can be splitted into
|
|
712 |
@{text "a"} and @{text "b"} such that:
|
|
713 |
\end{minipage}
|
|
714 |
*}
|
|
715 |
from h1 have "(x - xa_max) @ z \<noteq> []"
|
|
716 |
by (auto simp:strict_prefix_def elim:prefixE)
|
|
717 |
from star_decom [OF h3 this]
|
|
718 |
obtain a b where a_in: "a \<in> L\<^isub>1"
|
|
719 |
and a_neq: "a \<noteq> []" and b_in: "b \<in> L\<^isub>1\<star>"
|
|
720 |
and ab_max: "(x - xa_max) @ z = a @ b" by blast
|
|
721 |
-- {* Now the candiates for @{text "za"} and @{text "zb"} are found:*}
|
|
722 |
let ?za = "a - (x - xa_max)" and ?zb = "b"
|
|
723 |
have pfx: "(x - xa_max) \<le> a" (is "?P1")
|
|
724 |
and eq_z: "z = ?za @ ?zb" (is "?P2")
|
|
725 |
proof -
|
|
726 |
-- {*
|
|
727 |
\begin{minipage}{0.8\textwidth}
|
|
728 |
Since @{text "(x - xa_max) @ z = a @ b"}, string @{text "(x - xa_max) @ z"}
|
|
729 |
can be splitted in two ways:
|
|
730 |
\end{minipage}
|
|
731 |
*}
|
|
732 |
have "((x - xa_max) \<le> a \<and> (a - (x - xa_max)) @ b = z) \<or>
|
|
733 |
(a < (x - xa_max) \<and> ((x - xa_max) - a) @ z = b)"
|
|
734 |
using app_eq_dest[OF ab_max] by (auto simp:strict_prefix_def)
|
|
735 |
moreover {
|
|
736 |
-- {* However, the undsired way can be refuted by absurdity: *}
|
|
737 |
assume np: "a < (x - xa_max)"
|
|
738 |
and b_eqs: "((x - xa_max) - a) @ z = b"
|
|
739 |
have "False"
|
|
740 |
proof -
|
|
741 |
let ?xa_max' = "xa_max @ a"
|
|
742 |
have "?xa_max' < x"
|
|
743 |
using np h1 by (clarsimp simp:strict_prefix_def diff_prefix)
|
|
744 |
moreover have "?xa_max' \<in> L\<^isub>1\<star>"
|
|
745 |
using a_in h2 by (simp add:star_intro3)
|
|
746 |
moreover have "(x - ?xa_max') @ z \<in> L\<^isub>1\<star>"
|
|
747 |
using b_eqs b_in np h1 by (simp add:diff_diff_appd)
|
|
748 |
moreover have "\<not> (length ?xa_max' \<le> length xa_max)"
|
|
749 |
using a_neq by simp
|
|
750 |
ultimately show ?thesis using h4 by blast
|
|
751 |
qed }
|
|
752 |
-- {* Now it can be shown that the splitting goes the way we desired. *}
|
|
753 |
ultimately show ?P1 and ?P2 by auto
|
|
754 |
qed
|
|
755 |
hence "(x - xa_max)@?za \<in> L\<^isub>1" using a_in by (auto elim:prefixE)
|
|
756 |
-- {* Now candidates @{text "?za"} and @{text "?zb"} have all the requred properteis. *}
|
|
757 |
with eq_xya have "(y - ya) @ ?za \<in> L\<^isub>1"
|
|
758 |
by (auto simp:str_eq_def str_eq_rel_def)
|
|
759 |
with eq_z and b_in
|
|
760 |
show ?thesis using that by blast
|
|
761 |
qed
|
|
762 |
-- {*
|
|
763 |
@{text "?thesis"} can easily be shown using properties of @{text "za"} and @{text "zb"}:
|
|
764 |
*}
|
|
765 |
have "((y - ya) @ za) @ zb \<in> L\<^isub>1\<star>" using l_za ls_zb by blast
|
|
766 |
with eq_zab show ?thesis by simp
|
|
767 |
qed
|
|
768 |
with h5 h6 show ?thesis
|
|
769 |
by (drule_tac star_intro1, auto simp:strict_prefix_def elim:prefixE)
|
|
770 |
qed
|
|
771 |
}
|
|
772 |
-- {* By instantiating the reasoning pattern just derived for both directions:*}
|
|
773 |
from this [OF _ eq_tag] and this [OF _ eq_tag [THEN sym]]
|
|
774 |
-- {* The thesis is proved as a trival consequence: *}
|
|
775 |
show ?thesis unfolding str_eq_def str_eq_rel_def by blast
|
|
776 |
qed
|
|
777 |
|
|
778 |
lemma -- {* The oringal version with less explicit details. *}
|
|
779 |
fixes v w
|
|
780 |
assumes eq_tag: "tag_str_STAR L\<^isub>1 v = tag_str_STAR L\<^isub>1 w"
|
|
781 |
shows "(v::string) \<approx>(L\<^isub>1\<star>) w"
|
|
782 |
proof-
|
|
783 |
-- {*
|
|
784 |
\begin{minipage}{0.8\textwidth}
|
|
785 |
According to the definition of @{text "\<approx>Lang"},
|
|
786 |
proving @{text "v \<approx>(L\<^isub>1\<star>) w"} amounts to
|
|
787 |
showing: for any string @{text "u"},
|
|
788 |
if @{text "v @ u \<in> (L\<^isub>1\<star>)"} then @{text "w @ u \<in> (L\<^isub>1\<star>)"} and vice versa.
|
|
789 |
The reasoning pattern for both directions are the same, as derived
|
|
790 |
in the following:
|
|
791 |
\end{minipage}
|
|
792 |
*}
|
|
793 |
{ fix x y z
|
|
794 |
assume xz_in_star: "x @ z \<in> L\<^isub>1\<star>"
|
|
795 |
and tag_xy: "tag_str_STAR L\<^isub>1 x = tag_str_STAR L\<^isub>1 y"
|
|
796 |
have "y @ z \<in> L\<^isub>1\<star>"
|
|
797 |
proof(cases "x = []")
|
|
798 |
-- {*
|
|
799 |
The degenerated case when @{text "x"} is a null string is easy to prove:
|
|
800 |
*}
|
|
801 |
case True
|
|
802 |
with tag_xy have "y = []"
|
|
803 |
by (auto simp:tag_str_STAR_def strict_prefix_def)
|
|
804 |
thus ?thesis using xz_in_star True by simp
|
|
805 |
next
|
|
806 |
-- {*
|
|
807 |
\begin{minipage}{0.8\textwidth}
|
|
808 |
The case when @{text "x"} is not null, and
|
|
809 |
@{text "x @ z"} is in @{text "L\<^isub>1\<star>"},
|
|
810 |
\end{minipage}
|
|
811 |
*}
|
|
812 |
case False
|
|
813 |
obtain x_max
|
|
814 |
where h1: "x_max < x"
|
|
815 |
and h2: "x_max \<in> L\<^isub>1\<star>"
|
|
816 |
and h3: "(x - x_max) @ z \<in> L\<^isub>1\<star>"
|
|
817 |
and h4:"\<forall> xa < x. xa \<in> L\<^isub>1\<star> \<and> (x - xa) @ z \<in> L\<^isub>1\<star>
|
|
818 |
\<longrightarrow> length xa \<le> length x_max"
|
|
819 |
proof-
|
|
820 |
let ?S = "{xa. xa < x \<and> xa \<in> L\<^isub>1\<star> \<and> (x - xa) @ z \<in> L\<^isub>1\<star>}"
|
|
821 |
have "finite ?S"
|
|
822 |
by (rule_tac B = "{xa. xa < x}" in finite_subset,
|
|
823 |
auto simp:finite_strict_prefix_set)
|
|
824 |
moreover have "?S \<noteq> {}" using False xz_in_star
|
|
825 |
by (simp, rule_tac x = "[]" in exI, auto simp:strict_prefix_def)
|
|
826 |
ultimately have "\<exists> max \<in> ?S. \<forall> a \<in> ?S. length a \<le> length max"
|
|
827 |
using finite_set_has_max by blast
|
|
828 |
thus ?thesis using that by blast
|
|
829 |
qed
|
|
830 |
obtain ya
|
|
831 |
where h5: "ya < y" and h6: "ya \<in> L\<^isub>1\<star>" and h7: "(x - x_max) \<approx>L\<^isub>1 (y - ya)"
|
|
832 |
proof-
|
|
833 |
from tag_xy have "{\<approx>L\<^isub>1 `` {x - xa} |xa. xa < x \<and> xa \<in> L\<^isub>1\<star>} =
|
|
834 |
{\<approx>L\<^isub>1 `` {y - xa} |xa. xa < y \<and> xa \<in> L\<^isub>1\<star>}" (is "?left = ?right")
|
|
835 |
by (auto simp:tag_str_STAR_def)
|
|
836 |
moreover have "\<approx>L\<^isub>1 `` {x - x_max} \<in> ?left" using h1 h2 by auto
|
|
837 |
ultimately have "\<approx>L\<^isub>1 `` {x - x_max} \<in> ?right" by simp
|
|
838 |
with that show ?thesis apply
|
|
839 |
(simp add:Image_def str_eq_rel_def str_eq_def) by blast
|
|
840 |
qed
|
|
841 |
have "(y - ya) @ z \<in> L\<^isub>1\<star>"
|
|
842 |
proof-
|
|
843 |
from h3 h1 obtain a b where a_in: "a \<in> L\<^isub>1"
|
|
844 |
and a_neq: "a \<noteq> []" and b_in: "b \<in> L\<^isub>1\<star>"
|
|
845 |
and ab_max: "(x - x_max) @ z = a @ b"
|
|
846 |
by (drule_tac star_decom, auto simp:strict_prefix_def elim:prefixE)
|
|
847 |
have "(x - x_max) \<le> a \<and> (a - (x - x_max)) @ b = z"
|
|
848 |
proof -
|
|
849 |
have "((x - x_max) \<le> a \<and> (a - (x - x_max)) @ b = z) \<or>
|
|
850 |
(a < (x - x_max) \<and> ((x - x_max) - a) @ z = b)"
|
|
851 |
using app_eq_dest[OF ab_max] by (auto simp:strict_prefix_def)
|
|
852 |
moreover {
|
|
853 |
assume np: "a < (x - x_max)" and b_eqs: " ((x - x_max) - a) @ z = b"
|
|
854 |
have "False"
|
|
855 |
proof -
|
|
856 |
let ?x_max' = "x_max @ a"
|
|
857 |
have "?x_max' < x"
|
|
858 |
using np h1 by (clarsimp simp:strict_prefix_def diff_prefix)
|
|
859 |
moreover have "?x_max' \<in> L\<^isub>1\<star>"
|
|
860 |
using a_in h2 by (simp add:star_intro3)
|
|
861 |
moreover have "(x - ?x_max') @ z \<in> L\<^isub>1\<star>"
|
|
862 |
using b_eqs b_in np h1 by (simp add:diff_diff_appd)
|
|
863 |
moreover have "\<not> (length ?x_max' \<le> length x_max)"
|
|
864 |
using a_neq by simp
|
|
865 |
ultimately show ?thesis using h4 by blast
|
|
866 |
qed
|
|
867 |
} ultimately show ?thesis by blast
|
|
868 |
qed
|
|
869 |
then obtain za where z_decom: "z = za @ b"
|
|
870 |
and x_za: "(x - x_max) @ za \<in> L\<^isub>1"
|
|
871 |
using a_in by (auto elim:prefixE)
|
|
872 |
from x_za h7 have "(y - ya) @ za \<in> L\<^isub>1"
|
|
873 |
by (auto simp:str_eq_def str_eq_rel_def)
|
|
874 |
with b_in have "((y - ya) @ za) @ b \<in> L\<^isub>1\<star>" by blast
|
|
875 |
with z_decom show ?thesis by auto
|
|
876 |
qed
|
|
877 |
with h5 h6 show ?thesis
|
|
878 |
by (drule_tac star_intro1, auto simp:strict_prefix_def elim:prefixE)
|
|
879 |
qed
|
|
880 |
}
|
|
881 |
-- {* By instantiating the reasoning pattern just derived for both directions:*}
|
|
882 |
from this [OF _ eq_tag] and this [OF _ eq_tag [THEN sym]]
|
|
883 |
-- {* The thesis is proved as a trival consequence: *}
|
|
884 |
show ?thesis unfolding str_eq_def str_eq_rel_def by blast
|
|
885 |
qed
|
|
886 |
|
|
887 |
lemma quot_star_finiteI [intro]:
|
|
888 |
fixes L1::"lang"
|
|
889 |
assumes finite1: "finite (UNIV // \<approx>L1)"
|
|
890 |
shows "finite (UNIV // \<approx>(L1\<star>))"
|
|
891 |
proof (rule_tac tag = "tag_str_STAR L1" in tag_finite_imageD)
|
|
892 |
show "\<And>x y. tag_str_STAR L1 x = tag_str_STAR L1 y \<Longrightarrow> x \<approx>(L1\<star>) y"
|
|
893 |
by (rule tag_str_STAR_injI)
|
|
894 |
next
|
|
895 |
have *: "finite (Pow (UNIV // \<approx>L1))"
|
|
896 |
using finite1 by auto
|
|
897 |
show "finite (range (tag_str_STAR L1))"
|
|
898 |
unfolding tag_str_STAR_def
|
|
899 |
apply(rule finite_subset[OF _ *])
|
|
900 |
unfolding quotient_def
|
|
901 |
by auto
|
|
902 |
qed
|
|
903 |
|
|
904 |
subsubsection{* The conclusion *}
|
|
905 |
|
112
|
906 |
lemma Myhill_Nerode2:
|
63
|
907 |
fixes r::"rexp"
|
|
908 |
shows "finite (UNIV // \<approx>(L r))"
|
|
909 |
by (induct r) (auto)
|
|
910 |
|
112
|
911 |
|
|
912 |
section {* Closure properties *}
|
|
913 |
|
|
914 |
abbreviation
|
|
915 |
reg :: "lang \<Rightarrow> bool"
|
|
916 |
where
|
|
917 |
"reg A \<equiv> \<exists>r::rexp. A = L r"
|
|
918 |
|
|
919 |
|
|
920 |
theorem Myhill_Nerode:
|
|
921 |
shows "reg A \<longleftrightarrow> finite (UNIV // \<approx>A)"
|
|
922 |
using Myhill_Nerode1 Myhill_Nerode2 by auto
|
|
923 |
|
|
924 |
lemma closure_union[intro]:
|
|
925 |
assumes "reg A" "reg B"
|
|
926 |
shows "reg (A \<union> B)"
|
|
927 |
using assms
|
|
928 |
apply(auto)
|
|
929 |
apply(rule_tac x="ALT r ra" in exI)
|
|
930 |
apply(auto)
|
|
931 |
done
|
|
932 |
|
|
933 |
lemma closure_seq[intro]:
|
|
934 |
assumes "reg A" "reg B"
|
|
935 |
shows "reg (A ;; B)"
|
|
936 |
using assms
|
|
937 |
apply(auto)
|
|
938 |
apply(rule_tac x="SEQ r ra" in exI)
|
|
939 |
apply(auto)
|
|
940 |
done
|
|
941 |
|
|
942 |
lemma closure_star[intro]:
|
|
943 |
assumes "reg A"
|
|
944 |
shows "reg (A\<star>)"
|
|
945 |
using assms
|
|
946 |
apply(auto)
|
|
947 |
apply(rule_tac x="STAR r" in exI)
|
|
948 |
apply(auto)
|
|
949 |
done
|
|
950 |
|
|
951 |
lemma closure_complement[intro]:
|
|
952 |
assumes "reg A"
|
|
953 |
shows "reg (- A)"
|
|
954 |
using assms
|
|
955 |
unfolding Myhill_Nerode
|
|
956 |
unfolding str_eq_rel_def
|
|
957 |
by auto
|
|
958 |
|
|
959 |
lemma closure_difference[intro]:
|
|
960 |
assumes "reg A" "reg B"
|
|
961 |
shows "reg (A - B)"
|
|
962 |
proof -
|
|
963 |
have "A - B = - ((- A) \<union> B)" by blast
|
|
964 |
moreover
|
|
965 |
have "reg (- ((- A) \<union> B))"
|
|
966 |
using assms by blast
|
|
967 |
ultimately show "reg (A - B)" by simp
|
|
968 |
qed
|
|
969 |
|
|
970 |
lemma closure_intersection[intro]:
|
|
971 |
assumes "reg A" "reg B"
|
|
972 |
shows "reg (A \<inter> B)"
|
|
973 |
proof -
|
|
974 |
have "A \<inter> B = - ((- A) \<union> (- B))" by blast
|
|
975 |
moreover
|
|
976 |
have "reg (- ((- A) \<union> (- B)))"
|
|
977 |
using assms by blast
|
|
978 |
ultimately show "reg (A \<inter> B)" by simp
|
|
979 |
qed
|
|
980 |
|
|
981 |
|
63
|
982 |
end
|