2208
|
1 |
(* How to change the notation for \<lbrakk> \<rbrakk> meta-level implications? *)
|
2195
|
2 |
|
1975
b1281a0051ae
added stub for quotient paper; call with isabelle make qpaper
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
3 |
(*<*)
|
b1281a0051ae
added stub for quotient paper; call with isabelle make qpaper
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
4 |
theory Paper
|
2183
|
5 |
imports "Quotient"
|
1975
b1281a0051ae
added stub for quotient paper; call with isabelle make qpaper
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
6 |
"LaTeXsugar"
|
2186
|
7 |
"../Nominal/FSet"
|
1975
b1281a0051ae
added stub for quotient paper; call with isabelle make qpaper
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
8 |
begin
|
1994
|
9 |
|
|
10 |
notation (latex output)
|
2217
|
11 |
rel_conj ("_ OOO _" [53, 53] 52) and
|
|
12 |
"op -->" (infix "\<rightarrow>" 100) and
|
|
13 |
"==>" (infix "\<Rightarrow>" 100) and
|
2227
|
14 |
fun_map ("_ \<^raw:\mbox{\singlearr}> _" 51) and
|
|
15 |
fun_rel ("_ \<^raw:\mbox{\doublearr}> _" 51) and
|
2217
|
16 |
list_eq (infix "\<approx>" 50) and (* Not sure if we want this notation...? *)
|
2223
|
17 |
fempty ("\<emptyset>") and
|
|
18 |
funion ("_ \<union> _") and
|
|
19 |
finsert ("{_} \<union> _") and
|
2221
|
20 |
Cons ("_::_") and
|
|
21 |
concat ("flat") and
|
2223
|
22 |
fconcat ("\<Union>")
|
2220
|
23 |
|
2217
|
24 |
|
1994
|
25 |
|
2182
|
26 |
ML {*
|
|
27 |
fun nth_conj n (_, r) = nth (HOLogic.dest_conj r) n;
|
|
28 |
fun style_lhs_rhs proj = Scan.succeed (fn ctxt => fn t =>
|
|
29 |
let
|
|
30 |
val concl =
|
|
31 |
Object_Logic.drop_judgment (ProofContext.theory_of ctxt) (Logic.strip_imp_concl t)
|
|
32 |
in
|
|
33 |
case concl of (_ $ l $ r) => proj (l, r)
|
|
34 |
| _ => error ("Binary operator expected in term: " ^ Syntax.string_of_term ctxt concl)
|
|
35 |
end);
|
|
36 |
*}
|
|
37 |
setup {*
|
|
38 |
Term_Style.setup "rhs1" (style_lhs_rhs (nth_conj 0)) #>
|
|
39 |
Term_Style.setup "rhs2" (style_lhs_rhs (nth_conj 1)) #>
|
|
40 |
Term_Style.setup "rhs3" (style_lhs_rhs (nth_conj 2))
|
|
41 |
*}
|
1975
b1281a0051ae
added stub for quotient paper; call with isabelle make qpaper
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
42 |
(*>*)
|
b1281a0051ae
added stub for quotient paper; call with isabelle make qpaper
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
43 |
|
2227
|
44 |
|
1975
b1281a0051ae
added stub for quotient paper; call with isabelle make qpaper
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
45 |
section {* Introduction *}
|
b1281a0051ae
added stub for quotient paper; call with isabelle make qpaper
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
46 |
|
2102
200954544cae
added some of the quotient literature; a bit more to the qpaper
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
47 |
text {*
|
2205
|
48 |
\begin{flushright}
|
|
49 |
{\em ``Not using a [quotient] package has its advantages: we do not have to\\
|
|
50 |
collect all the theorems we shall ever want into one giant list;''}\\
|
2213
|
51 |
Larry Paulson \cite{Paulson06}
|
2237
|
52 |
\end{flushright}
|
2103
|
53 |
|
|
54 |
\noindent
|
2220
|
55 |
Isabelle is a popular generic theorem prover in which many logics can be
|
2214
|
56 |
implemented. The most widely used one, however, is Higher-Order Logic
|
|
57 |
(HOL). This logic consists of a small number of axioms and inference rules
|
|
58 |
over a simply-typed term-language. Safe reasoning in HOL is ensured by two
|
|
59 |
very restricted mechanisms for extending the logic: one is the definition of
|
|
60 |
new constants in terms of existing ones; the other is the introduction of
|
|
61 |
new types by identifying non-empty subsets in existing types. It is well
|
2223
|
62 |
understood how to use both mechanisms for dealing with quotient
|
2220
|
63 |
constructions in HOL (see \cite{Homeier05,Paulson06}). For example the
|
|
64 |
integers in Isabelle/HOL are constructed by a quotient construction over the
|
|
65 |
type @{typ "nat \<times> nat"} and the equivalence relation
|
2102
200954544cae
added some of the quotient literature; a bit more to the qpaper
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
66 |
|
2237
|
67 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
68 |
@{text "(n\<^isub>1, n\<^isub>2) \<approx> (m\<^isub>1, m\<^isub>2) \<equiv> n\<^isub>1 + m\<^isub>2 = m\<^isub>1 + n\<^isub>2"}\hfill\numbered{natpairequiv}
|
|
69 |
\end{isabelle}
|
2102
200954544cae
added some of the quotient literature; a bit more to the qpaper
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
70 |
|
200954544cae
added some of the quotient literature; a bit more to the qpaper
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
71 |
\noindent
|
2217
|
72 |
This constructions yields the new type @{typ int} and definitions for @{text
|
2220
|
73 |
"0"} and @{text "1"} of type @{typ int} can be given in terms of pairs of
|
|
74 |
natural numbers (namely @{text "(0, 0)"} and @{text "(1, 0)"}). Operations
|
|
75 |
such as @{text "add"} with type @{typ "int \<Rightarrow> int \<Rightarrow> int"} can be defined in
|
|
76 |
terms of operations on pairs of natural numbers (namely @{text
|
2224
|
77 |
"add_pair (n\<^isub>1, m\<^isub>1) (n\<^isub>2,
|
2222
|
78 |
m\<^isub>2) \<equiv> (n\<^isub>1 + n\<^isub>2, m\<^isub>1 + m\<^isub>2)"}).
|
|
79 |
Similarly one can construct the type of finite sets, written @{term "\<alpha> fset"},
|
2223
|
80 |
by quotienting the type @{text "\<alpha> list"} according to the equivalence relation
|
2103
|
81 |
|
2237
|
82 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
83 |
@{text "xs \<approx> ys \<equiv> (\<forall>x. memb x xs \<longleftrightarrow> memb x ys)"}\hfill\numbered{listequiv}
|
|
84 |
\end{isabelle}
|
2103
|
85 |
|
|
86 |
\noindent
|
2224
|
87 |
which states that two lists are equivalent if every element in one list is
|
|
88 |
also member in the other. The empty finite set, written @{term "{||}"}, can
|
|
89 |
then be defined as the empty list and the union of two finite sets, written
|
|
90 |
@{text "\<union>"}, as list append.
|
2220
|
91 |
|
|
92 |
An area where quotients are ubiquitous is reasoning about programming language
|
2226
|
93 |
calculi. A simple example is the lambda-calculus, whose raw terms are defined as
|
2220
|
94 |
|
|
95 |
@{text [display, indent=10] "t ::= x | t t | \<lambda>x.t"}
|
2217
|
96 |
|
2220
|
97 |
\noindent
|
2222
|
98 |
The problem with this definition arises when one attempts to
|
|
99 |
prove formally, for example, the substitution lemma \cite{Barendregt81} by induction
|
|
100 |
over the structure of terms. This can be fiendishly complicated (see
|
2220
|
101 |
\cite[Pages 94--104]{CurryFeys58} for some ``rough'' sketches of a proof
|
2226
|
102 |
about raw lambda-terms). In contrast, if we reason about
|
2220
|
103 |
$\alpha$-equated lambda-terms, that means terms quotient according to
|
2223
|
104 |
$\alpha$-equivalence, then the reasoning infrastructure provided,
|
|
105 |
for example, by Nominal Isabelle \cite{UrbanKaliszyk11} makes the formal
|
2222
|
106 |
proof of the substitution lemma almost trivial.
|
2220
|
107 |
|
|
108 |
The difficulty is that in order to be able to reason about integers, finite
|
2221
|
109 |
sets or $\alpha$-equated lambda-terms one needs to establish a reasoning
|
2220
|
110 |
infrastructure by transferring, or \emph{lifting}, definitions and theorems
|
2226
|
111 |
from the raw type @{typ "nat \<times> nat"} to the quotient type @{typ int}
|
2220
|
112 |
(similarly for finite sets and $\alpha$-equated lambda-terms). This lifting
|
2222
|
113 |
usually requires a \emph{lot} of tedious reasoning effort \cite{Paulson06}.
|
2223
|
114 |
It is feasible to to this work manually, if one has only a few quotient
|
|
115 |
constructions at hand. But if they have to be done over and over again as in
|
2222
|
116 |
Nominal Isabelle, then manual reasoning is not an option.
|
2221
|
117 |
|
2223
|
118 |
The purpose of a \emph{quotient package} is to ease the lifting of theorems
|
|
119 |
and automate the definitions and reasoning as much as possible. In the
|
|
120 |
context of HOL, there have been a few quotient packages already
|
2234
|
121 |
\cite{harrison-thesis,Slotosch97}. The most notable one is by Homeier
|
2223
|
122 |
\cite{Homeier05} implemented in HOL4. The fundamental construction these
|
|
123 |
quotient packages perform can be illustrated by the following picture:
|
2217
|
124 |
|
|
125 |
\begin{center}
|
2220
|
126 |
\mbox{}\hspace{20mm}\begin{tikzpicture}
|
|
127 |
%%\draw[step=2mm] (-4,-1) grid (4,1);
|
|
128 |
|
|
129 |
\draw[very thick] (0.7,0.3) circle (4.85mm);
|
|
130 |
\draw[rounded corners=1mm, very thick] ( 0.0,-0.9) rectangle ( 1.8, 0.9);
|
|
131 |
\draw[rounded corners=1mm, very thick] (-1.95,0.8) rectangle (-2.9,-0.195);
|
|
132 |
|
|
133 |
\draw (-2.0, 0.8) -- (0.7,0.8);
|
|
134 |
\draw (-2.0,-0.195) -- (0.7,-0.195);
|
2103
|
135 |
|
2220
|
136 |
\draw ( 0.7, 0.23) node {\begin{tabular}{@ {}c@ {}}equiv-\\[-1mm]clas.\end{tabular}};
|
|
137 |
\draw (-2.45, 0.35) node {\begin{tabular}{@ {}c@ {}}new\\[-1mm]type\end{tabular}};
|
|
138 |
\draw (1.8, 0.35) node[right=-0.1mm]
|
2224
|
139 |
{\begin{tabular}{@ {}l@ {}}existing\\[-1mm] type\\ (sets of raw elements)\end{tabular}};
|
2220
|
140 |
\draw (0.9, -0.55) node {\begin{tabular}{@ {}l@ {}}non-empty\\[-1mm]subset\end{tabular}};
|
|
141 |
|
|
142 |
\draw[->, very thick] (-1.8, 0.36) -- (-0.1,0.36);
|
|
143 |
\draw[<-, very thick] (-1.8, 0.16) -- (-0.1,0.16);
|
2221
|
144 |
\draw (-0.95, 0.26) node[above=0.4mm] {@{text Rep}};
|
|
145 |
\draw (-0.95, 0.26) node[below=0.4mm] {@{text Abs}};
|
2220
|
146 |
|
|
147 |
\end{tikzpicture}
|
|
148 |
\end{center}
|
2217
|
149 |
|
2221
|
150 |
\noindent
|
2234
|
151 |
The starting point is an existing type, often referred to as the \emph{raw
|
2237
|
152 |
type}, over which an equivalence relation given by the user is defined. With
|
|
153 |
this input the package introduces a new type, to which we refer as the
|
|
154 |
\emph{quotient type}. This type comes with an \emph{abstraction} and a
|
|
155 |
\emph{representation} function, written @{text Abs} and @{text
|
|
156 |
Rep}.\footnote{Actually slightly more basic functions are given; the @{text Abs}
|
|
157 |
and @{text Rep} need to be derived from them. We will show the details
|
|
158 |
later. } These functions relate elements in the existing type to ones in the
|
|
159 |
new type and vice versa; they can be uniquely identified by their type. For
|
|
160 |
example for the integer quotient construction the types of @{text Abs} and
|
|
161 |
@{text Rep} are
|
2224
|
162 |
|
|
163 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
2234
|
164 |
@{text "Abs :: nat \<times> nat \<Rightarrow> int"}\hspace{10mm}@{text "Rep :: int \<Rightarrow> nat \<times> nat"}
|
2224
|
165 |
\end{isabelle}
|
|
166 |
|
|
167 |
\noindent
|
|
168 |
However we often leave this typing information implicit for better
|
2232
|
169 |
readability, but sometimes write @{text Abs_int} and @{text Rep_int} if the
|
|
170 |
typing information is important. Every abstraction and representation
|
|
171 |
function stands for an isomorphism between the non-empty subset and elements
|
|
172 |
in the new type. They are necessary for making definitions involving the new
|
|
173 |
type. For example @{text "0"} and @{text "1"} of type @{typ int} can be
|
|
174 |
defined as
|
2221
|
175 |
|
|
176 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
177 |
@{text "0 \<equiv> Abs (0, 0)"}\hspace{10mm}@{text "1 \<equiv> Abs (1, 0)"}
|
|
178 |
\end{isabelle}
|
|
179 |
|
|
180 |
\noindent
|
2224
|
181 |
Slightly more complicated is the definition of @{text "add"} having type
|
2222
|
182 |
@{typ "int \<Rightarrow> int \<Rightarrow> int"}. Its definition is as follows
|
2221
|
183 |
|
2224
|
184 |
@{text [display, indent=10] "add n m \<equiv> Abs (add_pair (Rep n) (Rep m))"}
|
2221
|
185 |
|
|
186 |
\noindent
|
2224
|
187 |
where we take the representation of the arguments @{text n} and @{text m},
|
2226
|
188 |
add them according to the function @{text "add_pair"} and then take the
|
2221
|
189 |
abstraction of the result. This is all straightforward and the existing
|
|
190 |
quotient packages can deal with such definitions. But what is surprising
|
2223
|
191 |
that none of them can deal with slightly more complicated definitions involving
|
2221
|
192 |
\emph{compositions} of quotients. Such compositions are needed for example
|
2226
|
193 |
in case of quotienting lists to obtain finite sets and the operator that
|
|
194 |
flattens lists of lists, defined as follows
|
2102
200954544cae
added some of the quotient literature; a bit more to the qpaper
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
195 |
|
2220
|
196 |
@{thm [display, indent=10] concat.simps(1) concat.simps(2)[no_vars]}
|
2183
|
197 |
|
2103
|
198 |
\noindent
|
2221
|
199 |
We expect that the corresponding operator on finite sets, written @{term "fconcat"},
|
2234
|
200 |
builds the union of finite sets of finite sets:
|
2188
|
201 |
|
2220
|
202 |
@{thm [display, indent=10] fconcat_empty[no_vars] fconcat_insert[no_vars]}
|
2102
200954544cae
added some of the quotient literature; a bit more to the qpaper
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
203 |
|
2103
|
204 |
\noindent
|
2223
|
205 |
The quotient package should provide us with a definition for @{text "\<Union>"} in
|
2224
|
206 |
terms of @{text flat}, @{text Rep} and @{text Abs} (the latter two having
|
|
207 |
the type @{text "\<alpha> fset \<Rightarrow> \<alpha> list"} and @{text "\<alpha> list \<Rightarrow> \<alpha> fset"},
|
2226
|
208 |
respectively). The problem is that the method used in the existing quotient
|
2224
|
209 |
packages of just taking the representation of the arguments and then take
|
|
210 |
the abstraction of the result is \emph{not} enough. The reason is that case in case
|
|
211 |
of @{text "\<Union>"} we obtain the incorrect definition
|
|
212 |
|
2234
|
213 |
@{text [display, indent=10] "\<Union> S \<equiv> Abs_fset (flat (Rep_fset S))"}
|
2221
|
214 |
|
2224
|
215 |
\noindent
|
|
216 |
where the right-hand side is not even typable! This problem can be remedied in the
|
|
217 |
existing quotient packages by introducing an intermediate step and reasoning
|
2226
|
218 |
about flattening of lists of finite sets. However, this remedy is rather
|
2224
|
219 |
cumbersome and inelegant in light of our work, which can deal with such
|
|
220 |
definitions directly. The solution is that we need to build aggregate
|
|
221 |
representation and abstraction functions, which in case of @{text "\<Union>"}
|
|
222 |
generate the following definition
|
|
223 |
|
2234
|
224 |
@{text [display, indent=10] "\<Union> S \<equiv> Abs_fset (flat ((map Rep_fset \<circ> Rep_fset) S))"}
|
2221
|
225 |
|
|
226 |
\noindent
|
2223
|
227 |
where @{term map} is the usual mapping function for lists. In this paper we
|
2224
|
228 |
will present a formal definition of our aggregate abstraction and
|
2223
|
229 |
representation functions (this definition was omitted in \cite{Homeier05}).
|
2224
|
230 |
They generate definitions, like the one above for @{text "\<Union>"},
|
2226
|
231 |
according to the type of the raw constant and the type
|
2224
|
232 |
of the quotient constant. This means we also have to extend the notions
|
2237
|
233 |
of \emph{aggregate equivalence relation}, \emph{respectfulness} and \emph{preservation}
|
2231
|
234 |
from Homeier \cite{Homeier05}.
|
2223
|
235 |
|
2237
|
236 |
We are also able to address the criticism by Paulson \cite{Paulson06} cited
|
|
237 |
at the beginning of this section about having to collect theorems that are
|
|
238 |
lifted from the raw level to the quotient level. Our quotient package is the
|
|
239 |
first one that is modular so that it allows to lift single theorems
|
|
240 |
separately. This has the advantage for the user to develop a formal theory
|
|
241 |
interactively an a natural progression. A pleasing result of the modularity
|
|
242 |
is also that we are able to clearly specify what needs to be done in the
|
|
243 |
lifting process (this was only hinted at in \cite{Homeier05} and implemented
|
|
244 |
as a ``rough recipe'' in ML-code).
|
|
245 |
|
|
246 |
The paper is organised as follows: Section \ref{sec:prelims} presents briefly
|
|
247 |
some necessary preliminaries; Section \ref{sec:type} presents the definitions
|
|
248 |
of quotient types and shows how definitions can be made over quotient types. \ldots
|
2102
200954544cae
added some of the quotient literature; a bit more to the qpaper
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
249 |
*}
|
1975
b1281a0051ae
added stub for quotient paper; call with isabelle make qpaper
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
250 |
|
b1281a0051ae
added stub for quotient paper; call with isabelle make qpaper
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
251 |
|
2224
|
252 |
section {* Preliminaries and General Quotient\label{sec:prelims} *}
|
1978
|
253 |
|
|
254 |
text {*
|
2182
|
255 |
In this section we present the definitions of a quotient that follow
|
|
256 |
those by Homeier, the proofs can be found there.
|
|
257 |
|
|
258 |
\begin{definition}[Quotient]
|
|
259 |
A relation $R$ with an abstraction function $Abs$
|
|
260 |
and a representation function $Rep$ is a \emph{quotient}
|
|
261 |
if and only if:
|
1978
|
262 |
|
2182
|
263 |
\begin{enumerate}
|
|
264 |
\item @{thm (rhs1) Quotient_def[of "R", no_vars]}
|
|
265 |
\item @{thm (rhs2) Quotient_def[of "R", no_vars]}
|
|
266 |
\item @{thm (rhs3) Quotient_def[of "R", no_vars]}
|
|
267 |
\end{enumerate}
|
|
268 |
|
|
269 |
\end{definition}
|
1978
|
270 |
|
2188
|
271 |
\begin{definition}[Relation map and function map]\\
|
2190
|
272 |
@{thm fun_rel_def[of "R1" "R2", no_vars]}\\
|
2182
|
273 |
@{thm fun_map_def[no_vars]}
|
|
274 |
\end{definition}
|
|
275 |
|
|
276 |
The main theorems for building higher order quotients is:
|
|
277 |
\begin{lemma}[Function Quotient]
|
|
278 |
If @{thm (prem 1) fun_quotient[no_vars]} and @{thm (prem 2) fun_quotient[no_vars]}
|
|
279 |
then @{thm (concl) fun_quotient[no_vars]}
|
|
280 |
\end{lemma}
|
|
281 |
|
1978
|
282 |
*}
|
|
283 |
|
2195
|
284 |
subsection {* Higher Order Logic *}
|
|
285 |
|
|
286 |
text {*
|
|
287 |
|
|
288 |
Types:
|
|
289 |
\begin{eqnarray}\nonumber
|
|
290 |
@{text "\<sigma> ::="} & @{text "\<alpha>"} & \textrm{(type variable)} \\ \nonumber
|
|
291 |
@{text "|"} & @{text "(\<sigma>,\<dots>,\<sigma>)\<kappa>"} & \textrm{(type construction)}
|
|
292 |
\end{eqnarray}
|
|
293 |
|
|
294 |
Terms:
|
|
295 |
\begin{eqnarray}\nonumber
|
|
296 |
@{text "t ::="} & @{text "x\<^isup>\<sigma>"} & \textrm{(variable)} \\ \nonumber
|
|
297 |
@{text "|"} & @{text "c\<^isup>\<sigma>"} & \textrm{(constant)} \\ \nonumber
|
|
298 |
@{text "|"} & @{text "t t"} & \textrm{(application)} \\ \nonumber
|
|
299 |
@{text "|"} & @{text "\<lambda>x\<^isup>\<sigma>. t"} & \textrm{(abstraction)} \\ \nonumber
|
|
300 |
\end{eqnarray}
|
|
301 |
|
2234
|
302 |
{\it Say more about containers / maping functions }
|
|
303 |
|
2237
|
304 |
Such maps for most common types (list, pair, sum,
|
|
305 |
option, \ldots) are described in Homeier, and we assume that @{text "map"}
|
|
306 |
is the function that returns a map for a given type.
|
|
307 |
|
2195
|
308 |
*}
|
|
309 |
|
2237
|
310 |
section {* Quotient Types and Quotient Definitions\label{sec:type} *}
|
1978
|
311 |
|
2234
|
312 |
text {*
|
|
313 |
The first step in a quotient constructions is to take a name for the new
|
|
314 |
type, say @{text "\<kappa>\<^isub>q"}, and an equivalence relation defined over a
|
|
315 |
raw type, say @{text "\<sigma>"}. The equivalence relation for the quotient
|
|
316 |
construction, lets say @{text "R"}, must then be of type @{text "\<sigma> \<Rightarrow> \<sigma> \<Rightarrow>
|
2235
|
317 |
bool"}. The user-visible part of the declaration is therefore
|
2234
|
318 |
|
2235
|
319 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
320 |
\isacommand{quotient\_type}~~@{text "\<alpha>s \<kappa>\<^isub>q = \<sigma> / R"}
|
|
321 |
\end{isabelle}
|
|
322 |
|
|
323 |
\noindent
|
2237
|
324 |
and a proof that @{text "R"} is indeed an equivalence relation. Two concrete
|
|
325 |
examples are
|
|
326 |
|
|
327 |
|
|
328 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
329 |
\begin{tabular}{@ {}l}
|
|
330 |
\isacommand{quotient\_type}~~@{text "int = nat \<times> nat / \<approx>\<^bsub>nat \<times> nat\<^esub>"}\\
|
|
331 |
\isacommand{quotient\_type}~~@{text "\<alpha> fset = \<alpha> list / \<approx>\<^bsub>list\<^esub>"}
|
|
332 |
\end{tabular}
|
|
333 |
\end{isabelle}
|
|
334 |
|
|
335 |
\noindent
|
|
336 |
which introduce the type of integers and of finite sets using the
|
|
337 |
equivalence relations @{text "\<approx>\<^bsub>nat \<times> nat\<^esub>"} and @{text
|
|
338 |
"\<approx>\<^bsub>list\<^esub>"} defined earlier in \eqref{natpairequiv} and
|
|
339 |
\eqref{listequiv}, respectively. Given this data, we declare internally
|
|
340 |
the quotient types as
|
2234
|
341 |
|
|
342 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
343 |
\isacommand{typedef}~~@{text "\<alpha>s \<kappa>\<^isub>q = {c. \<exists>x. c = R x}"}
|
|
344 |
\end{isabelle}
|
|
345 |
|
|
346 |
\noindent
|
2237
|
347 |
where the right hand side is the (non-empty) set of equivalence classes of
|
|
348 |
@{text "R"}. The restriction in this declaration is that the type variables
|
|
349 |
in the raw type @{text "\<sigma>"} must be included in the type variables @{text
|
|
350 |
"\<alpha>s"} declared for @{text "\<kappa>\<^isub>q"}. HOL will provide us with
|
|
351 |
abstraction and representation functions having the type
|
2182
|
352 |
|
2234
|
353 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
354 |
@{text "abs_\<kappa>\<^isub>q :: \<sigma> set \<Rightarrow> \<alpha>s \<kappa>\<^isub>q"}\hspace{10mm}@{text "rep_\<kappa>\<^isub>q :: \<alpha>s \<kappa>\<^isub>q \<Rightarrow> \<sigma> set"}
|
|
355 |
\end{isabelle}
|
|
356 |
|
2235
|
357 |
\noindent
|
|
358 |
and relating the new quotient type and equivalence classes of the raw
|
|
359 |
type. However, as Homeier \cite{Homeier05} noted, it is much more convenient
|
|
360 |
to work with the following derived abstraction and representation functions
|
|
361 |
|
2234
|
362 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
363 |
@{text "Abs_\<kappa>\<^isub>q x \<equiv> abs_\<kappa>\<^isub>q (R x)"}\hspace{10mm}@{text "Rep_\<kappa>\<^isub>q x \<equiv> \<epsilon> (rep_\<kappa>\<^isub>q x)"}
|
|
364 |
\end{isabelle}
|
|
365 |
|
|
366 |
\noindent
|
2235
|
367 |
on the expense of having to use Hilbert's choice operator @{text "\<epsilon>"} in the
|
2237
|
368 |
definition of @{text "Rep_\<kappa>\<^isub>q"}. These derived notions relate the
|
|
369 |
quotient type and the raw type directly, as can be seen from their type,
|
|
370 |
namely @{text "\<sigma> \<Rightarrow> \<alpha>s \<kappa>\<^isub>q"} and @{text "\<alpha>s \<kappa>\<^isub>q \<Rightarrow> \<sigma>"},
|
|
371 |
respectively. Given that @{text "R"} is an equivalence relation, the
|
|
372 |
following property
|
|
373 |
|
2234
|
374 |
|
|
375 |
@{text [display, indent=10] "Quotient R Abs_\<kappa>\<^isub>q Rep_\<kappa>\<^isub>q"}
|
|
376 |
|
|
377 |
\noindent
|
|
378 |
holds (for the proof see \cite{Homeier05}).
|
2182
|
379 |
|
2237
|
380 |
The next step is to introduce new definitions involving the quotient type,
|
|
381 |
which need to be defined in terms of concepts of the raw type (remember this
|
|
382 |
is the only way how toe be able to extend HOL with new definitions). For the
|
|
383 |
user visible is the declaration
|
2235
|
384 |
|
|
385 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
2237
|
386 |
\isacommand{quotient\_definition}~~@{text "c :: \<tau>"}~~\isacommand{is}~~@{text "t :: \<sigma>"}
|
2235
|
387 |
\end{isabelle}
|
|
388 |
|
2237
|
389 |
\noindent
|
|
390 |
where @{text t} is the definiens (its type @{text \<sigma>} can always be inferred)
|
|
391 |
and @{text "c"} is the name of definiendum, whose type @{text "\<tau>"} needs to be
|
|
392 |
given explicitly (the point is that @{text "\<tau>"} and @{text "\<sigma>"} can only differ
|
|
393 |
in places where a quotient and raw type are involved). Two examples are
|
2188
|
394 |
|
2237
|
395 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
396 |
\begin{tabular}{@ {}l}
|
|
397 |
\isacommand{quotient\_definition}~~@{text "0 :: int"}~~\isacommand{is}~~@{text "(0::nat, 0::nat)"}\\
|
|
398 |
\isacommand{quotient\_definition}~~@{text "\<Union> :: (\<alpha> fset) fset \<Rightarrow> \<alpha> fset"}~~%
|
|
399 |
\isacommand{is}~~@{text "flat"}
|
|
400 |
\end{tabular}
|
|
401 |
\end{isabelle}
|
|
402 |
|
|
403 |
\noindent
|
|
404 |
The first one declares zero for integers and the second the operator for
|
|
405 |
building unions of finite sets. The problem for us is that from such
|
|
406 |
declarations we need to derive proper definitions using the @{text "Abs"}
|
|
407 |
and @{text "Rep"} functions for the quotient types involved. The data we
|
|
408 |
rely on is the given quotient type @{text "\<tau>"} and the raw type @{text "\<sigma>"}.
|
|
409 |
They allow us to define aggregate abstraction and representation functions
|
|
410 |
using the functions @{text "ABS (\<sigma>, \<tau>)"} and @{text "REP (\<sigma>, \<tau>)"} whose
|
|
411 |
clauses are given below. The idea behind them is to recursively descend into
|
|
412 |
both types and generate the appropriate @{text "Abs"} and @{text "Rep"}
|
|
413 |
in places where the types differ. Therefore we returning just the identity
|
|
414 |
whenever the types are equal.
|
2182
|
415 |
|
2227
|
416 |
\begin{center}
|
2234
|
417 |
\begin{longtable}{rcl}
|
2227
|
418 |
\multicolumn{3}{@ {\hspace{-4mm}}l}{equal types:}\\
|
|
419 |
@{text "ABS (\<sigma>, \<sigma>)"} & $\dn$ & @{text "id"}\\
|
|
420 |
@{text "REP (\<sigma>, \<sigma>)"} & $\dn$ & @{text "id"}\smallskip\\
|
|
421 |
\multicolumn{3}{@ {\hspace{-4mm}}l}{function types:}\\
|
2233
|
422 |
@{text "ABS (\<sigma>\<^isub>1 \<Rightarrow> \<sigma>\<^isub>2, \<tau>\<^isub>1 \<Rightarrow> \<tau>\<^isub>2)"} & $\dn$ & @{text "REP (\<sigma>\<^isub>1, \<tau>\<^isub>1) \<singlearr> ABS (\<sigma>\<^isub>2, \<tau>\<^isub>2)"}\\
|
|
423 |
@{text "REP (\<sigma>\<^isub>1 \<Rightarrow> \<sigma>\<^isub>2, \<tau>\<^isub>1 \<Rightarrow> \<tau>\<^isub>2)"} & $\dn$ & @{text "ABS (\<sigma>\<^isub>1, \<tau>\<^isub>1) \<singlearr> REP (\<sigma>\<^isub>2, \<tau>\<^isub>2)"}\smallskip\\
|
2227
|
424 |
\multicolumn{3}{@ {\hspace{-4mm}}l}{equal type constructors:}\\
|
2232
|
425 |
@{text "ABS (\<sigma>s \<kappa>, \<tau>s \<kappa>)"} & $\dn$ & @{text "map_\<kappa> (ABS (\<sigma>s, \<tau>s))"}\\
|
|
426 |
@{text "REP (\<sigma>s \<kappa>, \<tau>s \<kappa>)"} & $\dn$ & @{text "map_\<kappa> (REP (\<sigma>s, \<tau>s))"}\smallskip\\
|
2227
|
427 |
\multicolumn{3}{@ {\hspace{-4mm}}l}{unequal type constructors:}\\
|
2234
|
428 |
@{text "ABS (\<sigma>s \<kappa>, \<tau>s \<kappa>\<^isub>q)"} & $\dn$ & @{text "Abs_\<kappa>\<^isub>q \<circ> (MAP(\<rho>s \<kappa>) (ABS (\<sigma>s', \<tau>s')))"}\\
|
2237
|
429 |
@{text "REP (\<sigma>s \<kappa>, \<tau>s \<kappa>\<^isub>q)"} & $\dn$ & @{text "(MAP(\<rho>s \<kappa>) (REP (\<sigma>s', \<tau>s'))) \<circ> Rep_\<kappa>\<^isub>q"}
|
2234
|
430 |
\end{longtable}
|
2227
|
431 |
\end{center}
|
2234
|
432 |
%
|
2232
|
433 |
\noindent
|
2237
|
434 |
where in the last two clauses we have that the quotient type @{text "\<alpha>s
|
|
435 |
\<kappa>\<^isub>q"} is a quotient of the raw type @{text "\<rho>s \<kappa>"} (for example
|
|
436 |
@{text "int"} and @{text "nat \<times> nat"}, or @{text "\<alpha> fset"} and @{text "\<alpha>
|
|
437 |
list"}). The quotient construction ensures that the type variables in @{text
|
|
438 |
"\<rho>s"} must be amongst the @{text "\<alpha>s"}. The @{text "\<sigma>s'"} are given by the
|
|
439 |
matchers for the @{text "\<alpha>s"} when matching @{text "\<sigma>s \<kappa>\<^isub>q"} against
|
|
440 |
@{text "\<alpha>s \<kappa>\<^isub>q"}; similarly the @{text "\<tau>s'"} are given by the same
|
|
441 |
type-variables when matching @{text "\<tau>s \<kappa>"} against @{text "\<rho>s \<kappa>"}. The
|
|
442 |
function @{text "MAP"} calculates an \emph{aggregate map-function} for a raw
|
|
443 |
type as follows:
|
|
444 |
%
|
2227
|
445 |
\begin{center}
|
2237
|
446 |
\begin{longtable}{rcl}
|
|
447 |
@{text "MAP' (\<alpha>)"} & $\dn$ & @{text "a\<^sup>\<alpha>"}\\
|
2233
|
448 |
@{text "MAP' (\<kappa>)"} & $\dn$ & @{text "id"}\\
|
2232
|
449 |
@{text "MAP' (\<sigma>s \<kappa>)"} & $\dn$ & @{text "map_\<kappa> (MAP'(\<sigma>s))"}\smallskip\\
|
2233
|
450 |
@{text "MAP (\<sigma>)"} & $\dn$ & @{text "\<lambda>as. MAP'(\<sigma>)"}
|
2237
|
451 |
\end{longtable}
|
2227
|
452 |
\end{center}
|
2237
|
453 |
%
|
2232
|
454 |
\noindent
|
2233
|
455 |
In this definition we abuse the fact that we can interpret type-variables @{text \<alpha>} as
|
|
456 |
term variables @{text a}, and in the last clause build an abstraction over all
|
2232
|
457 |
term-variables inside the aggregate map-function generated by @{text "MAP'"}.
|
2237
|
458 |
This aggregate map-function is necessary if we build quotients, say @{text "(\<alpha>, \<beta>) \<kappa>\<^isub>q"},
|
2233
|
459 |
out of compound raw types, say @{text "(\<alpha> list) \<times> \<beta>"}. In this case @{text MAP}
|
|
460 |
generates the aggregate map-function:
|
2232
|
461 |
|
2233
|
462 |
@{text [display, indent=10] "\<lambda>a b. map_prod (map a) b"}
|
|
463 |
|
|
464 |
\noindent
|
|
465 |
Returning to our example about @{term "concat"} and @{term "fconcat"} which have the
|
|
466 |
types @{text "(\<alpha> list) list \<Rightarrow> \<alpha> list"} and @{text "(\<alpha> fset) fset \<Rightarrow> \<alpha> fset"}. Feeding this
|
|
467 |
into @{text ABS} gives us the abstraction function:
|
|
468 |
|
|
469 |
@{text [display, indent=10] "(map (map id \<circ> Rep_fset) \<circ> Rep_fset) \<singlearr> Abs_fset \<circ> map id"}
|
|
470 |
|
|
471 |
\noindent
|
2237
|
472 |
where we already performed some @{text "\<beta>"}-simplifications. In our
|
|
473 |
implementation we further simplify this by noticing the usual laws about
|
|
474 |
@{text "map"}s and @{text "id"}, namely @{term "map id = id"} and @{text "f
|
|
475 |
\<circ> id = id \<circ> f = f"}. This gives us the simplified abstraction function
|
|
476 |
|
2233
|
477 |
@{text [display, indent=10] "(map Rep_fset \<circ> Rep_fset) \<singlearr> Abs_fset"}
|
|
478 |
|
|
479 |
\noindent
|
|
480 |
which we can use for defining @{term "fconcat"} as follows
|
|
481 |
|
|
482 |
@{text [display, indent=10] "\<Union> \<equiv> ((map Rep_fset \<circ> Rep_fset) \<singlearr> Abs_fset) flat"}
|
2232
|
483 |
|
2237
|
484 |
\noindent
|
|
485 |
Note that by using the operator @{text "\<singlearr>"} we do not have to
|
|
486 |
distinguish between arguments and results: teh representation and abstraction
|
|
487 |
functions are just inverses which we can combine using @{text "\<singlearr>"}.
|
|
488 |
So all our definitions are of the general form
|
2188
|
489 |
|
2237
|
490 |
@{text [display, indent=10] "c \<equiv> ABS (\<sigma>, \<tau>) t"}
|
2227
|
491 |
|
2237
|
492 |
\noindent
|
|
493 |
where @{text \<sigma>} is the type of @{text "t"} and @{text "\<tau>"} the type of the
|
|
494 |
newly defined quotient constant @{text "c"}. To ensure we obtained a correct
|
|
495 |
definition, we can prove:
|
2227
|
496 |
|
|
497 |
\begin{lemma}
|
|
498 |
If @{text "ABS (\<sigma>, \<tau>)"} returns some abstraction function @{text "Abs"}
|
|
499 |
and @{text "REP (\<sigma>, \<tau>)"} some representation function @{text "Rep"},
|
|
500 |
then @{text "Abs"} is of type @{text "\<sigma> \<Rightarrow> \<tau>"} and @{text "Rep"} of type
|
|
501 |
@{text "\<tau> \<Rightarrow> \<sigma>"}.
|
|
502 |
\end{lemma}
|
2233
|
503 |
|
2237
|
504 |
\begin{proof}
|
|
505 |
By induction of the definitions of @{text "ABS"}, @{text "REP"} and @{text "MAP"}.
|
|
506 |
\end{proof}
|
|
507 |
|
|
508 |
\noindent
|
|
509 |
This lemma fails for the abstraction and representation functions used in,
|
|
510 |
for example, Homeier's quotient package.
|
2188
|
511 |
*}
|
|
512 |
|
|
513 |
subsection {* Respectfulness *}
|
|
514 |
|
|
515 |
text {*
|
|
516 |
|
|
517 |
A respectfulness lemma for a constant states that the equivalence
|
|
518 |
class returned by this constant depends only on the equivalence
|
2207
|
519 |
classes of the arguments applied to the constant. To automatically
|
|
520 |
lift a theorem that talks about a raw constant, to a theorem about
|
|
521 |
the quotient type a respectfulness theorem is required.
|
|
522 |
|
|
523 |
A respectfulness condition for a constant can be expressed in
|
|
524 |
terms of an aggregate relation between the constant and itself,
|
|
525 |
for example the respectfullness for @{term "append"}
|
2188
|
526 |
can be stated as:
|
|
527 |
|
2228
|
528 |
@{thm [display, indent=10] append_rsp[no_vars]}
|
2182
|
529 |
|
2190
|
530 |
\noindent
|
2228
|
531 |
Which after unfolding the definition of @{term "op ===>"} is equivalent to:
|
2188
|
532 |
|
2228
|
533 |
@{thm [display, indent=10] append_rsp_unfolded[no_vars]}
|
2188
|
534 |
|
2228
|
535 |
\noindent An aggregate relation is defined in terms of relation
|
|
536 |
composition, so we define it first:
|
2188
|
537 |
|
|
538 |
\begin{definition}[Composition of Relations]
|
2190
|
539 |
@{abbrev "rel_conj R1 R2"} where @{text OO} is the predicate
|
|
540 |
composition @{thm pred_compI[no_vars]}
|
2188
|
541 |
\end{definition}
|
|
542 |
|
2207
|
543 |
The aggregate relation for an aggregate raw type and quotient type
|
|
544 |
is defined as:
|
2188
|
545 |
|
|
546 |
\begin{itemize}
|
2207
|
547 |
\item @{text "REL(\<alpha>\<^isub>1, \<alpha>\<^isub>2)"} = @{text "op ="}
|
|
548 |
\item @{text "REL(\<sigma>, \<sigma>)"} = @{text "op ="}
|
|
549 |
\item @{text "REL((\<sigma>\<^isub>1,\<dots>,\<sigma>\<^isub>n))\<kappa>, (\<tau>\<^isub>1,\<dots>,\<tau>\<^isub>n))\<kappa>)"} = @{text "(rel \<kappa>) (REL(\<sigma>\<^isub>1,\<tau>\<^isub>1)) \<dots> (REL(\<sigma>\<^isub>n,\<tau>\<^isub>n))"}
|
|
550 |
\item @{text "REL((\<sigma>\<^isub>1,\<dots>,\<sigma>\<^isub>n))\<kappa>\<^isub>1, (\<tau>\<^isub>1,\<dots>,\<tau>\<^isub>m))\<kappa>\<^isub>2)"} = @{text "(rel \<kappa>\<^isub>1) (REL(\<rho>\<^isub>1,\<nu>\<^isub>1) \<dots> (REL(\<rho>\<^isub>p,\<nu>\<^isub>p) OOO Eqv_\<kappa>\<^isub>2"} provided @{text "\<eta> \<kappa>\<^isub>2 = (\<alpha>\<^isub>1\<dots>\<alpha>\<^isub>p)\<kappa>\<^isub>1 \<and> \<exists>s. s(\<sigma>s\<kappa>\<^isub>1)=\<rho>s\<kappa>\<^isub>1 \<and> s(\<tau>s\<kappa>\<^isub>2)=\<nu>s\<kappa>\<^isub>2"}
|
2189
|
551 |
|
2188
|
552 |
\end{itemize}
|
|
553 |
|
2207
|
554 |
Again, the last case is novel, so lets look at the example of
|
|
555 |
respectfullness for @{term concat}. The statement according to
|
|
556 |
the definition above is:
|
2190
|
557 |
|
2228
|
558 |
@{thm [display, indent=10] concat_rsp[no_vars]}
|
2189
|
559 |
|
2190
|
560 |
\noindent
|
|
561 |
By unfolding the definition of relation composition and relation map
|
|
562 |
we can see the equivalent statement just using the primitive list
|
|
563 |
equivalence relation:
|
|
564 |
|
2228
|
565 |
@{thm [display, indent=10] concat_rsp_unfolded[of "a" "a'" "b'" "b", no_vars]}
|
2189
|
566 |
|
2190
|
567 |
The statement reads that, for any lists of lists @{term a} and @{term b}
|
|
568 |
if there exist intermediate lists of lists @{term "a'"} and @{term "b'"}
|
|
569 |
such that each element of @{term a} is in the relation with an appropriate
|
|
570 |
element of @{term a'}, @{term a'} is in relation with @{term b'} and each
|
|
571 |
element of @{term b'} is in relation with the appropriate element of
|
|
572 |
@{term b}.
|
2189
|
573 |
|
|
574 |
*}
|
|
575 |
|
|
576 |
subsection {* Preservation *}
|
|
577 |
|
2190
|
578 |
text {*
|
2228
|
579 |
Sometimes a non-lifted polymorphic constant is instantiated to a
|
|
580 |
type being lifted. For example take the @{term "op #"} which inserts
|
|
581 |
an element in a list of pairs of natural numbers. When the theorem
|
|
582 |
is lifted, the pairs of natural numbers are to become integers, but
|
|
583 |
the head constant is still supposed to be the head constant, just
|
|
584 |
with a different type. To be able to lift such theorems
|
|
585 |
automatically, additional theorems provided by the user are
|
|
586 |
necessary, we call these \emph{preservation} theorems following
|
|
587 |
Homeier's naming.
|
2196
|
588 |
|
|
589 |
To lift theorems that talk about insertion in lists of lifted types
|
|
590 |
we need to know that for any quotient type with the abstraction and
|
|
591 |
representation functions @{text "Abs"} and @{text Rep} we have:
|
|
592 |
|
2228
|
593 |
@{thm [display, indent=10] (concl) cons_prs[no_vars]}
|
2196
|
594 |
|
|
595 |
This is not enough to lift theorems that talk about quotient compositions.
|
|
596 |
For some constants (for example empty list) it is possible to show a
|
|
597 |
general compositional theorem, but for @{term "op #"} it is necessary
|
|
598 |
to show that it respects the particular quotient type:
|
|
599 |
|
2228
|
600 |
@{thm [display, indent=10] insert_preserve2[no_vars]}
|
2190
|
601 |
*}
|
|
602 |
|
2191
|
603 |
subsection {* Composition of Quotient theorems *}
|
2189
|
604 |
|
2191
|
605 |
text {*
|
|
606 |
Given two quotients, one of which quotients a container, and the
|
|
607 |
other quotients the type in the container, we can write the
|
2193
|
608 |
composition of those quotients. To compose two quotient theorems
|
2207
|
609 |
we compose the relations with relation composition as defined above
|
|
610 |
and the abstraction and relation functions are the ones of the sub
|
|
611 |
quotients composed with the usual function composition.
|
|
612 |
The @{term "Rep"} and @{term "Abs"} functions that we obtain agree
|
|
613 |
with the definition of aggregate Abs/Rep functions and the
|
2193
|
614 |
relation is the same as the one given by aggregate relations.
|
|
615 |
This becomes especially interesting
|
2191
|
616 |
when we compose the quotient with itself, as there is no simple
|
|
617 |
intermediate step.
|
|
618 |
|
2193
|
619 |
Lets take again the example of @{term concat}. To be able to lift
|
2207
|
620 |
theorems that talk about it we provide the composition quotient
|
|
621 |
theorems, which then lets us perform the lifting procedure in an
|
|
622 |
unchanged way:
|
2188
|
623 |
|
2190
|
624 |
@{thm [display] quotient_compose_list[no_vars]}
|
2192
|
625 |
*}
|
|
626 |
|
2191
|
627 |
|
2227
|
628 |
section {* Lifting of Theorems *}
|
1978
|
629 |
|
2194
|
630 |
text {*
|
|
631 |
The core of the quotient package takes an original theorem that
|
|
632 |
talks about the raw types, and the statement of the theorem that
|
|
633 |
it is supposed to produce. This is different from other existing
|
2207
|
634 |
quotient packages, where only the raw theorems were necessary.
|
2194
|
635 |
We notice that in some cases only some occurrences of the raw
|
|
636 |
types need to be lifted. This is for example the case in the
|
|
637 |
new Nominal package, where a raw datatype that talks about
|
|
638 |
pairs of natural numbers or strings (being lists of characters)
|
|
639 |
should not be changed to a quotient datatype with constructors
|
|
640 |
taking integers or finite sets of characters. To simplify the
|
|
641 |
use of the quotient package we additionally provide an automated
|
|
642 |
statement translation mechanism that replaces occurrences of
|
|
643 |
types that match given quotients by appropriate lifted types.
|
|
644 |
|
|
645 |
Lifting the theorems is performed in three steps. In the following
|
|
646 |
we call these steps \emph{regularization}, \emph{injection} and
|
|
647 |
\emph{cleaning} following the names used in Homeier's HOL
|
2197
|
648 |
implementation.
|
2193
|
649 |
|
2197
|
650 |
We first define the statement of the regularized theorem based
|
|
651 |
on the original theorem and the goal theorem. Then we define
|
|
652 |
the statement of the injected theorem, based on the regularized
|
2208
|
653 |
theorem and the goal. We then show the 3 proofs, as all three
|
2197
|
654 |
can be performed independently from each other.
|
2193
|
655 |
|
2194
|
656 |
*}
|
1994
|
657 |
|
2197
|
658 |
subsection {* Regularization and Injection statements *}
|
1994
|
659 |
|
|
660 |
text {*
|
2197
|
661 |
|
2207
|
662 |
We first define the function @{text REG}, which takes the statements
|
|
663 |
of the raw theorem and the lifted theorem (both as terms) and
|
|
664 |
returns the statement of the regularized version. The intuition
|
|
665 |
behind this function is that it replaces quantifiers and
|
|
666 |
abstractions involving raw types by bounded ones, and equalities
|
|
667 |
involving raw types are replaced by appropriate aggregate
|
|
668 |
relations. It is defined as follows:
|
1994
|
669 |
|
2197
|
670 |
\begin{itemize}
|
2198
|
671 |
\item @{text "REG (\<lambda>x : \<sigma>. t, \<lambda>x : \<sigma>. s) = \<lambda>x : \<sigma>. REG (t, s)"}
|
|
672 |
\item @{text "REG (\<lambda>x : \<sigma>. t, \<lambda>x : \<tau>. s) = \<lambda>x : \<sigma> \<in> Res (REL (\<sigma>, \<tau>)). REG (t, s)"}
|
|
673 |
\item @{text "REG (\<forall>x : \<sigma>. t, \<forall>x : \<sigma>. s) = \<forall>x : \<sigma>. REG (t, s)"}
|
|
674 |
\item @{text "REG (\<forall>x : \<sigma>. t, \<forall>x : \<tau>. s) = \<forall>x : \<sigma> \<in> Res (REL (\<sigma>, \<tau>)). REG (t, s)"}
|
2197
|
675 |
\item @{text "REG ((op =) : \<sigma>, (op =) : \<sigma>) = (op =) : \<sigma>"}
|
|
676 |
\item @{text "REG ((op =) : \<sigma>, (op =) : \<tau>) = REL (\<sigma>, \<tau>) : \<sigma>"}
|
|
677 |
\item @{text "REG (t\<^isub>1 t\<^isub>2, s\<^isub>1 s\<^isub>2) = REG (t\<^isub>1, s\<^isub>1) REG (t\<^isub>2, s\<^isub>2)"}
|
2198
|
678 |
\item @{text "REG (v\<^isub>1, v\<^isub>2) = v\<^isub>1"}
|
|
679 |
\item @{text "REG (c\<^isub>1, c\<^isub>2) = c\<^isub>1"}
|
2197
|
680 |
\end{itemize}
|
1994
|
681 |
|
2230
|
682 |
In the above definition we omitted the cases for existential quantifiers
|
2207
|
683 |
and unique existential quantifiers, as they are very similar to the cases
|
|
684 |
for the universal quantifier.
|
2197
|
685 |
|
2207
|
686 |
Next we define the function @{text INJ} which takes the statement of
|
|
687 |
the regularized theorems and the statement of the lifted theorem both as
|
2230
|
688 |
terms and returns the statement of the injected theorem:
|
2198
|
689 |
|
|
690 |
\begin{itemize}
|
|
691 |
\item @{text "INJ ((\<lambda>x. t) : \<sigma>, (\<lambda>x. s) : \<sigma>) = \<lambda>x. (INJ (t, s)"}
|
|
692 |
\item @{text "INJ ((\<lambda>x. t) : \<sigma>, (\<lambda>x. s) : \<tau>) = REP(\<sigma>,\<tau>) (ABS (\<sigma>,\<tau>) (\<lambda>x. (INJ (t, s))))"}
|
|
693 |
\item @{text "INJ ((\<lambda>x \<in> R. t) : \<sigma>, (\<lambda>x. s) : \<tau>) = REP(\<sigma>,\<tau>) (ABS (\<sigma>,\<tau>) (\<lambda>x \<in> R. (INJ (t, s))))"}
|
|
694 |
\item @{text "INJ (\<forall> t, \<forall> s) = \<forall> (INJ (t, s)"}
|
|
695 |
\item @{text "INJ (\<forall> t \<in> R, \<forall> s) = \<forall> (INJ (t, s) \<in> R"}
|
|
696 |
\item @{text "INJ (t\<^isub>1 t\<^isub>2, s\<^isub>1 s\<^isub>2) = INJ (t\<^isub>1, s\<^isub>1) INJ (t\<^isub>2, s\<^isub>2)"}
|
|
697 |
\item @{text "INJ (v\<^isub>1 : \<sigma>, v\<^isub>2 : \<sigma>) = v\<^isub>1"}
|
|
698 |
\item @{text "INJ (v\<^isub>1 : \<sigma>, v\<^isub>2 : \<tau>) = REP(\<sigma>,\<tau>) (ABS (\<sigma>,\<tau>) (v\<^isub>1))"}
|
|
699 |
\item @{text "INJ (c\<^isub>1 : \<sigma>, c\<^isub>2 : \<sigma>) = c\<^isub>1"}
|
|
700 |
\item @{text "INJ (c\<^isub>1 : \<sigma>, c\<^isub>2 : \<tau>) = REP(\<sigma>,\<tau>) (ABS (\<sigma>,\<tau>) (c\<^isub>1))"}
|
|
701 |
\end{itemize}
|
|
702 |
|
|
703 |
For existential quantifiers and unique existential quantifiers it is
|
2230
|
704 |
defined similarly to the universal one.
|
2198
|
705 |
|
2197
|
706 |
*}
|
|
707 |
|
2208
|
708 |
subsection {* Proof procedure *}
|
|
709 |
|
|
710 |
(* In the below the type-guiding 'QuotTrue' assumption is removed; since we
|
|
711 |
present in a paper a version with typed-variables it is not necessary *)
|
2197
|
712 |
|
|
713 |
text {*
|
2208
|
714 |
|
|
715 |
With the above definitions of @{text "REG"} and @{text "INJ"} we can show
|
|
716 |
how the proof is performed. The first step is always the application of
|
|
717 |
of the following lemma:
|
|
718 |
|
2231
|
719 |
@{term [display, indent=10] "[|A; A --> B; B = C; C = D|] ==> D"}
|
2208
|
720 |
|
|
721 |
With @{text A} instantiated to the original raw theorem,
|
|
722 |
@{text B} instantiated to @{text "REG(A)"},
|
|
723 |
@{text C} instantiated to @{text "INJ(REG(A))"},
|
|
724 |
and @{text D} instantiated to the statement of the lifted theorem.
|
|
725 |
The first assumption can be immediately discharged using the original
|
|
726 |
theorem and the three left subgoals are exactly the subgoals of regularization,
|
|
727 |
injection and cleaning. The three can be proved independently by the
|
|
728 |
framework and in case there are non-solved subgoals they can be left
|
|
729 |
to the user.
|
|
730 |
|
|
731 |
The injection and cleaning subgoals are always solved if the appropriate
|
|
732 |
respectfulness and preservation theorems are given. It is not the case
|
|
733 |
with regularization; sometimes a theorem given by the user does not
|
|
734 |
imply a regularized version and a stronger one needs to be proved. This
|
|
735 |
is outside of the scope of the quotient package, so the user is then left
|
|
736 |
with such obligations. As an example lets see the simplest possible
|
|
737 |
non-liftable theorem for integers: When we want to prove @{term "0 \<noteq> 1"}
|
|
738 |
on integers the fact that @{term "\<not> (0, 0) = (1, 0)"} is not enough. It
|
|
739 |
only shows that particular items in the equivalence classes are not equal,
|
|
740 |
a more general statement saying that the classes are not equal is necessary.
|
|
741 |
*}
|
|
742 |
|
|
743 |
subsection {* Proving Regularization *}
|
|
744 |
|
|
745 |
text {*
|
1994
|
746 |
|
2209
|
747 |
Isabelle provides a set of \emph{mono} rules, that are used to split implications
|
2230
|
748 |
of similar statements into simpler implication subgoals. These are enhanced
|
2209
|
749 |
with special quotient theorem in the regularization goal. Below we only show
|
|
750 |
the versions for the universal quantifier. For the existential quantifier
|
2230
|
751 |
and abstraction they are analogous with some symmetry.
|
2199
|
752 |
|
2209
|
753 |
First, bounded universal quantifiers can be removed on the right:
|
2199
|
754 |
|
2231
|
755 |
@{thm [display, indent=10] ball_reg_right[no_vars]}
|
2206
|
756 |
|
2209
|
757 |
They can be removed anywhere if the relation is an equivalence relation:
|
|
758 |
|
2231
|
759 |
@{thm [display, indent=10] ball_reg_eqv[no_vars]}
|
2209
|
760 |
|
|
761 |
And finally it can be removed anywhere if @{term R2} is an equivalence relation, then:
|
2231
|
762 |
|
|
763 |
@{thm [display, indent=10] (concl) ball_reg_eqv_range[no_vars]}
|
2209
|
764 |
|
2231
|
765 |
The last theorem is new in comparison with Homeier's package, there the
|
|
766 |
injection procedure would be used to prove goals with such shape, and there
|
|
767 |
the equivalence assumption would be useful. We use it directly also for
|
|
768 |
composed relations where the range type is a type for which we know an
|
|
769 |
equivalence theorem. This allows separating regularization from injection.
|
2209
|
770 |
|
2206
|
771 |
*}
|
|
772 |
|
|
773 |
(*
|
2231
|
774 |
@{thm bex_reg_eqv_range[no_vars]}
|
2199
|
775 |
@{thm [display] bex_reg_left[no_vars]}
|
|
776 |
@{thm [display] bex1_bexeq_reg[no_vars]}
|
2206
|
777 |
@{thm [display] bex_reg_eqv[no_vars]}
|
2209
|
778 |
@{thm [display] babs_reg_eqv[no_vars]}
|
|
779 |
@{thm [display] babs_simp[no_vars]}
|
2206
|
780 |
*)
|
1994
|
781 |
|
|
782 |
subsection {* Injection *}
|
|
783 |
|
2199
|
784 |
text {*
|
2211
|
785 |
The injection proof starts with an equality between the regularized theorem
|
|
786 |
and the injected version. The proof again follows by the structure of the
|
|
787 |
two term, and is defined for a goal being a relation between the two terms.
|
2199
|
788 |
|
2211
|
789 |
\begin{itemize}
|
|
790 |
\item For two constants, an appropriate constant respectfullness assumption is used.
|
|
791 |
\item For two variables, the regularization assumptions state that they are related.
|
|
792 |
\item For two abstractions, they are eta-expanded and beta-reduced.
|
|
793 |
\end{itemize}
|
2199
|
794 |
|
2211
|
795 |
Otherwise the two terms are applications. There are two cases: If there is a REP/ABS
|
|
796 |
in the injected theorem we can use the theorem:
|
|
797 |
|
2199
|
798 |
@{thm [display] rep_abs_rsp[no_vars]}
|
|
799 |
|
2211
|
800 |
and continue the proof.
|
2199
|
801 |
|
2211
|
802 |
Otherwise we introduce an appropriate relation between the subterms and continue with
|
|
803 |
two subgoals using the lemma:
|
|
804 |
|
|
805 |
@{thm [display] apply_rsp[no_vars]}
|
2199
|
806 |
|
|
807 |
*}
|
|
808 |
|
1994
|
809 |
subsection {* Cleaning *}
|
|
810 |
|
2212
|
811 |
text {*
|
|
812 |
The @{text REG} and @{text INJ} functions have been defined in such a way
|
|
813 |
that establishing the goal theorem now consists only on rewriting the
|
|
814 |
injected theorem with the preservation theorems.
|
|
815 |
|
|
816 |
\begin{itemize}
|
|
817 |
\item First for lifted constants, their definitions are the preservation rules for
|
|
818 |
them.
|
|
819 |
\item For lambda abstractions lambda preservation establishes
|
|
820 |
the equality between the injected theorem and the goal. This allows both
|
|
821 |
abstraction and quantification over lifted types.
|
|
822 |
@{thm [display] lambda_prs[no_vars]}
|
|
823 |
\item Relations over lifted types are folded with:
|
|
824 |
@{thm [display] Quotient_rel_rep[no_vars]}
|
|
825 |
\item User given preservation theorems, that allow using higher level operations
|
|
826 |
and containers of types being lifted. An example may be
|
|
827 |
@{thm [display] map_prs(1)[no_vars]}
|
|
828 |
\end{itemize}
|
|
829 |
|
|
830 |
Preservation of relations and user given constant preservation lemmas *}
|
1994
|
831 |
|
|
832 |
section {* Examples *}
|
|
833 |
|
2210
|
834 |
(* Mention why equivalence *)
|
2206
|
835 |
|
2210
|
836 |
text {*
|
|
837 |
|
|
838 |
A user of our quotient package first needs to define an equivalence relation:
|
|
839 |
|
|
840 |
@{text "fun \<approx> where (x, y) \<approx> (u, v) = (x + v = u + y)"}
|
|
841 |
|
|
842 |
Then the user defines a quotient type:
|
|
843 |
|
|
844 |
@{text "quotient_type int = (nat \<times> nat) / \<approx>"}
|
|
845 |
|
|
846 |
Which leaves a proof obligation that the relation is an equivalence relation,
|
|
847 |
that can be solved with the automatic tactic with two definitions.
|
|
848 |
|
|
849 |
The user can then specify the constants on the quotient type:
|
|
850 |
|
|
851 |
@{text "quotient_definition 0 \<Colon> int is (0\<Colon>nat, 0\<Colon>nat)"}
|
|
852 |
@{text "fun plus_raw where plus_raw (x, y) (u, v) = (x + u, y + v)"}
|
|
853 |
@{text "quotient_definition (op +) \<Colon> (int \<Rightarrow> int \<Rightarrow> int) is plus_raw"}
|
|
854 |
|
|
855 |
Lets first take a simple theorem about addition on the raw level:
|
|
856 |
|
|
857 |
@{text "lemma plus_zero_raw: plus_raw (0, 0) i \<approx> i"}
|
|
858 |
|
|
859 |
When the user tries to lift a theorem about integer addition, the respectfulness
|
|
860 |
proof obligation is left, so let us prove it first:
|
|
861 |
|
|
862 |
@{text "lemma (op \<approx> \<Longrightarrow> op \<approx> \<Longrightarrow> op \<approx>) plus_raw plus_raw"}
|
|
863 |
|
|
864 |
Can be proved automatically by the system just by unfolding the definition
|
|
865 |
of @{term "op \<Longrightarrow>"}.
|
|
866 |
|
2230
|
867 |
Now the user can either prove a lifted lemma explicitly:
|
2210
|
868 |
|
|
869 |
@{text "lemma 0 + i = i by lifting plus_zero_raw"}
|
|
870 |
|
|
871 |
Or in this simple case use the automated translation mechanism:
|
|
872 |
|
|
873 |
@{text "thm plus_zero_raw[quot_lifted]"}
|
|
874 |
|
|
875 |
obtaining the same result.
|
|
876 |
*}
|
2206
|
877 |
|
1978
|
878 |
section {* Related Work *}
|
|
879 |
|
|
880 |
text {*
|
|
881 |
\begin{itemize}
|
|
882 |
|
2152
|
883 |
\item Peter Homeier's package~\cite{Homeier05} (and related work from there)
|
|
884 |
\item John Harrison's one~\cite{harrison-thesis} is the first one to lift theorems
|
|
885 |
but only first order.
|
1978
|
886 |
|
2152
|
887 |
\item PVS~\cite{PVS:Interpretations}
|
|
888 |
\item MetaPRL~\cite{Nogin02}
|
|
889 |
\item Manually defined quotients in Isabelle/HOL Library (Markus's Quotient\_Type,
|
|
890 |
Dixon's FSet, \ldots)
|
1978
|
891 |
|
|
892 |
\item Oscar Slotosch defines quotient-type automatically but no
|
2152
|
893 |
lifting~\cite{Slotosch97}.
|
1978
|
894 |
|
|
895 |
\item PER. And how to avoid it.
|
|
896 |
|
2152
|
897 |
\item Necessity of Hilbert Choice op and Larry's quotients~\cite{Paulson06}
|
1978
|
898 |
|
2152
|
899 |
\item Setoids in Coq and \cite{ChicliPS02}
|
1978
|
900 |
|
|
901 |
\end{itemize}
|
|
902 |
*}
|
1975
b1281a0051ae
added stub for quotient paper; call with isabelle make qpaper
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
903 |
|
2210
|
904 |
section {* Conclusion *}
|
|
905 |
|
2224
|
906 |
text {*
|
2237
|
907 |
|
|
908 |
|
|
909 |
The code of the quotient package described here is already included in the
|
|
910 |
standard distribution of Isabelle.\footnote{Avaiable from
|
|
911 |
\href{http://isabelle.in.tum.de/}{http://isabelle.in.tum.de/}.} It is
|
|
912 |
heavily used in Nominal Isabelle, which provides a convenient reasoning
|
|
913 |
infrastructure for programming language calculi involving binders. Earlier
|
|
914 |
versions of Nominal Isabelle have been used successfully in formalisations
|
|
915 |
of an equivalence checking algorithm for LF \cite{UrbanCheneyBerghofer08},
|
|
916 |
Typed Scheme~\cite{TobinHochstadtFelleisen08}, several calculi for
|
|
917 |
concurrency \cite{BengtsonParow09} and a strong normalisation result for
|
|
918 |
cut-elimination in classical logic \cite{UrbanZhu08}.
|
|
919 |
|
2224
|
920 |
*}
|
|
921 |
|
|
922 |
|
|
923 |
subsection {* Contributions *}
|
|
924 |
|
|
925 |
text {*
|
|
926 |
We present the detailed lifting procedure, which was not shown before.
|
|
927 |
|
|
928 |
The quotient package presented in this paper has the following
|
|
929 |
advantages over existing packages:
|
|
930 |
\begin{itemize}
|
|
931 |
|
|
932 |
\item We define quotient composition, function map composition and
|
|
933 |
relation map composition. This lets lifting polymorphic types with
|
|
934 |
subtypes quotiented as well. We extend the notions of
|
|
935 |
respectfulness and preservation to cope with quotient
|
|
936 |
composition.
|
|
937 |
|
|
938 |
\item We allow lifting only some occurrences of quotiented
|
|
939 |
types. Rsp/Prs extended. (used in nominal)
|
|
940 |
|
|
941 |
\item The quotient package is very modular. Definitions can be added
|
|
942 |
separately, rsp and prs can be proved separately, Quotients and maps
|
|
943 |
can be defined separately and theorems can
|
|
944 |
be lifted on a need basis. (useful with type-classes).
|
|
945 |
|
|
946 |
\item Can be used both manually (attribute, separate tactics,
|
|
947 |
rsp/prs databases) and programatically (automated definition of
|
|
948 |
lifted constants, the rsp proof obligations and theorem statement
|
|
949 |
translation according to given quotients).
|
|
950 |
|
|
951 |
\end{itemize}
|
|
952 |
*}
|
|
953 |
|
|
954 |
|
2227
|
955 |
|
1975
b1281a0051ae
added stub for quotient paper; call with isabelle make qpaper
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
956 |
(*<*)
|
b1281a0051ae
added stub for quotient paper; call with isabelle make qpaper
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
957 |
end
|
1978
|
958 |
(*>*)
|