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