author | urbanc |
Thu, 21 Oct 2010 13:42:08 +0000 | |
changeset 7 | 86167563a1ed |
parent 6 | 779e1d9fbf3e |
child 8 | 1f8fe5bfd381 |
permissions | -rw-r--r-- |
6 | 1 |
theory MyhillNerode |
2 |
imports "Main" |
|
3 |
begin |
|
4 |
||
5 |
text {* sequential composition of languages *} |
|
6 |
||
7 |
definition |
|
8 |
lang_seq :: "string set \<Rightarrow> string set \<Rightarrow> string set" ("_ ; _" [100,100] 100) |
|
9 |
where |
|
7
86167563a1ed
deleted the matcher ate the beginning; made it to work with stable Isabelle and the development version
urbanc
parents:
6
diff
changeset
|
10 |
"L1 ; L2 = {s1 @ s2 | s1 s2. s1 \<in> L1 \<and> s2 \<in> L2}" |
6 | 11 |
|
12 |
lemma lang_seq_empty: |
|
13 |
shows "{[]} ; L = L" |
|
14 |
and "L ; {[]} = L" |
|
15 |
unfolding lang_seq_def by auto |
|
16 |
||
17 |
lemma lang_seq_null: |
|
18 |
shows "{} ; L = {}" |
|
19 |
and "L ; {} = {}" |
|
20 |
unfolding lang_seq_def by auto |
|
21 |
||
22 |
lemma lang_seq_append: |
|
23 |
assumes a: "s1 \<in> L1" |
|
24 |
and b: "s2 \<in> L2" |
|
25 |
shows "s1@s2 \<in> L1 ; L2" |
|
26 |
unfolding lang_seq_def |
|
27 |
using a b by auto |
|
28 |
||
29 |
lemma lang_seq_union: |
|
30 |
shows "(L1 \<union> L2); L3 = (L1; L3) \<union> (L2; L3)" |
|
31 |
and "L1; (L2 \<union> L3) = (L1; L2) \<union> (L1; L3)" |
|
32 |
unfolding lang_seq_def by auto |
|
33 |
||
34 |
lemma lang_seq_assoc: |
|
35 |
shows "(L1 ; L2) ; L3 = L1 ; (L2 ; L3)" |
|
7
86167563a1ed
deleted the matcher ate the beginning; made it to work with stable Isabelle and the development version
urbanc
parents:
6
diff
changeset
|
36 |
unfolding lang_seq_def |
86167563a1ed
deleted the matcher ate the beginning; made it to work with stable Isabelle and the development version
urbanc
parents:
6
diff
changeset
|
37 |
apply(auto) |
86167563a1ed
deleted the matcher ate the beginning; made it to work with stable Isabelle and the development version
urbanc
parents:
6
diff
changeset
|
38 |
apply(metis) |
86167563a1ed
deleted the matcher ate the beginning; made it to work with stable Isabelle and the development version
urbanc
parents:
6
diff
changeset
|
39 |
by (metis append_assoc) |
6 | 40 |
|
41 |
lemma lang_seq_minus: |
|
42 |
shows "(L1; L2) - {[]} = |
|
43 |
(if [] \<in> L1 then L2 - {[]} else {}) \<union> |
|
44 |
(if [] \<in> L2 then L1 - {[]} else {}) \<union> ((L1 - {[]}); (L2 - {[]}))" |
|
45 |
apply(auto simp add: lang_seq_def) |
|
46 |
apply(metis mem_def self_append_conv) |
|
47 |
apply(metis mem_def self_append_conv2) |
|
48 |
apply(metis mem_def self_append_conv2) |
|
49 |
apply(metis mem_def self_append_conv) |
|
50 |
done |
|
51 |
||
52 |
section {* Kleene star for languages defined as least fixed point *} |
|
53 |
||
54 |
inductive_set |
|
55 |
Star :: "string set \<Rightarrow> string set" ("_\<star>" [101] 102) |
|
56 |
for L :: "string set" |
|
57 |
where |
|
58 |
start[intro]: "[] \<in> L\<star>" |
|
59 |
| step[intro]: "\<lbrakk>s1 \<in> L; s2 \<in> L\<star>\<rbrakk> \<Longrightarrow> s1@s2 \<in> L\<star>" |
|
60 |
||
61 |
lemma lang_star_empty: |
|
62 |
shows "{}\<star> = {[]}" |
|
63 |
by (auto elim: Star.cases) |
|
64 |
||
65 |
lemma lang_star_cases: |
|
66 |
shows "L\<star> = {[]} \<union> L ; L\<star>" |
|
67 |
proof |
|
68 |
{ fix x |
|
69 |
have "x \<in> L\<star> \<Longrightarrow> x \<in> {[]} \<union> L ; L\<star>" |
|
70 |
unfolding lang_seq_def |
|
71 |
by (induct rule: Star.induct) (auto) |
|
72 |
} |
|
73 |
then show "L\<star> \<subseteq> {[]} \<union> L ; L\<star>" by auto |
|
74 |
next |
|
75 |
show "{[]} \<union> L ; L\<star> \<subseteq> L\<star>" |
|
76 |
unfolding lang_seq_def by auto |
|
77 |
qed |
|
78 |
||
79 |
lemma lang_star_cases': |
|
80 |
shows "L\<star> = {[]} \<union> L\<star> ; L" |
|
81 |
proof |
|
82 |
{ fix x |
|
83 |
have "x \<in> L\<star> \<Longrightarrow> x \<in> {[]} \<union> L\<star> ; L" |
|
84 |
unfolding lang_seq_def |
|
85 |
apply (induct rule: Star.induct) |
|
86 |
apply simp |
|
87 |
apply simp |
|
88 |
apply (erule disjE) |
|
89 |
apply (auto)[1] |
|
90 |
apply (erule exE | erule conjE)+ |
|
91 |
apply (rule disjI2) |
|
92 |
apply (rule_tac x = "s1 @ s1a" in exI) |
|
93 |
by auto |
|
94 |
} |
|
95 |
then show "L\<star> \<subseteq> {[]} \<union> L\<star> ; L" by auto |
|
96 |
next |
|
97 |
show "{[]} \<union> L\<star> ; L \<subseteq> L\<star>" |
|
98 |
unfolding lang_seq_def |
|
99 |
apply auto |
|
100 |
apply (erule Star.induct) |
|
101 |
apply auto |
|
102 |
apply (drule step[of _ _ "[]"]) |
|
103 |
by (auto intro:start) |
|
104 |
qed |
|
105 |
||
106 |
lemma lang_star_simple: |
|
107 |
shows "L \<subseteq> L\<star>" |
|
108 |
by (subst lang_star_cases) |
|
109 |
(auto simp only: lang_seq_def) |
|
110 |
||
111 |
lemma lang_star_prop0_aux: |
|
112 |
"s2 \<in> L\<star> \<Longrightarrow> \<forall> s1. s1 \<in> L \<longrightarrow> (\<exists> s3 s4. s3 \<in> L\<star> \<and> s4 \<in> L \<and> s1 @ s2 = s3 @ s4)" |
|
113 |
apply (erule Star.induct) |
|
114 |
apply (clarify, rule_tac x = "[]" in exI, rule_tac x = s1 in exI, simp add:start) |
|
115 |
apply (clarify, drule_tac x = s1 in spec) |
|
116 |
apply (drule mp, simp, clarify) |
|
117 |
apply (rule_tac x = "s1a @ s3" in exI, rule_tac x = s4 in exI) |
|
118 |
by auto |
|
119 |
||
120 |
lemma lang_star_prop0: |
|
121 |
"\<lbrakk>s1 \<in> L; s2 \<in> L\<star>\<rbrakk> \<Longrightarrow> \<exists> s3 s4. s3 \<in> L\<star> \<and> s4 \<in> L \<and> s1 @ s2 = s3 @ s4" |
|
122 |
by (auto dest:lang_star_prop0_aux) |
|
123 |
||
124 |
lemma lang_star_prop1: |
|
125 |
assumes asm: "L1; L2 \<subseteq> L2" |
|
126 |
shows "L1\<star>; L2 \<subseteq> L2" |
|
127 |
proof - |
|
128 |
{ fix s1 s2 |
|
129 |
assume minor: "s2 \<in> L2" |
|
130 |
assume major: "s1 \<in> L1\<star>" |
|
131 |
then have "s1@s2 \<in> L2" |
|
132 |
proof(induct rule: Star.induct) |
|
133 |
case start |
|
134 |
show "[]@s2 \<in> L2" using minor by simp |
|
135 |
next |
|
136 |
case (step s1 s1') |
|
137 |
have "s1 \<in> L1" by fact |
|
138 |
moreover |
|
139 |
have "s1'@s2 \<in> L2" by fact |
|
140 |
ultimately have "s1@(s1'@s2) \<in> L1; L2" by (auto simp add: lang_seq_def) |
|
141 |
with asm have "s1@(s1'@s2) \<in> L2" by auto |
|
142 |
then show "(s1@s1')@s2 \<in> L2" by simp |
|
143 |
qed |
|
144 |
} |
|
145 |
then show "L1\<star>; L2 \<subseteq> L2" by (auto simp add: lang_seq_def) |
|
146 |
qed |
|
147 |
||
148 |
lemma lang_star_prop2_aux: |
|
149 |
"s2 \<in> L2\<star> \<Longrightarrow> \<forall> s1. s1 \<in> L1 \<and> L1 ; L2 \<subseteq> L1 \<longrightarrow> s1 @ s2 \<in> L1" |
|
150 |
apply (erule Star.induct, simp) |
|
151 |
apply (clarify, drule_tac x = "s1a @ s1" in spec) |
|
152 |
by (auto simp:lang_seq_def) |
|
153 |
||
154 |
lemma lang_star_prop2: |
|
155 |
"L1; L2 \<subseteq> L1 \<Longrightarrow> L1 ; L2\<star> \<subseteq> L1" |
|
156 |
by (auto dest!:lang_star_prop2_aux simp:lang_seq_def) |
|
157 |
||
158 |
lemma lang_star_seq_subseteq: |
|
159 |
shows "L ; L\<star> \<subseteq> L\<star>" |
|
160 |
using lang_star_cases by blast |
|
161 |
||
162 |
lemma lang_star_double: |
|
163 |
shows "L\<star>; L\<star> = L\<star>" |
|
164 |
proof |
|
165 |
show "L\<star> ; L\<star> \<subseteq> L\<star>" |
|
166 |
using lang_star_prop1 lang_star_seq_subseteq by blast |
|
167 |
next |
|
168 |
have "L\<star> \<subseteq> L\<star> \<union> L\<star>; (L; L\<star>)" by auto |
|
169 |
also have "\<dots> = L\<star>;{[]} \<union> L\<star>; (L; L\<star>)" by (simp add: lang_seq_empty) |
|
170 |
also have "\<dots> = L\<star>; ({[]} \<union> L; L\<star>)" by (simp only: lang_seq_union) |
|
171 |
also have "\<dots> = L\<star>; L\<star>" using lang_star_cases by simp |
|
172 |
finally show "L\<star> \<subseteq> L\<star> ; L\<star>" by simp |
|
173 |
qed |
|
174 |
||
175 |
lemma lang_star_seq_subseteq': |
|
176 |
shows "L\<star>; L \<subseteq> L\<star>" |
|
177 |
proof - |
|
178 |
have "L \<subseteq> L\<star>" by (rule lang_star_simple) |
|
179 |
then have "L\<star>; L \<subseteq> L\<star>; L\<star>" by (auto simp add: lang_seq_def) |
|
180 |
then show "L\<star>; L \<subseteq> L\<star>" using lang_star_double by blast |
|
181 |
qed |
|
182 |
||
183 |
lemma |
|
184 |
shows "L\<star> \<subseteq> L\<star>\<star>" |
|
185 |
by (rule lang_star_simple) |
|
186 |
||
187 |
section {* tricky section *} |
|
188 |
||
189 |
lemma k1: |
|
190 |
assumes b: "s \<in> L\<star>" |
|
191 |
and a: "s \<noteq> []" |
|
192 |
shows "s \<in> (L - {[]}); L\<star>" |
|
193 |
using b a |
|
194 |
apply(induct rule: Star.induct) |
|
195 |
apply(simp) |
|
196 |
apply(case_tac "s1=[]") |
|
197 |
apply(simp) |
|
198 |
apply(simp add: lang_seq_def) |
|
199 |
apply(blast) |
|
200 |
done |
|
201 |
||
202 |
section {* (relies on lemma k1) *} |
|
203 |
||
204 |
lemma zzz: |
|
205 |
shows "{s. c#s \<in> L1\<star>} = {s. c#s \<in> L1} ; (L1\<star>)" |
|
206 |
apply(auto simp add: lang_seq_def Cons_eq_append_conv) |
|
207 |
apply(drule k1) |
|
208 |
apply(auto)[1] |
|
209 |
apply(auto simp add: lang_seq_def)[1] |
|
210 |
apply(rule_tac x="tl s1" in exI) |
|
211 |
apply(rule_tac x="s2" in exI) |
|
212 |
apply(auto)[1] |
|
213 |
apply(auto simp add: Cons_eq_append_conv)[2] |
|
214 |
apply(drule lang_seq_append) |
|
215 |
apply(assumption) |
|
216 |
apply(rotate_tac 1) |
|
217 |
apply(drule rev_subsetD) |
|
218 |
apply(rule lang_star_seq_subseteq) |
|
219 |
apply(simp) |
|
220 |
done |
|
221 |
||
222 |
||
223 |
||
224 |
section {* regular expressions *} |
|
225 |
||
226 |
datatype rexp = |
|
227 |
NULL |
|
228 |
| EMPTY |
|
229 |
| CHAR char |
|
230 |
| SEQ rexp rexp |
|
231 |
| ALT rexp rexp |
|
232 |
| STAR rexp |
|
233 |
||
234 |
||
235 |
consts L:: "'a \<Rightarrow> string set" |
|
236 |
||
237 |
overloading L_rexp \<equiv> "L:: rexp \<Rightarrow> string set" |
|
238 |
begin |
|
239 |
fun |
|
240 |
L_rexp :: "rexp \<Rightarrow> string set" |
|
241 |
where |
|
242 |
"L_rexp (NULL) = {}" |
|
243 |
| "L_rexp (EMPTY) = {[]}" |
|
244 |
| "L_rexp (CHAR c) = {[c]}" |
|
245 |
| "L_rexp (SEQ r1 r2) = (L_rexp r1) ; (L_rexp r2)" |
|
246 |
| "L_rexp (ALT r1 r2) = (L_rexp r1) \<union> (L_rexp r2)" |
|
247 |
| "L_rexp (STAR r) = (L_rexp r)\<star>" |
|
248 |
end |
|
249 |
||
250 |
||
7
86167563a1ed
deleted the matcher ate the beginning; made it to work with stable Isabelle and the development version
urbanc
parents:
6
diff
changeset
|
251 |
(* ************ now is the codes writen by chunhan ************************************* *) |
6 | 252 |
|
253 |
section {* Arden's Lemma revised *} |
|
254 |
||
255 |
lemma arden_aux1: |
|
256 |
assumes a: "X \<subseteq> X ; A \<union> B" |
|
257 |
and b: "[] \<notin> A" |
|
258 |
shows "x \<in> X \<Longrightarrow> x \<in> B ; A\<star>" |
|
259 |
apply (induct x taking:length rule:measure_induct) |
|
260 |
apply (subgoal_tac "x \<in> X ; A \<union> B") |
|
261 |
defer |
|
262 |
using a |
|
263 |
apply (auto)[1] |
|
264 |
apply simp |
|
265 |
apply (erule disjE) |
|
266 |
defer |
|
267 |
apply (auto simp add:lang_seq_def) [1] |
|
268 |
apply (subgoal_tac "\<exists> x1 x2. x = x1 @ x2 \<and> x1 \<in> X \<and> x2 \<in> A") |
|
269 |
defer |
|
270 |
apply (auto simp add:lang_seq_def) [1] |
|
271 |
apply (erule exE | erule conjE)+ |
|
272 |
apply simp |
|
273 |
apply (drule_tac x = x1 in spec) |
|
274 |
apply (simp) |
|
275 |
using b |
|
276 |
apply - |
|
277 |
apply (auto)[1] |
|
278 |
apply (subgoal_tac "x1 @ x2 \<in> (B ; A\<star>) ; A") |
|
279 |
defer |
|
280 |
apply (auto simp add:lang_seq_def)[1] |
|
281 |
by (metis Un_absorb1 lang_seq_assoc lang_seq_union(2) lang_star_double lang_star_simple mem_def sup1CI) |
|
282 |
||
283 |
theorem ardens_revised: |
|
284 |
assumes nemp: "[] \<notin> A" |
|
285 |
shows "(X = X ; A \<union> B) \<longleftrightarrow> (X = B ; A\<star>)" |
|
286 |
apply(rule iffI) |
|
287 |
defer |
|
288 |
apply(simp) |
|
289 |
apply(subst lang_star_cases') |
|
290 |
apply(subst lang_seq_union) |
|
291 |
apply(simp add: lang_seq_empty) |
|
292 |
apply(simp add: lang_seq_assoc) |
|
293 |
apply(auto)[1] |
|
294 |
proof - |
|
295 |
assume "X = X ; A \<union> B" |
|
296 |
then have as1: "X ; A \<union> B \<subseteq> X" and as2: "X \<subseteq> X ; A \<union> B" by simp_all |
|
297 |
from as1 have a: "X ; A \<subseteq> X" and b: "B \<subseteq> X" by simp_all |
|
298 |
from b have "B; A\<star> \<subseteq> X ; A\<star>" by (auto simp add: lang_seq_def) |
|
299 |
moreover |
|
300 |
from a have "X ; A\<star> \<subseteq> X" |
|
301 |
||
302 |
by (rule lang_star_prop2) |
|
303 |
ultimately have f1: "B ; A\<star> \<subseteq> X" by simp |
|
304 |
from as2 nemp |
|
305 |
have f2: "X \<subseteq> B; A\<star>" using arden_aux1 by auto |
|
306 |
from f1 f2 show "X = B; A\<star>" by auto |
|
307 |
qed |
|
308 |
||
309 |
section {* equiv class' definition *} |
|
310 |
||
311 |
definition |
|
312 |
equiv_str :: "string \<Rightarrow> string set \<Rightarrow> string \<Rightarrow> bool" ("_ \<equiv>_\<equiv> _" [100, 100, 100] 100) |
|
313 |
where |
|
314 |
"x \<equiv>L'\<equiv> y \<longleftrightarrow> (\<forall>z. x@z \<in> L' \<longleftrightarrow> y@z \<in> L')" |
|
315 |
||
316 |
definition |
|
317 |
equiv_class :: "string \<Rightarrow> (string set) \<Rightarrow> string set" ("\<lbrakk>_\<rbrakk>_" [100, 100] 100) |
|
318 |
where |
|
319 |
"\<lbrakk>x\<rbrakk>L' \<equiv> {y. x \<equiv>L'\<equiv> y}" |
|
320 |
||
321 |
text {* Chunhan modifies Q to Quo *} |
|
322 |
definition |
|
323 |
quot :: "string set \<Rightarrow> (string set) \<Rightarrow> (string set) set" ("_ Quo _" [100, 100] 100) |
|
324 |
where |
|
325 |
"L' Quo R \<equiv> { \<lbrakk>x\<rbrakk>R | x. x \<in> L'}" |
|
326 |
||
327 |
lemma lang_eqs_union_of_eqcls: |
|
328 |
"Lang = \<Union> {X. X \<in> (UNIV Quo Lang) \<and> (\<forall> x \<in> X. x \<in> Lang)}" |
|
329 |
proof |
|
330 |
show "Lang \<subseteq> \<Union>{X \<in> UNIV Quo Lang. \<forall>x\<in>X. x \<in> Lang}" |
|
331 |
proof |
|
332 |
fix x |
|
333 |
assume "x \<in> Lang" |
|
334 |
thus "x \<in> \<Union>{X \<in> UNIV Quo Lang. \<forall>x\<in>X. x \<in> Lang}" |
|
335 |
proof (simp add:quot_def) |
|
336 |
assume "(1)": "x \<in> Lang" |
|
337 |
show "\<exists>xa. (\<exists>x. xa = \<lbrakk>x\<rbrakk>Lang) \<and> (\<forall>x\<in>xa. x \<in> Lang) \<and> x \<in> xa" (is "\<exists>xa.?P xa") |
|
338 |
proof - |
|
339 |
have "?P (\<lbrakk>x\<rbrakk>Lang)" using "(1)" |
|
340 |
by (auto simp:equiv_class_def equiv_str_def dest: spec[where x = "[]"]) |
|
341 |
thus ?thesis by blast |
|
342 |
qed |
|
343 |
qed |
|
344 |
qed |
|
345 |
next |
|
346 |
show "\<Union>{X \<in> UNIV Quo Lang. \<forall>x\<in>X. x \<in> Lang} \<subseteq> Lang" |
|
347 |
by auto |
|
348 |
qed |
|
349 |
||
350 |
lemma empty_notin_CS: "{} \<notin> UNIV Quo Lang" |
|
351 |
apply (clarsimp simp:quot_def equiv_class_def) |
|
352 |
by (rule_tac x = x in exI, auto simp:equiv_str_def) |
|
353 |
||
354 |
lemma no_two_cls_inters: |
|
355 |
"\<lbrakk>X \<in> UNIV Quo Lang; Y \<in> UNIV Quo Lang; X \<noteq> Y\<rbrakk> \<Longrightarrow> X \<inter> Y = {}" |
|
356 |
by (auto simp:quot_def equiv_class_def equiv_str_def) |
|
357 |
||
358 |
text {* equiv_class transition *} |
|
359 |
definition |
|
360 |
CT :: "string set \<Rightarrow> char \<Rightarrow> string set \<Rightarrow> bool" ("_-_\<rightarrow>_" [99,99]99) |
|
361 |
where |
|
362 |
"X-c\<rightarrow>Y \<equiv> ((X;{[c]}) \<subseteq> Y)" |
|
363 |
||
364 |
types t_equa_rhs = "(string set \<times> rexp) set" |
|
365 |
||
366 |
types t_equa = "(string set \<times> t_equa_rhs)" |
|
367 |
||
368 |
types t_equas = "t_equa set" |
|
369 |
||
370 |
text {* "empty_rhs" generates "\<lambda>" for init-state, just like "\<lambda>" for final states in Brzozowski method. |
|
371 |
But if the init-state is "{[]}" ("\<lambda>" itself) then empty set is returned, see definition of "equation_rhs" *} |
|
372 |
definition |
|
373 |
empty_rhs :: "string set \<Rightarrow> t_equa_rhs" |
|
374 |
where |
|
375 |
"empty_rhs X \<equiv> if ([] \<in> X) then {({[]}, EMPTY)} else {}" |
|
376 |
||
377 |
definition |
|
378 |
folds :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a set \<Rightarrow> 'b" |
|
379 |
where |
|
380 |
"folds f z S \<equiv> SOME x. fold_graph f z S x" |
|
381 |
||
382 |
definition |
|
383 |
equation_rhs :: "(string set) set \<Rightarrow> string set \<Rightarrow> t_equa_rhs" |
|
384 |
where |
|
385 |
"equation_rhs CS X \<equiv> if (X = {[]}) then {({[]}, EMPTY)} |
|
386 |
else {(S, folds ALT NULL {CHAR c| c. S-c\<rightarrow>X} )| S. S \<in> CS} \<union> empty_rhs X" |
|
387 |
||
388 |
definition |
|
389 |
equations :: "(string set) set \<Rightarrow> t_equas" |
|
390 |
where |
|
391 |
"equations CS \<equiv> {(X, equation_rhs CS X) | X. X \<in> CS}" |
|
392 |
||
393 |
overloading L_rhs \<equiv> "L:: t_equa_rhs \<Rightarrow> string set" |
|
394 |
begin |
|
395 |
fun L_rhs:: "t_equa_rhs \<Rightarrow> string set" |
|
396 |
where |
|
397 |
"L_rhs rhs = {x. \<exists> X r. (X, r) \<in> rhs \<and> x \<in> X;(L r)}" |
|
398 |
end |
|
399 |
||
400 |
definition |
|
401 |
distinct_rhs :: "t_equa_rhs \<Rightarrow> bool" |
|
402 |
where |
|
403 |
"distinct_rhs rhs \<equiv> \<forall> X reg\<^isub>1 reg\<^isub>2. (X, reg\<^isub>1) \<in> rhs \<and> (X, reg\<^isub>2) \<in> rhs \<longrightarrow> reg\<^isub>1 = reg\<^isub>2" |
|
404 |
||
405 |
definition |
|
406 |
distinct_equas_rhs :: "t_equas \<Rightarrow> bool" |
|
407 |
where |
|
408 |
"distinct_equas_rhs equas \<equiv> \<forall> X rhs. (X, rhs) \<in> equas \<longrightarrow> distinct_rhs rhs" |
|
409 |
||
410 |
definition |
|
411 |
distinct_equas :: "t_equas \<Rightarrow> bool" |
|
412 |
where |
|
413 |
"distinct_equas equas \<equiv> \<forall> X rhs rhs'. (X, rhs) \<in> equas \<and> (X, rhs') \<in> equas \<longrightarrow> rhs = rhs'" |
|
414 |
||
415 |
definition |
|
416 |
seq_rhs_r :: "t_equa_rhs \<Rightarrow> rexp \<Rightarrow> t_equa_rhs" |
|
417 |
where |
|
418 |
"seq_rhs_r rhs r \<equiv> (\<lambda>(X, reg). (X, SEQ reg r)) ` rhs" |
|
419 |
||
420 |
definition |
|
421 |
del_x_paired :: "('a \<times> 'b) set \<Rightarrow> 'a \<Rightarrow> ('a \<times> 'b) set" |
|
422 |
where |
|
423 |
"del_x_paired S x \<equiv> S - {X. X \<in> S \<and> fst X = x}" |
|
424 |
||
425 |
definition |
|
426 |
arden_variate :: "string set \<Rightarrow> rexp \<Rightarrow> t_equa_rhs \<Rightarrow> t_equa_rhs" |
|
427 |
where |
|
428 |
"arden_variate X r rhs \<equiv> seq_rhs_r (del_x_paired rhs X) (STAR r)" |
|
429 |
||
430 |
definition |
|
431 |
no_EMPTY_rhs :: "t_equa_rhs \<Rightarrow> bool" |
|
432 |
where |
|
433 |
"no_EMPTY_rhs rhs \<equiv> \<forall> X r. (X, r) \<in> rhs \<and> X \<noteq> {[]} \<longrightarrow> [] \<notin> L r" |
|
434 |
||
435 |
definition |
|
436 |
no_EMPTY_equas :: "t_equas \<Rightarrow> bool" |
|
437 |
where |
|
438 |
"no_EMPTY_equas equas \<equiv> \<forall> X rhs. (X, rhs) \<in> equas \<longrightarrow> no_EMPTY_rhs rhs" |
|
439 |
||
440 |
lemma fold_alt_null_eqs: |
|
441 |
"finite rS \<Longrightarrow> x \<in> L (folds ALT NULL rS) = (\<exists> r \<in> rS. x \<in> L r)" |
|
442 |
apply (simp add:folds_def) |
|
443 |
apply (rule someI2_ex) |
|
444 |
apply (erule finite_imp_fold_graph) |
|
445 |
apply (erule fold_graph.induct) |
|
446 |
by auto (*??? how do this be in Isar ?? *) |
|
447 |
||
448 |
lemma seq_rhs_r_prop1: |
|
449 |
"L (seq_rhs_r rhs r) = (L rhs);(L r)" |
|
450 |
apply (auto simp:seq_rhs_r_def image_def lang_seq_def) |
|
451 |
apply (rule_tac x = "s1 @ s1a" in exI, rule_tac x = "s2a" in exI, simp) |
|
452 |
apply (rule_tac x = a in exI, rule_tac x = b in exI, simp) |
|
453 |
apply (rule_tac x = s1 in exI, rule_tac x = s1a in exI, simp) |
|
454 |
apply (rule_tac x = X in exI, rule_tac x = "SEQ ra r" in exI, simp) |
|
455 |
apply (rule conjI) |
|
456 |
apply (rule_tac x = "(X, ra)" in bexI, simp+) |
|
457 |
apply (rule_tac x = s1a in exI, rule_tac x = "s2a @ s2" in exI, simp) |
|
458 |
apply (simp add:lang_seq_def) |
|
459 |
by (rule_tac x = s2a in exI, rule_tac x = s2 in exI, simp) |
|
460 |
||
461 |
lemma del_x_paired_prop1: |
|
462 |
"\<lbrakk>distinct_rhs rhs; (X, r) \<in> rhs\<rbrakk> \<Longrightarrow> X ; L r \<union> L (del_x_paired rhs X) = L rhs" |
|
7
86167563a1ed
deleted the matcher ate the beginning; made it to work with stable Isabelle and the development version
urbanc
parents:
6
diff
changeset
|
463 |
apply (simp add:del_x_paired_def) |
86167563a1ed
deleted the matcher ate the beginning; made it to work with stable Isabelle and the development version
urbanc
parents:
6
diff
changeset
|
464 |
apply (simp add: distinct_rhs_def) |
86167563a1ed
deleted the matcher ate the beginning; made it to work with stable Isabelle and the development version
urbanc
parents:
6
diff
changeset
|
465 |
apply(auto simp add: lang_seq_def) |
86167563a1ed
deleted the matcher ate the beginning; made it to work with stable Isabelle and the development version
urbanc
parents:
6
diff
changeset
|
466 |
apply(metis) |
86167563a1ed
deleted the matcher ate the beginning; made it to work with stable Isabelle and the development version
urbanc
parents:
6
diff
changeset
|
467 |
done |
6 | 468 |
|
469 |
lemma arden_variate_prop: |
|
470 |
assumes "(X, rx) \<in> rhs" |
|
471 |
shows "(\<forall> Y. Y \<noteq> X \<longrightarrow> (\<exists> r. (Y, r) \<in> rhs) = (\<exists> r. (Y, r) \<in> (arden_variate X rx rhs)))" |
|
472 |
proof (rule allI, rule impI) |
|
473 |
fix Y |
|
474 |
assume "(1)": "Y \<noteq> X" |
|
475 |
show "(\<exists>r. (Y, r) \<in> rhs) = (\<exists>r. (Y, r) \<in> arden_variate X rx rhs)" |
|
476 |
proof |
|
477 |
assume "(1_1)": "\<exists>r. (Y, r) \<in> rhs" |
|
478 |
show "\<exists>r. (Y, r) \<in> arden_variate X rx rhs" (is "\<exists>r. ?P r") |
|
479 |
proof - |
|
480 |
from "(1_1)" obtain r where "(Y, r) \<in> rhs" .. |
|
481 |
hence "?P (SEQ r (STAR rx))" |
|
482 |
proof (simp add:arden_variate_def image_def) |
|
483 |
have "(Y, r) \<in> rhs \<Longrightarrow> (Y, r) \<in> del_x_paired rhs X" |
|
484 |
by (auto simp:del_x_paired_def "(1)") |
|
485 |
thus "(Y, r) \<in> rhs \<Longrightarrow> (Y, SEQ r (STAR rx)) \<in> seq_rhs_r (del_x_paired rhs X) (STAR rx)" |
|
486 |
by (auto simp:seq_rhs_r_def) |
|
487 |
qed |
|
488 |
thus ?thesis by blast |
|
489 |
qed |
|
490 |
next |
|
491 |
assume "(2_1)": "\<exists>r. (Y, r) \<in> arden_variate X rx rhs" |
|
492 |
thus "\<exists>r. (Y, r) \<in> rhs" (is "\<exists> r. ?P r") |
|
493 |
by (auto simp:arden_variate_def del_x_paired_def seq_rhs_r_def image_def) |
|
494 |
qed |
|
495 |
qed |
|
496 |
||
497 |
text {* |
|
498 |
arden_variate_valid: proves variation from "X = X;r + Y;ry + \<dots>" to "X = Y;(SEQ ry (STAR r)) + \<dots>" holds the law of "language of left equiv language of right" |
|
499 |
*} |
|
500 |
lemma arden_variate_valid: |
|
501 |
assumes X_not_empty: "X \<noteq> {[]}" |
|
502 |
and l_eq_r: "X = L rhs" |
|
503 |
and dist: "distinct_rhs rhs" |
|
504 |
and no_empty: "no_EMPTY_rhs rhs" |
|
505 |
and self_contained: "(X, r) \<in> rhs" |
|
506 |
shows "X = L (arden_variate X r rhs)" |
|
507 |
proof - |
|
508 |
have "[] \<notin> L r" using no_empty X_not_empty self_contained |
|
509 |
by (auto simp:no_EMPTY_rhs_def) |
|
510 |
hence ardens: "X = X;(L r) \<union> (L (del_x_paired rhs X)) \<longleftrightarrow> X = (L (del_x_paired rhs X)) ; (L r)\<star>" |
|
511 |
by (rule ardens_revised) |
|
512 |
have del_x: "X = X ; L r \<union> L (del_x_paired rhs X) \<longleftrightarrow> X = L rhs" using dist l_eq_r self_contained |
|
513 |
by (auto dest!:del_x_paired_prop1) |
|
514 |
show ?thesis |
|
515 |
proof |
|
516 |
show "X \<subseteq> L (arden_variate X r rhs)" |
|
517 |
proof |
|
518 |
fix x |
|
519 |
assume "(1_1)": "x \<in> X" with l_eq_r ardens del_x |
|
520 |
show "x \<in> L (arden_variate X r rhs)" |
|
521 |
by (simp add:arden_variate_def seq_rhs_r_prop1 del:L_rhs.simps) |
|
522 |
qed |
|
523 |
next |
|
524 |
show "L (arden_variate X r rhs) \<subseteq> X" |
|
525 |
proof |
|
526 |
fix x |
|
527 |
assume "(2_1)": "x \<in> L (arden_variate X r rhs)" with ardens del_x l_eq_r |
|
528 |
show "x \<in> X" |
|
529 |
by (simp add:arden_variate_def seq_rhs_r_prop1 del:L_rhs.simps) |
|
530 |
qed |
|
531 |
qed |
|
532 |
qed |
|
533 |
||
534 |
text {* merge_rhs {(X1, r1), (x2, r2}, (x4, r4), \<dots>} {(x1, r1'), (x3, r3'), \<dots>} = {(x1, ALT r1 r1'}, (x2, r2), (x3, r3'), (x4, r4), \<dots>} *} |
|
535 |
definition |
|
536 |
merge_rhs :: "t_equa_rhs \<Rightarrow> t_equa_rhs \<Rightarrow> t_equa_rhs" |
|
537 |
where |
|
538 |
"merge_rhs rhs rhs' \<equiv> {(X, r). (\<exists> r1 r2. ((X,r1) \<in> rhs \<and> (X, r2) \<in> rhs') \<and> r = ALT r1 r2) \<or> |
|
539 |
(\<exists> r1. (X, r1) \<in> rhs \<and> (\<not> (\<exists> r2. (X, r2) \<in> rhs')) \<and> r = r1) \<or> |
|
540 |
(\<exists> r2. (X, r2) \<in> rhs' \<and> (\<not> (\<exists> r1. (X, r1) \<in> rhs)) \<and> r = r2) }" |
|
541 |
||
542 |
||
543 |
text {* rhs_subst rhs X=xrhs r: substitude all occurence of X in rhs((X,r) \<in> rhs) with xrhs *} |
|
544 |
definition |
|
545 |
rhs_subst :: "t_equa_rhs \<Rightarrow> string set \<Rightarrow> t_equa_rhs \<Rightarrow> rexp \<Rightarrow> t_equa_rhs" |
|
546 |
where |
|
547 |
"rhs_subst rhs X xrhs r \<equiv> merge_rhs (del_x_paired rhs X) (seq_rhs_r xrhs r)" |
|
548 |
||
549 |
definition |
|
550 |
equas_subst_f :: "string set \<Rightarrow> t_equa_rhs \<Rightarrow> t_equa \<Rightarrow> t_equa" |
|
551 |
where |
|
552 |
"equas_subst_f X xrhs equa \<equiv> let (Y, rhs) = equa in |
|
553 |
if (\<exists> r. (X, r) \<in> rhs) |
|
554 |
then (Y, rhs_subst rhs X xrhs (SOME r. (X, r) \<in> rhs)) |
|
555 |
else equa" |
|
556 |
||
557 |
definition |
|
558 |
equas_subst :: "t_equas \<Rightarrow> string set \<Rightarrow> t_equa_rhs \<Rightarrow> t_equas" |
|
559 |
where |
|
560 |
"equas_subst ES X xrhs \<equiv> del_x_paired (equas_subst_f X xrhs ` ES) X" |
|
561 |
||
562 |
lemma lang_seq_prop1: |
|
563 |
"x \<in> X ; L r \<Longrightarrow> x \<in> X ; (L r \<union> L r')" |
|
564 |
by (auto simp:lang_seq_def) |
|
565 |
||
566 |
lemma lang_seq_prop1': |
|
567 |
"x \<in> X; L r \<Longrightarrow> x \<in> X ; (L r' \<union> L r)" |
|
568 |
by (auto simp:lang_seq_def) |
|
569 |
||
570 |
lemma lang_seq_prop2: |
|
571 |
"x \<in> X; (L r \<union> L r') \<Longrightarrow> x \<in> X;L r \<or> x \<in> X;L r'" |
|
572 |
by (auto simp:lang_seq_def) |
|
573 |
||
574 |
lemma merge_rhs_prop1: |
|
575 |
shows "L (merge_rhs rhs rhs') = L rhs \<union> L rhs' " |
|
576 |
apply (auto simp add:merge_rhs_def dest!:lang_seq_prop2 intro:lang_seq_prop1) |
|
577 |
apply (rule_tac x = X in exI, rule_tac x = r1 in exI, simp) |
|
578 |
apply (case_tac "\<exists> r2. (X, r2) \<in> rhs'") |
|
579 |
apply (clarify, rule_tac x = X in exI, rule_tac x = "ALT r r2" in exI, simp add:lang_seq_prop1) |
|
580 |
apply (rule_tac x = X in exI, rule_tac x = r in exI, simp) |
|
581 |
apply (case_tac "\<exists> r1. (X, r1) \<in> rhs") |
|
582 |
apply (clarify, rule_tac x = X in exI, rule_tac x = "ALT r1 r" in exI, simp add:lang_seq_prop1') |
|
583 |
apply (rule_tac x = X in exI, rule_tac x = r in exI, simp) |
|
584 |
done |
|
585 |
||
586 |
lemma no_EMPTY_rhss_imp_merge_no_EMPTY: |
|
587 |
"\<lbrakk>no_EMPTY_rhs rhs; no_EMPTY_rhs rhs'\<rbrakk> \<Longrightarrow> no_EMPTY_rhs (merge_rhs rhs rhs')" |
|
588 |
apply (simp add:no_EMPTY_rhs_def merge_rhs_def) |
|
589 |
apply (clarify, (erule conjE | erule exE | erule disjE)+) |
|
590 |
by auto |
|
591 |
||
592 |
lemma distinct_rhs_prop: |
|
593 |
"\<lbrakk>distinct_rhs rhs; (X, r1) \<in> rhs; (X, r2) \<in> rhs\<rbrakk> \<Longrightarrow> r1 = r2" |
|
594 |
by (auto simp:distinct_rhs_def) |
|
595 |
||
596 |
lemma merge_rhs_prop2: |
|
597 |
assumes dist_rhs: "distinct_rhs rhs" |
|
598 |
and dist_rhs':"distinct_rhs rhs'" |
|
599 |
shows "distinct_rhs (merge_rhs rhs rhs')" |
|
600 |
apply (auto simp:merge_rhs_def distinct_rhs_def) |
|
601 |
using dist_rhs |
|
602 |
apply (drule distinct_rhs_prop, simp+) |
|
603 |
using dist_rhs' |
|
604 |
apply (drule distinct_rhs_prop, simp+) |
|
605 |
using dist_rhs |
|
606 |
apply (drule distinct_rhs_prop, simp+) |
|
607 |
using dist_rhs' |
|
608 |
apply (drule distinct_rhs_prop, simp+) |
|
609 |
done |
|
610 |
||
611 |
lemma seq_rhs_r_holds_distinct: |
|
612 |
"distinct_rhs rhs \<Longrightarrow> distinct_rhs (seq_rhs_r rhs r)" |
|
613 |
by (auto simp:distinct_rhs_def seq_rhs_r_def) |
|
614 |
||
615 |
lemma seq_rhs_r_prop0: |
|
616 |
assumes l_eq_r: "X = L xrhs" |
|
617 |
shows "L (seq_rhs_r xrhs r) = X ; L r " |
|
618 |
using l_eq_r |
|
619 |
by (auto simp only:seq_rhs_r_prop1) |
|
620 |
||
621 |
lemma rhs_subst_prop1: |
|
622 |
assumes l_eq_r: "X = L xrhs" |
|
623 |
and dist: "distinct_rhs rhs" |
|
624 |
shows "(X, r) \<in> rhs \<Longrightarrow> L rhs = L (rhs_subst rhs X xrhs r)" |
|
625 |
apply (simp add:rhs_subst_def merge_rhs_prop1 del:L_rhs.simps) |
|
626 |
using l_eq_r |
|
627 |
apply (drule_tac r = r in seq_rhs_r_prop0, simp del:L_rhs.simps) |
|
628 |
using dist |
|
629 |
by (auto dest!:del_x_paired_prop1 simp del:L_rhs.simps) |
|
630 |
||
631 |
lemma del_x_paired_holds_distinct_rhs: |
|
632 |
"distinct_rhs rhs \<Longrightarrow> distinct_rhs (del_x_paired rhs x)" |
|
633 |
by (auto simp:distinct_rhs_def del_x_paired_def) |
|
634 |
||
635 |
lemma rhs_subst_holds_distinct_rhs: |
|
636 |
"\<lbrakk>distinct_rhs rhs; distinct_rhs xrhs\<rbrakk> \<Longrightarrow> distinct_rhs (rhs_subst rhs X xrhs r)" |
|
637 |
apply (drule_tac r = r and rhs = xrhs in seq_rhs_r_holds_distinct) |
|
638 |
apply (drule_tac x = X in del_x_paired_holds_distinct_rhs) |
|
639 |
by (auto dest:merge_rhs_prop2[where rhs = "del_x_paired rhs X"] simp:rhs_subst_def) |
|
640 |
||
641 |
section {* myhill-nerode theorem *} |
|
642 |
||
643 |
definition left_eq_cls :: "t_equas \<Rightarrow> (string set) set" |
|
644 |
where |
|
645 |
"left_eq_cls ES \<equiv> {X. \<exists> rhs. (X, rhs) \<in> ES} " |
|
646 |
||
647 |
definition right_eq_cls :: "t_equas \<Rightarrow> (string set) set" |
|
648 |
where |
|
649 |
"right_eq_cls ES \<equiv> {Y. \<exists> X rhs r. (X, rhs) \<in> ES \<and> (Y, r) \<in> rhs }" |
|
650 |
||
651 |
definition rhs_eq_cls :: "t_equa_rhs \<Rightarrow> (string set) set" |
|
652 |
where |
|
653 |
"rhs_eq_cls rhs \<equiv> {Y. \<exists> r. (Y, r) \<in> rhs}" |
|
654 |
||
655 |
definition ardenable :: "t_equa \<Rightarrow> bool" |
|
656 |
where |
|
657 |
"ardenable equa \<equiv> let (X, rhs) = equa in |
|
658 |
distinct_rhs rhs \<and> no_EMPTY_rhs rhs \<and> X = L rhs" |
|
659 |
||
660 |
text {* |
|
661 |
Inv: Invairance of the equation-system, during the decrease of the equation-system, Inv holds. |
|
662 |
*} |
|
663 |
definition Inv :: "string set \<Rightarrow> t_equas \<Rightarrow> bool" |
|
664 |
where |
|
665 |
"Inv X ES \<equiv> finite ES \<and> (\<exists> rhs. (X, rhs) \<in> ES) \<and> distinct_equas ES \<and> |
|
666 |
(\<forall> X xrhs. (X, xrhs) \<in> ES \<longrightarrow> ardenable (X, xrhs) \<and> X \<noteq> {} \<and> rhs_eq_cls xrhs \<subseteq> insert {[]} (left_eq_cls ES))" |
|
667 |
||
668 |
text {* |
|
669 |
TCon: Termination Condition of the equation-system decreasion. |
|
670 |
*} |
|
671 |
definition TCon:: "'a set \<Rightarrow> bool" |
|
672 |
where |
|
673 |
"TCon ES \<equiv> card ES = 1" |
|
674 |
||
675 |
||
676 |
text {* |
|
677 |
The following is a iteration principle, and is the main framework for the proof: |
|
678 |
1: We can form the initial equation-system using "equations" defined above, and prove it has invariance Inv by lemma "init_ES_satisfy_Inv"; |
|
679 |
2: We can decrease the number of the equation-system using ardens_lemma_revised and substitution ("equas_subst", defined above), |
|
680 |
and prove it holds the property "step" in "wf_iter" by lemma "iteration_step" |
|
681 |
and finally using property Inv and TCon to prove the myhill-nerode theorem |
|
682 |
||
683 |
*} |
|
684 |
lemma wf_iter [rule_format]: |
|
685 |
fixes f |
|
686 |
assumes step: "\<And> e. \<lbrakk>P e; \<not> Q e\<rbrakk> \<Longrightarrow> (\<exists> e'. P e' \<and> (f(e'), f(e)) \<in> less_than)" |
|
687 |
shows pe: "P e \<longrightarrow> (\<exists> e'. P e' \<and> Q e')" |
|
688 |
proof(induct e rule: wf_induct |
|
689 |
[OF wf_inv_image[OF wf_less_than, where f = "f"]], clarify) |
|
690 |
fix x |
|
691 |
assume h [rule_format]: |
|
692 |
"\<forall>y. (y, x) \<in> inv_image less_than f \<longrightarrow> P y \<longrightarrow> (\<exists>e'. P e' \<and> Q e')" |
|
693 |
and px: "P x" |
|
694 |
show "\<exists>e'. P e' \<and> Q e'" |
|
695 |
proof(cases "Q x") |
|
696 |
assume "Q x" with px show ?thesis by blast |
|
697 |
next |
|
698 |
assume nq: "\<not> Q x" |
|
699 |
from step [OF px nq] |
|
700 |
obtain e' where pe': "P e'" and ltf: "(f e', f x) \<in> less_than" by auto |
|
701 |
show ?thesis |
|
702 |
proof(rule h) |
|
703 |
from ltf show "(e', x) \<in> inv_image less_than f" |
|
704 |
by (simp add:inv_image_def) |
|
705 |
next |
|
706 |
from pe' show "P e'" . |
|
707 |
qed |
|
708 |
qed |
|
709 |
qed |
|
710 |
||
711 |
||
712 |
(* ********************************* BEGIN: proving the initial equation-system satisfies Inv **************************************** *) |
|
713 |
||
714 |
lemma distinct_rhs_equations: |
|
715 |
"(X, xrhs) \<in> equations (UNIV Quo Lang) \<Longrightarrow> distinct_rhs xrhs" |
|
716 |
by (auto simp: equations_def equation_rhs_def distinct_rhs_def empty_rhs_def dest:no_two_cls_inters) |
|
717 |
||
718 |
lemma every_nonempty_eqclass_has_strings: |
|
719 |
"\<lbrakk>X \<in> (UNIV Quo Lang); X \<noteq> {[]}\<rbrakk> \<Longrightarrow> \<exists> clist. clist \<in> X \<and> clist \<noteq> []" |
|
720 |
by (auto simp:quot_def equiv_class_def equiv_str_def) |
|
721 |
||
722 |
lemma every_eqclass_is_derived_from_empty: |
|
723 |
assumes not_empty: "X \<noteq> {[]}" |
|
724 |
shows "X \<in> (UNIV Quo Lang) \<Longrightarrow> \<exists> clist. {[]};{clist} \<subseteq> X \<and> clist \<noteq> []" |
|
725 |
using not_empty |
|
726 |
apply (drule_tac every_nonempty_eqclass_has_strings, simp) |
|
727 |
by (auto intro:exI[where x = clist] simp:lang_seq_def) |
|
728 |
||
729 |
lemma equiv_str_in_CS: |
|
730 |
"\<lbrakk>clist\<rbrakk>Lang \<in> (UNIV Quo Lang)" |
|
731 |
by (auto simp:quot_def) |
|
732 |
||
733 |
lemma has_str_imp_defined_by_str: |
|
734 |
"\<lbrakk>str \<in> X; X \<in> UNIV Quo Lang\<rbrakk> \<Longrightarrow> X = \<lbrakk>str\<rbrakk>Lang" |
|
735 |
by (auto simp:quot_def equiv_class_def equiv_str_def) |
|
736 |
||
737 |
lemma every_eqclass_has_ascendent: |
|
738 |
assumes has_str: "clist @ [c] \<in> X" |
|
739 |
and in_CS: "X \<in> UNIV Quo Lang" |
|
740 |
shows "\<exists> Y. Y \<in> UNIV Quo Lang \<and> Y-c\<rightarrow>X \<and> clist \<in> Y" (is "\<exists> Y. ?P Y") |
|
741 |
proof - |
|
742 |
have "?P (\<lbrakk>clist\<rbrakk>Lang)" |
|
743 |
proof - |
|
744 |
have "\<lbrakk>clist\<rbrakk>Lang \<in> UNIV Quo Lang" |
|
745 |
by (simp add:quot_def, rule_tac x = clist in exI, simp) |
|
746 |
moreover have "\<lbrakk>clist\<rbrakk>Lang-c\<rightarrow>X" |
|
747 |
proof - |
|
748 |
have "X = \<lbrakk>(clist @ [c])\<rbrakk>Lang" using has_str in_CS |
|
749 |
by (auto intro!:has_str_imp_defined_by_str) |
|
750 |
moreover have "\<forall> sl. sl \<in> \<lbrakk>clist\<rbrakk>Lang \<longrightarrow> sl @ [c] \<in> \<lbrakk>(clist @ [c])\<rbrakk>Lang" |
|
751 |
by (auto simp:equiv_class_def equiv_str_def) |
|
752 |
ultimately show ?thesis unfolding CT_def lang_seq_def |
|
753 |
by auto |
|
754 |
qed |
|
755 |
moreover have "clist \<in> \<lbrakk>clist\<rbrakk>Lang" |
|
756 |
by (auto simp:equiv_str_def equiv_class_def) |
|
757 |
ultimately show "?P (\<lbrakk>clist\<rbrakk>Lang)" by simp |
|
758 |
qed |
|
759 |
thus ?thesis by blast |
|
760 |
qed |
|
761 |
||
762 |
lemma finite_charset_rS: |
|
763 |
"finite {CHAR c |c. Y-c\<rightarrow>X}" |
|
764 |
by (rule_tac A = UNIV and f = CHAR in finite_surj, auto) |
|
765 |
||
766 |
lemma l_eq_r_in_equations: |
|
767 |
assumes X_in_equas: "(X, xrhs) \<in> equations (UNIV Quo Lang)" |
|
768 |
shows "X = L xrhs" |
|
769 |
proof (cases "X = {[]}") |
|
770 |
case True |
|
771 |
thus ?thesis using X_in_equas |
|
772 |
by (simp add:equations_def equation_rhs_def lang_seq_def) |
|
773 |
next |
|
774 |
case False |
|
775 |
show ?thesis |
|
776 |
proof |
|
777 |
show "X \<subseteq> L xrhs" |
|
778 |
proof |
|
779 |
fix x |
|
780 |
assume "(1)": "x \<in> X" |
|
781 |
show "x \<in> L xrhs" |
|
782 |
proof (cases "x = []") |
|
783 |
assume empty: "x = []" |
|
784 |
hence "x \<in> L (empty_rhs X)" using "(1)" |
|
785 |
by (auto simp:empty_rhs_def lang_seq_def) |
|
786 |
thus ?thesis using X_in_equas False empty "(1)" |
|
787 |
unfolding equations_def equation_rhs_def by auto |
|
788 |
next |
|
789 |
assume not_empty: "x \<noteq> []" |
|
790 |
hence "\<exists> clist c. x = clist @ [c]" by (case_tac x rule:rev_cases, auto) |
|
791 |
then obtain clist c where decom: "x = clist @ [c]" by blast |
|
792 |
moreover have "\<And> Y. \<lbrakk>Y \<in> UNIV Quo Lang; Y-c\<rightarrow>X; clist \<in> Y\<rbrakk>\<Longrightarrow> [c] \<in> L (folds ALT NULL {CHAR c |c. Y-c\<rightarrow>X})" |
|
793 |
proof - |
|
794 |
fix Y |
|
795 |
assume Y_is_eq_cl: "Y \<in> UNIV Quo Lang" |
|
796 |
and Y_CT_X: "Y-c\<rightarrow>X" |
|
797 |
and clist_in_Y: "clist \<in> Y" |
|
798 |
with finite_charset_rS |
|
799 |
show "[c] \<in> L (folds ALT NULL {CHAR c |c. Y-c\<rightarrow>X})" |
|
800 |
by (auto simp :fold_alt_null_eqs) |
|
801 |
qed |
|
802 |
hence "\<exists>Xa. Xa \<in> UNIV Quo Lang \<and> clist @ [c] \<in> Xa ; L (folds ALT NULL {CHAR c |c. Xa-c\<rightarrow>X})" |
|
803 |
using X_in_equas False not_empty "(1)" decom |
|
804 |
by (auto dest!:every_eqclass_has_ascendent simp:equations_def equation_rhs_def lang_seq_def) |
|
805 |
then obtain Xa where "Xa \<in> UNIV Quo Lang \<and> clist @ [c] \<in> Xa ; L (folds ALT NULL {CHAR c |c. Xa-c\<rightarrow>X})" by blast |
|
806 |
hence "x \<in> L {(S, folds ALT NULL {CHAR c |c. S-c\<rightarrow>X}) |S. S \<in> UNIV Quo Lang}" using X_in_equas "(1)" decom |
|
807 |
by (auto simp add:equations_def equation_rhs_def intro!:exI[where x = Xa]) |
|
808 |
thus "x \<in> L xrhs" using X_in_equas False not_empty unfolding equations_def equation_rhs_def |
|
809 |
by auto |
|
810 |
qed |
|
811 |
qed |
|
812 |
next |
|
813 |
show "L xrhs \<subseteq> X" |
|
814 |
proof |
|
815 |
fix x |
|
816 |
assume "(2)": "x \<in> L xrhs" |
|
817 |
have "(2_1)": "\<And> s1 s2 r Xa. \<lbrakk>s1 \<in> Xa; s2 \<in> L (folds ALT NULL {CHAR c |c. Xa-c\<rightarrow>X})\<rbrakk> \<Longrightarrow> s1 @ s2 \<in> X" |
|
818 |
using finite_charset_rS |
|
819 |
by (auto simp:CT_def lang_seq_def fold_alt_null_eqs) |
|
820 |
have "(2_2)": "\<And> s1 s2 Xa r.\<lbrakk>s1 \<in> Xa; s2 \<in> L r; (Xa, r) \<in> empty_rhs X\<rbrakk> \<Longrightarrow> s1 @ s2 \<in> X" |
|
821 |
by (simp add:empty_rhs_def split:if_splits) |
|
822 |
show "x \<in> X" using X_in_equas False "(2)" |
|
823 |
by (auto intro:"(2_1)" "(2_2)" simp:equations_def equation_rhs_def lang_seq_def) |
|
824 |
qed |
|
825 |
qed |
|
826 |
qed |
|
827 |
||
828 |
lemma finite_CT_chars: |
|
829 |
"finite {CHAR c |c. Xa-c\<rightarrow>X}" |
|
830 |
by (auto) |
|
831 |
||
832 |
lemma no_EMPTY_equations: |
|
833 |
"(X, xrhs) \<in> equations CS \<Longrightarrow> no_EMPTY_rhs xrhs" |
|
834 |
apply (clarsimp simp add:equations_def equation_rhs_def) |
|
835 |
apply (simp add:no_EMPTY_rhs_def empty_rhs_def, auto) |
|
836 |
apply (subgoal_tac "finite {CHAR c |c. Xa-c\<rightarrow>X}", drule_tac x = "[]" in fold_alt_null_eqs, clarsimp, rule finite_CT_chars)+ |
|
837 |
done |
|
838 |
||
839 |
lemma init_ES_satisfy_ardenable: |
|
840 |
"(X, xrhs) \<in> equations (UNIV Quo Lang) \<Longrightarrow> ardenable (X, xrhs)" |
|
841 |
unfolding ardenable_def |
|
842 |
by (auto intro:distinct_rhs_equations no_EMPTY_equations simp:l_eq_r_in_equations simp del:L_rhs.simps) |
|
843 |
||
844 |
lemma init_ES_satisfy_Inv: |
|
845 |
assumes finite_CS: "finite (UNIV Quo Lang)" |
|
846 |
and X_in_eq_cls: "X \<in> UNIV Quo Lang" |
|
847 |
shows "Inv X (equations (UNIV Quo Lang))" |
|
848 |
proof - |
|
849 |
have "finite (equations (UNIV Quo Lang))" using finite_CS |
|
850 |
by (auto simp:equations_def) |
|
851 |
moreover have "\<exists>rhs. (X, rhs) \<in> equations (UNIV Quo Lang)" using X_in_eq_cls |
|
852 |
by (simp add:equations_def) |
|
853 |
moreover have "distinct_equas (equations (UNIV Quo Lang))" |
|
854 |
by (auto simp:distinct_equas_def equations_def) |
|
855 |
moreover have "\<forall>X xrhs. (X, xrhs) \<in> equations (UNIV Quo Lang) \<longrightarrow> |
|
856 |
rhs_eq_cls xrhs \<subseteq> insert {[]} (left_eq_cls (equations (UNIV Quo Lang)))" |
|
857 |
apply (simp add:left_eq_cls_def equations_def rhs_eq_cls_def equation_rhs_def) |
|
858 |
by (auto simp:empty_rhs_def split:if_splits) |
|
859 |
moreover have "\<forall>X xrhs. (X, xrhs) \<in> equations (UNIV Quo Lang) \<longrightarrow> X \<noteq> {}" |
|
860 |
by (clarsimp simp:equations_def empty_notin_CS intro:classical) |
|
861 |
moreover have "\<forall>X xrhs. (X, xrhs) \<in> equations (UNIV Quo Lang) \<longrightarrow> ardenable (X, xrhs)" |
|
862 |
by (auto intro!:init_ES_satisfy_ardenable) |
|
863 |
ultimately show ?thesis by (simp add:Inv_def) |
|
864 |
qed |
|
865 |
||
866 |
||
867 |
(* ********************************* END: proving the initial equation-system satisfies Inv **************************************** *) |
|
868 |
||
869 |
||
870 |
(* ***************************** BEGIN: proving every equation-system's iteration step satisfies Inv ******************************* *) |
|
871 |
||
872 |
lemma not_T_aux: "\<lbrakk>\<not> TCon (insert a A); x = a\<rbrakk> |
|
873 |
\<Longrightarrow> \<exists>y. x \<noteq> y \<and> y \<in> insert a A " |
|
874 |
apply (case_tac "insert a A = {a}") |
|
875 |
by (auto simp:TCon_def) |
|
876 |
||
877 |
lemma not_T_atleast_2[rule_format]: |
|
878 |
"finite S \<Longrightarrow> \<forall> x. x \<in> S \<and> (\<not> TCon S)\<longrightarrow> (\<exists> y. x \<noteq> y \<and> y \<in> S)" |
|
879 |
apply (erule finite.induct, simp) |
|
880 |
apply (clarify, case_tac "x = a") |
|
881 |
by (erule not_T_aux, auto) |
|
882 |
||
883 |
lemma exist_another_equa: |
|
884 |
"\<lbrakk>\<not> TCon ES; finite ES; distinct_equas ES; (X, rhl) \<in> ES\<rbrakk> \<Longrightarrow> \<exists> Y yrhl. (Y, yrhl) \<in> ES \<and> X \<noteq> Y" |
|
885 |
apply (drule not_T_atleast_2, simp) |
|
886 |
apply (clarsimp simp:distinct_equas_def) |
|
887 |
apply (drule_tac x= X in spec, drule_tac x = rhl in spec, drule_tac x = b in spec) |
|
888 |
by auto |
|
889 |
||
890 |
lemma Inv_mono_with_lambda: |
|
891 |
assumes Inv_ES: "Inv X ES" |
|
892 |
and X_noteq_Y: "X \<noteq> {[]}" |
|
893 |
shows "Inv X (ES - {({[]}, yrhs)})" |
|
894 |
proof - |
|
895 |
have "finite (ES - {({[]}, yrhs)})" using Inv_ES |
|
896 |
by (simp add:Inv_def) |
|
897 |
moreover have "\<exists>rhs. (X, rhs) \<in> ES - {({[]}, yrhs)}" using Inv_ES X_noteq_Y |
|
898 |
by (simp add:Inv_def) |
|
899 |
moreover have "distinct_equas (ES - {({[]}, yrhs)})" using Inv_ES X_noteq_Y |
|
900 |
apply (clarsimp simp:Inv_def distinct_equas_def) |
|
901 |
by (drule_tac x = Xa in spec, simp) |
|
902 |
moreover have "\<forall>X xrhs.(X, xrhs) \<in> ES - {({[]}, yrhs)} \<longrightarrow> |
|
903 |
ardenable (X, xrhs) \<and> X \<noteq> {}" using Inv_ES |
|
904 |
by (clarify, simp add:Inv_def) |
|
905 |
moreover |
|
906 |
have "insert {[]} (left_eq_cls (ES - {({[]}, yrhs)})) = insert {[]} (left_eq_cls ES)" |
|
907 |
by (auto simp:left_eq_cls_def) |
|
908 |
hence "\<forall>X xrhs.(X, xrhs) \<in> ES - {({[]}, yrhs)} \<longrightarrow> |
|
909 |
rhs_eq_cls xrhs \<subseteq> insert {[]} (left_eq_cls (ES - {({[]}, yrhs)}))" |
|
910 |
using Inv_ES by (auto simp:Inv_def) |
|
911 |
ultimately show ?thesis by (simp add:Inv_def) |
|
912 |
qed |
|
913 |
||
914 |
lemma non_empty_card_prop: |
|
915 |
"finite ES \<Longrightarrow> \<forall>e. e \<in> ES \<longrightarrow> card ES - Suc 0 < card ES" |
|
916 |
apply (erule finite.induct, simp) |
|
917 |
apply (case_tac[!] "a \<in> A") |
|
918 |
by (auto simp:insert_absorb) |
|
919 |
||
920 |
lemma ardenable_prop: |
|
921 |
assumes not_lambda: "Y \<noteq> {[]}" |
|
922 |
and ardable: "ardenable (Y, yrhs)" |
|
923 |
shows "\<exists> yrhs'. Y = L yrhs' \<and> distinct_rhs yrhs' \<and> rhs_eq_cls yrhs' = rhs_eq_cls yrhs - {Y}" (is "\<exists> yrhs'. ?P yrhs'") |
|
924 |
proof (cases "(\<exists> reg. (Y, reg) \<in> yrhs)") |
|
925 |
case True |
|
926 |
thus ?thesis |
|
927 |
proof |
|
928 |
fix reg |
|
929 |
assume self_contained: "(Y, reg) \<in> yrhs" |
|
930 |
show ?thesis |
|
931 |
proof - |
|
932 |
have "?P (arden_variate Y reg yrhs)" |
|
933 |
proof - |
|
934 |
have "Y = L (arden_variate Y reg yrhs)" |
|
935 |
using self_contained not_lambda ardable |
|
936 |
by (rule_tac arden_variate_valid, simp_all add:ardenable_def) |
|
937 |
moreover have "distinct_rhs (arden_variate Y reg yrhs)" |
|
938 |
using ardable |
|
939 |
by (auto simp:distinct_rhs_def arden_variate_def seq_rhs_r_def del_x_paired_def ardenable_def) |
|
940 |
moreover have "rhs_eq_cls (arden_variate Y reg yrhs) = rhs_eq_cls yrhs - {Y}" |
|
941 |
proof - |
|
942 |
have "\<And> rhs r. rhs_eq_cls (seq_rhs_r rhs r) = rhs_eq_cls rhs" |
|
943 |
apply (auto simp:rhs_eq_cls_def seq_rhs_r_def image_def) |
|
944 |
by (rule_tac x = "SEQ ra r" in exI, rule_tac x = "(x, ra)" in bexI, simp+) |
|
945 |
moreover have "\<And> rhs X. rhs_eq_cls (del_x_paired rhs X) = rhs_eq_cls rhs - {X}" |
|
946 |
by (auto simp:rhs_eq_cls_def del_x_paired_def) |
|
947 |
ultimately show ?thesis by (simp add:arden_variate_def) |
|
948 |
qed |
|
949 |
ultimately show ?thesis by simp |
|
950 |
qed |
|
951 |
thus ?thesis by (rule_tac x= "arden_variate Y reg yrhs" in exI, simp) |
|
952 |
qed |
|
953 |
qed |
|
954 |
next |
|
955 |
case False |
|
956 |
hence "(2)": "rhs_eq_cls yrhs - {Y} = rhs_eq_cls yrhs" |
|
957 |
by (auto simp:rhs_eq_cls_def) |
|
958 |
show ?thesis |
|
959 |
proof - |
|
960 |
have "?P yrhs" using False ardable "(2)" |
|
961 |
by (simp add:ardenable_def) |
|
962 |
thus ?thesis by blast |
|
963 |
qed |
|
964 |
qed |
|
965 |
||
966 |
lemma equas_subst_f_del_no_other: |
|
967 |
assumes self_contained: "(Y, rhs) \<in> ES" |
|
968 |
shows "\<exists> rhs'. (Y, rhs') \<in> (equas_subst_f X xrhs ` ES)" (is "\<exists> rhs'. ?P rhs'") |
|
969 |
proof - |
|
970 |
have "\<exists> rhs'. equas_subst_f X xrhs (Y, rhs) = (Y, rhs')" |
|
971 |
by (auto simp:equas_subst_f_def) |
|
972 |
then obtain rhs' where "equas_subst_f X xrhs (Y, rhs) = (Y, rhs')" by blast |
|
973 |
hence "?P rhs'" unfolding image_def using self_contained |
|
974 |
by (auto intro:bexI[where x = "(Y, rhs)"]) |
|
975 |
thus ?thesis by blast |
|
976 |
qed |
|
977 |
||
978 |
lemma del_x_paired_del_only_x: |
|
979 |
"\<lbrakk>X \<noteq> Y; (X, rhs) \<in> ES\<rbrakk> \<Longrightarrow> (X, rhs) \<in> del_x_paired ES Y" |
|
980 |
by (auto simp:del_x_paired_def) |
|
981 |
||
982 |
lemma equas_subst_del_no_other: |
|
983 |
"\<lbrakk>(X, rhs) \<in> ES; X \<noteq> Y\<rbrakk> \<Longrightarrow> (\<exists>rhs. (X, rhs) \<in> equas_subst ES Y rhs')" |
|
984 |
unfolding equas_subst_def |
|
985 |
apply (drule_tac X = Y and xrhs = rhs' in equas_subst_f_del_no_other) |
|
986 |
by (erule exE, drule del_x_paired_del_only_x, auto) |
|
987 |
||
988 |
lemma equas_subst_holds_distinct: |
|
989 |
"distinct_equas ES \<Longrightarrow> distinct_equas (equas_subst ES Y rhs')" |
|
990 |
apply (clarsimp simp add:equas_subst_def distinct_equas_def del_x_paired_def equas_subst_f_def) |
|
991 |
by (auto split:if_splits) |
|
992 |
||
993 |
lemma del_x_paired_dels: |
|
994 |
"(X, rhs) \<in> ES \<Longrightarrow> {Y. Y \<in> ES \<and> fst Y = X} \<inter> ES \<noteq> {}" |
|
995 |
by (auto) |
|
996 |
||
997 |
lemma del_x_paired_subset: |
|
998 |
"(X, rhs) \<in> ES \<Longrightarrow> ES - {Y. Y \<in> ES \<and> fst Y = X} \<subset> ES" |
|
999 |
apply (drule del_x_paired_dels) |
|
1000 |
by auto |
|
1001 |
||
1002 |
lemma del_x_paired_card_less: |
|
1003 |
"\<lbrakk>finite ES; (X, rhs) \<in> ES\<rbrakk> \<Longrightarrow> card (del_x_paired ES X) < card ES" |
|
1004 |
apply (simp add:del_x_paired_def) |
|
1005 |
apply (drule del_x_paired_subset) |
|
1006 |
by (auto intro:psubset_card_mono) |
|
1007 |
||
1008 |
lemma equas_subst_card_less: |
|
1009 |
"\<lbrakk>finite ES; (Y, yrhs) \<in> ES\<rbrakk> \<Longrightarrow> card (equas_subst ES Y rhs') < card ES" |
|
1010 |
apply (simp add:equas_subst_def) |
|
1011 |
apply (frule_tac h = "equas_subst_f Y rhs'" in finite_imageI) |
|
1012 |
apply (drule_tac f = "equas_subst_f Y rhs'" in Finite_Set.card_image_le) |
|
1013 |
apply (drule_tac X = Y and xrhs = rhs' in equas_subst_f_del_no_other,erule exE) |
|
1014 |
by (drule del_x_paired_card_less, auto) |
|
1015 |
||
1016 |
lemma equas_subst_holds_distinct_rhs: |
|
1017 |
assumes dist': "distinct_rhs yrhs'" |
|
1018 |
and history: "\<forall>X xrhs. (X, xrhs) \<in> ES \<longrightarrow> ardenable (X, xrhs)" |
|
1019 |
and X_in : "(X, xrhs) \<in> equas_subst ES Y yrhs'" |
|
1020 |
shows "distinct_rhs xrhs" |
|
1021 |
using X_in history |
|
1022 |
apply (clarsimp simp:equas_subst_def del_x_paired_def) |
|
1023 |
apply (drule_tac x = a in spec, drule_tac x = b in spec) |
|
1024 |
apply (simp add:ardenable_def equas_subst_f_def) |
|
1025 |
by (auto intro:rhs_subst_holds_distinct_rhs simp:dist' split:if_splits) |
|
1026 |
||
1027 |
lemma r_no_EMPTY_imp_seq_rhs_r_no_EMPTY: |
|
1028 |
"[] \<notin> L r \<Longrightarrow> no_EMPTY_rhs (seq_rhs_r rhs r)" |
|
1029 |
by (auto simp:no_EMPTY_rhs_def seq_rhs_r_def lang_seq_def) |
|
1030 |
||
1031 |
lemma del_x_paired_holds_no_EMPTY: |
|
1032 |
"no_EMPTY_rhs yrhs \<Longrightarrow> no_EMPTY_rhs (del_x_paired yrhs Y)" |
|
1033 |
by (auto simp:no_EMPTY_rhs_def del_x_paired_def) |
|
1034 |
||
1035 |
lemma rhs_subst_holds_no_EMPTY: |
|
1036 |
"\<lbrakk>no_EMPTY_rhs yrhs; (Y, r) \<in> yrhs; Y \<noteq> {[]}\<rbrakk> \<Longrightarrow> no_EMPTY_rhs (rhs_subst yrhs Y rhs' r)" |
|
1037 |
apply (auto simp:rhs_subst_def intro!:no_EMPTY_rhss_imp_merge_no_EMPTY r_no_EMPTY_imp_seq_rhs_r_no_EMPTY del_x_paired_holds_no_EMPTY) |
|
1038 |
by (auto simp:no_EMPTY_rhs_def) |
|
1039 |
||
1040 |
lemma equas_subst_holds_no_EMPTY: |
|
1041 |
assumes substor: "Y \<noteq> {[]}" |
|
1042 |
and history: "\<forall>X xrhs. (X, xrhs) \<in> ES \<longrightarrow> ardenable (X, xrhs)" |
|
1043 |
and X_in:"(X, xrhs) \<in> equas_subst ES Y yrhs'" |
|
1044 |
shows "no_EMPTY_rhs xrhs" |
|
1045 |
proof- |
|
1046 |
from X_in have "\<exists> (Z, zrhs) \<in> ES. (X, xrhs) = equas_subst_f Y yrhs' (Z, zrhs)" |
|
1047 |
by (auto simp add:equas_subst_def del_x_paired_def) |
|
1048 |
then obtain Z zrhs where Z_in: "(Z, zrhs) \<in> ES" |
|
1049 |
and X_Z: "(X, xrhs) = equas_subst_f Y yrhs' (Z, zrhs)" by blast |
|
1050 |
hence dist_zrhs: "distinct_rhs zrhs" using history |
|
1051 |
by (auto simp:ardenable_def) |
|
1052 |
show ?thesis |
|
1053 |
proof (cases "\<exists> r. (Y, r) \<in> zrhs") |
|
1054 |
case True |
|
1055 |
then obtain r where Y_in_zrhs: "(Y, r) \<in> zrhs" .. |
|
1056 |
hence some: "(SOME r. (Y, r) \<in> zrhs) = r" using Z_in dist_zrhs |
|
1057 |
by (auto simp:distinct_rhs_def) |
|
1058 |
hence "no_EMPTY_rhs (rhs_subst zrhs Y yrhs' r)" |
|
1059 |
using substor Y_in_zrhs history Z_in |
|
1060 |
by (rule_tac rhs_subst_holds_no_EMPTY, auto simp:ardenable_def) |
|
1061 |
thus ?thesis using X_Z True some |
|
1062 |
by (simp add:equas_subst_def equas_subst_f_def) |
|
1063 |
next |
|
1064 |
case False |
|
1065 |
hence "(X, xrhs) = (Z, zrhs)" using Z_in X_Z |
|
1066 |
by (simp add:equas_subst_f_def) |
|
1067 |
thus ?thesis using history Z_in |
|
1068 |
by (auto simp:ardenable_def) |
|
1069 |
qed |
|
1070 |
qed |
|
1071 |
||
1072 |
lemma equas_subst_f_holds_left_eq_right: |
|
1073 |
assumes substor: "Y = L rhs'" |
|
1074 |
and history: "\<forall>X xrhs. (X, xrhs) \<in> ES \<longrightarrow> distinct_rhs xrhs \<and> X = L xrhs" |
|
1075 |
and subst: "(X, xrhs) = equas_subst_f Y rhs' (Z, zrhs)" |
|
1076 |
and self_contained: "(Z, zrhs) \<in> ES" |
|
1077 |
shows "X = L xrhs" |
|
1078 |
proof (cases "\<exists> r. (Y, r) \<in> zrhs") |
|
1079 |
case True |
|
1080 |
from True obtain r where "(1)":"(Y, r) \<in> zrhs" .. |
|
1081 |
show ?thesis |
|
1082 |
proof - |
|
1083 |
from history self_contained |
|
1084 |
have dist: "distinct_rhs zrhs" by auto |
|
1085 |
hence "(SOME r. (Y, r) \<in> zrhs) = r" using self_contained "(1)" |
|
1086 |
using distinct_rhs_def by (auto intro:some_equality) |
|
1087 |
moreover have "L zrhs = L (rhs_subst zrhs Y rhs' r)" using substor dist "(1)" self_contained |
|
1088 |
by (rule_tac rhs_subst_prop1, auto simp:distinct_equas_rhs_def) |
|
1089 |
ultimately show ?thesis using subst history self_contained |
|
1090 |
by (auto simp:equas_subst_f_def split:if_splits) |
|
1091 |
qed |
|
1092 |
next |
|
1093 |
case False |
|
1094 |
thus ?thesis using history subst self_contained |
|
1095 |
by (auto simp:equas_subst_f_def) |
|
1096 |
qed |
|
1097 |
||
1098 |
lemma equas_subst_holds_left_eq_right: |
|
1099 |
assumes history: "\<forall>X xrhs. (X, xrhs) \<in> ES \<longrightarrow> ardenable (X, xrhs)" |
|
1100 |
and substor: "Y = L rhs'" |
|
1101 |
and X_in : "(X, xrhs) \<in> equas_subst ES Y yrhs'" |
|
1102 |
shows "\<forall>X xrhs. (X, xrhs) \<in> equas_subst ES Y rhs' \<longrightarrow> X = L xrhs" |
|
1103 |
apply (clarsimp simp add:equas_subst_def del_x_paired_def) |
|
1104 |
using substor |
|
1105 |
apply (drule_tac equas_subst_f_holds_left_eq_right) |
|
1106 |
using history |
|
1107 |
by (auto simp:ardenable_def) |
|
1108 |
||
1109 |
lemma equas_subst_holds_ardenable: |
|
1110 |
assumes substor: "Y = L yrhs'" |
|
1111 |
and history: "\<forall>X xrhs. (X, xrhs) \<in> ES \<longrightarrow> ardenable (X, xrhs)" |
|
1112 |
and X_in:"(X, xrhs) \<in> equas_subst ES Y yrhs'" |
|
1113 |
and dist': "distinct_rhs yrhs'" |
|
1114 |
and not_lambda: "Y \<noteq> {[]}" |
|
1115 |
shows "ardenable (X, xrhs)" |
|
1116 |
proof - |
|
1117 |
have "distinct_rhs xrhs" using history X_in dist' |
|
1118 |
by (auto dest:equas_subst_holds_distinct_rhs) |
|
1119 |
moreover have "no_EMPTY_rhs xrhs" using history X_in not_lambda |
|
1120 |
by (auto intro:equas_subst_holds_no_EMPTY) |
|
1121 |
moreover have "X = L xrhs" using history substor X_in |
|
1122 |
by (auto dest: equas_subst_holds_left_eq_right simp del:L_rhs.simps) |
|
1123 |
ultimately show ?thesis using ardenable_def by simp |
|
1124 |
qed |
|
1125 |
||
1126 |
lemma equas_subst_holds_cls_defined: |
|
1127 |
assumes X_in: "(X, xrhs) \<in> equas_subst ES Y yrhs'" |
|
1128 |
and Inv_ES: "Inv X' ES" |
|
1129 |
and subst: "(Y, yrhs) \<in> ES" |
|
1130 |
and cls_holds_but_Y: "rhs_eq_cls yrhs' = rhs_eq_cls yrhs - {Y}" |
|
1131 |
shows "rhs_eq_cls xrhs \<subseteq> insert {[]} (left_eq_cls (equas_subst ES Y yrhs'))" |
|
1132 |
proof- |
|
1133 |
have tac: "\<lbrakk> A \<subseteq> B; C \<subseteq> D; E \<subseteq> A \<union> B\<rbrakk> \<Longrightarrow> E \<subseteq> B \<union> D" by auto |
|
1134 |
from X_in have "\<exists> (Z, zrhs) \<in> ES. (X, xrhs) = equas_subst_f Y yrhs' (Z, zrhs)" |
|
1135 |
by (auto simp add:equas_subst_def del_x_paired_def) |
|
1136 |
then obtain Z zrhs where Z_in: "(Z, zrhs) \<in> ES" |
|
1137 |
and X_Z: "(X, xrhs) = equas_subst_f Y yrhs' (Z, zrhs)" by blast |
|
1138 |
hence "rhs_eq_cls zrhs \<subseteq> insert {[]} (left_eq_cls ES)" using Inv_ES |
|
1139 |
by (auto simp:Inv_def) |
|
1140 |
moreover have "rhs_eq_cls yrhs' \<subseteq> insert {[]} (left_eq_cls ES) - {Y}" |
|
1141 |
using Inv_ES subst cls_holds_but_Y |
|
1142 |
by (auto simp:Inv_def) |
|
1143 |
moreover have "rhs_eq_cls xrhs \<subseteq> rhs_eq_cls zrhs \<union> rhs_eq_cls yrhs' - {Y}" |
|
1144 |
using X_Z cls_holds_but_Y |
|
1145 |
apply (clarsimp simp add:equas_subst_f_def rhs_subst_def split:if_splits) |
|
1146 |
by (auto simp:rhs_eq_cls_def merge_rhs_def del_x_paired_def seq_rhs_r_def) |
|
1147 |
moreover have "left_eq_cls (equas_subst ES Y yrhs') = left_eq_cls ES - {Y}" using subst |
|
1148 |
by (auto simp: left_eq_cls_def equas_subst_def del_x_paired_def equas_subst_f_def |
|
1149 |
dest: equas_subst_f_del_no_other |
|
1150 |
split: if_splits) |
|
1151 |
ultimately show ?thesis by blast |
|
1152 |
qed |
|
1153 |
||
1154 |
lemma iteration_step: |
|
1155 |
assumes Inv_ES: "Inv X ES" |
|
1156 |
and not_T: "\<not> TCon ES" |
|
1157 |
shows "(\<exists> ES'. Inv X ES' \<and> (card ES', card ES) \<in> less_than)" |
|
1158 |
proof - |
|
1159 |
from Inv_ES not_T have another: "\<exists>Y yrhs. (Y, yrhs) \<in> ES \<and> X \<noteq> Y" unfolding Inv_def |
|
1160 |
by (clarify, rule_tac exist_another_equa[where X = X], auto) |
|
1161 |
then obtain Y yrhs where subst: "(Y, yrhs) \<in> ES" and not_X: " X \<noteq> Y" by blast |
|
1162 |
show ?thesis (is "\<exists> ES'. ?P ES'") |
|
1163 |
proof (cases "Y = {[]}") |
|
1164 |
case True |
|
1165 |
--"in this situation, we pick a \"\<lambda>\" equation, thus directly remove it from the equation-system" |
|
1166 |
have "?P (ES - {(Y, yrhs)})" |
|
1167 |
proof |
|
1168 |
show "Inv X (ES - {(Y, yrhs)})" using True not_X |
|
1169 |
by (simp add:Inv_ES Inv_mono_with_lambda) |
|
1170 |
next |
|
1171 |
show "(card (ES - {(Y, yrhs)}), card ES) \<in> less_than" using Inv_ES subst |
|
1172 |
by (auto elim:non_empty_card_prop[rule_format] simp:Inv_def) |
|
1173 |
qed |
|
1174 |
thus ?thesis by blast |
|
1175 |
next |
|
1176 |
case False |
|
1177 |
--"in this situation, we pick a equation and using ardenable to get a rhs without itself in it, then use equas_subst to form a new equation-system" |
|
1178 |
hence "\<exists> yrhs'. Y = L yrhs' \<and> distinct_rhs yrhs' \<and> rhs_eq_cls yrhs' = rhs_eq_cls yrhs - {Y}" using subst Inv_ES |
|
1179 |
by (auto intro:ardenable_prop simp add:Inv_def simp del:L_rhs.simps) |
|
1180 |
then obtain yrhs' where Y'_l_eq_r: "Y = L yrhs'" |
|
1181 |
and dist_Y': "distinct_rhs yrhs'" |
|
1182 |
and cls_holds_but_Y: "rhs_eq_cls yrhs' = rhs_eq_cls yrhs - {Y}" by blast |
|
1183 |
hence "?P (equas_subst ES Y yrhs')" |
|
1184 |
proof - |
|
1185 |
have finite_del: "\<And> S x. finite S \<Longrightarrow> finite (del_x_paired S x)" |
|
1186 |
apply (rule_tac A = "del_x_paired S x" in finite_subset) |
|
1187 |
by (auto simp:del_x_paired_def) |
|
1188 |
have "finite (equas_subst ES Y yrhs')" using Inv_ES |
|
1189 |
by (auto intro!:finite_del simp:equas_subst_def Inv_def) |
|
1190 |
moreover have "\<exists>rhs. (X, rhs) \<in> equas_subst ES Y yrhs'" using Inv_ES not_X |
|
1191 |
by (auto intro:equas_subst_del_no_other simp:Inv_def) |
|
1192 |
moreover have "distinct_equas (equas_subst ES Y yrhs')" using Inv_ES |
|
1193 |
by (auto intro:equas_subst_holds_distinct simp:Inv_def) |
|
1194 |
moreover have "\<forall>X xrhs. (X, xrhs) \<in> equas_subst ES Y yrhs' \<longrightarrow> ardenable (X, xrhs)" |
|
1195 |
using Inv_ES dist_Y' False Y'_l_eq_r |
|
1196 |
apply (clarsimp simp:Inv_def) |
|
1197 |
by (rule equas_subst_holds_ardenable, simp_all) |
|
1198 |
moreover have "\<forall>X xrhs. (X, xrhs) \<in> equas_subst ES Y yrhs' \<longrightarrow> X \<noteq> {}" using Inv_ES |
|
1199 |
by (clarsimp simp:equas_subst_def Inv_def del_x_paired_def equas_subst_f_def split:if_splits, auto) |
|
1200 |
moreover have "\<forall>X xrhs. (X, xrhs) \<in> equas_subst ES Y yrhs' \<longrightarrow> |
|
1201 |
rhs_eq_cls xrhs \<subseteq> insert {[]} (left_eq_cls (equas_subst ES Y yrhs'))" |
|
1202 |
using Inv_ES subst cls_holds_but_Y |
|
1203 |
apply (rule_tac impI | rule_tac allI)+ |
|
1204 |
by (erule equas_subst_holds_cls_defined, auto) |
|
1205 |
moreover have "(card (equas_subst ES Y yrhs'), card ES) \<in> less_than"using Inv_ES subst |
|
1206 |
by (simp add:equas_subst_card_less Inv_def) |
|
1207 |
ultimately show "?P (equas_subst ES Y yrhs')" by (auto simp:Inv_def) |
|
1208 |
qed |
|
1209 |
thus ?thesis by blast |
|
1210 |
qed |
|
1211 |
qed |
|
1212 |
||
1213 |
(* ****************************** END: proving every equation-system's iteration step satisfies Inv ******************************* *) |
|
1214 |
||
1215 |
lemma iteration_conc: |
|
1216 |
assumes history: "Inv X ES" |
|
1217 |
shows "\<exists> ES'. Inv X ES' \<and> TCon ES'" (is "\<exists> ES'. ?P ES'") |
|
1218 |
proof (cases "TCon ES") |
|
1219 |
case True |
|
1220 |
hence "?P ES" using history by simp |
|
1221 |
thus ?thesis by blast |
|
1222 |
next |
|
1223 |
case False |
|
1224 |
thus ?thesis using history iteration_step |
|
1225 |
by (rule_tac f = card in wf_iter, simp_all) |
|
1226 |
qed |
|
1227 |
||
1228 |
lemma eqset_imp_iff': "A = B \<Longrightarrow> \<forall> x. x \<in> A \<longleftrightarrow> x \<in> B" |
|
1229 |
apply (auto simp:mem_def) |
|
1230 |
done |
|
1231 |
||
1232 |
lemma set_cases2: |
|
1233 |
"\<lbrakk>(A = {} \<Longrightarrow> R A); \<And> x. (A = {x}) \<Longrightarrow> R A; \<And> x y. \<lbrakk>x \<noteq> y; x \<in> A; y \<in> A\<rbrakk> \<Longrightarrow> R A\<rbrakk> \<Longrightarrow> R A" |
|
1234 |
apply (case_tac "A = {}", simp) |
|
1235 |
by (case_tac "\<exists> x. A = {x}", clarsimp, blast) |
|
1236 |
||
1237 |
lemma rhs_aux:"\<lbrakk>distinct_rhs rhs; {Y. \<exists>r. (Y, r) \<in> rhs} = {X}\<rbrakk> \<Longrightarrow> (\<exists>r. rhs = {(X, r)})" |
|
1238 |
apply (rule_tac A = rhs in set_cases2, simp) |
|
1239 |
apply (drule_tac x = X in eqset_imp_iff, clarsimp) |
|
1240 |
apply (drule eqset_imp_iff',clarsimp) |
|
1241 |
apply (frule_tac x = a in spec, drule_tac x = aa in spec) |
|
1242 |
by (auto simp:distinct_rhs_def) |
|
1243 |
||
1244 |
lemma every_eqcl_has_reg: |
|
1245 |
assumes finite_CS: "finite (UNIV Quo Lang)" |
|
1246 |
and X_in_CS: "X \<in> (UNIV Quo Lang)" |
|
1247 |
shows "\<exists> (reg::rexp). L reg = X" (is "\<exists> r. ?E r") |
|
1248 |
proof- |
|
1249 |
have "\<exists>ES'. Inv X ES' \<and> TCon ES'" using finite_CS X_in_CS |
|
1250 |
by (auto intro:init_ES_satisfy_Inv iteration_conc) |
|
1251 |
then obtain ES' where Inv_ES': "Inv X ES'" |
|
1252 |
and TCon_ES': "TCon ES'" by blast |
|
1253 |
from Inv_ES' TCon_ES' |
|
1254 |
have "\<exists> rhs. ES' = {(X, rhs)}" |
|
1255 |
apply (clarsimp simp:Inv_def TCon_def) |
|
1256 |
apply (rule_tac x = rhs in exI) |
|
1257 |
by (auto dest!:card_Suc_Diff1 simp:card_eq_0_iff) |
|
1258 |
then obtain rhs where ES'_single_equa: "ES' = {(X, rhs)}" .. |
|
1259 |
hence X_ardenable: "ardenable (X, rhs)" using Inv_ES' |
|
1260 |
by (simp add:Inv_def) |
|
1261 |
||
1262 |
from X_ardenable have X_l_eq_r: "X = L rhs" |
|
1263 |
by (simp add:ardenable_def) |
|
1264 |
hence rhs_not_empty: "rhs \<noteq> {}" using Inv_ES' ES'_single_equa |
|
1265 |
by (auto simp:Inv_def ardenable_def) |
|
1266 |
have rhs_eq_cls: "rhs_eq_cls rhs \<subseteq> {X, {[]}}" |
|
1267 |
using Inv_ES' ES'_single_equa |
|
1268 |
by (auto simp:Inv_def ardenable_def left_eq_cls_def) |
|
1269 |
have X_not_empty: "X \<noteq> {}" using Inv_ES' ES'_single_equa |
|
1270 |
by (auto simp:Inv_def) |
|
1271 |
show ?thesis |
|
1272 |
proof (cases "X = {[]}") |
|
1273 |
case True |
|
1274 |
hence "?E EMPTY" by (simp) |
|
1275 |
thus ?thesis by blast |
|
1276 |
next |
|
1277 |
case False with X_ardenable |
|
1278 |
have "\<exists> rhs'. X = L rhs' \<and> rhs_eq_cls rhs' = rhs_eq_cls rhs - {X} \<and> distinct_rhs rhs'" |
|
1279 |
by (drule_tac ardenable_prop, auto) |
|
1280 |
then obtain rhs' where X_eq_rhs': "X = L rhs'" |
|
1281 |
and rhs'_eq_cls: "rhs_eq_cls rhs' = rhs_eq_cls rhs - {X}" |
|
1282 |
and rhs'_dist : "distinct_rhs rhs'" by blast |
|
1283 |
have "rhs_eq_cls rhs' \<subseteq> {{[]}}" using rhs_eq_cls False rhs'_eq_cls rhs_not_empty |
|
1284 |
by blast |
|
1285 |
hence "rhs_eq_cls rhs' = {{[]}}" using X_not_empty X_eq_rhs' |
|
1286 |
by (auto simp:rhs_eq_cls_def) |
|
1287 |
hence "\<exists> r. rhs' = {({[]}, r)}" using rhs'_dist |
|
1288 |
by (auto intro:rhs_aux simp:rhs_eq_cls_def) |
|
1289 |
then obtain r where "rhs' = {({[]}, r)}" .. |
|
1290 |
hence "?E r" using X_eq_rhs' by (auto simp add:lang_seq_def) |
|
1291 |
thus ?thesis by blast |
|
1292 |
qed |
|
1293 |
qed |
|
1294 |
||
1295 |
theorem myhill_nerode: |
|
1296 |
assumes finite_CS: "finite (UNIV Quo Lang)" |
|
1297 |
shows "\<exists> (reg::rexp). Lang = L reg" (is "\<exists> r. ?P r") |
|
1298 |
proof - |
|
1299 |
have has_r_each: "\<forall>C\<in>{X \<in> UNIV Quo Lang. \<forall>x\<in>X. x \<in> Lang}. \<exists>(r::rexp). C = L r" using finite_CS |
|
1300 |
by (auto dest:every_eqcl_has_reg) |
|
1301 |
have "\<exists> (rS::rexp set). finite rS \<and> |
|
1302 |
(\<forall> C \<in> {X \<in> UNIV Quo Lang. \<forall>x\<in>X. x \<in> Lang}. \<exists> r \<in> rS. C = L r) \<and> |
|
1303 |
(\<forall> r \<in> rS. \<exists> C \<in> {X \<in> UNIV Quo Lang. \<forall>x\<in>X. x \<in> Lang}. C = L r)" |
|
1304 |
(is "\<exists> rS. ?Q rS") |
|
1305 |
proof- |
|
1306 |
have "\<And> C. C \<in> {X \<in> UNIV Quo Lang. \<forall>x\<in>X. x \<in> Lang} \<Longrightarrow> C = L (SOME (ra::rexp). C = L ra)" |
|
1307 |
using has_r_each |
|
1308 |
apply (erule_tac x = C in ballE, erule_tac exE) |
|
1309 |
by (rule_tac a = r in someI2, simp+) |
|
1310 |
hence "?Q ((\<lambda> C. SOME r. C = L r) ` {X \<in> UNIV Quo Lang. \<forall>x\<in>X. x \<in> Lang})" using has_r_each |
|
1311 |
using finite_CS by auto |
|
1312 |
thus ?thesis by blast |
|
1313 |
qed |
|
1314 |
then obtain rS where finite_rS : "finite rS" |
|
1315 |
and has_r_each': "\<forall> C \<in> {X \<in> UNIV Quo Lang. \<forall>x\<in>X. x \<in> Lang}. \<exists> r \<in> (rS::rexp set). C = L r" |
|
1316 |
and has_cl_each: "\<forall> r \<in> (rS::rexp set). \<exists> C \<in> {X \<in> UNIV Quo Lang. \<forall>x\<in>X. x \<in> Lang}. C = L r" by blast |
|
1317 |
have "?P (folds ALT NULL rS)" |
|
1318 |
proof |
|
1319 |
show "Lang \<subseteq> L (folds ALT NULL rS)" using finite_rS lang_eqs_union_of_eqcls[of Lang] has_r_each' |
|
1320 |
apply (clarsimp simp:fold_alt_null_eqs) by blast |
|
1321 |
next |
|
1322 |
show "L (folds ALT NULL rS) \<subseteq> Lang" using finite_rS lang_eqs_union_of_eqcls[of Lang] has_cl_each |
|
1323 |
by (clarsimp simp:fold_alt_null_eqs) |
|
1324 |
qed |
|
1325 |
thus ?thesis by blast |
|
1326 |
qed |
|
1327 |
||
1328 |
end |