Quotient-Paper/Paper.thy
changeset 2413 1341a2d7570f
parent 2412 63f0e7f914dd
child 2414 67e57fc3cd2a
equal deleted inserted replaced
2412:63f0e7f914dd 2413:1341a2d7570f
   330 
   330 
   331   \noindent
   331   \noindent
   332   Using extensionality and unfolding the definition of @{text "\<singlearr>"}, 
   332   Using extensionality and unfolding the definition of @{text "\<singlearr>"}, 
   333   we can get back to \eqref{adddef}. 
   333   we can get back to \eqref{adddef}. 
   334   In what follows we shall use the convention to write @{text "map_\<kappa>"} for a map-function 
   334   In what follows we shall use the convention to write @{text "map_\<kappa>"} for a map-function 
   335   of the type-constructor @{text \<kappa>}. In our implementation we maintain 
   335   of the type-constructor @{text \<kappa>}. For a type @{text \<kappa>} with arguments @{text "\<alpha>\<^isub>1\<^isub>\<dots>\<^isub>n"} the
       
   336   type of @{text "map_\<kappa>"} has to be @{text "\<alpha>\<^isub>1\<Rightarrow>\<dots>\<Rightarrow>\<alpha>\<^isub>n\<Rightarrow>\<alpha>\<^isub>1\<dots>\<alpha>\<^isub>n \<kappa>"}. For example @{text "map_list"}
       
   337   has to have the type @{text "\<alpha>\<Rightarrow>\<alpha> list"}.
       
   338   In our implementation we maintain
   336   a database of these map-functions that can be dynamically extended.
   339   a database of these map-functions that can be dynamically extended.
   337 
   340 
   338   It will also be necessary to have operators, referred to as @{text "rel_\<kappa>"},
   341   It will also be necessary to have operators, referred to as @{text "rel_\<kappa>"},
   339   which define equivalence relations in terms of constituent equivalence
   342   which define equivalence relations in terms of constituent equivalence
   340   relations. For example given two equivalence relations @{text "R\<^isub>1"}
   343   relations. For example given two equivalence relations @{text "R\<^isub>1"}
   369   relations, abstraction and representation functions:
   372   relations, abstraction and representation functions:
   370 
   373 
   371   \begin{definition}[Quotient Types]
   374   \begin{definition}[Quotient Types]
   372   Given a relation $R$, an abstraction function $Abs$
   375   Given a relation $R$, an abstraction function $Abs$
   373   and a representation function $Rep$, the predicate @{term "Quotient R Abs Rep"}
   376   and a representation function $Rep$, the predicate @{term "Quotient R Abs Rep"}
   374   means
   377   holds if and only if
   375   \begin{enumerate}
   378   \begin{enumerate}
   376   \item @{thm (rhs1) Quotient_def[of "R", no_vars]}
   379   \item @{thm (rhs1) Quotient_def[of "R", no_vars]}
   377   \item @{thm (rhs2) Quotient_def[of "R", no_vars]}
   380   \item @{thm (rhs2) Quotient_def[of "R", no_vars]}
   378   \item @{thm (rhs3) Quotient_def[of "R", no_vars]}
   381   \item @{thm (rhs3) Quotient_def[of "R", no_vars]}
   379   \end{enumerate}
   382   \end{enumerate}
   405   holds if and only if there exists a @{text y} such that @{thm (prem 1) pred_compI[of "R\<^isub>1" "x" "y" "R\<^isub>2" "z"]} and
   408   holds if and only if there exists a @{text y} such that @{thm (prem 1) pred_compI[of "R\<^isub>1" "x" "y" "R\<^isub>2" "z"]} and
   406   @{thm (prem 2) pred_compI[of "R\<^isub>1" "x" "y" "R\<^isub>2" "z"]}.
   409   @{thm (prem 2) pred_compI[of "R\<^isub>1" "x" "y" "R\<^isub>2" "z"]}.
   407   \end{definition}
   410   \end{definition}
   408 
   411 
   409   \noindent
   412   \noindent
   410   Unfortunately, there are two predicaments with compositions of relations.
   413   Unfortunately a general quotient theorem for @{text "\<circ>\<circ>\<circ>"}, analogous to the one
   411   First, a general quotient theorem for @{text "\<circ>\<circ>\<circ>"}, like the one for @{text "\<singlearr>"} 
   414   for @{text "\<singlearr>"} given in Proposition \ref{funquot}, would not be true
   412   given in Proposition \ref{funquot},
   415   in general. It cannot even be stated inside HOL, because of restrictions on types.
   413   cannot be stated inside HOL, because of restrictions on types.
   416   However, we can prove specific instances of a
   414   Second, even if we were able to state such a quotient theorem, it
       
   415   would not be true in general. However, we can prove specific instances of a
       
   416   quotient theorem for composing particular quotient relations.
   417   quotient theorem for composing particular quotient relations.
   417   For example, to lift theorems involving @{term flat} the quotient theorem for 
   418   For example, to lift theorems involving @{term flat} the quotient theorem for 
   418   composing @{text "\<approx>\<^bsub>list\<^esub>"} will be necessary: given @{term "Quotient R Abs Rep"} 
   419   composing @{text "\<approx>\<^bsub>list\<^esub>"} will be necessary: given @{term "Quotient R Abs Rep"} 
   419   with @{text R} being an equivalence relation, then
   420   with @{text R} being an equivalence relation, then
   420 
   421 
   519   \noindent
   520   \noindent
   520   The first one declares zero for integers and the second the operator for
   521   The first one declares zero for integers and the second the operator for
   521   building unions of finite sets (@{text "flat"} having the type 
   522   building unions of finite sets (@{text "flat"} having the type 
   522   @{text "(\<alpha> list) list \<Rightarrow> \<alpha> list"}). 
   523   @{text "(\<alpha> list) list \<Rightarrow> \<alpha> list"}). 
   523 
   524 
   524   The problem for us is that from such declarations we need to derive proper
   525   From such declarations given by the user, the quotient package needs to derive proper
   525   definitions using @{text "Abs"} and @{text "Rep"}. The data we rely on is the given quotient type
   526   definitions using @{text "Abs"} and @{text "Rep"}. The data we rely on is the given quotient type
   526   @{text "\<tau>"} and the raw type @{text "\<sigma>"}.  They allow us to define \emph{aggregate
   527   @{text "\<tau>"} and the raw type @{text "\<sigma>"}.  They allow us to define \emph{aggregate
   527   abstraction} and \emph{representation functions} using the functions @{text "ABS (\<sigma>,
   528   abstraction} and \emph{representation functions} using the functions @{text "ABS (\<sigma>,
   528   \<tau>)"} and @{text "REP (\<sigma>, \<tau>)"} whose clauses we shall give below. The idea behind
   529   \<tau>)"} and @{text "REP (\<sigma>, \<tau>)"} whose clauses we shall give below. The idea behind
   529   these two functions is to simultaneously descend into the raw types @{text \<sigma>} and 
   530   these two functions is to simultaneously descend into the raw types @{text \<sigma>} and 
  1064   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %
  1065   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %
  1065   \isacommand{lemma}~~@{text "add_pair_zero: int_rel (add_pair (0, 0) x) x"}
  1066   \isacommand{lemma}~~@{text "add_pair_zero: int_rel (add_pair (0, 0) x) x"}
  1066   \end{isabelle}
  1067   \end{isabelle}
  1067 
  1068 
  1068   \noindent
  1069   \noindent
  1069   If the user lifts this theorem, all proof obligations are 
  1070   If the user lifts this theorem, the quotient package performs all the lifting
  1070   automatically discharged, except the respectfulness
  1071   automatically leaving the respectfulness proof for the constant @{text "add_pair"}
  1071   proof for @{text "add_pair"}:
  1072   as the only remaining proof obligation. This property needs to be proved by the user:
  1072 
  1073 
  1073   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %
  1074   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %
  1074   \begin{tabular}{@ {}l}
  1075   \begin{tabular}{@ {}l}
  1075   \isacommand{lemma}~~@{text "[quot_respect]:"}\\ 
  1076   \isacommand{lemma}~~@{text "[quot_respect]:"}\\ 
  1076   @{text "(int_rel \<doublearr> int_rel \<doublearr> int_rel) add_pair add_pair"}
  1077   @{text "(int_rel \<doublearr> int_rel \<doublearr> int_rel) add_pair add_pair"}
  1077   \end{tabular}
  1078   \end{tabular}
  1078   \end{isabelle}
  1079   \end{isabelle}
  1079 
  1080 
  1080   \noindent
  1081   \noindent
  1081   This property needs to be proved by the user. It
  1082   It can be discharged automatically by Isabelle when hinting to unfold the definition
  1082   can be discharged automatically by Isabelle when hinting to unfold the definition
       
  1083   of @{text "\<doublearr>"}.
  1083   of @{text "\<doublearr>"}.
  1084   After this, the user can prove the lifted lemma as follows:
  1084   After this, the user can prove the lifted lemma as follows:
  1085 
  1085 
  1086   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %
  1086   \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %
  1087   \isacommand{lemma}~~@{text "0 + (x :: int) = x"}~~\isacommand{by}~~@{text "lifting add_pair_zero"}
  1087   \isacommand{lemma}~~@{text "0 + (x :: int) = x"}~~\isacommand{by}~~@{text "lifting add_pair_zero"}