Journal/Paper.thy
changeset 178 c6ebfe052109
parent 177 50cc1a39c990
child 179 edacc141060f
equal deleted inserted replaced
177:50cc1a39c990 178:c6ebfe052109
   224 
   224 
   225   \end{tabular}
   225   \end{tabular}
   226   \end{center}
   226   \end{center}
   227 
   227 
   228   \noindent
   228   \noindent
   229   On `paper' or a theorem prover based on set-theory, we can define the corresponding 
   229   On `paper' we can define the corresponding 
   230   graph in terms of the disjoint 
   230   graph in terms of the disjoint 
   231   union of the state nodes. Unfortunately in HOL, the standard definition for disjoint 
   231   union of the state nodes. Unfortunately in HOL, the standard definition for disjoint 
   232   union, namely 
   232   union, namely 
   233   %
   233   %
   234   \begin{equation}\label{disjointunion}
   234   \begin{equation}\label{disjointunion}
   239   changes the type---the disjoint union is not a set, but a set of
   239   changes the type---the disjoint union is not a set, but a set of
   240   pairs. Using this definition for disjoint union means we do not have a
   240   pairs. Using this definition for disjoint union means we do not have a
   241   single type for automata. As a result we will not be able to define a regular
   241   single type for automata. As a result we will not be able to define a regular
   242   language as one for which there exists an automaton that recognises all its
   242   language as one for which there exists an automaton that recognises all its
   243   strings. This is because we cannot make a definition in HOL that is polymorphic in 
   243   strings. This is because we cannot make a definition in HOL that is polymorphic in 
   244   the state type and also there is no type quantification available in HOL (unlike 
   244   the state type and there is no type quantification available in HOL (unlike 
   245   in Coq, for example).
   245   in Coq, for example).
   246 
   246 
   247   An alternative, which provides us with a single type for automata, is to give every 
   247   An alternative, which provides us with a single type for automata, is to give every 
   248   state node an identity, for example a natural
   248   state node an identity, for example a natural
   249   number, and then be careful to rename these identities apart whenever
   249   number, and then be careful to rename these identities apart whenever
   314 
   314 
   315   In this paper, we will not attempt to formalise automata theory in
   315   In this paper, we will not attempt to formalise automata theory in
   316   Isabelle/HOL nor will we attempt to formalise automata proofs from the
   316   Isabelle/HOL nor will we attempt to formalise automata proofs from the
   317   literature, but take a different approach to regular languages than is
   317   literature, but take a different approach to regular languages than is
   318   usually taken. Instead of defining a regular language as one where there
   318   usually taken. Instead of defining a regular language as one where there
   319   exists an automaton that recognises all strings of the language, we define a
   319   exists an automaton that recognises all its strings, we define a
   320   regular language as:
   320   regular language as:
   321 
   321 
   322   \begin{dfntn}
   322   \begin{dfntn}
   323   A language @{text A} is \emph{regular}, provided there is a regular expression that matches all
   323   A language @{text A} is \emph{regular}, provided there is a regular expression that matches all
   324   strings of @{text "A"}.
   324   strings of @{text "A"}.
   327   \noindent
   327   \noindent
   328   The reason is that regular expressions, unlike graphs, matrices and
   328   The reason is that regular expressions, unlike graphs, matrices and
   329   functions, can be easily defined as an inductive datatype. A reasoning
   329   functions, can be easily defined as an inductive datatype. A reasoning
   330   infrastructure (like induction and recursion) comes then for free in
   330   infrastructure (like induction and recursion) comes then for free in
   331   HOL. Moreover, no side-conditions will be needed for regular expressions,
   331   HOL. Moreover, no side-conditions will be needed for regular expressions,
   332   like we usually need for automata. This convenience of regular expressions has
   332   like we need for automata. This convenience of regular expressions has
   333   recently been exploited in HOL4 with a formalisation of regular expression
   333   recently been exploited in HOL4 with a formalisation of regular expression
   334   matching based on derivatives \cite{OwensSlind08} and with an equivalence
   334   matching based on derivatives \cite{OwensSlind08} and with an equivalence
   335   checker for regular expressions in Isabelle/HOL \cite{KraussNipkow11}.  The
   335   checker for regular expressions in Isabelle/HOL \cite{KraussNipkow11}.  The
   336   main purpose of this paper is to show that a central result about regular
   336   main purpose of this paper is to show that a central result about regular
   337   languages---the Myhill-Nerode theorem---can be recreated by only using
   337   languages---the Myhill-Nerode theorem---can be recreated by only using
   348   an argument about solving equational sytems.  This argument appears to be
   348   an argument about solving equational sytems.  This argument appears to be
   349   folklore. For the other part, we give two proofs: one direct proof using
   349   folklore. For the other part, we give two proofs: one direct proof using
   350   certain tagging-functions, and another indirect proof using Antimirov's
   350   certain tagging-functions, and another indirect proof using Antimirov's
   351   partial derivatives \cite{Antimirov95}. Again to our best knowledge, the
   351   partial derivatives \cite{Antimirov95}. Again to our best knowledge, the
   352   tagging-functions have not been used before to establish the Myhill-Nerode
   352   tagging-functions have not been used before to establish the Myhill-Nerode
   353   theorem. Derivatives of regular expressions have been used widely in the
   353   theorem. Derivatives of regular expressions have been recently used quite
   354   literature about regular expressions. However, partial derivatives are more
   354   widely in the literature about regular expressions. However, partial
   355   suitable in the context of the Myhill-Nerode theorem, since it is easier to
   355   derivatives are more suitable in the context of the Myhill-Nerode theorem,
   356   establish formally their finiteness result.
   356   since it is easier to establish formally their finiteness result.
   357 
   357 
   358 *}
   358 *}
   359 
   359 
   360 section {* Preliminaries *}
   360 section {* Preliminaries *}
   361 
   361 
   582   \noindent
   582   \noindent
   583   which means that if we concatenate the character @{text c} to the end of all 
   583   which means that if we concatenate the character @{text c} to the end of all 
   584   strings in the equivalence class @{text Y}, we obtain a subset of 
   584   strings in the equivalence class @{text Y}, we obtain a subset of 
   585   @{text X}. Note that we do not define an automaton here, we merely relate two sets
   585   @{text X}. Note that we do not define an automaton here, we merely relate two sets
   586   (with the help of a character). In our concrete example we have 
   586   (with the help of a character). In our concrete example we have 
   587   @{term "X\<^isub>1 \<Turnstile>c\<Rightarrow> X\<^isub>2"}, @{term "X\<^isub>1 \<Turnstile>d\<Rightarrow> X\<^isub>3"} with @{text d} being any 
   587   @{term "X\<^isub>1 \<Turnstile>c\<Rightarrow> X\<^isub>2"}, @{term "X\<^isub>1 \<Turnstile>d\<^isub>i\<Rightarrow> X\<^isub>3"} with @{text "d\<^isub>i"} being any 
   588   other character than @{text c}, and @{term "X\<^isub>3 \<Turnstile>d\<Rightarrow> X\<^isub>3"} for any @{text d}.
   588   other character than @{text c}, and @{term "X\<^isub>3 \<Turnstile>c\<^isub>j\<Rightarrow> X\<^isub>3"} for any 
       
   589   caracter @{text "c\<^isub>j"}.
   589   
   590   
   590   Next we construct an \emph{initial equational system} that
   591   Next we construct an \emph{initial equational system} that
   591   contains an equation for each equivalence class. We first give
   592   contains an equation for each equivalence class. We first give
   592   an informal description of this construction. Suppose we have 
   593   an informal description of this construction. Suppose we have 
   593   the equivalence classes @{text "X\<^isub>1,\<dots>,X\<^isub>n"}, there must be one and only one that
   594   the equivalence classes @{text "X\<^isub>1,\<dots>,X\<^isub>n"}, there must be one and only one that
   638   \end{equation}
   639   \end{equation}
   639   
   640   
   640   \noindent
   641   \noindent
   641   where @{text "d\<^isub>1\<dots>d\<^isub>n"} is the sequence of all characters
   642   where @{text "d\<^isub>1\<dots>d\<^isub>n"} is the sequence of all characters
   642   except @{text c}, and @{text "c\<^isub>1\<dots>c\<^isub>m"} is the sequence of all
   643   except @{text c}, and @{text "c\<^isub>1\<dots>c\<^isub>m"} is the sequence of all
   643   characters.  In our initial equation systems there can only be finitely many
   644   characters.  
   644   terms of the form @{text "(Y\<^isub>i\<^isub>j, ATOM c\<^isub>i\<^isub>j)"},
       
   645   since by assumption there are only finitely many equivalence classes and
       
   646   only finitely many characters.
       
   647 
   645 
   648   Overloading the function @{text \<calL>} for the two kinds of terms in the
   646   Overloading the function @{text \<calL>} for the two kinds of terms in the
   649   equational system, we have
   647   equational system, we have
   650   
   648   
   651   \begin{center}
   649   \begin{center}
   743 
   741 
   744   \noindent
   742   \noindent
   745   In this definition, we first delete all terms of the form @{text "(X, r)"} from @{text rhs};
   743   In this definition, we first delete all terms of the form @{text "(X, r)"} from @{text rhs};
   746   then we calculate the combined regular expressions for all @{text r} coming 
   744   then we calculate the combined regular expressions for all @{text r} coming 
   747   from the deleted @{text "(X, r)"}, and take the @{const Star} of it;
   745   from the deleted @{text "(X, r)"}, and take the @{const Star} of it;
   748   finally we append this regular expression to @{text rhs'}. It can be easily seen 
   746   finally we append this regular expression to @{text rhs'}. If we apply this
   749   that this operation mimics Arden's Lemma on the level of equations. To ensure
   747   operation to the right-hand side of @{text "X\<^isub>3"} in \eqref{exmpcs}, we obtain
   750   the non-emptiness condition of Arden's Lemma we say that a right-hand side is
   748   the equation:
   751   @{text ardenable} provided
   749 
       
   750   \begin{center}
       
   751   \begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l}
       
   752   @{term "X\<^isub>3"} & @{text "="} & 
       
   753     @{text "(X\<^isub>1, TIMES (ATOM d\<^isub>1) (STAR \<^raw:\ensuremath{\bigplus}>{ATOM c\<^isub>1,\<dots>,ATOM c\<^isub>m})) + \<dots> "}\\
       
   754   & & \mbox{}\hspace{13mm}
       
   755      @{text "\<dots> + (X\<^isub>1, TIMES (ATOM d\<^isub>n) (STAR \<^raw:\ensuremath{\bigplus}>{ATOM c\<^isub>1,\<dots>,ATOM c\<^isub>m}))"}
       
   756   \end{tabular}
       
   757   \end{center}
       
   758 
       
   759 
       
   760   \noindent
       
   761   That means we eliminated the dependency of @{text "X\<^isub>3"} on the
       
   762   right-hand side.  Note we used the abbreviation 
       
   763   @{text "\<^raw:\ensuremath{\bigplus}>{ATOM c\<^isub>1,\<dots>,ATOM c\<^isub>m}"} 
       
   764   to stand for a regular expression that matches with every character. In 
       
   765   our algorithm we are only interested in the existence of such a regular expresion
       
   766   and not specify it any further. 
       
   767 
       
   768   It can be easily seen that the @{text "Arden"}-operation mimics Arden's
       
   769   Lemma on the level of equations. To ensure the non-emptiness condition of
       
   770   Arden's Lemma we say that a right-hand side is @{text ardenable} provided
   752 
   771 
   753   \begin{center}
   772   \begin{center}
   754   @{thm ardenable_def}
   773   @{thm ardenable_def}
   755   \end{center}
   774   \end{center}
   756 
   775 
   783   \noindent
   802   \noindent
   784   We again delete first all occurrences of @{text "(X, r)"} in @{text rhs}; we then calculate
   803   We again delete first all occurrences of @{text "(X, r)"} in @{text rhs}; we then calculate
   785   the regular expression corresponding to the deleted terms; finally we append this
   804   the regular expression corresponding to the deleted terms; finally we append this
   786   regular expression to @{text "xrhs"} and union it up with @{text rhs'}. When we use
   805   regular expression to @{text "xrhs"} and union it up with @{text rhs'}. When we use
   787   the substitution operation we will arrange it so that @{text "xrhs"} does not contain
   806   the substitution operation we will arrange it so that @{text "xrhs"} does not contain
   788   any occurrence of @{text X}.
   807   any occurrence of @{text X}. For example substituting the first equation in
       
   808   \eqref{exmpcs} into the right-hand side of the second, thus eliminating the equivalence 
       
   809   class @{text "X\<^isub>1"}, gives us the equation
       
   810 
       
   811   \begin{equation}\label{exmpresult}
       
   812   \mbox{\begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l}
       
   813   @{term "X\<^isub>2"} & @{text "="} & @{text "\<lambda>(TIMES ONE (ATOM c))"}\\
       
   814   \end{tabular}}
       
   815   \end{equation}
   789 
   816 
   790   With these two operations in place, we can define the operation that removes one equation
   817   With these two operations in place, we can define the operation that removes one equation
   791   from an equational systems @{text ES}. The operation @{const Subst_all}
   818   from an equational systems @{text ES}. The operation @{const Subst_all}
   792   substitutes an equation @{text "X = xrhs"} throughout an equational system @{text ES}; 
   819   substitutes an equation @{text "X = xrhs"} throughout an equational system @{text ES}; 
   793   @{const Remove} then completely removes such an equation from @{text ES} by substituting 
   820   @{const Remove} then completely removes such an equation from @{text ES} by substituting