210 \noindent |
210 \noindent |
211 Regular languages are an important and well-understood subject in Computer |
211 Regular languages are an important and well-understood subject in Computer |
212 Science, with many beautiful theorems and many useful algorithms. There is a |
212 Science, with many beautiful theorems and many useful algorithms. There is a |
213 wide range of textbooks on this subject, many of which are aimed at students |
213 wide range of textbooks on this subject, many of which are aimed at students |
214 and contain very detailed `pencil-and-paper' proofs |
214 and contain very detailed `pencil-and-paper' proofs |
215 (e.g.~\cite{HopcroftUllman69,Kozen97}). It seems natural to exercise theorem provers by |
215 (e.g.~the textbooks by \citeN{HopcroftUllman69} and by \citeN{Kozen97}). |
|
216 It seems natural to exercise theorem provers by |
216 formalising the theorems and by verifying formally the algorithms. |
217 formalising the theorems and by verifying formally the algorithms. |
217 |
218 |
218 A popular choice for a theorem prover would be one based on Higher-Order |
219 A popular choice for a theorem prover would be one based on Higher-Order |
219 Logic (HOL), for example HOL4, HOLlight or Isabelle/HOL. For the development |
220 Logic (HOL), for example HOL4, HOLlight or Isabelle/HOL. For the development |
220 presented in this paper we will use the Isabelle/HOL. HOL is a predicate calculus |
221 presented in this paper we will use the Isabelle/HOL. HOL is a predicate calculus |
221 that allows quantification over predicate variables. Its type system is |
222 that allows quantification over predicate variables. Its type system is |
222 based on Church's Simple Theory of Types \cite{Church40}. Although many |
223 based on the Simple Theory of Types by \citeN{Church40}. Although many |
223 mathematical concepts can be conveniently expressed in HOL, there are some |
224 mathematical concepts can be conveniently expressed in HOL, there are some |
224 limitations that hurt badly when attempting a simple-minded formalisation |
225 limitations that hurt when attempting a simple-minded formalisation |
225 of regular languages in it. |
226 of regular languages in it. |
226 |
227 |
227 The typical approach (for example \cite{HopcroftUllman69,Kozen97}) to |
228 The typical approach to |
228 regular languages is to introduce finite deterministic automata and then |
229 regular languages, taken for example by \citeN{HopcroftUllman69} |
229 define everything in terms of them. For example, a regular language is |
230 and by \citeN{Kozen97}, is to introduce finite deterministic automata and then |
|
231 define most notions in terms of them. For example, a regular language is |
230 normally defined as: |
232 normally defined as: |
231 |
233 |
232 \begin{dfntn}\label{baddef} |
234 \begin{dfntn}\label{baddef} |
233 A language @{text A} is \emph{regular}, provided there is a |
235 A language @{text A} is \emph{regular}, provided there is a |
234 finite deterministic automaton that recognises all strings of @{text "A"}. |
236 finite deterministic automaton that recognises all strings of @{text "A"}. |
239 convince oneself that regular languages are closed under complementation: |
241 convince oneself that regular languages are closed under complementation: |
240 one just has to exchange the accepting and non-accepting states in the |
242 one just has to exchange the accepting and non-accepting states in the |
241 corresponding automaton to obtain an automaton for the complement language. |
243 corresponding automaton to obtain an automaton for the complement language. |
242 The problem, however, lies with formalising such reasoning in a |
244 The problem, however, lies with formalising such reasoning in a |
243 theorem prover. Automata are built up from states and transitions that are |
245 theorem prover. Automata are built up from states and transitions that are |
244 usually represented as graphs, matrices or functions, none of which can be |
246 commonly represented as graphs, matrices or functions, none of which, unfortunately, |
245 defined as an inductive datatype. |
247 can be defined as an inductive datatype. |
246 |
248 |
247 In case of graphs and matrices, this means we have to build our own |
249 In case of graphs and matrices, this means we have to build our own |
248 reasoning infrastructure for them, as neither Isabelle/HOL nor HOL4 nor |
250 reasoning infrastructure for them, as neither Isabelle/HOL nor HOL4 nor |
249 HOLlight support them with libraries. Even worse, reasoning about graphs and |
251 HOLlight support them with libraries. Also, reasoning about graphs and |
250 matrices can be a real hassle in theorem provers, because |
252 matrices can be a hassle in theorem provers, because |
251 we have to be able to combine automata. Consider for |
253 we have to be able to combine automata. Consider for |
252 example the operation of sequencing two automata, say $A_1$ and $A_2$, by |
254 example the operation of sequencing two automata, say $A_1$ and $A_2$, by |
253 connecting the accepting states of $A_1$ to the initial state of $A_2$: |
255 connecting the accepting states of $A_1$ to the initial state of $A_2$: |
254 |
256 |
255 \begin{center} |
257 \begin{center} |
364 `` & If the reader finds the above treatment in terms of bit lists revoltingly |
367 `` & If the reader finds the above treatment in terms of bit lists revoltingly |
365 concrete, I cannot disagree. A more abstract approach is clearly desirable.'' |
368 concrete, I cannot disagree. A more abstract approach is clearly desirable.'' |
366 \end{tabular} |
369 \end{tabular} |
367 \end{quote}\smallskip |
370 \end{quote}\smallskip |
368 |
371 |
369 |
372 %\noindent |
370 \noindent |
373 %Moreover, it is not so clear how to conveniently impose a finiteness |
371 Moreover, it is not so clear how to conveniently impose a finiteness |
374 %condition upon functions in order to represent \emph{finite} automata. The |
372 condition upon functions in order to represent \emph{finite} automata. The |
375 %best is probably to resort to more advanced reasoning frameworks, such as |
373 best is probably to resort to more advanced reasoning frameworks, such as |
376 %\emph{locales} or \emph{type classes}, which are \emph{not} available in all |
374 \emph{locales} or \emph{type classes}, which are \emph{not} available in all |
377 %HOL-based theorem provers. |
375 HOL-based theorem provers. |
|
376 |
378 |
377 Because of these problems to do with representing automata, there seems to |
379 Because of these problems to do with representing automata, there seems to |
378 be no substantial formalisation of automata theory and regular languages |
380 be no substantial formalisation of automata theory and regular languages |
379 carried out in HOL-based theorem provers. Nipkow \cite{Nipkow98} establishes |
381 carried out in HOL-based theorem provers. \citeN{Nipkow98} establishes |
380 the link between regular expressions and automata in the context of |
382 the link between regular expressions and automata in the context of |
381 lexing. Berghofer and Reiter \cite{BerghoferReiter09} formalise automata |
383 lexing. \citeN{BerghoferReiter09} formalise automata |
382 working over bit strings in the context of Presburger arithmetic. The only |
384 working over bit strings in the context of Presburger arithmetic. The only |
383 larger formalisations of automata theory are carried out in Nuprl |
385 larger formalisations of automata theory are carried out in Nuprl by |
384 \cite{Constable00} and in Coq, e.g.~\cite{Almeidaetal10,Filliatre97}. |
386 \citeN{Constable00} and in Coq by \citeN{Filliatre97}, \citeN{Almeidaetal10} |
385 |
387 and \citeN{Braibant12}. |
386 Also, one might consider automata as just convenient `vehicles' for |
388 |
387 establishing properties about regular languages. However, paper proofs |
389 %Also, one might consider automata as just convenient `vehicles' for |
388 about automata often involve subtle side-conditions which are easily |
390 %establishing properties about regular languages. However, paper proofs |
389 overlooked, but which make formal reasoning rather painful. For example |
391 %about automata often involve subtle side-conditions which are easily |
390 Kozen's proof of the Myhill-Nerode Theorem requires that automata do not |
392 %overlooked, but which make formal reasoning rather painful. For example |
391 have inaccessible states \cite{Kozen97}. Another subtle side-condition is |
393 %Kozen's proof of the Myhill-Nerode Theorem requires that automata do not |
392 completeness of automata, that is automata need to have total transition |
394 %have inaccessible states \cite{Kozen97}. Another subtle side-condition is |
393 functions and at most one `sink' state from which there is no connection to |
395 %completeness of automata, that is automata need to have total transition |
394 a final state (Brzozowski mentions this side-condition in the context of |
396 %functions and at most one `sink' state from which there is no connection to |
395 state complexity of automata \cite{Brzozowski10}, but it is also needed |
397 %a final state (Brzozowski mentions this side-condition in the context of |
396 in the usual construction of the complement automaton). Such side-conditions mean |
398 %state complexity of automata \cite{Brzozowski10}, but it is also needed |
397 that if we define a regular language as one for which there exists \emph{a} |
399 %in the usual construction of the complement automaton). Such side-conditions mean |
398 finite automaton that recognises all its strings (see |
400 %that if we define a regular language as one for which there exists \emph{a} |
399 Definition~\ref{baddef}), then we need a lemma which ensures that another |
401 %finite automaton that recognises all its strings (see |
400 equivalent one can be found satisfying the side-condition, and also need to |
402 %Definition~\ref{baddef}), then we need a lemma which ensures that another |
401 make sure our operations on automata preserve them. Unfortunately, such |
403 %equivalent one can be found satisfying the side-condition, and also need to |
402 `little' and `obvious' lemmas make formalisations of automata theory |
404 %make sure our operations on automata preserve them. Unfortunately, such |
403 hair-pulling experiences. |
405 %`little' and `obvious' lemmas make formalisations of automata theory |
|
406 %hair-pulling experiences. |
404 |
407 |
405 In this paper, we will not attempt to formalise automata theory in |
408 In this paper, we will not attempt to formalise automata theory in |
406 Isabelle/HOL nor will we attempt to formalise automata proofs from the |
409 Isabelle/HOL nor will we attempt to formalise automata proofs from the |
407 literature, but take a different approach to regular languages than is |
410 literature, but take a different approach to regular languages than is |
408 usually taken. Instead of defining a regular language as one where there |
411 usually taken. Instead of defining a regular language as one where there |
414 that matches all strings of @{text "A"}. |
417 that matches all strings of @{text "A"}. |
415 \end{dfntn} |
418 \end{dfntn} |
416 |
419 |
417 \noindent |
420 \noindent |
418 And then `forget' automata completely. |
421 And then `forget' automata completely. |
419 The reason is that regular expressions, unlike graphs, matrices and |
422 The reason is that regular expressions %, unlike graphs, matrices and |
420 functions, can be easily defined as an inductive datatype. A reasoning |
423 %functions, |
421 infrastructure (like induction and recursion) comes for free in |
424 can be defined as an inductive datatype and a reasoning |
422 HOL. Moreover, no side-conditions will be needed for regular expressions, |
425 infrastructure for them (like induction and recursion) comes for free in |
423 like we need for automata. This convenience of regular expressions has |
426 HOL. %Moreover, no side-conditions will be needed for regular expressions, |
|
427 %like we need for automata. |
|
428 This convenience of regular expressions has |
424 recently been exploited in HOL4 with a formalisation of regular expression |
429 recently been exploited in HOL4 with a formalisation of regular expression |
425 matching based on derivatives \cite{OwensSlind08} and with an equivalence |
430 matching based on derivatives by \citeN{OwensSlind08}, and with an equivalence |
426 checker for regular expressions in Isabelle/HOL \cite{KraussNipkow11}. The |
431 checker for regular expressions in Isabelle/HOL by \citeN{KraussNipkow11}. The |
427 main purpose of this paper is to show that a central result about regular |
432 main purpose of this paper is to show that a central result about regular |
428 languages---the Myhill-Nerode Theorem---can be recreated by only using |
433 languages---the Myhill-Nerode Theorem---can be recreated by only using |
429 regular expressions. This theorem gives necessary and sufficient conditions |
434 regular expressions. This theorem gives necessary and sufficient conditions |
430 for when a language is regular. As a corollary of this theorem we can easily |
435 for when a language is regular. As a corollary of this theorem we can easily |
431 establish the usual closure properties, including complementation, for |
436 establish the usual closure properties, including complementation, for |
432 regular languages. We use the Continuation Lemma \cite{Rosenberg06}, |
437 regular languages. We use the Continuation Lemma, which is also a corollary |
433 which is also a corollary of the Myhill-Nerode Theorem, for establishing |
438 of the Myhill-Nerode Theorem, for establishing |
434 the non-regularity of the language @{text "a\<^isup>nb\<^isup>n"}.\medskip |
439 the non-regularity of the language @{text "a\<^isup>nb\<^isup>n"}.\medskip |
435 |
440 |
436 \noindent |
441 \noindent |
437 {\bf Contributions:} There is an extensive literature on regular languages. |
442 {\bf Contributions:} There is an extensive literature on regular languages. |
438 To our best knowledge, our proof of the Myhill-Nerode Theorem is the first |
443 To our best knowledge, our proof of the Myhill-Nerode Theorem is the first |
439 that is based on regular expressions, only. The part of this theorem stating |
444 that is based on regular expressions, only. The part of this theorem stating |
440 that finitely many partitions imply regularity of the language is proved by |
445 that finitely many partitions imply regularity of the language is proved by |
441 an argument about solving equational systems. This argument appears to be |
446 an argument about solving equational systems. This argument appears to be |
442 folklore. For the other part, we give two proofs: one direct proof using |
447 folklore. For the other part, we give two proofs: one direct proof using |
443 certain tagging-functions, and another indirect proof using Antimirov's |
448 certain tagging-functions, and another indirect proof using Antimirov's |
444 partial derivatives \cite{Antimirov95}. Again to our best knowledge, the |
449 partial derivatives \citeyear{Antimirov95}. Again to our best knowledge, the |
445 tagging-functions have not been used before for establishing the Myhill-Nerode |
450 tagging-functions have not been used before for establishing the Myhill-Nerode |
446 Theorem. Derivatives of regular expressions have been used recently quite |
451 Theorem. Derivatives of regular expressions have been used recently quite |
447 widely in the literature; partial derivatives, in contrast, attract much |
452 widely in the literature; partial derivatives, in contrast, attract much |
448 less attention. However, partial derivatives are more suitable in the |
453 less attention. However, partial derivatives are more suitable in the |
449 context of the Myhill-Nerode Theorem, since it is easier to establish |
454 context of the Myhill-Nerode Theorem, since it is easier to establish |
701 equivalence classes and only finitely many characters. |
709 equivalence classes and only finitely many characters. |
702 The term @{text "\<lambda>(ONE)"} in the first equation acts as a marker for the initial state, that |
710 The term @{text "\<lambda>(ONE)"} in the first equation acts as a marker for the initial state, that |
703 is the equivalence class |
711 is the equivalence class |
704 containing the empty string @{text "[]"}.\footnote{Note that we mark, roughly speaking, the |
712 containing the empty string @{text "[]"}.\footnote{Note that we mark, roughly speaking, the |
705 single `initial' state in the equational system, which is different from |
713 single `initial' state in the equational system, which is different from |
706 the method by Brzozowski \cite{Brzozowski64}, where he marks the |
714 the method by \citeN{Brzozowski64}, where he marks the |
707 `terminal' states. We are forced to set up the equational system in our |
715 `terminal' states. We are forced to set up the equational system in our |
708 way, because the Myhill-Nerode Relation determines the `direction' of the |
716 way, because the Myhill-Nerode Relation determines the `direction' of the |
709 transitions---the successor `state' of an equivalence class @{text Y} can |
717 transitions---the successor `state' of an equivalence class @{text Y} can |
710 be reached by adding a character to the end of @{text Y}. This is also the |
718 be reached by adding a character to the end of @{text Y}. This is also the |
711 reason why we have to use our reversed version of Arden's Lemma.} |
719 reason why we have to use our reversed version of Arden's Lemma.} |
712 In our running example we have the initial equational system |
720 In our running example we have the initial equational system |
713 |
721 % |
714 \begin{equation}\label{exmpcs} |
722 \begin{equation}\label{exmpcs} |
715 \mbox{\begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l} |
723 \mbox{\begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l} |
716 @{term "X\<^isub>1"} & @{text "="} & @{text "\<lambda>(ONE)"}\\ |
724 @{term "X\<^isub>1"} & @{text "="} & @{text "\<lambda>(ONE)"}\\ |
717 @{term "X\<^isub>2"} & @{text "="} & @{text "(X\<^isub>1, ATOM c)"}\\ |
725 @{term "X\<^isub>2"} & @{text "="} & @{text "(X\<^isub>1, ATOM c)"}\\ |
718 @{term "X\<^isub>3"} & @{text "="} & @{text "(X\<^isub>1, ATOM d\<^isub>1) + \<dots> + (X\<^isub>1, ATOM d\<^isub>n)"}\\ |
726 @{term "X\<^isub>3"} & @{text "="} & @{text "(X\<^isub>1, ATOM d\<^isub>1) + \<dots> + (X\<^isub>1, ATOM d\<^isub>n)"}\\ |
1188 \noindent |
1197 \noindent |
1189 Much more interesting, however, are the inductive cases. They seem hard to be solved |
1198 Much more interesting, however, are the inductive cases. They seem hard to be solved |
1190 directly. The reader is invited to try. |
1199 directly. The reader is invited to try. |
1191 |
1200 |
1192 In order to see how our proof proceeds consider the following suggestive picture |
1201 In order to see how our proof proceeds consider the following suggestive picture |
1193 taken from Constable et al \cite{Constable00}: |
1202 given by \citeN{Constable00}: |
1194 |
1203 % |
1195 \begin{equation}\label{pics} |
1204 \begin{equation}\label{pics} |
1196 \mbox{\begin{tabular}{c@ {\hspace{10mm}}c@ {\hspace{10mm}}c} |
1205 \mbox{\begin{tabular}{c@ {\hspace{10mm}}c@ {\hspace{10mm}}c} |
1197 \begin{tikzpicture}[scale=1] |
1206 \begin{tikzpicture}[scale=0.95] |
1198 %Circle |
1207 %Circle |
1199 \draw[thick] (0,0) circle (1.1); |
1208 \draw[thick] (0,0) circle (1.1); |
1200 \end{tikzpicture} |
1209 \end{tikzpicture} |
1201 & |
1210 & |
1202 \begin{tikzpicture}[scale=1] |
1211 \begin{tikzpicture}[scale=0.95] |
1203 %Circle |
1212 %Circle |
1204 \draw[thick] (0,0) circle (1.1); |
1213 \draw[thick] (0,0) circle (1.1); |
1205 %Main rays |
1214 %Main rays |
1206 \foreach \a in {0, 90,...,359} |
1215 \foreach \a in {0, 90,...,359} |
1207 \draw[very thick] (0, 0) -- (\a:1.1); |
1216 \draw[very thick] (0, 0) -- (\a:1.1); |
1208 \foreach \a / \l in {45/1, 135/2, 225/3, 315/4} |
1217 \foreach \a / \l in {45/1, 135/2, 225/3, 315/4} |
1209 \draw (\a: 0.65) node {$a_\l$}; |
1218 \draw (\a: 0.65) node {$a_\l$}; |
1210 \end{tikzpicture} |
1219 \end{tikzpicture} |
1211 & |
1220 & |
1212 \begin{tikzpicture}[scale=1] |
1221 \begin{tikzpicture}[scale=0.95] |
1213 %Circle |
1222 %Circle |
1214 \draw[thick] (0,0) circle (1.1); |
1223 \draw[thick] (0,0) circle (1.1); |
1215 %Main rays |
1224 %Main rays |
1216 \foreach \a in {0, 45,...,359} |
1225 \foreach \a in {0, 45,...,359} |
1217 \draw[very thick] (0, 0) -- (\a:1.1); |
1226 \draw[very thick] (0, 0) -- (\a:1.1); |
1709 \noindent |
1718 \noindent |
1710 The last two clauses extend derivatives from characters to strings. The |
1719 The last two clauses extend derivatives from characters to strings. The |
1711 boolean function @{term "nullable r"} needed in the @{const Times}-case tests |
1720 boolean function @{term "nullable r"} needed in the @{const Times}-case tests |
1712 whether a regular expression can recognise the empty string. It can be defined as |
1721 whether a regular expression can recognise the empty string. It can be defined as |
1713 follows. |
1722 follows. |
1714 |
1723 % |
1715 \begin{center} |
1724 \begin{center} |
1716 \begin{tabular}{c} |
1725 \begin{longtable}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1.5mm}}l@ {}} |
1717 \begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1.5mm}}l@ {}} |
|
1718 @{thm (lhs) nullable.simps(1)} & @{text "\<equiv>"} & @{thm (rhs) nullable.simps(1)}\\ |
1726 @{thm (lhs) nullable.simps(1)} & @{text "\<equiv>"} & @{thm (rhs) nullable.simps(1)}\\ |
1719 @{thm (lhs) nullable.simps(2)} & @{text "\<equiv>"} & @{thm (rhs) nullable.simps(2)}\\ |
1727 @{thm (lhs) nullable.simps(2)} & @{text "\<equiv>"} & @{thm (rhs) nullable.simps(2)}\\ |
1720 @{thm (lhs) nullable.simps(3)} & @{text "\<equiv>"} & @{thm (rhs) nullable.simps(3)}\\ |
1728 @{thm (lhs) nullable.simps(3)} & @{text "\<equiv>"} & @{thm (rhs) nullable.simps(3)}\\ |
1721 @{thm (lhs) nullable.simps(4)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]} |
1729 @{thm (lhs) nullable.simps(4)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]} |
1722 & @{text "\<equiv>"} & @{thm (rhs) nullable.simps(4)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]}\\ |
1730 & @{text "\<equiv>"} & @{thm (rhs) nullable.simps(4)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]}\\ |
1723 @{thm (lhs) nullable.simps(5)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]} |
1731 @{thm (lhs) nullable.simps(5)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]} |
1724 & @{text "\<equiv>"} & @{thm (rhs) nullable.simps(5)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]}\\ |
1732 & @{text "\<equiv>"} & @{thm (rhs) nullable.simps(5)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]}\\ |
1725 @{thm (lhs) nullable.simps(6)} & @{text "\<equiv>"} & @{thm (rhs) nullable.simps(6)}\\ |
1733 @{thm (lhs) nullable.simps(6)} & @{text "\<equiv>"} & @{thm (rhs) nullable.simps(6)} |
1726 \end{tabular} |
1734 \end{longtable} |
1727 \end{tabular} |
|
1728 \end{center} |
1735 \end{center} |
1729 |
1736 |
1730 \noindent |
1737 \noindent |
1731 By induction on the regular expression @{text r}, respectively on the string @{text s}, |
1738 By induction on the regular expression @{text r}, respectively on the string @{text s}, |
1732 one can easily show that left-quotients and derivatives of regular expressions |
1739 one can easily show that left-quotients and derivatives of regular expressions |
1733 relate as follows (see for example~\cite{Sakarovitch09}): |
1740 relate as follows (see for example~\cite{Sakarovitch09}): |
1734 |
1741 % |
1735 \begin{equation}\label{Dersders} |
1742 \begin{equation}\label{Dersders} |
1736 \mbox{\begin{tabular}{c} |
1743 \mbox{\begin{tabular}{c} |
1737 @{thm Deriv_deriv}\\ |
1744 @{thm Deriv_deriv}\\ |
1738 @{thm Derivs_derivs} |
1745 @{thm Derivs_derivs} |
1739 \end{tabular}} |
1746 \end{tabular}} |
2015 steps: regular expression @{text "\<Rightarrow>"} non-deterministic automaton @{text |
2021 steps: regular expression @{text "\<Rightarrow>"} non-deterministic automaton @{text |
2016 "\<Rightarrow>"} deterministic automaton @{text "\<Rightarrow>"} complement automaton @{text "\<Rightarrow>"} |
2022 "\<Rightarrow>"} deterministic automaton @{text "\<Rightarrow>"} complement automaton @{text "\<Rightarrow>"} |
2017 regular expression. Clearly not something you want to formalise in a theorem |
2023 regular expression. Clearly not something you want to formalise in a theorem |
2018 prover if it is cumbersome to reason about automata. |
2024 prover if it is cumbersome to reason about automata. |
2019 |
2025 |
2020 Once closure under complement is established, closure under intersection |
2026 %Once closure under complement is established, closure under intersection |
2021 and set difference is also easy, because |
2027 %and set difference is also easy, because |
2022 |
2028 % |
2023 \begin{center} |
2029 %\begin{center} |
2024 \begin{tabular}{c} |
2030 %\begin{tabular}{c} |
2025 @{term "A \<inter> B = - (- A \<union> - B)"}\\ |
2031 %@{term "A \<inter> B = - (- A \<union> - B)"}\\ |
2026 @{term "A - B = - (- A \<union> B)"} |
2032 %@{term "A - B = - (- A \<union> B)"} |
2027 \end{tabular} |
2033 %\end{tabular} |
2028 \end{center} |
2034 %\end{center} |
2029 |
2035 % |
2030 \noindent |
2036 %\noindent |
2031 Since all finite languages are regular, then by closure under complement also |
2037 %Since all finite languages are regular, then by closure under complement also |
2032 all co-finite languages. Closure of regular languages under reversal, that is |
2038 %all co-finite languages. |
2033 |
2039 % |
2034 \begin{center} |
2040 %Closure of regular languages under reversal, that is |
2035 @{text "A\<^bsup>-1\<^esup> \<equiv> {s\<^bsup>-1\<^esup> | s \<in> A}"} |
2041 % |
2036 \end{center} |
2042 %\begin{center} |
2037 |
2043 %@{text "A\<^bsup>-1\<^esup> \<equiv> {s\<^bsup>-1\<^esup> | s \<in> A}"} |
2038 \noindent |
2044 %\end{center} |
2039 can be shown with the help of the following operation defined recursively over |
2045 % |
2040 regular expressions |
2046 %\noindent |
2041 |
2047 %can be shown with the help of the following operation defined recursively over |
2042 \begin{center} |
2048 %regular expressions |
2043 \begin{tabular}{r@ {\hspace{1mm}}c@ {\hspace{1mm}}l} |
2049 % |
2044 @{thm (lhs) Rev.simps(1)} & @{text "\<equiv>"} & @{thm (rhs) Rev.simps(1)}\\ |
2050 %\begin{center} |
2045 @{thm (lhs) Rev.simps(2)} & @{text "\<equiv>"} & @{thm (rhs) Rev.simps(2)}\\ |
2051 %\begin{tabular}{r@ {\hspace{1mm}}c@ {\hspace{1mm}}l} |
2046 @{thm (lhs) Rev.simps(3)} & @{text "\<equiv>"} & @{thm (rhs) Rev.simps(3)}\\ |
2052 %@{thm (lhs) Rev.simps(1)} & @{text "\<equiv>"} & @{thm (rhs) Rev.simps(1)}\\ |
2047 @{thm (lhs) Rev.simps(4)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]} & @{text "\<equiv>"} & |
2053 %@{thm (lhs) Rev.simps(2)} & @{text "\<equiv>"} & @{thm (rhs) Rev.simps(2)}\\ |
2048 @{thm (rhs) Rev.simps(4)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]}\\ |
2054 %@{thm (lhs) Rev.simps(3)} & @{text "\<equiv>"} & @{thm (rhs) Rev.simps(3)}\\ |
2049 @{thm (lhs) Rev.simps(5)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]} & @{text "\<equiv>"} & |
2055 %@{thm (lhs) Rev.simps(4)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]} & @{text "\<equiv>"} & |
2050 @{thm (rhs) Rev.simps(5)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]}\\ |
2056 % @{thm (rhs) Rev.simps(4)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]}\\ |
2051 @{thm (lhs) Rev.simps(6)} & @{text "\<equiv>"} & @{thm (rhs) Rev.simps(6)}\\ |
2057 %@{thm (lhs) Rev.simps(5)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]} & @{text "\<equiv>"} & |
2052 \end{tabular} |
2058 % @{thm (rhs) Rev.simps(5)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]}\\ |
2053 \end{center} |
2059 %@{thm (lhs) Rev.simps(6)} & @{text "\<equiv>"} & @{thm (rhs) Rev.simps(6)}\\ |
2054 |
2060 %\end{tabular} |
2055 \noindent |
2061 %\end{center} |
2056 For this operation we can show |
2062 % |
2057 |
2063 %\noindent |
2058 \begin{center} |
2064 %For this operation we can show |
2059 @{text "(\<calL>(r))\<^bsup>-1\<^esup>"}~@{text "="}~@{thm (rhs) rev_lang} |
2065 % |
2060 \end{center} |
2066 %\begin{center} |
2061 |
2067 %@{text "(\<calL>(r))\<^bsup>-1\<^esup>"}~@{text "="}~@{thm (rhs) rev_lang} |
2062 \noindent |
2068 %\end{center} |
2063 from which closure under reversal of regular languages follows. |
2069 % |
|
2070 %\noindent |
|
2071 %from which closure under reversal of regular languages follows. |
2064 |
2072 |
2065 A perhaps surprising fact is that regular languages are closed under any |
2073 A perhaps surprising fact is that regular languages are closed under any |
2066 left-quotient. Define |
2074 left-quotient. Define |
2067 |
2075 |
2068 \begin{center} |
2076 \begin{center} |
2116 \end{center} |
2129 \end{center} |
2117 |
2130 |
2118 \noindent |
2131 \noindent |
2119 We like to establish |
2132 We like to establish |
2120 |
2133 |
2121 \begin{thrm}[(Haines \cite{Haines69})]\label{subseqreg} |
2134 \begin{thrm}[\cite{Haines69}]\label{subseqreg} |
2122 For every language @{text A}, the languages @{text "(i)"} @{term "SUBSEQ A"} and |
2135 For every language @{text A}, the languages @{text "(i)"} @{term "SUBSEQ A"} and |
2123 @{text "(ii)"} @{term "SUPSEQ A"} |
2136 @{text "(ii)"} @{term "SUPSEQ A"} |
2124 are regular. |
2137 are regular. |
2125 \end{thrm} |
2138 \end{thrm} |
2126 |
2139 |
2127 \noindent |
2140 \noindent |
2128 Our proof follows the one given in \cite[Pages 92--95]{Shallit08}, except that we use |
2141 Our proof follows the one given by \citeN[Pages 92--95]{Shallit08}, except that we use |
2129 Higman's Lemma, which is already proved in the Isabelle/HOL library |
2142 Higman's Lemma, which is already proved in the Isabelle/HOL library by |
2130 \cite{Berghofer03}.\footnote{Unfortunately, Berghofer's formalisation of Higman's Lemma |
2143 Sternagel. |
2131 is restricted to 2-letter alphabets, |
|
2132 which means also our formalisation of Theorem~\ref{subseqreg} is `tainted' with |
|
2133 this constraint. However our methodology is applicable to any alphabet of finite size.} |
|
2134 Higman's Lemma allows us to infer that every language @{text A} of antichains, satisfying |
2144 Higman's Lemma allows us to infer that every language @{text A} of antichains, satisfying |
2135 |
2145 % |
2136 \begin{equation}\label{higman} |
2146 \begin{equation}\label{higman} |
2137 @{text "\<forall>x, y \<in> A."}~@{term "x \<noteq> y \<longrightarrow> \<not>(x \<preceq> y) \<and> \<not>(y \<preceq> x)"} |
2147 @{text "\<forall>x, y \<in> A."}~@{term "x \<noteq> y \<longrightarrow> \<not>(x \<preceq> y) \<and> \<not>(y \<preceq> x)"} |
2138 \end{equation} |
2148 \end{equation} |
2139 |
2149 |
2140 \noindent |
2150 \noindent |
2141 is finite. |
2151 is finite. |
2142 |
2152 |
2143 The first step in our proof of Theorem~\ref{subseqreg} is to establish the |
2153 The first step in our proof of Theorem~\ref{subseqreg} is to establish the |
2144 following simple properties for @{term SUPSEQ} |
2154 following simple properties for @{term SUPSEQ} |
2145 |
2155 % |
2146 \begin{equation}\label{supseqprops} |
2156 \begin{equation}\label{supseqprops} |
2147 \mbox{\begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l} |
2157 \mbox{\begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l} |
2148 @{thm (lhs) SUPSEQ_simps(1)} & @{text "\<equiv>"} & @{thm (rhs) SUPSEQ_simps(1)}\\ |
2158 @{thm (lhs) SUPSEQ_simps(1)} & @{text "\<equiv>"} & @{thm (rhs) SUPSEQ_simps(1)}\\ |
2149 @{thm (lhs) SUPSEQ_simps(2)} & @{text "\<equiv>"} & @{thm (rhs) SUPSEQ_simps(2)}\\ |
2159 @{thm (lhs) SUPSEQ_simps(2)} & @{text "\<equiv>"} & @{thm (rhs) SUPSEQ_simps(2)}\\ |
2150 @{thm (lhs) SUPSEQ_atom} & @{text "\<equiv>"} & @{thm (rhs) SUPSEQ_atom}\\ |
2160 @{thm (lhs) SUPSEQ_atom} & @{text "\<equiv>"} & @{thm (rhs) SUPSEQ_atom}\\ |
2300 expressions can conveniently be defined as a datatype in theorem |
2310 expressions can conveniently be defined as a datatype in theorem |
2301 provers. For us it was therefore interesting to find out how far we can push |
2311 provers. For us it was therefore interesting to find out how far we can push |
2302 this point of view. We have established in Isabelle/HOL both directions |
2312 this point of view. We have established in Isabelle/HOL both directions |
2303 of the Myhill-Nerode Theorem. |
2313 of the Myhill-Nerode Theorem. |
2304 % |
2314 % |
2305 \begin{thrm}[(The Myhill-Nerode Theorem)]\mbox{}\\ |
2315 \begin{thrm}[(Myhill-Nerode Theorem)]\mbox{}\\ |
2306 A language @{text A} is regular if and only if @{thm (rhs) Myhill_Nerode}. |
2316 A language @{text A} is regular if and only if @{thm (rhs) Myhill_Nerode}. |
2307 \end{thrm} |
2317 \end{thrm} |
2308 |
2318 |
2309 \noindent |
2319 \noindent |
2310 Having formalised this theorem means we pushed our point of view quite |
2320 Having formalised this theorem means we pushed our point of view quite |
2311 far. Using this theorem we can obviously prove when a language is \emph{not} |
2321 far. Using this theorem we can obviously prove when a language is \emph{not} |
2312 regular---by establishing that it has infinitely many equivalence classes |
2322 regular---by establishing that it has infinitely many equivalence classes |
2313 generated by the Myhill-Nerode Relation (this is usually the purpose of the |
2323 generated by the Myhill-Nerode Relation (this is usually the purpose of the |
2314 Pumping Lemma \cite{Kozen97}). We can also use it to establish the standard |
2324 Pumping Lemma). We can also use it to establish the standard |
2315 textbook results about closure properties of regular languages. Interesting |
2325 textbook results about closure properties of regular languages. Interesting |
2316 is the case of closure under complement, because it seems difficult to |
2326 is the case of closure under complement, because it seems difficult to |
2317 construct a regular expression for the complement language by direct |
2327 construct a regular expression for the complement language by direct |
2318 means. However the existence of such a regular expression can be easily |
2328 means. However the existence of such a regular expression can be easily |
2319 proved using the Myhill-Nerode Theorem. |
2329 proved using the Myhill-Nerode Theorem. |
2320 |
2330 |
2321 Our insistence on regular expressions for proving the Myhill-Nerode Theorem |
2331 %Our insistence on regular expressions for proving the Myhill-Nerode Theorem |
2322 arose from the problem of defining formally the regularity of a language. |
2332 %arose from the problem of defining formally the regularity of a language. |
2323 In order to guarantee consistency, |
2333 %In order to guarantee consistency, |
2324 formalisations in HOL can only extend the logic with definitions that introduce a new concept in |
2334 %formalisations in HOL can only extend the logic with definitions that introduce a new concept in |
2325 terms of already existing notions. A convenient definition for automata |
2335 %terms of already existing notions. A convenient definition for automata |
2326 (based on graphs) uses a polymorphic type for the state nodes. This allows |
2336 %(based on graphs) uses a polymorphic type for the state nodes. This allows |
2327 us to use the standard operation for disjoint union whenever we need to compose two |
2337 %us to use the standard operation for disjoint union whenever we need to compose two |
2328 automata. Unfortunately, we cannot use such a polymorphic definition |
2338 %automata. Unfortunately, we cannot use such a polymorphic definition |
2329 in HOL as part of the definition for regularity of a language (a predicate |
2339 %in HOL as part of the definition for regularity of a language (a predicate |
2330 over sets of strings). Consider for example the following attempt: |
2340 %over sets of strings). Consider for example the following attempt: |
2331 |
2341 % |
2332 \begin{center} |
2342 %\begin{center} |
2333 @{text "is_regular A \<equiv> \<exists>M(\<alpha>). is_dfa (M) \<and> \<calL>(M) = A"} |
2343 %@{text "is_regular A \<equiv> \<exists>M(\<alpha>). is_dfa (M) \<and> \<calL>(M) = A"} |
2334 \end{center} |
2344 %\end{center} |
2335 |
2345 % |
2336 \noindent |
2346 %\noindent |
2337 In this definifion, the definiens is polymorphic in the type of the automata |
2347 %In this definifion, the definiens is polymorphic in the type of the automata |
2338 @{text "M"} (indicated by dependency on the type-variable @{text "\<alpha>"}), but the definiendum |
2348 %@{text "M"} (indicated by dependency on the type-variable @{text "\<alpha>"}), but the definiendum |
2339 @{text "is_regular"} is not. Such definitions are excluded from HOL, because |
2349 %@{text "is_regular"} is not. Such definitions are excluded from HOL, because |
2340 they can lead easily to inconsistencies (see \cite{PittsHOL4} for a simple |
2350 %they can lead easily to inconsistencies (see \cite{PittsHOL4} for a simple |
2341 example). Also HOL does not contain type-quantifiers which would allow us to |
2351 %example). Also HOL does not contain type-quantifiers which would allow us to |
2342 get rid of the polymorphism by quantifying over the type-variable @{text |
2352 %get rid of the polymorphism by quantifying over the type-variable |
2343 "\<alpha>"}. Therefore when defining regularity in terms of automata, the |
2353 %@{text "\<alpha>"}. Therefore when defining regularity in terms of automata, the |
2344 natural way out in HOL is to resort to state nodes with an identity, for |
2354 %natural way out in HOL is to resort to state nodes with an identity, for |
2345 example a natural number. Unfortunatly, the consequence is that we have to |
2355 %example a natural number. Unfortunatly, the consequence is that we have to |
2346 be careful when combining two automata so that there is no clash between two |
2356 %be careful when combining two automata so that there is no clash between two |
2347 such states. This makes formalisations quite fiddly and rather |
2357 %such states. This makes formalisations quite fiddly and rather |
2348 unpleasant. Regular expressions proved much more convenient for reasoning in |
2358 %unpleasant. Regular expressions proved much more convenient for reasoning in |
2349 HOL since they can be defined as inductive datatype and a reasoning |
2359 %HOL since they can be defined as inductive datatype and a reasoning |
2350 infrastructure comes for free. The definition of regularity in terms of |
2360 %infrastructure comes for free. The definition of regularity in terms of |
2351 regular expressions poses no problem at all for HOL. We showed in this |
2361 %regular expressions poses no problem at all for HOL. We showed in this |
2352 paper that they can be used for establishing the central result in regular |
2362 %paper that they can be used for establishing the central result in regular |
2353 language theory---the Myhill-Nerode Theorem. |
2363 %language theory---the Myhill-Nerode Theorem. |
2354 |
2364 |
2355 While regular expressions are convenient, they have some limitations. One is |
2365 While regular expressions are convenient, they have some limitations. One is |
2356 that there seems to be no method of calculating a minimal regular expression |
2366 that there seems to be no method of calculating a minimal regular expression |
2357 (for example in terms of length) for a regular language, like there is for |
2367 (for example in terms of length) for a regular language, like there is for |
2358 automata. On the other hand, efficient regular expression matching, without |
2368 automata. On the other hand, efficient regular expression matching, without |
2359 using automata, poses no problem \cite{OwensReppyTuron09}. For an |
2369 using automata, poses no problem as shown by \citeN{OwensReppyTuron09}. For an |
2360 implementation of a simple regular expression matcher, whose correctness has |
2370 implementation of a simple regular expression matcher, whose correctness has |
2361 been formally established, we refer the reader to Owens and Slind |
2371 been formally established, we refer the reader to |
2362 \cite{OwensSlind08}. In our opinion, their formalisation is considerably |
2372 \citeN{OwensSlind08}. In our opinion, their formalisation is considerably |
2363 slicker than for example the approach to regular expression matching taken |
2373 slicker than for example the approach to regular expression matching taken |
2364 in \cite{Harper99} and \cite{Yi06}. |
2374 by \citeN{Harper99} and by \citeN{Yi06}. |
2365 |
2375 |
2366 Our proof of the first direction is very much inspired by \emph{Brzozowski's |
2376 Our proof of the first direction is very much inspired by \emph{Brzozowski's |
2367 algebraic method} used to convert a finite automaton to a regular expression |
2377 algebraic method} \citeyear{Brzozowski64} used to convert a finite automaton to a regular expression. |
2368 \cite{Brzozowski64}. The close connection can be seen by considering the |
2378 The close connection can be seen by considering the |
2369 equivalence classes as the states of the minimal automaton for the regular |
2379 equivalence classes as the states of the minimal automaton for the regular |
2370 language. However there are some subtle differences. Because our equivalence |
2380 language. However there are some subtle differences. Because our equivalence |
2371 classes (or correspondingly states) arise from the Myhill-Nerode Relation, the most natural |
2381 classes (or correspondingly states) arise from the Myhill-Nerode Relation, the most natural |
2372 choice is to characterise each state with the set of strings starting from |
2382 choice is to characterise each state with the set of strings starting from |
2373 the initial state leading up to that state. Usually, however, the states are |
2383 the initial state leading up to that state. Usually, however, the states are |
2381 |
2391 |
2382 We presented two proofs for the second direction of the Myhill-Nerode |
2392 We presented two proofs for the second direction of the Myhill-Nerode |
2383 Theorem. One direct proof using tagging-functions and another using partial |
2393 Theorem. One direct proof using tagging-functions and another using partial |
2384 derivatives. This part of our work is where our method using regular |
2394 derivatives. This part of our work is where our method using regular |
2385 expressions shines, because we can completely side-step the standard |
2395 expressions shines, because we can completely side-step the standard |
2386 argument \cite{Kozen97} where automata need to be composed. However, it is |
2396 argument (for example used by \citeN{Kozen97}) where automata need to be composed. However, it is |
2387 also the direction where we had to spend most of the `conceptual' time, as |
2397 also the direction where we had to spend most of the `conceptual' time, as |
2388 our first proof based on tagging-functions is new for establishing the |
2398 our first proof based on tagging-functions is new for establishing the |
2389 Myhill-Nerode Theorem. All standard proofs of this direction proceed by |
2399 Myhill-Nerode Theorem. All standard proofs of this direction proceed by |
2390 arguments over automata. |
2400 arguments over automata. |
2391 |
2401 |
2392 The indirect proof for the second direction arose from our interest in |
2402 The indirect proof for the second direction arose from our interest in |
2393 Brzozowski's derivatives for regular expression matching. While Brzozowski |
2403 Brzozowski's derivatives for regular expression matching. While \citeN{Brzozowski64} |
2394 already established that there are only |
2404 already established that there are only |
2395 finitely many dissimilar derivatives for every regular expression, this |
2405 finitely many dissimilar derivatives for every regular expression, this |
2396 result is not as straightforward to formalise in a theorem prover as one |
2406 result is not as straightforward to formalise in a theorem prover as one |
2397 might wish. The reason is that the set of dissimilar derivatives is not |
2407 might wish. The reason is that the set of dissimilar derivatives is not |
2398 defined inductively, but in terms of an ACI-equivalence relation. This |
2408 defined inductively, but in terms of an ACI-equivalence relation. This |
2399 difficulty prevented for example Krauss and Nipkow to prove termination of |
2409 difficulty prevented for example \citeN{KraussNipkow11} to prove termination of |
2400 their equivalence checker for regular expressions |
2410 their equivalence checker for regular expressions. Their checker is based on Brzozowski's derivatives |
2401 \cite{KraussNipkow11}. Their checker is based on Brzozowski's derivatives |
|
2402 and for their argument the lack of a formal proof of termination is not |
2411 and for their argument the lack of a formal proof of termination is not |
2403 crucial (it merely lets them ``sleep better'' \cite{KraussNipkow11}). We |
2412 crucial (it merely lets them ``sleep better'' \cite{KraussNipkow11}). We |
2404 expect that their development simplifies by using partial derivatives, |
2413 expect that their development simplifies by using partial derivatives, |
2405 instead of derivatives, and that the termination of the algorithm can be |
2414 instead of derivatives, and that the termination of the algorithm can be |
2406 formally established (the main ingredient is |
2415 formally established (the main ingredient is |
2407 Theorem~\ref{antimirov}). However, since partial derivatives use sets of |
2416 Theorem~\ref{antimirov}). However, since partial derivatives use sets of |
2408 regular expressions, one needs to carefully analyse whether the resulting |
2417 regular expressions, one needs to carefully analyse whether the resulting |
2409 algorithm is still executable. Given the existing infrastructure for |
2418 algorithm is still executable. Given the infrastructure for |
2410 executable sets in Isabelle/HOL \cite{Haftmann09}, it should. |
2419 executable sets introduced by \citeN{Haftmann09} in Isabelle/HOL, it should. |
2411 |
2420 |
2412 Our formalisation of the Myhill-Nerode Theorem consists of 780 lines of |
2421 Our formalisation of the Myhill-Nerode Theorem consists of 780 lines of |
2413 Isabelle/Isar code for the first direction and 460 for the second (the one |
2422 Isabelle/Isar code for the first direction and 460 for the second (the one |
2414 based on tagging-functions), plus around 300 lines of standard material |
2423 based on tagging-functions), plus around 300 lines of standard material |
2415 about regular languages. The formalisation of derivatives and partial |
2424 about regular languages. The formalisation of derivatives and partial |
2416 derivatives shown in Section~\ref{derivatives} consists of 390 lines of |
2425 derivatives shown in Section~\ref{derivatives} consists of 390 lines of |
2417 code. The closure properties in Section~\ref{closure} (except Theorem~\ref{subseqreg}) |
2426 code. The closure properties in Section~\ref{closure} (except Theorem~\ref{subseqreg}) |
2418 can be established in |
2427 can be established in |
2419 190 lines of code. The Continuation Lemma and the non-regularity of @{text "a\<^sup>n b\<^sup>n"} |
2428 100 lines of code. The Continuation Lemma and the non-regularity of @{text "a\<^sup>n b\<^sup>n"} |
2420 require 70 lines of code. |
2429 require 70 lines of code. |
2421 The algorithm for solving equational systems, which we |
2430 The algorithm for solving equational systems, which we |
2422 used in the first direction, is conceptually relatively simple. Still the |
2431 used in the first direction, is conceptually relatively simple. Still the |
2423 use of sets over which the algorithm operates means it is not as easy to |
2432 use of sets over which the algorithm operates means it is not as easy to |
2424 formalise as one might hope. However, it seems sets cannot be avoided since |
2433 formalise as one might hope. However, it seems sets cannot be avoided since |
2425 the `input' of the algorithm consists of equivalence classes and we cannot |
2434 the `input' of the algorithm consists of equivalence classes and we cannot |
2426 see how to reformulate the theory so that we can use lists or matrices. Lists would be |
2435 see how to reformulate the theory so that we can use lists or matrices. Lists would be |
2427 much easier to reason about, since we can define functions over them by |
2436 much easier to reason about, since we can define functions over them by |
2428 recursion. For sets we have to use set-comprehensions, which is slightly |
2437 recursion. For sets we have to use set-comprehensions, which is slightly |
2429 unwieldy. Matrices would allow us to use the slick formalisation by |
2438 unwieldy. Matrices would allow us to use the slick formalisation by |
2430 Nipkow of the Gauss-Jordan algorithm \cite{Nipkow11}. |
2439 \citeN{Nipkow11} of the Gauss-Jordan algorithm. |
2431 |
2440 |
2432 While our formalisation might appear large, it should be seen |
2441 While our formalisation might appear large, it should be seen |
2433 in the context of the work done by Constable at al \cite{Constable00} who |
2442 in the context of the work done by \citeN{Constable00} who |
2434 formalised the Myhill-Nerode Theorem in Nuprl using automata. They write |
2443 formalised the Myhill-Nerode Theorem in Nuprl using automata. They write |
2435 that their four-member team would need something on the magnitude of 18 months |
2444 that their four-member team would need something on the magnitude of 18 months |
2436 for their formalisation of the first eleven chapters of \cite{HopcroftUllman69}, |
2445 for their formalisation of the first eleven chapters of the textbook by \citeN{HopcroftUllman69}, |
2437 which includes the Myhill-Nerode theorem. It is hard to gauge the size of a |
2446 which includes the Myhill-Nerode theorem. It is hard to gauge the size of a |
2438 formalisation in Nurpl, but from what is shown in the Nuprl Math Library |
2447 formalisation in Nurpl, but from what is shown in the Nuprl Math Library |
2439 about their development it seems substantially larger than ours. We attribute |
2448 about their development it seems substantially larger than ours. We attribute |
2440 this to our use of regular expressions, which meant we did not need to `fight' |
2449 this to our use of regular expressions, which meant we did not need to `fight' |
2441 the theorem prover. |
2450 the theorem prover. |
2442 Also, Filli\^atre reports that his formalisation in |
2451 Also, \citeN{Filliatre97} reports that his formalisation in |
2443 Coq of automata theory and Kleene's theorem is ``rather big'' |
2452 Coq of automata theory and Kleene's theorem is ``rather big''. |
2444 \cite{Filliatre97}. More recently, Almeida et al reported about another |
2453 More recently, \citeN{Almeidaetal10} reported about another |
2445 formalisation of regular languages in Coq \cite{Almeidaetal10}. Their |
2454 formalisation of regular languages in Coq. Their |
2446 main result is the |
2455 main result is the |
2447 correctness of Mirkin's construction of an automaton from a regular |
2456 correctness of Mirkin's construction of an automaton from a regular |
2448 expression using partial derivatives. This took approximately 10600 lines |
2457 expression using partial derivatives. This took approximately 10600 lines |
2449 of code. Also Braibant formalised a large part of regular language |
2458 of code. Also \citeN{Braibant12} formalised a large part of regular language |
2450 theory and Kleene algebras in Coq \cite{Braibant12}. While he is mainly interested |
2459 theory and Kleene algebras in Coq. While he is mainly interested |
2451 in implementing decision procedures for Kleene algebras, his library |
2460 in implementing decision procedures for Kleene algebras, his library |
2452 includes a proof of the Myhill-Nerode theorem. He reckons that our |
2461 includes a proof of the Myhill-Nerode theorem. He reckons that our |
2453 ``development is more concise'' than his one based on matrices \cite[Page 67]{Braibant12}. |
2462 ``development is more concise'' than his one based on matrices \cite[Page 67]{Braibant12}. |
2454 In terms of time, the estimate for our formalisation is that we |
2463 In terms of time, the estimate for our formalisation is that we |
2455 needed approximately 3 months and this included the time to find our proof |
2464 needed approximately 3 months and this included the time to find our proof |
2456 arguments. Unlike Constable et al, who were able to follow the Myhill-Nerode |
2465 arguments. Unlike \citeN{Constable00}, who were able to follow the Myhill-Nerode |
2457 proof from \cite{HopcroftUllman69}, we had to find our own arguments. So for us the |
2466 proof by \citeN{HopcroftUllman69}, we had to find our own arguments. So for us the |
2458 formalisation was not the bottleneck. The code of |
2467 formalisation was not the bottleneck. The code of |
2459 our formalisation can be found in the Archive of Formal Proofs at |
2468 our formalisation can be found in the Archive of Formal Proofs at |
2460 \mbox{\url{http://afp.sourceforge.net/entries/Myhill-Nerode.shtml}} |
2469 \mbox{\url{http://afp.sourceforge.net/entries/Myhill-Nerode.shtml}} |
2461 \cite{myhillnerodeafp11}.\medskip |
2470 \cite{myhillnerodeafp11}.\smallskip |
2462 |
2471 |
2463 \noindent |
2472 \noindent |
2464 {\bf Acknowledgements:} |
2473 {\bf Acknowledgements:} |
2465 We are grateful for the comments we received from Larry Paulson. Tobias |
2474 We are grateful for the comments we received from Larry Paulson. Tobias |
2466 Nipkow made us aware of the properties in Theorem~\ref{subseqreg} and Tjark |
2475 Nipkow made us aware of the properties in Theorem~\ref{subseqreg} and Tjark |
2467 Weber helped us with proving them. |
2476 Weber helped us with proving them. Christian Sternagel provided us with a |
2468 |
2477 version of Higman's Lemma that applies to arbtrary, but finite alphabets. |
2469 \bibliographystyle{plain} |
2478 |
|
2479 \bibliographystyle{acmtrans} |
2470 \bibliography{root} |
2480 \bibliography{root} |
2471 |
2481 |
2472 \newpage |
2482 \newpage |
2473 \begin{appendix} |
2483 \begin{appendix} |
2474 \section{Appendix$^\star$} |
2484 \section{Appendix$^\star$} |