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