184 \noindent |
184 \noindent |
185 Moreover, it is not so clear how to conveniently impose a finiteness condition |
185 Moreover, it is not so clear how to conveniently impose a finiteness condition |
186 upon functions in order to represent \emph{finite} automata. The best is |
186 upon functions in order to represent \emph{finite} automata. The best is |
187 probably to resort to more advanced reasoning frameworks, such as \emph{locales} |
187 probably to resort to more advanced reasoning frameworks, such as \emph{locales} |
188 or \emph{type classes}, |
188 or \emph{type classes}, |
189 which are \emph{not} avaiable in all HOL-based theorem provers. |
189 which are \emph{not} available in all HOL-based theorem provers. |
190 |
190 |
191 Because of these problems to do with representing automata, there seems |
191 Because of these problems to do with representing automata, there seems |
192 to be no substantial formalisation of automata theory and regular languages |
192 to be no substantial formalisation of automata theory and regular languages |
193 carried out in HOL-based theorem provers. Nipkow \cite{Nipkow98} establishes |
193 carried out in HOL-based theorem provers. Nipkow \cite{Nipkow98} establishes |
194 the link between regular expressions and automata in |
194 the link between regular expressions and automata in |
307 \noindent |
307 \noindent |
308 Using this property we can show that @{term "B ;; (A \<up> n) \<subseteq> X"} holds for |
308 Using this property we can show that @{term "B ;; (A \<up> n) \<subseteq> X"} holds for |
309 all @{text n}. From this we can infer @{term "B ;; A\<star> \<subseteq> X"} using the definition |
309 all @{text n}. From this we can infer @{term "B ;; A\<star> \<subseteq> X"} using the definition |
310 of @{text "\<star>"}. |
310 of @{text "\<star>"}. |
311 For the inclusion in the other direction we assume a string @{text s} |
311 For the inclusion in the other direction we assume a string @{text s} |
312 with length @{text k} is element in @{text X}. Since @{thm (prem 1) arden} |
312 with length @{text k} is an element in @{text X}. Since @{thm (prem 1) arden} |
313 we know by Prop.~\ref{langprops}@{text "(ii)"} that |
313 we know by Prop.~\ref{langprops}@{text "(ii)"} that |
314 @{term "s \<notin> X ;; (A \<up> Suc k)"} since its length is only @{text k} |
314 @{term "s \<notin> X ;; (A \<up> Suc k)"} since its length is only @{text k} |
315 (the strings in @{term "X ;; (A \<up> Suc k)"} are all longer). |
315 (the strings in @{term "X ;; (A \<up> Suc k)"} are all longer). |
316 From @{text "(*)"} it follows then that |
316 From @{text "(*)"} it follows then that |
317 @{term s} must be element in @{term "(\<Union>m\<in>{0..k}. B ;; (A \<up> m))"}. This in turn |
317 @{term s} must be an element in @{term "(\<Union>m\<in>{0..k}. B ;; (A \<up> m))"}. This in turn |
318 implies that @{term s} is in @{term "(\<Union>n. B ;; (A \<up> n))"}. Using Prop.~\ref{langprops}@{text "(iii)"} |
318 implies that @{term s} is in @{term "(\<Union>n. B ;; (A \<up> n))"}. Using Prop.~\ref{langprops}@{text "(iii)"} |
319 this is equal to @{term "B ;; A\<star>"}, as we needed to show.\qed |
319 this is equal to @{term "B ;; A\<star>"}, as we needed to show.\qed |
320 \end{proof} |
320 \end{proof} |
321 |
321 |
322 \noindent |
322 \noindent |
589 @{thm (prem 3) Arden_keeps_eq}, then |
589 @{thm (prem 3) Arden_keeps_eq}, then |
590 @{text "X = \<Union>\<calL> ` (Arden X rhs)"} |
590 @{text "X = \<Union>\<calL> ` (Arden X rhs)"} |
591 \end{lemma} |
591 \end{lemma} |
592 |
592 |
593 \noindent |
593 \noindent |
594 The \emph{substituion-operation} takes an equation |
594 The \emph{substitution-operation} takes an equation |
595 of the form @{text "X = xrhs"} and substitutes it into the right-hand side @{text rhs}. |
595 of the form @{text "X = xrhs"} and substitutes it into the right-hand side @{text rhs}. |
596 |
596 |
597 \begin{center} |
597 \begin{center} |
598 \begin{tabular}{rc@ {\hspace{2mm}}r@ {\hspace{1mm}}l} |
598 \begin{tabular}{rc@ {\hspace{2mm}}r@ {\hspace{1mm}}l} |
599 @{thm (lhs) Subst_def} & @{text "\<equiv>"}~~\mbox{} & \multicolumn{2}{@ {\hspace{-2mm}}l}{@{text "let"}}\\ |
599 @{thm (lhs) Subst_def} & @{text "\<equiv>"}~~\mbox{} & \multicolumn{2}{@ {\hspace{-2mm}}l}{@{text "let"}}\\ |
602 & & \multicolumn{2}{@ {\hspace{-2mm}}l}{@{text "in"}~~@{term "rhs' \<union> append_rhs_rexp xrhs r'"}}\\ |
602 & & \multicolumn{2}{@ {\hspace{-2mm}}l}{@{text "in"}~~@{term "rhs' \<union> append_rhs_rexp xrhs r'"}}\\ |
603 \end{tabular} |
603 \end{tabular} |
604 \end{center} |
604 \end{center} |
605 |
605 |
606 \noindent |
606 \noindent |
607 We again delete first all occurrence of @{text "(X, r)"} in @{text rhs}; we then calculate |
607 We again delete first all occurrences of @{text "(X, r)"} in @{text rhs}; we then calculate |
608 the regular expression corresponding to the deleted terms; finally we append this |
608 the regular expression corresponding to the deleted terms; finally we append this |
609 regular expression to @{text "xrhs"} and union it up with @{text rhs'}. When we use |
609 regular expression to @{text "xrhs"} and union it up with @{text rhs'}. When we use |
610 the substitution operation we will arrange it so that @{text "xrhs"} does not contain |
610 the substitution operation we will arrange it so that @{text "xrhs"} does not contain |
611 any occurrence of @{text X}. |
611 any occurrence of @{text X}. |
612 |
612 |
613 With these two operation in place, we can define the operation that removes one equation |
613 With these two operations in place, we can define the operation that removes one equation |
614 from an equational systems @{text ES}. The operation @{const Subst_all} |
614 from an equational systems @{text ES}. The operation @{const Subst_all} |
615 substitutes an equation @{text "X = xrhs"} throughout an equational system @{text ES}; |
615 substitutes an equation @{text "X = xrhs"} throughout an equational system @{text ES}; |
616 @{const Remove} then completely removes such an equation from @{text ES} by substituting |
616 @{const Remove} then completely removes such an equation from @{text ES} by substituting |
617 it to the rest of the equational system, but first eliminating all recursive occurrences |
617 it to the rest of the equational system, but first eliminating all recursive occurrences |
618 of @{text X} by applying @{const Arden} to @{text "xrhs"}. |
618 of @{text X} by applying @{const Arden} to @{text "xrhs"}. |
781 removes the equation @{text "Y = yrhs"} from the system, and therefore |
781 removes the equation @{text "Y = yrhs"} from the system, and therefore |
782 the cardinality of @{const Iter} strictly decreases.\qed |
782 the cardinality of @{const Iter} strictly decreases.\qed |
783 \end{proof} |
783 \end{proof} |
784 |
784 |
785 \noindent |
785 \noindent |
786 This brings us to our property we want establish for @{text Solve}. |
786 This brings us to our property we want to establish for @{text Solve}. |
787 |
787 |
788 |
788 |
789 \begin{lemma} |
789 \begin{lemma} |
790 If @{thm (prem 1) Solve} and @{thm (prem 2) Solve} then there exists |
790 If @{thm (prem 1) Solve} and @{thm (prem 2) Solve} then there exists |
791 a @{text rhs} such that @{term "Solve X (Init (UNIV // \<approx>A)) = {(X, rhs)}"} |
791 a @{text rhs} such that @{term "Solve X (Init (UNIV // \<approx>A)) = {(X, rhs)}"} |
821 \begin{lemma}\label{every_eqcl_has_reg} |
821 \begin{lemma}\label{every_eqcl_has_reg} |
822 @{thm[mode=IfThen] every_eqcl_has_reg} |
822 @{thm[mode=IfThen] every_eqcl_has_reg} |
823 \end{lemma} |
823 \end{lemma} |
824 |
824 |
825 \begin{proof} |
825 \begin{proof} |
826 By the preceeding Lemma, we know that there exists a @{text "rhs"} such |
826 By the preceding Lemma, we know that there exists a @{text "rhs"} such |
827 that @{term "Solve X (Init (UNIV // \<approx>A))"} returns the equation @{text "X = rhs"}, |
827 that @{term "Solve X (Init (UNIV // \<approx>A))"} returns the equation @{text "X = rhs"}, |
828 and that the invariant holds for this equation. That means we |
828 and that the invariant holds for this equation. That means we |
829 know @{text "X = \<Union>\<calL> ` rhs"}. We further know that |
829 know @{text "X = \<Union>\<calL> ` rhs"}. We further know that |
830 this is equal to \mbox{@{text "\<Union>\<calL> ` (Arden X rhs)"}} using the properties of the |
830 this is equal to \mbox{@{text "\<Union>\<calL> ` (Arden X rhs)"}} using the properties of the |
831 invariant and Lem.~\ref{ardenable}. Using the validity property for the equation @{text "X = rhs"}, |
831 invariant and Lem.~\ref{ardenable}. Using the validity property for the equation @{text "X = rhs"}, |
1152 @{term "y @ z \<in> A ;; B"}, as needed in this case. |
1152 @{term "y @ z \<in> A ;; B"}, as needed in this case. |
1153 |
1153 |
1154 Second, there exists a @{text "z'"} such that @{term "x @ z' \<in> A"} and @{text "z - z' \<in> B"}. |
1154 Second, there exists a @{text "z'"} such that @{term "x @ z' \<in> A"} and @{text "z - z' \<in> B"}. |
1155 By the assumption about @{term "tag_str_SEQ A B"} we have |
1155 By the assumption about @{term "tag_str_SEQ A B"} we have |
1156 @{term "\<approx>A `` {x} = \<approx>A `` {y}"} and thus @{term "x \<approx>A y"}. Which means by the Myhill-Nerode |
1156 @{term "\<approx>A `` {x} = \<approx>A `` {y}"} and thus @{term "x \<approx>A y"}. Which means by the Myhill-Nerode |
1157 relation that @{term "y @ z' \<in> A"} holds. Using @{text "z - z' \<in> B"}, we can conclude aslo in this case |
1157 relation that @{term "y @ z' \<in> A"} holds. Using @{text "z - z' \<in> B"}, we can conclude also in this case |
1158 with @{term "y @ z \<in> A ;; B"}. We again can complete the @{const SEQ}-case |
1158 with @{term "y @ z \<in> A ;; B"}. We again can complete the @{const SEQ}-case |
1159 by setting @{text A} to @{term "L r\<^isub>1"} and @{text B} to @{term "L r\<^isub>2"}.\qed |
1159 by setting @{text A} to @{term "L r\<^isub>1"} and @{text B} to @{term "L r\<^isub>2"}.\qed |
1160 \end{proof} |
1160 \end{proof} |
1161 |
1161 |
1162 \noindent |
1162 \noindent |
1239 % |
1239 % |
1240 \noindent |
1240 \noindent |
1241 We first need to consider the case that @{text x} is the empty string. |
1241 We first need to consider the case that @{text x} is the empty string. |
1242 From the assumption we can infer @{text y} is the empty string and |
1242 From the assumption we can infer @{text y} is the empty string and |
1243 clearly have @{text "y @ z \<in> A\<star>"}. In case @{text x} is not the empty |
1243 clearly have @{text "y @ z \<in> A\<star>"}. In case @{text x} is not the empty |
1244 string, we can devide the string @{text "x @ z"} as shown in the picture |
1244 string, we can divide the string @{text "x @ z"} as shown in the picture |
1245 above. By the tagging function we have |
1245 above. By the tagging function we have |
1246 % |
1246 % |
1247 \begin{center} |
1247 \begin{center} |
1248 @{term "\<approx>A `` {(x - x'\<^isub>m\<^isub>a\<^isub>x)} \<in> ({\<approx>A `` {x - x'} |x'. x' < x \<and> x' \<in> A\<star>})"} |
1248 @{term "\<approx>A `` {(x - x'\<^isub>m\<^isub>a\<^isub>x)} \<in> ({\<approx>A `` {x - x'} |x'. x' < x \<and> x' \<in> A\<star>})"} |
1249 \end{center} |
1249 \end{center} |
1272 text {* |
1272 text {* |
1273 In this paper we took the view that a regular language is one where there |
1273 In this paper we took the view that a regular language is one where there |
1274 exists a regular expression that matches all of its strings. Regular |
1274 exists a regular expression that matches all of its strings. Regular |
1275 expressions can conveniently be defined as a datatype in a HOL-based theorem |
1275 expressions can conveniently be defined as a datatype in a HOL-based theorem |
1276 prover. For us it was therefore interesting to find out how far we can push |
1276 prover. For us it was therefore interesting to find out how far we can push |
1277 this point of view. We have establised both directions of the Myhill-Nerode |
1277 this point of view. We have established both directions of the Myhill-Nerode |
1278 theorem. |
1278 theorem. |
1279 % |
1279 % |
1280 \begin{theorem}[The Myhill-Nerode Theorem]\mbox{}\\ |
1280 \begin{theorem}[The Myhill-Nerode Theorem]\mbox{}\\ |
1281 A language @{text A} is regular if and only if @{thm (rhs) Myhill_Nerode}. |
1281 A language @{text A} is regular if and only if @{thm (rhs) Myhill_Nerode}. |
1282 \end{theorem} |
1282 \end{theorem} |
1321 direction and 475 for the second, plus around 300 lines of standard material about |
1321 direction and 475 for the second, plus around 300 lines of standard material about |
1322 regular languages. While this might be seen as too large to count as a |
1322 regular languages. While this might be seen as too large to count as a |
1323 concise proof pearl, this should be seen in the context of the work done by |
1323 concise proof pearl, this should be seen in the context of the work done by |
1324 Constable at al \cite{Constable00} who formalised the Myhill-Nerode theorem |
1324 Constable at al \cite{Constable00} who formalised the Myhill-Nerode theorem |
1325 in Nuprl using automata. They write that their four-member team needed |
1325 in Nuprl using automata. They write that their four-member team needed |
1326 something on the magnitute of 18 months for their formalisation. The |
1326 something on the magnitude of 18 months for their formalisation. The |
1327 estimate for our formalisation is that we needed approximately 3 months and |
1327 estimate for our formalisation is that we needed approximately 3 months and |
1328 this included the time to find our proof arguments. Unlike Constable et al, |
1328 this included the time to find our proof arguments. Unlike Constable et al, |
1329 who were able to follow the proofs from \cite{HopcroftUllman69}, we had to |
1329 who were able to follow the proofs from \cite{HopcroftUllman69}, we had to |
1330 find our own arguments. So for us the formalisation was not the |
1330 find our own arguments. So for us the formalisation was not the |
1331 bottleneck. It is hard to gauge the size of a formalisation in Nurpl, but |
1331 bottleneck. It is hard to gauge the size of a formalisation in Nurpl, but |
1334 Mercurial Repository at |
1334 Mercurial Repository at |
1335 \mbox{\url{http://www4.in.tum.de/~urbanc/regexp.html}}. |
1335 \mbox{\url{http://www4.in.tum.de/~urbanc/regexp.html}}. |
1336 |
1336 |
1337 |
1337 |
1338 Our proof of the first direction is very much inspired by \emph{Brzozowski's |
1338 Our proof of the first direction is very much inspired by \emph{Brzozowski's |
1339 algebraic mehod} used to convert a finite automaton to a regular |
1339 algebraic method} used to convert a finite automaton to a regular |
1340 expression \cite{Brzozowski64}. The close connection can be seen by considering the equivalence |
1340 expression \cite{Brzozowski64}. The close connection can be seen by considering the equivalence |
1341 classes as the states of the minimal automaton for the regular language. |
1341 classes as the states of the minimal automaton for the regular language. |
1342 However there are some subtle differences. Since we identify equivalence |
1342 However there are some subtle differences. Since we identify equivalence |
1343 classes with the states of the automaton, then the most natural choice is to |
1343 classes with the states of the automaton, then the most natural choice is to |
1344 characterise each state with the set of strings starting from the initial |
1344 characterise each state with the set of strings starting from the initial |