1975
b1281a0051ae
added stub for quotient paper; call with isabelle make qpaper
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 1
(*<*)
b1281a0051ae
added stub for quotient paper; call with isabelle make qpaper
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 2
theory Paper
2183
+ − 3
imports "Quotient"
1975
b1281a0051ae
added stub for quotient paper; call with isabelle make qpaper
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 4
"LaTeXsugar"
2186
+ − 5
"../Nominal/FSet"
1975
b1281a0051ae
added stub for quotient paper; call with isabelle make qpaper
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 6
begin
1994
+ − 7
2286
e7bc2ae30faf
added a few points that need to be looked at the next version of the qpaper
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 8
(****
e7bc2ae30faf
added a few points that need to be looked at the next version of the qpaper
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 9
e7bc2ae30faf
added a few points that need to be looked at the next version of the qpaper
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 10
** things to do for the next version
e7bc2ae30faf
added a few points that need to be looked at the next version of the qpaper
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 11
*
e7bc2ae30faf
added a few points that need to be looked at the next version of the qpaper
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 12
* - what are quot_thms?
2287
+ − 13
* - what do all preservation theorems look like,
+ − 14
in particular preservation for quotient
+ − 15
compositions
2333
+ − 16
- explain how Quotient R Abs Rep is proved (j-version)
+ − 17
- give an example where precise specification helps (core Haskell in nominal?)
2374
+ − 18
2414
+ − 19
- Mention Andreas Lochbiler in Acknowledgements and 'desceding'.
+ − 20
2286
e7bc2ae30faf
added a few points that need to be looked at the next version of the qpaper
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 21
*)
e7bc2ae30faf
added a few points that need to be looked at the next version of the qpaper
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 22
1994
+ − 23
notation (latex output)
2258
+ − 24
rel_conj ("_ \<circ>\<circ>\<circ> _" [53, 53] 52) and
2269
+ − 25
pred_comp ("_ \<circ>\<circ> _" [1, 1] 30) and
2258
+ − 26
"op -->" (infix "\<longrightarrow>" 100) and
+ − 27
"==>" (infix "\<Longrightarrow>" 100) and
2444
+ − 28
fun_map ("_ \<singlearr> _" 51) and
+ − 29
fun_rel ("_ \<doublearr> _" 51) and
2217
+ − 30
list_eq (infix "\<approx>" 50) and (* Not sure if we want this notation...? *)
2223
+ − 31
fempty ("\<emptyset>") and
+ − 32
funion ("_ \<union> _") and
+ − 33
finsert ("{_} \<union> _") and
2221
+ − 34
Cons ("_::_") and
+ − 35
concat ("flat") and
2444
+ − 36
fconcat ("\<Union>") and
+ − 37
Quotient ("Quot _ _ _")
+ − 38
2217
+ − 39
1994
+ − 40
2182
+ − 41
ML {*
+ − 42
fun nth_conj n (_, r) = nth (HOLogic.dest_conj r) n;
2274
+ − 43
2182
+ − 44
fun style_lhs_rhs proj = Scan.succeed (fn ctxt => fn t =>
+ − 45
let
+ − 46
val concl =
+ − 47
Object_Logic.drop_judgment (ProofContext.theory_of ctxt) (Logic.strip_imp_concl t)
+ − 48
in
+ − 49
case concl of (_ $ l $ r) => proj (l, r)
+ − 50
| _ => error ("Binary operator expected in term: " ^ Syntax.string_of_term ctxt concl)
+ − 51
end);
+ − 52
*}
2274
+ − 53
2182
+ − 54
setup {*
+ − 55
Term_Style.setup "rhs1" (style_lhs_rhs (nth_conj 0)) #>
+ − 56
Term_Style.setup "rhs2" (style_lhs_rhs (nth_conj 1)) #>
+ − 57
Term_Style.setup "rhs3" (style_lhs_rhs (nth_conj 2))
+ − 58
*}
2274
+ − 59
1975
b1281a0051ae
added stub for quotient paper; call with isabelle make qpaper
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 60
(*>*)
b1281a0051ae
added stub for quotient paper; call with isabelle make qpaper
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 61
2227
+ − 62
1975
b1281a0051ae
added stub for quotient paper; call with isabelle make qpaper
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 63
section {* Introduction *}
b1281a0051ae
added stub for quotient paper; call with isabelle make qpaper
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 64
2102
200954544cae
added some of the quotient literature; a bit more to the qpaper
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 65
text {*
2443
+ − 66
\noindent
2445
+ − 67
One might think quotients have been studied to death, but in the context of
+ − 68
theorem provers many questions concerning them are far from settled. In
+ − 69
this paper we address the question of how to establish a convenient reasoning
+ − 70
infrastructure
+ − 71
for quotient constructions in the Isabelle/HOL,
+ − 72
theorem prover. Higher-Order Logic (HOL) consists
2443
+ − 73
of a small number of axioms and inference rules over a simply-typed
+ − 74
term-language. Safe reasoning in HOL is ensured by two very restricted
+ − 75
mechanisms for extending the logic: one is the definition of new constants
+ − 76
in terms of existing ones; the other is the introduction of new types by
2445
+ − 77
identifying non-empty subsets in existing types. Previous work has shown how
2443
+ − 78
to use both mechanisms for dealing with quotient constructions in HOL (see
+ − 79
\cite{Homeier05,Paulson06}). For example the integers in Isabelle/HOL are
+ − 80
constructed by a quotient construction over the type @{typ "nat \<times> nat"} and
+ − 81
the equivalence relation
2103
+ − 82
2102
200954544cae
added some of the quotient literature; a bit more to the qpaper
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 83
2443
+ − 84
\begin{isabelle}\ \ \ \ \ %%%
2237
+ − 85
@{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}
+ − 86
\end{isabelle}
2102
200954544cae
added some of the quotient literature; a bit more to the qpaper
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 87
200954544cae
added some of the quotient literature; a bit more to the qpaper
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 88
\noindent
2217
+ − 89
This constructions yields the new type @{typ int} and definitions for @{text
2220
+ − 90
"0"} and @{text "1"} of type @{typ int} can be given in terms of pairs of
+ − 91
natural numbers (namely @{text "(0, 0)"} and @{text "(1, 0)"}). Operations
+ − 92
such as @{text "add"} with type @{typ "int \<Rightarrow> int \<Rightarrow> int"} can be defined in
+ − 93
terms of operations on pairs of natural numbers (namely @{text
2224
+ − 94
"add_pair (n\<^isub>1, m\<^isub>1) (n\<^isub>2,
2222
+ − 95
m\<^isub>2) \<equiv> (n\<^isub>1 + n\<^isub>2, m\<^isub>1 + m\<^isub>2)"}).
+ − 96
Similarly one can construct the type of finite sets, written @{term "\<alpha> fset"},
2223
+ − 97
by quotienting the type @{text "\<alpha> list"} according to the equivalence relation
2103
+ − 98
2443
+ − 99
\begin{isabelle}\ \ \ \ \ %%%
2237
+ − 100
@{text "xs \<approx> ys \<equiv> (\<forall>x. memb x xs \<longleftrightarrow> memb x ys)"}\hfill\numbered{listequiv}
+ − 101
\end{isabelle}
2103
+ − 102
+ − 103
\noindent
2224
+ − 104
which states that two lists are equivalent if every element in one list is
+ − 105
also member in the other. The empty finite set, written @{term "{||}"}, can
+ − 106
then be defined as the empty list and the union of two finite sets, written
+ − 107
@{text "\<union>"}, as list append.
2220
+ − 108
2269
+ − 109
Quotients are important in a variety of areas, but they are really ubiquitous in
2258
+ − 110
the area of reasoning about programming language calculi. A simple example
+ − 111
is the lambda-calculus, whose raw terms are defined as
+ − 112
2220
+ − 113
2443
+ − 114
\begin{isabelle}\ \ \ \ \ %%%
2238
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 115
@{text "t ::= x | t t | \<lambda>x.t"}\hfill\numbered{lambda}
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 116
\end{isabelle}
2217
+ − 117
2220
+ − 118
\noindent
2256
+ − 119
The problem with this definition arises, for instance, when one attempts to
+ − 120
prove formally the substitution lemma \cite{Barendregt81} by induction
2222
+ − 121
over the structure of terms. This can be fiendishly complicated (see
2220
+ − 122
\cite[Pages 94--104]{CurryFeys58} for some ``rough'' sketches of a proof
2226
+ − 123
about raw lambda-terms). In contrast, if we reason about
2220
+ − 124
$\alpha$-equated lambda-terms, that means terms quotient according to
2223
+ − 125
$\alpha$-equivalence, then the reasoning infrastructure provided,
+ − 126
for example, by Nominal Isabelle \cite{UrbanKaliszyk11} makes the formal
2222
+ − 127
proof of the substitution lemma almost trivial.
2220
+ − 128
+ − 129
The difficulty is that in order to be able to reason about integers, finite
2221
+ − 130
sets or $\alpha$-equated lambda-terms one needs to establish a reasoning
2220
+ − 131
infrastructure by transferring, or \emph{lifting}, definitions and theorems
2226
+ − 132
from the raw type @{typ "nat \<times> nat"} to the quotient type @{typ int}
2220
+ − 133
(similarly for finite sets and $\alpha$-equated lambda-terms). This lifting
2222
+ − 134
usually requires a \emph{lot} of tedious reasoning effort \cite{Paulson06}.
2443
+ − 135
In principle it is feasible to do this work manually, if one has only a few quotient
2247
+ − 136
constructions at hand. But if they have to be done over and over again, as in
2222
+ − 137
Nominal Isabelle, then manual reasoning is not an option.
2221
+ − 138
2223
+ − 139
The purpose of a \emph{quotient package} is to ease the lifting of theorems
2238
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 140
and automate the reasoning as much as possible. In the
2223
+ − 141
context of HOL, there have been a few quotient packages already
2234
+ − 142
\cite{harrison-thesis,Slotosch97}. The most notable one is by Homeier
2223
+ − 143
\cite{Homeier05} implemented in HOL4. The fundamental construction these
+ − 144
quotient packages perform can be illustrated by the following picture:
2217
+ − 145
2417
+ − 146
%%% FIXME: Referee 1 says:
+ − 147
%%% Diagram is unclear. Firstly, isn't an existing type a "set (not sets) of raw elements"?
+ − 148
%%% Secondly, isn't the _set of_ equivalence classes mapped to and from the new type?
+ − 149
%%% Thirdly, what do the words "non-empty subset" refer to ?
+ − 150
2423
+ − 151
%%% Cezary: I like the diagram, maybe 'new type' could be outside, but otherwise
+ − 152
%%% I wouldn't change it.
+ − 153
2217
+ − 154
\begin{center}
2220
+ − 155
\mbox{}\hspace{20mm}\begin{tikzpicture}
+ − 156
%%\draw[step=2mm] (-4,-1) grid (4,1);
+ − 157
+ − 158
\draw[very thick] (0.7,0.3) circle (4.85mm);
+ − 159
\draw[rounded corners=1mm, very thick] ( 0.0,-0.9) rectangle ( 1.8, 0.9);
+ − 160
\draw[rounded corners=1mm, very thick] (-1.95,0.8) rectangle (-2.9,-0.195);
+ − 161
+ − 162
\draw (-2.0, 0.8) -- (0.7,0.8);
+ − 163
\draw (-2.0,-0.195) -- (0.7,-0.195);
2103
+ − 164
2220
+ − 165
\draw ( 0.7, 0.23) node {\begin{tabular}{@ {}c@ {}}equiv-\\[-1mm]clas.\end{tabular}};
+ − 166
\draw (-2.45, 0.35) node {\begin{tabular}{@ {}c@ {}}new\\[-1mm]type\end{tabular}};
+ − 167
\draw (1.8, 0.35) node[right=-0.1mm]
2224
+ − 168
{\begin{tabular}{@ {}l@ {}}existing\\[-1mm] type\\ (sets of raw elements)\end{tabular}};
2220
+ − 169
\draw (0.9, -0.55) node {\begin{tabular}{@ {}l@ {}}non-empty\\[-1mm]subset\end{tabular}};
+ − 170
+ − 171
\draw[->, very thick] (-1.8, 0.36) -- (-0.1,0.36);
+ − 172
\draw[<-, very thick] (-1.8, 0.16) -- (-0.1,0.16);
2221
+ − 173
\draw (-0.95, 0.26) node[above=0.4mm] {@{text Rep}};
+ − 174
\draw (-0.95, 0.26) node[below=0.4mm] {@{text Abs}};
2220
+ − 175
+ − 176
\end{tikzpicture}
+ − 177
\end{center}
2217
+ − 178
2221
+ − 179
\noindent
2247
+ − 180
The starting point is an existing type, to which we refer as the
2269
+ − 181
\emph{raw type} and over which an equivalence relation given by the user is
2238
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 182
defined. With this input the package introduces a new type, to which we
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 183
refer as the \emph{quotient type}. This type comes with an
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 184
\emph{abstraction} and a \emph{representation} function, written @{text Abs}
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 185
and @{text Rep}.\footnote{Actually slightly more basic functions are given;
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 186
the functions @{text Abs} and @{text Rep} need to be derived from them. We
2269
+ − 187
will show the details later. } They relate elements in the
+ − 188
existing type to elements in the new type and vice versa, and can be uniquely
2256
+ − 189
identified by their quotient type. For example for the integer quotient construction
2238
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 190
the types of @{text Abs} and @{text Rep} are
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 191
2224
+ − 192
2443
+ − 193
\begin{isabelle}\ \ \ \ \ %%%
2234
+ − 194
@{text "Abs :: nat \<times> nat \<Rightarrow> int"}\hspace{10mm}@{text "Rep :: int \<Rightarrow> nat \<times> nat"}
2224
+ − 195
\end{isabelle}
+ − 196
+ − 197
\noindent
2238
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 198
We therefore often write @{text Abs_int} and @{text Rep_int} if the
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 199
typing information is important.
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 200
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 201
Every abstraction and representation function stands for an isomorphism
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 202
between the non-empty subset and elements in the new type. They are
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 203
necessary for making definitions involving the new type. For example @{text
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 204
"0"} and @{text "1"} of type @{typ int} can be defined as
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 205
2221
+ − 206
2443
+ − 207
\begin{isabelle}\ \ \ \ \ %%%
2238
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 208
@{text "0 \<equiv> Abs_int (0, 0)"}\hspace{10mm}@{text "1 \<equiv> Abs_int (1, 0)"}
2221
+ − 209
\end{isabelle}
+ − 210
+ − 211
\noindent
2224
+ − 212
Slightly more complicated is the definition of @{text "add"} having type
2222
+ − 213
@{typ "int \<Rightarrow> int \<Rightarrow> int"}. Its definition is as follows
2221
+ − 214
2443
+ − 215
\begin{isabelle}\ \ \ \ \ %%%
2258
+ − 216
@{text "add n m \<equiv> Abs_int (add_pair (Rep_int n) (Rep_int m))"}
+ − 217
\hfill\numbered{adddef}
+ − 218
\end{isabelle}
+ − 219
2221
+ − 220
\noindent
2224
+ − 221
where we take the representation of the arguments @{text n} and @{text m},
2226
+ − 222
add them according to the function @{text "add_pair"} and then take the
2221
+ − 223
abstraction of the result. This is all straightforward and the existing
2412
+ − 224
quotient packages can deal with such definitions. But what is surprising is
2223
+ − 225
that none of them can deal with slightly more complicated definitions involving
2221
+ − 226
\emph{compositions} of quotients. Such compositions are needed for example
2247
+ − 227
in case of quotienting lists to yield finite sets and the operator that
2226
+ − 228
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
+ − 229
2443
+ − 230
\begin{isabelle}\ \ \ \ \ %%%
+ − 231
@{thm concat.simps(1)[THEN eq_reflection]}\hspace{10mm}
+ − 232
@{thm concat.simps(2)[THEN eq_reflection, no_vars]}
+ − 233
\end{isabelle}
2183
+ − 234
2103
+ − 235
\noindent
2221
+ − 236
We expect that the corresponding operator on finite sets, written @{term "fconcat"},
2248
+ − 237
builds finite unions of finite sets:
2188
+ − 238
2443
+ − 239
\begin{isabelle}\ \ \ \ \ %%%
+ − 240
@{thm fconcat_empty[THEN eq_reflection, no_vars]}\hspace{10mm}
+ − 241
@{thm fconcat_insert[THEN eq_reflection, no_vars]}
+ − 242
\end{isabelle}
2102
200954544cae
added some of the quotient literature; a bit more to the qpaper
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 243
2103
+ − 244
\noindent
2256
+ − 245
The quotient package should automatically provide us with a definition for @{text "\<Union>"} in
2238
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 246
terms of @{text flat}, @{text Rep_fset} and @{text Abs_fset}. The problem is
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 247
that the method used in the existing quotient
2247
+ − 248
packages of just taking the representation of the arguments and then taking
2258
+ − 249
the abstraction of the result is \emph{not} enough. The reason is that in case
2224
+ − 250
of @{text "\<Union>"} we obtain the incorrect definition
+ − 251
2443
+ − 252
\begin{isabelle}\ \ \ \ \ %%%
+ − 253
@{text "\<Union> S \<equiv> Abs_fset (flat (Rep_fset S))"}
+ − 254
\end{isabelle}
2221
+ − 255
2224
+ − 256
\noindent
+ − 257
where the right-hand side is not even typable! This problem can be remedied in the
+ − 258
existing quotient packages by introducing an intermediate step and reasoning
2226
+ − 259
about flattening of lists of finite sets. However, this remedy is rather
2224
+ − 260
cumbersome and inelegant in light of our work, which can deal with such
+ − 261
definitions directly. The solution is that we need to build aggregate
+ − 262
representation and abstraction functions, which in case of @{text "\<Union>"}
+ − 263
generate the following definition
+ − 264
2443
+ − 265
\begin{isabelle}\ \ \ \ \ %%%
+ − 266
@{text "\<Union> S \<equiv> Abs_fset (flat ((map_list Rep_fset \<circ> Rep_fset) S))"}
+ − 267
\end{isabelle}
2221
+ − 268
+ − 269
\noindent
2367
+ − 270
where @{term map_list} is the usual mapping function for lists. In this paper we
2224
+ − 271
will present a formal definition of our aggregate abstraction and
2223
+ − 272
representation functions (this definition was omitted in \cite{Homeier05}).
2224
+ − 273
They generate definitions, like the one above for @{text "\<Union>"},
2226
+ − 274
according to the type of the raw constant and the type
2224
+ − 275
of the quotient constant. This means we also have to extend the notions
2237
+ − 276
of \emph{aggregate equivalence relation}, \emph{respectfulness} and \emph{preservation}
2231
+ − 277
from Homeier \cite{Homeier05}.
2223
+ − 278
2445
+ − 279
In addition we are able to clearly specify what is involved
2256
+ − 280
in the lifting process (this was only hinted at in \cite{Homeier05} and
2445
+ − 281
implemented as a ``rough recipe'' in ML-code). A pleasing side-result
+ − 282
is that our procedure for lifting theorems is completely deterministic
+ − 283
following the structure of the theorem being lifted and the theorem
+ − 284
on the quotient level. Space constraints, unfortunately, allow us to only
+ − 285
sketch this part of our work in Section 5 and we defer the reader to a longer
+ − 286
version for the details. However, we will give in Section 3 and 4 all
+ − 287
definitions that specify the input and output data of our three-step
+ − 288
lifting procedure. Section 6 gives an example how our quotient package
+ − 289
works in practise.
2102
200954544cae
added some of the quotient literature; a bit more to the qpaper
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 290
*}
1975
b1281a0051ae
added stub for quotient paper; call with isabelle make qpaper
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 291
2443
+ − 292
section {* Preliminaries and General\\ Quotients\label{sec:prelims} *}
1978
+ − 293
+ − 294
text {*
2443
+ − 295
\noindent
2445
+ − 296
We will give in this section a crude overview of HOL and describe the main
2274
+ − 297
definitions given by Homeier for quotients \cite{Homeier05}.
2258
+ − 298
2274
+ − 299
At its core, HOL is based on a simply-typed term language, where types are
2269
+ − 300
recorded in Church-style fashion (that means, we can always infer the type of
2258
+ − 301
a term and its subterms without any additional information). The grammars
2443
+ − 302
for types and terms are
2256
+ − 303
2443
+ − 304
\begin{isabelle}\ \ \ \ \ %%%
+ − 305
\begin{tabular}{@ {}c@ {\hspace{10mm}}c@ {}}
+ − 306
@{text "\<sigma>, \<tau> ::= \<alpha> | (\<sigma>,\<dots>, \<sigma>) \<kappa>"} &
+ − 307
@{text "t, s ::= x\<^isup>\<sigma> | c\<^isup>\<sigma> | t t | \<lambda>x\<^isup>\<sigma>. t"}\\
2256
+ − 308
\end{tabular}
+ − 309
\end{isabelle}
+ − 310
+ − 311
\noindent
2443
+ − 312
with types being either type variables or type constructors and terms
+ − 313
being variables, constants, applications or abstractions.
2256
+ − 314
We often write just @{text \<kappa>} for @{text "() \<kappa>"}, and use @{text "\<alpha>s"} and
2258
+ − 315
@{text "\<sigma>s"} to stand for collections of type variables and types,
+ − 316
respectively. The type of a term is often made explicit by writing @{text
2274
+ − 317
"t :: \<sigma>"}. HOL includes a type @{typ bool} for booleans and the function
+ − 318
type, written @{text "\<sigma> \<Rightarrow> \<tau>"}. HOL also contains many primitive and defined
2332
9a560e489c64
polished paper again (and took out some claims about Homeier's package)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 319
constants; for example, a primitive constant is equality, with type @{text "= :: \<sigma> \<Rightarrow> \<sigma> \<Rightarrow>
2287
+ − 320
bool"}, and the identity function with type @{text "id :: \<sigma> \<Rightarrow> \<sigma>"} is
2332
9a560e489c64
polished paper again (and took out some claims about Homeier's package)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 321
defined as @{text "\<lambda>x\<^sup>\<sigma>. x\<^sup>\<sigma>"}.
2256
+ − 322
2258
+ − 323
An important point to note is that theorems in HOL can be seen as a subset
2287
+ − 324
of terms that are constructed specially (namely through axioms and proof
2269
+ − 325
rules). As a result we are able to define automatic proof
2258
+ − 326
procedures showing that one theorem implies another by decomposing the term
+ − 327
underlying the first theorem.
+ − 328
2333
+ − 329
Like Homeier's, our work relies on map-functions defined for every type
2367
+ − 330
constructor taking some arguments, for example @{text map_list} for lists. Homeier
2274
+ − 331
describes in \cite{Homeier05} map-functions for products, sums, options and
+ − 332
also the following map for function types
2258
+ − 333
2443
+ − 334
\begin{isabelle}\ \ \ \ \ %%%
+ − 335
@{thm fun_map_def[no_vars, THEN eq_reflection]}
+ − 336
\end{isabelle}
2258
+ − 337
+ − 338
\noindent
+ − 339
Using this map-function, we can give the following, equivalent, but more
2332
9a560e489c64
polished paper again (and took out some claims about Homeier's package)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 340
uniform definition for @{text add} shown in \eqref{adddef}:
2256
+ − 341
2443
+ − 342
\begin{isabelle}\ \ \ \ \ %%%
+ − 343
@{text "add \<equiv> (Rep_int \<singlearr> Rep_int \<singlearr> Abs_int) add_pair"}
+ − 344
\end{isabelle}
2182
+ − 345
2258
+ − 346
\noindent
2274
+ − 347
Using extensionality and unfolding the definition of @{text "\<singlearr>"},
+ − 348
we can get back to \eqref{adddef}.
+ − 349
In what follows we shall use the convention to write @{text "map_\<kappa>"} for a map-function
2413
+ − 350
of the type-constructor @{text \<kappa>}. For a type @{text \<kappa>} with arguments @{text "\<alpha>\<^isub>1\<^isub>\<dots>\<^isub>n"} the
2444
+ − 351
type of the function @{text "map_\<kappa>"} has to be @{text "\<alpha>\<^isub>1\<Rightarrow>\<dots>\<Rightarrow>\<alpha>\<^isub>n\<Rightarrow>\<alpha>\<^isub>1\<dots>\<alpha>\<^isub>n \<kappa>"}.
+ − 352
For example @{text "map_list"}
2413
+ − 353
has to have the type @{text "\<alpha>\<Rightarrow>\<alpha> list"}.
+ − 354
In our implementation we maintain
2274
+ − 355
a database of these map-functions that can be dynamically extended.
2258
+ − 356
+ − 357
It will also be necessary to have operators, referred to as @{text "rel_\<kappa>"},
+ − 358
which define equivalence relations in terms of constituent equivalence
+ − 359
relations. For example given two equivalence relations @{text "R\<^isub>1"}
+ − 360
and @{text "R\<^isub>2"}, we can define an equivalence relations over
+ − 361
products as follows
2443
+ − 362
+ − 363
\begin{isabelle}\ \ \ \ \ %%%
+ − 364
@{text "(R\<^isub>1 \<tripple> R\<^isub>2) (x\<^isub>1, x\<^isub>2) (y\<^isub>1, y\<^isub>2) \<equiv> R\<^isub>1 x\<^isub>1 y\<^isub>1 \<and> R\<^isub>2 x\<^isub>2 y\<^isub>2"}
+ − 365
\end{isabelle}
1978
+ − 366
2258
+ − 367
\noindent
2269
+ − 368
Homeier gives also the following operator for defining equivalence
+ − 369
relations over function types
2258
+ − 370
%
2443
+ − 371
\begin{isabelle}\ \ \ \ \ %%%
2274
+ − 372
@{thm fun_rel_def[of "R\<^isub>1" "R\<^isub>2", no_vars, THEN eq_reflection]}
+ − 373
\hfill\numbered{relfun}
+ − 374
\end{isabelle}
+ − 375
+ − 376
\noindent
2319
+ − 377
In the context of quotients, the following two notions from \cite{Homeier05}
+ − 378
are needed later on.
2274
+ − 379
+ − 380
\begin{definition}[Respects]\label{def:respects}
+ − 381
An element @{text "x"} respects a relation @{text "R"} provided @{text "R x x"}.
+ − 382
\end{definition}
+ − 383
2444
+ − 384
\begin{definition}[Bounded $\forall$ and $\lambda$]\label{def:babs}
2274
+ − 385
@{text "\<forall>x \<in> S. P x"} holds if for all @{text x}, @{text "x \<in> S"} implies @{text "P x"};
+ − 386
and @{text "(\<lambda>x \<in> S. f x) = f x"} provided @{text "x \<in> S"}.
+ − 387
\end{definition}
2258
+ − 388
+ − 389
The central definition in Homeier's work \cite{Homeier05} relates equivalence
+ − 390
relations, abstraction and representation functions:
+ − 391
+ − 392
\begin{definition}[Quotient Types]
+ − 393
Given a relation $R$, an abstraction function $Abs$
+ − 394
and a representation function $Rep$, the predicate @{term "Quotient R Abs Rep"}
2413
+ − 395
holds if and only if
2444
+ − 396
\begin{isabelle}\ \ \ \ \ %%%%
+ − 397
\begin{tabular}{rl}
+ − 398
(i) & \begin{isa}@{thm (rhs1) Quotient_def[of "R", no_vars]}\end{isa}\\
+ − 399
(ii) & \begin{isa}@{thm (rhs2) Quotient_def[of "R", no_vars]}\end{isa}\\
+ − 400
(iii) & \begin{isa}@{thm (rhs3) Quotient_def[of "R", no_vars]}\end{isa}\\
+ − 401
\end{tabular}
+ − 402
\end{isabelle}
2182
+ − 403
\end{definition}
+ − 404
2258
+ − 405
\noindent
2444
+ − 406
The value of this definition lies in the fact that validity of @{term "Quotient R Abs Rep"} can
+ − 407
often be proved in terms of the validity of @{term "Quot"} over the constituent
2269
+ − 408
types of @{text "R"}, @{text Abs} and @{text Rep}.
2258
+ − 409
For example Homeier proves the following property for higher-order quotient
+ − 410
types:
+ − 411
2269
+ − 412
\begin{proposition}\label{funquot}
2444
+ − 413
\begin{isa}
2258
+ − 414
@{thm[mode=IfThen] fun_quotient[where ?R1.0="R\<^isub>1" and ?R2.0="R\<^isub>2"
+ − 415
and ?abs1.0="Abs\<^isub>1" and ?abs2.0="Abs\<^isub>2" and ?rep1.0="Rep\<^isub>1" and ?rep2.0="Rep\<^isub>2"]}
2444
+ − 416
\end{isa}
2258
+ − 417
\end{proposition}
2195
+ − 418
2258
+ − 419
\noindent
2274
+ − 420
As a result, Homeier is able to build an automatic prover that can nearly
2444
+ − 421
always discharge a proof obligation involving @{text "Quot"}. Our quotient
2269
+ − 422
package makes heavy
+ − 423
use of this part of Homeier's work including an extension
2445
+ − 424
for dealing with \emph{conjugations} of equivalence relations\footnote{That are
+ − 425
symmetric by definition.} defined as follows:
2234
+ − 426
2417
+ − 427
%%% FIXME Referee 2 claims that composition-of-relations means OO, and this is also
+ − 428
%%% what wikipedia says. Any idea for a different name? Conjugation of Relations?
+ − 429
2444
+ − 430
\begin{definition}%%[Composition of Relations]
2258
+ − 431
@{abbrev "rel_conj R\<^isub>1 R\<^isub>2"} where @{text "\<circ>\<circ>"} is the predicate
2319
+ − 432
composition defined by
+ − 433
@{thm (concl) pred_compI[of "R\<^isub>1" "x" "y" "R\<^isub>2" "z"]}
2366
+ − 434
holds if and only if there exists a @{text y} such that @{thm (prem 1) pred_compI[of "R\<^isub>1" "x" "y" "R\<^isub>2" "z"]} and
2274
+ − 435
@{thm (prem 2) pred_compI[of "R\<^isub>1" "x" "y" "R\<^isub>2" "z"]}.
2258
+ − 436
\end{definition}
2237
+ − 437
2258
+ − 438
\noindent
2413
+ − 439
Unfortunately a general quotient theorem for @{text "\<circ>\<circ>\<circ>"}, analogous to the one
+ − 440
for @{text "\<singlearr>"} given in Proposition \ref{funquot}, would not be true
+ − 441
in general. It cannot even be stated inside HOL, because of restrictions on types.
+ − 442
However, we can prove specific instances of a
2282
+ − 443
quotient theorem for composing particular quotient relations.
2287
+ − 444
For example, to lift theorems involving @{term flat} the quotient theorem for
+ − 445
composing @{text "\<approx>\<^bsub>list\<^esub>"} will be necessary: given @{term "Quotient R Abs Rep"}
+ − 446
with @{text R} being an equivalence relation, then
2282
+ − 447
2443
+ − 448
\begin{isabelle}\ \ \ \ \ %%%
2444
+ − 449
\begin{tabular}{r@ {\hspace{1mm}}l}
+ − 450
@{text "Quot"} & @{text "(rel_list R \<circ>\<circ>\<circ> \<approx>\<^bsub>list\<^esub>)"}\\
+ − 451
& @{text "(Abs_fset \<circ> map_list Abs)"}\\
+ − 452
& @{text "(map_list Rep \<circ> Rep_fset)"}\\
+ − 453
\end{tabular}
2443
+ − 454
\end{isabelle}
2195
+ − 455
*}
+ − 456
2444
+ − 457
section {* Quotient Types and Quotient\\ Definitions\label{sec:type} *}
1978
+ − 458
2234
+ − 459
text {*
2445
+ − 460
\noindent
2247
+ − 461
The first step in a quotient construction is to take a name for the new
2238
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 462
type, say @{text "\<kappa>\<^isub>q"}, and an equivalence relation, say @{text R},
2247
+ − 463
defined over a raw type, say @{text "\<sigma>"}. The type of the equivalence
2269
+ − 464
relation must be @{text "\<sigma> \<Rightarrow> \<sigma> \<Rightarrow> bool"}. The user-visible part of
+ − 465
the quotient type declaration is therefore
2234
+ − 466
2443
+ − 467
\begin{isabelle}\ \ \ \ \ %%%
2269
+ − 468
\isacommand{quotient\_type}~~@{text "\<alpha>s \<kappa>\<^isub>q = \<sigma> / R"}\hfill\numbered{typedecl}
2235
+ − 469
\end{isabelle}
+ − 470
+ − 471
\noindent
2445
+ − 472
and a proof that @{text "R"} is indeed an equivalence relation. The @{text "\<alpha>s"}
+ − 473
indicate the arity of the new type and the type-variables of @{text "\<sigma>"} can only
+ − 474
be contained in @{text "\<alpha>s"}. Two concrete
2237
+ − 475
examples are
+ − 476
+ − 477
2443
+ − 478
\begin{isabelle}\ \ \ \ \ %%%
2237
+ − 479
\begin{tabular}{@ {}l}
+ − 480
\isacommand{quotient\_type}~~@{text "int = nat \<times> nat / \<approx>\<^bsub>nat \<times> nat\<^esub>"}\\
+ − 481
\isacommand{quotient\_type}~~@{text "\<alpha> fset = \<alpha> list / \<approx>\<^bsub>list\<^esub>"}
+ − 482
\end{tabular}
+ − 483
\end{isabelle}
+ − 484
+ − 485
\noindent
+ − 486
which introduce the type of integers and of finite sets using the
+ − 487
equivalence relations @{text "\<approx>\<^bsub>nat \<times> nat\<^esub>"} and @{text
2269
+ − 488
"\<approx>\<^bsub>list\<^esub>"} defined in \eqref{natpairequiv} and
2247
+ − 489
\eqref{listequiv}, respectively (the proofs about being equivalence
2274
+ − 490
relations is omitted). Given this data, we define for declarations shown in
+ − 491
\eqref{typedecl} the quotient types internally as
2234
+ − 492
2443
+ − 493
\begin{isabelle}\ \ \ \ \ %%%
2234
+ − 494
\isacommand{typedef}~~@{text "\<alpha>s \<kappa>\<^isub>q = {c. \<exists>x. c = R x}"}
+ − 495
\end{isabelle}
+ − 496
+ − 497
\noindent
2247
+ − 498
where the right-hand side is the (non-empty) set of equivalence classes of
2274
+ − 499
@{text "R"}. The constraint in this declaration is that the type variables
2237
+ − 500
in the raw type @{text "\<sigma>"} must be included in the type variables @{text
2274
+ − 501
"\<alpha>s"} declared for @{text "\<kappa>\<^isub>q"}. HOL will then provide us with the following
2269
+ − 502
abstraction and representation functions
2182
+ − 503
2443
+ − 504
\begin{isabelle}\ \ \ \ \ %%%
2234
+ − 505
@{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"}
+ − 506
\end{isabelle}
+ − 507
2235
+ − 508
\noindent
2269
+ − 509
As can be seen from the type, they relate the new quotient type and equivalence classes of the raw
2235
+ − 510
type. However, as Homeier \cite{Homeier05} noted, it is much more convenient
+ − 511
to work with the following derived abstraction and representation functions
+ − 512
2443
+ − 513
\begin{isabelle}\ \ \ \ \ %%%
2234
+ − 514
@{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)"}
+ − 515
\end{isabelle}
+ − 516
+ − 517
\noindent
2235
+ − 518
on the expense of having to use Hilbert's choice operator @{text "\<epsilon>"} in the
2237
+ − 519
definition of @{text "Rep_\<kappa>\<^isub>q"}. These derived notions relate the
+ − 520
quotient type and the raw type directly, as can be seen from their type,
+ − 521
namely @{text "\<sigma> \<Rightarrow> \<alpha>s \<kappa>\<^isub>q"} and @{text "\<alpha>s \<kappa>\<^isub>q \<Rightarrow> \<sigma>"},
+ − 522
respectively. Given that @{text "R"} is an equivalence relation, the
2274
+ − 523
following property holds for every quotient type
+ − 524
(for the proof see \cite{Homeier05}).
2237
+ − 525
2258
+ − 526
\begin{proposition}
2445
+ − 527
\begin{isa}@{term "Quotient R Abs_\<kappa>\<^isub>q Rep_\<kappa>\<^isub>q"}.\end{isa}
2258
+ − 528
\end{proposition}
2234
+ − 529
2247
+ − 530
The next step in a quotient construction is to introduce definitions of new constants
+ − 531
involving the quotient type. These definitions need to be given in terms of concepts
2238
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 532
of the raw type (remember this is the only way how to extend HOL
2269
+ − 533
with new definitions). For the user the visible part of such definitions is the declaration
2235
+ − 534
2443
+ − 535
\begin{isabelle}\ \ \ \ \ %%%
2237
+ − 536
\isacommand{quotient\_definition}~~@{text "c :: \<tau>"}~~\isacommand{is}~~@{text "t :: \<sigma>"}
2235
+ − 537
\end{isabelle}
+ − 538
2237
+ − 539
\noindent
+ − 540
where @{text t} is the definiens (its type @{text \<sigma>} can always be inferred)
+ − 541
and @{text "c"} is the name of definiendum, whose type @{text "\<tau>"} needs to be
+ − 542
given explicitly (the point is that @{text "\<tau>"} and @{text "\<sigma>"} can only differ
2269
+ − 543
in places where a quotient and raw type is involved). Two concrete examples are
2188
+ − 544
2443
+ − 545
\begin{isabelle}\ \ \ \ \ %%%
2237
+ − 546
\begin{tabular}{@ {}l}
+ − 547
\isacommand{quotient\_definition}~~@{text "0 :: int"}~~\isacommand{is}~~@{text "(0::nat, 0::nat)"}\\
+ − 548
\isacommand{quotient\_definition}~~@{text "\<Union> :: (\<alpha> fset) fset \<Rightarrow> \<alpha> fset"}~~%
+ − 549
\isacommand{is}~~@{text "flat"}
+ − 550
\end{tabular}
+ − 551
\end{isabelle}
+ − 552
+ − 553
\noindent
+ − 554
The first one declares zero for integers and the second the operator for
2274
+ − 555
building unions of finite sets (@{text "flat"} having the type
+ − 556
@{text "(\<alpha> list) list \<Rightarrow> \<alpha> list"}).
2238
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 557
2413
+ − 558
From such declarations given by the user, the quotient package needs to derive proper
2332
9a560e489c64
polished paper again (and took out some claims about Homeier's package)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 559
definitions using @{text "Abs"} and @{text "Rep"}. The data we rely on is the given quotient type
2247
+ − 560
@{text "\<tau>"} and the raw type @{text "\<sigma>"}. They allow us to define \emph{aggregate
+ − 561
abstraction} and \emph{representation functions} using the functions @{text "ABS (\<sigma>,
2332
9a560e489c64
polished paper again (and took out some claims about Homeier's package)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 562
\<tau>)"} and @{text "REP (\<sigma>, \<tau>)"} whose clauses we shall give below. The idea behind
2274
+ − 563
these two functions is to simultaneously descend into the raw types @{text \<sigma>} and
2247
+ − 564
quotient types @{text \<tau>}, and generate the appropriate
2238
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 565
@{text "Abs"} and @{text "Rep"} in places where the types differ. Therefore
2269
+ − 566
we generate just the identity whenever the types are equal. On the ``way'' down,
+ − 567
however we might have to use map-functions to let @{text Abs} and @{text Rep} act
2274
+ − 568
over the appropriate types. In what follows we use the short-hand notation
2332
9a560e489c64
polished paper again (and took out some claims about Homeier's package)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 569
@{text "ABS (\<sigma>s, \<tau>s)"} to mean @{text "ABS (\<sigma>\<^isub>1, \<tau>\<^isub>1)\<dots>ABS (\<sigma>\<^isub>n, \<tau>\<^isub>n)"}; similarly
2274
+ − 570
for @{text REP}.
+ − 571
%
2227
+ − 572
\begin{center}
2252
+ − 573
\hfill
2444
+ − 574
\begin{tabular}{@ {\hspace{2mm}}l@ {}}
+ − 575
\multicolumn{1}{@ {}l}{equal types:}\\
+ − 576
@{text "ABS (\<sigma>, \<sigma>)"} $\dn$ @{text "id :: \<sigma> \<Rightarrow> \<sigma>"}\\
+ − 577
@{text "REP (\<sigma>, \<sigma>)"} $\dn$ @{text "id :: \<sigma> \<Rightarrow> \<sigma>"}\smallskip\\
+ − 578
\multicolumn{1}{@ {}l}{function types:}\\
+ − 579
@{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)"}\\
+ − 580
@{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\\
+ − 581
\multicolumn{1}{@ {}l}{equal type constructors:}\\
+ − 582
@{text "ABS (\<sigma>s \<kappa>, \<tau>s \<kappa>)"} $\dn$ @{text "map_\<kappa> (ABS (\<sigma>s, \<tau>s))"}\\
+ − 583
@{text "REP (\<sigma>s \<kappa>, \<tau>s \<kappa>)"} $\dn$ @{text "map_\<kappa> (REP (\<sigma>s, \<tau>s))"}\smallskip\\
+ − 584
\multicolumn{1}{@ {}l}{unequal type constructors:}\\
+ − 585
@{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)))"}\\
+ − 586
@{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"}
2247
+ − 587
\end{tabular}\hfill\numbered{ABSREP}
2227
+ − 588
\end{center}
2234
+ − 589
%
2232
+ − 590
\noindent
2445
+ − 591
In the last two clauses are subtle. We rely in them on the fact that the type @{text "\<alpha>s
2238
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 592
\<kappa>\<^isub>q"} is the quotient of the raw type @{text "\<rho>s \<kappa>"} (for example
2237
+ − 593
@{text "int"} and @{text "nat \<times> nat"}, or @{text "\<alpha> fset"} and @{text "\<alpha>
2445
+ − 594
list"}). This data is given by declarations shown in \eqref{typedecl}.
+ − 595
The quotient construction ensures that the type variables in @{text
2367
+ − 596
"\<rho>s \<kappa>"} must be among the @{text "\<alpha>s"}. The @{text "\<sigma>s'"} are given by the
+ − 597
substitutions for the @{text "\<alpha>s"} when matching @{text "\<sigma>s \<kappa>"} against
2445
+ − 598
@{text "\<rho>s \<kappa>"}. This calculation determines what are the types in place
+ − 599
of the type variables @{text "\<alpha>s"} in the instance of
+ − 600
quotient type @{text "\<alpha>s \<kappa>\<^isub>q"}---namely @{text "\<tau>s"}, and the corresponding
+ − 601
types in place of the @{text "\<alpha>s"} in the raw type @{text "\<rho>s \<kappa>"}---namely @{text "\<sigma>s'"}. The
2237
+ − 602
function @{text "MAP"} calculates an \emph{aggregate map-function} for a raw
+ − 603
type as follows:
+ − 604
%
2227
+ − 605
\begin{center}
2444
+ − 606
\begin{tabular}{r@ {\hspace{1mm}}c@ {\hspace{1mm}}l}
2237
+ − 607
@{text "MAP' (\<alpha>)"} & $\dn$ & @{text "a\<^sup>\<alpha>"}\\
2238
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 608
@{text "MAP' (\<kappa>)"} & $\dn$ & @{text "id :: \<kappa> \<Rightarrow> \<kappa>"}\\
2232
+ − 609
@{text "MAP' (\<sigma>s \<kappa>)"} & $\dn$ & @{text "map_\<kappa> (MAP'(\<sigma>s))"}\smallskip\\
2233
+ − 610
@{text "MAP (\<sigma>)"} & $\dn$ & @{text "\<lambda>as. MAP'(\<sigma>)"}
2238
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 611
\end{tabular}
2227
+ − 612
\end{center}
2237
+ − 613
%
2232
+ − 614
\noindent
2366
+ − 615
In this definition we rely on the fact that in the first clause we can interpret type-variables @{text \<alpha>} as
2238
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 616
term variables @{text a}. In the last clause we build an abstraction over all
2274
+ − 617
term-variables of the map-function generated by the auxiliary function
2238
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 618
@{text "MAP'"}.
2274
+ − 619
The need for aggregate map-functions can be seen in cases where we build quotients,
2247
+ − 620
say @{text "(\<alpha>, \<beta>) \<kappa>\<^isub>q"}, out of compound raw types, say @{text "(\<alpha> list) \<times> \<beta>"}.
+ − 621
In this case @{text MAP} generates the
+ − 622
aggregate map-function:
2232
+ − 623
2421
+ − 624
%%% FIXME: Reviewer 2 asks: last two lines defining ABS and REP for
+ − 625
%%% unequal type constructors: How are the $\varrho$s defined? The
+ − 626
%%% following paragraph mentions them, but this paragraph is unclear,
+ − 627
%%% since it then mentions $\alpha$s, which do not seem to be defined
+ − 628
%%% either. As a result, I do not understand the first two sentences
+ − 629
%%% in this paragraph. I can imagine roughly what the following
+ − 630
%%% sentence `The $\sigma$s' are given by the matchers for the
+ − 631
%%% $\alpha$s$ when matching $\varrho$s $\kappa$ against $\sigma$s
+ − 632
%%% $\kappa$.' means, but also think that it is too vague.
+ − 633
2443
+ − 634
\begin{isabelle}\ \ \ \ \ %%%
+ − 635
@{text "\<lambda>a b. map_prod (map_list a) b"}
+ − 636
\end{isabelle}
+ − 637
2233
+ − 638
\noindent
2274
+ − 639
which is essential in order to define the corresponding aggregate
+ − 640
abstraction and representation functions.
2238
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 641
2247
+ − 642
To see how these definitions pan out in practise, let us return to our
+ − 643
example about @{term "concat"} and @{term "fconcat"}, where we have the raw type
+ − 644
@{text "(\<alpha> list) list \<Rightarrow> \<alpha> list"} and the quotient type @{text "(\<alpha> fset) fset \<Rightarrow> \<alpha>
2274
+ − 645
fset"}. Feeding these types into @{text ABS} gives us (after some @{text "\<beta>"}-simplifications)
2247
+ − 646
the abstraction function
2233
+ − 647
2443
+ − 648
\begin{isabelle}\ \ \ \ \ %%%
2444
+ − 649
\begin{tabular}{l}
+ − 650
@{text "(map_list (map_list id \<circ> Rep_fset) \<circ> Rep_fset) \<singlearr>"}\\
+ − 651
\mbox{}\hspace{4.5cm}@{text " Abs_fset \<circ> map_list id"}
+ − 652
\end{tabular}
2443
+ − 653
\end{isabelle}
2233
+ − 654
+ − 655
\noindent
2247
+ − 656
In our implementation we further
+ − 657
simplify this function by rewriting with the usual laws about @{text
2367
+ − 658
"map"}s and @{text "id"}, for example @{term "map_list id = id"} and @{text "f \<circ> id =
2274
+ − 659
id \<circ> f = f"}. This gives us the simpler abstraction function
2237
+ − 660
2443
+ − 661
\begin{isabelle}\ \ \ \ \ %%%
+ − 662
@{text "(map_list Rep_fset \<circ> Rep_fset) \<singlearr> Abs_fset"}
+ − 663
\end{isabelle}
2233
+ − 664
+ − 665
\noindent
+ − 666
which we can use for defining @{term "fconcat"} as follows
+ − 667
2443
+ − 668
\begin{isabelle}\ \ \ \ \ %%%
+ − 669
@{text "\<Union> \<equiv> ((map_list Rep_fset \<circ> Rep_fset) \<singlearr> Abs_fset) flat"}
+ − 670
\end{isabelle}
2232
+ − 671
2237
+ − 672
\noindent
2247
+ − 673
Note that by using the operator @{text "\<singlearr>"} and special clauses
+ − 674
for function types in \eqref{ABSREP}, we do not have to
2252
+ − 675
distinguish between arguments and results, but can deal with them uniformly.
+ − 676
Consequently, all definitions in the quotient package
2238
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 677
are of the general form
2188
+ − 678
2443
+ − 679
\begin{isabelle}\ \ \ \ \ %%%
+ − 680
@{text "c \<equiv> ABS (\<sigma>, \<tau>) t"}
+ − 681
\end{isabelle}
2227
+ − 682
2237
+ − 683
\noindent
2238
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 684
where @{text \<sigma>} is the type of the definiens @{text "t"} and @{text "\<tau>"} the
2247
+ − 685
type of the defined quotient constant @{text "c"}. This data can be easily
+ − 686
generated from the declaration given by the user.
2252
+ − 687
To increase the confidence in this way of making definitions, we can prove
2247
+ − 688
that the terms involved are all typable.
2227
+ − 689
+ − 690
\begin{lemma}
+ − 691
If @{text "ABS (\<sigma>, \<tau>)"} returns some abstraction function @{text "Abs"}
+ − 692
and @{text "REP (\<sigma>, \<tau>)"} some representation function @{text "Rep"},
+ − 693
then @{text "Abs"} is of type @{text "\<sigma> \<Rightarrow> \<tau>"} and @{text "Rep"} of type
+ − 694
@{text "\<tau> \<Rightarrow> \<sigma>"}.
+ − 695
\end{lemma}
2233
+ − 696
2237
+ − 697
\begin{proof}
2274
+ − 698
By mutual induction and analysing the definitions of @{text "ABS"} and @{text "REP"}.
+ − 699
The cases of equal types and function types are
2247
+ − 700
straightforward (the latter follows from @{text "\<singlearr>"} having the
+ − 701
type @{text "(\<alpha> \<Rightarrow> \<beta>) \<Rightarrow> (\<gamma> \<Rightarrow> \<delta>) \<Rightarrow> (\<beta> \<Rightarrow> \<gamma>) \<Rightarrow> (\<alpha> \<Rightarrow> \<delta>)"}). In case of equal type
+ − 702
constructors we can observe that a map-function after applying the functions
+ − 703
@{text "ABS (\<sigma>s, \<tau>s)"} produces a term of type @{text "\<sigma>s \<kappa> \<Rightarrow> \<tau>s \<kappa>"}. The
+ − 704
interesting case is the one with unequal type constructors. Since we know
+ − 705
the quotient is between @{text "\<alpha>s \<kappa>\<^isub>q"} and @{text "\<rho>s \<kappa>"}, we have
+ − 706
that @{text "Abs_\<kappa>\<^isub>q"} is of type @{text "\<rho>s \<kappa> \<Rightarrow> \<alpha>s
+ − 707
\<kappa>\<^isub>q"}. This type can be more specialised to @{text "\<rho>s[\<tau>s] \<kappa> \<Rightarrow> \<tau>s
+ − 708
\<kappa>\<^isub>q"} where the type variables @{text "\<alpha>s"} are instantiated with the
+ − 709
@{text "\<tau>s"}. The complete type can be calculated by observing that @{text
+ − 710
"MAP (\<rho>s \<kappa>)"}, after applying the functions @{text "ABS (\<sigma>s', \<tau>s)"} to it,
+ − 711
returns a term of type @{text "\<rho>s[\<sigma>s'] \<kappa> \<Rightarrow> \<rho>s[\<tau>s] \<kappa>"}. This type is
+ − 712
equivalent to @{text "\<sigma>s \<kappa> \<Rightarrow> \<rho>s[\<tau>s] \<kappa>"}, which we just have to compose with
+ − 713
@{text "\<rho>s[\<tau>s] \<kappa> \<Rightarrow> \<tau>s \<kappa>\<^isub>q"} according to the type of @{text "\<circ>"}.\qed
2237
+ − 714
\end{proof}
2188
+ − 715
*}
+ − 716
2444
+ − 717
section {* Respectfulness and\\ Preservation \label{sec:resp} *}
2188
+ − 718
+ − 719
text {*
2445
+ − 720
\noindent
2247
+ − 721
The main point of the quotient package is to automatically ``lift'' theorems
+ − 722
involving constants over the raw type to theorems involving constants over
2274
+ − 723
the quotient type. Before we can describe this lifting process, we need to impose
2332
9a560e489c64
polished paper again (and took out some claims about Homeier's package)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 724
two restrictions in form of proof obligations that arise during the
2274
+ − 725
lifting. The reason is that even if definitions for all raw constants
+ − 726
can be given, \emph{not} all theorems can be lifted to the quotient type. Most
2287
+ − 727
notable is the bound variable function, that is the constant @{text bn}, defined
2274
+ − 728
for raw lambda-terms as follows
2188
+ − 729
2444
+ − 730
\begin{isabelle}
+ − 731
\begin{center}
2252
+ − 732
@{text "bn (x) \<equiv> \<emptyset>"}\hspace{4mm}
2444
+ − 733
@{text "bn (t\<^isub>1 t\<^isub>2) \<equiv> bn (t\<^isub>1) \<union> bn (t\<^isub>2)"}\smallskip\\
2247
+ − 734
@{text "bn (\<lambda>x. t) \<equiv> {x} \<union> bn (t)"}
2444
+ − 735
\end{center}
2247
+ − 736
\end{isabelle}
2238
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 737
2247
+ − 738
\noindent
2274
+ − 739
We can generate a definition for this constant using @{text ABS} and @{text REP}.
+ − 740
But this constant does \emph{not} respect @{text "\<alpha>"}-equivalence and
2247
+ − 741
consequently no theorem involving this constant can be lifted to @{text
+ − 742
"\<alpha>"}-equated lambda terms. Homeier formulates the restrictions in terms of
2277
+ − 743
the properties of \emph{respectfulness} and \emph{preservation}. We have
2258
+ − 744
to slightly extend Homeier's definitions in order to deal with quotient
2247
+ − 745
compositions.
+ − 746
2422
+ − 747
%%% FIXME: Reviewer 3 asks why are the definitions that follow enough to deal
+ − 748
%%% with quotient composition.
+ − 749
2247
+ − 750
To formally define what respectfulness is, we have to first define
2419
+ − 751
the notion of \emph{aggregate equivalence relations} using the function @{text "REL(\<sigma>, \<tau>)"}
+ − 752
The idea behind this function is to simultaneously descend into the raw types
+ − 753
@{text \<sigma>} and quotient types @{text \<tau>}, and generate the appropriate
+ − 754
quotient equivalence relations in places where the types differ and equalities
+ − 755
elsewhere.
2274
+ − 756
+ − 757
\begin{center}
+ − 758
\hfill
2444
+ − 759
\begin{tabular}{l}
+ − 760
\multicolumn{1}{@ {}l}{equal types:}\\
+ − 761
@{text "REL (\<sigma>, \<sigma>)"} $\dn$ @{text "= :: \<sigma> \<Rightarrow> \<sigma> \<Rightarrow> bool"}\smallskip\\
+ − 762
\multicolumn{1}{@ {}l}{equal type constructors:}\\
+ − 763
@{text "REL (\<sigma>s \<kappa>, \<tau>s \<kappa>)"} $\dn$ @{text "rel_\<kappa> (REL (\<sigma>s, \<tau>s))"}\smallskip\\
+ − 764
\multicolumn{1}{@ {}l}{unequal type constructors:}\\
+ − 765
@{text "REL (\<sigma>s \<kappa>, \<tau>s \<kappa>\<^isub>q)"} $\dn$ @{text "rel_\<kappa>\<^isub>q (REL (\<sigma>s', \<tau>s))"}\\
2274
+ − 766
\end{tabular}\hfill\numbered{REL}
+ − 767
\end{center}
2238
8ddf1330f2ed
completed proof and started section about respectfulness and preservation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 768
2274
+ − 769
\noindent
+ − 770
The @{text "\<sigma>s'"} in the last clause are calculated as in \eqref{ABSREP}:
2444
+ − 771
again we know that type @{text "\<alpha>s \<kappa>\<^isub>q"} is the quotient of the raw type
2367
+ − 772
@{text "\<rho>s \<kappa>"}. The @{text "\<sigma>s'"} are the substitutions for @{text "\<alpha>s"} obtained by matching
2274
+ − 773
@{text "\<rho>s \<kappa>"} and @{text "\<sigma>s \<kappa>"}.
+ − 774
2332
9a560e489c64
polished paper again (and took out some claims about Homeier's package)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 775
Let us return to the lifting procedure of theorems. Assume we have a theorem
2274
+ − 776
that contains the raw constant @{text "c\<^isub>r :: \<sigma>"} and which we want to
+ − 777
lift to a theorem where @{text "c\<^isub>r"} is replaced by the corresponding
+ − 778
constant @{text "c\<^isub>q :: \<tau>"} defined over a quotient type. In this situation
2287
+ − 779
we generate the following proof obligation
2274
+ − 780
2443
+ − 781
\begin{isabelle}\ \ \ \ \ %%%
+ − 782
@{text "REL (\<sigma>, \<tau>) c\<^isub>r c\<^isub>r"}
+ − 783
\end{isabelle}
2258
+ − 784
2274
+ − 785
\noindent
2277
+ − 786
Homeier calls these proof obligations \emph{respectfulness
2278
+ − 787
theorems}. However, unlike his quotient package, we might have several
+ − 788
respectfulness theorems for one constant---he has at most one.
+ − 789
The reason is that because of our quotient compositions, the types
2416
12283a96e851
The type does determine respectfulness, the constant without an instantiated type does not.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 790
@{text \<sigma>} and @{text \<tau>} are not completely determined by @{text "c\<^bsub>r\<^esub>"}.
12283a96e851
The type does determine respectfulness, the constant without an instantiated type does not.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 791
And for every instantiation of the types, a corresponding
12283a96e851
The type does determine respectfulness, the constant without an instantiated type does not.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 792
respectfulness theorem is necessary.
2278
+ − 793
+ − 794
Before lifting a theorem, we require the user to discharge
2332
9a560e489c64
polished paper again (and took out some claims about Homeier's package)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 795
respectfulness proof obligations. In case of @{text bn}
9a560e489c64
polished paper again (and took out some claims about Homeier's package)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 796
this obligation is as follows
2274
+ − 797
2443
+ − 798
\begin{isabelle}\ \ \ \ \ %%%
+ − 799
@{text "(\<approx>\<^isub>\<alpha> \<doublearr> =) bn bn"}
+ − 800
\end{isabelle}
2274
+ − 801
+ − 802
\noindent
2332
9a560e489c64
polished paper again (and took out some claims about Homeier's package)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 803
and the point is that the user cannot discharge it: because it is not true. To see this,
2274
+ − 804
we can just unfold the definition of @{text "\<doublearr>"} \eqref{relfun}
2412
+ − 805
using extensionality to obtain the false statement
2274
+ − 806
2443
+ − 807
\begin{isabelle}\ \ \ \ \ %%%
+ − 808
@{text "\<forall>t\<^isub>1 t\<^isub>2. if t\<^isub>1 \<approx>\<^isub>\<alpha> t\<^isub>2 then bn(t\<^isub>1) = bn(t\<^isub>2)"}
+ − 809
\end{isabelle}
+ − 810
2274
+ − 811
\noindent
+ − 812
In contrast, if we lift a theorem about @{text "append"} to a theorem describing
+ − 813
the union of finite sets, then we need to discharge the proof obligation
+ − 814
2443
+ − 815
\begin{isabelle}\ \ \ \ \ %%%
+ − 816
@{text "(\<approx>\<^bsub>list\<^esub> \<doublearr> \<approx>\<^bsub>list\<^esub> \<doublearr> \<approx>\<^bsub>list\<^esub>) append append"}
+ − 817
\end{isabelle}
2275
69b80ad616c5
finished section 4, but put some things I do not understand on comment
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 818
69b80ad616c5
finished section 4, but put some things I do not understand on comment
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 819
\noindent
69b80ad616c5
finished section 4, but put some things I do not understand on comment
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 820
To do so, we have to establish
69b80ad616c5
finished section 4, but put some things I do not understand on comment
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 821
2443
+ − 822
\begin{isabelle}\ \ \ \ \ %%%
2287
+ − 823
if @{text "xs \<approx>\<^bsub>list\<^esub> ys"} and @{text "us \<approx>\<^bsub>list\<^esub> vs"}
+ − 824
then @{text "xs @ us \<approx>\<^bsub>list\<^esub> ys @ vs"}
2275
69b80ad616c5
finished section 4, but put some things I do not understand on comment
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 825
\end{isabelle}
69b80ad616c5
finished section 4, but put some things I do not understand on comment
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 826
69b80ad616c5
finished section 4, but put some things I do not understand on comment
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 827
\noindent
69b80ad616c5
finished section 4, but put some things I do not understand on comment
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 828
which is straightforward given the definition shown in \eqref{listequiv}.
69b80ad616c5
finished section 4, but put some things I do not understand on comment
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 829
2333
+ − 830
The second restriction we have to impose arises from non-lifted polymorphic
+ − 831
constants, which are instantiated to a type being quotient. For example,
+ − 832
take the @{term "cons"}-constructor to add a pair of natural numbers to a
+ − 833
list, whereby we assume the pair of natural numbers turns into an integer in
+ − 834
the quotient construction. The point is that we still want to use @{text
+ − 835
cons} for adding integers to lists---just with a different type. To be able
+ − 836
to lift such theorems, we need a \emph{preservation property} for @{text
+ − 837
cons}. Assuming we have a polymorphic raw constant @{text "c\<^isub>r :: \<sigma>"}
+ − 838
and a corresponding quotient constant @{text "c\<^isub>q :: \<tau>"}, then a
+ − 839
preservation property is as follows
+ − 840
2421
+ − 841
%%% FIXME: Reviewer 2 asks: You say what a preservation theorem is,
+ − 842
%%% but not which preservation theorems you assume. Do you generate a
+ − 843
%%% proof obligation for a preservation theorem for each raw constant
+ − 844
%%% and its corresponding lifted constant?
+ − 845
+ − 846
%%% Cezary: I think this would be a nice thing to do but we have not
+ − 847
%%% done it, the theorems need to be 'guessed' from the remaining obligations
2275
69b80ad616c5
finished section 4, but put some things I do not understand on comment
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 848
2443
+ − 849
\begin{isabelle}\ \ \ \ \ %%%
+ − 850
@{text "Quotient R\<^bsub>\<alpha>s\<^esub> Abs\<^bsub>\<alpha>s\<^esub> Rep\<^bsub>\<alpha>s\<^esub> implies ABS (\<sigma>, \<tau>) c\<^isub>r = c\<^isub>r"}
+ − 851
\end{isabelle}
2275
69b80ad616c5
finished section 4, but put some things I do not understand on comment
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 852
69b80ad616c5
finished section 4, but put some things I do not understand on comment
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 853
\noindent
69b80ad616c5
finished section 4, but put some things I do not understand on comment
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 854
where the @{text "\<alpha>s"} stand for the type variables in the type of @{text "c\<^isub>r"}.
2278
+ − 855
In case of @{text cons} (which has type @{text "\<alpha> \<Rightarrow> \<alpha> list \<Rightarrow> \<alpha> list"}) we have
2275
69b80ad616c5
finished section 4, but put some things I do not understand on comment
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 856
2443
+ − 857
\begin{isabelle}\ \ \ \ \ %%%
2445
+ − 858
@{text "(Rep \<singlearr> map_list Rep \<singlearr> map_list Abs) cons = cons"}
2443
+ − 859
\end{isabelle}
2274
+ − 860
+ − 861
\noindent
2445
+ − 862
under the assumption @{text "Quotient R Abs Rep"}. The point is that if we have
2278
+ − 863
an instance of @{text cons} where the type variable @{text \<alpha>} is instantiated
+ − 864
with @{text "nat \<times> nat"} and we also quotient this type to yield integers,
2445
+ − 865
then we need to show this preservation property.
2274
+ − 866
2279
+ − 867
%%%@ {thm [display, indent=10] insert_preserve2[no_vars]}
2189
+ − 868
2278
+ − 869
%Given two quotients, one of which quotients a container, and the
+ − 870
%other quotients the type in the container, we can write the
+ − 871
%composition of those quotients. To compose two quotient theorems
+ − 872
%we compose the relations with relation composition as defined above
+ − 873
%and the abstraction and relation functions are the ones of the sub
+ − 874
%quotients composed with the usual function composition.
+ − 875
%The @ {term "Rep"} and @ {term "Abs"} functions that we obtain agree
+ − 876
%with the definition of aggregate Abs/Rep functions and the
+ − 877
%relation is the same as the one given by aggregate relations.
+ − 878
%This becomes especially interesting
+ − 879
%when we compose the quotient with itself, as there is no simple
+ − 880
%intermediate step.
+ − 881
%
+ − 882
%Lets take again the example of @ {term flat}. To be able to lift
+ − 883
%theorems that talk about it we provide the composition quotient
+ − 884
%theorem which allows quotienting inside the container:
+ − 885
%
+ − 886
%If @ {term R} is an equivalence relation and @ {term "Quotient R Abs Rep"}
+ − 887
%then
+ − 888
%
2367
+ − 889
%@ {text [display, indent=10] "Quotient (list_rel R \<circ>\<circ>\<circ> \<approx>\<^bsub>list\<^esub>) (abs_fset \<circ> map_list Abs) (map_list Rep o rep_fset)"}
2275
69b80ad616c5
finished section 4, but put some things I do not understand on comment
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 890
%%%
69b80ad616c5
finished section 4, but put some things I do not understand on comment
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 891
%%%\noindent
69b80ad616c5
finished section 4, but put some things I do not understand on comment
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 892
%%%this theorem will then instantiate the quotients needed in the
69b80ad616c5
finished section 4, but put some things I do not understand on comment
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 893
%%%injection and cleaning proofs allowing the lifting procedure to
69b80ad616c5
finished section 4, but put some things I do not understand on comment
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 894
%%%proceed in an unchanged way.
2192
+ − 895
*}
+ − 896
2256
+ − 897
section {* Lifting of Theorems\label{sec:lift} *}
1978
+ − 898
2194
+ − 899
text {*
2271
+ − 900
2422
+ − 901
%%% FIXME Reviewer 3 asks: Section 5 shows the technicalities of
+ − 902
%%% lifting theorems. But there is no clarification about the
+ − 903
%%% correctness. A reader would also be interested in seeing some
+ − 904
%%% discussions about the generality and limitation of the approach
+ − 905
%%% proposed there
+ − 906
2445
+ − 907
\noindent
2278
+ − 908
The main benefit of a quotient package is to lift automatically theorems over raw
+ − 909
types to theorems over quotient types. We will perform this lifting in
+ − 910
three phases, called \emph{regularization},
2287
+ − 911
\emph{injection} and \emph{cleaning} according to procedures in Homeier's ML-code.
2445
+ − 912
Space restrictions, unfortunately, prevent us from giving anything but a sketch of these three
+ − 913
phases. However, we will precisely define the input and output data of these phases
+ − 914
(this was omitted in \cite{Homeier05}).
2271
+ − 915
2278
+ − 916
The purpose of regularization is to change the quantifiers and abstractions
2412
+ − 917
in a ``raw'' theorem to quantifiers over variables that respect their respective relations
2279
+ − 918
(Definition \ref{def:respects} states what respects means). The purpose of injection is to add @{term Rep}
2271
+ − 919
and @{term Abs} of appropriate types in front of constants and variables
2332
9a560e489c64
polished paper again (and took out some claims about Homeier's package)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 920
of the raw type so that they can be replaced by the corresponding constants from the
2279
+ − 921
quotient type. The purpose of cleaning is to bring the theorem derived in the
+ − 922
first two phases into the form the user has specified. Abstractly, our
+ − 923
package establishes the following three proof steps:
+ − 924
2421
+ − 925
%%% FIXME: Reviewer 1 complains that the reader needs to guess the
+ − 926
%%% meaning of reg_thm and inj_thm, as well as the arguments of REG
+ − 927
%%% which are given above. I wouldn't change it.
+ − 928
2279
+ − 929
\begin{center}
2369
+ − 930
\begin{tabular}{l@ {\hspace{4mm}}l}
2371
+ − 931
1.) Regularization & @{text "raw_thm \<longrightarrow> reg_thm"}\\
2369
+ − 932
2.) Injection & @{text "reg_thm \<longleftrightarrow> inj_thm"}\\
+ − 933
3.) Cleaning & @{text "inj_thm \<longleftrightarrow> quot_thm"}\\
2279
+ − 934
\end{tabular}
+ − 935
\end{center}
2193
+ − 936
2279
+ − 937
\noindent
2371
+ − 938
which means, stringed together, the raw theorem implies the quotient theorem.
+ − 939
In contrast to other quotient packages, our package requires that the user specifies
+ − 940
both, the @{text "raw_thm"} (as theorem) and the \emph{term} of the @{text "quot_thm"}.\footnote{Though we
2279
+ − 941
also provide a fully automated mode, where the @{text "quot_thm"} is guessed
2371
+ − 942
from the form of @{text "raw_thm"}.} As a result, the user has fine control
+ − 943
over which parts of a raw theorem should be lifted.
2279
+ − 944
2371
+ − 945
The second and third proof step performed in package will always succeed if the appropriate
2279
+ − 946
respectfulness and preservation theorems are given. In contrast, the first
+ − 947
proof step can fail: a theorem given by the user does not always
2319
+ − 948
imply a regularized version and a stronger one needs to be proved. An example
2287
+ − 949
for this kind of failure is the simple statement for integers @{text "0 \<noteq> 1"}.
+ − 950
One might hope that it can be proved by lifting @{text "(0, 0) \<noteq> (1, 0)"},
2371
+ − 951
but this raw theorem only shows that two particular elements in the
2319
+ − 952
equivalence classes are not equal. In order to obtain @{text "0 \<noteq> 1"}, a
+ − 953
more general statement stipulating that the equivalence classes are not
+ − 954
equal is necessary. This kind of failure is beyond the scope where the
+ − 955
quotient package can help: the user has to provide a raw theorem that
+ − 956
can be regularized automatically, or has to provide an explicit proof
2445
+ − 957
for the first proof step. Homeier gives more details about this issue
+ − 958
in the long version of \cite{Homeier05}.
2193
+ − 959
2271
+ − 960
In the following we will first define the statement of the
2280
229660b9f2fc
Fix regularization. Two "FIXME" left in introduction. Minor spellings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 961
regularized theorem based on @{text "raw_thm"} and
2279
+ − 962
@{text "quot_thm"}. Then we define the statement of the injected theorem, based
2287
+ − 963
on @{text "reg_thm"} and @{text "quot_thm"}. We then show the three proof steps,
2279
+ − 964
which can all be performed independently from each other.
2197
+ − 965
2373
+ − 966
We first define the function @{text REG}, which takes the terms of the
2371
+ − 967
@{text "raw_thm"} and @{text "quot_thm"} as input and returns
2373
+ − 968
@{text "reg_thm"}. The idea
2207
+ − 969
behind this function is that it replaces quantifiers and
+ − 970
abstractions involving raw types by bounded ones, and equalities
2373
+ − 971
involving raw types by appropriate aggregate
2445
+ − 972
equivalence relations. It is defined by simultaneous recursion on
+ − 973
the structure of the terms of @{text "raw_thm"} and @{text "quot_thm"} as follows:
+ − 974
%
2244
+ − 975
\begin{center}
2445
+ − 976
\begin{tabular}{@ {}l@ {}}
+ − 977
\multicolumn{1}{@ {}l@ {}}{abstractions:}\smallskip\\
2444
+ − 978
@{text "REG (\<lambda>x\<^sup>\<sigma>. t, \<lambda>x\<^sup>\<tau>. s)"} $\dn$
2273
+ − 979
$\begin{cases}
+ − 980
@{text "\<lambda>x\<^sup>\<sigma>. REG (t, s)"} \quad\mbox{provided @{text "\<sigma> = \<tau>"}}\\
2445
+ − 981
@{text "\<lambda>x\<^sup>\<sigma> \<in> Resp (REL (\<sigma>, \<tau>)). REG (t, s)"}
2273
+ − 982
\end{cases}$\smallskip\\
2445
+ − 983
\multicolumn{1}{@ {}l@ {}}{universal quantifiers:}\\
2444
+ − 984
@{text "REG (\<forall>x\<^sup>\<sigma>. t, \<forall>x\<^sup>\<tau>. s)"} $\dn$
2273
+ − 985
$\begin{cases}
+ − 986
@{text "\<forall>x\<^sup>\<sigma>. REG (t, s)"} \quad\mbox{provided @{text "\<sigma> = \<tau>"}}\\
2445
+ − 987
@{text "\<forall>x\<^sup>\<sigma> \<in> Resp (REL (\<sigma>, \<tau>)). REG (t, s)"}
2273
+ − 988
\end{cases}$\smallskip\\
2445
+ − 989
\multicolumn{1}{@ {}l@ {}}{equality:}\smallskip\\
2280
229660b9f2fc
Fix regularization. Two "FIXME" left in introduction. Minor spellings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 990
%% REL of two equal types is the equality so we do not need a separate case
2445
+ − 991
@{text "REG (=\<^bsup>\<sigma>\<Rightarrow>\<sigma>\<Rightarrow>bool\<^esup>, =\<^bsup>\<tau>\<Rightarrow>\<tau>\<Rightarrow>bool\<^esup>)"} $\dn$ @{text "REL (\<sigma>, \<tau>)"}\smallskip\\
+ − 992
\multicolumn{1}{@ {}l@ {}}{applications, variables and constants:}\\
2444
+ − 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)"}\\
+ − 994
@{text "REG (x\<^isub>1, x\<^isub>2)"} $\dn$ @{text "x\<^isub>1"}\\
+ − 995
@{text "REG (c\<^isub>1, c\<^isub>2)"} $\dn$ @{text "c\<^isub>1"}\\
2371
+ − 996
\end{tabular}
2244
+ − 997
\end{center}
2273
+ − 998
%
+ − 999
\noindent
2230
+ − 1000
In the above definition we omitted the cases for existential quantifiers
2207
+ − 1001
and unique existential quantifiers, as they are very similar to the cases
2376
+ − 1002
for the universal quantifier.
2279
+ − 1003
+ − 1004
Next we define the function @{text INJ} which takes as argument
+ − 1005
@{text "reg_thm"} and @{text "quot_thm"} (both as
+ − 1006
terms) and returns @{text "inj_thm"}:
2198
+ − 1007
2245
+ − 1008
\begin{center}
2444
+ − 1009
\begin{tabular}{l}
+ − 1010
\multicolumn{1}{@ {}l}{abstractions:}\\
+ − 1011
@{text "INJ (\<lambda>x. t :: \<sigma>, \<lambda>x. s :: \<tau>) "} $\dn$\\
+ − 1012
\hspace{18mm}$\begin{cases}
2273
+ − 1013
@{text "\<lambda>x. INJ (t, s)"} \quad\mbox{provided @{text "\<sigma> = \<tau>"}}\\
+ − 1014
@{text "REP (\<sigma>, \<tau>) (ABS (\<sigma>, \<tau>) (\<lambda>x. INJ (t, s)))"}
2444
+ − 1015
\end{cases}$\smallskip\\
+ − 1016
@{text "INJ (\<lambda>x \<in> R. t :: \<sigma>, \<lambda>x. s :: \<tau>) "} $\dn$\\
+ − 1017
\hspace{18mm}@{text "REP (\<sigma>, \<tau>) (ABS (\<sigma>, \<tau>) (\<lambda>x \<in> R. INJ (t, s)))"}\smallskip\\
+ − 1018
\multicolumn{1}{@ {}l}{universal quantifiers:}\\
+ − 1019
@{text "INJ (\<forall> t, \<forall> s) "} $\dn$ @{text "\<forall> INJ (t, s)"}\\
+ − 1020
@{text "INJ (\<forall> t \<in> R, \<forall> s) "} $\dn$ @{text "\<forall> INJ (t, s) \<in> R"}\smallskip\\
+ − 1021
\multicolumn{1}{@ {}l}{applications, variables and constants:}\smallskip\\
+ − 1022
@{text "INJ (t\<^isub>1 t\<^isub>2, s\<^isub>1 s\<^isub>2) "} $\dn$ @{text " INJ (t\<^isub>1, s\<^isub>1) INJ (t\<^isub>2, s\<^isub>2)"}\\
+ − 1023
@{text "INJ (x\<^isub>1\<^sup>\<sigma>, x\<^isub>2\<^sup>\<tau>) "} $\dn$
2273
+ − 1024
$\begin{cases}
+ − 1025
@{text "x\<^isub>1"} \quad\mbox{provided @{text "\<sigma> = \<tau>"}}\\
+ − 1026
@{text "REP (\<sigma>, \<tau>) (ABS (\<sigma>, \<tau>) x\<^isub>1)"}\\
+ − 1027
\end{cases}$\\
2444
+ − 1028
@{text "INJ (c\<^isub>1\<^sup>\<sigma>, c\<^isub>2\<^sup>\<tau>) "} $\dn$
2273
+ − 1029
$\begin{cases}
+ − 1030
@{text "c\<^isub>1"} \quad\mbox{provided @{text "\<sigma> = \<tau>"}}\\
+ − 1031
@{text "REP (\<sigma>, \<tau>) (ABS (\<sigma>, \<tau>) c\<^isub>1)"}\\
+ − 1032
\end{cases}$\\
2245
+ − 1033
\end{tabular}
+ − 1034
\end{center}
2198
+ − 1035
2279
+ − 1036
\noindent
2319
+ − 1037
In this definition we again omitted the cases for existential and unique existential
2376
+ − 1038
quantifiers.
2208
+ − 1039
2421
+ − 1040
%%% FIXME: Reviewer2 citing following sentence: You mention earlier
+ − 1041
%%% that this implication may fail to be true. Does that meant that
+ − 1042
%%% the `first proof step' is a heuristic that proves the implication
+ − 1043
%%% raw_thm \implies reg_thm in some instances, but fails in others?
+ − 1044
%%% You should clarify under which circumstances the implication is
+ − 1045
%%% being proved here.
2423
+ − 1046
%%% Cezary: It would be nice to cite Homeiers discussions in the
+ − 1047
%%% Quotient Package manual from HOL (the longer paper), do you agree?
2421
+ − 1048
2445
+ − 1049
In the first phase, establishing @{text "raw_thm \<longrightarrow> reg_thm"}, we always
2279
+ − 1050
start with an implication. Isabelle provides \emph{mono} rules that can split up
2319
+ − 1051
the implications into simpler implicational subgoals. This succeeds for every
2332
9a560e489c64
polished paper again (and took out some claims about Homeier's package)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1052
monotone connective, except in places where the function @{text REG} replaced,
2445
+ − 1053
for instance, a quantifier by a bounded quantifier. To decompose them, we have
+ − 1054
to prove that the relations involved are aggregate equivalence relations.
2208
+ − 1055
2445
+ − 1056
+ − 1057
%In this case we have
+ − 1058
%rules of the form
+ − 1059
%
+ − 1060
% \begin{isabelle}\ \ \ \ \ %%%
+ − 1061
%@{text "(\<forall>x. R x \<longrightarrow> (P x \<longrightarrow> Q x)) \<longrightarrow> (\<forall>x. P x \<longrightarrow> \<forall>x \<in> R. Q x)"}
+ − 1062
%\end{isabelle}
2279
+ − 1063
2445
+ − 1064
%\noindent
+ − 1065
%They decompose a bounded quantifier on the right-hand side. We can decompose a
+ − 1066
%bounded quantifier anywhere if R is an equivalence relation or
+ − 1067
%if it is a relation over function types with the range being an equivalence
+ − 1068
%relation. If @{text R} is an equivalence relation we can prove that
2261
+ − 1069
2445
+ − 1070
%\begin{isabelle}\ \ \ \ \ %%%
+ − 1071
%@{text "\<forall>x \<in> Resp R. P x = \<forall>x. P x"}
+ − 1072
%\end{isabelle}
2199
+ − 1073
2445
+ − 1074
%\noindent
+ − 1075
%If @{term R\<^isub>2} is an equivalence relation, we can prove that for any predicate @{term P}
2231
+ − 1076
2421
+ − 1077
%%% FIXME Reviewer 1 claims the theorem is obviously false so maybe we
+ − 1078
%%% should include a proof sketch?
+ − 1079
2445
+ − 1080
%\begin{isabelle}\ \ \ \ \ %%%
+ − 1081
%@{thm (concl) ball_reg_eqv_range[of R\<^isub>1 R\<^isub>2, no_vars]}
+ − 1082
%\end{isabelle}
2209
+ − 1083
2445
+ − 1084
%\noindent
+ − 1085
%The last theorem is new in comparison with Homeier's package. There the
+ − 1086
%injection procedure would be used to prove such goals and
+ − 1087
%the assumption about the equivalence relation would be used. We use the above theorem directly,
+ − 1088
%because this allows us to completely separate the first and the second
+ − 1089
%proof step into two independent ``units''.
2206
+ − 1090
2445
+ − 1091
The second phase, establishing @{text "reg_thm \<longleftrightarrow> inj_thm"}, starts with an equality
2412
+ − 1092
between the terms of the regularized theorem and the injected theorem.
2279
+ − 1093
The proof again follows the structure of the
2445
+ − 1094
two underlying terms taking respectfulness theorems into account.
2199
+ − 1095
2445
+ − 1096
%\begin{itemize}
+ − 1097
%\item For two constants an appropriate respectfulness theorem is applied.
+ − 1098
%\item For two variables, we use the assumptions proved in the regularization step.
+ − 1099
%\item For two abstractions, we @{text "\<eta>"}-expand and @{text "\<beta>"}-reduce them.
+ − 1100
%\item For two applications, we check that the right-hand side is an application of
+ − 1101
% @{term Rep} to an @{term Abs} and @{term "Quotient R Rep Abs"} holds. If yes then we
+ − 1102
% can apply the theorem:
2271
+ − 1103
2445
+ − 1104
%\begin{isabelle}\ \ \ \ \ %%%
+ − 1105
% @{term "R x y \<longrightarrow> R x (Rep (Abs y))"}
+ − 1106
%\end{isabelle}
2271
+ − 1107
2445
+ − 1108
% Otherwise we introduce an appropriate relation between the subterms
+ − 1109
% and continue with two subgoals using the lemma:
2271
+ − 1110
2445
+ − 1111
%\begin{isabelle}\ \ \ \ \ %%%
+ − 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)"}
+ − 1113
%\end{isabelle}
+ − 1114
%\end{itemize}
2199
+ − 1115
2279
+ − 1116
We defined the theorem @{text "inj_thm"} in such a way that
2445
+ − 1117
establishing in the third phase the equivalence @{text "inj_thm \<longleftrightarrow> quot_thm"} can be
2279
+ − 1118
achieved by rewriting @{text "inj_thm"} with the preservation theorems and quotient
2445
+ − 1119
definitions. This step also requires that the definitions of all lifted constants
+ − 1120
are used to fold the @{term Rep} with the raw constants. We will give more details
+ − 1121
about our lifting procedure in a longer version of this paper.
+ − 1122
+ − 1123
%Next for
+ − 1124
%all abstractions and quantifiers the lambda and
+ − 1125
%quantifier preservation theorems are used to replace the
+ − 1126
%variables that include raw types with respects by quantifiers
+ − 1127
%over variables that include quotient types. We show here only
+ − 1128
%the lambda preservation theorem. Given
+ − 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:
2211
+ − 1130
2445
+ − 1131
%\begin{isabelle}\ \ \ \ \ %%%
+ − 1132
%@{thm (concl) lambda_prs[of _ "Abs\<^isub>1" "Rep\<^isub>1" _ "Abs\<^isub>2" "Rep\<^isub>2", no_vars]}
+ − 1133
%\end{isabelle}
2199
+ − 1134
2445
+ − 1135
%\noindent
+ − 1136
%Next, relations over lifted types can be rewritten to equalities
+ − 1137
%over lifted type. Rewriting is performed with the following theorem,
+ − 1138
%which has been shown by Homeier~\cite{Homeier05}:
2211
+ − 1139
2445
+ − 1140
%\begin{isabelle}\ \ \ \ \ %%%
+ − 1141
%@{thm (concl) Quotient_rel_rep[no_vars]}
+ − 1142
%\end{isabelle}
2199
+ − 1143
2445
+ − 1144
+ − 1145
%Finally, we rewrite with the preservation theorems. This will result
+ − 1146
%in two equal terms that can be solved by reflexivity.
+ − 1147
*}
1994
+ − 1148
2376
+ − 1149
2274
+ − 1150
section {* Examples \label{sec:examples} *}
1994
+ − 1151
2421
+ − 1152
text {*
2206
+ − 1153
2421
+ − 1154
%%% FIXME Reviewer 1 would like an example of regularized and injected
+ − 1155
%%% statements. He asks for the examples twice, but I would still ignore
+ − 1156
%%% it due to lack of space...
2210
+ − 1157
2445
+ − 1158
\noindent
2332
9a560e489c64
polished paper again (and took out some claims about Homeier's package)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1159
In this section we will show a sequence of declarations for defining the
9a560e489c64
polished paper again (and took out some claims about Homeier's package)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1160
type of integers by quotienting pairs of natural numbers, and
9a560e489c64
polished paper again (and took out some claims about Homeier's package)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1161
lifting one theorem.
2210
+ − 1162
2240
+ − 1163
A user of our quotient package first needs to define a relation on
2332
9a560e489c64
polished paper again (and took out some claims about Homeier's package)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1164
the raw type with which the quotienting will be performed. We give
2279
+ − 1165
the same integer relation as the one presented in \eqref{natpairequiv}:
2240
+ − 1166
2443
+ − 1167
\begin{isabelle}\ \ \ \ \ %
2279
+ − 1168
\begin{tabular}{@ {}l}
+ − 1169
\isacommand{fun}~~@{text "int_rel :: (nat \<times> nat) \<Rightarrow> (nat \<times> nat) \<Rightarrow> (nat \<times> nat)"}\\
+ − 1170
\isacommand{where}~~@{text "int_rel (m, n) (p, q) = (m + q = n + p)"}
+ − 1171
\end{tabular}
2239
+ − 1172
\end{isabelle}
2210
+ − 1173
2239
+ − 1174
\noindent
2332
9a560e489c64
polished paper again (and took out some claims about Homeier's package)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1175
Next the quotient type must be defined. This generates a proof obligation that the
2279
+ − 1176
relation is an equivalence relation, which is solved automatically using the
2332
9a560e489c64
polished paper again (and took out some claims about Homeier's package)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1177
definition of equivalence and extensionality:
2210
+ − 1178
2443
+ − 1179
\begin{isabelle}\ \ \ \ \ %
2279
+ − 1180
\begin{tabular}{@ {}l}
+ − 1181
\isacommand{quotient\_type}~~@{text "int"}~~\isacommand{=}~~@{text "(nat \<times> nat)"}~~\isacommand{/}~~@{text "int_rel"}\\
+ − 1182
\hspace{5mm}@{text "by (auto simp add: equivp_def expand_fun_eq)"}
+ − 1183
\end{tabular}
2239
+ − 1184
\end{isabelle}
2210
+ − 1185
2239
+ − 1186
\noindent
2210
+ − 1187
The user can then specify the constants on the quotient type:
+ − 1188
2443
+ − 1189
\begin{isabelle}\ \ \ \ \ %
2240
+ − 1190
\begin{tabular}{@ {}l}
2279
+ − 1191
\isacommand{quotient\_definition}~~@{text "0 :: int"}~~\isacommand{is}~~@{text "(0 :: nat, 0 :: nat)"}\\[3mm]
2443
+ − 1192
\isacommand{fun}~~@{text "add_pair"}\\
+ − 1193
\isacommand{where}~~%
2287
+ − 1194
@{text "add_pair (m, n) (p, q) \<equiv> (m + p :: nat, n + q :: nat)"}\\
2273
+ − 1195
\isacommand{quotient\_definition}~~@{text "+ :: int \<Rightarrow> int \<Rightarrow> int"}~~%
2287
+ − 1196
\isacommand{is}~~@{text "add_pair"}\\
2240
+ − 1197
\end{tabular}
+ − 1198
\end{isabelle}
2210
+ − 1199
2240
+ − 1200
\noindent
2279
+ − 1201
The following theorem about addition on the raw level can be proved.
2210
+ − 1202
2443
+ − 1203
\begin{isabelle}\ \ \ \ \ %
2287
+ − 1204
\isacommand{lemma}~~@{text "add_pair_zero: int_rel (add_pair (0, 0) x) x"}
2240
+ − 1205
\end{isabelle}
2210
+ − 1206
2240
+ − 1207
\noindent
2413
+ − 1208
If the user lifts this theorem, the quotient package performs all the lifting
+ − 1209
automatically leaving the respectfulness proof for the constant @{text "add_pair"}
+ − 1210
as the only remaining proof obligation. This property needs to be proved by the user:
2210
+ − 1211
2443
+ − 1212
\begin{isabelle}\ \ \ \ \ %
2279
+ − 1213
\begin{tabular}{@ {}l}
2287
+ − 1214
\isacommand{lemma}~~@{text "[quot_respect]:"}\\
+ − 1215
@{text "(int_rel \<doublearr> int_rel \<doublearr> int_rel) add_pair add_pair"}
2279
+ − 1216
\end{tabular}
2240
+ − 1217
\end{isabelle}
+ − 1218
+ − 1219
\noindent
2413
+ − 1220
It can be discharged automatically by Isabelle when hinting to unfold the definition
2273
+ − 1221
of @{text "\<doublearr>"}.
2332
9a560e489c64
polished paper again (and took out some claims about Homeier's package)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1222
After this, the user can prove the lifted lemma as follows:
2210
+ − 1223
2443
+ − 1224
\begin{isabelle}\ \ \ \ \ %
2287
+ − 1225
\isacommand{lemma}~~@{text "0 + (x :: int) = x"}~~\isacommand{by}~~@{text "lifting add_pair_zero"}
2240
+ − 1226
\end{isabelle}
2210
+ − 1227
2240
+ − 1228
\noindent
2333
+ − 1229
or by using the completely automated mode stating just:
2210
+ − 1230
2443
+ − 1231
\begin{isabelle}\ \ \ \ \ %
2287
+ − 1232
\isacommand{thm}~~@{text "add_pair_zero[quot_lifted]"}
2240
+ − 1233
\end{isabelle}
2210
+ − 1234
2240
+ − 1235
\noindent
2443
+ − 1236
Both methods give the same result, namely @{text "0 + x = x"}
2333
+ − 1237
where @{text x} is of type integer.
2279
+ − 1238
Although seemingly simple, arriving at this result without the help of a quotient
2333
+ − 1239
package requires a substantial reasoning effort (see \cite{Paulson06}).
2210
+ − 1240
*}
2206
+ − 1241
2256
+ − 1242
section {* Conclusion and Related Work\label{sec:conc}*}
1978
+ − 1243
+ − 1244
text {*
2243
+ − 1245
2445
+ − 1246
\noindent
2333
+ − 1247
The code of the quotient package and the examples described here are already
+ − 1248
included in the standard distribution of Isabelle.\footnote{Available from
+ − 1249
\href{http://isabelle.in.tum.de/}{http://isabelle.in.tum.de/}.} The package is
+ − 1250
heavily used in the new version of Nominal Isabelle, which provides a
+ − 1251
convenient reasoning infrastructure for programming language calculi
+ − 1252
involving general binders. To achieve this, it builds types representing
+ − 1253
@{text \<alpha>}-equivalent terms. Earlier versions of Nominal Isabelle have been
+ − 1254
used successfully in formalisations of an equivalence checking algorithm for
+ − 1255
LF \cite{UrbanCheneyBerghofer08}, Typed
+ − 1256
Scheme~\cite{TobinHochstadtFelleisen08}, several calculi for concurrency
+ − 1257
\cite{BengtsonParow09} and a strong normalisation result for cut-elimination
+ − 1258
in classical logic \cite{UrbanZhu08}.
+ − 1259
2237
+ − 1260
2333
+ − 1261
There is a wide range of existing literature for dealing with quotients
+ − 1262
in theorem provers. Slotosch~\cite{Slotosch97} implemented a mechanism that
+ − 1263
automatically defines quotient types for Isabelle/HOL. But he did not
+ − 1264
include theorem lifting. Harrison's quotient package~\cite{harrison-thesis}
+ − 1265
is the first one that is able to automatically lift theorems, however only
+ − 1266
first-order theorems (that is theorems where abstractions, quantifiers and
+ − 1267
variables do not involve functions that include the quotient type). There is
+ − 1268
also some work on quotient types in non-HOL based systems and logical
+ − 1269
frameworks, including theory interpretations in
+ − 1270
PVS~\cite{PVS:Interpretations}, new types in MetaPRL~\cite{Nogin02}, and
+ − 1271
setoids in Coq \cite{ChicliPS02}. Paulson showed a construction of
+ − 1272
quotients that does not require the Hilbert Choice operator, but also only
+ − 1273
first-order theorems can be lifted~\cite{Paulson06}. The most related work
+ − 1274
to our package is the package for HOL4 by Homeier~\cite{Homeier05}. He
+ − 1275
introduced most of the abstract notions about quotients and also deals with
+ − 1276
lifting of higher-order theorems. However, he cannot deal with quotient
+ − 1277
compositions (needed for lifting theorems about @{text flat}). Also, a
+ − 1278
number of his definitions, like @{text ABS}, @{text REP} and @{text INJ} etc
+ − 1279
only exist in \cite{Homeier05} as ML-code, not included in the paper.
2334
+ − 1280
Like Homeier's, our quotient package can deal with partial equivalence
+ − 1281
relations, but for lack of space we do not describe the mechanisms
+ − 1282
needed for this kind of quotient constructions.
2224
+ − 1283
2422
+ − 1284
%%% FIXME Reviewer 3 would like to know more about the lifting in Coq and PVS,
+ − 1285
%%% and some comparison. I don't think we have the space for any additions...
2333
+ − 1286
+ − 1287
One feature of our quotient package is that when lifting theorems, the user
+ − 1288
can precisely specify what the lifted theorem should look like. This feature
+ − 1289
is necessary, for example, when lifting an induction principle for two
+ − 1290
lists. Assuming this principle has as the conclusion a predicate of the
+ − 1291
form @{text "P xs ys"}, then we can precisely specify whether we want to
+ − 1292
quotient @{text "xs"} or @{text "ys"}, or both. We found this feature very
+ − 1293
useful in the new version of Nominal Isabelle, where such a choice is
+ − 1294
required to generate a reasoning infrastructure for alpha-equated terms.
2287
+ − 1295
%%
+ − 1296
%% give an example for this
+ − 1297
%%
2278
+ − 1298
\medskip
2224
+ − 1299
2263
+ − 1300
\noindent
2287
+ − 1301
{\bf Acknowledgements:} We would like to thank Peter Homeier for the many
2277
+ − 1302
discussions about his HOL4 quotient package and explaining to us
2283
+ − 1303
some of its finer points in the implementation. Without his patient
+ − 1304
help, this work would have been impossible.
2263
+ − 1305
2224
+ − 1306
*}
+ − 1307
+ − 1308
2227
+ − 1309
1975
b1281a0051ae
added stub for quotient paper; call with isabelle make qpaper
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 1310
(*<*)
b1281a0051ae
added stub for quotient paper; call with isabelle make qpaper
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 1311
end
1978
+ − 1312
(*>*)