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