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