author | urbanc |
Mon, 13 Feb 2012 04:22:52 +0000 | |
changeset 308 | a401d2dff7d0 |
parent 203 | 5d724fe0e096 |
child 338 | e7504bfdbd50 |
permissions | -rw-r--r-- |
63 | 1 |
theory Myhill_2 |
203 | 2 |
imports Myhill_1 "~~/src/HOL/Library/List_Prefix" |
63 | 3 |
begin |
4 |
||
203 | 5 |
section {* Second direction of MN: @{text "regular language \<Rightarrow> finite partition"} *} |
6 |
||
7 |
subsection {* Tagging functions *} |
|
63 | 8 |
|
9 |
definition |
|
181 | 10 |
tag_eq :: "('a list \<Rightarrow> 'b) \<Rightarrow> ('a list \<times> 'a list) set" ("=_=") |
63 | 11 |
where |
166 | 12 |
"=tag= \<equiv> {(x, y). tag x = tag y}" |
117 | 13 |
|
181 | 14 |
abbreviation |
15 |
tag_eq_applied :: "'a list \<Rightarrow> ('a list \<Rightarrow> 'b) \<Rightarrow> 'a list \<Rightarrow> bool" ("_ =_= _") |
|
16 |
where |
|
17 |
"x =tag= y \<equiv> (x, y) \<in> =tag=" |
|
18 |
||
183 | 19 |
lemma [simp]: |
181 | 20 |
shows "(\<approx>A) `` {x} = (\<approx>A) `` {y} \<longleftrightarrow> x \<approx>A y" |
183 | 21 |
unfolding str_eq_def by auto |
181 | 22 |
|
183 | 23 |
lemma refined_intro: |
181 | 24 |
assumes "\<And>x y z. \<lbrakk>x =tag= y; x @ z \<in> A\<rbrakk> \<Longrightarrow> y @ z \<in> A" |
25 |
shows "=tag= \<subseteq> \<approx>A" |
|
183 | 26 |
using assms unfolding str_eq_def tag_eq_def |
181 | 27 |
apply(clarify, simp (no_asm_use)) |
28 |
by metis |
|
29 |
||
117 | 30 |
lemma finite_eq_tag_rel: |
63 | 31 |
assumes rng_fnt: "finite (range tag)" |
109 | 32 |
shows "finite (UNIV // =tag=)" |
63 | 33 |
proof - |
119 | 34 |
let "?f" = "\<lambda>X. tag ` X" and ?A = "(UNIV // =tag=)" |
118 | 35 |
have "finite (?f ` ?A)" |
36 |
proof - |
|
119 | 37 |
have "range ?f \<subseteq> (Pow (range tag))" unfolding Pow_def by auto |
38 |
moreover |
|
39 |
have "finite (Pow (range tag))" using rng_fnt by simp |
|
40 |
ultimately |
|
41 |
have "finite (range ?f)" unfolding image_def by (blast intro: finite_subset) |
|
42 |
moreover |
|
43 |
have "?f ` ?A \<subseteq> range ?f" by auto |
|
44 |
ultimately show "finite (?f ` ?A)" by (rule rev_finite_subset) |
|
63 | 45 |
qed |
118 | 46 |
moreover |
119 | 47 |
have "inj_on ?f ?A" |
118 | 48 |
proof - |
49 |
{ fix X Y |
|
50 |
assume X_in: "X \<in> ?A" |
|
51 |
and Y_in: "Y \<in> ?A" |
|
52 |
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
|
53 |
then obtain x y |
119 | 54 |
where "x \<in> X" "y \<in> Y" "tag x = tag y" |
181 | 55 |
unfolding quotient_def Image_def image_def tag_eq_def |
119 | 56 |
by (simp) (blast) |
57 |
with X_in Y_in |
|
118 | 58 |
have "X = Y" |
181 | 59 |
unfolding quotient_def tag_eq_def by auto |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
60 |
} |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
61 |
then show "inj_on ?f ?A" unfolding inj_on_def by auto |
118 | 62 |
qed |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
63 |
ultimately show "finite (UNIV // =tag=)" by (rule finite_imageD) |
63 | 64 |
qed |
65 |
||
66 |
lemma refined_partition_finite: |
|
118 | 67 |
assumes fnt: "finite (UNIV // R1)" |
63 | 68 |
and refined: "R1 \<subseteq> R2" |
118 | 69 |
and eq1: "equiv UNIV R1" and eq2: "equiv UNIV R2" |
70 |
shows "finite (UNIV // R2)" |
|
63 | 71 |
proof - |
118 | 72 |
let ?f = "\<lambda>X. {R1 `` {x} | x. x \<in> X}" |
73 |
and ?A = "UNIV // R2" and ?B = "UNIV // R1" |
|
74 |
have "?f ` ?A \<subseteq> Pow ?B" |
|
75 |
unfolding image_def Pow_def quotient_def by auto |
|
76 |
moreover |
|
77 |
have "finite (Pow ?B)" using fnt by simp |
|
78 |
ultimately |
|
79 |
have "finite (?f ` ?A)" by (rule finite_subset) |
|
80 |
moreover |
|
81 |
have "inj_on ?f ?A" |
|
82 |
proof - |
|
83 |
{ fix X Y |
|
84 |
assume X_in: "X \<in> ?A" and Y_in: "Y \<in> ?A" and eq_f: "?f X = ?f Y" |
|
85 |
from quotientE [OF X_in] |
|
86 |
obtain x where "X = R2 `` {x}" by blast |
|
87 |
with equiv_class_self[OF eq2] have x_in: "x \<in> X" by simp |
|
88 |
then have "R1 ``{x} \<in> ?f X" by auto |
|
89 |
with eq_f have "R1 `` {x} \<in> ?f Y" by simp |
|
90 |
then obtain y |
|
91 |
where y_in: "y \<in> Y" and eq_r1_xy: "R1 `` {x} = R1 `` {y}" by auto |
|
92 |
with eq_equiv_class[OF _ eq1] |
|
93 |
have "(x, y) \<in> R1" by blast |
|
94 |
with refined have "(x, y) \<in> R2" by auto |
|
95 |
with quotient_eqI [OF eq2 X_in Y_in x_in y_in] |
|
96 |
have "X = Y" . |
|
97 |
} |
|
98 |
then show "inj_on ?f ?A" unfolding inj_on_def by blast |
|
63 | 99 |
qed |
118 | 100 |
ultimately show "finite (UNIV // R2)" by (rule finite_imageD) |
63 | 101 |
qed |
102 |
||
103 |
lemma tag_finite_imageD: |
|
104 |
assumes rng_fnt: "finite (range tag)" |
|
187 | 105 |
and refined: "=tag= \<subseteq> \<approx>A" |
119 | 106 |
shows "finite (UNIV // \<approx>A)" |
107 |
proof (rule_tac refined_partition_finite [of "=tag="]) |
|
108 |
show "finite (UNIV // =tag=)" by (rule finite_eq_tag_rel[OF rng_fnt]) |
|
109 |
next |
|
187 | 110 |
show "=tag= \<subseteq> \<approx>A" using refined . |
119 | 111 |
next |
112 |
show "equiv UNIV =tag=" |
|
187 | 113 |
and "equiv UNIV (\<approx>A)" |
114 |
unfolding equiv_def str_eq_def tag_eq_def refl_on_def sym_def trans_def |
|
119 | 115 |
by auto |
63 | 116 |
qed |
117 |
||
118 |
||
203 | 119 |
subsection {* Base cases: @{const Zero}, @{const One} and @{const Atom} *} |
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}" |
181 | 123 |
unfolding quotient_def Image_def str_eq_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 |
lemma quot_one_subset: |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
131 |
shows "UNIV // \<approx>{[]} \<subseteq> {{[]}, UNIV - {[]}}" |
63 | 132 |
proof |
133 |
fix x |
|
134 |
assume "x \<in> UNIV // \<approx>{[]}" |
|
187 | 135 |
then obtain y where h: "x = {z. y \<approx>{[]} z}" |
63 | 136 |
unfolding quotient_def Image_def by blast |
187 | 137 |
{ assume "y = []" |
138 |
with h have "x = {[]}" by (auto simp: str_eq_def) |
|
139 |
then have "x \<in> {{[]}, UNIV - {[]}}" by simp } |
|
140 |
moreover |
|
141 |
{ assume "y \<noteq> []" |
|
142 |
with h have "x = UNIV - {[]}" by (auto simp: str_eq_def) |
|
143 |
then have "x \<in> {{[]}, UNIV - {[]}}" by simp } |
|
144 |
ultimately show "x \<in> {{[]}, UNIV - {[]}}" by blast |
|
63 | 145 |
qed |
146 |
||
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
|
147 |
lemma quot_one_finiteI [intro]: |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
148 |
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
|
149 |
by (rule finite_subset[OF quot_one_subset]) (simp) |
63 | 150 |
|
151 |
||
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
|
152 |
lemma quot_atom_subset: |
63 | 153 |
"UNIV // (\<approx>{[c]}) \<subseteq> {{[]},{[c]}, UNIV - {[], [c]}}" |
154 |
proof |
|
155 |
fix x |
|
156 |
assume "x \<in> UNIV // \<approx>{[c]}" |
|
157 |
then obtain y where h: "x = {z. (y, z) \<in> \<approx>{[c]}}" |
|
158 |
unfolding quotient_def Image_def by blast |
|
159 |
show "x \<in> {{[]},{[c]}, UNIV - {[], [c]}}" |
|
160 |
proof - |
|
161 |
{ assume "y = []" hence "x = {[]}" using h |
|
181 | 162 |
by (auto simp: str_eq_def) } |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
163 |
moreover |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
164 |
{ assume "y = [c]" hence "x = {[c]}" using h |
181 | 165 |
by (auto dest!: spec[where x = "[]"] simp: str_eq_def) } |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
166 |
moreover |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
167 |
{ assume "y \<noteq> []" and "y \<noteq> [c]" |
63 | 168 |
hence "\<forall> z. (y @ z) \<noteq> [c]" by (case_tac y, auto) |
169 |
moreover have "\<And> p. (p \<noteq> [] \<and> p \<noteq> [c]) = (\<forall> q. p @ q \<noteq> [c])" |
|
170 |
by (case_tac p, auto) |
|
171 |
ultimately have "x = UNIV - {[],[c]}" using h |
|
181 | 172 |
by (auto simp add: str_eq_def) |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
173 |
} |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
174 |
ultimately show ?thesis by blast |
63 | 175 |
qed |
176 |
qed |
|
177 |
||
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
|
178 |
lemma quot_atom_finiteI [intro]: |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
179 |
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
|
180 |
by (rule finite_subset[OF quot_atom_subset]) (simp) |
63 | 181 |
|
182 |
||
203 | 183 |
subsection {* Case for @{const Plus} *} |
63 | 184 |
|
185 |
definition |
|
181 | 186 |
tag_Plus :: "'a lang \<Rightarrow> 'a lang \<Rightarrow> 'a list \<Rightarrow> ('a lang \<times> 'a lang)" |
63 | 187 |
where |
183 | 188 |
"tag_Plus A B \<equiv> \<lambda>x. (\<approx>A `` {x}, \<approx>B `` {x})" |
63 | 189 |
|
181 | 190 |
lemma quot_plus_finiteI [intro]: |
119 | 191 |
assumes finite1: "finite (UNIV // \<approx>A)" |
192 |
and finite2: "finite (UNIV // \<approx>B)" |
|
193 |
shows "finite (UNIV // \<approx>(A \<union> B))" |
|
181 | 194 |
proof (rule_tac tag = "tag_Plus A B" in tag_finite_imageD) |
119 | 195 |
have "finite ((UNIV // \<approx>A) \<times> (UNIV // \<approx>B))" |
196 |
using finite1 finite2 by auto |
|
181 | 197 |
then show "finite (range (tag_Plus A B))" |
198 |
unfolding tag_Plus_def quotient_def |
|
119 | 199 |
by (rule rev_finite_subset) (auto) |
200 |
next |
|
183 | 201 |
show "=tag_Plus A B= \<subseteq> \<approx>(A \<union> B)" |
202 |
unfolding tag_eq_def tag_Plus_def str_eq_def by auto |
|
63 | 203 |
qed |
204 |
||
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
205 |
|
203 | 206 |
subsection {* Case for @{text "Times"} *} |
63 | 207 |
|
181 | 208 |
definition |
184 | 209 |
"Partitions x \<equiv> {(x\<^isub>p, x\<^isub>s). x\<^isub>p @ x\<^isub>s = x}" |
181 | 210 |
|
182
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
211 |
lemma conc_partitions_elim: |
181 | 212 |
assumes "x \<in> A \<cdot> B" |
213 |
shows "\<exists>(u, v) \<in> Partitions x. u \<in> A \<and> v \<in> B" |
|
183 | 214 |
using assms unfolding conc_def Partitions_def |
181 | 215 |
by auto |
216 |
||
182
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
217 |
lemma conc_partitions_intro: |
181 | 218 |
assumes "(u, v) \<in> Partitions x \<and> u \<in> A \<and> v \<in> B" |
219 |
shows "x \<in> A \<cdot> B" |
|
183 | 220 |
using assms unfolding conc_def Partitions_def |
181 | 221 |
by auto |
222 |
||
182
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
223 |
lemma equiv_class_member: |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
224 |
assumes "x \<in> A" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
225 |
and "\<approx>A `` {x} = \<approx>A `` {y}" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
226 |
shows "y \<in> A" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
227 |
using assms |
183 | 228 |
apply(simp) |
229 |
apply(simp add: str_eq_def) |
|
182
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
230 |
apply(metis append_Nil2) |
181 | 231 |
done |
232 |
||
184 | 233 |
definition |
234 |
tag_Times :: "'a lang \<Rightarrow> 'a lang \<Rightarrow> 'a list \<Rightarrow> 'a lang \<times> 'a lang set" |
|
181 | 235 |
where |
184 | 236 |
"tag_Times A B \<equiv> \<lambda>x. (\<approx>A `` {x}, {(\<approx>B `` {x\<^isub>s}) | x\<^isub>p x\<^isub>s. x\<^isub>p \<in> A \<and> (x\<^isub>p, x\<^isub>s) \<in> Partitions x})" |
181 | 237 |
|
182
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
238 |
lemma tag_Times_injI: |
184 | 239 |
assumes a: "tag_Times A B x = tag_Times A B y" |
181 | 240 |
and c: "x @ z \<in> A \<cdot> B" |
241 |
shows "y @ z \<in> A \<cdot> B" |
|
242 |
proof - |
|
243 |
from c obtain u v where |
|
244 |
h1: "(u, v) \<in> Partitions (x @ z)" and |
|
245 |
h2: "u \<in> A" and |
|
182
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
246 |
h3: "v \<in> B" by (auto dest: conc_partitions_elim) |
181 | 247 |
from h1 have "x @ z = u @ v" unfolding Partitions_def by simp |
248 |
then obtain us |
|
249 |
where "(x = u @ us \<and> us @ z = v) \<or> (x @ us = u \<and> z = us @ v)" |
|
250 |
by (auto simp add: append_eq_append_conv2) |
|
251 |
moreover |
|
252 |
{ assume eq: "x = u @ us" "us @ z = v" |
|
184 | 253 |
have "(\<approx>B `` {us}) \<in> snd (tag_Times A B x)" |
254 |
unfolding Partitions_def tag_Times_def using h2 eq |
|
255 |
by (auto simp add: str_eq_def) |
|
256 |
then have "(\<approx>B `` {us}) \<in> snd (tag_Times A B y)" |
|
257 |
using a by simp |
|
181 | 258 |
then obtain u' us' where |
184 | 259 |
q1: "u' \<in> A" and |
181 | 260 |
q2: "\<approx>B `` {us} = \<approx>B `` {us'}" and |
184 | 261 |
q3: "(u', us') \<in> Partitions y" |
262 |
unfolding tag_Times_def by auto |
|
263 |
from q2 h3 eq |
|
181 | 264 |
have "us' @ z \<in> B" |
265 |
unfolding Image_def str_eq_def by auto |
|
184 | 266 |
then have "y @ z \<in> A \<cdot> B" using q1 q3 |
181 | 267 |
unfolding Partitions_def by auto |
268 |
} |
|
269 |
moreover |
|
270 |
{ assume eq: "x @ us = u" "z = us @ v" |
|
184 | 271 |
have "(\<approx>A `` {x}) = fst (tag_Times A B x)" |
272 |
by (simp add: tag_Times_def) |
|
273 |
then have "(\<approx>A `` {x}) = fst (tag_Times A B y)" |
|
181 | 274 |
using a by simp |
184 | 275 |
then have "\<approx>A `` {x} = \<approx>A `` {y}" |
276 |
by (simp add: tag_Times_def) |
|
181 | 277 |
moreover |
278 |
have "x @ us \<in> A" using h2 eq by simp |
|
279 |
ultimately |
|
182
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
280 |
have "y @ us \<in> A" using equiv_class_member |
181 | 281 |
unfolding Image_def str_eq_def by blast |
282 |
then have "(y @ us) @ v \<in> A \<cdot> B" |
|
283 |
using h3 unfolding conc_def by blast |
|
284 |
then have "y @ z \<in> A \<cdot> B" using eq by simp |
|
285 |
} |
|
286 |
ultimately show "y @ z \<in> A \<cdot> B" by blast |
|
287 |
qed |
|
288 |
||
289 |
lemma quot_conc_finiteI [intro]: |
|
290 |
assumes fin1: "finite (UNIV // \<approx>A)" |
|
291 |
and fin2: "finite (UNIV // \<approx>B)" |
|
292 |
shows "finite (UNIV // \<approx>(A \<cdot> B))" |
|
293 |
proof (rule_tac tag = "tag_Times A B" in tag_finite_imageD) |
|
183 | 294 |
have "\<And>x y z. \<lbrakk>tag_Times A B x = tag_Times A B y; x @ z \<in> A \<cdot> B\<rbrakk> \<Longrightarrow> y @ z \<in> A \<cdot> B" |
295 |
by (rule tag_Times_injI) |
|
296 |
(auto simp add: tag_Times_def tag_eq_def) |
|
297 |
then show "=tag_Times A B= \<subseteq> \<approx>(A \<cdot> B)" |
|
298 |
by (rule refined_intro) |
|
299 |
(auto simp add: tag_eq_def) |
|
63 | 300 |
next |
184 | 301 |
have *: "finite ((UNIV // \<approx>A) \<times> (Pow (UNIV // \<approx>B)))" |
63 | 302 |
using fin1 fin2 by auto |
181 | 303 |
show "finite (range (tag_Times A B))" |
304 |
unfolding tag_Times_def |
|
63 | 305 |
apply(rule finite_subset[OF _ *]) |
306 |
unfolding quotient_def |
|
307 |
by auto |
|
308 |
qed |
|
309 |
||
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
310 |
|
203 | 311 |
subsection {* Case for @{const "Star"} *} |
63 | 312 |
|
183 | 313 |
lemma star_partitions_elim: |
182
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
314 |
assumes "x @ z \<in> A\<star>" "x \<noteq> []" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
315 |
shows "\<exists>(u, v) \<in> Partitions (x @ z). u < x \<and> u \<in> A\<star> \<and> v \<in> A\<star>" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
316 |
proof - |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
317 |
have "([], x @ z) \<in> Partitions (x @ z)" "[] < x" "[] \<in> A\<star>" "x @ z \<in> A\<star>" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
318 |
using assms by (auto simp add: Partitions_def strict_prefix_def) |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
319 |
then show "\<exists>(u, v) \<in> Partitions (x @ z). u < x \<and> u \<in> A\<star> \<and> v \<in> A\<star>" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
320 |
by blast |
63 | 321 |
qed |
322 |
||
182
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
323 |
lemma finite_set_has_max2: |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
324 |
"\<lbrakk>finite A; A \<noteq> {}\<rbrakk> \<Longrightarrow> \<exists> max \<in> A. \<forall> a \<in> A. length a \<le> length max" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
325 |
apply(induct rule:finite.induct) |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
326 |
apply(simp) |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
327 |
by (metis (full_types) all_not_in_conv insert_iff linorder_linear order_trans) |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
328 |
|
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
|
329 |
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
|
330 |
shows "finite {xa. xa < (x::'a list)}" |
63 | 331 |
apply (induct x rule:rev_induct, simp) |
332 |
apply (subgoal_tac "{xa. xa < xs @ [x]} = {xa. xa < xs} \<union> {xs}") |
|
333 |
by (auto simp:strict_prefix_def) |
|
334 |
||
182
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
335 |
lemma append_eq_cases: |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
336 |
assumes a: "x @ y = m @ n" "m \<noteq> []" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
337 |
shows "x \<le> m \<or> m < x" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
338 |
unfolding prefix_def strict_prefix_def using a |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
339 |
by (auto simp add: append_eq_append_conv2) |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
340 |
|
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
341 |
lemma star_spartitions_elim2: |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
342 |
assumes a: "x @ z \<in> A\<star>" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
343 |
and b: "x \<noteq> []" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
344 |
shows "\<exists>(u, v) \<in> Partitions x. \<exists> (u', v') \<in> Partitions z. u < x \<and> u \<in> A\<star> \<and> v @ u' \<in> A \<and> v' \<in> A\<star>" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
345 |
proof - |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
346 |
def S \<equiv> "{u | u v. (u, v) \<in> Partitions x \<and> u < x \<and> u \<in> A\<star> \<and> v @ z \<in> A\<star>}" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
347 |
have "finite {u. u < x}" by (rule finite_strict_prefix_set) |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
348 |
then have "finite S" unfolding S_def |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
349 |
by (rule rev_finite_subset) (auto) |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
350 |
moreover |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
351 |
have "S \<noteq> {}" using a b unfolding S_def Partitions_def |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
352 |
by (auto simp: strict_prefix_def) |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
353 |
ultimately have "\<exists> u_max \<in> S. \<forall> u \<in> S. length u \<le> length u_max" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
354 |
using finite_set_has_max2 by blast |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
355 |
then obtain u_max v |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
356 |
where h0: "(u_max, v) \<in> Partitions x" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
357 |
and h1: "u_max < x" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
358 |
and h2: "u_max \<in> A\<star>" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
359 |
and h3: "v @ z \<in> A\<star>" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
360 |
and h4: "\<forall> u v. (u, v) \<in> Partitions x \<and> u < x \<and> u \<in> A\<star> \<and> v @ z \<in> A\<star> \<longrightarrow> length u \<le> length u_max" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
361 |
unfolding S_def Partitions_def by blast |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
362 |
have q: "v \<noteq> []" using h0 h1 b unfolding Partitions_def by auto |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
363 |
from h3 obtain a b |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
364 |
where i1: "(a, b) \<in> Partitions (v @ z)" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
365 |
and i2: "a \<in> A" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
366 |
and i3: "b \<in> A\<star>" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
367 |
and i4: "a \<noteq> []" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
368 |
unfolding Partitions_def |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
369 |
using q by (auto dest: star_decom) |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
370 |
have "v \<le> a" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
371 |
proof (rule ccontr) |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
372 |
assume a: "\<not>(v \<le> a)" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
373 |
from i1 have i1': "a @ b = v @ z" unfolding Partitions_def by simp |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
374 |
then have "a \<le> v \<or> v < a" using append_eq_cases q by blast |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
375 |
then have q: "a < v" using a unfolding strict_prefix_def prefix_def by auto |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
376 |
then obtain as where eq: "a @ as = v" unfolding strict_prefix_def prefix_def by auto |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
377 |
have "(u_max @ a, as) \<in> Partitions x" using eq h0 unfolding Partitions_def by auto |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
378 |
moreover |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
379 |
have "u_max @ a < x" using h0 eq q unfolding Partitions_def strict_prefix_def prefix_def by auto |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
380 |
moreover |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
381 |
have "u_max @ a \<in> A\<star>" using i2 h2 by simp |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
382 |
moreover |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
383 |
have "as @ z \<in> A\<star>" using i1' i2 i3 eq by auto |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
384 |
ultimately have "length (u_max @ a) \<le> length u_max" using h4 by blast |
183 | 385 |
with i4 show "False" by auto |
182
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
386 |
qed |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
387 |
with i1 obtain za zb |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
388 |
where k1: "v @ za = a" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
389 |
and k2: "(za, zb) \<in> Partitions z" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
390 |
and k4: "zb = b" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
391 |
unfolding Partitions_def prefix_def |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
392 |
by (auto simp add: append_eq_append_conv2) |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
393 |
show "\<exists> (u, v) \<in> Partitions x. \<exists> (u', v') \<in> Partitions z. u < x \<and> u \<in> A\<star> \<and> v @ u' \<in> A \<and> v' \<in> A\<star>" |
183 | 394 |
using h0 h1 h2 i2 i3 k1 k2 k4 unfolding Partitions_def by blast |
182
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
395 |
qed |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
396 |
|
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
397 |
definition |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
398 |
tag_Star :: "'a lang \<Rightarrow> 'a list \<Rightarrow> ('a lang) set" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
399 |
where |
187 | 400 |
"tag_Star A \<equiv> \<lambda>x. {\<approx>A `` {v} | u v. u < x \<and> u \<in> A\<star> \<and> (u, v) \<in> Partitions x}" |
182
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
401 |
|
183 | 402 |
lemma tag_Star_non_empty_injI: |
182
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
403 |
assumes a: "tag_Star A x = tag_Star A y" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
404 |
and c: "x @ z \<in> A\<star>" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
405 |
and d: "x \<noteq> []" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
406 |
shows "y @ z \<in> A\<star>" |
183 | 407 |
proof - |
408 |
obtain u v u' v' |
|
409 |
where a1: "(u, v) \<in> Partitions x" "(u', v')\<in> Partitions z" |
|
410 |
and a2: "u < x" |
|
411 |
and a3: "u \<in> A\<star>" |
|
412 |
and a4: "v @ u' \<in> A" |
|
413 |
and a5: "v' \<in> A\<star>" |
|
414 |
using c d by (auto dest: star_spartitions_elim2) |
|
415 |
have "(\<approx>A) `` {v} \<in> tag_Star A x" |
|
416 |
apply(simp add: tag_Star_def Partitions_def str_eq_def) |
|
417 |
using a1 a2 a3 by (auto simp add: Partitions_def) |
|
418 |
then have "(\<approx>A) `` {v} \<in> tag_Star A y" using a by simp |
|
419 |
then obtain u1 v1 |
|
420 |
where b1: "v \<approx>A v1" |
|
421 |
and b3: "u1 \<in> A\<star>" |
|
422 |
and b4: "(u1, v1) \<in> Partitions y" |
|
423 |
unfolding tag_Star_def by auto |
|
424 |
have c: "v1 @ u' \<in> A\<star>" using b1 a4 unfolding str_eq_def by simp |
|
425 |
have "u1 @ (v1 @ u') @ v' \<in> A\<star>" |
|
426 |
using b3 c a5 by (simp only: append_in_starI) |
|
427 |
then show "y @ z \<in> A\<star>" using b4 a1 |
|
428 |
unfolding Partitions_def by auto |
|
429 |
qed |
|
430 |
||
431 |
lemma tag_Star_empty_injI: |
|
182
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
432 |
assumes a: "tag_Star A x = tag_Star A y" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
433 |
and c: "x @ z \<in> A\<star>" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
434 |
and d: "x = []" |
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
435 |
shows "y @ z \<in> A\<star>" |
187 | 436 |
proof - |
437 |
from a have "{} = tag_Star A y" unfolding tag_Star_def using d by auto |
|
438 |
then have "y = []" |
|
439 |
unfolding tag_Star_def Partitions_def strict_prefix_def prefix_def |
|
440 |
by (auto) (metis Nil_in_star append_self_conv2) |
|
441 |
then show "y @ z \<in> A\<star>" using c d by simp |
|
442 |
qed |
|
182
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
443 |
|
63 | 444 |
lemma quot_star_finiteI [intro]: |
166 | 445 |
assumes finite1: "finite (UNIV // \<approx>A)" |
446 |
shows "finite (UNIV // \<approx>(A\<star>))" |
|
181 | 447 |
proof (rule_tac tag = "tag_Star A" in tag_finite_imageD) |
183 | 448 |
have "\<And>x y z. \<lbrakk>tag_Star A x = tag_Star A y; x @ z \<in> A\<star>\<rbrakk> \<Longrightarrow> y @ z \<in> A\<star>" |
449 |
by (case_tac "x = []") (blast intro: tag_Star_empty_injI tag_Star_non_empty_injI)+ |
|
450 |
then show "=(tag_Star A)= \<subseteq> \<approx>(A\<star>)" |
|
451 |
by (rule refined_intro) (auto simp add: tag_eq_def) |
|
63 | 452 |
next |
166 | 453 |
have *: "finite (Pow (UNIV // \<approx>A))" |
182
560712a29a36
a version of the proof which dispenses with the notion of string-subtraction
urbanc
parents:
181
diff
changeset
|
454 |
using finite1 by auto |
181 | 455 |
show "finite (range (tag_Star A))" |
183 | 456 |
unfolding tag_Star_def |
457 |
by (rule finite_subset[OF _ *]) |
|
458 |
(auto simp add: quotient_def) |
|
63 | 459 |
qed |
460 |
||
203 | 461 |
subsection {* The conclusion of the second direction *} |
63 | 462 |
|
112 | 463 |
lemma Myhill_Nerode2: |
183 | 464 |
fixes r::"'a rexp" |
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
|
465 |
shows "finite (UNIV // \<approx>(lang r))" |
63 | 466 |
by (induct r) (auto) |
467 |
||
183 | 468 |
end |