author | urbanc |
Tue, 08 Feb 2011 15:50:26 +0000 | |
changeset 79 | bba9c80735f9 |
parent 76 | 1589bf5c1ad8 |
child 80 | f901a26bf1ac |
permissions | -rw-r--r-- |
42 | 1 |
theory Myhill_1 |
75 | 2 |
imports Main |
42 | 3 |
begin |
4 |
||
5 |
(* |
|
6 |
text {* |
|
7 |
\begin{figure} |
|
8 |
\centering |
|
9 |
\scalebox{0.95}{ |
|
10 |
\begin{tikzpicture}[->,>=latex,shorten >=1pt,auto,node distance=1.2cm, semithick] |
|
11 |
\node[state,initial] (n1) {$1$}; |
|
12 |
\node[state,accepting] (n2) [right = 10em of n1] {$2$}; |
|
13 |
||
14 |
\path (n1) edge [bend left] node {$0$} (n2) |
|
15 |
(n1) edge [loop above] node{$1$} (n1) |
|
16 |
(n2) edge [loop above] node{$0$} (n2) |
|
17 |
(n2) edge [bend left] node {$1$} (n1) |
|
18 |
; |
|
19 |
\end{tikzpicture}} |
|
20 |
\caption{An example automaton (or partition)}\label{fig:example_automata} |
|
21 |
\end{figure} |
|
22 |
*} |
|
23 |
||
24 |
*) |
|
25 |
||
26 |
||
27 |
section {* Preliminary definitions *} |
|
28 |
||
43 | 29 |
types lang = "string set" |
30 |
||
70 | 31 |
text {* Sequential composition of two languages *} |
43 | 32 |
|
60 | 33 |
definition |
34 |
Seq :: "lang \<Rightarrow> lang \<Rightarrow> lang" (infixr ";;" 100) |
|
42 | 35 |
where |
54 | 36 |
"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 | 37 |
|
70 | 38 |
|
56
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
39 |
text {* Some properties of operator @{text ";;"}. *} |
50 | 40 |
|
56
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
41 |
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
|
42 |
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
|
43 |
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
|
44 |
using a by simp |
42 | 45 |
|
50 | 46 |
lemma seq_union_distrib_right: |
47 |
shows "(A \<union> B) ;; C = (A ;; C) \<union> (B ;; C)" |
|
48 |
unfolding Seq_def by auto |
|
49 |
||
50 |
lemma seq_union_distrib_left: |
|
51 |
shows "C ;; (A \<union> B) = (C ;; A) \<union> (C ;; B)" |
|
52 |
unfolding Seq_def by auto |
|
42 | 53 |
|
54 |
lemma seq_intro: |
|
70 | 55 |
assumes a: "x \<in> A" "y \<in> B" |
56 |
shows "x @ y \<in> A ;; B " |
|
57 |
using a by (auto simp: Seq_def) |
|
42 | 58 |
|
59 |
lemma seq_assoc: |
|
50 | 60 |
shows "(A ;; B) ;; C = A ;; (B ;; C)" |
61 |
unfolding Seq_def |
|
62 |
apply(auto) |
|
63 |
apply(blast) |
|
42 | 64 |
by (metis append_assoc) |
65 |
||
50 | 66 |
lemma seq_empty [simp]: |
67 |
shows "A ;; {[]} = A" |
|
68 |
and "{[]} ;; A = A" |
|
69 |
by (simp_all add: Seq_def) |
|
70 |
||
70 | 71 |
|
72 |
text {* Power and Star of a language *} |
|
73 |
||
56
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
74 |
fun |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
75 |
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
|
76 |
where |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
77 |
"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
|
78 |
| "A \<up> (Suc n) = A ;; (A \<up> n)" |
50 | 79 |
|
56
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
80 |
definition |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
81 |
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
|
82 |
where |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
83 |
"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
|
84 |
|
70 | 85 |
|
56
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
86 |
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
|
87 |
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
|
88 |
proof - |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
89 |
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
|
90 |
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
|
91 |
qed |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
92 |
|
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
93 |
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
|
94 |
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
|
95 |
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
|
96 |
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
|
97 |
proof - |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
98 |
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
|
99 |
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
|
100 |
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
|
101 |
qed |
42 | 102 |
|
56
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
103 |
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
|
104 |
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
|
105 |
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
|
106 |
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
|
107 |
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
|
108 |
proof - |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
109 |
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
|
110 |
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
|
111 |
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
|
112 |
(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
|
113 |
qed |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
114 |
|
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
115 |
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
|
116 |
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
|
117 |
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
|
118 |
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
|
119 |
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
|
120 |
by (induct rule: star_induct) (auto) |
42 | 121 |
|
56
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
122 |
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
|
123 |
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
|
124 |
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
|
125 |
proof - |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
126 |
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
|
127 |
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
|
128 |
qed |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
129 |
|
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
130 |
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
|
131 |
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
|
132 |
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
|
133 |
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
|
134 |
using a b by (blast intro: star_intro1 star_intro2) |
42 | 135 |
|
71 | 136 |
lemma star_cases: |
137 |
shows "A\<star> = {[]} \<union> A ;; A\<star>" |
|
138 |
proof |
|
139 |
{ fix x |
|
140 |
have "x \<in> A\<star> \<Longrightarrow> x \<in> {[]} \<union> A ;; A\<star>" |
|
141 |
unfolding Seq_def |
|
142 |
by (induct rule: star_induct) (auto) |
|
143 |
} |
|
144 |
then show "A\<star> \<subseteq> {[]} \<union> A ;; A\<star>" by auto |
|
145 |
next |
|
146 |
show "{[]} \<union> A ;; A\<star> \<subseteq> A\<star>" |
|
147 |
unfolding Seq_def by auto |
|
148 |
qed |
|
149 |
||
42 | 150 |
lemma star_decom: |
71 | 151 |
assumes a: "x \<in> A\<star>" "x \<noteq> []" |
152 |
shows "\<exists>a b. x = a @ b \<and> a \<noteq> [] \<and> a \<in> A \<and> b \<in> A\<star>" |
|
153 |
using a |
|
56
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
154 |
apply(induct rule: star_induct) |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
155 |
apply(simp) |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
156 |
apply(blast) |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
157 |
done |
42 | 158 |
|
50 | 159 |
lemma |
160 |
shows seq_Union_left: "B ;; (\<Union>n. A \<up> n) = (\<Union>n. B ;; (A \<up> n))" |
|
161 |
and seq_Union_right: "(\<Union>n. A \<up> n) ;; B = (\<Union>n. (A \<up> n) ;; B)" |
|
162 |
unfolding Seq_def by auto |
|
163 |
||
164 |
lemma seq_pow_comm: |
|
165 |
shows "A ;; (A \<up> n) = (A \<up> n) ;; A" |
|
166 |
by (induct n) (simp_all add: seq_assoc[symmetric]) |
|
167 |
||
168 |
lemma seq_star_comm: |
|
169 |
shows "A ;; A\<star> = A\<star> ;; A" |
|
56
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
170 |
unfolding Star_def |
50 | 171 |
unfolding seq_Union_left |
172 |
unfolding seq_pow_comm |
|
173 |
unfolding seq_Union_right |
|
174 |
by simp |
|
175 |
||
176 |
text {* Two lemmas about the length of strings in @{text "A \<up> n"} *} |
|
177 |
||
178 |
lemma pow_length: |
|
179 |
assumes a: "[] \<notin> A" |
|
180 |
and b: "s \<in> A \<up> Suc n" |
|
181 |
shows "n < length s" |
|
182 |
using b |
|
183 |
proof (induct n arbitrary: s) |
|
184 |
case 0 |
|
185 |
have "s \<in> A \<up> Suc 0" by fact |
|
186 |
with a have "s \<noteq> []" by auto |
|
187 |
then show "0 < length s" by auto |
|
188 |
next |
|
189 |
case (Suc n) |
|
190 |
have ih: "\<And>s. s \<in> A \<up> Suc n \<Longrightarrow> n < length s" by fact |
|
191 |
have "s \<in> A \<up> Suc (Suc n)" by fact |
|
192 |
then obtain s1 s2 where eq: "s = s1 @ s2" and *: "s1 \<in> A" and **: "s2 \<in> A \<up> Suc n" |
|
193 |
by (auto simp add: Seq_def) |
|
194 |
from ih ** have "n < length s2" by simp |
|
195 |
moreover have "0 < length s1" using * a by auto |
|
196 |
ultimately show "Suc n < length s" unfolding eq |
|
197 |
by (simp only: length_append) |
|
198 |
qed |
|
199 |
||
200 |
lemma seq_pow_length: |
|
201 |
assumes a: "[] \<notin> A" |
|
202 |
and b: "s \<in> B ;; (A \<up> Suc n)" |
|
203 |
shows "n < length s" |
|
204 |
proof - |
|
205 |
from b obtain s1 s2 where eq: "s = s1 @ s2" and *: "s2 \<in> A \<up> Suc n" |
|
206 |
unfolding Seq_def by auto |
|
207 |
from * have " n < length s2" by (rule pow_length[OF a]) |
|
208 |
then show "n < length s" using eq by simp |
|
209 |
qed |
|
210 |
||
211 |
||
212 |
section {* A slightly modified version of Arden's lemma *} |
|
213 |
||
70 | 214 |
|
215 |
text {* A helper lemma for Arden *} |
|
50 | 216 |
|
217 |
lemma ardens_helper: |
|
218 |
assumes eq: "X = X ;; A \<union> B" |
|
219 |
shows "X = X ;; (A \<up> Suc n) \<union> (\<Union>m\<in>{0..n}. B ;; (A \<up> m))" |
|
220 |
proof (induct n) |
|
221 |
case 0 |
|
222 |
show "X = X ;; (A \<up> Suc 0) \<union> (\<Union>(m::nat)\<in>{0..0}. B ;; (A \<up> m))" |
|
223 |
using eq by simp |
|
224 |
next |
|
225 |
case (Suc n) |
|
226 |
have ih: "X = X ;; (A \<up> Suc n) \<union> (\<Union>m\<in>{0..n}. B ;; (A \<up> m))" by fact |
|
227 |
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 |
|
228 |
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))" |
|
229 |
by (simp add: seq_union_distrib_right seq_assoc) |
|
230 |
also have "\<dots> = X ;; (A \<up> Suc (Suc n)) \<union> (\<Union>m\<in>{0..Suc n}. B ;; (A \<up> m))" |
|
231 |
by (auto simp add: le_Suc_eq) |
|
232 |
finally show "X = X ;; (A \<up> Suc (Suc n)) \<union> (\<Union>m\<in>{0..Suc n}. B ;; (A \<up> m))" . |
|
233 |
qed |
|
234 |
||
235 |
theorem ardens_revised: |
|
236 |
assumes nemp: "[] \<notin> A" |
|
237 |
shows "X = X ;; A \<union> B \<longleftrightarrow> X = B ;; A\<star>" |
|
238 |
proof |
|
239 |
assume eq: "X = B ;; A\<star>" |
|
240 |
have "A\<star> = {[]} \<union> A\<star> ;; A" |
|
241 |
unfolding seq_star_comm[symmetric] |
|
71 | 242 |
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
|
243 |
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
|
244 |
by (rule seq_add_left) |
50 | 245 |
also have "\<dots> = B \<union> B ;; (A\<star> ;; A)" |
246 |
unfolding seq_union_distrib_left by simp |
|
247 |
also have "\<dots> = B \<union> (B ;; A\<star>) ;; A" |
|
248 |
by (simp only: seq_assoc) |
|
249 |
finally show "X = X ;; A \<union> B" |
|
250 |
using eq by blast |
|
251 |
next |
|
252 |
assume eq: "X = X ;; A \<union> B" |
|
253 |
{ fix n::nat |
|
254 |
have "B ;; (A \<up> n) \<subseteq> X" using ardens_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
|
255 |
then have "B ;; A\<star> \<subseteq> X" |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
256 |
unfolding Seq_def Star_def UNION_def |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
257 |
by auto |
50 | 258 |
moreover |
259 |
{ fix s::string |
|
260 |
obtain k where "k = length s" by auto |
|
261 |
then have not_in: "s \<notin> X ;; (A \<up> Suc k)" |
|
262 |
using seq_pow_length[OF nemp] by blast |
|
263 |
assume "s \<in> X" |
|
264 |
then have "s \<in> X ;; (A \<up> Suc k) \<union> (\<Union>m\<in>{0..k}. B ;; (A \<up> m))" |
|
265 |
using ardens_helper[OF eq, of "k"] by auto |
|
266 |
then have "s \<in> (\<Union>m\<in>{0..k}. B ;; (A \<up> m))" using not_in by auto |
|
267 |
moreover |
|
268 |
have "(\<Union>m\<in>{0..k}. B ;; (A \<up> m)) \<subseteq> (\<Union>n. B ;; (A \<up> n))" by auto |
|
269 |
ultimately |
|
56
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
270 |
have "s \<in> B ;; A\<star>" |
b3898315e687
removed the inductive definition of Star and replaced it by a definition in terms of pow
urbanc
parents:
54
diff
changeset
|
271 |
unfolding seq_Union_left Star_def |
50 | 272 |
by auto } |
273 |
then have "X \<subseteq> B ;; A\<star>" by auto |
|
274 |
ultimately |
|
275 |
show "X = B ;; A\<star>" by simp |
|
276 |
qed |
|
277 |
||
42 | 278 |
|
70 | 279 |
section {* Regular Expressions *} |
48 | 280 |
|
281 |
datatype rexp = |
|
282 |
NULL |
|
283 |
| EMPTY |
|
284 |
| CHAR char |
|
285 |
| SEQ rexp rexp |
|
286 |
| ALT rexp rexp |
|
287 |
| STAR rexp |
|
288 |
||
289 |
||
290 |
text {* |
|
291 |
The following @{text "L"} is an overloaded operator, where @{text "L(x)"} evaluates to |
|
292 |
the language represented by the syntactic object @{text "x"}. |
|
293 |
*} |
|
294 |
||
70 | 295 |
consts L:: "'a \<Rightarrow> lang" |
48 | 296 |
|
70 | 297 |
text {* The @{text "L (rexp)"} for regular expressions. *} |
298 |
||
299 |
overloading L_rexp \<equiv> "L:: rexp \<Rightarrow> lang" |
|
48 | 300 |
begin |
301 |
fun |
|
302 |
L_rexp :: "rexp \<Rightarrow> string set" |
|
303 |
where |
|
304 |
"L_rexp (NULL) = {}" |
|
305 |
| "L_rexp (EMPTY) = {[]}" |
|
306 |
| "L_rexp (CHAR c) = {[c]}" |
|
307 |
| "L_rexp (SEQ r1 r2) = (L_rexp r1) ;; (L_rexp r2)" |
|
308 |
| "L_rexp (ALT r1 r2) = (L_rexp r1) \<union> (L_rexp r2)" |
|
309 |
| "L_rexp (STAR r) = (L_rexp r)\<star>" |
|
310 |
end |
|
311 |
||
70 | 312 |
|
313 |
section {* Folds for Sets *} |
|
314 |
||
50 | 315 |
text {* |
70 | 316 |
To obtain equational system out of finite set of equivalence classes, a fold operation |
317 |
on finite sets @{text "folds"} is defined. The use of @{text "SOME"} makes @{text "folds"} |
|
318 |
more robust than the @{text "fold"} in the Isabelle library. The expression @{text "folds f"} |
|
50 | 319 |
makes sense when @{text "f"} is not @{text "associative"} and @{text "commutitive"}, |
320 |
while @{text "fold f"} does not. |
|
321 |
*} |
|
322 |
||
76 | 323 |
|
50 | 324 |
definition |
325 |
folds :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a set \<Rightarrow> 'b" |
|
326 |
where |
|
327 |
"folds f z S \<equiv> SOME x. fold_graph f z S x" |
|
328 |
||
76 | 329 |
abbreviation |
330 |
Setalt ("\<Uplus>_" [1000] 999) |
|
331 |
where |
|
332 |
"\<Uplus>A == folds ALT NULL A" |
|
333 |
||
50 | 334 |
text {* |
70 | 335 |
The following lemma ensures that the arbitrary choice made by the |
336 |
@{text "SOME"} in @{text "folds"} does not affect the @{text "L"}-value |
|
337 |
of the resultant regular expression. |
|
79 | 338 |
*} |
70 | 339 |
|
50 | 340 |
lemma folds_alt_simp [simp]: |
70 | 341 |
assumes a: "finite rs" |
76 | 342 |
shows "L (\<Uplus>rs) = \<Union> (L ` rs)" |
75 | 343 |
apply(rule set_eqI) |
70 | 344 |
apply(simp add: folds_def) |
345 |
apply(rule someI2_ex) |
|
346 |
apply(rule_tac finite_imp_fold_graph[OF a]) |
|
347 |
apply(erule fold_graph.induct) |
|
348 |
apply(auto) |
|
349 |
done |
|
50 | 350 |
|
70 | 351 |
|
352 |
text {* Just a technical lemma for collections and pairs *} |
|
353 |
||
75 | 354 |
lemma Pair_Collect[simp]: |
48 | 355 |
shows "(x, y) \<in> {(x, y). P x y} \<longleftrightarrow> P x y" |
356 |
by simp |
|
357 |
||
358 |
text {* |
|
70 | 359 |
@{text "\<approx>A"} is an equivalence class defined by language @{text "A"}. |
48 | 360 |
*} |
361 |
definition |
|
71 | 362 |
str_eq_rel :: "lang \<Rightarrow> (string \<times> string) set" ("\<approx>_" [100] 100) |
48 | 363 |
where |
70 | 364 |
"\<approx>A \<equiv> {(x, y). (\<forall>z. x @ z \<in> A \<longleftrightarrow> y @ z \<in> A)}" |
48 | 365 |
|
366 |
text {* |
|
70 | 367 |
Among the equivalence clases of @{text "\<approx>A"}, the set @{text "finals A"} singles out |
368 |
those which contains the strings from @{text "A"}. |
|
48 | 369 |
*} |
370 |
||
371 |
definition |
|
71 | 372 |
finals :: "lang \<Rightarrow> lang set" |
373 |
where |
|
374 |
"finals A \<equiv> {\<approx>A `` {x} | x . x \<in> A}" |
|
48 | 375 |
|
376 |
text {* |
|
70 | 377 |
The following lemma establishes the relationshipt between |
378 |
@{text "finals A"} and @{text "A"}. |
|
48 | 379 |
*} |
70 | 380 |
|
48 | 381 |
lemma lang_is_union_of_finals: |
70 | 382 |
shows "A = \<Union> finals A" |
383 |
unfolding finals_def |
|
384 |
unfolding Image_def |
|
385 |
unfolding str_eq_rel_def |
|
386 |
apply(auto) |
|
387 |
apply(drule_tac x = "[]" in spec) |
|
388 |
apply(auto) |
|
389 |
done |
|
390 |
||
79 | 391 |
lemma finals_in_partitions: |
392 |
shows "finals A \<subseteq> (UNIV // \<approx>A)" |
|
76 | 393 |
unfolding finals_def |
394 |
unfolding quotient_def |
|
395 |
by auto |
|
396 |
||
48 | 397 |
section {* Direction @{text "finite partition \<Rightarrow> regular language"}*} |
398 |
||
42 | 399 |
text {* |
400 |
The relationship between equivalent classes can be described by an |
|
70 | 401 |
equational system. For example, in equational system \eqref{example_eqns}, |
402 |
$X_0, X_1$ are equivalent classes. The first equation says every string in |
|
403 |
$X_0$ is obtained either by appending one $b$ to a string in $X_0$ or by |
|
404 |
appending one $a$ to a string in $X_1$ or just be an empty string |
|
405 |
(represented by the regular expression $\lambda$). Similary, the second |
|
406 |
equation tells how the strings inside $X_1$ are composed. |
|
407 |
||
42 | 408 |
\begin{equation}\label{example_eqns} |
409 |
\begin{aligned} |
|
410 |
X_0 & = X_0 b + X_1 a + \lambda \\ |
|
411 |
X_1 & = X_0 a + X_1 b |
|
412 |
\end{aligned} |
|
413 |
\end{equation} |
|
70 | 414 |
|
415 |
\noindent |
|
416 |
The summands on the right hand side is represented by the following data |
|
417 |
type @{text "rhs_item"}, mnemonic for 'right hand side item'. Generally, |
|
418 |
there are two kinds of right hand side items, one kind corresponds to pure |
|
419 |
regular expressions, like the $\lambda$ in \eqref{example_eqns}, the other |
|
420 |
kind corresponds to transitions from one one equivalent class to another, |
|
421 |
like the $X_0 b, X_1 a$ etc. |
|
422 |
||
423 |
*} |
|
42 | 424 |
|
425 |
datatype rhs_item = |
|
70 | 426 |
Lam "rexp" (* Lambda *) |
427 |
| Trn "lang" "rexp" (* Transition *) |
|
428 |
||
42 | 429 |
|
430 |
text {* |
|
431 |
In this formalization, pure regular expressions like $\lambda$ is |
|
70 | 432 |
repsented by @{text "Lam(EMPTY)"}, while transitions like $X_0 a$ is |
433 |
represented by @{term "Trn X\<^isub>0 (CHAR a)"}. |
|
434 |
*} |
|
42 | 435 |
|
436 |
text {* |
|
437 |
The functions @{text "the_r"} and @{text "the_Trn"} are used to extract |
|
438 |
subcomponents from right hand side items. |
|
439 |
*} |
|
440 |
||
70 | 441 |
fun |
442 |
the_r :: "rhs_item \<Rightarrow> rexp" |
|
443 |
where |
|
444 |
"the_r (Lam r) = r" |
|
42 | 445 |
|
70 | 446 |
fun |
79 | 447 |
the_trn_rexp:: "rhs_item \<Rightarrow> rexp" |
70 | 448 |
where |
79 | 449 |
"the_trn_rexp (Trn Y r) = r" |
42 | 450 |
|
451 |
text {* |
|
70 | 452 |
Every right-hand side item @{text "itm"} defines a language given |
453 |
by @{text "L(itm)"}, defined as: |
|
42 | 454 |
*} |
70 | 455 |
|
456 |
overloading L_rhs_e \<equiv> "L:: rhs_item \<Rightarrow> lang" |
|
42 | 457 |
begin |
70 | 458 |
fun L_rhs_e:: "rhs_item \<Rightarrow> lang" |
42 | 459 |
where |
70 | 460 |
"L_rhs_e (Lam r) = L r" |
461 |
| "L_rhs_e (Trn X r) = X ;; L r" |
|
42 | 462 |
end |
463 |
||
464 |
text {* |
|
465 |
The right hand side of every equation is represented by a set of |
|
466 |
items. The string set defined by such a set @{text "itms"} is given |
|
467 |
by @{text "L(itms)"}, defined as: |
|
468 |
*} |
|
469 |
||
70 | 470 |
overloading L_rhs \<equiv> "L:: rhs_item set \<Rightarrow> lang" |
42 | 471 |
begin |
70 | 472 |
fun L_rhs:: "rhs_item set \<Rightarrow> lang" |
473 |
where |
|
474 |
"L_rhs rhs = \<Union> (L ` rhs)" |
|
42 | 475 |
end |
476 |
||
477 |
text {* |
|
70 | 478 |
Given a set of equivalence classes @{text "CS"} and one equivalence class @{text "X"} among |
42 | 479 |
@{text "CS"}, the term @{text "init_rhs CS X"} is used to extract the right hand side of |
480 |
the equation describing the formation of @{text "X"}. The definition of @{text "init_rhs"} |
|
481 |
is: |
|
71 | 482 |
*} |
483 |
||
484 |
definition |
|
75 | 485 |
transition :: "lang \<Rightarrow> rexp \<Rightarrow> lang \<Rightarrow> bool" ("_ \<Turnstile>_\<Rightarrow>_" [100,100,100] 100) |
71 | 486 |
where |
75 | 487 |
"Y \<Turnstile>r\<Rightarrow> X \<equiv> Y ;; (L r) \<subseteq> X" |
42 | 488 |
|
489 |
definition |
|
490 |
"init_rhs CS X \<equiv> |
|
491 |
if ([] \<in> X) then |
|
75 | 492 |
{Lam EMPTY} \<union> {Trn Y (CHAR c) | Y c. Y \<in> CS \<and> Y \<Turnstile>(CHAR c)\<Rightarrow> X} |
42 | 493 |
else |
75 | 494 |
{Trn Y (CHAR c)| Y c. Y \<in> CS \<and> Y \<Turnstile>(CHAR c)\<Rightarrow> X}" |
42 | 495 |
|
496 |
text {* |
|
497 |
In the definition of @{text "init_rhs"}, the term |
|
498 |
@{text "{Trn Y (CHAR c)| Y c. Y \<in> CS \<and> Y ;; {[c]} \<subseteq> X}"} appearing on both branches |
|
499 |
describes the formation of strings in @{text "X"} out of transitions, while |
|
500 |
the term @{text "{Lam(EMPTY)}"} describes the empty string which is intrinsically contained in |
|
501 |
@{text "X"} rather than by transition. This @{text "{Lam(EMPTY)}"} corresponds to |
|
502 |
the $\lambda$ in \eqref{example_eqns}. |
|
503 |
||
504 |
With the help of @{text "init_rhs"}, the equitional system descrbing the formation of every |
|
505 |
equivalent class inside @{text "CS"} is given by the following @{text "eqs(CS)"}. |
|
71 | 506 |
*} |
42 | 507 |
|
70 | 508 |
|
42 | 509 |
definition "eqs CS \<equiv> {(X, init_rhs CS X) | X. X \<in> CS}" |
75 | 510 |
|
511 |
||
512 |
||
42 | 513 |
(************ arden's lemma variation ********************) |
514 |
||
515 |
text {* |
|
79 | 516 |
The following @{text "trns_of rhs X"} returns all @{text "X"}-items in @{text "rhs"}. |
76 | 517 |
*} |
70 | 518 |
|
42 | 519 |
definition |
79 | 520 |
"trns_of rhs X \<equiv> {Trn X r | r. Trn X r \<in> rhs}" |
42 | 521 |
|
522 |
text {* |
|
523 |
The following @{text "rexp_of rhs X"} combines all regular expressions in @{text "X"}-items |
|
524 |
using @{text "ALT"} to form a single regular expression. |
|
525 |
It will be used later to implement @{text "arden_variate"} and @{text "rhs_subst"}. |
|
526 |
*} |
|
527 |
||
528 |
definition |
|
79 | 529 |
"rexp_of rhs X \<equiv> \<Uplus> {r. Trn X r \<in> rhs}" |
42 | 530 |
|
531 |
text {* |
|
79 | 532 |
The following @{text "lam_of rhs"} returns all pure regular expression trns in @{text "rhs"}. |
75 | 533 |
*} |
42 | 534 |
|
535 |
definition |
|
536 |
"lam_of rhs \<equiv> {Lam r | r. Lam r \<in> rhs}" |
|
537 |
||
538 |
text {* |
|
539 |
The following @{text "rexp_of_lam rhs"} combines pure regular expression items in @{text "rhs"} |
|
540 |
using @{text "ALT"} to form a single regular expression. |
|
541 |
When all variables inside @{text "rhs"} are eliminated, @{text "rexp_of_lam rhs"} |
|
542 |
is used to compute compute the regular expression corresponds to @{text "rhs"}. |
|
75 | 543 |
*} |
42 | 544 |
|
76 | 545 |
|
42 | 546 |
definition |
79 | 547 |
"rexp_of_lam rhs \<equiv> \<Uplus> {r. Lam r \<in> rhs}" |
42 | 548 |
|
549 |
text {* |
|
550 |
The following @{text "attach_rexp rexp' itm"} attach |
|
551 |
the regular expression @{text "rexp'"} to |
|
552 |
the right of right hand side item @{text "itm"}. |
|
75 | 553 |
*} |
42 | 554 |
|
70 | 555 |
fun |
556 |
attach_rexp :: "rexp \<Rightarrow> rhs_item \<Rightarrow> rhs_item" |
|
42 | 557 |
where |
558 |
"attach_rexp rexp' (Lam rexp) = Lam (SEQ rexp rexp')" |
|
559 |
| "attach_rexp rexp' (Trn X rexp) = Trn X (SEQ rexp rexp')" |
|
560 |
||
561 |
text {* |
|
562 |
The following @{text "append_rhs_rexp rhs rexp"} attaches |
|
563 |
@{text "rexp"} to every item in @{text "rhs"}. |
|
75 | 564 |
*} |
42 | 565 |
|
566 |
definition |
|
567 |
"append_rhs_rexp rhs rexp \<equiv> (attach_rexp rexp) ` rhs" |
|
568 |
||
569 |
text {* |
|
570 |
With the help of the two functions immediately above, Ardens' |
|
571 |
transformation on right hand side @{text "rhs"} is implemented |
|
572 |
by the following function @{text "arden_variate X rhs"}. |
|
71 | 573 |
After this transformation, the recursive occurence of @{text "X"} |
574 |
in @{text "rhs"} will be eliminated, while the string set defined |
|
575 |
by @{text "rhs"} is kept unchanged. |
|
576 |
*} |
|
577 |
||
42 | 578 |
definition |
579 |
"arden_variate X rhs \<equiv> |
|
79 | 580 |
append_rhs_rexp (rhs - trns_of rhs X) (STAR (\<Uplus> {r. Trn X r \<in> rhs}))" |
42 | 581 |
|
582 |
||
583 |
(*********** substitution of ES *************) |
|
584 |
||
585 |
text {* |
|
586 |
Suppose the equation defining @{text "X"} is $X = xrhs$, |
|
587 |
the purpose of @{text "rhs_subst"} is to substitute all occurences of @{text "X"} in |
|
588 |
@{text "rhs"} by @{text "xrhs"}. |
|
589 |
A litte thought may reveal that the final result |
|
590 |
should be: first append $(a_1 | a_2 | \ldots | a_n)$ to every item of @{text "xrhs"} and then |
|
591 |
union the result with all non-@{text "X"}-items of @{text "rhs"}. |
|
592 |
*} |
|
70 | 593 |
|
42 | 594 |
definition |
595 |
"rhs_subst rhs X xrhs \<equiv> |
|
79 | 596 |
(rhs - (trns_of rhs X)) \<union> (append_rhs_rexp xrhs (\<Uplus> {r. Trn X r \<in> rhs}))" |
42 | 597 |
|
598 |
text {* |
|
599 |
Suppose the equation defining @{text "X"} is $X = xrhs$, the follwing |
|
600 |
@{text "eqs_subst ES X xrhs"} substitute @{text "xrhs"} into every equation |
|
601 |
of the equational system @{text "ES"}. |
|
602 |
*} |
|
603 |
||
604 |
definition |
|
605 |
"eqs_subst ES X xrhs \<equiv> {(Y, rhs_subst yrhs X xrhs) | Y yrhs. (Y, yrhs) \<in> ES}" |
|
606 |
||
607 |
text {* |
|
71 | 608 |
The computation of regular expressions for equivalence classes is accomplished |
42 | 609 |
using a iteration principle given by the following lemma. |
71 | 610 |
*} |
42 | 611 |
|
612 |
lemma wf_iter [rule_format]: |
|
613 |
fixes f |
|
614 |
assumes step: "\<And> e. \<lbrakk>P e; \<not> Q e\<rbrakk> \<Longrightarrow> (\<exists> e'. P e' \<and> (f(e'), f(e)) \<in> less_than)" |
|
615 |
shows pe: "P e \<longrightarrow> (\<exists> e'. P e' \<and> Q e')" |
|
616 |
proof(induct e rule: wf_induct |
|
617 |
[OF wf_inv_image[OF wf_less_than, where f = "f"]], clarify) |
|
618 |
fix x |
|
619 |
assume h [rule_format]: |
|
620 |
"\<forall>y. (y, x) \<in> inv_image less_than f \<longrightarrow> P y \<longrightarrow> (\<exists>e'. P e' \<and> Q e')" |
|
621 |
and px: "P x" |
|
622 |
show "\<exists>e'. P e' \<and> Q e'" |
|
623 |
proof(cases "Q x") |
|
624 |
assume "Q x" with px show ?thesis by blast |
|
625 |
next |
|
626 |
assume nq: "\<not> Q x" |
|
627 |
from step [OF px nq] |
|
628 |
obtain e' where pe': "P e'" and ltf: "(f e', f x) \<in> less_than" by auto |
|
629 |
show ?thesis |
|
630 |
proof(rule h) |
|
631 |
from ltf show "(e', x) \<in> inv_image less_than f" |
|
632 |
by (simp add:inv_image_def) |
|
633 |
next |
|
634 |
from pe' show "P e'" . |
|
635 |
qed |
|
636 |
qed |
|
637 |
qed |
|
638 |
||
639 |
text {* |
|
75 | 640 |
The @{text "P"} in lemma @{text "wf_iter"} is an invariant kept throughout the iteration procedure. |
42 | 641 |
The particular invariant used to solve our problem is defined by function @{text "Inv(ES)"}, |
642 |
an invariant over equal system @{text "ES"}. |
|
643 |
Every definition starting next till @{text "Inv"} stipulates a property to be satisfied by @{text "ES"}. |
|
644 |
*} |
|
645 |
||
646 |
text {* |
|
647 |
Every variable is defined at most onece in @{text "ES"}. |
|
648 |
*} |
|
75 | 649 |
|
42 | 650 |
definition |
651 |
"distinct_equas ES \<equiv> |
|
652 |
\<forall> X rhs rhs'. (X, rhs) \<in> ES \<and> (X, rhs') \<in> ES \<longrightarrow> rhs = rhs'" |
|
70 | 653 |
|
42 | 654 |
text {* |
655 |
Every equation in @{text "ES"} (represented by @{text "(X, rhs)"}) is valid, i.e. @{text "(X = L rhs)"}. |
|
656 |
*} |
|
657 |
definition |
|
658 |
"valid_eqns ES \<equiv> \<forall> X rhs. (X, rhs) \<in> ES \<longrightarrow> (X = L rhs)" |
|
659 |
||
660 |
text {* |
|
661 |
The following @{text "rhs_nonempty rhs"} requires regular expressions occuring in transitional |
|
662 |
items of @{text "rhs"} does not contain empty string. This is necessary for |
|
663 |
the application of Arden's transformation to @{text "rhs"}. |
|
664 |
*} |
|
70 | 665 |
|
42 | 666 |
definition |
667 |
"rhs_nonempty rhs \<equiv> (\<forall> Y r. Trn Y r \<in> rhs \<longrightarrow> [] \<notin> L r)" |
|
668 |
||
669 |
text {* |
|
670 |
The following @{text "ardenable ES"} requires that Arden's transformation is applicable |
|
671 |
to every equation of equational system @{text "ES"}. |
|
672 |
*} |
|
70 | 673 |
|
42 | 674 |
definition |
675 |
"ardenable ES \<equiv> \<forall> X rhs. (X, rhs) \<in> ES \<longrightarrow> rhs_nonempty rhs" |
|
676 |
||
677 |
(* The following non_empty seems useless. *) |
|
678 |
definition |
|
679 |
"non_empty ES \<equiv> \<forall> X rhs. (X, rhs) \<in> ES \<longrightarrow> X \<noteq> {}" |
|
680 |
||
681 |
text {* |
|
682 |
The following @{text "finite_rhs ES"} requires every equation in @{text "rhs"} be finite. |
|
683 |
*} |
|
684 |
definition |
|
685 |
"finite_rhs ES \<equiv> \<forall> X rhs. (X, rhs) \<in> ES \<longrightarrow> finite rhs" |
|
686 |
||
687 |
text {* |
|
688 |
The following @{text "classes_of rhs"} returns all variables (or equivalent classes) |
|
689 |
occuring in @{text "rhs"}. |
|
690 |
*} |
|
691 |
definition |
|
692 |
"classes_of rhs \<equiv> {X. \<exists> r. Trn X r \<in> rhs}" |
|
693 |
||
694 |
text {* |
|
695 |
The following @{text "lefts_of ES"} returns all variables |
|
696 |
defined by equational system @{text "ES"}. |
|
697 |
*} |
|
698 |
definition |
|
699 |
"lefts_of ES \<equiv> {Y | Y yrhs. (Y, yrhs) \<in> ES}" |
|
700 |
||
701 |
text {* |
|
702 |
The following @{text "self_contained ES"} requires that every |
|
703 |
variable occuring on the right hand side of equations is already defined by some |
|
704 |
equation in @{text "ES"}. |
|
705 |
*} |
|
706 |
definition |
|
707 |
"self_contained ES \<equiv> \<forall> (X, xrhs) \<in> ES. classes_of xrhs \<subseteq> lefts_of ES" |
|
708 |
||
709 |
||
710 |
text {* |
|
711 |
The invariant @{text "Inv(ES)"} is a conjunction of all the previously defined constaints. |
|
712 |
*} |
|
713 |
definition |
|
714 |
"Inv ES \<equiv> valid_eqns ES \<and> finite ES \<and> distinct_equas ES \<and> ardenable ES \<and> |
|
715 |
non_empty ES \<and> finite_rhs ES \<and> self_contained ES" |
|
716 |
||
717 |
subsection {* The proof of this direction *} |
|
718 |
||
719 |
subsubsection {* Basic properties *} |
|
720 |
||
721 |
text {* |
|
722 |
The following are some basic properties of the above definitions. |
|
723 |
*} |
|
724 |
||
725 |
lemma L_rhs_union_distrib: |
|
70 | 726 |
fixes A B::"rhs_item set" |
727 |
shows "L A \<union> L B = L (A \<union> B)" |
|
42 | 728 |
by simp |
729 |
||
79 | 730 |
lemma finite_Trn: |
731 |
assumes fin: "finite rhs" |
|
732 |
shows "finite {r. Trn Y r \<in> rhs}" |
|
733 |
proof - |
|
734 |
have "finite {Trn Y r | Y r. Trn Y r \<in> rhs}" |
|
735 |
by (rule rev_finite_subset[OF fin]) (auto) |
|
736 |
then have "finite (the_trn_rexp ` {Trn Y r | Y r. Trn Y r \<in> rhs})" |
|
737 |
by auto |
|
738 |
then show "finite {r. Trn Y r \<in> rhs}" |
|
739 |
apply(erule_tac rev_finite_subset) |
|
740 |
apply(auto simp add: image_def) |
|
741 |
apply(rule_tac x="Trn Y x" in exI) |
|
742 |
apply(auto) |
|
743 |
done |
|
744 |
qed |
|
745 |
||
746 |
lemma finite_Lam: |
|
747 |
assumes fin:"finite rhs" |
|
748 |
shows "finite {r. Lam r \<in> rhs}" |
|
749 |
proof - |
|
750 |
have "finite {Lam r | r. Lam r \<in> rhs}" |
|
751 |
by (rule rev_finite_subset[OF fin]) (auto) |
|
752 |
then have "finite (the_r ` {Lam r | r. Lam r \<in> rhs})" |
|
753 |
by auto |
|
754 |
then show "finite {r. Lam r \<in> rhs}" |
|
755 |
apply(erule_tac rev_finite_subset) |
|
756 |
apply(auto simp add: image_def) |
|
757 |
done |
|
42 | 758 |
qed |
759 |
||
760 |
lemma rexp_of_empty: |
|
761 |
assumes finite:"finite rhs" |
|
762 |
and nonempty:"rhs_nonempty rhs" |
|
79 | 763 |
shows "[] \<notin> L (\<Uplus> {r. Trn X r \<in> rhs})" |
42 | 764 |
using finite nonempty rhs_nonempty_def |
79 | 765 |
using finite_Trn[OF finite] |
766 |
by (auto) |
|
42 | 767 |
|
768 |
lemma [intro!]: |
|
769 |
"P (Trn X r) \<Longrightarrow> (\<exists>a. (\<exists>r. a = Trn X r \<and> P a))" by auto |
|
770 |
||
771 |
lemma lang_of_rexp_of: |
|
772 |
assumes finite:"finite rhs" |
|
79 | 773 |
shows "L ({Trn X r| r. Trn X r \<in> rhs}) = X ;; (L (\<Uplus>{r. Trn X r \<in> rhs}))" |
42 | 774 |
proof - |
79 | 775 |
have "finite {r. Trn X r \<in> rhs}" |
776 |
by (rule finite_Trn[OF finite]) |
|
777 |
then show ?thesis |
|
778 |
apply(auto simp add: Seq_def) |
|
779 |
apply(rule_tac x = "s\<^isub>1" in exI, rule_tac x = "s\<^isub>2" in exI, auto) |
|
780 |
apply(rule_tac x= "Trn X xa" in exI) |
|
781 |
apply(auto simp: Seq_def) |
|
782 |
done |
|
42 | 783 |
qed |
784 |
||
785 |
lemma rexp_of_lam_eq_lam_set: |
|
79 | 786 |
assumes fin: "finite rhs" |
787 |
shows "L (\<Uplus>{r. Lam r \<in> rhs}) = L ({Lam r | r. Lam r \<in> rhs})" |
|
42 | 788 |
proof - |
79 | 789 |
have "finite ({r. Lam r \<in> rhs})" using fin by (rule finite_Lam) |
790 |
then show ?thesis by auto |
|
42 | 791 |
qed |
792 |
||
793 |
lemma [simp]: |
|
70 | 794 |
"L (attach_rexp r xb) = L xb ;; L r" |
79 | 795 |
apply (cases xb, auto simp: Seq_def) |
54 | 796 |
apply(rule_tac x = "s\<^isub>1 @ s\<^isub>1'" in exI, rule_tac x = "s\<^isub>2'" in exI) |
797 |
apply(auto simp: Seq_def) |
|
798 |
done |
|
42 | 799 |
|
800 |
lemma lang_of_append_rhs: |
|
801 |
"L (append_rhs_rexp rhs r) = L rhs ;; L r" |
|
802 |
apply (auto simp:append_rhs_rexp_def image_def) |
|
803 |
apply (auto simp:Seq_def) |
|
804 |
apply (rule_tac x = "L xb ;; L r" in exI, auto simp add:Seq_def) |
|
805 |
by (rule_tac x = "attach_rexp r xb" in exI, auto simp:Seq_def) |
|
806 |
||
807 |
lemma classes_of_union_distrib: |
|
808 |
"classes_of A \<union> classes_of B = classes_of (A \<union> B)" |
|
809 |
by (auto simp add:classes_of_def) |
|
810 |
||
811 |
lemma lefts_of_union_distrib: |
|
812 |
"lefts_of A \<union> lefts_of B = lefts_of (A \<union> B)" |
|
813 |
by (auto simp:lefts_of_def) |
|
814 |
||
815 |
||
816 |
subsubsection {* Intialization *} |
|
817 |
||
818 |
text {* |
|
819 |
The following several lemmas until @{text "init_ES_satisfy_Inv"} shows that |
|
820 |
the initial equational system satisfies invariant @{text "Inv"}. |
|
71 | 821 |
*} |
42 | 822 |
|
823 |
lemma defined_by_str: |
|
824 |
"\<lbrakk>s \<in> X; X \<in> UNIV // (\<approx>Lang)\<rbrakk> \<Longrightarrow> X = (\<approx>Lang) `` {s}" |
|
825 |
by (auto simp:quotient_def Image_def str_eq_rel_def) |
|
826 |
||
827 |
lemma every_eqclass_has_transition: |
|
828 |
assumes has_str: "s @ [c] \<in> X" |
|
829 |
and in_CS: "X \<in> UNIV // (\<approx>Lang)" |
|
830 |
obtains Y where "Y \<in> UNIV // (\<approx>Lang)" and "Y ;; {[c]} \<subseteq> X" and "s \<in> Y" |
|
831 |
proof - |
|
832 |
def Y \<equiv> "(\<approx>Lang) `` {s}" |
|
833 |
have "Y \<in> UNIV // (\<approx>Lang)" |
|
834 |
unfolding Y_def quotient_def by auto |
|
835 |
moreover |
|
836 |
have "X = (\<approx>Lang) `` {s @ [c]}" |
|
837 |
using has_str in_CS defined_by_str by blast |
|
838 |
then have "Y ;; {[c]} \<subseteq> X" |
|
839 |
unfolding Y_def Image_def Seq_def |
|
840 |
unfolding str_eq_rel_def |
|
841 |
by clarsimp |
|
842 |
moreover |
|
843 |
have "s \<in> Y" unfolding Y_def |
|
844 |
unfolding Image_def str_eq_rel_def by simp |
|
845 |
ultimately show thesis by (blast intro: that) |
|
846 |
qed |
|
847 |
||
848 |
lemma l_eq_r_in_eqs: |
|
849 |
assumes X_in_eqs: "(X, xrhs) \<in> (eqs (UNIV // (\<approx>Lang)))" |
|
850 |
shows "X = L xrhs" |
|
851 |
proof |
|
852 |
show "X \<subseteq> L xrhs" |
|
853 |
proof |
|
854 |
fix x |
|
855 |
assume "(1)": "x \<in> X" |
|
856 |
show "x \<in> L xrhs" |
|
857 |
proof (cases "x = []") |
|
858 |
assume empty: "x = []" |
|
859 |
thus ?thesis using X_in_eqs "(1)" |
|
860 |
by (auto simp:eqs_def init_rhs_def) |
|
861 |
next |
|
862 |
assume not_empty: "x \<noteq> []" |
|
863 |
then obtain clist c where decom: "x = clist @ [c]" |
|
864 |
by (case_tac x rule:rev_cases, auto) |
|
865 |
have "X \<in> UNIV // (\<approx>Lang)" using X_in_eqs by (auto simp:eqs_def) |
|
866 |
then obtain Y |
|
867 |
where "Y \<in> UNIV // (\<approx>Lang)" |
|
868 |
and "Y ;; {[c]} \<subseteq> X" |
|
869 |
and "clist \<in> Y" |
|
870 |
using decom "(1)" every_eqclass_has_transition by blast |
|
871 |
hence |
|
75 | 872 |
"x \<in> L {Trn Y (CHAR c)| Y c. Y \<in> UNIV // (\<approx>Lang) \<and> Y \<Turnstile>(CHAR c)\<Rightarrow> X}" |
71 | 873 |
unfolding transition_def |
874 |
using "(1)" decom |
|
42 | 875 |
by (simp, rule_tac x = "Trn Y (CHAR c)" in exI, simp add:Seq_def) |
71 | 876 |
thus ?thesis using X_in_eqs "(1)" |
877 |
by (simp add: eqs_def init_rhs_def) |
|
42 | 878 |
qed |
879 |
qed |
|
880 |
next |
|
881 |
show "L xrhs \<subseteq> X" using X_in_eqs |
|
71 | 882 |
by (auto simp:eqs_def init_rhs_def transition_def) |
42 | 883 |
qed |
884 |
||
885 |
lemma finite_init_rhs: |
|
886 |
assumes finite: "finite CS" |
|
887 |
shows "finite (init_rhs CS X)" |
|
888 |
proof- |
|
889 |
have "finite {Trn Y (CHAR c) |Y c. Y \<in> CS \<and> Y ;; {[c]} \<subseteq> X}" (is "finite ?A") |
|
890 |
proof - |
|
891 |
def S \<equiv> "{(Y, c)| Y c. Y \<in> CS \<and> Y ;; {[c]} \<subseteq> X}" |
|
892 |
def h \<equiv> "\<lambda> (Y, c). Trn Y (CHAR c)" |
|
893 |
have "finite (CS \<times> (UNIV::char set))" using finite by auto |
|
894 |
hence "finite S" using S_def |
|
895 |
by (rule_tac B = "CS \<times> UNIV" in finite_subset, auto) |
|
896 |
moreover have "?A = h ` S" by (auto simp: S_def h_def image_def) |
|
897 |
ultimately show ?thesis |
|
898 |
by auto |
|
899 |
qed |
|
71 | 900 |
thus ?thesis by (simp add:init_rhs_def transition_def) |
42 | 901 |
qed |
902 |
||
903 |
lemma init_ES_satisfy_Inv: |
|
904 |
assumes finite_CS: "finite (UNIV // (\<approx>Lang))" |
|
905 |
shows "Inv (eqs (UNIV // (\<approx>Lang)))" |
|
906 |
proof - |
|
907 |
have "finite (eqs (UNIV // (\<approx>Lang)))" using finite_CS |
|
908 |
by (simp add:eqs_def) |
|
909 |
moreover have "distinct_equas (eqs (UNIV // (\<approx>Lang)))" |
|
910 |
by (simp add:distinct_equas_def eqs_def) |
|
911 |
moreover have "ardenable (eqs (UNIV // (\<approx>Lang)))" |
|
912 |
by (auto simp add:ardenable_def eqs_def init_rhs_def rhs_nonempty_def del:L_rhs.simps) |
|
913 |
moreover have "valid_eqns (eqs (UNIV // (\<approx>Lang)))" |
|
914 |
using l_eq_r_in_eqs by (simp add:valid_eqns_def) |
|
915 |
moreover have "non_empty (eqs (UNIV // (\<approx>Lang)))" |
|
916 |
by (auto simp:non_empty_def eqs_def quotient_def Image_def str_eq_rel_def) |
|
917 |
moreover have "finite_rhs (eqs (UNIV // (\<approx>Lang)))" |
|
918 |
using finite_init_rhs[OF finite_CS] |
|
919 |
by (auto simp:finite_rhs_def eqs_def) |
|
920 |
moreover have "self_contained (eqs (UNIV // (\<approx>Lang)))" |
|
921 |
by (auto simp:self_contained_def eqs_def init_rhs_def classes_of_def lefts_of_def) |
|
922 |
ultimately show ?thesis by (simp add:Inv_def) |
|
923 |
qed |
|
924 |
||
925 |
subsubsection {* |
|
926 |
Interation step |
|
927 |
*} |
|
928 |
||
929 |
text {* |
|
930 |
From this point until @{text "iteration_step"}, it is proved |
|
931 |
that there exists iteration steps which keep @{text "Inv(ES)"} while |
|
932 |
decreasing the size of @{text "ES"}. |
|
71 | 933 |
*} |
934 |
||
42 | 935 |
lemma arden_variate_keeps_eq: |
936 |
assumes l_eq_r: "X = L rhs" |
|
79 | 937 |
and not_empty: "[] \<notin> L (\<Uplus>{r. Trn X r \<in> rhs})" |
42 | 938 |
and finite: "finite rhs" |
939 |
shows "X = L (arden_variate X rhs)" |
|
940 |
proof - |
|
79 | 941 |
thm rexp_of_def |
942 |
def A \<equiv> "L (\<Uplus>{r. Trn X r \<in> rhs})" |
|
943 |
def b \<equiv> "rhs - trns_of rhs X" |
|
42 | 944 |
def B \<equiv> "L b" |
945 |
have "X = B ;; A\<star>" |
|
946 |
proof- |
|
79 | 947 |
have "L rhs = L(trns_of rhs X \<union> b)" by (auto simp: b_def trns_of_def) |
948 |
also have "\<dots> = X ;; A \<union> B" |
|
949 |
unfolding trns_of_def |
|
950 |
unfolding L_rhs_union_distrib[symmetric] |
|
951 |
by (simp only: lang_of_rexp_of finite B_def A_def) |
|
952 |
finally show ?thesis |
|
42 | 953 |
using l_eq_r not_empty |
79 | 954 |
apply(rule_tac ardens_revised[THEN iffD1]) |
955 |
apply(simp add: A_def) |
|
956 |
apply(simp) |
|
957 |
done |
|
42 | 958 |
qed |
79 | 959 |
moreover have "L (arden_variate X rhs) = (B ;; A\<star>)" |
42 | 960 |
by (simp only:arden_variate_def L_rhs_union_distrib lang_of_append_rhs |
50 | 961 |
B_def A_def b_def L_rexp.simps seq_union_distrib_left) |
42 | 962 |
ultimately show ?thesis by simp |
963 |
qed |
|
964 |
||
965 |
lemma append_keeps_finite: |
|
966 |
"finite rhs \<Longrightarrow> finite (append_rhs_rexp rhs r)" |
|
967 |
by (auto simp:append_rhs_rexp_def) |
|
968 |
||
969 |
lemma arden_variate_keeps_finite: |
|
970 |
"finite rhs \<Longrightarrow> finite (arden_variate X rhs)" |
|
971 |
by (auto simp:arden_variate_def append_keeps_finite) |
|
972 |
||
973 |
lemma append_keeps_nonempty: |
|
974 |
"rhs_nonempty rhs \<Longrightarrow> rhs_nonempty (append_rhs_rexp rhs r)" |
|
975 |
apply (auto simp:rhs_nonempty_def append_rhs_rexp_def) |
|
976 |
by (case_tac x, auto simp:Seq_def) |
|
977 |
||
978 |
lemma nonempty_set_sub: |
|
979 |
"rhs_nonempty rhs \<Longrightarrow> rhs_nonempty (rhs - A)" |
|
980 |
by (auto simp:rhs_nonempty_def) |
|
981 |
||
982 |
lemma nonempty_set_union: |
|
983 |
"\<lbrakk>rhs_nonempty rhs; rhs_nonempty rhs'\<rbrakk> \<Longrightarrow> rhs_nonempty (rhs \<union> rhs')" |
|
984 |
by (auto simp:rhs_nonempty_def) |
|
985 |
||
986 |
lemma arden_variate_keeps_nonempty: |
|
987 |
"rhs_nonempty rhs \<Longrightarrow> rhs_nonempty (arden_variate X rhs)" |
|
988 |
by (simp only:arden_variate_def append_keeps_nonempty nonempty_set_sub) |
|
989 |
||
990 |
||
991 |
lemma rhs_subst_keeps_nonempty: |
|
992 |
"\<lbrakk>rhs_nonempty rhs; rhs_nonempty xrhs\<rbrakk> \<Longrightarrow> rhs_nonempty (rhs_subst rhs X xrhs)" |
|
993 |
by (simp only:rhs_subst_def append_keeps_nonempty nonempty_set_union nonempty_set_sub) |
|
994 |
||
995 |
lemma rhs_subst_keeps_eq: |
|
996 |
assumes substor: "X = L xrhs" |
|
997 |
and finite: "finite rhs" |
|
998 |
shows "L (rhs_subst rhs X xrhs) = L rhs" (is "?Left = ?Right") |
|
999 |
proof- |
|
79 | 1000 |
def A \<equiv> "L (rhs - trns_of rhs X)" |
1001 |
have "?Left = A \<union> L (append_rhs_rexp xrhs (\<Uplus>{r. Trn X r \<in> rhs}))" |
|
1002 |
unfolding rhs_subst_def |
|
1003 |
unfolding L_rhs_union_distrib[symmetric] |
|
1004 |
by (simp add: A_def) |
|
1005 |
moreover have "?Right = A \<union> L ({Trn X r | r. Trn X r \<in> rhs})" |
|
42 | 1006 |
proof- |
79 | 1007 |
have "rhs = (rhs - trns_of rhs X) \<union> (trns_of rhs X)" by (auto simp add: trns_of_def) |
1008 |
thus ?thesis |
|
1009 |
unfolding A_def |
|
1010 |
unfolding L_rhs_union_distrib |
|
1011 |
unfolding trns_of_def |
|
1012 |
by simp |
|
42 | 1013 |
qed |
79 | 1014 |
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 | 1015 |
using finite substor by (simp only:lang_of_append_rhs lang_of_rexp_of) |
1016 |
ultimately show ?thesis by simp |
|
1017 |
qed |
|
1018 |
||
1019 |
lemma rhs_subst_keeps_finite_rhs: |
|
1020 |
"\<lbrakk>finite rhs; finite yrhs\<rbrakk> \<Longrightarrow> finite (rhs_subst rhs Y yrhs)" |
|
1021 |
by (auto simp:rhs_subst_def append_keeps_finite) |
|
1022 |
||
1023 |
lemma eqs_subst_keeps_finite: |
|
1024 |
assumes finite:"finite (ES:: (string set \<times> rhs_item set) set)" |
|
1025 |
shows "finite (eqs_subst ES Y yrhs)" |
|
1026 |
proof - |
|
1027 |
have "finite {(Ya, rhs_subst yrhsa Y yrhs) |Ya yrhsa. (Ya, yrhsa) \<in> ES}" |
|
1028 |
(is "finite ?A") |
|
1029 |
proof- |
|
1030 |
def eqns' \<equiv> "{((Ya::string set), yrhsa)| Ya yrhsa. (Ya, yrhsa) \<in> ES}" |
|
1031 |
def h \<equiv> "\<lambda> ((Ya::string set), yrhsa). (Ya, rhs_subst yrhsa Y yrhs)" |
|
1032 |
have "finite (h ` eqns')" using finite h_def eqns'_def by auto |
|
1033 |
moreover have "?A = h ` eqns'" by (auto simp:h_def eqns'_def) |
|
1034 |
ultimately show ?thesis by auto |
|
1035 |
qed |
|
1036 |
thus ?thesis by (simp add:eqs_subst_def) |
|
1037 |
qed |
|
1038 |
||
1039 |
lemma eqs_subst_keeps_finite_rhs: |
|
1040 |
"\<lbrakk>finite_rhs ES; finite yrhs\<rbrakk> \<Longrightarrow> finite_rhs (eqs_subst ES Y yrhs)" |
|
1041 |
by (auto intro:rhs_subst_keeps_finite_rhs simp add:eqs_subst_def finite_rhs_def) |
|
1042 |
||
1043 |
lemma append_rhs_keeps_cls: |
|
1044 |
"classes_of (append_rhs_rexp rhs r) = classes_of rhs" |
|
1045 |
apply (auto simp:classes_of_def append_rhs_rexp_def) |
|
1046 |
apply (case_tac xa, auto simp:image_def) |
|
1047 |
by (rule_tac x = "SEQ ra r" in exI, rule_tac x = "Trn x ra" in bexI, simp+) |
|
1048 |
||
1049 |
lemma arden_variate_removes_cl: |
|
1050 |
"classes_of (arden_variate Y yrhs) = classes_of yrhs - {Y}" |
|
79 | 1051 |
apply (simp add:arden_variate_def append_rhs_keeps_cls trns_of_def) |
42 | 1052 |
by (auto simp:classes_of_def) |
1053 |
||
1054 |
lemma lefts_of_keeps_cls: |
|
1055 |
"lefts_of (eqs_subst ES Y yrhs) = lefts_of ES" |
|
1056 |
by (auto simp:lefts_of_def eqs_subst_def) |
|
1057 |
||
1058 |
lemma rhs_subst_updates_cls: |
|
1059 |
"X \<notin> classes_of xrhs \<Longrightarrow> |
|
1060 |
classes_of (rhs_subst rhs X xrhs) = classes_of rhs \<union> classes_of xrhs - {X}" |
|
1061 |
apply (simp only:rhs_subst_def append_rhs_keeps_cls |
|
1062 |
classes_of_union_distrib[THEN sym]) |
|
79 | 1063 |
by (auto simp:classes_of_def trns_of_def) |
42 | 1064 |
|
1065 |
lemma eqs_subst_keeps_self_contained: |
|
1066 |
fixes Y |
|
1067 |
assumes sc: "self_contained (ES \<union> {(Y, yrhs)})" (is "self_contained ?A") |
|
1068 |
shows "self_contained (eqs_subst ES Y (arden_variate Y yrhs))" |
|
1069 |
(is "self_contained ?B") |
|
1070 |
proof- |
|
1071 |
{ fix X xrhs' |
|
1072 |
assume "(X, xrhs') \<in> ?B" |
|
1073 |
then obtain xrhs |
|
1074 |
where xrhs_xrhs': "xrhs' = rhs_subst xrhs Y (arden_variate Y yrhs)" |
|
1075 |
and X_in: "(X, xrhs) \<in> ES" by (simp add:eqs_subst_def, blast) |
|
1076 |
have "classes_of xrhs' \<subseteq> lefts_of ?B" |
|
1077 |
proof- |
|
1078 |
have "lefts_of ?B = lefts_of ES" by (auto simp add:lefts_of_def eqs_subst_def) |
|
1079 |
moreover have "classes_of xrhs' \<subseteq> lefts_of ES" |
|
1080 |
proof- |
|
1081 |
have "classes_of xrhs' \<subseteq> |
|
1082 |
classes_of xrhs \<union> classes_of (arden_variate Y yrhs) - {Y}" |
|
1083 |
proof- |
|
1084 |
have "Y \<notin> classes_of (arden_variate Y yrhs)" |
|
1085 |
using arden_variate_removes_cl by simp |
|
1086 |
thus ?thesis using xrhs_xrhs' by (auto simp:rhs_subst_updates_cls) |
|
1087 |
qed |
|
1088 |
moreover have "classes_of xrhs \<subseteq> lefts_of ES \<union> {Y}" using X_in sc |
|
1089 |
apply (simp only:self_contained_def lefts_of_union_distrib[THEN sym]) |
|
1090 |
by (drule_tac x = "(X, xrhs)" in bspec, auto simp:lefts_of_def) |
|
1091 |
moreover have "classes_of (arden_variate Y yrhs) \<subseteq> lefts_of ES \<union> {Y}" |
|
1092 |
using sc |
|
1093 |
by (auto simp add:arden_variate_removes_cl self_contained_def lefts_of_def) |
|
1094 |
ultimately show ?thesis by auto |
|
1095 |
qed |
|
1096 |
ultimately show ?thesis by simp |
|
1097 |
qed |
|
1098 |
} thus ?thesis by (auto simp only:eqs_subst_def self_contained_def) |
|
1099 |
qed |
|
1100 |
||
1101 |
lemma eqs_subst_satisfy_Inv: |
|
1102 |
assumes Inv_ES: "Inv (ES \<union> {(Y, yrhs)})" |
|
1103 |
shows "Inv (eqs_subst ES Y (arden_variate Y yrhs))" |
|
1104 |
proof - |
|
1105 |
have finite_yrhs: "finite yrhs" |
|
1106 |
using Inv_ES by (auto simp:Inv_def finite_rhs_def) |
|
1107 |
have nonempty_yrhs: "rhs_nonempty yrhs" |
|
1108 |
using Inv_ES by (auto simp:Inv_def ardenable_def) |
|
1109 |
have Y_eq_yrhs: "Y = L yrhs" |
|
1110 |
using Inv_ES by (simp only:Inv_def valid_eqns_def, blast) |
|
1111 |
have "distinct_equas (eqs_subst ES Y (arden_variate Y yrhs))" |
|
1112 |
using Inv_ES |
|
1113 |
by (auto simp:distinct_equas_def eqs_subst_def Inv_def) |
|
1114 |
moreover have "finite (eqs_subst ES Y (arden_variate Y yrhs))" |
|
1115 |
using Inv_ES by (simp add:Inv_def eqs_subst_keeps_finite) |
|
1116 |
moreover have "finite_rhs (eqs_subst ES Y (arden_variate Y yrhs))" |
|
1117 |
proof- |
|
1118 |
have "finite_rhs ES" using Inv_ES |
|
1119 |
by (simp add:Inv_def finite_rhs_def) |
|
1120 |
moreover have "finite (arden_variate Y yrhs)" |
|
1121 |
proof - |
|
1122 |
have "finite yrhs" using Inv_ES |
|
1123 |
by (auto simp:Inv_def finite_rhs_def) |
|
1124 |
thus ?thesis using arden_variate_keeps_finite by simp |
|
1125 |
qed |
|
1126 |
ultimately show ?thesis |
|
1127 |
by (simp add:eqs_subst_keeps_finite_rhs) |
|
1128 |
qed |
|
1129 |
moreover have "ardenable (eqs_subst ES Y (arden_variate Y yrhs))" |
|
1130 |
proof - |
|
1131 |
{ fix X rhs |
|
1132 |
assume "(X, rhs) \<in> ES" |
|
1133 |
hence "rhs_nonempty rhs" using prems Inv_ES |
|
1134 |
by (simp add:Inv_def ardenable_def) |
|
1135 |
with nonempty_yrhs |
|
1136 |
have "rhs_nonempty (rhs_subst rhs Y (arden_variate Y yrhs))" |
|
1137 |
by (simp add:nonempty_yrhs |
|
1138 |
rhs_subst_keeps_nonempty arden_variate_keeps_nonempty) |
|
1139 |
} thus ?thesis by (auto simp add:ardenable_def eqs_subst_def) |
|
1140 |
qed |
|
1141 |
moreover have "valid_eqns (eqs_subst ES Y (arden_variate Y yrhs))" |
|
1142 |
proof- |
|
1143 |
have "Y = L (arden_variate Y yrhs)" |
|
1144 |
using Y_eq_yrhs Inv_ES finite_yrhs nonempty_yrhs |
|
1145 |
by (rule_tac arden_variate_keeps_eq, (simp add:rexp_of_empty)+) |
|
1146 |
thus ?thesis using Inv_ES |
|
1147 |
by (clarsimp simp add:valid_eqns_def |
|
1148 |
eqs_subst_def rhs_subst_keeps_eq Inv_def finite_rhs_def |
|
1149 |
simp del:L_rhs.simps) |
|
1150 |
qed |
|
1151 |
moreover have |
|
1152 |
non_empty_subst: "non_empty (eqs_subst ES Y (arden_variate Y yrhs))" |
|
1153 |
using Inv_ES by (auto simp:Inv_def non_empty_def eqs_subst_def) |
|
1154 |
moreover |
|
1155 |
have self_subst: "self_contained (eqs_subst ES Y (arden_variate Y yrhs))" |
|
1156 |
using Inv_ES eqs_subst_keeps_self_contained by (simp add:Inv_def) |
|
1157 |
ultimately show ?thesis using Inv_ES by (simp add:Inv_def) |
|
1158 |
qed |
|
1159 |
||
1160 |
lemma eqs_subst_card_le: |
|
1161 |
assumes finite: "finite (ES::(string set \<times> rhs_item set) set)" |
|
1162 |
shows "card (eqs_subst ES Y yrhs) <= card ES" |
|
1163 |
proof- |
|
1164 |
def f \<equiv> "\<lambda> x. ((fst x)::string set, rhs_subst (snd x) Y yrhs)" |
|
1165 |
have "eqs_subst ES Y yrhs = f ` ES" |
|
1166 |
apply (auto simp:eqs_subst_def f_def image_def) |
|
1167 |
by (rule_tac x = "(Ya, yrhsa)" in bexI, simp+) |
|
1168 |
thus ?thesis using finite by (auto intro:card_image_le) |
|
1169 |
qed |
|
1170 |
||
1171 |
lemma eqs_subst_cls_remains: |
|
1172 |
"(X, xrhs) \<in> ES \<Longrightarrow> \<exists> xrhs'. (X, xrhs') \<in> (eqs_subst ES Y yrhs)" |
|
1173 |
by (auto simp:eqs_subst_def) |
|
1174 |
||
1175 |
lemma card_noteq_1_has_more: |
|
1176 |
assumes card:"card S \<noteq> 1" |
|
1177 |
and e_in: "e \<in> S" |
|
1178 |
and finite: "finite S" |
|
1179 |
obtains e' where "e' \<in> S \<and> e \<noteq> e'" |
|
1180 |
proof- |
|
1181 |
have "card (S - {e}) > 0" |
|
1182 |
proof - |
|
1183 |
have "card S > 1" using card e_in finite |
|
1184 |
by (case_tac "card S", auto) |
|
1185 |
thus ?thesis using finite e_in by auto |
|
1186 |
qed |
|
1187 |
hence "S - {e} \<noteq> {}" using finite by (rule_tac notI, simp) |
|
1188 |
thus "(\<And>e'. e' \<in> S \<and> e \<noteq> e' \<Longrightarrow> thesis) \<Longrightarrow> thesis" by auto |
|
1189 |
qed |
|
1190 |
||
1191 |
lemma iteration_step: |
|
1192 |
assumes Inv_ES: "Inv ES" |
|
1193 |
and X_in_ES: "(X, xrhs) \<in> ES" |
|
1194 |
and not_T: "card ES \<noteq> 1" |
|
1195 |
shows "\<exists> ES'. (Inv ES' \<and> (\<exists> xrhs'.(X, xrhs') \<in> ES')) \<and> |
|
1196 |
(card ES', card ES) \<in> less_than" (is "\<exists> ES'. ?P ES'") |
|
1197 |
proof - |
|
1198 |
have finite_ES: "finite ES" using Inv_ES by (simp add:Inv_def) |
|
1199 |
then obtain Y yrhs |
|
1200 |
where Y_in_ES: "(Y, yrhs) \<in> ES" and not_eq: "(X, xrhs) \<noteq> (Y, yrhs)" |
|
1201 |
using not_T X_in_ES by (drule_tac card_noteq_1_has_more, auto) |
|
1202 |
def ES' == "ES - {(Y, yrhs)}" |
|
1203 |
let ?ES'' = "eqs_subst ES' Y (arden_variate Y yrhs)" |
|
1204 |
have "?P ?ES''" |
|
1205 |
proof - |
|
1206 |
have "Inv ?ES''" using Y_in_ES Inv_ES |
|
1207 |
by (rule_tac eqs_subst_satisfy_Inv, simp add:ES'_def insert_absorb) |
|
1208 |
moreover have "\<exists>xrhs'. (X, xrhs') \<in> ?ES''" using not_eq X_in_ES |
|
1209 |
by (rule_tac ES = ES' in eqs_subst_cls_remains, auto simp add:ES'_def) |
|
1210 |
moreover have "(card ?ES'', card ES) \<in> less_than" |
|
1211 |
proof - |
|
1212 |
have "finite ES'" using finite_ES ES'_def by auto |
|
1213 |
moreover have "card ES' < card ES" using finite_ES Y_in_ES |
|
1214 |
by (auto simp:ES'_def card_gt_0_iff intro:diff_Suc_less) |
|
1215 |
ultimately show ?thesis |
|
1216 |
by (auto dest:eqs_subst_card_le elim:le_less_trans) |
|
1217 |
qed |
|
1218 |
ultimately show ?thesis by simp |
|
1219 |
qed |
|
1220 |
thus ?thesis by blast |
|
1221 |
qed |
|
1222 |
||
1223 |
subsubsection {* |
|
1224 |
Conclusion of the proof |
|
1225 |
*} |
|
1226 |
||
1227 |
text {* |
|
1228 |
From this point until @{text "hard_direction"}, the hard direction is proved |
|
1229 |
through a simple application of the iteration principle. |
|
1230 |
*} |
|
1231 |
||
1232 |
lemma iteration_conc: |
|
1233 |
assumes history: "Inv ES" |
|
1234 |
and X_in_ES: "\<exists> xrhs. (X, xrhs) \<in> ES" |
|
1235 |
shows |
|
1236 |
"\<exists> ES'. (Inv ES' \<and> (\<exists> xrhs'. (X, xrhs') \<in> ES')) \<and> card ES' = 1" |
|
1237 |
(is "\<exists> ES'. ?P ES'") |
|
1238 |
proof (cases "card ES = 1") |
|
1239 |
case True |
|
1240 |
thus ?thesis using history X_in_ES |
|
1241 |
by blast |
|
1242 |
next |
|
1243 |
case False |
|
1244 |
thus ?thesis using history iteration_step X_in_ES |
|
1245 |
by (rule_tac f = card in wf_iter, auto) |
|
1246 |
qed |
|
1247 |
||
1248 |
lemma last_cl_exists_rexp: |
|
1249 |
assumes ES_single: "ES = {(X, xrhs)}" |
|
1250 |
and Inv_ES: "Inv ES" |
|
1251 |
shows "\<exists> (r::rexp). L r = X" (is "\<exists> r. ?P r") |
|
1252 |
proof- |
|
79 | 1253 |
def A \<equiv> "arden_variate X xrhs" |
1254 |
have "?P (rexp_of_lam A)" |
|
42 | 1255 |
proof - |
79 | 1256 |
thm lam_of_def |
1257 |
thm rexp_of_lam_def |
|
1258 |
have "L (\<Uplus>{r. Lam r \<in> A}) = L ({Lam r | r. Lam r \<in> A})" |
|
42 | 1259 |
proof(rule rexp_of_lam_eq_lam_set) |
79 | 1260 |
show "finite A" |
1261 |
unfolding A_def |
|
1262 |
using Inv_ES ES_single |
|
1263 |
by (rule_tac arden_variate_keeps_finite) |
|
1264 |
(auto simp add: Inv_def finite_rhs_def) |
|
42 | 1265 |
qed |
79 | 1266 |
also have "\<dots> = L A" |
42 | 1267 |
proof- |
79 | 1268 |
have "lam_of A = A" |
42 | 1269 |
proof- |
79 | 1270 |
have "classes_of A = {}" using Inv_ES ES_single |
1271 |
unfolding A_def |
|
42 | 1272 |
by (simp add:arden_variate_removes_cl |
1273 |
self_contained_def Inv_def lefts_of_def) |
|
79 | 1274 |
thus ?thesis |
1275 |
unfolding A_def |
|
42 | 1276 |
by (auto simp only:lam_of_def classes_of_def, case_tac x, auto) |
1277 |
qed |
|
79 | 1278 |
thus ?thesis unfolding lam_of_def by simp |
42 | 1279 |
qed |
1280 |
also have "\<dots> = X" |
|
79 | 1281 |
unfolding A_def |
42 | 1282 |
proof(rule arden_variate_keeps_eq [THEN sym]) |
1283 |
show "X = L xrhs" using Inv_ES ES_single |
|
1284 |
by (auto simp only:Inv_def valid_eqns_def) |
|
1285 |
next |
|
79 | 1286 |
from Inv_ES ES_single show "[] \<notin> L (\<Uplus>{r. Trn X r \<in> xrhs})" |
42 | 1287 |
by(simp add:Inv_def ardenable_def rexp_of_empty finite_rhs_def) |
1288 |
next |
|
1289 |
from Inv_ES ES_single show "finite xrhs" |
|
1290 |
by (simp add:Inv_def finite_rhs_def) |
|
1291 |
qed |
|
79 | 1292 |
finally show ?thesis unfolding rexp_of_lam_def by simp |
42 | 1293 |
qed |
1294 |
thus ?thesis by auto |
|
1295 |
qed |
|
1296 |
||
1297 |
lemma every_eqcl_has_reg: |
|
1298 |
assumes finite_CS: "finite (UNIV // (\<approx>Lang))" |
|
1299 |
and X_in_CS: "X \<in> (UNIV // (\<approx>Lang))" |
|
1300 |
shows "\<exists> (reg::rexp). L reg = X" (is "\<exists> r. ?E r") |
|
1301 |
proof - |
|
1302 |
from X_in_CS have "\<exists> xrhs. (X, xrhs) \<in> (eqs (UNIV // (\<approx>Lang)))" |
|
1303 |
by (auto simp:eqs_def init_rhs_def) |
|
1304 |
then obtain ES xrhs where Inv_ES: "Inv ES" |
|
1305 |
and X_in_ES: "(X, xrhs) \<in> ES" |
|
1306 |
and card_ES: "card ES = 1" |
|
1307 |
using finite_CS X_in_CS init_ES_satisfy_Inv iteration_conc |
|
1308 |
by blast |
|
1309 |
hence ES_single_equa: "ES = {(X, xrhs)}" |
|
1310 |
by (auto simp:Inv_def dest!:card_Suc_Diff1 simp:card_eq_0_iff) |
|
1311 |
thus ?thesis using Inv_ES |
|
1312 |
by (rule last_cl_exists_rexp) |
|
1313 |
qed |
|
1314 |
||
1315 |
theorem hard_direction: |
|
70 | 1316 |
assumes finite_CS: "finite (UNIV // \<approx>A)" |
1317 |
shows "\<exists>r::rexp. A = L r" |
|
42 | 1318 |
proof - |
70 | 1319 |
have "\<forall> X \<in> (UNIV // \<approx>A). \<exists>reg::rexp. X = L reg" |
42 | 1320 |
using finite_CS every_eqcl_has_reg by blast |
1321 |
then obtain f |
|
70 | 1322 |
where f_prop: "\<forall> X \<in> (UNIV // \<approx>A). X = L ((f X)::rexp)" |
1323 |
by (auto dest: bchoice) |
|
1324 |
def rs \<equiv> "f ` (finals A)" |
|
1325 |
have "A = \<Union> (finals A)" using lang_is_union_of_finals by auto |
|
76 | 1326 |
also have "\<dots> = L (\<Uplus>rs)" |
42 | 1327 |
proof - |
1328 |
have "finite rs" |
|
1329 |
proof - |
|
70 | 1330 |
have "finite (finals A)" |
1331 |
using finite_CS finals_in_partitions[of "A"] |
|
42 | 1332 |
by (erule_tac finite_subset, simp) |
1333 |
thus ?thesis using rs_def by auto |
|
1334 |
qed |
|
1335 |
thus ?thesis |
|
70 | 1336 |
using f_prop rs_def finals_in_partitions[of "A"] by auto |
42 | 1337 |
qed |
1338 |
finally show ?thesis by blast |
|
1339 |
qed |
|
1340 |
||
1341 |
end |