author | urbanc |
Thu, 03 Feb 2011 09:54:19 +0000 | |
changeset 61 | 070f543e2560 |
parent 60 | fb08f41ca33d |
child 66 | 828ea293b61f |
permissions | -rw-r--r-- |
24 | 1 |
(*<*) |
2 |
theory Paper |
|
39
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
3 |
imports "../Myhill" "LaTeXsugar" |
24 | 4 |
begin |
39
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
5 |
|
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
6 |
declare [[show_question_marks = false]] |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
7 |
|
54 | 8 |
consts |
9 |
REL :: "(string \<times> string) \<Rightarrow> bool" |
|
10 |
||
11 |
||
39
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
12 |
notation (latex output) |
50 | 13 |
str_eq_rel ("\<approx>\<^bsub>_\<^esub>") and |
14 |
Seq (infixr "\<cdot>" 100) and |
|
15 |
Star ("_\<^bsup>\<star>\<^esup>") and |
|
16 |
pow ("_\<^bsup>_\<^esup>" [100, 100] 100) and |
|
58 | 17 |
Suc ("_+1" [100] 100) and |
54 | 18 |
quotient ("_ \<^raw:\ensuremath{\!\sslash\!}> _" [90, 90] 90) and |
19 |
REL ("\<approx>") |
|
52
4a517c6ac07d
tuning of the syntax; needs the stmaryrd latex package
urbanc
parents:
51
diff
changeset
|
20 |
|
24 | 21 |
(*>*) |
22 |
||
23 |
section {* Introduction *} |
|
24 |
||
25 |
text {* |
|
58 | 26 |
Regular languages are an important and well-understood subject in Computer |
60 | 27 |
Science, with many beautiful theorems and many useful algorithms. There is a |
28 |
wide range of textbooks on this subject, many of which are aimed at |
|
61 | 29 |
students and contain very detailed ``pencil-and-paper'' proofs |
60 | 30 |
(e.g.~\cite{Kozen97}). It seems natural to exercise theorem provers by |
31 |
formalising these theorems and by verifying formally the algorithms. |
|
59 | 32 |
|
60 | 33 |
There is however a problem with this: the typical approach to regular |
61 | 34 |
languages is to introduce finite automata and then define everything in terms of |
60 | 35 |
them. For example, a regular language is normally defined as one where |
36 |
there is a finite deterministic automaton that recognises all the strings of |
|
61 | 37 |
the language. This approach has many benefits. One is that it is easy to convince |
60 | 38 |
oneself from the fact that regular languages are closed under |
39 |
complementation: one just has to exchange the accepting and non-accepting |
|
61 | 40 |
states in the corresponding automaton to obtain an automaton for the complement language. |
60 | 41 |
The problem lies with formalising such reasoning in a theorem |
42 |
prover, in our case Isabelle/HOL. Automata need to be represented as graphs |
|
43 |
or matrices, neither of which can be defined as inductive datatype.\footnote{In |
|
44 |
some works functions are used to represent transitions, but they are also not |
|
45 |
inductive datatypes.} This means we have to build our own reasoning infrastructure |
|
61 | 46 |
for them, as neither Isabelle nor HOL4 nor HOLlight support them with libraries. |
47 |
||
48 |
Even worse, reasoning about graphs in typed languages can be a real hassle. |
|
49 |
Consider for example the operation of combining |
|
60 | 50 |
two automata into a new automaton by connecting their |
61 | 51 |
initial states to a new initial state (similarly with the accepting states): |
60 | 52 |
|
53 |
\begin{center} |
|
54 |
picture |
|
55 |
\end{center} |
|
56 |
||
57 |
\noindent |
|
58 |
How should we implement this operation? On paper we can just |
|
59 |
form the disjoint union of the state nodes and add two more nodes---one for the |
|
61 | 60 |
new initial state, the other for the new accepting state. In a theorem |
61 |
prover based on set-theory, this operaton can be more or less |
|
62 |
straightforwardly implemented. But in a HOL-based theorem prover the |
|
63 |
standard definition of disjoint unions as pairs |
|
60 | 64 |
|
61 | 65 |
\begin{center} |
66 |
definition |
|
67 |
\end{center} |
|
60 | 68 |
|
61 | 69 |
\noindent |
70 |
changes the type (from sets of nodes to sets of pairs). This means we |
|
71 |
cannot formulate in this represeantation any property about \emph{all} |
|
72 |
automata---since there is no type quantification available in HOL-based |
|
73 |
theorem provers. A working alternative is to give every state node an |
|
74 |
identity, for example a natural number, and then be careful to rename |
|
75 |
these indentities appropriately when connecting two automata together. |
|
76 |
This results in very clunky side-proofs establishing that properties |
|
77 |
are invariant under renaming. We are only aware of the formalisation |
|
78 |
of automata theory in Nuprl that carries this approach trough and is |
|
79 |
quite substantial. |
|
58 | 80 |
|
61 | 81 |
We will take a completely different approach to formalising theorems |
82 |
about regular languages. Instead of defining a regular language as one |
|
83 |
where there exists an automaton that recognises all of its strings, we |
|
84 |
define a regular language as |
|
54 | 85 |
|
86 |
\begin{definition}[A Regular Language] |
|
87 |
A language @{text A} is regular, if there is a regular expression that matches all |
|
88 |
strings of @{text "A"}. |
|
89 |
\end{definition} |
|
90 |
||
91 |
\noindent |
|
61 | 92 |
The reason is that regular expressinons, unlike graphs and metrices, can |
93 |
be eaily defined as inductive datatype and this means a reasoning infrastructre |
|
94 |
comes for them in Isabelle for free. The purpose of this paper is to |
|
95 |
show that a central and highly non-trivisl result about regular languages, |
|
96 |
namely the Myhill-Nerode theorem, can be recreated only using regular |
|
97 |
expressions. In our approach we do not need to formalise graps or |
|
98 |
metrices. |
|
99 |
||
100 |
||
101 |
\noindent |
|
60 | 102 |
{\bf Contributions:} A proof of the Myhill-Nerode Theorem based on regular expressions. The |
54 | 103 |
finiteness part of this theorem is proved using tagging-functions (which to our knowledge |
104 |
are novel in this context). |
|
24 | 105 |
|
106 |
*} |
|
107 |
||
50 | 108 |
section {* Preliminaries *} |
109 |
||
110 |
text {* |
|
58 | 111 |
Strings in Isabelle/HOL are lists of characters and the |
112 |
\emph{empty string} is the empty list, written @{term "[]"}. \emph{Languages} are sets of |
|
113 |
strings. The language containing all strings is written in Isabelle/HOL as @{term "UNIV::string set"}. |
|
114 |
The notation for the quotient of a language @{text A} according to a relation @{term REL} is |
|
115 |
@{term "A // REL"}. The concatenation of two languages is written @{term "A ;; B"}; a language |
|
116 |
raised tow the power $n$ is written @{term "A \<up> n"}. Both concepts are defined as |
|
54 | 117 |
|
118 |
\begin{center} |
|
58 | 119 |
@{thm Seq_def[THEN eq_reflection, where A1="A" and B1="B"]} |
120 |
\hspace{7mm} |
|
121 |
@{thm pow.simps(1)[THEN eq_reflection, where A1="A"]} |
|
122 |
\hspace{7mm} |
|
123 |
@{thm pow.simps(2)[THEN eq_reflection, where A1="A" and n1="n"]} |
|
54 | 124 |
\end{center} |
125 |
||
126 |
\noindent |
|
58 | 127 |
where @{text "@"} is the usual list-append operation. The Kleene-star of a language @{text A} |
128 |
is defined as the union over all powers, namely @{thm Star_def}. |
|
129 |
||
54 | 130 |
|
131 |
Regular expressions are defined as the following datatype |
|
132 |
||
133 |
\begin{center} |
|
134 |
@{text r} @{text "::="} |
|
135 |
@{term NULL}\hspace{1.5mm}@{text"|"}\hspace{1.5mm} |
|
136 |
@{term EMPTY}\hspace{1.5mm}@{text"|"}\hspace{1.5mm} |
|
137 |
@{term "CHAR c"}\hspace{1.5mm}@{text"|"}\hspace{1.5mm} |
|
138 |
@{term "SEQ r r"}\hspace{1.5mm}@{text"|"}\hspace{1.5mm} |
|
139 |
@{term "ALT r r"}\hspace{1.5mm}@{text"|"}\hspace{1.5mm} |
|
140 |
@{term "STAR r"} |
|
141 |
\end{center} |
|
142 |
||
51 | 143 |
Central to our proof will be the solution of equational systems |
50 | 144 |
involving regular expressions. For this we will use the following ``reverse'' |
145 |
version of Arden's lemma. |
|
146 |
||
147 |
\begin{lemma}[Reverse Arden's Lemma]\mbox{}\\ |
|
148 |
If @{thm (prem 1) ardens_revised} then |
|
149 |
@{thm (lhs) ardens_revised} has the unique solution |
|
150 |
@{thm (rhs) ardens_revised}. |
|
151 |
\end{lemma} |
|
152 |
||
153 |
\begin{proof} |
|
51 | 154 |
For the right-to-left direction we assume @{thm (rhs) ardens_revised} and show |
155 |
that @{thm (lhs) ardens_revised} holds. From Lemma ??? we have @{term "A\<star> = {[]} \<union> A ;; A\<star>"}, |
|
50 | 156 |
which is equal to @{term "A\<star> = {[]} \<union> A\<star> ;; A"}. Adding @{text B} to both |
157 |
sides gives @{term "B ;; A\<star> = B ;; ({[]} \<union> A\<star> ;; A)"}, whose right-hand side |
|
51 | 158 |
is equal to @{term "(B ;; A\<star>) ;; A \<union> B"}. This completes this direction. |
50 | 159 |
|
160 |
For the other direction we assume @{thm (lhs) ardens_revised}. By a simple induction |
|
51 | 161 |
on @{text n}, we can establish the property |
50 | 162 |
|
163 |
\begin{center} |
|
164 |
@{text "(*)"}\hspace{5mm} @{thm (concl) ardens_helper} |
|
165 |
\end{center} |
|
166 |
||
167 |
\noindent |
|
168 |
Using this property we can show that @{term "B ;; (A \<up> n) \<subseteq> X"} holds for |
|
169 |
all @{text n}. From this we can infer @{term "B ;; A\<star> \<subseteq> X"} using Lemma ???. |
|
51 | 170 |
For the inclusion in the other direction we assume a string @{text s} |
50 | 171 |
with length @{text k} is element in @{text X}. Since @{thm (prem 1) ardens_revised} |
51 | 172 |
we know that @{term "s \<notin> X ;; (A \<up> Suc k)"} since its length is only @{text k} |
173 |
(the strings in @{term "X ;; (A \<up> Suc k)"} are all longer). |
|
53 | 174 |
From @{text "(*)"} it follows then that |
50 | 175 |
@{term s} must be element in @{term "(\<Union>m\<in>{0..k}. B ;; (A \<up> m))"}. This in turn |
176 |
implies that @{term s} is in @{term "(\<Union>n. B ;; (A \<up> n))"}. Using Lemma ??? this |
|
177 |
is equal to @{term "B ;; A\<star>"}, as we needed to show.\qed |
|
178 |
\end{proof} |
|
179 |
*} |
|
39
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
180 |
|
54 | 181 |
section {* Finite Partitions Imply Regularity of a Language *} |
182 |
||
183 |
text {* |
|
184 |
\begin{theorem} |
|
185 |
Given a language @{text A}. |
|
186 |
@{thm[mode=IfThen] hard_direction[where Lang="A"]} |
|
187 |
\end{theorem} |
|
188 |
*} |
|
189 |
||
190 |
section {* Regular Expressions Generate Finitely Many Partitions *} |
|
39
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
191 |
|
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
192 |
text {* |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
193 |
|
54 | 194 |
\begin{theorem} |
39
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
195 |
Given @{text "r"} is a regular expressions, then @{thm rexp_imp_finite}. |
54 | 196 |
\end{theorem} |
39
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
197 |
|
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
198 |
\begin{proof} |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
199 |
By induction on the structure of @{text r}. The cases for @{const NULL}, @{const EMPTY} |
50 | 200 |
and @{const CHAR} are straightforward, because we can easily establish |
39
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
201 |
|
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
202 |
\begin{center} |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
203 |
\begin{tabular}{l} |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
204 |
@{thm quot_null_eq}\\ |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
205 |
@{thm quot_empty_subset}\\ |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
206 |
@{thm quot_char_subset} |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
207 |
\end{tabular} |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
208 |
\end{center} |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
209 |
|
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
210 |
\end{proof} |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
211 |
*} |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
212 |
|
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
213 |
|
54 | 214 |
section {* Conclusion and Related Work *} |
215 |
||
24 | 216 |
(*<*) |
217 |
end |
|
218 |
(*>*) |