author | urbanc |
Thu, 02 Jun 2011 20:02:16 +0000 | |
changeset 167 | 61d0a412a3ae |
parent 162 | e93760534354 |
child 170 | b1258b7d2789 |
permissions | -rw-r--r-- |
24 | 1 |
(*<*) |
2 |
theory Paper |
|
167 | 3 |
imports "../Closure" |
24 | 4 |
begin |
39
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
5 |
|
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
6 |
declare [[show_question_marks = false]] |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
7 |
|
54 | 8 |
consts |
9 |
REL :: "(string \<times> string) \<Rightarrow> bool" |
|
66 | 10 |
UPLUS :: "'a set \<Rightarrow> 'a set \<Rightarrow> (nat \<times> 'a) set" |
54 | 11 |
|
70 | 12 |
abbreviation |
13 |
"EClass x R \<equiv> R `` {x}" |
|
54 | 14 |
|
92 | 15 |
abbreviation |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
16 |
"Append_rexp2 r_itm r \<equiv> Append_rexp r r_itm" |
92 | 17 |
|
18 |
||
39
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
19 |
notation (latex output) |
50 | 20 |
str_eq_rel ("\<approx>\<^bsub>_\<^esub>") and |
75 | 21 |
str_eq ("_ \<approx>\<^bsub>_\<^esub> _") and |
50 | 22 |
Seq (infixr "\<cdot>" 100) and |
23 |
Star ("_\<^bsup>\<star>\<^esup>") and |
|
24 |
pow ("_\<^bsup>_\<^esup>" [100, 100] 100) and |
|
58 | 25 |
Suc ("_+1" [100] 100) and |
54 | 26 |
quotient ("_ \<^raw:\ensuremath{\!\sslash\!}> _" [90, 90] 90) and |
66 | 27 |
REL ("\<approx>") and |
67 | 28 |
UPLUS ("_ \<^raw:\ensuremath{\uplus}> _" [90, 90] 90) and |
167 | 29 |
L_rexp ("\<^raw:\ensuremath{\cal{L}}>'(_')" [0] 101) and |
75 | 30 |
Lam ("\<lambda>'(_')" [100] 100) and |
89 | 31 |
Trn ("'(_, _')" [100, 100] 100) and |
71 | 32 |
EClass ("\<lbrakk>_\<rbrakk>\<^bsub>_\<^esub>" [100, 100] 100) and |
88 | 33 |
transition ("_ \<^raw:\ensuremath{\stackrel{\text{>_\<^raw:}}{\Longmapsto}}> _" [100, 100, 100] 100) and |
92 | 34 |
Setalt ("\<^raw:\ensuremath{\bigplus}>_" [1000] 999) and |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
35 |
Append_rexp2 ("_ \<^raw:\ensuremath{\triangleleft}> _" [100, 100] 100) and |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
36 |
Append_rexp_rhs ("_ \<^raw:\ensuremath{\triangleleft}> _" [100, 100] 50) and |
119 | 37 |
uminus ("\<^raw:\ensuremath{\overline{>_\<^raw:}}>" [100] 100) and |
38 |
tag_str_ALT ("tag\<^isub>A\<^isub>L\<^isub>T _ _" [100, 100] 100) and |
|
121
1cf12a107b03
added directory with the small files and numbers of lines
urbanc
parents:
120
diff
changeset
|
39 |
tag_str_ALT ("tag\<^isub>A\<^isub>L\<^isub>T _ _ _" [100, 100, 100] 100) and |
1cf12a107b03
added directory with the small files and numbers of lines
urbanc
parents:
120
diff
changeset
|
40 |
tag_str_SEQ ("tag\<^isub>S\<^isub>E\<^isub>Q _ _" [100, 100] 100) and |
1cf12a107b03
added directory with the small files and numbers of lines
urbanc
parents:
120
diff
changeset
|
41 |
tag_str_SEQ ("tag\<^isub>S\<^isub>E\<^isub>Q _ _ _" [100, 100, 100] 100) and |
1cf12a107b03
added directory with the small files and numbers of lines
urbanc
parents:
120
diff
changeset
|
42 |
tag_str_STAR ("tag\<^isub>S\<^isub>T\<^isub>A\<^isub>R _" [100] 100) and |
1cf12a107b03
added directory with the small files and numbers of lines
urbanc
parents:
120
diff
changeset
|
43 |
tag_str_STAR ("tag\<^isub>S\<^isub>T\<^isub>A\<^isub>R _ _" [100, 100] 100) |
167 | 44 |
|
119 | 45 |
lemma meta_eq_app: |
46 |
shows "f \<equiv> \<lambda>x. g x \<Longrightarrow> f x \<equiv> g x" |
|
47 |
by auto |
|
48 |
||
167 | 49 |
(* THEOREMS *) |
50 |
||
51 |
notation (Rule output) |
|
52 |
"==>" ("\<^raw:\mbox{}\inferrule{\mbox{>_\<^raw:}}>\<^raw:{\mbox{>_\<^raw:}}>") |
|
53 |
||
54 |
syntax (Rule output) |
|
55 |
"_bigimpl" :: "asms \<Rightarrow> prop \<Rightarrow> prop" |
|
56 |
("\<^raw:\mbox{}\inferrule{>_\<^raw:}>\<^raw:{\mbox{>_\<^raw:}}>") |
|
57 |
||
58 |
"_asms" :: "prop \<Rightarrow> asms \<Rightarrow> asms" |
|
59 |
("\<^raw:\mbox{>_\<^raw:}\\>/ _") |
|
60 |
||
61 |
"_asm" :: "prop \<Rightarrow> asms" ("\<^raw:\mbox{>_\<^raw:}>") |
|
62 |
||
63 |
notation (Axiom output) |
|
64 |
"Trueprop" ("\<^raw:\mbox{}\inferrule{\mbox{}}{\mbox{>_\<^raw:}}>") |
|
65 |
||
66 |
notation (IfThen output) |
|
67 |
"==>" ("\<^raw:{\normalsize{}>If\<^raw:\,}> _/ \<^raw:{\normalsize \,>then\<^raw:\,}>/ _.") |
|
68 |
syntax (IfThen output) |
|
69 |
"_bigimpl" :: "asms \<Rightarrow> prop \<Rightarrow> prop" |
|
70 |
("\<^raw:{\normalsize{}>If\<^raw:\,}> _ /\<^raw:{\normalsize \,>then\<^raw:\,}>/ _.") |
|
71 |
"_asms" :: "prop \<Rightarrow> asms \<Rightarrow> asms" ("\<^raw:\mbox{>_\<^raw:}> /\<^raw:{\normalsize \,>and\<^raw:\,}>/ _") |
|
72 |
"_asm" :: "prop \<Rightarrow> asms" ("\<^raw:\mbox{>_\<^raw:}>") |
|
73 |
||
74 |
notation (IfThenNoBox output) |
|
75 |
"==>" ("\<^raw:{\normalsize{}>If\<^raw:\,}> _/ \<^raw:{\normalsize \,>then\<^raw:\,}>/ _.") |
|
76 |
syntax (IfThenNoBox output) |
|
77 |
"_bigimpl" :: "asms \<Rightarrow> prop \<Rightarrow> prop" |
|
78 |
("\<^raw:{\normalsize{}>If\<^raw:\,}> _ /\<^raw:{\normalsize \,>then\<^raw:\,}>/ _.") |
|
79 |
"_asms" :: "prop \<Rightarrow> asms \<Rightarrow> asms" ("_ /\<^raw:{\normalsize \,>and\<^raw:\,}>/ _") |
|
80 |
"_asm" :: "prop \<Rightarrow> asms" ("_") |
|
81 |
||
82 |
||
24 | 83 |
(*>*) |
84 |
||
70 | 85 |
|
24 | 86 |
section {* Introduction *} |
87 |
||
88 |
text {* |
|
167 | 89 |
\noindent |
58 | 90 |
Regular languages are an important and well-understood subject in Computer |
60 | 91 |
Science, with many beautiful theorems and many useful algorithms. There is a |
66 | 92 |
wide range of textbooks on this subject, many of which are aimed at students |
115 | 93 |
and contain very detailed `pencil-and-paper' proofs |
60 | 94 |
(e.g.~\cite{Kozen97}). It seems natural to exercise theorem provers by |
101 | 95 |
formalising the theorems and by verifying formally the algorithms. |
59 | 96 |
|
66 | 97 |
There is however a problem: the typical approach to regular languages is to |
98 |
introduce finite automata and then define everything in terms of them. For |
|
99 |
example, a regular language is normally defined as one whose strings are |
|
100 |
recognised by a finite deterministic automaton. This approach has many |
|
71 | 101 |
benefits. Among them is the fact that it is easy to convince oneself that |
66 | 102 |
regular languages are closed under complementation: one just has to exchange |
103 |
the accepting and non-accepting states in the corresponding automaton to |
|
104 |
obtain an automaton for the complement language. The problem, however, lies with |
|
67 | 105 |
formalising such reasoning in a HOL-based theorem prover, in our case |
115 | 106 |
Isabelle/HOL. Automata are built up from states and transitions that |
82 | 107 |
need to be represented as graphs, matrices or functions, none |
154 | 108 |
of which can be defined as an inductive datatype. |
66 | 109 |
|
82 | 110 |
In case of graphs and matrices, this means we have to build our own |
111 |
reasoning infrastructure for them, as neither Isabelle/HOL nor HOL4 nor |
|
112 |
HOLlight support them with libraries. Even worse, reasoning about graphs and |
|
113 |
matrices can be a real hassle in HOL-based theorem provers. Consider for |
|
114 |
example the operation of sequencing two automata, say $A_1$ and $A_2$, by |
|
167 | 115 |
connecting the accepting states of $A_1$ to the initial state of $A_2$: |
159 | 116 |
% |
60 | 117 |
\begin{center} |
66 | 118 |
\begin{tabular}{ccc} |
119 |
\begin{tikzpicture}[scale=0.8] |
|
120 |
%\draw[step=2mm] (-1,-1) grid (1,1); |
|
121 |
||
122 |
\draw[rounded corners=1mm, very thick] (-1.0,-0.3) rectangle (-0.2,0.3); |
|
123 |
\draw[rounded corners=1mm, very thick] ( 0.2,-0.3) rectangle ( 1.0,0.3); |
|
124 |
||
125 |
\node (A) at (-1.0,0.0) [circle, very thick, draw, fill=white, inner sep=0.4mm] {}; |
|
126 |
\node (B) at ( 0.2,0.0) [circle, very thick, draw, fill=white, inner sep=0.4mm] {}; |
|
127 |
||
128 |
\node (C) at (-0.2, 0.13) [circle, very thick, draw, fill=white, inner sep=0.4mm] {}; |
|
129 |
\node (D) at (-0.2,-0.13) [circle, very thick, draw, fill=white, inner sep=0.4mm] {}; |
|
130 |
||
131 |
\node (E) at (1.0, 0.2) [circle, very thick, draw, fill=white, inner sep=0.4mm] {}; |
|
132 |
\node (F) at (1.0,-0.0) [circle, very thick, draw, fill=white, inner sep=0.4mm] {}; |
|
133 |
\node (G) at (1.0,-0.2) [circle, very thick, draw, fill=white, inner sep=0.4mm] {}; |
|
134 |
||
135 |
\draw (-0.6,0.0) node {\footnotesize$A_1$}; |
|
136 |
\draw ( 0.6,0.0) node {\footnotesize$A_2$}; |
|
137 |
\end{tikzpicture} |
|
138 |
||
139 |
& |
|
140 |
||
141 |
\raisebox{1.1mm}{\bf\Large$\;\;\;\Rightarrow\,\;\;$} |
|
142 |
||
143 |
& |
|
144 |
||
145 |
\begin{tikzpicture}[scale=0.8] |
|
146 |
%\draw[step=2mm] (-1,-1) grid (1,1); |
|
147 |
||
148 |
\draw[rounded corners=1mm, very thick] (-1.0,-0.3) rectangle (-0.2,0.3); |
|
149 |
\draw[rounded corners=1mm, very thick] ( 0.2,-0.3) rectangle ( 1.0,0.3); |
|
150 |
||
151 |
\node (A) at (-1.0,0.0) [circle, very thick, draw, fill=white, inner sep=0.4mm] {}; |
|
152 |
\node (B) at ( 0.2,0.0) [circle, very thick, draw, fill=white, inner sep=0.4mm] {}; |
|
153 |
||
154 |
\node (C) at (-0.2, 0.13) [circle, very thick, draw, fill=white, inner sep=0.4mm] {}; |
|
155 |
\node (D) at (-0.2,-0.13) [circle, very thick, draw, fill=white, inner sep=0.4mm] {}; |
|
156 |
||
157 |
\node (E) at (1.0, 0.2) [circle, very thick, draw, fill=white, inner sep=0.4mm] {}; |
|
158 |
\node (F) at (1.0,-0.0) [circle, very thick, draw, fill=white, inner sep=0.4mm] {}; |
|
159 |
\node (G) at (1.0,-0.2) [circle, very thick, draw, fill=white, inner sep=0.4mm] {}; |
|
160 |
||
161 |
\draw (C) to [very thick, bend left=45] (B); |
|
162 |
\draw (D) to [very thick, bend right=45] (B); |
|
163 |
||
164 |
\draw (-0.6,0.0) node {\footnotesize$A_1$}; |
|
165 |
\draw ( 0.6,0.0) node {\footnotesize$A_2$}; |
|
166 |
\end{tikzpicture} |
|
167 |
||
168 |
\end{tabular} |
|
60 | 169 |
\end{center} |
170 |
||
171 |
\noindent |
|
115 | 172 |
On `paper' we can define the corresponding graph in terms of the disjoint |
88 | 173 |
union of the state nodes. Unfortunately in HOL, the standard definition for disjoint |
66 | 174 |
union, namely |
82 | 175 |
% |
176 |
\begin{equation}\label{disjointunion} |
|
66 | 177 |
@{term "UPLUS A\<^isub>1 A\<^isub>2 \<equiv> {(1, x) | x. x \<in> A\<^isub>1} \<union> {(2, y) | y. y \<in> A\<^isub>2}"} |
82 | 178 |
\end{equation} |
60 | 179 |
|
61 | 180 |
\noindent |
66 | 181 |
changes the type---the disjoint union is not a set, but a set of pairs. |
135 | 182 |
Using this definition for disjoint union means we do not have a single type for automata |
92 | 183 |
and hence will not be able to state certain properties about \emph{all} |
154 | 184 |
automata, since there is no type quantification available in HOL (unlike in Coq, for example). An |
67 | 185 |
alternative, which provides us with a single type for automata, is to give every |
186 |
state node an identity, for example a natural |
|
70 | 187 |
number, and then be careful to rename these identities apart whenever |
67 | 188 |
connecting two automata. This results in clunky proofs |
66 | 189 |
establishing that properties are invariant under renaming. Similarly, |
67 | 190 |
connecting two automata represented as matrices results in very adhoc |
66 | 191 |
constructions, which are not pleasant to reason about. |
192 |
||
82 | 193 |
Functions are much better supported in Isabelle/HOL, but they still lead to similar |
88 | 194 |
problems as with graphs. Composing, for example, two non-deterministic automata in parallel |
93 | 195 |
requires also the formalisation of disjoint unions. Nipkow \cite{Nipkow98} |
101 | 196 |
dismisses for this the option of using identities, because it leads according to |
197 |
him to ``messy proofs''. He |
|
103 | 198 |
opts for a variant of \eqref{disjointunion} using bit lists, but writes |
82 | 199 |
|
200 |
\begin{quote} |
|
93 | 201 |
\it% |
202 |
\begin{tabular}{@ {}l@ {}p{0.88\textwidth}@ {}} |
|
101 | 203 |
`` & All lemmas appear obvious given a picture of the composition of automata\ldots |
204 |
Yet their proofs require a painful amount of detail.'' |
|
205 |
\end{tabular} |
|
206 |
\end{quote} |
|
207 |
||
208 |
\noindent |
|
209 |
and |
|
210 |
||
211 |
\begin{quote} |
|
212 |
\it% |
|
213 |
\begin{tabular}{@ {}l@ {}p{0.88\textwidth}@ {}} |
|
93 | 214 |
`` & If the reader finds the above treatment in terms of bit lists revoltingly |
101 | 215 |
concrete, I cannot disagree. A more abstract approach is clearly desirable.'' |
93 | 216 |
\end{tabular} |
82 | 217 |
\end{quote} |
101 | 218 |
|
219 |
||
82 | 220 |
\noindent |
221 |
Moreover, it is not so clear how to conveniently impose a finiteness condition |
|
222 |
upon functions in order to represent \emph{finite} automata. The best is |
|
92 | 223 |
probably to resort to more advanced reasoning frameworks, such as \emph{locales} |
224 |
or \emph{type classes}, |
|
134 | 225 |
which are \emph{not} available in all HOL-based theorem provers. |
82 | 226 |
|
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
227 |
{\bf add commnets from Brozowski} |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
228 |
|
66 | 229 |
Because of these problems to do with representing automata, there seems |
230 |
to be no substantial formalisation of automata theory and regular languages |
|
115 | 231 |
carried out in HOL-based theorem provers. Nipkow \cite{Nipkow98} establishes |
232 |
the link between regular expressions and automata in |
|
233 |
the context of lexing. Berghofer and Reiter \cite{BerghoferReiter09} |
|
234 |
formalise automata working over |
|
235 |
bit strings in the context of Presburger arithmetic. |
|
114 | 236 |
The only larger formalisations of automata theory |
115 | 237 |
are carried out in Nuprl \cite{Constable00} and in Coq \cite{Filliatre97}. |
58 | 238 |
|
82 | 239 |
In this paper, we will not attempt to formalise automata theory in |
159 | 240 |
Isabelle/HOL, but take a different approach to regular |
82 | 241 |
languages. Instead of defining a regular language as one where there exists |
242 |
an automaton that recognises all strings of the language, we define a |
|
243 |
regular language as: |
|
54 | 244 |
|
167 | 245 |
\begin{dfntn} |
77 | 246 |
A language @{text A} is \emph{regular}, provided there is a regular expression that matches all |
54 | 247 |
strings of @{text "A"}. |
167 | 248 |
\end{dfntn} |
54 | 249 |
|
250 |
\noindent |
|
110 | 251 |
The reason is that regular expressions, unlike graphs, matrices and functions, can |
71 | 252 |
be easily defined as inductive datatype. Consequently a corresponding reasoning |
253 |
infrastructure comes for free. This has recently been exploited in HOL4 with a formalisation |
|
101 | 254 |
of regular expression matching based on derivatives \cite{OwensSlind08} and |
255 |
with an equivalence checker for regular expressions in Isabelle/HOL \cite{KraussNipkow11}. |
|
256 |
The purpose of this paper is to |
|
71 | 257 |
show that a central result about regular languages---the Myhill-Nerode theorem---can |
258 |
be recreated by only using regular expressions. This theorem gives necessary |
|
259 |
and sufficient conditions for when a language is regular. As a corollary of this |
|
67 | 260 |
theorem we can easily establish the usual closure properties, including |
261 |
complementation, for regular languages.\smallskip |
|
61 | 262 |
|
263 |
\noindent |
|
88 | 264 |
{\bf Contributions:} |
265 |
There is an extensive literature on regular languages. |
|
159 | 266 |
To our best knowledge, our proof of the Myhill-Nerode theorem is the |
67 | 267 |
first that is based on regular expressions, only. We prove the part of this theorem |
268 |
stating that a regular expression has only finitely many partitions using certain |
|
135 | 269 |
tagging-functions. Again to our best knowledge, these tagging-functions have |
67 | 270 |
not been used before to establish the Myhill-Nerode theorem. |
24 | 271 |
*} |
272 |
||
50 | 273 |
section {* Preliminaries *} |
274 |
||
275 |
text {* |
|
67 | 276 |
Strings in Isabelle/HOL are lists of characters with the \emph{empty string} |
92 | 277 |
being represented by the empty list, written @{term "[]"}. \emph{Languages} |
67 | 278 |
are sets of strings. The language containing all strings is written in |
71 | 279 |
Isabelle/HOL as @{term "UNIV::string set"}. The concatenation of two languages |
167 | 280 |
is written @{term "A \<cdot> B"} and a language raised to the power @{text n} is written |
93 | 281 |
@{term "A \<up> n"}. They are defined as usual |
54 | 282 |
|
283 |
\begin{center} |
|
58 | 284 |
@{thm Seq_def[THEN eq_reflection, where A1="A" and B1="B"]} |
285 |
\hspace{7mm} |
|
286 |
@{thm pow.simps(1)[THEN eq_reflection, where A1="A"]} |
|
287 |
\hspace{7mm} |
|
288 |
@{thm pow.simps(2)[THEN eq_reflection, where A1="A" and n1="n"]} |
|
54 | 289 |
\end{center} |
290 |
||
291 |
\noindent |
|
113 | 292 |
where @{text "@"} is the list-append operation. The Kleene-star of a language @{text A} |
71 | 293 |
is defined as the union over all powers, namely @{thm Star_def}. In the paper |
88 | 294 |
we will make use of the following properties of these constructions. |
58 | 295 |
|
167 | 296 |
\begin{prpstn}\label{langprops}\mbox{}\\ |
92 | 297 |
\begin{tabular}{@ {}ll} |
298 |
(i) & @{thm star_cases} \\ |
|
299 |
(ii) & @{thm[mode=IfThen] pow_length}\\ |
|
300 |
(iii) & @{thm seq_Union_left} \\ |
|
71 | 301 |
\end{tabular} |
167 | 302 |
\end{prpstn} |
71 | 303 |
|
304 |
\noindent |
|
100 | 305 |
In @{text "(ii)"} we use the notation @{term "length s"} for the length of a |
156 | 306 |
string; this property states that if \mbox{@{term "[] \<notin> A"}} then the lengths of |
100 | 307 |
the strings in @{term "A \<up> (Suc n)"} must be longer than @{text n}. We omit |
308 |
the proofs for these properties, but invite the reader to consult our |
|
123 | 309 |
formalisation.\footnote{Available at \url{http://www4.in.tum.de/~urbanc/regexp.html}} |
71 | 310 |
|
90 | 311 |
The notation in Isabelle/HOL for the quotient of a language @{text A} according to an |
312 |
equivalence relation @{term REL} is @{term "A // REL"}. We will write |
|
71 | 313 |
@{text "\<lbrakk>x\<rbrakk>\<^isub>\<approx>"} for the equivalence class defined |
156 | 314 |
as \mbox{@{text "{y | y \<approx> x}"}}. |
71 | 315 |
|
316 |
||
51 | 317 |
Central to our proof will be the solution of equational systems |
156 | 318 |
involving equivalence classes of languages. For this we will use Arden's Lemma \cite{Brzozowski64}, |
167 | 319 |
which solves equations of the form @{term "X = A \<cdot> X \<union> B"} provided |
115 | 320 |
@{term "[] \<notin> A"}. However we will need the following `reverse' |
167 | 321 |
version of Arden's Lemma (`reverse' in the sense of changing the order of @{term "A \<cdot> X"} to |
322 |
\mbox{@{term "X \<cdot> A"}}). |
|
50 | 323 |
|
167 | 324 |
\begin{lmm}[Reverse Arden's Lemma]\label{arden}\mbox{}\\ |
86 | 325 |
If @{thm (prem 1) arden} then |
115 | 326 |
@{thm (lhs) arden} if and only if |
86 | 327 |
@{thm (rhs) arden}. |
167 | 328 |
\end{lmm} |
50 | 329 |
|
330 |
\begin{proof} |
|
86 | 331 |
For the right-to-left direction we assume @{thm (rhs) arden} and show |
332 |
that @{thm (lhs) arden} holds. From Prop.~\ref{langprops}@{text "(i)"} |
|
167 | 333 |
we have @{term "A\<star> = {[]} \<union> A \<cdot> A\<star>"}, |
334 |
which is equal to @{term "A\<star> = {[]} \<union> A\<star> \<cdot> A"}. Adding @{text B} to both |
|
335 |
sides gives @{term "B \<cdot> A\<star> = B \<cdot> ({[]} \<union> A\<star> \<cdot> A)"}, whose right-hand side |
|
336 |
is equal to @{term "(B \<cdot> A\<star>) \<cdot> A \<union> B"}. This completes this direction. |
|
50 | 337 |
|
86 | 338 |
For the other direction we assume @{thm (lhs) arden}. By a simple induction |
51 | 339 |
on @{text n}, we can establish the property |
50 | 340 |
|
341 |
\begin{center} |
|
86 | 342 |
@{text "(*)"}\hspace{5mm} @{thm (concl) arden_helper} |
50 | 343 |
\end{center} |
344 |
||
345 |
\noindent |
|
167 | 346 |
Using this property we can show that @{term "B \<cdot> (A \<up> n) \<subseteq> X"} holds for |
347 |
all @{text n}. From this we can infer @{term "B \<cdot> A\<star> \<subseteq> X"} using the definition |
|
71 | 348 |
of @{text "\<star>"}. |
51 | 349 |
For the inclusion in the other direction we assume a string @{text s} |
134 | 350 |
with length @{text k} is an element in @{text X}. Since @{thm (prem 1) arden} |
75 | 351 |
we know by Prop.~\ref{langprops}@{text "(ii)"} that |
167 | 352 |
@{term "s \<notin> X \<cdot> (A \<up> Suc k)"} since its length is only @{text k} |
353 |
(the strings in @{term "X \<cdot> (A \<up> Suc k)"} are all longer). |
|
53 | 354 |
From @{text "(*)"} it follows then that |
167 | 355 |
@{term s} must be an element in @{term "(\<Union>m\<in>{0..k}. B \<cdot> (A \<up> m))"}. This in turn |
356 |
implies that @{term s} is in @{term "(\<Union>n. B \<cdot> (A \<up> n))"}. Using Prop.~\ref{langprops}@{text "(iii)"} |
|
357 |
this is equal to @{term "B \<cdot> A\<star>"}, as we needed to show.\qed |
|
50 | 358 |
\end{proof} |
67 | 359 |
|
360 |
\noindent |
|
88 | 361 |
Regular expressions are defined as the inductive datatype |
67 | 362 |
|
363 |
\begin{center} |
|
364 |
@{text r} @{text "::="} |
|
365 |
@{term NULL}\hspace{1.5mm}@{text"|"}\hspace{1.5mm} |
|
366 |
@{term EMPTY}\hspace{1.5mm}@{text"|"}\hspace{1.5mm} |
|
367 |
@{term "CHAR c"}\hspace{1.5mm}@{text"|"}\hspace{1.5mm} |
|
368 |
@{term "SEQ r r"}\hspace{1.5mm}@{text"|"}\hspace{1.5mm} |
|
369 |
@{term "ALT r r"}\hspace{1.5mm}@{text"|"}\hspace{1.5mm} |
|
370 |
@{term "STAR r"} |
|
371 |
\end{center} |
|
372 |
||
373 |
\noindent |
|
88 | 374 |
and the language matched by a regular expression is defined as |
67 | 375 |
|
376 |
\begin{center} |
|
377 |
\begin{tabular}{c@ {\hspace{10mm}}c} |
|
378 |
\begin{tabular}{rcl} |
|
379 |
@{thm (lhs) L_rexp.simps(1)} & @{text "\<equiv>"} & @{thm (rhs) L_rexp.simps(1)}\\ |
|
380 |
@{thm (lhs) L_rexp.simps(2)} & @{text "\<equiv>"} & @{thm (rhs) L_rexp.simps(2)}\\ |
|
381 |
@{thm (lhs) L_rexp.simps(3)[where c="c"]} & @{text "\<equiv>"} & @{thm (rhs) L_rexp.simps(3)[where c="c"]}\\ |
|
382 |
\end{tabular} |
|
383 |
& |
|
384 |
\begin{tabular}{rcl} |
|
385 |
@{thm (lhs) L_rexp.simps(4)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]} & @{text "\<equiv>"} & |
|
386 |
@{thm (rhs) L_rexp.simps(4)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]}\\ |
|
387 |
@{thm (lhs) L_rexp.simps(5)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]} & @{text "\<equiv>"} & |
|
388 |
@{thm (rhs) L_rexp.simps(5)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]}\\ |
|
389 |
@{thm (lhs) L_rexp.simps(6)[where r="r"]} & @{text "\<equiv>"} & |
|
390 |
@{thm (rhs) L_rexp.simps(6)[where r="r"]}\\ |
|
391 |
\end{tabular} |
|
392 |
\end{tabular} |
|
393 |
\end{center} |
|
70 | 394 |
|
100 | 395 |
Given a finite set of regular expressions @{text rs}, we will make use of the operation of generating |
132 | 396 |
a regular expression that matches the union of all languages of @{text rs}. We only need to know the |
397 |
existence |
|
92 | 398 |
of such a regular expression and therefore we use Isabelle/HOL's @{const "fold_graph"} and Hilbert's |
93 | 399 |
@{text "\<epsilon>"} to define @{term "\<Uplus>rs"}. This operation, roughly speaking, folds @{const ALT} over the |
100 | 400 |
set @{text rs} with @{const NULL} for the empty set. We can prove that for a finite set @{text rs} |
110 | 401 |
% |
402 |
\begin{equation}\label{uplus} |
|
403 |
\mbox{@{thm (lhs) folds_alt_simp} @{text "= \<Union> (\<calL> ` rs)"}} |
|
404 |
\end{equation} |
|
88 | 405 |
|
406 |
\noindent |
|
90 | 407 |
holds, whereby @{text "\<calL> ` rs"} stands for the |
408 |
image of the set @{text rs} under function @{text "\<calL>"}. |
|
50 | 409 |
*} |
39
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
410 |
|
132 | 411 |
|
133 | 412 |
section {* The Myhill-Nerode Theorem, First Part *} |
54 | 413 |
|
414 |
text {* |
|
77 | 415 |
The key definition in the Myhill-Nerode theorem is the |
75 | 416 |
\emph{Myhill-Nerode relation}, which states that w.r.t.~a language two |
417 |
strings are related, provided there is no distinguishing extension in this |
|
154 | 418 |
language. This can be defined as a tertiary relation. |
75 | 419 |
|
167 | 420 |
\begin{dfntn}[Myhill-Nerode Relation] Given a language @{text A}, two strings @{text x} and |
123 | 421 |
@{text y} are Myhill-Nerode related provided |
117 | 422 |
\begin{center} |
75 | 423 |
@{thm str_eq_def[simplified str_eq_rel_def Pair_Collect]} |
117 | 424 |
\end{center} |
167 | 425 |
\end{dfntn} |
70 | 426 |
|
71 | 427 |
\noindent |
75 | 428 |
It is easy to see that @{term "\<approx>A"} is an equivalence relation, which |
429 |
partitions the set of all strings, @{text "UNIV"}, into a set of disjoint |
|
108 | 430 |
equivalence classes. To illustrate this quotient construction, let us give a simple |
101 | 431 |
example: consider the regular language containing just |
92 | 432 |
the string @{text "[c]"}. The relation @{term "\<approx>({[c]})"} partitions @{text UNIV} |
101 | 433 |
into three equivalence classes @{text "X\<^isub>1"}, @{text "X\<^isub>2"} and @{text "X\<^isub>3"} |
90 | 434 |
as follows |
435 |
||
436 |
\begin{center} |
|
437 |
@{text "X\<^isub>1 = {[]}"}\hspace{5mm} |
|
438 |
@{text "X\<^isub>2 = {[c]}"}\hspace{5mm} |
|
439 |
@{text "X\<^isub>3 = UNIV - {[], [c]}"} |
|
440 |
\end{center} |
|
441 |
||
442 |
One direction of the Myhill-Nerode theorem establishes |
|
93 | 443 |
that if there are finitely many equivalence classes, like in the example above, then |
444 |
the language is regular. In our setting we therefore have to show: |
|
75 | 445 |
|
167 | 446 |
\begin{thrm}\label{myhillnerodeone} |
96 | 447 |
@{thm[mode=IfThen] Myhill_Nerode1} |
167 | 448 |
\end{thrm} |
71 | 449 |
|
75 | 450 |
\noindent |
90 | 451 |
To prove this theorem, we first define the set @{term "finals A"} as those equivalence |
100 | 452 |
classes from @{term "UNIV // \<approx>A"} that contain strings of @{text A}, namely |
75 | 453 |
% |
71 | 454 |
\begin{equation} |
70 | 455 |
@{thm finals_def} |
71 | 456 |
\end{equation} |
457 |
||
458 |
\noindent |
|
132 | 459 |
In our running example, @{text "X\<^isub>2"} is the only |
460 |
equivalence class in @{term "finals {[c]}"}. |
|
90 | 461 |
It is straightforward to show that in general @{thm lang_is_union_of_finals} and |
79 | 462 |
@{thm finals_in_partitions} hold. |
75 | 463 |
Therefore if we know that there exists a regular expression for every |
100 | 464 |
equivalence class in \mbox{@{term "finals A"}} (which by assumption must be |
93 | 465 |
a finite set), then we can use @{text "\<bigplus>"} to obtain a regular expression |
98 | 466 |
that matches every string in @{text A}. |
70 | 467 |
|
75 | 468 |
|
90 | 469 |
Our proof of Thm.~\ref{myhillnerodeone} relies on a method that can calculate a |
79 | 470 |
regular expression for \emph{every} equivalence class, not just the ones |
77 | 471 |
in @{term "finals A"}. We |
93 | 472 |
first define the notion of \emph{one-character-transition} between |
473 |
two equivalence classes |
|
75 | 474 |
% |
71 | 475 |
\begin{equation} |
476 |
@{thm transition_def} |
|
477 |
\end{equation} |
|
70 | 478 |
|
71 | 479 |
\noindent |
92 | 480 |
which means that if we concatenate the character @{text c} to the end of all |
481 |
strings in the equivalence class @{text Y}, we obtain a subset of |
|
77 | 482 |
@{text X}. Note that we do not define an automaton here, we merely relate two sets |
110 | 483 |
(with the help of a character). In our concrete example we have |
92 | 484 |
@{term "X\<^isub>1 \<Turnstile>c\<Rightarrow> X\<^isub>2"}, @{term "X\<^isub>1 \<Turnstile>d\<Rightarrow> X\<^isub>3"} with @{text d} being any |
93 | 485 |
other character than @{text c}, and @{term "X\<^isub>3 \<Turnstile>d\<Rightarrow> X\<^isub>3"} for any @{text d}. |
75 | 486 |
|
156 | 487 |
Next we construct an \emph{initial equational system} that |
488 |
contains an equation for each equivalence class. We first give |
|
489 |
an informal description of this construction. Suppose we have |
|
75 | 490 |
the equivalence classes @{text "X\<^isub>1,\<dots>,X\<^isub>n"}, there must be one and only one that |
491 |
contains the empty string @{text "[]"} (since equivalence classes are disjoint). |
|
77 | 492 |
Let us assume @{text "[] \<in> X\<^isub>1"}. We build the following equational system |
75 | 493 |
|
494 |
\begin{center} |
|
495 |
\begin{tabular}{rcl} |
|
496 |
@{text "X\<^isub>1"} & @{text "="} & @{text "(Y\<^isub>1\<^isub>1, CHAR c\<^isub>1\<^isub>1) + \<dots> + (Y\<^isub>1\<^isub>p, CHAR c\<^isub>1\<^isub>p) + \<lambda>(EMPTY)"} \\ |
|
497 |
@{text "X\<^isub>2"} & @{text "="} & @{text "(Y\<^isub>2\<^isub>1, CHAR c\<^isub>2\<^isub>1) + \<dots> + (Y\<^isub>2\<^isub>o, CHAR c\<^isub>2\<^isub>o)"} \\ |
|
498 |
& $\vdots$ \\ |
|
499 |
@{text "X\<^isub>n"} & @{text "="} & @{text "(Y\<^isub>n\<^isub>1, CHAR c\<^isub>n\<^isub>1) + \<dots> + (Y\<^isub>n\<^isub>q, CHAR c\<^isub>n\<^isub>q)"}\\ |
|
500 |
\end{tabular} |
|
501 |
\end{center} |
|
70 | 502 |
|
75 | 503 |
\noindent |
100 | 504 |
where the terms @{text "(Y\<^isub>i\<^isub>j, CHAR c\<^isub>i\<^isub>j)"} |
505 |
stand for all transitions @{term "Y\<^isub>i\<^isub>j \<Turnstile>c\<^isub>i\<^isub>j\<Rightarrow> |
|
159 | 506 |
X\<^isub>i"}. |
507 |
%The intuition behind the equational system is that every |
|
508 |
%equation @{text "X\<^isub>i = rhs\<^isub>i"} in this system |
|
509 |
%corresponds roughly to a state of an automaton whose name is @{text X\<^isub>i} and its predecessor states |
|
510 |
%are the @{text "Y\<^isub>i\<^isub>j"}; the @{text "c\<^isub>i\<^isub>j"} are the labels of the transitions from these |
|
511 |
%predecessor states to @{text X\<^isub>i}. |
|
512 |
There can only be |
|
156 | 513 |
finitely many terms of the form @{text "(Y\<^isub>i\<^isub>j, CHAR c\<^isub>i\<^isub>j)"} in a right-hand side |
514 |
since by assumption there are only finitely many |
|
159 | 515 |
equivalence classes and only finitely many characters. |
516 |
The term @{text "\<lambda>(EMPTY)"} in the first equation acts as a marker for the initial state, that |
|
517 |
is the equivalence class |
|
100 | 518 |
containing @{text "[]"}.\footnote{Note that we mark, roughly speaking, the |
115 | 519 |
single `initial' state in the equational system, which is different from |
100 | 520 |
the method by Brzozowski \cite{Brzozowski64}, where he marks the |
115 | 521 |
`terminal' states. We are forced to set up the equational system in our |
522 |
way, because the Myhill-Nerode relation determines the `direction' of the |
|
123 | 523 |
transitions---the successor `state' of an equivalence class @{text Y} can |
524 |
be reached by adding a character to the end of @{text Y}. This is also the |
|
156 | 525 |
reason why we have to use our reverse version of Arden's Lemma.} |
159 | 526 |
%In our initial equation system there can only be |
527 |
%finitely many terms of the form @{text "(Y\<^isub>i\<^isub>j, CHAR c\<^isub>i\<^isub>j)"} in a right-hand side |
|
528 |
%since by assumption there are only finitely many |
|
529 |
%equivalence classes and only finitely many characters. |
|
100 | 530 |
Overloading the function @{text \<calL>} for the two kinds of terms in the |
92 | 531 |
equational system, we have |
75 | 532 |
|
533 |
\begin{center} |
|
92 | 534 |
@{text "\<calL>(Y, r) \<equiv>"} % |
167 | 535 |
@{thm (rhs) L_trm.simps(2)[where X="Y" and r="r", THEN eq_reflection]}\hspace{10mm} |
536 |
@{thm L_trm.simps(1)[where r="r", THEN eq_reflection]} |
|
75 | 537 |
\end{center} |
538 |
||
539 |
\noindent |
|
100 | 540 |
and we can prove for @{text "X\<^isub>2\<^isub>.\<^isub>.\<^isub>n"} that the following equations |
75 | 541 |
% |
542 |
\begin{equation}\label{inv1} |
|
83 | 543 |
@{text "X\<^isub>i = \<calL>(Y\<^isub>i\<^isub>1, CHAR c\<^isub>i\<^isub>1) \<union> \<dots> \<union> \<calL>(Y\<^isub>i\<^isub>q, CHAR c\<^isub>i\<^isub>q)"}. |
75 | 544 |
\end{equation} |
545 |
||
546 |
\noindent |
|
547 |
hold. Similarly for @{text "X\<^isub>1"} we can show the following equation |
|
548 |
% |
|
549 |
\begin{equation}\label{inv2} |
|
159 | 550 |
@{text "X\<^isub>1 = \<calL>(Y\<^isub>1\<^isub>1, CHAR c\<^isub>1\<^isub>1) \<union> \<dots> \<union> \<calL>(Y\<^isub>1\<^isub>p, CHAR c\<^isub>1\<^isub>p) \<union> \<calL>(\<lambda>(EMPTY))"}. |
75 | 551 |
\end{equation} |
552 |
||
553 |
\noindent |
|
160 | 554 |
holds. The reason for adding the @{text \<lambda>}-marker to our initial equational system is |
103 | 555 |
to obtain this equation: it only holds with the marker, since none of |
108 | 556 |
the other terms contain the empty string. The point of the initial equational system is |
557 |
that solving it means we will be able to extract a regular expression for every equivalence class. |
|
100 | 558 |
|
101 | 559 |
Our representation for the equations in Isabelle/HOL are pairs, |
108 | 560 |
where the first component is an equivalence class (a set of strings) |
561 |
and the second component |
|
101 | 562 |
is a set of terms. Given a set of equivalence |
100 | 563 |
classes @{text CS}, our initial equational system @{term "Init CS"} is thus |
101 | 564 |
formally defined as |
104 | 565 |
% |
566 |
\begin{equation}\label{initcs} |
|
567 |
\mbox{\begin{tabular}{rcl} |
|
100 | 568 |
@{thm (lhs) Init_rhs_def} & @{text "\<equiv>"} & |
569 |
@{text "if"}~@{term "[] \<in> X"}\\ |
|
570 |
& & @{text "then"}~@{term "{Trn Y (CHAR c) | Y c. Y \<in> CS \<and> Y \<Turnstile>c\<Rightarrow> X} \<union> {Lam EMPTY}"}\\ |
|
571 |
& & @{text "else"}~@{term "{Trn Y (CHAR c)| Y c. Y \<in> CS \<and> Y \<Turnstile>c\<Rightarrow> X}"}\\ |
|
572 |
@{thm (lhs) Init_def} & @{text "\<equiv>"} & @{thm (rhs) Init_def} |
|
104 | 573 |
\end{tabular}} |
574 |
\end{equation} |
|
100 | 575 |
|
576 |
||
577 |
||
578 |
\noindent |
|
579 |
Because we use sets of terms |
|
101 | 580 |
for representing the right-hand sides of equations, we can |
100 | 581 |
prove \eqref{inv1} and \eqref{inv2} more concisely as |
93 | 582 |
% |
167 | 583 |
\begin{lmm}\label{inv} |
100 | 584 |
If @{thm (prem 1) test} then @{text "X = \<Union> \<calL> ` rhs"}. |
167 | 585 |
\end{lmm} |
77 | 586 |
|
93 | 587 |
\noindent |
92 | 588 |
Our proof of Thm.~\ref{myhillnerodeone} will proceed by transforming the |
100 | 589 |
initial equational system into one in \emph{solved form} maintaining the invariant |
108 | 590 |
in Lem.~\ref{inv}. From the solved form we will be able to read |
89 | 591 |
off the regular expressions. |
592 |
||
100 | 593 |
In order to transform an equational system into solved form, we have two |
89 | 594 |
operations: one that takes an equation of the form @{text "X = rhs"} and removes |
110 | 595 |
any recursive occurrences of @{text X} in the @{text rhs} using our variant of Arden's |
92 | 596 |
Lemma. The other operation takes an equation @{text "X = rhs"} |
89 | 597 |
and substitutes @{text X} throughout the rest of the equational system |
110 | 598 |
adjusting the remaining regular expressions appropriately. To define this adjustment |
108 | 599 |
we define the \emph{append-operation} taking a term and a regular expression as argument |
89 | 600 |
|
601 |
\begin{center} |
|
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
602 |
@{thm Append_rexp.simps(2)[where X="Y" and r="r\<^isub>1" and rexp="r\<^isub>2", THEN eq_reflection]}\hspace{10mm} |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
603 |
@{thm Append_rexp.simps(1)[where r="r\<^isub>1" and rexp="r\<^isub>2", THEN eq_reflection]} |
89 | 604 |
\end{center} |
605 |
||
92 | 606 |
\noindent |
108 | 607 |
We lift this operation to entire right-hand sides of equations, written as |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
608 |
@{thm (lhs) Append_rexp_rhs_def[where rexp="r"]}. With this we can define |
101 | 609 |
the \emph{arden-operation} for an equation of the form @{text "X = rhs"} as: |
110 | 610 |
% |
611 |
\begin{equation}\label{arden_def} |
|
612 |
\mbox{\begin{tabular}{rc@ {\hspace{2mm}}r@ {\hspace{1mm}}l} |
|
94 | 613 |
@{thm (lhs) Arden_def} & @{text "\<equiv>"}~~\mbox{} & \multicolumn{2}{@ {\hspace{-2mm}}l}{@{text "let"}}\\ |
614 |
& & @{text "rhs' ="} & @{term "rhs - {Trn X r | r. Trn X r \<in> rhs}"} \\ |
|
615 |
& & @{text "r' ="} & @{term "STAR (\<Uplus> {r. Trn X r \<in> rhs})"}\\ |
|
616 |
& & \multicolumn{2}{@ {\hspace{-2mm}}l}{@{text "in"}~~@{term "append_rhs_rexp rhs' r'"}}\\ |
|
110 | 617 |
\end{tabular}} |
618 |
\end{equation} |
|
93 | 619 |
|
620 |
\noindent |
|
101 | 621 |
In this definition, we first delete all terms of the form @{text "(X, r)"} from @{text rhs}; |
110 | 622 |
then we calculate the combined regular expressions for all @{text r} coming |
94 | 623 |
from the deleted @{text "(X, r)"}, and take the @{const STAR} of it; |
624 |
finally we append this regular expression to @{text rhs'}. It can be easily seen |
|
156 | 625 |
that this operation mimics Arden's Lemma on the level of equations. To ensure |
626 |
the non-emptiness condition of Arden's Lemma we say that a right-hand side is |
|
154 | 627 |
@{text ardenable} provided |
110 | 628 |
|
629 |
\begin{center} |
|
630 |
@{thm ardenable_def} |
|
631 |
\end{center} |
|
632 |
||
633 |
\noindent |
|
156 | 634 |
This allows us to prove a version of Arden's Lemma on the level of equations. |
110 | 635 |
|
167 | 636 |
\begin{lmm}\label{ardenable} |
113 | 637 |
Given an equation @{text "X = rhs"}. |
110 | 638 |
If @{text "X = \<Union>\<calL> ` rhs"}, |
115 | 639 |
@{thm (prem 2) Arden_keeps_eq}, and |
110 | 640 |
@{thm (prem 3) Arden_keeps_eq}, then |
135 | 641 |
@{text "X = \<Union>\<calL> ` (Arden X rhs)"}. |
167 | 642 |
\end{lmm} |
110 | 643 |
|
644 |
\noindent |
|
156 | 645 |
Our @{text ardenable} condition is slightly stronger than needed for applying Arden's Lemma, |
646 |
but we can still ensure that it holds troughout our algorithm of transforming equations |
|
647 |
into solved form. The \emph{substitution-operation} takes an equation |
|
95 | 648 |
of the form @{text "X = xrhs"} and substitutes it into the right-hand side @{text rhs}. |
94 | 649 |
|
650 |
\begin{center} |
|
95 | 651 |
\begin{tabular}{rc@ {\hspace{2mm}}r@ {\hspace{1mm}}l} |
652 |
@{thm (lhs) Subst_def} & @{text "\<equiv>"}~~\mbox{} & \multicolumn{2}{@ {\hspace{-2mm}}l}{@{text "let"}}\\ |
|
653 |
& & @{text "rhs' ="} & @{term "rhs - {Trn X r | r. Trn X r \<in> rhs}"} \\ |
|
654 |
& & @{text "r' ="} & @{term "\<Uplus> {r. Trn X r \<in> rhs}"}\\ |
|
655 |
& & \multicolumn{2}{@ {\hspace{-2mm}}l}{@{text "in"}~~@{term "rhs' \<union> append_rhs_rexp xrhs r'"}}\\ |
|
656 |
\end{tabular} |
|
94 | 657 |
\end{center} |
95 | 658 |
|
659 |
\noindent |
|
134 | 660 |
We again delete first all occurrences of @{text "(X, r)"} in @{text rhs}; we then calculate |
95 | 661 |
the regular expression corresponding to the deleted terms; finally we append this |
662 |
regular expression to @{text "xrhs"} and union it up with @{text rhs'}. When we use |
|
663 |
the substitution operation we will arrange it so that @{text "xrhs"} does not contain |
|
110 | 664 |
any occurrence of @{text X}. |
96 | 665 |
|
134 | 666 |
With these two operations in place, we can define the operation that removes one equation |
100 | 667 |
from an equational systems @{text ES}. The operation @{const Subst_all} |
96 | 668 |
substitutes an equation @{text "X = xrhs"} throughout an equational system @{text ES}; |
100 | 669 |
@{const Remove} then completely removes such an equation from @{text ES} by substituting |
110 | 670 |
it to the rest of the equational system, but first eliminating all recursive occurrences |
96 | 671 |
of @{text X} by applying @{const Arden} to @{text "xrhs"}. |
672 |
||
673 |
\begin{center} |
|
674 |
\begin{tabular}{rcl} |
|
675 |
@{thm (lhs) Subst_all_def} & @{text "\<equiv>"} & @{thm (rhs) Subst_all_def}\\ |
|
676 |
@{thm (lhs) Remove_def} & @{text "\<equiv>"} & @{thm (rhs) Remove_def} |
|
677 |
\end{tabular} |
|
678 |
\end{center} |
|
100 | 679 |
|
680 |
\noindent |
|
110 | 681 |
Finally, we can define how an equational system should be solved. For this |
107 | 682 |
we will need to iterate the process of eliminating equations until only one equation |
154 | 683 |
will be left in the system. However, we do not just want to have any equation |
107 | 684 |
as being the last one, but the one involving the equivalence class for |
685 |
which we want to calculate the regular |
|
108 | 686 |
expression. Let us suppose this equivalence class is @{text X}. |
107 | 687 |
Since @{text X} is the one to be solved, in every iteration step we have to pick an |
108 | 688 |
equation to be eliminated that is different from @{text X}. In this way |
689 |
@{text X} is kept to the final step. The choice is implemented using Hilbert's choice |
|
107 | 690 |
operator, written @{text SOME} in the definition below. |
100 | 691 |
|
692 |
\begin{center} |
|
693 |
\begin{tabular}{rc@ {\hspace{4mm}}r@ {\hspace{1mm}}l} |
|
694 |
@{thm (lhs) Iter_def} & @{text "\<equiv>"}~~\mbox{} & \multicolumn{2}{@ {\hspace{-4mm}}l}{@{text "let"}}\\ |
|
695 |
& & @{text "(Y, yrhs) ="} & @{term "SOME (Y, yrhs). (Y, yrhs) \<in> ES \<and> X \<noteq> Y"} \\ |
|
696 |
& & \multicolumn{2}{@ {\hspace{-4mm}}l}{@{text "in"}~~@{term "Remove ES Y yrhs"}}\\ |
|
697 |
\end{tabular} |
|
698 |
\end{center} |
|
699 |
||
700 |
\noindent |
|
110 | 701 |
The last definition we need applies @{term Iter} over and over until a condition |
159 | 702 |
@{text Cond} is \emph{not} satisfied anymore. This condition states that there |
110 | 703 |
are more than one equation left in the equational system @{text ES}. To solve |
704 |
an equational system we use Isabelle/HOL's @{text while}-operator as follows: |
|
101 | 705 |
|
100 | 706 |
\begin{center} |
707 |
@{thm Solve_def} |
|
708 |
\end{center} |
|
709 |
||
101 | 710 |
\noindent |
103 | 711 |
We are not concerned here with the definition of this operator |
115 | 712 |
(see Berghofer and Nipkow \cite{BerghoferNipkow00}), but note that we eliminate |
103 | 713 |
in each @{const Iter}-step a single equation, and therefore |
714 |
have a well-founded termination order by taking the cardinality |
|
715 |
of the equational system @{text ES}. This enables us to prove |
|
115 | 716 |
properties about our definition of @{const Solve} when we `call' it with |
104 | 717 |
the equivalence class @{text X} and the initial equational system |
718 |
@{term "Init (UNIV // \<approx>A)"} from |
|
108 | 719 |
\eqref{initcs} using the principle: |
110 | 720 |
% |
721 |
\begin{equation}\label{whileprinciple} |
|
722 |
\mbox{\begin{tabular}{l} |
|
103 | 723 |
@{term "invariant (Init (UNIV // \<approx>A))"} \\ |
724 |
@{term "\<forall>ES. invariant ES \<and> Cond ES \<longrightarrow> invariant (Iter X ES)"}\\ |
|
725 |
@{term "\<forall>ES. invariant ES \<and> Cond ES \<longrightarrow> card (Iter X ES) < card ES"}\\ |
|
726 |
@{term "\<forall>ES. invariant ES \<and> \<not> Cond ES \<longrightarrow> P ES"}\\ |
|
727 |
\hline |
|
728 |
\multicolumn{1}{c}{@{term "P (Solve X (Init (UNIV // \<approx>A)))"}} |
|
110 | 729 |
\end{tabular}} |
730 |
\end{equation} |
|
103 | 731 |
|
732 |
\noindent |
|
104 | 733 |
This principle states that given an invariant (which we will specify below) |
734 |
we can prove a property |
|
735 |
@{text "P"} involving @{const Solve}. For this we have to discharge the following |
|
736 |
proof obligations: first the |
|
113 | 737 |
initial equational system satisfies the invariant; second the iteration |
154 | 738 |
step @{text "Iter"} preserves the invariant as long as the condition @{term Cond} holds; |
113 | 739 |
third @{text "Iter"} decreases the termination order, and fourth that |
104 | 740 |
once the condition does not hold anymore then the property @{text P} must hold. |
103 | 741 |
|
104 | 742 |
The property @{term P} in our proof will state that @{term "Solve X (Init (UNIV // \<approx>A))"} |
108 | 743 |
returns with a single equation @{text "X = xrhs"} for some @{text "xrhs"}, and |
104 | 744 |
that this equational system still satisfies the invariant. In order to get |
745 |
the proof through, the invariant is composed of the following six properties: |
|
103 | 746 |
|
747 |
\begin{center} |
|
104 | 748 |
\begin{tabular}{@ {}rcl@ {\hspace{-13mm}}l @ {}} |
749 |
@{text "invariant ES"} & @{text "\<equiv>"} & |
|
103 | 750 |
@{term "finite ES"} & @{text "(finiteness)"}\\ |
751 |
& @{text "\<and>"} & @{thm (rhs) finite_rhs_def} & @{text "(finiteness rhs)"}\\ |
|
104 | 752 |
& @{text "\<and>"} & @{text "\<forall>(X, rhs)\<in>ES. X = \<Union>\<calL> ` rhs"} & @{text "(soundness)"}\\ |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
753 |
& @{text "\<and>"} & @{thm (rhs) distinctness_def}\\ |
104 | 754 |
& & & @{text "(distinctness)"}\\ |
110 | 755 |
& @{text "\<and>"} & @{thm (rhs) ardenable_all_def} & @{text "(ardenable)"}\\ |
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
756 |
& @{text "\<and>"} & @{thm (rhs) validity_def} & @{text "(validity)"}\\ |
103 | 757 |
\end{tabular} |
758 |
\end{center} |
|
759 |
||
104 | 760 |
\noindent |
761 |
The first two ensure that the equational system is always finite (number of equations |
|
160 | 762 |
and number of terms in each equation); the third makes sure the `meaning' of the |
108 | 763 |
equations is preserved under our transformations. The other properties are a bit more |
764 |
technical, but are needed to get our proof through. Distinctness states that every |
|
154 | 765 |
equation in the system is distinct. @{text Ardenable} ensures that we can always |
156 | 766 |
apply the @{text Arden} operation. |
108 | 767 |
The last property states that every @{text rhs} can only contain equivalence classes |
768 |
for which there is an equation. Therefore @{text lhss} is just the set containing |
|
769 |
the first components of an equational system, |
|
770 |
while @{text "rhss"} collects all equivalence classes @{text X} in the terms of the |
|
123 | 771 |
form @{term "Trn X r"}. That means formally @{thm (lhs) lhss_def}~@{text "\<equiv> {X | (X, rhs) \<in> ES}"} |
110 | 772 |
and @{thm (lhs) rhss_def}~@{text "\<equiv> {X | (X, r) \<in> rhs}"}. |
108 | 773 |
|
104 | 774 |
|
110 | 775 |
It is straightforward to prove that the initial equational system satisfies the |
105 | 776 |
invariant. |
777 |
||
167 | 778 |
\begin{lmm}\label{invzero} |
104 | 779 |
@{thm[mode=IfThen] Init_ES_satisfies_invariant} |
167 | 780 |
\end{lmm} |
104 | 781 |
|
105 | 782 |
\begin{proof} |
783 |
Finiteness is given by the assumption and the way how we set up the |
|
784 |
initial equational system. Soundness is proved in Lem.~\ref{inv}. Distinctness |
|
154 | 785 |
follows from the fact that the equivalence classes are disjoint. The @{text ardenable} |
113 | 786 |
property also follows from the setup of the initial equational system, as does |
105 | 787 |
validity.\qed |
788 |
\end{proof} |
|
789 |
||
113 | 790 |
\noindent |
791 |
Next we show that @{text Iter} preserves the invariant. |
|
792 |
||
167 | 793 |
\begin{lmm}\label{iterone} |
104 | 794 |
@{thm[mode=IfThen] iteration_step_invariant[where xrhs="rhs"]} |
167 | 795 |
\end{lmm} |
104 | 796 |
|
107 | 797 |
\begin{proof} |
156 | 798 |
The argument boils down to choosing an equation @{text "Y = yrhs"} to be eliminated |
110 | 799 |
and to show that @{term "Subst_all (ES - {(Y, yrhs)}) Y (Arden Y yrhs)"} |
800 |
preserves the invariant. |
|
801 |
We prove this as follows: |
|
802 |
||
803 |
\begin{center} |
|
804 |
@{text "\<forall> ES."} @{thm (prem 1) Subst_all_satisfies_invariant} implies |
|
805 |
@{thm (concl) Subst_all_satisfies_invariant} |
|
806 |
\end{center} |
|
807 |
||
808 |
\noindent |
|
156 | 809 |
Finiteness is straightforward, as the @{const Subst} and @{const Arden} operations |
116 | 810 |
keep the equational system finite. These operations also preserve soundness |
113 | 811 |
and distinctness (we proved soundness for @{const Arden} in Lem.~\ref{ardenable}). |
154 | 812 |
The property @{text ardenable} is clearly preserved because the append-operation |
110 | 813 |
cannot make a regular expression to match the empty string. Validity is |
814 |
given because @{const Arden} removes an equivalence class from @{text yrhs} |
|
815 |
and then @{const Subst_all} removes @{text Y} from the equational system. |
|
132 | 816 |
Having proved the implication above, we can instantiate @{text "ES"} with @{text "ES - {(Y, yrhs)}"} |
110 | 817 |
which matches with our proof-obligation of @{const "Subst_all"}. Since |
132 | 818 |
\mbox{@{term "ES = ES - {(Y, yrhs)} \<union> {(Y, yrhs)}"}}, we can use the assumption |
110 | 819 |
to complete the proof.\qed |
107 | 820 |
\end{proof} |
821 |
||
113 | 822 |
\noindent |
823 |
We also need the fact that @{text Iter} decreases the termination measure. |
|
824 |
||
167 | 825 |
\begin{lmm}\label{itertwo} |
104 | 826 |
@{thm[mode=IfThen] iteration_step_measure[simplified (no_asm), where xrhs="rhs"]} |
167 | 827 |
\end{lmm} |
104 | 828 |
|
105 | 829 |
\begin{proof} |
830 |
By assumption we know that @{text "ES"} is finite and has more than one element. |
|
831 |
Therefore there must be an element @{term "(Y, yrhs) \<in> ES"} with |
|
110 | 832 |
@{term "(Y, yrhs) \<noteq> (X, rhs)"}. Using the distinctness property we can infer |
105 | 833 |
that @{term "Y \<noteq> X"}. We further know that @{text "Remove ES Y yrhs"} |
834 |
removes the equation @{text "Y = yrhs"} from the system, and therefore |
|
835 |
the cardinality of @{const Iter} strictly decreases.\qed |
|
836 |
\end{proof} |
|
837 |
||
113 | 838 |
\noindent |
134 | 839 |
This brings us to our property we want to establish for @{text Solve}. |
113 | 840 |
|
841 |
||
167 | 842 |
\begin{lmm} |
104 | 843 |
If @{thm (prem 1) Solve} and @{thm (prem 2) Solve} then there exists |
844 |
a @{text rhs} such that @{term "Solve X (Init (UNIV // \<approx>A)) = {(X, rhs)}"} |
|
845 |
and @{term "invariant {(X, rhs)}"}. |
|
167 | 846 |
\end{lmm} |
104 | 847 |
|
107 | 848 |
\begin{proof} |
110 | 849 |
In order to prove this lemma using \eqref{whileprinciple}, we have to use a slightly |
850 |
stronger invariant since Lem.~\ref{iterone} and \ref{itertwo} have the precondition |
|
851 |
that @{term "(X, rhs) \<in> ES"} for some @{text rhs}. This precondition is needed |
|
852 |
in order to choose in the @{const Iter}-step an equation that is not \mbox{@{term "X = rhs"}}. |
|
113 | 853 |
Therefore our invariant cannot be just @{term "invariant ES"}, but must be |
110 | 854 |
@{term "invariant ES \<and> (\<exists>rhs. (X, rhs) \<in> ES)"}. By assumption |
855 |
@{thm (prem 2) Solve} and Lem.~\ref{invzero}, the more general invariant holds for |
|
856 |
the initial equational system. This is premise 1 of~\eqref{whileprinciple}. |
|
857 |
Premise 2 is given by Lem.~\ref{iterone} and the fact that @{const Iter} might |
|
858 |
modify the @{text rhs} in the equation @{term "X = rhs"}, but does not remove it. |
|
859 |
Premise 3 of~\eqref{whileprinciple} is by Lem.~\ref{itertwo}. Now in premise 4 |
|
860 |
we like to show that there exists a @{text rhs} such that @{term "ES = {(X, rhs)}"} |
|
861 |
and that @{text "invariant {(X, rhs)}"} holds, provided the condition @{text "Cond"} |
|
113 | 862 |
does not holds. By the stronger invariant we know there exists such a @{text "rhs"} |
110 | 863 |
with @{term "(X, rhs) \<in> ES"}. Because @{text Cond} is not true, we know the cardinality |
123 | 864 |
of @{text ES} is @{text 1}. This means @{text "ES"} must actually be the set @{text "{(X, rhs)}"}, |
110 | 865 |
for which the invariant holds. This allows us to conclude that |
113 | 866 |
@{term "Solve X (Init (UNIV // \<approx>A)) = {(X, rhs)}"} and @{term "invariant {(X, rhs)}"} hold, |
867 |
as needed.\qed |
|
107 | 868 |
\end{proof} |
869 |
||
106 | 870 |
\noindent |
871 |
With this lemma in place we can show that for every equivalence class in @{term "UNIV // \<approx>A"} |
|
872 |
there exists a regular expression. |
|
873 |
||
167 | 874 |
\begin{lmm}\label{every_eqcl_has_reg} |
105 | 875 |
@{thm[mode=IfThen] every_eqcl_has_reg} |
167 | 876 |
\end{lmm} |
105 | 877 |
|
878 |
\begin{proof} |
|
138 | 879 |
By the preceding lemma, we know that there exists a @{text "rhs"} such |
105 | 880 |
that @{term "Solve X (Init (UNIV // \<approx>A))"} returns the equation @{text "X = rhs"}, |
881 |
and that the invariant holds for this equation. That means we |
|
882 |
know @{text "X = \<Union>\<calL> ` rhs"}. We further know that |
|
109 | 883 |
this is equal to \mbox{@{text "\<Union>\<calL> ` (Arden X rhs)"}} using the properties of the |
123 | 884 |
invariant and Lem.~\ref{ardenable}. Using the validity property for the equation @{text "X = rhs"}, |
156 | 885 |
we can infer that @{term "rhss rhs \<subseteq> {X}"} and because the @{text Arden} operation |
106 | 886 |
removes that @{text X} from @{text rhs}, that @{term "rhss (Arden X rhs) = {}"}. |
113 | 887 |
This means the right-hand side @{term "Arden X rhs"} can only consist of terms of the form @{term "Lam r"}. |
154 | 888 |
So we can collect those (finitely many) regular expressions @{text rs} and have @{term "X = L (\<Uplus>rs)"}. |
106 | 889 |
With this we can conclude the proof.\qed |
105 | 890 |
\end{proof} |
891 |
||
106 | 892 |
\noindent |
893 |
Lem.~\ref{every_eqcl_has_reg} allows us to finally give a proof for the first direction |
|
894 |
of the Myhill-Nerode theorem. |
|
105 | 895 |
|
106 | 896 |
\begin{proof}[of Thm.~\ref{myhillnerodeone}] |
123 | 897 |
By Lem.~\ref{every_eqcl_has_reg} we know that there exists a regular expression for |
105 | 898 |
every equivalence class in @{term "UNIV // \<approx>A"}. Since @{text "finals A"} is |
110 | 899 |
a subset of @{term "UNIV // \<approx>A"}, we also know that for every equivalence class |
123 | 900 |
in @{term "finals A"} there exists a regular expression. Moreover by assumption |
106 | 901 |
we know that @{term "finals A"} must be finite, and therefore there must be a finite |
105 | 902 |
set of regular expressions @{text "rs"} such that |
159 | 903 |
@{term "\<Union>(finals A) = L (\<Uplus>rs)"}. |
105 | 904 |
Since the left-hand side is equal to @{text A}, we can use @{term "\<Uplus>rs"} |
107 | 905 |
as the regular expression that is needed in the theorem.\qed |
105 | 906 |
\end{proof} |
54 | 907 |
*} |
908 |
||
100 | 909 |
|
910 |
||
911 |
||
912 |
section {* Myhill-Nerode, Second Part *} |
|
39
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
913 |
|
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
914 |
text {* |
116 | 915 |
We will prove in this section the second part of the Myhill-Nerode |
160 | 916 |
theorem. It can be formulated in our setting as follows: |
39
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
917 |
|
167 | 918 |
\begin{thrm} |
135 | 919 |
Given @{text "r"} is a regular expression, then @{thm Myhill_Nerode2}. |
167 | 920 |
\end{thrm} |
39
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
921 |
|
116 | 922 |
\noindent |
923 |
The proof will be by induction on the structure of @{text r}. It turns out |
|
924 |
the base cases are straightforward. |
|
925 |
||
926 |
||
927 |
\begin{proof}[Base Cases] |
|
928 |
The cases for @{const NULL}, @{const EMPTY} and @{const CHAR} are routine, because |
|
149 | 929 |
we can easily establish that |
39
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
930 |
|
114 | 931 |
\begin{center} |
932 |
\begin{tabular}{l} |
|
933 |
@{thm quot_null_eq}\\ |
|
934 |
@{thm quot_empty_subset}\\ |
|
935 |
@{thm quot_char_subset} |
|
936 |
\end{tabular} |
|
937 |
\end{center} |
|
938 |
||
116 | 939 |
\noindent |
940 |
hold, which shows that @{term "UNIV // \<approx>(L r)"} must be finite.\qed |
|
114 | 941 |
\end{proof} |
109 | 942 |
|
116 | 943 |
\noindent |
154 | 944 |
Much more interesting, however, are the inductive cases. They seem hard to solve |
117 | 945 |
directly. The reader is invited to try. |
946 |
||
135 | 947 |
Our proof will rely on some |
138 | 948 |
\emph{tagging-functions} defined over strings. Given the inductive hypothesis, it will |
135 | 949 |
be easy to prove that the \emph{range} of these tagging-functions is finite |
119 | 950 |
(the range of a function @{text f} is defined as @{text "range f \<equiv> f ` UNIV"}). |
135 | 951 |
With this we will be able to infer that the tagging-functions, seen as relations, |
117 | 952 |
give rise to finitely many equivalence classes of @{const UNIV}. Finally we |
135 | 953 |
will show that the tagging-relations are more refined than @{term "\<approx>(L r)"}, which |
123 | 954 |
implies that @{term "UNIV // \<approx>(L r)"} must also be finite (a relation @{text "R\<^isub>1"} |
955 |
is said to \emph{refine} @{text "R\<^isub>2"} provided @{text "R\<^isub>1 \<subseteq> R\<^isub>2"}). |
|
956 |
We formally define the notion of a \emph{tagging-relation} as follows. |
|
117 | 957 |
|
167 | 958 |
\begin{dfntn}[Tagging-Relation] Given a tagging-function @{text tag}, then two strings @{text x} |
119 | 959 |
and @{text y} are \emph{tag-related} provided |
117 | 960 |
\begin{center} |
159 | 961 |
@{text "x =tag= y \<equiv> tag x = tag y"}\;. |
117 | 962 |
\end{center} |
167 | 963 |
\end{dfntn} |
117 | 964 |
|
145 | 965 |
|
123 | 966 |
In order to establish finiteness of a set @{text A}, we shall use the following powerful |
118 | 967 |
principle from Isabelle/HOL's library. |
968 |
% |
|
969 |
\begin{equation}\label{finiteimageD} |
|
970 |
@{thm[mode=IfThen] finite_imageD} |
|
971 |
\end{equation} |
|
972 |
||
973 |
\noindent |
|
123 | 974 |
It states that if an image of a set under an injective function @{text f} (injective over this set) |
131 | 975 |
is finite, then the set @{text A} itself must be finite. We can use it to establish the following |
118 | 976 |
two lemmas. |
977 |
||
167 | 978 |
\begin{lmm}\label{finone} |
117 | 979 |
@{thm[mode=IfThen] finite_eq_tag_rel} |
167 | 980 |
\end{lmm} |
117 | 981 |
|
982 |
\begin{proof} |
|
119 | 983 |
We set in \eqref{finiteimageD}, @{text f} to be @{text "X \<mapsto> tag ` X"}. We have |
123 | 984 |
@{text "range f"} to be a subset of @{term "Pow (range tag)"}, which we know must be |
119 | 985 |
finite by assumption. Now @{term "f (UNIV // =tag=)"} is a subset of @{text "range f"}, |
986 |
and so also finite. Injectivity amounts to showing that @{text "X = Y"} under the |
|
987 |
assumptions that @{text "X, Y \<in> "}~@{term "UNIV // =tag="} and @{text "f X = f Y"}. |
|
149 | 988 |
From the assumptions we can obtain @{text "x \<in> X"} and @{text "y \<in> Y"} with |
123 | 989 |
@{text "tag x = tag y"}. Since @{text x} and @{text y} are tag-related, this in |
990 |
turn means that the equivalence classes @{text X} |
|
119 | 991 |
and @{text Y} must be equal.\qed |
117 | 992 |
\end{proof} |
993 |
||
167 | 994 |
\begin{lmm}\label{fintwo} |
123 | 995 |
Given two equivalence relations @{text "R\<^isub>1"} and @{text "R\<^isub>2"}, whereby |
118 | 996 |
@{text "R\<^isub>1"} refines @{text "R\<^isub>2"}. |
997 |
If @{thm (prem 1) refined_partition_finite[where ?R1.0="R\<^isub>1" and ?R2.0="R\<^isub>2"]} |
|
998 |
then @{thm (concl) refined_partition_finite[where ?R1.0="R\<^isub>1" and ?R2.0="R\<^isub>2"]}. |
|
167 | 999 |
\end{lmm} |
117 | 1000 |
|
1001 |
\begin{proof} |
|
123 | 1002 |
We prove this lemma again using \eqref{finiteimageD}. This time we set @{text f} to |
118 | 1003 |
be @{text "X \<mapsto>"}~@{term "{R\<^isub>1 `` {x} | x. x \<in> X}"}. It is easy to see that |
135 | 1004 |
@{term "finite (f ` (UNIV // R\<^isub>2))"} because it is a subset of @{term "Pow (UNIV // R\<^isub>1)"}, |
118 | 1005 |
which is finite by assumption. What remains to be shown is that @{text f} is injective |
1006 |
on @{term "UNIV // R\<^isub>2"}. This is equivalent to showing that two equivalence |
|
1007 |
classes, say @{text "X"} and @{text Y}, in @{term "UNIV // R\<^isub>2"} are equal, provided |
|
1008 |
@{text "f X = f Y"}. For @{text "X = Y"} to be equal, we have to find two elements |
|
1009 |
@{text "x \<in> X"} and @{text "y \<in> Y"} such that they are @{text R\<^isub>2} related. |
|
135 | 1010 |
We know there exists a @{text "x \<in> X"} with \mbox{@{term "X = R\<^isub>2 `` {x}"}}. |
1011 |
From the latter fact we can infer that @{term "R\<^isub>1 ``{x} \<in> f X"} |
|
123 | 1012 |
and further @{term "R\<^isub>1 ``{x} \<in> f Y"}. This means we can obtain a @{text y} |
1013 |
such that @{term "R\<^isub>1 `` {x} = R\<^isub>1 `` {y}"} holds. Consequently @{text x} and @{text y} |
|
118 | 1014 |
are @{text "R\<^isub>1"}-related. Since by assumption @{text "R\<^isub>1"} refines @{text "R\<^isub>2"}, |
1015 |
they must also be @{text "R\<^isub>2"}-related, as we need to show.\qed |
|
117 | 1016 |
\end{proof} |
1017 |
||
1018 |
\noindent |
|
119 | 1019 |
Chaining Lem.~\ref{finone} and \ref{fintwo} together, means in order to show |
135 | 1020 |
that @{term "UNIV // \<approx>(L r)"} is finite, we have to find a tagging-function whose |
119 | 1021 |
range can be shown to be finite and whose tagging-relation refines @{term "\<approx>(L r)"}. |
123 | 1022 |
Let us attempt the @{const ALT}-case first. |
119 | 1023 |
|
1024 |
\begin{proof}[@{const "ALT"}-Case] |
|
135 | 1025 |
We take as tagging-function |
132 | 1026 |
% |
119 | 1027 |
\begin{center} |
1028 |
@{thm tag_str_ALT_def[where A="A" and B="B", THEN meta_eq_app]} |
|
1029 |
\end{center} |
|
117 | 1030 |
|
119 | 1031 |
\noindent |
1032 |
where @{text "A"} and @{text "B"} are some arbitrary languages. |
|
1033 |
We can show in general, if @{term "finite (UNIV // \<approx>A)"} and @{term "finite (UNIV // \<approx>B)"} |
|
1034 |
then @{term "finite ((UNIV // \<approx>A) \<times> (UNIV // \<approx>B))"} holds. The range of |
|
127 | 1035 |
@{term "tag_str_ALT A B"} is a subset of this product set---so finite. It remains to be shown |
120 | 1036 |
that @{text "=tag\<^isub>A\<^isub>L\<^isub>T A B="} refines @{term "\<approx>(A \<union> B)"}. This amounts to |
1037 |
showing |
|
1038 |
% |
|
1039 |
\begin{center} |
|
1040 |
@{term "tag\<^isub>A\<^isub>L\<^isub>T A B x = tag\<^isub>A\<^isub>L\<^isub>T A B y \<longrightarrow> x \<approx>(A \<union> B) y"} |
|
1041 |
\end{center} |
|
132 | 1042 |
% |
120 | 1043 |
\noindent |
1044 |
which by unfolding the Myhill-Nerode relation is identical to |
|
1045 |
% |
|
1046 |
\begin{equation}\label{pattern} |
|
1047 |
@{text "\<forall>z. tag\<^isub>A\<^isub>L\<^isub>T A B x = tag\<^isub>A\<^isub>L\<^isub>T A B y \<and> x @ z \<in> A \<union> B \<longrightarrow> y @ z \<in> A \<union> B"} |
|
1048 |
\end{equation} |
|
132 | 1049 |
% |
120 | 1050 |
\noindent |
1051 |
since both @{text "=tag\<^isub>A\<^isub>L\<^isub>T A B="} and @{term "\<approx>(A \<union> B)"} are symmetric. To solve |
|
142
f1fea2c2713f
changed one occurence of tagging function into tagging relation
urbanc
parents:
138
diff
changeset
|
1052 |
\eqref{pattern} we just have to unfold the definition of the tagging-function and analyse |
123 | 1053 |
in which set, @{text A} or @{text B}, the string @{term "x @ z"} is. |
1054 |
The definition of the tagging-function will give us in each case the |
|
1055 |
information to infer that @{text "y @ z \<in> A \<union> B"}. |
|
1056 |
Finally we |
|
120 | 1057 |
can discharge this case by setting @{text A} to @{term "L r\<^isub>1"} and @{text B} to @{term "L r\<^isub>2"}.\qed |
119 | 1058 |
\end{proof} |
1059 |
||
109 | 1060 |
|
121
1cf12a107b03
added directory with the small files and numbers of lines
urbanc
parents:
120
diff
changeset
|
1061 |
\noindent |
1cf12a107b03
added directory with the small files and numbers of lines
urbanc
parents:
120
diff
changeset
|
1062 |
The pattern in \eqref{pattern} is repeated for the other two cases. Unfortunately, |
123 | 1063 |
they are slightly more complicated. In the @{const SEQ}-case we essentially have |
1064 |
to be able to infer that |
|
132 | 1065 |
% |
123 | 1066 |
\begin{center} |
167 | 1067 |
@{text "\<dots>"}@{term "x @ z \<in> A \<cdot> B \<longrightarrow> y @ z \<in> A \<cdot> B"} |
123 | 1068 |
\end{center} |
132 | 1069 |
% |
123 | 1070 |
\noindent |
135 | 1071 |
using the information given by the appropriate tagging-function. The complication |
167 | 1072 |
is to find out what the possible splits of @{text "x @ z"} are to be in @{term "A \<cdot> B"} |
135 | 1073 |
(this was easy in case of @{term "A \<union> B"}). To deal with this complication we define the |
124
8233510cab6c
added definition of string prefix and string subtraction
urbanc
parents:
123
diff
changeset
|
1074 |
notions of \emph{string prefixes} |
132 | 1075 |
% |
124
8233510cab6c
added definition of string prefix and string subtraction
urbanc
parents:
123
diff
changeset
|
1076 |
\begin{center} |
8233510cab6c
added definition of string prefix and string subtraction
urbanc
parents:
123
diff
changeset
|
1077 |
@{text "x \<le> y \<equiv> \<exists>z. y = x @ z"}\hspace{10mm} |
8233510cab6c
added definition of string prefix and string subtraction
urbanc
parents:
123
diff
changeset
|
1078 |
@{text "x < y \<equiv> x \<le> y \<and> x \<noteq> y"} |
8233510cab6c
added definition of string prefix and string subtraction
urbanc
parents:
123
diff
changeset
|
1079 |
\end{center} |
132 | 1080 |
% |
124
8233510cab6c
added definition of string prefix and string subtraction
urbanc
parents:
123
diff
changeset
|
1081 |
\noindent |
8233510cab6c
added definition of string prefix and string subtraction
urbanc
parents:
123
diff
changeset
|
1082 |
and \emph{string subtraction}: |
132 | 1083 |
% |
124
8233510cab6c
added definition of string prefix and string subtraction
urbanc
parents:
123
diff
changeset
|
1084 |
\begin{center} |
159 | 1085 |
@{text "[] - y \<equiv> []"}\hspace{10mm} |
1086 |
@{text "x - [] \<equiv> x"}\hspace{10mm} |
|
1087 |
@{text "cx - dy \<equiv> if c = d then x - y else cx"} |
|
124
8233510cab6c
added definition of string prefix and string subtraction
urbanc
parents:
123
diff
changeset
|
1088 |
\end{center} |
132 | 1089 |
% |
124
8233510cab6c
added definition of string prefix and string subtraction
urbanc
parents:
123
diff
changeset
|
1090 |
\noindent |
142
f1fea2c2713f
changed one occurence of tagging function into tagging relation
urbanc
parents:
138
diff
changeset
|
1091 |
where @{text c} and @{text d} are characters, and @{text x} and @{text y} are strings. |
132 | 1092 |
|
167 | 1093 |
Now assuming @{term "x @ z \<in> A \<cdot> B"} there are only two possible ways of how to `split' |
1094 |
this string to be in @{term "A \<cdot> B"}: |
|
132 | 1095 |
% |
125 | 1096 |
\begin{center} |
159 | 1097 |
\begin{tabular}{@ {}c@ {\hspace{10mm}}c@ {}} |
125 | 1098 |
\scalebox{0.7}{ |
1099 |
\begin{tikzpicture} |
|
159 | 1100 |
\node[draw,minimum height=3.8ex] (xa) { $\hspace{3em}@{text "x'"}\hspace{3em}$ }; |
1101 |
\node[draw,minimum height=3.8ex, right=-0.03em of xa] (xxa) { $\hspace{0.2em}@{text "x - x'"}\hspace{0.2em}$ }; |
|
1102 |
\node[draw,minimum height=3.8ex, right=-0.03em of xxa] (z) { $\hspace{5em}@{text z}\hspace{5em}$ }; |
|
125 | 1103 |
|
1104 |
\draw[decoration={brace,transform={yscale=3}},decorate] |
|
1105 |
(xa.north west) -- ($(xxa.north east)+(0em,0em)$) |
|
128 | 1106 |
node[midway, above=0.5em]{@{text x}}; |
125 | 1107 |
|
1108 |
\draw[decoration={brace,transform={yscale=3}},decorate] |
|
1109 |
(z.north west) -- ($(z.north east)+(0em,0em)$) |
|
128 | 1110 |
node[midway, above=0.5em]{@{text z}}; |
125 | 1111 |
|
1112 |
\draw[decoration={brace,transform={yscale=3}},decorate] |
|
1113 |
($(xa.north west)+(0em,3ex)$) -- ($(z.north east)+(0em,3ex)$) |
|
167 | 1114 |
node[midway, above=0.8em]{@{term "x @ z \<in> A \<cdot> B"}}; |
125 | 1115 |
|
1116 |
\draw[decoration={brace,transform={yscale=3}},decorate] |
|
1117 |
($(z.south east)+(0em,0ex)$) -- ($(xxa.south west)+(0em,0ex)$) |
|
1118 |
node[midway, below=0.5em]{@{term "(x - x') @ z \<in> B"}}; |
|
1119 |
||
1120 |
\draw[decoration={brace,transform={yscale=3}},decorate] |
|
1121 |
($(xa.south east)+(0em,0ex)$) -- ($(xa.south west)+(0em,0ex)$) |
|
1122 |
node[midway, below=0.5em]{@{term "x' \<in> A"}}; |
|
1123 |
\end{tikzpicture}} |
|
159 | 1124 |
& |
125 | 1125 |
\scalebox{0.7}{ |
1126 |
\begin{tikzpicture} |
|
159 | 1127 |
\node[draw,minimum height=3.8ex] (x) { $\hspace{4.8em}@{text x}\hspace{4.8em}$ }; |
1128 |
\node[draw,minimum height=3.8ex, right=-0.03em of x] (za) { $\hspace{0.6em}@{text "z'"}\hspace{0.6em}$ }; |
|
1129 |
\node[draw,minimum height=3.8ex, right=-0.03em of za] (zza) { $\hspace{2.6em}@{text "z - z'"}\hspace{2.6em}$ }; |
|
125 | 1130 |
|
1131 |
\draw[decoration={brace,transform={yscale=3}},decorate] |
|
1132 |
(x.north west) -- ($(za.north west)+(0em,0em)$) |
|
128 | 1133 |
node[midway, above=0.5em]{@{text x}}; |
125 | 1134 |
|
1135 |
\draw[decoration={brace,transform={yscale=3}},decorate] |
|
1136 |
($(za.north west)+(0em,0ex)$) -- ($(zza.north east)+(0em,0ex)$) |
|
128 | 1137 |
node[midway, above=0.5em]{@{text z}}; |
125 | 1138 |
|
1139 |
\draw[decoration={brace,transform={yscale=3}},decorate] |
|
1140 |
($(x.north west)+(0em,3ex)$) -- ($(zza.north east)+(0em,3ex)$) |
|
167 | 1141 |
node[midway, above=0.8em]{@{term "x @ z \<in> A \<cdot> B"}}; |
125 | 1142 |
|
1143 |
\draw[decoration={brace,transform={yscale=3}},decorate] |
|
1144 |
($(za.south east)+(0em,0ex)$) -- ($(x.south west)+(0em,0ex)$) |
|
1145 |
node[midway, below=0.5em]{@{text "x @ z' \<in> A"}}; |
|
1146 |
||
1147 |
\draw[decoration={brace,transform={yscale=3}},decorate] |
|
1148 |
($(zza.south east)+(0em,0ex)$) -- ($(za.south east)+(0em,0ex)$) |
|
1149 |
node[midway, below=0.5em]{@{text "(z - z') \<in> B"}}; |
|
1150 |
\end{tikzpicture}} |
|
159 | 1151 |
\end{tabular} |
125 | 1152 |
\end{center} |
132 | 1153 |
% |
125 | 1154 |
\noindent |
156 | 1155 |
Either there is a prefix of @{text x} in @{text A} and the rest is in @{text B} (first picture), |
1156 |
or @{text x} and a prefix of @{text "z"} is in @{text A} and the rest in @{text B} (second picture). |
|
167 | 1157 |
In both cases we have to show that @{term "y @ z \<in> A \<cdot> B"}. For this we use the |
125 | 1158 |
following tagging-function |
132 | 1159 |
% |
121
1cf12a107b03
added directory with the small files and numbers of lines
urbanc
parents:
120
diff
changeset
|
1160 |
\begin{center} |
1cf12a107b03
added directory with the small files and numbers of lines
urbanc
parents:
120
diff
changeset
|
1161 |
@{thm tag_str_SEQ_def[where ?L1.0="A" and ?L2.0="B", THEN meta_eq_app]} |
1cf12a107b03
added directory with the small files and numbers of lines
urbanc
parents:
120
diff
changeset
|
1162 |
\end{center} |
125 | 1163 |
|
1164 |
\noindent |
|
132 | 1165 |
with the idea that in the first split we have to make sure that @{text "(x - x') @ z"} |
127 | 1166 |
is in the language @{text B}. |
125 | 1167 |
|
1168 |
\begin{proof}[@{const SEQ}-Case] |
|
127 | 1169 |
If @{term "finite (UNIV // \<approx>A)"} and @{term "finite (UNIV // \<approx>B)"} |
1170 |
then @{term "finite ((UNIV // \<approx>A) \<times> (Pow (UNIV // \<approx>B)))"} holds. The range of |
|
1171 |
@{term "tag_str_SEQ A B"} is a subset of this product set, and therefore finite. |
|
130 | 1172 |
We have to show injectivity of this tagging-function as |
132 | 1173 |
% |
127 | 1174 |
\begin{center} |
167 | 1175 |
@{term "\<forall>z. tag_str_SEQ A B x = tag_str_SEQ A B y \<and> x @ z \<in> A \<cdot> B \<longrightarrow> y @ z \<in> A \<cdot> B"} |
127 | 1176 |
\end{center} |
132 | 1177 |
% |
127 | 1178 |
\noindent |
128 | 1179 |
There are two cases to be considered (see pictures above). First, there exists |
1180 |
a @{text "x'"} such that |
|
127 | 1181 |
@{text "x' \<in> A"}, @{text "x' \<le> x"} and @{text "(x - x') @ z \<in> B"} hold. We therefore have |
132 | 1182 |
% |
127 | 1183 |
\begin{center} |
1184 |
@{term "(\<approx>B `` {x - x'}) \<in> ({\<approx>B `` {x - x'} |x'. x' \<le> x \<and> x' \<in> A})"} |
|
1185 |
\end{center} |
|
132 | 1186 |
% |
127 | 1187 |
\noindent |
1188 |
and by the assumption about @{term "tag_str_SEQ A B"} also |
|
132 | 1189 |
% |
127 | 1190 |
\begin{center} |
1191 |
@{term "(\<approx>B `` {x - x'}) \<in> ({\<approx>B `` {y - y'} |y'. y' \<le> y \<and> y' \<in> A})"} |
|
1192 |
\end{center} |
|
132 | 1193 |
% |
127 | 1194 |
\noindent |
1195 |
That means there must be a @{text "y'"} such that @{text "y' \<in> A"} and |
|
1196 |
@{term "\<approx>B `` {x - x'} = \<approx>B `` {y - y'}"}. This equality means that |
|
1197 |
@{term "(x - x') \<approx>B (y - y')"} holds. Unfolding the Myhill-Nerode |
|
1198 |
relation and together with the fact that @{text "(x - x') @ z \<in> B"}, we |
|
1199 |
have @{text "(y - y') @ z \<in> B"}. We already know @{text "y' \<in> A"}, therefore |
|
167 | 1200 |
@{term "y @ z \<in> A \<cdot> B"}, as needed in this case. |
127 | 1201 |
|
1202 |
Second, there exists a @{text "z'"} such that @{term "x @ z' \<in> A"} and @{text "z - z' \<in> B"}. |
|
1203 |
By the assumption about @{term "tag_str_SEQ A B"} we have |
|
1204 |
@{term "\<approx>A `` {x} = \<approx>A `` {y}"} and thus @{term "x \<approx>A y"}. Which means by the Myhill-Nerode |
|
134 | 1205 |
relation that @{term "y @ z' \<in> A"} holds. Using @{text "z - z' \<in> B"}, we can conclude also in this case |
167 | 1206 |
with @{term "y @ z \<in> A \<cdot> B"}. We again can complete the @{const SEQ}-case |
129 | 1207 |
by setting @{text A} to @{term "L r\<^isub>1"} and @{text B} to @{term "L r\<^isub>2"}.\qed |
121
1cf12a107b03
added directory with the small files and numbers of lines
urbanc
parents:
120
diff
changeset
|
1208 |
\end{proof} |
128 | 1209 |
|
1210 |
\noindent |
|
135 | 1211 |
The case for @{const STAR} is similar to @{const SEQ}, but poses a few extra challenges. When |
137 | 1212 |
we analyse the case that @{text "x @ z"} is an element in @{term "A\<star>"} and @{text x} is not the |
130 | 1213 |
empty string, we |
128 | 1214 |
have the following picture: |
132 | 1215 |
% |
128 | 1216 |
\begin{center} |
1217 |
\scalebox{0.7}{ |
|
1218 |
\begin{tikzpicture} |
|
1219 |
\node[draw,minimum height=3.8ex] (xa) { $\hspace{4em}@{text "x'\<^isub>m\<^isub>a\<^isub>x"}\hspace{4em}$ }; |
|
1220 |
\node[draw,minimum height=3.8ex, right=-0.03em of xa] (xxa) { $\hspace{0.5em}@{text "x - x'\<^isub>m\<^isub>a\<^isub>x"}\hspace{0.5em}$ }; |
|
1221 |
\node[draw,minimum height=3.8ex, right=-0.03em of xxa] (za) { $\hspace{2em}@{text "z\<^isub>a"}\hspace{2em}$ }; |
|
1222 |
\node[draw,minimum height=3.8ex, right=-0.03em of za] (zb) { $\hspace{7em}@{text "z\<^isub>b"}\hspace{7em}$ }; |
|
1223 |
||
1224 |
\draw[decoration={brace,transform={yscale=3}},decorate] |
|
1225 |
(xa.north west) -- ($(xxa.north east)+(0em,0em)$) |
|
1226 |
node[midway, above=0.5em]{@{text x}}; |
|
1227 |
||
1228 |
\draw[decoration={brace,transform={yscale=3}},decorate] |
|
1229 |
(za.north west) -- ($(zb.north east)+(0em,0em)$) |
|
1230 |
node[midway, above=0.5em]{@{text z}}; |
|
1231 |
||
1232 |
\draw[decoration={brace,transform={yscale=3}},decorate] |
|
1233 |
($(xa.north west)+(0em,3ex)$) -- ($(zb.north east)+(0em,3ex)$) |
|
1234 |
node[midway, above=0.8em]{@{term "x @ z \<in> A\<star>"}}; |
|
1235 |
||
1236 |
\draw[decoration={brace,transform={yscale=3}},decorate] |
|
1237 |
($(za.south east)+(0em,0ex)$) -- ($(xxa.south west)+(0em,0ex)$) |
|
1238 |
node[midway, below=0.5em]{@{text "(x - x'\<^isub>m\<^isub>a\<^isub>x) @ z\<^isub>a \<in> A"}}; |
|
1239 |
||
1240 |
\draw[decoration={brace,transform={yscale=3}},decorate] |
|
1241 |
($(xa.south east)+(0em,0ex)$) -- ($(xa.south west)+(0em,0ex)$) |
|
136 | 1242 |
node[midway, below=0.5em]{@{term "x'\<^isub>m\<^isub>a\<^isub>x \<in> A\<star>"}}; |
128 | 1243 |
|
1244 |
\draw[decoration={brace,transform={yscale=3}},decorate] |
|
1245 |
($(zb.south east)+(0em,0ex)$) -- ($(zb.south west)+(0em,0ex)$) |
|
136 | 1246 |
node[midway, below=0.5em]{@{term "z\<^isub>b \<in> A\<star>"}}; |
128 | 1247 |
|
1248 |
\draw[decoration={brace,transform={yscale=3}},decorate] |
|
1249 |
($(zb.south east)+(0em,-4ex)$) -- ($(xxa.south west)+(0em,-4ex)$) |
|
136 | 1250 |
node[midway, below=0.5em]{@{term "(x - x'\<^isub>m\<^isub>a\<^isub>x) @ z \<in> A\<star>"}}; |
128 | 1251 |
\end{tikzpicture}} |
1252 |
\end{center} |
|
132 | 1253 |
% |
128 | 1254 |
\noindent |
135 | 1255 |
We can find a strict prefix @{text "x'"} of @{text x} such that @{term "x' \<in> A\<star>"}, |
1256 |
@{text "x' < x"} and the rest @{term "(x - x') @ z \<in> A\<star>"}. For example the empty string |
|
128 | 1257 |
@{text "[]"} would do. |
135 | 1258 |
There are potentially many such prefixes, but there can only be finitely many of them (the |
128 | 1259 |
string @{text x} is finite). Let us therefore choose the longest one and call it |
1260 |
@{text "x'\<^isub>m\<^isub>a\<^isub>x"}. Now for the rest of the string @{text "(x - x'\<^isub>m\<^isub>a\<^isub>x) @ z"} we |
|
135 | 1261 |
know it is in @{term "A\<star>"}. By definition of @{term "A\<star>"}, we can separate |
1262 |
this string into two parts, say @{text "a"} and @{text "b"}, such that @{text "a \<in> A"} |
|
1263 |
and @{term "b \<in> A\<star>"}. Now @{text a} must be strictly longer than @{text "x - x'\<^isub>m\<^isub>a\<^isub>x"}, |
|
128 | 1264 |
otherwise @{text "x'\<^isub>m\<^isub>a\<^isub>x"} is not the longest prefix. That means @{text a} |
1265 |
`overlaps' with @{text z}, splitting it into two components @{text "z\<^isub>a"} and |
|
1266 |
@{text "z\<^isub>b"}. For this we know that @{text "(x - x'\<^isub>m\<^isub>a\<^isub>x) @ z\<^isub>a \<in> A"} and |
|
135 | 1267 |
@{term "z\<^isub>b \<in> A\<star>"}. To cut a story short, we have divided @{term "x @ z \<in> A\<star>"} |
128 | 1268 |
such that we have a string @{text a} with @{text "a \<in> A"} that lies just on the |
145 | 1269 |
`border' of @{text x} and @{text z}. This string is @{text "(x - x'\<^isub>m\<^isub>a\<^isub>x) @ z\<^isub>a"}. |
128 | 1270 |
|
135 | 1271 |
In order to show that @{term "x @ z \<in> A\<star>"} implies @{term "y @ z \<in> A\<star>"}, we use |
128 | 1272 |
the following tagging-function: |
132 | 1273 |
% |
121
1cf12a107b03
added directory with the small files and numbers of lines
urbanc
parents:
120
diff
changeset
|
1274 |
\begin{center} |
132 | 1275 |
@{thm tag_str_STAR_def[where ?L1.0="A", THEN meta_eq_app]}\smallskip |
121
1cf12a107b03
added directory with the small files and numbers of lines
urbanc
parents:
120
diff
changeset
|
1276 |
\end{center} |
128 | 1277 |
|
1278 |
\begin{proof}[@{const STAR}-Case] |
|
130 | 1279 |
If @{term "finite (UNIV // \<approx>A)"} |
1280 |
then @{term "finite (Pow (UNIV // \<approx>A))"} holds. The range of |
|
1281 |
@{term "tag_str_STAR A"} is a subset of this set, and therefore finite. |
|
1282 |
Again we have to show injectivity of this tagging-function as |
|
132 | 1283 |
% |
130 | 1284 |
\begin{center} |
1285 |
@{term "\<forall>z. tag_str_STAR A x = tag_str_STAR A y \<and> x @ z \<in> A\<star> \<longrightarrow> y @ z \<in> A\<star>"} |
|
1286 |
\end{center} |
|
132 | 1287 |
% |
130 | 1288 |
\noindent |
1289 |
We first need to consider the case that @{text x} is the empty string. |
|
1290 |
From the assumption we can infer @{text y} is the empty string and |
|
135 | 1291 |
clearly have @{term "y @ z \<in> A\<star>"}. In case @{text x} is not the empty |
134 | 1292 |
string, we can divide the string @{text "x @ z"} as shown in the picture |
135 | 1293 |
above. By the tagging-function we have |
132 | 1294 |
% |
130 | 1295 |
\begin{center} |
1296 |
@{term "\<approx>A `` {(x - x'\<^isub>m\<^isub>a\<^isub>x)} \<in> ({\<approx>A `` {x - x'} |x'. x' < x \<and> x' \<in> A\<star>})"} |
|
1297 |
\end{center} |
|
132 | 1298 |
% |
130 | 1299 |
\noindent |
1300 |
which by assumption is equal to |
|
132 | 1301 |
% |
130 | 1302 |
\begin{center} |
1303 |
@{term "\<approx>A `` {(x - x'\<^isub>m\<^isub>a\<^isub>x)} \<in> ({\<approx>A `` {y - y'} |y'. y' < y \<and> y' \<in> A\<star>})"} |
|
1304 |
\end{center} |
|
132 | 1305 |
% |
130 | 1306 |
\noindent |
135 | 1307 |
and we know that we have a @{term "y' \<in> A\<star>"} and @{text "y' < y"} |
132 | 1308 |
and also know @{term "(x - x'\<^isub>m\<^isub>a\<^isub>x) \<approx>A (y - y')"}. Unfolding the Myhill-Nerode |
135 | 1309 |
relation we know @{term "(y - y') @ z\<^isub>a \<in> A"}. We also know that @{term "z\<^isub>b \<in> A\<star>"}. |
1310 |
Therefore @{term "y' @ ((y - y') @ z\<^isub>a) @ z\<^isub>b \<in> A\<star>"}, which means |
|
1311 |
@{term "y @ z \<in> A\<star>"}. As the last step we have to set @{text "A"} to @{term "L r"} and |
|
132 | 1312 |
complete the proof.\qed |
121
1cf12a107b03
added directory with the small files and numbers of lines
urbanc
parents:
120
diff
changeset
|
1313 |
\end{proof} |
39
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
1314 |
*} |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
1315 |
|
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1316 |
section {* Second Part based on Partial Derivatives *} |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1317 |
|
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1318 |
text {* |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1319 |
We briefly considered using the method Brzozowski presented in the |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1320 |
Appendix of~\cite{Brzozowski64} in order to prove the second |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1321 |
direction of the Myhill-Nerode theorem. There he calculates the |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1322 |
derivatives for regular expressions and shows that for every |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1323 |
language there can be only finitely many of them %derivations (if |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1324 |
regarded equal modulo ACI). We could have used as tagging-function |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1325 |
the set of derivatives of a regular expression with respect to a |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1326 |
language. Using the fact that two strings are Myhill-Nerode related |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1327 |
whenever their derivative is the same, together with the fact that |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1328 |
there are only finitely such derivatives would give us a similar |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1329 |
argument as ours. However it seems not so easy to calculate the set |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1330 |
of derivatives modulo ACI. Therefore we preferred our direct method |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1331 |
of using tagging-functions. |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1332 |
|
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1333 |
*} |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1334 |
|
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1335 |
section {* Closure Properties *} |
39
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
1336 |
|
117 | 1337 |
|
54 | 1338 |
section {* Conclusion and Related Work *} |
1339 |
||
92 | 1340 |
text {* |
112 | 1341 |
In this paper we took the view that a regular language is one where there |
115 | 1342 |
exists a regular expression that matches all of its strings. Regular |
145 | 1343 |
expressions can conveniently be defined as a datatype in HOL-based theorem |
1344 |
provers. For us it was therefore interesting to find out how far we can push |
|
154 | 1345 |
this point of view. We have established in Isabelle/HOL both directions |
1346 |
of the Myhill-Nerode theorem. |
|
132 | 1347 |
% |
167 | 1348 |
\begin{thrm}[The Myhill-Nerode Theorem]\mbox{}\\ |
132 | 1349 |
A language @{text A} is regular if and only if @{thm (rhs) Myhill_Nerode}. |
167 | 1350 |
\end{thrm} |
132 | 1351 |
% |
1352 |
\noindent |
|
1353 |
Having formalised this theorem means we |
|
1354 |
pushed our point of view quite far. Using this theorem we can obviously prove when a language |
|
112 | 1355 |
is \emph{not} regular---by establishing that it has infinitely many |
1356 |
equivalence classes generated by the Myhill-Nerode relation (this is usually |
|
1357 |
the purpose of the pumping lemma \cite{Kozen97}). We can also use it to |
|
1358 |
establish the standard textbook results about closure properties of regular |
|
1359 |
languages. Interesting is the case of closure under complement, because |
|
1360 |
it seems difficult to construct a regular expression for the complement |
|
113 | 1361 |
language by direct means. However the existence of such a regular expression |
1362 |
can be easily proved using the Myhill-Nerode theorem since |
|
132 | 1363 |
% |
112 | 1364 |
\begin{center} |
1365 |
@{term "s\<^isub>1 \<approx>A s\<^isub>2"} if and only if @{term "s\<^isub>1 \<approx>(-A) s\<^isub>2"} |
|
1366 |
\end{center} |
|
132 | 1367 |
% |
112 | 1368 |
\noindent |
1369 |
holds for any strings @{text "s\<^isub>1"} and @{text |
|
114 | 1370 |
"s\<^isub>2"}. Therefore @{text A} and the complement language @{term "-A"} give rise to the same |
159 | 1371 |
partitions. Proving the existence of such a regular expression via automata |
1372 |
using the standard method would |
|
114 | 1373 |
be quite involved. It includes the |
112 | 1374 |
steps: regular expression @{text "\<Rightarrow>"} non-deterministic automaton @{text |
1375 |
"\<Rightarrow>"} deterministic automaton @{text "\<Rightarrow>"} complement automaton @{text "\<Rightarrow>"} |
|
1376 |
regular expression. |
|
1377 |
||
116 | 1378 |
While regular expressions are convenient in formalisations, they have some |
122 | 1379 |
limitations. One is that there seems to be no method of calculating a |
123 | 1380 |
minimal regular expression (for example in terms of length) for a regular |
1381 |
language, like there is |
|
1382 |
for automata. On the other hand, efficient regular expression matching, |
|
1383 |
without using automata, poses no problem \cite{OwensReppyTuron09}. |
|
1384 |
For an implementation of a simple regular expression matcher, |
|
122 | 1385 |
whose correctness has been formally established, we refer the reader to |
1386 |
Owens and Slind \cite{OwensSlind08}. |
|
116 | 1387 |
|
1388 |
||
143
1cc87efb3b53
formalisation of first direction is now only 780 loc
urbanc
parents:
142
diff
changeset
|
1389 |
Our formalisation consists of 780 lines of Isabelle/Isar code for the first |
149 | 1390 |
direction and 460 for the second, plus around 300 lines of standard material about |
122 | 1391 |
regular languages. While this might be seen as too large to count as a |
1392 |
concise proof pearl, this should be seen in the context of the work done by |
|
1393 |
Constable at al \cite{Constable00} who formalised the Myhill-Nerode theorem |
|
1394 |
in Nuprl using automata. They write that their four-member team needed |
|
134 | 1395 |
something on the magnitude of 18 months for their formalisation. The |
122 | 1396 |
estimate for our formalisation is that we needed approximately 3 months and |
1397 |
this included the time to find our proof arguments. Unlike Constable et al, |
|
1398 |
who were able to follow the proofs from \cite{HopcroftUllman69}, we had to |
|
1399 |
find our own arguments. So for us the formalisation was not the |
|
1400 |
bottleneck. It is hard to gauge the size of a formalisation in Nurpl, but |
|
1401 |
from what is shown in the Nuprl Math Library about their development it |
|
1402 |
seems substantially larger than ours. The code of ours can be found in the |
|
1403 |
Mercurial Repository at |
|
132 | 1404 |
\mbox{\url{http://www4.in.tum.de/~urbanc/regexp.html}}. |
113 | 1405 |
|
112 | 1406 |
|
1407 |
Our proof of the first direction is very much inspired by \emph{Brzozowski's |
|
134 | 1408 |
algebraic method} used to convert a finite automaton to a regular |
113 | 1409 |
expression \cite{Brzozowski64}. The close connection can be seen by considering the equivalence |
111 | 1410 |
classes as the states of the minimal automaton for the regular language. |
114 | 1411 |
However there are some subtle differences. Since we identify equivalence |
111 | 1412 |
classes with the states of the automaton, then the most natural choice is to |
1413 |
characterise each state with the set of strings starting from the initial |
|
113 | 1414 |
state leading up to that state. Usually, however, the states are characterised as the |
123 | 1415 |
strings starting from that state leading to the terminal states. The first |
1416 |
choice has consequences about how the initial equational system is set up. We have |
|
115 | 1417 |
the $\lambda$-term on our `initial state', while Brzozowski has it on the |
111 | 1418 |
terminal states. This means we also need to reverse the direction of Arden's |
156 | 1419 |
Lemma. |
92 | 1420 |
|
162
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1421 |
This is also where our method shines, because we can completely |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1422 |
side-step the standard argument \cite{Kozen97} where automata need |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1423 |
to be composed, which as stated in the Introduction is not so easy |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1424 |
to formalise in a HOL-based theorem prover. However, it is also the |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1425 |
direction where we had to spend most of the `conceptual' time, as |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1426 |
our proof-argument based on tagging-functions is new for |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1427 |
establishing the Myhill-Nerode theorem. All standard proofs of this |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1428 |
direction proceed by arguments over automata.\medskip |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1429 |
|
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1430 |
\noindent |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1431 |
{\bf Acknowledgements:} We are grateful for the comments we received from Larry |
e93760534354
added directory for journal version; took uptodate version of the theory files
urbanc
parents:
160
diff
changeset
|
1432 |
Paulson. |
111 | 1433 |
|
92 | 1434 |
*} |
1435 |
||
1436 |
||
24 | 1437 |
(*<*) |
1438 |
end |
|
1439 |
(*>*) |