author | urbanc |
Mon, 14 Feb 2011 09:38:18 +0000 | |
changeset 101 | d3fe0597080a |
parent 100 | 2409827d8eb8 |
child 103 | f460d5f75cb5 |
permissions | -rw-r--r-- |
42 | 1 |
theory Myhill_1 |
91 | 2 |
imports Main Folds While_Combinator |
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 |
section {* A modified version of Arden's lemma *} |
50 | 188 |
|
70 | 189 |
text {* A helper lemma for Arden *} |
50 | 190 |
|
86 | 191 |
lemma arden_helper: |
50 | 192 |
assumes eq: "X = X ;; A \<union> B" |
193 |
shows "X = X ;; (A \<up> Suc n) \<union> (\<Union>m\<in>{0..n}. B ;; (A \<up> m))" |
|
194 |
proof (induct n) |
|
195 |
case 0 |
|
196 |
show "X = X ;; (A \<up> Suc 0) \<union> (\<Union>(m::nat)\<in>{0..0}. B ;; (A \<up> m))" |
|
197 |
using eq by simp |
|
198 |
next |
|
199 |
case (Suc n) |
|
200 |
have ih: "X = X ;; (A \<up> Suc n) \<union> (\<Union>m\<in>{0..n}. B ;; (A \<up> m))" by fact |
|
201 |
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 |
|
202 |
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))" |
|
203 |
by (simp add: seq_union_distrib_right seq_assoc) |
|
204 |
also have "\<dots> = X ;; (A \<up> Suc (Suc n)) \<union> (\<Union>m\<in>{0..Suc n}. B ;; (A \<up> m))" |
|
205 |
by (auto simp add: le_Suc_eq) |
|
206 |
finally show "X = X ;; (A \<up> Suc (Suc n)) \<union> (\<Union>m\<in>{0..Suc n}. B ;; (A \<up> m))" . |
|
207 |
qed |
|
208 |
||
86 | 209 |
theorem arden: |
50 | 210 |
assumes nemp: "[] \<notin> A" |
211 |
shows "X = X ;; A \<union> B \<longleftrightarrow> X = B ;; A\<star>" |
|
212 |
proof |
|
213 |
assume eq: "X = B ;; A\<star>" |
|
214 |
have "A\<star> = {[]} \<union> A\<star> ;; A" |
|
215 |
unfolding seq_star_comm[symmetric] |
|
71 | 216 |
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
|
217 |
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
|
218 |
by (rule seq_add_left) |
50 | 219 |
also have "\<dots> = B \<union> B ;; (A\<star> ;; A)" |
220 |
unfolding seq_union_distrib_left by simp |
|
221 |
also have "\<dots> = B \<union> (B ;; A\<star>) ;; A" |
|
222 |
by (simp only: seq_assoc) |
|
223 |
finally show "X = X ;; A \<union> B" |
|
224 |
using eq by blast |
|
225 |
next |
|
226 |
assume eq: "X = X ;; A \<union> B" |
|
227 |
{ fix n::nat |
|
86 | 228 |
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
|
229 |
then have "B ;; A\<star> \<subseteq> X" |
86 | 230 |
unfolding Seq_def Star_def UNION_def by auto |
50 | 231 |
moreover |
232 |
{ fix s::string |
|
233 |
obtain k where "k = length s" by auto |
|
234 |
then have not_in: "s \<notin> X ;; (A \<up> Suc k)" |
|
235 |
using seq_pow_length[OF nemp] by blast |
|
236 |
assume "s \<in> X" |
|
237 |
then have "s \<in> X ;; (A \<up> Suc k) \<union> (\<Union>m\<in>{0..k}. B ;; (A \<up> m))" |
|
86 | 238 |
using arden_helper[OF eq, of "k"] by auto |
50 | 239 |
then have "s \<in> (\<Union>m\<in>{0..k}. B ;; (A \<up> m))" using not_in by auto |
240 |
moreover |
|
241 |
have "(\<Union>m\<in>{0..k}. B ;; (A \<up> m)) \<subseteq> (\<Union>n. B ;; (A \<up> n))" by auto |
|
242 |
ultimately |
|
56
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
243 |
have "s \<in> B ;; A\<star>" |
86 | 244 |
unfolding seq_Union_left Star_def by auto } |
50 | 245 |
then have "X \<subseteq> B ;; A\<star>" by auto |
246 |
ultimately |
|
247 |
show "X = B ;; A\<star>" by simp |
|
248 |
qed |
|
249 |
||
42 | 250 |
|
70 | 251 |
section {* Regular Expressions *} |
48 | 252 |
|
253 |
datatype rexp = |
|
254 |
NULL |
|
255 |
| EMPTY |
|
256 |
| CHAR char |
|
257 |
| SEQ rexp rexp |
|
258 |
| ALT rexp rexp |
|
259 |
| STAR rexp |
|
260 |
||
261 |
||
262 |
text {* |
|
86 | 263 |
The function @{text L} is overloaded, with the idea that @{text "L x"} |
264 |
evaluates to the language represented by the object @{text x}. |
|
48 | 265 |
*} |
266 |
||
70 | 267 |
consts L:: "'a \<Rightarrow> lang" |
48 | 268 |
|
70 | 269 |
overloading L_rexp \<equiv> "L:: rexp \<Rightarrow> lang" |
48 | 270 |
begin |
271 |
fun |
|
88 | 272 |
L_rexp :: "rexp \<Rightarrow> lang" |
48 | 273 |
where |
274 |
"L_rexp (NULL) = {}" |
|
275 |
| "L_rexp (EMPTY) = {[]}" |
|
276 |
| "L_rexp (CHAR c) = {[c]}" |
|
277 |
| "L_rexp (SEQ r1 r2) = (L_rexp r1) ;; (L_rexp r2)" |
|
278 |
| "L_rexp (ALT r1 r2) = (L_rexp r1) \<union> (L_rexp r2)" |
|
279 |
| "L_rexp (STAR r) = (L_rexp r)\<star>" |
|
280 |
end |
|
281 |
||
88 | 282 |
|
86 | 283 |
text {* ALT-combination of a set or regulare expressions *} |
50 | 284 |
|
76 | 285 |
abbreviation |
286 |
Setalt ("\<Uplus>_" [1000] 999) |
|
287 |
where |
|
94 | 288 |
"\<Uplus>A \<equiv> folds ALT NULL A" |
76 | 289 |
|
50 | 290 |
text {* |
86 | 291 |
For finite sets, @{term Setalt} is preserved under @{term L}. |
79 | 292 |
*} |
70 | 293 |
|
50 | 294 |
lemma folds_alt_simp [simp]: |
88 | 295 |
fixes rs::"rexp set" |
70 | 296 |
assumes a: "finite rs" |
76 | 297 |
shows "L (\<Uplus>rs) = \<Union> (L ` rs)" |
94 | 298 |
unfolding folds_def |
75 | 299 |
apply(rule set_eqI) |
70 | 300 |
apply(rule someI2_ex) |
301 |
apply(rule_tac finite_imp_fold_graph[OF a]) |
|
302 |
apply(erule fold_graph.induct) |
|
303 |
apply(auto) |
|
304 |
done |
|
50 | 305 |
|
70 | 306 |
|
86 | 307 |
section {* Direction @{text "finite partition \<Rightarrow> regular language"} *} |
308 |
||
309 |
||
70 | 310 |
text {* Just a technical lemma for collections and pairs *} |
311 |
||
75 | 312 |
lemma Pair_Collect[simp]: |
48 | 313 |
shows "(x, y) \<in> {(x, y). P x y} \<longleftrightarrow> P x y" |
314 |
by simp |
|
315 |
||
86 | 316 |
text {* Myhill-Nerode relation *} |
317 |
||
48 | 318 |
definition |
71 | 319 |
str_eq_rel :: "lang \<Rightarrow> (string \<times> string) set" ("\<approx>_" [100] 100) |
48 | 320 |
where |
70 | 321 |
"\<approx>A \<equiv> {(x, y). (\<forall>z. x @ z \<in> A \<longleftrightarrow> y @ z \<in> A)}" |
48 | 322 |
|
323 |
text {* |
|
86 | 324 |
Among the equivalence clases of @{text "\<approx>A"}, the set @{text "finals A"} |
325 |
singles out those which contains the strings from @{text A}. |
|
48 | 326 |
*} |
327 |
||
328 |
definition |
|
71 | 329 |
finals :: "lang \<Rightarrow> lang set" |
330 |
where |
|
331 |
"finals A \<equiv> {\<approx>A `` {x} | x . x \<in> A}" |
|
48 | 332 |
|
70 | 333 |
|
48 | 334 |
lemma lang_is_union_of_finals: |
70 | 335 |
shows "A = \<Union> finals A" |
336 |
unfolding finals_def |
|
337 |
unfolding Image_def |
|
338 |
unfolding str_eq_rel_def |
|
339 |
apply(auto) |
|
340 |
apply(drule_tac x = "[]" in spec) |
|
341 |
apply(auto) |
|
342 |
done |
|
343 |
||
79 | 344 |
lemma finals_in_partitions: |
345 |
shows "finals A \<subseteq> (UNIV // \<approx>A)" |
|
94 | 346 |
unfolding finals_def quotient_def |
76 | 347 |
by auto |
348 |
||
86 | 349 |
section {* Equational systems *} |
42 | 350 |
|
89 | 351 |
text {* The two kinds of terms in the rhs of equations. *} |
352 |
||
42 | 353 |
datatype rhs_item = |
86 | 354 |
Lam "rexp" (* Lambda-marker *) |
70 | 355 |
| Trn "lang" "rexp" (* Transition *) |
356 |
||
42 | 357 |
|
86 | 358 |
overloading L_rhs_item \<equiv> "L:: rhs_item \<Rightarrow> lang" |
42 | 359 |
begin |
86 | 360 |
fun L_rhs_item:: "rhs_item \<Rightarrow> lang" |
42 | 361 |
where |
86 | 362 |
"L_rhs_item (Lam r) = L r" |
363 |
| "L_rhs_item (Trn X r) = X ;; L r" |
|
42 | 364 |
end |
365 |
||
70 | 366 |
overloading L_rhs \<equiv> "L:: rhs_item set \<Rightarrow> lang" |
42 | 367 |
begin |
70 | 368 |
fun L_rhs:: "rhs_item set \<Rightarrow> lang" |
369 |
where |
|
370 |
"L_rhs rhs = \<Union> (L ` rhs)" |
|
42 | 371 |
end |
372 |
||
96 | 373 |
lemma L_rhs_union_distrib: |
374 |
fixes A B::"rhs_item set" |
|
375 |
shows "L A \<union> L B = L (A \<union> B)" |
|
376 |
by simp |
|
377 |
||
378 |
||
379 |
||
86 | 380 |
text {* Transitions between equivalence classes *} |
71 | 381 |
|
382 |
definition |
|
92 | 383 |
transition :: "lang \<Rightarrow> char \<Rightarrow> lang \<Rightarrow> bool" ("_ \<Turnstile>_\<Rightarrow>_" [100,100,100] 100) |
71 | 384 |
where |
92 | 385 |
"Y \<Turnstile>c\<Rightarrow> X \<equiv> Y ;; {[c]} \<subseteq> X" |
42 | 386 |
|
86 | 387 |
text {* Initial equational system *} |
388 |
||
42 | 389 |
definition |
96 | 390 |
"Init_rhs CS X \<equiv> |
42 | 391 |
if ([] \<in> X) then |
92 | 392 |
{Lam EMPTY} \<union> {Trn Y (CHAR c) | Y c. Y \<in> CS \<and> Y \<Turnstile>c\<Rightarrow> X} |
42 | 393 |
else |
92 | 394 |
{Trn Y (CHAR c)| Y c. Y \<in> CS \<and> Y \<Turnstile>c\<Rightarrow> X}" |
42 | 395 |
|
86 | 396 |
definition |
96 | 397 |
"Init CS \<equiv> {(X, Init_rhs CS X) | X. X \<in> CS}" |
75 | 398 |
|
399 |
||
400 |
||
86 | 401 |
section {* Arden Operation on equations *} |
42 | 402 |
|
403 |
text {* |
|
86 | 404 |
The function @{text "attach_rexp r item"} SEQ-composes @{text r} to the |
405 |
right of every rhs-item. |
|
75 | 406 |
*} |
42 | 407 |
|
70 | 408 |
fun |
92 | 409 |
append_rexp :: "rexp \<Rightarrow> rhs_item \<Rightarrow> rhs_item" |
42 | 410 |
where |
92 | 411 |
"append_rexp r (Lam rexp) = Lam (SEQ rexp r)" |
412 |
| "append_rexp r (Trn X rexp) = Trn X (SEQ rexp r)" |
|
42 | 413 |
|
414 |
||
415 |
definition |
|
92 | 416 |
"append_rhs_rexp rhs rexp \<equiv> (append_rexp rexp) ` rhs" |
42 | 417 |
|
86 | 418 |
definition |
94 | 419 |
"Arden X rhs \<equiv> |
420 |
append_rhs_rexp (rhs - {Trn X r | r. Trn X r \<in> rhs}) (STAR (\<Uplus> {r. Trn X r \<in> rhs}))" |
|
86 | 421 |
|
422 |
||
423 |
section {* Substitution Operation on equations *} |
|
424 |
||
425 |
text {* |
|
95 | 426 |
Suppose and equation @{text "X = xrhs"}, @{text "Subst"} substitutes |
86 | 427 |
all occurences of @{text "X"} in @{text "rhs"} by @{text "xrhs"}. |
71 | 428 |
*} |
429 |
||
42 | 430 |
definition |
94 | 431 |
"Subst rhs X xrhs \<equiv> |
432 |
(rhs - {Trn X r | r. Trn X r \<in> rhs}) \<union> (append_rhs_rexp xrhs (\<Uplus> {r. Trn X r \<in> rhs}))" |
|
42 | 433 |
|
434 |
text {* |
|
86 | 435 |
@{text "eqs_subst ES X xrhs"} substitutes @{text xrhs} into every |
436 |
equation of the equational system @{text ES}. |
|
437 |
*} |
|
42 | 438 |
|
97 | 439 |
types esystem = "(lang \<times> rhs_item set) set" |
440 |
||
42 | 441 |
definition |
97 | 442 |
Subst_all :: "esystem \<Rightarrow> lang \<Rightarrow> rhs_item set \<Rightarrow> esystem" |
443 |
where |
|
94 | 444 |
"Subst_all ES X xrhs \<equiv> {(Y, Subst yrhs X xrhs) | Y yrhs. (Y, yrhs) \<in> ES}" |
86 | 445 |
|
42 | 446 |
text {* |
91 | 447 |
The following term @{text "remove ES Y yrhs"} removes the equation |
448 |
@{text "Y = yrhs"} from equational system @{text "ES"} by replacing |
|
449 |
all occurences of @{text "Y"} by its definition (using @{text "eqs_subst"}). |
|
450 |
The @{text "Y"}-definition is made non-recursive using Arden's transformation |
|
451 |
@{text "arden_variate Y yrhs"}. |
|
452 |
*} |
|
453 |
||
454 |
definition |
|
96 | 455 |
"Remove ES X xrhs \<equiv> |
456 |
Subst_all (ES - {(X, xrhs)}) X (Arden X xrhs)" |
|
457 |
||
458 |
||
459 |
section {* While-combinator *} |
|
91 | 460 |
|
461 |
text {* |
|
96 | 462 |
The following term @{text "Iter X ES"} represents one iteration in the while loop. |
91 | 463 |
It arbitrarily chooses a @{text "Y"} different from @{text "X"} to remove. |
71 | 464 |
*} |
42 | 465 |
|
91 | 466 |
definition |
96 | 467 |
"Iter X ES \<equiv> (let (Y, yrhs) = SOME (Y, yrhs). (Y, yrhs) \<in> ES \<and> X \<noteq> Y |
95 | 468 |
in Remove ES Y yrhs)" |
42 | 469 |
|
97 | 470 |
lemma IterI2: |
471 |
assumes "(Y, yrhs) \<in> ES" |
|
472 |
and "X \<noteq> Y" |
|
473 |
and "\<And>Y yrhs. \<lbrakk>(Y, yrhs) \<in> ES; X \<noteq> Y\<rbrakk> \<Longrightarrow> Q (Remove ES Y yrhs)" |
|
474 |
shows "Q (Iter X ES)" |
|
475 |
unfolding Iter_def using assms |
|
476 |
by (rule_tac a="(Y, yrhs)" in someI2) (auto) |
|
477 |
||
478 |
||
42 | 479 |
text {* |
96 | 480 |
The following term @{text "Reduce X ES"} repeatedly removes characteriztion equations |
91 | 481 |
for unknowns other than @{text "X"} until one is left. |
42 | 482 |
*} |
483 |
||
97 | 484 |
abbreviation |
101 | 485 |
"Cond ES \<equiv> card ES \<noteq> 1" |
97 | 486 |
|
91 | 487 |
definition |
101 | 488 |
"Solve X ES \<equiv> while Cond (Iter X) ES" |
97 | 489 |
|
91 | 490 |
text {* |
97 | 491 |
Since the @{text "while"} combinator from HOL library is used to implement @{text "Solve X ES"}, |
91 | 492 |
the induction principle @{thm [source] while_rule} is used to proved the desired properties |
97 | 493 |
of @{text "Solve X ES"}. For this purpose, an invariant predicate @{text "invariant"} is defined |
91 | 494 |
in terms of a series of auxilliary predicates: |
495 |
*} |
|
86 | 496 |
|
497 |
section {* Invariants *} |
|
498 |
||
97 | 499 |
text {* Every variable is defined at most once in @{text ES}. *} |
75 | 500 |
|
42 | 501 |
definition |
502 |
"distinct_equas ES \<equiv> |
|
86 | 503 |
\<forall> X rhs rhs'. (X, rhs) \<in> ES \<and> (X, rhs') \<in> ES \<longrightarrow> rhs = rhs'" |
70 | 504 |
|
97 | 505 |
|
42 | 506 |
text {* |
86 | 507 |
Every equation in @{text ES} (represented by @{text "(X, rhs)"}) |
97 | 508 |
is valid, i.e. @{text "X = L rhs"}. |
86 | 509 |
*} |
510 |
||
42 | 511 |
definition |
97 | 512 |
"valid_eqns ES \<equiv> \<forall>(X, rhs) \<in> ES. X = L rhs" |
42 | 513 |
|
514 |
text {* |
|
86 | 515 |
@{text "rhs_nonempty rhs"} requires regular expressions occuring in |
516 |
transitional items of @{text "rhs"} do not contain empty string. This is |
|
517 |
necessary for the application of Arden's transformation to @{text "rhs"}. |
|
518 |
*} |
|
70 | 519 |
|
42 | 520 |
definition |
521 |
"rhs_nonempty rhs \<equiv> (\<forall> Y r. Trn Y r \<in> rhs \<longrightarrow> [] \<notin> L r)" |
|
522 |
||
523 |
text {* |
|
86 | 524 |
The following @{text "ardenable ES"} requires that Arden's transformation |
525 |
is applicable to every equation of equational system @{text "ES"}. |
|
526 |
*} |
|
70 | 527 |
|
42 | 528 |
definition |
97 | 529 |
"ardenable ES \<equiv> \<forall>(X, rhs) \<in> ES. rhs_nonempty rhs" |
42 | 530 |
|
86 | 531 |
text {* |
532 |
@{text "finite_rhs ES"} requires every equation in @{text "rhs"} |
|
533 |
be finite. |
|
534 |
*} |
|
42 | 535 |
definition |
536 |
"finite_rhs ES \<equiv> \<forall> X rhs. (X, rhs) \<in> ES \<longrightarrow> finite rhs" |
|
537 |
||
538 |
text {* |
|
86 | 539 |
@{text "classes_of rhs"} returns all variables (or equivalent classes) |
42 | 540 |
occuring in @{text "rhs"}. |
541 |
*} |
|
86 | 542 |
|
42 | 543 |
definition |
97 | 544 |
"classes_of rhs \<equiv> {X | X r. Trn X r \<in> rhs}" |
42 | 545 |
|
546 |
text {* |
|
86 | 547 |
@{text "lefts_of ES"} returns all variables defined by an |
548 |
equational system @{text "ES"}. |
|
549 |
*} |
|
42 | 550 |
definition |
551 |
"lefts_of ES \<equiv> {Y | Y yrhs. (Y, yrhs) \<in> ES}" |
|
552 |
||
553 |
text {* |
|
86 | 554 |
The following @{text "self_contained ES"} requires that every variable occuring |
555 |
on the right hand side of equations is already defined by some equation in @{text "ES"}. |
|
556 |
*} |
|
42 | 557 |
definition |
97 | 558 |
"self_contained ES \<equiv> \<forall>(X, xrhs) \<in> ES. classes_of xrhs \<subseteq> lefts_of ES" |
42 | 559 |
|
560 |
||
561 |
text {* |
|
86 | 562 |
The invariant @{text "invariant(ES)"} is a conjunction of all the previously defined constaints. |
42 | 563 |
*} |
564 |
definition |
|
86 | 565 |
"invariant ES \<equiv> valid_eqns ES \<and> finite ES \<and> distinct_equas ES \<and> ardenable ES \<and> |
87 | 566 |
finite_rhs ES \<and> self_contained ES" |
42 | 567 |
|
96 | 568 |
|
569 |
lemma invariantI: |
|
570 |
assumes "valid_eqns ES" "finite ES" "distinct_equas ES" "ardenable ES" |
|
571 |
"finite_rhs ES" "self_contained ES" |
|
572 |
shows "invariant ES" |
|
573 |
using assms by (simp add: invariant_def) |
|
574 |
||
42 | 575 |
subsection {* The proof of this direction *} |
576 |
||
577 |
subsubsection {* Basic properties *} |
|
578 |
||
579 |
text {* |
|
580 |
The following are some basic properties of the above definitions. |
|
581 |
*} |
|
582 |
||
583 |
||
79 | 584 |
lemma finite_Trn: |
585 |
assumes fin: "finite rhs" |
|
586 |
shows "finite {r. Trn Y r \<in> rhs}" |
|
587 |
proof - |
|
588 |
have "finite {Trn Y r | Y r. Trn Y r \<in> rhs}" |
|
589 |
by (rule rev_finite_subset[OF fin]) (auto) |
|
81 | 590 |
then have "finite ((\<lambda>(Y, r). Trn Y r) ` {(Y, r) | Y r. Trn Y r \<in> rhs})" |
591 |
by (simp add: image_Collect) |
|
592 |
then have "finite {(Y, r) | Y r. Trn Y r \<in> rhs}" |
|
593 |
by (erule_tac finite_imageD) (simp add: inj_on_def) |
|
79 | 594 |
then show "finite {r. Trn Y r \<in> rhs}" |
81 | 595 |
by (erule_tac f="snd" in finite_surj) (auto simp add: image_def) |
79 | 596 |
qed |
597 |
||
598 |
lemma finite_Lam: |
|
96 | 599 |
assumes fin: "finite rhs" |
79 | 600 |
shows "finite {r. Lam r \<in> rhs}" |
601 |
proof - |
|
602 |
have "finite {Lam r | r. Lam r \<in> rhs}" |
|
603 |
by (rule rev_finite_subset[OF fin]) (auto) |
|
604 |
then show "finite {r. Lam r \<in> rhs}" |
|
81 | 605 |
apply(simp add: image_Collect[symmetric]) |
606 |
apply(erule finite_imageD) |
|
607 |
apply(auto simp add: inj_on_def) |
|
79 | 608 |
done |
42 | 609 |
qed |
610 |
||
611 |
lemma rexp_of_empty: |
|
96 | 612 |
assumes finite: "finite rhs" |
613 |
and nonempty: "rhs_nonempty rhs" |
|
79 | 614 |
shows "[] \<notin> L (\<Uplus> {r. Trn X r \<in> rhs})" |
42 | 615 |
using finite nonempty rhs_nonempty_def |
79 | 616 |
using finite_Trn[OF finite] |
97 | 617 |
by auto |
42 | 618 |
|
619 |
lemma lang_of_rexp_of: |
|
620 |
assumes finite:"finite rhs" |
|
79 | 621 |
shows "L ({Trn X r| r. Trn X r \<in> rhs}) = X ;; (L (\<Uplus>{r. Trn X r \<in> rhs}))" |
42 | 622 |
proof - |
79 | 623 |
have "finite {r. Trn X r \<in> rhs}" |
624 |
by (rule finite_Trn[OF finite]) |
|
625 |
then show ?thesis |
|
626 |
apply(auto simp add: Seq_def) |
|
96 | 627 |
apply(rule_tac x = "s\<^isub>1" in exI, rule_tac x = "s\<^isub>2" in exI) |
628 |
apply(auto) |
|
79 | 629 |
apply(rule_tac x= "Trn X xa" in exI) |
96 | 630 |
apply(auto simp add: Seq_def) |
79 | 631 |
done |
42 | 632 |
qed |
633 |
||
96 | 634 |
lemma lang_of_append: |
635 |
"L (append_rexp r rhs_item) = L rhs_item ;; L r" |
|
636 |
by (induct rule: append_rexp.induct) |
|
637 |
(auto simp add: seq_assoc) |
|
42 | 638 |
|
639 |
lemma lang_of_append_rhs: |
|
640 |
"L (append_rhs_rexp rhs r) = L rhs ;; L r" |
|
96 | 641 |
unfolding append_rhs_rexp_def |
642 |
by (auto simp add: Seq_def lang_of_append) |
|
42 | 643 |
|
644 |
lemma classes_of_union_distrib: |
|
96 | 645 |
shows "classes_of (A \<union> B) = classes_of A \<union> classes_of B" |
646 |
by (auto simp add: classes_of_def) |
|
42 | 647 |
|
648 |
lemma lefts_of_union_distrib: |
|
96 | 649 |
shows "lefts_of (A \<union> B) = lefts_of A \<union> lefts_of B" |
650 |
by (auto simp add: lefts_of_def) |
|
42 | 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: |
|
100 | 661 |
assumes "s \<in> X" "X \<in> UNIV // \<approx>A" |
662 |
shows "X = \<approx>A `` {s}" |
|
663 |
using assms |
|
664 |
unfolding quotient_def Image_def str_eq_rel_def |
|
665 |
by auto |
|
42 | 666 |
|
667 |
lemma every_eqclass_has_transition: |
|
668 |
assumes has_str: "s @ [c] \<in> X" |
|
100 | 669 |
and in_CS: "X \<in> UNIV // \<approx>A" |
670 |
obtains Y where "Y \<in> UNIV // \<approx>A" and "Y ;; {[c]} \<subseteq> X" and "s \<in> Y" |
|
42 | 671 |
proof - |
100 | 672 |
def Y \<equiv> "\<approx>A `` {s}" |
673 |
have "Y \<in> UNIV // \<approx>A" |
|
42 | 674 |
unfolding Y_def quotient_def by auto |
675 |
moreover |
|
100 | 676 |
have "X = \<approx>A `` {s @ [c]}" |
42 | 677 |
using has_str in_CS defined_by_str by blast |
678 |
then have "Y ;; {[c]} \<subseteq> X" |
|
679 |
unfolding Y_def Image_def Seq_def |
|
680 |
unfolding str_eq_rel_def |
|
681 |
by clarsimp |
|
682 |
moreover |
|
683 |
have "s \<in> Y" unfolding Y_def |
|
684 |
unfolding Image_def str_eq_rel_def by simp |
|
100 | 685 |
ultimately show thesis using that by blast |
42 | 686 |
qed |
687 |
||
688 |
lemma l_eq_r_in_eqs: |
|
100 | 689 |
assumes X_in_eqs: "(X, rhs) \<in> Init (UNIV // \<approx>A)" |
690 |
shows "X = L rhs" |
|
42 | 691 |
proof |
100 | 692 |
show "X \<subseteq> L rhs" |
42 | 693 |
proof |
694 |
fix x |
|
695 |
assume "(1)": "x \<in> X" |
|
100 | 696 |
show "x \<in> L rhs" |
42 | 697 |
proof (cases "x = []") |
698 |
assume empty: "x = []" |
|
699 |
thus ?thesis using X_in_eqs "(1)" |
|
96 | 700 |
by (auto simp: Init_def Init_rhs_def) |
42 | 701 |
next |
702 |
assume not_empty: "x \<noteq> []" |
|
703 |
then obtain clist c where decom: "x = clist @ [c]" |
|
704 |
by (case_tac x rule:rev_cases, auto) |
|
100 | 705 |
have "X \<in> UNIV // \<approx>A" using X_in_eqs by (auto simp:Init_def) |
42 | 706 |
then obtain Y |
100 | 707 |
where "Y \<in> UNIV // \<approx>A" |
42 | 708 |
and "Y ;; {[c]} \<subseteq> X" |
709 |
and "clist \<in> Y" |
|
710 |
using decom "(1)" every_eqclass_has_transition by blast |
|
711 |
hence |
|
100 | 712 |
"x \<in> L {Trn Y (CHAR c)| Y c. Y \<in> UNIV // \<approx>A \<and> Y \<Turnstile>c\<Rightarrow> X}" |
71 | 713 |
unfolding transition_def |
714 |
using "(1)" decom |
|
42 | 715 |
by (simp, rule_tac x = "Trn Y (CHAR c)" in exI, simp add:Seq_def) |
71 | 716 |
thus ?thesis using X_in_eqs "(1)" |
96 | 717 |
by (simp add: Init_def Init_rhs_def) |
42 | 718 |
qed |
719 |
qed |
|
720 |
next |
|
100 | 721 |
show "L rhs \<subseteq> X" using X_in_eqs |
96 | 722 |
by (auto simp:Init_def Init_rhs_def transition_def) |
42 | 723 |
qed |
724 |
||
100 | 725 |
lemma test: |
726 |
assumes X_in_eqs: "(X, rhs) \<in> Init (UNIV // \<approx>A)" |
|
727 |
shows "X = \<Union> (L ` rhs)" |
|
728 |
using assms |
|
729 |
by (drule_tac l_eq_r_in_eqs) (simp) |
|
730 |
||
731 |
||
96 | 732 |
lemma finite_Init_rhs: |
42 | 733 |
assumes finite: "finite CS" |
96 | 734 |
shows "finite (Init_rhs CS X)" |
42 | 735 |
proof- |
736 |
have "finite {Trn Y (CHAR c) |Y c. Y \<in> CS \<and> Y ;; {[c]} \<subseteq> X}" (is "finite ?A") |
|
737 |
proof - |
|
738 |
def S \<equiv> "{(Y, c)| Y c. Y \<in> CS \<and> Y ;; {[c]} \<subseteq> X}" |
|
739 |
def h \<equiv> "\<lambda> (Y, c). Trn Y (CHAR c)" |
|
740 |
have "finite (CS \<times> (UNIV::char set))" using finite by auto |
|
741 |
hence "finite S" using S_def |
|
742 |
by (rule_tac B = "CS \<times> UNIV" in finite_subset, auto) |
|
743 |
moreover have "?A = h ` S" by (auto simp: S_def h_def image_def) |
|
744 |
ultimately show ?thesis |
|
745 |
by auto |
|
746 |
qed |
|
96 | 747 |
thus ?thesis by (simp add:Init_rhs_def transition_def) |
42 | 748 |
qed |
749 |
||
96 | 750 |
lemma Init_ES_satisfies_invariant: |
751 |
assumes finite_CS: "finite (UNIV // \<approx>A)" |
|
752 |
shows "invariant (Init (UNIV // \<approx>A))" |
|
753 |
proof (rule invariantI) |
|
754 |
show "valid_eqns (Init (UNIV // \<approx>A))" |
|
755 |
unfolding valid_eqns_def |
|
97 | 756 |
using l_eq_r_in_eqs by auto |
96 | 757 |
show "finite (Init (UNIV // \<approx>A))" using finite_CS |
758 |
unfolding Init_def by simp |
|
759 |
show "distinct_equas (Init (UNIV // \<approx>A))" |
|
760 |
unfolding distinct_equas_def Init_def by simp |
|
761 |
show "ardenable (Init (UNIV // \<approx>A))" |
|
762 |
unfolding ardenable_def Init_def Init_rhs_def rhs_nonempty_def |
|
763 |
by auto |
|
764 |
show "finite_rhs (Init (UNIV // \<approx>A))" |
|
765 |
using finite_Init_rhs[OF finite_CS] |
|
766 |
unfolding finite_rhs_def Init_def by auto |
|
767 |
show "self_contained (Init (UNIV // \<approx>A))" |
|
768 |
unfolding self_contained_def Init_def Init_rhs_def classes_of_def lefts_of_def |
|
769 |
by auto |
|
42 | 770 |
qed |
771 |
||
91 | 772 |
subsubsection {* Interation step *} |
42 | 773 |
|
774 |
text {* |
|
91 | 775 |
From this point until @{text "iteration_step"}, |
96 | 776 |
the correctness of the iteration step @{text "Iter X ES"} is proved. |
71 | 777 |
*} |
778 |
||
94 | 779 |
lemma Arden_keeps_eq: |
42 | 780 |
assumes l_eq_r: "X = L rhs" |
79 | 781 |
and not_empty: "[] \<notin> L (\<Uplus>{r. Trn X r \<in> rhs})" |
42 | 782 |
and finite: "finite rhs" |
94 | 783 |
shows "X = L (Arden X rhs)" |
42 | 784 |
proof - |
79 | 785 |
def A \<equiv> "L (\<Uplus>{r. Trn X r \<in> rhs})" |
94 | 786 |
def b \<equiv> "rhs - {Trn X r | r. Trn X r \<in> rhs}" |
42 | 787 |
def B \<equiv> "L b" |
788 |
have "X = B ;; A\<star>" |
|
789 |
proof- |
|
94 | 790 |
have "L rhs = L({Trn X r | r. Trn X r \<in> rhs} \<union> b)" by (auto simp: b_def) |
79 | 791 |
also have "\<dots> = X ;; A \<union> B" |
792 |
unfolding L_rhs_union_distrib[symmetric] |
|
793 |
by (simp only: lang_of_rexp_of finite B_def A_def) |
|
794 |
finally show ?thesis |
|
42 | 795 |
using l_eq_r not_empty |
86 | 796 |
apply(rule_tac arden[THEN iffD1]) |
79 | 797 |
apply(simp add: A_def) |
798 |
apply(simp) |
|
799 |
done |
|
42 | 800 |
qed |
94 | 801 |
moreover have "L (Arden X rhs) = B ;; A\<star>" |
802 |
by (simp only:Arden_def L_rhs_union_distrib lang_of_append_rhs |
|
50 | 803 |
B_def A_def b_def L_rexp.simps seq_union_distrib_left) |
42 | 804 |
ultimately show ?thesis by simp |
805 |
qed |
|
806 |
||
807 |
lemma append_keeps_finite: |
|
808 |
"finite rhs \<Longrightarrow> finite (append_rhs_rexp rhs r)" |
|
809 |
by (auto simp:append_rhs_rexp_def) |
|
810 |
||
94 | 811 |
lemma Arden_keeps_finite: |
812 |
"finite rhs \<Longrightarrow> finite (Arden X rhs)" |
|
813 |
by (auto simp:Arden_def append_keeps_finite) |
|
42 | 814 |
|
815 |
lemma append_keeps_nonempty: |
|
816 |
"rhs_nonempty rhs \<Longrightarrow> rhs_nonempty (append_rhs_rexp rhs r)" |
|
817 |
apply (auto simp:rhs_nonempty_def append_rhs_rexp_def) |
|
818 |
by (case_tac x, auto simp:Seq_def) |
|
819 |
||
820 |
lemma nonempty_set_sub: |
|
821 |
"rhs_nonempty rhs \<Longrightarrow> rhs_nonempty (rhs - A)" |
|
822 |
by (auto simp:rhs_nonempty_def) |
|
823 |
||
824 |
lemma nonempty_set_union: |
|
825 |
"\<lbrakk>rhs_nonempty rhs; rhs_nonempty rhs'\<rbrakk> \<Longrightarrow> rhs_nonempty (rhs \<union> rhs')" |
|
826 |
by (auto simp:rhs_nonempty_def) |
|
827 |
||
94 | 828 |
lemma Arden_keeps_nonempty: |
829 |
"rhs_nonempty rhs \<Longrightarrow> rhs_nonempty (Arden X rhs)" |
|
830 |
by (simp only:Arden_def append_keeps_nonempty nonempty_set_sub) |
|
42 | 831 |
|
832 |
||
94 | 833 |
lemma Subst_keeps_nonempty: |
834 |
"\<lbrakk>rhs_nonempty rhs; rhs_nonempty xrhs\<rbrakk> \<Longrightarrow> rhs_nonempty (Subst rhs X xrhs)" |
|
835 |
by (simp only:Subst_def append_keeps_nonempty nonempty_set_union nonempty_set_sub) |
|
42 | 836 |
|
94 | 837 |
lemma Subst_keeps_eq: |
42 | 838 |
assumes substor: "X = L xrhs" |
839 |
and finite: "finite rhs" |
|
94 | 840 |
shows "L (Subst rhs X xrhs) = L rhs" (is "?Left = ?Right") |
42 | 841 |
proof- |
94 | 842 |
def A \<equiv> "L (rhs - {Trn X r | r. Trn X r \<in> rhs})" |
79 | 843 |
have "?Left = A \<union> L (append_rhs_rexp xrhs (\<Uplus>{r. Trn X r \<in> rhs}))" |
94 | 844 |
unfolding Subst_def |
79 | 845 |
unfolding L_rhs_union_distrib[symmetric] |
846 |
by (simp add: A_def) |
|
847 |
moreover have "?Right = A \<union> L ({Trn X r | r. Trn X r \<in> rhs})" |
|
42 | 848 |
proof- |
94 | 849 |
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 | 850 |
thus ?thesis |
851 |
unfolding A_def |
|
852 |
unfolding L_rhs_union_distrib |
|
853 |
by simp |
|
42 | 854 |
qed |
79 | 855 |
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 | 856 |
using finite substor by (simp only:lang_of_append_rhs lang_of_rexp_of) |
857 |
ultimately show ?thesis by simp |
|
858 |
qed |
|
859 |
||
94 | 860 |
lemma Subst_keeps_finite_rhs: |
861 |
"\<lbrakk>finite rhs; finite yrhs\<rbrakk> \<Longrightarrow> finite (Subst rhs Y yrhs)" |
|
862 |
by (auto simp:Subst_def append_keeps_finite) |
|
42 | 863 |
|
94 | 864 |
lemma Subst_all_keeps_finite: |
42 | 865 |
assumes finite:"finite (ES:: (string set \<times> rhs_item set) set)" |
94 | 866 |
shows "finite (Subst_all ES Y yrhs)" |
42 | 867 |
proof - |
94 | 868 |
have "finite {(Ya, Subst yrhsa Y yrhs) |Ya yrhsa. (Ya, yrhsa) \<in> ES}" |
42 | 869 |
(is "finite ?A") |
870 |
proof- |
|
97 | 871 |
def eqns' \<equiv> "{(Ya::lang, yrhsa) | Ya yrhsa. (Ya, yrhsa) \<in> ES}" |
872 |
def h \<equiv> "\<lambda>(Ya::lang, yrhsa). (Ya, Subst yrhsa Y yrhs)" |
|
42 | 873 |
have "finite (h ` eqns')" using finite h_def eqns'_def by auto |
874 |
moreover have "?A = h ` eqns'" by (auto simp:h_def eqns'_def) |
|
875 |
ultimately show ?thesis by auto |
|
876 |
qed |
|
94 | 877 |
thus ?thesis by (simp add:Subst_all_def) |
42 | 878 |
qed |
879 |
||
94 | 880 |
lemma Subst_all_keeps_finite_rhs: |
881 |
"\<lbrakk>finite_rhs ES; finite yrhs\<rbrakk> \<Longrightarrow> finite_rhs (Subst_all ES Y yrhs)" |
|
882 |
by (auto intro:Subst_keeps_finite_rhs simp add:Subst_all_def finite_rhs_def) |
|
42 | 883 |
|
884 |
lemma append_rhs_keeps_cls: |
|
885 |
"classes_of (append_rhs_rexp rhs r) = classes_of rhs" |
|
886 |
apply (auto simp:classes_of_def append_rhs_rexp_def) |
|
887 |
apply (case_tac xa, auto simp:image_def) |
|
888 |
by (rule_tac x = "SEQ ra r" in exI, rule_tac x = "Trn x ra" in bexI, simp+) |
|
889 |
||
94 | 890 |
lemma Arden_removes_cl: |
891 |
"classes_of (Arden Y yrhs) = classes_of yrhs - {Y}" |
|
892 |
apply (simp add:Arden_def append_rhs_keeps_cls) |
|
42 | 893 |
by (auto simp:classes_of_def) |
894 |
||
895 |
lemma lefts_of_keeps_cls: |
|
94 | 896 |
"lefts_of (Subst_all ES Y yrhs) = lefts_of ES" |
897 |
by (auto simp:lefts_of_def Subst_all_def) |
|
42 | 898 |
|
94 | 899 |
lemma Subst_updates_cls: |
42 | 900 |
"X \<notin> classes_of xrhs \<Longrightarrow> |
94 | 901 |
classes_of (Subst rhs X xrhs) = classes_of rhs \<union> classes_of xrhs - {X}" |
96 | 902 |
apply (simp only:Subst_def append_rhs_keeps_cls classes_of_union_distrib) |
94 | 903 |
by (auto simp:classes_of_def) |
42 | 904 |
|
94 | 905 |
lemma Subst_all_keeps_self_contained: |
42 | 906 |
assumes sc: "self_contained (ES \<union> {(Y, yrhs)})" (is "self_contained ?A") |
94 | 907 |
shows "self_contained (Subst_all ES Y (Arden Y yrhs))" |
42 | 908 |
(is "self_contained ?B") |
909 |
proof- |
|
910 |
{ fix X xrhs' |
|
911 |
assume "(X, xrhs') \<in> ?B" |
|
912 |
then obtain xrhs |
|
94 | 913 |
where xrhs_xrhs': "xrhs' = Subst xrhs Y (Arden Y yrhs)" |
914 |
and X_in: "(X, xrhs) \<in> ES" by (simp add:Subst_all_def, blast) |
|
42 | 915 |
have "classes_of xrhs' \<subseteq> lefts_of ?B" |
916 |
proof- |
|
94 | 917 |
have "lefts_of ?B = lefts_of ES" by (auto simp add:lefts_of_def Subst_all_def) |
42 | 918 |
moreover have "classes_of xrhs' \<subseteq> lefts_of ES" |
919 |
proof- |
|
920 |
have "classes_of xrhs' \<subseteq> |
|
94 | 921 |
classes_of xrhs \<union> classes_of (Arden Y yrhs) - {Y}" |
42 | 922 |
proof- |
94 | 923 |
have "Y \<notin> classes_of (Arden Y yrhs)" |
924 |
using Arden_removes_cl by simp |
|
925 |
thus ?thesis using xrhs_xrhs' by (auto simp:Subst_updates_cls) |
|
42 | 926 |
qed |
927 |
moreover have "classes_of xrhs \<subseteq> lefts_of ES \<union> {Y}" using X_in sc |
|
96 | 928 |
apply (simp only:self_contained_def lefts_of_union_distrib) |
42 | 929 |
by (drule_tac x = "(X, xrhs)" in bspec, auto simp:lefts_of_def) |
94 | 930 |
moreover have "classes_of (Arden Y yrhs) \<subseteq> lefts_of ES \<union> {Y}" |
42 | 931 |
using sc |
94 | 932 |
by (auto simp add:Arden_removes_cl self_contained_def lefts_of_def) |
42 | 933 |
ultimately show ?thesis by auto |
934 |
qed |
|
935 |
ultimately show ?thesis by simp |
|
936 |
qed |
|
94 | 937 |
} thus ?thesis by (auto simp only:Subst_all_def self_contained_def) |
42 | 938 |
qed |
939 |
||
96 | 940 |
lemma Subst_all_satisfies_invariant: |
86 | 941 |
assumes invariant_ES: "invariant (ES \<union> {(Y, yrhs)})" |
94 | 942 |
shows "invariant (Subst_all ES Y (Arden Y yrhs))" |
96 | 943 |
proof (rule invariantI) |
944 |
have Y_eq_yrhs: "Y = L yrhs" |
|
945 |
using invariant_ES by (simp only:invariant_def valid_eqns_def, blast) |
|
946 |
have finite_yrhs: "finite yrhs" |
|
86 | 947 |
using invariant_ES by (auto simp:invariant_def finite_rhs_def) |
42 | 948 |
have nonempty_yrhs: "rhs_nonempty yrhs" |
86 | 949 |
using invariant_ES by (auto simp:invariant_def ardenable_def) |
96 | 950 |
show "valid_eqns (Subst_all ES Y (Arden Y yrhs))" |
951 |
proof- |
|
952 |
have "Y = L (Arden Y yrhs)" |
|
953 |
using Y_eq_yrhs invariant_ES finite_yrhs nonempty_yrhs |
|
954 |
by (rule_tac Arden_keeps_eq, (simp add:rexp_of_empty)+) |
|
955 |
thus ?thesis using invariant_ES |
|
97 | 956 |
by (auto simp add:valid_eqns_def |
96 | 957 |
Subst_all_def Subst_keeps_eq invariant_def finite_rhs_def |
958 |
simp del:L_rhs.simps) |
|
959 |
qed |
|
960 |
show "finite (Subst_all ES Y (Arden Y yrhs))" |
|
961 |
using invariant_ES by (simp add:invariant_def Subst_all_keeps_finite) |
|
962 |
show "distinct_equas (Subst_all ES Y (Arden Y yrhs))" |
|
86 | 963 |
using invariant_ES |
94 | 964 |
by (auto simp:distinct_equas_def Subst_all_def invariant_def) |
96 | 965 |
show "ardenable (Subst_all ES Y (Arden Y yrhs))" |
966 |
proof - |
|
967 |
{ fix X rhs |
|
968 |
assume "(X, rhs) \<in> ES" |
|
969 |
hence "rhs_nonempty rhs" using prems invariant_ES |
|
97 | 970 |
by (auto simp add:invariant_def ardenable_def) |
96 | 971 |
with nonempty_yrhs |
972 |
have "rhs_nonempty (Subst rhs Y (Arden Y yrhs))" |
|
973 |
by (simp add:nonempty_yrhs |
|
974 |
Subst_keeps_nonempty Arden_keeps_nonempty) |
|
975 |
} thus ?thesis by (auto simp add:ardenable_def Subst_all_def) |
|
976 |
qed |
|
977 |
show "finite_rhs (Subst_all ES Y (Arden Y yrhs))" |
|
42 | 978 |
proof- |
86 | 979 |
have "finite_rhs ES" using invariant_ES |
980 |
by (simp add:invariant_def finite_rhs_def) |
|
94 | 981 |
moreover have "finite (Arden Y yrhs)" |
42 | 982 |
proof - |
86 | 983 |
have "finite yrhs" using invariant_ES |
984 |
by (auto simp:invariant_def finite_rhs_def) |
|
94 | 985 |
thus ?thesis using Arden_keeps_finite by simp |
42 | 986 |
qed |
987 |
ultimately show ?thesis |
|
94 | 988 |
by (simp add:Subst_all_keeps_finite_rhs) |
42 | 989 |
qed |
96 | 990 |
show "self_contained (Subst_all ES Y (Arden Y yrhs))" |
94 | 991 |
using invariant_ES Subst_all_keeps_self_contained by (simp add:invariant_def) |
42 | 992 |
qed |
993 |
||
97 | 994 |
lemma Remove_in_card_measure: |
995 |
assumes finite: "finite ES" |
|
996 |
and in_ES: "(X, rhs) \<in> ES" |
|
997 |
shows "(Remove ES X rhs, ES) \<in> measure card" |
|
998 |
proof - |
|
999 |
def f \<equiv> "\<lambda> x. ((fst x)::lang, Subst (snd x) X (Arden X rhs))" |
|
1000 |
def ES' \<equiv> "ES - {(X, rhs)}" |
|
1001 |
have "Subst_all ES' X (Arden X rhs) = f ` ES'" |
|
1002 |
apply (auto simp: Subst_all_def f_def image_def) |
|
1003 |
by (rule_tac x = "(Y, yrhs)" in bexI, simp+) |
|
1004 |
then have "card (Subst_all ES' X (Arden X rhs)) \<le> card ES'" |
|
1005 |
unfolding ES'_def using finite by (auto intro: card_image_le) |
|
1006 |
also have "\<dots> < card ES" unfolding ES'_def |
|
1007 |
using in_ES finite by (rule_tac card_Diff1_less) |
|
1008 |
finally show "(Remove ES X rhs, ES) \<in> measure card" |
|
1009 |
unfolding Remove_def ES'_def by simp |
|
42 | 1010 |
qed |
97 | 1011 |
|
42 | 1012 |
|
94 | 1013 |
lemma Subst_all_cls_remains: |
1014 |
"(X, xrhs) \<in> ES \<Longrightarrow> \<exists> xrhs'. (X, xrhs') \<in> (Subst_all ES Y yrhs)" |
|
97 | 1015 |
by (auto simp: Subst_all_def) |
42 | 1016 |
|
1017 |
lemma card_noteq_1_has_more: |
|
1018 |
assumes card:"card S \<noteq> 1" |
|
1019 |
and e_in: "e \<in> S" |
|
1020 |
and finite: "finite S" |
|
97 | 1021 |
obtains e' where "e' \<in> S \<and> e \<noteq> e'" |
42 | 1022 |
proof- |
1023 |
have "card (S - {e}) > 0" |
|
1024 |
proof - |
|
97 | 1025 |
have "card S > 1" using card e_in finite |
1026 |
by (cases "card S") (auto) |
|
42 | 1027 |
thus ?thesis using finite e_in by auto |
1028 |
qed |
|
1029 |
hence "S - {e} \<noteq> {}" using finite by (rule_tac notI, simp) |
|
1030 |
thus "(\<And>e'. e' \<in> S \<and> e \<noteq> e' \<Longrightarrow> thesis) \<Longrightarrow> thesis" by auto |
|
1031 |
qed |
|
1032 |
||
97 | 1033 |
|
1034 |
||
1035 |
lemma iteration_step_measure: |
|
91 | 1036 |
assumes Inv_ES: "invariant ES" |
42 | 1037 |
and X_in_ES: "(X, xrhs) \<in> ES" |
1038 |
and not_T: "card ES \<noteq> 1" |
|
97 | 1039 |
shows "(Iter X ES, ES) \<in> measure card" |
1040 |
proof - |
|
1041 |
have finite_ES: "finite ES" using Inv_ES by (simp add: invariant_def) |
|
1042 |
then obtain Y yrhs |
|
1043 |
where Y_in_ES: "(Y, yrhs) \<in> ES" and not_eq: "(X, xrhs) \<noteq> (Y, yrhs)" |
|
1044 |
using not_T X_in_ES by (drule_tac card_noteq_1_has_more) (auto) |
|
1045 |
then have "(Y, yrhs) \<in> ES " "X \<noteq> Y" |
|
1046 |
using X_in_ES Inv_ES |
|
1047 |
by (auto simp: invariant_def distinct_equas_def) |
|
1048 |
then show "(Iter X ES, ES) \<in> measure card" |
|
1049 |
apply(rule IterI2) |
|
1050 |
apply(rule Remove_in_card_measure) |
|
1051 |
apply(simp_all add: finite_ES) |
|
1052 |
done |
|
1053 |
qed |
|
1054 |
||
1055 |
lemma iteration_step_invariant: |
|
1056 |
assumes Inv_ES: "invariant ES" |
|
1057 |
and X_in_ES: "(X, xrhs) \<in> ES" |
|
1058 |
and not_T: "card ES \<noteq> 1" |
|
1059 |
shows "invariant (Iter X ES)" |
|
42 | 1060 |
proof - |
91 | 1061 |
have finite_ES: "finite ES" using Inv_ES by (simp add: invariant_def) |
42 | 1062 |
then obtain Y yrhs |
1063 |
where Y_in_ES: "(Y, yrhs) \<in> ES" and not_eq: "(X, xrhs) \<noteq> (Y, yrhs)" |
|
97 | 1064 |
using not_T X_in_ES by (drule_tac card_noteq_1_has_more) (auto) |
1065 |
then have "(Y, yrhs) \<in> ES " "X \<noteq> Y" |
|
1066 |
using X_in_ES Inv_ES |
|
1067 |
by (auto simp: invariant_def distinct_equas_def) |
|
1068 |
then show "invariant (Iter X ES)" |
|
1069 |
proof(rule IterI2) |
|
1070 |
fix Y yrhs |
|
1071 |
assume h: "(Y, yrhs) \<in> ES" "X \<noteq> Y" |
|
1072 |
then have "ES - {(Y, yrhs)} \<union> {(Y, yrhs)} = ES" by auto |
|
1073 |
then show "invariant (Remove ES Y yrhs)" unfolding Remove_def |
|
1074 |
using Inv_ES by (rule_tac Subst_all_satisfies_invariant) (simp) |
|
42 | 1075 |
qed |
1076 |
qed |
|
1077 |
||
97 | 1078 |
lemma iteration_step_ex: |
1079 |
assumes Inv_ES: "invariant ES" |
|
1080 |
and X_in_ES: "(X, xrhs) \<in> ES" |
|
1081 |
and not_T: "card ES \<noteq> 1" |
|
1082 |
shows "\<exists>xrhs'. (X, xrhs') \<in> (Iter X ES)" |
|
1083 |
proof - |
|
1084 |
have finite_ES: "finite ES" using Inv_ES by (simp add: invariant_def) |
|
1085 |
then obtain Y yrhs |
|
1086 |
where Y_in_ES: "(Y, yrhs) \<in> ES" and not_eq: "(X, xrhs) \<noteq> (Y, yrhs)" |
|
1087 |
using not_T X_in_ES by (drule_tac card_noteq_1_has_more) (auto) |
|
1088 |
then have "(Y, yrhs) \<in> ES " "X \<noteq> Y" |
|
1089 |
using X_in_ES Inv_ES |
|
1090 |
by (auto simp: invariant_def distinct_equas_def) |
|
1091 |
then show "\<exists>xrhs'. (X, xrhs') \<in> (Iter X ES)" |
|
1092 |
apply(rule IterI2) |
|
1093 |
unfolding Remove_def |
|
1094 |
apply(rule Subst_all_cls_remains) |
|
1095 |
using X_in_ES |
|
1096 |
apply(auto) |
|
1097 |
done |
|
1098 |
qed |
|
1099 |
||
91 | 1100 |
|
1101 |
subsubsection {* Conclusion of the proof *} |
|
42 | 1102 |
|
1103 |
text {* |
|
1104 |
From this point until @{text "hard_direction"}, the hard direction is proved |
|
1105 |
through a simple application of the iteration principle. |
|
1106 |
*} |
|
1107 |
||
97 | 1108 |
|
91 | 1109 |
lemma reduce_x: |
1110 |
assumes inv: "invariant ES" |
|
1111 |
and contain_x: "(X, xrhs) \<in> ES" |
|
97 | 1112 |
shows "\<exists> xrhs'. Solve X ES = {(X, xrhs')} \<and> invariant(Solve X ES)" |
91 | 1113 |
proof - |
1114 |
let ?Inv = "\<lambda> ES. (invariant ES \<and> (\<exists> xrhs. (X, xrhs) \<in> ES))" |
|
97 | 1115 |
show ?thesis unfolding Solve_def |
1116 |
proof (rule while_rule [where P = ?Inv and r = "measure card"]) |
|
91 | 1117 |
from inv and contain_x show "?Inv ES" by auto |
1118 |
next |
|
1119 |
show "wf (measure card)" by simp |
|
1120 |
next |
|
1121 |
fix ES |
|
1122 |
assume inv: "?Inv ES" and crd: "card ES \<noteq> 1" |
|
97 | 1123 |
then show "(Iter X ES, ES) \<in> measure card" |
1124 |
apply(clarify) |
|
1125 |
apply(rule iteration_step_measure) |
|
1126 |
apply(auto) |
|
1127 |
done |
|
91 | 1128 |
next |
1129 |
fix ES |
|
1130 |
assume inv: "?Inv ES" and crd: "card ES \<noteq> 1" |
|
97 | 1131 |
then show "?Inv (Iter X ES)" |
1132 |
apply - |
|
1133 |
apply(auto) |
|
1134 |
apply(rule iteration_step_invariant) |
|
1135 |
apply(auto) |
|
1136 |
apply(rule iteration_step_ex) |
|
1137 |
apply(auto) |
|
1138 |
done |
|
91 | 1139 |
next |
1140 |
fix ES |
|
1141 |
assume "?Inv ES" and "\<not> card ES \<noteq> 1" |
|
1142 |
thus "\<exists>xrhs'. ES = {(X, xrhs')} \<and> invariant ES" |
|
1143 |
apply (auto, rule_tac x = xrhs in exI) |
|
1144 |
by (auto simp: invariant_def dest!:card_Suc_Diff1 simp:card_eq_0_iff) |
|
1145 |
qed |
|
42 | 1146 |
qed |
91 | 1147 |
|
42 | 1148 |
lemma last_cl_exists_rexp: |
91 | 1149 |
assumes Inv_ES: "invariant {(X, xrhs)}" |
96 | 1150 |
shows "\<exists>r::rexp. L r = X" |
42 | 1151 |
proof- |
94 | 1152 |
def A \<equiv> "Arden X xrhs" |
96 | 1153 |
have eq: "{Lam r | r. Lam r \<in> A} = A" |
42 | 1154 |
proof - |
96 | 1155 |
have "classes_of A = {}" using Inv_ES |
1156 |
unfolding A_def self_contained_def invariant_def lefts_of_def |
|
1157 |
by (simp add: Arden_removes_cl) |
|
1158 |
thus ?thesis unfolding A_def classes_of_def |
|
1159 |
apply(auto simp only:) |
|
1160 |
apply(case_tac x) |
|
1161 |
apply(auto) |
|
1162 |
done |
|
42 | 1163 |
qed |
96 | 1164 |
have "finite A" using Inv_ES unfolding A_def invariant_def finite_rhs_def |
1165 |
using Arden_keeps_finite by auto |
|
1166 |
then have "finite {r. Lam r \<in> A}" by (rule finite_Lam) |
|
1167 |
then have "L (\<Uplus>{r. Lam r \<in> A}) = L ({Lam r | r. Lam r \<in> A})" |
|
1168 |
by auto |
|
1169 |
also have "\<dots> = L A" by (simp add: eq) |
|
1170 |
also have "\<dots> = X" |
|
1171 |
proof - |
|
1172 |
have "X = L xrhs" using Inv_ES unfolding invariant_def valid_eqns_def |
|
1173 |
by auto |
|
1174 |
moreover |
|
1175 |
from Inv_ES have "[] \<notin> L (\<Uplus>{r. Trn X r \<in> xrhs})" |
|
1176 |
unfolding invariant_def ardenable_def finite_rhs_def |
|
1177 |
by(simp add: rexp_of_empty) |
|
1178 |
moreover |
|
1179 |
from Inv_ES have "finite xrhs" unfolding invariant_def finite_rhs_def |
|
1180 |
by simp |
|
1181 |
ultimately show "L A = X" unfolding A_def |
|
1182 |
by (rule Arden_keeps_eq[symmetric]) |
|
1183 |
qed |
|
1184 |
finally have "L (\<Uplus>{r. Lam r \<in> A}) = X" . |
|
1185 |
then show "\<exists>r::rexp. L r = X" by blast |
|
42 | 1186 |
qed |
91 | 1187 |
|
42 | 1188 |
lemma every_eqcl_has_reg: |
96 | 1189 |
assumes finite_CS: "finite (UNIV // \<approx>A)" |
1190 |
and X_in_CS: "X \<in> (UNIV // \<approx>A)" |
|
1191 |
shows "\<exists>r::rexp. L r = X" |
|
42 | 1192 |
proof - |
96 | 1193 |
def ES \<equiv> "Init (UNIV // \<approx>A)" |
1194 |
have "invariant ES" using finite_CS unfolding ES_def |
|
1195 |
by (rule Init_ES_satisfies_invariant) |
|
1196 |
moreover |
|
1197 |
from X_in_CS obtain xrhs where "(X, xrhs) \<in> ES" unfolding ES_def |
|
1198 |
unfolding Init_def Init_rhs_def by auto |
|
1199 |
ultimately |
|
97 | 1200 |
obtain xrhs' where "Solve X ES = {(X, xrhs')}" "invariant (Solve X ES)" |
96 | 1201 |
using reduce_x by blast |
1202 |
then show "\<exists>r::rexp. L r = X" |
|
1203 |
using last_cl_exists_rexp by auto |
|
42 | 1204 |
qed |
1205 |
||
91 | 1206 |
|
96 | 1207 |
lemma bchoice_finite_set: |
1208 |
assumes a: "\<forall>x \<in> S. \<exists>y. x = f y" |
|
1209 |
and b: "finite S" |
|
1210 |
shows "\<exists>ys. (\<Union> S) = \<Union>(f ` ys) \<and> finite ys" |
|
1211 |
using bchoice[OF a] b |
|
1212 |
apply(erule_tac exE) |
|
1213 |
apply(rule_tac x="fa ` S" in exI) |
|
1214 |
apply(auto) |
|
1215 |
done |
|
1216 |
||
1217 |
theorem Myhill_Nerode1: |
|
70 | 1218 |
assumes finite_CS: "finite (UNIV // \<approx>A)" |
1219 |
shows "\<exists>r::rexp. A = L r" |
|
42 | 1220 |
proof - |
96 | 1221 |
have f: "finite (finals A)" |
1222 |
using finals_in_partitions finite_CS by (rule finite_subset) |
|
1223 |
have "\<forall>X \<in> (UNIV // \<approx>A). \<exists>r::rexp. X = L r" |
|
42 | 1224 |
using finite_CS every_eqcl_has_reg by blast |
96 | 1225 |
then have a: "\<forall>X \<in> finals A. \<exists>r::rexp. X = L r" |
1226 |
using finals_in_partitions by auto |
|
1227 |
then obtain rs::"rexp set" where "\<Union> (finals A) = \<Union>(L ` rs)" "finite rs" |
|
1228 |
using f by (auto dest: bchoice_finite_set) |
|
1229 |
then have "A = L (\<Uplus>rs)" |
|
1230 |
unfolding lang_is_union_of_finals[symmetric] by simp |
|
1231 |
then show "\<exists>r::rexp. A = L r" by blast |
|
42 | 1232 |
qed |
1233 |
||
96 | 1234 |
|
42 | 1235 |
end |