Paper/Paper.thy
changeset 123 23c0e6f2929d
parent 122 ab6637008963
child 124 8233510cab6c
equal deleted inserted replaced
122:ab6637008963 123:23c0e6f2929d
   266   \noindent
   266   \noindent
   267   In @{text "(ii)"} we use the notation @{term "length s"} for the length of a
   267   In @{text "(ii)"} we use the notation @{term "length s"} for the length of a
   268   string; this property states that if @{term "[] \<notin> A"} then the lengths of
   268   string; this property states that if @{term "[] \<notin> A"} then the lengths of
   269   the strings in @{term "A \<up> (Suc n)"} must be longer than @{text n}.  We omit
   269   the strings in @{term "A \<up> (Suc n)"} must be longer than @{text n}.  We omit
   270   the proofs for these properties, but invite the reader to consult our
   270   the proofs for these properties, but invite the reader to consult our
   271   formalisation.\footnote{Available at \url{http://www4.in.tum.de/~urbanc/cgi-bin/repos.cgi/regexp/}}
   271   formalisation.\footnote{Available at \url{http://www4.in.tum.de/~urbanc/regexp.html}}
   272 
   272 
   273   The notation in Isabelle/HOL for the quotient of a language @{text A} according to an 
   273   The notation in Isabelle/HOL for the quotient of a language @{text A} according to an 
   274   equivalence relation @{term REL} is @{term "A // REL"}. We will write 
   274   equivalence relation @{term REL} is @{term "A // REL"}. We will write 
   275   @{text "\<lbrakk>x\<rbrakk>\<^isub>\<approx>"} for the equivalence class defined 
   275   @{text "\<lbrakk>x\<rbrakk>\<^isub>\<approx>"} for the equivalence class defined 
   276   as @{text "{y | y \<approx> x}"}.
   276   as @{text "{y | y \<approx> x}"}.
   278 
   278 
   279   Central to our proof will be the solution of equational systems
   279   Central to our proof will be the solution of equational systems
   280   involving equivalence classes of languages. For this we will use Arden's lemma \cite{Brzozowski64},
   280   involving equivalence classes of languages. For this we will use Arden's lemma \cite{Brzozowski64},
   281   which solves equations of the form @{term "X = A ;; X \<union> B"} provided
   281   which solves equations of the form @{term "X = A ;; X \<union> B"} provided
   282   @{term "[] \<notin> A"}. However we will need the following `reverse' 
   282   @{term "[] \<notin> A"}. However we will need the following `reverse' 
   283   version of Arden's lemma (`reverse' in the sense of changing the order of @{text "\<cdot>"}).
   283   version of Arden's lemma (`reverse' in the sense of changing the order of @{term "A ;; X"} to
       
   284   \mbox{@{term "X ;; A"}}).
   284 
   285 
   285   \begin{lemma}[Reverse Arden's Lemma]\label{arden}\mbox{}\\
   286   \begin{lemma}[Reverse Arden's Lemma]\label{arden}\mbox{}\\
   286   If @{thm (prem 1) arden} then
   287   If @{thm (prem 1) arden} then
   287   @{thm (lhs) arden} if and only if
   288   @{thm (lhs) arden} if and only if
   288   @{thm (rhs) arden}.
   289   @{thm (rhs) arden}.
   375   \emph{Myhill-Nerode relation}, which states that w.r.t.~a language two 
   376   \emph{Myhill-Nerode relation}, which states that w.r.t.~a language two 
   376   strings are related, provided there is no distinguishing extension in this
   377   strings are related, provided there is no distinguishing extension in this
   377   language. This can be defined as tertiary relation.
   378   language. This can be defined as tertiary relation.
   378 
   379 
   379   \begin{definition}[Myhill-Nerode Relation] Given a language @{text A}, two strings @{text x} and
   380   \begin{definition}[Myhill-Nerode Relation] Given a language @{text A}, two strings @{text x} and
   380   @{text y} are related provided
   381   @{text y} are Myhill-Nerode related provided
   381   \begin{center}
   382   \begin{center}
   382   @{thm str_eq_def[simplified str_eq_rel_def Pair_Collect]}
   383   @{thm str_eq_def[simplified str_eq_rel_def Pair_Collect]}
   383   \end{center}
   384   \end{center}
   384   \end{definition}
   385   \end{definition}
   385 
   386 
   467   containing @{text "[]"}.\footnote{Note that we mark, roughly speaking, the
   468   containing @{text "[]"}.\footnote{Note that we mark, roughly speaking, the
   468   single `initial' state in the equational system, which is different from
   469   single `initial' state in the equational system, which is different from
   469   the method by Brzozowski \cite{Brzozowski64}, where he marks the
   470   the method by Brzozowski \cite{Brzozowski64}, where he marks the
   470   `terminal' states. We are forced to set up the equational system in our
   471   `terminal' states. We are forced to set up the equational system in our
   471   way, because the Myhill-Nerode relation determines the `direction' of the
   472   way, because the Myhill-Nerode relation determines the `direction' of the
   472   transitions. The successor `state' of an equivalence class @{text Y} can
   473   transitions---the successor `state' of an equivalence class @{text Y} can
   473   be reached by adding characters to the end of @{text Y}. This is also the
   474   be reached by adding a character to the end of @{text Y}. This is also the
   474   reason why we have to use our reverse version of Arden's lemma.}
   475   reason why we have to use our reverse version of Arden's lemma.}
   475   Overloading the function @{text \<calL>} for the two kinds of terms in the
   476   Overloading the function @{text \<calL>} for the two kinds of terms in the
   476   equational system, we have
   477   equational system, we have
   477   
   478   
   478   \begin{center}
   479   \begin{center}
   709   apply the arden operation. 
   710   apply the arden operation. 
   710   The last property states that every @{text rhs} can only contain equivalence classes
   711   The last property states that every @{text rhs} can only contain equivalence classes
   711   for which there is an equation. Therefore @{text lhss} is just the set containing 
   712   for which there is an equation. Therefore @{text lhss} is just the set containing 
   712   the first components of an equational system,
   713   the first components of an equational system,
   713   while @{text "rhss"} collects all equivalence classes @{text X} in the terms of the 
   714   while @{text "rhss"} collects all equivalence classes @{text X} in the terms of the 
   714   form @{term "Trn X r"}. That means @{thm (lhs) lhss_def}~@{text "\<equiv> {X | (X, rhs) \<in> ES}"} 
   715   form @{term "Trn X r"}. That means formally @{thm (lhs) lhss_def}~@{text "\<equiv> {X | (X, rhs) \<in> ES}"} 
   715   and @{thm (lhs) rhss_def}~@{text "\<equiv> {X | (X, r) \<in> rhs}"}.
   716   and @{thm (lhs) rhss_def}~@{text "\<equiv> {X | (X, r) \<in> rhs}"}.
   716   
   717   
   717 
   718 
   718   It is straightforward to prove that the initial equational system satisfies the
   719   It is straightforward to prove that the initial equational system satisfies the
   719   invariant.
   720   invariant.
   802   Premise 3 of~\eqref{whileprinciple} is by Lem.~\ref{itertwo}. Now in premise 4
   803   Premise 3 of~\eqref{whileprinciple} is by Lem.~\ref{itertwo}. Now in premise 4
   803   we like to show that there exists a @{text rhs} such that @{term "ES = {(X, rhs)}"}
   804   we like to show that there exists a @{text rhs} such that @{term "ES = {(X, rhs)}"}
   804   and that @{text "invariant {(X, rhs)}"} holds, provided the condition @{text "Cond"}
   805   and that @{text "invariant {(X, rhs)}"} holds, provided the condition @{text "Cond"}
   805   does not holds. By the stronger invariant we know there exists such a @{text "rhs"}
   806   does not holds. By the stronger invariant we know there exists such a @{text "rhs"}
   806   with @{term "(X, rhs) \<in> ES"}. Because @{text Cond} is not true, we know the cardinality
   807   with @{term "(X, rhs) \<in> ES"}. Because @{text Cond} is not true, we know the cardinality
   807   of @{text ES} is @{text 1}. This means @{text "ES"} must actually be the equation @{text "X = rhs"},
   808   of @{text ES} is @{text 1}. This means @{text "ES"} must actually be the set @{text "{(X, rhs)}"},
   808   for which the invariant holds. This allows us to conclude that 
   809   for which the invariant holds. This allows us to conclude that 
   809   @{term "Solve X (Init (UNIV // \<approx>A)) = {(X, rhs)}"} and @{term "invariant {(X, rhs)}"} hold,
   810   @{term "Solve X (Init (UNIV // \<approx>A)) = {(X, rhs)}"} and @{term "invariant {(X, rhs)}"} hold,
   810   as needed.\qed
   811   as needed.\qed
   811   \end{proof}
   812   \end{proof}
   812 
   813 
   822   By the preceeding Lemma, we know that there exists a @{text "rhs"} such
   823   By the preceeding Lemma, we know that there exists a @{text "rhs"} such
   823   that @{term "Solve X (Init (UNIV // \<approx>A))"} returns the equation @{text "X = rhs"},
   824   that @{term "Solve X (Init (UNIV // \<approx>A))"} returns the equation @{text "X = rhs"},
   824   and that the invariant holds for this equation. That means we 
   825   and that the invariant holds for this equation. That means we 
   825   know @{text "X = \<Union>\<calL> ` rhs"}. We further know that
   826   know @{text "X = \<Union>\<calL> ` rhs"}. We further know that
   826   this is equal to \mbox{@{text "\<Union>\<calL> ` (Arden X rhs)"}} using the properties of the 
   827   this is equal to \mbox{@{text "\<Union>\<calL> ` (Arden X rhs)"}} using the properties of the 
   827   invariant and Lem.\ref{ardenable}. Using the validity property for the equation @{text "X = rhs"},
   828   invariant and Lem.~\ref{ardenable}. Using the validity property for the equation @{text "X = rhs"},
   828   we can infer that @{term "rhss rhs \<subseteq> {X}"} and because the arden operation
   829   we can infer that @{term "rhss rhs \<subseteq> {X}"} and because the arden operation
   829   removes that @{text X} from @{text rhs}, that @{term "rhss (Arden X rhs) = {}"}.
   830   removes that @{text X} from @{text rhs}, that @{term "rhss (Arden X rhs) = {}"}.
   830   This means the right-hand side @{term "Arden X rhs"} can only consist of terms of the form @{term "Lam r"}.
   831   This means the right-hand side @{term "Arden X rhs"} can only consist of terms of the form @{term "Lam r"}.
   831   So we can collect those (finitely many) regular expressions and have @{term "X = L (\<Uplus>rs)"}.
   832   So we can collect those (finitely many) regular expressions and have @{term "X = L (\<Uplus>rs)"}.
   832   With this we can conclude the proof.\qed
   833   With this we can conclude the proof.\qed
   835   \noindent
   836   \noindent
   836   Lem.~\ref{every_eqcl_has_reg} allows us to finally give a proof for the first direction
   837   Lem.~\ref{every_eqcl_has_reg} allows us to finally give a proof for the first direction
   837   of the Myhill-Nerode theorem.
   838   of the Myhill-Nerode theorem.
   838 
   839 
   839   \begin{proof}[of Thm.~\ref{myhillnerodeone}]
   840   \begin{proof}[of Thm.~\ref{myhillnerodeone}]
   840   By Lem.~\ref{every_eqcl_has_reg} we know that there exists a regular language for
   841   By Lem.~\ref{every_eqcl_has_reg} we know that there exists a regular expression for
   841   every equivalence class in @{term "UNIV // \<approx>A"}. Since @{text "finals A"} is
   842   every equivalence class in @{term "UNIV // \<approx>A"}. Since @{text "finals A"} is
   842   a subset of  @{term "UNIV // \<approx>A"}, we also know that for every equivalence class
   843   a subset of  @{term "UNIV // \<approx>A"}, we also know that for every equivalence class
   843   in @{term "finals A"} there exists a regular language. Moreover by assumption 
   844   in @{term "finals A"} there exists a regular expression. Moreover by assumption 
   844   we know that @{term "finals A"} must be finite, and therefore there must be a finite
   845   we know that @{term "finals A"} must be finite, and therefore there must be a finite
   845   set of regular expressions @{text "rs"} such that
   846   set of regular expressions @{text "rs"} such that
   846 
   847 
   847   \begin{center}
   848   \begin{center}
   848   @{term "\<Union>(finals A) = L (\<Uplus>rs)"}
   849   @{term "\<Union>(finals A) = L (\<Uplus>rs)"}
   894 
   895 
   895   Our method will rely on some
   896   Our method will rely on some
   896   \emph{tagging functions} defined over strings. Given the inductive hypothesis, it will 
   897   \emph{tagging functions} defined over strings. Given the inductive hypothesis, it will 
   897   be easy to prove that the range of these tagging functions is finite
   898   be easy to prove that the range of these tagging functions is finite
   898   (the range of a function @{text f} is defined as @{text "range f \<equiv> f ` UNIV"}).
   899   (the range of a function @{text f} is defined as @{text "range f \<equiv> f ` UNIV"}).
   899   With this we will be able to infer that the tagging functions, seen as a relation,
   900   With this we will be able to infer that the tagging functions, seen as relations,
   900   give rise to finitely many equivalence classes of @{const UNIV}. Finally we 
   901   give rise to finitely many equivalence classes of @{const UNIV}. Finally we 
   901   will show that the tagging relation is more refined than @{term "\<approx>(L r)"}, which
   902   will show that the tagging relation is more refined than @{term "\<approx>(L r)"}, which
   902   implies that @{term "UNIV // \<approx>(L r)"} must also be finite. 
   903   implies that @{term "UNIV // \<approx>(L r)"} must also be finite (a relation @{text "R\<^isub>1"} 
   903   A relation @{text "R\<^isub>1"} is said to \emph{refine} @{text "R\<^isub>2"} provided @{text "R\<^isub>1 \<subseteq> R\<^isub>2"}.
   904   is said to \emph{refine} @{text "R\<^isub>2"} provided @{text "R\<^isub>1 \<subseteq> R\<^isub>2"}).
   904   We formally define the notion of a \emph{tag-relation} as follows.
   905   We formally define the notion of a \emph{tagging-relation} as follows.
   905 
   906 
   906   \begin{definition}[Tagging-Relation] Given a tag-function @{text tag}, then two strings @{text x}
   907   \begin{definition}[Tagging-Relation] Given a tagging-function @{text tag}, then two strings @{text x}
   907   and @{text y} are \emph{tag-related} provided
   908   and @{text y} are \emph{tag-related} provided
   908   \begin{center}
   909   \begin{center}
   909   @{text "x =tag= y \<equiv> tag x = tag y"}
   910   @{text "x =tag= y \<equiv> tag x = tag y"}
   910   \end{center}
   911   \end{center}
   911   \end{definition}
   912   \end{definition}
   912 
   913 
   913   \noindent
   914   \noindent
   914   In order to establish finiteness of a set @{text A} we shall use the following powerful
   915   In order to establish finiteness of a set @{text A}, we shall use the following powerful
   915   principle from Isabelle/HOL's library.
   916   principle from Isabelle/HOL's library.
   916   %
   917   %
   917   \begin{equation}\label{finiteimageD}
   918   \begin{equation}\label{finiteimageD}
   918   @{thm[mode=IfThen] finite_imageD}
   919   @{thm[mode=IfThen] finite_imageD}
   919   \end{equation}
   920   \end{equation}
   920 
   921 
   921   \noindent
   922   \noindent
   922   It states that if an image of a set under an injective function @{text f} (over this set) 
   923   It states that if an image of a set under an injective function @{text f} (injective over this set) 
   923   is finite, then @{text A} itself must be finite. We can use it to establish the following 
   924   is finite, then @{text A} itself must be finite. We can use it to establish the following 
   924   two lemmas.
   925   two lemmas.
   925 
   926 
   926   \begin{lemma}\label{finone}
   927   \begin{lemma}\label{finone}
   927   @{thm[mode=IfThen] finite_eq_tag_rel}
   928   @{thm[mode=IfThen] finite_eq_tag_rel}
   928   \end{lemma}
   929   \end{lemma}
   929 
   930 
   930   \begin{proof}
   931   \begin{proof}
   931   We set in \eqref{finiteimageD}, @{text f} to be @{text "X \<mapsto> tag ` X"}. We have
   932   We set in \eqref{finiteimageD}, @{text f} to be @{text "X \<mapsto> tag ` X"}. We have
   932   @{text "range f"} to be subset of @{term "Pow (range tag)"}, which we know must be
   933   @{text "range f"} to be a subset of @{term "Pow (range tag)"}, which we know must be
   933   finite by assumption. Now @{term "f (UNIV // =tag=)"} is a subset of @{text "range f"},
   934   finite by assumption. Now @{term "f (UNIV // =tag=)"} is a subset of @{text "range f"},
   934   and so also finite. Injectivity amounts to showing that @{text "X = Y"} under the
   935   and so also finite. Injectivity amounts to showing that @{text "X = Y"} under the
   935   assumptions that @{text "X, Y \<in> "}~@{term "UNIV // =tag="} and @{text "f X = f Y"}.
   936   assumptions that @{text "X, Y \<in> "}~@{term "UNIV // =tag="} and @{text "f X = f Y"}.
   936   From the assumption we can obtain a @{text "x \<in> X"} and @{text "y \<in> Y"} with 
   937   From the assumption we can obtain @{text "x \<in> X"} and @{text "y \<in> Y"} with 
   937   @{text "tag x = tag y"}. This in turn means that the equivalence classes @{text X}
   938   @{text "tag x = tag y"}. Since @{text x} and @{text y} are tag-related, this in 
       
   939   turn means that the equivalence classes @{text X}
   938   and @{text Y} must be equal.\qed
   940   and @{text Y} must be equal.\qed
   939   \end{proof}
   941   \end{proof}
   940 
   942 
   941   \begin{lemma}\label{fintwo} 
   943   \begin{lemma}\label{fintwo} 
   942   Given two equivalence relations @{text "R\<^isub>1"} and @{text "R\<^isub>2"}, where
   944   Given two equivalence relations @{text "R\<^isub>1"} and @{text "R\<^isub>2"}, whereby
   943   @{text "R\<^isub>1"} refines @{text "R\<^isub>2"}.
   945   @{text "R\<^isub>1"} refines @{text "R\<^isub>2"}.
   944   If @{thm (prem 1) refined_partition_finite[where ?R1.0="R\<^isub>1" and ?R2.0="R\<^isub>2"]}
   946   If @{thm (prem 1) refined_partition_finite[where ?R1.0="R\<^isub>1" and ?R2.0="R\<^isub>2"]}
   945   then @{thm (concl) refined_partition_finite[where ?R1.0="R\<^isub>1" and ?R2.0="R\<^isub>2"]}.
   947   then @{thm (concl) refined_partition_finite[where ?R1.0="R\<^isub>1" and ?R2.0="R\<^isub>2"]}.
   946   \end{lemma}
   948   \end{lemma}
   947 
   949 
   948   \begin{proof}
   950   \begin{proof}
   949   We prove this lemma again using \eqref{finiteimageD}. For this we set @{text f} to
   951   We prove this lemma again using \eqref{finiteimageD}. This time we set @{text f} to
   950   be @{text "X \<mapsto>"}~@{term "{R\<^isub>1 `` {x} | x. x \<in> X}"}. It is easy to see that 
   952   be @{text "X \<mapsto>"}~@{term "{R\<^isub>1 `` {x} | x. x \<in> X}"}. It is easy to see that 
   951   @{text "finite (f ` (UNIV // R\<^isub>2))"} because it is a subset of @{text "Pow (UNIV // R\<^isub>1)"},
   953   @{text "finite (f ` (UNIV // R\<^isub>2))"} because it is a subset of @{text "Pow (UNIV // R\<^isub>1)"},
   952   which is finite by assumption. What remains to be shown is that @{text f} is injective
   954   which is finite by assumption. What remains to be shown is that @{text f} is injective
   953   on @{term "UNIV // R\<^isub>2"}. This is equivalent to showing that two equivalence 
   955   on @{term "UNIV // R\<^isub>2"}. This is equivalent to showing that two equivalence 
   954   classes, say @{text "X"} and @{text Y}, in @{term "UNIV // R\<^isub>2"} are equal, provided
   956   classes, say @{text "X"} and @{text Y}, in @{term "UNIV // R\<^isub>2"} are equal, provided
   955   @{text "f X = f Y"}. For @{text "X = Y"} to be equal, we have to find two elements
   957   @{text "f X = f Y"}. For @{text "X = Y"} to be equal, we have to find two elements
   956   @{text "x \<in> X"} and @{text "y \<in> Y"} such that they are @{text R\<^isub>2} related.
   958   @{text "x \<in> X"} and @{text "y \<in> Y"} such that they are @{text R\<^isub>2} related.
   957   We know there exists a @{text x} with @{term "X = R\<^isub>2 `` {x}"}
   959   We know there exists a @{text x} with @{term "X = R\<^isub>2 `` {x}"}
   958   and @{text "x \<in> X"}. From the latter fact we can infer that @{term "R\<^isub>1 ``{x} \<in> f X"}
   960   and @{text "x \<in> X"}. From the latter fact we can infer that @{term "R\<^isub>1 ``{x} \<in> f X"}
   959   and further @{term "R\<^isub>1 ``{x} \<in> f Y"}. From this we can obtain a @{text y}
   961   and further @{term "R\<^isub>1 ``{x} \<in> f Y"}. This means we can obtain a @{text y}
   960   such that @{term "R\<^isub>1 `` {x} = R\<^isub>1 `` {y}"} holds. This means @{text x} and @{text y}
   962   such that @{term "R\<^isub>1 `` {x} = R\<^isub>1 `` {y}"} holds. Consequently @{text x} and @{text y}
   961   are @{text "R\<^isub>1"}-related. Since by assumption @{text "R\<^isub>1"} refines @{text "R\<^isub>2"},
   963   are @{text "R\<^isub>1"}-related. Since by assumption @{text "R\<^isub>1"} refines @{text "R\<^isub>2"},
   962   they must also be @{text "R\<^isub>2"}-related, as we need to show.\qed
   964   they must also be @{text "R\<^isub>2"}-related, as we need to show.\qed
   963   \end{proof}
   965   \end{proof}
   964 
   966 
   965   \noindent
   967   \noindent
   966   Chaining Lem.~\ref{finone} and \ref{fintwo} together, means in order to show
   968   Chaining Lem.~\ref{finone} and \ref{fintwo} together, means in order to show
   967   that @{term "UNIV // \<approx>(L r)"} is finite, we have to find a tagging function whose
   969   that @{term "UNIV // \<approx>(L r)"} is finite, we have to find a tagging function whose
   968   range can be shown to be finite and whose tagging-relation refines @{term "\<approx>(L r)"}.
   970   range can be shown to be finite and whose tagging-relation refines @{term "\<approx>(L r)"}.
   969   Let us attempt the @{const ALT}-case.
   971   Let us attempt the @{const ALT}-case first.
   970 
   972 
   971   \begin{proof}[@{const "ALT"}-Case] 
   973   \begin{proof}[@{const "ALT"}-Case] 
   972   We take as tagging function 
   974   We take as tagging function 
   973 
   975 
   974   \begin{center}
   976   \begin{center}
   977 
   979 
   978   \noindent
   980   \noindent
   979   where @{text "A"} and @{text "B"} are some arbitrary languages.
   981   where @{text "A"} and @{text "B"} are some arbitrary languages.
   980   We can show in general, if @{term "finite (UNIV // \<approx>A)"} and @{term "finite (UNIV // \<approx>B)"}
   982   We can show in general, if @{term "finite (UNIV // \<approx>A)"} and @{term "finite (UNIV // \<approx>B)"}
   981   then @{term "finite ((UNIV // \<approx>A) \<times> (UNIV // \<approx>B))"} holds. The range of
   983   then @{term "finite ((UNIV // \<approx>A) \<times> (UNIV // \<approx>B))"} holds. The range of
   982   @{term "tag_str_ALT A B"} is a subset of this product set. It remains to show
   984   @{term "tag_str_ALT A B"} is a subset of this product set, so finite. It remains to be shown
   983   that @{text "=tag\<^isub>A\<^isub>L\<^isub>T A B="} refines @{term "\<approx>(A \<union> B)"}. This amounts to 
   985   that @{text "=tag\<^isub>A\<^isub>L\<^isub>T A B="} refines @{term "\<approx>(A \<union> B)"}. This amounts to 
   984   showing
   986   showing
   985   %
   987   %
   986   \begin{center}
   988   \begin{center}
   987   @{term "tag\<^isub>A\<^isub>L\<^isub>T A B x = tag\<^isub>A\<^isub>L\<^isub>T A B y \<longrightarrow> x \<approx>(A \<union> B) y"}
   989   @{term "tag\<^isub>A\<^isub>L\<^isub>T A B x = tag\<^isub>A\<^isub>L\<^isub>T A B y \<longrightarrow> x \<approx>(A \<union> B) y"}
   994   @{text "\<forall>z. tag\<^isub>A\<^isub>L\<^isub>T A B x = tag\<^isub>A\<^isub>L\<^isub>T A B y \<and> x @ z \<in> A \<union> B \<longrightarrow> y @ z \<in> A \<union> B"}
   996   @{text "\<forall>z. tag\<^isub>A\<^isub>L\<^isub>T A B x = tag\<^isub>A\<^isub>L\<^isub>T A B y \<and> x @ z \<in> A \<union> B \<longrightarrow> y @ z \<in> A \<union> B"}
   995   \end{equation}
   997   \end{equation}
   996 
   998 
   997   \noindent
   999   \noindent
   998   since both @{text "=tag\<^isub>A\<^isub>L\<^isub>T A B="} and @{term "\<approx>(A \<union> B)"} are symmetric. To solve
  1000   since both @{text "=tag\<^isub>A\<^isub>L\<^isub>T A B="} and @{term "\<approx>(A \<union> B)"} are symmetric. To solve
   999   \eqref{pattern} we just have to unfold the tagging-relation and analyse 
  1001   \eqref{pattern} we just have to unfold the definition of the tagging-relation and analyse 
  1000   in which set, @{text A} or @{text B}, the string @{term "x @ z"} is. Fianlly we
  1002   in which set, @{text A} or @{text B}, the string @{term "x @ z"} is. 
       
  1003   The definition of the tagging-function will give us in each case the
       
  1004   information to infer that @{text "y @ z \<in> A \<union> B"}.
       
  1005   Finally we
  1001   can discharge this case by setting @{text A} to @{term "L r\<^isub>1"} and @{text B} to @{term "L r\<^isub>2"}.\qed
  1006   can discharge this case by setting @{text A} to @{term "L r\<^isub>1"} and @{text B} to @{term "L r\<^isub>2"}.\qed
  1002   \end{proof}
  1007   \end{proof}
  1003 
  1008 
  1004 
  1009 
  1005   \noindent
  1010   \noindent
  1006   The pattern in \eqref{pattern} is repeated for the other two cases. Unfortunately,
  1011   The pattern in \eqref{pattern} is repeated for the other two cases. Unfortunately,
  1007   they are slightly more complicated. 
  1012   they are slightly more complicated. In the @{const SEQ}-case we essentially have
       
  1013   to be able to infer that 
       
  1014 
       
  1015   \begin{center}
       
  1016   @{term "x @ z \<in> A ;; B \<longrightarrow> y @ z \<in> A ;; B"}
       
  1017   \end{center}
       
  1018 
       
  1019   \noindent
       
  1020   using the information given by the appropriate tagging function. The complication 
       
  1021   is to find out what the possible splits of @{text "x @ z"} are to be in @{term "A ;; B"}.
  1008 
  1022 
  1009 
  1023 
  1010   \begin{proof}[@{const SEQ}-Case]
  1024   \begin{proof}[@{const SEQ}-Case]
  1011 
  1025 
  1012   \begin{center}
  1026   \begin{center}
  1057   "\<Rightarrow>"} deterministic automaton @{text "\<Rightarrow>"} complement automaton @{text "\<Rightarrow>"}
  1071   "\<Rightarrow>"} deterministic automaton @{text "\<Rightarrow>"} complement automaton @{text "\<Rightarrow>"}
  1058   regular expression.
  1072   regular expression.
  1059 
  1073 
  1060   While regular expressions are convenient in formalisations, they have some
  1074   While regular expressions are convenient in formalisations, they have some
  1061   limitations. One is that there seems to be no method of calculating a
  1075   limitations. One is that there seems to be no method of calculating a
  1062   minimal regular expression (for example in terms of length), like there is
  1076   minimal regular expression (for example in terms of length) for a regular
  1063   for automata. For an implementation of a simple regular expression matcher,
  1077   language, like there is
       
  1078   for automata. On the other hand, efficient regular expression matching,
       
  1079   without using automata, poses no problem \cite{OwensReppyTuron09}.
       
  1080   For an implementation of a simple regular expression matcher,
  1064   whose correctness has been formally established, we refer the reader to
  1081   whose correctness has been formally established, we refer the reader to
  1065   Owens and Slind \cite{OwensSlind08}.
  1082   Owens and Slind \cite{OwensSlind08}.
  1066 
  1083 
  1067 
  1084 
  1068   Our formalisation consists of 790 lines of Isabelle/Isar code for the first
  1085   Our formalisation consists of 790 lines of Isabelle/Isar code for the first
  1069   direction and 475 for the second, plus 300 lines of standard material about
  1086   direction and 475 for the second, plus around 300 lines of standard material about
  1070   regular languages. While this might be seen as too large to count as a
  1087   regular languages. While this might be seen as too large to count as a
  1071   concise proof pearl, this should be seen in the context of the work done by
  1088   concise proof pearl, this should be seen in the context of the work done by
  1072   Constable at al \cite{Constable00} who formalised the Myhill-Nerode theorem
  1089   Constable at al \cite{Constable00} who formalised the Myhill-Nerode theorem
  1073   in Nuprl using automata. They write that their four-member team needed
  1090   in Nuprl using automata. They write that their four-member team needed
  1074   something on the magnitute of 18 months for their formalisation. The
  1091   something on the magnitute of 18 months for their formalisation. The
  1080   from what is shown in the Nuprl Math Library about their development it
  1097   from what is shown in the Nuprl Math Library about their development it
  1081   seems substantially larger than ours. The code of ours can be found in the
  1098   seems substantially larger than ours. The code of ours can be found in the
  1082   Mercurial Repository at
  1099   Mercurial Repository at
  1083 
  1100 
  1084   \begin{center}
  1101   \begin{center}
  1085   \url{http://www4.in.tum.de/~urbanc/cgi-bin/repos.cgi/regexp/}
  1102   \url{http://www4.in.tum.de/~urbanc/regexp.html}
  1086   \end{center}
  1103   \end{center}
  1087 
  1104 
  1088 
  1105 
  1089   Our proof of the first direction is very much inspired by \emph{Brzozowski's
  1106   Our proof of the first direction is very much inspired by \emph{Brzozowski's
  1090   algebraic mehod} used to convert a finite automaton to a regular
  1107   algebraic mehod} used to convert a finite automaton to a regular
  1092   classes as the states of the minimal automaton for the regular language.
  1109   classes as the states of the minimal automaton for the regular language.
  1093   However there are some subtle differences. Since we identify equivalence
  1110   However there are some subtle differences. Since we identify equivalence
  1094   classes with the states of the automaton, then the most natural choice is to
  1111   classes with the states of the automaton, then the most natural choice is to
  1095   characterise each state with the set of strings starting from the initial
  1112   characterise each state with the set of strings starting from the initial
  1096   state leading up to that state. Usually, however, the states are characterised as the
  1113   state leading up to that state. Usually, however, the states are characterised as the
  1097   ones starting from that state leading to the terminal states.  The first
  1114   strings starting from that state leading to the terminal states.  The first
  1098   choice has consequences how the initial equational system is set up. We have
  1115   choice has consequences about how the initial equational system is set up. We have
  1099   the $\lambda$-term on our `initial state', while Brzozowski has it on the
  1116   the $\lambda$-term on our `initial state', while Brzozowski has it on the
  1100   terminal states. This means we also need to reverse the direction of Arden's
  1117   terminal states. This means we also need to reverse the direction of Arden's
  1101   lemma.
  1118   lemma.
  1102 
  1119 
  1103   We briefly considered using the method Brzozowski presented in the Appendix
  1120   We briefly considered using the method Brzozowski presented in the Appendix
  1104   of~\cite{Brzozowski64} in order to prove the second direction of the
  1121   of~\cite{Brzozowski64} in order to prove the second direction of the
  1105   Myhill-Nerode theorem. There he calculates the derivatives for regular
  1122   Myhill-Nerode theorem. There he calculates the derivatives for regular
  1106   expressions and shows that there can be only finitely many of them. We could
  1123   expressions and shows that there can be only finitely many of them. We could
  1107   have used as the tag of a string @{text s} the derivative of a regular expression
  1124   have used as the tag of a string @{text s} the derivative of a regular expression
  1108   generated with respect to @{text s}.  Using the fact that two strings are
  1125   generated with respect to @{text s}.  Using the fact that two strings are
  1109   Myhill-Nerode related whenever their derivative is the same together with
  1126   Myhill-Nerode related whenever their derivative is the same, together with
  1110   the fact that there are only finitely many derivatives for a regular
  1127   the fact that there are only finitely many derivatives for a regular
  1111   expression would give us a similar argument as ours. However it seems not so easy to
  1128   expression would give us a similar argument as ours. However it seems not so easy to
  1112   calculate the derivatives and then to count them. Therefore we preferred our
  1129   calculate the derivatives and then to count them. Therefore we preferred our
  1113   direct method of using tagging-functions involving equivalence classes. This
  1130   direct method of using tagging-functions. This
  1114   is also where our method shines, because we can completely side-step the
  1131   is also where our method shines, because we can completely side-step the
  1115   standard argument \cite{Kozen97} where automata need to be composed, which
  1132   standard argument \cite{Kozen97} where automata need to be composed, which
  1116   as stated in the Introduction is not so convenient to formalise in a 
  1133   as stated in the Introduction is not so convenient to formalise in a 
  1117   HOL-based theorem prover. However, it is also the direction where we had to 
  1134   HOL-based theorem prover. However, it is also the direction where we had to 
  1118   spend most of the `conceptual' time, as our proof-argument based on tagging functions
  1135   spend most of the `conceptual' time, as our proof-argument based on tagging-functions
  1119   is new for establishing the Myhill-Nerode theorem.
  1136   is new for establishing the Myhill-Nerode theorem. All standard proofs 
       
  1137   of this direction proceed by arguments over automata.
  1120 
  1138 
  1121 *}
  1139 *}
  1122 
  1140 
  1123 
  1141 
  1124 (*<*)
  1142 (*<*)