author | urbanc |
Wed, 09 Feb 2011 07:27:30 +0000 | |
changeset 89 | 42af13d194c9 |
parent 88 | 1436fc451bb9 |
child 91 | 37ab56205097 |
permissions | -rw-r--r-- |
42 | 1 |
theory Myhill_1 |
86 | 2 |
imports Main Folds |
42 | 3 |
begin |
4 |
||
5 |
section {* Preliminary definitions *} |
|
6 |
||
43 | 7 |
types lang = "string set" |
8 |
||
86 | 9 |
|
70 | 10 |
text {* Sequential composition of two languages *} |
43 | 11 |
|
60 | 12 |
definition |
13 |
Seq :: "lang \<Rightarrow> lang \<Rightarrow> lang" (infixr ";;" 100) |
|
42 | 14 |
where |
54 | 15 |
"A ;; B = {s\<^isub>1 @ s\<^isub>2 | s\<^isub>1 s\<^isub>2. s\<^isub>1 \<in> A \<and> s\<^isub>2 \<in> B}" |
42 | 16 |
|
70 | 17 |
|
56
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
18 |
text {* Some properties of operator @{text ";;"}. *} |
50 | 19 |
|
56
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
20 |
lemma seq_add_left: |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
21 |
assumes a: "A = B" |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
22 |
shows "C ;; A = C ;; B" |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
23 |
using a by simp |
42 | 24 |
|
50 | 25 |
lemma seq_union_distrib_right: |
26 |
shows "(A \<union> B) ;; C = (A ;; C) \<union> (B ;; C)" |
|
27 |
unfolding Seq_def by auto |
|
28 |
||
29 |
lemma seq_union_distrib_left: |
|
30 |
shows "C ;; (A \<union> B) = (C ;; A) \<union> (C ;; B)" |
|
31 |
unfolding Seq_def by auto |
|
42 | 32 |
|
33 |
lemma seq_intro: |
|
70 | 34 |
assumes a: "x \<in> A" "y \<in> B" |
35 |
shows "x @ y \<in> A ;; B " |
|
36 |
using a by (auto simp: Seq_def) |
|
42 | 37 |
|
38 |
lemma seq_assoc: |
|
50 | 39 |
shows "(A ;; B) ;; C = A ;; (B ;; C)" |
40 |
unfolding Seq_def |
|
41 |
apply(auto) |
|
42 |
apply(blast) |
|
42 | 43 |
by (metis append_assoc) |
44 |
||
50 | 45 |
lemma seq_empty [simp]: |
46 |
shows "A ;; {[]} = A" |
|
47 |
and "{[]} ;; A = A" |
|
48 |
by (simp_all add: Seq_def) |
|
49 |
||
70 | 50 |
|
51 |
text {* Power and Star of a language *} |
|
52 |
||
56
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
53 |
fun |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
54 |
pow :: "lang \<Rightarrow> nat \<Rightarrow> lang" (infixl "\<up>" 100) |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
55 |
where |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
56 |
"A \<up> 0 = {[]}" |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
57 |
| "A \<up> (Suc n) = A ;; (A \<up> n)" |
50 | 58 |
|
56
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
59 |
definition |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
60 |
Star :: "lang \<Rightarrow> lang" ("_\<star>" [101] 102) |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
61 |
where |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
62 |
"A\<star> \<equiv> (\<Union>n. A \<up> n)" |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
63 |
|
70 | 64 |
|
56
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
65 |
lemma star_start[intro]: |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
66 |
shows "[] \<in> A\<star>" |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
67 |
proof - |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
68 |
have "[] \<in> A \<up> 0" by auto |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
69 |
then show "[] \<in> A\<star>" unfolding Star_def by blast |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
70 |
qed |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
71 |
|
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
72 |
lemma star_step [intro]: |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
73 |
assumes a: "s1 \<in> A" |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
74 |
and b: "s2 \<in> A\<star>" |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
75 |
shows "s1 @ s2 \<in> A\<star>" |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
76 |
proof - |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
77 |
from b obtain n where "s2 \<in> A \<up> n" unfolding Star_def by auto |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
78 |
then have "s1 @ s2 \<in> A \<up> (Suc n)" using a by (auto simp add: Seq_def) |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
79 |
then show "s1 @ s2 \<in> A\<star>" unfolding Star_def by blast |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
80 |
qed |
42 | 81 |
|
56
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
82 |
lemma star_induct[consumes 1, case_names start step]: |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
83 |
assumes a: "x \<in> A\<star>" |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
84 |
and b: "P []" |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
85 |
and c: "\<And>s1 s2. \<lbrakk>s1 \<in> A; s2 \<in> A\<star>; P s2\<rbrakk> \<Longrightarrow> P (s1 @ s2)" |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
86 |
shows "P x" |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
87 |
proof - |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
88 |
from a obtain n where "x \<in> A \<up> n" unfolding Star_def by auto |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
89 |
then show "P x" |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
90 |
by (induct n arbitrary: x) |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
91 |
(auto intro!: b c simp add: Seq_def Star_def) |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
92 |
qed |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
93 |
|
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
94 |
lemma star_intro1: |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
95 |
assumes a: "x \<in> A\<star>" |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
96 |
and b: "y \<in> A\<star>" |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
97 |
shows "x @ y \<in> A\<star>" |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
98 |
using a b |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
99 |
by (induct rule: star_induct) (auto) |
42 | 100 |
|
56
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
101 |
lemma star_intro2: |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
102 |
assumes a: "y \<in> A" |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
103 |
shows "y \<in> A\<star>" |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
104 |
proof - |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
105 |
from a have "y @ [] \<in> A\<star>" by blast |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
106 |
then show "y \<in> A\<star>" by simp |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
107 |
qed |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
108 |
|
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
109 |
lemma star_intro3: |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
110 |
assumes a: "x \<in> A\<star>" |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
111 |
and b: "y \<in> A" |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
112 |
shows "x @ y \<in> A\<star>" |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
113 |
using a b by (blast intro: star_intro1 star_intro2) |
42 | 114 |
|
71 | 115 |
lemma star_cases: |
116 |
shows "A\<star> = {[]} \<union> A ;; A\<star>" |
|
117 |
proof |
|
118 |
{ fix x |
|
119 |
have "x \<in> A\<star> \<Longrightarrow> x \<in> {[]} \<union> A ;; A\<star>" |
|
120 |
unfolding Seq_def |
|
121 |
by (induct rule: star_induct) (auto) |
|
122 |
} |
|
123 |
then show "A\<star> \<subseteq> {[]} \<union> A ;; A\<star>" by auto |
|
124 |
next |
|
125 |
show "{[]} \<union> A ;; A\<star> \<subseteq> A\<star>" |
|
126 |
unfolding Seq_def by auto |
|
127 |
qed |
|
128 |
||
42 | 129 |
lemma star_decom: |
71 | 130 |
assumes a: "x \<in> A\<star>" "x \<noteq> []" |
131 |
shows "\<exists>a b. x = a @ b \<and> a \<noteq> [] \<and> a \<in> A \<and> b \<in> A\<star>" |
|
132 |
using a |
|
86 | 133 |
by (induct rule: star_induct) (blast)+ |
42 | 134 |
|
50 | 135 |
lemma |
136 |
shows seq_Union_left: "B ;; (\<Union>n. A \<up> n) = (\<Union>n. B ;; (A \<up> n))" |
|
137 |
and seq_Union_right: "(\<Union>n. A \<up> n) ;; B = (\<Union>n. (A \<up> n) ;; B)" |
|
138 |
unfolding Seq_def by auto |
|
139 |
||
140 |
lemma seq_pow_comm: |
|
141 |
shows "A ;; (A \<up> n) = (A \<up> n) ;; A" |
|
142 |
by (induct n) (simp_all add: seq_assoc[symmetric]) |
|
143 |
||
144 |
lemma seq_star_comm: |
|
145 |
shows "A ;; A\<star> = A\<star> ;; A" |
|
86 | 146 |
unfolding Star_def seq_Union_left |
147 |
unfolding seq_pow_comm seq_Union_right |
|
50 | 148 |
by simp |
149 |
||
86 | 150 |
|
50 | 151 |
text {* Two lemmas about the length of strings in @{text "A \<up> n"} *} |
152 |
||
153 |
lemma pow_length: |
|
154 |
assumes a: "[] \<notin> A" |
|
155 |
and b: "s \<in> A \<up> Suc n" |
|
156 |
shows "n < length s" |
|
157 |
using b |
|
158 |
proof (induct n arbitrary: s) |
|
159 |
case 0 |
|
160 |
have "s \<in> A \<up> Suc 0" by fact |
|
161 |
with a have "s \<noteq> []" by auto |
|
162 |
then show "0 < length s" by auto |
|
163 |
next |
|
164 |
case (Suc n) |
|
165 |
have ih: "\<And>s. s \<in> A \<up> Suc n \<Longrightarrow> n < length s" by fact |
|
166 |
have "s \<in> A \<up> Suc (Suc n)" by fact |
|
167 |
then obtain s1 s2 where eq: "s = s1 @ s2" and *: "s1 \<in> A" and **: "s2 \<in> A \<up> Suc n" |
|
168 |
by (auto simp add: Seq_def) |
|
169 |
from ih ** have "n < length s2" by simp |
|
170 |
moreover have "0 < length s1" using * a by auto |
|
171 |
ultimately show "Suc n < length s" unfolding eq |
|
172 |
by (simp only: length_append) |
|
173 |
qed |
|
174 |
||
175 |
lemma seq_pow_length: |
|
176 |
assumes a: "[] \<notin> A" |
|
177 |
and b: "s \<in> B ;; (A \<up> Suc n)" |
|
178 |
shows "n < length s" |
|
179 |
proof - |
|
180 |
from b obtain s1 s2 where eq: "s = s1 @ s2" and *: "s2 \<in> A \<up> Suc n" |
|
181 |
unfolding Seq_def by auto |
|
182 |
from * have " n < length s2" by (rule pow_length[OF a]) |
|
183 |
then show "n < length s" using eq by simp |
|
184 |
qed |
|
185 |
||
186 |
||
86 | 187 |
|
188 |
section {* A modified version of Arden's lemma *} |
|
50 | 189 |
|
70 | 190 |
|
191 |
text {* A helper lemma for Arden *} |
|
50 | 192 |
|
86 | 193 |
lemma arden_helper: |
50 | 194 |
assumes eq: "X = X ;; A \<union> B" |
195 |
shows "X = X ;; (A \<up> Suc n) \<union> (\<Union>m\<in>{0..n}. B ;; (A \<up> m))" |
|
196 |
proof (induct n) |
|
197 |
case 0 |
|
198 |
show "X = X ;; (A \<up> Suc 0) \<union> (\<Union>(m::nat)\<in>{0..0}. B ;; (A \<up> m))" |
|
199 |
using eq by simp |
|
200 |
next |
|
201 |
case (Suc n) |
|
202 |
have ih: "X = X ;; (A \<up> Suc n) \<union> (\<Union>m\<in>{0..n}. B ;; (A \<up> m))" by fact |
|
203 |
also have "\<dots> = (X ;; A \<union> B) ;; (A \<up> Suc n) \<union> (\<Union>m\<in>{0..n}. B ;; (A \<up> m))" using eq by simp |
|
204 |
also have "\<dots> = X ;; (A \<up> Suc (Suc n)) \<union> (B ;; (A \<up> Suc n)) \<union> (\<Union>m\<in>{0..n}. B ;; (A \<up> m))" |
|
205 |
by (simp add: seq_union_distrib_right seq_assoc) |
|
206 |
also have "\<dots> = X ;; (A \<up> Suc (Suc n)) \<union> (\<Union>m\<in>{0..Suc n}. B ;; (A \<up> m))" |
|
207 |
by (auto simp add: le_Suc_eq) |
|
208 |
finally show "X = X ;; (A \<up> Suc (Suc n)) \<union> (\<Union>m\<in>{0..Suc n}. B ;; (A \<up> m))" . |
|
209 |
qed |
|
210 |
||
86 | 211 |
theorem arden: |
50 | 212 |
assumes nemp: "[] \<notin> A" |
213 |
shows "X = X ;; A \<union> B \<longleftrightarrow> X = B ;; A\<star>" |
|
214 |
proof |
|
215 |
assume eq: "X = B ;; A\<star>" |
|
216 |
have "A\<star> = {[]} \<union> A\<star> ;; A" |
|
217 |
unfolding seq_star_comm[symmetric] |
|
71 | 218 |
by (rule star_cases) |
56
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
219 |
then have "B ;; A\<star> = B ;; ({[]} \<union> A\<star> ;; A)" |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
220 |
by (rule seq_add_left) |
50 | 221 |
also have "\<dots> = B \<union> B ;; (A\<star> ;; A)" |
222 |
unfolding seq_union_distrib_left by simp |
|
223 |
also have "\<dots> = B \<union> (B ;; A\<star>) ;; A" |
|
224 |
by (simp only: seq_assoc) |
|
225 |
finally show "X = X ;; A \<union> B" |
|
226 |
using eq by blast |
|
227 |
next |
|
228 |
assume eq: "X = X ;; A \<union> B" |
|
229 |
{ fix n::nat |
|
86 | 230 |
have "B ;; (A \<up> n) \<subseteq> X" using arden_helper[OF eq, of "n"] by auto } |
56
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
231 |
then have "B ;; A\<star> \<subseteq> X" |
86 | 232 |
unfolding Seq_def Star_def UNION_def by auto |
50 | 233 |
moreover |
234 |
{ fix s::string |
|
235 |
obtain k where "k = length s" by auto |
|
236 |
then have not_in: "s \<notin> X ;; (A \<up> Suc k)" |
|
237 |
using seq_pow_length[OF nemp] by blast |
|
238 |
assume "s \<in> X" |
|
239 |
then have "s \<in> X ;; (A \<up> Suc k) \<union> (\<Union>m\<in>{0..k}. B ;; (A \<up> m))" |
|
86 | 240 |
using arden_helper[OF eq, of "k"] by auto |
50 | 241 |
then have "s \<in> (\<Union>m\<in>{0..k}. B ;; (A \<up> m))" using not_in by auto |
242 |
moreover |
|
243 |
have "(\<Union>m\<in>{0..k}. B ;; (A \<up> m)) \<subseteq> (\<Union>n. B ;; (A \<up> n))" by auto |
|
244 |
ultimately |
|
56
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
245 |
have "s \<in> B ;; A\<star>" |
86 | 246 |
unfolding seq_Union_left Star_def by auto } |
50 | 247 |
then have "X \<subseteq> B ;; A\<star>" by auto |
248 |
ultimately |
|
249 |
show "X = B ;; A\<star>" by simp |
|
250 |
qed |
|
251 |
||
42 | 252 |
|
70 | 253 |
section {* Regular Expressions *} |
48 | 254 |
|
255 |
datatype rexp = |
|
256 |
NULL |
|
257 |
| EMPTY |
|
258 |
| CHAR char |
|
259 |
| SEQ rexp rexp |
|
260 |
| ALT rexp rexp |
|
261 |
| STAR rexp |
|
262 |
||
263 |
||
264 |
text {* |
|
86 | 265 |
The function @{text L} is overloaded, with the idea that @{text "L x"} |
266 |
evaluates to the language represented by the object @{text x}. |
|
48 | 267 |
*} |
268 |
||
70 | 269 |
consts L:: "'a \<Rightarrow> lang" |
48 | 270 |
|
70 | 271 |
overloading L_rexp \<equiv> "L:: rexp \<Rightarrow> lang" |
48 | 272 |
begin |
273 |
fun |
|
88 | 274 |
L_rexp :: "rexp \<Rightarrow> lang" |
48 | 275 |
where |
276 |
"L_rexp (NULL) = {}" |
|
277 |
| "L_rexp (EMPTY) = {[]}" |
|
278 |
| "L_rexp (CHAR c) = {[c]}" |
|
279 |
| "L_rexp (SEQ r1 r2) = (L_rexp r1) ;; (L_rexp r2)" |
|
280 |
| "L_rexp (ALT r1 r2) = (L_rexp r1) \<union> (L_rexp r2)" |
|
281 |
| "L_rexp (STAR r) = (L_rexp r)\<star>" |
|
282 |
end |
|
283 |
||
88 | 284 |
|
86 | 285 |
text {* ALT-combination of a set or regulare expressions *} |
50 | 286 |
|
76 | 287 |
abbreviation |
288 |
Setalt ("\<Uplus>_" [1000] 999) |
|
289 |
where |
|
290 |
"\<Uplus>A == folds ALT NULL A" |
|
291 |
||
50 | 292 |
text {* |
86 | 293 |
For finite sets, @{term Setalt} is preserved under @{term L}. |
79 | 294 |
*} |
70 | 295 |
|
50 | 296 |
lemma folds_alt_simp [simp]: |
88 | 297 |
fixes rs::"rexp set" |
70 | 298 |
assumes a: "finite rs" |
76 | 299 |
shows "L (\<Uplus>rs) = \<Union> (L ` rs)" |
75 | 300 |
apply(rule set_eqI) |
70 | 301 |
apply(simp add: folds_def) |
302 |
apply(rule someI2_ex) |
|
303 |
apply(rule_tac finite_imp_fold_graph[OF a]) |
|
304 |
apply(erule fold_graph.induct) |
|
305 |
apply(auto) |
|
306 |
done |
|
50 | 307 |
|
70 | 308 |
|
86 | 309 |
|
310 |
section {* Direction @{text "finite partition \<Rightarrow> regular language"} *} |
|
311 |
||
312 |
||
70 | 313 |
text {* Just a technical lemma for collections and pairs *} |
314 |
||
75 | 315 |
lemma Pair_Collect[simp]: |
48 | 316 |
shows "(x, y) \<in> {(x, y). P x y} \<longleftrightarrow> P x y" |
317 |
by simp |
|
318 |
||
86 | 319 |
text {* Myhill-Nerode relation *} |
320 |
||
48 | 321 |
definition |
71 | 322 |
str_eq_rel :: "lang \<Rightarrow> (string \<times> string) set" ("\<approx>_" [100] 100) |
48 | 323 |
where |
70 | 324 |
"\<approx>A \<equiv> {(x, y). (\<forall>z. x @ z \<in> A \<longleftrightarrow> y @ z \<in> A)}" |
48 | 325 |
|
326 |
text {* |
|
86 | 327 |
Among the equivalence clases of @{text "\<approx>A"}, the set @{text "finals A"} |
328 |
singles out those which contains the strings from @{text A}. |
|
48 | 329 |
*} |
330 |
||
331 |
definition |
|
71 | 332 |
finals :: "lang \<Rightarrow> lang set" |
333 |
where |
|
334 |
"finals A \<equiv> {\<approx>A `` {x} | x . x \<in> A}" |
|
48 | 335 |
|
70 | 336 |
|
48 | 337 |
lemma lang_is_union_of_finals: |
70 | 338 |
shows "A = \<Union> finals A" |
339 |
unfolding finals_def |
|
340 |
unfolding Image_def |
|
341 |
unfolding str_eq_rel_def |
|
342 |
apply(auto) |
|
343 |
apply(drule_tac x = "[]" in spec) |
|
344 |
apply(auto) |
|
345 |
done |
|
346 |
||
79 | 347 |
lemma finals_in_partitions: |
348 |
shows "finals A \<subseteq> (UNIV // \<approx>A)" |
|
76 | 349 |
unfolding finals_def |
350 |
unfolding quotient_def |
|
351 |
by auto |
|
352 |
||
48 | 353 |
|
86 | 354 |
section {* Equational systems *} |
42 | 355 |
|
89 | 356 |
|
357 |
text {* The two kinds of terms in the rhs of equations. *} |
|
358 |
||
42 | 359 |
datatype rhs_item = |
86 | 360 |
Lam "rexp" (* Lambda-marker *) |
70 | 361 |
| Trn "lang" "rexp" (* Transition *) |
362 |
||
42 | 363 |
|
86 | 364 |
overloading L_rhs_item \<equiv> "L:: rhs_item \<Rightarrow> lang" |
42 | 365 |
begin |
86 | 366 |
fun L_rhs_item:: "rhs_item \<Rightarrow> lang" |
42 | 367 |
where |
86 | 368 |
"L_rhs_item (Lam r) = L r" |
369 |
| "L_rhs_item (Trn X r) = X ;; L r" |
|
42 | 370 |
end |
371 |
||
70 | 372 |
overloading L_rhs \<equiv> "L:: rhs_item set \<Rightarrow> lang" |
42 | 373 |
begin |
70 | 374 |
fun L_rhs:: "rhs_item set \<Rightarrow> lang" |
375 |
where |
|
376 |
"L_rhs rhs = \<Union> (L ` rhs)" |
|
42 | 377 |
end |
378 |
||
86 | 379 |
definition |
380 |
"trns_of rhs X \<equiv> {Trn X r | r. Trn X r \<in> rhs}" |
|
381 |
||
382 |
text {* Transitions between equivalence classes *} |
|
71 | 383 |
|
384 |
definition |
|
75 | 385 |
transition :: "lang \<Rightarrow> rexp \<Rightarrow> lang \<Rightarrow> bool" ("_ \<Turnstile>_\<Rightarrow>_" [100,100,100] 100) |
71 | 386 |
where |
75 | 387 |
"Y \<Turnstile>r\<Rightarrow> X \<equiv> Y ;; (L r) \<subseteq> X" |
42 | 388 |
|
86 | 389 |
text {* Initial equational system *} |
390 |
||
42 | 391 |
definition |
392 |
"init_rhs CS X \<equiv> |
|
393 |
if ([] \<in> X) then |
|
75 | 394 |
{Lam EMPTY} \<union> {Trn Y (CHAR c) | Y c. Y \<in> CS \<and> Y \<Turnstile>(CHAR c)\<Rightarrow> X} |
42 | 395 |
else |
75 | 396 |
{Trn Y (CHAR c)| Y c. Y \<in> CS \<and> Y \<Turnstile>(CHAR c)\<Rightarrow> X}" |
42 | 397 |
|
86 | 398 |
definition |
399 |
"eqs CS \<equiv> {(X, init_rhs CS X) | X. X \<in> CS}" |
|
75 | 400 |
|
401 |
||
402 |
||
86 | 403 |
section {* Arden Operation on equations *} |
42 | 404 |
|
405 |
text {* |
|
86 | 406 |
The function @{text "attach_rexp r item"} SEQ-composes @{text r} to the |
407 |
right of every rhs-item. |
|
75 | 408 |
*} |
42 | 409 |
|
70 | 410 |
fun |
411 |
attach_rexp :: "rexp \<Rightarrow> rhs_item \<Rightarrow> rhs_item" |
|
42 | 412 |
where |
86 | 413 |
"attach_rexp r (Lam rexp) = Lam (SEQ rexp r)" |
414 |
| "attach_rexp r (Trn X rexp) = Trn X (SEQ rexp r)" |
|
42 | 415 |
|
416 |
||
417 |
definition |
|
418 |
"append_rhs_rexp rhs rexp \<equiv> (attach_rexp rexp) ` rhs" |
|
419 |
||
86 | 420 |
definition |
421 |
"arden_op X rhs \<equiv> |
|
422 |
append_rhs_rexp (rhs - trns_of rhs X) (STAR (\<Uplus> {r. Trn X r \<in> rhs}))" |
|
423 |
||
424 |
||
425 |
section {* Substitution Operation on equations *} |
|
426 |
||
427 |
text {* |
|
428 |
Suppose and equation @{text "X = xrhs"}, @{text "subst_op"} substitutes |
|
429 |
all occurences of @{text "X"} in @{text "rhs"} by @{text "xrhs"}. |
|
71 | 430 |
*} |
431 |
||
42 | 432 |
definition |
86 | 433 |
"subst_op rhs X xrhs \<equiv> |
79 | 434 |
(rhs - (trns_of rhs X)) \<union> (append_rhs_rexp xrhs (\<Uplus> {r. Trn X r \<in> rhs}))" |
42 | 435 |
|
436 |
text {* |
|
86 | 437 |
@{text "eqs_subst ES X xrhs"} substitutes @{text xrhs} into every |
438 |
equation of the equational system @{text ES}. |
|
439 |
*} |
|
42 | 440 |
|
441 |
definition |
|
86 | 442 |
"subst_op_all ES X xrhs \<equiv> {(Y, subst_op yrhs X xrhs) | Y yrhs. (Y, yrhs) \<in> ES}" |
443 |
||
444 |
||
445 |
section {* Well-founded iteration *} |
|
42 | 446 |
|
447 |
text {* |
|
71 | 448 |
The computation of regular expressions for equivalence classes is accomplished |
42 | 449 |
using a iteration principle given by the following lemma. |
71 | 450 |
*} |
42 | 451 |
|
452 |
lemma wf_iter [rule_format]: |
|
453 |
fixes f |
|
454 |
assumes step: "\<And> e. \<lbrakk>P e; \<not> Q e\<rbrakk> \<Longrightarrow> (\<exists> e'. P e' \<and> (f(e'), f(e)) \<in> less_than)" |
|
455 |
shows pe: "P e \<longrightarrow> (\<exists> e'. P e' \<and> Q e')" |
|
456 |
proof(induct e rule: wf_induct |
|
457 |
[OF wf_inv_image[OF wf_less_than, where f = "f"]], clarify) |
|
458 |
fix x |
|
459 |
assume h [rule_format]: |
|
460 |
"\<forall>y. (y, x) \<in> inv_image less_than f \<longrightarrow> P y \<longrightarrow> (\<exists>e'. P e' \<and> Q e')" |
|
461 |
and px: "P x" |
|
462 |
show "\<exists>e'. P e' \<and> Q e'" |
|
463 |
proof(cases "Q x") |
|
464 |
assume "Q x" with px show ?thesis by blast |
|
465 |
next |
|
466 |
assume nq: "\<not> Q x" |
|
467 |
from step [OF px nq] |
|
468 |
obtain e' where pe': "P e'" and ltf: "(f e', f x) \<in> less_than" by auto |
|
469 |
show ?thesis |
|
470 |
proof(rule h) |
|
471 |
from ltf show "(e', x) \<in> inv_image less_than f" |
|
472 |
by (simp add:inv_image_def) |
|
473 |
next |
|
474 |
from pe' show "P e'" . |
|
475 |
qed |
|
476 |
qed |
|
477 |
qed |
|
478 |
||
479 |
text {* |
|
75 | 480 |
The @{text "P"} in lemma @{text "wf_iter"} is an invariant kept throughout the iteration procedure. |
42 | 481 |
The particular invariant used to solve our problem is defined by function @{text "Inv(ES)"}, |
482 |
an invariant over equal system @{text "ES"}. |
|
483 |
Every definition starting next till @{text "Inv"} stipulates a property to be satisfied by @{text "ES"}. |
|
484 |
*} |
|
485 |
||
86 | 486 |
|
487 |
section {* Invariants *} |
|
488 |
||
489 |
text {* Every variable is defined at most onece in @{text ES}. *} |
|
75 | 490 |
|
42 | 491 |
definition |
492 |
"distinct_equas ES \<equiv> |
|
86 | 493 |
\<forall> X rhs rhs'. (X, rhs) \<in> ES \<and> (X, rhs') \<in> ES \<longrightarrow> rhs = rhs'" |
70 | 494 |
|
42 | 495 |
text {* |
86 | 496 |
Every equation in @{text ES} (represented by @{text "(X, rhs)"}) |
497 |
is valid, i.e. @{text "(X = L rhs)"}. |
|
498 |
*} |
|
499 |
||
42 | 500 |
definition |
501 |
"valid_eqns ES \<equiv> \<forall> X rhs. (X, rhs) \<in> ES \<longrightarrow> (X = L rhs)" |
|
502 |
||
503 |
text {* |
|
86 | 504 |
@{text "rhs_nonempty rhs"} requires regular expressions occuring in |
505 |
transitional items of @{text "rhs"} do not contain empty string. This is |
|
506 |
necessary for the application of Arden's transformation to @{text "rhs"}. |
|
507 |
*} |
|
70 | 508 |
|
42 | 509 |
definition |
510 |
"rhs_nonempty rhs \<equiv> (\<forall> Y r. Trn Y r \<in> rhs \<longrightarrow> [] \<notin> L r)" |
|
511 |
||
512 |
text {* |
|
86 | 513 |
The following @{text "ardenable ES"} requires that Arden's transformation |
514 |
is applicable to every equation of equational system @{text "ES"}. |
|
515 |
*} |
|
70 | 516 |
|
42 | 517 |
definition |
518 |
"ardenable ES \<equiv> \<forall> X rhs. (X, rhs) \<in> ES \<longrightarrow> rhs_nonempty rhs" |
|
519 |
||
86 | 520 |
text {* |
521 |
@{text "finite_rhs ES"} requires every equation in @{text "rhs"} |
|
522 |
be finite. |
|
523 |
*} |
|
42 | 524 |
definition |
525 |
"finite_rhs ES \<equiv> \<forall> X rhs. (X, rhs) \<in> ES \<longrightarrow> finite rhs" |
|
526 |
||
527 |
text {* |
|
86 | 528 |
@{text "classes_of rhs"} returns all variables (or equivalent classes) |
42 | 529 |
occuring in @{text "rhs"}. |
530 |
*} |
|
86 | 531 |
|
42 | 532 |
definition |
533 |
"classes_of rhs \<equiv> {X. \<exists> r. Trn X r \<in> rhs}" |
|
534 |
||
535 |
text {* |
|
86 | 536 |
@{text "lefts_of ES"} returns all variables defined by an |
537 |
equational system @{text "ES"}. |
|
538 |
*} |
|
42 | 539 |
definition |
540 |
"lefts_of ES \<equiv> {Y | Y yrhs. (Y, yrhs) \<in> ES}" |
|
541 |
||
542 |
text {* |
|
86 | 543 |
The following @{text "self_contained ES"} requires that every variable occuring |
544 |
on the right hand side of equations is already defined by some equation in @{text "ES"}. |
|
545 |
*} |
|
42 | 546 |
definition |
547 |
"self_contained ES \<equiv> \<forall> (X, xrhs) \<in> ES. classes_of xrhs \<subseteq> lefts_of ES" |
|
548 |
||
549 |
||
550 |
text {* |
|
86 | 551 |
The invariant @{text "invariant(ES)"} is a conjunction of all the previously defined constaints. |
42 | 552 |
*} |
553 |
definition |
|
86 | 554 |
"invariant ES \<equiv> valid_eqns ES \<and> finite ES \<and> distinct_equas ES \<and> ardenable ES \<and> |
87 | 555 |
finite_rhs ES \<and> self_contained ES" |
42 | 556 |
|
557 |
subsection {* The proof of this direction *} |
|
558 |
||
559 |
subsubsection {* Basic properties *} |
|
560 |
||
561 |
text {* |
|
562 |
The following are some basic properties of the above definitions. |
|
563 |
*} |
|
564 |
||
565 |
lemma L_rhs_union_distrib: |
|
70 | 566 |
fixes A B::"rhs_item set" |
567 |
shows "L A \<union> L B = L (A \<union> B)" |
|
42 | 568 |
by simp |
569 |
||
79 | 570 |
lemma finite_Trn: |
571 |
assumes fin: "finite rhs" |
|
572 |
shows "finite {r. Trn Y r \<in> rhs}" |
|
573 |
proof - |
|
574 |
have "finite {Trn Y r | Y r. Trn Y r \<in> rhs}" |
|
575 |
by (rule rev_finite_subset[OF fin]) (auto) |
|
81 | 576 |
then have "finite ((\<lambda>(Y, r). Trn Y r) ` {(Y, r) | Y r. Trn Y r \<in> rhs})" |
577 |
by (simp add: image_Collect) |
|
578 |
then have "finite {(Y, r) | Y r. Trn Y r \<in> rhs}" |
|
579 |
by (erule_tac finite_imageD) (simp add: inj_on_def) |
|
79 | 580 |
then show "finite {r. Trn Y r \<in> rhs}" |
81 | 581 |
by (erule_tac f="snd" in finite_surj) (auto simp add: image_def) |
79 | 582 |
qed |
583 |
||
584 |
lemma finite_Lam: |
|
585 |
assumes fin:"finite rhs" |
|
586 |
shows "finite {r. Lam r \<in> rhs}" |
|
587 |
proof - |
|
588 |
have "finite {Lam r | r. Lam r \<in> rhs}" |
|
589 |
by (rule rev_finite_subset[OF fin]) (auto) |
|
590 |
then show "finite {r. Lam r \<in> rhs}" |
|
81 | 591 |
apply(simp add: image_Collect[symmetric]) |
592 |
apply(erule finite_imageD) |
|
593 |
apply(auto simp add: inj_on_def) |
|
79 | 594 |
done |
42 | 595 |
qed |
596 |
||
597 |
lemma rexp_of_empty: |
|
598 |
assumes finite:"finite rhs" |
|
599 |
and nonempty:"rhs_nonempty rhs" |
|
79 | 600 |
shows "[] \<notin> L (\<Uplus> {r. Trn X r \<in> rhs})" |
42 | 601 |
using finite nonempty rhs_nonempty_def |
79 | 602 |
using finite_Trn[OF finite] |
603 |
by (auto) |
|
42 | 604 |
|
605 |
lemma [intro!]: |
|
606 |
"P (Trn X r) \<Longrightarrow> (\<exists>a. (\<exists>r. a = Trn X r \<and> P a))" by auto |
|
607 |
||
608 |
lemma lang_of_rexp_of: |
|
609 |
assumes finite:"finite rhs" |
|
79 | 610 |
shows "L ({Trn X r| r. Trn X r \<in> rhs}) = X ;; (L (\<Uplus>{r. Trn X r \<in> rhs}))" |
42 | 611 |
proof - |
79 | 612 |
have "finite {r. Trn X r \<in> rhs}" |
613 |
by (rule finite_Trn[OF finite]) |
|
614 |
then show ?thesis |
|
615 |
apply(auto simp add: Seq_def) |
|
616 |
apply(rule_tac x = "s\<^isub>1" in exI, rule_tac x = "s\<^isub>2" in exI, auto) |
|
617 |
apply(rule_tac x= "Trn X xa" in exI) |
|
618 |
apply(auto simp: Seq_def) |
|
619 |
done |
|
42 | 620 |
qed |
621 |
||
622 |
lemma rexp_of_lam_eq_lam_set: |
|
79 | 623 |
assumes fin: "finite rhs" |
624 |
shows "L (\<Uplus>{r. Lam r \<in> rhs}) = L ({Lam r | r. Lam r \<in> rhs})" |
|
42 | 625 |
proof - |
79 | 626 |
have "finite ({r. Lam r \<in> rhs})" using fin by (rule finite_Lam) |
627 |
then show ?thesis by auto |
|
42 | 628 |
qed |
629 |
||
630 |
lemma [simp]: |
|
70 | 631 |
"L (attach_rexp r xb) = L xb ;; L r" |
79 | 632 |
apply (cases xb, auto simp: Seq_def) |
54 | 633 |
apply(rule_tac x = "s\<^isub>1 @ s\<^isub>1'" in exI, rule_tac x = "s\<^isub>2'" in exI) |
634 |
apply(auto simp: Seq_def) |
|
635 |
done |
|
42 | 636 |
|
637 |
lemma lang_of_append_rhs: |
|
638 |
"L (append_rhs_rexp rhs r) = L rhs ;; L r" |
|
639 |
apply (auto simp:append_rhs_rexp_def image_def) |
|
640 |
apply (auto simp:Seq_def) |
|
641 |
apply (rule_tac x = "L xb ;; L r" in exI, auto simp add:Seq_def) |
|
642 |
by (rule_tac x = "attach_rexp r xb" in exI, auto simp:Seq_def) |
|
643 |
||
644 |
lemma classes_of_union_distrib: |
|
645 |
"classes_of A \<union> classes_of B = classes_of (A \<union> B)" |
|
646 |
by (auto simp add:classes_of_def) |
|
647 |
||
648 |
lemma lefts_of_union_distrib: |
|
649 |
"lefts_of A \<union> lefts_of B = lefts_of (A \<union> B)" |
|
650 |
by (auto simp:lefts_of_def) |
|
651 |
||
652 |
||
653 |
subsubsection {* Intialization *} |
|
654 |
||
655 |
text {* |
|
86 | 656 |
The following several lemmas until @{text "init_ES_satisfy_invariant"} shows that |
657 |
the initial equational system satisfies invariant @{text "invariant"}. |
|
71 | 658 |
*} |
42 | 659 |
|
660 |
lemma defined_by_str: |
|
661 |
"\<lbrakk>s \<in> X; X \<in> UNIV // (\<approx>Lang)\<rbrakk> \<Longrightarrow> X = (\<approx>Lang) `` {s}" |
|
662 |
by (auto simp:quotient_def Image_def str_eq_rel_def) |
|
663 |
||
664 |
lemma every_eqclass_has_transition: |
|
665 |
assumes has_str: "s @ [c] \<in> X" |
|
666 |
and in_CS: "X \<in> UNIV // (\<approx>Lang)" |
|
667 |
obtains Y where "Y \<in> UNIV // (\<approx>Lang)" and "Y ;; {[c]} \<subseteq> X" and "s \<in> Y" |
|
668 |
proof - |
|
669 |
def Y \<equiv> "(\<approx>Lang) `` {s}" |
|
670 |
have "Y \<in> UNIV // (\<approx>Lang)" |
|
671 |
unfolding Y_def quotient_def by auto |
|
672 |
moreover |
|
673 |
have "X = (\<approx>Lang) `` {s @ [c]}" |
|
674 |
using has_str in_CS defined_by_str by blast |
|
675 |
then have "Y ;; {[c]} \<subseteq> X" |
|
676 |
unfolding Y_def Image_def Seq_def |
|
677 |
unfolding str_eq_rel_def |
|
678 |
by clarsimp |
|
679 |
moreover |
|
680 |
have "s \<in> Y" unfolding Y_def |
|
681 |
unfolding Image_def str_eq_rel_def by simp |
|
682 |
ultimately show thesis by (blast intro: that) |
|
683 |
qed |
|
684 |
||
685 |
lemma l_eq_r_in_eqs: |
|
686 |
assumes X_in_eqs: "(X, xrhs) \<in> (eqs (UNIV // (\<approx>Lang)))" |
|
687 |
shows "X = L xrhs" |
|
688 |
proof |
|
689 |
show "X \<subseteq> L xrhs" |
|
690 |
proof |
|
691 |
fix x |
|
692 |
assume "(1)": "x \<in> X" |
|
693 |
show "x \<in> L xrhs" |
|
694 |
proof (cases "x = []") |
|
695 |
assume empty: "x = []" |
|
696 |
thus ?thesis using X_in_eqs "(1)" |
|
697 |
by (auto simp:eqs_def init_rhs_def) |
|
698 |
next |
|
699 |
assume not_empty: "x \<noteq> []" |
|
700 |
then obtain clist c where decom: "x = clist @ [c]" |
|
701 |
by (case_tac x rule:rev_cases, auto) |
|
702 |
have "X \<in> UNIV // (\<approx>Lang)" using X_in_eqs by (auto simp:eqs_def) |
|
703 |
then obtain Y |
|
704 |
where "Y \<in> UNIV // (\<approx>Lang)" |
|
705 |
and "Y ;; {[c]} \<subseteq> X" |
|
706 |
and "clist \<in> Y" |
|
707 |
using decom "(1)" every_eqclass_has_transition by blast |
|
708 |
hence |
|
75 | 709 |
"x \<in> L {Trn Y (CHAR c)| Y c. Y \<in> UNIV // (\<approx>Lang) \<and> Y \<Turnstile>(CHAR c)\<Rightarrow> X}" |
71 | 710 |
unfolding transition_def |
711 |
using "(1)" decom |
|
42 | 712 |
by (simp, rule_tac x = "Trn Y (CHAR c)" in exI, simp add:Seq_def) |
71 | 713 |
thus ?thesis using X_in_eqs "(1)" |
714 |
by (simp add: eqs_def init_rhs_def) |
|
42 | 715 |
qed |
716 |
qed |
|
717 |
next |
|
718 |
show "L xrhs \<subseteq> X" using X_in_eqs |
|
71 | 719 |
by (auto simp:eqs_def init_rhs_def transition_def) |
42 | 720 |
qed |
721 |
||
722 |
lemma finite_init_rhs: |
|
723 |
assumes finite: "finite CS" |
|
724 |
shows "finite (init_rhs CS X)" |
|
725 |
proof- |
|
726 |
have "finite {Trn Y (CHAR c) |Y c. Y \<in> CS \<and> Y ;; {[c]} \<subseteq> X}" (is "finite ?A") |
|
727 |
proof - |
|
728 |
def S \<equiv> "{(Y, c)| Y c. Y \<in> CS \<and> Y ;; {[c]} \<subseteq> X}" |
|
729 |
def h \<equiv> "\<lambda> (Y, c). Trn Y (CHAR c)" |
|
730 |
have "finite (CS \<times> (UNIV::char set))" using finite by auto |
|
731 |
hence "finite S" using S_def |
|
732 |
by (rule_tac B = "CS \<times> UNIV" in finite_subset, auto) |
|
733 |
moreover have "?A = h ` S" by (auto simp: S_def h_def image_def) |
|
734 |
ultimately show ?thesis |
|
735 |
by auto |
|
736 |
qed |
|
71 | 737 |
thus ?thesis by (simp add:init_rhs_def transition_def) |
42 | 738 |
qed |
739 |
||
86 | 740 |
lemma init_ES_satisfy_invariant: |
42 | 741 |
assumes finite_CS: "finite (UNIV // (\<approx>Lang))" |
86 | 742 |
shows "invariant (eqs (UNIV // (\<approx>Lang)))" |
42 | 743 |
proof - |
744 |
have "finite (eqs (UNIV // (\<approx>Lang)))" using finite_CS |
|
745 |
by (simp add:eqs_def) |
|
746 |
moreover have "distinct_equas (eqs (UNIV // (\<approx>Lang)))" |
|
747 |
by (simp add:distinct_equas_def eqs_def) |
|
748 |
moreover have "ardenable (eqs (UNIV // (\<approx>Lang)))" |
|
749 |
by (auto simp add:ardenable_def eqs_def init_rhs_def rhs_nonempty_def del:L_rhs.simps) |
|
750 |
moreover have "valid_eqns (eqs (UNIV // (\<approx>Lang)))" |
|
751 |
using l_eq_r_in_eqs by (simp add:valid_eqns_def) |
|
752 |
moreover have "finite_rhs (eqs (UNIV // (\<approx>Lang)))" |
|
753 |
using finite_init_rhs[OF finite_CS] |
|
754 |
by (auto simp:finite_rhs_def eqs_def) |
|
755 |
moreover have "self_contained (eqs (UNIV // (\<approx>Lang)))" |
|
756 |
by (auto simp:self_contained_def eqs_def init_rhs_def classes_of_def lefts_of_def) |
|
86 | 757 |
ultimately show ?thesis by (simp add:invariant_def) |
42 | 758 |
qed |
759 |
||
760 |
subsubsection {* |
|
761 |
Interation step |
|
762 |
*} |
|
763 |
||
764 |
text {* |
|
765 |
From this point until @{text "iteration_step"}, it is proved |
|
86 | 766 |
that there exists iteration steps which keep @{text "invariant(ES)"} while |
42 | 767 |
decreasing the size of @{text "ES"}. |
71 | 768 |
*} |
769 |
||
86 | 770 |
lemma arden_op_keeps_eq: |
42 | 771 |
assumes l_eq_r: "X = L rhs" |
79 | 772 |
and not_empty: "[] \<notin> L (\<Uplus>{r. Trn X r \<in> rhs})" |
42 | 773 |
and finite: "finite rhs" |
86 | 774 |
shows "X = L (arden_op X rhs)" |
42 | 775 |
proof - |
79 | 776 |
def A \<equiv> "L (\<Uplus>{r. Trn X r \<in> rhs})" |
777 |
def b \<equiv> "rhs - trns_of rhs X" |
|
42 | 778 |
def B \<equiv> "L b" |
779 |
have "X = B ;; A\<star>" |
|
780 |
proof- |
|
79 | 781 |
have "L rhs = L(trns_of rhs X \<union> b)" by (auto simp: b_def trns_of_def) |
782 |
also have "\<dots> = X ;; A \<union> B" |
|
783 |
unfolding trns_of_def |
|
784 |
unfolding L_rhs_union_distrib[symmetric] |
|
785 |
by (simp only: lang_of_rexp_of finite B_def A_def) |
|
786 |
finally show ?thesis |
|
42 | 787 |
using l_eq_r not_empty |
86 | 788 |
apply(rule_tac arden[THEN iffD1]) |
79 | 789 |
apply(simp add: A_def) |
790 |
apply(simp) |
|
791 |
done |
|
42 | 792 |
qed |
86 | 793 |
moreover have "L (arden_op X rhs) = (B ;; A\<star>)" |
794 |
by (simp only:arden_op_def L_rhs_union_distrib lang_of_append_rhs |
|
50 | 795 |
B_def A_def b_def L_rexp.simps seq_union_distrib_left) |
42 | 796 |
ultimately show ?thesis by simp |
797 |
qed |
|
798 |
||
799 |
lemma append_keeps_finite: |
|
800 |
"finite rhs \<Longrightarrow> finite (append_rhs_rexp rhs r)" |
|
801 |
by (auto simp:append_rhs_rexp_def) |
|
802 |
||
86 | 803 |
lemma arden_op_keeps_finite: |
804 |
"finite rhs \<Longrightarrow> finite (arden_op X rhs)" |
|
805 |
by (auto simp:arden_op_def append_keeps_finite) |
|
42 | 806 |
|
807 |
lemma append_keeps_nonempty: |
|
808 |
"rhs_nonempty rhs \<Longrightarrow> rhs_nonempty (append_rhs_rexp rhs r)" |
|
809 |
apply (auto simp:rhs_nonempty_def append_rhs_rexp_def) |
|
810 |
by (case_tac x, auto simp:Seq_def) |
|
811 |
||
812 |
lemma nonempty_set_sub: |
|
813 |
"rhs_nonempty rhs \<Longrightarrow> rhs_nonempty (rhs - A)" |
|
814 |
by (auto simp:rhs_nonempty_def) |
|
815 |
||
816 |
lemma nonempty_set_union: |
|
817 |
"\<lbrakk>rhs_nonempty rhs; rhs_nonempty rhs'\<rbrakk> \<Longrightarrow> rhs_nonempty (rhs \<union> rhs')" |
|
818 |
by (auto simp:rhs_nonempty_def) |
|
819 |
||
86 | 820 |
lemma arden_op_keeps_nonempty: |
821 |
"rhs_nonempty rhs \<Longrightarrow> rhs_nonempty (arden_op X rhs)" |
|
822 |
by (simp only:arden_op_def append_keeps_nonempty nonempty_set_sub) |
|
42 | 823 |
|
824 |
||
86 | 825 |
lemma subst_op_keeps_nonempty: |
826 |
"\<lbrakk>rhs_nonempty rhs; rhs_nonempty xrhs\<rbrakk> \<Longrightarrow> rhs_nonempty (subst_op rhs X xrhs)" |
|
827 |
by (simp only:subst_op_def append_keeps_nonempty nonempty_set_union nonempty_set_sub) |
|
42 | 828 |
|
86 | 829 |
lemma subst_op_keeps_eq: |
42 | 830 |
assumes substor: "X = L xrhs" |
831 |
and finite: "finite rhs" |
|
86 | 832 |
shows "L (subst_op rhs X xrhs) = L rhs" (is "?Left = ?Right") |
42 | 833 |
proof- |
79 | 834 |
def A \<equiv> "L (rhs - trns_of rhs X)" |
835 |
have "?Left = A \<union> L (append_rhs_rexp xrhs (\<Uplus>{r. Trn X r \<in> rhs}))" |
|
86 | 836 |
unfolding subst_op_def |
79 | 837 |
unfolding L_rhs_union_distrib[symmetric] |
838 |
by (simp add: A_def) |
|
839 |
moreover have "?Right = A \<union> L ({Trn X r | r. Trn X r \<in> rhs})" |
|
42 | 840 |
proof- |
79 | 841 |
have "rhs = (rhs - trns_of rhs X) \<union> (trns_of rhs X)" by (auto simp add: trns_of_def) |
842 |
thus ?thesis |
|
843 |
unfolding A_def |
|
844 |
unfolding L_rhs_union_distrib |
|
845 |
unfolding trns_of_def |
|
846 |
by simp |
|
42 | 847 |
qed |
79 | 848 |
moreover have "L (append_rhs_rexp xrhs (\<Uplus>{r. Trn X r \<in> rhs})) = L ({Trn X r | r. Trn X r \<in> rhs})" |
42 | 849 |
using finite substor by (simp only:lang_of_append_rhs lang_of_rexp_of) |
850 |
ultimately show ?thesis by simp |
|
851 |
qed |
|
852 |
||
86 | 853 |
lemma subst_op_keeps_finite_rhs: |
854 |
"\<lbrakk>finite rhs; finite yrhs\<rbrakk> \<Longrightarrow> finite (subst_op rhs Y yrhs)" |
|
855 |
by (auto simp:subst_op_def append_keeps_finite) |
|
42 | 856 |
|
86 | 857 |
lemma subst_op_all_keeps_finite: |
42 | 858 |
assumes finite:"finite (ES:: (string set \<times> rhs_item set) set)" |
86 | 859 |
shows "finite (subst_op_all ES Y yrhs)" |
42 | 860 |
proof - |
86 | 861 |
have "finite {(Ya, subst_op yrhsa Y yrhs) |Ya yrhsa. (Ya, yrhsa) \<in> ES}" |
42 | 862 |
(is "finite ?A") |
863 |
proof- |
|
864 |
def eqns' \<equiv> "{((Ya::string set), yrhsa)| Ya yrhsa. (Ya, yrhsa) \<in> ES}" |
|
86 | 865 |
def h \<equiv> "\<lambda> ((Ya::string set), yrhsa). (Ya, subst_op yrhsa Y yrhs)" |
42 | 866 |
have "finite (h ` eqns')" using finite h_def eqns'_def by auto |
867 |
moreover have "?A = h ` eqns'" by (auto simp:h_def eqns'_def) |
|
868 |
ultimately show ?thesis by auto |
|
869 |
qed |
|
86 | 870 |
thus ?thesis by (simp add:subst_op_all_def) |
42 | 871 |
qed |
872 |
||
86 | 873 |
lemma subst_op_all_keeps_finite_rhs: |
874 |
"\<lbrakk>finite_rhs ES; finite yrhs\<rbrakk> \<Longrightarrow> finite_rhs (subst_op_all ES Y yrhs)" |
|
875 |
by (auto intro:subst_op_keeps_finite_rhs simp add:subst_op_all_def finite_rhs_def) |
|
42 | 876 |
|
877 |
lemma append_rhs_keeps_cls: |
|
878 |
"classes_of (append_rhs_rexp rhs r) = classes_of rhs" |
|
879 |
apply (auto simp:classes_of_def append_rhs_rexp_def) |
|
880 |
apply (case_tac xa, auto simp:image_def) |
|
881 |
by (rule_tac x = "SEQ ra r" in exI, rule_tac x = "Trn x ra" in bexI, simp+) |
|
882 |
||
86 | 883 |
lemma arden_op_removes_cl: |
884 |
"classes_of (arden_op Y yrhs) = classes_of yrhs - {Y}" |
|
885 |
apply (simp add:arden_op_def append_rhs_keeps_cls trns_of_def) |
|
42 | 886 |
by (auto simp:classes_of_def) |
887 |
||
888 |
lemma lefts_of_keeps_cls: |
|
86 | 889 |
"lefts_of (subst_op_all ES Y yrhs) = lefts_of ES" |
890 |
by (auto simp:lefts_of_def subst_op_all_def) |
|
42 | 891 |
|
86 | 892 |
lemma subst_op_updates_cls: |
42 | 893 |
"X \<notin> classes_of xrhs \<Longrightarrow> |
86 | 894 |
classes_of (subst_op rhs X xrhs) = classes_of rhs \<union> classes_of xrhs - {X}" |
895 |
apply (simp only:subst_op_def append_rhs_keeps_cls |
|
42 | 896 |
classes_of_union_distrib[THEN sym]) |
79 | 897 |
by (auto simp:classes_of_def trns_of_def) |
42 | 898 |
|
86 | 899 |
lemma subst_op_all_keeps_self_contained: |
42 | 900 |
fixes Y |
901 |
assumes sc: "self_contained (ES \<union> {(Y, yrhs)})" (is "self_contained ?A") |
|
86 | 902 |
shows "self_contained (subst_op_all ES Y (arden_op Y yrhs))" |
42 | 903 |
(is "self_contained ?B") |
904 |
proof- |
|
905 |
{ fix X xrhs' |
|
906 |
assume "(X, xrhs') \<in> ?B" |
|
907 |
then obtain xrhs |
|
86 | 908 |
where xrhs_xrhs': "xrhs' = subst_op xrhs Y (arden_op Y yrhs)" |
909 |
and X_in: "(X, xrhs) \<in> ES" by (simp add:subst_op_all_def, blast) |
|
42 | 910 |
have "classes_of xrhs' \<subseteq> lefts_of ?B" |
911 |
proof- |
|
86 | 912 |
have "lefts_of ?B = lefts_of ES" by (auto simp add:lefts_of_def subst_op_all_def) |
42 | 913 |
moreover have "classes_of xrhs' \<subseteq> lefts_of ES" |
914 |
proof- |
|
915 |
have "classes_of xrhs' \<subseteq> |
|
86 | 916 |
classes_of xrhs \<union> classes_of (arden_op Y yrhs) - {Y}" |
42 | 917 |
proof- |
86 | 918 |
have "Y \<notin> classes_of (arden_op Y yrhs)" |
919 |
using arden_op_removes_cl by simp |
|
920 |
thus ?thesis using xrhs_xrhs' by (auto simp:subst_op_updates_cls) |
|
42 | 921 |
qed |
922 |
moreover have "classes_of xrhs \<subseteq> lefts_of ES \<union> {Y}" using X_in sc |
|
923 |
apply (simp only:self_contained_def lefts_of_union_distrib[THEN sym]) |
|
924 |
by (drule_tac x = "(X, xrhs)" in bspec, auto simp:lefts_of_def) |
|
86 | 925 |
moreover have "classes_of (arden_op Y yrhs) \<subseteq> lefts_of ES \<union> {Y}" |
42 | 926 |
using sc |
86 | 927 |
by (auto simp add:arden_op_removes_cl self_contained_def lefts_of_def) |
42 | 928 |
ultimately show ?thesis by auto |
929 |
qed |
|
930 |
ultimately show ?thesis by simp |
|
931 |
qed |
|
86 | 932 |
} thus ?thesis by (auto simp only:subst_op_all_def self_contained_def) |
42 | 933 |
qed |
934 |
||
86 | 935 |
lemma subst_op_all_satisfy_invariant: |
936 |
assumes invariant_ES: "invariant (ES \<union> {(Y, yrhs)})" |
|
937 |
shows "invariant (subst_op_all ES Y (arden_op Y yrhs))" |
|
42 | 938 |
proof - |
939 |
have finite_yrhs: "finite yrhs" |
|
86 | 940 |
using invariant_ES by (auto simp:invariant_def finite_rhs_def) |
42 | 941 |
have nonempty_yrhs: "rhs_nonempty yrhs" |
86 | 942 |
using invariant_ES by (auto simp:invariant_def ardenable_def) |
42 | 943 |
have Y_eq_yrhs: "Y = L yrhs" |
86 | 944 |
using invariant_ES by (simp only:invariant_def valid_eqns_def, blast) |
945 |
have "distinct_equas (subst_op_all ES Y (arden_op Y yrhs))" |
|
946 |
using invariant_ES |
|
947 |
by (auto simp:distinct_equas_def subst_op_all_def invariant_def) |
|
948 |
moreover have "finite (subst_op_all ES Y (arden_op Y yrhs))" |
|
949 |
using invariant_ES by (simp add:invariant_def subst_op_all_keeps_finite) |
|
950 |
moreover have "finite_rhs (subst_op_all ES Y (arden_op Y yrhs))" |
|
42 | 951 |
proof- |
86 | 952 |
have "finite_rhs ES" using invariant_ES |
953 |
by (simp add:invariant_def finite_rhs_def) |
|
954 |
moreover have "finite (arden_op Y yrhs)" |
|
42 | 955 |
proof - |
86 | 956 |
have "finite yrhs" using invariant_ES |
957 |
by (auto simp:invariant_def finite_rhs_def) |
|
958 |
thus ?thesis using arden_op_keeps_finite by simp |
|
42 | 959 |
qed |
960 |
ultimately show ?thesis |
|
86 | 961 |
by (simp add:subst_op_all_keeps_finite_rhs) |
42 | 962 |
qed |
86 | 963 |
moreover have "ardenable (subst_op_all ES Y (arden_op Y yrhs))" |
42 | 964 |
proof - |
965 |
{ fix X rhs |
|
966 |
assume "(X, rhs) \<in> ES" |
|
86 | 967 |
hence "rhs_nonempty rhs" using prems invariant_ES |
968 |
by (simp add:invariant_def ardenable_def) |
|
42 | 969 |
with nonempty_yrhs |
86 | 970 |
have "rhs_nonempty (subst_op rhs Y (arden_op Y yrhs))" |
42 | 971 |
by (simp add:nonempty_yrhs |
86 | 972 |
subst_op_keeps_nonempty arden_op_keeps_nonempty) |
973 |
} thus ?thesis by (auto simp add:ardenable_def subst_op_all_def) |
|
42 | 974 |
qed |
86 | 975 |
moreover have "valid_eqns (subst_op_all ES Y (arden_op Y yrhs))" |
42 | 976 |
proof- |
86 | 977 |
have "Y = L (arden_op Y yrhs)" |
978 |
using Y_eq_yrhs invariant_ES finite_yrhs nonempty_yrhs |
|
979 |
by (rule_tac arden_op_keeps_eq, (simp add:rexp_of_empty)+) |
|
980 |
thus ?thesis using invariant_ES |
|
42 | 981 |
by (clarsimp simp add:valid_eqns_def |
86 | 982 |
subst_op_all_def subst_op_keeps_eq invariant_def finite_rhs_def |
42 | 983 |
simp del:L_rhs.simps) |
984 |
qed |
|
985 |
moreover |
|
86 | 986 |
have self_subst: "self_contained (subst_op_all ES Y (arden_op Y yrhs))" |
987 |
using invariant_ES subst_op_all_keeps_self_contained by (simp add:invariant_def) |
|
988 |
ultimately show ?thesis using invariant_ES by (simp add:invariant_def) |
|
42 | 989 |
qed |
990 |
||
86 | 991 |
lemma subst_op_all_card_le: |
42 | 992 |
assumes finite: "finite (ES::(string set \<times> rhs_item set) set)" |
86 | 993 |
shows "card (subst_op_all ES Y yrhs) <= card ES" |
42 | 994 |
proof- |
86 | 995 |
def f \<equiv> "\<lambda> x. ((fst x)::string set, subst_op (snd x) Y yrhs)" |
996 |
have "subst_op_all ES Y yrhs = f ` ES" |
|
997 |
apply (auto simp:subst_op_all_def f_def image_def) |
|
42 | 998 |
by (rule_tac x = "(Ya, yrhsa)" in bexI, simp+) |
999 |
thus ?thesis using finite by (auto intro:card_image_le) |
|
1000 |
qed |
|
1001 |
||
86 | 1002 |
lemma subst_op_all_cls_remains: |
1003 |
"(X, xrhs) \<in> ES \<Longrightarrow> \<exists> xrhs'. (X, xrhs') \<in> (subst_op_all ES Y yrhs)" |
|
1004 |
by (auto simp:subst_op_all_def) |
|
42 | 1005 |
|
1006 |
lemma card_noteq_1_has_more: |
|
1007 |
assumes card:"card S \<noteq> 1" |
|
1008 |
and e_in: "e \<in> S" |
|
1009 |
and finite: "finite S" |
|
1010 |
obtains e' where "e' \<in> S \<and> e \<noteq> e'" |
|
1011 |
proof- |
|
1012 |
have "card (S - {e}) > 0" |
|
1013 |
proof - |
|
1014 |
have "card S > 1" using card e_in finite |
|
1015 |
by (case_tac "card S", auto) |
|
1016 |
thus ?thesis using finite e_in by auto |
|
1017 |
qed |
|
1018 |
hence "S - {e} \<noteq> {}" using finite by (rule_tac notI, simp) |
|
1019 |
thus "(\<And>e'. e' \<in> S \<and> e \<noteq> e' \<Longrightarrow> thesis) \<Longrightarrow> thesis" by auto |
|
1020 |
qed |
|
1021 |
||
1022 |
lemma iteration_step: |
|
86 | 1023 |
assumes invariant_ES: "invariant ES" |
42 | 1024 |
and X_in_ES: "(X, xrhs) \<in> ES" |
1025 |
and not_T: "card ES \<noteq> 1" |
|
86 | 1026 |
shows "\<exists> ES'. (invariant ES' \<and> (\<exists> xrhs'.(X, xrhs') \<in> ES')) \<and> |
42 | 1027 |
(card ES', card ES) \<in> less_than" (is "\<exists> ES'. ?P ES'") |
1028 |
proof - |
|
86 | 1029 |
have finite_ES: "finite ES" using invariant_ES by (simp add:invariant_def) |
42 | 1030 |
then obtain Y yrhs |
1031 |
where Y_in_ES: "(Y, yrhs) \<in> ES" and not_eq: "(X, xrhs) \<noteq> (Y, yrhs)" |
|
1032 |
using not_T X_in_ES by (drule_tac card_noteq_1_has_more, auto) |
|
1033 |
def ES' == "ES - {(Y, yrhs)}" |
|
86 | 1034 |
let ?ES'' = "subst_op_all ES' Y (arden_op Y yrhs)" |
42 | 1035 |
have "?P ?ES''" |
1036 |
proof - |
|
86 | 1037 |
have "invariant ?ES''" using Y_in_ES invariant_ES |
1038 |
by (rule_tac subst_op_all_satisfy_invariant, simp add:ES'_def insert_absorb) |
|
42 | 1039 |
moreover have "\<exists>xrhs'. (X, xrhs') \<in> ?ES''" using not_eq X_in_ES |
86 | 1040 |
by (rule_tac ES = ES' in subst_op_all_cls_remains, auto simp add:ES'_def) |
42 | 1041 |
moreover have "(card ?ES'', card ES) \<in> less_than" |
1042 |
proof - |
|
1043 |
have "finite ES'" using finite_ES ES'_def by auto |
|
1044 |
moreover have "card ES' < card ES" using finite_ES Y_in_ES |
|
1045 |
by (auto simp:ES'_def card_gt_0_iff intro:diff_Suc_less) |
|
1046 |
ultimately show ?thesis |
|
86 | 1047 |
by (auto dest:subst_op_all_card_le elim:le_less_trans) |
42 | 1048 |
qed |
1049 |
ultimately show ?thesis by simp |
|
1050 |
qed |
|
1051 |
thus ?thesis by blast |
|
1052 |
qed |
|
1053 |
||
1054 |
subsubsection {* |
|
1055 |
Conclusion of the proof |
|
1056 |
*} |
|
1057 |
||
1058 |
text {* |
|
1059 |
From this point until @{text "hard_direction"}, the hard direction is proved |
|
1060 |
through a simple application of the iteration principle. |
|
1061 |
*} |
|
1062 |
||
1063 |
lemma iteration_conc: |
|
86 | 1064 |
assumes history: "invariant ES" |
42 | 1065 |
and X_in_ES: "\<exists> xrhs. (X, xrhs) \<in> ES" |
1066 |
shows |
|
86 | 1067 |
"\<exists> ES'. (invariant ES' \<and> (\<exists> xrhs'. (X, xrhs') \<in> ES')) \<and> card ES' = 1" |
42 | 1068 |
(is "\<exists> ES'. ?P ES'") |
1069 |
proof (cases "card ES = 1") |
|
1070 |
case True |
|
1071 |
thus ?thesis using history X_in_ES |
|
1072 |
by blast |
|
1073 |
next |
|
1074 |
case False |
|
1075 |
thus ?thesis using history iteration_step X_in_ES |
|
1076 |
by (rule_tac f = card in wf_iter, auto) |
|
1077 |
qed |
|
1078 |
||
1079 |
lemma last_cl_exists_rexp: |
|
1080 |
assumes ES_single: "ES = {(X, xrhs)}" |
|
86 | 1081 |
and invariant_ES: "invariant ES" |
42 | 1082 |
shows "\<exists> (r::rexp). L r = X" (is "\<exists> r. ?P r") |
1083 |
proof- |
|
86 | 1084 |
def A \<equiv> "arden_op X xrhs" |
81 | 1085 |
have "?P (\<Uplus>{r. Lam r \<in> A})" |
42 | 1086 |
proof - |
79 | 1087 |
have "L (\<Uplus>{r. Lam r \<in> A}) = L ({Lam r | r. Lam r \<in> A})" |
42 | 1088 |
proof(rule rexp_of_lam_eq_lam_set) |
79 | 1089 |
show "finite A" |
1090 |
unfolding A_def |
|
86 | 1091 |
using invariant_ES ES_single |
1092 |
by (rule_tac arden_op_keeps_finite) |
|
1093 |
(auto simp add: invariant_def finite_rhs_def) |
|
42 | 1094 |
qed |
79 | 1095 |
also have "\<dots> = L A" |
42 | 1096 |
proof- |
80 | 1097 |
have "{Lam r | r. Lam r \<in> A} = A" |
42 | 1098 |
proof- |
86 | 1099 |
have "classes_of A = {}" using invariant_ES ES_single |
79 | 1100 |
unfolding A_def |
86 | 1101 |
by (simp add:arden_op_removes_cl |
1102 |
self_contained_def invariant_def lefts_of_def) |
|
79 | 1103 |
thus ?thesis |
1104 |
unfolding A_def |
|
80 | 1105 |
by (auto simp only: classes_of_def, case_tac x, auto) |
42 | 1106 |
qed |
80 | 1107 |
thus ?thesis by simp |
42 | 1108 |
qed |
1109 |
also have "\<dots> = X" |
|
79 | 1110 |
unfolding A_def |
86 | 1111 |
proof(rule arden_op_keeps_eq [THEN sym]) |
1112 |
show "X = L xrhs" using invariant_ES ES_single |
|
1113 |
by (auto simp only:invariant_def valid_eqns_def) |
|
42 | 1114 |
next |
86 | 1115 |
from invariant_ES ES_single show "[] \<notin> L (\<Uplus>{r. Trn X r \<in> xrhs})" |
1116 |
by(simp add:invariant_def ardenable_def rexp_of_empty finite_rhs_def) |
|
42 | 1117 |
next |
86 | 1118 |
from invariant_ES ES_single show "finite xrhs" |
1119 |
by (simp add:invariant_def finite_rhs_def) |
|
42 | 1120 |
qed |
81 | 1121 |
finally show ?thesis by simp |
42 | 1122 |
qed |
1123 |
thus ?thesis by auto |
|
1124 |
qed |
|
1125 |
||
1126 |
lemma every_eqcl_has_reg: |
|
1127 |
assumes finite_CS: "finite (UNIV // (\<approx>Lang))" |
|
1128 |
and X_in_CS: "X \<in> (UNIV // (\<approx>Lang))" |
|
1129 |
shows "\<exists> (reg::rexp). L reg = X" (is "\<exists> r. ?E r") |
|
1130 |
proof - |
|
1131 |
from X_in_CS have "\<exists> xrhs. (X, xrhs) \<in> (eqs (UNIV // (\<approx>Lang)))" |
|
1132 |
by (auto simp:eqs_def init_rhs_def) |
|
86 | 1133 |
then obtain ES xrhs where invariant_ES: "invariant ES" |
42 | 1134 |
and X_in_ES: "(X, xrhs) \<in> ES" |
1135 |
and card_ES: "card ES = 1" |
|
86 | 1136 |
using finite_CS X_in_CS init_ES_satisfy_invariant iteration_conc |
42 | 1137 |
by blast |
1138 |
hence ES_single_equa: "ES = {(X, xrhs)}" |
|
86 | 1139 |
by (auto simp:invariant_def dest!:card_Suc_Diff1 simp:card_eq_0_iff) |
1140 |
thus ?thesis using invariant_ES |
|
42 | 1141 |
by (rule last_cl_exists_rexp) |
1142 |
qed |
|
1143 |
||
1144 |
theorem hard_direction: |
|
70 | 1145 |
assumes finite_CS: "finite (UNIV // \<approx>A)" |
1146 |
shows "\<exists>r::rexp. A = L r" |
|
42 | 1147 |
proof - |
70 | 1148 |
have "\<forall> X \<in> (UNIV // \<approx>A). \<exists>reg::rexp. X = L reg" |
42 | 1149 |
using finite_CS every_eqcl_has_reg by blast |
1150 |
then obtain f |
|
70 | 1151 |
where f_prop: "\<forall> X \<in> (UNIV // \<approx>A). X = L ((f X)::rexp)" |
1152 |
by (auto dest: bchoice) |
|
1153 |
def rs \<equiv> "f ` (finals A)" |
|
1154 |
have "A = \<Union> (finals A)" using lang_is_union_of_finals by auto |
|
76 | 1155 |
also have "\<dots> = L (\<Uplus>rs)" |
42 | 1156 |
proof - |
1157 |
have "finite rs" |
|
1158 |
proof - |
|
70 | 1159 |
have "finite (finals A)" |
1160 |
using finite_CS finals_in_partitions[of "A"] |
|
42 | 1161 |
by (erule_tac finite_subset, simp) |
1162 |
thus ?thesis using rs_def by auto |
|
1163 |
qed |
|
1164 |
thus ?thesis |
|
70 | 1165 |
using f_prop rs_def finals_in_partitions[of "A"] by auto |
42 | 1166 |
qed |
1167 |
finally show ?thesis by blast |
|
1168 |
qed |
|
1169 |
||
1170 |
end |