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