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