Paper/Paper.thy
changeset 108 212bfa431fa5
parent 107 6f4f9b7b9891
child 109 79b37ef9505f
equal deleted inserted replaced
107:6f4f9b7b9891 108:212bfa431fa5
   369   \end{definition}
   369   \end{definition}
   370 
   370 
   371   \noindent
   371   \noindent
   372   It is easy to see that @{term "\<approx>A"} is an equivalence relation, which
   372   It is easy to see that @{term "\<approx>A"} is an equivalence relation, which
   373   partitions the set of all strings, @{text "UNIV"}, into a set of disjoint
   373   partitions the set of all strings, @{text "UNIV"}, into a set of disjoint
   374   equivalence classes. To illustrate this quotient construction, let us give an 
   374   equivalence classes. To illustrate this quotient construction, let us give a simple 
   375   example: consider the regular language containing just
   375   example: consider the regular language containing just
   376   the string @{text "[c]"}. The relation @{term "\<approx>({[c]})"} partitions @{text UNIV}
   376   the string @{text "[c]"}. The relation @{term "\<approx>({[c]})"} partitions @{text UNIV}
   377   into three equivalence classes @{text "X\<^isub>1"}, @{text "X\<^isub>2"} and  @{text "X\<^isub>3"}
   377   into three equivalence classes @{text "X\<^isub>1"}, @{text "X\<^isub>2"} and  @{text "X\<^isub>3"}
   378   as follows
   378   as follows
   379   
   379   
   481   \end{equation}
   481   \end{equation}
   482 
   482 
   483   \noindent
   483   \noindent
   484   The reason for adding the @{text \<lambda>}-marker to our initial equational system is 
   484   The reason for adding the @{text \<lambda>}-marker to our initial equational system is 
   485   to obtain this equation: it only holds with the marker, since none of 
   485   to obtain this equation: it only holds with the marker, since none of 
   486   the other terms contain the empty string. 
   486   the other terms contain the empty string. The point of the initial equational system is
       
   487   that solving it means we will be able to extract a regular expression for every equivalence class. 
   487 
   488 
   488   Our representation for the equations in Isabelle/HOL are pairs,
   489   Our representation for the equations in Isabelle/HOL are pairs,
   489   where the first component is an equivalence class and the second component
   490   where the first component is an equivalence class (a set of strings)
       
   491   and the second component
   490   is a set of terms. Given a set of equivalence
   492   is a set of terms. Given a set of equivalence
   491   classes @{text CS}, our initial equational system @{term "Init CS"} is thus 
   493   classes @{text CS}, our initial equational system @{term "Init CS"} is thus 
   492   formally defined as
   494   formally defined as
   493   %
   495   %
   494   \begin{equation}\label{initcs}
   496   \begin{equation}\label{initcs}
   513   \end{lemma}
   515   \end{lemma}
   514 
   516 
   515   \noindent
   517   \noindent
   516   Our proof of Thm.~\ref{myhillnerodeone} will proceed by transforming the
   518   Our proof of Thm.~\ref{myhillnerodeone} will proceed by transforming the
   517   initial equational system into one in \emph{solved form} maintaining the invariant
   519   initial equational system into one in \emph{solved form} maintaining the invariant
   518   in Lemma \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
   519   off the regular expressions. 
   521   off the regular expressions. 
   520 
   522 
   521   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 
   522   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
   523   the recursive occurences of @{text X} in the @{text rhs} using our variant of Arden's 
   525   any recursive occurences of @{text X} in the @{text rhs} using our variant of Arden's 
   524   Lemma. The other operation takes an equation @{text "X = rhs"}
   526   Lemma. The other operation takes an equation @{text "X = rhs"}
   525   and substitutes @{text X} throughout the rest of the equational system
   527   and substitutes @{text X} throughout the rest of the equational system
   526   adjusting the remaining regular expressions approriately. To define this adjustment 
   528   adjusting the remaining regular expressions approriately. To define this adjustment 
   527   we define the \emph{append-operation} 
   529   we define the \emph{append-operation} taking a term and a regular expression as argument
   528 
   530 
   529   \begin{center}
   531   \begin{center}
   530   @{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}
   531   @{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]}
   532   \end{center}
   534   \end{center}
   533 
   535 
   534   \noindent
   536   \noindent
   535   which we also lift to entire right-hand sides of equations, written as
   537   We lift this operation to entire right-hand sides of equations, written as
   536   @{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
   537   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:
   538   
   540   
   539   \begin{center}
   541   \begin{center}
   540   \begin{tabular}{rc@ {\hspace{2mm}}r@ {\hspace{1mm}}l}
   542   \begin{tabular}{rc@ {\hspace{2mm}}r@ {\hspace{1mm}}l}
   588   Finially, we can define how an equational system should be solved. For this 
   590   Finially, we can define how an equational system should be solved. For this 
   589   we will need to iterate the process of eliminating equations until only one equation
   591   we will need to iterate the process of eliminating equations until only one equation
   590   will be left in the system. However, we not just want to have any equation
   592   will be left in the system. However, we not just want to have any equation
   591   as being the last one, but the one involving the equivalence class for 
   593   as being the last one, but the one involving the equivalence class for 
   592   which we want to calculate the regular 
   594   which we want to calculate the regular 
   593   expression. Let us suppose the equivalence class is @{text X}. 
   595   expression. Let us suppose this equivalence class is @{text X}. 
   594   Since @{text X} is the one to be solved, in every iteration step we have to pick an
   596   Since @{text X} is the one to be solved, in every iteration step we have to pick an
   595   equation to be eliminated that which is different from @{text X}. In this way 
   597   equation to be eliminated that is different from @{text X}. In this way 
   596   @{text X} is kept to the final step. The choice is implemented by Hilbert's choice 
   598   @{text X} is kept to the final step. The choice is implemented using Hilbert's choice 
   597   operator, written @{text SOME} in the definition below.
   599   operator, written @{text SOME} in the definition below.
   598   
   600   
   599   \begin{center}
   601   \begin{center}
   600   \begin{tabular}{rc@ {\hspace{4mm}}r@ {\hspace{1mm}}l}
   602   \begin{tabular}{rc@ {\hspace{4mm}}r@ {\hspace{1mm}}l}
   601   @{thm (lhs) Iter_def} & @{text "\<equiv>"}~~\mbox{} & \multicolumn{2}{@ {\hspace{-4mm}}l}{@{text "let"}}\\ 
   603   @{thm (lhs) Iter_def} & @{text "\<equiv>"}~~\mbox{} & \multicolumn{2}{@ {\hspace{-4mm}}l}{@{text "let"}}\\ 
   621   have a well-founded termination order by taking the cardinality 
   623   have a well-founded termination order by taking the cardinality 
   622   of the equational system @{text ES}. This enables us to prove
   624   of the equational system @{text ES}. This enables us to prove
   623   properties about our definition of @{const Solve} when we ``call'' it with
   625   properties about our definition of @{const Solve} when we ``call'' it with
   624   the equivalence class @{text X} and the initial equational system 
   626   the equivalence class @{text X} and the initial equational system 
   625   @{term "Init (UNIV // \<approx>A)"} from
   627   @{term "Init (UNIV // \<approx>A)"} from
   626   \eqref{initcs}:
   628   \eqref{initcs} using the principle:
   627 
   629 
   628 
   630 
   629   \begin{center}
   631   \begin{center}
   630   \begin{tabular}{l}
   632   \begin{tabular}{l}
   631   @{term "invariant (Init (UNIV // \<approx>A))"} \\
   633   @{term "invariant (Init (UNIV // \<approx>A))"} \\
   646   step @{text "Iter"} preserves the the invariant as long as the condition @{term Cond} holds;
   648   step @{text "Iter"} preserves the the invariant as long as the condition @{term Cond} holds;
   647   third that @{text "Iter"} decreases the termination order, and fourth that
   649   third that @{text "Iter"} decreases the termination order, and fourth that
   648   once the condition does not hold anymore then the property @{text P} must hold.
   650   once the condition does not hold anymore then the property @{text P} must hold.
   649 
   651 
   650   The property @{term P} in our proof will state that @{term "Solve X (Init (UNIV // \<approx>A))"}
   652   The property @{term P} in our proof will state that @{term "Solve X (Init (UNIV // \<approx>A))"}
   651   returns with a single equation @{text "X = xrhs"}, for some @{text "xrhs"} and
   653   returns with a single equation @{text "X = xrhs"} for some @{text "xrhs"}, and
   652   that this equational system still satisfies the invariant. In order to get
   654   that this equational system still satisfies the invariant. In order to get
   653   the proof through, the invariant is composed of the following six properties:
   655   the proof through, the invariant is composed of the following six properties:
   654 
   656 
   655   \begin{center}
   657   \begin{center}
   656   \begin{tabular}{@ {}rcl@ {\hspace{-13mm}}l @ {}}
   658   \begin{tabular}{@ {}rcl@ {\hspace{-13mm}}l @ {}}
   665   \end{tabular}
   667   \end{tabular}
   666   \end{center}
   668   \end{center}
   667  
   669  
   668   \noindent
   670   \noindent
   669   The first two ensure that the equational system is always finite (number of equations
   671   The first two ensure that the equational system is always finite (number of equations
   670   and number of terms in each equation); \ldots
   672   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
       
   674   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
       
   676   apply the arden operation. For this we have to make sure that in every @{text rhs}, 
       
   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
       
   686   for which there is an equation. Therefore @{text lhss} is just the set containing 
       
   687   the first components of an equational system,
       
   688   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}"} 
       
   690   and @{thm (lhs) rhss_def}~@{text "\<equiv> {X | (X, r) \<in> rhs}"}).
       
   691   
   671 
   692 
   672   It is straightforward to prove that the inital equational system satisfies the
   693   It is straightforward to prove that the inital equational system satisfies the
   673   invariant.
   694   invariant.
   674 
   695 
   675   \begin{lemma}
   696   \begin{lemma}