Journal/Paper.thy
changeset 193 2a5ac68db24b
parent 190 b73478aaf33e
child 194 5347d7556487
equal deleted inserted replaced
192:ce24ed955cca 193:2a5ac68db24b
    40 
    40 
    41 notation (latex output)
    41 notation (latex output)
    42   str_eq ("\<approx>\<^bsub>_\<^esub>") and
    42   str_eq ("\<approx>\<^bsub>_\<^esub>") and
    43   str_eq_applied ("_ \<approx>\<^bsub>_\<^esub> _") and
    43   str_eq_applied ("_ \<approx>\<^bsub>_\<^esub> _") and
    44   conc (infixr "\<cdot>" 100) and
    44   conc (infixr "\<cdot>" 100) and
    45   star ("_\<^bsup>\<star>\<^esup>") and
    45   star ("_\<^bsup>\<star>\<^esup>" [101] 200) and
    46   pow ("_\<^bsup>_\<^esup>" [100, 100] 100) and
    46   pow ("_\<^bsup>_\<^esup>" [100, 100] 100) and
    47   Suc ("_+1" [100] 100) and
    47   Suc ("_+1" [100] 100) and
    48   quotient ("_ \<^raw:\ensuremath{\!\sslash\!}> _" [90, 90] 90) and
    48   quotient ("_ \<^raw:\ensuremath{\!\sslash\!}> _" [90, 90] 90) and
    49   REL ("\<approx>") and
    49   REL ("\<approx>") and
    50   UPLUS ("_ \<^raw:\ensuremath{\uplus}> _" [90, 90] 90) and
    50   UPLUS ("_ \<^raw:\ensuremath{\uplus}> _" [90, 90] 90) and
    64   tag_Plus ("+tag _ _ _" [100, 100, 100] 100) and
    64   tag_Plus ("+tag _ _ _" [100, 100, 100] 100) and
    65   tag_Times ("\<times>tag _ _" [100, 100] 100) and
    65   tag_Times ("\<times>tag _ _" [100, 100] 100) and
    66   tag_Times ("\<times>tag _ _ _" [100, 100, 100] 100) and
    66   tag_Times ("\<times>tag _ _ _" [100, 100, 100] 100) and
    67   tag_Star ("\<star>tag _" [100] 100) and
    67   tag_Star ("\<star>tag _" [100] 100) and
    68   tag_Star ("\<star>tag _ _" [100, 100] 100) and
    68   tag_Star ("\<star>tag _ _" [100, 100] 100) and
    69   tag_eq ("\<^raw:$\threesim$>\<^bsub>_\<^esub>") and
    69   tag_eq ("\<^raw:$\threesim$>\<^bsub>_\<^esub>" [100] 100) and
    70   Delta ("\<Delta>'(_')") and
    70   Delta ("\<Delta>'(_')") and
    71   nullable ("\<delta>'(_')") and
    71   nullable ("\<delta>'(_')") and
    72   Cons ("_ :: _" [100, 100] 100) and
    72   Cons ("_ :: _" [100, 100] 100) and
    73   Rev ("Rev _" [1000] 100) and
    73   Rev ("Rev _" [1000] 100) and
    74   Der ("Der _ _" [1000, 1000] 100) and
    74   Der ("Der _ _" [1000, 1000] 100) and
    75   ONE ("ONE" 999) and
    75   ONE ("ONE" 999) and
    76   ZERO ("ZERO" 999)
    76   ZERO ("ZERO" 999) and
       
    77   pders_lang ("pderl") and
       
    78   UNIV1 ("UNIV\<^isup>+") and
       
    79   Ders_lang ("Derl")
    77 
    80 
    78 lemma meta_eq_app:
    81 lemma meta_eq_app:
    79   shows "f \<equiv> \<lambda>x. g x \<Longrightarrow> f x \<equiv> g x"
    82   shows "f \<equiv> \<lambda>x. g x \<Longrightarrow> f x \<equiv> g x"
    80   by auto
    83   by auto
    81 
    84 
   150   presented in this paper we will use the latter. HOL is a predicate calculus
   153   presented in this paper we will use the latter. HOL is a predicate calculus
   151   that allows quantification over predicate variables. Its type system is
   154   that allows quantification over predicate variables. Its type system is
   152   based on Church's Simple Theory of Types \cite{Church40}.  Although many
   155   based on Church's Simple Theory of Types \cite{Church40}.  Although many
   153   mathematical concepts can be conveniently expressed in HOL, there are some
   156   mathematical concepts can be conveniently expressed in HOL, there are some
   154   limitations that hurt badly, if one attempts a simple-minded formalisation
   157   limitations that hurt badly, if one attempts a simple-minded formalisation
   155   of regular languages in it.  The typical approach to regular languages is to
   158   of regular languages in it. 
       
   159 
       
   160   The typical approach to regular languages is to
   156   introduce finite automata and then define everything in terms of them
   161   introduce finite automata and then define everything in terms of them
   157   \cite{Kozen97}.  For example, a regular language is normally defined as:
   162   \cite{Kozen97}.  For example, a regular language is normally defined as:
   158 
   163 
   159   \begin{dfntn}\label{baddef}
   164   \begin{dfntn}\label{baddef}
   160   A language @{text A} is \emph{regular}, provided there is a 
   165   A language @{text A} is \emph{regular}, provided there is a 
   202   \draw ( 0.6,0.0) node {\small$A_2$};
   207   \draw ( 0.6,0.0) node {\small$A_2$};
   203   \end{tikzpicture}
   208   \end{tikzpicture}
   204 
   209 
   205   & 
   210   & 
   206 
   211 
   207   \raisebox{1.1mm}{\bf\Large$\;\;\;\Rightarrow\,\;\;$}
   212   \raisebox{2.1mm}{\bf\Large$\;\;\;\Rightarrow\,\;\;$}
   208 
   213 
   209   &
   214   &
   210 
   215 
   211   \begin{tikzpicture}[scale=1]
   216   \begin{tikzpicture}[scale=1]
   212   %\draw[step=2mm] (-1,-1) grid (1,1);
   217   %\draw[step=2mm] (-1,-1) grid (1,1);
   314   automata, that is automata need to have total transition functions and at
   319   automata, that is automata need to have total transition functions and at
   315   most one `sink' state from which there is no connection to a final state
   320   most one `sink' state from which there is no connection to a final state
   316   (Brzozowski mentions this side-condition in the context of state complexity
   321   (Brzozowski mentions this side-condition in the context of state complexity
   317   of automata \cite{Brzozowski10}). Such side-conditions mean that if we
   322   of automata \cite{Brzozowski10}). Such side-conditions mean that if we
   318   define a regular language as one for which there exists \emph{a} finite
   323   define a regular language as one for which there exists \emph{a} finite
   319   automaton that recognises all its strings (see Def.~\ref{baddef}), then we
   324   automaton that recognises all its strings (see Definition~\ref{baddef}), then we
   320   need a lemma which ensures that another equivalent one can be found
   325   need a lemma which ensures that another equivalent one can be found
   321   satisfying the side-condition. Unfortunately, such `little' and `obvious'
   326   satisfying the side-condition. Unfortunately, such `little' and `obvious'
   322   lemmas make a formalisation of automata theory a hair-pulling experience.
   327   lemmas make a formalisation of automata theory a hair-pulling experience.
   323 
   328 
   324 
   329 
  1093 text {*
  1098 text {*
  1094   \noindent
  1099   \noindent
  1095   In this section we will give a proof for establishing the second 
  1100   In this section we will give a proof for establishing the second 
  1096   part of the Myhill-Nerode theorem. It can be formulated in our setting as follows:
  1101   part of the Myhill-Nerode theorem. It can be formulated in our setting as follows:
  1097 
  1102 
  1098   \begin{thrm}
  1103   \begin{thrm}\label{myhillnerodetwo}
  1099   Given @{text "r"} is a regular expression, then @{thm Myhill_Nerode2}.
  1104   Given @{text "r"} is a regular expression, then @{thm Myhill_Nerode2}.
  1100   \end{thrm}  
  1105   \end{thrm}  
  1101 
  1106 
  1102   \noindent
  1107   \noindent
  1103   The proof will be by induction on the structure of @{text r}. It turns out
  1108   The proof will be by induction on the structure of @{text r}. It turns out
  1558   \noindent
  1563   \noindent
  1559   As we have seen in the previous section, in order to establish
  1564   As we have seen in the previous section, in order to establish
  1560   the second direction of the Myhill-Nerode theorem, we need to find 
  1565   the second direction of the Myhill-Nerode theorem, we need to find 
  1561   a more refined relation than @{term "\<approx>(lang r)"} for which we can
  1566   a more refined relation than @{term "\<approx>(lang r)"} for which we can
  1562   show that there are only finitely many equivalence classes. So far we 
  1567   show that there are only finitely many equivalence classes. So far we 
  1563   showed this by induction on @{text "r"}. However, there is also 
  1568   showed this directly by induction on @{text "r"} using tagging-functions. 
  1564   an indirect method to come up with such a refined relation by using
  1569   However, there is also  an indirect method to come up with such a refined 
  1565   derivatives of regular expressions \cite{Brzozowski64}. 
  1570   relation by using derivatives of regular expressions \cite{Brzozowski64}. 
  1566 
  1571 
  1567   Assume the following two definitions for a \emph{left-quotient} of a language,
  1572   Assume the following two definitions for the \emph{left-quotient} of a language,
  1568   which we write as @{term "Der c A"} and @{term "Ders s A"} where @{text c}
  1573   which we write as @{term "Der c A"} and @{term "Ders s A"} where @{text c}
  1569   is a character and @{text s} a string:
  1574   is a character and @{text s} a string, respectively:
  1570 
  1575 
  1571   \begin{center}
  1576   \begin{center}
  1572   \begin{tabular}{r@ {\hspace{1mm}}c@ {\hspace{2mm}}l}
  1577   \begin{tabular}{r@ {\hspace{1mm}}c@ {\hspace{2mm}}l}
  1573   @{thm (lhs) Der_def}  & @{text "\<equiv>"} & @{thm (rhs) Der_def}\\
  1578   @{thm (lhs) Der_def}  & @{text "\<equiv>"} & @{thm (rhs) Der_def}\\
  1574   @{thm (lhs) Ders_def} & @{text "\<equiv>"} & @{thm (rhs) Ders_def}\\
  1579   @{thm (lhs) Ders_def} & @{text "\<equiv>"} & @{thm (rhs) Ders_def}\\
  1575   \end{tabular}
  1580   \end{tabular}
  1576   \end{center}
  1581   \end{center}
  1577 
  1582 
  1578   \noindent
  1583   \noindent
  1579   In order to aid readability, we shall also make use of the following abbreviation
  1584   In order to aid readability, we shall make use of the following abbreviation
  1580 
  1585 
  1581   \begin{center}
  1586   \begin{center}
  1582   @{abbrev "Derss s As"}
  1587   @{abbrev "Derss s As"}
  1583   \end{center}
  1588   \end{center}
  1584   
  1589   
  1585   \noindent
  1590   \noindent
  1586   where we apply the left-quotient to a set of languages and then combine the results.
  1591   where we apply the left-quotient to a set of languages and then combine the results.
  1587   Clearly we have the following relation between the Myhill-Nerode relation
  1592   Clearly we have the following equivalence between the Myhill-Nerode relation
  1588   (Def.~\ref{myhillneroderel}) and left-quotients
  1593   (Definition~\ref{myhillneroderel}) and left-quotients
  1589 
  1594 
  1590   \begin{equation}\label{mhders}
  1595   \begin{equation}\label{mhders}
  1591   @{term "x \<approx>A y"} \hspace{4mm}\text{if and only if}\hspace{4mm} @{term "Ders x A = Ders y A"}
  1596   @{term "x \<approx>A y"} \hspace{4mm}\text{if and only if}\hspace{4mm} @{term "Ders x A = Ders y A"}
  1592   \end{equation}
  1597   \end{equation}
  1593 
  1598 
  1594   \noindent
  1599   \noindent
  1595   It is also straightforward to establish the following properties for left-quotients:
  1600   It is also straightforward to establish the following properties of left-quotients
  1596   
  1601   
  1597   \begin{equation}
  1602   \begin{equation}
  1598   \mbox{\begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{2mm}}l}
  1603   \mbox{\begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{2mm}}l}
  1599   @{thm (lhs) Der_simps(1)} & $=$ & @{thm (rhs) Der_simps(1)}\\
  1604   @{thm (lhs) Der_simps(1)} & $=$ & @{thm (rhs) Der_simps(1)}\\
  1600   @{thm (lhs) Der_simps(2)} & $=$ & @{thm (rhs) Der_simps(2)}\\
  1605   @{thm (lhs) Der_simps(2)} & $=$ & @{thm (rhs) Der_simps(2)}\\
  1608   %   & @{thm (rhs) Ders_simps(3)[where ?s1.0="s\<^isub>1" and ?s2.0="s\<^isub>2"]}\\
  1613   %   & @{thm (rhs) Ders_simps(3)[where ?s1.0="s\<^isub>1" and ?s2.0="s\<^isub>2"]}\\
  1609   \end{tabular}}
  1614   \end{tabular}}
  1610   \end{equation}
  1615   \end{equation}
  1611 
  1616 
  1612   \noindent
  1617   \noindent
  1613   where @{text "\<Delta>"} is a function that tests whether the empty string
  1618   where @{text "\<Delta>"} in the fifth line is a function that tests whether the empty string
  1614   is in the language and returns @{term "{[]}"} or @{term "{}"}, accordingly.
  1619   is in the language and returns @{term "{[]}"} or @{term "{}"}, accordingly.
  1615   The only interesting case above is the last one where we use Prop.~\ref{langprops}@{text "(i)"}
  1620   The only interesting case above is the last one where we use Prop.~\ref{langprops}@{text "(i)"}
  1616   in order to infer that @{term "Der c (A\<star>) = Der c (A \<cdot> A\<star>)"}. We can 
  1621   in order to infer that @{term "Der c (A\<star>) = Der c (A \<cdot> A\<star>)"}. We can 
  1617   then complete the proof by observing that @{term "Delta A \<cdot> Der c (A\<star>) \<subseteq> (Der c A) \<cdot> A\<star>"}.
  1622   then complete the proof by noting that @{term "Delta A \<cdot> Der c (A\<star>) \<subseteq> (Der c A) \<cdot> A\<star>"}.
  1618   
  1623   
  1619   Brzozowski observed that the left-quotients for languages of regular
  1624   Brzozowski observed that the left-quotients for languages of regular
  1620   expressions can be calculated directly via the notion of \emph{derivatives
  1625   expressions can be calculated directly using the notion of \emph{derivatives
  1621   of a regular expression} \cite{Brzozowski64}, which we define in Isabelle/HOL as 
  1626   of a regular expression} \cite{Brzozowski64}. We define this notion in 
  1622   follows:
  1627   Isabelle/HOL as follows:
  1623 
  1628 
  1624   \begin{center}
  1629   \begin{center}
  1625   \begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1.5mm}}l@ {}}
  1630   \begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1.5mm}}l@ {}}
  1626   @{thm (lhs) der.simps(1)}  & @{text "\<equiv>"} & @{thm (rhs) der.simps(1)}\\
  1631   @{thm (lhs) der.simps(1)}  & @{text "\<equiv>"} & @{thm (rhs) der.simps(1)}\\
  1627   @{thm (lhs) der.simps(2)}  & @{text "\<equiv>"} & @{thm (rhs) der.simps(2)}\\
  1632   @{thm (lhs) der.simps(2)}  & @{text "\<equiv>"} & @{thm (rhs) der.simps(2)}\\
  1640   \end{center}
  1645   \end{center}
  1641 
  1646 
  1642   \noindent
  1647   \noindent
  1643   The last two clauses extend derivatives from characters to strings---i.e.~list of
  1648   The last two clauses extend derivatives from characters to strings---i.e.~list of
  1644   characters. The list-cons operator is written \mbox{@{text "_ :: _"}}. The
  1649   characters. The list-cons operator is written \mbox{@{text "_ :: _"}}. The
  1645   function @{term "nullable r"} needed in the @{const Times}-case tests
  1650   boolean function @{term "nullable r"} needed in the @{const Times}-case tests
  1646   whether a regular expression can recognise the empty string:
  1651   whether a regular expression can recognise the empty string:
  1647 
  1652 
  1648   \begin{center}
  1653   \begin{center}
  1649   \begin{tabular}{c@ {\hspace{10mm}}c}
  1654   \begin{tabular}{c@ {\hspace{10mm}}c}
  1650   \begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1.5mm}}l@ {}}
  1655   \begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1.5mm}}l@ {}}
  1685   \end{equation}
  1690   \end{equation}
  1686 
  1691 
  1687 
  1692 
  1688   \noindent
  1693   \noindent
  1689   which means the right-hand side (seen as relation) refines the
  1694   which means the right-hand side (seen as relation) refines the
  1690   Myhill-Nerode relation.  Consequently, we can use 
  1695   Myhill-Nerode relation.  Consequently, we can use
  1691   @{text "\<^raw:$\threesim$>\<^bsub>(\<lambda>x. ders x r)\<^esub>"} as a tagging-relation
  1696   @{text "\<^raw:$\threesim$>\<^bsub>(\<lambda>x. ders x r)\<^esub>"} as a tagging-relation
  1692   for the regular expression @{text r}. However, in
  1697   for the regular expression @{text r}. However, in
  1693   order to be useful for teh second part of the Myhill-Nerode theorem, we also have to show that
  1698   order to be useful for the second part of the Myhill-Nerode theorem, we also have to show that
  1694   for the corresponding language there are only finitely many derivatives---thus ensuring
  1699   for the corresponding language there are only finitely many derivatives---thus ensuring
  1695   that there are only finitely many equivalence classes. Unfortunately, this
  1700   that there are only finitely many equivalence classes. Unfortunately, this
  1696   is not true in general. Sakarovitch gives an example where a regular
  1701   is not true in general. Sakarovitch gives an example where a regular
  1697   expression  has infinitely many derivatives w.r.t.~a language
  1702   expression  has infinitely many derivatives w.r.t.~the language
  1698   \cite[Page~141]{Sakarovitch09}. What Brzozowski \cite{Brzozowski64} proved
  1703   \mbox{@{term "({a} \<cdot> {b})\<star> \<union> ({a} \<cdot> {b})\<star> \<cdot> {a}"}}
  1699   is that for every language there \emph{are} only finitely `dissimilar'
  1704   \cite[Page~141]{Sakarovitch09}. 
  1700   derivatives for a regular expression. Two regular expressions are said to be
  1705 
  1701   \emph{similar} provided they can be identified using the using the @{text
  1706   What Brzozowski \cite{Brzozowski64} established is that for every language there
  1702   "ACI"}-identities:
  1707   \emph{are} only finitely `dissimilar' derivatives for a regular
       
  1708   expression. Two regular expressions are said to be \emph{similar} provided
       
  1709   they can be identified using the using the @{text "ACI"}-identities:
       
  1710 
  1703 
  1711 
  1704   \begin{equation}\label{ACI}
  1712   \begin{equation}\label{ACI}
  1705   \mbox{\begin{tabular}{cl}
  1713   \mbox{\begin{tabular}{cl}
  1706   (@{text 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)"}\\
  1714   (@{text 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)"}\\
  1707   (@{text C}) & @{term "Plus r\<^isub>1 r\<^isub>2"} $\equiv$ @{term "Plus r\<^isub>2 r\<^isub>1"}\\
  1715   (@{text C}) & @{term "Plus r\<^isub>1 r\<^isub>2"} $\equiv$ @{term "Plus r\<^isub>2 r\<^isub>1"}\\
  1754   derivatives w.r.t~the character @{text c}, then build the image of this set under the
  1762   derivatives w.r.t~the character @{text c}, then build the image of this set under the
  1755   function @{term "pders s"} and finally `union up' all resulting sets. It will be
  1763   function @{term "pders s"} and finally `union up' all resulting sets. It will be
  1756   convenient to introduce for this the following abbreviation
  1764   convenient to introduce for this the following abbreviation
  1757 
  1765 
  1758   \begin{center}
  1766   \begin{center}
  1759   @{abbrev "pderss s A"}
  1767   @{abbrev "pderss s rs"}
  1760   \end{center}
  1768   \end{center}
  1761 
  1769 
  1762   \noindent
  1770   \noindent
  1763   which simplifies the last clause of @{const "pders"} to
  1771   which simplifies the last clause of @{const "pders"} to
  1764 
  1772 
  1822   \end{tabular}}
  1830   \end{tabular}}
  1823   \end{equation} 
  1831   \end{equation} 
  1824 
  1832 
  1825   \noindent
  1833   \noindent
  1826   These two properties confirm the observation made earlier 
  1834   These two properties confirm the observation made earlier 
  1827   that by using sets, partial derivatives have the @{text "ACI"}-identidies
  1835   that by using sets, partial derivatives have the @{text "ACI"}-identities
  1828   of derivatives already built in. 
  1836   of derivatives already built in. 
  1829 
  1837 
  1830   Antimirov also proved that for every language and regular expression 
  1838   Antimirov also proved that for every language and regular expression 
  1831   there are only finitely many partial derivatives.
  1839   there are only finitely many partial derivatives, whereby the partial
       
  1840   derivatives of @{text r} w.r.t.~a language @{text A} is defined as
       
  1841 
       
  1842   \begin{equation}\label{Pdersdef}
       
  1843   @{thm pders_lang_def}
       
  1844   \end{equation}
       
  1845 
       
  1846   \begin{thrm}[Antimirov \cite{Antimirov95}]\label{antimirov}
       
  1847   For every language @{text A} and every regular expression @{text r}, 
       
  1848   \mbox{@{thm finite_pders_lang}}.
       
  1849   \end{thrm}
       
  1850 
       
  1851   \noindent
       
  1852   Antimirov's argument first shows this theorem for the language @{term UNIV1}, 
       
  1853   which is the set of all non-empty strings. For this he proves:
       
  1854 
       
  1855   \begin{equation}
       
  1856   \mbox{\begin{tabular}{l}
       
  1857   @{thm pders_lang_Zero}\\
       
  1858   @{thm pders_lang_One}\\
       
  1859   @{thm pders_lang_Atom}\\
       
  1860   @{thm pders_lang_Plus[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]}\\
       
  1861   @{thm pders_lang_Times[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]}\\
       
  1862   @{thm pders_lang_Star}\\
       
  1863   \end{tabular}}
       
  1864   \end{equation}
       
  1865 
       
  1866   \noindent
       
  1867   from which one can deduce by induction on @{text r} that
       
  1868 
       
  1869   \begin{center}
       
  1870   @{thm finite_pders_lang_UNIV1}
       
  1871   \end{center}
       
  1872 
       
  1873   \noindent
       
  1874   holds. Now Antimirov's theorem follows because
       
  1875 
       
  1876   \begin{center}
       
  1877   @{thm pders_lang_UNIV}\\
       
  1878   \end{center}
       
  1879 
       
  1880   \noindent
       
  1881   and for all languages @{text "A"}, @{thm pders_lang_subset[where B="UNIV",
       
  1882   simplified]} holds.  Since we follow Antimirov's proof quite closely in our
       
  1883   formalisation, we omit the details.
       
  1884 
       
  1885 
       
  1886   Let us return to our proof of the second direction in the Myhill-Nerode
       
  1887   theorem. The point of the above calculations is to use 
       
  1888   @{text "\<^raw:$\threesim$>\<^bsub>(\<lambda>x. ders x r)\<^esub>"} as tagging-relation. 
       
  1889 
       
  1890 
       
  1891   \begin{proof}[Proof of Theorem~\ref{myhillnerodetwo}]
       
  1892   Using \eqref{mhders}
       
  1893   and \eqref{Derspders} we can easily infer that
       
  1894 
       
  1895   \begin{center}
       
  1896   @{term "x \<approx>(lang r) y"}\hspace{4mm}\mbox{provided}\hspace{4mm}@{term "pders x r = pders y r"}
       
  1897   \end{center}
       
  1898 
       
  1899   \noindent
       
  1900   which means the tagging-relation @{text "\<^raw:$\threesim$>\<^bsub>(\<lambda>x. ders x r)\<^esub>"} refines @{term "\<approx>(lang r)"}.
       
  1901   So we know by Lemma~\ref{fintwo}, \mbox{@{term "finite (UNIV // (\<approx>(lang r)))"}} 
       
  1902   holds if @{term "finite (UNIV // (=(\<lambda>x. pders x r)=))"}. In order to establish 
       
  1903   the latter, we can use Lemma~\ref{finone} and show that the range of the 
       
  1904   tagging-function \mbox{@{term "\<lambda>x. pders x r"}} is finite. For this recall Definition
       
  1905   \ref{Pdersdef}, which gives us that 
       
  1906 
       
  1907   \begin{center}
       
  1908   @{thm pders_lang_def[where A="UNIV", simplified]}
       
  1909   \end{center}
       
  1910 
       
  1911   \noindent
       
  1912   Now the range of @{term "\<lambda>x. pders x r"} is a subset of @{term "Pow (pders_lang UNIV r)"},
       
  1913   which we know is finite by Theorem~\ref{antimirov}. This means there 
       
  1914   are only finitely many equivalence classes of @{text "\<^raw:$\threesim$>\<^bsub>(\<lambda>x. ders x r)\<^esub>"},
       
  1915   and we can again conclude the second part of the Myhill-Nerode theorem.
       
  1916   \end{proof}
  1832 *}
  1917 *}
  1833 
  1918 
  1834 section {* Closure Properties *}
  1919 section {* Closure Properties *}
  1835 
  1920 
  1836 text {*
  1921 text {*
  1837   \noindent
  1922   \noindent
  1838   The real beauty of regular languages is that they are closed
  1923   The real beauty of regular languages is that they are closed
  1839   under almost all set operations. Closure under union, concatenation and Kleene-star
  1924   under almost all set operations. Closure under union, concatenation and Kleene-star
  1840   are trivial to establish given our definition of regularity (Def.~\ref{regular}).
  1925   are trivial to establish given our definition of regularity (Definition~\ref{regular}).
  1841   More interesting is the closure under complement, because
  1926   More interesting is the closure under complement, because
  1842   it seems difficult to construct a regular expression for the complement
  1927   it seems difficult to construct a regular expression for the complement
  1843   language by direct means. However the existence of such a regular expression
  1928   language by direct means. However the existence of such a regular expression
  1844   can now be easily proved using the Myhill-Nerode theorem since 
  1929   can now be easily proved using the Myhill-Nerode theorem since 
  1845   
  1930   
  1848   \end{center}
  1933   \end{center}
  1849   
  1934   
  1850   \noindent
  1935   \noindent
  1851   holds for any strings @{text "s\<^isub>1"} and @{text
  1936   holds for any strings @{text "s\<^isub>1"} and @{text
  1852   "s\<^isub>2"}. Therefore @{text A} and the complement language @{term "-A"}
  1937   "s\<^isub>2"}. Therefore @{text A} and the complement language @{term "-A"}
  1853   give rise to the same partitions.
  1938   give rise to the same partitions. So if one is finite, the other is too and the
       
  1939   other way around.
  1854 
  1940 
  1855   Once closure under complement is established, closure under intersection
  1941   Once closure under complement is established, closure under intersection
  1856   and set difference is also easy, because
  1942   and set difference is also easy, because
  1857 
  1943 
  1858   \begin{center}
  1944   \begin{center}
  1884       @{thm (rhs) Rev.simps(5)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]}\\
  1970       @{thm (rhs) Rev.simps(5)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]}\\
  1885   @{thm (lhs) Rev.simps(6)} & @{text "\<equiv>"} & @{thm (rhs) Rev.simps(6)}\\
  1971   @{thm (lhs) Rev.simps(6)} & @{text "\<equiv>"} & @{thm (rhs) Rev.simps(6)}\\
  1886   \end{tabular}
  1972   \end{tabular}
  1887   \end{center}
  1973   \end{center}
  1888 
  1974 
  1889 
  1975   \noindent
  1890   In connection with left-quotient, the perhaps surprising fact is that
  1976   For this operation we can so
  1891   regular languages are closed under any left-quotient.
  1977 
  1892 
  1978   \begin{center}
  1893   
  1979   @{text "(\<calL>(r))\<^bsup>-1\<^esup>"}~@{text "="}~@{thm (rhs) rev_lang}
       
  1980   \end{center}
       
  1981   
       
  1982   \noindent
       
  1983   from which closure under reversal follows.
       
  1984 
       
  1985   The perhaps the most surprising fact is that regular languages are closed under any 
       
  1986   left-quotient. Define 
       
  1987 
       
  1988   \begin{center}
       
  1989   @{abbrev "Ders_lang B A"}
       
  1990   \end{center}
       
  1991 
       
  1992   \noindent
       
  1993   and assume @{text A} is regular. From this we know there exists a regular
       
  1994   expression @{text r} such that @{term "A = lang r"}. We also know that
       
  1995   @{term "pders_lang B r"} is finite. By definition and Lemma~\ref{Derspders}
       
  1996   
       
  1997   \begin{equation}\label{eqq}
       
  1998   @{term "Ders_lang B (lang r) = (\<Union> lang ` (pders_lang B r))"}
       
  1999   \end{equation}
       
  2000 
       
  2001   \noindent
       
  2002   Since there are only finitely many regular expressions in @{term "pders_lang B r"}
       
  2003   by Theorem~\ref{antimirov}, we know that the right-hand side of \eqref{eqq}, is 
       
  2004   equal to @{term "lang (\<Uplus>(pders_lang B r))"} using \eqref{uplus}. Hence
       
  2005   the regular expression @{term "pders_lang B r"} verifies that @{term "Ders_lang B A"} 
       
  2006   is regular.
       
  2007 
  1894 *}
  2008 *}
  1895 
  2009 
  1896 
  2010 
  1897 section {* Conclusion and Related Work *}
  2011 section {* Conclusion and Related Work *}
  1898 
  2012