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