author | urbanc |
Wed, 02 Feb 2011 15:43:22 +0000 | |
changeset 59 | fc35eb54fdc9 |
parent 58 | 0d4d5bb321dc |
child 60 | fb08f41ca33d |
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 |
27 |
Science with many beautiful theorems and many useful algorithms. There is a |
|
59 | 28 |
wide range of textbooks about this subject. Many of which, such as |
58 | 29 |
\cite{Kozen97}, are aimed at students and contain very detailed |
30 |
``pencil-and-paper'' proofs. It seems natural to exercise theorem provers by |
|
59 | 31 |
formalising these theorems and by verifying formally the algorithms. |
32 |
||
33 |
There is however a problem: the typical approach to the subject of regular |
|
34 |
languages is to introduce finite automata and define everything in terms of |
|
35 |
automata. For example, a regular language is nearly always defined as one |
|
36 |
where there is a finite deterministic automata that recognises all the |
|
37 |
strings of the language. One benefit of this approach is that it is easy |
|
38 |
to prove on paper that regular languages are closed under complementation: |
|
39 |
one just has to exchange the accepting and non-accepting states in the corresponding |
|
40 |
automata into non-accepting. The problem with automata is that they need |
|
41 |
to be represented as graphs (nodes represent states and edges, transitions) |
|
42 |
or as matrices (recording the transitions between states). Both representations |
|
43 |
cannot be defined in terms of inductive datatypes, and a reasoning infrastructure |
|
44 |
must be established manually. To our knowledge neither |
|
45 |
Isabelle nor HOL4 nor Coq have a readily usable reasoning library for graphs |
|
46 |
and matrices. Moreover, the reasoning about graphs can be quite cumbersome. |
|
47 |
Cosider for example the frequently used operation of combinding two automata |
|
48 |
into a new compound automaton. While on paper, this can be done by just forming |
|
49 |
the disjoint union of the nodes, this does not work in typed systems \dots |
|
50 |
||
58 | 51 |
|
52 |
||
53 |
||
54 |
||
55 |
||
54 | 56 |
|
57 |
Therefore instead of defining a regular language as being one where there exists an |
|
58 |
automata that regognises all of its strings, we define |
|
59 |
||
60 |
\begin{definition}[A Regular Language] |
|
61 |
A language @{text A} is regular, if there is a regular expression that matches all |
|
62 |
strings of @{text "A"}. |
|
63 |
\end{definition} |
|
64 |
||
65 |
\noindent |
|
66 |
{\bf Contributions:} A proof of the Myhil-Nerode Theorem based on regular expressions. The |
|
67 |
finiteness part of this theorem is proved using tagging-functions (which to our knowledge |
|
68 |
are novel in this context). |
|
24 | 69 |
|
70 |
*} |
|
71 |
||
50 | 72 |
section {* Preliminaries *} |
73 |
||
74 |
text {* |
|
58 | 75 |
Strings in Isabelle/HOL are lists of characters and the |
76 |
\emph{empty string} is the empty list, written @{term "[]"}. \emph{Languages} are sets of |
|
77 |
strings. The language containing all strings is written in Isabelle/HOL as @{term "UNIV::string set"}. |
|
78 |
The notation for the quotient of a language @{text A} according to a relation @{term REL} is |
|
79 |
@{term "A // REL"}. The concatenation of two languages is written @{term "A ;; B"}; a language |
|
80 |
raised tow the power $n$ is written @{term "A \<up> n"}. Both concepts are defined as |
|
54 | 81 |
|
82 |
\begin{center} |
|
58 | 83 |
@{thm Seq_def[THEN eq_reflection, where A1="A" and B1="B"]} |
84 |
\hspace{7mm} |
|
85 |
@{thm pow.simps(1)[THEN eq_reflection, where A1="A"]} |
|
86 |
\hspace{7mm} |
|
87 |
@{thm pow.simps(2)[THEN eq_reflection, where A1="A" and n1="n"]} |
|
54 | 88 |
\end{center} |
89 |
||
90 |
\noindent |
|
58 | 91 |
where @{text "@"} is the usual list-append operation. The Kleene-star of a language @{text A} |
92 |
is defined as the union over all powers, namely @{thm Star_def}. |
|
93 |
||
54 | 94 |
|
95 |
Regular expressions are defined as the following datatype |
|
96 |
||
97 |
\begin{center} |
|
98 |
@{text r} @{text "::="} |
|
99 |
@{term NULL}\hspace{1.5mm}@{text"|"}\hspace{1.5mm} |
|
100 |
@{term EMPTY}\hspace{1.5mm}@{text"|"}\hspace{1.5mm} |
|
101 |
@{term "CHAR c"}\hspace{1.5mm}@{text"|"}\hspace{1.5mm} |
|
102 |
@{term "SEQ r r"}\hspace{1.5mm}@{text"|"}\hspace{1.5mm} |
|
103 |
@{term "ALT r r"}\hspace{1.5mm}@{text"|"}\hspace{1.5mm} |
|
104 |
@{term "STAR r"} |
|
105 |
\end{center} |
|
106 |
||
51 | 107 |
Central to our proof will be the solution of equational systems |
50 | 108 |
involving regular expressions. For this we will use the following ``reverse'' |
109 |
version of Arden's lemma. |
|
110 |
||
111 |
\begin{lemma}[Reverse Arden's Lemma]\mbox{}\\ |
|
112 |
If @{thm (prem 1) ardens_revised} then |
|
113 |
@{thm (lhs) ardens_revised} has the unique solution |
|
114 |
@{thm (rhs) ardens_revised}. |
|
115 |
\end{lemma} |
|
116 |
||
117 |
\begin{proof} |
|
51 | 118 |
For the right-to-left direction we assume @{thm (rhs) ardens_revised} and show |
119 |
that @{thm (lhs) ardens_revised} holds. From Lemma ??? we have @{term "A\<star> = {[]} \<union> A ;; A\<star>"}, |
|
50 | 120 |
which is equal to @{term "A\<star> = {[]} \<union> A\<star> ;; A"}. Adding @{text B} to both |
121 |
sides gives @{term "B ;; A\<star> = B ;; ({[]} \<union> A\<star> ;; A)"}, whose right-hand side |
|
51 | 122 |
is equal to @{term "(B ;; A\<star>) ;; A \<union> B"}. This completes this direction. |
50 | 123 |
|
124 |
For the other direction we assume @{thm (lhs) ardens_revised}. By a simple induction |
|
51 | 125 |
on @{text n}, we can establish the property |
50 | 126 |
|
127 |
\begin{center} |
|
128 |
@{text "(*)"}\hspace{5mm} @{thm (concl) ardens_helper} |
|
129 |
\end{center} |
|
130 |
||
131 |
\noindent |
|
132 |
Using this property we can show that @{term "B ;; (A \<up> n) \<subseteq> X"} holds for |
|
133 |
all @{text n}. From this we can infer @{term "B ;; A\<star> \<subseteq> X"} using Lemma ???. |
|
51 | 134 |
For the inclusion in the other direction we assume a string @{text s} |
50 | 135 |
with length @{text k} is element in @{text X}. Since @{thm (prem 1) ardens_revised} |
51 | 136 |
we know that @{term "s \<notin> X ;; (A \<up> Suc k)"} since its length is only @{text k} |
137 |
(the strings in @{term "X ;; (A \<up> Suc k)"} are all longer). |
|
53 | 138 |
From @{text "(*)"} it follows then that |
50 | 139 |
@{term s} must be element in @{term "(\<Union>m\<in>{0..k}. B ;; (A \<up> m))"}. This in turn |
140 |
implies that @{term s} is in @{term "(\<Union>n. B ;; (A \<up> n))"}. Using Lemma ??? this |
|
141 |
is equal to @{term "B ;; A\<star>"}, as we needed to show.\qed |
|
142 |
\end{proof} |
|
143 |
*} |
|
39
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
144 |
|
54 | 145 |
section {* Finite Partitions Imply Regularity of a Language *} |
146 |
||
147 |
text {* |
|
148 |
\begin{theorem} |
|
149 |
Given a language @{text A}. |
|
150 |
@{thm[mode=IfThen] hard_direction[where Lang="A"]} |
|
151 |
\end{theorem} |
|
152 |
*} |
|
153 |
||
154 |
section {* Regular Expressions Generate Finitely Many Partitions *} |
|
39
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
155 |
|
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
156 |
text {* |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
157 |
|
54 | 158 |
\begin{theorem} |
39
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
159 |
Given @{text "r"} is a regular expressions, then @{thm rexp_imp_finite}. |
54 | 160 |
\end{theorem} |
39
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
161 |
|
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
162 |
\begin{proof} |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
163 |
By induction on the structure of @{text r}. The cases for @{const NULL}, @{const EMPTY} |
50 | 164 |
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
|
165 |
|
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
166 |
\begin{center} |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
167 |
\begin{tabular}{l} |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
168 |
@{thm quot_null_eq}\\ |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
169 |
@{thm quot_empty_subset}\\ |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
170 |
@{thm quot_char_subset} |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
171 |
\end{tabular} |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
172 |
\end{center} |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
173 |
|
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
174 |
\end{proof} |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
175 |
*} |
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
176 |
|
a59473f0229d
tuned a little bit the section about finite partitions
urbanc
parents:
37
diff
changeset
|
177 |
|
54 | 178 |
section {* Conclusion and Related Work *} |
179 |
||
24 | 180 |
(*<*) |
181 |
end |
|
182 |
(*>*) |