Quotient-Paper/Paper.thy
changeset 2235 ad725de6e39b
parent 2234 8035515bbbc6
child 2236 b8dda31890ff
equal deleted inserted replaced
2234:8035515bbbc6 2235:ad725de6e39b
   303 text {*
   303 text {*
   304   The first step in a quotient constructions is to take a name for the new
   304   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
   305   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
   306   raw type, say @{text "\<sigma>"}. The equivalence relation for the quotient
   307   construction, lets say @{text "R"}, must then be of type @{text "\<sigma> \<Rightarrow> \<sigma> \<Rightarrow>
   307   construction, lets say @{text "R"}, must then be of type @{text "\<sigma> \<Rightarrow> \<sigma> \<Rightarrow>
   308   bool"}. Given this data, we can automatically declare the quotient type as
   308   bool"}. The user-visible part of the declaration is therefore 
   309 
   309 
       
   310   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
       
   311   \isacommand{quotient\_type}~~@{text "\<alpha>s \<kappa>\<^isub>q = \<sigma> / R"}
       
   312   \end{isabelle}
       
   313 
       
   314   \noindent
       
   315   and a proof that @{text "R"} is indeed an equivalence relation.
       
   316   Given this data, we can internally declare the quotient type as
   310   
   317   
   311   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
   318   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
   312   \isacommand{typedef}~~@{text "\<alpha>s \<kappa>\<^isub>q = {c. \<exists>x. c = R x}"}
   319   \isacommand{typedef}~~@{text "\<alpha>s \<kappa>\<^isub>q = {c. \<exists>x. c = R x}"}
   313   \end{isabelle}
   320   \end{isabelle}
   314 
   321 
   315   \noindent
   322   \noindent
   316   being the set of equivalence classes of @{text "R"}. The restriction in this declaration
   323   being the (non-empty) set of equivalence classes of @{text "R"}. The
   317   is that the type variables in the raw type @{text "\<sigma>"} must be included in the 
   324   restriction in this declaration is that the type variables in the raw type
   318   type variables @{text "\<alpha>s"} declared for @{text "\<kappa>\<^isub>q"}. HOL will provide us 
   325   @{text "\<sigma>"} must be included in the type variables @{text "\<alpha>s"} declared for
   319   with abstraction and representation functions having the type
   326   @{text "\<kappa>\<^isub>q"}. HOL will provide us with abstraction and
       
   327   representation functions having the type
   320 
   328 
   321   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
   329   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
   322   @{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"}
   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"}
   323   \end{isabelle}
   331   \end{isabelle}
   324 
   332 
   325   \noindent
   333   \noindent 
   326   relating the new quotient type and raw type. However, as Homeier noted, it is easier 
   334   and relating the new quotient type and equivalence classes of the raw
   327   to work with the following derived definitions
   335   type. However, as Homeier \cite{Homeier05} noted, it is much more convenient
   328   
   336   to work with the following derived abstraction and representation functions
       
   337 
   329   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
   338   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
   330   @{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)"}
   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)"}
   331   \end{isabelle}
   340   \end{isabelle}
   332   
   341   
   333   \noindent
   342   \noindent
   334   on the expense of having to use Hilbert's choice operator @{text "\<epsilon>"}. With these
   343   on the expense of having to use Hilbert's choice operator @{text "\<epsilon>"} in the
   335   definitions the abstraction and representation functions relate directly the 
   344   definition of @{text "Rep_\<kappa>\<^isub>q"}. These derived notions relate the quotient type
   336   quotient and raw types (their type is  @{text "\<sigma> \<Rightarrow> \<alpha>s \<kappa>\<^isub>q"} and @{text "\<alpha>s \<kappa>\<^isub>q \<Rightarrow> \<sigma>"}, 
   345   and the raw type directly, as can be seen from their type, namely @{text "\<sigma>
   337   respectively). We can show that the property
   346   \<Rightarrow> \<alpha>s \<kappa>\<^isub>q"} and @{text "\<alpha>s \<kappa>\<^isub>q \<Rightarrow> \<sigma>"}, respectively.  Given that
       
   347   @{text "R"} is an equivalence relation, the following property
   338 
   348 
   339   @{text [display, indent=10] "Quotient R Abs_\<kappa>\<^isub>q Rep_\<kappa>\<^isub>q"}
   349   @{text [display, indent=10] "Quotient R Abs_\<kappa>\<^isub>q Rep_\<kappa>\<^isub>q"}
   340 
   350 
   341   \noindent
   351   \noindent
   342   holds (for the proof see \cite{Homeier05}).
   352   holds (for the proof see \cite{Homeier05}).
       
   353 
       
   354   The next step is to lift definitions over the raw type to definitions over the
       
   355   quotient type. For this we providing the declaration
       
   356 
       
   357   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
       
   358   \isacommand{quotient\_definition}~~@{text "c :: \<tau>"}~\isacommand{is}~@{text "c' :: \<sigma>"}
       
   359   \end{isabelle}
   343 
   360 
   344   To define a constant on the lifted type, an aggregate abstraction
   361   To define a constant on the lifted type, an aggregate abstraction
   345   function is applied to the raw constant. Below we describe the operation
   362   function is applied to the raw constant. Below we describe the operation
   346   that generates
   363   that generates
   347   an aggregate @{term "Abs"} or @{term "Rep"} function given the
   364   an aggregate @{term "Abs"} or @{term "Rep"} function given the
   413 
   430 
   414   \noindent
   431   \noindent
   415   where we already performed some @{text "\<beta>"}-simplifications. In our implementation
   432   where we already performed some @{text "\<beta>"}-simplifications. In our implementation
   416   we further simplified this by noticing the usual laws about @{text "map"}s and @{text "id"},
   433   we further simplified this by noticing the usual laws about @{text "map"}s and @{text "id"},
   417   namely @{term "map id = id"} and 
   434   namely @{term "map id = id"} and 
   418   @{text "f \<circ> id = id \<circ> f = f"}. This gives us the simplified abstarction function
   435   @{text "f \<circ> id = id \<circ> f = f"}. This gives us the simplified abstraction function
   419   
   436   
   420   @{text [display, indent=10] "(map Rep_fset \<circ> Rep_fset) \<singlearr> Abs_fset"}
   437   @{text [display, indent=10] "(map Rep_fset \<circ> Rep_fset) \<singlearr> Abs_fset"}
   421 
   438 
   422   \noindent
   439   \noindent
   423   which we can use for defining @{term "fconcat"} as follows
   440   which we can use for defining @{term "fconcat"} as follows
   437   obtaining a list and applies @{term abs_fset} obtaining the composed
   454   obtaining a list and applies @{term abs_fset} obtaining the composed
   438   finite set.
   455   finite set.
   439 
   456 
   440   For every type map function we require the property that @{term "map id = id"}.
   457   For every type map function we require the property that @{term "map id = id"}.
   441   With this we can compactify the term, removing the identity mappings,
   458   With this we can compactify the term, removing the identity mappings,
   442   obtaining a definition that is the same as the one privided by Homeier
   459   obtaining a definition that is the same as the one provided by Homeier
   443   in the cases where the internal type does not change.
   460   in the cases where the internal type does not change.
   444 
   461 
   445   {\it we should be able to prove}
   462   {\it we should be able to prove}
   446 
   463 
   447   \begin{lemma}
   464   \begin{lemma}