1566 the second direction of the Myhill-Nerode theorem, we need to find |
1566 the second direction of the Myhill-Nerode theorem, we need to find |
1567 a more refined relation than @{term "\<approx>(lang r)"} for which we can |
1567 a more refined relation than @{term "\<approx>(lang r)"} for which we can |
1568 show that there are only finitely many equivalence classes. So far we |
1568 show that there are only finitely many equivalence classes. So far we |
1569 showed this directly by induction on @{text "r"} using tagging-functions. |
1569 showed this directly by induction on @{text "r"} using tagging-functions. |
1570 However, there is also an indirect method to come up with such a refined |
1570 However, there is also an indirect method to come up with such a refined |
1571 relation by using derivatives of regular expressions \cite{Brzozowski64}. |
1571 relation by using derivatives of regular expressions~\cite{Brzozowski64}. |
1572 |
1572 |
1573 Assume the following two definitions for the \emph{left-quotient} of a language, |
1573 Assume the following two definitions for the \emph{left-quotient} of a language, |
1574 which we write as @{term "Der c A"} and @{term "Ders s A"} where @{text c} |
1574 which we write as @{term "Der c A"} and @{term "Ders s A"} where @{text c} |
1575 is a character and @{text s} a string, respectively: |
1575 is a character and @{text s} a string, respectively: |
1576 |
1576 |
1616 \end{equation} |
1616 \end{equation} |
1617 |
1617 |
1618 \noindent |
1618 \noindent |
1619 where @{text "\<Delta>"} in the fifth line is a function that tests whether the empty string |
1619 where @{text "\<Delta>"} in the fifth line is a function that tests whether the empty string |
1620 is in the language and returns @{term "{[]}"} or @{term "{}"}, accordingly. |
1620 is in the language and returns @{term "{[]}"} or @{term "{}"}, accordingly. |
1621 The only interesting case above is the last one where we use Prop.~\ref{langprops}@{text "(i)"} |
1621 The only interesting case is the last one where we use Prop.~\ref{langprops}@{text "(i)"} |
1622 in order to infer that @{term "Der c (A\<star>) = Der c (A \<cdot> A\<star>)"}. We can |
1622 in order to infer that @{term "Der c (A\<star>) = Der c (A \<cdot> A\<star>)"}. We can |
1623 then complete the proof by noting that @{term "Delta A \<cdot> Der c (A\<star>) \<subseteq> (Der c A) \<cdot> A\<star>"}. |
1623 then complete the proof by noting that @{term "Delta A \<cdot> Der c (A\<star>) \<subseteq> (Der c A) \<cdot> A\<star>"}. |
1624 |
1624 |
1625 Brzozowski observed that the left-quotients for languages of regular |
1625 Brzozowski observed that the left-quotients for languages of regular |
1626 expressions can be calculated directly using the notion of \emph{derivatives |
1626 expressions can be calculated directly using the notion of \emph{derivatives |
1647 |
1647 |
1648 \noindent |
1648 \noindent |
1649 The last two clauses extend derivatives from characters to strings---i.e.~list of |
1649 The last two clauses extend derivatives from characters to strings---i.e.~list of |
1650 characters. The list-cons operator is written \mbox{@{text "_ :: _"}}. The |
1650 characters. The list-cons operator is written \mbox{@{text "_ :: _"}}. The |
1651 boolean function @{term "nullable r"} needed in the @{const Times}-case tests |
1651 boolean function @{term "nullable r"} needed in the @{const Times}-case tests |
1652 whether a regular expression can recognise the empty string: |
1652 whether a regular expression can recognise the empty string. It can be defined as |
|
1653 follows. |
1653 |
1654 |
1654 \begin{center} |
1655 \begin{center} |
1655 \begin{tabular}{c@ {\hspace{10mm}}c} |
1656 \begin{tabular}{c@ {\hspace{10mm}}c} |
1656 \begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1.5mm}}l@ {}} |
1657 \begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1.5mm}}l@ {}} |
1657 @{thm (lhs) nullable.simps(1)} & @{text "\<equiv>"} & @{thm (rhs) nullable.simps(1)}\\ |
1658 @{thm (lhs) nullable.simps(1)} & @{text "\<equiv>"} & @{thm (rhs) nullable.simps(1)}\\ |
1668 \end{tabular} |
1669 \end{tabular} |
1669 \end{center} |
1670 \end{center} |
1670 |
1671 |
1671 \noindent |
1672 \noindent |
1672 By induction on the regular expression @{text r}, respectively on the string @{text s}, |
1673 By induction on the regular expression @{text r}, respectively on the string @{text s}, |
1673 one can easily show that left-quotients and derivatives relate as follows |
1674 one can easily show that left-quotients and derivatives of regular expressions |
1674 \cite{Sakarovitch09}: |
1675 relate as follows (for example \cite{Sakarovitch09}): |
1675 |
1676 |
1676 \begin{equation}\label{Dersders} |
1677 \begin{equation}\label{Dersders} |
1677 \mbox{\begin{tabular}{c} |
1678 \mbox{\begin{tabular}{c} |
1678 @{thm Der_der}\\ |
1679 @{thm Der_der}\\ |
1679 @{thm Ders_ders} |
1680 @{thm Ders_ders} |
1680 \end{tabular}} |
1681 \end{tabular}} |
1681 \end{equation} |
1682 \end{equation} |
1682 |
1683 |
1683 \noindent |
1684 \noindent |
1684 The importance in the context of the Myhill-Nerode theorem is that |
1685 The importance of this fact in the context of the Myhill-Nerode theorem is that |
1685 we can use \eqref{mhders} and \eqref{Dersders} in order to |
1686 we can use \eqref{mhders} and \eqref{Dersders} in order to |
1686 establish that @{term "x \<approx>(lang r) y"} is equivalent to |
1687 establish that @{term "x \<approx>(lang r) y"} is equivalent to |
1687 @{term "lang (ders x r) = lang (ders y r)"}. Hence |
1688 \mbox{@{term "lang (ders x r) = lang (ders y r)"}}. Hence |
1688 |
1689 |
1689 \begin{equation} |
1690 \begin{equation} |
1690 @{term "x \<approx>(lang r) y"}\hspace{4mm}\mbox{provided}\hspace{4mm}@{term "ders x r = ders y r"} |
1691 @{term "x \<approx>(lang r) y"}\hspace{4mm}\mbox{provided}\hspace{4mm}@{term "ders x r = ders y r"} |
1691 \end{equation} |
1692 \end{equation} |
1692 |
1693 |
1693 |
1694 |
1694 \noindent |
1695 \noindent |
1695 which means the right-hand side (seen as relation) refines the |
1696 which means the right-hand side (seen as relation) refines the Myhill-Nerode |
1696 Myhill-Nerode relation. Consequently, we can use |
1697 relation. Consequently, we can use @{text |
1697 @{text "\<^raw:$\threesim$>\<^bsub>(\<lambda>x. ders x r)\<^esub>"} as a tagging-relation |
1698 "\<^raw:$\threesim$>\<^bsub>(\<lambda>x. ders x r)\<^esub>"} as a |
1698 for the regular expression @{text r}. However, in |
1699 tagging-relation. However, in order to be useful for the second part of the |
1699 order to be useful for the second part of the Myhill-Nerode theorem, we also have to show that |
1700 Myhill-Nerode theorem, we have to be able to establish that for the |
1700 for the corresponding language there are only finitely many derivatives---thus ensuring |
1701 corresponding language there are only finitely many derivatives---thus |
1701 that there are only finitely many equivalence classes. Unfortunately, this |
1702 ensuring that there are only finitely many equivalence |
1702 is not true in general. Sakarovitch gives an example where a regular |
1703 classes. Unfortunately, this is not true in general. Sakarovitch gives an |
1703 expression has infinitely many derivatives w.r.t.~the language |
1704 example where a regular expression has infinitely many derivatives |
1704 \mbox{@{term "({a} \<cdot> {b})\<star> \<union> ({a} \<cdot> {b})\<star> \<cdot> {a}"}} |
1705 w.r.t.~the language \mbox{@{term "({a} \<cdot> {b})\<star> \<union> ({a} \<cdot> {b})\<star> \<cdot> {a}"}} |
1705 \cite[Page~141]{Sakarovitch09}. |
1706 \cite[Page~141]{Sakarovitch09}. |
|
1707 |
1706 |
1708 |
1707 What Brzozowski \cite{Brzozowski64} established is that for every language there |
1709 What Brzozowski \cite{Brzozowski64} established is that for every language there |
1708 \emph{are} only finitely `dissimilar' derivatives for a regular |
1710 \emph{are} only finitely `dissimilar' derivatives of a regular |
1709 expression. Two regular expressions are said to be \emph{similar} provided |
1711 expression. Two regular expressions are said to be \emph{similar} provided |
1710 they can be identified using the using the @{text "ACI"}-identities: |
1712 they can be identified using the using the @{text "ACI"}-identities: |
1711 |
1713 |
1712 |
1714 |
1713 \begin{equation}\label{ACI} |
1715 \begin{equation}\label{ACI} |
2048 Our insistence on regular expressions for proving the Myhill-Nerode theorem |
2050 Our insistence on regular expressions for proving the Myhill-Nerode theorem |
2049 arose from the limitations of HOL on which the popular theorem provers HOL4, |
2051 arose from the limitations of HOL on which the popular theorem provers HOL4, |
2050 HOLlight and Isabelle/HOL are based. In order to guarantee consistency, |
2052 HOLlight and Isabelle/HOL are based. In order to guarantee consistency, |
2051 formalisations can only extend HOL by definitions that introduce a notion in |
2053 formalisations can only extend HOL by definitions that introduce a notion in |
2052 terms of already existing concepts. A convenient definition for automata |
2054 terms of already existing concepts. A convenient definition for automata |
2053 (based on graphs) use a polymorphic type for the state nodes. This allows us |
2055 (based on graphs) uses a polymorphic type for the state nodes. This allows |
2054 to use the standard operation of disjoint union in order to compose two |
2056 us to use the standard operation of disjoint union in order to compose two |
2055 automata. But we cannot use such a polymorphic definition of automata in HOL |
2057 automata. Unfortunately, we cannot use such a polymorphic definition of |
2056 as part of the definition for regularity of a language (a set of strings). |
2058 in HOL as part of the definition for regularity of a language (a |
2057 Consider the following attempt |
2059 set of strings). Consider the following attempt |
2058 |
|
2059 |
2060 |
2060 \begin{center} |
2061 \begin{center} |
2061 @{text "is_regular A \<equiv> \<exists>M(\<alpha>). is_finite_automata (M) \<and> \<calL>(M) = A"} |
2062 @{text "is_regular A \<equiv> \<exists>M(\<alpha>). is_finite_automata (M) \<and> \<calL>(M) = A"} |
2062 \end{center} |
2063 \end{center} |
2063 |
2064 |