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