Quotient-Paper/Paper.thy
changeset 2332 9a560e489c64
parent 2319 7c8783d2dcd0
child 2333 a0fecce8b244
equal deleted inserted replaced
2331:f170ee51eed2 2332:9a560e489c64
   253   of \emph{aggregate equivalence relation}, \emph{respectfulness} and \emph{preservation}
   253   of \emph{aggregate equivalence relation}, \emph{respectfulness} and \emph{preservation}
   254   from Homeier \cite{Homeier05}.
   254   from Homeier \cite{Homeier05}.
   255 
   255 
   256   In addition we are able to address the criticism by Paulson \cite{Paulson06} cited
   256   In addition we are able to address the criticism by Paulson \cite{Paulson06} cited
   257   at the beginning of this section about having to collect theorems that are
   257   at the beginning of this section about having to collect theorems that are
   258   lifted from the raw level to the quotient level into one giant list. Our
   258   lifted from the raw level to the quotient level into one giant list. Homeier's and
   259   quotient package is the first one that is modular so that it allows to lift
   259   also our quotient package are modular so that they allow lifting
   260   single higher-order theorems separately. This has the advantage for the user of being able to develop a
   260   theorems separately. This has the advantage for the user of being able to develop a
   261   formal theory interactively as a natural progression. A pleasing side-result of
   261   formal theory interactively as a natural progression. A pleasing side-result of
   262   the modularity is that we are able to clearly specify what is involved
   262   the modularity is that we are able to clearly specify what is involved
   263   in the lifting process (this was only hinted at in \cite{Homeier05} and
   263   in the lifting process (this was only hinted at in \cite{Homeier05} and
   264   implemented as a ``rough recipe'' in ML-code).
   264   implemented as a ``rough recipe'' in ML-code).
   265 
   265 
   297   We often write just @{text \<kappa>} for @{text "() \<kappa>"}, and use @{text "\<alpha>s"} and
   297   We often write just @{text \<kappa>} for @{text "() \<kappa>"}, and use @{text "\<alpha>s"} and
   298   @{text "\<sigma>s"} to stand for collections of type variables and types,
   298   @{text "\<sigma>s"} to stand for collections of type variables and types,
   299   respectively.  The type of a term is often made explicit by writing @{text
   299   respectively.  The type of a term is often made explicit by writing @{text
   300   "t :: \<sigma>"}. HOL includes a type @{typ bool} for booleans and the function
   300   "t :: \<sigma>"}. HOL includes a type @{typ bool} for booleans and the function
   301   type, written @{text "\<sigma> \<Rightarrow> \<tau>"}. HOL also contains many primitive and defined
   301   type, written @{text "\<sigma> \<Rightarrow> \<tau>"}. HOL also contains many primitive and defined
   302   constants; a primitive constant is equality, with type @{text "= :: \<sigma> \<Rightarrow> \<sigma> \<Rightarrow>
   302   constants; for example, a primitive constant is equality, with type @{text "= :: \<sigma> \<Rightarrow> \<sigma> \<Rightarrow>
   303   bool"}, and the identity function with type @{text "id :: \<sigma> \<Rightarrow> \<sigma>"} is
   303   bool"}, and the identity function with type @{text "id :: \<sigma> \<Rightarrow> \<sigma>"} is
   304   defined as @{text "\<lambda>x\<^sup>\<sigma>. x\<^sup>\<sigma>"}).
   304   defined as @{text "\<lambda>x\<^sup>\<sigma>. x\<^sup>\<sigma>"}.
   305 
   305 
   306   An important point to note is that theorems in HOL can be seen as a subset
   306   An important point to note is that theorems in HOL can be seen as a subset
   307   of terms that are constructed specially (namely through axioms and proof
   307   of terms that are constructed specially (namely through axioms and proof
   308   rules). As a result we are able to define automatic proof
   308   rules). As a result we are able to define automatic proof
   309   procedures showing that one theorem implies another by decomposing the term
   309   procedures showing that one theorem implies another by decomposing the term
   316 
   316 
   317   @{thm [display, indent=10] fun_map_def[no_vars, THEN eq_reflection]}
   317   @{thm [display, indent=10] fun_map_def[no_vars, THEN eq_reflection]}
   318 
   318 
   319   \noindent
   319   \noindent
   320   Using this map-function, we can give the following, equivalent, but more 
   320   Using this map-function, we can give the following, equivalent, but more 
   321   uniform, definition for @{text add} shown in \eqref{adddef}:
   321   uniform definition for @{text add} shown in \eqref{adddef}:
   322 
   322 
   323   @{text [display, indent=10] "add \<equiv> (Rep_int \<singlearr> Rep_int \<singlearr> Abs_int) add_pair"}
   323   @{text [display, indent=10] "add \<equiv> (Rep_int \<singlearr> Rep_int \<singlearr> Abs_int) add_pair"}
   324 
   324 
   325   \noindent
   325   \noindent
   326   Using extensionality and unfolding the definition of @{text "\<singlearr>"}, 
   326   Using extensionality and unfolding the definition of @{text "\<singlearr>"}, 
   372   \item @{thm (rhs3) Quotient_def[of "R", no_vars]}
   372   \item @{thm (rhs3) Quotient_def[of "R", no_vars]}
   373   \end{enumerate}
   373   \end{enumerate}
   374   \end{definition}
   374   \end{definition}
   375 
   375 
   376   \noindent
   376   \noindent
   377   The value of this definition is that validity of @{text "Quotient R Abs Rep"} can 
   377   The value of this definition lies in the fact that validity of @{text "Quotient R Abs Rep"} can 
   378   often be proved in terms of the validity of @{text "Quotient"} over the constituent 
   378   often be proved in terms of the validity of @{text "Quotient"} over the constituent 
   379   types of @{text "R"}, @{text Abs} and @{text Rep}. 
   379   types of @{text "R"}, @{text Abs} and @{text Rep}. 
   380   For example Homeier proves the following property for higher-order quotient
   380   For example Homeier proves the following property for higher-order quotient
   381   types:
   381   types:
   382  
   382  
   401   \end{definition}
   401   \end{definition}
   402 
   402 
   403   \noindent
   403   \noindent
   404   Unfortunately, there are two predicaments with compositions of relations.
   404   Unfortunately, there are two predicaments with compositions of relations.
   405   First, a general quotient theorem, like the one given in Proposition \ref{funquot},
   405   First, a general quotient theorem, like the one given in Proposition \ref{funquot},
   406   cannot be stated inside HOL, because of the restriction on types.
   406   cannot be stated inside HOL, because of restrictions on types.
   407   Second, even if we were able to state such a quotient theorem, it
   407   Second, even if we were able to state such a quotient theorem, it
   408   would not be true in general. However, we can prove specific instances of a
   408   would not be true in general. However, we can prove specific instances of a
   409   quotient theorem for composing particular quotient relations.
   409   quotient theorem for composing particular quotient relations.
   410   For example, to lift theorems involving @{term flat} the quotient theorem for 
   410   For example, to lift theorems involving @{term flat} the quotient theorem for 
   411   composing @{text "\<approx>\<^bsub>list\<^esub>"} will be necessary: given @{term "Quotient R Abs Rep"} 
   411   composing @{text "\<approx>\<^bsub>list\<^esub>"} will be necessary: given @{term "Quotient R Abs Rep"} 
   513   The first one declares zero for integers and the second the operator for
   513   The first one declares zero for integers and the second the operator for
   514   building unions of finite sets (@{text "flat"} having the type 
   514   building unions of finite sets (@{text "flat"} having the type 
   515   @{text "(\<alpha> list) list \<Rightarrow> \<alpha> list"}). 
   515   @{text "(\<alpha> list) list \<Rightarrow> \<alpha> list"}). 
   516 
   516 
   517   The problem for us is that from such declarations we need to derive proper
   517   The problem for us is that from such declarations we need to derive proper
   518   definitions using the @{text "Abs"} and @{text "Rep"} functions for the
   518   definitions using @{text "Abs"} and @{text "Rep"}. The data we rely on is the given quotient type
   519   quotient types involved. The data we rely on is the given quotient type
       
   520   @{text "\<tau>"} and the raw type @{text "\<sigma>"}.  They allow us to define \emph{aggregate
   519   @{text "\<tau>"} and the raw type @{text "\<sigma>"}.  They allow us to define \emph{aggregate
   521   abstraction} and \emph{representation functions} using the functions @{text "ABS (\<sigma>,
   520   abstraction} and \emph{representation functions} using the functions @{text "ABS (\<sigma>,
   522   \<tau>)"} and @{text "REP (\<sigma>, \<tau>)"} whose clauses we give below. The idea behind
   521   \<tau>)"} and @{text "REP (\<sigma>, \<tau>)"} whose clauses we shall give below. The idea behind
   523   these two functions is to simultaneously descend into the raw types @{text \<sigma>} and 
   522   these two functions is to simultaneously descend into the raw types @{text \<sigma>} and 
   524   quotient types @{text \<tau>}, and generate the appropriate
   523   quotient types @{text \<tau>}, and generate the appropriate
   525   @{text "Abs"} and @{text "Rep"} in places where the types differ. Therefore
   524   @{text "Abs"} and @{text "Rep"} in places where the types differ. Therefore
   526   we generate just the identity whenever the types are equal. On the ``way'' down,
   525   we generate just the identity whenever the types are equal. On the ``way'' down,
   527   however we might have to use map-functions to let @{text Abs} and @{text Rep} act
   526   however we might have to use map-functions to let @{text Abs} and @{text Rep} act
   528   over the appropriate types. In what follows we use the short-hand notation 
   527   over the appropriate types. In what follows we use the short-hand notation 
   529   @{text "ABS (\<sigma>s, \<tau>s)"} to mean @{text "ABS (\<sigma>\<^isub>1, \<tau>\<^isub>1)\<dots>ABS (\<sigma>\<^isub>i, \<tau>\<^isub>i)"}; similarly 
   528   @{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 
   530   for @{text REP}.
   529   for @{text REP}.
   531   %
   530   %
   532   \begin{center}
   531   \begin{center}
   533   \hfill
   532   \hfill
   534   \begin{tabular}{rcl}
   533   \begin{tabular}{rcl}
   655 
   654 
   656 text {*
   655 text {*
   657   The main point of the quotient package is to automatically ``lift'' theorems
   656   The main point of the quotient package is to automatically ``lift'' theorems
   658   involving constants over the raw type to theorems involving constants over
   657   involving constants over the raw type to theorems involving constants over
   659   the quotient type. Before we can describe this lifting process, we need to impose 
   658   the quotient type. Before we can describe this lifting process, we need to impose 
   660   two restrictions in the form of proof obligations that arise during the
   659   two restrictions in form of proof obligations that arise during the
   661   lifting. The reason is that even if definitions for all raw constants 
   660   lifting. The reason is that even if definitions for all raw constants 
   662   can be given, \emph{not} all theorems can be lifted to the quotient type. Most 
   661   can be given, \emph{not} all theorems can be lifted to the quotient type. Most 
   663   notable is the bound variable function, that is the constant @{text bn}, defined 
   662   notable is the bound variable function, that is the constant @{text bn}, defined 
   664   for raw lambda-terms as follows
   663   for raw lambda-terms as follows
   665 
   664 
   697   The @{text "\<sigma>s'"} in the last clause are calculated as in \eqref{ABSREP}:
   696   The @{text "\<sigma>s'"} in the last clause are calculated as in \eqref{ABSREP}:
   698   we know that type @{text "\<alpha>s \<kappa>\<^isub>q"} is the quotient of the raw type 
   697   we know that type @{text "\<alpha>s \<kappa>\<^isub>q"} is the quotient of the raw type 
   699   @{text "\<rho>s \<kappa>"}. The @{text "\<sigma>s'"} are determined by matching 
   698   @{text "\<rho>s \<kappa>"}. The @{text "\<sigma>s'"} are determined by matching 
   700   @{text "\<rho>s \<kappa>"} and @{text "\<sigma>s \<kappa>"}.
   699   @{text "\<rho>s \<kappa>"} and @{text "\<sigma>s \<kappa>"}.
   701 
   700 
   702   Lets return to the lifting procedure of theorems. Assume we have a theorem
   701   Let us return to the lifting procedure of theorems. Assume we have a theorem
   703   that contains the raw constant @{text "c\<^isub>r :: \<sigma>"} and which we want to
   702   that contains the raw constant @{text "c\<^isub>r :: \<sigma>"} and which we want to
   704   lift to a theorem where @{text "c\<^isub>r"} is replaced by the corresponding
   703   lift to a theorem where @{text "c\<^isub>r"} is replaced by the corresponding
   705   constant @{text "c\<^isub>q :: \<tau>"} defined over a quotient type. In this situation 
   704   constant @{text "c\<^isub>q :: \<tau>"} defined over a quotient type. In this situation 
   706   we generate the following proof obligation
   705   we generate the following proof obligation
   707 
   706 
   715   @{text \<sigma>} and @{text \<tau>} are not completely determined by the type of @{text "c\<^bsub>r\<^esub>"}.
   714   @{text \<sigma>} and @{text \<tau>} are not completely determined by the type of @{text "c\<^bsub>r\<^esub>"}.
   716   And for every instantiation of the types, we might end up with a 
   715   And for every instantiation of the types, we might end up with a 
   717   corresponding respectfulness theorem.
   716   corresponding respectfulness theorem.
   718 
   717 
   719   Before lifting a theorem, we require the user to discharge
   718   Before lifting a theorem, we require the user to discharge
   720   respectfulness proof obligations. And the point with @{text bn} is that the respectfulness theorem
   719   respectfulness proof obligations. In case of @{text bn}
   721   looks as follows
   720   this obligation is as follows
   722 
   721 
   723   @{text [display, indent=10] "(\<approx>\<^isub>\<alpha> \<doublearr> =) bn bn"}
   722   @{text [display, indent=10] "(\<approx>\<^isub>\<alpha> \<doublearr> =) bn bn"}
   724 
   723 
   725   \noindent
   724   \noindent
   726   and the user cannot discharge it: because it is not true. To see this,
   725   and the point is that the user cannot discharge it: because it is not true. To see this,
   727   we can just unfold the definition of @{text "\<doublearr>"} \eqref{relfun} 
   726   we can just unfold the definition of @{text "\<doublearr>"} \eqref{relfun} 
   728   using extensionally to obtain
   727   using extensionally to obtain the false statement
   729 
   728 
   730   @{text [display, indent=10] "\<forall>t\<^isub>1 t\<^isub>2. if t\<^isub>1 \<approx>\<^isub>\<alpha> t\<^isub>2 implies bn(t\<^isub>1) = bn(t\<^isub>2)"}
   729   @{text [display, indent=10] "\<forall>t\<^isub>1 t\<^isub>2. if t\<^isub>1 \<approx>\<^isub>\<alpha> t\<^isub>2 implies bn(t\<^isub>1) = bn(t\<^isub>2)"}
   731  
   730  
   732   \noindent
   731   \noindent
   733   In contrast, if we lift a theorem about @{text "append"} to a theorem describing 
   732   In contrast, if we lift a theorem about @{text "append"} to a theorem describing 
   747   which is straightforward given the definition shown in \eqref{listequiv}.
   746   which is straightforward given the definition shown in \eqref{listequiv}.
   748 
   747 
   749   The second restriction we have to impose arises from
   748   The second restriction we have to impose arises from
   750   non-lifted polymorphic constants, which are instantiated to a
   749   non-lifted polymorphic constants, which are instantiated to a
   751   type being quotient. For example, take the @{term "cons"}-constructor to 
   750   type being quotient. For example, take the @{term "cons"}-constructor to 
   752   add a pair of natural numbers to a list, whereby teh pair of natural numbers 
   751   add a pair of natural numbers to a list, whereby the pair of natural numbers 
   753   is to become an integer in te quotient construction. The point is that we 
   752   turns into an integer in the quotient construction. The point is that we 
   754   still want to use @{text cons} for
   753   still want to use @{text cons} for
   755   adding integers to lists---just with a different type. 
   754   adding integers to lists---just with a different type. 
   756   To be able to lift such theorems, we need a \emph{preservation property} 
   755   To be able to lift such theorems, we need a \emph{preservation property} 
   757   for @{text cons}. Assuming we have a polymorphic raw constant 
   756   for @{text cons}. Assuming we have a polymorphic raw constant 
   758   @{text "c\<^isub>r :: \<sigma>"} and a corresponding quotient constant @{text "c\<^isub>q :: \<tau>"}, 
   757   @{text "c\<^isub>r :: \<sigma>"} and a corresponding quotient constant @{text "c\<^isub>q :: \<tau>"}, 
   813 
   812 
   814   The purpose of regularization is to change the quantifiers and abstractions
   813   The purpose of regularization is to change the quantifiers and abstractions
   815   in a ``raw'' theorem to quantifiers over variables that respect the relation
   814   in a ``raw'' theorem to quantifiers over variables that respect the relation
   816   (Definition \ref{def:respects} states what respects means). The purpose of injection is to add @{term Rep}
   815   (Definition \ref{def:respects} states what respects means). The purpose of injection is to add @{term Rep}
   817   and @{term Abs} of appropriate types in front of constants and variables
   816   and @{term Abs} of appropriate types in front of constants and variables
   818   of the raw type so that they can be replaced by the ones that include the
   817   of the raw type so that they can be replaced by the corresponding constants from the
   819   quotient type. The purpose of cleaning is to bring the theorem derived in the
   818   quotient type. The purpose of cleaning is to bring the theorem derived in the
   820   first two phases into the form the user has specified. Abstractly, our
   819   first two phases into the form the user has specified. Abstractly, our
   821   package establishes the following three proof steps:
   820   package establishes the following three proof steps:
   822 
   821 
   823   \begin{center}
   822   \begin{center}
   930   quantifiers.
   929   quantifiers.
   931 
   930 
   932   In the first proof step, establishing @{text "raw_thm \<longrightarrow> reg_thm"}, we always 
   931   In the first proof step, establishing @{text "raw_thm \<longrightarrow> reg_thm"}, we always 
   933   start with an implication. Isabelle provides \emph{mono} rules that can split up 
   932   start with an implication. Isabelle provides \emph{mono} rules that can split up 
   934   the implications into simpler implicational subgoals. This succeeds for every
   933   the implications into simpler implicational subgoals. This succeeds for every
   935   monotone connective, except in places where the function @{text REG} inserted,
   934   monotone connective, except in places where the function @{text REG} replaced,
   936   for instance, a quantifier by a bounded quantifier. In this case we have 
   935   for instance, a quantifier by a bounded quantifier. In this case we have 
   937   rules of the form
   936   rules of the form
   938 
   937 
   939   @{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)"}
   938   @{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)"}
   940 
   939 
   945   relation. If @{text R} is an equivalence relation we can prove that
   944   relation. If @{text R} is an equivalence relation we can prove that
   946 
   945 
   947   @{text [display, indent=10] "\<forall>x \<in> Respects R. P x = \<forall>x. P x"}    
   946   @{text [display, indent=10] "\<forall>x \<in> Respects R. P x = \<forall>x. P x"}    
   948 
   947 
   949   \noindent
   948   \noindent
   950   And when @{term R\<^isub>2} is an equivalence relation and we can prove
   949   If @{term R\<^isub>2} is an equivalence relation, we can prove
   951 
   950 
   952   @{thm [display, indent=10] (concl) ball_reg_eqv_range[of R\<^isub>1 R\<^isub>2, no_vars]}
   951   @{thm [display, indent=10] (concl) ball_reg_eqv_range[of R\<^isub>1 R\<^isub>2, no_vars]}
   953 
   952 
   954   \noindent
   953   \noindent
   955   The last theorem is new in comparison with Homeier's package. There the
   954   The last theorem is new in comparison with Homeier's package. There the
   956   injection procedure would be used to prove such goals, and 
   955   injection procedure would be used to prove such goals and 
   957   the assumption about the equivalence relation would be used. We use the above theorem directly,
   956   the assumption about the equivalence relation would be used. We use the above theorem directly,
   958   because this allows us to completely separate the first and the second
   957   because this allows us to completely separate the first and the second
   959   proof step into two independent ``units''.
   958   proof step into two independent ``units''.
   960 
   959 
   961   The second proof step, establishing @{text "reg_thm \<longleftrightarrow> inj_thm"},  starts with an equality. 
   960   The second proof step, establishing @{text "reg_thm \<longleftrightarrow> inj_thm"},  starts with an equality. 
   962   The proof again follows the structure of the
   961   The proof again follows the structure of the
   963   two underlying terms, and is defined for a goal being a relation between these two terms.
   962   two underlying terms and is defined for a goal being a relation between these two terms.
   964 
   963 
   965   \begin{itemize}
   964   \begin{itemize}
   966   \item For two constants an appropriate constant respectfulness lemma is applied.
   965   \item For two constants an appropriate respectfulness theorem is applied.
   967   \item For two variables, we use the assumptions proved in the regularization step.
   966   \item For two variables, we use the assumptions proved in the regularization step.
   968   \item For two abstractions, we @{text "\<eta>"}-expand and @{text "\<beta>"}-reduce them.
   967   \item For two abstractions, we @{text "\<eta>"}-expand and @{text "\<beta>"}-reduce them.
   969   \item For two applications, we check that the right-hand side is an application of
   968   \item For two applications, we check that the right-hand side is an application of
   970     @{term Rep} to an @{term Abs} and @{term "Quotient R Rep Abs"}. If yes then we
   969     @{term Rep} to an @{term Abs} and @{term "Quotient R Rep Abs"} holds. If yes then we
   971     can apply the theorem:
   970     can apply the theorem:
   972 
   971 
   973     @{term [display, indent=10] "R x y \<longrightarrow> R x (Rep (Abs y))"}
   972     @{term [display, indent=10] "R x y \<longrightarrow> R x (Rep (Abs y))"}
   974 
   973 
   975     Otherwise we introduce an appropriate relation between the subterms
   974     Otherwise we introduce an appropriate relation between the subterms
   992 
   991 
   993     @{thm [display, indent=10] (concl) lambda_prs[of _ "Abs\<^isub>1" "Rep\<^isub>1" "Abs\<^isub>2" "Rep\<^isub>2", no_vars]}
   992     @{thm [display, indent=10] (concl) lambda_prs[of _ "Abs\<^isub>1" "Rep\<^isub>1" "Abs\<^isub>2" "Rep\<^isub>2", no_vars]}
   994 
   993 
   995   \noindent
   994   \noindent
   996   Next, relations over lifted types are folded to equalities.
   995   Next, relations over lifted types are folded to equalities.
   997   For this the following theorem has been shown in Homeier~\cite{Homeier05}:
   996   For this the following theorem has been shown by  Homeier~\cite{Homeier05}:
   998 
   997 
   999     @{thm [display, indent=10] (concl) Quotient_rel_rep[no_vars]}
   998     @{thm [display, indent=10] (concl) Quotient_rel_rep[no_vars]}
  1000 
   999 
  1001   \noindent
  1000   \noindent
  1002   Finally, we rewrite with the preservation theorems. This will result
  1001   Finally, we rewrite with the preservation theorems. This will result
  1007 
  1006 
  1008 (* Mention why equivalence *)
  1007 (* Mention why equivalence *)
  1009 
  1008 
  1010 text {*
  1009 text {*
  1011 
  1010 
  1012   In this section we will show, a complete interaction with the quotient package
  1011   In this section we will show a sequence of declarations for defining the 
  1013   for defining the type of integers by quotienting pairs of natural numbers and
  1012   type of integers by quotienting pairs of natural numbers, and
  1014   lifting theorems to integers. Our quotient package is fully compatible with
  1013   lifting one theorem. 
  1015   Isabelle type classes, but for clarity we will not use them in this example.
       
  1016   In a larger formalization of integers using the type class mechanism would
       
  1017   provide many algebraic properties ``for free''.
       
  1018 
  1014 
  1019   A user of our quotient package first needs to define a relation on
  1015   A user of our quotient package first needs to define a relation on
  1020   the raw type, by which the quotienting will be performed. We give
  1016   the raw type with which the quotienting will be performed. We give
  1021   the same integer relation as the one presented in \eqref{natpairequiv}:
  1017   the same integer relation as the one presented in \eqref{natpairequiv}:
  1022 
  1018 
  1023   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %
  1019   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %
  1024   \begin{tabular}{@ {}l}
  1020   \begin{tabular}{@ {}l}
  1025   \isacommand{fun}~~@{text "int_rel :: (nat \<times> nat) \<Rightarrow> (nat \<times> nat) \<Rightarrow> (nat \<times> nat)"}\\
  1021   \isacommand{fun}~~@{text "int_rel :: (nat \<times> nat) \<Rightarrow> (nat \<times> nat) \<Rightarrow> (nat \<times> nat)"}\\
  1026   \isacommand{where}~~@{text "int_rel (m, n) (p, q) = (m + q = n + p)"}
  1022   \isacommand{where}~~@{text "int_rel (m, n) (p, q) = (m + q = n + p)"}
  1027   \end{tabular}
  1023   \end{tabular}
  1028   \end{isabelle}
  1024   \end{isabelle}
  1029 
  1025 
  1030   \noindent
  1026   \noindent
  1031   Next the quotient type is defined. This generates a proof obligation that the
  1027   Next the quotient type must be defined. This generates a proof obligation that the
  1032   relation is an equivalence relation, which is solved automatically using the
  1028   relation is an equivalence relation, which is solved automatically using the
  1033   definition and extensionality:
  1029   definition of equivalence and extensionality:
  1034 
  1030 
  1035   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %
  1031   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %
  1036   \begin{tabular}{@ {}l}
  1032   \begin{tabular}{@ {}l}
  1037   \isacommand{quotient\_type}~~@{text "int"}~~\isacommand{=}~~@{text "(nat \<times> nat)"}~~\isacommand{/}~~@{text "int_rel"}\\
  1033   \isacommand{quotient\_type}~~@{text "int"}~~\isacommand{=}~~@{text "(nat \<times> nat)"}~~\isacommand{/}~~@{text "int_rel"}\\
  1038   \hspace{5mm}@{text "by (auto simp add: equivp_def expand_fun_eq)"}
  1034   \hspace{5mm}@{text "by (auto simp add: equivp_def expand_fun_eq)"}
  1058   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %
  1054   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %
  1059   \isacommand{lemma}~~@{text "add_pair_zero: int_rel (add_pair (0, 0) x) x"}
  1055   \isacommand{lemma}~~@{text "add_pair_zero: int_rel (add_pair (0, 0) x) x"}
  1060   \end{isabelle}
  1056   \end{isabelle}
  1061 
  1057 
  1062   \noindent
  1058   \noindent
  1063   If the user attempts to lift this theorem, all proof obligations are 
  1059   If the user lifts this theorem, all proof obligations are 
  1064   automatically discharged, except the respectfulness
  1060   automatically discharged, except the respectfulness
  1065   proof for @{text "add_pair"}:
  1061   proof for @{text "add_pair"}:
  1066 
  1062 
  1067   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %
  1063   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %
  1068   \begin{tabular}{@ {}l}
  1064   \begin{tabular}{@ {}l}
  1070   @{text "(int_rel \<doublearr> int_rel \<doublearr> int_rel) add_pair add_pair"}
  1066   @{text "(int_rel \<doublearr> int_rel \<doublearr> int_rel) add_pair add_pair"}
  1071   \end{tabular}
  1067   \end{tabular}
  1072   \end{isabelle}
  1068   \end{isabelle}
  1073 
  1069 
  1074   \noindent
  1070   \noindent
  1075   This can be discharged automatically by Isabelle when telling it to unfold the definition
  1071   This property needs to beproved by the user. It
       
  1072   can be discharged automatically by Isabelle when hinting to unfold the definition
  1076   of @{text "\<doublearr>"}.
  1073   of @{text "\<doublearr>"}.
  1077   After this, the user can prove the lifted lemma explicitly:
  1074   After this, the user can prove the lifted lemma as follows:
  1078 
  1075 
  1079   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %
  1076   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %
  1080   \isacommand{lemma}~~@{text "0 + (x :: int) = x"}~~\isacommand{by}~~@{text "lifting add_pair_zero"}
  1077   \isacommand{lemma}~~@{text "0 + (x :: int) = x"}~~\isacommand{by}~~@{text "lifting add_pair_zero"}
  1081   \end{isabelle}
  1078   \end{isabelle}
  1082 
  1079 
  1083   \noindent
  1080   \noindent
  1084   or by the completely automated mode by stating:
  1081   or by using the completely automated stating just:
  1085 
  1082 
  1086   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %
  1083   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %
  1087   \isacommand{thm}~~@{text "add_pair_zero[quot_lifted]"}
  1084   \isacommand{thm}~~@{text "add_pair_zero[quot_lifted]"}
  1088   \end{isabelle}
  1085   \end{isabelle}
  1089 
  1086 
  1128   in PVS~\cite{PVS:Interpretations}, new types in MetaPRL~\cite{Nogin02}, 
  1125   in PVS~\cite{PVS:Interpretations}, new types in MetaPRL~\cite{Nogin02}, 
  1129   and setoids in Coq \cite{ChicliPS02}.
  1126   and setoids in Coq \cite{ChicliPS02}.
  1130   Paulson showed a construction of quotients that does not require the
  1127   Paulson showed a construction of quotients that does not require the
  1131   Hilbert Choice operator, but also only first-order theorems can be lifted~\cite{Paulson06}.
  1128   Hilbert Choice operator, but also only first-order theorems can be lifted~\cite{Paulson06}.
  1132   The most related work to our package is the package for HOL4 by Homeier~\cite{Homeier05}.
  1129   The most related work to our package is the package for HOL4 by Homeier~\cite{Homeier05}.
  1133   He introduced most of the abstract notions about quotients and also deals with the
  1130   He introduced most of the abstract notions about quotients and also deals with
  1134   lifting of higher-order theorems. However, he cannot deal with quotient compositions (needed
  1131   lifting of higher-order theorems. However, he cannot deal with quotient compositions (needed
  1135   for lifting theorems about @{text flat}). Also, a number of his definitions, like @{text ABS},
  1132   for lifting theorems about @{text flat}). Also, a number of his definitions, like @{text ABS},
  1136   @{text REP} and @{text INJ} etc only exist in \cite{Homeier05} as ML-code, not included
  1133   @{text REP} and @{text INJ} etc only exist in \cite{Homeier05} as ML-code, not included
  1137   in the paper. 
  1134   in the paper. 
  1138 
  1135 
  1139   One advantage of our package is that it is modular---in the sense that every step
  1136   One feature of our quotient package is that when lifting theorems, the user can
  1140   in the quotient construction can be done independently (see the criticism of Paulson
       
  1141   about other quotient packages). This modularity is essential in the context of
       
  1142   Isabelle, which supports type-classes and locales.
       
  1143 
       
  1144   Another feature of our quotient package is that when lifting theorems, teh user can
       
  1145   precisely specify what the lifted theorem should look like. This feature is
  1137   precisely specify what the lifted theorem should look like. This feature is
  1146   necessary, for example, when lifting an induction principle for two lists.
  1138   necessary, for example, when lifting an induction principle for two lists.
  1147   This principle has as the conclusion a predicate of the form @{text "P xs ys"},
  1139   Assuming this principle has as the conclusion a predicate of the form @{text "P xs ys"},
  1148   and we can precisely specify whether we want to quotient @{text "xs"} or @{text "ys"},
  1140   then we can precisely specify whether we want to quotient @{text "xs"} or @{text "ys"},
  1149   or both. We found this feature very useful in the new version of Nominal 
  1141   or both. We found this feature very useful in the new version of Nominal 
  1150   Isabelle, where such a choice is required to generate a resoning infrastructure
  1142   Isabelle, where such a choice is required to generate a resoning infrastructure
  1151   for alpha-equated terms. 
  1143   for alpha-equated terms. 
  1152 %%
  1144 %%
  1153 %% give an example for this
  1145 %% give an example for this