author | urbanc |
Thu, 03 Feb 2011 05:38:47 +0000 | |
changeset 60 | fb08f41ca33d |
parent 59 | fc35eb54fdc9 |
child 61 | 070f543e2560 |
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 |
|
29 |
students containing very detailed ``pencil-and-paper'' proofs |
|
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 |
34 |
languages is to introduce automata and then define everything in terms of |
|
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 |
|
37 |
the language. One benefit of this approach is that it is easy to convince |
|
38 |
oneself from the fact that regular languages are closed under |
|
39 |
complementation: one just has to exchange the accepting and non-accepting |
|
40 |
states in the automaton to obtain an automaton for the complement language. |
|
41 |
||
42 |
The problem lies with formalising such reasoning in a theorem |
|
43 |
prover, in our case Isabelle/HOL. Automata need to be represented as graphs |
|
44 |
or matrices, neither of which can be defined as inductive datatype.\footnote{In |
|
45 |
some works functions are used to represent transitions, but they are also not |
|
46 |
inductive datatypes.} This means we have to build our own reasoning infrastructure |
|
47 |
for them, as neither Isabelle nor HOL4 support them with libraries. |
|
48 |
Even worse, reasoning about graphs in typed languages can be a real hassle |
|
49 |
making proofs quite clunky. Consider for example the operation of combining |
|
50 |
two automata into a new automaton by connecting their |
|
51 |
initial states to a new initial state (similarly with the accepting states):a |
|
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 |
|
60 |
new initial state, the other for the new accepting state. |
|
61 |
||
62 |
||
59 | 63 |
|
58 | 64 |
|
65 |
||
66 |
||
67 |
||
68 |
||
54 | 69 |
|
70 |
Therefore instead of defining a regular language as being one where there exists an |
|
60 | 71 |
automata that recognises all of its strings, we define |
54 | 72 |
|
73 |
\begin{definition}[A Regular Language] |
|
74 |
A language @{text A} is regular, if there is a regular expression that matches all |
|
75 |
strings of @{text "A"}. |
|
76 |
\end{definition} |
|
77 |
||
78 |
\noindent |
|
60 | 79 |
{\bf Contributions:} A proof of the Myhill-Nerode Theorem based on regular expressions. The |
54 | 80 |
finiteness part of this theorem is proved using tagging-functions (which to our knowledge |
81 |
are novel in this context). |
|
24 | 82 |
|
83 |
*} |
|
84 |
||
50 | 85 |
section {* Preliminaries *} |
86 |
||
87 |
text {* |
|
58 | 88 |
Strings in Isabelle/HOL are lists of characters and the |
89 |
\emph{empty string} is the empty list, written @{term "[]"}. \emph{Languages} are sets of |
|
90 |
strings. The language containing all strings is written in Isabelle/HOL as @{term "UNIV::string set"}. |
|
91 |
The notation for the quotient of a language @{text A} according to a relation @{term REL} is |
|
92 |
@{term "A // REL"}. The concatenation of two languages is written @{term "A ;; B"}; a language |
|
93 |
raised tow the power $n$ is written @{term "A \<up> n"}. Both concepts are defined as |
|
54 | 94 |
|
95 |
\begin{center} |
|
58 | 96 |
@{thm Seq_def[THEN eq_reflection, where A1="A" and B1="B"]} |
97 |
\hspace{7mm} |
|
98 |
@{thm pow.simps(1)[THEN eq_reflection, where A1="A"]} |
|
99 |
\hspace{7mm} |
|
100 |
@{thm pow.simps(2)[THEN eq_reflection, where A1="A" and n1="n"]} |
|
54 | 101 |
\end{center} |
102 |
||
103 |
\noindent |
|
58 | 104 |
where @{text "@"} is the usual list-append operation. The Kleene-star of a language @{text A} |
105 |
is defined as the union over all powers, namely @{thm Star_def}. |
|
106 |
||
54 | 107 |
|
108 |
Regular expressions are defined as the following datatype |
|
109 |
||
110 |
\begin{center} |
|
111 |
@{text r} @{text "::="} |
|
112 |
@{term NULL}\hspace{1.5mm}@{text"|"}\hspace{1.5mm} |
|
113 |
@{term EMPTY}\hspace{1.5mm}@{text"|"}\hspace{1.5mm} |
|
114 |
@{term "CHAR c"}\hspace{1.5mm}@{text"|"}\hspace{1.5mm} |
|
115 |
@{term "SEQ r r"}\hspace{1.5mm}@{text"|"}\hspace{1.5mm} |
|
116 |
@{term "ALT r r"}\hspace{1.5mm}@{text"|"}\hspace{1.5mm} |
|
117 |
@{term "STAR r"} |
|
118 |
\end{center} |
|
119 |
||
51 | 120 |
Central to our proof will be the solution of equational systems |
50 | 121 |
involving regular expressions. For this we will use the following ``reverse'' |
122 |
version of Arden's lemma. |
|
123 |
||
124 |
\begin{lemma}[Reverse Arden's Lemma]\mbox{}\\ |
|
125 |
If @{thm (prem 1) ardens_revised} then |
|
126 |
@{thm (lhs) ardens_revised} has the unique solution |
|
127 |
@{thm (rhs) ardens_revised}. |
|
128 |
\end{lemma} |
|
129 |
||
130 |
\begin{proof} |
|
51 | 131 |
For the right-to-left direction we assume @{thm (rhs) ardens_revised} and show |
132 |
that @{thm (lhs) ardens_revised} holds. From Lemma ??? we have @{term "A\<star> = {[]} \<union> A ;; A\<star>"}, |
|
50 | 133 |
which is equal to @{term "A\<star> = {[]} \<union> A\<star> ;; A"}. Adding @{text B} to both |
134 |
sides gives @{term "B ;; A\<star> = B ;; ({[]} \<union> A\<star> ;; A)"}, whose right-hand side |
|
51 | 135 |
is equal to @{term "(B ;; A\<star>) ;; A \<union> B"}. This completes this direction. |
50 | 136 |
|
137 |
For the other direction we assume @{thm (lhs) ardens_revised}. By a simple induction |
|
51 | 138 |
on @{text n}, we can establish the property |
50 | 139 |
|
140 |
\begin{center} |
|
141 |
@{text "(*)"}\hspace{5mm} @{thm (concl) ardens_helper} |
|
142 |
\end{center} |
|
143 |
||
144 |
\noindent |
|
145 |
Using this property we can show that @{term "B ;; (A \<up> n) \<subseteq> X"} holds for |
|
146 |
all @{text n}. From this we can infer @{term "B ;; A\<star> \<subseteq> X"} using Lemma ???. |
|
51 | 147 |
For the inclusion in the other direction we assume a string @{text s} |
50 | 148 |
with length @{text k} is element in @{text X}. Since @{thm (prem 1) ardens_revised} |
51 | 149 |
we know that @{term "s \<notin> X ;; (A \<up> Suc k)"} since its length is only @{text k} |
150 |
(the strings in @{term "X ;; (A \<up> Suc k)"} are all longer). |
|
53 | 151 |
From @{text "(*)"} it follows then that |
50 | 152 |
@{term s} must be element in @{term "(\<Union>m\<in>{0..k}. B ;; (A \<up> m))"}. This in turn |
153 |
implies that @{term s} is in @{term "(\<Union>n. B ;; (A \<up> n))"}. Using Lemma ??? this |
|
154 |
is equal to @{term "B ;; A\<star>"}, as we needed to show.\qed |
|
155 |
\end{proof} |
|
156 |
*} |
|
39
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
157 |
|
54 | 158 |
section {* Finite Partitions Imply Regularity of a Language *} |
159 |
||
160 |
text {* |
|
161 |
\begin{theorem} |
|
162 |
Given a language @{text A}. |
|
163 |
@{thm[mode=IfThen] hard_direction[where Lang="A"]} |
|
164 |
\end{theorem} |
|
165 |
*} |
|
166 |
||
167 |
section {* Regular Expressions Generate Finitely Many Partitions *} |
|
39
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
168 |
|
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
169 |
text {* |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
170 |
|
54 | 171 |
\begin{theorem} |
39
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
172 |
Given @{text "r"} is a regular expressions, then @{thm rexp_imp_finite}. |
54 | 173 |
\end{theorem} |
39
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
174 |
|
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
175 |
\begin{proof} |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
176 |
By induction on the structure of @{text r}. The cases for @{const NULL}, @{const EMPTY} |
50 | 177 |
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
|
178 |
|
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
179 |
\begin{center} |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
180 |
\begin{tabular}{l} |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
181 |
@{thm quot_null_eq}\\ |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
182 |
@{thm quot_empty_subset}\\ |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
183 |
@{thm quot_char_subset} |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
184 |
\end{tabular} |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
185 |
\end{center} |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
186 |
|
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
187 |
\end{proof} |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
188 |
*} |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
189 |
|
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
190 |
|
54 | 191 |
section {* Conclusion and Related Work *} |
192 |
||
24 | 193 |
(*<*) |
194 |
end |
|
195 |
(*>*) |