Journal/Paper.thy
changeset 174 2b414a8a7132
parent 173 d371536861bc
child 175 edc642266a82
equal deleted inserted replaced
173:d371536861bc 174:2b414a8a7132
    46   Suc ("_+1" [100] 100) and
    46   Suc ("_+1" [100] 100) and
    47   quotient ("_ \<^raw:\ensuremath{\!\sslash\!}> _" [90, 90] 90) and
    47   quotient ("_ \<^raw:\ensuremath{\!\sslash\!}> _" [90, 90] 90) and
    48   REL ("\<approx>") and
    48   REL ("\<approx>") and
    49   UPLUS ("_ \<^raw:\ensuremath{\uplus}> _" [90, 90] 90) and
    49   UPLUS ("_ \<^raw:\ensuremath{\uplus}> _" [90, 90] 90) and
    50   lang ("\<^raw:\ensuremath{\cal{L}}>'(_')" [0] 101) and
    50   lang ("\<^raw:\ensuremath{\cal{L}}>'(_')" [0] 101) and
       
    51   lang_trm ("\<^raw:\ensuremath{\cal{L}}>'(_')" [0] 101) and
    51   Lam ("\<lambda>'(_')" [100] 100) and 
    52   Lam ("\<lambda>'(_')" [100] 100) and 
    52   Trn ("'(_, _')" [100, 100] 100) and 
    53   Trn ("'(_, _')" [100, 100] 100) and 
    53   EClass ("\<lbrakk>_\<rbrakk>\<^bsub>_\<^esub>" [100, 100] 100) and
    54   EClass ("\<lbrakk>_\<rbrakk>\<^bsub>_\<^esub>" [100, 100] 100) and
    54   transition ("_ \<^raw:\ensuremath{\stackrel{\text{>_\<^raw:}}{\Longmapsto}}> _" [100, 100, 100] 100) and
    55   transition ("_ \<^raw:\ensuremath{\stackrel{\text{>_\<^raw:}}{\Longmapsto}}> _" [100, 100, 100] 100) and
    55   Setalt ("\<^raw:\ensuremath{\bigplus}>_" [1000] 999) and
    56   Setalt ("\<^raw:\ensuremath{\bigplus}>_" [1000] 999) and
    56   Append_rexp2 ("_ \<^raw:\ensuremath{\triangleleft}> _" [100, 100] 100) and
    57   Append_rexp2 ("_ \<^raw:\ensuremath{\triangleleft}> _" [100, 100] 100) and
    57   Append_rexp_rhs ("_ \<^raw:\ensuremath{\triangleleft}> _" [100, 100] 50) and
    58   Append_rexp_rhs ("_ \<^raw:\ensuremath{\triangleleft}> _" [100, 100] 50) and
    58   
    59   
    59   uminus ("\<^raw:\ensuremath{\overline{>_\<^raw:}}>" [100] 100) and
    60   uminus ("\<^raw:\ensuremath{\overline{>_\<^raw:}}>" [100] 100) and
    60   tag_str_Plus ("tag\<^isub>A\<^isub>L\<^isub>T _ _" [100, 100] 100) and
    61   tag_str_Plus ("tag\<^bsub>PLUS\<^esub> _ _" [100, 100] 100) and
    61   tag_str_Plus ("tag\<^isub>A\<^isub>L\<^isub>T _ _ _" [100, 100, 100] 100) and
    62   tag_str_Plus ("tag\<^bsub>PLUS\<^esub> _ _ _" [100, 100, 100] 100) and
    62   tag_str_Times ("tag\<^isub>S\<^isub>E\<^isub>Q _ _" [100, 100] 100) and
    63   tag_str_Times ("tag\<^isub>S\<^isub>E\<^isub>Q _ _" [100, 100] 100) and
    63   tag_str_Times ("tag\<^isub>S\<^isub>E\<^isub>Q _ _ _" [100, 100, 100] 100) and
    64   tag_str_Times ("tag\<^isub>S\<^isub>E\<^isub>Q _ _ _" [100, 100, 100] 100) and
    64   tag_str_Star ("tag\<^isub>S\<^isub>T\<^isub>A\<^isub>R _" [100] 100) and
    65   tag_str_Star ("tag\<^isub>S\<^isub>T\<^isub>A\<^isub>R _" [100] 100) and
    65   tag_str_Star ("tag\<^isub>S\<^isub>T\<^isub>A\<^isub>R _ _" [100, 100] 100)
    66   tag_str_Star ("tag\<^isub>S\<^isub>T\<^isub>A\<^isub>R _ _" [100, 100] 100) and
       
    67   tag_eq_rel ("\<^raw:$\threesim$>\<^bsub>_\<^esub>") and
       
    68   Delta ("\<Delta>'(_')") and
       
    69   nullable ("\<delta>'(_')")
    66 
    70 
    67 lemma meta_eq_app:
    71 lemma meta_eq_app:
    68   shows "f \<equiv> \<lambda>x. g x \<Longrightarrow> f x \<equiv> g x"
    72   shows "f \<equiv> \<lambda>x. g x \<Longrightarrow> f x \<equiv> g x"
    69   by auto
    73   by auto
    70 
    74 
   225   \noindent
   229   \noindent
   226   changes the type---the disjoint union is not a set, but a set of
   230   changes the type---the disjoint union is not a set, but a set of
   227   pairs. Using this definition for disjoint union means we do not have a
   231   pairs. Using this definition for disjoint union means we do not have a
   228   single type for automata. As a result we will not be able to define a regular
   232   single type for automata. As a result we will not be able to define a regular
   229   language as one for which there exists an automaton that recognises all its
   233   language as one for which there exists an automaton that recognises all its
   230   strings. Similarly, we cannot state properties about \emph{all} automata,
   234   strings, since there is no type quantification available in HOL (unlike in Coq, for
   231   since there is no type quantification available in HOL (unlike in Coq, for
       
   232   example).
   235   example).
   233 
   236 
   234   An alternative, which provides us with a single type for automata, is to give every 
   237   An alternative, which provides us with a single type for automata, is to give every 
   235   state node an identity, for example a natural
   238   state node an identity, for example a natural
   236   number, and then be careful to rename these identities apart whenever
   239   number, and then be careful to rename these identities apart whenever
   316   will be needed for regular expressions. Moreover, a reasoning infrastructure 
   319   will be needed for regular expressions. Moreover, a reasoning infrastructure 
   317   (like induction and recursion) comes for free in HOL-based theorem provers. 
   320   (like induction and recursion) comes for free in HOL-based theorem provers. 
   318   This has recently been exploited in HOL4 with a formalisation of
   321   This has recently been exploited in HOL4 with a formalisation of
   319   regular expression matching based on derivatives \cite{OwensSlind08} and
   322   regular expression matching based on derivatives \cite{OwensSlind08} and
   320   with an equivalence checker for regular expressions in Isabelle/HOL
   323   with an equivalence checker for regular expressions in Isabelle/HOL
   321   \cite{KraussNipkow11}.  The purpose of this paper is to show that a central
   324   \cite{KraussNipkow11}.  The main purpose of this paper is to show that a central
   322   result about regular languages---the Myhill-Nerode theorem---can be
   325   result about regular languages---the Myhill-Nerode theorem---can be
   323   recreated by only using regular expressions. This theorem gives necessary
   326   recreated by only using regular expressions. This theorem gives necessary
   324   and sufficient conditions for when a language is regular. As a corollary of
   327   and sufficient conditions for when a language is regular. As a corollary of
   325   this theorem we can easily establish the usual closure properties, including
   328   this theorem we can easily establish the usual closure properties, including
   326   complementation, for regular languages.\medskip
   329   complementation, for regular languages.\medskip
   327   
   330   
   328   \noindent
   331   \noindent 
   329   {\bf Contributions:} There is an extensive literature on regular languages.
   332   {\bf Contributions:} There is an extensive literature on regular
   330   To our best knowledge, our proof of the Myhill-Nerode theorem is the first
   333   languages.  To our best knowledge, our proof of the Myhill-Nerode theorem is
   331   that is based on regular expressions, only. The part of this theorem stating
   334   the first that is based on regular expressions, only. The part of this
   332   that finitely many partitions imply regularity of the language is proved by 
   335   theorem stating that finitely many partitions imply regularity of the
   333   an argument about solving equational sytems.  This argument seems to be folklore.
   336   language is proved by an argument about solving equational sytems.  This
   334   For the other part, we give two proofs: a
   337   argument appears to be folklore. For the other part, we give two proofs: one
   335   direct proof using certain tagging-functions, and an indirect proof using
   338   direct proof using certain tagging-functions, and another indirect proof
   336   Antimirov's partial derivatives \cite{Antimirov95} (also earlier russion work). 
   339   using Antimirov's partial derivatives \cite{Antimirov95}. Again to our best
   337   Again to our best knowledge, the tagging-functions have not been used before to
   340   knowledge, the tagging-functions have not been used before to establish the
   338   establish the Myhill-Nerode theorem. 
   341   Myhill-Nerode theorem. Derivatives of regular expressions have been used
   339 
   342   extensively in the literature, unlike partial derivatives. However, partial
       
   343   derivatives are more suitable in the context of the Myhill-Nerode theorem,
       
   344   since it is easier to establish formally their finiteness result.
   340 *}
   345 *}
   341 
   346 
   342 section {* Preliminaries *}
   347 section {* Preliminaries *}
   343 
   348 
   344 text {*
   349 text {*
   422   @{term "s \<notin> X \<cdot> (A \<up> Suc k)"} since its length is only @{text k}
   427   @{term "s \<notin> X \<cdot> (A \<up> Suc k)"} since its length is only @{text k}
   423   (the strings in @{term "X \<cdot> (A \<up> Suc k)"} are all longer). 
   428   (the strings in @{term "X \<cdot> (A \<up> Suc k)"} are all longer). 
   424   From @{text "(*)"} it follows then that
   429   From @{text "(*)"} it follows then that
   425   @{term s} must be an element in @{term "(\<Union>m\<in>{0..k}. B \<cdot> (A \<up> m))"}. This in turn
   430   @{term s} must be an element in @{term "(\<Union>m\<in>{0..k}. B \<cdot> (A \<up> m))"}. This in turn
   426   implies that @{term s} is in @{term "(\<Union>n. B \<cdot> (A \<up> n))"}. Using Prop.~\ref{langprops}@{text "(iii)"} 
   431   implies that @{term s} is in @{term "(\<Union>n. B \<cdot> (A \<up> n))"}. Using Prop.~\ref{langprops}@{text "(iii)"} 
   427   this is equal to @{term "B \<cdot> A\<star>"}, as we needed to show.\qed
   432   this is equal to @{term "B \<cdot> A\<star>"}, as we needed to show.
   428   \end{proof}
   433   \end{proof}
   429 
   434 
   430   \noindent
   435   \noindent
   431   Regular expressions are defined as the inductive datatype
   436   Regular expressions are defined as the inductive datatype
   432 
   437 
   480 
   485 
   481 
   486 
   482 section {* The Myhill-Nerode Theorem, First Part *}
   487 section {* The Myhill-Nerode Theorem, First Part *}
   483 
   488 
   484 text {*
   489 text {*
   485   Folklore: Henzinger (arden-DFA-regexp.pdf)
   490   \footnote{Folklore: Henzinger (arden-DFA-regexp.pdf); Hofmann}
   486 
       
   487 
   491 
   488   \noindent
   492   \noindent
   489   The key definition in the Myhill-Nerode theorem is the
   493   The key definition in the Myhill-Nerode theorem is the
   490   \emph{Myhill-Nerode relation}, which states that w.r.t.~a language two 
   494   \emph{Myhill-Nerode relation}, which states that w.r.t.~a language two 
   491   strings are related, provided there is no distinguishing extension in this
   495   strings are related, provided there is no distinguishing extension in this
   492   language. This can be defined as a tertiary relation.
   496   language. This can be defined as a tertiary relation.
   493 
   497 
   494   \begin{dfntn}[Myhill-Nerode Relation] Given a language @{text A}, two strings @{text x} and
   498   \begin{dfntn}[Myhill-Nerode Relation]\label{myhillneroderel} 
       
   499   Given a language @{text A}, two strings @{text x} and
   495   @{text y} are Myhill-Nerode related provided
   500   @{text y} are Myhill-Nerode related provided
   496   \begin{center}
   501   \begin{center}
   497   @{thm str_eq_def[simplified str_eq_rel_def Pair_Collect]}
   502   @{thm str_eq_def[simplified str_eq_rel_def Pair_Collect]}
   498   \end{center}
   503   \end{center}
   499   \end{dfntn}
   504   \end{dfntn}
   530   \end{equation}
   535   \end{equation}
   531 
   536 
   532   \noindent
   537   \noindent
   533   In our running example, @{text "X\<^isub>2"} is the only 
   538   In our running example, @{text "X\<^isub>2"} is the only 
   534   equivalence class in @{term "finals {[c]}"}.
   539   equivalence class in @{term "finals {[c]}"}.
   535   It is straightforward to show that in general @{thm lang_is_union_of_finals} and 
   540   It is straightforward to show that in general 
   536   @{thm finals_in_partitions} hold. 
   541 
       
   542   \begin{center}
       
   543   @{thm lang_is_union_of_finals}\hspace{15mm} 
       
   544   @{thm finals_in_partitions} 
       
   545   \end{center}
       
   546 
       
   547   \noindent
       
   548   hold. 
   537   Therefore if we know that there exists a regular expression for every
   549   Therefore if we know that there exists a regular expression for every
   538   equivalence class in \mbox{@{term "finals A"}} (which by assumption must be
   550   equivalence class in \mbox{@{term "finals A"}} (which by assumption must be
   539   a finite set), then we can use @{text "\<bigplus>"} to obtain a regular expression 
   551   a finite set), then we can use @{text "\<bigplus>"} to obtain a regular expression 
   540   that matches every string in @{text A}.
   552   that matches every string in @{text A}.
   541 
   553 
   856   \begin{proof}
   868   \begin{proof}
   857   Finiteness is given by the assumption and the way how we set up the 
   869   Finiteness is given by the assumption and the way how we set up the 
   858   initial equational system. Soundness is proved in Lem.~\ref{inv}. Distinctness
   870   initial equational system. Soundness is proved in Lem.~\ref{inv}. Distinctness
   859   follows from the fact that the equivalence classes are disjoint. The @{text ardenable}
   871   follows from the fact that the equivalence classes are disjoint. The @{text ardenable}
   860   property also follows from the setup of the initial equational system, as does 
   872   property also follows from the setup of the initial equational system, as does 
   861   validity.\qed
   873   validity.
   862   \end{proof}
   874   \end{proof}
   863 
   875 
   864   \noindent
   876   \noindent
   865   Next we show that @{text Iter} preserves the invariant.
   877   Next we show that @{text Iter} preserves the invariant.
   866 
   878 
   888   given because @{const Arden} removes an equivalence class from @{text yrhs}
   900   given because @{const Arden} removes an equivalence class from @{text yrhs}
   889   and then @{const Subst_all} removes @{text Y} from the equational system.
   901   and then @{const Subst_all} removes @{text Y} from the equational system.
   890   Having proved the implication above, we can instantiate @{text "ES"} with @{text "ES - {(Y, yrhs)}"}
   902   Having proved the implication above, we can instantiate @{text "ES"} with @{text "ES - {(Y, yrhs)}"}
   891   which matches with our proof-obligation of @{const "Subst_all"}. Since
   903   which matches with our proof-obligation of @{const "Subst_all"}. Since
   892   \mbox{@{term "ES = ES - {(Y, yrhs)} \<union> {(Y, yrhs)}"}}, we can use the assumption 
   904   \mbox{@{term "ES = ES - {(Y, yrhs)} \<union> {(Y, yrhs)}"}}, we can use the assumption 
   893   to complete the proof.\qed 
   905   to complete the proof.
   894   \end{proof}
   906   \end{proof}
   895 
   907 
   896   \noindent
   908   \noindent
   897   We also need the fact that @{text Iter} decreases the termination measure.
   909   We also need the fact that @{text Iter} decreases the termination measure.
   898 
   910 
   904   By assumption we know that @{text "ES"} is finite and has more than one element.
   916   By assumption we know that @{text "ES"} is finite and has more than one element.
   905   Therefore there must be an element @{term "(Y, yrhs) \<in> ES"} with 
   917   Therefore there must be an element @{term "(Y, yrhs) \<in> ES"} with 
   906   @{term "(Y, yrhs) \<noteq> (X, rhs)"}. Using the distinctness property we can infer
   918   @{term "(Y, yrhs) \<noteq> (X, rhs)"}. Using the distinctness property we can infer
   907   that @{term "Y \<noteq> X"}. We further know that @{text "Remove ES Y yrhs"}
   919   that @{term "Y \<noteq> X"}. We further know that @{text "Remove ES Y yrhs"}
   908   removes the equation @{text "Y = yrhs"} from the system, and therefore 
   920   removes the equation @{text "Y = yrhs"} from the system, and therefore 
   909   the cardinality of @{const Iter} strictly decreases.\qed
   921   the cardinality of @{const Iter} strictly decreases.
   910   \end{proof}
   922   \end{proof}
   911 
   923 
   912   \noindent
   924   \noindent
   913   This brings us to our property we want to establish for @{text Solve}.
   925   This brings us to our property we want to establish for @{text Solve}.
   914 
   926 
   936   does not holds. By the stronger invariant we know there exists such a @{text "rhs"}
   948   does not holds. By the stronger invariant we know there exists such a @{text "rhs"}
   937   with @{term "(X, rhs) \<in> ES"}. Because @{text Cond} is not true, we know the cardinality
   949   with @{term "(X, rhs) \<in> ES"}. Because @{text Cond} is not true, we know the cardinality
   938   of @{text ES} is @{text 1}. This means @{text "ES"} must actually be the set @{text "{(X, rhs)}"},
   950   of @{text ES} is @{text 1}. This means @{text "ES"} must actually be the set @{text "{(X, rhs)}"},
   939   for which the invariant holds. This allows us to conclude that 
   951   for which the invariant holds. This allows us to conclude that 
   940   @{term "Solve X (Init (UNIV // \<approx>A)) = {(X, rhs)}"} and @{term "invariant {(X, rhs)}"} hold,
   952   @{term "Solve X (Init (UNIV // \<approx>A)) = {(X, rhs)}"} and @{term "invariant {(X, rhs)}"} hold,
   941   as needed.\qed
   953   as needed.
   942   \end{proof}
   954   \end{proof}
   943 
   955 
   944   \noindent
   956   \noindent
   945   With this lemma in place we can show that for every equivalence class in @{term "UNIV // \<approx>A"}
   957   With this lemma in place we can show that for every equivalence class in @{term "UNIV // \<approx>A"}
   946   there exists a regular expression.
   958   there exists a regular expression.
   958   invariant and Lem.~\ref{ardenable}. Using the validity property for the equation @{text "X = rhs"},
   970   invariant and Lem.~\ref{ardenable}. Using the validity property for the equation @{text "X = rhs"},
   959   we can infer that @{term "rhss rhs \<subseteq> {X}"} and because the @{text Arden} operation
   971   we can infer that @{term "rhss rhs \<subseteq> {X}"} and because the @{text Arden} operation
   960   removes that @{text X} from @{text rhs}, that @{term "rhss (Arden X rhs) = {}"}.
   972   removes that @{text X} from @{text rhs}, that @{term "rhss (Arden X rhs) = {}"}.
   961   This means the right-hand side @{term "Arden X rhs"} can only consist of terms of the form @{term "Lam r"}.
   973   This means the right-hand side @{term "Arden X rhs"} can only consist of terms of the form @{term "Lam r"}.
   962   So we can collect those (finitely many) regular expressions @{text rs} and have @{term "X = L (\<Uplus>rs)"}.
   974   So we can collect those (finitely many) regular expressions @{text rs} and have @{term "X = L (\<Uplus>rs)"}.
   963   With this we can conclude the proof.\qed
   975   With this we can conclude the proof.
   964   \end{proof}
   976   \end{proof}
   965 
   977 
   966   \noindent
   978   \noindent
   967   Lem.~\ref{every_eqcl_has_reg} allows us to finally give a proof for the first direction
   979   Lem.~\ref{every_eqcl_has_reg} allows us to finally give a proof for the first direction
   968   of the Myhill-Nerode theorem.
   980   of the Myhill-Nerode theorem.
   974   in @{term "finals A"} there exists a regular expression. Moreover by assumption 
   986   in @{term "finals A"} there exists a regular expression. Moreover by assumption 
   975   we know that @{term "finals A"} must be finite, and therefore there must be a finite
   987   we know that @{term "finals A"} must be finite, and therefore there must be a finite
   976   set of regular expressions @{text "rs"} such that
   988   set of regular expressions @{text "rs"} such that
   977   @{term "\<Union>(finals A) = L (\<Uplus>rs)"}.
   989   @{term "\<Union>(finals A) = L (\<Uplus>rs)"}.
   978   Since the left-hand side is equal to @{text A}, we can use @{term "\<Uplus>rs"} 
   990   Since the left-hand side is equal to @{text A}, we can use @{term "\<Uplus>rs"} 
   979   as the regular expression that is needed in the theorem.\qed
   991   as the regular expression that is needed in the theorem.
   980   \end{proof}
   992   \end{proof}
   981 *}
   993 *}
   982 
   994 
   983 
   995 
   984 
   996 
   985 
   997 
   986 section {* Myhill-Nerode, Second Part *}
   998 section {* Myhill-Nerode, Second Part *}
   987 
   999 
   988 text {*
  1000 text {*
   989   \noindent
  1001   \noindent
   990   We will prove in this section the second part of the Myhill-Nerode
  1002   In this section and the next we will give two proofs for establishing the second 
   991   theorem. It can be formulated in our setting as follows:
  1003   part of the Myhill-Nerode theorem. It can be formulated in our setting as follows:
   992 
  1004 
   993   \begin{thrm}
  1005   \begin{thrm}
   994   Given @{text "r"} is a regular expression, then @{thm Myhill_Nerode2}.
  1006   Given @{text "r"} is a regular expression, then @{thm Myhill_Nerode2}.
   995   \end{thrm}  
  1007   \end{thrm}  
   996 
  1008 
   997   \noindent
  1009   \noindent
   998   The proof will be by induction on the structure of @{text r}. It turns out
  1010   The first proof will be by induction on the structure of @{text r}. It turns out
   999   the base cases are straightforward.
  1011   the base cases are straightforward.
  1000 
  1012 
  1001 
  1013 
  1002   \begin{proof}[Base Cases]
  1014   \begin{proof}[Base Cases]
  1003   The cases for @{const ZERO}, @{const ONE} and @{const ATOM} are routine, because 
  1015   The cases for @{const ZERO}, @{const ONE} and @{const ATOM} are routine, because 
  1010   @{thm quot_atom_subset}
  1022   @{thm quot_atom_subset}
  1011   \end{tabular}
  1023   \end{tabular}
  1012   \end{center}
  1024   \end{center}
  1013 
  1025 
  1014   \noindent
  1026   \noindent
  1015   hold, which shows that @{term "UNIV // \<approx>(L r)"} must be finite.\qed
  1027   hold, which shows that @{term "UNIV // \<approx>(lang r)"} must be finite.
  1016   \end{proof}
  1028   \end{proof}
  1017 
  1029 
  1018   \noindent
  1030   \noindent
  1019   Much more interesting, however, are the inductive cases. They seem hard to solve 
  1031   Much more interesting, however, are the inductive cases. They seem hard to solve 
  1020   directly. The reader is invited to try. 
  1032   directly. The reader is invited to try. 
  1021 
  1033 
  1022   Our proof will rely on some
  1034   Our first proof will rely on some
  1023   \emph{tagging-functions} defined over strings. Given the inductive hypothesis, it will 
  1035   \emph{tagging-functions} defined over strings. Given the inductive hypothesis, it will 
  1024   be easy to prove that the \emph{range} of these tagging-functions is finite
  1036   be easy to prove that the \emph{range} of these tagging-functions is finite. 
  1025   (the range of a function @{text f} is defined as @{text "range f \<equiv> f ` UNIV"}).
  1037   The range of a function @{text f} is defined as 
       
  1038   
       
  1039   \begin{center}
       
  1040   @{text "range f \<equiv> f ` UNIV"}
       
  1041   \end{center}
       
  1042 
       
  1043   \noindent
       
  1044   that means we take the image of @{text f} w.r.t.~all elements in the domain. 
  1026   With this we will be able to infer that the tagging-functions, seen as relations,
  1045   With this we will be able to infer that the tagging-functions, seen as relations,
  1027   give rise to finitely many equivalence classes of @{const UNIV}. Finally we 
  1046   give rise to finitely many equivalence classes of @{const UNIV}. Finally we 
  1028   will show that the tagging-relations are more refined than @{term "\<approx>(L r)"}, which
  1047   will show that the tagging-relations are more refined than @{term "\<approx>(lang r)"}, which
  1029   implies that @{term "UNIV // \<approx>(L r)"} must also be finite (a relation @{text "R\<^isub>1"} 
  1048   implies that @{term "UNIV // \<approx>(lang r)"} must also be finite---a relation @{text "R\<^isub>1"} 
  1030   is said to \emph{refine} @{text "R\<^isub>2"} provided @{text "R\<^isub>1 \<subseteq> R\<^isub>2"}).
  1049   is said to \emph{refine} @{text "R\<^isub>2"} provided @{text "R\<^isub>1 \<subseteq> R\<^isub>2"}.
  1031   We formally define the notion of a \emph{tagging-relation} as follows.
  1050   We formally define the notion of a \emph{tagging-relation} as follows.
  1032 
  1051 
  1033   \begin{dfntn}[Tagging-Relation] Given a tagging-function @{text tag}, then two strings @{text x}
  1052   \begin{dfntn}[Tagging-Relation] Given a tagging-function @{text tag}, then two strings @{text x}
  1034   and @{text y} are \emph{tag-related} provided
  1053   and @{text y} are \emph{tag-related} provided
  1035   \begin{center}
  1054   \begin{center}
  1036   @{text "x =tag= y \<equiv> tag x = tag y"}\;.
  1055   @{text "x \<^raw:$\threesim$>\<^bsub>tag\<^esub> y \<equiv> tag x = tag y"}\;.
  1037   \end{center}
  1056   \end{center}
  1038   \end{dfntn}
  1057   \end{dfntn}
  1039 
  1058 
  1040 
  1059 
  1041   In order to establish finiteness of a set @{text A}, we shall use the following powerful
  1060   In order to establish finiteness of a set @{text A}, we shall use the following powerful
  1061   and so also finite. Injectivity amounts to showing that @{text "X = Y"} under the
  1080   and so also finite. Injectivity amounts to showing that @{text "X = Y"} under the
  1062   assumptions that @{text "X, Y \<in> "}~@{term "UNIV // =tag="} and @{text "f X = f Y"}.
  1081   assumptions that @{text "X, Y \<in> "}~@{term "UNIV // =tag="} and @{text "f X = f Y"}.
  1063   From the assumptions we can obtain @{text "x \<in> X"} and @{text "y \<in> Y"} with 
  1082   From the assumptions we can obtain @{text "x \<in> X"} and @{text "y \<in> Y"} with 
  1064   @{text "tag x = tag y"}. Since @{text x} and @{text y} are tag-related, this in 
  1083   @{text "tag x = tag y"}. Since @{text x} and @{text y} are tag-related, this in 
  1065   turn means that the equivalence classes @{text X}
  1084   turn means that the equivalence classes @{text X}
  1066   and @{text Y} must be equal.\qed
  1085   and @{text Y} must be equal.
  1067   \end{proof}
  1086   \end{proof}
  1068 
  1087 
  1069   \begin{lmm}\label{fintwo} 
  1088   \begin{lmm}\label{fintwo} 
  1070   Given two equivalence relations @{text "R\<^isub>1"} and @{text "R\<^isub>2"}, whereby
  1089   Given two equivalence relations @{text "R\<^isub>1"} and @{text "R\<^isub>2"}, whereby
  1071   @{text "R\<^isub>1"} refines @{text "R\<^isub>2"}.
  1090   @{text "R\<^isub>1"} refines @{text "R\<^isub>2"}.
  1075 
  1094 
  1076   \begin{proof}
  1095   \begin{proof}
  1077   We prove this lemma again using \eqref{finiteimageD}. This time we set @{text f} to
  1096   We prove this lemma again using \eqref{finiteimageD}. This time we set @{text f} to
  1078   be @{text "X \<mapsto>"}~@{term "{R\<^isub>1 `` {x} | x. x \<in> X}"}. It is easy to see that 
  1097   be @{text "X \<mapsto>"}~@{term "{R\<^isub>1 `` {x} | x. x \<in> X}"}. It is easy to see that 
  1079   @{term "finite (f ` (UNIV // R\<^isub>2))"} because it is a subset of @{term "Pow (UNIV // R\<^isub>1)"},
  1098   @{term "finite (f ` (UNIV // R\<^isub>2))"} because it is a subset of @{term "Pow (UNIV // R\<^isub>1)"},
  1080   which is finite by assumption. What remains to be shown is that @{text f} is injective
  1099   which must be finite by assumption. What remains to be shown is that @{text f} is injective
  1081   on @{term "UNIV // R\<^isub>2"}. This is equivalent to showing that two equivalence 
  1100   on @{term "UNIV // R\<^isub>2"}. This is equivalent to showing that two equivalence 
  1082   classes, say @{text "X"} and @{text Y}, in @{term "UNIV // R\<^isub>2"} are equal, provided
  1101   classes, say @{text "X"} and @{text Y}, in @{term "UNIV // R\<^isub>2"} are equal, provided
  1083   @{text "f X = f Y"}. For @{text "X = Y"} to be equal, we have to find two elements
  1102   @{text "f X = f Y"}. For @{text "X = Y"} to be equal, we have to find two elements
  1084   @{text "x \<in> X"} and @{text "y \<in> Y"} such that they are @{text R\<^isub>2} related.
  1103   @{text "x \<in> X"} and @{text "y \<in> Y"} such that they are @{text R\<^isub>2} related.
  1085   We know there exists a @{text "x \<in> X"} with \mbox{@{term "X = R\<^isub>2 `` {x}"}}. 
  1104   We know there exists a @{text "x \<in> X"} with \mbox{@{term "X = R\<^isub>2 `` {x}"}}. 
  1086   From the latter fact we can infer that @{term "R\<^isub>1 ``{x} \<in> f X"}
  1105   From the latter fact we can infer that @{term "R\<^isub>1 ``{x} \<in> f X"}
  1087   and further @{term "R\<^isub>1 ``{x} \<in> f Y"}. This means we can obtain a @{text y}
  1106   and further @{term "R\<^isub>1 ``{x} \<in> f Y"}. This means we can obtain a @{text y}
  1088   such that @{term "R\<^isub>1 `` {x} = R\<^isub>1 `` {y}"} holds. Consequently @{text x} and @{text y}
  1107   such that @{term "R\<^isub>1 `` {x} = R\<^isub>1 `` {y}"} holds. Consequently @{text x} and @{text y}
  1089   are @{text "R\<^isub>1"}-related. Since by assumption @{text "R\<^isub>1"} refines @{text "R\<^isub>2"},
  1108   are @{text "R\<^isub>1"}-related. Since by assumption @{text "R\<^isub>1"} refines @{text "R\<^isub>2"},
  1090   they must also be @{text "R\<^isub>2"}-related, as we need to show.\qed
  1109   they must also be @{text "R\<^isub>2"}-related, as we need to show.
  1091   \end{proof}
  1110   \end{proof}
  1092 
  1111 
  1093   \noindent
  1112   \noindent
  1094   Chaining Lem.~\ref{finone} and \ref{fintwo} together, means in order to show
  1113   Chaining Lem.~\ref{finone} and \ref{fintwo} together, means in order to show
  1095   that @{term "UNIV // \<approx>(L r)"} is finite, we have to find a tagging-function whose
  1114   that @{term "UNIV // \<approx>(lang r)"} is finite, we have to find a tagging-function whose
  1096   range can be shown to be finite and whose tagging-relation refines @{term "\<approx>(L r)"}.
  1115   range can be shown to be finite and whose tagging-relation refines @{term "\<approx>(lang r)"}.
  1097   Let us attempt the @{const PLUS}-case first.
  1116   Let us attempt the @{const PLUS}-case first.
  1098 
  1117 
  1099   \begin{proof}[@{const "PLUS"}-Case] 
  1118   \begin{proof}[@{const "PLUS"}-Case] 
  1100   We take as tagging-function 
  1119   We take as tagging-function 
  1101   %
  1120   %
  1105 
  1124 
  1106   \noindent
  1125   \noindent
  1107   where @{text "A"} and @{text "B"} are some arbitrary languages.
  1126   where @{text "A"} and @{text "B"} are some arbitrary languages.
  1108   We can show in general, if @{term "finite (UNIV // \<approx>A)"} and @{term "finite (UNIV // \<approx>B)"}
  1127   We can show in general, if @{term "finite (UNIV // \<approx>A)"} and @{term "finite (UNIV // \<approx>B)"}
  1109   then @{term "finite ((UNIV // \<approx>A) \<times> (UNIV // \<approx>B))"} holds. The range of
  1128   then @{term "finite ((UNIV // \<approx>A) \<times> (UNIV // \<approx>B))"} holds. The range of
  1110   @{term "tag_str_PLUS A B"} is a subset of this product set---so finite. It remains to be shown
  1129   @{term "tag_str_Plus A B"} is a subset of this product set---so finite. It remains to be shown
  1111   that @{text "=tag\<^isub>A\<^isub>L\<^isub>T A B="} refines @{term "\<approx>(A \<union> B)"}. This amounts to 
  1130   that @{text "=tag\<^isub>A\<^isub>L\<^isub>T A B="} refines @{term "\<approx>(A \<union> B)"}. This amounts to 
  1112   showing
  1131   showing
  1113   %
  1132   %
  1114   \begin{center}
  1133   \begin{center}
  1115   @{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"}
  1134   @{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"}
  1127   \eqref{pattern} we just have to unfold the definition of the tagging-function and analyse 
  1146   \eqref{pattern} we just have to unfold the definition of the tagging-function and analyse 
  1128   in which set, @{text A} or @{text B}, the string @{term "x @ z"} is. 
  1147   in which set, @{text A} or @{text B}, the string @{term "x @ z"} is. 
  1129   The definition of the tagging-function will give us in each case the
  1148   The definition of the tagging-function will give us in each case the
  1130   information to infer that @{text "y @ z \<in> A \<union> B"}.
  1149   information to infer that @{text "y @ z \<in> A \<union> B"}.
  1131   Finally we
  1150   Finally we
  1132   can discharge this case by setting @{text A} to @{term "L r\<^isub>1"} and @{text B} to @{term "L r\<^isub>2"}.\qed
  1151   can discharge this case by setting @{text A} to @{term "lang r\<^isub>1"} and @{text B} to @{term "lang r\<^isub>2"}.
  1133   \end{proof}
  1152   \end{proof}
  1134 
  1153 
  1135 
  1154 
  1136   \noindent
  1155   \noindent
  1137   The pattern in \eqref{pattern} is repeated for the other two cases. Unfortunately,
  1156   The pattern in \eqref{pattern} is repeated for the other two cases. Unfortunately,
  1277   Second, there exists a @{text "z'"} such that @{term "x @ z' \<in> A"} and @{text "z - z' \<in> B"}.
  1296   Second, there exists a @{text "z'"} such that @{term "x @ z' \<in> A"} and @{text "z - z' \<in> B"}.
  1278   By the assumption about @{term "tag_str_TIMES A B"} we have
  1297   By the assumption about @{term "tag_str_TIMES A B"} we have
  1279   @{term "\<approx>A `` {x} = \<approx>A `` {y}"} and thus @{term "x \<approx>A y"}. Which means by the Myhill-Nerode
  1298   @{term "\<approx>A `` {x} = \<approx>A `` {y}"} and thus @{term "x \<approx>A y"}. Which means by the Myhill-Nerode
  1280   relation that @{term "y @ z' \<in> A"} holds. Using @{text "z - z' \<in> B"}, we can conclude also in this case
  1299   relation that @{term "y @ z' \<in> A"} holds. Using @{text "z - z' \<in> B"}, we can conclude also in this case
  1281   with @{term "y @ z \<in> A \<cdot> B"}. We again can complete the @{const TIMES}-case
  1300   with @{term "y @ z \<in> A \<cdot> B"}. We again can complete the @{const TIMES}-case
  1282   by setting @{text A} to @{term "L r\<^isub>1"} and @{text B} to @{term "L r\<^isub>2"}.\qed 
  1301   by setting @{text A} to @{term "lang r\<^isub>1"} and @{text B} to @{term "lang r\<^isub>2"}. 
  1283   \end{proof}
  1302   \end{proof}
  1284   
  1303   
  1285   \noindent
  1304   \noindent
  1286   The case for @{const STAR} is similar to @{const TIMES}, but poses a few extra challenges. When
  1305   The case for @{const STAR} is similar to @{const TIMES}, but poses a few extra challenges. When
  1287   we analyse the case that @{text "x @ z"} is an element in @{term "A\<star>"} and @{text x} is not the 
  1306   we analyse the case that @{text "x @ z"} is an element in @{term "A\<star>"} and @{text x} is not the 
  1381   \noindent 
  1400   \noindent 
  1382   and we know that we have a @{term "y' \<in> A\<star>"} and @{text "y' < y"}
  1401   and we know that we have a @{term "y' \<in> A\<star>"} and @{text "y' < y"}
  1383   and also know @{term "(x - x'\<^isub>m\<^isub>a\<^isub>x) \<approx>A (y - y')"}. Unfolding the Myhill-Nerode
  1402   and also know @{term "(x - x'\<^isub>m\<^isub>a\<^isub>x) \<approx>A (y - y')"}. Unfolding the Myhill-Nerode
  1384   relation we know @{term "(y - y') @ z\<^isub>a \<in> A"}. We also know that @{term "z\<^isub>b \<in> A\<star>"}.
  1403   relation we know @{term "(y - y') @ z\<^isub>a \<in> A"}. We also know that @{term "z\<^isub>b \<in> A\<star>"}.
  1385   Therefore @{term "y' @ ((y - y') @ z\<^isub>a) @ z\<^isub>b \<in> A\<star>"}, which means
  1404   Therefore @{term "y' @ ((y - y') @ z\<^isub>a) @ z\<^isub>b \<in> A\<star>"}, which means
  1386   @{term "y @ z \<in> A\<star>"}. As the last step we have to set @{text "A"} to @{term "L r"} and
  1405   @{term "y @ z \<in> A\<star>"}. As the last step we have to set @{text "A"} to @{term "lang r"} and
  1387   complete the proof.\qed
  1406   complete the proof.
  1388   \end{proof}
  1407   \end{proof}
  1389 *}
  1408 *}
  1390 
  1409 
  1391 section {* Second Part based on Partial Derivatives *}
  1410 section {* Second Part based on Partial Derivatives *}
  1392 
  1411 
  1393 text {*
  1412 text {*
  1394   \noindent
  1413   \noindent
  1395   As we have seen in the previous section, in order to establish
  1414   As we have seen in the previous section, in order to establish
  1396   the second direction of the Myhill-Nerode theorem, we need to find 
  1415   the second direction of the Myhill-Nerode theorem, we need to find 
  1397   a more refined relation (more refined than ??) for which we can
  1416   a more refined relation than @{term "\<approx>(lang r)"} for which we can
  1398   show that there are only finitely many equivalence classes.
  1417   show that there are only finitely many equivalence classes. So far we 
  1399   Brzozowski presented in the Appendix of~\cite{Brzozowski64} 
  1418   showed this by induction on @{text "r"}. However, there is also 
       
  1419   an indirect method to come up with such a refined relation. Assume
       
  1420   the following two definitions for a left-quotient of a language, which 
       
  1421   we write as @{term "Der c A"} and @{term "Ders s A"} where 
       
  1422   @{text c} is a character and @{text s} a string:
       
  1423 
       
  1424   \begin{center}
       
  1425   \begin{tabular}{r@ {\hspace{1mm}}c@ {\hspace{2mm}}l}
       
  1426   @{thm (lhs) Der_def}  & @{text "\<equiv>"} & @{thm (rhs) Der_def}\\
       
  1427   @{thm (lhs) Ders_def} & @{text "\<equiv>"} & @{thm (rhs) Ders_def}\\
       
  1428   \end{tabular}
       
  1429   \end{center}
       
  1430 
       
  1431   \noindent
       
  1432   Now clearly we have the following relation between the Myhill-Nerode relation
       
  1433   (Definition~\ref{myhillneroderel}) and left-quotients
       
  1434 
       
  1435   \begin{equation}\label{mhders}
       
  1436   @{term "x \<approx>A y"} \hspace{4mm}\text{if and only if}\hspace{4mm} @{term "Ders x A = Ders y A"}
       
  1437   \end{equation}
       
  1438 
       
  1439   \noindent
       
  1440   It is realtively easy to establish the following identidies for left-quotients:
       
  1441   
       
  1442   \begin{center}
       
  1443   \begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{2mm}}l}
       
  1444   @{thm (lhs) Der_zero}  & $=$ & @{thm (rhs) Der_zero}\\
       
  1445   @{thm (lhs) Der_one}   & $=$ & @{thm (rhs) Der_one}\\
       
  1446   @{thm (lhs) Der_atom}  & $=$ & @{thm (rhs) Der_atom}\\
       
  1447   @{thm (lhs) Der_union} & $=$ & @{thm (rhs) Der_union}\\
       
  1448   @{thm (lhs) Der_conc}  & $=$ & @{thm (rhs) Der_conc}\\
       
  1449   @{thm (lhs) Der_star}  & $=$ & @{thm (rhs) Der_star}\\
       
  1450   \end{tabular}
       
  1451   \end{center}
       
  1452 
       
  1453   \noindent
       
  1454   where @{text "\<Delta>"} is a function that tests whether the empty string
       
  1455   is in the language and returns @{term "{[]}"} or @{term "{}"}, respectively.
       
  1456   The only interesting case above is the last one where we use Prop.~\ref{langprops}
       
  1457   in order to infer that @{term "Der c (A\<star>) = Der c (A \<cdot> A\<star>)"}. We can 
       
  1458   then complete the proof by observing that @{term "Delta A \<cdot> Der c (A\<star>) \<subseteq> (Der c A) \<cdot> A\<star>"}.
       
  1459   
       
  1460   Brzozowski observed that the left-quotients for languages of regular
       
  1461   expressions can be calculated directly via the notion of \emph{derivatives
       
  1462   of a regular expressions} \cite{Brzozowski64} which we define in Isabelle/HOL as 
       
  1463   follows:
       
  1464 
       
  1465   \begin{center}
       
  1466   \begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1.5mm}}l@ {}}
       
  1467   @{thm (lhs) der.simps(1)}  & @{text "\<equiv>"} & @{thm (rhs) der.simps(1)}\\
       
  1468   @{thm (lhs) der.simps(2)}  & @{text "\<equiv>"} & @{thm (rhs) der.simps(2)}\\
       
  1469   @{thm (lhs) der.simps(3)[where c'="d"]}  & @{text "\<equiv>"} & @{thm (rhs) der.simps(3)[where c'="d"]}\\
       
  1470   @{thm (lhs) der.simps(4)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]}  
       
  1471      & @{text "\<equiv>"} & @{thm (rhs) der.simps(4)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]}\\
       
  1472   @{thm (lhs) der.simps(5)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]}  
       
  1473      & @{text "\<equiv>"}\\ 
       
  1474   \multicolumn{3}{@ {\hspace{5mm}}l@ {}}{@{thm (rhs) der.simps(5)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]}}\\
       
  1475   @{thm (lhs) der.simps(6)}  & @{text "\<equiv>"} & @{thm (rhs) der.simps(6)}\smallskip\\
       
  1476   @{thm (lhs) ders.simps(1)}  & @{text "\<equiv>"} & @{thm (rhs) ders.simps(1)}\\
       
  1477   @{thm (lhs) ders.simps(2)}  & @{text "\<equiv>"} & @{thm (rhs) ders.simps(2)}\\
       
  1478   \end{tabular}
       
  1479   \end{center}
       
  1480 
       
  1481   \noindent
       
  1482   The function @{term "nullable r"} tests whether the regular expression
       
  1483   can recognise the empty string:
       
  1484 
       
  1485   \begin{center}
       
  1486   \begin{tabular}{cc}
       
  1487   \begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1.5mm}}l@ {}}
       
  1488   @{thm (lhs) nullable.simps(1)}  & @{text "\<equiv>"} & @{thm (rhs) nullable.simps(1)}\\
       
  1489   @{thm (lhs) nullable.simps(2)}  & @{text "\<equiv>"} & @{thm (rhs) nullable.simps(2)}\\
       
  1490   @{thm (lhs) nullable.simps(3)}  & @{text "\<equiv>"} & @{thm (rhs) nullable.simps(3)}\\
       
  1491   \end{tabular} &
       
  1492   \begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1.5mm}}l@ {}}
       
  1493   @{thm (lhs) nullable.simps(4)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]}  
       
  1494      & @{text "\<equiv>"} & @{thm (rhs) nullable.simps(4)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]}\\
       
  1495   @{thm (lhs) nullable.simps(5)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]}  
       
  1496      & @{text "\<equiv>"} & @{thm (rhs) nullable.simps(5)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]}\\
       
  1497   @{thm (lhs) nullable.simps(6)}  & @{text "\<equiv>"} & @{thm (rhs) nullable.simps(6)}\\
       
  1498   \end{tabular}
       
  1499   \end{tabular}
       
  1500   \end{center}
       
  1501 
       
  1502   \noindent
       
  1503   Brzozowski proved 
       
  1504 
       
  1505   \begin{equation}\label{Dersders}
       
  1506   \mbox{\begin{tabular}{l}
       
  1507   @{thm Der_der}\\
       
  1508   @{thm Ders_ders}
       
  1509   \end{tabular}}
       
  1510   \end{equation}
       
  1511 
       
  1512   \noindent
       
  1513   where the first is by induction on @{text r} and the second by a simple
       
  1514   calculation.
       
  1515 
       
  1516   The importance in the context of the Myhill-Nerode theorem is that 
       
  1517   we can use \eqref{mhders} and \eqref{Dersders} in order to derive
       
  1518 
       
  1519   \begin{center}
       
  1520   @{term "x \<approx>(lang r) y"} \hspace{4mm}if and only if\hspace{4mm} 
       
  1521   @{term "lang (ders x r) = lang (ders y r)"}
       
  1522   \end{center}
       
  1523 
       
  1524   \noindent
       
  1525   which means @{term "x \<approx>(lang r) y"} provided @{term "ders x r = ders y r"}.
       
  1526   Consequently, we can use as the tagging relation 
       
  1527   @{text "\<^raw:$\threesim$>\<^bsub>(\<lambda>x. ders x r)\<^esub>"}, which we know refines @{term "\<approx>(lang r)"}. 
       
  1528   This almost helps us because Brozowski also proved that there for every 
       
  1529   language there are only 
       
  1530   finitely `dissimilar' derivatives for a regular expression. Two regulare
       
  1531   expressions are similar if they can be identified using the using the 
       
  1532   ACI-identities
       
  1533 
       
  1534   \begin{center}
       
  1535   \begin{tabular}{cl}
       
  1536   (A) & @{term "Plus (Plus r\<^isub>1 r\<^isub>2) r\<^isub>3"} $\equiv$ @{term "Plus r\<^isub>1 (Plus r\<^isub>2 r\<^isub>3)"}\\
       
  1537   (C) & @{term "Plus r\<^isub>1 r\<^isub>2"} $\equiv$ @{term "Plus r\<^isub>2 r\<^isub>1"}\\
       
  1538   (I) & @{term "Plus r r"} $\equiv$ @{term "r"}\\
       
  1539   \end{tabular}
       
  1540   \end{center}
       
  1541 
       
  1542   \noindent
       
  1543   Without the indentification, we unfortunately obtain infinitely many
       
  1544   derivations (an example is given in \cite[Page~141]{Sakarovitch09}).
       
  1545   Reasoning modulo ACI can be done, but it is very painful in a theorem prover.
       
  1546 
  1400 
  1547 
  1401   in order to prove the second
  1548   in order to prove the second
  1402   direction of the Myhill-Nerode theorem. There he calculates the
  1549   direction of the Myhill-Nerode theorem. There he calculates the
  1403   derivatives for regular expressions and shows that for every
  1550   derivatives for regular expressions and shows that for every
  1404   language there can be only finitely many of them %derivations (if
  1551   language there can be only finitely many of them %derivations (if