731 \end{center} |
735 \end{center} |
732 |
736 |
733 \noindent |
737 \noindent |
734 Finiteness is straightforward, as @{const Subst} and @{const Arden} operations |
738 Finiteness is straightforward, as @{const Subst} and @{const Arden} operations |
735 keep the equational system finite. These operation also preserve soundness |
739 keep the equational system finite. These operation also preserve soundness |
736 distinctness (we proved soundness for @{const Arden} in Lem.~\ref{ardenable}). |
740 and distinctness (we proved soundness for @{const Arden} in Lem.~\ref{ardenable}). |
737 The property Ardenable is clearly preserved because the append-operation |
741 The property ardenable is clearly preserved because the append-operation |
738 cannot make a regular expression to match the empty string. Validity is |
742 cannot make a regular expression to match the empty string. Validity is |
739 given because @{const Arden} removes an equivalence class from @{text yrhs} |
743 given because @{const Arden} removes an equivalence class from @{text yrhs} |
740 and then @{const Subst_all} removes @{text Y} from the equational system. |
744 and then @{const Subst_all} removes @{text Y} from the equational system. |
741 Having proved the implication above, we can replace @{text "ES"} with @{text "ES - {(Y, yrhs)}"} |
745 Having proved the implication above, we can replace @{text "ES"} with @{text "ES - {(Y, yrhs)}"} |
742 which matches with our proof-obligation of @{const "Subst_all"}. Since |
746 which matches with our proof-obligation of @{const "Subst_all"}. Since |
743 \mbox{@{term "ES = ES - {(Y, yrhs)} \<union> {(Y, yrhs)}"}}, we can use our assumption |
747 \mbox{@{term "ES = ES - {(Y, yrhs)} \<union> {(Y, yrhs)}"}}, we can use our assumption |
744 to complete the proof.\qed |
748 to complete the proof.\qed |
745 \end{proof} |
749 \end{proof} |
746 |
750 |
|
751 \noindent |
|
752 We also need the fact that @{text Iter} decreases the termination measure. |
|
753 |
747 \begin{lemma}\label{itertwo} |
754 \begin{lemma}\label{itertwo} |
748 @{thm[mode=IfThen] iteration_step_measure[simplified (no_asm), where xrhs="rhs"]} |
755 @{thm[mode=IfThen] iteration_step_measure[simplified (no_asm), where xrhs="rhs"]} |
749 \end{lemma} |
756 \end{lemma} |
750 |
757 |
751 \begin{proof} |
758 \begin{proof} |
766 \begin{proof} |
777 \begin{proof} |
767 In order to prove this lemma using \eqref{whileprinciple}, we have to use a slightly |
778 In order to prove this lemma using \eqref{whileprinciple}, we have to use a slightly |
768 stronger invariant since Lem.~\ref{iterone} and \ref{itertwo} have the precondition |
779 stronger invariant since Lem.~\ref{iterone} and \ref{itertwo} have the precondition |
769 that @{term "(X, rhs) \<in> ES"} for some @{text rhs}. This precondition is needed |
780 that @{term "(X, rhs) \<in> ES"} for some @{text rhs}. This precondition is needed |
770 in order to choose in the @{const Iter}-step an equation that is not \mbox{@{term "X = rhs"}}. |
781 in order to choose in the @{const Iter}-step an equation that is not \mbox{@{term "X = rhs"}}. |
771 Therefore our invariant is cannot be just @{term "invariant ES"}, but must be |
782 Therefore our invariant cannot be just @{term "invariant ES"}, but must be |
772 @{term "invariant ES \<and> (\<exists>rhs. (X, rhs) \<in> ES)"}. By assumption |
783 @{term "invariant ES \<and> (\<exists>rhs. (X, rhs) \<in> ES)"}. By assumption |
773 @{thm (prem 2) Solve} and Lem.~\ref{invzero}, the more general invariant holds for |
784 @{thm (prem 2) Solve} and Lem.~\ref{invzero}, the more general invariant holds for |
774 the initial equational system. This is premise 1 of~\eqref{whileprinciple}. |
785 the initial equational system. This is premise 1 of~\eqref{whileprinciple}. |
775 Premise 2 is given by Lem.~\ref{iterone} and the fact that @{const Iter} might |
786 Premise 2 is given by Lem.~\ref{iterone} and the fact that @{const Iter} might |
776 modify the @{text rhs} in the equation @{term "X = rhs"}, but does not remove it. |
787 modify the @{text rhs} in the equation @{term "X = rhs"}, but does not remove it. |
777 Premise 3 of~\eqref{whileprinciple} is by Lem.~\ref{itertwo}. Now in premise 4 |
788 Premise 3 of~\eqref{whileprinciple} is by Lem.~\ref{itertwo}. Now in premise 4 |
778 we like to show that there exists a @{text rhs} such that @{term "ES = {(X, rhs)}"} |
789 we like to show that there exists a @{text rhs} such that @{term "ES = {(X, rhs)}"} |
779 and that @{text "invariant {(X, rhs)}"} holds, provided the condition @{text "Cond"} |
790 and that @{text "invariant {(X, rhs)}"} holds, provided the condition @{text "Cond"} |
780 does not hols. By the stronger invariant we know there exists such a @{text "rhs"} |
791 does not holds. By the stronger invariant we know there exists such a @{text "rhs"} |
781 with @{term "(X, rhs) \<in> ES"}. Because @{text Cond} is not true, we know the cardinality |
792 with @{term "(X, rhs) \<in> ES"}. Because @{text Cond} is not true, we know the cardinality |
782 of @{text ES} is @{text 1}. This means @{text "ES"} must actually be the equation @{text "X = rhs"}, |
793 of @{text ES} is @{text 1}. This means @{text "ES"} must actually be the equation @{text "X = rhs"}, |
783 for which the invariant holds. This allows us to conclude that |
794 for which the invariant holds. This allows us to conclude that |
784 @{term "Solve X (Init (UNIV // \<approx>A)) = {(X, rhs)}"} and @{term "invariant {(X, rhs)}"} hold.\qed |
795 @{term "Solve X (Init (UNIV // \<approx>A)) = {(X, rhs)}"} and @{term "invariant {(X, rhs)}"} hold, |
|
796 as needed.\qed |
785 \end{proof} |
797 \end{proof} |
786 |
798 |
787 \noindent |
799 \noindent |
788 With this lemma in place we can show that for every equivalence class in @{term "UNIV // \<approx>A"} |
800 With this lemma in place we can show that for every equivalence class in @{term "UNIV // \<approx>A"} |
789 there exists a regular expression. |
801 there exists a regular expression. |
879 equivalence classes generated by the Myhill-Nerode relation (this is usually |
891 equivalence classes generated by the Myhill-Nerode relation (this is usually |
880 the purpose of the pumping lemma \cite{Kozen97}). We can also use it to |
892 the purpose of the pumping lemma \cite{Kozen97}). We can also use it to |
881 establish the standard textbook results about closure properties of regular |
893 establish the standard textbook results about closure properties of regular |
882 languages. Interesting is the case of closure under complement, because |
894 languages. Interesting is the case of closure under complement, because |
883 it seems difficult to construct a regular expression for the complement |
895 it seems difficult to construct a regular expression for the complement |
884 language by direct means. However the existence can be easily proved using |
896 language by direct means. However the existence of such a regular expression |
885 the Myhill-Nerode theorem since clearly |
897 can be easily proved using the Myhill-Nerode theorem since |
886 |
898 |
887 \begin{center} |
899 \begin{center} |
888 @{term "s\<^isub>1 \<approx>A s\<^isub>2"} if and only if @{term "s\<^isub>1 \<approx>(-A) s\<^isub>2"} |
900 @{term "s\<^isub>1 \<approx>A s\<^isub>2"} if and only if @{term "s\<^isub>1 \<approx>(-A) s\<^isub>2"} |
889 \end{center} |
901 \end{center} |
890 |
902 |
891 \noindent |
903 \noindent |
892 holds for any strings @{text "s\<^isub>1"} and @{text |
904 holds for any strings @{text "s\<^isub>1"} and @{text |
893 "s\<^isub>2"}. Therefore @{text A} and @{term "-A"} give rise to the same |
905 "s\<^isub>2"}. Therefore @{text A} and @{term "-A"} give rise to the same |
894 partitions. From the closure under complementation follows also the closure |
906 partitions. |
895 under intersection and set difference by some simple set calculations. |
|
896 Proving the same result via automata would be quite involved. It includes the |
907 Proving the same result via automata would be quite involved. It includes the |
897 steps: regular expression @{text "\<Rightarrow>"} non-deterministic automaton @{text |
908 steps: regular expression @{text "\<Rightarrow>"} non-deterministic automaton @{text |
898 "\<Rightarrow>"} deterministic automaton @{text "\<Rightarrow>"} complement automaton @{text "\<Rightarrow>"} |
909 "\<Rightarrow>"} deterministic automaton @{text "\<Rightarrow>"} complement automaton @{text "\<Rightarrow>"} |
899 regular expression. |
910 regular expression. |
900 |
911 |
901 Our formalisation consists of ??? lines of Isar code for the first |
912 Our formalisation consists of ??? lines of Isabelle/Isar code for the first |
902 direction and ??? for the second. While this might be seen as too large |
913 direction and ??? for the second. While this might be seen as too large to |
903 to count as a concise proof pearl, this should be seen in the context |
914 count as a concise proof pearl, this should be seen in the context of the |
904 of the work done by Constable at al \cite{Constable00} who formalised |
915 work done by Constable at al \cite{Constable00} who formalised the |
905 the Myhill-Nerode theorem in Nuprl using automata. They write that |
916 Myhill-Nerode theorem in Nuprl using automata. This is the most |
906 their four-member team needed something on the magnitute of 18 months |
917 They write that their |
907 to formalise the Myhill-Nerode theorem. Our estimate is that we needed |
918 four-member team needed something on the magnitute of 18 months to formalise |
908 approximately 3 months for our fomalisation and this included the time |
919 the Myhill-Nerode theorem. The estimate for our formalisation is that we |
909 to find our proof arguments, as we could not find them in the literature. |
920 needed approximately 3 months and this included the time to find our proof |
910 So for us the formalisation was not the bottleneck. It is hard for us |
921 arguments. Unlike Constable et al, who were able to follow the proofs from |
911 to gauge the size of a formalisation in Nurpl, but from what is shown in |
922 \cite{???}, we had to find our own arguments. So for us the formalisation |
912 the Nuprl Math Library their development seems substantially larger. |
923 was not the bottleneck. It is hard to gauge the size of a formalisation in |
|
924 Nurpl, but from what is shown in the Nuprl Math Library about their |
|
925 development it seems substantially larger than ours. The code of |
|
926 ours can be found under |
|
927 |
|
928 \begin{center} |
|
929 ??? |
|
930 \end{center} |
|
931 |
913 |
932 |
914 Our proof of the first direction is very much inspired by \emph{Brzozowski's |
933 Our proof of the first direction is very much inspired by \emph{Brzozowski's |
915 algebraic mehod} used to convert a finite automaton to a regular |
934 algebraic mehod} used to convert a finite automaton to a regular |
916 expression. The close connection can be seen by considering the equivalence |
935 expression \cite{Brzozowski64}. The close connection can be seen by considering the equivalence |
917 classes as the states of the minimal automaton for the regular language. |
936 classes as the states of the minimal automaton for the regular language. |
918 However there are some subtle differences. If we identify equivalence |
937 However there are some subtle differences. If we identify equivalence |
919 classes with the states of the automaton, then the most natural choice is to |
938 classes with the states of the automaton, then the most natural choice is to |
920 characterise each state with the set of strings starting from the initial |
939 characterise each state with the set of strings starting from the initial |
921 state leading up to that state. Usually the states are characterised as the |
940 state leading up to that state. Usually, however, the states are characterised as the |
922 ones starting from that state leading to the terminal states. The first |
941 ones starting from that state leading to the terminal states. The first |
923 choice has consequences how the initial equational system is set up. We have |
942 choice has consequences how the initial equational system is set up. We have |
924 the $\lambda$-term on our ``initial state'', while Brzozowski has it on the |
943 the $\lambda$-term on our ``initial state'', while Brzozowski has it on the |
925 terminal states. This means we also need to reverse the direction of Arden's |
944 terminal states. This means we also need to reverse the direction of Arden's |
926 lemma. |
945 lemma. |
927 |
946 |
928 We briefly considered using the method Brzozowski presented in the Appendix |
947 We briefly considered using the method Brzozowski presented in the Appendix |
929 of \cite{Brzozowski64} in order to prove the second direction of the |
948 of~\cite{Brzozowski64} in order to prove the second direction of the |
930 Myhill-Nerode theorem. There he calculates the derivatives for regular |
949 Myhill-Nerode theorem. There he calculates the derivatives for regular |
931 expressions and shows that there can be only finitely many of them. We could |
950 expressions and shows that there can be only finitely many of them. We could |
932 use as the tag of a string @{text s} the derivative of a regular expression |
951 use as the tag of a string @{text s} the derivative of a regular expression |
933 generated with respect to @{text s}. Using the fact that two strings are |
952 generated with respect to @{text s}. Using the fact that two strings are |
934 Myhill-Nerode related whenever their derivative is the same together with |
953 Myhill-Nerode related whenever their derivative is the same together with |
935 the fact that there are only finitely many derivatives for a regular |
954 the fact that there are only finitely many derivatives for a regular |
936 expression would give us the same argument. However it seems not so easy to |
955 expression would give us the same argument as ours. However it seems not so easy to |
937 calculate the derivatives and then to count them. Therefore we preferred our |
956 calculate the derivatives and then to count them. Therefore we preferred our |
938 direct method of using tagging-functions involving equivalence classes. This |
957 direct method of using tagging-functions involving equivalence classes. This |
939 is also where our method shines, because we can completely side-step the |
958 is also where our method shines, because we can completely side-step the |
940 standard argument \cite{Kozen97} where automata need to be composed, which |
959 standard argument \cite{Kozen97} where automata need to be composed, which |
941 is not so convenient to formalise in a HOL-based theorem prover. |
960 as stated in the Introduction is not so convenient to formalise in a |
|
961 HOL-based theorem prover. |
942 |
962 |
943 While regular expressions are convenient in formalisations, they have some |
963 While regular expressions are convenient in formalisations, they have some |
944 limitations. One is that there seems to be no notion of a minimal regular |
964 limitations. One is that there seems to be no notion of a minimal regular |
945 expression, like there is a notion of a minimal automaton for a regular |
965 expression, like there is for automata. For an implementation of a simple |
946 expression. |
966 regular expression matcher, whose correctness has been formally |
|
967 established, we refer the reader to \cite{OwensSlind08}. |
947 |
968 |
948 *} |
969 *} |
949 |
970 |
950 |
971 |
951 (*<*) |
972 (*<*) |