822 By the preceeding Lemma, we know that there exists a @{text "rhs"} such |
823 By the preceeding Lemma, we know that there exists a @{text "rhs"} such |
823 that @{term "Solve X (Init (UNIV // \<approx>A))"} returns the equation @{text "X = rhs"}, |
824 that @{term "Solve X (Init (UNIV // \<approx>A))"} returns the equation @{text "X = rhs"}, |
824 and that the invariant holds for this equation. That means we |
825 and that the invariant holds for this equation. That means we |
825 know @{text "X = \<Union>\<calL> ` rhs"}. We further know that |
826 know @{text "X = \<Union>\<calL> ` rhs"}. We further know that |
826 this is equal to \mbox{@{text "\<Union>\<calL> ` (Arden X rhs)"}} using the properties of the |
827 this is equal to \mbox{@{text "\<Union>\<calL> ` (Arden X rhs)"}} using the properties of the |
827 invariant and Lem.\ref{ardenable}. Using the validity property for the equation @{text "X = rhs"}, |
828 invariant and Lem.~\ref{ardenable}. Using the validity property for the equation @{text "X = rhs"}, |
828 we can infer that @{term "rhss rhs \<subseteq> {X}"} and because the arden operation |
829 we can infer that @{term "rhss rhs \<subseteq> {X}"} and because the arden operation |
829 removes that @{text X} from @{text rhs}, that @{term "rhss (Arden X rhs) = {}"}. |
830 removes that @{text X} from @{text rhs}, that @{term "rhss (Arden X rhs) = {}"}. |
830 This means the right-hand side @{term "Arden X rhs"} can only consist of terms of the form @{term "Lam r"}. |
831 This means the right-hand side @{term "Arden X rhs"} can only consist of terms of the form @{term "Lam r"}. |
831 So we can collect those (finitely many) regular expressions and have @{term "X = L (\<Uplus>rs)"}. |
832 So we can collect those (finitely many) regular expressions and have @{term "X = L (\<Uplus>rs)"}. |
832 With this we can conclude the proof.\qed |
833 With this we can conclude the proof.\qed |
894 |
895 |
895 Our method will rely on some |
896 Our method will rely on some |
896 \emph{tagging functions} defined over strings. Given the inductive hypothesis, it will |
897 \emph{tagging functions} defined over strings. Given the inductive hypothesis, it will |
897 be easy to prove that the range of these tagging functions is finite |
898 be easy to prove that the range of these tagging functions is finite |
898 (the range of a function @{text f} is defined as @{text "range f \<equiv> f ` UNIV"}). |
899 (the range of a function @{text f} is defined as @{text "range f \<equiv> f ` UNIV"}). |
899 With this we will be able to infer that the tagging functions, seen as a relation, |
900 With this we will be able to infer that the tagging functions, seen as relations, |
900 give rise to finitely many equivalence classes of @{const UNIV}. Finally we |
901 give rise to finitely many equivalence classes of @{const UNIV}. Finally we |
901 will show that the tagging relation is more refined than @{term "\<approx>(L r)"}, which |
902 will show that the tagging relation is more refined than @{term "\<approx>(L r)"}, which |
902 implies that @{term "UNIV // \<approx>(L r)"} must also be finite. |
903 implies that @{term "UNIV // \<approx>(L r)"} must also be finite (a relation @{text "R\<^isub>1"} |
903 A relation @{text "R\<^isub>1"} is said to \emph{refine} @{text "R\<^isub>2"} provided @{text "R\<^isub>1 \<subseteq> R\<^isub>2"}. |
904 is said to \emph{refine} @{text "R\<^isub>2"} provided @{text "R\<^isub>1 \<subseteq> R\<^isub>2"}). |
904 We formally define the notion of a \emph{tag-relation} as follows. |
905 We formally define the notion of a \emph{tagging-relation} as follows. |
905 |
906 |
906 \begin{definition}[Tagging-Relation] Given a tag-function @{text tag}, then two strings @{text x} |
907 \begin{definition}[Tagging-Relation] Given a tagging-function @{text tag}, then two strings @{text x} |
907 and @{text y} are \emph{tag-related} provided |
908 and @{text y} are \emph{tag-related} provided |
908 \begin{center} |
909 \begin{center} |
909 @{text "x =tag= y \<equiv> tag x = tag y"} |
910 @{text "x =tag= y \<equiv> tag x = tag y"} |
910 \end{center} |
911 \end{center} |
911 \end{definition} |
912 \end{definition} |
912 |
913 |
913 \noindent |
914 \noindent |
914 In order to establish finiteness of a set @{text A} we shall use the following powerful |
915 In order to establish finiteness of a set @{text A}, we shall use the following powerful |
915 principle from Isabelle/HOL's library. |
916 principle from Isabelle/HOL's library. |
916 % |
917 % |
917 \begin{equation}\label{finiteimageD} |
918 \begin{equation}\label{finiteimageD} |
918 @{thm[mode=IfThen] finite_imageD} |
919 @{thm[mode=IfThen] finite_imageD} |
919 \end{equation} |
920 \end{equation} |
920 |
921 |
921 \noindent |
922 \noindent |
922 It states that if an image of a set under an injective function @{text f} (over this set) |
923 It states that if an image of a set under an injective function @{text f} (injective over this set) |
923 is finite, then @{text A} itself must be finite. We can use it to establish the following |
924 is finite, then @{text A} itself must be finite. We can use it to establish the following |
924 two lemmas. |
925 two lemmas. |
925 |
926 |
926 \begin{lemma}\label{finone} |
927 \begin{lemma}\label{finone} |
927 @{thm[mode=IfThen] finite_eq_tag_rel} |
928 @{thm[mode=IfThen] finite_eq_tag_rel} |
928 \end{lemma} |
929 \end{lemma} |
929 |
930 |
930 \begin{proof} |
931 \begin{proof} |
931 We set in \eqref{finiteimageD}, @{text f} to be @{text "X \<mapsto> tag ` X"}. We have |
932 We set in \eqref{finiteimageD}, @{text f} to be @{text "X \<mapsto> tag ` X"}. We have |
932 @{text "range f"} to be subset of @{term "Pow (range tag)"}, which we know must be |
933 @{text "range f"} to be a subset of @{term "Pow (range tag)"}, which we know must be |
933 finite by assumption. Now @{term "f (UNIV // =tag=)"} is a subset of @{text "range f"}, |
934 finite by assumption. Now @{term "f (UNIV // =tag=)"} is a subset of @{text "range f"}, |
934 and so also finite. Injectivity amounts to showing that @{text "X = Y"} under the |
935 and so also finite. Injectivity amounts to showing that @{text "X = Y"} under the |
935 assumptions that @{text "X, Y \<in> "}~@{term "UNIV // =tag="} and @{text "f X = f Y"}. |
936 assumptions that @{text "X, Y \<in> "}~@{term "UNIV // =tag="} and @{text "f X = f Y"}. |
936 From the assumption we can obtain a @{text "x \<in> X"} and @{text "y \<in> Y"} with |
937 From the assumption we can obtain @{text "x \<in> X"} and @{text "y \<in> Y"} with |
937 @{text "tag x = tag y"}. This in turn means that the equivalence classes @{text X} |
938 @{text "tag x = tag y"}. Since @{text x} and @{text y} are tag-related, this in |
|
939 turn means that the equivalence classes @{text X} |
938 and @{text Y} must be equal.\qed |
940 and @{text Y} must be equal.\qed |
939 \end{proof} |
941 \end{proof} |
940 |
942 |
941 \begin{lemma}\label{fintwo} |
943 \begin{lemma}\label{fintwo} |
942 Given two equivalence relations @{text "R\<^isub>1"} and @{text "R\<^isub>2"}, where |
944 Given two equivalence relations @{text "R\<^isub>1"} and @{text "R\<^isub>2"}, whereby |
943 @{text "R\<^isub>1"} refines @{text "R\<^isub>2"}. |
945 @{text "R\<^isub>1"} refines @{text "R\<^isub>2"}. |
944 If @{thm (prem 1) refined_partition_finite[where ?R1.0="R\<^isub>1" and ?R2.0="R\<^isub>2"]} |
946 If @{thm (prem 1) refined_partition_finite[where ?R1.0="R\<^isub>1" and ?R2.0="R\<^isub>2"]} |
945 then @{thm (concl) refined_partition_finite[where ?R1.0="R\<^isub>1" and ?R2.0="R\<^isub>2"]}. |
947 then @{thm (concl) refined_partition_finite[where ?R1.0="R\<^isub>1" and ?R2.0="R\<^isub>2"]}. |
946 \end{lemma} |
948 \end{lemma} |
947 |
949 |
948 \begin{proof} |
950 \begin{proof} |
949 We prove this lemma again using \eqref{finiteimageD}. For this we set @{text f} to |
951 We prove this lemma again using \eqref{finiteimageD}. This time we set @{text f} to |
950 be @{text "X \<mapsto>"}~@{term "{R\<^isub>1 `` {x} | x. x \<in> X}"}. It is easy to see that |
952 be @{text "X \<mapsto>"}~@{term "{R\<^isub>1 `` {x} | x. x \<in> X}"}. It is easy to see that |
951 @{text "finite (f ` (UNIV // R\<^isub>2))"} because it is a subset of @{text "Pow (UNIV // R\<^isub>1)"}, |
953 @{text "finite (f ` (UNIV // R\<^isub>2))"} because it is a subset of @{text "Pow (UNIV // R\<^isub>1)"}, |
952 which is finite by assumption. What remains to be shown is that @{text f} is injective |
954 which is finite by assumption. What remains to be shown is that @{text f} is injective |
953 on @{term "UNIV // R\<^isub>2"}. This is equivalent to showing that two equivalence |
955 on @{term "UNIV // R\<^isub>2"}. This is equivalent to showing that two equivalence |
954 classes, say @{text "X"} and @{text Y}, in @{term "UNIV // R\<^isub>2"} are equal, provided |
956 classes, say @{text "X"} and @{text Y}, in @{term "UNIV // R\<^isub>2"} are equal, provided |
955 @{text "f X = f Y"}. For @{text "X = Y"} to be equal, we have to find two elements |
957 @{text "f X = f Y"}. For @{text "X = Y"} to be equal, we have to find two elements |
956 @{text "x \<in> X"} and @{text "y \<in> Y"} such that they are @{text R\<^isub>2} related. |
958 @{text "x \<in> X"} and @{text "y \<in> Y"} such that they are @{text R\<^isub>2} related. |
957 We know there exists a @{text x} with @{term "X = R\<^isub>2 `` {x}"} |
959 We know there exists a @{text x} with @{term "X = R\<^isub>2 `` {x}"} |
958 and @{text "x \<in> X"}. From the latter fact we can infer that @{term "R\<^isub>1 ``{x} \<in> f X"} |
960 and @{text "x \<in> X"}. From the latter fact we can infer that @{term "R\<^isub>1 ``{x} \<in> f X"} |
959 and further @{term "R\<^isub>1 ``{x} \<in> f Y"}. From this we can obtain a @{text y} |
961 and further @{term "R\<^isub>1 ``{x} \<in> f Y"}. This means we can obtain a @{text y} |
960 such that @{term "R\<^isub>1 `` {x} = R\<^isub>1 `` {y}"} holds. This means @{text x} and @{text y} |
962 such that @{term "R\<^isub>1 `` {x} = R\<^isub>1 `` {y}"} holds. Consequently @{text x} and @{text y} |
961 are @{text "R\<^isub>1"}-related. Since by assumption @{text "R\<^isub>1"} refines @{text "R\<^isub>2"}, |
963 are @{text "R\<^isub>1"}-related. Since by assumption @{text "R\<^isub>1"} refines @{text "R\<^isub>2"}, |
962 they must also be @{text "R\<^isub>2"}-related, as we need to show.\qed |
964 they must also be @{text "R\<^isub>2"}-related, as we need to show.\qed |
963 \end{proof} |
965 \end{proof} |
964 |
966 |
965 \noindent |
967 \noindent |
966 Chaining Lem.~\ref{finone} and \ref{fintwo} together, means in order to show |
968 Chaining Lem.~\ref{finone} and \ref{fintwo} together, means in order to show |
967 that @{term "UNIV // \<approx>(L r)"} is finite, we have to find a tagging function whose |
969 that @{term "UNIV // \<approx>(L r)"} is finite, we have to find a tagging function whose |
968 range can be shown to be finite and whose tagging-relation refines @{term "\<approx>(L r)"}. |
970 range can be shown to be finite and whose tagging-relation refines @{term "\<approx>(L r)"}. |
969 Let us attempt the @{const ALT}-case. |
971 Let us attempt the @{const ALT}-case first. |
970 |
972 |
971 \begin{proof}[@{const "ALT"}-Case] |
973 \begin{proof}[@{const "ALT"}-Case] |
972 We take as tagging function |
974 We take as tagging function |
973 |
975 |
974 \begin{center} |
976 \begin{center} |
1057 "\<Rightarrow>"} deterministic automaton @{text "\<Rightarrow>"} complement automaton @{text "\<Rightarrow>"} |
1071 "\<Rightarrow>"} deterministic automaton @{text "\<Rightarrow>"} complement automaton @{text "\<Rightarrow>"} |
1058 regular expression. |
1072 regular expression. |
1059 |
1073 |
1060 While regular expressions are convenient in formalisations, they have some |
1074 While regular expressions are convenient in formalisations, they have some |
1061 limitations. One is that there seems to be no method of calculating a |
1075 limitations. One is that there seems to be no method of calculating a |
1062 minimal regular expression (for example in terms of length), like there is |
1076 minimal regular expression (for example in terms of length) for a regular |
1063 for automata. For an implementation of a simple regular expression matcher, |
1077 language, like there is |
|
1078 for automata. On the other hand, efficient regular expression matching, |
|
1079 without using automata, poses no problem \cite{OwensReppyTuron09}. |
|
1080 For an implementation of a simple regular expression matcher, |
1064 whose correctness has been formally established, we refer the reader to |
1081 whose correctness has been formally established, we refer the reader to |
1065 Owens and Slind \cite{OwensSlind08}. |
1082 Owens and Slind \cite{OwensSlind08}. |
1066 |
1083 |
1067 |
1084 |
1068 Our formalisation consists of 790 lines of Isabelle/Isar code for the first |
1085 Our formalisation consists of 790 lines of Isabelle/Isar code for the first |
1069 direction and 475 for the second, plus 300 lines of standard material about |
1086 direction and 475 for the second, plus around 300 lines of standard material about |
1070 regular languages. While this might be seen as too large to count as a |
1087 regular languages. While this might be seen as too large to count as a |
1071 concise proof pearl, this should be seen in the context of the work done by |
1088 concise proof pearl, this should be seen in the context of the work done by |
1072 Constable at al \cite{Constable00} who formalised the Myhill-Nerode theorem |
1089 Constable at al \cite{Constable00} who formalised the Myhill-Nerode theorem |
1073 in Nuprl using automata. They write that their four-member team needed |
1090 in Nuprl using automata. They write that their four-member team needed |
1074 something on the magnitute of 18 months for their formalisation. The |
1091 something on the magnitute of 18 months for their formalisation. The |
1092 classes as the states of the minimal automaton for the regular language. |
1109 classes as the states of the minimal automaton for the regular language. |
1093 However there are some subtle differences. Since we identify equivalence |
1110 However there are some subtle differences. Since we identify equivalence |
1094 classes with the states of the automaton, then the most natural choice is to |
1111 classes with the states of the automaton, then the most natural choice is to |
1095 characterise each state with the set of strings starting from the initial |
1112 characterise each state with the set of strings starting from the initial |
1096 state leading up to that state. Usually, however, the states are characterised as the |
1113 state leading up to that state. Usually, however, the states are characterised as the |
1097 ones starting from that state leading to the terminal states. The first |
1114 strings starting from that state leading to the terminal states. The first |
1098 choice has consequences how the initial equational system is set up. We have |
1115 choice has consequences about how the initial equational system is set up. We have |
1099 the $\lambda$-term on our `initial state', while Brzozowski has it on the |
1116 the $\lambda$-term on our `initial state', while Brzozowski has it on the |
1100 terminal states. This means we also need to reverse the direction of Arden's |
1117 terminal states. This means we also need to reverse the direction of Arden's |
1101 lemma. |
1118 lemma. |
1102 |
1119 |
1103 We briefly considered using the method Brzozowski presented in the Appendix |
1120 We briefly considered using the method Brzozowski presented in the Appendix |
1104 of~\cite{Brzozowski64} in order to prove the second direction of the |
1121 of~\cite{Brzozowski64} in order to prove the second direction of the |
1105 Myhill-Nerode theorem. There he calculates the derivatives for regular |
1122 Myhill-Nerode theorem. There he calculates the derivatives for regular |
1106 expressions and shows that there can be only finitely many of them. We could |
1123 expressions and shows that there can be only finitely many of them. We could |
1107 have used as the tag of a string @{text s} the derivative of a regular expression |
1124 have used as the tag of a string @{text s} the derivative of a regular expression |
1108 generated with respect to @{text s}. Using the fact that two strings are |
1125 generated with respect to @{text s}. Using the fact that two strings are |
1109 Myhill-Nerode related whenever their derivative is the same together with |
1126 Myhill-Nerode related whenever their derivative is the same, together with |
1110 the fact that there are only finitely many derivatives for a regular |
1127 the fact that there are only finitely many derivatives for a regular |
1111 expression would give us a similar argument as ours. However it seems not so easy to |
1128 expression would give us a similar argument as ours. However it seems not so easy to |
1112 calculate the derivatives and then to count them. Therefore we preferred our |
1129 calculate the derivatives and then to count them. Therefore we preferred our |
1113 direct method of using tagging-functions involving equivalence classes. This |
1130 direct method of using tagging-functions. This |
1114 is also where our method shines, because we can completely side-step the |
1131 is also where our method shines, because we can completely side-step the |
1115 standard argument \cite{Kozen97} where automata need to be composed, which |
1132 standard argument \cite{Kozen97} where automata need to be composed, which |
1116 as stated in the Introduction is not so convenient to formalise in a |
1133 as stated in the Introduction is not so convenient to formalise in a |
1117 HOL-based theorem prover. However, it is also the direction where we had to |
1134 HOL-based theorem prover. However, it is also the direction where we had to |
1118 spend most of the `conceptual' time, as our proof-argument based on tagging functions |
1135 spend most of the `conceptual' time, as our proof-argument based on tagging-functions |
1119 is new for establishing the Myhill-Nerode theorem. |
1136 is new for establishing the Myhill-Nerode theorem. All standard proofs |
|
1137 of this direction proceed by arguments over automata. |
1120 |
1138 |
1121 *} |
1139 *} |
1122 |
1140 |
1123 |
1141 |
1124 (*<*) |
1142 (*<*) |