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