Journal/Paper.thy
changeset 381 99161cd17c0f
parent 379 8c4b6fb43ebe
child 383 c8cb6914f4c8
equal deleted inserted replaced
380:c028b07a4fa8 381:99161cd17c0f
   561   "\<lbrakk>x\<rbrakk>\<^isub>\<approx> = \<lbrakk>y\<rbrakk>\<^isub>\<approx>"}.
   561   "\<lbrakk>x\<rbrakk>\<^isub>\<approx> = \<lbrakk>y\<rbrakk>\<^isub>\<approx>"}.
   562 
   562 
   563 
   563 
   564   Central to our proof will be the solution of equational systems
   564   Central to our proof will be the solution of equational systems
   565   involving equivalence classes of languages. For this we will use Arden's Lemma 
   565   involving equivalence classes of languages. For this we will use Arden's Lemma 
   566   (see for example \cite[Page 100]{Sakarovitch09}),
   566   (see for example \citet[Page 100]{Sakarovitch09}),
   567   which solves equations of the form @{term "X = A \<cdot> X \<union> B"} provided
   567   which solves equations of the form @{term "X = A \<cdot> X \<union> B"} provided
   568   @{term "[] \<notin> A"}. However we will need the following `reversed' 
   568   @{term "[] \<notin> A"}. However we will need the following `reversed' 
   569   version of Arden's Lemma (`reversed' in the sense of changing the order of @{term "A \<cdot> X"} to
   569   version of Arden's Lemma (`reversed' in the sense of changing the order of @{term "A \<cdot> X"} to
   570   \mbox{@{term "X \<cdot> A"}}).
   570   \mbox{@{term "X \<cdot> A"}}).
   571   %\footnote{The details of the proof for the reversed Arden's Lemma
   571   %\footnote{The details of the proof for the reversed Arden's Lemma
   657 
   657 
   658   \noindent
   658   \noindent
   659   It is easy to see that @{term "\<approx>A"} is an equivalence relation, which
   659   It is easy to see that @{term "\<approx>A"} is an equivalence relation, which
   660   partitions the set of all strings, @{text "UNIV"}, into a set of disjoint
   660   partitions the set of all strings, @{text "UNIV"}, into a set of disjoint
   661   equivalence classes. To illustrate this quotient construction, let us give a simple 
   661   equivalence classes. To illustrate this quotient construction, let us give a simple 
   662   example: consider the regular language containing just
   662   example: consider the regular language built up over the alphabet @{term "{a, b}"} and 
   663   the string @{text "[c]"}. The relation @{term "\<approx>({[c]})"} partitions @{text UNIV}
   663   containing just the string two strings @{text "[a]"} and @{text "[a, b]"}. The 
   664   into three equivalence classes @{text "X\<^isub>1"}, @{text "X\<^isub>2"} and  @{text "X\<^isub>3"}
   664   relation @{term "\<approx>({[a], [a, b]})"} partitions @{text UNIV}
       
   665   into four equivalence classes @{text "X\<^isub>1"}, @{text "X\<^isub>2"}, @{text "X\<^isub>3"} and @{text "X\<^isub>4"}
   665   as follows
   666   as follows
   666   
   667   
   667   \begin{center}
   668   \begin{center}
   668   \begin{tabular}{l}
   669   \begin{tabular}{l}
   669   @{text "X\<^isub>1 = {[]}"}\\
   670   @{text "X\<^isub>1 = {[]}"}\\
   670   @{text "X\<^isub>2 = {[c]}"}\\
   671   @{text "X\<^isub>2 = {[a]}"}\\
   671   @{text "X\<^isub>3 = UNIV - {[], [c]}"}
   672   @{text "X\<^isub>3 = {[a, b]}"}\\
       
   673   @{text "X\<^isub>4 = UNIV - {[], [a], [a, b]}"}
   672   \end{tabular}
   674   \end{tabular}
   673   \end{center}
   675   \end{center}
   674 
   676 
   675   One direction of the Myhill-Nerode Theorem establishes 
   677   One direction of the Myhill-Nerode Theorem establishes 
   676   that if there are finitely many equivalence classes, like in the example above, then 
   678   that if there are finitely many equivalence classes, like in the example above, then 
   687   \begin{equation} 
   689   \begin{equation} 
   688   @{thm finals_def}
   690   @{thm finals_def}
   689   \end{equation}
   691   \end{equation}
   690 
   692 
   691   \noindent
   693   \noindent
   692   In our running example, @{text "X\<^isub>2"} is the only 
   694   In our running example, @{text "X\<^isub>2"} and @{text "X\<^isub>3"} are the only 
   693   equivalence class in @{term "finals {[c]}"}.
   695   equivalence classes in @{term "finals {[a], [a, b]}"}.
   694   It is straightforward to show that in general 
   696   It is straightforward to show that in general 
   695   %
   697   %
   696   \begin{equation}\label{finalprops}
   698   \begin{equation}\label{finalprops}
   697   @{thm lang_is_union_of_finals}\hspace{15mm} 
   699   @{thm lang_is_union_of_finals}\hspace{15mm} 
   698   @{thm finals_in_partitions} 
   700   @{thm finals_in_partitions} 
   721   strings in the equivalence class @{text Y}, we obtain a subset of 
   723   strings in the equivalence class @{text Y}, we obtain a subset of 
   722   @{text X}. 
   724   @{text X}. 
   723   %Note that we do not define formally an automaton here, 
   725   %Note that we do not define formally an automaton here, 
   724   %we merely relate two sets
   726   %we merely relate two sets
   725   %(with the help of a character). 
   727   %(with the help of a character). 
   726   In our concrete example we have 
   728   In our concrete example we have
   727   @{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 
   729 
   728   other character than @{text c}, and @{term "X\<^isub>3 \<Turnstile>c\<^isub>j\<Rightarrow> X\<^isub>3"} for any 
   730   \begin{center} 
   729   character @{text "c\<^isub>j"}.
   731   \begin{tabular}{l}
       
   732   @{term "X\<^isub>1 \<Turnstile>a\<Rightarrow> X\<^isub>2"},\; @{term "X\<^isub>1 \<Turnstile>b\<Rightarrow> X\<^isub>4"};\\ 
       
   733   @{term "X\<^isub>2 \<Turnstile>b\<Rightarrow> X\<^isub>3"},\; @{term "X\<^isub>2 \<Turnstile>a\<Rightarrow> X\<^isub>4"};\\
       
   734   @{term "X\<^isub>3 \<Turnstile>a\<Rightarrow> X\<^isub>4"},\; @{term "X\<^isub>3 \<Turnstile>b\<Rightarrow> X\<^isub>4"} and\\ 
       
   735   @{term "X\<^isub>4 \<Turnstile>a\<Rightarrow> X\<^isub>4"},\; @{term "X\<^isub>4 \<Turnstile>b\<Rightarrow> X\<^isub>4"}.
       
   736   \end{tabular}
       
   737   \end{center}
   730   
   738   
   731   Next we construct an \emph{initial equational system} that
   739   Next we construct an \emph{initial equational system} that
   732   contains an equation for each equivalence class. We first give
   740   contains an equation for each equivalence class. We first give
   733   an informal description of this construction. Suppose we have 
   741   an informal description of this construction. Suppose we have 
   734   the equivalence classes @{text "X\<^isub>1,\<dots>,X\<^isub>n"}, there must be one and only one that
   742   the equivalence classes @{text "X\<^isub>1,\<dots>,X\<^isub>n"}, there must be one and only one that
   771   In our running example we have the initial equational system
   779   In our running example we have the initial equational system
   772   %
   780   %
   773   \begin{equation}\label{exmpcs}
   781   \begin{equation}\label{exmpcs}
   774   \mbox{\begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l}
   782   \mbox{\begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l}
   775   @{term "X\<^isub>1"} & @{text "="} & @{text "\<lambda>(ONE)"}\\
   783   @{term "X\<^isub>1"} & @{text "="} & @{text "\<lambda>(ONE)"}\\
   776   @{term "X\<^isub>2"} & @{text "="} & @{text "(X\<^isub>1, ATOM c)"}\\
   784   @{term "X\<^isub>2"} & @{text "="} & @{text "(X\<^isub>1, ATOM a)"}\\
   777   @{term "X\<^isub>3"} & @{text "="} & @{text "(X\<^isub>1, ATOM d\<^isub>1) + \<dots> + (X\<^isub>1, ATOM d\<^isub>n)"}\\
   785   @{term "X\<^isub>3"} & @{text "="} & @{text "(X\<^isub>2, ATOM b)"}\\
   778                & & \mbox{}\hspace{10mm}@{text "+ (X\<^isub>3, ATOM c\<^isub>1) + \<dots> + (X\<^isub>3, ATOM c\<^isub>m)"}
   786   @{term "X\<^isub>4"} & @{text "="} & @{text "(X\<^isub>1, ATOM b) + (X\<^isub>2, ATOM a) + (X\<^isub>3, ATOM a)"}\\
       
   787           & & \mbox{}\hspace{0mm}@{text "+ (X\<^isub>3, ATOM b) + (X\<^isub>4, ATOM a) + (X\<^isub>4, ATOM b)"}\\
   779   \end{tabular}}
   788   \end{tabular}}
   780   \end{equation}
   789   \end{equation}
   781   
   790 
   782   \noindent
   791   \noindent
   783   where @{text "d\<^isub>1\<dots>d\<^isub>n"} is the sequence of all characters
       
   784   but not containing @{text c}, and @{text "c\<^isub>1\<dots>c\<^isub>m"} is the sequence of all
       
   785   characters.  
       
   786 
       
   787   Overloading the function @{text \<calL>} for the two kinds of terms in the
   792   Overloading the function @{text \<calL>} for the two kinds of terms in the
   788   equational system, we have
   793   equational system, we have
   789   
   794   
   790   \begin{center}
   795   \begin{center}
   791   @{text "\<calL>(Y, r) \<equiv>"} %
   796   @{text "\<calL>(Y, r) \<equiv>"} %
   881   \noindent
   886   \noindent
   882   In this definition, we first delete all terms of the form @{text "(X, r)"} from @{text rhs};
   887   In this definition, we first delete all terms of the form @{text "(X, r)"} from @{text rhs};
   883   then we calculate the combined regular expressions for all @{text r} coming 
   888   then we calculate the combined regular expressions for all @{text r} coming 
   884   from the deleted @{text "(X, r)"}, and take the @{const Star} of it;
   889   from the deleted @{text "(X, r)"}, and take the @{const Star} of it;
   885   finally we append this regular expression to @{text rhs'}. If we apply this
   890   finally we append this regular expression to @{text rhs'}. If we apply this
   886   operation to the right-hand side of @{text "X\<^isub>3"} in \eqref{exmpcs}, we obtain
   891   operation to the right-hand side of @{text "X\<^isub>4"} in \eqref{exmpcs}, we obtain
   887   the equation:
   892   the equation:
   888 
   893 
   889   \begin{center}
   894   \begin{center}
   890   \begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l}
   895   \begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l}
   891   @{term "X\<^isub>3"} & @{text "="} & 
   896   @{term "X\<^isub>4"} & @{text "="} & 
   892     @{text "(X\<^isub>1, TIMES (ATOM d\<^isub>1) (STAR \<^raw:\ensuremath{\bigplus}>{ATOM c\<^isub>1,\<dots>, ATOM c\<^isub>m})) + \<dots> "}\\
   897     @{text "(X\<^isub>1, TIMES (ATOM b) (STAR \<^raw:\ensuremath{\bigplus}>{ATOM a, ATOM b})) +"}\\
   893   & & \mbox{}\hspace{13mm}
   898   & & @{text "(X\<^isub>2, TIMES (ATOM a) (STAR \<^raw:\ensuremath{\bigplus}>{ATOM a, ATOM b})) +"}\\
   894      @{text "\<dots> + (X\<^isub>1, TIMES (ATOM d\<^isub>n) (STAR \<^raw:\ensuremath{\bigplus}>{ATOM c\<^isub>1,\<dots>, ATOM c\<^isub>m}))"}
   899   & & @{text "(X\<^isub>3, TIMES (ATOM a) (STAR \<^raw:\ensuremath{\bigplus}>{ATOM a, ATOM b})) +"}\\
       
   900   & & @{text "(X\<^isub>3, TIMES (ATOM b) (STAR \<^raw:\ensuremath{\bigplus}>{ATOM a, ATOM b}))"}
   895   \end{tabular}
   901   \end{tabular}
   896   \end{center}
   902   \end{center}
   897 
   903 
   898 
   904 
   899   \noindent
   905   \noindent
   900   That means we eliminated the recursive occurrence of @{text "X\<^isub>3"} on the
   906   That means we eliminated the recursive occurrence of @{text "X\<^isub>4"} on the
   901   right-hand side.  Note we used the abbreviation 
   907   right-hand side. 
   902   @{text "\<^raw:\ensuremath{\bigplus}>{ATOM c\<^isub>1,\<dots>, ATOM c\<^isub>m}"} 
       
   903   to stand for a regular expression that matches with every character. In 
       
   904   our algorithm we are only interested in the existence of such a regular expression
       
   905   and do not specify it any further. 
       
   906 
   908 
   907   It can be easily seen that the @{text "Arden"}-operation mimics Arden's
   909   It can be easily seen that the @{text "Arden"}-operation mimics Arden's
   908   Lemma on the level of equations. To ensure the non-emptiness condition of
   910   Lemma on the level of equations. To ensure the non-emptiness condition of
   909   Arden's Lemma we say that a right-hand side is @{text ardenable} provided
   911   Arden's Lemma we say that a right-hand side is @{text ardenable} provided
   910 
   912 
   949   \eqref{exmpcs} into the right-hand side of the second, thus eliminating the equivalence 
   951   \eqref{exmpcs} into the right-hand side of the second, thus eliminating the equivalence 
   950   class @{text "X\<^isub>1"}, gives us the equation
   952   class @{text "X\<^isub>1"}, gives us the equation
   951   %
   953   %
   952   \begin{equation}\label{exmpresult}
   954   \begin{equation}\label{exmpresult}
   953   \mbox{\begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l}
   955   \mbox{\begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l}
   954   @{term "X\<^isub>2"} & @{text "="} & @{text "\<lambda>(TIMES ONE (ATOM c))"}
   956   @{term "X\<^isub>2"} & @{text "="} & @{text "\<lambda>(TIMES ONE (ATOM a))"}
   955   \end{tabular}}
   957   \end{tabular}}
   956   \end{equation}
   958   \end{equation}
   957 
   959 
   958   With these two operations in place, we can define the operation that removes one equation
   960   With these two operations in place, we can define the operation that removes one equation
   959   from an equational systems @{text ES}. The operation @{const Subst_all}
   961   from an equational systems @{text ES}. The operation @{const Subst_all}
  1192   Lemma~\ref{every_eqcl_has_reg} allows us to finally give a proof for the first direction
  1194   Lemma~\ref{every_eqcl_has_reg} allows us to finally give a proof for the first direction
  1193   of the Myhill-Nerode Theorem.
  1195   of the Myhill-Nerode Theorem.
  1194 
  1196 
  1195   \begin{proof}[of Theorem~\ref{myhillnerodeone}]
  1197   \begin{proof}[of Theorem~\ref{myhillnerodeone}]
  1196   By Lemma~\ref{every_eqcl_has_reg} we know that there exists a regular expression for
  1198   By Lemma~\ref{every_eqcl_has_reg} we know that there exists a regular expression for
  1197   every equivalence class in @{term "UNIV // \<approx>A"}. Since @{text "finals A"} is
  1199   every equivalence class in @{term "UNIV // \<approx>A"}:
       
  1200 
       
  1201   \[
       
  1202   \mbox{if}\;@{term "X \<in> (UNIV // \<approx>A)"}\;\mbox{then there exists a}\; 
       
  1203   @{text "r"}\;\mbox{such that}\;@{term "X = lang r"}
       
  1204   \]\smallskip
       
  1205 
       
  1206   \noindent
       
  1207   Since @{text "finals A"} is
  1198   a subset of  @{term "UNIV // \<approx>A"}, we also know that for every equivalence class
  1208   a subset of  @{term "UNIV // \<approx>A"}, we also know that for every equivalence class
  1199   in @{term "finals A"} there exists a regular expression. Moreover by assumption 
  1209   in @{term "finals A"} there exists a regular expression. Moreover by assumption 
  1200   we know that @{term "finals A"} must be finite, and therefore there must be a finite
  1210   we know that @{term "finals A"} must be finite, and therefore there must be a finite
  1201   set of regular expressions @{text "rs"} such that
  1211   set of regular expressions @{text "rs"} such that
  1202   @{term "\<Union>(finals A) = lang (\<Uplus>rs)"}.
  1212   @{term "\<Union>(finals A) = lang (\<Uplus>rs)"}.
  1203   Since the left-hand side is equal to @{text A}, we can use @{term "\<Uplus>rs"} 
  1213   Since the left-hand side is equal to @{text A}, we can use @{term "\<Uplus>rs"} 
  1204   as the regular expression that is needed in the theorem.
  1214   as the regular expression that is needed in the theorem.
  1205   \end{proof}
  1215   \end{proof}
  1206 
  1216 
  1207   \noindent
  1217   \noindent
       
  1218   Solving the equational system of our running example gives as solution for the 
       
  1219   two final equivalence classes:
       
  1220 
       
  1221   \begin{center}
       
  1222   \begin{tabular}{r@ {\hspace{1mm}}c@ {\hspace{1mm}}l}
       
  1223   @{text "X\<^isub>2"} & @{text "="} & @{text "TIMES ONE (ATOM a)"}\\
       
  1224   @{text "X\<^isub>3"} & @{text "="} & @{text "TIMES (TIMES ONE (ATOM a)) (ATOM b)"}
       
  1225   \end{tabular}
       
  1226   \end{center}
       
  1227 
       
  1228   \noindent
       
  1229   Combining them with $\bigplus$ gives us a regular expression for the language @{text "{[a], [a, b]}"}.
       
  1230 
  1208   Note that our algorithm for solving equational systems provides also a method for
  1231   Note that our algorithm for solving equational systems provides also a method for
  1209   calculating a regular expression for the complement of a regular language:
  1232   calculating a regular expression for the complement of a regular language:
  1210   if we combine all regular
  1233   if we combine all regular
  1211   expressions corresponding to equivalence classes not in @{term "finals A"},
  1234   expressions corresponding to equivalence classes not in @{term "finals A"} 
       
  1235   (in the running example @{text "X\<^isub>1"} and @{text "X\<^isub>4"}),
  1212   then we obtain a regular expression for the complement language @{term "- A"}.
  1236   then we obtain a regular expression for the complement language @{term "- A"}.
  1213   This is similar to the usual construction of a `complement automaton'.
  1237   This is similar to the usual construction of a `complement automaton'.
       
  1238 
  1214 *}
  1239 *}
  1215 
  1240 
  1216 section {* Myhill-Nerode, Second Part *}
  1241 section {* Myhill-Nerode, Second Part *}
  1217 
  1242 
  1218 text {*
  1243 text {*
  1294   provided @{text "R\<^isub>1 \<subseteq> R\<^isub>2"}. 
  1319   provided @{text "R\<^isub>1 \<subseteq> R\<^isub>2"}. 
  1295   \end{definition}
  1320   \end{definition}
  1296 
  1321 
  1297   \noindent
  1322   \noindent
  1298   For constructing @{text R}, we will rely on some \emph{tagging-functions}
  1323   For constructing @{text R}, we will rely on some \emph{tagging-functions}
  1299   defined over strings. Given the inductive hypothesis, it will be easy to
  1324   defined over strings, see Fig.~\ref{tagfig}. They are parameterised by sets
       
  1325   of strings @{text A} and @{text B} standing for the induction hypotheses.
       
  1326   Given the inductive hypotheses, it will be easy to
  1300   prove that the \emph{range} of these tagging-functions is finite. The range
  1327   prove that the \emph{range} of these tagging-functions is finite. The range
  1301   of a function @{text f} is defined as
  1328   of a function @{text f} is defined as
  1302 
  1329 
       
  1330  
  1303   \begin{center}
  1331   \begin{center}
  1304   @{text "range f \<equiv> f ` UNIV"}
  1332   @{text "range f \<equiv> f ` UNIV"}
  1305   \end{center}
  1333   \end{center}
  1306 
  1334 
  1307   \noindent
  1335   \noindent
  1331 
  1359 
  1332   \noindent
  1360   \noindent
  1333   It states that if an image of a set under an injective function @{text f} (injective over this set) 
  1361   It states that if an image of a set under an injective function @{text f} (injective over this set) 
  1334   is finite, then the set @{text A} itself must be finite. We can use it to establish the following 
  1362   is finite, then the set @{text A} itself must be finite. We can use it to establish the following 
  1335   two lemmas.
  1363   two lemmas.
       
  1364 
       
  1365   \begin{figure}[t]
       
  1366   \normalsize
       
  1367   \begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l}
       
  1368   @{thm (lhs) tag_Plus_def[where A="A" and B="B", THEN meta_eq_app]} &
       
  1369   @{text "\<equiv>"} &
       
  1370   @{thm (rhs) tag_Plus_def[where A="A" and B="B", THEN meta_eq_app]} \\
       
  1371   @{thm (lhs) tag_Times_def[where ?A="A" and ?B="B"]}\;@{text "x"} & @{text "\<equiv>"} &
       
  1372   @{text "(\<lbrakk>x\<rbrakk>\<^bsub>\<approx>A\<^esub>, {\<lbrakk>x\<^isub>s\<rbrakk>\<^bsub>\<approx>B\<^esub> | x\<^isub>p \<in> A \<and> (x\<^isub>p, x\<^isub>s) \<in> Partitions x})"}\\
       
  1373   @{thm (lhs) tag_Star_def[where ?A="A", THEN meta_eq_app]} & @{text "\<equiv>"} &
       
  1374   @{text "{\<lbrakk>x\<^isub>s\<rbrakk>\<^bsub>\<approx>A\<^esub> | x\<^isub>p < x \<and> x\<^isub>p \<in> A\<^isup>\<star> \<and> (x\<^isub>p, x\<^isub>s) \<in> Partitions x}"}
       
  1375   \end{tabular}
       
  1376   \caption{Three tagging functions used the cases for @{term "PLUS"}, @{term "TIMES"} and @{term "STAR"} 
       
  1377   regular expressions. The sets @{text A} and @{text B} are arbitrary languages instantiated
       
  1378   in the proof with the induction hypotheses. \emph{Partitions} is a function
       
  1379   that generates all possible partitions of a string.\label{tagfig}}
       
  1380   \end{figure}
       
  1381 
  1336 
  1382 
  1337   \begin{lemma}\label{finone}
  1383   \begin{lemma}\label{finone}
  1338   @{thm[mode=IfThen] finite_eq_tag_rel}
  1384   @{thm[mode=IfThen] finite_eq_tag_rel}
  1339   \end{lemma}
  1385   \end{lemma}
  1340 
  1386 
  1377 
  1423 
  1378   \noindent
  1424   \noindent
  1379   Chaining Lemma~\ref{finone} and \ref{fintwo} together, means in order to show
  1425   Chaining Lemma~\ref{finone} and \ref{fintwo} together, means in order to show
  1380   that @{term "UNIV // \<approx>(lang r)"} is finite, we have to construct a tagging-function whose
  1426   that @{term "UNIV // \<approx>(lang r)"} is finite, we have to construct a tagging-function whose
  1381   range can be shown to be finite and whose tagging-relation refines @{term "\<approx>(lang r)"}.
  1427   range can be shown to be finite and whose tagging-relation refines @{term "\<approx>(lang r)"}.
  1382   Let us attempt the @{const PLUS}-case first. We take as tagging-function 
  1428   Let us attempt the @{const PLUS}-case first. We take as tagging-function from Fig.~\ref{tagfig}
  1383  
  1429  
  1384   \begin{center}
  1430   \begin{center}
  1385   @{thm tag_Plus_def[where A="A" and B="B", THEN meta_eq_app]}
  1431   @{thm tag_Plus_def[where A="A" and B="B", THEN meta_eq_app]}
  1386   \end{center}
  1432   \end{center}
  1387 
  1433 
  1508   This will solve the second case.
  1554   This will solve the second case.
  1509   Taking the two requirements, @{text "("}@{text "*"}@{text ")"} and @{text "(**)"}, together we define the
  1555   Taking the two requirements, @{text "("}@{text "*"}@{text ")"} and @{text "(**)"}, together we define the
  1510   tagging-function in the @{const Times}-case as:
  1556   tagging-function in the @{const Times}-case as:
  1511 
  1557 
  1512   \begin{center}
  1558   \begin{center}
  1513   @{thm (lhs) tag_Times_def[where ?A="A" and ?B="B"]}~@{text "\<equiv>"}~
  1559   @{thm (lhs) tag_Times_def[where ?A="A" and ?B="B"]}\;@{text "x"}~@{text "\<equiv>"}~
  1514   @{text "(\<lbrakk>x\<rbrakk>\<^bsub>\<approx>A\<^esub>, {\<lbrakk>x\<^isub>s\<rbrakk>\<^bsub>\<approx>B\<^esub> | x\<^isub>p \<in> A \<and> (x\<^isub>p, x\<^isub>s) \<in> Partitions x})"}
  1560   @{text "(\<lbrakk>x\<rbrakk>\<^bsub>\<approx>A\<^esub>, {\<lbrakk>x\<^isub>s\<rbrakk>\<^bsub>\<approx>B\<^esub> | x\<^isub>p \<in> A \<and> (x\<^isub>p, x\<^isub>s) \<in> Partitions x})"}
  1515   \end{center}
  1561   \end{center}
  1516 
  1562 
  1517   \noindent
  1563   \noindent
  1518   Note that we have to make the assumption for all suffixes @{text "x\<^isub>s"}, since we do 
  1564   Note that we have to make the assumption for all suffixes @{text "x\<^isub>s"}, since we do 
  1677   "y\<^isub>s @ z\<^isub>a \<in> A"}. We also know that @{term "z\<^isub>b \<in> A\<star>"}.
  1723   "y\<^isub>s @ z\<^isub>a \<in> A"}. We also know that @{term "z\<^isub>b \<in> A\<star>"}.
  1678   Therefore @{term "y\<^isub>p @ (y\<^isub>s @ z\<^isub>a) @ z\<^isub>b \<in>
  1724   Therefore @{term "y\<^isub>p @ (y\<^isub>s @ z\<^isub>a) @ z\<^isub>b \<in>
  1679   A\<star>"}, which means @{term "y @ z \<in> A\<star>"}. The last step is to set
  1725   A\<star>"}, which means @{term "y @ z \<in> A\<star>"}. The last step is to set
  1680   @{text "A"} to @{term "lang r"} and thus complete the proof.
  1726   @{text "A"} to @{term "lang r"} and thus complete the proof.
  1681   \end{proof}
  1727   \end{proof}
       
  1728 
       
  1729   \begin{rmk}
       
  1730   While our proof using tagging functions might seem like a rabbit pulled 
       
  1731   out of a hat, the intuition behind can be rationalised taking the 
       
  1732   view that the equivalence classes @{term "UNIV // \<approx>(lang r)"} stand for the 
       
  1733   states of the minimal automaton for the language @{term "lang r"}. The theorem 
       
  1734   amounts to showing that this minimal automaton has finitely many states. 
       
  1735   However, by showing that our @{text "\<^raw:$\threesim$>\<^bsub>tag\<^esub>"} relation 
       
  1736   refines @{term "\<approx>A"} we do not actually have to show that the minimal automata
       
  1737   has finitely many states, but only that we can show finiteness for an 
       
  1738   automaton with at least as many states and which can recognise the same 
       
  1739   language. By performing the induction over the regular expression @{text r},
       
  1740   this means we have to construct inductively an automaton in
       
  1741   the cases for @{term PLUS}, @{term TIMES} and @{term STAR}.
       
  1742 
       
  1743   In the @{text PLUS}-case, we can assume finitely many equivalence classes of the form
       
  1744   @{text "\<lbrakk>_\<rbrakk>\<^bsub>\<approx>A\<^esub>"} and @{text "\<lbrakk>_\<rbrakk>\<^bsub>\<approx>B\<^esub>"}, each standing for an automaton recognising the 
       
  1745   languages @{text A} and @{text B} respectively. 
       
  1746   The @{text "+tag"} function constructs pairs of the form @{text "(\<lbrakk>_\<rbrakk>\<^bsub>\<approx>A\<^esub>, \<lbrakk>_\<rbrakk>\<^bsub>\<approx>B\<^esub>)"} 
       
  1747   which can be seen as the states of an automaton recognising the language 
       
  1748   \mbox{@{term "A \<union> B"}}. This is the usual product construction of automata: 
       
  1749   Given a string @{text x}, the first automata will be in the state  @{text "\<lbrakk>x\<rbrakk>\<^bsub>\<approx>A\<^esub>"}
       
  1750   after recognising @{text x} (similarly @{text "\<lbrakk>x\<rbrakk>\<^bsub>\<approx>B\<^esub>"} for the other automaton). The product
       
  1751   automaton will be in the state \mbox{@{text "(\<lbrakk>x\<rbrakk>\<^bsub>\<approx>A\<^esub>, \<lbrakk>x\<rbrakk>\<^bsub>\<approx>B\<^esub>)"}}, which is accepting
       
  1752   if at least one component is an accepting state.
       
  1753 
       
  1754   The @{text "TIMES"}-case is a bit more complicated---essentially we 
       
  1755   need to sequentially compose the two automata with the states @{text "\<lbrakk>_\<rbrakk>\<^bsub>\<approx>A\<^esub>"}, 
       
  1756   respectively @{text "\<lbrakk>_\<rbrakk>\<^bsub>\<approx>B\<^esub>"}. We achieve this sequential composition by
       
  1757   taking the first automaton @{text "\<lbrakk>_\<rbrakk>\<^bsub>\<approx>A\<^esub>"} and append on each of its accepting
       
  1758   state the automaton @{text "\<lbrakk>_\<rbrakk>\<^bsub>\<approx>B\<^esub>"}. Unfortunately, this does not lead directly
       
  1759   to a correct composition, since the automaton @{text "\<lbrakk>_\<rbrakk>\<^bsub>\<approx>A\<^esub>"} might have consumed
       
  1760   some of the input needed for the automaton @{text "\<lbrakk>_\<rbrakk>\<^bsub>\<approx>B\<^esub>"} to succeed. The 
       
  1761   textbook construction for sequentially composing two automata circumvents this
       
  1762   problem by connecting the terminating states of the first automaton via
       
  1763   an epsilon-transition to the initial state of the second automaton (see for
       
  1764   example \citeN{Kozen97}). In the absence of any epsilon-transition analogue in our work, 
       
  1765   we let the second automaton
       
  1766   start in all possible states that may have been reached if the first
       
  1767   automaton had not consumed the input meant for the second. We achieve this
       
  1768   by having a set of states as the second component generated by our 
       
  1769   @{text "\<times>tag"} function (see second clause in Fig.~\ref{tagfig}).
       
  1770   A state of this sequentially composed automaton is accepting, if the first 
       
  1771   component is accepting and at least one state in the set is also accepting.
       
  1772 
       
  1773   The idea behind the @{text "STAR"}-case is similar to the @{text "TIMES"}-case.
       
  1774   We assume some automaton has consumed some strictly smaller part of the input;
       
  1775   we need to check that from the state we ended up in a terminal state in the 
       
  1776   automaton @{text "\<lbrakk>_\<rbrakk>\<^bsub>\<approx>A\<^esub>"}. Since we do not know from which state this will 
       
  1777   succeed, we need to run the automaton from all possible states we could have 
       
  1778   ended up in. Therefore the @{text "\<star>tag"} function generates a set of states.
       
  1779   \end{rmk}
  1682 *}
  1780 *}
  1683 
  1781 
  1684 section {* Second Part proved using Partial Derivatives *}
  1782 section {* Second Part proved using Partial Derivatives *}
  1685 
  1783 
  1686 text {*
  1784 text {*
  2209   The first step in our proof of Theorem~\ref{subseqreg} is to establish the 
  2307   The first step in our proof of Theorem~\ref{subseqreg} is to establish the 
  2210   following simple properties for @{term SUPSEQ}
  2308   following simple properties for @{term SUPSEQ}
  2211   %
  2309   %
  2212   \begin{equation}\label{supseqprops}
  2310   \begin{equation}\label{supseqprops}
  2213   \mbox{\begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l}
  2311   \mbox{\begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l}
  2214   @{thm (lhs) SUPSEQ_simps(1)} & @{text "\<equiv>"} & @{thm (rhs) SUPSEQ_simps(1)}\\  
  2312   @{thm (lhs) SUPSEQ_simps(1)} & @{text "="} & @{thm (rhs) SUPSEQ_simps(1)}\\  
  2215   @{thm (lhs) SUPSEQ_simps(2)} & @{text "\<equiv>"} & @{thm (rhs) SUPSEQ_simps(2)}\\ 
  2313   @{thm (lhs) SUPSEQ_simps(2)} & @{text "="} & @{thm (rhs) SUPSEQ_simps(2)}\\ 
  2216   @{thm (lhs) SUPSEQ_atom} & @{text "\<equiv>"} & @{thm (rhs) SUPSEQ_atom}\\ 
  2314   @{thm (lhs) SUPSEQ_atom} & @{text "="} & @{thm (rhs) SUPSEQ_atom}\\ 
  2217   @{thm (lhs) SUPSEQ_union} & @{text "\<equiv>"} & @{thm (rhs) SUPSEQ_union}\\
  2315   @{thm (lhs) SUPSEQ_union} & @{text "="} & @{thm (rhs) SUPSEQ_union}\\
  2218   @{thm (lhs) SUPSEQ_conc} & @{text "\<equiv>"} & @{thm (rhs) SUPSEQ_conc}\\
  2316   @{thm (lhs) SUPSEQ_conc} & @{text "="} & @{thm (rhs) SUPSEQ_conc}\\
  2219   @{thm (lhs) SUPSEQ_star} & @{text "\<equiv>"} & @{thm (rhs) SUPSEQ_star}
  2317   @{thm (lhs) SUPSEQ_star} & @{text "="} & @{thm (rhs) SUPSEQ_star}
  2220   \end{tabular}}
  2318   \end{tabular}}
  2221   \end{equation}
  2319   \end{equation}
  2222 
  2320 
  2223   \noindent
  2321   \noindent
  2224   whereby the last equation follows from the fact that @{term "A\<star>"} contains the
  2322   whereby the last equation follows from the fact that @{term "A\<star>"} contains the
  2363   \noindent
  2461   \noindent
  2364   In this paper we took the view that a regular language is one where there
  2462   In this paper we took the view that a regular language is one where there
  2365   exists a regular expression that matches all of its strings. Regular
  2463   exists a regular expression that matches all of its strings. Regular
  2366   expressions can conveniently be defined as a datatype in theorem
  2464   expressions can conveniently be defined as a datatype in theorem
  2367   provers. For us it was therefore interesting to find out how far we can push
  2465   provers. For us it was therefore interesting to find out how far we can push
  2368   this point of view. But this question whether formal language theory can
  2466   this point of view. But this question whether regular language theory can
  2369   be done without automata crops up also in non-theorem prover contexts. For 
  2467   be done without automata crops up also in non-theorem prover contexts. Recall 
  2370   example, Gasarch asked in the Computational Complexity blog by \citeN{GasarchBlog} 
  2468   Gasarch's speculation cited in the Introduction. 
  2371   whether the complementation of 
       
  2372   regular-expression languages can be proved without using automata. He concluded
       
  2373  
       
  2374   \begin{quote}
       
  2375   {\it \ldots it can't be done}
       
  2376   \end{quote} 
       
  2377 
       
  2378   \noindent
       
  2379   and even pondered
       
  2380 
       
  2381   \begin{quote}
       
  2382   {\it \ldots [b]ut is there a rigorous way to even state that?} 
       
  2383   \end{quote} 
       
  2384 
       
  2385   \noindent
       
  2386   We have established in Isabelle/HOL both directions 
  2469   We have established in Isabelle/HOL both directions 
  2387   of the Myhill-Nerode Theorem.
  2470   of the Myhill-Nerode Theorem.
  2388   %
  2471   %
  2389   \begin{theorem}[Myhill-Nerode Theorem]\mbox{}\\
  2472   \begin{theorem}[Myhill-Nerode Theorem]\mbox{}\\
  2390   A language @{text A} is regular if and only if @{thm (rhs) Myhill_Nerode}.
  2473   A language @{text A} is regular if and only if @{thm (rhs) Myhill_Nerode}.
  2396   regular---by establishing that it has infinitely many equivalence classes
  2479   regular---by establishing that it has infinitely many equivalence classes
  2397   generated by the Myhill-Nerode Relation (this is usually the purpose of the
  2480   generated by the Myhill-Nerode Relation (this is usually the purpose of the
  2398   Pumping Lemma).  We can also use it to establish the standard
  2481   Pumping Lemma).  We can also use it to establish the standard
  2399   textbook results about closure properties of regular languages. The case of 
  2482   textbook results about closure properties of regular languages. The case of 
  2400   closure under complement follows easily from the Myhill-Nerode Theorem.
  2483   closure under complement follows easily from the Myhill-Nerode Theorem.
  2401   So our answer to Gasarch is ``{\it it can be done!''}  
  2484   So our answer to Gasarch is ``{\it yes we can!''}  
  2402 
  2485 
  2403   %Our insistence on regular expressions for proving the Myhill-Nerode Theorem
  2486   %Our insistence on regular expressions for proving the Myhill-Nerode Theorem
  2404   %arose from the problem of defining formally the regularity of a language.
  2487   %arose from the problem of defining formally the regularity of a language.
  2405   %In order to guarantee consistency,
  2488   %In order to guarantee consistency,
  2406   %formalisations in HOL can only extend the logic with definitions that introduce a new concept in
  2489   %formalisations in HOL can only extend the logic with definitions that introduce a new concept in
  2463   state', while Brzozowski has it on the terminal states. This means we also
  2546   state', while Brzozowski has it on the terminal states. This means we also
  2464   need to reverse the direction of Arden's Lemma. We have not found anything
  2547   need to reverse the direction of Arden's Lemma. We have not found anything
  2465   in the `pencil-and-paper-reasoning' literature about our way of proving the 
  2548   in the `pencil-and-paper-reasoning' literature about our way of proving the 
  2466   first direction of the Myhill-Nerode Theorem, but it appears to be folklore.
  2549   first direction of the Myhill-Nerode Theorem, but it appears to be folklore.
  2467 
  2550 
  2468   We presented two proofs for the second direction of the Myhill-Nerode
  2551   We presented two proofs for the second direction of the
  2469   Theorem. One direct proof using tagging-functions and another using partial
  2552   Myhill-Nerode Theorem. One direct proof using tagging-functions and
  2470   derivatives. This part of our work is where our method using regular
  2553   another using partial derivatives. This part of our work is where
  2471   expressions shines, because we can completely side-step the standard
  2554   our method using regular expressions shines, because we can perform
  2472   argument (for example used by \citeN{Kozen97}) where automata need to be composed. However, it is
  2555   an induction on the structure of refular expressions. However, it is
  2473   also the direction where we had to spend most of the `conceptual' time, as
  2556   also the direction where we had to spend most of the `conceptual'
  2474   our first proof based on tagging-functions is new for establishing the
  2557   time, as our first proof based on tagging-functions is new for
  2475   Myhill-Nerode Theorem. All standard proofs of this direction proceed by
  2558   establishing the Myhill-Nerode Theorem. All standard proofs of this
  2476   arguments over automata.
  2559   direction proceed by arguments over automata.
  2477   
  2560   
  2478   The indirect proof for the second direction arose from our interest in
  2561   The indirect proof for the second direction arose from our interest in
  2479   Brzozowski's derivatives for regular expression matching.  While \citeN{Brzozowski64} 
  2562   Brzozowski's derivatives for regular expression matching.  While \citeN{Brzozowski64} 
  2480   already established that there are only
  2563   already established that there are only
  2481   finitely many dissimilar derivatives for every regular expression, this
  2564   finitely many dissimilar derivatives for every regular expression, this