diff -r 22c6b6144abd -r 8035515bbbc6 Quotient-Paper/Paper.thy --- a/Quotient-Paper/Paper.thy Sun Jun 13 14:39:55 2010 +0200 +++ b/Quotient-Paper/Paper.thy Sun Jun 13 17:01:15 2010 +0200 @@ -114,7 +114,7 @@ The purpose of a \emph{quotient package} is to ease the lifting of theorems and automate the definitions and reasoning as much as possible. In the context of HOL, there have been a few quotient packages already - \cite{harrison-thesis,Slotosch97}. The most notable is the one by Homeier + \cite{harrison-thesis,Slotosch97}. The most notable one is by Homeier \cite{Homeier05} implemented in HOL4. The fundamental construction these quotient packages perform can be illustrated by the following picture: @@ -144,19 +144,19 @@ \end{center} \noindent - The starting point is an existing type, often referred to as the - \emph{raw level}, over which an equivalence relation given by the user is + The starting point is an existing type, often referred to as the \emph{raw + type}, over which an equivalence relation given by the user is defined. With this input the package introduces a new type, to which we - refer as the \emph{quotient level}. This type comes with an + refer as the \emph{quotient type}. This type comes with an \emph{abstraction} and a \emph{representation} function, written @{text Abs} - and @{text Rep}. These functions relate elements in the existing type to - ones in the new type and vice versa; they can be uniquely identified by - their type. For example for the integer quotient construction the types of - @{text Abs} and @{text Rep} are - + and @{text Rep}.\footnote{Actually they need to be derived from slightly + more basic functions. We will show the details later. } These functions + relate elements in the existing type to ones in the new type and vice versa; + they can be uniquely identified by their type. For example for the integer + quotient construction the types of @{text Abs} and @{text Rep} are \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% - @{text "Abs::nat \ nat \ int"}\hspace{10mm}@{text "Rep::int \ nat \ nat"} + @{text "Abs :: nat \ nat \ int"}\hspace{10mm}@{text "Rep :: int \ nat \ nat"} \end{isabelle} \noindent @@ -192,7 +192,7 @@ \noindent We expect that the corresponding operator on finite sets, written @{term "fconcat"}, - behaves as follows: + builds the union of finite sets of finite sets: @{thm [display, indent=10] fconcat_empty[no_vars] fconcat_insert[no_vars]} @@ -205,7 +205,7 @@ the abstraction of the result is \emph{not} enough. The reason is that case in case of @{text "\"} we obtain the incorrect definition - @{text [display, indent=10] "\ S \ Abs (flat (Rep S))"} + @{text [display, indent=10] "\ S \ Abs_fset (flat (Rep_fset S))"} \noindent where the right-hand side is not even typable! This problem can be remedied in the @@ -216,7 +216,7 @@ representation and abstraction functions, which in case of @{text "\"} generate the following definition - @{text [display, indent=10] "\ S \ Abs (flat ((map Rep \ Rep) S))"} + @{text [display, indent=10] "\ S \ Abs_fset (flat ((map Rep_fset \ Rep_fset) S))"} \noindent where @{term map} is the usual mapping function for lists. In this paper we @@ -294,13 +294,52 @@ @{text "|"} & @{text "\x\<^isup>\. t"} & \textrm{(abstraction)} \\ \nonumber \end{eqnarray} + {\it Say more about containers / maping functions } + *} section {* Quotient Types and Lifting of Definitions *} -(* Say more about containers? *) +text {* + The first step in a quotient constructions is to take a name for the new + type, say @{text "\\<^isub>q"}, and an equivalence relation defined over a + raw type, say @{text "\"}. The equivalence relation for the quotient + construction, lets say @{text "R"}, must then be of type @{text "\ \ \ \ + bool"}. Given this data, we can automatically declare the quotient type as + + + \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% + \isacommand{typedef}~~@{text "\s \\<^isub>q = {c. \x. c = R x}"} + \end{isabelle} + + \noindent + being the set of equivalence classes of @{text "R"}. The restriction in this declaration + is that the type variables in the raw type @{text "\"} must be included in the + type variables @{text "\s"} declared for @{text "\\<^isub>q"}. HOL will provide us + with abstraction and representation functions having the type -text {* + \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% + @{text "abs_\\<^isub>q :: \ set \ \s \\<^isub>q"}\hspace{10mm}@{text "rep_\\<^isub>q :: \s \\<^isub>q \ \ set"} + \end{isabelle} + + \noindent + relating the new quotient type and raw type. However, as Homeier noted, it is easier + to work with the following derived definitions + + \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% + @{text "Abs_\\<^isub>q x \ abs_\\<^isub>q (R x)"}\hspace{10mm}@{text "Rep_\\<^isub>q x \ \ (rep_\\<^isub>q x)"} + \end{isabelle} + + \noindent + on the expense of having to use Hilbert's choice operator @{text "\"}. With these + definitions the abstraction and representation functions relate directly the + quotient and raw types (their type is @{text "\ \ \s \\<^isub>q"} and @{text "\s \\<^isub>q \ \"}, + respectively). We can show that the property + + @{text [display, indent=10] "Quotient R Abs_\\<^isub>q Rep_\\<^isub>q"} + + \noindent + holds (for the proof see \cite{Homeier05}). To define a constant on the lifted type, an aggregate abstraction function is applied to the raw constant. Below we describe the operation @@ -317,17 +356,9 @@ as follows: {\it the first argument is the raw type and the second argument the quotient type} - - + % \begin{center} - \begin{tabular}{rcl} - - % type variable case says that variables must be equal...therefore subsumed by the equal case below - % - %\multicolumn{3}{@ {\hspace{-4mm}}l}{type variables:}\\ - %@{text "ABS (\\<^isub>1, \\<^isub>2)"} & $\dn$ & @{text "id"}\\ - %@{text "REP (\\<^isub>1, \\<^isub>2)"} & $\dn$ & @{text "id"}\smallskip\\ - + \begin{longtable}{rcl} \multicolumn{3}{@ {\hspace{-4mm}}l}{equal types:}\\ @{text "ABS (\, \)"} & $\dn$ & @{text "id"}\\ @{text "REP (\, \)"} & $\dn$ & @{text "id"}\smallskip\\ @@ -338,19 +369,19 @@ @{text "ABS (\s \, \s \)"} & $\dn$ & @{text "map_\ (ABS (\s, \s))"}\\ @{text "REP (\s \, \s \)"} & $\dn$ & @{text "map_\ (REP (\s, \s))"}\smallskip\\ \multicolumn{3}{@ {\hspace{-4mm}}l}{unequal type constructors:}\\ - @{text "ABS (\s \\<^isub>1, \s \\<^isub>2)"} & $\dn$ & @{text "Abs_\\<^isub>2 \ (MAP(\s \\<^isub>1) (ABS (\s', \s')))"}\\ - @{text "REP (\s \\<^isub>1, \s \\<^isub>2)"} & $\dn$ & @{text "(MAP(\s \\<^isub>1) (REP (\s', \s'))) \ Rep_\\<^isub>2"}\\ - \end{tabular} + @{text "ABS (\s \, \s \\<^isub>q)"} & $\dn$ & @{text "Abs_\\<^isub>q \ (MAP(\s \) (ABS (\s', \s')))"}\\ + @{text "REP (\s \, \s \\<^isub>q)"} & $\dn$ & @{text "(MAP(\s \) (REP (\s', \s'))) \ Rep_\\<^isub>q"}\\ + \end{longtable} \end{center} - + % \noindent - where in the last two clauses we have that the quotient type @{text "\s \\<^isub>2"} is a quotient of - the raw type @{text "\s \\<^isub>1"} (for example @{text "\ fset"} and @{text "\ list"}). + where in the last two clauses we have that the quotient type @{text "\s \\<^isub>q"} is a quotient of + the raw type @{text "\s \"} (for example @{text "\ fset"} and @{text "\ list"}). The quotient construction ensures that the type variables in @{text "\s"} must be amongst the @{text "\s"}. Now the @{text "\s'"} are given by the matchers for the @{text "\s"} - when matching @{text "\s \\<^isub>2"} against @{text "\s \\<^isub>2"}; similarly the @{text "\s'"} are given by the - same type-variables when matching @{text "\s \\<^isub>1"} against @{text "\s \\<^isub>1"}. + when matching @{text "\s \\<^isub>q"} against @{text "\s \\<^isub>q"}; similarly the @{text "\s'"} are given by the + same type-variables when matching @{text "\s \"} against @{text "\s \"}. The function @{text "MAP"} calculates an \emph{aggregate map-function} for a type as follows: