Quotient-Paper/Paper.thy
changeset 2237 d1ab5d2d6926
parent 2236 b8dda31890ff
child 2238 8ddf1330f2ed
equal deleted inserted replaced
2236:b8dda31890ff 2237:d1ab5d2d6926
    47 text {* 
    47 text {* 
    48    \begin{flushright}
    48    \begin{flushright}
    49   {\em ``Not using a [quotient] package has its advantages: we do not have to\\ 
    49   {\em ``Not using a [quotient] package has its advantages: we do not have to\\ 
    50     collect all the theorems we shall ever want into one giant list;''}\\
    50     collect all the theorems we shall ever want into one giant list;''}\\
    51     Larry Paulson \cite{Paulson06}
    51     Larry Paulson \cite{Paulson06}
    52   \end{flushright}\smallskip
    52   \end{flushright}
    53 
    53 
    54   \noindent
    54   \noindent
    55   Isabelle is a popular generic theorem prover in which many logics can be
    55   Isabelle is a popular generic theorem prover in which many logics can be
    56   implemented. The most widely used one, however, is Higher-Order Logic
    56   implemented. The most widely used one, however, is Higher-Order Logic
    57   (HOL). This logic consists of a small number of axioms and inference rules
    57   (HOL). This logic consists of a small number of axioms and inference rules
    62   understood how to use both mechanisms for dealing with quotient
    62   understood how to use both mechanisms for dealing with quotient
    63   constructions in HOL (see \cite{Homeier05,Paulson06}).  For example the
    63   constructions in HOL (see \cite{Homeier05,Paulson06}).  For example the
    64   integers in Isabelle/HOL are constructed by a quotient construction over the
    64   integers in Isabelle/HOL are constructed by a quotient construction over the
    65   type @{typ "nat \<times> nat"} and the equivalence relation
    65   type @{typ "nat \<times> nat"} and the equivalence relation
    66 
    66 
    67   @{text [display, indent=10] "(n\<^isub>1, n\<^isub>2) \<approx> (m\<^isub>1, m\<^isub>2) \<equiv> n\<^isub>1 + m\<^isub>2 = m\<^isub>1 + n\<^isub>2"}
    67   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
       
    68   @{text "(n\<^isub>1, n\<^isub>2) \<approx> (m\<^isub>1, m\<^isub>2) \<equiv> n\<^isub>1 + m\<^isub>2 = m\<^isub>1 + n\<^isub>2"}\hfill\numbered{natpairequiv}
       
    69   \end{isabelle}
    68 
    70 
    69   \noindent
    71   \noindent
    70   This constructions yields the new type @{typ int} and definitions for @{text
    72   This constructions yields the new type @{typ int} and definitions for @{text
    71   "0"} and @{text "1"} of type @{typ int} can be given in terms of pairs of
    73   "0"} and @{text "1"} of type @{typ int} can be given in terms of pairs of
    72   natural numbers (namely @{text "(0, 0)"} and @{text "(1, 0)"}). Operations
    74   natural numbers (namely @{text "(0, 0)"} and @{text "(1, 0)"}). Operations
    75   "add_pair (n\<^isub>1, m\<^isub>1) (n\<^isub>2,
    77   "add_pair (n\<^isub>1, m\<^isub>1) (n\<^isub>2,
    76   m\<^isub>2) \<equiv> (n\<^isub>1 + n\<^isub>2, m\<^isub>1 + m\<^isub>2)"}).
    78   m\<^isub>2) \<equiv> (n\<^isub>1 + n\<^isub>2, m\<^isub>1 + m\<^isub>2)"}).
    77   Similarly one can construct the type of finite sets, written @{term "\<alpha> fset"}, 
    79   Similarly one can construct the type of finite sets, written @{term "\<alpha> fset"}, 
    78   by quotienting the type @{text "\<alpha> list"} according to the equivalence relation
    80   by quotienting the type @{text "\<alpha> list"} according to the equivalence relation
    79 
    81 
    80   @{text [display, indent=10] "xs \<approx> ys \<equiv> (\<forall>x. memb x xs \<longleftrightarrow> memb x ys)"}
    82   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
       
    83   @{text "xs \<approx> ys \<equiv> (\<forall>x. memb x xs \<longleftrightarrow> memb x ys)"}\hfill\numbered{listequiv}
       
    84   \end{isabelle}
    81 
    85 
    82   \noindent
    86   \noindent
    83   which states that two lists are equivalent if every element in one list is
    87   which states that two lists are equivalent if every element in one list is
    84   also member in the other. The empty finite set, written @{term "{||}"}, can
    88   also member in the other. The empty finite set, written @{term "{||}"}, can
    85   then be defined as the empty list and the union of two finite sets, written
    89   then be defined as the empty list and the union of two finite sets, written
   143   \end{tikzpicture}
   147   \end{tikzpicture}
   144   \end{center}
   148   \end{center}
   145 
   149 
   146   \noindent
   150   \noindent
   147   The starting point is an existing type, often referred to as the \emph{raw
   151   The starting point is an existing type, often referred to as the \emph{raw
   148   type}, over which an equivalence relation given by the user is
   152   type}, over which an equivalence relation given by the user is defined. With
   149   defined. With this input the package introduces a new type, to which we
   153   this input the package introduces a new type, to which we refer as the
   150   refer as the \emph{quotient type}. This type comes with an
   154   \emph{quotient type}. This type comes with an \emph{abstraction} and a
   151   \emph{abstraction} and a \emph{representation} function, written @{text Abs}
   155   \emph{representation} function, written @{text Abs} and @{text
   152   and @{text Rep}.\footnote{Actually they need to be derived from slightly
   156   Rep}.\footnote{Actually slightly more basic functions are given; the @{text Abs}
   153   more basic functions. We will show the details later. } These functions
   157   and @{text Rep} need to be derived from them. We will show the details
   154   relate elements in the existing type to ones in the new type and vice versa;
   158   later. } These functions relate elements in the existing type to ones in the
   155   they can be uniquely identified by their type. For example for the integer
   159   new type and vice versa; they can be uniquely identified by their type. For
   156   quotient construction the types of @{text Abs} and @{text Rep} are
   160   example for the integer quotient construction the types of @{text Abs} and
       
   161   @{text Rep} are
   157 
   162 
   158   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
   163   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
   159   @{text "Abs :: nat \<times> nat \<Rightarrow> int"}\hspace{10mm}@{text "Rep :: int \<Rightarrow> nat \<times> nat"}
   164   @{text "Abs :: nat \<times> nat \<Rightarrow> int"}\hspace{10mm}@{text "Rep :: int \<Rightarrow> nat \<times> nat"}
   160   \end{isabelle}
   165   \end{isabelle}
   161 
   166 
   223   will present a formal definition of our aggregate abstraction and
   228   will present a formal definition of our aggregate abstraction and
   224   representation functions (this definition was omitted in \cite{Homeier05}). 
   229   representation functions (this definition was omitted in \cite{Homeier05}). 
   225   They generate definitions, like the one above for @{text "\<Union>"}, 
   230   They generate definitions, like the one above for @{text "\<Union>"}, 
   226   according to the type of the raw constant and the type
   231   according to the type of the raw constant and the type
   227   of the quotient constant. This means we also have to extend the notions
   232   of the quotient constant. This means we also have to extend the notions
   228   of \emph{aggregate relation}, \emph{respectfulness} and \emph{preservation}
   233   of \emph{aggregate equivalence relation}, \emph{respectfulness} and \emph{preservation}
   229   from Homeier \cite{Homeier05}.
   234   from Homeier \cite{Homeier05}.
   230 
   235 
   231   We will also address the criticism by Paulson \cite{Paulson06} cited at the
   236   We are also able to address the criticism by Paulson \cite{Paulson06} cited
   232   beginning of this section about having to collect theorems that are lifted from the raw
   237   at the beginning of this section about having to collect theorems that are
   233   level to the quotient level. Our quotient package is the first one that is modular so that it
   238   lifted from the raw level to the quotient level. Our quotient package is the
   234   allows to lift single theorems separately. This has the advantage for the
   239   first one that is modular so that it allows to lift single theorems
   235   user to develop a formal theory interactively an a natural progression. A
   240   separately. This has the advantage for the user to develop a formal theory
   236   pleasing result of the modularity is also that we are able to clearly
   241   interactively an a natural progression. A pleasing result of the modularity
   237   specify what needs to be done in the lifting process (this was only hinted at in
   242   is also that we are able to clearly specify what needs to be done in the
   238   \cite{Homeier05} and implemented as a ``rough recipe'' in ML-code).
   243   lifting process (this was only hinted at in \cite{Homeier05} and implemented
   239  
   244   as a ``rough recipe'' in ML-code).
   240   The paper is organised as follows \ldots
   245 
   241 *}
   246   The paper is organised as follows: Section \ref{sec:prelims} presents briefly
   242 
   247   some necessary preliminaries; Section \ref{sec:type} presents the definitions 
       
   248   of quotient types and shows how definitions can be made over quotient types. \ldots
       
   249 *}
   243 
   250 
   244 
   251 
   245 section {* Preliminaries and General Quotient\label{sec:prelims} *}
   252 section {* Preliminaries and General Quotient\label{sec:prelims} *}
   246 
       
   247 
       
   248 
   253 
   249 text {*
   254 text {*
   250   In this section we present the definitions of a quotient that follow
   255   In this section we present the definitions of a quotient that follow
   251   those by Homeier, the proofs can be found there.
   256   those by Homeier, the proofs can be found there.
   252 
   257 
   294       @{text "|"} & @{text "\<lambda>x\<^isup>\<sigma>. t"} & \textrm{(abstraction)} \\ \nonumber
   299       @{text "|"} & @{text "\<lambda>x\<^isup>\<sigma>. t"} & \textrm{(abstraction)} \\ \nonumber
   295   \end{eqnarray}
   300   \end{eqnarray}
   296 
   301 
   297   {\it Say more about containers / maping functions }
   302   {\it Say more about containers / maping functions }
   298 
   303 
   299 *}
   304   Such maps for most common types (list, pair, sum,
   300 
   305   option, \ldots) are described in Homeier, and we assume that @{text "map"}
   301 section {* Quotient Types and Lifting of Definitions *}
   306   is the function that returns a map for a given type.
       
   307 
       
   308 *}
       
   309 
       
   310 section {* Quotient Types and Quotient Definitions\label{sec:type} *}
   302 
   311 
   303 text {*
   312 text {*
   304   The first step in a quotient constructions is to take a name for the new
   313   The first step in a quotient constructions is to take a name for the new
   305   type, say @{text "\<kappa>\<^isub>q"}, and an equivalence relation defined over a
   314   type, say @{text "\<kappa>\<^isub>q"}, and an equivalence relation defined over a
   306   raw type, say @{text "\<sigma>"}. The equivalence relation for the quotient
   315   raw type, say @{text "\<sigma>"}. The equivalence relation for the quotient
   310   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
   319   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
   311   \isacommand{quotient\_type}~~@{text "\<alpha>s \<kappa>\<^isub>q = \<sigma> / R"}
   320   \isacommand{quotient\_type}~~@{text "\<alpha>s \<kappa>\<^isub>q = \<sigma> / R"}
   312   \end{isabelle}
   321   \end{isabelle}
   313 
   322 
   314   \noindent
   323   \noindent
   315   and a proof that @{text "R"} is indeed an equivalence relation.
   324   and a proof that @{text "R"} is indeed an equivalence relation. Two concrete
   316   Given this data, we can internally declare the quotient type as
   325   examples are
       
   326 
       
   327   
       
   328   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
       
   329   \begin{tabular}{@ {}l}
       
   330   \isacommand{quotient\_type}~~@{text "int = nat \<times> nat / \<approx>\<^bsub>nat \<times> nat\<^esub>"}\\
       
   331   \isacommand{quotient\_type}~~@{text "\<alpha> fset = \<alpha> list / \<approx>\<^bsub>list\<^esub>"}
       
   332   \end{tabular}
       
   333   \end{isabelle}
       
   334 
       
   335   \noindent
       
   336   which introduce the type of integers and of finite sets using the
       
   337   equivalence relations @{text "\<approx>\<^bsub>nat \<times> nat\<^esub>"} and @{text
       
   338   "\<approx>\<^bsub>list\<^esub>"} defined earlier in \eqref{natpairequiv} and
       
   339   \eqref{listequiv}, respectively.  Given this data, we declare internally 
       
   340   the quotient types as
   317   
   341   
   318   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
   342   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
   319   \isacommand{typedef}~~@{text "\<alpha>s \<kappa>\<^isub>q = {c. \<exists>x. c = R x}"}
   343   \isacommand{typedef}~~@{text "\<alpha>s \<kappa>\<^isub>q = {c. \<exists>x. c = R x}"}
   320   \end{isabelle}
   344   \end{isabelle}
   321 
   345 
   322   \noindent
   346   \noindent
   323   being the (non-empty) set of equivalence classes of @{text "R"}. The
   347   where the right hand side is the (non-empty) set of equivalence classes of
   324   restriction in this declaration is that the type variables in the raw type
   348   @{text "R"}. The restriction in this declaration is that the type variables
   325   @{text "\<sigma>"} must be included in the type variables @{text "\<alpha>s"} declared for
   349   in the raw type @{text "\<sigma>"} must be included in the type variables @{text
   326   @{text "\<kappa>\<^isub>q"}. HOL will provide us with abstraction and
   350   "\<alpha>s"} declared for @{text "\<kappa>\<^isub>q"}. HOL will provide us with
   327   representation functions having the type
   351   abstraction and representation functions having the type
   328 
   352 
   329   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
   353   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
   330   @{text "abs_\<kappa>\<^isub>q :: \<sigma> set \<Rightarrow> \<alpha>s \<kappa>\<^isub>q"}\hspace{10mm}@{text "rep_\<kappa>\<^isub>q :: \<alpha>s \<kappa>\<^isub>q \<Rightarrow> \<sigma> set"}
   354   @{text "abs_\<kappa>\<^isub>q :: \<sigma> set \<Rightarrow> \<alpha>s \<kappa>\<^isub>q"}\hspace{10mm}@{text "rep_\<kappa>\<^isub>q :: \<alpha>s \<kappa>\<^isub>q \<Rightarrow> \<sigma> set"}
   331   \end{isabelle}
   355   \end{isabelle}
   332 
   356 
   339   @{text "Abs_\<kappa>\<^isub>q x \<equiv> abs_\<kappa>\<^isub>q (R x)"}\hspace{10mm}@{text "Rep_\<kappa>\<^isub>q x \<equiv> \<epsilon> (rep_\<kappa>\<^isub>q x)"}
   363   @{text "Abs_\<kappa>\<^isub>q x \<equiv> abs_\<kappa>\<^isub>q (R x)"}\hspace{10mm}@{text "Rep_\<kappa>\<^isub>q x \<equiv> \<epsilon> (rep_\<kappa>\<^isub>q x)"}
   340   \end{isabelle}
   364   \end{isabelle}
   341   
   365   
   342   \noindent
   366   \noindent
   343   on the expense of having to use Hilbert's choice operator @{text "\<epsilon>"} in the
   367   on the expense of having to use Hilbert's choice operator @{text "\<epsilon>"} in the
   344   definition of @{text "Rep_\<kappa>\<^isub>q"}. These derived notions relate the quotient type
   368   definition of @{text "Rep_\<kappa>\<^isub>q"}. These derived notions relate the
   345   and the raw type directly, as can be seen from their type, namely @{text "\<sigma>
   369   quotient type and the raw type directly, as can be seen from their type,
   346   \<Rightarrow> \<alpha>s \<kappa>\<^isub>q"} and @{text "\<alpha>s \<kappa>\<^isub>q \<Rightarrow> \<sigma>"}, respectively.  Given that
   370   namely @{text "\<sigma> \<Rightarrow> \<alpha>s \<kappa>\<^isub>q"} and @{text "\<alpha>s \<kappa>\<^isub>q \<Rightarrow> \<sigma>"},
   347   @{text "R"} is an equivalence relation, the following property
   371   respectively.  Given that @{text "R"} is an equivalence relation, the
       
   372   following property
       
   373 
   348 
   374 
   349   @{text [display, indent=10] "Quotient R Abs_\<kappa>\<^isub>q Rep_\<kappa>\<^isub>q"}
   375   @{text [display, indent=10] "Quotient R Abs_\<kappa>\<^isub>q Rep_\<kappa>\<^isub>q"}
   350 
   376 
   351   \noindent
   377   \noindent
   352   holds (for the proof see \cite{Homeier05}).
   378   holds (for the proof see \cite{Homeier05}).
   353 
   379 
   354   The next step is to lift definitions over the raw type to definitions over the
   380   The next step is to introduce new definitions involving the quotient type,
   355   quotient type. For this we provide the declaration
   381   which need to be defined in terms of concepts of the raw type (remember this 
   356 
   382   is the only way how toe be able to extend HOL with new definitions). For the
   357   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
   383   user visible is the declaration
   358   \isacommand{quotient\_definition}~~@{text "c :: \<tau>"}~\isacommand{is}~@{text "c' :: \<sigma>"}
   384 
   359   \end{isabelle}
   385   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
   360 
   386   \isacommand{quotient\_definition}~~@{text "c :: \<tau>"}~~\isacommand{is}~~@{text "t :: \<sigma>"}
   361   To define a constant on the lifted type, an aggregate abstraction
   387   \end{isabelle}
   362   function is applied to the raw constant. Below we describe the operation
   388 
   363   that generates
   389   \noindent
   364   an aggregate @{term "Abs"} or @{term "Rep"} function given the
   390   where @{text t} is the definiens (its type @{text \<sigma>} can always be inferred)
   365   compound raw type and the compound quotient type.
   391   and @{text "c"} is the name of definiendum, whose type @{text "\<tau>"} needs to be
   366   This operation will also be used in translations of theorem statements
   392   given explicitly (the point is that @{text "\<tau>"} and @{text "\<sigma>"} can only differ 
   367   and in the lifting procedure.
   393   in places where a quotient and raw type are involved). Two examples are
   368 
   394 
   369   The operation is additionally able to descend into types for which
   395   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
   370   maps are known. Such maps for most common types (list, pair, sum,
   396   \begin{tabular}{@ {}l}
   371   option, \ldots) are described in Homeier, and we assume that @{text "map"}
   397   \isacommand{quotient\_definition}~~@{text "0 :: int"}~~\isacommand{is}~~@{text "(0::nat, 0::nat)"}\\
   372   is the function that returns a map for a given type. Then REP/ABS is defined
   398   \isacommand{quotient\_definition}~~@{text "\<Union> :: (\<alpha> fset) fset \<Rightarrow> \<alpha> fset"}~~%
   373   as follows:
   399   \isacommand{is}~~@{text "flat"} 
   374 
   400   \end{tabular}
   375   {\it the first argument is the raw type and the second argument the quotient type}
   401   \end{isabelle}
   376   %
   402   
       
   403   \noindent
       
   404   The first one declares zero for integers and the second the operator for
       
   405   building unions of finite sets. The problem for us is that from such
       
   406   declarations we need to derive proper definitions using the @{text "Abs"}
       
   407   and @{text "Rep"} functions for the quotient types involved. The data we
       
   408   rely on is the given quotient type @{text "\<tau>"} and the raw type @{text "\<sigma>"}.
       
   409   They allow us to define aggregate abstraction and representation functions
       
   410   using the functions @{text "ABS (\<sigma>, \<tau>)"} and @{text "REP (\<sigma>, \<tau>)"} whose 
       
   411   clauses are given below. The idea behind them is to recursively descend into 
       
   412   both types and generate the appropriate @{text "Abs"} and @{text "Rep"} 
       
   413   in places where the types differ. Therefore we returning just the identity
       
   414   whenever the types are equal.
       
   415 
   377   \begin{center}
   416   \begin{center}
   378   \begin{longtable}{rcl}
   417   \begin{longtable}{rcl}
   379   \multicolumn{3}{@ {\hspace{-4mm}}l}{equal types:}\\ 
   418   \multicolumn{3}{@ {\hspace{-4mm}}l}{equal types:}\\ 
   380   @{text "ABS (\<sigma>, \<sigma>)"} & $\dn$ & @{text "id"}\\
   419   @{text "ABS (\<sigma>, \<sigma>)"} & $\dn$ & @{text "id"}\\
   381   @{text "REP (\<sigma>, \<sigma>)"} & $\dn$ & @{text "id"}\smallskip\\
   420   @{text "REP (\<sigma>, \<sigma>)"} & $\dn$ & @{text "id"}\smallskip\\
   385   \multicolumn{3}{@ {\hspace{-4mm}}l}{equal type constructors:}\\ 
   424   \multicolumn{3}{@ {\hspace{-4mm}}l}{equal type constructors:}\\ 
   386   @{text "ABS (\<sigma>s \<kappa>, \<tau>s \<kappa>)"} & $\dn$ & @{text "map_\<kappa> (ABS (\<sigma>s, \<tau>s))"}\\
   425   @{text "ABS (\<sigma>s \<kappa>, \<tau>s \<kappa>)"} & $\dn$ & @{text "map_\<kappa> (ABS (\<sigma>s, \<tau>s))"}\\
   387   @{text "REP (\<sigma>s \<kappa>, \<tau>s \<kappa>)"} & $\dn$ & @{text "map_\<kappa> (REP (\<sigma>s, \<tau>s))"}\smallskip\\
   426   @{text "REP (\<sigma>s \<kappa>, \<tau>s \<kappa>)"} & $\dn$ & @{text "map_\<kappa> (REP (\<sigma>s, \<tau>s))"}\smallskip\\
   388   \multicolumn{3}{@ {\hspace{-4mm}}l}{unequal type constructors:}\\
   427   \multicolumn{3}{@ {\hspace{-4mm}}l}{unequal type constructors:}\\
   389   @{text "ABS (\<sigma>s \<kappa>, \<tau>s \<kappa>\<^isub>q)"} & $\dn$ & @{text "Abs_\<kappa>\<^isub>q \<circ> (MAP(\<rho>s \<kappa>) (ABS (\<sigma>s', \<tau>s')))"}\\
   428   @{text "ABS (\<sigma>s \<kappa>, \<tau>s \<kappa>\<^isub>q)"} & $\dn$ & @{text "Abs_\<kappa>\<^isub>q \<circ> (MAP(\<rho>s \<kappa>) (ABS (\<sigma>s', \<tau>s')))"}\\
   390   @{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"}\\
   429   @{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"}
   391   \end{longtable}
   430   \end{longtable}
   392   \end{center}
   431   \end{center}
   393   %
   432   %
   394   \noindent
   433   \noindent
   395   where in the last two clauses we have that the quotient type @{text "\<alpha>s \<kappa>\<^isub>q"} is a quotient of
   434   where in the last two clauses we have that the quotient type @{text "\<alpha>s
   396   the raw type @{text "\<rho>s \<kappa>"} (for example @{text "\<alpha> fset"} and @{text "\<alpha> list"}). 
   435   \<kappa>\<^isub>q"} is a quotient of the raw type @{text "\<rho>s \<kappa>"} (for example
   397   The quotient construction ensures that the type variables in @{text "\<rho>s"} 
   436   @{text "int"} and @{text "nat \<times> nat"}, or @{text "\<alpha> fset"} and @{text "\<alpha>
   398   must be amongst the @{text "\<alpha>s"}. Now the @{text "\<sigma>s'"} are given by the matchers 
   437   list"}). The quotient construction ensures that the type variables in @{text
   399   for the @{text "\<alpha>s"} 
   438   "\<rho>s"} must be amongst the @{text "\<alpha>s"}. The @{text "\<sigma>s'"} are given by the
   400   when matching  @{text "\<sigma>s \<kappa>\<^isub>q"} against @{text "\<alpha>s \<kappa>\<^isub>q"}; similarly the @{text "\<tau>s'"} are given by the 
   439   matchers for the @{text "\<alpha>s"} when matching @{text "\<sigma>s \<kappa>\<^isub>q"} against
   401   same type-variables when matching @{text "\<tau>s \<kappa>"} against @{text "\<rho>s \<kappa>"}.
   440   @{text "\<alpha>s \<kappa>\<^isub>q"}; similarly the @{text "\<tau>s'"} are given by the same
   402   The function @{text "MAP"} calculates an \emph{aggregate map-function} for a type 
   441   type-variables when matching @{text "\<tau>s \<kappa>"} against @{text "\<rho>s \<kappa>"}.  The
   403   as follows:
   442   function @{text "MAP"} calculates an \emph{aggregate map-function} for a raw
   404 
   443   type as follows:
       
   444   %
   405   \begin{center}
   445   \begin{center}
   406   \begin{tabular}{rcl}
   446   \begin{longtable}{rcl}
   407   @{text "MAP' (\<alpha>)"} & $\dn$ & @{text "a"}\\
   447   @{text "MAP' (\<alpha>)"} & $\dn$ & @{text "a\<^sup>\<alpha>"}\\
   408   @{text "MAP' (\<kappa>)"} & $\dn$ & @{text "id"}\\
   448   @{text "MAP' (\<kappa>)"} & $\dn$ & @{text "id"}\\
   409   @{text "MAP' (\<sigma>s \<kappa>)"} & $\dn$ & @{text "map_\<kappa> (MAP'(\<sigma>s))"}\smallskip\\
   449   @{text "MAP' (\<sigma>s \<kappa>)"} & $\dn$ & @{text "map_\<kappa> (MAP'(\<sigma>s))"}\smallskip\\
   410   @{text "MAP (\<sigma>)"} & $\dn$ & @{text "\<lambda>as. MAP'(\<sigma>)"}  
   450   @{text "MAP (\<sigma>)"} & $\dn$ & @{text "\<lambda>as. MAP'(\<sigma>)"}  
   411   \end{tabular}
   451   \end{longtable}
   412   \end{center}
   452   \end{center}
   413 
   453   %
   414   \noindent
   454   \noindent
   415   In this definition we abuse the fact that we can interpret type-variables @{text \<alpha>} as 
   455   In this definition we abuse the fact that we can interpret type-variables @{text \<alpha>} as 
   416   term variables @{text a}, and in the last clause build an abstraction over all
   456   term variables @{text a}, and in the last clause build an abstraction over all
   417   term-variables inside the aggregate map-function generated by @{text "MAP'"}.
   457   term-variables inside the aggregate map-function generated by @{text "MAP'"}.
   418   This aggregate map-function is necessary if we build quotients, say @{text "(\<alpha>, \<beta>) foo"},
   458   This aggregate map-function is necessary if we build quotients, say @{text "(\<alpha>, \<beta>) \<kappa>\<^isub>q"},
   419   out of compound raw types, say @{text "(\<alpha> list) \<times> \<beta>"}. In this case @{text MAP}
   459   out of compound raw types, say @{text "(\<alpha> list) \<times> \<beta>"}. In this case @{text MAP}
   420   generates the aggregate map-function:
   460   generates the aggregate map-function:
   421 
   461 
   422   @{text [display, indent=10] "\<lambda>a b. map_prod (map a) b"}
   462   @{text [display, indent=10] "\<lambda>a b. map_prod (map a) b"}
   423   
   463   
   427   into @{text ABS} gives us the abstraction function:
   467   into @{text ABS} gives us the abstraction function:
   428 
   468 
   429   @{text [display, indent=10] "(map (map id \<circ> Rep_fset) \<circ> Rep_fset) \<singlearr> Abs_fset \<circ> map id"}
   469   @{text [display, indent=10] "(map (map id \<circ> Rep_fset) \<circ> Rep_fset) \<singlearr> Abs_fset \<circ> map id"}
   430 
   470 
   431   \noindent
   471   \noindent
   432   where we already performed some @{text "\<beta>"}-simplifications. In our implementation
   472   where we already performed some @{text "\<beta>"}-simplifications. In our
   433   we further simplified this by noticing the usual laws about @{text "map"}s and @{text "id"},
   473   implementation we further simplify this by noticing the usual laws about
   434   namely @{term "map id = id"} and 
   474   @{text "map"}s and @{text "id"}, namely @{term "map id = id"} and @{text "f
   435   @{text "f \<circ> id = id \<circ> f = f"}. This gives us the simplified abstraction function
   475   \<circ> id = id \<circ> f = f"}. This gives us the simplified abstraction function
   436   
   476 
   437   @{text [display, indent=10] "(map Rep_fset \<circ> Rep_fset) \<singlearr> Abs_fset"}
   477   @{text [display, indent=10] "(map Rep_fset \<circ> Rep_fset) \<singlearr> Abs_fset"}
   438 
   478 
   439   \noindent
   479   \noindent
   440   which we can use for defining @{term "fconcat"} as follows
   480   which we can use for defining @{term "fconcat"} as follows
   441 
   481 
   442   @{text [display, indent=10] "\<Union> \<equiv> ((map Rep_fset \<circ> Rep_fset) \<singlearr> Abs_fset) flat"}
   482   @{text [display, indent=10] "\<Union> \<equiv> ((map Rep_fset \<circ> Rep_fset) \<singlearr> Abs_fset) flat"}
   443 
   483 
   444   Apart from the last 2 points the definition is same as the one implemented in
   484   \noindent
   445   in Homeier's HOL package. Adding composition in last two cases is necessary
   485   Note that by using the operator @{text "\<singlearr>"} we do not have to 
   446   for compositional quotients. We illustrate the different behaviour of the
   486   distinguish between arguments and results: teh representation and abstraction
   447   definition by showing the derived definition of @{term fconcat}:
   487   functions are just inverses which we can combine using @{text "\<singlearr>"}.
   448 
   488   So all our definitions are of the general form
   449   @{thm fconcat_def[no_vars]}
   489 
   450 
   490   @{text [display, indent=10] "c \<equiv> ABS (\<sigma>, \<tau>) t"}
   451   The aggregate @{term Abs} function takes a finite set of finite sets
   491 
   452   and applies @{term "map rep_fset"} composed with @{term rep_fset} to
   492   \noindent
   453   its input, obtaining a list of lists, passes the result to @{term concat}
   493   where @{text \<sigma>} is the type of @{text "t"} and @{text "\<tau>"} the type of the 
   454   obtaining a list and applies @{term abs_fset} obtaining the composed
   494   newly defined quotient constant @{text "c"}. To ensure we obtained a correct 
   455   finite set.
   495   definition, we can prove:
   456 
       
   457   For every type map function we require the property that @{term "map id = id"}.
       
   458   With this we can compactify the term, removing the identity mappings,
       
   459   obtaining a definition that is the same as the one provided by Homeier
       
   460   in the cases where the internal type does not change.
       
   461 
       
   462   {\it we should be able to prove}
       
   463 
   496 
   464   \begin{lemma}
   497   \begin{lemma}
   465   If @{text "ABS (\<sigma>, \<tau>)"} returns some abstraction function @{text "Abs"} 
   498   If @{text "ABS (\<sigma>, \<tau>)"} returns some abstraction function @{text "Abs"} 
   466   and @{text "REP (\<sigma>, \<tau>)"} some representation function @{text "Rep"}, 
   499   and @{text "REP (\<sigma>, \<tau>)"} some representation function @{text "Rep"}, 
   467   then @{text "Abs"} is of type @{text "\<sigma> \<Rightarrow> \<tau>"} and @{text "Rep"} of type
   500   then @{text "Abs"} is of type @{text "\<sigma> \<Rightarrow> \<tau>"} and @{text "Rep"} of type
   468   @{text "\<tau> \<Rightarrow> \<sigma>"}.
   501   @{text "\<tau> \<Rightarrow> \<sigma>"}.
   469   \end{lemma}
   502   \end{lemma}
   470 
   503 
   471   This lemma fails in the over-simplified abstraction and representation function used
   504   \begin{proof}
   472   in Homeier's quotient package.
   505   By induction of the definitions of @{text "ABS"}, @{text "REP"} and @{text "MAP"}.
       
   506   \end{proof}
       
   507   
       
   508   \noindent
       
   509   This lemma fails for the abstraction and representation functions used in,
       
   510   for example, Homeier's quotient package.
   473 *}
   511 *}
   474 
   512 
   475 subsection {* Respectfulness *}
   513 subsection {* Respectfulness *}
   476 
   514 
   477 text {*
   515 text {*
   864 *}
   902 *}
   865 
   903 
   866 section {* Conclusion *}
   904 section {* Conclusion *}
   867 
   905 
   868 text {*
   906 text {*
   869   The package is part of the standard distribution of Isabelle.
   907 
       
   908 
       
   909   The code of the quotient package described here is already included in the
       
   910   standard distribution of Isabelle.\footnote{Avaiable from
       
   911   \href{http://isabelle.in.tum.de/}{http://isabelle.in.tum.de/}.} It is
       
   912   heavily used in Nominal Isabelle, which provides a convenient reasoning
       
   913   infrastructure for programming language calculi involving binders.  Earlier
       
   914   versions of Nominal Isabelle have been used successfully in formalisations
       
   915   of an equivalence checking algorithm for LF \cite{UrbanCheneyBerghofer08},
       
   916   Typed Scheme~\cite{TobinHochstadtFelleisen08}, several calculi for
       
   917   concurrency \cite{BengtsonParow09} and a strong normalisation result for
       
   918   cut-elimination in classical logic \cite{UrbanZhu08}.
       
   919 
   870 *}
   920 *}
   871 
   921 
   872 
   922 
   873 subsection {* Contributions *}
   923 subsection {* Contributions *}
   874 
   924