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