Quotient-Paper/Paper.thy
changeset 2445 10148a447359
parent 2444 d769c24094cf
child 2455 0bc1db726f81
equal deleted inserted replaced
2444:d769c24094cf 2445:10148a447359
    62 
    62 
    63 section {* Introduction *}
    63 section {* Introduction *}
    64 
    64 
    65 text {* 
    65 text {* 
    66   \noindent
    66   \noindent
    67   One might think they have been studied to death, but in the context of
    67   One might think quotients have been studied to death, but in the context of
    68   theorem provers many questions concerning quotients are far from settled. In
    68   theorem provers many questions concerning them are far from settled. In
    69   this paper we address the question how a convenient reasoning infrastructure
    69   this paper we address the question of how to establish a convenient reasoning 
    70   for quotient constructions can be established in Isabelle/HOL, a popular
    70   infrastructure
    71   generic theorem prover. Higher-Order Logic (HOL) consists
    71   for quotient constructions in the Isabelle/HOL, 
       
    72   theorem prover. Higher-Order Logic (HOL) consists
    72   of a small number of axioms and inference rules over a simply-typed
    73   of a small number of axioms and inference rules over a simply-typed
    73   term-language. Safe reasoning in HOL is ensured by two very restricted
    74   term-language. Safe reasoning in HOL is ensured by two very restricted
    74   mechanisms for extending the logic: one is the definition of new constants
    75   mechanisms for extending the logic: one is the definition of new constants
    75   in terms of existing ones; the other is the introduction of new types by
    76   in terms of existing ones; the other is the introduction of new types by
    76   identifying non-empty subsets in existing types. It is well understood how
    77   identifying non-empty subsets in existing types. Previous work has shown how
    77   to use both mechanisms for dealing with quotient constructions in HOL (see
    78   to use both mechanisms for dealing with quotient constructions in HOL (see
    78   \cite{Homeier05,Paulson06}).  For example the integers in Isabelle/HOL are
    79   \cite{Homeier05,Paulson06}).  For example the integers in Isabelle/HOL are
    79   constructed by a quotient construction over the type @{typ "nat \<times> nat"} and
    80   constructed by a quotient construction over the type @{typ "nat \<times> nat"} and
    80   the equivalence relation
    81   the equivalence relation
    81 
    82 
   273   according to the type of the raw constant and the type
   274   according to the type of the raw constant and the type
   274   of the quotient constant. This means we also have to extend the notions
   275   of the quotient constant. This means we also have to extend the notions
   275   of \emph{aggregate equivalence relation}, \emph{respectfulness} and \emph{preservation}
   276   of \emph{aggregate equivalence relation}, \emph{respectfulness} and \emph{preservation}
   276   from Homeier \cite{Homeier05}.
   277   from Homeier \cite{Homeier05}.
   277 
   278 
   278   In addition we are able to address the criticism by Paulson \cite{Paulson06} cited
   279   In addition we are able to clearly specify what is involved
   279   at the beginning of this section about having to collect theorems that are
       
   280   lifted from the raw level to the quotient level into one giant list. Homeier's and
       
   281   also our quotient package are modular so that they allow lifting
       
   282   theorems separately. This has the advantage for the user of being able to develop a
       
   283   formal theory interactively as a natural progression. A pleasing side-result of
       
   284   the modularity is that we are able to clearly specify what is involved
       
   285   in the lifting process (this was only hinted at in \cite{Homeier05} and
   280   in the lifting process (this was only hinted at in \cite{Homeier05} and
   286   implemented as a ``rough recipe'' in ML-code).
   281   implemented as a ``rough recipe'' in ML-code). A pleasing side-result
   287 
   282   is that our procedure for lifting theorems is completely deterministic
   288 
   283   following the structure of the theorem being lifted and the theorem
   289   %The paper is organised as follows: Section \ref{sec:prelims} presents briefly
   284   on the quotient level. Space constraints, unfortunately, allow us to only 
   290   %some necessary preliminaries; Section \ref{sec:type} describes the definitions 
   285   sketch this part of our work in Section 5 and we defer the reader to a longer
   291   %of quotient types and shows how definitions of constants can be made over 
   286   version for the details. However, we will give in Section 3 and 4 all 
   292   %quotient types. Section \ref{sec:resp} introduces the notions of respectfulness
   287   definitions that specify the input and output data of our three-step 
   293   %and preservation; Section \ref{sec:lift} describes the lifting of theorems;
   288   lifting procedure. Section 6 gives an example how our quotient package
   294   %Section \ref{sec:examples} presents some examples
   289   works in practise. 
   295   %and Section \ref{sec:conc} concludes and compares our results to existing 
       
   296   %work.
       
   297 *}
   290 *}
   298 
   291 
   299 section {* Preliminaries and General\\ Quotients\label{sec:prelims} *}
   292 section {* Preliminaries and General\\ Quotients\label{sec:prelims} *}
   300 
   293 
   301 text {*
   294 text {*
   302   \noindent
   295   \noindent
   303   We give in this section a crude overview of HOL and describe the main
   296   We will give in this section a crude overview of HOL and describe the main
   304   definitions given by Homeier for quotients \cite{Homeier05}.
   297   definitions given by Homeier for quotients \cite{Homeier05}.
   305 
   298 
   306   At its core, HOL is based on a simply-typed term language, where types are 
   299   At its core, HOL is based on a simply-typed term language, where types are 
   307   recorded in Church-style fashion (that means, we can always infer the type of 
   300   recorded in Church-style fashion (that means, we can always infer the type of 
   308   a term and its subterms without any additional information). The grammars
   301   a term and its subterms without any additional information). The grammars
   426   \noindent
   419   \noindent
   427   As a result, Homeier is able to build an automatic prover that can nearly
   420   As a result, Homeier is able to build an automatic prover that can nearly
   428   always discharge a proof obligation involving @{text "Quot"}. Our quotient
   421   always discharge a proof obligation involving @{text "Quot"}. Our quotient
   429   package makes heavy 
   422   package makes heavy 
   430   use of this part of Homeier's work including an extension 
   423   use of this part of Homeier's work including an extension 
   431   for dealing with compositions of equivalence relations defined as follows:
   424   for dealing with \emph{conjugations} of equivalence relations\footnote{That are 
       
   425   symmetric by definition.} defined as follows:
   432 
   426 
   433 %%% FIXME Referee 2 claims that composition-of-relations means OO, and this is also
   427 %%% FIXME Referee 2 claims that composition-of-relations means OO, and this is also
   434 %%% what wikipedia says. Any idea for a different name? Conjugation of Relations?
   428 %%% what wikipedia says. Any idea for a different name? Conjugation of Relations?
   435 
   429 
   436   \begin{definition}%%[Composition of Relations]
   430   \begin{definition}%%[Composition of Relations]
   461 *}
   455 *}
   462 
   456 
   463 section {* Quotient Types and Quotient\\ Definitions\label{sec:type} *}
   457 section {* Quotient Types and Quotient\\ Definitions\label{sec:type} *}
   464 
   458 
   465 text {*
   459 text {*
       
   460   \noindent
   466   The first step in a quotient construction is to take a name for the new
   461   The first step in a quotient construction is to take a name for the new
   467   type, say @{text "\<kappa>\<^isub>q"}, and an equivalence relation, say @{text R},
   462   type, say @{text "\<kappa>\<^isub>q"}, and an equivalence relation, say @{text R},
   468   defined over a raw type, say @{text "\<sigma>"}. The type of the equivalence
   463   defined over a raw type, say @{text "\<sigma>"}. The type of the equivalence
   469   relation must be @{text "\<sigma> \<Rightarrow> \<sigma> \<Rightarrow> bool"}. The user-visible part of
   464   relation must be @{text "\<sigma> \<Rightarrow> \<sigma> \<Rightarrow> bool"}. The user-visible part of
   470   the quotient type declaration is therefore
   465   the quotient type declaration is therefore
   472   \begin{isabelle}\ \ \ \ \ %%%
   467   \begin{isabelle}\ \ \ \ \ %%%
   473   \isacommand{quotient\_type}~~@{text "\<alpha>s \<kappa>\<^isub>q = \<sigma> / R"}\hfill\numbered{typedecl}
   468   \isacommand{quotient\_type}~~@{text "\<alpha>s \<kappa>\<^isub>q = \<sigma> / R"}\hfill\numbered{typedecl}
   474   \end{isabelle}
   469   \end{isabelle}
   475 
   470 
   476   \noindent
   471   \noindent
   477   and a proof that @{text "R"} is indeed an equivalence relation. Two concrete
   472   and a proof that @{text "R"} is indeed an equivalence relation. The @{text "\<alpha>s"}
       
   473   indicate the arity of the new type and the type-variables of @{text "\<sigma>"} can only
       
   474   be contained in @{text "\<alpha>s"}. Two concrete
   478   examples are
   475   examples are
   479 
   476 
   480   
   477   
   481   \begin{isabelle}\ \ \ \ \ %%%
   478   \begin{isabelle}\ \ \ \ \ %%%
   482   \begin{tabular}{@ {}l}
   479   \begin{tabular}{@ {}l}
   525   respectively.  Given that @{text "R"} is an equivalence relation, the
   522   respectively.  Given that @{text "R"} is an equivalence relation, the
   526   following property holds  for every quotient type 
   523   following property holds  for every quotient type 
   527   (for the proof see \cite{Homeier05}).
   524   (for the proof see \cite{Homeier05}).
   528 
   525 
   529   \begin{proposition}
   526   \begin{proposition}
   530   @{term "Quotient R Abs_\<kappa>\<^isub>q Rep_\<kappa>\<^isub>q"}.
   527   \begin{isa}@{term "Quotient R Abs_\<kappa>\<^isub>q Rep_\<kappa>\<^isub>q"}.\end{isa}
   531   \end{proposition}
   528   \end{proposition}
   532 
   529 
   533   The next step in a quotient construction is to introduce definitions of new constants
   530   The next step in a quotient construction is to introduce definitions of new constants
   534   involving the quotient type. These definitions need to be given in terms of concepts
   531   involving the quotient type. These definitions need to be given in terms of concepts
   535   of the raw type (remember this is the only way how to extend HOL
   532   of the raw type (remember this is the only way how to extend HOL
   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"}
   586   @{text "REP (\<sigma>s \<kappa>, \<tau>s \<kappa>\<^isub>q)"} $\dn$ @{text "(MAP(\<rho>s \<kappa>) (REP (\<sigma>s', \<tau>s))) \<circ> Rep_\<kappa>\<^isub>q"}
   590   \end{tabular}\hfill\numbered{ABSREP}
   587   \end{tabular}\hfill\numbered{ABSREP}
   591   \end{center}
   588   \end{center}
   592   %
   589   %
   593   \noindent
   590   \noindent
   594   In the last two clauses we rely on the fact that the type @{text "\<alpha>s
   591   In the last two clauses are subtle. We rely in them on the fact that the type @{text "\<alpha>s
   595   \<kappa>\<^isub>q"} is the quotient of the raw type @{text "\<rho>s \<kappa>"} (for example
   592   \<kappa>\<^isub>q"} is the quotient of the raw type @{text "\<rho>s \<kappa>"} (for example
   596   @{text "int"} and @{text "nat \<times> nat"}, or @{text "\<alpha> fset"} and @{text "\<alpha>
   593   @{text "int"} and @{text "nat \<times> nat"}, or @{text "\<alpha> fset"} and @{text "\<alpha>
   597   list"}). The quotient construction ensures that the type variables in @{text
   594   list"}). This data is given by declarations shown in \eqref{typedecl}.
       
   595   The quotient construction ensures that the type variables in @{text
   598   "\<rho>s \<kappa>"} must be among the @{text "\<alpha>s"}. The @{text "\<sigma>s'"} are given by the
   596   "\<rho>s \<kappa>"} must be among the @{text "\<alpha>s"}. The @{text "\<sigma>s'"} are given by the
   599   substitutions for the @{text "\<alpha>s"} when matching  @{text "\<sigma>s \<kappa>"} against
   597   substitutions for the @{text "\<alpha>s"} when matching  @{text "\<sigma>s \<kappa>"} against
   600   @{text "\<rho>s \<kappa>"}.  The
   598   @{text "\<rho>s \<kappa>"}. This calculation determines what are the types in place
       
   599   of the type variables @{text "\<alpha>s"} in the instance of 
       
   600   quotient type @{text "\<alpha>s \<kappa>\<^isub>q"}---namely @{text "\<tau>s"}, and the corresponding 
       
   601   types in place of the @{text "\<alpha>s"} in the raw type @{text "\<rho>s \<kappa>"}---namely @{text "\<sigma>s'"}. The
   601   function @{text "MAP"} calculates an \emph{aggregate map-function} for a raw
   602   function @{text "MAP"} calculates an \emph{aggregate map-function} for a raw
   602   type as follows:
   603   type as follows:
   603   %
   604   %
   604   \begin{center}
   605   \begin{center}
   605   \begin{tabular}{r@ {\hspace{1mm}}c@ {\hspace{1mm}}l}
   606   \begin{tabular}{r@ {\hspace{1mm}}c@ {\hspace{1mm}}l}
   714 *}
   715 *}
   715 
   716 
   716 section {* Respectfulness and\\ Preservation \label{sec:resp} *}
   717 section {* Respectfulness and\\ Preservation \label{sec:resp} *}
   717 
   718 
   718 text {*
   719 text {*
       
   720   \noindent
   719   The main point of the quotient package is to automatically ``lift'' theorems
   721   The main point of the quotient package is to automatically ``lift'' theorems
   720   involving constants over the raw type to theorems involving constants over
   722   involving constants over the raw type to theorems involving constants over
   721   the quotient type. Before we can describe this lifting process, we need to impose 
   723   the quotient type. Before we can describe this lifting process, we need to impose 
   722   two restrictions in form of proof obligations that arise during the
   724   two restrictions in form of proof obligations that arise during the
   723   lifting. The reason is that even if definitions for all raw constants 
   725   lifting. The reason is that even if definitions for all raw constants 
   851   \noindent
   853   \noindent
   852   where the @{text "\<alpha>s"} stand for the type variables in the type of @{text "c\<^isub>r"}.
   854   where the @{text "\<alpha>s"} stand for the type variables in the type of @{text "c\<^isub>r"}.
   853   In case of @{text cons} (which has type @{text "\<alpha> \<Rightarrow> \<alpha> list \<Rightarrow> \<alpha> list"}) we have 
   855   In case of @{text cons} (which has type @{text "\<alpha> \<Rightarrow> \<alpha> list \<Rightarrow> \<alpha> list"}) we have 
   854 
   856 
   855   \begin{isabelle}\ \ \ \ \ %%%
   857   \begin{isabelle}\ \ \ \ \ %%%
   856   @{text "(Rep ---> map_list Rep ---> map_list Abs) cons = cons"}
   858   @{text "(Rep \<singlearr> map_list Rep \<singlearr> map_list Abs) cons = cons"}
   857   \end{isabelle}
   859   \end{isabelle}
   858 
   860 
   859   \noindent
   861   \noindent
   860   under the assumption @{text "Quotient R Abs Rep"}. Interestingly, if we have
   862   under the assumption @{text "Quotient R Abs Rep"}. The point is that if we have
   861   an instance of @{text cons} where the type variable @{text \<alpha>} is instantiated
   863   an instance of @{text cons} where the type variable @{text \<alpha>} is instantiated
   862   with @{text "nat \<times> nat"} and we also quotient this type to yield integers,
   864   with @{text "nat \<times> nat"} and we also quotient this type to yield integers,
   863   then we need to show the corresponding preservation property.
   865   then we need to show this preservation property.
   864 
   866 
   865   %%%@ {thm [display, indent=10] insert_preserve2[no_vars]}
   867   %%%@ {thm [display, indent=10] insert_preserve2[no_vars]}
   866 
   868 
   867   %Given two quotients, one of which quotients a container, and the
   869   %Given two quotients, one of which quotients a container, and the
   868   %other quotients the type in the container, we can write the
   870   %other quotients the type in the container, we can write the
   900 %%% lifting theorems. But there is no clarification about the
   902 %%% lifting theorems. But there is no clarification about the
   901 %%% correctness. A reader would also be interested in seeing some
   903 %%% correctness. A reader would also be interested in seeing some
   902 %%% discussions about the generality and limitation of the approach
   904 %%% discussions about the generality and limitation of the approach
   903 %%% proposed there
   905 %%% proposed there
   904 
   906 
       
   907   \noindent
   905   The main benefit of a quotient package is to lift automatically theorems over raw
   908   The main benefit of a quotient package is to lift automatically theorems over raw
   906   types to theorems over quotient types. We will perform this lifting in
   909   types to theorems over quotient types. We will perform this lifting in
   907   three phases, called \emph{regularization},
   910   three phases, called \emph{regularization},
   908   \emph{injection} and \emph{cleaning} according to procedures in Homeier's ML-code.
   911   \emph{injection} and \emph{cleaning} according to procedures in Homeier's ML-code.
       
   912   Space restrictions, unfortunately, prevent us from giving anything but a sketch of these three
       
   913   phases. However, we will precisely define the input and output data of these phases
       
   914   (this was omitted in \cite{Homeier05}).
   909 
   915 
   910   The purpose of regularization is to change the quantifiers and abstractions
   916   The purpose of regularization is to change the quantifiers and abstractions
   911   in a ``raw'' theorem to quantifiers over variables that respect their respective relations
   917   in a ``raw'' theorem to quantifiers over variables that respect their respective relations
   912   (Definition \ref{def:respects} states what respects means). The purpose of injection is to add @{term Rep}
   918   (Definition \ref{def:respects} states what respects means). The purpose of injection is to add @{term Rep}
   913   and @{term Abs} of appropriate types in front of constants and variables
   919   and @{term Abs} of appropriate types in front of constants and variables
   946   equivalence classes are not equal. In order to obtain @{text "0 \<noteq> 1"}, a  
   952   equivalence classes are not equal. In order to obtain @{text "0 \<noteq> 1"}, a  
   947   more general statement stipulating that the equivalence classes are not 
   953   more general statement stipulating that the equivalence classes are not 
   948   equal is necessary.  This kind of failure is beyond the scope where the 
   954   equal is necessary.  This kind of failure is beyond the scope where the 
   949   quotient package can help: the user has to provide a raw theorem that
   955   quotient package can help: the user has to provide a raw theorem that
   950   can be regularized automatically, or has to provide an explicit proof
   956   can be regularized automatically, or has to provide an explicit proof
   951   for the first proof step.
   957   for the first proof step. Homeier gives more details about this issue
       
   958   in the long version of \cite{Homeier05}.
   952 
   959 
   953   In the following we will first define the statement of the
   960   In the following we will first define the statement of the
   954   regularized theorem based on @{text "raw_thm"} and
   961   regularized theorem based on @{text "raw_thm"} and
   955   @{text "quot_thm"}. Then we define the statement of the injected theorem, based
   962   @{text "quot_thm"}. Then we define the statement of the injected theorem, based
   956   on @{text "reg_thm"} and @{text "quot_thm"}. We then show the three proof steps,
   963   on @{text "reg_thm"} and @{text "quot_thm"}. We then show the three proof steps,
   960   @{text "raw_thm"} and @{text "quot_thm"} as input and returns
   967   @{text "raw_thm"} and @{text "quot_thm"} as input and returns
   961   @{text "reg_thm"}. The idea
   968   @{text "reg_thm"}. The idea
   962   behind this function is that it replaces quantifiers and
   969   behind this function is that it replaces quantifiers and
   963   abstractions involving raw types by bounded ones, and equalities
   970   abstractions involving raw types by bounded ones, and equalities
   964   involving raw types by appropriate aggregate
   971   involving raw types by appropriate aggregate
   965   equivalence relations. It is defined by simultaneously recursing on 
   972   equivalence relations. It is defined by simultaneous recursion on 
   966   the structure of  @{text "raw_thm"} and @{text "quot_thm"} as follows:
   973   the structure of  the terms of @{text "raw_thm"} and @{text "quot_thm"} as follows:
   967 
   974   %
   968   \begin{center}
   975   \begin{center}
   969   \begin{tabular}{l}
   976   \begin{tabular}{@ {}l@ {}}
   970   \multicolumn{1}{@ {}l}{abstractions:}\smallskip\\
   977   \multicolumn{1}{@ {}l@ {}}{abstractions:}\smallskip\\
   971   @{text "REG (\<lambda>x\<^sup>\<sigma>. t, \<lambda>x\<^sup>\<tau>. s)"} $\dn$ 
   978   @{text "REG (\<lambda>x\<^sup>\<sigma>. t, \<lambda>x\<^sup>\<tau>. s)"} $\dn$ 
   972   $\begin{cases}
   979   $\begin{cases}
   973   @{text "\<lambda>x\<^sup>\<sigma>. REG (t, s)"} \quad\mbox{provided @{text "\<sigma> = \<tau>"}}\\
   980   @{text "\<lambda>x\<^sup>\<sigma>. REG (t, s)"} \quad\mbox{provided @{text "\<sigma> = \<tau>"}}\\
   974   @{text "\<lambda>x\<^sup>\<sigma> \<in> Respects (REL (\<sigma>, \<tau>)). REG (t, s)"}
   981   @{text "\<lambda>x\<^sup>\<sigma> \<in> Resp (REL (\<sigma>, \<tau>)). REG (t, s)"}
   975   \end{cases}$\smallskip\\
   982   \end{cases}$\smallskip\\
   976   \\
   983   \multicolumn{1}{@ {}l@ {}}{universal quantifiers:}\\
   977   \multicolumn{1}{@ {}l}{universal quantifiers:}\\
       
   978   @{text "REG (\<forall>x\<^sup>\<sigma>. t, \<forall>x\<^sup>\<tau>. s)"} $\dn$
   984   @{text "REG (\<forall>x\<^sup>\<sigma>. t, \<forall>x\<^sup>\<tau>. s)"} $\dn$
   979   $\begin{cases}
   985   $\begin{cases}
   980   @{text "\<forall>x\<^sup>\<sigma>. REG (t, s)"} \quad\mbox{provided @{text "\<sigma> = \<tau>"}}\\
   986   @{text "\<forall>x\<^sup>\<sigma>. REG (t, s)"} \quad\mbox{provided @{text "\<sigma> = \<tau>"}}\\
   981   @{text "\<forall>x\<^sup>\<sigma> \<in> Respects (REL (\<sigma>, \<tau>)). REG (t, s)"}
   987   @{text "\<forall>x\<^sup>\<sigma> \<in> Resp (REL (\<sigma>, \<tau>)). REG (t, s)"}
   982   \end{cases}$\smallskip\\
   988   \end{cases}$\smallskip\\
   983   \multicolumn{1}{@ {}l}{equality:}\smallskip\\
   989   \multicolumn{1}{@ {}l@ {}}{equality:}\smallskip\\
   984   %% REL of two equal types is the equality so we do not need a separate case
   990   %% REL of two equal types is the equality so we do not need a separate case
   985   @{text "REG (=\<^bsup>\<sigma>\<Rightarrow>\<sigma>\<Rightarrow>bool\<^esup>, =\<^bsup>\<tau>\<Rightarrow>\<tau>\<Rightarrow>bool\<^esup>)"} $\dn$ @{text "REL (\<sigma>, \<tau>)"}\\\smallskip\\
   991   @{text "REG (=\<^bsup>\<sigma>\<Rightarrow>\<sigma>\<Rightarrow>bool\<^esup>, =\<^bsup>\<tau>\<Rightarrow>\<tau>\<Rightarrow>bool\<^esup>)"} $\dn$ @{text "REL (\<sigma>, \<tau>)"}\smallskip\\
   986   \multicolumn{1}{@ {}l}{applications, variables and constants:}\\
   992   \multicolumn{1}{@ {}l@ {}}{applications, variables and constants:}\\
   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)"}\\
   993   @{text "REG (t\<^isub>1 t\<^isub>2, s\<^isub>1 s\<^isub>2)"} $\dn$ @{text "REG (t\<^isub>1, s\<^isub>1) REG (t\<^isub>2, s\<^isub>2)"}\\
   988   @{text "REG (x\<^isub>1, x\<^isub>2)"} $\dn$ @{text "x\<^isub>1"}\\
   994   @{text "REG (x\<^isub>1, x\<^isub>2)"} $\dn$ @{text "x\<^isub>1"}\\
   989   @{text "REG (c\<^isub>1, c\<^isub>2)"} $\dn$ @{text "c\<^isub>1"}\\
   995   @{text "REG (c\<^isub>1, c\<^isub>2)"} $\dn$ @{text "c\<^isub>1"}\\
   990   \end{tabular}
   996   \end{tabular}
   991   \end{center}
   997   \end{center}
  1038 %%% You should clarify under which circumstances the implication is
  1044 %%% You should clarify under which circumstances the implication is
  1039 %%% being proved here.
  1045 %%% being proved here.
  1040 %%% Cezary: It would be nice to cite Homeiers discussions in the
  1046 %%% Cezary: It would be nice to cite Homeiers discussions in the
  1041 %%% Quotient Package manual from HOL (the longer paper), do you agree?
  1047 %%% Quotient Package manual from HOL (the longer paper), do you agree?
  1042 
  1048 
  1043   In the first proof step, establishing @{text "raw_thm \<longrightarrow> reg_thm"}, we always 
  1049   In the first phase, establishing @{text "raw_thm \<longrightarrow> reg_thm"}, we always 
  1044   start with an implication. Isabelle provides \emph{mono} rules that can split up 
  1050   start with an implication. Isabelle provides \emph{mono} rules that can split up 
  1045   the implications into simpler implicational subgoals. This succeeds for every
  1051   the implications into simpler implicational subgoals. This succeeds for every
  1046   monotone connective, except in places where the function @{text REG} replaced,
  1052   monotone connective, except in places where the function @{text REG} replaced,
  1047   for instance, a quantifier by a bounded quantifier. In this case we have 
  1053   for instance, a quantifier by a bounded quantifier. To decompose them, we have 
  1048   rules of the form
  1054   to prove that the relations involved are aggregate equivalence relations.
  1049 
  1055 
  1050   \begin{isabelle}\ \ \ \ \ %%%
  1056   
  1051   @{text "(\<forall>x. R x \<longrightarrow> (P x \<longrightarrow> Q x)) \<longrightarrow> (\<forall>x. P x \<longrightarrow> \<forall>x \<in> R. Q x)"}
  1057   %In this case we have 
  1052   \end{isabelle}
  1058   %rules of the form
  1053 
  1059   %
  1054   \noindent
  1060   % \begin{isabelle}\ \ \ \ \ %%%
  1055   They decompose a bounded quantifier on the right-hand side. We can decompose a
  1061   %@{text "(\<forall>x. R x \<longrightarrow> (P x \<longrightarrow> Q x)) \<longrightarrow> (\<forall>x. P x \<longrightarrow> \<forall>x \<in> R. Q x)"}
  1056   bounded quantifier anywhere if R is an equivalence relation or
  1062   %\end{isabelle}
  1057   if it is a relation over function types with the range being an equivalence
  1063 
  1058   relation. If @{text R} is an equivalence relation we can prove that
  1064   %\noindent
  1059 
  1065   %They decompose a bounded quantifier on the right-hand side. We can decompose a
  1060   \begin{isabelle}\ \ \ \ \ %%%
  1066   %bounded quantifier anywhere if R is an equivalence relation or
  1061   @{text "\<forall>x \<in> Respects R. P x = \<forall>x. P x"}    
  1067   %if it is a relation over function types with the range being an equivalence
  1062   \end{isabelle}
  1068   %relation. If @{text R} is an equivalence relation we can prove that
  1063 
  1069 
  1064   \noindent
  1070   %\begin{isabelle}\ \ \ \ \ %%%
  1065   If @{term R\<^isub>2} is an equivalence relation, we can prove that for any predicate @{term P}
  1071   %@{text "\<forall>x \<in> Resp R. P x = \<forall>x. P x"}    
       
  1072   %\end{isabelle}
       
  1073 
       
  1074   %\noindent
       
  1075   %If @{term R\<^isub>2} is an equivalence relation, we can prove that for any predicate @{term P}
  1066 
  1076 
  1067 %%% FIXME Reviewer 1 claims the theorem is obviously false so maybe we
  1077 %%% FIXME Reviewer 1 claims the theorem is obviously false so maybe we
  1068 %%% should include a proof sketch?
  1078 %%% should include a proof sketch?
  1069 
  1079 
  1070   \begin{isabelle}\ \ \ \ \ %%%
  1080   %\begin{isabelle}\ \ \ \ \ %%%
  1071   @{thm (concl) ball_reg_eqv_range[of R\<^isub>1 R\<^isub>2, no_vars]}
  1081   %@{thm (concl) ball_reg_eqv_range[of R\<^isub>1 R\<^isub>2, no_vars]}
  1072   \end{isabelle}
  1082   %\end{isabelle}
  1073 
  1083 
  1074   \noindent
  1084   %\noindent
  1075   The last theorem is new in comparison with Homeier's package. There the
  1085   %The last theorem is new in comparison with Homeier's package. There the
  1076   injection procedure would be used to prove such goals and 
  1086   %injection procedure would be used to prove such goals and 
  1077   the assumption about the equivalence relation would be used. We use the above theorem directly,
  1087   %the assumption about the equivalence relation would be used. We use the above theorem directly,
  1078   because this allows us to completely separate the first and the second
  1088   %because this allows us to completely separate the first and the second
  1079   proof step into two independent ``units''.
  1089   %proof step into two independent ``units''.
  1080 
  1090 
  1081   The second proof step, establishing @{text "reg_thm \<longleftrightarrow> inj_thm"},  starts with an equality
  1091   The second phase, establishing @{text "reg_thm \<longleftrightarrow> inj_thm"},  starts with an equality
  1082   between the terms of the regularized theorem and the injected theorem.
  1092   between the terms of the regularized theorem and the injected theorem.
  1083   The proof again follows the structure of the
  1093   The proof again follows the structure of the
  1084   two underlying terms and is defined for a goal being a relation between these two terms.
  1094   two underlying terms taking respectfulness theorems into account.
  1085 
  1095 
  1086   \begin{itemize}
  1096   %\begin{itemize}
  1087   \item For two constants an appropriate respectfulness theorem is applied.
  1097   %\item For two constants an appropriate respectfulness theorem is applied.
  1088   \item For two variables, we use the assumptions proved in the regularization step.
  1098   %\item For two variables, we use the assumptions proved in the regularization step.
  1089   \item For two abstractions, we @{text "\<eta>"}-expand and @{text "\<beta>"}-reduce them.
  1099   %\item For two abstractions, we @{text "\<eta>"}-expand and @{text "\<beta>"}-reduce them.
  1090   \item For two applications, we check that the right-hand side is an application of
  1100   %\item For two applications, we check that the right-hand side is an application of
  1091     @{term Rep} to an @{term Abs} and @{term "Quotient R Rep Abs"} holds. If yes then we
  1101   %  @{term Rep} to an @{term Abs} and @{term "Quotient R Rep Abs"} holds. If yes then we
  1092     can apply the theorem:
  1102   %  can apply the theorem:
  1093 
  1103 
  1094   \begin{isabelle}\ \ \ \ \ %%%
  1104   %\begin{isabelle}\ \ \ \ \ %%%
  1095     @{term "R x y \<longrightarrow> R x (Rep (Abs y))"}
  1105   %  @{term "R x y \<longrightarrow> R x (Rep (Abs y))"}
  1096   \end{isabelle}
  1106   %\end{isabelle}
  1097 
  1107 
  1098     Otherwise we introduce an appropriate relation between the subterms
  1108   %  Otherwise we introduce an appropriate relation between the subterms
  1099     and continue with two subgoals using the lemma:
  1109   %  and continue with two subgoals using the lemma:
  1100 
  1110 
  1101   \begin{isabelle}\ \ \ \ \ %%%
  1111   %\begin{isabelle}\ \ \ \ \ %%%
  1102     @{text "(R\<^isub>1 \<doublearr> R\<^isub>2) f g \<longrightarrow> R\<^isub>1 x y \<longrightarrow> R\<^isub>2 (f x) (g y)"}
  1112   %  @{text "(R\<^isub>1 \<doublearr> R\<^isub>2) f g \<longrightarrow> R\<^isub>1 x y \<longrightarrow> R\<^isub>2 (f x) (g y)"}
  1103   \end{isabelle}
  1113   %\end{isabelle}
  1104   \end{itemize}
  1114   %\end{itemize}
  1105 
  1115 
  1106   We defined the theorem @{text "inj_thm"} in such a way that
  1116   We defined the theorem @{text "inj_thm"} in such a way that
  1107   establishing the equivalence @{text "inj_thm \<longleftrightarrow> quot_thm"} can be
  1117   establishing in the third phase the equivalence @{text "inj_thm \<longleftrightarrow> quot_thm"} can be
  1108   achieved by rewriting @{text "inj_thm"} with the preservation theorems and quotient
  1118   achieved by rewriting @{text "inj_thm"} with the preservation theorems and quotient
  1109   definitions. First the definitions of all lifted constants
  1119   definitions. This step also requires that the definitions of all lifted constants
  1110   are used to fold the @{term Rep} with the raw constants. Next for
  1120   are used to fold the @{term Rep} with the raw constants. We will give more details
  1111   all abstractions and quantifiers the lambda and
  1121   about our lifting procedure in a longer version of this paper.
  1112   quantifier preservation theorems are used to replace the
  1122 
  1113   variables that include raw types with respects by quantifiers
  1123   %Next for
  1114   over variables that include quotient types. We show here only
  1124   %all abstractions and quantifiers the lambda and
  1115   the lambda preservation theorem. Given
  1125   %quantifier preservation theorems are used to replace the
  1116   @{term "Quotient R\<^isub>1 Abs\<^isub>1 Rep\<^isub>1"} and @{term "Quotient R\<^isub>2 Abs\<^isub>2 Rep\<^isub>2"}, we have:
  1126   %variables that include raw types with respects by quantifiers
  1117 
  1127   %over variables that include quotient types. We show here only
  1118   \begin{isabelle}\ \ \ \ \ %%%
  1128   %the lambda preservation theorem. Given
  1119   @{thm (concl) lambda_prs[of _ "Abs\<^isub>1" "Rep\<^isub>1" _ "Abs\<^isub>2" "Rep\<^isub>2", no_vars]}
  1129   %@{term "Quotient R\<^isub>1 Abs\<^isub>1 Rep\<^isub>1"} and @{term "Quotient R\<^isub>2 Abs\<^isub>2 Rep\<^isub>2"}, we have:
  1120   \end{isabelle}
  1130 
  1121 
  1131   %\begin{isabelle}\ \ \ \ \ %%%
  1122   \noindent
  1132   %@{thm (concl) lambda_prs[of _ "Abs\<^isub>1" "Rep\<^isub>1" _ "Abs\<^isub>2" "Rep\<^isub>2", no_vars]}
  1123   Next, relations over lifted types can be rewritten to equalities
  1133   %\end{isabelle}
  1124   over lifted type. Rewriting is performed with the following theorem,
  1134 
  1125   which has been shown by Homeier~\cite{Homeier05}:
  1135   %\noindent
  1126 
  1136   %Next, relations over lifted types can be rewritten to equalities
  1127   \begin{isabelle}\ \ \ \ \ %%%
  1137   %over lifted type. Rewriting is performed with the following theorem,
  1128   @{thm (concl) Quotient_rel_rep[no_vars]}
  1138   %which has been shown by Homeier~\cite{Homeier05}:
  1129   \end{isabelle}
  1139 
  1130 
  1140   %\begin{isabelle}\ \ \ \ \ %%%
  1131   \noindent
  1141   %@{thm (concl) Quotient_rel_rep[no_vars]}
  1132   Finally, we rewrite with the preservation theorems. This will result
  1142   %\end{isabelle}
  1133   in two equal terms that can be solved by reflexivity.
  1143 
  1134   *}
  1144   
       
  1145   %Finally, we rewrite with the preservation theorems. This will result
       
  1146   %in two equal terms that can be solved by reflexivity.
       
  1147 *}
  1135 
  1148 
  1136 
  1149 
  1137 section {* Examples \label{sec:examples} *}
  1150 section {* Examples \label{sec:examples} *}
  1138 
  1151 
  1139 text {*
  1152 text {*
  1140 
  1153 
  1141 %%% FIXME Reviewer 1 would like an example of regularized and injected
  1154 %%% FIXME Reviewer 1 would like an example of regularized and injected
  1142 %%% statements. He asks for the examples twice, but I would still ignore
  1155 %%% statements. He asks for the examples twice, but I would still ignore
  1143 %%% it due to lack of space...
  1156 %%% it due to lack of space...
  1144 
  1157 
       
  1158   \noindent
  1145   In this section we will show a sequence of declarations for defining the 
  1159   In this section we will show a sequence of declarations for defining the 
  1146   type of integers by quotienting pairs of natural numbers, and
  1160   type of integers by quotienting pairs of natural numbers, and
  1147   lifting one theorem. 
  1161   lifting one theorem. 
  1148 
  1162 
  1149   A user of our quotient package first needs to define a relation on
  1163   A user of our quotient package first needs to define a relation on
  1227 
  1241 
  1228 section {* Conclusion and Related Work\label{sec:conc}*}
  1242 section {* Conclusion and Related Work\label{sec:conc}*}
  1229 
  1243 
  1230 text {*
  1244 text {*
  1231 
  1245 
       
  1246   \noindent
  1232   The code of the quotient package and the examples described here are already
  1247   The code of the quotient package and the examples described here are already
  1233   included in the standard distribution of Isabelle.\footnote{Available from
  1248   included in the standard distribution of Isabelle.\footnote{Available from
  1234   \href{http://isabelle.in.tum.de/}{http://isabelle.in.tum.de/}.} The package is
  1249   \href{http://isabelle.in.tum.de/}{http://isabelle.in.tum.de/}.} The package is
  1235   heavily used in the new version of Nominal Isabelle, which provides a
  1250   heavily used in the new version of Nominal Isabelle, which provides a
  1236   convenient reasoning infrastructure for programming language calculi
  1251   convenient reasoning infrastructure for programming language calculi