64 |
64 |
65 |
65 |
66 section {* Introduction *} |
66 section {* Introduction *} |
67 |
67 |
68 text {* |
68 text {* |
69 \begin{flushright} |
69 \noindent |
70 {\em ``Not using a [quotient] package has its advantages: we do not have to\\ |
70 One might think they have been studied to death, but in the context of |
71 collect all the theorems we shall ever want into one giant list;''}\\ |
71 theorem provers many questions concerning quotients are far from settled. In |
72 Larry Paulson \cite{Paulson06} |
72 this paper we address the question how a convenient reasoning infrastructure |
73 \end{flushright} |
73 for quotient constructions can be established in Isabelle/HOL, a popular |
74 |
74 generic theorem prover. Higher-Order Logic (HOL) consists |
75 \noindent |
75 of a small number of axioms and inference rules over a simply-typed |
76 Isabelle is a popular generic theorem prover in which many logics can be |
76 term-language. Safe reasoning in HOL is ensured by two very restricted |
77 implemented. The most widely used one, however, is Higher-Order Logic |
77 mechanisms for extending the logic: one is the definition of new constants |
78 (HOL). This logic consists of a small number of axioms and inference rules |
78 in terms of existing ones; the other is the introduction of new types by |
79 over a simply-typed term-language. Safe reasoning in HOL is ensured by two |
79 identifying non-empty subsets in existing types. It is well understood how |
80 very restricted mechanisms for extending the logic: one is the definition of |
80 to use both mechanisms for dealing with quotient constructions in HOL (see |
81 new constants in terms of existing ones; the other is the introduction of |
81 \cite{Homeier05,Paulson06}). For example the integers in Isabelle/HOL are |
82 new types by identifying non-empty subsets in existing types. It is well |
82 constructed by a quotient construction over the type @{typ "nat \<times> nat"} and |
83 understood how to use both mechanisms for dealing with quotient |
83 the equivalence relation |
84 constructions in HOL (see \cite{Homeier05,Paulson06}). For example the |
84 |
85 integers in Isabelle/HOL are constructed by a quotient construction over the |
85 |
86 type @{typ "nat \<times> nat"} and the equivalence relation |
86 \begin{isabelle}\ \ \ \ \ %%% |
87 |
|
88 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
|
89 @{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} |
87 @{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} |
90 \end{isabelle} |
88 \end{isabelle} |
91 |
89 |
92 \noindent |
90 \noindent |
93 This constructions yields the new type @{typ int} and definitions for @{text |
91 This constructions yields the new type @{typ int} and definitions for @{text |
98 "add_pair (n\<^isub>1, m\<^isub>1) (n\<^isub>2, |
96 "add_pair (n\<^isub>1, m\<^isub>1) (n\<^isub>2, |
99 m\<^isub>2) \<equiv> (n\<^isub>1 + n\<^isub>2, m\<^isub>1 + m\<^isub>2)"}). |
97 m\<^isub>2) \<equiv> (n\<^isub>1 + n\<^isub>2, m\<^isub>1 + m\<^isub>2)"}). |
100 Similarly one can construct the type of finite sets, written @{term "\<alpha> fset"}, |
98 Similarly one can construct the type of finite sets, written @{term "\<alpha> fset"}, |
101 by quotienting the type @{text "\<alpha> list"} according to the equivalence relation |
99 by quotienting the type @{text "\<alpha> list"} according to the equivalence relation |
102 |
100 |
103 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
101 \begin{isabelle}\ \ \ \ \ %%% |
104 @{text "xs \<approx> ys \<equiv> (\<forall>x. memb x xs \<longleftrightarrow> memb x ys)"}\hfill\numbered{listequiv} |
102 @{text "xs \<approx> ys \<equiv> (\<forall>x. memb x xs \<longleftrightarrow> memb x ys)"}\hfill\numbered{listequiv} |
105 \end{isabelle} |
103 \end{isabelle} |
106 |
104 |
107 \noindent |
105 \noindent |
108 which states that two lists are equivalent if every element in one list is |
106 which states that two lists are equivalent if every element in one list is |
113 Quotients are important in a variety of areas, but they are really ubiquitous in |
111 Quotients are important in a variety of areas, but they are really ubiquitous in |
114 the area of reasoning about programming language calculi. A simple example |
112 the area of reasoning about programming language calculi. A simple example |
115 is the lambda-calculus, whose raw terms are defined as |
113 is the lambda-calculus, whose raw terms are defined as |
116 |
114 |
117 |
115 |
118 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
116 \begin{isabelle}\ \ \ \ \ %%% |
119 @{text "t ::= x | t t | \<lambda>x.t"}\hfill\numbered{lambda} |
117 @{text "t ::= x | t t | \<lambda>x.t"}\hfill\numbered{lambda} |
120 \end{isabelle} |
118 \end{isabelle} |
121 |
119 |
122 \noindent |
120 \noindent |
123 The problem with this definition arises, for instance, when one attempts to |
121 The problem with this definition arises, for instance, when one attempts to |
134 sets or $\alpha$-equated lambda-terms one needs to establish a reasoning |
132 sets or $\alpha$-equated lambda-terms one needs to establish a reasoning |
135 infrastructure by transferring, or \emph{lifting}, definitions and theorems |
133 infrastructure by transferring, or \emph{lifting}, definitions and theorems |
136 from the raw type @{typ "nat \<times> nat"} to the quotient type @{typ int} |
134 from the raw type @{typ "nat \<times> nat"} to the quotient type @{typ int} |
137 (similarly for finite sets and $\alpha$-equated lambda-terms). This lifting |
135 (similarly for finite sets and $\alpha$-equated lambda-terms). This lifting |
138 usually requires a \emph{lot} of tedious reasoning effort \cite{Paulson06}. |
136 usually requires a \emph{lot} of tedious reasoning effort \cite{Paulson06}. |
139 It is feasible to do this work manually, if one has only a few quotient |
137 In principle it is feasible to do this work manually, if one has only a few quotient |
140 constructions at hand. But if they have to be done over and over again, as in |
138 constructions at hand. But if they have to be done over and over again, as in |
141 Nominal Isabelle, then manual reasoning is not an option. |
139 Nominal Isabelle, then manual reasoning is not an option. |
142 |
140 |
143 The purpose of a \emph{quotient package} is to ease the lifting of theorems |
141 The purpose of a \emph{quotient package} is to ease the lifting of theorems |
144 and automate the reasoning as much as possible. In the |
142 and automate the reasoning as much as possible. In the |
206 between the non-empty subset and elements in the new type. They are |
204 between the non-empty subset and elements in the new type. They are |
207 necessary for making definitions involving the new type. For example @{text |
205 necessary for making definitions involving the new type. For example @{text |
208 "0"} and @{text "1"} of type @{typ int} can be defined as |
206 "0"} and @{text "1"} of type @{typ int} can be defined as |
209 |
207 |
210 |
208 |
211 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
209 \begin{isabelle}\ \ \ \ \ %%% |
212 @{text "0 \<equiv> Abs_int (0, 0)"}\hspace{10mm}@{text "1 \<equiv> Abs_int (1, 0)"} |
210 @{text "0 \<equiv> Abs_int (0, 0)"}\hspace{10mm}@{text "1 \<equiv> Abs_int (1, 0)"} |
213 \end{isabelle} |
211 \end{isabelle} |
214 |
212 |
215 \noindent |
213 \noindent |
216 Slightly more complicated is the definition of @{text "add"} having type |
214 Slightly more complicated is the definition of @{text "add"} having type |
217 @{typ "int \<Rightarrow> int \<Rightarrow> int"}. Its definition is as follows |
215 @{typ "int \<Rightarrow> int \<Rightarrow> int"}. Its definition is as follows |
218 |
216 |
219 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
217 \begin{isabelle}\ \ \ \ \ %%% |
220 @{text "add n m \<equiv> Abs_int (add_pair (Rep_int n) (Rep_int m))"} |
218 @{text "add n m \<equiv> Abs_int (add_pair (Rep_int n) (Rep_int m))"} |
221 \hfill\numbered{adddef} |
219 \hfill\numbered{adddef} |
222 \end{isabelle} |
220 \end{isabelle} |
223 |
221 |
224 \noindent |
222 \noindent |
229 that none of them can deal with slightly more complicated definitions involving |
227 that none of them can deal with slightly more complicated definitions involving |
230 \emph{compositions} of quotients. Such compositions are needed for example |
228 \emph{compositions} of quotients. Such compositions are needed for example |
231 in case of quotienting lists to yield finite sets and the operator that |
229 in case of quotienting lists to yield finite sets and the operator that |
232 flattens lists of lists, defined as follows |
230 flattens lists of lists, defined as follows |
233 |
231 |
234 @{thm [display, indent=10] concat.simps(1) concat.simps(2)[no_vars]} |
232 \begin{isabelle}\ \ \ \ \ %%% |
|
233 @{thm concat.simps(1)[THEN eq_reflection]}\hspace{10mm} |
|
234 @{thm concat.simps(2)[THEN eq_reflection, no_vars]} |
|
235 \end{isabelle} |
235 |
236 |
236 \noindent |
237 \noindent |
237 We expect that the corresponding operator on finite sets, written @{term "fconcat"}, |
238 We expect that the corresponding operator on finite sets, written @{term "fconcat"}, |
238 builds finite unions of finite sets: |
239 builds finite unions of finite sets: |
239 |
240 |
240 @{thm [display, indent=10] fconcat_empty[no_vars] fconcat_insert[no_vars]} |
241 \begin{isabelle}\ \ \ \ \ %%% |
|
242 @{thm fconcat_empty[THEN eq_reflection, no_vars]}\hspace{10mm} |
|
243 @{thm fconcat_insert[THEN eq_reflection, no_vars]} |
|
244 \end{isabelle} |
241 |
245 |
242 \noindent |
246 \noindent |
243 The quotient package should automatically provide us with a definition for @{text "\<Union>"} in |
247 The quotient package should automatically provide us with a definition for @{text "\<Union>"} in |
244 terms of @{text flat}, @{text Rep_fset} and @{text Abs_fset}. The problem is |
248 terms of @{text flat}, @{text Rep_fset} and @{text Abs_fset}. The problem is |
245 that the method used in the existing quotient |
249 that the method used in the existing quotient |
246 packages of just taking the representation of the arguments and then taking |
250 packages of just taking the representation of the arguments and then taking |
247 the abstraction of the result is \emph{not} enough. The reason is that in case |
251 the abstraction of the result is \emph{not} enough. The reason is that in case |
248 of @{text "\<Union>"} we obtain the incorrect definition |
252 of @{text "\<Union>"} we obtain the incorrect definition |
249 |
253 |
250 @{text [display, indent=10] "\<Union> S \<equiv> Abs_fset (flat (Rep_fset S))"} |
254 \begin{isabelle}\ \ \ \ \ %%% |
|
255 @{text "\<Union> S \<equiv> Abs_fset (flat (Rep_fset S))"} |
|
256 \end{isabelle} |
251 |
257 |
252 \noindent |
258 \noindent |
253 where the right-hand side is not even typable! This problem can be remedied in the |
259 where the right-hand side is not even typable! This problem can be remedied in the |
254 existing quotient packages by introducing an intermediate step and reasoning |
260 existing quotient packages by introducing an intermediate step and reasoning |
255 about flattening of lists of finite sets. However, this remedy is rather |
261 about flattening of lists of finite sets. However, this remedy is rather |
256 cumbersome and inelegant in light of our work, which can deal with such |
262 cumbersome and inelegant in light of our work, which can deal with such |
257 definitions directly. The solution is that we need to build aggregate |
263 definitions directly. The solution is that we need to build aggregate |
258 representation and abstraction functions, which in case of @{text "\<Union>"} |
264 representation and abstraction functions, which in case of @{text "\<Union>"} |
259 generate the following definition |
265 generate the following definition |
260 |
266 |
261 @{text [display, indent=10] "\<Union> S \<equiv> Abs_fset (flat ((map_list Rep_fset \<circ> Rep_fset) S))"} |
267 \begin{isabelle}\ \ \ \ \ %%% |
|
268 @{text "\<Union> S \<equiv> Abs_fset (flat ((map_list Rep_fset \<circ> Rep_fset) S))"} |
|
269 \end{isabelle} |
262 |
270 |
263 \noindent |
271 \noindent |
264 where @{term map_list} is the usual mapping function for lists. In this paper we |
272 where @{term map_list} is the usual mapping function for lists. In this paper we |
265 will present a formal definition of our aggregate abstraction and |
273 will present a formal definition of our aggregate abstraction and |
266 representation functions (this definition was omitted in \cite{Homeier05}). |
274 representation functions (this definition was omitted in \cite{Homeier05}). |
279 the modularity is that we are able to clearly specify what is involved |
287 the modularity is that we are able to clearly specify what is involved |
280 in the lifting process (this was only hinted at in \cite{Homeier05} and |
288 in the lifting process (this was only hinted at in \cite{Homeier05} and |
281 implemented as a ``rough recipe'' in ML-code). |
289 implemented as a ``rough recipe'' in ML-code). |
282 |
290 |
283 |
291 |
284 The paper is organised as follows: Section \ref{sec:prelims} presents briefly |
292 %The paper is organised as follows: Section \ref{sec:prelims} presents briefly |
285 some necessary preliminaries; Section \ref{sec:type} describes the definitions |
293 %some necessary preliminaries; Section \ref{sec:type} describes the definitions |
286 of quotient types and shows how definitions of constants can be made over |
294 %of quotient types and shows how definitions of constants can be made over |
287 quotient types. Section \ref{sec:resp} introduces the notions of respectfulness |
295 %quotient types. Section \ref{sec:resp} introduces the notions of respectfulness |
288 and preservation; Section \ref{sec:lift} describes the lifting of theorems; |
296 %and preservation; Section \ref{sec:lift} describes the lifting of theorems; |
289 Section \ref{sec:examples} presents some examples |
297 %Section \ref{sec:examples} presents some examples |
290 and Section \ref{sec:conc} concludes and compares our results to existing |
298 %and Section \ref{sec:conc} concludes and compares our results to existing |
291 work. |
299 %work. |
292 *} |
300 *} |
293 |
301 |
294 section {* Preliminaries and General Quotients\label{sec:prelims} *} |
302 section {* Preliminaries and General\\ Quotients\label{sec:prelims} *} |
295 |
303 |
296 text {* |
304 text {* |
|
305 \noindent |
297 We give in this section a crude overview of HOL and describe the main |
306 We give in this section a crude overview of HOL and describe the main |
298 definitions given by Homeier for quotients \cite{Homeier05}. |
307 definitions given by Homeier for quotients \cite{Homeier05}. |
299 |
308 |
300 At its core, HOL is based on a simply-typed term language, where types are |
309 At its core, HOL is based on a simply-typed term language, where types are |
301 recorded in Church-style fashion (that means, we can always infer the type of |
310 recorded in Church-style fashion (that means, we can always infer the type of |
302 a term and its subterms without any additional information). The grammars |
311 a term and its subterms without any additional information). The grammars |
303 for types and terms are as follows |
312 for types and terms are |
304 |
313 |
305 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
314 \begin{isabelle}\ \ \ \ \ %%% |
306 \begin{tabular}{@ {}rl@ {\hspace{3mm}}l@ {}} |
315 \begin{tabular}{@ {}c@ {\hspace{10mm}}c@ {}} |
307 @{text "\<sigma>, \<tau> ::="} & @{text "\<alpha> | (\<sigma>,\<dots>, \<sigma>) \<kappa>"} & (type variables and type constructors)\\ |
316 @{text "\<sigma>, \<tau> ::= \<alpha> | (\<sigma>,\<dots>, \<sigma>) \<kappa>"} & |
308 @{text "t, s ::="} & @{text "x\<^isup>\<sigma> | c\<^isup>\<sigma> | t t | \<lambda>x\<^isup>\<sigma>. t"} & |
317 @{text "t, s ::= x\<^isup>\<sigma> | c\<^isup>\<sigma> | t t | \<lambda>x\<^isup>\<sigma>. t"}\\ |
309 (variables, constants, applications and abstractions)\\ |
|
310 \end{tabular} |
318 \end{tabular} |
311 \end{isabelle} |
319 \end{isabelle} |
312 |
320 |
313 \noindent |
321 \noindent |
|
322 with types being either type variables or type constructors and terms |
|
323 being variables, constants, applications or abstractions. |
314 We often write just @{text \<kappa>} for @{text "() \<kappa>"}, and use @{text "\<alpha>s"} and |
324 We often write just @{text \<kappa>} for @{text "() \<kappa>"}, and use @{text "\<alpha>s"} and |
315 @{text "\<sigma>s"} to stand for collections of type variables and types, |
325 @{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 |
326 respectively. The type of a term is often made explicit by writing @{text |
317 "t :: \<sigma>"}. HOL includes a type @{typ bool} for booleans and the function |
327 "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 |
328 type, written @{text "\<sigma> \<Rightarrow> \<tau>"}. HOL also contains many primitive and defined |
329 Like Homeier's, our work relies on map-functions defined for every type |
339 Like Homeier's, our work relies on map-functions defined for every type |
330 constructor taking some arguments, for example @{text map_list} for lists. Homeier |
340 constructor taking some arguments, for example @{text map_list} for lists. Homeier |
331 describes in \cite{Homeier05} map-functions for products, sums, options and |
341 describes in \cite{Homeier05} map-functions for products, sums, options and |
332 also the following map for function types |
342 also the following map for function types |
333 |
343 |
334 @{thm [display, indent=10] fun_map_def[no_vars, THEN eq_reflection]} |
344 \begin{isabelle}\ \ \ \ \ %%% |
|
345 @{thm fun_map_def[no_vars, THEN eq_reflection]} |
|
346 \end{isabelle} |
335 |
347 |
336 \noindent |
348 \noindent |
337 Using this map-function, we can give the following, equivalent, but more |
349 Using this map-function, we can give the following, equivalent, but more |
338 uniform definition for @{text add} shown in \eqref{adddef}: |
350 uniform definition for @{text add} shown in \eqref{adddef}: |
339 |
351 |
340 @{text [display, indent=10] "add \<equiv> (Rep_int \<singlearr> Rep_int \<singlearr> Abs_int) add_pair"} |
352 \begin{isabelle}\ \ \ \ \ %%% |
|
353 @{text "add \<equiv> (Rep_int \<singlearr> Rep_int \<singlearr> Abs_int) add_pair"} |
|
354 \end{isabelle} |
341 |
355 |
342 \noindent |
356 \noindent |
343 Using extensionality and unfolding the definition of @{text "\<singlearr>"}, |
357 Using extensionality and unfolding the definition of @{text "\<singlearr>"}, |
344 we can get back to \eqref{adddef}. |
358 we can get back to \eqref{adddef}. |
345 In what follows we shall use the convention to write @{text "map_\<kappa>"} for a map-function |
359 In what follows we shall use the convention to write @{text "map_\<kappa>"} for a map-function |
352 It will also be necessary to have operators, referred to as @{text "rel_\<kappa>"}, |
366 It will also be necessary to have operators, referred to as @{text "rel_\<kappa>"}, |
353 which define equivalence relations in terms of constituent equivalence |
367 which define equivalence relations in terms of constituent equivalence |
354 relations. For example given two equivalence relations @{text "R\<^isub>1"} |
368 relations. For example given two equivalence relations @{text "R\<^isub>1"} |
355 and @{text "R\<^isub>2"}, we can define an equivalence relations over |
369 and @{text "R\<^isub>2"}, we can define an equivalence relations over |
356 products as follows |
370 products as follows |
357 % |
371 |
358 @{text [display, indent=10] "(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"} |
372 \begin{isabelle}\ \ \ \ \ %%% |
|
373 @{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"} |
|
374 \end{isabelle} |
359 |
375 |
360 \noindent |
376 \noindent |
361 Homeier gives also the following operator for defining equivalence |
377 Homeier gives also the following operator for defining equivalence |
362 relations over function types |
378 relations over function types |
363 % |
379 % |
364 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
380 \begin{isabelle}\ \ \ \ \ %%% |
365 @{thm fun_rel_def[of "R\<^isub>1" "R\<^isub>2", no_vars, THEN eq_reflection]} |
381 @{thm fun_rel_def[of "R\<^isub>1" "R\<^isub>2", no_vars, THEN eq_reflection]} |
366 \hfill\numbered{relfun} |
382 \hfill\numbered{relfun} |
367 \end{isabelle} |
383 \end{isabelle} |
368 |
384 |
369 \noindent |
385 \noindent |
431 quotient theorem for composing particular quotient relations. |
447 quotient theorem for composing particular quotient relations. |
432 For example, to lift theorems involving @{term flat} the quotient theorem for |
448 For example, to lift theorems involving @{term flat} the quotient theorem for |
433 composing @{text "\<approx>\<^bsub>list\<^esub>"} will be necessary: given @{term "Quotient R Abs Rep"} |
449 composing @{text "\<approx>\<^bsub>list\<^esub>"} will be necessary: given @{term "Quotient R Abs Rep"} |
434 with @{text R} being an equivalence relation, then |
450 with @{text R} being an equivalence relation, then |
435 |
451 |
436 @{text [display, indent=2] "Quotient (rel_list R \<circ>\<circ>\<circ> \<approx>\<^bsub>list\<^esub>) (Abs_fset \<circ> map_list Abs) (map_list Rep \<circ> Rep_fset)"} |
452 \begin{isabelle}\ \ \ \ \ %%% |
437 |
453 @{text "Quotient (rel_list R \<circ>\<circ>\<circ> \<approx>\<^bsub>list\<^esub>) (Abs_fset \<circ> map_list Abs) (map_list Rep \<circ> Rep_fset)"} |
438 \vspace{-.5mm} |
454 \end{isabelle} |
439 *} |
455 *} |
440 |
456 |
441 section {* Quotient Types and Quotient Definitions\label{sec:type} *} |
457 section {* Quotient Types and Quotient Definitions\label{sec:type} *} |
442 |
458 |
443 text {* |
459 text {* |
445 type, say @{text "\<kappa>\<^isub>q"}, and an equivalence relation, say @{text R}, |
461 type, say @{text "\<kappa>\<^isub>q"}, and an equivalence relation, say @{text R}, |
446 defined over a raw type, say @{text "\<sigma>"}. The type of the equivalence |
462 defined over a raw type, say @{text "\<sigma>"}. The type of the equivalence |
447 relation must be @{text "\<sigma> \<Rightarrow> \<sigma> \<Rightarrow> bool"}. The user-visible part of |
463 relation must be @{text "\<sigma> \<Rightarrow> \<sigma> \<Rightarrow> bool"}. The user-visible part of |
448 the quotient type declaration is therefore |
464 the quotient type declaration is therefore |
449 |
465 |
450 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
466 \begin{isabelle}\ \ \ \ \ %%% |
451 \isacommand{quotient\_type}~~@{text "\<alpha>s \<kappa>\<^isub>q = \<sigma> / R"}\hfill\numbered{typedecl} |
467 \isacommand{quotient\_type}~~@{text "\<alpha>s \<kappa>\<^isub>q = \<sigma> / R"}\hfill\numbered{typedecl} |
452 \end{isabelle} |
468 \end{isabelle} |
453 |
469 |
454 \noindent |
470 \noindent |
455 and a proof that @{text "R"} is indeed an equivalence relation. Two concrete |
471 and a proof that @{text "R"} is indeed an equivalence relation. Two concrete |
456 examples are |
472 examples are |
457 |
473 |
458 |
474 |
459 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
475 \begin{isabelle}\ \ \ \ \ %%% |
460 \begin{tabular}{@ {}l} |
476 \begin{tabular}{@ {}l} |
461 \isacommand{quotient\_type}~~@{text "int = nat \<times> nat / \<approx>\<^bsub>nat \<times> nat\<^esub>"}\\ |
477 \isacommand{quotient\_type}~~@{text "int = nat \<times> nat / \<approx>\<^bsub>nat \<times> nat\<^esub>"}\\ |
462 \isacommand{quotient\_type}~~@{text "\<alpha> fset = \<alpha> list / \<approx>\<^bsub>list\<^esub>"} |
478 \isacommand{quotient\_type}~~@{text "\<alpha> fset = \<alpha> list / \<approx>\<^bsub>list\<^esub>"} |
463 \end{tabular} |
479 \end{tabular} |
464 \end{isabelle} |
480 \end{isabelle} |
469 "\<approx>\<^bsub>list\<^esub>"} defined in \eqref{natpairequiv} and |
485 "\<approx>\<^bsub>list\<^esub>"} defined in \eqref{natpairequiv} and |
470 \eqref{listequiv}, respectively (the proofs about being equivalence |
486 \eqref{listequiv}, respectively (the proofs about being equivalence |
471 relations is omitted). Given this data, we define for declarations shown in |
487 relations is omitted). Given this data, we define for declarations shown in |
472 \eqref{typedecl} the quotient types internally as |
488 \eqref{typedecl} the quotient types internally as |
473 |
489 |
474 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
490 \begin{isabelle}\ \ \ \ \ %%% |
475 \isacommand{typedef}~~@{text "\<alpha>s \<kappa>\<^isub>q = {c. \<exists>x. c = R x}"} |
491 \isacommand{typedef}~~@{text "\<alpha>s \<kappa>\<^isub>q = {c. \<exists>x. c = R x}"} |
476 \end{isabelle} |
492 \end{isabelle} |
477 |
493 |
478 \noindent |
494 \noindent |
479 where the right-hand side is the (non-empty) set of equivalence classes of |
495 where the right-hand side is the (non-empty) set of equivalence classes of |
480 @{text "R"}. The constraint in this declaration is that the type variables |
496 @{text "R"}. The constraint in this declaration is that the type variables |
481 in the raw type @{text "\<sigma>"} must be included in the type variables @{text |
497 in the raw type @{text "\<sigma>"} must be included in the type variables @{text |
482 "\<alpha>s"} declared for @{text "\<kappa>\<^isub>q"}. HOL will then provide us with the following |
498 "\<alpha>s"} declared for @{text "\<kappa>\<^isub>q"}. HOL will then provide us with the following |
483 abstraction and representation functions |
499 abstraction and representation functions |
484 |
500 |
485 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
501 \begin{isabelle}\ \ \ \ \ %%% |
486 @{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"} |
502 @{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"} |
487 \end{isabelle} |
503 \end{isabelle} |
488 |
504 |
489 \noindent |
505 \noindent |
490 As can be seen from the type, they relate the new quotient type and equivalence classes of the raw |
506 As can be seen from the type, they relate the new quotient type and equivalence classes of the raw |
491 type. However, as Homeier \cite{Homeier05} noted, it is much more convenient |
507 type. However, as Homeier \cite{Homeier05} noted, it is much more convenient |
492 to work with the following derived abstraction and representation functions |
508 to work with the following derived abstraction and representation functions |
493 |
509 |
494 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
510 \begin{isabelle}\ \ \ \ \ %%% |
495 @{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)"} |
511 @{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)"} |
496 \end{isabelle} |
512 \end{isabelle} |
497 |
513 |
498 \noindent |
514 \noindent |
499 on the expense of having to use Hilbert's choice operator @{text "\<epsilon>"} in the |
515 on the expense of having to use Hilbert's choice operator @{text "\<epsilon>"} in the |
511 The next step in a quotient construction is to introduce definitions of new constants |
527 The next step in a quotient construction is to introduce definitions of new constants |
512 involving the quotient type. These definitions need to be given in terms of concepts |
528 involving the quotient type. These definitions need to be given in terms of concepts |
513 of the raw type (remember this is the only way how to extend HOL |
529 of the raw type (remember this is the only way how to extend HOL |
514 with new definitions). For the user the visible part of such definitions is the declaration |
530 with new definitions). For the user the visible part of such definitions is the declaration |
515 |
531 |
516 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
532 \begin{isabelle}\ \ \ \ \ %%% |
517 \isacommand{quotient\_definition}~~@{text "c :: \<tau>"}~~\isacommand{is}~~@{text "t :: \<sigma>"} |
533 \isacommand{quotient\_definition}~~@{text "c :: \<tau>"}~~\isacommand{is}~~@{text "t :: \<sigma>"} |
518 \end{isabelle} |
534 \end{isabelle} |
519 |
535 |
520 \noindent |
536 \noindent |
521 where @{text t} is the definiens (its type @{text \<sigma>} can always be inferred) |
537 where @{text t} is the definiens (its type @{text \<sigma>} can always be inferred) |
522 and @{text "c"} is the name of definiendum, whose type @{text "\<tau>"} needs to be |
538 and @{text "c"} is the name of definiendum, whose type @{text "\<tau>"} needs to be |
523 given explicitly (the point is that @{text "\<tau>"} and @{text "\<sigma>"} can only differ |
539 given explicitly (the point is that @{text "\<tau>"} and @{text "\<sigma>"} can only differ |
524 in places where a quotient and raw type is involved). Two concrete examples are |
540 in places where a quotient and raw type is involved). Two concrete examples are |
525 |
541 |
526 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
542 \begin{isabelle}\ \ \ \ \ %%% |
527 \begin{tabular}{@ {}l} |
543 \begin{tabular}{@ {}l} |
528 \isacommand{quotient\_definition}~~@{text "0 :: int"}~~\isacommand{is}~~@{text "(0::nat, 0::nat)"}\\ |
544 \isacommand{quotient\_definition}~~@{text "0 :: int"}~~\isacommand{is}~~@{text "(0::nat, 0::nat)"}\\ |
529 \isacommand{quotient\_definition}~~@{text "\<Union> :: (\<alpha> fset) fset \<Rightarrow> \<alpha> fset"}~~% |
545 \isacommand{quotient\_definition}~~@{text "\<Union> :: (\<alpha> fset) fset \<Rightarrow> \<alpha> fset"}~~% |
530 \isacommand{is}~~@{text "flat"} |
546 \isacommand{is}~~@{text "flat"} |
531 \end{tabular} |
547 \end{tabular} |
607 %%% in this paragraph. I can imagine roughly what the following |
623 %%% in this paragraph. I can imagine roughly what the following |
608 %%% sentence `The $\sigma$s' are given by the matchers for the |
624 %%% sentence `The $\sigma$s' are given by the matchers for the |
609 %%% $\alpha$s$ when matching $\varrho$s $\kappa$ against $\sigma$s |
625 %%% $\alpha$s$ when matching $\varrho$s $\kappa$ against $\sigma$s |
610 %%% $\kappa$.' means, but also think that it is too vague. |
626 %%% $\kappa$.' means, but also think that it is too vague. |
611 |
627 |
612 @{text [display, indent=10] "\<lambda>a b. map_prod (map_list a) b"} |
628 \begin{isabelle}\ \ \ \ \ %%% |
613 |
629 @{text "\<lambda>a b. map_prod (map_list a) b"} |
|
630 \end{isabelle} |
|
631 |
614 \noindent |
632 \noindent |
615 which is essential in order to define the corresponding aggregate |
633 which is essential in order to define the corresponding aggregate |
616 abstraction and representation functions. |
634 abstraction and representation functions. |
617 |
635 |
618 To see how these definitions pan out in practise, let us return to our |
636 To see how these definitions pan out in practise, let us return to our |
619 example about @{term "concat"} and @{term "fconcat"}, where we have the raw type |
637 example about @{term "concat"} and @{term "fconcat"}, where we have the raw type |
620 @{text "(\<alpha> list) list \<Rightarrow> \<alpha> list"} and the quotient type @{text "(\<alpha> fset) fset \<Rightarrow> \<alpha> |
638 @{text "(\<alpha> list) list \<Rightarrow> \<alpha> list"} and the quotient type @{text "(\<alpha> fset) fset \<Rightarrow> \<alpha> |
621 fset"}. Feeding these types into @{text ABS} gives us (after some @{text "\<beta>"}-simplifications) |
639 fset"}. Feeding these types into @{text ABS} gives us (after some @{text "\<beta>"}-simplifications) |
622 the abstraction function |
640 the abstraction function |
623 |
641 |
624 @{text [display, indent=10] "(map_list (map_list id \<circ> Rep_fset) \<circ> Rep_fset) \<singlearr> Abs_fset \<circ> map_list id"} |
642 \begin{isabelle}\ \ \ \ \ %%% |
|
643 @{text "(map_list (map_list id \<circ> Rep_fset) \<circ> Rep_fset) \<singlearr> Abs_fset \<circ> map_list id"} |
|
644 \end{isabelle} |
625 |
645 |
626 \noindent |
646 \noindent |
627 In our implementation we further |
647 In our implementation we further |
628 simplify this function by rewriting with the usual laws about @{text |
648 simplify this function by rewriting with the usual laws about @{text |
629 "map"}s and @{text "id"}, for example @{term "map_list id = id"} and @{text "f \<circ> id = |
649 "map"}s and @{text "id"}, for example @{term "map_list id = id"} and @{text "f \<circ> id = |
630 id \<circ> f = f"}. This gives us the simpler abstraction function |
650 id \<circ> f = f"}. This gives us the simpler abstraction function |
631 |
651 |
632 @{text [display, indent=10] "(map_list Rep_fset \<circ> Rep_fset) \<singlearr> Abs_fset"} |
652 \begin{isabelle}\ \ \ \ \ %%% |
|
653 @{text "(map_list Rep_fset \<circ> Rep_fset) \<singlearr> Abs_fset"} |
|
654 \end{isabelle} |
633 |
655 |
634 \noindent |
656 \noindent |
635 which we can use for defining @{term "fconcat"} as follows |
657 which we can use for defining @{term "fconcat"} as follows |
636 |
658 |
637 @{text [display, indent=10] "\<Union> \<equiv> ((map_list Rep_fset \<circ> Rep_fset) \<singlearr> Abs_fset) flat"} |
659 \begin{isabelle}\ \ \ \ \ %%% |
|
660 @{text "\<Union> \<equiv> ((map_list Rep_fset \<circ> Rep_fset) \<singlearr> Abs_fset) flat"} |
|
661 \end{isabelle} |
638 |
662 |
639 \noindent |
663 \noindent |
640 Note that by using the operator @{text "\<singlearr>"} and special clauses |
664 Note that by using the operator @{text "\<singlearr>"} and special clauses |
641 for function types in \eqref{ABSREP}, we do not have to |
665 for function types in \eqref{ABSREP}, we do not have to |
642 distinguish between arguments and results, but can deal with them uniformly. |
666 distinguish between arguments and results, but can deal with them uniformly. |
643 Consequently, all definitions in the quotient package |
667 Consequently, all definitions in the quotient package |
644 are of the general form |
668 are of the general form |
645 |
669 |
646 @{text [display, indent=10] "c \<equiv> ABS (\<sigma>, \<tau>) t"} |
670 \begin{isabelle}\ \ \ \ \ %%% |
|
671 @{text "c \<equiv> ABS (\<sigma>, \<tau>) t"} |
|
672 \end{isabelle} |
647 |
673 |
648 \noindent |
674 \noindent |
649 where @{text \<sigma>} is the type of the definiens @{text "t"} and @{text "\<tau>"} the |
675 where @{text \<sigma>} is the type of the definiens @{text "t"} and @{text "\<tau>"} the |
650 type of the defined quotient constant @{text "c"}. This data can be easily |
676 type of the defined quotient constant @{text "c"}. This data can be easily |
651 generated from the declaration given by the user. |
677 generated from the declaration given by the user. |
689 lifting. The reason is that even if definitions for all raw constants |
715 lifting. The reason is that even if definitions for all raw constants |
690 can be given, \emph{not} all theorems can be lifted to the quotient type. Most |
716 can be given, \emph{not} all theorems can be lifted to the quotient type. Most |
691 notable is the bound variable function, that is the constant @{text bn}, defined |
717 notable is the bound variable function, that is the constant @{text bn}, defined |
692 for raw lambda-terms as follows |
718 for raw lambda-terms as follows |
693 |
719 |
694 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
720 \begin{isabelle}\ \ \ \ \ %%% |
695 @{text "bn (x) \<equiv> \<emptyset>"}\hspace{4mm} |
721 @{text "bn (x) \<equiv> \<emptyset>"}\hspace{4mm} |
696 @{text "bn (t\<^isub>1 t\<^isub>2) \<equiv> bn (t\<^isub>1) \<union> bn (t\<^isub>2)"}\hspace{4mm} |
722 @{text "bn (t\<^isub>1 t\<^isub>2) \<equiv> bn (t\<^isub>1) \<union> bn (t\<^isub>2)"}\hspace{4mm} |
697 @{text "bn (\<lambda>x. t) \<equiv> {x} \<union> bn (t)"} |
723 @{text "bn (\<lambda>x. t) \<equiv> {x} \<union> bn (t)"} |
698 \end{isabelle} |
724 \end{isabelle} |
699 |
725 |
739 that contains the raw constant @{text "c\<^isub>r :: \<sigma>"} and which we want to |
765 that contains the raw constant @{text "c\<^isub>r :: \<sigma>"} and which we want to |
740 lift to a theorem where @{text "c\<^isub>r"} is replaced by the corresponding |
766 lift to a theorem where @{text "c\<^isub>r"} is replaced by the corresponding |
741 constant @{text "c\<^isub>q :: \<tau>"} defined over a quotient type. In this situation |
767 constant @{text "c\<^isub>q :: \<tau>"} defined over a quotient type. In this situation |
742 we generate the following proof obligation |
768 we generate the following proof obligation |
743 |
769 |
744 @{text [display, indent=10] "REL (\<sigma>, \<tau>) c\<^isub>r c\<^isub>r"} |
770 \begin{isabelle}\ \ \ \ \ %%% |
|
771 @{text "REL (\<sigma>, \<tau>) c\<^isub>r c\<^isub>r"} |
|
772 \end{isabelle} |
745 |
773 |
746 \noindent |
774 \noindent |
747 Homeier calls these proof obligations \emph{respectfulness |
775 Homeier calls these proof obligations \emph{respectfulness |
748 theorems}. However, unlike his quotient package, we might have several |
776 theorems}. However, unlike his quotient package, we might have several |
749 respectfulness theorems for one constant---he has at most one. |
777 respectfulness theorems for one constant---he has at most one. |
754 |
782 |
755 Before lifting a theorem, we require the user to discharge |
783 Before lifting a theorem, we require the user to discharge |
756 respectfulness proof obligations. In case of @{text bn} |
784 respectfulness proof obligations. In case of @{text bn} |
757 this obligation is as follows |
785 this obligation is as follows |
758 |
786 |
759 @{text [display, indent=10] "(\<approx>\<^isub>\<alpha> \<doublearr> =) bn bn"} |
787 \begin{isabelle}\ \ \ \ \ %%% |
|
788 @{text "(\<approx>\<^isub>\<alpha> \<doublearr> =) bn bn"} |
|
789 \end{isabelle} |
760 |
790 |
761 \noindent |
791 \noindent |
762 and the point is that the user cannot discharge it: because it is not true. To see this, |
792 and the point is that the user cannot discharge it: because it is not true. To see this, |
763 we can just unfold the definition of @{text "\<doublearr>"} \eqref{relfun} |
793 we can just unfold the definition of @{text "\<doublearr>"} \eqref{relfun} |
764 using extensionality to obtain the false statement |
794 using extensionality to obtain the false statement |
765 |
795 |
766 @{text [display, indent=10] "\<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)"} |
796 \begin{isabelle}\ \ \ \ \ %%% |
767 |
797 @{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)"} |
|
798 \end{isabelle} |
|
799 |
768 \noindent |
800 \noindent |
769 In contrast, if we lift a theorem about @{text "append"} to a theorem describing |
801 In contrast, if we lift a theorem about @{text "append"} to a theorem describing |
770 the union of finite sets, then we need to discharge the proof obligation |
802 the union of finite sets, then we need to discharge the proof obligation |
771 |
803 |
772 @{text [display, indent=10] "(\<approx>\<^bsub>list\<^esub> \<doublearr> \<approx>\<^bsub>list\<^esub> \<doublearr> \<approx>\<^bsub>list\<^esub>) append append"} |
804 \begin{isabelle}\ \ \ \ \ %%% |
|
805 @{text "(\<approx>\<^bsub>list\<^esub> \<doublearr> \<approx>\<^bsub>list\<^esub> \<doublearr> \<approx>\<^bsub>list\<^esub>) append append"} |
|
806 \end{isabelle} |
773 |
807 |
774 \noindent |
808 \noindent |
775 To do so, we have to establish |
809 To do so, we have to establish |
776 |
810 |
777 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
811 \begin{isabelle}\ \ \ \ \ %%% |
778 if @{text "xs \<approx>\<^bsub>list\<^esub> ys"} and @{text "us \<approx>\<^bsub>list\<^esub> vs"} |
812 if @{text "xs \<approx>\<^bsub>list\<^esub> ys"} and @{text "us \<approx>\<^bsub>list\<^esub> vs"} |
779 then @{text "xs @ us \<approx>\<^bsub>list\<^esub> ys @ vs"} |
813 then @{text "xs @ us \<approx>\<^bsub>list\<^esub> ys @ vs"} |
780 \end{isabelle} |
814 \end{isabelle} |
781 |
815 |
782 \noindent |
816 \noindent |
799 %%% and its corresponding lifted constant? |
833 %%% and its corresponding lifted constant? |
800 |
834 |
801 %%% Cezary: I think this would be a nice thing to do but we have not |
835 %%% Cezary: I think this would be a nice thing to do but we have not |
802 %%% done it, the theorems need to be 'guessed' from the remaining obligations |
836 %%% done it, the theorems need to be 'guessed' from the remaining obligations |
803 |
837 |
804 @{text [display, indent=10] "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"} |
838 \begin{isabelle}\ \ \ \ \ %%% |
|
839 @{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"} |
|
840 \end{isabelle} |
805 |
841 |
806 \noindent |
842 \noindent |
807 where the @{text "\<alpha>s"} stand for the type variables in the type of @{text "c\<^isub>r"}. |
843 where the @{text "\<alpha>s"} stand for the type variables in the type of @{text "c\<^isub>r"}. |
808 In case of @{text cons} (which has type @{text "\<alpha> \<Rightarrow> \<alpha> list \<Rightarrow> \<alpha> list"}) we have |
844 In case of @{text cons} (which has type @{text "\<alpha> \<Rightarrow> \<alpha> list \<Rightarrow> \<alpha> list"}) we have |
809 |
845 |
810 @{text [display, indent=10] "(Rep ---> map_list Rep ---> map_list Abs) cons = cons"} |
846 \begin{isabelle}\ \ \ \ \ %%% |
|
847 @{text "(Rep ---> map_list Rep ---> map_list Abs) cons = cons"} |
|
848 \end{isabelle} |
811 |
849 |
812 \noindent |
850 \noindent |
813 under the assumption @{text "Quotient R Abs Rep"}. Interestingly, if we have |
851 under the assumption @{text "Quotient R Abs Rep"}. Interestingly, if we have |
814 an instance of @{text cons} where the type variable @{text \<alpha>} is instantiated |
852 an instance of @{text cons} where the type variable @{text \<alpha>} is instantiated |
815 with @{text "nat \<times> nat"} and we also quotient this type to yield integers, |
853 with @{text "nat \<times> nat"} and we also quotient this type to yield integers, |
998 the implications into simpler implicational subgoals. This succeeds for every |
1036 the implications into simpler implicational subgoals. This succeeds for every |
999 monotone connective, except in places where the function @{text REG} replaced, |
1037 monotone connective, except in places where the function @{text REG} replaced, |
1000 for instance, a quantifier by a bounded quantifier. In this case we have |
1038 for instance, a quantifier by a bounded quantifier. In this case we have |
1001 rules of the form |
1039 rules of the form |
1002 |
1040 |
1003 @{text [display, indent=10] "(\<forall>x. R x \<longrightarrow> (P x \<longrightarrow> Q x)) \<longrightarrow> (\<forall>x. P x \<longrightarrow> \<forall>x \<in> R. Q x)"} |
1041 \begin{isabelle}\ \ \ \ \ %%% |
|
1042 @{text "(\<forall>x. R x \<longrightarrow> (P x \<longrightarrow> Q x)) \<longrightarrow> (\<forall>x. P x \<longrightarrow> \<forall>x \<in> R. Q x)"} |
|
1043 \end{isabelle} |
1004 |
1044 |
1005 \noindent |
1045 \noindent |
1006 They decompose a bounded quantifier on the right-hand side. We can decompose a |
1046 They decompose a bounded quantifier on the right-hand side. We can decompose a |
1007 bounded quantifier anywhere if R is an equivalence relation or |
1047 bounded quantifier anywhere if R is an equivalence relation or |
1008 if it is a relation over function types with the range being an equivalence |
1048 if it is a relation over function types with the range being an equivalence |
1009 relation. If @{text R} is an equivalence relation we can prove that |
1049 relation. If @{text R} is an equivalence relation we can prove that |
1010 |
1050 |
1011 @{text [display, indent=10] "\<forall>x \<in> Respects R. P x = \<forall>x. P x"} |
1051 \begin{isabelle}\ \ \ \ \ %%% |
|
1052 @{text "\<forall>x \<in> Respects R. P x = \<forall>x. P x"} |
|
1053 \end{isabelle} |
1012 |
1054 |
1013 \noindent |
1055 \noindent |
1014 If @{term R\<^isub>2} is an equivalence relation, we can prove that for any predicate @{term P} |
1056 If @{term R\<^isub>2} is an equivalence relation, we can prove that for any predicate @{term P} |
1015 |
1057 |
1016 %%% FIXME Reviewer 1 claims the theorem is obviously false so maybe we |
1058 %%% FIXME Reviewer 1 claims the theorem is obviously false so maybe we |
1017 %%% should include a proof sketch? |
1059 %%% should include a proof sketch? |
1018 |
1060 |
1019 @{thm [display, indent=10] (concl) ball_reg_eqv_range[of R\<^isub>1 R\<^isub>2, no_vars]} |
1061 \begin{isabelle}\ \ \ \ \ %%% |
|
1062 @{thm (concl) ball_reg_eqv_range[of R\<^isub>1 R\<^isub>2, no_vars]} |
|
1063 \end{isabelle} |
1020 |
1064 |
1021 \noindent |
1065 \noindent |
1022 The last theorem is new in comparison with Homeier's package. There the |
1066 The last theorem is new in comparison with Homeier's package. There the |
1023 injection procedure would be used to prove such goals and |
1067 injection procedure would be used to prove such goals and |
1024 the assumption about the equivalence relation would be used. We use the above theorem directly, |
1068 the assumption about the equivalence relation would be used. We use the above theorem directly, |
1036 \item For two abstractions, we @{text "\<eta>"}-expand and @{text "\<beta>"}-reduce them. |
1080 \item For two abstractions, we @{text "\<eta>"}-expand and @{text "\<beta>"}-reduce them. |
1037 \item For two applications, we check that the right-hand side is an application of |
1081 \item For two applications, we check that the right-hand side is an application of |
1038 @{term Rep} to an @{term Abs} and @{term "Quotient R Rep Abs"} holds. If yes then we |
1082 @{term Rep} to an @{term Abs} and @{term "Quotient R Rep Abs"} holds. If yes then we |
1039 can apply the theorem: |
1083 can apply the theorem: |
1040 |
1084 |
1041 @{term [display, indent=10] "R x y \<longrightarrow> R x (Rep (Abs y))"} |
1085 \begin{isabelle}\ \ \ \ \ %%% |
|
1086 @{term "R x y \<longrightarrow> R x (Rep (Abs y))"} |
|
1087 \end{isabelle} |
1042 |
1088 |
1043 Otherwise we introduce an appropriate relation between the subterms |
1089 Otherwise we introduce an appropriate relation between the subterms |
1044 and continue with two subgoals using the lemma: |
1090 and continue with two subgoals using the lemma: |
1045 |
1091 |
1046 @{text [display, indent=10] "(R\<^isub>1 \<doublearr> R\<^isub>2) f g \<longrightarrow> R\<^isub>1 x y \<longrightarrow> R\<^isub>2 (f x) (g y)"} |
1092 \begin{isabelle}\ \ \ \ \ %%% |
|
1093 @{text "(R\<^isub>1 \<doublearr> R\<^isub>2) f g \<longrightarrow> R\<^isub>1 x y \<longrightarrow> R\<^isub>2 (f x) (g y)"} |
|
1094 \end{isabelle} |
1047 \end{itemize} |
1095 \end{itemize} |
1048 |
1096 |
1049 We defined the theorem @{text "inj_thm"} in such a way that |
1097 We defined the theorem @{text "inj_thm"} in such a way that |
1050 establishing the equivalence @{text "inj_thm \<longleftrightarrow> quot_thm"} can be |
1098 establishing the equivalence @{text "inj_thm \<longleftrightarrow> quot_thm"} can be |
1051 achieved by rewriting @{text "inj_thm"} with the preservation theorems and quotient |
1099 achieved by rewriting @{text "inj_thm"} with the preservation theorems and quotient |
1056 variables that include raw types with respects by quantifiers |
1104 variables that include raw types with respects by quantifiers |
1057 over variables that include quotient types. We show here only |
1105 over variables that include quotient types. We show here only |
1058 the lambda preservation theorem. Given |
1106 the lambda preservation theorem. Given |
1059 @{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: |
1107 @{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: |
1060 |
1108 |
1061 @{thm [display, indent=10] (concl) lambda_prs[of _ "Abs\<^isub>1" "Rep\<^isub>1" _ "Abs\<^isub>2" "Rep\<^isub>2", no_vars]} |
1109 \begin{isabelle}\ \ \ \ \ %%% |
|
1110 @{thm (concl) lambda_prs[of _ "Abs\<^isub>1" "Rep\<^isub>1" _ "Abs\<^isub>2" "Rep\<^isub>2", no_vars]} |
|
1111 \end{isabelle} |
1062 |
1112 |
1063 \noindent |
1113 \noindent |
1064 Next, relations over lifted types can be rewritten to equalities |
1114 Next, relations over lifted types can be rewritten to equalities |
1065 over lifted type. Rewriting is performed with the following theorem, |
1115 over lifted type. Rewriting is performed with the following theorem, |
1066 which has been shown by Homeier~\cite{Homeier05}: |
1116 which has been shown by Homeier~\cite{Homeier05}: |
1067 |
1117 |
1068 @{thm [display, indent=10] (concl) Quotient_rel_rep[no_vars]} |
1118 \begin{isabelle}\ \ \ \ \ %%% |
|
1119 @{thm (concl) Quotient_rel_rep[no_vars]} |
|
1120 \end{isabelle} |
1069 |
1121 |
1070 \noindent |
1122 \noindent |
1071 Finally, we rewrite with the preservation theorems. This will result |
1123 Finally, we rewrite with the preservation theorems. This will result |
1072 in two equal terms that can be solved by reflexivity. |
1124 in two equal terms that can be solved by reflexivity. |
1073 *} |
1125 *} |
1087 |
1139 |
1088 A user of our quotient package first needs to define a relation on |
1140 A user of our quotient package first needs to define a relation on |
1089 the raw type with which the quotienting will be performed. We give |
1141 the raw type with which the quotienting will be performed. We give |
1090 the same integer relation as the one presented in \eqref{natpairequiv}: |
1142 the same integer relation as the one presented in \eqref{natpairequiv}: |
1091 |
1143 |
1092 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ % |
1144 \begin{isabelle}\ \ \ \ \ % |
1093 \begin{tabular}{@ {}l} |
1145 \begin{tabular}{@ {}l} |
1094 \isacommand{fun}~~@{text "int_rel :: (nat \<times> nat) \<Rightarrow> (nat \<times> nat) \<Rightarrow> (nat \<times> nat)"}\\ |
1146 \isacommand{fun}~~@{text "int_rel :: (nat \<times> nat) \<Rightarrow> (nat \<times> nat) \<Rightarrow> (nat \<times> nat)"}\\ |
1095 \isacommand{where}~~@{text "int_rel (m, n) (p, q) = (m + q = n + p)"} |
1147 \isacommand{where}~~@{text "int_rel (m, n) (p, q) = (m + q = n + p)"} |
1096 \end{tabular} |
1148 \end{tabular} |
1097 \end{isabelle} |
1149 \end{isabelle} |
1099 \noindent |
1151 \noindent |
1100 Next the quotient type must be defined. This generates a proof obligation that the |
1152 Next the quotient type must be defined. This generates a proof obligation that the |
1101 relation is an equivalence relation, which is solved automatically using the |
1153 relation is an equivalence relation, which is solved automatically using the |
1102 definition of equivalence and extensionality: |
1154 definition of equivalence and extensionality: |
1103 |
1155 |
1104 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ % |
1156 \begin{isabelle}\ \ \ \ \ % |
1105 \begin{tabular}{@ {}l} |
1157 \begin{tabular}{@ {}l} |
1106 \isacommand{quotient\_type}~~@{text "int"}~~\isacommand{=}~~@{text "(nat \<times> nat)"}~~\isacommand{/}~~@{text "int_rel"}\\ |
1158 \isacommand{quotient\_type}~~@{text "int"}~~\isacommand{=}~~@{text "(nat \<times> nat)"}~~\isacommand{/}~~@{text "int_rel"}\\ |
1107 \hspace{5mm}@{text "by (auto simp add: equivp_def expand_fun_eq)"} |
1159 \hspace{5mm}@{text "by (auto simp add: equivp_def expand_fun_eq)"} |
1108 \end{tabular} |
1160 \end{tabular} |
1109 \end{isabelle} |
1161 \end{isabelle} |
1110 |
1162 |
1111 \noindent |
1163 \noindent |
1112 The user can then specify the constants on the quotient type: |
1164 The user can then specify the constants on the quotient type: |
1113 |
1165 |
1114 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ % |
1166 \begin{isabelle}\ \ \ \ \ % |
1115 \begin{tabular}{@ {}l} |
1167 \begin{tabular}{@ {}l} |
1116 \isacommand{quotient\_definition}~~@{text "0 :: int"}~~\isacommand{is}~~@{text "(0 :: nat, 0 :: nat)"}\\[3mm] |
1168 \isacommand{quotient\_definition}~~@{text "0 :: int"}~~\isacommand{is}~~@{text "(0 :: nat, 0 :: nat)"}\\[3mm] |
1117 \isacommand{fun}~~@{text "add_pair"}~~\isacommand{where}~~% |
1169 \isacommand{fun}~~@{text "add_pair"}\\ |
|
1170 \isacommand{where}~~% |
1118 @{text "add_pair (m, n) (p, q) \<equiv> (m + p :: nat, n + q :: nat)"}\\ |
1171 @{text "add_pair (m, n) (p, q) \<equiv> (m + p :: nat, n + q :: nat)"}\\ |
1119 \isacommand{quotient\_definition}~~@{text "+ :: int \<Rightarrow> int \<Rightarrow> int"}~~% |
1172 \isacommand{quotient\_definition}~~@{text "+ :: int \<Rightarrow> int \<Rightarrow> int"}~~% |
1120 \isacommand{is}~~@{text "add_pair"}\\ |
1173 \isacommand{is}~~@{text "add_pair"}\\ |
1121 \end{tabular} |
1174 \end{tabular} |
1122 \end{isabelle} |
1175 \end{isabelle} |
1123 |
1176 |
1124 \noindent |
1177 \noindent |
1125 The following theorem about addition on the raw level can be proved. |
1178 The following theorem about addition on the raw level can be proved. |
1126 |
1179 |
1127 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ % |
1180 \begin{isabelle}\ \ \ \ \ % |
1128 \isacommand{lemma}~~@{text "add_pair_zero: int_rel (add_pair (0, 0) x) x"} |
1181 \isacommand{lemma}~~@{text "add_pair_zero: int_rel (add_pair (0, 0) x) x"} |
1129 \end{isabelle} |
1182 \end{isabelle} |
1130 |
1183 |
1131 \noindent |
1184 \noindent |
1132 If the user lifts this theorem, the quotient package performs all the lifting |
1185 If the user lifts this theorem, the quotient package performs all the lifting |
1133 automatically leaving the respectfulness proof for the constant @{text "add_pair"} |
1186 automatically leaving the respectfulness proof for the constant @{text "add_pair"} |
1134 as the only remaining proof obligation. This property needs to be proved by the user: |
1187 as the only remaining proof obligation. This property needs to be proved by the user: |
1135 |
1188 |
1136 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ % |
1189 \begin{isabelle}\ \ \ \ \ % |
1137 \begin{tabular}{@ {}l} |
1190 \begin{tabular}{@ {}l} |
1138 \isacommand{lemma}~~@{text "[quot_respect]:"}\\ |
1191 \isacommand{lemma}~~@{text "[quot_respect]:"}\\ |
1139 @{text "(int_rel \<doublearr> int_rel \<doublearr> int_rel) add_pair add_pair"} |
1192 @{text "(int_rel \<doublearr> int_rel \<doublearr> int_rel) add_pair add_pair"} |
1140 \end{tabular} |
1193 \end{tabular} |
1141 \end{isabelle} |
1194 \end{isabelle} |
1143 \noindent |
1196 \noindent |
1144 It can be discharged automatically by Isabelle when hinting to unfold the definition |
1197 It can be discharged automatically by Isabelle when hinting to unfold the definition |
1145 of @{text "\<doublearr>"}. |
1198 of @{text "\<doublearr>"}. |
1146 After this, the user can prove the lifted lemma as follows: |
1199 After this, the user can prove the lifted lemma as follows: |
1147 |
1200 |
1148 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ % |
1201 \begin{isabelle}\ \ \ \ \ % |
1149 \isacommand{lemma}~~@{text "0 + (x :: int) = x"}~~\isacommand{by}~~@{text "lifting add_pair_zero"} |
1202 \isacommand{lemma}~~@{text "0 + (x :: int) = x"}~~\isacommand{by}~~@{text "lifting add_pair_zero"} |
1150 \end{isabelle} |
1203 \end{isabelle} |
1151 |
1204 |
1152 \noindent |
1205 \noindent |
1153 or by using the completely automated mode stating just: |
1206 or by using the completely automated mode stating just: |
1154 |
1207 |
1155 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ % |
1208 \begin{isabelle}\ \ \ \ \ % |
1156 \isacommand{thm}~~@{text "add_pair_zero[quot_lifted]"} |
1209 \isacommand{thm}~~@{text "add_pair_zero[quot_lifted]"} |
1157 \end{isabelle} |
1210 \end{isabelle} |
1158 |
1211 |
1159 \noindent |
1212 \noindent |
1160 Both methods give the same result, namely |
1213 Both methods give the same result, namely @{text "0 + x = x"} |
1161 |
|
1162 @{text [display, indent=10] "0 + x = x"} |
|
1163 |
|
1164 \noindent |
|
1165 where @{text x} is of type integer. |
1214 where @{text x} is of type integer. |
1166 Although seemingly simple, arriving at this result without the help of a quotient |
1215 Although seemingly simple, arriving at this result without the help of a quotient |
1167 package requires a substantial reasoning effort (see \cite{Paulson06}). |
1216 package requires a substantial reasoning effort (see \cite{Paulson06}). |
1168 *} |
1217 *} |
1169 |
1218 |