author | urbanc |
Tue, 31 May 2011 20:32:49 +0000 | |
changeset 165 | b04cc5e4e84c |
parent 162 | e93760534354 |
child 166 | 7743d2ad71d1 |
permissions | -rw-r--r-- |
42 | 1 |
theory Myhill_1 |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
2 |
imports Main Folds Regular |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
3 |
"~~/src/HOL/Library/While_Combinator" |
42 | 4 |
begin |
5 |
||
86 | 6 |
section {* Direction @{text "finite partition \<Rightarrow> regular language"} *} |
7 |
||
75 | 8 |
lemma Pair_Collect[simp]: |
48 | 9 |
shows "(x, y) \<in> {(x, y). P x y} \<longleftrightarrow> P x y" |
10 |
by simp |
|
11 |
||
86 | 12 |
text {* Myhill-Nerode relation *} |
13 |
||
48 | 14 |
definition |
71 | 15 |
str_eq_rel :: "lang \<Rightarrow> (string \<times> string) set" ("\<approx>_" [100] 100) |
48 | 16 |
where |
70 | 17 |
"\<approx>A \<equiv> {(x, y). (\<forall>z. x @ z \<in> A \<longleftrightarrow> y @ z \<in> A)}" |
48 | 18 |
|
19 |
definition |
|
71 | 20 |
finals :: "lang \<Rightarrow> lang set" |
21 |
where |
|
108 | 22 |
"finals A \<equiv> {\<approx>A `` {s} | s . s \<in> A}" |
48 | 23 |
|
24 |
lemma lang_is_union_of_finals: |
|
70 | 25 |
shows "A = \<Union> finals A" |
26 |
unfolding finals_def |
|
27 |
unfolding Image_def |
|
28 |
unfolding str_eq_rel_def |
|
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
29 |
by (auto) (metis append_Nil2) |
70 | 30 |
|
79 | 31 |
lemma finals_in_partitions: |
32 |
shows "finals A \<subseteq> (UNIV // \<approx>A)" |
|
94 | 33 |
unfolding finals_def quotient_def |
76 | 34 |
by auto |
35 |
||
86 | 36 |
section {* Equational systems *} |
42 | 37 |
|
89 | 38 |
text {* The two kinds of terms in the rhs of equations. *} |
39 |
||
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
40 |
datatype rhs_trm = |
86 | 41 |
Lam "rexp" (* Lambda-marker *) |
70 | 42 |
| Trn "lang" "rexp" (* Transition *) |
43 |
||
42 | 44 |
|
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
45 |
overloading L_rhs_trm \<equiv> "L:: rhs_trm \<Rightarrow> lang" |
42 | 46 |
begin |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
47 |
fun L_rhs_trm:: "rhs_trm \<Rightarrow> lang" |
42 | 48 |
where |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
49 |
"L_rhs_trm (Lam r) = L r" |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
50 |
| "L_rhs_trm (Trn X r) = X ;; L r" |
42 | 51 |
end |
52 |
||
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
53 |
overloading L_rhs \<equiv> "L:: rhs_trm set \<Rightarrow> lang" |
42 | 54 |
begin |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
55 |
fun L_rhs:: "rhs_trm set \<Rightarrow> lang" |
70 | 56 |
where |
57 |
"L_rhs rhs = \<Union> (L ` rhs)" |
|
42 | 58 |
end |
59 |
||
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
60 |
lemma L_rhs_set: |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
61 |
shows "L {Trn X r | r. P r} = \<Union>{L (Trn X r) | r. P r}" |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
62 |
by (auto simp del: L_rhs_trm.simps) |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
63 |
|
96 | 64 |
lemma L_rhs_union_distrib: |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
65 |
fixes A B::"rhs_trm set" |
96 | 66 |
shows "L A \<union> L B = L (A \<union> B)" |
67 |
by simp |
|
68 |
||
69 |
||
70 |
||
86 | 71 |
text {* Transitions between equivalence classes *} |
71 | 72 |
|
73 |
definition |
|
92 | 74 |
transition :: "lang \<Rightarrow> char \<Rightarrow> lang \<Rightarrow> bool" ("_ \<Turnstile>_\<Rightarrow>_" [100,100,100] 100) |
71 | 75 |
where |
92 | 76 |
"Y \<Turnstile>c\<Rightarrow> X \<equiv> Y ;; {[c]} \<subseteq> X" |
42 | 77 |
|
86 | 78 |
text {* Initial equational system *} |
79 |
||
42 | 80 |
definition |
96 | 81 |
"Init_rhs CS X \<equiv> |
42 | 82 |
if ([] \<in> X) then |
92 | 83 |
{Lam EMPTY} \<union> {Trn Y (CHAR c) | Y c. Y \<in> CS \<and> Y \<Turnstile>c\<Rightarrow> X} |
42 | 84 |
else |
92 | 85 |
{Trn Y (CHAR c)| Y c. Y \<in> CS \<and> Y \<Turnstile>c\<Rightarrow> X}" |
42 | 86 |
|
86 | 87 |
definition |
96 | 88 |
"Init CS \<equiv> {(X, Init_rhs CS X) | X. X \<in> CS}" |
75 | 89 |
|
90 |
||
86 | 91 |
section {* Arden Operation on equations *} |
42 | 92 |
|
70 | 93 |
fun |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
94 |
Append_rexp :: "rexp \<Rightarrow> rhs_trm \<Rightarrow> rhs_trm" |
42 | 95 |
where |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
96 |
"Append_rexp r (Lam rexp) = Lam (SEQ rexp r)" |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
97 |
| "Append_rexp r (Trn X rexp) = Trn X (SEQ rexp r)" |
42 | 98 |
|
99 |
||
100 |
definition |
|
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
101 |
"Append_rexp_rhs rhs rexp \<equiv> (Append_rexp rexp) ` rhs" |
42 | 102 |
|
86 | 103 |
definition |
94 | 104 |
"Arden X rhs \<equiv> |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
105 |
Append_rexp_rhs (rhs - {Trn X r | r. Trn X r \<in> rhs}) (STAR (\<Uplus> {r. Trn X r \<in> rhs}))" |
86 | 106 |
|
107 |
||
108 |
section {* Substitution Operation on equations *} |
|
109 |
||
42 | 110 |
definition |
94 | 111 |
"Subst rhs X xrhs \<equiv> |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
112 |
(rhs - {Trn X r | r. Trn X r \<in> rhs}) \<union> (Append_rexp_rhs xrhs (\<Uplus> {r. Trn X r \<in> rhs}))" |
97 | 113 |
|
42 | 114 |
definition |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
115 |
Subst_all :: "(lang \<times> rhs_trm set) set \<Rightarrow> lang \<Rightarrow> rhs_trm set \<Rightarrow> (lang \<times> rhs_trm set) set" |
97 | 116 |
where |
94 | 117 |
"Subst_all ES X xrhs \<equiv> {(Y, Subst yrhs X xrhs) | Y yrhs. (Y, yrhs) \<in> ES}" |
86 | 118 |
|
91 | 119 |
definition |
96 | 120 |
"Remove ES X xrhs \<equiv> |
121 |
Subst_all (ES - {(X, xrhs)}) X (Arden X xrhs)" |
|
122 |
||
123 |
||
124 |
section {* While-combinator *} |
|
91 | 125 |
|
126 |
definition |
|
96 | 127 |
"Iter X ES \<equiv> (let (Y, yrhs) = SOME (Y, yrhs). (Y, yrhs) \<in> ES \<and> X \<noteq> Y |
95 | 128 |
in Remove ES Y yrhs)" |
42 | 129 |
|
97 | 130 |
lemma IterI2: |
131 |
assumes "(Y, yrhs) \<in> ES" |
|
132 |
and "X \<noteq> Y" |
|
133 |
and "\<And>Y yrhs. \<lbrakk>(Y, yrhs) \<in> ES; X \<noteq> Y\<rbrakk> \<Longrightarrow> Q (Remove ES Y yrhs)" |
|
134 |
shows "Q (Iter X ES)" |
|
135 |
unfolding Iter_def using assms |
|
136 |
by (rule_tac a="(Y, yrhs)" in someI2) (auto) |
|
137 |
||
138 |
abbreviation |
|
101 | 139 |
"Cond ES \<equiv> card ES \<noteq> 1" |
97 | 140 |
|
91 | 141 |
definition |
101 | 142 |
"Solve X ES \<equiv> while Cond (Iter X) ES" |
97 | 143 |
|
86 | 144 |
|
145 |
section {* Invariants *} |
|
146 |
||
42 | 147 |
definition |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
148 |
"distinctness ES \<equiv> |
86 | 149 |
\<forall> X rhs rhs'. (X, rhs) \<in> ES \<and> (X, rhs') \<in> ES \<longrightarrow> rhs = rhs'" |
70 | 150 |
|
42 | 151 |
definition |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
152 |
"soundness ES \<equiv> \<forall>(X, rhs) \<in> ES. X = L rhs" |
70 | 153 |
|
42 | 154 |
definition |
110 | 155 |
"ardenable rhs \<equiv> (\<forall> Y r. Trn Y r \<in> rhs \<longrightarrow> [] \<notin> L r)" |
42 | 156 |
|
157 |
definition |
|
110 | 158 |
"ardenable_all ES \<equiv> \<forall>(X, rhs) \<in> ES. ardenable rhs" |
42 | 159 |
|
160 |
definition |
|
103 | 161 |
"finite_rhs ES \<equiv> \<forall>(X, rhs) \<in> ES. finite rhs" |
162 |
||
163 |
lemma finite_rhs_def2: |
|
164 |
"finite_rhs ES = (\<forall> X rhs. (X, rhs) \<in> ES \<longrightarrow> finite rhs)" |
|
165 |
unfolding finite_rhs_def by auto |
|
42 | 166 |
|
167 |
definition |
|
104 | 168 |
"rhss rhs \<equiv> {X | X r. Trn X r \<in> rhs}" |
42 | 169 |
|
170 |
definition |
|
103 | 171 |
"lhss ES \<equiv> {Y | Y yrhs. (Y, yrhs) \<in> ES}" |
42 | 172 |
|
173 |
definition |
|
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
174 |
"validity ES \<equiv> \<forall>(X, rhs) \<in> ES. rhss rhs \<subseteq> lhss ES" |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
175 |
|
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
176 |
lemma rhss_union_distrib: |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
177 |
shows "rhss (A \<union> B) = rhss A \<union> rhss B" |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
178 |
by (auto simp add: rhss_def) |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
179 |
|
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
180 |
lemma lhss_union_distrib: |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
181 |
shows "lhss (A \<union> B) = lhss A \<union> lhss B" |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
182 |
by (auto simp add: lhss_def) |
42 | 183 |
|
184 |
||
185 |
definition |
|
103 | 186 |
"invariant ES \<equiv> finite ES |
187 |
\<and> finite_rhs ES |
|
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
188 |
\<and> soundness ES |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
189 |
\<and> distinctness ES |
110 | 190 |
\<and> ardenable_all ES |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
191 |
\<and> validity ES" |
42 | 192 |
|
96 | 193 |
|
194 |
lemma invariantI: |
|
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
195 |
assumes "soundness ES" "finite ES" "distinctness ES" "ardenable_all ES" |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
196 |
"finite_rhs ES" "validity ES" |
96 | 197 |
shows "invariant ES" |
198 |
using assms by (simp add: invariant_def) |
|
199 |
||
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
200 |
|
42 | 201 |
subsection {* The proof of this direction *} |
202 |
||
79 | 203 |
lemma finite_Trn: |
204 |
assumes fin: "finite rhs" |
|
205 |
shows "finite {r. Trn Y r \<in> rhs}" |
|
206 |
proof - |
|
207 |
have "finite {Trn Y r | Y r. Trn Y r \<in> rhs}" |
|
208 |
by (rule rev_finite_subset[OF fin]) (auto) |
|
81 | 209 |
then have "finite ((\<lambda>(Y, r). Trn Y r) ` {(Y, r) | Y r. Trn Y r \<in> rhs})" |
210 |
by (simp add: image_Collect) |
|
211 |
then have "finite {(Y, r) | Y r. Trn Y r \<in> rhs}" |
|
212 |
by (erule_tac finite_imageD) (simp add: inj_on_def) |
|
79 | 213 |
then show "finite {r. Trn Y r \<in> rhs}" |
81 | 214 |
by (erule_tac f="snd" in finite_surj) (auto simp add: image_def) |
79 | 215 |
qed |
216 |
||
217 |
lemma finite_Lam: |
|
96 | 218 |
assumes fin: "finite rhs" |
79 | 219 |
shows "finite {r. Lam r \<in> rhs}" |
220 |
proof - |
|
221 |
have "finite {Lam r | r. Lam r \<in> rhs}" |
|
222 |
by (rule rev_finite_subset[OF fin]) (auto) |
|
223 |
then show "finite {r. Lam r \<in> rhs}" |
|
81 | 224 |
apply(simp add: image_Collect[symmetric]) |
225 |
apply(erule finite_imageD) |
|
226 |
apply(auto simp add: inj_on_def) |
|
79 | 227 |
done |
42 | 228 |
qed |
229 |
||
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
230 |
lemma rhs_trm_soundness: |
42 | 231 |
assumes finite:"finite rhs" |
79 | 232 |
shows "L ({Trn X r| r. Trn X r \<in> rhs}) = X ;; (L (\<Uplus>{r. Trn X r \<in> rhs}))" |
42 | 233 |
proof - |
79 | 234 |
have "finite {r. Trn X r \<in> rhs}" |
235 |
by (rule finite_Trn[OF finite]) |
|
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
236 |
then show "L ({Trn X r| r. Trn X r \<in> rhs}) = X ;; (L (\<Uplus>{r. Trn X r \<in> rhs}))" |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
237 |
by (simp only: L_rhs_set L_rhs_trm.simps) (auto simp add: Seq_def) |
42 | 238 |
qed |
239 |
||
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
240 |
lemma lang_of_append_rexp: |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
241 |
"L (Append_rexp r rhs_trm) = L rhs_trm ;; L r" |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
242 |
by (induct rule: Append_rexp.induct) |
96 | 243 |
(auto simp add: seq_assoc) |
42 | 244 |
|
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
245 |
lemma lang_of_append_rexp_rhs: |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
246 |
"L (Append_rexp_rhs rhs r) = L rhs ;; L r" |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
247 |
unfolding Append_rexp_rhs_def |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
248 |
by (auto simp add: Seq_def lang_of_append_rexp) |
42 | 249 |
|
250 |
||
251 |
||
252 |
subsubsection {* Intialization *} |
|
253 |
||
254 |
lemma defined_by_str: |
|
100 | 255 |
assumes "s \<in> X" "X \<in> UNIV // \<approx>A" |
256 |
shows "X = \<approx>A `` {s}" |
|
257 |
using assms |
|
258 |
unfolding quotient_def Image_def str_eq_rel_def |
|
259 |
by auto |
|
42 | 260 |
|
261 |
lemma every_eqclass_has_transition: |
|
262 |
assumes has_str: "s @ [c] \<in> X" |
|
100 | 263 |
and in_CS: "X \<in> UNIV // \<approx>A" |
264 |
obtains Y where "Y \<in> UNIV // \<approx>A" and "Y ;; {[c]} \<subseteq> X" and "s \<in> Y" |
|
42 | 265 |
proof - |
100 | 266 |
def Y \<equiv> "\<approx>A `` {s}" |
267 |
have "Y \<in> UNIV // \<approx>A" |
|
42 | 268 |
unfolding Y_def quotient_def by auto |
269 |
moreover |
|
100 | 270 |
have "X = \<approx>A `` {s @ [c]}" |
42 | 271 |
using has_str in_CS defined_by_str by blast |
272 |
then have "Y ;; {[c]} \<subseteq> X" |
|
273 |
unfolding Y_def Image_def Seq_def |
|
274 |
unfolding str_eq_rel_def |
|
275 |
by clarsimp |
|
276 |
moreover |
|
277 |
have "s \<in> Y" unfolding Y_def |
|
278 |
unfolding Image_def str_eq_rel_def by simp |
|
100 | 279 |
ultimately show thesis using that by blast |
42 | 280 |
qed |
281 |
||
282 |
lemma l_eq_r_in_eqs: |
|
100 | 283 |
assumes X_in_eqs: "(X, rhs) \<in> Init (UNIV // \<approx>A)" |
284 |
shows "X = L rhs" |
|
42 | 285 |
proof |
100 | 286 |
show "X \<subseteq> L rhs" |
42 | 287 |
proof |
288 |
fix x |
|
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
289 |
assume in_X: "x \<in> X" |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
290 |
{ assume empty: "x = []" |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
291 |
then have "x \<in> L rhs" using X_in_eqs in_X |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
292 |
unfolding Init_def Init_rhs_def |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
293 |
by auto |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
294 |
} |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
295 |
moreover |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
296 |
{ assume not_empty: "x \<noteq> []" |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
297 |
then obtain s c where decom: "x = s @ [c]" |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
298 |
using rev_cases by blast |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
299 |
have "X \<in> UNIV // \<approx>A" using X_in_eqs unfolding Init_def by auto |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
300 |
then obtain Y where "Y \<in> UNIV // \<approx>A" "Y ;; {[c]} \<subseteq> X" "s \<in> Y" |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
301 |
using decom in_X every_eqclass_has_transition by blast |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
302 |
then have "x \<in> L {Trn Y (CHAR c)| Y c. Y \<in> UNIV // \<approx>A \<and> Y \<Turnstile>c\<Rightarrow> X}" |
71 | 303 |
unfolding transition_def |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
304 |
using decom by (force simp add: Seq_def) |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
305 |
then have "x \<in> L rhs" using X_in_eqs in_X |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
306 |
unfolding Init_def Init_rhs_def by simp |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
307 |
} |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
308 |
ultimately show "x \<in> L rhs" by blast |
42 | 309 |
qed |
310 |
next |
|
100 | 311 |
show "L rhs \<subseteq> X" using X_in_eqs |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
312 |
unfolding Init_def Init_rhs_def transition_def |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
313 |
by auto |
42 | 314 |
qed |
315 |
||
100 | 316 |
lemma test: |
317 |
assumes X_in_eqs: "(X, rhs) \<in> Init (UNIV // \<approx>A)" |
|
318 |
shows "X = \<Union> (L ` rhs)" |
|
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
319 |
using assms l_eq_r_in_eqs by (simp) |
100 | 320 |
|
96 | 321 |
lemma finite_Init_rhs: |
42 | 322 |
assumes finite: "finite CS" |
96 | 323 |
shows "finite (Init_rhs CS X)" |
42 | 324 |
proof- |
105 | 325 |
def S \<equiv> "{(Y, c)| Y c. Y \<in> CS \<and> Y ;; {[c]} \<subseteq> X}" |
326 |
def h \<equiv> "\<lambda> (Y, c). Trn Y (CHAR c)" |
|
327 |
have "finite (CS \<times> (UNIV::char set))" using finite by auto |
|
328 |
then have "finite S" using S_def |
|
329 |
by (rule_tac B = "CS \<times> UNIV" in finite_subset) (auto) |
|
330 |
moreover have "{Trn Y (CHAR c) |Y c. Y \<in> CS \<and> Y ;; {[c]} \<subseteq> X} = h ` S" |
|
331 |
unfolding S_def h_def image_def by auto |
|
332 |
ultimately |
|
333 |
have "finite {Trn Y (CHAR c) |Y c. Y \<in> CS \<and> Y ;; {[c]} \<subseteq> X}" by auto |
|
334 |
then show "finite (Init_rhs CS X)" unfolding Init_rhs_def transition_def by simp |
|
42 | 335 |
qed |
336 |
||
96 | 337 |
lemma Init_ES_satisfies_invariant: |
338 |
assumes finite_CS: "finite (UNIV // \<approx>A)" |
|
339 |
shows "invariant (Init (UNIV // \<approx>A))" |
|
340 |
proof (rule invariantI) |
|
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
341 |
show "soundness (Init (UNIV // \<approx>A))" |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
342 |
unfolding soundness_def |
97 | 343 |
using l_eq_r_in_eqs by auto |
96 | 344 |
show "finite (Init (UNIV // \<approx>A))" using finite_CS |
345 |
unfolding Init_def by simp |
|
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
346 |
show "distinctness (Init (UNIV // \<approx>A))" |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
347 |
unfolding distinctness_def Init_def by simp |
110 | 348 |
show "ardenable_all (Init (UNIV // \<approx>A))" |
349 |
unfolding ardenable_all_def Init_def Init_rhs_def ardenable_def |
|
103 | 350 |
by auto |
96 | 351 |
show "finite_rhs (Init (UNIV // \<approx>A))" |
352 |
using finite_Init_rhs[OF finite_CS] |
|
353 |
unfolding finite_rhs_def Init_def by auto |
|
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
354 |
show "validity (Init (UNIV // \<approx>A))" |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
355 |
unfolding validity_def Init_def Init_rhs_def rhss_def lhss_def |
96 | 356 |
by auto |
42 | 357 |
qed |
358 |
||
91 | 359 |
subsubsection {* Interation step *} |
42 | 360 |
|
94 | 361 |
lemma Arden_keeps_eq: |
42 | 362 |
assumes l_eq_r: "X = L rhs" |
110 | 363 |
and not_empty: "ardenable rhs" |
42 | 364 |
and finite: "finite rhs" |
94 | 365 |
shows "X = L (Arden X rhs)" |
42 | 366 |
proof - |
79 | 367 |
def A \<equiv> "L (\<Uplus>{r. Trn X r \<in> rhs})" |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
368 |
def b \<equiv> "{Trn X r | r. Trn X r \<in> rhs}" |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
369 |
def B \<equiv> "L (rhs - b)" |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
370 |
have not_empty2: "[] \<notin> A" |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
371 |
using finite_Trn[OF finite] not_empty |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
372 |
unfolding A_def ardenable_def by simp |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
373 |
have "X = L rhs" using l_eq_r by simp |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
374 |
also have "\<dots> = L (b \<union> (rhs - b))" unfolding b_def by auto |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
375 |
also have "\<dots> = L b \<union> B" unfolding B_def by (simp only: L_rhs_union_distrib) |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
376 |
also have "\<dots> = X ;; A \<union> B" |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
377 |
unfolding b_def |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
378 |
unfolding rhs_trm_soundness[OF finite] |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
379 |
unfolding A_def |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
380 |
by blast |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
381 |
finally have "X = X ;; A \<union> B" . |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
382 |
then have "X = B ;; A\<star>" |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
383 |
by (simp add: arden[OF not_empty2]) |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
384 |
also have "\<dots> = L (Arden X rhs)" |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
385 |
unfolding Arden_def A_def B_def b_def |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
386 |
by (simp only: lang_of_append_rexp_rhs L_rexp.simps) |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
387 |
finally show "X = L (Arden X rhs)" by simp |
42 | 388 |
qed |
389 |
||
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
390 |
lemma Append_keeps_finite: |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
391 |
"finite rhs \<Longrightarrow> finite (Append_rexp_rhs rhs r)" |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
392 |
by (auto simp:Append_rexp_rhs_def) |
42 | 393 |
|
94 | 394 |
lemma Arden_keeps_finite: |
395 |
"finite rhs \<Longrightarrow> finite (Arden X rhs)" |
|
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
396 |
by (auto simp:Arden_def Append_keeps_finite) |
42 | 397 |
|
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
398 |
lemma Append_keeps_nonempty: |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
399 |
"ardenable rhs \<Longrightarrow> ardenable (Append_rexp_rhs rhs r)" |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
400 |
apply (auto simp:ardenable_def Append_rexp_rhs_def) |
42 | 401 |
by (case_tac x, auto simp:Seq_def) |
402 |
||
403 |
lemma nonempty_set_sub: |
|
110 | 404 |
"ardenable rhs \<Longrightarrow> ardenable (rhs - A)" |
405 |
by (auto simp:ardenable_def) |
|
42 | 406 |
|
407 |
lemma nonempty_set_union: |
|
110 | 408 |
"\<lbrakk>ardenable rhs; ardenable rhs'\<rbrakk> \<Longrightarrow> ardenable (rhs \<union> rhs')" |
409 |
by (auto simp:ardenable_def) |
|
42 | 410 |
|
94 | 411 |
lemma Arden_keeps_nonempty: |
110 | 412 |
"ardenable rhs \<Longrightarrow> ardenable (Arden X rhs)" |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
413 |
by (simp only:Arden_def Append_keeps_nonempty nonempty_set_sub) |
42 | 414 |
|
415 |
||
94 | 416 |
lemma Subst_keeps_nonempty: |
110 | 417 |
"\<lbrakk>ardenable rhs; ardenable xrhs\<rbrakk> \<Longrightarrow> ardenable (Subst rhs X xrhs)" |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
418 |
by (simp only: Subst_def Append_keeps_nonempty nonempty_set_union nonempty_set_sub) |
42 | 419 |
|
94 | 420 |
lemma Subst_keeps_eq: |
42 | 421 |
assumes substor: "X = L xrhs" |
422 |
and finite: "finite rhs" |
|
94 | 423 |
shows "L (Subst rhs X xrhs) = L rhs" (is "?Left = ?Right") |
42 | 424 |
proof- |
94 | 425 |
def A \<equiv> "L (rhs - {Trn X r | r. Trn X r \<in> rhs})" |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
426 |
have "?Left = A \<union> L (Append_rexp_rhs xrhs (\<Uplus>{r. Trn X r \<in> rhs}))" |
94 | 427 |
unfolding Subst_def |
79 | 428 |
unfolding L_rhs_union_distrib[symmetric] |
429 |
by (simp add: A_def) |
|
430 |
moreover have "?Right = A \<union> L ({Trn X r | r. Trn X r \<in> rhs})" |
|
42 | 431 |
proof- |
94 | 432 |
have "rhs = (rhs - {Trn X r | r. Trn X r \<in> rhs}) \<union> ({Trn X r | r. Trn X r \<in> rhs})" by auto |
79 | 433 |
thus ?thesis |
434 |
unfolding A_def |
|
435 |
unfolding L_rhs_union_distrib |
|
436 |
by simp |
|
42 | 437 |
qed |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
438 |
moreover have "L (Append_rexp_rhs xrhs (\<Uplus>{r. Trn X r \<in> rhs})) = L ({Trn X r | r. Trn X r \<in> rhs})" |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
439 |
using finite substor by (simp only: lang_of_append_rexp_rhs rhs_trm_soundness) |
42 | 440 |
ultimately show ?thesis by simp |
441 |
qed |
|
442 |
||
94 | 443 |
lemma Subst_keeps_finite_rhs: |
444 |
"\<lbrakk>finite rhs; finite yrhs\<rbrakk> \<Longrightarrow> finite (Subst rhs Y yrhs)" |
|
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
445 |
by (auto simp: Subst_def Append_keeps_finite) |
42 | 446 |
|
94 | 447 |
lemma Subst_all_keeps_finite: |
110 | 448 |
assumes finite: "finite ES" |
94 | 449 |
shows "finite (Subst_all ES Y yrhs)" |
42 | 450 |
proof - |
110 | 451 |
def eqns \<equiv> "{(X::lang, rhs) |X rhs. (X, rhs) \<in> ES}" |
452 |
def h \<equiv> "\<lambda>(X::lang, rhs). (X, Subst rhs Y yrhs)" |
|
453 |
have "finite (h ` eqns)" using finite h_def eqns_def by auto |
|
454 |
moreover |
|
455 |
have "Subst_all ES Y yrhs = h ` eqns" unfolding h_def eqns_def Subst_all_def by auto |
|
456 |
ultimately |
|
457 |
show "finite (Subst_all ES Y yrhs)" by simp |
|
42 | 458 |
qed |
459 |
||
94 | 460 |
lemma Subst_all_keeps_finite_rhs: |
461 |
"\<lbrakk>finite_rhs ES; finite yrhs\<rbrakk> \<Longrightarrow> finite_rhs (Subst_all ES Y yrhs)" |
|
462 |
by (auto intro:Subst_keeps_finite_rhs simp add:Subst_all_def finite_rhs_def) |
|
42 | 463 |
|
464 |
lemma append_rhs_keeps_cls: |
|
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
465 |
"rhss (Append_rexp_rhs rhs r) = rhss rhs" |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
466 |
apply (auto simp:rhss_def Append_rexp_rhs_def) |
42 | 467 |
apply (case_tac xa, auto simp:image_def) |
468 |
by (rule_tac x = "SEQ ra r" in exI, rule_tac x = "Trn x ra" in bexI, simp+) |
|
469 |
||
94 | 470 |
lemma Arden_removes_cl: |
104 | 471 |
"rhss (Arden Y yrhs) = rhss yrhs - {Y}" |
94 | 472 |
apply (simp add:Arden_def append_rhs_keeps_cls) |
104 | 473 |
by (auto simp:rhss_def) |
42 | 474 |
|
103 | 475 |
lemma lhss_keeps_cls: |
476 |
"lhss (Subst_all ES Y yrhs) = lhss ES" |
|
477 |
by (auto simp:lhss_def Subst_all_def) |
|
42 | 478 |
|
94 | 479 |
lemma Subst_updates_cls: |
104 | 480 |
"X \<notin> rhss xrhs \<Longrightarrow> |
481 |
rhss (Subst rhs X xrhs) = rhss rhs \<union> rhss xrhs - {X}" |
|
482 |
apply (simp only:Subst_def append_rhs_keeps_cls rhss_union_distrib) |
|
483 |
by (auto simp:rhss_def) |
|
42 | 484 |
|
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
485 |
lemma Subst_all_keeps_validity: |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
486 |
assumes sc: "validity (ES \<union> {(Y, yrhs)})" (is "validity ?A") |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
487 |
shows "validity (Subst_all ES Y (Arden Y yrhs))" (is "validity ?B") |
110 | 488 |
proof - |
42 | 489 |
{ fix X xrhs' |
490 |
assume "(X, xrhs') \<in> ?B" |
|
491 |
then obtain xrhs |
|
94 | 492 |
where xrhs_xrhs': "xrhs' = Subst xrhs Y (Arden Y yrhs)" |
493 |
and X_in: "(X, xrhs) \<in> ES" by (simp add:Subst_all_def, blast) |
|
104 | 494 |
have "rhss xrhs' \<subseteq> lhss ?B" |
42 | 495 |
proof- |
103 | 496 |
have "lhss ?B = lhss ES" by (auto simp add:lhss_def Subst_all_def) |
104 | 497 |
moreover have "rhss xrhs' \<subseteq> lhss ES" |
42 | 498 |
proof- |
110 | 499 |
have "rhss xrhs' \<subseteq> rhss xrhs \<union> rhss (Arden Y yrhs) - {Y}" |
42 | 500 |
proof- |
104 | 501 |
have "Y \<notin> rhss (Arden Y yrhs)" |
94 | 502 |
using Arden_removes_cl by simp |
503 |
thus ?thesis using xrhs_xrhs' by (auto simp:Subst_updates_cls) |
|
42 | 504 |
qed |
104 | 505 |
moreover have "rhss xrhs \<subseteq> lhss ES \<union> {Y}" using X_in sc |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
506 |
apply (simp only:validity_def lhss_union_distrib) |
103 | 507 |
by (drule_tac x = "(X, xrhs)" in bspec, auto simp:lhss_def) |
104 | 508 |
moreover have "rhss (Arden Y yrhs) \<subseteq> lhss ES \<union> {Y}" |
42 | 509 |
using sc |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
510 |
by (auto simp add:Arden_removes_cl validity_def lhss_def) |
42 | 511 |
ultimately show ?thesis by auto |
512 |
qed |
|
513 |
ultimately show ?thesis by simp |
|
514 |
qed |
|
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
515 |
} thus ?thesis by (auto simp only:Subst_all_def validity_def) |
42 | 516 |
qed |
517 |
||
96 | 518 |
lemma Subst_all_satisfies_invariant: |
86 | 519 |
assumes invariant_ES: "invariant (ES \<union> {(Y, yrhs)})" |
94 | 520 |
shows "invariant (Subst_all ES Y (Arden Y yrhs))" |
96 | 521 |
proof (rule invariantI) |
522 |
have Y_eq_yrhs: "Y = L yrhs" |
|
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
523 |
using invariant_ES by (simp only:invariant_def soundness_def, blast) |
96 | 524 |
have finite_yrhs: "finite yrhs" |
86 | 525 |
using invariant_ES by (auto simp:invariant_def finite_rhs_def) |
110 | 526 |
have nonempty_yrhs: "ardenable yrhs" |
527 |
using invariant_ES by (auto simp:invariant_def ardenable_all_def) |
|
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
528 |
show "soundness (Subst_all ES Y (Arden Y yrhs))" |
110 | 529 |
proof - |
96 | 530 |
have "Y = L (Arden Y yrhs)" |
103 | 531 |
using Y_eq_yrhs invariant_ES finite_yrhs |
532 |
using finite_Trn[OF finite_yrhs] |
|
533 |
apply(rule_tac Arden_keeps_eq) |
|
534 |
apply(simp_all) |
|
110 | 535 |
unfolding invariant_def ardenable_all_def ardenable_def |
103 | 536 |
apply(auto) |
537 |
done |
|
538 |
thus ?thesis using invariant_ES |
|
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
539 |
unfolding invariant_def finite_rhs_def2 soundness_def Subst_all_def |
103 | 540 |
by (auto simp add: Subst_keeps_eq simp del: L_rhs.simps) |
96 | 541 |
qed |
542 |
show "finite (Subst_all ES Y (Arden Y yrhs))" |
|
543 |
using invariant_ES by (simp add:invariant_def Subst_all_keeps_finite) |
|
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
544 |
show "distinctness (Subst_all ES Y (Arden Y yrhs))" |
110 | 545 |
using invariant_ES |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
546 |
unfolding distinctness_def Subst_all_def invariant_def by auto |
110 | 547 |
show "ardenable_all (Subst_all ES Y (Arden Y yrhs))" |
96 | 548 |
proof - |
549 |
{ fix X rhs |
|
550 |
assume "(X, rhs) \<in> ES" |
|
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
551 |
hence "ardenable rhs" using invariant_ES |
110 | 552 |
by (auto simp add:invariant_def ardenable_all_def) |
96 | 553 |
with nonempty_yrhs |
110 | 554 |
have "ardenable (Subst rhs Y (Arden Y yrhs))" |
96 | 555 |
by (simp add:nonempty_yrhs |
556 |
Subst_keeps_nonempty Arden_keeps_nonempty) |
|
110 | 557 |
} thus ?thesis by (auto simp add:ardenable_all_def Subst_all_def) |
96 | 558 |
qed |
559 |
show "finite_rhs (Subst_all ES Y (Arden Y yrhs))" |
|
42 | 560 |
proof- |
86 | 561 |
have "finite_rhs ES" using invariant_ES |
562 |
by (simp add:invariant_def finite_rhs_def) |
|
94 | 563 |
moreover have "finite (Arden Y yrhs)" |
42 | 564 |
proof - |
86 | 565 |
have "finite yrhs" using invariant_ES |
566 |
by (auto simp:invariant_def finite_rhs_def) |
|
94 | 567 |
thus ?thesis using Arden_keeps_finite by simp |
42 | 568 |
qed |
569 |
ultimately show ?thesis |
|
94 | 570 |
by (simp add:Subst_all_keeps_finite_rhs) |
42 | 571 |
qed |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
572 |
show "validity (Subst_all ES Y (Arden Y yrhs))" |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
573 |
using invariant_ES Subst_all_keeps_validity by (simp add:invariant_def) |
42 | 574 |
qed |
575 |
||
97 | 576 |
lemma Remove_in_card_measure: |
577 |
assumes finite: "finite ES" |
|
578 |
and in_ES: "(X, rhs) \<in> ES" |
|
579 |
shows "(Remove ES X rhs, ES) \<in> measure card" |
|
580 |
proof - |
|
581 |
def f \<equiv> "\<lambda> x. ((fst x)::lang, Subst (snd x) X (Arden X rhs))" |
|
582 |
def ES' \<equiv> "ES - {(X, rhs)}" |
|
583 |
have "Subst_all ES' X (Arden X rhs) = f ` ES'" |
|
584 |
apply (auto simp: Subst_all_def f_def image_def) |
|
585 |
by (rule_tac x = "(Y, yrhs)" in bexI, simp+) |
|
586 |
then have "card (Subst_all ES' X (Arden X rhs)) \<le> card ES'" |
|
587 |
unfolding ES'_def using finite by (auto intro: card_image_le) |
|
588 |
also have "\<dots> < card ES" unfolding ES'_def |
|
589 |
using in_ES finite by (rule_tac card_Diff1_less) |
|
590 |
finally show "(Remove ES X rhs, ES) \<in> measure card" |
|
591 |
unfolding Remove_def ES'_def by simp |
|
42 | 592 |
qed |
97 | 593 |
|
42 | 594 |
|
94 | 595 |
lemma Subst_all_cls_remains: |
596 |
"(X, xrhs) \<in> ES \<Longrightarrow> \<exists> xrhs'. (X, xrhs') \<in> (Subst_all ES Y yrhs)" |
|
97 | 597 |
by (auto simp: Subst_all_def) |
42 | 598 |
|
599 |
lemma card_noteq_1_has_more: |
|
103 | 600 |
assumes card:"Cond ES" |
601 |
and e_in: "(X, xrhs) \<in> ES" |
|
602 |
and finite: "finite ES" |
|
603 |
shows "\<exists>(Y, yrhs) \<in> ES. (X, xrhs) \<noteq> (Y, yrhs)" |
|
42 | 604 |
proof- |
103 | 605 |
have "card ES > 1" using card e_in finite |
606 |
by (cases "card ES") (auto) |
|
607 |
then have "card (ES - {(X, xrhs)}) > 0" |
|
608 |
using finite e_in by auto |
|
609 |
then have "(ES - {(X, xrhs)}) \<noteq> {}" using finite by (rule_tac notI, simp) |
|
610 |
then show "\<exists>(Y, yrhs) \<in> ES. (X, xrhs) \<noteq> (Y, yrhs)" |
|
611 |
by auto |
|
42 | 612 |
qed |
613 |
||
97 | 614 |
lemma iteration_step_measure: |
91 | 615 |
assumes Inv_ES: "invariant ES" |
42 | 616 |
and X_in_ES: "(X, xrhs) \<in> ES" |
105 | 617 |
and Cnd: "Cond ES " |
97 | 618 |
shows "(Iter X ES, ES) \<in> measure card" |
619 |
proof - |
|
105 | 620 |
have fin: "finite ES" using Inv_ES unfolding invariant_def by simp |
97 | 621 |
then obtain Y yrhs |
622 |
where Y_in_ES: "(Y, yrhs) \<in> ES" and not_eq: "(X, xrhs) \<noteq> (Y, yrhs)" |
|
105 | 623 |
using Cnd X_in_ES by (drule_tac card_noteq_1_has_more) (auto) |
97 | 624 |
then have "(Y, yrhs) \<in> ES " "X \<noteq> Y" |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
625 |
using X_in_ES Inv_ES unfolding invariant_def distinctness_def |
103 | 626 |
by auto |
97 | 627 |
then show "(Iter X ES, ES) \<in> measure card" |
628 |
apply(rule IterI2) |
|
629 |
apply(rule Remove_in_card_measure) |
|
105 | 630 |
apply(simp_all add: fin) |
97 | 631 |
done |
632 |
qed |
|
633 |
||
634 |
lemma iteration_step_invariant: |
|
635 |
assumes Inv_ES: "invariant ES" |
|
636 |
and X_in_ES: "(X, xrhs) \<in> ES" |
|
105 | 637 |
and Cnd: "Cond ES" |
97 | 638 |
shows "invariant (Iter X ES)" |
42 | 639 |
proof - |
91 | 640 |
have finite_ES: "finite ES" using Inv_ES by (simp add: invariant_def) |
42 | 641 |
then obtain Y yrhs |
642 |
where Y_in_ES: "(Y, yrhs) \<in> ES" and not_eq: "(X, xrhs) \<noteq> (Y, yrhs)" |
|
105 | 643 |
using Cnd X_in_ES by (drule_tac card_noteq_1_has_more) (auto) |
103 | 644 |
then have "(Y, yrhs) \<in> ES" "X \<noteq> Y" |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
645 |
using X_in_ES Inv_ES unfolding invariant_def distinctness_def |
103 | 646 |
by auto |
97 | 647 |
then show "invariant (Iter X ES)" |
648 |
proof(rule IterI2) |
|
649 |
fix Y yrhs |
|
650 |
assume h: "(Y, yrhs) \<in> ES" "X \<noteq> Y" |
|
651 |
then have "ES - {(Y, yrhs)} \<union> {(Y, yrhs)} = ES" by auto |
|
652 |
then show "invariant (Remove ES Y yrhs)" unfolding Remove_def |
|
110 | 653 |
using Inv_ES |
654 |
by (rule_tac Subst_all_satisfies_invariant) (simp) |
|
42 | 655 |
qed |
656 |
qed |
|
657 |
||
97 | 658 |
lemma iteration_step_ex: |
659 |
assumes Inv_ES: "invariant ES" |
|
660 |
and X_in_ES: "(X, xrhs) \<in> ES" |
|
105 | 661 |
and Cnd: "Cond ES" |
97 | 662 |
shows "\<exists>xrhs'. (X, xrhs') \<in> (Iter X ES)" |
663 |
proof - |
|
664 |
have finite_ES: "finite ES" using Inv_ES by (simp add: invariant_def) |
|
665 |
then obtain Y yrhs |
|
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
666 |
where "(Y, yrhs) \<in> ES" "(X, xrhs) \<noteq> (Y, yrhs)" |
105 | 667 |
using Cnd X_in_ES by (drule_tac card_noteq_1_has_more) (auto) |
97 | 668 |
then have "(Y, yrhs) \<in> ES " "X \<noteq> Y" |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
669 |
using X_in_ES Inv_ES unfolding invariant_def distinctness_def |
103 | 670 |
by auto |
97 | 671 |
then show "\<exists>xrhs'. (X, xrhs') \<in> (Iter X ES)" |
672 |
apply(rule IterI2) |
|
673 |
unfolding Remove_def |
|
674 |
apply(rule Subst_all_cls_remains) |
|
675 |
using X_in_ES |
|
676 |
apply(auto) |
|
677 |
done |
|
678 |
qed |
|
679 |
||
91 | 680 |
|
681 |
subsubsection {* Conclusion of the proof *} |
|
42 | 682 |
|
103 | 683 |
lemma Solve: |
684 |
assumes fin: "finite (UNIV // \<approx>A)" |
|
685 |
and X_in: "X \<in> (UNIV // \<approx>A)" |
|
104 | 686 |
shows "\<exists>rhs. Solve X (Init (UNIV // \<approx>A)) = {(X, rhs)} \<and> invariant {(X, rhs)}" |
91 | 687 |
proof - |
104 | 688 |
def Inv \<equiv> "\<lambda>ES. invariant ES \<and> (\<exists>rhs. (X, rhs) \<in> ES)" |
103 | 689 |
have "Inv (Init (UNIV // \<approx>A))" unfolding Inv_def |
690 |
using fin X_in by (simp add: Init_ES_satisfies_invariant, simp add: Init_def) |
|
691 |
moreover |
|
692 |
{ fix ES |
|
693 |
assume inv: "Inv ES" and crd: "Cond ES" |
|
694 |
then have "Inv (Iter X ES)" |
|
695 |
unfolding Inv_def |
|
696 |
by (auto simp add: iteration_step_invariant iteration_step_ex) } |
|
697 |
moreover |
|
698 |
{ fix ES |
|
110 | 699 |
assume inv: "Inv ES" and not_crd: "\<not>Cond ES" |
700 |
from inv obtain rhs where "(X, rhs) \<in> ES" unfolding Inv_def by auto |
|
701 |
moreover |
|
702 |
from not_crd have "card ES = 1" by simp |
|
703 |
ultimately |
|
704 |
have "ES = {(X, rhs)}" by (auto simp add: card_Suc_eq) |
|
705 |
then have "\<exists>rhs'. ES = {(X, rhs')} \<and> invariant {(X, rhs')}" using inv |
|
706 |
unfolding Inv_def by auto } |
|
103 | 707 |
moreover |
708 |
have "wf (measure card)" by simp |
|
709 |
moreover |
|
710 |
{ fix ES |
|
711 |
assume inv: "Inv ES" and crd: "Cond ES" |
|
712 |
then have "(Iter X ES, ES) \<in> measure card" |
|
713 |
unfolding Inv_def |
|
97 | 714 |
apply(clarify) |
103 | 715 |
apply(rule_tac iteration_step_measure) |
97 | 716 |
apply(auto) |
103 | 717 |
done } |
718 |
ultimately |
|
104 | 719 |
show "\<exists>rhs. Solve X (Init (UNIV // \<approx>A)) = {(X, rhs)} \<and> invariant {(X, rhs)}" |
103 | 720 |
unfolding Solve_def by (rule while_rule) |
42 | 721 |
qed |
91 | 722 |
|
106 | 723 |
lemma every_eqcl_has_reg: |
724 |
assumes finite_CS: "finite (UNIV // \<approx>A)" |
|
725 |
and X_in_CS: "X \<in> (UNIV // \<approx>A)" |
|
726 |
shows "\<exists>r::rexp. X = L r" |
|
727 |
proof - |
|
728 |
from finite_CS X_in_CS |
|
729 |
obtain xrhs where Inv_ES: "invariant {(X, xrhs)}" |
|
730 |
using Solve by metis |
|
731 |
||
94 | 732 |
def A \<equiv> "Arden X xrhs" |
105 | 733 |
have "rhss xrhs \<subseteq> {X}" using Inv_ES |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
734 |
unfolding validity_def invariant_def rhss_def lhss_def |
105 | 735 |
by auto |
736 |
then have "rhss A = {}" unfolding A_def |
|
737 |
by (simp add: Arden_removes_cl) |
|
738 |
then have eq: "{Lam r | r. Lam r \<in> A} = A" unfolding rhss_def |
|
739 |
by (auto, case_tac x, auto) |
|
740 |
||
96 | 741 |
have "finite A" using Inv_ES unfolding A_def invariant_def finite_rhs_def |
742 |
using Arden_keeps_finite by auto |
|
105 | 743 |
then have fin: "finite {r. Lam r \<in> A}" by (rule finite_Lam) |
744 |
||
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
149
diff
changeset
|
745 |
have "X = L xrhs" using Inv_ES unfolding invariant_def soundness_def |
105 | 746 |
by simp |
747 |
then have "X = L A" using Inv_ES |
|
110 | 748 |
unfolding A_def invariant_def ardenable_all_def finite_rhs_def |
105 | 749 |
by (rule_tac Arden_keeps_eq) (simp_all add: finite_Trn) |
750 |
then have "X = L {Lam r | r. Lam r \<in> A}" using eq by simp |
|
751 |
then have "X = L (\<Uplus>{r. Lam r \<in> A})" using fin by auto |
|
106 | 752 |
then show "\<exists>r::rexp. X = L r" by blast |
42 | 753 |
qed |
754 |
||
96 | 755 |
lemma bchoice_finite_set: |
756 |
assumes a: "\<forall>x \<in> S. \<exists>y. x = f y" |
|
757 |
and b: "finite S" |
|
758 |
shows "\<exists>ys. (\<Union> S) = \<Union>(f ` ys) \<and> finite ys" |
|
759 |
using bchoice[OF a] b |
|
760 |
apply(erule_tac exE) |
|
761 |
apply(rule_tac x="fa ` S" in exI) |
|
762 |
apply(auto) |
|
763 |
done |
|
764 |
||
765 |
theorem Myhill_Nerode1: |
|
70 | 766 |
assumes finite_CS: "finite (UNIV // \<approx>A)" |
767 |
shows "\<exists>r::rexp. A = L r" |
|
42 | 768 |
proof - |
105 | 769 |
have fin: "finite (finals A)" |
96 | 770 |
using finals_in_partitions finite_CS by (rule finite_subset) |
771 |
have "\<forall>X \<in> (UNIV // \<approx>A). \<exists>r::rexp. X = L r" |
|
42 | 772 |
using finite_CS every_eqcl_has_reg by blast |
96 | 773 |
then have a: "\<forall>X \<in> finals A. \<exists>r::rexp. X = L r" |
774 |
using finals_in_partitions by auto |
|
775 |
then obtain rs::"rexp set" where "\<Union> (finals A) = \<Union>(L ` rs)" "finite rs" |
|
105 | 776 |
using fin by (auto dest: bchoice_finite_set) |
96 | 777 |
then have "A = L (\<Uplus>rs)" |
778 |
unfolding lang_is_union_of_finals[symmetric] by simp |
|
779 |
then show "\<exists>r::rexp. A = L r" by blast |
|
42 | 780 |
qed |
781 |
||
96 | 782 |
|
42 | 783 |
end |