62 |
62 |
63 section {* Introduction *} |
63 section {* Introduction *} |
64 |
64 |
65 text {* |
65 text {* |
66 \noindent |
66 \noindent |
67 One might think they have been studied to death, but in the context of |
67 One might think quotients have been studied to death, but in the context of |
68 theorem provers many questions concerning quotients are far from settled. In |
68 theorem provers many questions concerning them are far from settled. In |
69 this paper we address the question how a convenient reasoning infrastructure |
69 this paper we address the question of how to establish a convenient reasoning |
70 for quotient constructions can be established in Isabelle/HOL, a popular |
70 infrastructure |
71 generic theorem prover. Higher-Order Logic (HOL) consists |
71 for quotient constructions in the Isabelle/HOL, |
|
72 theorem prover. Higher-Order Logic (HOL) consists |
72 of a small number of axioms and inference rules over a simply-typed |
73 of a small number of axioms and inference rules over a simply-typed |
73 term-language. Safe reasoning in HOL is ensured by two very restricted |
74 term-language. Safe reasoning in HOL is ensured by two very restricted |
74 mechanisms for extending the logic: one is the definition of new constants |
75 mechanisms for extending the logic: one is the definition of new constants |
75 in terms of existing ones; the other is the introduction of new types by |
76 in terms of existing ones; the other is the introduction of new types by |
76 identifying non-empty subsets in existing types. It is well understood how |
77 identifying non-empty subsets in existing types. Previous work has shown how |
77 to use both mechanisms for dealing with quotient constructions in HOL (see |
78 to use both mechanisms for dealing with quotient constructions in HOL (see |
78 \cite{Homeier05,Paulson06}). For example the integers in Isabelle/HOL are |
79 \cite{Homeier05,Paulson06}). For example the integers in Isabelle/HOL are |
79 constructed by a quotient construction over the type @{typ "nat \<times> nat"} and |
80 constructed by a quotient construction over the type @{typ "nat \<times> nat"} and |
80 the equivalence relation |
81 the equivalence relation |
81 |
82 |
273 according to the type of the raw constant and the type |
274 according to the type of the raw constant and the type |
274 of the quotient constant. This means we also have to extend the notions |
275 of the quotient constant. This means we also have to extend the notions |
275 of \emph{aggregate equivalence relation}, \emph{respectfulness} and \emph{preservation} |
276 of \emph{aggregate equivalence relation}, \emph{respectfulness} and \emph{preservation} |
276 from Homeier \cite{Homeier05}. |
277 from Homeier \cite{Homeier05}. |
277 |
278 |
278 In addition we are able to address the criticism by Paulson \cite{Paulson06} cited |
279 In addition we are able to clearly specify what is involved |
279 at the beginning of this section about having to collect theorems that are |
|
280 lifted from the raw level to the quotient level into one giant list. Homeier's and |
|
281 also our quotient package are modular so that they allow lifting |
|
282 theorems separately. This has the advantage for the user of being able to develop a |
|
283 formal theory interactively as a natural progression. A pleasing side-result of |
|
284 the modularity is that we are able to clearly specify what is involved |
|
285 in the lifting process (this was only hinted at in \cite{Homeier05} and |
280 in the lifting process (this was only hinted at in \cite{Homeier05} and |
286 implemented as a ``rough recipe'' in ML-code). |
281 implemented as a ``rough recipe'' in ML-code). A pleasing side-result |
287 |
282 is that our procedure for lifting theorems is completely deterministic |
288 |
283 following the structure of the theorem being lifted and the theorem |
289 %The paper is organised as follows: Section \ref{sec:prelims} presents briefly |
284 on the quotient level. Space constraints, unfortunately, allow us to only |
290 %some necessary preliminaries; Section \ref{sec:type} describes the definitions |
285 sketch this part of our work in Section 5 and we defer the reader to a longer |
291 %of quotient types and shows how definitions of constants can be made over |
286 version for the details. However, we will give in Section 3 and 4 all |
292 %quotient types. Section \ref{sec:resp} introduces the notions of respectfulness |
287 definitions that specify the input and output data of our three-step |
293 %and preservation; Section \ref{sec:lift} describes the lifting of theorems; |
288 lifting procedure. Section 6 gives an example how our quotient package |
294 %Section \ref{sec:examples} presents some examples |
289 works in practise. |
295 %and Section \ref{sec:conc} concludes and compares our results to existing |
|
296 %work. |
|
297 *} |
290 *} |
298 |
291 |
299 section {* Preliminaries and General\\ Quotients\label{sec:prelims} *} |
292 section {* Preliminaries and General\\ Quotients\label{sec:prelims} *} |
300 |
293 |
301 text {* |
294 text {* |
302 \noindent |
295 \noindent |
303 We give in this section a crude overview of HOL and describe the main |
296 We will give in this section a crude overview of HOL and describe the main |
304 definitions given by Homeier for quotients \cite{Homeier05}. |
297 definitions given by Homeier for quotients \cite{Homeier05}. |
305 |
298 |
306 At its core, HOL is based on a simply-typed term language, where types are |
299 At its core, HOL is based on a simply-typed term language, where types are |
307 recorded in Church-style fashion (that means, we can always infer the type of |
300 recorded in Church-style fashion (that means, we can always infer the type of |
308 a term and its subterms without any additional information). The grammars |
301 a term and its subterms without any additional information). The grammars |
960 @{text "raw_thm"} and @{text "quot_thm"} as input and returns |
967 @{text "raw_thm"} and @{text "quot_thm"} as input and returns |
961 @{text "reg_thm"}. The idea |
968 @{text "reg_thm"}. The idea |
962 behind this function is that it replaces quantifiers and |
969 behind this function is that it replaces quantifiers and |
963 abstractions involving raw types by bounded ones, and equalities |
970 abstractions involving raw types by bounded ones, and equalities |
964 involving raw types by appropriate aggregate |
971 involving raw types by appropriate aggregate |
965 equivalence relations. It is defined by simultaneously recursing on |
972 equivalence relations. It is defined by simultaneous recursion on |
966 the structure of @{text "raw_thm"} and @{text "quot_thm"} as follows: |
973 the structure of the terms of @{text "raw_thm"} and @{text "quot_thm"} as follows: |
967 |
974 % |
968 \begin{center} |
975 \begin{center} |
969 \begin{tabular}{l} |
976 \begin{tabular}{@ {}l@ {}} |
970 \multicolumn{1}{@ {}l}{abstractions:}\smallskip\\ |
977 \multicolumn{1}{@ {}l@ {}}{abstractions:}\smallskip\\ |
971 @{text "REG (\<lambda>x\<^sup>\<sigma>. t, \<lambda>x\<^sup>\<tau>. s)"} $\dn$ |
978 @{text "REG (\<lambda>x\<^sup>\<sigma>. t, \<lambda>x\<^sup>\<tau>. s)"} $\dn$ |
972 $\begin{cases} |
979 $\begin{cases} |
973 @{text "\<lambda>x\<^sup>\<sigma>. REG (t, s)"} \quad\mbox{provided @{text "\<sigma> = \<tau>"}}\\ |
980 @{text "\<lambda>x\<^sup>\<sigma>. REG (t, s)"} \quad\mbox{provided @{text "\<sigma> = \<tau>"}}\\ |
974 @{text "\<lambda>x\<^sup>\<sigma> \<in> Respects (REL (\<sigma>, \<tau>)). REG (t, s)"} |
981 @{text "\<lambda>x\<^sup>\<sigma> \<in> Resp (REL (\<sigma>, \<tau>)). REG (t, s)"} |
975 \end{cases}$\smallskip\\ |
982 \end{cases}$\smallskip\\ |
976 \\ |
983 \multicolumn{1}{@ {}l@ {}}{universal quantifiers:}\\ |
977 \multicolumn{1}{@ {}l}{universal quantifiers:}\\ |
|
978 @{text "REG (\<forall>x\<^sup>\<sigma>. t, \<forall>x\<^sup>\<tau>. s)"} $\dn$ |
984 @{text "REG (\<forall>x\<^sup>\<sigma>. t, \<forall>x\<^sup>\<tau>. s)"} $\dn$ |
979 $\begin{cases} |
985 $\begin{cases} |
980 @{text "\<forall>x\<^sup>\<sigma>. REG (t, s)"} \quad\mbox{provided @{text "\<sigma> = \<tau>"}}\\ |
986 @{text "\<forall>x\<^sup>\<sigma>. REG (t, s)"} \quad\mbox{provided @{text "\<sigma> = \<tau>"}}\\ |
981 @{text "\<forall>x\<^sup>\<sigma> \<in> Respects (REL (\<sigma>, \<tau>)). REG (t, s)"} |
987 @{text "\<forall>x\<^sup>\<sigma> \<in> Resp (REL (\<sigma>, \<tau>)). REG (t, s)"} |
982 \end{cases}$\smallskip\\ |
988 \end{cases}$\smallskip\\ |
983 \multicolumn{1}{@ {}l}{equality:}\smallskip\\ |
989 \multicolumn{1}{@ {}l@ {}}{equality:}\smallskip\\ |
984 %% REL of two equal types is the equality so we do not need a separate case |
990 %% REL of two equal types is the equality so we do not need a separate case |
985 @{text "REG (=\<^bsup>\<sigma>\<Rightarrow>\<sigma>\<Rightarrow>bool\<^esup>, =\<^bsup>\<tau>\<Rightarrow>\<tau>\<Rightarrow>bool\<^esup>)"} $\dn$ @{text "REL (\<sigma>, \<tau>)"}\\\smallskip\\ |
991 @{text "REG (=\<^bsup>\<sigma>\<Rightarrow>\<sigma>\<Rightarrow>bool\<^esup>, =\<^bsup>\<tau>\<Rightarrow>\<tau>\<Rightarrow>bool\<^esup>)"} $\dn$ @{text "REL (\<sigma>, \<tau>)"}\smallskip\\ |
986 \multicolumn{1}{@ {}l}{applications, variables and constants:}\\ |
992 \multicolumn{1}{@ {}l@ {}}{applications, variables and constants:}\\ |
987 @{text "REG (t\<^isub>1 t\<^isub>2, s\<^isub>1 s\<^isub>2)"} $\dn$ @{text "REG (t\<^isub>1, s\<^isub>1) REG (t\<^isub>2, s\<^isub>2)"}\\ |
993 @{text "REG (t\<^isub>1 t\<^isub>2, s\<^isub>1 s\<^isub>2)"} $\dn$ @{text "REG (t\<^isub>1, s\<^isub>1) REG (t\<^isub>2, s\<^isub>2)"}\\ |
988 @{text "REG (x\<^isub>1, x\<^isub>2)"} $\dn$ @{text "x\<^isub>1"}\\ |
994 @{text "REG (x\<^isub>1, x\<^isub>2)"} $\dn$ @{text "x\<^isub>1"}\\ |
989 @{text "REG (c\<^isub>1, c\<^isub>2)"} $\dn$ @{text "c\<^isub>1"}\\ |
995 @{text "REG (c\<^isub>1, c\<^isub>2)"} $\dn$ @{text "c\<^isub>1"}\\ |
990 \end{tabular} |
996 \end{tabular} |
991 \end{center} |
997 \end{center} |
1038 %%% You should clarify under which circumstances the implication is |
1044 %%% You should clarify under which circumstances the implication is |
1039 %%% being proved here. |
1045 %%% being proved here. |
1040 %%% Cezary: It would be nice to cite Homeiers discussions in the |
1046 %%% Cezary: It would be nice to cite Homeiers discussions in the |
1041 %%% Quotient Package manual from HOL (the longer paper), do you agree? |
1047 %%% Quotient Package manual from HOL (the longer paper), do you agree? |
1042 |
1048 |
1043 In the first proof step, establishing @{text "raw_thm \<longrightarrow> reg_thm"}, we always |
1049 In the first phase, establishing @{text "raw_thm \<longrightarrow> reg_thm"}, we always |
1044 start with an implication. Isabelle provides \emph{mono} rules that can split up |
1050 start with an implication. Isabelle provides \emph{mono} rules that can split up |
1045 the implications into simpler implicational subgoals. This succeeds for every |
1051 the implications into simpler implicational subgoals. This succeeds for every |
1046 monotone connective, except in places where the function @{text REG} replaced, |
1052 monotone connective, except in places where the function @{text REG} replaced, |
1047 for instance, a quantifier by a bounded quantifier. In this case we have |
1053 for instance, a quantifier by a bounded quantifier. To decompose them, we have |
1048 rules of the form |
1054 to prove that the relations involved are aggregate equivalence relations. |
1049 |
1055 |
1050 \begin{isabelle}\ \ \ \ \ %%% |
1056 |
1051 @{text "(\<forall>x. R x \<longrightarrow> (P x \<longrightarrow> Q x)) \<longrightarrow> (\<forall>x. P x \<longrightarrow> \<forall>x \<in> R. Q x)"} |
1057 %In this case we have |
1052 \end{isabelle} |
1058 %rules of the form |
1053 |
1059 % |
1054 \noindent |
1060 % \begin{isabelle}\ \ \ \ \ %%% |
1055 They decompose a bounded quantifier on the right-hand side. We can decompose a |
1061 %@{text "(\<forall>x. R x \<longrightarrow> (P x \<longrightarrow> Q x)) \<longrightarrow> (\<forall>x. P x \<longrightarrow> \<forall>x \<in> R. Q x)"} |
1056 bounded quantifier anywhere if R is an equivalence relation or |
1062 %\end{isabelle} |
1057 if it is a relation over function types with the range being an equivalence |
1063 |
1058 relation. If @{text R} is an equivalence relation we can prove that |
1064 %\noindent |
1059 |
1065 %They decompose a bounded quantifier on the right-hand side. We can decompose a |
1060 \begin{isabelle}\ \ \ \ \ %%% |
1066 %bounded quantifier anywhere if R is an equivalence relation or |
1061 @{text "\<forall>x \<in> Respects R. P x = \<forall>x. P x"} |
1067 %if it is a relation over function types with the range being an equivalence |
1062 \end{isabelle} |
1068 %relation. If @{text R} is an equivalence relation we can prove that |
1063 |
1069 |
1064 \noindent |
1070 %\begin{isabelle}\ \ \ \ \ %%% |
1065 If @{term R\<^isub>2} is an equivalence relation, we can prove that for any predicate @{term P} |
1071 %@{text "\<forall>x \<in> Resp R. P x = \<forall>x. P x"} |
|
1072 %\end{isabelle} |
|
1073 |
|
1074 %\noindent |
|
1075 %If @{term R\<^isub>2} is an equivalence relation, we can prove that for any predicate @{term P} |
1066 |
1076 |
1067 %%% FIXME Reviewer 1 claims the theorem is obviously false so maybe we |
1077 %%% FIXME Reviewer 1 claims the theorem is obviously false so maybe we |
1068 %%% should include a proof sketch? |
1078 %%% should include a proof sketch? |
1069 |
1079 |
1070 \begin{isabelle}\ \ \ \ \ %%% |
1080 %\begin{isabelle}\ \ \ \ \ %%% |
1071 @{thm (concl) ball_reg_eqv_range[of R\<^isub>1 R\<^isub>2, no_vars]} |
1081 %@{thm (concl) ball_reg_eqv_range[of R\<^isub>1 R\<^isub>2, no_vars]} |
1072 \end{isabelle} |
1082 %\end{isabelle} |
1073 |
1083 |
1074 \noindent |
1084 %\noindent |
1075 The last theorem is new in comparison with Homeier's package. There the |
1085 %The last theorem is new in comparison with Homeier's package. There the |
1076 injection procedure would be used to prove such goals and |
1086 %injection procedure would be used to prove such goals and |
1077 the assumption about the equivalence relation would be used. We use the above theorem directly, |
1087 %the assumption about the equivalence relation would be used. We use the above theorem directly, |
1078 because this allows us to completely separate the first and the second |
1088 %because this allows us to completely separate the first and the second |
1079 proof step into two independent ``units''. |
1089 %proof step into two independent ``units''. |
1080 |
1090 |
1081 The second proof step, establishing @{text "reg_thm \<longleftrightarrow> inj_thm"}, starts with an equality |
1091 The second phase, establishing @{text "reg_thm \<longleftrightarrow> inj_thm"}, starts with an equality |
1082 between the terms of the regularized theorem and the injected theorem. |
1092 between the terms of the regularized theorem and the injected theorem. |
1083 The proof again follows the structure of the |
1093 The proof again follows the structure of the |
1084 two underlying terms and is defined for a goal being a relation between these two terms. |
1094 two underlying terms taking respectfulness theorems into account. |
1085 |
1095 |
1086 \begin{itemize} |
1096 %\begin{itemize} |
1087 \item For two constants an appropriate respectfulness theorem is applied. |
1097 %\item For two constants an appropriate respectfulness theorem is applied. |
1088 \item For two variables, we use the assumptions proved in the regularization step. |
1098 %\item For two variables, we use the assumptions proved in the regularization step. |
1089 \item For two abstractions, we @{text "\<eta>"}-expand and @{text "\<beta>"}-reduce them. |
1099 %\item For two abstractions, we @{text "\<eta>"}-expand and @{text "\<beta>"}-reduce them. |
1090 \item For two applications, we check that the right-hand side is an application of |
1100 %\item For two applications, we check that the right-hand side is an application of |
1091 @{term Rep} to an @{term Abs} and @{term "Quotient R Rep Abs"} holds. If yes then we |
1101 % @{term Rep} to an @{term Abs} and @{term "Quotient R Rep Abs"} holds. If yes then we |
1092 can apply the theorem: |
1102 % can apply the theorem: |
1093 |
1103 |
1094 \begin{isabelle}\ \ \ \ \ %%% |
1104 %\begin{isabelle}\ \ \ \ \ %%% |
1095 @{term "R x y \<longrightarrow> R x (Rep (Abs y))"} |
1105 % @{term "R x y \<longrightarrow> R x (Rep (Abs y))"} |
1096 \end{isabelle} |
1106 %\end{isabelle} |
1097 |
1107 |
1098 Otherwise we introduce an appropriate relation between the subterms |
1108 % Otherwise we introduce an appropriate relation between the subterms |
1099 and continue with two subgoals using the lemma: |
1109 % and continue with two subgoals using the lemma: |
1100 |
1110 |
1101 \begin{isabelle}\ \ \ \ \ %%% |
1111 %\begin{isabelle}\ \ \ \ \ %%% |
1102 @{text "(R\<^isub>1 \<doublearr> R\<^isub>2) f g \<longrightarrow> R\<^isub>1 x y \<longrightarrow> R\<^isub>2 (f x) (g y)"} |
1112 % @{text "(R\<^isub>1 \<doublearr> R\<^isub>2) f g \<longrightarrow> R\<^isub>1 x y \<longrightarrow> R\<^isub>2 (f x) (g y)"} |
1103 \end{isabelle} |
1113 %\end{isabelle} |
1104 \end{itemize} |
1114 %\end{itemize} |
1105 |
1115 |
1106 We defined the theorem @{text "inj_thm"} in such a way that |
1116 We defined the theorem @{text "inj_thm"} in such a way that |
1107 establishing the equivalence @{text "inj_thm \<longleftrightarrow> quot_thm"} can be |
1117 establishing in the third phase the equivalence @{text "inj_thm \<longleftrightarrow> quot_thm"} can be |
1108 achieved by rewriting @{text "inj_thm"} with the preservation theorems and quotient |
1118 achieved by rewriting @{text "inj_thm"} with the preservation theorems and quotient |
1109 definitions. First the definitions of all lifted constants |
1119 definitions. This step also requires that the definitions of all lifted constants |
1110 are used to fold the @{term Rep} with the raw constants. Next for |
1120 are used to fold the @{term Rep} with the raw constants. We will give more details |
1111 all abstractions and quantifiers the lambda and |
1121 about our lifting procedure in a longer version of this paper. |
1112 quantifier preservation theorems are used to replace the |
1122 |
1113 variables that include raw types with respects by quantifiers |
1123 %Next for |
1114 over variables that include quotient types. We show here only |
1124 %all abstractions and quantifiers the lambda and |
1115 the lambda preservation theorem. Given |
1125 %quantifier preservation theorems are used to replace the |
1116 @{term "Quotient R\<^isub>1 Abs\<^isub>1 Rep\<^isub>1"} and @{term "Quotient R\<^isub>2 Abs\<^isub>2 Rep\<^isub>2"}, we have: |
1126 %variables that include raw types with respects by quantifiers |
1117 |
1127 %over variables that include quotient types. We show here only |
1118 \begin{isabelle}\ \ \ \ \ %%% |
1128 %the lambda preservation theorem. Given |
1119 @{thm (concl) lambda_prs[of _ "Abs\<^isub>1" "Rep\<^isub>1" _ "Abs\<^isub>2" "Rep\<^isub>2", no_vars]} |
1129 %@{term "Quotient R\<^isub>1 Abs\<^isub>1 Rep\<^isub>1"} and @{term "Quotient R\<^isub>2 Abs\<^isub>2 Rep\<^isub>2"}, we have: |
1120 \end{isabelle} |
1130 |
1121 |
1131 %\begin{isabelle}\ \ \ \ \ %%% |
1122 \noindent |
1132 %@{thm (concl) lambda_prs[of _ "Abs\<^isub>1" "Rep\<^isub>1" _ "Abs\<^isub>2" "Rep\<^isub>2", no_vars]} |
1123 Next, relations over lifted types can be rewritten to equalities |
1133 %\end{isabelle} |
1124 over lifted type. Rewriting is performed with the following theorem, |
1134 |
1125 which has been shown by Homeier~\cite{Homeier05}: |
1135 %\noindent |
1126 |
1136 %Next, relations over lifted types can be rewritten to equalities |
1127 \begin{isabelle}\ \ \ \ \ %%% |
1137 %over lifted type. Rewriting is performed with the following theorem, |
1128 @{thm (concl) Quotient_rel_rep[no_vars]} |
1138 %which has been shown by Homeier~\cite{Homeier05}: |
1129 \end{isabelle} |
1139 |
1130 |
1140 %\begin{isabelle}\ \ \ \ \ %%% |
1131 \noindent |
1141 %@{thm (concl) Quotient_rel_rep[no_vars]} |
1132 Finally, we rewrite with the preservation theorems. This will result |
1142 %\end{isabelle} |
1133 in two equal terms that can be solved by reflexivity. |
1143 |
1134 *} |
1144 |
|
1145 %Finally, we rewrite with the preservation theorems. This will result |
|
1146 %in two equal terms that can be solved by reflexivity. |
|
1147 *} |
1135 |
1148 |
1136 |
1149 |
1137 section {* Examples \label{sec:examples} *} |
1150 section {* Examples \label{sec:examples} *} |
1138 |
1151 |
1139 text {* |
1152 text {* |
1140 |
1153 |
1141 %%% FIXME Reviewer 1 would like an example of regularized and injected |
1154 %%% FIXME Reviewer 1 would like an example of regularized and injected |
1142 %%% statements. He asks for the examples twice, but I would still ignore |
1155 %%% statements. He asks for the examples twice, but I would still ignore |
1143 %%% it due to lack of space... |
1156 %%% it due to lack of space... |
1144 |
1157 |
|
1158 \noindent |
1145 In this section we will show a sequence of declarations for defining the |
1159 In this section we will show a sequence of declarations for defining the |
1146 type of integers by quotienting pairs of natural numbers, and |
1160 type of integers by quotienting pairs of natural numbers, and |
1147 lifting one theorem. |
1161 lifting one theorem. |
1148 |
1162 |
1149 A user of our quotient package first needs to define a relation on |
1163 A user of our quotient package first needs to define a relation on |