Quotient-Paper/Paper.thy
changeset 2327 bcb037806e16
parent 2287 adb5b1349280
child 2319 7c8783d2dcd0
equal deleted inserted replaced
2326:b51532dd5689 2327:bcb037806e16
     2 theory Paper
     2 theory Paper
     3 imports "Quotient"
     3 imports "Quotient"
     4         "LaTeXsugar"
     4         "LaTeXsugar"
     5         "../Nominal/FSet"
     5         "../Nominal/FSet"
     6 begin
     6 begin
       
     7 
       
     8 (****
       
     9 
       
    10 ** things to do for the next version
       
    11 *
       
    12 * - what are quot_thms?
       
    13 * - what do all preservation theorems look like,
       
    14     in particular preservation for quotient
       
    15     compositions
       
    16 *)
     7 
    17 
     8 notation (latex output)
    18 notation (latex output)
     9   rel_conj ("_ \<circ>\<circ>\<circ> _" [53, 53] 52) and
    19   rel_conj ("_ \<circ>\<circ>\<circ> _" [53, 53] 52) and
    10   pred_comp ("_ \<circ>\<circ> _" [1, 1] 30) and
    20   pred_comp ("_ \<circ>\<circ> _" [1, 1] 30) and
    11   "op -->" (infix "\<longrightarrow>" 100) and
    21   "op -->" (infix "\<longrightarrow>" 100) and
   288   @{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,
   289   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
   290   "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
   291   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
   292   constants; a primitive constant is equality, with type @{text "= :: \<sigma> \<Rightarrow> \<sigma> \<Rightarrow>
   302   constants; a primitive constant is equality, with type @{text "= :: \<sigma> \<Rightarrow> \<sigma> \<Rightarrow>
   293   bool"}, and the identity function with type @{text "id :: \<sigma> => \<sigma>"} is
   303   bool"}, and the identity function with type @{text "id :: \<sigma> \<Rightarrow> \<sigma>"} is
   294   defined as @{text "\<lambda>x\<^sup>\<sigma>. x\<^sup>\<sigma>"}).
   304   defined as @{text "\<lambda>x\<^sup>\<sigma>. x\<^sup>\<sigma>"}).
   295 
   305 
   296   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
   297   of terms that are constructed specially (namely through axioms and prove
   307   of terms that are constructed specially (namely through axioms and proof
   298   rules). As a result we are able to define automatic proof
   308   rules). As a result we are able to define automatic proof
   299   procedures showing that one theorem implies another by decomposing the term
   309   procedures showing that one theorem implies another by decomposing the term
   300   underlying the first theorem.
   310   underlying the first theorem.
   301 
   311 
   302   Like Homeier, our work relies on map-functions defined for every type
   312   Like Homeier, our work relies on map-functions defined for every type
   394   First, a general quotient theorem, like the one given in Proposition \ref{funquot},
   404   First, a general quotient theorem, like the one given in Proposition \ref{funquot},
   395   cannot be stated inside HOL, because of the restriction on types.
   405   cannot be stated inside HOL, because of the restriction on types.
   396   Second, even if we were able to state such a quotient theorem, it
   406   Second, even if we were able to state such a quotient theorem, it
   397   would not be true in general. However, we can prove specific instances of a
   407   would not be true in general. However, we can prove specific instances of a
   398   quotient theorem for composing particular quotient relations.
   408   quotient theorem for composing particular quotient relations.
   399   To lift @{term flat} the quotient theorem for composing @{text "\<approx>\<^bsub>list\<^esub>"}
   409   For example, to lift theorems involving @{term flat} the quotient theorem for 
   400   is necessary:
   410   composing @{text "\<approx>\<^bsub>list\<^esub>"} will be necessary: given @{term "Quotient R Abs Rep"} 
   401 % It says when lists are being quotiented to finite sets,
   411   with @{text R} being an equivalence relation, then
   402 % the contents of the lists can be quotiented as well
   412 
   403  If @{term R} is an equivalence relation and @{term "Quotient R Abs Rep"} then
   413   @{text [display, indent=10] "Quotient (list_rel R \<circ>\<circ>\<circ> \<approx>\<^bsub>list\<^esub>) (abs_fset \<circ> map Abs) (map Rep \<circ> rep_fset)"}
   404 
       
   405   @{text [display, indent=10] "Quotient (list_rel R \<circ>\<circ>\<circ> \<approx>\<^bsub>list\<^esub>) (abs_fset \<circ> map Abs) (map Rep o rep_fset)"}
       
   406 
   414 
   407   \vspace{-.5mm}
   415   \vspace{-.5mm}
   408 
       
   409 
       
   410 *}
   416 *}
   411 
   417 
   412 section {* Quotient Types and Quotient Definitions\label{sec:type} *}
   418 section {* Quotient Types and Quotient Definitions\label{sec:type} *}
   413 
   419 
   414 text {*
   420 text {*
   474   respectively.  Given that @{text "R"} is an equivalence relation, the
   480   respectively.  Given that @{text "R"} is an equivalence relation, the
   475   following property holds  for every quotient type 
   481   following property holds  for every quotient type 
   476   (for the proof see \cite{Homeier05}).
   482   (for the proof see \cite{Homeier05}).
   477 
   483 
   478   \begin{proposition}
   484   \begin{proposition}
   479   @{text "Quotient R Abs_\<kappa>\<^isub>q Rep_\<kappa>\<^isub>q"}
   485   @{text "Quotient R Abs_\<kappa>\<^isub>q Rep_\<kappa>\<^isub>q"}.
   480   \end{proposition}
   486   \end{proposition}
   481 
   487 
   482   The next step in a quotient construction is to introduce definitions of new constants
   488   The next step in a quotient construction is to introduce definitions of new constants
   483   involving the quotient type. These definitions need to be given in terms of concepts
   489   involving the quotient type. These definitions need to be given in terms of concepts
   484   of the raw type (remember this is the only way how to extend HOL
   490   of the raw type (remember this is the only way how to extend HOL
   651   involving constants over the raw type to theorems involving constants over
   657   involving constants over the raw type to theorems involving constants over
   652   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 
   653   two restrictions in the form of proof obligations that arise during the
   659   two restrictions in the form of proof obligations that arise during the
   654   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 
   655   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 
   656   notably 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 
   657   for raw lambda-terms as follows
   663   for raw lambda-terms as follows
   658 
   664 
   659   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
   665   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
   660   @{text "bn (x) \<equiv> \<emptyset>"}\hspace{4mm}
   666   @{text "bn (x) \<equiv> \<emptyset>"}\hspace{4mm}
   661   @{text "bn (t\<^isub>1 t\<^isub>2) \<equiv> bn (t\<^isub>1) \<union> bn (t\<^isub>2)"}\hspace{4mm}
   667   @{text "bn (t\<^isub>1 t\<^isub>2) \<equiv> bn (t\<^isub>1) \<union> bn (t\<^isub>2)"}\hspace{4mm}
   670   the properties of \emph{respectfulness} and \emph{preservation}. We have
   676   the properties of \emph{respectfulness} and \emph{preservation}. We have
   671   to slightly extend Homeier's definitions in order to deal with quotient
   677   to slightly extend Homeier's definitions in order to deal with quotient
   672   compositions. 
   678   compositions. 
   673 
   679 
   674   To formally define what respectfulness is, we have to first define 
   680   To formally define what respectfulness is, we have to first define 
   675   the notion of \emph{aggregate equivalence relations} using @{text REL}:
   681   the notion of \emph{aggregate equivalence relations} using the function @{text REL}:
   676 
   682 
   677   \begin{center}
   683   \begin{center}
   678   \hfill
   684   \hfill
   679   \begin{tabular}{rcl}
   685   \begin{tabular}{rcl}
   680   \multicolumn{3}{@ {\hspace{-4mm}}l}{equal types:}\\ 
   686   \multicolumn{3}{@ {\hspace{-4mm}}l}{equal types:}\\ 
   694 
   700 
   695   Lets return to the lifting procedure of theorems. Assume we have a theorem
   701   Lets return to the lifting procedure of theorems. Assume we have a theorem
   696   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
   697   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
   698   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 
   699   we throw the following proof obligation
   705   we generate the following proof obligation
   700 
   706 
   701   @{text [display, indent=10] "REL (\<sigma>, \<tau>) c\<^isub>r c\<^isub>r"}
   707   @{text [display, indent=10] "REL (\<sigma>, \<tau>) c\<^isub>r c\<^isub>r"}
   702 
   708 
   703   %%% PROBLEM I do not yet completely understand the 
   709   \noindent
   704   %%% form of respectfulness theorems
       
   705   %%%\noindent
       
   706   %%%if @ {text \<sigma>} and @ {text \<tau>} have no type variables. In case they have, then
       
   707   %%%the proof obligation is of the form
       
   708   %%% 
       
   709   %%%@ {text [display, indent=10] "Quotient R\<^bsub>\<alpha>s\<^esub> Abs\<^bsub>\<alpha>s\<^esub> Rep\<^bsub>\<alpha>s\<^esub>  implies  REL (\<sigma>, \<tau>) c\<^isub>r c\<^isub>r"}
       
   710 
       
   711   %%% ANSWER: The respectfulness theorems never have any quotient assumptions,
       
   712   %%% So the commited version is ok.
       
   713 
       
   714   \noindent
       
   715   %%%where @ {text "\<alpha>s"} are the type variables in @{text \<sigma>} and @{text \<tau>}.
       
   716   Homeier calls these proof obligations \emph{respectfulness
   710   Homeier calls these proof obligations \emph{respectfulness
   717   theorems}. However, unlike his quotient package, we might have several
   711   theorems}. However, unlike his quotient package, we might have several
   718   respectfulness theorems for one constant---he has at most one.
   712   respectfulness theorems for one constant---he has at most one.
   719   The reason is that because of our quotient compositions, the types
   713   The reason is that because of our quotient compositions, the types
   720   @{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>"}.
   721   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 
   722   corresponding respectfulness theorem.
   716   corresponding respectfulness theorem.
   723 
   717 
   724   Before lifting a theorem, we require the user to discharge
   718   Before lifting a theorem, we require the user to discharge
   725   them. And the point with @{text bn} is that the respectfulness theorem
   719   respectfulness proof obligations. And the point with @{text bn} is that the respectfulness theorem
   726   looks as follows
   720   looks as follows
   727 
   721 
   728   @{text [display, indent=10] "(\<approx>\<^isub>\<alpha> \<doublearr> =) bn bn"}
   722   @{text [display, indent=10] "(\<approx>\<^isub>\<alpha> \<doublearr> =) bn bn"}
   729 
   723 
   730   \noindent
   724   \noindent
   731   and the user cannot discharge it---because it is not true. To see this,
   725   and the user cannot discharge it: because it is not true. To see this,
   732   we can just unfold the definition of @{text "\<doublearr>"} \eqref{relfun} 
   726   we can just unfold the definition of @{text "\<doublearr>"} \eqref{relfun} 
   733   using extensionally to obtain
   727   using extensionally to obtain
   734 
   728 
   735   @{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)"}
   736  
   730  
   742 
   736 
   743   \noindent
   737   \noindent
   744   To do so, we have to establish
   738   To do so, we have to establish
   745   
   739   
   746   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
   740   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
   747   if @{thm (prem1) append_rsp_unfolded[of xs ys us vs, no_vars]} and
   741   if @{text "xs \<approx>\<^bsub>list\<^esub> ys"} and  @{text "us \<approx>\<^bsub>list\<^esub> vs"}
   748   @{thm (prem2) append_rsp_unfolded[of xs ys us vs, no_vars]}
   742   then @{text "xs @ us \<approx>\<^bsub>list\<^esub> ys @ vs"}
   749   then @{thm (concl) append_rsp_unfolded[of xs ys us vs, no_vars]} 
       
   750   \end{isabelle}
   743   \end{isabelle}
   751 
   744 
   752   \noindent
   745   \noindent
   753   which is straightforward given the definition shown in \eqref{listequiv}.
   746   which is straightforward given the definition shown in \eqref{listequiv}.
   754 
   747 
   755   The second restriction we have to impose arises from
   748   The second restriction we have to impose arises from
   756   non-lifted polymorphic constants, which are instantiated to a
   749   non-lifted polymorphic constants, which are instantiated to a
   757   type being quotient. For example, take the @{term "cons"} to 
   750   type being quotient. For example, take the @{term "cons"}-constructor to 
   758   add a pair of natural numbers to a list. The pair of natural numbers 
   751   add a pair of natural numbers to a list, whereby teh pair of natural numbers 
   759   is to become an integer. But we still want to use @{text cons} for
   752   is to become an integer in te quotient construction. The point is that we 
       
   753   still want to use @{text cons} for
   760   adding integers to lists---just with a different type. 
   754   adding integers to lists---just with a different type. 
   761   To be able to lift such theorems, we need a \emph{preservation theorem} 
   755   To be able to lift such theorems, we need a \emph{preservation property} 
   762   for @{text cons}. Assuming we have a polymorphic raw constant 
   756   for @{text cons}. Assuming we have a polymorphic raw constant 
   763   @{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>"}, 
   764   then a preservation theorem is as follows
   758   then a preservation property is as follows
   765 
   759 
   766   @{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"}
   760   @{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"}
   767 
   761 
   768   \noindent
   762   \noindent
   769   where the @{text "\<alpha>s"} stand for the type variables in the type of @{text "c\<^isub>r"}.
   763   where the @{text "\<alpha>s"} stand for the type variables in the type of @{text "c\<^isub>r"}.
   773 
   767 
   774   \noindent
   768   \noindent
   775   under the assumption @{text "Quotient R Abs Rep"}. Interestingly, if we have
   769   under the assumption @{text "Quotient R Abs Rep"}. Interestingly, if we have
   776   an instance of @{text cons} where the type variable @{text \<alpha>} is instantiated
   770   an instance of @{text cons} where the type variable @{text \<alpha>} is instantiated
   777   with @{text "nat \<times> nat"} and we also quotient this type to yield integers,
   771   with @{text "nat \<times> nat"} and we also quotient this type to yield integers,
   778   then we need to show the corresponding preservation lemma.
   772   then we need to show the corresponding preservation property.
   779 
   773 
   780   %%%@ {thm [display, indent=10] insert_preserve2[no_vars]}
   774   %%%@ {thm [display, indent=10] insert_preserve2[no_vars]}
   781 
   775 
   782   %Given two quotients, one of which quotients a container, and the
   776   %Given two quotients, one of which quotients a container, and the
   783   %other quotients the type in the container, we can write the
   777   %other quotients the type in the container, we can write the
   812 text {*
   806 text {*
   813 
   807 
   814   The main benefit of a quotient package is to lift automatically theorems over raw
   808   The main benefit of a quotient package is to lift automatically theorems over raw
   815   types to theorems over quotient types. We will perform this lifting in
   809   types to theorems over quotient types. We will perform this lifting in
   816   three phases, called \emph{regularization},
   810   three phases, called \emph{regularization},
   817   \emph{injection} and \emph{cleaning}.
   811   \emph{injection} and \emph{cleaning} according to procedures in Homeier's ML-code.
   818 
   812 
   819   The purpose of regularization is to change the quantifiers and abstractions
   813   The purpose of regularization is to change the quantifiers and abstractions
   820   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
   821   (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}
   822   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
   832   3.) & @{text "inj_thm \<longleftrightarrow> quot_thm"}\\
   826   3.) & @{text "inj_thm \<longleftrightarrow> quot_thm"}\\
   833   \end{tabular}
   827   \end{tabular}
   834   \end{center}
   828   \end{center}
   835 
   829 
   836   \noindent
   830   \noindent
       
   831   which means the raw theorem implies the quotient theorem.
   837   In contrast to other quotient packages, our package requires
   832   In contrast to other quotient packages, our package requires
   838   the \emph{term} of the @{text "quot_thm"} to be given by the user.\footnote{Though we
   833   the \emph{term} of the @{text "quot_thm"} to be given by the user.\footnote{Though we
   839   also provide a fully automated mode, where the @{text "quot_thm"} is guessed
   834   also provide a fully automated mode, where the @{text "quot_thm"} is guessed
   840   from @{text "raw_thm"}.} As a result, it is possible that a user can lift only some
   835   from the form of @{text "raw_thm"}.} As a result, it is possible that a user can lift only some
   841   occurrences of a raw type. 
   836   occurrences of a raw type, but not others. 
   842 
   837 
   843   The second and third proof step will always succeed if the appropriate
   838   The second and third proof step will always succeed if the appropriate
   844   respectfulness and preservation theorems are given. In contrast, the first
   839   respectfulness and preservation theorems are given. In contrast, the first
   845   proof step can fail: a theorem given by the user does not always
   840   proof step can fail: a theorem given by the user does not always
   846   imply a regularized version and a stronger one needs to be proved. This
   841   imply a regularized version and a stronger one needs to be proved. This
   847   is outside of the scope where the quotient package can help. An example
   842   is outside of the scope where the quotient package can help. An example
   848   for the failure is the simple statement for integers @{text "0 \<noteq> 1"}.
   843   for this kind of failure is the simple statement for integers @{text "0 \<noteq> 1"}.
   849   It does not follow by lifting from the fact that @{text "(0, 0) \<noteq> (1, 0)"}. 
   844   One might hope that it can be proved by lifting @{text "(0, 0) \<noteq> (1, 0)"},  
   850   The raw theorem only shows that particular element in the
   845   but the raw theorem only shows that particular element in the
   851   equivalence classes are not equal. A more general statement saying that
   846   equivalence classes are not equal. A more general statement stipulating that
   852   the equivalence classes are not equal is necessary.
   847   the equivalence classes are not equal is necessary, and then leads to the
       
   848   theorem  @{text "0 \<noteq> 1"}.
   853 
   849 
   854   In the following we will first define the statement of the
   850   In the following we will first define the statement of the
   855   regularized theorem based on @{text "raw_thm"} and
   851   regularized theorem based on @{text "raw_thm"} and
   856   @{text "quot_thm"}. Then we define the statement of the injected theorem, based
   852   @{text "quot_thm"}. Then we define the statement of the injected theorem, based
   857   on @{text "reg_thm"} theorem and @{text "quot_thm"}. We then show the 3 proofs,
   853   on @{text "reg_thm"} and @{text "quot_thm"}. We then show the three proof steps,
   858   which can all be performed independently from each other.
   854   which can all be performed independently from each other.
   859 
   855 
   860   We define the function @{text REG}. The intuition
   856   We first define the function @{text REG}. The intuition
   861   behind this function is that it replaces quantifiers and
   857   behind this function is that it replaces quantifiers and
   862   abstractions involving raw types by bounded ones, and equalities
   858   abstractions involving raw types by bounded ones, and equalities
   863   involving raw types are replaced by appropriate aggregate
   859   involving raw types are replaced by appropriate aggregate
   864   equivalence relations. It is defined as follows:
   860   equivalence relations. It is defined as follows:
   865 
   861 
   889   \end{center}
   885   \end{center}
   890   %
   886   %
   891   \noindent
   887   \noindent
   892   In the above definition we omitted the cases for existential quantifiers
   888   In the above definition we omitted the cases for existential quantifiers
   893   and unique existential quantifiers, as they are very similar to the cases
   889   and unique existential quantifiers, as they are very similar to the cases
   894   for the universal quantifier.
   890   for the universal quantifier. For the third and fourt clause, note that 
       
   891   @{text "\<forall>x. P"} is defined as @{text "\<forall> (\<lambda>x. P)"}.
   895 
   892 
   896   Next we define the function @{text INJ} which takes as argument
   893   Next we define the function @{text INJ} which takes as argument
   897   @{text "reg_thm"} and @{text "quot_thm"} (both as
   894   @{text "reg_thm"} and @{text "quot_thm"} (both as
   898   terms) and returns @{text "inj_thm"}:
   895   terms) and returns @{text "inj_thm"}:
   899 
   896 
   931 
   928 
   932   In the first proof step, establishing @{text "raw_thm \<longrightarrow> reg_thm"}, we always 
   929   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 
   930   start with an implication. Isabelle provides \emph{mono} rules that can split up 
   934   the implications into simpler implication subgoals. This succeeds for every
   931   the implications into simpler implication subgoals. This succeeds for every
   935   monotone connective, except in places where the function @{text REG} inserted,
   932   monotone connective, except in places where the function @{text REG} inserted,
   936   for example, a quantifier by a bounded quantifier. In this case we have 
   933   for instance, a quantifier by a bounded quantifier. In this case we have 
   937   rules of the form
   934   rules of the form
   938 
   935 
   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)"}
   936   @{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 
   937 
   941   \noindent
   938   \noindent
   951 
   948 
   952   @{thm [display, indent=10] (concl) ball_reg_eqv_range[of R\<^isub>1 R\<^isub>2, no_vars]}
   949   @{thm [display, indent=10] (concl) ball_reg_eqv_range[of R\<^isub>1 R\<^isub>2, no_vars]}
   953 
   950 
   954   \noindent
   951   \noindent
   955   The last theorem is new in comparison with Homeier's package. There the
   952   The last theorem is new in comparison with Homeier's package. There the
   956   injection procedure would be used to prove such goals, and there
   953   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,
   954   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
   955   because this allows us to completely separate the first and the second
   959   proof step into independent ``units''.
   956   proof step into two independent ``units''.
   960 
   957 
   961   The second proof step, establishing @{text "reg_thm \<longleftrightarrow> inj_thm"},  starts with an equality. 
   958   The second proof step, establishing @{text "reg_thm \<longleftrightarrow> inj_thm"},  starts with an equality. 
   962   The proof again follows the structure of the
   959   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.
   960   two underlying terms, and is defined for a goal being a relation between these two terms.
   964 
   961 
   979   \end{itemize}
   976   \end{itemize}
   980 
   977 
   981   We defined the theorem @{text "inj_thm"} in such a way that
   978   We defined the theorem @{text "inj_thm"} in such a way that
   982   establishing the equivalence @{text "inj_thm \<longleftrightarrow> quot_thm"} can be
   979   establishing the equivalence @{text "inj_thm \<longleftrightarrow> quot_thm"} can be
   983   achieved by rewriting @{text "inj_thm"} with the preservation theorems and quotient
   980   achieved by rewriting @{text "inj_thm"} with the preservation theorems and quotient
   984   definitions. Then all lifted constants, their definitions
   981   definitions. Then for all lifted constants, their definitions
   985   are used to fold the @{term Rep} with the raw constant. Next for
   982   are used to fold the @{term Rep} with the raw constant. Next for
   986   all abstractions and quantifiers the lambda and
   983   all abstractions and quantifiers the lambda and
   987   quantifier preservation theorems are used to replace the
   984   quantifier preservation theorems are used to replace the
   988   variables that include raw types with respects by quantifiers
   985   variables that include raw types with respects by quantifiers
   989   over variables that include quotient types. We show here only
   986   over variables that include quotient types. We show here only
  1043   The user can then specify the constants on the quotient type:
  1040   The user can then specify the constants on the quotient type:
  1044 
  1041 
  1045   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %
  1042   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %
  1046   \begin{tabular}{@ {}l}
  1043   \begin{tabular}{@ {}l}
  1047   \isacommand{quotient\_definition}~~@{text "0 :: int"}~~\isacommand{is}~~@{text "(0 :: nat, 0 :: nat)"}\\[3mm]
  1044   \isacommand{quotient\_definition}~~@{text "0 :: int"}~~\isacommand{is}~~@{text "(0 :: nat, 0 :: nat)"}\\[3mm]
  1048   \isacommand{fun}~~@{text "plus_raw"}~~\isacommand{where}~~%
  1045   \isacommand{fun}~~@{text "add_pair"}~~\isacommand{where}~~%
  1049   @{text "plus_raw (m, n) (p, q) = (m + p :: nat, n + q :: nat)"}\\
  1046   @{text "add_pair (m, n) (p, q) \<equiv> (m + p :: nat, n + q :: nat)"}\\
  1050   \isacommand{quotient\_definition}~~@{text "+ :: int \<Rightarrow> int \<Rightarrow> int"}~~%
  1047   \isacommand{quotient\_definition}~~@{text "+ :: int \<Rightarrow> int \<Rightarrow> int"}~~%
  1051   \isacommand{is}~~@{text "plus_raw"}\\
  1048   \isacommand{is}~~@{text "add_pair"}\\
  1052   \end{tabular}
  1049   \end{tabular}
  1053   \end{isabelle}
  1050   \end{isabelle}
  1054 
  1051 
  1055   \noindent
  1052   \noindent
  1056   The following theorem about addition on the raw level can be proved.
  1053   The following theorem about addition on the raw level can be proved.
  1057 
  1054 
  1058   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %
  1055   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %
  1059   \isacommand{lemma}~~@{text "plus_zero_raw: int_rel (plus_raw (0, 0) x) x"}
  1056   \isacommand{lemma}~~@{text "add_pair_zero: int_rel (add_pair (0, 0) x) x"}
  1060   \end{isabelle}
  1057   \end{isabelle}
  1061 
  1058 
  1062   \noindent
  1059   \noindent
  1063   If the user attempts to lift this theorem, all proof obligations are 
  1060   If the user attempts to lift this theorem, all proof obligations are 
  1064   automatically discharged, except the respectfulness
  1061   automatically discharged, except the respectfulness
  1065   proof for @{text "plus_raw"}:
  1062   proof for @{text "add_pair"}:
  1066 
  1063 
  1067   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %
  1064   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %
  1068   \begin{tabular}{@ {}l}
  1065   \begin{tabular}{@ {}l}
  1069   \isacommand{lemma}~~@{text "[quot_respect]:\\ 
  1066   \isacommand{lemma}~~@{text "[quot_respect]:"}\\ 
  1070   (int_rel \<doublearr> int_rel \<doublearr> int_rel) plus_raw plus_raw"}
  1067   @{text "(int_rel \<doublearr> int_rel \<doublearr> int_rel) add_pair add_pair"}
  1071   \end{tabular}
  1068   \end{tabular}
  1072   \end{isabelle}
  1069   \end{isabelle}
  1073 
  1070 
  1074   \noindent
  1071   \noindent
  1075   This can be discharged automatically by Isabelle when telling it to unfold the definition
  1072   This can be discharged automatically by Isabelle when telling it 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 explicitly:
  1078 
  1075 
  1079   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %
  1076   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %
  1080   \isacommand{lemma}~~@{text "0 + (x :: int) = x"}~~\isacommand{by}~~@{text "lifting plus_zero_raw"}
  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 the completely automated mode by stating:
  1085 
  1082 
  1086   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %
  1083   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %
  1087   \isacommand{thm}~~@{text "plus_zero_raw[quot_lifted]"}
  1084   \isacommand{thm}~~@{text "add_pair_zero[quot_lifted]"}
  1088   \end{isabelle}
  1085   \end{isabelle}
  1089 
  1086 
  1090   \noindent
  1087   \noindent
  1091   Both methods give the same result, namely
  1088   Both methods give the same result, namely
  1092 
  1089 
  1093   @{text [display, indent=10] "0 + x = x"}
  1090   @{text [display, indent=10] "0 + x = x"}
  1094 
  1091 
  1095   \noindent
  1092   \noindent
  1096   Although seemingly simple, arriving at this result without the help of a quotient
  1093   Although seemingly simple, arriving at this result without the help of a quotient
  1097   package requires substantial reasoning effort.
  1094   package requires a substantial reasoning effort.
  1098 *}
  1095 *}
  1099 
  1096 
  1100 section {* Conclusion and Related Work\label{sec:conc}*}
  1097 section {* Conclusion and Related Work\label{sec:conc}*}
  1101 
  1098 
  1102 text {*
  1099 text {*
  1104   The code of the quotient package and the examples described here are
  1101   The code of the quotient package and the examples described here are
  1105   already included in the
  1102   already included in the
  1106   standard distribution of Isabelle.\footnote{Available from
  1103   standard distribution of Isabelle.\footnote{Available from
  1107   \href{http://isabelle.in.tum.de/}{http://isabelle.in.tum.de/}.} It is
  1104   \href{http://isabelle.in.tum.de/}{http://isabelle.in.tum.de/}.} It is
  1108   heavily used in the new version of Nominal Isabelle, which provides a convenient reasoning
  1105   heavily used in the new version of Nominal Isabelle, which provides a convenient reasoning
  1109   infrastructure for programming language calculi involving binders.  
  1106   infrastructure for programming language calculi involving general binders.  
  1110   To achieve this, it builds types representing @{text \<alpha>}-equivalent terms.
  1107   To achieve this, it builds types representing @{text \<alpha>}-equivalent terms.
  1111   Earlier
  1108   Earlier
  1112   versions of Nominal Isabelle have been used successfully in formalisations
  1109   versions of Nominal Isabelle have been used successfully in formalisations
  1113   of an equivalence checking algorithm for LF \cite{UrbanCheneyBerghofer08},
  1110   of an equivalence checking algorithm for LF \cite{UrbanCheneyBerghofer08},
  1114   Typed Scheme~\cite{TobinHochstadtFelleisen08}, several calculi for
  1111   Typed Scheme~\cite{TobinHochstadtFelleisen08}, several calculi for
  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 the
  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 ML-code. On the other hand, Homeier
  1133   @{text REP} and @{text INJ} etc only exist in \cite{Homeier05} as ML-code, not included
  1137   is able to deal with partial quotient constructions, which we have not implemented.
  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 advantage of our package is that it is modular---in the sense that every step
  1140   in the quotient construction can be done independently (see the criticism of Paulson
  1137   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
  1138   about other quotient packages). This modularity is essential in the context of
  1142   Isabelle, which supports type-classes and locales.
  1139   Isabelle, which supports type-classes and locales.
  1143 
  1140 
  1144   Another feature of our quotient package is that when lifting theorems, we can
  1141   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
  1142   precisely specify what the lifted theorem should look like. This feature is
  1146   necessary, for example, when lifting an inductive principle about two lists.
  1143   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"},
  1144   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"},
  1145   and 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 
  1146   or both. We found this feature very useful in the new version of Nominal 
  1150   Isabelle.
  1147   Isabelle, where such a choice is required to generate a resoning infrastructure
       
  1148   for alpha-equated terms. 
       
  1149 %%
       
  1150 %% give an example for this
       
  1151 %%
  1151   \medskip
  1152   \medskip
  1152 
  1153 
  1153   \noindent
  1154   \noindent
  1154   {\bf Acknowledgements:} We would like to thank Peter Homeier for the
  1155   {\bf Acknowledgements:} We would like to thank Peter Homeier for the many
  1155   discussions about his HOL4 quotient package and explaining to us
  1156   discussions about his HOL4 quotient package and explaining to us
  1156   some of its finer points in the implementation.
  1157   some of its finer points in the implementation. Without his patient
       
  1158   help, this work would have been impossible.
  1157 
  1159 
  1158 *}
  1160 *}
  1159 
  1161 
  1160 
  1162 
  1161 
  1163