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 |
|
51 lang ("\<^raw:\ensuremath{\cal{L}}>" 101) and |
51 lang ("\<^raw:\ensuremath{\cal{L}}>'(_')" [0] 101) and |
52 lang ("\<^raw:\ensuremath{\cal{L}}>'(_')" [0] 101) and |
52 lang_trm ("\<^raw:\ensuremath{\cal{L}}>'(_')" [0] 101) and |
53 lang_trm ("\<^raw:\ensuremath{\cal{L}}>'(_')" [0] 101) and |
53 Lam ("\<lambda>'(_')" [100] 100) and |
54 Lam ("\<lambda>'(_')" [100] 100) and |
54 Trn ("'(_, _')" [100, 100] 100) and |
55 Trn ("'(_, _')" [100, 100] 100) and |
55 EClass ("\<lbrakk>_\<rbrakk>\<^bsub>_\<^esub>" [100, 100] 100) and |
56 EClass ("\<lbrakk>_\<rbrakk>\<^bsub>_\<^esub>" [100, 100] 100) and |
305 involve subtle side-conditions which are easily overlooked, but which make |
310 involve subtle side-conditions which are easily overlooked, but which make |
306 formal reasoning rather painful. For example Kozen's proof of the |
311 formal reasoning rather painful. For example Kozen's proof of the |
307 Myhill-Nerode theorem requires that automata do not have inaccessible |
312 Myhill-Nerode theorem requires that automata do not have inaccessible |
308 states \cite{Kozen97}. Another subtle side-condition is completeness of |
313 states \cite{Kozen97}. Another subtle side-condition is completeness of |
309 automata, that is automata need to have total transition functions and at most one |
314 automata, that is automata need to have total transition functions and at most one |
310 `sink' state from which there is no connection to a final state (Brozowski |
315 `sink' state from which there is no connection to a final state (Brzozowski |
311 mentions this side-condition in the context of state complexity |
316 mentions this side-condition in the context of state complexity |
312 of automata \cite{Brozowski10}). Such side-conditions mean that if we define a regular |
317 of automata \cite{Brzozowski10}). Such side-conditions mean that if we define a regular |
313 language as one for which there exists \emph{a} finite automaton that |
318 language as one for which there exists \emph{a} finite automaton that |
314 recognises all its strings (see Def.~\ref{baddef}), then we need a lemma which |
319 recognises all its strings (see Def.~\ref{baddef}), then we need a lemma which |
315 ensures that another equivalent can be found satisfying the |
320 ensures that another equivalent can be found satisfying the |
316 side-condition. Unfortunately, such `little' and `obvious' lemmas make |
321 side-condition. Unfortunately, such `little' and `obvious' lemmas make |
317 a formalisation of automata theory a hair-pulling experience. |
322 a formalisation of automata theory a hair-pulling experience. |
1463 @{text "x\<^isub>p < x"} and the rest @{term "x\<^isub>s @ z \<in> A\<star>"}. For example the empty string |
1468 @{text "x\<^isub>p < x"} and the rest @{term "x\<^isub>s @ z \<in> A\<star>"}. For example the empty string |
1464 @{text "[]"} would do. |
1469 @{text "[]"} would do. |
1465 There are potentially many such prefixes, but there can only be finitely many of them (the |
1470 There are potentially many such prefixes, but there can only be finitely many of them (the |
1466 string @{text x} is finite). Let us therefore choose the longest one and call it |
1471 string @{text x} is finite). Let us therefore choose the longest one and call it |
1467 @{text "x\<^bsub>pmax\<^esub>"}. Now for the rest of the string @{text "x\<^isub>s @ z"} we |
1472 @{text "x\<^bsub>pmax\<^esub>"}. Now for the rest of the string @{text "x\<^isub>s @ z"} we |
1468 know it is in @{term "A\<star>"} and it is not the empty string. By Lemma~\ref{langprops}@{text "(i)"}, |
1473 know it is in @{term "A\<star>"} and it is not the empty string. By Prop.~\ref{langprops}@{text "(i)"}, |
1469 we can separate |
1474 we can separate |
1470 this string into two parts, say @{text "a"} and @{text "b"}, such that @{text "a \<in> A"} |
1475 this string into two parts, say @{text "a"} and @{text "b"}, such that @{text "a \<in> A"} |
1471 and @{term "b \<in> A\<star>"}. Now @{text a} must be strictly longer than @{text "x\<^isub>s"}, |
1476 and @{term "b \<in> A\<star>"}. Now @{text a} must be strictly longer than @{text "x\<^isub>s"}, |
1472 otherwise @{text "x\<^bsub>pmax\<^esub>"} is not the longest prefix. That means @{text a} |
1477 otherwise @{text "x\<^bsub>pmax\<^esub>"} is not the longest prefix. That means @{text a} |
1473 `overlaps' with @{text z}, splitting it into two components @{text "z\<^isub>a"} and |
1478 `overlaps' with @{text z}, splitting it into two components @{text "z\<^isub>a"} and |
1540 @{thm (lhs) Ders_def} & @{text "\<equiv>"} & @{thm (rhs) Ders_def}\\ |
1545 @{thm (lhs) Ders_def} & @{text "\<equiv>"} & @{thm (rhs) Ders_def}\\ |
1541 \end{tabular} |
1546 \end{tabular} |
1542 \end{center} |
1547 \end{center} |
1543 |
1548 |
1544 \noindent |
1549 \noindent |
1545 Now clearly we have the following relation between the Myhill-Nerode relation |
1550 Clearly we have the following relation between the Myhill-Nerode relation |
1546 (Definition~\ref{myhillneroderel}) and left-quotients |
1551 (Def.~\ref{myhillneroderel}) and left-quotients |
1547 |
1552 |
1548 \begin{equation}\label{mhders} |
1553 \begin{equation}\label{mhders} |
1549 @{term "x \<approx>A y"} \hspace{4mm}\text{if and only if}\hspace{4mm} @{term "Ders x A = Ders y A"} |
1554 @{term "x \<approx>A y"} \hspace{4mm}\text{if and only if}\hspace{4mm} @{term "Ders x A = Ders y A"} |
1550 \end{equation} |
1555 \end{equation} |
1551 |
1556 |
1552 \noindent |
1557 \noindent |
1553 It is realtively easy to establish the following properties for left-quotients: |
1558 It is realtively easy to establish the following properties for left-quotients: |
1554 |
1559 |
1555 \begin{center} |
1560 \begin{equation} |
1556 \begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{2mm}}l} |
1561 \mbox{\begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{2mm}}l} |
1557 @{thm (lhs) Der_zero} & $=$ & @{thm (rhs) Der_zero}\\ |
1562 @{thm (lhs) Der_zero} & $=$ & @{thm (rhs) Der_zero}\\ |
1558 @{thm (lhs) Der_one} & $=$ & @{thm (rhs) Der_one}\\ |
1563 @{thm (lhs) Der_one} & $=$ & @{thm (rhs) Der_one}\\ |
1559 @{thm (lhs) Der_atom} & $=$ & @{thm (rhs) Der_atom}\\ |
1564 @{thm (lhs) Der_atom} & $=$ & @{thm (rhs) Der_atom}\\ |
1560 @{thm (lhs) Der_union} & $=$ & @{thm (rhs) Der_union}\\ |
1565 @{thm (lhs) Der_union} & $=$ & @{thm (rhs) Der_union}\\ |
1561 @{thm (lhs) Der_conc} & $=$ & @{thm (rhs) Der_conc}\\ |
1566 @{thm (lhs) Der_conc} & $=$ & @{thm (rhs) Der_conc}\\ |
1562 @{thm (lhs) Der_star} & $=$ & @{thm (rhs) Der_star}\\ |
1567 @{thm (lhs) Der_star} & $=$ & @{thm (rhs) Der_star}\\ |
1563 \end{tabular} |
1568 @{thm (lhs) Ders_nil} & $=$ & @{thm (rhs) Ders_nil}\\ |
1564 \end{center} |
1569 @{thm (lhs) Ders_cons} & $=$ & @{thm (rhs) Ders_cons}\\ |
|
1570 %@{thm (lhs) Ders_append[where ?s1.0="s\<^isub>1" and ?s2.0="s\<^isub>2"]} & $=$ |
|
1571 % & @{thm (rhs) Ders_append[where ?s1.0="s\<^isub>1" and ?s2.0="s\<^isub>2"]}\\ |
|
1572 \end{tabular}} |
|
1573 \end{equation} |
1565 |
1574 |
1566 \noindent |
1575 \noindent |
1567 where @{text "\<Delta>"} is a function that tests whether the empty string |
1576 where @{text "\<Delta>"} is a function that tests whether the empty string |
1568 is in the language and returns @{term "{[]}"} or @{term "{}"}, respectively. |
1577 is in the language and returns @{term "{[]}"} or @{term "{}"}, respectively. |
1569 The only interesting case above is the last one where we use Prop.~\ref{langprops} |
1578 The only interesting case above is the last one where we use Prop.~\ref{langprops} |
1570 in order to infer that @{term "Der c (A\<star>) = Der c (A \<cdot> A\<star>)"}. We can |
1579 in order to infer that @{term "Der c (A\<star>) = Der c (A \<cdot> A\<star>)"}. We can |
1571 then complete the proof by observing that @{term "Delta A \<cdot> Der c (A\<star>) \<subseteq> (Der c A) \<cdot> A\<star>"}. |
1580 then complete the proof by observing that @{term "Delta A \<cdot> Der c (A\<star>) \<subseteq> (Der c A) \<cdot> A\<star>"}. |
1572 |
1581 |
1573 Brzozowski observed that the left-quotients for languages of regular |
1582 Brzozowski observed that the left-quotients for languages of regular |
1574 expressions can be calculated directly via the notion of \emph{derivatives |
1583 expressions can be calculated directly via the notion of \emph{derivatives |
1575 of a regular expressions} \cite{Brzozowski64} which we define in Isabelle/HOL as |
1584 of a regular expression} \cite{Brzozowski64}, which we define in Isabelle/HOL as |
1576 follows: |
1585 follows: |
1577 |
1586 |
1578 \begin{center} |
1587 \begin{center} |
1579 \begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1.5mm}}l@ {}} |
1588 \begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1.5mm}}l@ {}} |
1580 @{thm (lhs) der.simps(1)} & @{text "\<equiv>"} & @{thm (rhs) der.simps(1)}\\ |
1589 @{thm (lhs) der.simps(1)} & @{text "\<equiv>"} & @{thm (rhs) der.simps(1)}\\ |
1613 \end{tabular} |
1624 \end{tabular} |
1614 \end{tabular} |
1625 \end{tabular} |
1615 \end{center} |
1626 \end{center} |
1616 |
1627 |
1617 \noindent |
1628 \noindent |
1618 Brzozowski proved |
1629 By induction on the regular expression @{text r}, respectively the string @{text s}, |
|
1630 one can easily show that left-quotients and derivatives relate as follows |
|
1631 \cite{Sakarovitch09}: |
1619 |
1632 |
1620 \begin{equation}\label{Dersders} |
1633 \begin{equation}\label{Dersders} |
1621 \mbox{\begin{tabular}{l} |
1634 \mbox{\begin{tabular}{c} |
1622 @{thm Der_der}\\ |
1635 @{thm Der_der}\\ |
1623 @{thm Ders_ders} |
1636 @{thm Ders_ders} |
1624 \end{tabular}} |
1637 \end{tabular}} |
1625 \end{equation} |
1638 \end{equation} |
1626 |
1639 |
1627 \noindent |
1640 \noindent |
1628 where the first is by induction on @{text r} and the second by a simple |
|
1629 calculation. |
|
1630 |
|
1631 The importance in the context of the Myhill-Nerode theorem is that |
1641 The importance in the context of the Myhill-Nerode theorem is that |
1632 we can use \eqref{mhders} and \eqref{Dersders} in order to derive |
1642 we can use \eqref{mhders} and the equations above in order to |
1633 |
1643 establish that @{term "x \<approx>(lang r) y"} if and only if |
1634 \begin{center} |
1644 @{term "lang (ders x r) = lang (ders y r)"}. From this we obtain |
1635 @{term "x \<approx>(lang r) y"} \hspace{4mm}if and only if\hspace{4mm} |
1645 |
1636 @{term "lang (ders x r) = lang (ders y r)"} |
1646 \begin{equation} |
1637 \end{center} |
1647 @{term "x \<approx>(lang r) y"}\hspace{4mm}\mbox{provided}\hspace{4mm}@{term "ders x r = ders y r"} |
1638 |
1648 \end{equation} |
1639 \noindent |
1649 |
1640 which means @{term "x \<approx>(lang r) y"} provided @{term "ders x r = ders y r"}. |
1650 |
1641 Consequently, we can use as the tagging relation |
1651 \noindent |
1642 @{text "\<^raw:$\threesim$>\<^bsub>(\<lambda>x. ders x r)\<^esub>"}, which we know refines @{term "\<approx>(lang r)"}. |
1652 Consequently, we can use as the tagging relation @{text |
1643 This almost helps us because Brozowski also proved that there for every |
1653 "\<^raw:$\threesim$>\<^bsub>(\<lambda>x. ders x r)\<^esub>"}, since it refines |
1644 language there are only |
1654 @{term "\<approx>(lang r)"}. However, in order to be useful in the Myhill-Nerode |
1645 finitely `dissimilar' derivatives for a regular expression. Two regulare |
1655 theorem, we have to show that for a language there are only finitely many |
1646 expressions are similar if they can be identified using the using the |
1656 derivatives. Unfortunately, this is not true in general: Sakarovitch gives |
1647 ACI-identities |
1657 an example with infinitely many derivatives |
|
1658 \cite[Page~141]{Sakarovitch09}. What Brzozowski \cite{Brzozowski64} proved is |
|
1659 that for every language there \emph{are} finitely `dissimilar' derivatives for a |
|
1660 regular expression. Two regular expressions are said to be \emph{similar} |
|
1661 provided they can be identified using the using the @{text "ACI"}-identities: |
1648 |
1662 |
1649 \begin{center} |
1663 \begin{center} |
1650 \begin{tabular}{cl} |
1664 \begin{tabular}{cl} |
1651 (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)"}\\ |
1665 (@{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)"}\\ |
1652 (C) & @{term "Plus r\<^isub>1 r\<^isub>2"} $\equiv$ @{term "Plus r\<^isub>2 r\<^isub>1"}\\ |
1666 (@{text C}) & @{term "Plus r\<^isub>1 r\<^isub>2"} $\equiv$ @{term "Plus r\<^isub>2 r\<^isub>1"}\\ |
1653 (I) & @{term "Plus r r"} $\equiv$ @{term "r"}\\ |
1667 (@{text I}) & @{term "Plus r r"} $\equiv$ @{term "r"}\\ |
1654 \end{tabular} |
1668 \end{tabular} |
1655 \end{center} |
1669 \end{center} |
1656 |
1670 |
1657 \noindent |
1671 \noindent |
1658 Without the indentification, we unfortunately obtain infinitely many |
1672 Carrying this idea through menas we now have to reasoning modulo @{text "ACI"}. |
1659 derivations (an example is given in \cite[Page~141]{Sakarovitch09}). |
1673 This can be done, but it is very painful in a theorem prover (since there is |
1660 Reasoning modulo ACI can be done, but it is very painful in a theorem prover. |
1674 no direct characterisation of the set of dissimlar derivatives). |
1661 |
1675 |
1662 Fortunately, there is a much simpler approach using partial |
1676 Fortunately, there is a much simpler approach using \emph{partial |
1663 derivatives introduced by Antimirov \cite{Antimirov95}. |
1677 derivatives}. They were introduced by Antimirov \cite{Antimirov95} and can be defined |
|
1678 in Isabelle/HOL as follows: |
1664 |
1679 |
1665 \begin{center} |
1680 \begin{center} |
1666 \begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1.5mm}}l@ {}} |
1681 \begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1.5mm}}l@ {}} |
1667 @{thm (lhs) pder.simps(1)} & @{text "\<equiv>"} & @{thm (rhs) pder.simps(1)}\\ |
1682 @{thm (lhs) pder.simps(1)} & @{text "\<equiv>"} & @{thm (rhs) pder.simps(1)}\\ |
1668 @{thm (lhs) pder.simps(2)} & @{text "\<equiv>"} & @{thm (rhs) pder.simps(2)}\\ |
1683 @{thm (lhs) pder.simps(2)} & @{text "\<equiv>"} & @{thm (rhs) pder.simps(2)}\\ |
1678 @{thm (lhs) pders.simps(1)} & @{text "\<equiv>"} & @{thm (rhs) pders.simps(1)}\\ |
1693 @{thm (lhs) pders.simps(1)} & @{text "\<equiv>"} & @{thm (rhs) pders.simps(1)}\\ |
1679 @{thm (lhs) pders.simps(2)} & @{text "\<equiv>"} & @{thm (rhs) pders.simps(2)}\\ |
1694 @{thm (lhs) pders.simps(2)} & @{text "\<equiv>"} & @{thm (rhs) pders.simps(2)}\\ |
1680 \end{tabular} |
1695 \end{tabular} |
1681 \end{center} |
1696 \end{center} |
1682 |
1697 |
|
1698 \noindent |
|
1699 Unlike `simple' derivatives, these functions return a set of regular |
|
1700 expressions. In the @{const Times} and @{const Star} cases we use |
|
1701 |
|
1702 \begin{center} |
|
1703 @{text "TIMESS rs r \<equiv> {TIMES r' r | r' \<in> rs}"} |
|
1704 \end{center} |
|
1705 |
|
1706 \noindent |
|
1707 in order to `sequence' a regular expressions with respect to a set of regular |
|
1708 expresions. Note that in the last case we first build the set of partial derivatives |
|
1709 w.r.t~@{text c}, then build the image of this set under the function @{term "pders s"} |
|
1710 and finally `union up' all resulting sets. Note also that in some sense, partial |
|
1711 derivatives have the @{text "ACI"}-identities already build in. Antimirov |
|
1712 \cite{Antimirov95} |
|
1713 showed |
|
1714 |
|
1715 \begin{equation} |
|
1716 \mbox{\begin{tabular}{c} |
|
1717 @{thm Der_pder}\\ |
|
1718 @{thm Ders_pders} |
|
1719 \end{tabular}} |
|
1720 \end{equation} |
|
1721 |
|
1722 \noindent |
|
1723 and proved that for every language and regular expression there are only finitely |
|
1724 many partial derivatives. |
1683 *} |
1725 *} |
1684 |
1726 |
1685 section {* Closure Properties *} |
1727 section {* Closure Properties *} |
1686 |
1728 |
|
1729 text {* |
|
1730 The beautiful characteristics of regular languages is that they are closed |
|
1731 under many operations. Closure under union, sequencencing and Kleene-star |
|
1732 are trivial to establish given our definition of regularity (Def.~\ref{regular}). |
|
1733 More interesting is the closure under complement, because |
|
1734 it seems difficult to construct a regular expression for the complement |
|
1735 language by direct means. However the existence of such a regular expression |
|
1736 can now be easily proved using the Myhill-Nerode theorem since |
|
1737 |
|
1738 \begin{center} |
|
1739 @{term "s\<^isub>1 \<approx>A s\<^isub>2"} if and only if @{term "s\<^isub>1 \<approx>(-A) s\<^isub>2"} |
|
1740 \end{center} |
|
1741 |
|
1742 \noindent |
|
1743 holds for any strings @{text "s\<^isub>1"} and @{text |
|
1744 "s\<^isub>2"}. Therefore @{text A} and the complement language @{term "-A"} |
|
1745 give rise to the same partitions. |
|
1746 |
|
1747 Once closure under complement is established, closure under intersection |
|
1748 and set difference is also easy, because |
|
1749 |
|
1750 \begin{center} |
|
1751 \begin{tabular}{c} |
|
1752 @{term "A \<inter> B = - (- A \<union> - B)"}\\ |
|
1753 @{term "A - B = - (- A \<union> B)"} |
|
1754 \end{tabular} |
|
1755 \end{center} |
|
1756 |
|
1757 \noindent |
|
1758 Closure of regular languages under reversal, which means |
|
1759 |
|
1760 \begin{center} |
|
1761 @{text "A\<^bsup>-1\<^esup> \<equiv> {s\<^bsup>-1\<^esup> | s \<in> A}"} |
|
1762 \end{center} |
|
1763 |
|
1764 \noindent |
|
1765 can be shown with the help of the following operation defined on regular |
|
1766 expressions |
|
1767 |
|
1768 \begin{center} |
|
1769 \begin{tabular}{r@ {\hspace{1mm}}c@ {\hspace{1mm}}l} |
|
1770 @{thm (lhs) Rev.simps(1)} & @{text "\<equiv>"} & @{thm (rhs) Rev.simps(1)}\\ |
|
1771 @{thm (lhs) Rev.simps(2)} & @{text "\<equiv>"} & @{thm (rhs) Rev.simps(2)}\\ |
|
1772 @{thm (lhs) Rev.simps(3)} & @{text "\<equiv>"} & @{thm (rhs) Rev.simps(3)}\\ |
|
1773 @{thm (lhs) Rev.simps(4)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]} & @{text "\<equiv>"} & |
|
1774 @{thm (rhs) Rev.simps(4)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]}\\ |
|
1775 @{thm (lhs) Rev.simps(5)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]} & @{text "\<equiv>"} & |
|
1776 @{thm (rhs) Rev.simps(5)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]}\\ |
|
1777 @{thm (lhs) Rev.simps(6)} & @{text "\<equiv>"} & @{thm (rhs) Rev.simps(6)}\\ |
|
1778 \end{tabular} |
|
1779 \end{center} |
|
1780 |
|
1781 |
|
1782 In connection with left-quotient, the perhaps surprising fact is that |
|
1783 regular languages are closed under any left-quotient. |
|
1784 |
|
1785 |
|
1786 *} |
|
1787 |
1687 |
1788 |
1688 section {* Conclusion and Related Work *} |
1789 section {* Conclusion and Related Work *} |
1689 |
1790 |
1690 text {* |
1791 text {* |
|
1792 \noindent |
1691 In this paper we took the view that a regular language is one where there |
1793 In this paper we took the view that a regular language is one where there |
1692 exists a regular expression that matches all of its strings. Regular |
1794 exists a regular expression that matches all of its strings. Regular |
1693 expressions can conveniently be defined as a datatype in HOL-based theorem |
1795 expressions can conveniently be defined as a datatype in HOL-based theorem |
1694 provers. For us it was therefore interesting to find out how far we can push |
1796 provers. For us it was therefore interesting to find out how far we can push |
1695 this point of view. We have established in Isabelle/HOL both directions |
1797 this point of view. We have established in Isabelle/HOL both directions |
1696 of the Myhill-Nerode theorem. |
1798 of the Myhill-Nerode theorem. |
1697 % |
1799 % |
1698 \begin{thrm}[The Myhill-Nerode Theorem]\mbox{}\\ |
1800 \begin{thrm}[The Myhill-Nerode Theorem]\mbox{}\\ |
1699 A language @{text A} is regular if and only if @{thm (rhs) Myhill_Nerode}. |
1801 A language @{text A} is regular if and only if @{thm (rhs) Myhill_Nerode}. |
1700 \end{thrm} |
1802 \end{thrm} |
1701 % |
1803 |
1702 \noindent |
1804 \noindent |
1703 Having formalised this theorem means we |
1805 Having formalised this theorem means we pushed our point of view quite |
1704 pushed our point of view quite far. Using this theorem we can obviously prove when a language |
1806 far. Using this theorem we can obviously prove when a language is \emph{not} |
1705 is \emph{not} regular---by establishing that it has infinitely many |
1807 regular---by establishing that it has infinitely many equivalence classes |
1706 equivalence classes generated by the Myhill-Nerode relation (this is usually |
1808 generated by the Myhill-Nerode relation (this is usually the purpose of the |
1707 the purpose of the pumping lemma \cite{Kozen97}). We can also use it to |
1809 pumping lemma \cite{Kozen97}). We can also use it to establish the standard |
1708 establish the standard textbook results about closure properties of regular |
1810 textbook results about closure properties of regular languages. Interesting |
1709 languages. Interesting is the case of closure under complement, because |
1811 is the case of closure under complement, because it seems difficult to |
1710 it seems difficult to construct a regular expression for the complement |
1812 construct a regular expression for the complement language by direct |
1711 language by direct means. However the existence of such a regular expression |
1813 means. However the existence of such a regular expression can be easily |
1712 can be easily proved using the Myhill-Nerode theorem since |
1814 proved using the Myhill-Nerode theorem. Proving the existence of such a |
1713 % |
1815 regular expression via automata using the standard method would be quite |
1714 \begin{center} |
1816 involved. It includes the steps: regular expression @{text "\<Rightarrow>"} |
1715 @{term "s\<^isub>1 \<approx>A s\<^isub>2"} if and only if @{term "s\<^isub>1 \<approx>(-A) s\<^isub>2"} |
1817 non-deterministic automaton @{text "\<Rightarrow>"} deterministic automaton @{text "\<Rightarrow>"} |
1716 \end{center} |
1818 complement automaton @{text "\<Rightarrow>"} regular expression. |
1717 % |
1819 |
1718 \noindent |
|
1719 holds for any strings @{text "s\<^isub>1"} and @{text |
|
1720 "s\<^isub>2"}. Therefore @{text A} and the complement language @{term "-A"} give rise to the same |
|
1721 partitions. Proving the existence of such a regular expression via automata |
|
1722 using the standard method would |
|
1723 be quite involved. It includes the |
|
1724 steps: regular expression @{text "\<Rightarrow>"} non-deterministic automaton @{text |
|
1725 "\<Rightarrow>"} deterministic automaton @{text "\<Rightarrow>"} complement automaton @{text "\<Rightarrow>"} |
|
1726 regular expression. |
|
1727 |
1820 |
1728 While regular expressions are convenient in formalisations, they have some |
1821 While regular expressions are convenient in formalisations, they have some |
1729 limitations. One is that there seems to be no method of calculating a |
1822 limitations. One is that there seems to be no method of calculating a |
1730 minimal regular expression (for example in terms of length) for a regular |
1823 minimal regular expression (for example in terms of length) for a regular |
1731 language, like there is |
1824 language, like there is |
1735 whose correctness has been formally established, we refer the reader to |
1828 whose correctness has been formally established, we refer the reader to |
1736 Owens and Slind \cite{OwensSlind08}. |
1829 Owens and Slind \cite{OwensSlind08}. |
1737 |
1830 |
1738 |
1831 |
1739 Our formalisation consists of 780 lines of Isabelle/Isar code for the first |
1832 Our formalisation consists of 780 lines of Isabelle/Isar code for the first |
1740 direction and 460 for the second, plus around 300 lines of standard material about |
1833 direction and 460 for the second, plus around 300 lines of standard material |
1741 regular languages. While this might be seen as too large to count as a |
1834 about regular languages. While this might be seen large, it should be seen |
1742 concise proof pearl, this should be seen in the context of the work done by |
1835 in the context of the work done by Constable at al \cite{Constable00} who |
1743 Constable at al \cite{Constable00} who formalised the Myhill-Nerode theorem |
1836 formalised the Myhill-Nerode theorem in Nuprl using automata. They write |
1744 in Nuprl using automata. They write that their four-member team needed |
1837 that their four-member team needed something on the magnitude of 18 months |
1745 something on the magnitude of 18 months for their formalisation. The |
1838 for their formalisation. The estimate for our formalisation is that we |
1746 estimate for our formalisation is that we needed approximately 3 months and |
1839 needed approximately 3 months and this included the time to find our proof |
1747 this included the time to find our proof arguments. Unlike Constable et al, |
1840 arguments. Unlike Constable et al, who were able to follow the proofs from |
1748 who were able to follow the proofs from \cite{HopcroftUllman69}, we had to |
1841 \cite{HopcroftUllman69}, we had to find our own arguments. So for us the |
1749 find our own arguments. So for us the formalisation was not the |
1842 formalisation was not the bottleneck. It is hard to gauge the size of a |
1750 bottleneck. It is hard to gauge the size of a formalisation in Nurpl, but |
1843 formalisation in Nurpl, but from what is shown in the Nuprl Math Library |
1751 from what is shown in the Nuprl Math Library about their development it |
1844 about their development it seems substantially larger than ours. The code of |
1752 seems substantially larger than ours. The code of ours can be found in the |
1845 ours can be found in the Mercurial Repository at |
1753 Mercurial Repository at |
|
1754 \mbox{\url{http://www4.in.tum.de/~urbanc/regexp.html}}. |
1846 \mbox{\url{http://www4.in.tum.de/~urbanc/regexp.html}}. |
|
1847 |
1755 |
1848 |
1756 |
1849 |
1757 Our proof of the first direction is very much inspired by \emph{Brzozowski's |
1850 Our proof of the first direction is very much inspired by \emph{Brzozowski's |
1758 algebraic method} used to convert a finite automaton to a regular |
1851 algebraic method} used to convert a finite automaton to a regular |
1759 expression \cite{Brzozowski64}. The close connection can be seen by considering the equivalence |
1852 expression \cite{Brzozowski64}. The close connection can be seen by considering the equivalence |