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