Paper/Paper.thy
changeset 110 e500cab16be4
parent 109 79b37ef9505f
child 111 d65d071798ff
equal deleted inserted replaced
109:79b37ef9505f 110:e500cab16be4
   174   \noindent
   174   \noindent
   175   Moreover, it is not so clear how to conveniently impose a finiteness condition 
   175   Moreover, it is not so clear how to conveniently impose a finiteness condition 
   176   upon functions in order to represent \emph{finite} automata. The best is
   176   upon functions in order to represent \emph{finite} automata. The best is
   177   probably to resort to more advanced reasoning frameworks, such as \emph{locales}
   177   probably to resort to more advanced reasoning frameworks, such as \emph{locales}
   178   or \emph{type classes},
   178   or \emph{type classes},
   179   which are not avaiable in \emph{all} HOL-based theorem provers.
   179   which are \emph{not} avaiable in all HOL-based theorem provers.
   180 
   180 
   181   Because of these problems to do with representing automata, there seems
   181   Because of these problems to do with representing automata, there seems
   182   to be no substantial formalisation of automata theory and regular languages 
   182   to be no substantial formalisation of automata theory and regular languages 
   183   carried out in HOL-based theorem provers. Nipkow establishes in 
   183   carried out in HOL-based theorem provers. Nipkow establishes in 
   184   \cite{Nipkow98} the link between regular expressions and automata in
   184   \cite{Nipkow98} the link between regular expressions and automata in
   196   A language @{text A} is \emph{regular}, provided there is a regular expression that matches all
   196   A language @{text A} is \emph{regular}, provided there is a regular expression that matches all
   197   strings of @{text "A"}.
   197   strings of @{text "A"}.
   198   \end{definition}
   198   \end{definition}
   199   
   199   
   200   \noindent
   200   \noindent
   201   The reason is that regular expressions, unlike graphs, matrices and functons, can
   201   The reason is that regular expressions, unlike graphs, matrices and functions, can
   202   be easily defined as inductive datatype. Consequently a corresponding reasoning 
   202   be easily defined as inductive datatype. Consequently a corresponding reasoning 
   203   infrastructure comes for free. This has recently been exploited in HOL4 with a formalisation
   203   infrastructure comes for free. This has recently been exploited in HOL4 with a formalisation
   204   of regular expression matching based on derivatives \cite{OwensSlind08} and
   204   of regular expression matching based on derivatives \cite{OwensSlind08} and
   205   with an equivalence checker for regular expressions in Isabelle/HOL \cite{KraussNipkow11}.  
   205   with an equivalence checker for regular expressions in Isabelle/HOL \cite{KraussNipkow11}.  
   206   The purpose of this paper is to
   206   The purpose of this paper is to
   344   Given a finite set of regular expressions @{text rs}, we will make use of the operation of generating 
   344   Given a finite set of regular expressions @{text rs}, we will make use of the operation of generating 
   345   a regular expression that matches all languages of @{text rs}. We only need to know the existence
   345   a regular expression that matches all languages of @{text rs}. We only need to know the existence
   346   of such a regular expression and therefore we use Isabelle/HOL's @{const "fold_graph"} and Hilbert's
   346   of such a regular expression and therefore we use Isabelle/HOL's @{const "fold_graph"} and Hilbert's
   347   @{text "\<epsilon>"} to define @{term "\<Uplus>rs"}. This operation, roughly speaking, folds @{const ALT} over the 
   347   @{text "\<epsilon>"} to define @{term "\<Uplus>rs"}. This operation, roughly speaking, folds @{const ALT} over the 
   348   set @{text rs} with @{const NULL} for the empty set. We can prove that for a finite set @{text rs}
   348   set @{text rs} with @{const NULL} for the empty set. We can prove that for a finite set @{text rs}
   349 
   349   %
   350   \begin{center}
   350   \begin{equation}\label{uplus}
   351   @{thm (lhs) folds_alt_simp} @{text "= \<Union> (\<calL> ` rs)"}
   351   \mbox{@{thm (lhs) folds_alt_simp} @{text "= \<Union> (\<calL> ` rs)"}}
   352   \end{center}
   352   \end{equation}
   353 
   353 
   354   \noindent
   354   \noindent
   355   holds, whereby @{text "\<calL> ` rs"} stands for the 
   355   holds, whereby @{text "\<calL> ` rs"} stands for the 
   356   image of the set @{text rs} under function @{text "\<calL>"}.
   356   image of the set @{text rs} under function @{text "\<calL>"}.
   357 *}
   357 *}
   421 
   421 
   422   \noindent
   422   \noindent
   423   which means that if we concatenate the character @{text c} to the end of all 
   423   which means that if we concatenate the character @{text c} to the end of all 
   424   strings in the equivalence class @{text Y}, we obtain a subset of 
   424   strings in the equivalence class @{text Y}, we obtain a subset of 
   425   @{text X}. Note that we do not define an automaton here, we merely relate two sets
   425   @{text X}. Note that we do not define an automaton here, we merely relate two sets
   426   (with respect to a character). In our concrete example we have 
   426   (with the help of a character). In our concrete example we have 
   427   @{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 
   427   @{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 
   428   other character than @{text c}, and @{term "X\<^isub>3 \<Turnstile>d\<Rightarrow> X\<^isub>3"} for any @{text d}.
   428   other character than @{text c}, and @{term "X\<^isub>3 \<Turnstile>d\<Rightarrow> X\<^isub>3"} for any @{text d}.
   429   
   429   
   430   Next we build an \emph{initial} equational system that
   430   Next we build an \emph{initial equational system} that
   431   contains an equation for each equivalence class. Suppose we have 
   431   contains an equation for each equivalence class. Suppose we have 
   432   the equivalence classes @{text "X\<^isub>1,\<dots>,X\<^isub>n"}, there must be one and only one that
   432   the equivalence classes @{text "X\<^isub>1,\<dots>,X\<^isub>n"}, there must be one and only one that
   433   contains the empty string @{text "[]"} (since equivalence classes are disjoint).
   433   contains the empty string @{text "[]"} (since equivalence classes are disjoint).
   434   Let us assume @{text "[] \<in> X\<^isub>1"}. We build the following equational system
   434   Let us assume @{text "[] \<in> X\<^isub>1"}. We build the following equational system
   435   
   435   
   444 
   444 
   445   \noindent
   445   \noindent
   446   where the terms @{text "(Y\<^isub>i\<^isub>j, CHAR c\<^isub>i\<^isub>j)"}
   446   where the terms @{text "(Y\<^isub>i\<^isub>j, CHAR c\<^isub>i\<^isub>j)"}
   447   stand for all transitions @{term "Y\<^isub>i\<^isub>j \<Turnstile>c\<^isub>i\<^isub>j\<Rightarrow>
   447   stand for all transitions @{term "Y\<^isub>i\<^isub>j \<Turnstile>c\<^isub>i\<^isub>j\<Rightarrow>
   448   X\<^isub>i"}.   There can only be
   448   X\<^isub>i"}.   There can only be
   449   finitely many such terms in a right-hand side since there are only finitely many
   449   finitely many such terms in a right-hand side since by assumption there are only finitely many
   450   equivalence classes and only finitely many characters.  The term @{text
   450   equivalence classes and only finitely many characters.  The term @{text
   451   "\<lambda>(EMPTY)"} in the first equation acts as a marker for the equivalence class
   451   "\<lambda>(EMPTY)"} in the first equation acts as a marker for the equivalence class
   452   containing @{text "[]"}.\footnote{Note that we mark, roughly speaking, the
   452   containing @{text "[]"}.\footnote{Note that we mark, roughly speaking, the
   453   single ``initial'' state in the equational system, which is different from
   453   single ``initial'' state in the equational system, which is different from
   454   the method by Brzozowski \cite{Brzozowski64}, where he marks the
   454   the method by Brzozowski \cite{Brzozowski64}, where he marks the
   520   in Lem.~\ref{inv}. From the solved form we will be able to read
   520   in Lem.~\ref{inv}. From the solved form we will be able to read
   521   off the regular expressions. 
   521   off the regular expressions. 
   522 
   522 
   523   In order to transform an equational system into solved form, we have two 
   523   In order to transform an equational system into solved form, we have two 
   524   operations: one that takes an equation of the form @{text "X = rhs"} and removes
   524   operations: one that takes an equation of the form @{text "X = rhs"} and removes
   525   any recursive occurences of @{text X} in the @{text rhs} using our variant of Arden's 
   525   any recursive occurrences of @{text X} in the @{text rhs} using our variant of Arden's 
   526   Lemma. The other operation takes an equation @{text "X = rhs"}
   526   Lemma. The other operation takes an equation @{text "X = rhs"}
   527   and substitutes @{text X} throughout the rest of the equational system
   527   and substitutes @{text X} throughout the rest of the equational system
   528   adjusting the remaining regular expressions approriately. To define this adjustment 
   528   adjusting the remaining regular expressions appropriately. To define this adjustment 
   529   we define the \emph{append-operation} taking a term and a regular expression as argument
   529   we define the \emph{append-operation} taking a term and a regular expression as argument
   530 
   530 
   531   \begin{center}
   531   \begin{center}
   532   @{thm append_rexp.simps(2)[where X="Y" and r="r\<^isub>1" and rexp="r\<^isub>2", THEN eq_reflection]}\hspace{10mm}
   532   @{thm append_rexp.simps(2)[where X="Y" and r="r\<^isub>1" and rexp="r\<^isub>2", THEN eq_reflection]}\hspace{10mm}
   533   @{thm append_rexp.simps(1)[where r="r\<^isub>1" and rexp="r\<^isub>2", THEN eq_reflection]}
   533   @{thm append_rexp.simps(1)[where r="r\<^isub>1" and rexp="r\<^isub>2", THEN eq_reflection]}
   535 
   535 
   536   \noindent
   536   \noindent
   537   We lift this operation to entire right-hand sides of equations, written as
   537   We lift this operation to entire right-hand sides of equations, written as
   538   @{thm (lhs) append_rhs_rexp_def[where rexp="r"]}. With this we can define
   538   @{thm (lhs) append_rhs_rexp_def[where rexp="r"]}. With this we can define
   539   the \emph{arden-operation} for an equation of the form @{text "X = rhs"} as:
   539   the \emph{arden-operation} for an equation of the form @{text "X = rhs"} as:
   540   
   540   %
   541   \begin{center}
   541   \begin{equation}\label{arden_def}
   542   \begin{tabular}{rc@ {\hspace{2mm}}r@ {\hspace{1mm}}l}
   542   \mbox{\begin{tabular}{rc@ {\hspace{2mm}}r@ {\hspace{1mm}}l}
   543   @{thm (lhs) Arden_def} & @{text "\<equiv>"}~~\mbox{} & \multicolumn{2}{@ {\hspace{-2mm}}l}{@{text "let"}}\\ 
   543   @{thm (lhs) Arden_def} & @{text "\<equiv>"}~~\mbox{} & \multicolumn{2}{@ {\hspace{-2mm}}l}{@{text "let"}}\\ 
   544    & & @{text "rhs' ="} & @{term "rhs - {Trn X r | r. Trn X r \<in> rhs}"} \\
   544    & & @{text "rhs' ="} & @{term "rhs - {Trn X r | r. Trn X r \<in> rhs}"} \\
   545    & & @{text "r' ="}   & @{term "STAR (\<Uplus> {r. Trn X r \<in> rhs})"}\\
   545    & & @{text "r' ="}   & @{term "STAR (\<Uplus> {r. Trn X r \<in> rhs})"}\\
   546    & &  \multicolumn{2}{@ {\hspace{-2mm}}l}{@{text "in"}~~@{term "append_rhs_rexp rhs' r'"}}\\ 
   546    & &  \multicolumn{2}{@ {\hspace{-2mm}}l}{@{text "in"}~~@{term "append_rhs_rexp rhs' r'"}}\\ 
   547   \end{tabular}
   547   \end{tabular}}
   548   \end{center}
   548   \end{equation}
   549 
   549 
   550   \noindent
   550   \noindent
   551   In this definition, we first delete all terms of the form @{text "(X, r)"} from @{text rhs};
   551   In this definition, we first delete all terms of the form @{text "(X, r)"} from @{text rhs};
   552   then we calculate the combinded regular expressions for all @{text r} coming 
   552   then we calculate the combined regular expressions for all @{text r} coming 
   553   from the deleted @{text "(X, r)"}, and take the @{const STAR} of it;
   553   from the deleted @{text "(X, r)"}, and take the @{const STAR} of it;
   554   finally we append this regular expression to @{text rhs'}. It can be easily seen 
   554   finally we append this regular expression to @{text rhs'}. It can be easily seen 
   555   that this operation mimics Arden's lemma on the level of equations.  
   555   that this operation mimics Arden's lemma on the level of equations. To ensure
       
   556   the non-emptiness condition of Arden's lemma we say that a right-hand side is
       
   557   \emph{ardenable} provided
       
   558 
       
   559   \begin{center}
       
   560   @{thm ardenable_def}
       
   561   \end{center}
       
   562 
       
   563   \noindent
       
   564   This allows us to prove
       
   565 
       
   566   \begin{lemma}\label{ardenable}
       
   567   If @{text "X = \<Union>\<calL> ` rhs"},
       
   568   @{thm (prem 2) Arden_keeps_eq} and
       
   569   @{thm (prem 3) Arden_keeps_eq}, then
       
   570   @{text "X = \<Union>\<calL> ` (Arden X rhs)"}
       
   571   \end{lemma}
       
   572   
       
   573   \noindent
   556   The \emph{substituion-operation} takes an equation
   574   The \emph{substituion-operation} takes an equation
   557   of the form @{text "X = xrhs"} and substitutes it into the right-hand side @{text rhs}.
   575   of the form @{text "X = xrhs"} and substitutes it into the right-hand side @{text rhs}.
   558 
   576 
   559   \begin{center}
   577   \begin{center}
   560   \begin{tabular}{rc@ {\hspace{2mm}}r@ {\hspace{1mm}}l}
   578   \begin{tabular}{rc@ {\hspace{2mm}}r@ {\hspace{1mm}}l}
   564    & &  \multicolumn{2}{@ {\hspace{-2mm}}l}{@{text "in"}~~@{term "rhs' \<union> append_rhs_rexp xrhs r'"}}\\ 
   582    & &  \multicolumn{2}{@ {\hspace{-2mm}}l}{@{text "in"}~~@{term "rhs' \<union> append_rhs_rexp xrhs r'"}}\\ 
   565   \end{tabular}
   583   \end{tabular}
   566   \end{center}
   584   \end{center}
   567 
   585 
   568   \noindent
   586   \noindent
   569   We again delete first all occurence of @{text "(X, r)"} in @{text rhs}; we then calculate
   587   We again delete first all occurrence of @{text "(X, r)"} in @{text rhs}; we then calculate
   570   the regular expression corresponding to the deleted terms; finally we append this
   588   the regular expression corresponding to the deleted terms; finally we append this
   571   regular expression to @{text "xrhs"} and union it up with @{text rhs'}. When we use
   589   regular expression to @{text "xrhs"} and union it up with @{text rhs'}. When we use
   572   the substitution operation we will arrange it so that @{text "xrhs"} does not contain
   590   the substitution operation we will arrange it so that @{text "xrhs"} does not contain
   573   any occurence of @{text X}.
   591   any occurrence of @{text X}.
   574 
   592 
   575   With these two operation in place, we can define the operation that removes one equation
   593   With these two operation in place, we can define the operation that removes one equation
   576   from an equational systems @{text ES}. The operation @{const Subst_all}
   594   from an equational systems @{text ES}. The operation @{const Subst_all}
   577   substitutes an equation @{text "X = xrhs"} throughout an equational system @{text ES}; 
   595   substitutes an equation @{text "X = xrhs"} throughout an equational system @{text ES}; 
   578   @{const Remove} then completely removes such an equation from @{text ES} by substituting 
   596   @{const Remove} then completely removes such an equation from @{text ES} by substituting 
   579   it to the rest of the equational system, but first eliminating all recursive occurences
   597   it to the rest of the equational system, but first eliminating all recursive occurrences
   580   of @{text X} by applying @{const Arden} to @{text "xrhs"}.
   598   of @{text X} by applying @{const Arden} to @{text "xrhs"}.
   581 
   599 
   582   \begin{center}
   600   \begin{center}
   583   \begin{tabular}{rcl}
   601   \begin{tabular}{rcl}
   584   @{thm (lhs) Subst_all_def} & @{text "\<equiv>"} & @{thm (rhs) Subst_all_def}\\
   602   @{thm (lhs) Subst_all_def} & @{text "\<equiv>"} & @{thm (rhs) Subst_all_def}\\
   585   @{thm (lhs) Remove_def}    & @{text "\<equiv>"} & @{thm (rhs) Remove_def}
   603   @{thm (lhs) Remove_def}    & @{text "\<equiv>"} & @{thm (rhs) Remove_def}
   586   \end{tabular}
   604   \end{tabular}
   587   \end{center}
   605   \end{center}
   588 
   606 
   589   \noindent
   607   \noindent
   590   Finially, we can define how an equational system should be solved. For this 
   608   Finally, we can define how an equational system should be solved. For this 
   591   we will need to iterate the process of eliminating equations until only one equation
   609   we will need to iterate the process of eliminating equations until only one equation
   592   will be left in the system. However, we not just want to have any equation
   610   will be left in the system. However, we not just want to have any equation
   593   as being the last one, but the one involving the equivalence class for 
   611   as being the last one, but the one involving the equivalence class for 
   594   which we want to calculate the regular 
   612   which we want to calculate the regular 
   595   expression. Let us suppose this equivalence class is @{text X}. 
   613   expression. Let us suppose this equivalence class is @{text X}. 
   605    & &  \multicolumn{2}{@ {\hspace{-4mm}}l}{@{text "in"}~~@{term "Remove ES Y yrhs"}}\\ 
   623    & &  \multicolumn{2}{@ {\hspace{-4mm}}l}{@{text "in"}~~@{term "Remove ES Y yrhs"}}\\ 
   606   \end{tabular}
   624   \end{tabular}
   607   \end{center}
   625   \end{center}
   608 
   626 
   609   \noindent
   627   \noindent
   610   The last definition we need applies @{term Iter} over and over again until a condition 
   628   The last definition we need applies @{term Iter} over and over until a condition 
   611   @{text COND} is \emph{not} satisfied anymore. The condition states that there
   629   @{text Cond} is \emph{not} satisfied anymore. The condition states that there
   612   are more than one equation left in the equational system @{text ES}. For this
   630   are more than one equation left in the equational system @{text ES}. To solve
   613   we use Isabelle/HOL's @{text while}-operator as follows:
   631   an equational system we use Isabelle/HOL's @{text while}-operator as follows:
   614   
   632   
   615   \begin{center}
   633   \begin{center}
   616   @{thm Solve_def}
   634   @{thm Solve_def}
   617   \end{center}
   635   \end{center}
   618 
   636 
   624   of the equational system @{text ES}. This enables us to prove
   642   of the equational system @{text ES}. This enables us to prove
   625   properties about our definition of @{const Solve} when we ``call'' it with
   643   properties about our definition of @{const Solve} when we ``call'' it with
   626   the equivalence class @{text X} and the initial equational system 
   644   the equivalence class @{text X} and the initial equational system 
   627   @{term "Init (UNIV // \<approx>A)"} from
   645   @{term "Init (UNIV // \<approx>A)"} from
   628   \eqref{initcs} using the principle:
   646   \eqref{initcs} using the principle:
   629 
   647   %
   630 
   648   \begin{equation}\label{whileprinciple}
   631   \begin{center}
   649   \mbox{\begin{tabular}{l}
   632   \begin{tabular}{l}
       
   633   @{term "invariant (Init (UNIV // \<approx>A))"} \\
   650   @{term "invariant (Init (UNIV // \<approx>A))"} \\
   634   @{term "\<forall>ES. invariant ES \<and> Cond ES \<longrightarrow> invariant (Iter X ES)"}\\
   651   @{term "\<forall>ES. invariant ES \<and> Cond ES \<longrightarrow> invariant (Iter X ES)"}\\
   635   @{term "\<forall>ES. invariant ES \<and> Cond ES \<longrightarrow> card (Iter X ES) < card ES"}\\
   652   @{term "\<forall>ES. invariant ES \<and> Cond ES \<longrightarrow> card (Iter X ES) < card ES"}\\
   636   @{term "\<forall>ES. invariant ES \<and> \<not> Cond ES \<longrightarrow> P ES"}\\
   653   @{term "\<forall>ES. invariant ES \<and> \<not> Cond ES \<longrightarrow> P ES"}\\
   637   \hline
   654   \hline
   638   \multicolumn{1}{c}{@{term "P (Solve X (Init (UNIV // \<approx>A)))"}}
   655   \multicolumn{1}{c}{@{term "P (Solve X (Init (UNIV // \<approx>A)))"}}
   639   \end{tabular}
   656   \end{tabular}}
   640   \end{center}
   657   \end{equation}
   641 
   658 
   642   \noindent
   659   \noindent
   643   This principle states that given an invariant (which we will specify below) 
   660   This principle states that given an invariant (which we will specify below) 
   644   we can prove a property
   661   we can prove a property
   645   @{text "P"} involving @{const Solve}. For this we have to discharge the following
   662   @{text "P"} involving @{const Solve}. For this we have to discharge the following
   660       @{term "finite ES"} & @{text "(finiteness)"}\\
   677       @{term "finite ES"} & @{text "(finiteness)"}\\
   661   & @{text "\<and>"} & @{thm (rhs) finite_rhs_def} & @{text "(finiteness rhs)"}\\
   678   & @{text "\<and>"} & @{thm (rhs) finite_rhs_def} & @{text "(finiteness rhs)"}\\
   662   & @{text "\<and>"} & @{text "\<forall>(X, rhs)\<in>ES. X = \<Union>\<calL> ` rhs"} & @{text "(soundness)"}\\
   679   & @{text "\<and>"} & @{text "\<forall>(X, rhs)\<in>ES. X = \<Union>\<calL> ` rhs"} & @{text "(soundness)"}\\
   663   & @{text "\<and>"} & @{thm (rhs) distinct_equas_def}\\
   680   & @{text "\<and>"} & @{thm (rhs) distinct_equas_def}\\
   664   &             &  & @{text "(distinctness)"}\\
   681   &             &  & @{text "(distinctness)"}\\
   665   & @{text "\<and>"} & @{thm (rhs) ardenable_def} & @{text "(ardenable)"}\\   
   682   & @{text "\<and>"} & @{thm (rhs) ardenable_all_def} & @{text "(ardenable)"}\\   
   666   & @{text "\<and>"} & @{thm (rhs) valid_eqs_def} & @{text "(validity)"}\\
   683   & @{text "\<and>"} & @{thm (rhs) valid_eqs_def} & @{text "(validity)"}\\
   667   \end{tabular}
   684   \end{tabular}
   668   \end{center}
   685   \end{center}
   669  
   686  
   670   \noindent
   687   \noindent
   671   The first two ensure that the equational system is always finite (number of equations
   688   The first two ensure that the equational system is always finite (number of equations
   672   and number of terms in each equation); the second makes sure the ``meaning'' of the 
   689   and number of terms in each equation); the second makes sure the ``meaning'' of the 
   673   equations is preserved under our transformations. The other properties are a bit more
   690   equations is preserved under our transformations. The other properties are a bit more
   674   technical, but are needed to get our proof through. Distinctness states that every
   691   technical, but are needed to get our proof through. Distinctness states that every
   675   equation in the system is distinct; @{text "ardenable"} ensures that we can always
   692   equation in the system is distinct. Ardenable ensures that we can always
   676   apply the arden operation. For this we have to make sure that in every @{text rhs}, 
   693   apply the arden operation. 
   677   terms of the form @{term "Trn Y r"} cannot have a regular expresion that matches the
       
   678   empty string. Therefore @{text "rhs_nonempty"} is defined as
       
   679 
       
   680   \begin{center}
       
   681   @{thm rhs_nonempty_def}
       
   682   \end{center}
       
   683 
       
   684   \noindent
       
   685   The last property states that every @{text rhs} can only contain equivalence classes
   694   The last property states that every @{text rhs} can only contain equivalence classes
   686   for which there is an equation. Therefore @{text lhss} is just the set containing 
   695   for which there is an equation. Therefore @{text lhss} is just the set containing 
   687   the first components of an equational system,
   696   the first components of an equational system,
   688   while @{text "rhss"} collects all equivalence classes @{text X} in the terms of the 
   697   while @{text "rhss"} collects all equivalence classes @{text X} in the terms of the 
   689   form @{term "Trn X r"} (that means @{thm (lhs) lhss_def}~@{text "\<equiv> {X | (X, rhs) \<in> ES}"} 
   698   form @{term "Trn X r"}. That means @{thm (lhs) lhss_def}~@{text "\<equiv> {X | (X, rhs) \<in> ES}"} 
   690   and @{thm (lhs) rhss_def}~@{text "\<equiv> {X | (X, r) \<in> rhs}"}).
   699   and @{thm (lhs) rhss_def}~@{text "\<equiv> {X | (X, r) \<in> rhs}"}.
   691   
   700   
   692 
   701 
   693   It is straightforward to prove that the inital equational system satisfies the
   702   It is straightforward to prove that the initial equational system satisfies the
   694   invariant.
   703   invariant.
   695 
   704 
   696   \begin{lemma}
   705   \begin{lemma}\label{invzero}
   697   @{thm[mode=IfThen] Init_ES_satisfies_invariant}
   706   @{thm[mode=IfThen] Init_ES_satisfies_invariant}
   698   \end{lemma}
   707   \end{lemma}
   699 
   708 
   700   \begin{proof}
   709   \begin{proof}
   701   Finiteness is given by the assumption and the way how we set up the 
   710   Finiteness is given by the assumption and the way how we set up the 
   702   initial equational system. Soundness is proved in Lem.~\ref{inv}. Distinctness
   711   initial equational system. Soundness is proved in Lem.~\ref{inv}. Distinctness
   703   follows from the fact that the equivalence classes are disjoint. The ardenable
   712   follows from the fact that the equivalence classes are disjoint. The ardenable
   704   property also follows from the setup of the equational system as does 
   713   property also follows from the setup of the equational system, as does 
   705   validity.\qed
   714   validity.\qed
   706   \end{proof}
   715   \end{proof}
   707 
   716 
   708   \begin{lemma}
   717   \begin{lemma}\label{iterone}
   709   @{thm[mode=IfThen] iteration_step_invariant[where xrhs="rhs"]}
   718   @{thm[mode=IfThen] iteration_step_invariant[where xrhs="rhs"]}
   710   \end{lemma}
   719   \end{lemma}
   711 
   720 
   712   \begin{proof} 
   721   \begin{proof} 
   713   ???
   722   This boils down to choosing an equation @{text "Y = yrhs"} to be eliminated
       
   723   and to show that @{term "Subst_all (ES - {(Y, yrhs)}) Y (Arden Y yrhs)"} 
       
   724   preserves the invariant.
       
   725   We prove this as follows:
       
   726 
       
   727   \begin{center}
       
   728   @{text "\<forall> ES."} @{thm (prem 1) Subst_all_satisfies_invariant} implies
       
   729   @{thm (concl) Subst_all_satisfies_invariant}
       
   730   \end{center}
       
   731 
       
   732   \noindent
       
   733   Finiteness is straightforward, as @{const Subst} and @{const Arden} operations 
       
   734   keep the equational system finite. These operation also preserve soundness 
       
   735   distinctness (we proved soundness for @{const Arden} in Lem.~\ref{ardenable}).
       
   736   The property Ardenable is clearly preserved because the append-operation
       
   737   cannot make a regular expression to match the empty string. Validity is
       
   738   given because @{const Arden} removes an equivalence class from @{text yrhs}
       
   739   and then @{const Subst_all} removes @{text Y} from the equational system.
       
   740   Having proved the implication above, we can replace @{text "ES"} with @{text "ES - {(Y, yrhs)}"}
       
   741   which matches with our proof-obligation of @{const "Subst_all"}. Since
       
   742   \mbox{@{term "ES = ES - {(Y, yrhs)} \<union> {(Y, yrhs)}"}}, we can use our assumption 
       
   743   to complete the proof.\qed 
   714   \end{proof}
   744   \end{proof}
   715 
   745 
   716   \begin{lemma}
   746   \begin{lemma}\label{itertwo}
   717   @{thm[mode=IfThen] iteration_step_measure[simplified (no_asm), where xrhs="rhs"]}
   747   @{thm[mode=IfThen] iteration_step_measure[simplified (no_asm), where xrhs="rhs"]}
   718   \end{lemma}
   748   \end{lemma}
   719 
   749 
   720   \begin{proof}
   750   \begin{proof}
   721   By assumption we know that @{text "ES"} is finite and has more than one element.
   751   By assumption we know that @{text "ES"} is finite and has more than one element.
   722   Therefore there must be an element @{term "(Y, yrhs) \<in> ES"} with 
   752   Therefore there must be an element @{term "(Y, yrhs) \<in> ES"} with 
   723   @{term "(Y, yrhs) \<noteq> (X, rhs)"}. Using the distictness property we can infer
   753   @{term "(Y, yrhs) \<noteq> (X, rhs)"}. Using the distinctness property we can infer
   724   that @{term "Y \<noteq> X"}. We further know that @{text "Remove ES Y yrhs"}
   754   that @{term "Y \<noteq> X"}. We further know that @{text "Remove ES Y yrhs"}
   725   removes the equation @{text "Y = yrhs"} from the system, and therefore 
   755   removes the equation @{text "Y = yrhs"} from the system, and therefore 
   726   the cardinality of @{const Iter} strictly decreases.\qed
   756   the cardinality of @{const Iter} strictly decreases.\qed
   727   \end{proof}
   757   \end{proof}
   728 
   758 
   731   a @{text rhs} such that  @{term "Solve X (Init (UNIV // \<approx>A)) = {(X, rhs)}"}
   761   a @{text rhs} such that  @{term "Solve X (Init (UNIV // \<approx>A)) = {(X, rhs)}"}
   732   and @{term "invariant {(X, rhs)}"}.
   762   and @{term "invariant {(X, rhs)}"}.
   733   \end{lemma}
   763   \end{lemma}
   734 
   764 
   735   \begin{proof} 
   765   \begin{proof} 
   736   ???
   766   In order to prove this lemma using \eqref{whileprinciple}, we have to use a slightly
       
   767   stronger invariant since Lem.~\ref{iterone} and \ref{itertwo} have the precondition 
       
   768   that @{term "(X, rhs) \<in> ES"} for some @{text rhs}. This precondition is needed
       
   769   in order to choose in the @{const Iter}-step an equation that is not \mbox{@{term "X = rhs"}}.
       
   770   Therefore our invariant is cannot be just @{term "invariant ES"}, but must be 
       
   771   @{term "invariant ES \<and> (\<exists>rhs. (X, rhs) \<in> ES)"}. By assumption 
       
   772   @{thm (prem 2) Solve} and Lem.~\ref{invzero}, the more general invariant holds for
       
   773   the initial equational system. This is premise 1 of~\eqref{whileprinciple}.
       
   774   Premise 2 is given by Lem.~\ref{iterone} and the fact that @{const Iter} might
       
   775   modify the @{text rhs} in the equation @{term "X = rhs"}, but does not remove it.
       
   776   Premise 3 of~\eqref{whileprinciple} is by Lem.~\ref{itertwo}. Now in premise 4
       
   777   we like to show that there exists a @{text rhs} such that @{term "ES = {(X, rhs)}"}
       
   778   and that @{text "invariant {(X, rhs)}"} holds, provided the condition @{text "Cond"}
       
   779   does not hols. By the stronger invariant we know there exists such a @{text "rhs"}
       
   780   with @{term "(X, rhs) \<in> ES"}. Because @{text Cond} is not true, we know the cardinality
       
   781   of @{text ES} is @{text 1}. This means @{text "ES"} must actually be the equation @{text "X = rhs"},
       
   782   for which the invariant holds. This allows us to conclude that 
       
   783   @{term "Solve X (Init (UNIV // \<approx>A)) = {(X, rhs)}"} and @{term "invariant {(X, rhs)}"} hold.\qed
   737   \end{proof}
   784   \end{proof}
   738 
   785 
   739   \noindent
   786   \noindent
   740   With this lemma in place we can show that for every equivalence class in @{term "UNIV // \<approx>A"}
   787   With this lemma in place we can show that for every equivalence class in @{term "UNIV // \<approx>A"}
   741   there exists a regular expression.
   788   there exists a regular expression.
   748   By the preceeding Lemma, we know that there exists a @{text "rhs"} such
   795   By the preceeding Lemma, we know that there exists a @{text "rhs"} such
   749   that @{term "Solve X (Init (UNIV // \<approx>A))"} returns the equation @{text "X = rhs"},
   796   that @{term "Solve X (Init (UNIV // \<approx>A))"} returns the equation @{text "X = rhs"},
   750   and that the invariant holds for this equation. That means we 
   797   and that the invariant holds for this equation. That means we 
   751   know @{text "X = \<Union>\<calL> ` rhs"}. We further know that
   798   know @{text "X = \<Union>\<calL> ` rhs"}. We further know that
   752   this is equal to \mbox{@{text "\<Union>\<calL> ` (Arden X rhs)"}} using the properties of the 
   799   this is equal to \mbox{@{text "\<Union>\<calL> ` (Arden X rhs)"}} using the properties of the 
   753   invariant and Lem.~???. Using the validity property for the equation @{text "X = rhs"},
   800   invariant and Lem.\ref{ardenable}. Using the validity property for the equation @{text "X = rhs"},
   754   we can infer that @{term "rhss rhs \<subseteq> {X}"} and because the arden operation
   801   we can infer that @{term "rhss rhs \<subseteq> {X}"} and because the arden operation
   755   removes that @{text X} from @{text rhs}, that @{term "rhss (Arden X rhs) = {}"}.
   802   removes that @{text X} from @{text rhs}, that @{term "rhss (Arden X rhs) = {}"}.
   756   That means @{term "Arden X rhs"} can only consist of terms of the form @{term "Lam r"}.
   803   That means @{term "Arden X rhs"} can only consist of terms of the form @{term "Lam r"}.
   757   So we can collect those (finitely many) regular expressions and have @{term "X = L (\<Uplus>rs)"}.
   804   So we can collect those (finitely many) regular expressions and have @{term "X = L (\<Uplus>rs)"}.
   758   With this we can conclude the proof.\qed
   805   With this we can conclude the proof.\qed
   763   of the Myhill-Nerode theorem.
   810   of the Myhill-Nerode theorem.
   764 
   811 
   765   \begin{proof}[of Thm.~\ref{myhillnerodeone}]
   812   \begin{proof}[of Thm.~\ref{myhillnerodeone}]
   766   By Lem.~\ref{every_eqcl_has_reg} we know that there exists a regular language for
   813   By Lem.~\ref{every_eqcl_has_reg} we know that there exists a regular language for
   767   every equivalence class in @{term "UNIV // \<approx>A"}. Since @{text "finals A"} is
   814   every equivalence class in @{term "UNIV // \<approx>A"}. Since @{text "finals A"} is
   768   a subset of  @{term "UNIV // \<approx>A"}, we also know that for every equvalence class
   815   a subset of  @{term "UNIV // \<approx>A"}, we also know that for every equivalence class
   769   in @{term "finals A"} there exists a regular language. Moreover by assumption 
   816   in @{term "finals A"} there exists a regular language. Moreover by assumption 
   770   we know that @{term "finals A"} must be finite, and therefore there must be a finite
   817   we know that @{term "finals A"} must be finite, and therefore there must be a finite
   771   set of regular expressions @{text "rs"} such that
   818   set of regular expressions @{text "rs"} such that
   772 
   819 
   773   \begin{center}
   820   \begin{center}