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