14 in particular preservation for quotient |
14 in particular preservation for quotient |
15 compositions |
15 compositions |
16 - explain how Quotient R Abs Rep is proved (j-version) |
16 - explain how Quotient R Abs Rep is proved (j-version) |
17 - give an example where precise specification helps (core Haskell in nominal?) |
17 - give an example where precise specification helps (core Haskell in nominal?) |
18 |
18 |
19 - Quote from Peter: |
|
20 |
|
21 One might think quotient have been studied to death, but |
|
22 |
|
23 - Mention Andreas Lochbiler in Acknowledgements and 'desceding'. |
19 - Mention Andreas Lochbiler in Acknowledgements and 'desceding'. |
24 |
20 |
25 *) |
21 *) |
26 |
22 |
27 notation (latex output) |
23 notation (latex output) |
28 rel_conj ("_ \<circ>\<circ>\<circ> _" [53, 53] 52) and |
24 rel_conj ("_ \<circ>\<circ>\<circ> _" [53, 53] 52) and |
29 pred_comp ("_ \<circ>\<circ> _" [1, 1] 30) and |
25 pred_comp ("_ \<circ>\<circ> _" [1, 1] 30) and |
30 "op -->" (infix "\<longrightarrow>" 100) and |
26 "op -->" (infix "\<longrightarrow>" 100) and |
31 "==>" (infix "\<Longrightarrow>" 100) and |
27 "==>" (infix "\<Longrightarrow>" 100) and |
32 fun_map ("_ \<^raw:\mbox{\singlearr}> _" 51) and |
28 fun_map ("_ \<singlearr> _" 51) and |
33 fun_rel ("_ \<^raw:\mbox{\doublearr}> _" 51) and |
29 fun_rel ("_ \<doublearr> _" 51) and |
34 list_eq (infix "\<approx>" 50) and (* Not sure if we want this notation...? *) |
30 list_eq (infix "\<approx>" 50) and (* Not sure if we want this notation...? *) |
35 fempty ("\<emptyset>") and |
31 fempty ("\<emptyset>") and |
36 funion ("_ \<union> _") and |
32 funion ("_ \<union> _") and |
37 finsert ("{_} \<union> _") and |
33 finsert ("{_} \<union> _") and |
38 Cons ("_::_") and |
34 Cons ("_::_") and |
39 concat ("flat") and |
35 concat ("flat") and |
40 fconcat ("\<Union>") |
36 fconcat ("\<Union>") and |
41 |
37 Quotient ("Quot _ _ _") |
|
38 |
42 |
39 |
43 |
40 |
44 ML {* |
41 ML {* |
45 fun nth_conj n (_, r) = nth (HOLogic.dest_conj r) n; |
42 fun nth_conj n (_, r) = nth (HOLogic.dest_conj r) n; |
46 |
43 |
356 \noindent |
353 \noindent |
357 Using extensionality and unfolding the definition of @{text "\<singlearr>"}, |
354 Using extensionality and unfolding the definition of @{text "\<singlearr>"}, |
358 we can get back to \eqref{adddef}. |
355 we can get back to \eqref{adddef}. |
359 In what follows we shall use the convention to write @{text "map_\<kappa>"} for a map-function |
356 In what follows we shall use the convention to write @{text "map_\<kappa>"} for a map-function |
360 of the type-constructor @{text \<kappa>}. For a type @{text \<kappa>} with arguments @{text "\<alpha>\<^isub>1\<^isub>\<dots>\<^isub>n"} the |
357 of the type-constructor @{text \<kappa>}. For a type @{text \<kappa>} with arguments @{text "\<alpha>\<^isub>1\<^isub>\<dots>\<^isub>n"} the |
361 type of @{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>"}. For example @{text "map_list"} |
358 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>"}. |
|
359 For example @{text "map_list"} |
362 has to have the type @{text "\<alpha>\<Rightarrow>\<alpha> list"}. |
360 has to have the type @{text "\<alpha>\<Rightarrow>\<alpha> list"}. |
363 In our implementation we maintain |
361 In our implementation we maintain |
364 a database of these map-functions that can be dynamically extended. |
362 a database of these map-functions that can be dynamically extended. |
365 |
363 |
366 It will also be necessary to have operators, referred to as @{text "rel_\<kappa>"}, |
364 It will also be necessary to have operators, referred to as @{text "rel_\<kappa>"}, |
388 |
386 |
389 \begin{definition}[Respects]\label{def:respects} |
387 \begin{definition}[Respects]\label{def:respects} |
390 An element @{text "x"} respects a relation @{text "R"} provided @{text "R x x"}. |
388 An element @{text "x"} respects a relation @{text "R"} provided @{text "R x x"}. |
391 \end{definition} |
389 \end{definition} |
392 |
390 |
393 \begin{definition}[Bounded Quantification and Bounded Abstractions]\label{def:babs} |
391 \begin{definition}[Bounded $\forall$ and $\lambda$]\label{def:babs} |
394 @{text "\<forall>x \<in> S. P x"} holds if for all @{text x}, @{text "x \<in> S"} implies @{text "P x"}; |
392 @{text "\<forall>x \<in> S. P x"} holds if for all @{text x}, @{text "x \<in> S"} implies @{text "P x"}; |
395 and @{text "(\<lambda>x \<in> S. f x) = f x"} provided @{text "x \<in> S"}. |
393 and @{text "(\<lambda>x \<in> S. f x) = f x"} provided @{text "x \<in> S"}. |
396 \end{definition} |
394 \end{definition} |
397 |
395 |
398 The central definition in Homeier's work \cite{Homeier05} relates equivalence |
396 The central definition in Homeier's work \cite{Homeier05} relates equivalence |
400 |
398 |
401 \begin{definition}[Quotient Types] |
399 \begin{definition}[Quotient Types] |
402 Given a relation $R$, an abstraction function $Abs$ |
400 Given a relation $R$, an abstraction function $Abs$ |
403 and a representation function $Rep$, the predicate @{term "Quotient R Abs Rep"} |
401 and a representation function $Rep$, the predicate @{term "Quotient R Abs Rep"} |
404 holds if and only if |
402 holds if and only if |
405 \begin{enumerate} |
403 \begin{isabelle}\ \ \ \ \ %%%% |
406 \item @{thm (rhs1) Quotient_def[of "R", no_vars]} |
404 \begin{tabular}{rl} |
407 \item @{thm (rhs2) Quotient_def[of "R", no_vars]} |
405 (i) & \begin{isa}@{thm (rhs1) Quotient_def[of "R", no_vars]}\end{isa}\\ |
408 \item @{thm (rhs3) Quotient_def[of "R", no_vars]} |
406 (ii) & \begin{isa}@{thm (rhs2) Quotient_def[of "R", no_vars]}\end{isa}\\ |
409 \end{enumerate} |
407 (iii) & \begin{isa}@{thm (rhs3) Quotient_def[of "R", no_vars]}\end{isa}\\ |
|
408 \end{tabular} |
|
409 \end{isabelle} |
410 \end{definition} |
410 \end{definition} |
411 |
411 |
412 \noindent |
412 \noindent |
413 The value of this definition lies in the fact that validity of @{text "Quotient R Abs Rep"} can |
413 The value of this definition lies in the fact that validity of @{term "Quotient R Abs Rep"} can |
414 often be proved in terms of the validity of @{text "Quotient"} over the constituent |
414 often be proved in terms of the validity of @{term "Quot"} over the constituent |
415 types of @{text "R"}, @{text Abs} and @{text Rep}. |
415 types of @{text "R"}, @{text Abs} and @{text Rep}. |
416 For example Homeier proves the following property for higher-order quotient |
416 For example Homeier proves the following property for higher-order quotient |
417 types: |
417 types: |
418 |
418 |
419 \begin{proposition}\label{funquot} |
419 \begin{proposition}\label{funquot} |
|
420 \begin{isa} |
420 @{thm[mode=IfThen] fun_quotient[where ?R1.0="R\<^isub>1" and ?R2.0="R\<^isub>2" |
421 @{thm[mode=IfThen] fun_quotient[where ?R1.0="R\<^isub>1" and ?R2.0="R\<^isub>2" |
421 and ?abs1.0="Abs\<^isub>1" and ?abs2.0="Abs\<^isub>2" and ?rep1.0="Rep\<^isub>1" and ?rep2.0="Rep\<^isub>2"]} |
422 and ?abs1.0="Abs\<^isub>1" and ?abs2.0="Abs\<^isub>2" and ?rep1.0="Rep\<^isub>1" and ?rep2.0="Rep\<^isub>2"]} |
|
423 \end{isa} |
422 \end{proposition} |
424 \end{proposition} |
423 |
425 |
424 \noindent |
426 \noindent |
425 As a result, Homeier is able to build an automatic prover that can nearly |
427 As a result, Homeier is able to build an automatic prover that can nearly |
426 always discharge a proof obligation involving @{text "Quotient"}. Our quotient |
428 always discharge a proof obligation involving @{text "Quot"}. Our quotient |
427 package makes heavy |
429 package makes heavy |
428 use of this part of Homeier's work including an extension |
430 use of this part of Homeier's work including an extension |
429 for dealing with compositions of equivalence relations defined as follows: |
431 for dealing with compositions of equivalence relations defined as follows: |
430 |
432 |
431 %%% FIXME Referee 2 claims that composition-of-relations means OO, and this is also |
433 %%% FIXME Referee 2 claims that composition-of-relations means OO, and this is also |
432 %%% what wikipedia says. Any idea for a different name? Conjugation of Relations? |
434 %%% what wikipedia says. Any idea for a different name? Conjugation of Relations? |
433 |
435 |
434 \begin{definition}[Composition of Relations] |
436 \begin{definition}%%[Composition of Relations] |
435 @{abbrev "rel_conj R\<^isub>1 R\<^isub>2"} where @{text "\<circ>\<circ>"} is the predicate |
437 @{abbrev "rel_conj R\<^isub>1 R\<^isub>2"} where @{text "\<circ>\<circ>"} is the predicate |
436 composition defined by |
438 composition defined by |
437 @{thm (concl) pred_compI[of "R\<^isub>1" "x" "y" "R\<^isub>2" "z"]} |
439 @{thm (concl) pred_compI[of "R\<^isub>1" "x" "y" "R\<^isub>2" "z"]} |
438 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 |
440 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 |
439 @{thm (prem 2) pred_compI[of "R\<^isub>1" "x" "y" "R\<^isub>2" "z"]}. |
441 @{thm (prem 2) pred_compI[of "R\<^isub>1" "x" "y" "R\<^isub>2" "z"]}. |
448 For example, to lift theorems involving @{term flat} the quotient theorem for |
450 For example, to lift theorems involving @{term flat} the quotient theorem for |
449 composing @{text "\<approx>\<^bsub>list\<^esub>"} will be necessary: given @{term "Quotient R Abs Rep"} |
451 composing @{text "\<approx>\<^bsub>list\<^esub>"} will be necessary: given @{term "Quotient R Abs Rep"} |
450 with @{text R} being an equivalence relation, then |
452 with @{text R} being an equivalence relation, then |
451 |
453 |
452 \begin{isabelle}\ \ \ \ \ %%% |
454 \begin{isabelle}\ \ \ \ \ %%% |
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)"} |
455 \begin{tabular}{r@ {\hspace{1mm}}l} |
|
456 @{text "Quot"} & @{text "(rel_list R \<circ>\<circ>\<circ> \<approx>\<^bsub>list\<^esub>)"}\\ |
|
457 & @{text "(Abs_fset \<circ> map_list Abs)"}\\ |
|
458 & @{text "(map_list Rep \<circ> Rep_fset)"}\\ |
|
459 \end{tabular} |
454 \end{isabelle} |
460 \end{isabelle} |
455 *} |
461 *} |
456 |
462 |
457 section {* Quotient Types and Quotient Definitions\label{sec:type} *} |
463 section {* Quotient Types and Quotient\\ Definitions\label{sec:type} *} |
458 |
464 |
459 text {* |
465 text {* |
460 The first step in a quotient construction is to take a name for the new |
466 The first step in a quotient construction is to take a name for the new |
461 type, say @{text "\<kappa>\<^isub>q"}, and an equivalence relation, say @{text R}, |
467 type, say @{text "\<kappa>\<^isub>q"}, and an equivalence relation, say @{text R}, |
462 defined over a raw type, say @{text "\<sigma>"}. The type of the equivalence |
468 defined over a raw type, say @{text "\<sigma>"}. The type of the equivalence |
519 respectively. Given that @{text "R"} is an equivalence relation, the |
525 respectively. Given that @{text "R"} is an equivalence relation, the |
520 following property holds for every quotient type |
526 following property holds for every quotient type |
521 (for the proof see \cite{Homeier05}). |
527 (for the proof see \cite{Homeier05}). |
522 |
528 |
523 \begin{proposition} |
529 \begin{proposition} |
524 @{text "Quotient R Abs_\<kappa>\<^isub>q Rep_\<kappa>\<^isub>q"}. |
530 @{term "Quotient R Abs_\<kappa>\<^isub>q Rep_\<kappa>\<^isub>q"}. |
525 \end{proposition} |
531 \end{proposition} |
526 |
532 |
527 The next step in a quotient construction is to introduce definitions of new constants |
533 The next step in a quotient construction is to introduce definitions of new constants |
528 involving the quotient type. These definitions need to be given in terms of concepts |
534 involving the quotient type. These definitions need to be given in terms of concepts |
529 of the raw type (remember this is the only way how to extend HOL |
535 of the raw type (remember this is the only way how to extend HOL |
566 @{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 |
572 @{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 |
567 for @{text REP}. |
573 for @{text REP}. |
568 % |
574 % |
569 \begin{center} |
575 \begin{center} |
570 \hfill |
576 \hfill |
571 \begin{tabular}{rcl} |
577 \begin{tabular}{@ {\hspace{2mm}}l@ {}} |
572 \multicolumn{3}{@ {\hspace{-4mm}}l}{equal types:}\\ |
578 \multicolumn{1}{@ {}l}{equal types:}\\ |
573 @{text "ABS (\<sigma>, \<sigma>)"} & $\dn$ & @{text "id :: \<sigma> \<Rightarrow> \<sigma>"}\\ |
579 @{text "ABS (\<sigma>, \<sigma>)"} $\dn$ @{text "id :: \<sigma> \<Rightarrow> \<sigma>"}\\ |
574 @{text "REP (\<sigma>, \<sigma>)"} & $\dn$ & @{text "id :: \<sigma> \<Rightarrow> \<sigma>"}\smallskip\\ |
580 @{text "REP (\<sigma>, \<sigma>)"} $\dn$ @{text "id :: \<sigma> \<Rightarrow> \<sigma>"}\smallskip\\ |
575 \multicolumn{3}{@ {\hspace{-4mm}}l}{function types:}\\ |
581 \multicolumn{1}{@ {}l}{function types:}\\ |
576 @{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)"}\\ |
582 @{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)"}\\ |
577 @{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\\ |
583 @{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\\ |
578 \multicolumn{3}{@ {\hspace{-4mm}}l}{equal type constructors:}\\ |
584 \multicolumn{1}{@ {}l}{equal type constructors:}\\ |
579 @{text "ABS (\<sigma>s \<kappa>, \<tau>s \<kappa>)"} & $\dn$ & @{text "map_\<kappa> (ABS (\<sigma>s, \<tau>s))"}\\ |
585 @{text "ABS (\<sigma>s \<kappa>, \<tau>s \<kappa>)"} $\dn$ @{text "map_\<kappa> (ABS (\<sigma>s, \<tau>s))"}\\ |
580 @{text "REP (\<sigma>s \<kappa>, \<tau>s \<kappa>)"} & $\dn$ & @{text "map_\<kappa> (REP (\<sigma>s, \<tau>s))"}\smallskip\\ |
586 @{text "REP (\<sigma>s \<kappa>, \<tau>s \<kappa>)"} $\dn$ @{text "map_\<kappa> (REP (\<sigma>s, \<tau>s))"}\smallskip\\ |
581 \multicolumn{3}{@ {\hspace{-4mm}}l}{unequal type constructors with @{text "\<alpha>s |
587 \multicolumn{1}{@ {}l}{unequal type constructors:}\\ |
582 \<kappa>\<^isub>q"} being the quotient of the raw type @{text "\<rho>s \<kappa>"}:}\\ |
588 @{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)))"}\\ |
583 @{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)))"}\\ |
589 @{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"} |
584 @{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"} |
|
585 \end{tabular}\hfill\numbered{ABSREP} |
590 \end{tabular}\hfill\numbered{ABSREP} |
586 \end{center} |
591 \end{center} |
587 % |
592 % |
588 \noindent |
593 \noindent |
589 In the last two clauses we rely on the fact that the type @{text "\<alpha>s |
594 In the last two clauses we rely on the fact that the type @{text "\<alpha>s |
595 @{text "\<rho>s \<kappa>"}. The |
600 @{text "\<rho>s \<kappa>"}. The |
596 function @{text "MAP"} calculates an \emph{aggregate map-function} for a raw |
601 function @{text "MAP"} calculates an \emph{aggregate map-function} for a raw |
597 type as follows: |
602 type as follows: |
598 % |
603 % |
599 \begin{center} |
604 \begin{center} |
600 \begin{tabular}{rcl} |
605 \begin{tabular}{r@ {\hspace{1mm}}c@ {\hspace{1mm}}l} |
601 @{text "MAP' (\<alpha>)"} & $\dn$ & @{text "a\<^sup>\<alpha>"}\\ |
606 @{text "MAP' (\<alpha>)"} & $\dn$ & @{text "a\<^sup>\<alpha>"}\\ |
602 @{text "MAP' (\<kappa>)"} & $\dn$ & @{text "id :: \<kappa> \<Rightarrow> \<kappa>"}\\ |
607 @{text "MAP' (\<kappa>)"} & $\dn$ & @{text "id :: \<kappa> \<Rightarrow> \<kappa>"}\\ |
603 @{text "MAP' (\<sigma>s \<kappa>)"} & $\dn$ & @{text "map_\<kappa> (MAP'(\<sigma>s))"}\smallskip\\ |
608 @{text "MAP' (\<sigma>s \<kappa>)"} & $\dn$ & @{text "map_\<kappa> (MAP'(\<sigma>s))"}\smallskip\\ |
604 @{text "MAP (\<sigma>)"} & $\dn$ & @{text "\<lambda>as. MAP'(\<sigma>)"} |
609 @{text "MAP (\<sigma>)"} & $\dn$ & @{text "\<lambda>as. MAP'(\<sigma>)"} |
605 \end{tabular} |
610 \end{tabular} |
638 @{text "(\<alpha> list) list \<Rightarrow> \<alpha> list"} and the quotient type @{text "(\<alpha> fset) fset \<Rightarrow> \<alpha> |
643 @{text "(\<alpha> list) list \<Rightarrow> \<alpha> list"} and the quotient type @{text "(\<alpha> fset) fset \<Rightarrow> \<alpha> |
639 fset"}. Feeding these types into @{text ABS} gives us (after some @{text "\<beta>"}-simplifications) |
644 fset"}. Feeding these types into @{text ABS} gives us (after some @{text "\<beta>"}-simplifications) |
640 the abstraction function |
645 the abstraction function |
641 |
646 |
642 \begin{isabelle}\ \ \ \ \ %%% |
647 \begin{isabelle}\ \ \ \ \ %%% |
643 @{text "(map_list (map_list id \<circ> Rep_fset) \<circ> Rep_fset) \<singlearr> Abs_fset \<circ> map_list id"} |
648 \begin{tabular}{l} |
|
649 @{text "(map_list (map_list id \<circ> Rep_fset) \<circ> Rep_fset) \<singlearr>"}\\ |
|
650 \mbox{}\hspace{4.5cm}@{text " Abs_fset \<circ> map_list id"} |
|
651 \end{tabular} |
644 \end{isabelle} |
652 \end{isabelle} |
645 |
653 |
646 \noindent |
654 \noindent |
647 In our implementation we further |
655 In our implementation we further |
648 simplify this function by rewriting with the usual laws about @{text |
656 simplify this function by rewriting with the usual laws about @{text |
703 equivalent to @{text "\<sigma>s \<kappa> \<Rightarrow> \<rho>s[\<tau>s] \<kappa>"}, which we just have to compose with |
711 equivalent to @{text "\<sigma>s \<kappa> \<Rightarrow> \<rho>s[\<tau>s] \<kappa>"}, which we just have to compose with |
704 @{text "\<rho>s[\<tau>s] \<kappa> \<Rightarrow> \<tau>s \<kappa>\<^isub>q"} according to the type of @{text "\<circ>"}.\qed |
712 @{text "\<rho>s[\<tau>s] \<kappa> \<Rightarrow> \<tau>s \<kappa>\<^isub>q"} according to the type of @{text "\<circ>"}.\qed |
705 \end{proof} |
713 \end{proof} |
706 *} |
714 *} |
707 |
715 |
708 section {* Respectfulness and Preservation \label{sec:resp} *} |
716 section {* Respectfulness and\\ Preservation \label{sec:resp} *} |
709 |
717 |
710 text {* |
718 text {* |
711 The main point of the quotient package is to automatically ``lift'' theorems |
719 The main point of the quotient package is to automatically ``lift'' theorems |
712 involving constants over the raw type to theorems involving constants over |
720 involving constants over the raw type to theorems involving constants over |
713 the quotient type. Before we can describe this lifting process, we need to impose |
721 the quotient type. Before we can describe this lifting process, we need to impose |
715 lifting. The reason is that even if definitions for all raw constants |
723 lifting. The reason is that even if definitions for all raw constants |
716 can be given, \emph{not} all theorems can be lifted to the quotient type. Most |
724 can be given, \emph{not} all theorems can be lifted to the quotient type. Most |
717 notable is the bound variable function, that is the constant @{text bn}, defined |
725 notable is the bound variable function, that is the constant @{text bn}, defined |
718 for raw lambda-terms as follows |
726 for raw lambda-terms as follows |
719 |
727 |
720 \begin{isabelle}\ \ \ \ \ %%% |
728 \begin{isabelle} |
|
729 \begin{center} |
721 @{text "bn (x) \<equiv> \<emptyset>"}\hspace{4mm} |
730 @{text "bn (x) \<equiv> \<emptyset>"}\hspace{4mm} |
722 @{text "bn (t\<^isub>1 t\<^isub>2) \<equiv> bn (t\<^isub>1) \<union> bn (t\<^isub>2)"}\hspace{4mm} |
731 @{text "bn (t\<^isub>1 t\<^isub>2) \<equiv> bn (t\<^isub>1) \<union> bn (t\<^isub>2)"}\smallskip\\ |
723 @{text "bn (\<lambda>x. t) \<equiv> {x} \<union> bn (t)"} |
732 @{text "bn (\<lambda>x. t) \<equiv> {x} \<union> bn (t)"} |
|
733 \end{center} |
724 \end{isabelle} |
734 \end{isabelle} |
725 |
735 |
726 \noindent |
736 \noindent |
727 We can generate a definition for this constant using @{text ABS} and @{text REP}. |
737 We can generate a definition for this constant using @{text ABS} and @{text REP}. |
728 But this constant does \emph{not} respect @{text "\<alpha>"}-equivalence and |
738 But this constant does \emph{not} respect @{text "\<alpha>"}-equivalence and |
742 quotient equivalence relations in places where the types differ and equalities |
752 quotient equivalence relations in places where the types differ and equalities |
743 elsewhere. |
753 elsewhere. |
744 |
754 |
745 \begin{center} |
755 \begin{center} |
746 \hfill |
756 \hfill |
747 \begin{tabular}{rcl} |
757 \begin{tabular}{l} |
748 \multicolumn{3}{@ {\hspace{-4mm}}l}{equal types:}\\ |
758 \multicolumn{1}{@ {}l}{equal types:}\\ |
749 @{text "REL (\<sigma>, \<sigma>)"} & $\dn$ & @{text "= :: \<sigma> \<Rightarrow> \<sigma> \<Rightarrow> bool"}\smallskip\\ |
759 @{text "REL (\<sigma>, \<sigma>)"} $\dn$ @{text "= :: \<sigma> \<Rightarrow> \<sigma> \<Rightarrow> bool"}\smallskip\\ |
750 \multicolumn{3}{@ {\hspace{-4mm}}l}{equal type constructors:}\\ |
760 \multicolumn{1}{@ {}l}{equal type constructors:}\\ |
751 @{text "REL (\<sigma>s \<kappa>, \<tau>s \<kappa>)"} & $\dn$ & @{text "rel_\<kappa> (REL (\<sigma>s, \<tau>s))"}\smallskip\\ |
761 @{text "REL (\<sigma>s \<kappa>, \<tau>s \<kappa>)"} $\dn$ @{text "rel_\<kappa> (REL (\<sigma>s, \<tau>s))"}\smallskip\\ |
752 \multicolumn{3}{@ {\hspace{-4mm}}l}{unequal type constructors with @{text "\<alpha>s |
762 \multicolumn{1}{@ {}l}{unequal type constructors:}\\ |
753 \<kappa>\<^isub>q"} being the quotient of the raw type @{text "\<rho>s \<kappa>"}:}\smallskip\\ |
763 @{text "REL (\<sigma>s \<kappa>, \<tau>s \<kappa>\<^isub>q)"} $\dn$ @{text "rel_\<kappa>\<^isub>q (REL (\<sigma>s', \<tau>s))"}\\ |
754 @{text "REL (\<sigma>s \<kappa>, \<tau>s \<kappa>\<^isub>q)"} & $\dn$ & @{text "rel_\<kappa>\<^isub>q (REL (\<sigma>s', \<tau>s))"}\\ |
|
755 \end{tabular}\hfill\numbered{REL} |
764 \end{tabular}\hfill\numbered{REL} |
756 \end{center} |
765 \end{center} |
757 |
766 |
758 \noindent |
767 \noindent |
759 The @{text "\<sigma>s'"} in the last clause are calculated as in \eqref{ABSREP}: |
768 The @{text "\<sigma>s'"} in the last clause are calculated as in \eqref{ABSREP}: |
760 we know that type @{text "\<alpha>s \<kappa>\<^isub>q"} is the quotient of the raw type |
769 again we know that type @{text "\<alpha>s \<kappa>\<^isub>q"} is the quotient of the raw type |
761 @{text "\<rho>s \<kappa>"}. The @{text "\<sigma>s'"} are the substitutions for @{text "\<alpha>s"} obtained by matching |
770 @{text "\<rho>s \<kappa>"}. The @{text "\<sigma>s'"} are the substitutions for @{text "\<alpha>s"} obtained by matching |
762 @{text "\<rho>s \<kappa>"} and @{text "\<sigma>s \<kappa>"}. |
771 @{text "\<rho>s \<kappa>"} and @{text "\<sigma>s \<kappa>"}. |
763 |
772 |
764 Let us return to the lifting procedure of theorems. Assume we have a theorem |
773 Let us return to the lifting procedure of theorems. Assume we have a theorem |
765 that contains the raw constant @{text "c\<^isub>r :: \<sigma>"} and which we want to |
774 that contains the raw constant @{text "c\<^isub>r :: \<sigma>"} and which we want to |
955 involving raw types by appropriate aggregate |
964 involving raw types by appropriate aggregate |
956 equivalence relations. It is defined by simultaneously recursing on |
965 equivalence relations. It is defined by simultaneously recursing on |
957 the structure of @{text "raw_thm"} and @{text "quot_thm"} as follows: |
966 the structure of @{text "raw_thm"} and @{text "quot_thm"} as follows: |
958 |
967 |
959 \begin{center} |
968 \begin{center} |
960 \begin{tabular}{rcl} |
969 \begin{tabular}{l} |
961 \multicolumn{3}{@ {}l}{abstractions:}\smallskip\\ |
970 \multicolumn{1}{@ {}l}{abstractions:}\smallskip\\ |
962 @{text "REG (\<lambda>x\<^sup>\<sigma>. t, \<lambda>x\<^sup>\<tau>. s)"} & $\dn$ & |
971 @{text "REG (\<lambda>x\<^sup>\<sigma>. t, \<lambda>x\<^sup>\<tau>. s)"} $\dn$ |
963 $\begin{cases} |
972 $\begin{cases} |
964 @{text "\<lambda>x\<^sup>\<sigma>. REG (t, s)"} \quad\mbox{provided @{text "\<sigma> = \<tau>"}}\\ |
973 @{text "\<lambda>x\<^sup>\<sigma>. REG (t, s)"} \quad\mbox{provided @{text "\<sigma> = \<tau>"}}\\ |
965 @{text "\<lambda>x\<^sup>\<sigma> \<in> Respects (REL (\<sigma>, \<tau>)). REG (t, s)"} |
974 @{text "\<lambda>x\<^sup>\<sigma> \<in> Respects (REL (\<sigma>, \<tau>)). REG (t, s)"} |
966 \end{cases}$\smallskip\\ |
975 \end{cases}$\smallskip\\ |
967 \\ |
976 \\ |
968 \multicolumn{3}{@ {}l}{universal quantifiers:}\\ |
977 \multicolumn{1}{@ {}l}{universal quantifiers:}\\ |
969 @{text "REG (\<forall>x\<^sup>\<sigma>. t, \<forall>x\<^sup>\<tau>. s)"} & $\dn$ & |
978 @{text "REG (\<forall>x\<^sup>\<sigma>. t, \<forall>x\<^sup>\<tau>. s)"} $\dn$ |
970 $\begin{cases} |
979 $\begin{cases} |
971 @{text "\<forall>x\<^sup>\<sigma>. REG (t, s)"} \quad\mbox{provided @{text "\<sigma> = \<tau>"}}\\ |
980 @{text "\<forall>x\<^sup>\<sigma>. REG (t, s)"} \quad\mbox{provided @{text "\<sigma> = \<tau>"}}\\ |
972 @{text "\<forall>x\<^sup>\<sigma> \<in> Respects (REL (\<sigma>, \<tau>)). REG (t, s)"} |
981 @{text "\<forall>x\<^sup>\<sigma> \<in> Respects (REL (\<sigma>, \<tau>)). REG (t, s)"} |
973 \end{cases}$\smallskip\\ |
982 \end{cases}$\smallskip\\ |
974 \multicolumn{3}{@ {}l}{equality:}\smallskip\\ |
983 \multicolumn{1}{@ {}l}{equality:}\smallskip\\ |
975 %% REL of two equal types is the equality so we do not need a separate case |
984 %% REL of two equal types is the equality so we do not need a separate case |
976 @{text "REG (=\<^bsup>\<sigma>\<Rightarrow>\<sigma>\<Rightarrow>bool\<^esup>, =\<^bsup>\<tau>\<Rightarrow>\<tau>\<Rightarrow>bool\<^esup>)"} & $\dn$ & @{text "REL (\<sigma>, \<tau>)"}\\\smallskip\\ |
985 @{text "REG (=\<^bsup>\<sigma>\<Rightarrow>\<sigma>\<Rightarrow>bool\<^esup>, =\<^bsup>\<tau>\<Rightarrow>\<tau>\<Rightarrow>bool\<^esup>)"} $\dn$ @{text "REL (\<sigma>, \<tau>)"}\\\smallskip\\ |
977 \multicolumn{3}{@ {}l}{applications, variables and constants:}\\ |
986 \multicolumn{1}{@ {}l}{applications, variables and constants:}\\ |
978 @{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)"}\\ |
987 @{text "REG (t\<^isub>1 t\<^isub>2, s\<^isub>1 s\<^isub>2)"} $\dn$ @{text "REG (t\<^isub>1, s\<^isub>1) REG (t\<^isub>2, s\<^isub>2)"}\\ |
979 @{text "REG (x\<^isub>1, x\<^isub>2)"} & $\dn$ & @{text "x\<^isub>1"}\\ |
988 @{text "REG (x\<^isub>1, x\<^isub>2)"} $\dn$ @{text "x\<^isub>1"}\\ |
980 @{text "REG (c\<^isub>1, c\<^isub>2)"} & $\dn$ & @{text "c\<^isub>1"}\\ |
989 @{text "REG (c\<^isub>1, c\<^isub>2)"} $\dn$ @{text "c\<^isub>1"}\\ |
981 \end{tabular} |
990 \end{tabular} |
982 \end{center} |
991 \end{center} |
983 % |
992 % |
984 \noindent |
993 \noindent |
985 In the above definition we omitted the cases for existential quantifiers |
994 In the above definition we omitted the cases for existential quantifiers |
989 Next we define the function @{text INJ} which takes as argument |
998 Next we define the function @{text INJ} which takes as argument |
990 @{text "reg_thm"} and @{text "quot_thm"} (both as |
999 @{text "reg_thm"} and @{text "quot_thm"} (both as |
991 terms) and returns @{text "inj_thm"}: |
1000 terms) and returns @{text "inj_thm"}: |
992 |
1001 |
993 \begin{center} |
1002 \begin{center} |
994 \begin{tabular}{rcl} |
1003 \begin{tabular}{l} |
995 \multicolumn{3}{@ {\hspace{-4mm}}l}{abstractions:}\\ |
1004 \multicolumn{1}{@ {}l}{abstractions:}\\ |
996 @{text "INJ (\<lambda>x. t :: \<sigma>, \<lambda>x. s :: \<tau>) "} & $\dn$ & |
1005 @{text "INJ (\<lambda>x. t :: \<sigma>, \<lambda>x. s :: \<tau>) "} $\dn$\\ |
997 $\begin{cases} |
1006 \hspace{18mm}$\begin{cases} |
998 @{text "\<lambda>x. INJ (t, s)"} \quad\mbox{provided @{text "\<sigma> = \<tau>"}}\\ |
1007 @{text "\<lambda>x. INJ (t, s)"} \quad\mbox{provided @{text "\<sigma> = \<tau>"}}\\ |
999 @{text "REP (\<sigma>, \<tau>) (ABS (\<sigma>, \<tau>) (\<lambda>x. INJ (t, s)))"} |
1008 @{text "REP (\<sigma>, \<tau>) (ABS (\<sigma>, \<tau>) (\<lambda>x. INJ (t, s)))"} |
1000 \end{cases}$\\ |
1009 \end{cases}$\smallskip\\ |
1001 @{text "INJ (\<lambda>x \<in> R. t :: \<sigma>, \<lambda>x. s :: \<tau>) "} & $\dn$ |
1010 @{text "INJ (\<lambda>x \<in> R. t :: \<sigma>, \<lambda>x. s :: \<tau>) "} $\dn$\\ |
1002 & @{text "REP (\<sigma>, \<tau>) (ABS (\<sigma>, \<tau>) (\<lambda>x \<in> R. INJ (t, s)))"}\smallskip\\ |
1011 \hspace{18mm}@{text "REP (\<sigma>, \<tau>) (ABS (\<sigma>, \<tau>) (\<lambda>x \<in> R. INJ (t, s)))"}\smallskip\\ |
1003 \multicolumn{3}{@ {\hspace{-4mm}}l}{universal quantifiers:}\\ |
1012 \multicolumn{1}{@ {}l}{universal quantifiers:}\\ |
1004 @{text "INJ (\<forall> t, \<forall> s) "} & $\dn$ & @{text "\<forall> INJ (t, s)"}\\ |
1013 @{text "INJ (\<forall> t, \<forall> s) "} $\dn$ @{text "\<forall> INJ (t, s)"}\\ |
1005 @{text "INJ (\<forall> t \<in> R, \<forall> s) "} & $\dn$ & @{text "\<forall> INJ (t, s) \<in> R"}\smallskip\\ |
1014 @{text "INJ (\<forall> t \<in> R, \<forall> s) "} $\dn$ @{text "\<forall> INJ (t, s) \<in> R"}\smallskip\\ |
1006 \multicolumn{3}{@ {\hspace{-4mm}}l}{applications, variables and constants:}\smallskip\\ |
1015 \multicolumn{1}{@ {}l}{applications, variables and constants:}\smallskip\\ |
1007 @{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)"}\\ |
1016 @{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)"}\\ |
1008 @{text "INJ (x\<^isub>1\<^sup>\<sigma>, x\<^isub>2\<^sup>\<tau>) "} & $\dn$ & |
1017 @{text "INJ (x\<^isub>1\<^sup>\<sigma>, x\<^isub>2\<^sup>\<tau>) "} $\dn$ |
1009 $\begin{cases} |
1018 $\begin{cases} |
1010 @{text "x\<^isub>1"} \quad\mbox{provided @{text "\<sigma> = \<tau>"}}\\ |
1019 @{text "x\<^isub>1"} \quad\mbox{provided @{text "\<sigma> = \<tau>"}}\\ |
1011 @{text "REP (\<sigma>, \<tau>) (ABS (\<sigma>, \<tau>) x\<^isub>1)"}\\ |
1020 @{text "REP (\<sigma>, \<tau>) (ABS (\<sigma>, \<tau>) x\<^isub>1)"}\\ |
1012 \end{cases}$\\ |
1021 \end{cases}$\\ |
1013 @{text "INJ (c\<^isub>1\<^sup>\<sigma>, c\<^isub>2\<^sup>\<tau>) "} & $\dn$ & |
1022 @{text "INJ (c\<^isub>1\<^sup>\<sigma>, c\<^isub>2\<^sup>\<tau>) "} $\dn$ |
1014 $\begin{cases} |
1023 $\begin{cases} |
1015 @{text "c\<^isub>1"} \quad\mbox{provided @{text "\<sigma> = \<tau>"}}\\ |
1024 @{text "c\<^isub>1"} \quad\mbox{provided @{text "\<sigma> = \<tau>"}}\\ |
1016 @{text "REP (\<sigma>, \<tau>) (ABS (\<sigma>, \<tau>) c\<^isub>1)"}\\ |
1025 @{text "REP (\<sigma>, \<tau>) (ABS (\<sigma>, \<tau>) c\<^isub>1)"}\\ |
1017 \end{cases}$\\ |
1026 \end{cases}$\\ |
1018 \end{tabular} |
1027 \end{tabular} |