Quotient-Paper/Paper.thy
changeset 2312 ad03df7e8056
parent 2213 231a20534950
child 2214 02e03d4287ec
equal deleted inserted replaced
2311:4da5c5c29009 2312:ad03df7e8056
       
     1 (* How to change the notation for \<lbrakk> \<rbrakk> meta-level implications? *)
     1 
     2 
     2 (*<*)
     3 (*<*)
     3 theory Paper
     4 theory Paper
     4 imports "Quotient"
     5 imports "Quotient"
     5         "LaTeXsugar"
     6         "LaTeXsugar"
     6         "../Nominal/FSet"
     7         "../Nominal/FSet"
     7 begin
     8 begin
     8 
     9 
       
    10 print_syntax
       
    11 
     9 notation (latex output)
    12 notation (latex output)
    10   rel_conj ("_ OOO _" [53, 53] 52)
    13   rel_conj ("_ OOO _" [53, 53] 52)
    11 and
    14 and
    12   fun_map ("_ ---> _" [51, 51] 50)
    15   "op -->" (infix "\<rightarrow>" 100)
    13 and
    16 and
    14   fun_rel ("_ ===> _" [51, 51] 50)
    17   "==>" (infix "\<Rightarrow>" 100)
       
    18 and
       
    19   fun_map (infix "\<longrightarrow>" 51)
       
    20 and
       
    21   fun_rel (infix "\<Longrightarrow>" 51)
    15 and
    22 and
    16   list_eq (infix "\<approx>" 50) (* Not sure if we want this notation...? *)
    23   list_eq (infix "\<approx>" 50) (* Not sure if we want this notation...? *)
    17 
    24 
    18 ML {*
    25 ML {*
    19 fun nth_conj n (_, r) = nth (HOLogic.dest_conj r) n;
    26 fun nth_conj n (_, r) = nth (HOLogic.dest_conj r) n;
    34 (*>*)
    41 (*>*)
    35 
    42 
    36 section {* Introduction *}
    43 section {* Introduction *}
    37 
    44 
    38 text {* 
    45 text {* 
    39   {\hfill quote by Larry}\bigskip
    46    \begin{flushright}
       
    47   {\em ``Not using a [quotient] package has its advantages: we do not have to\\ 
       
    48     collect all the theorems we shall ever want into one giant list;''}\\
       
    49     Larry Paulson \cite{Paulson06}
       
    50   \end{flushright}\smallskip
    40 
    51 
    41   \noindent
    52   \noindent
    42   Isabelle is a generic theorem prover in which many logics can be implemented. 
    53   Isabelle is a generic theorem prover in which many logics can be implemented. 
    43   The most widely used one, however, is
    54   The most widely used one, however, is
    44   Higher-Order Logic (HOL). This logic consists of a small number of 
    55   Higher-Order Logic (HOL). This logic consists of a small number of 
    45   axioms and inference
    56   axioms and inference
    46   rules over a simply-typed term-language. Safe reasoning in HOL is ensured by two very restricted 
    57   rules over a simply-typed term-language. Safe reasoning in HOL is ensured by two very restricted 
    47   mechanisms for extending the logic: one is the definition of new constants
    58   mechanisms for extending the logic: one is the definition of new constants
    48   in terms of existing ones; the other is the introduction of new types
    59   in terms of existing ones; the other is the introduction of new types
    49   by identifying non-empty subsets in existing types. It is well understood 
    60   by identifying non-empty subsets in existing types. It is well understood 
    50   to use both mechanism for dealing with quotient constructions in HOL (cite Larry).
    61   to use both mechanisms for dealing with quotient constructions in HOL (see for example 
       
    62   \cite{Paulson06}).
    51   For example the integers in Isabelle/HOL are constructed by a quotient construction over 
    63   For example the integers in Isabelle/HOL are constructed by a quotient construction over 
    52   the type @{typ "nat \<times> nat"} and the equivalence relation
    64   the type @{typ "nat \<times> nat"} and the equivalence relation
    53 
    65 
    54 % I would avoid substraction for natural numbers.
    66 % I would avoid substraction for natural numbers.
    55 
    67 
   111 
   123 
   112   \item We allow lifting only some occurrences of quotiented
   124   \item We allow lifting only some occurrences of quotiented
   113     types. Rsp/Prs extended. (used in nominal)
   125     types. Rsp/Prs extended. (used in nominal)
   114 
   126 
   115   \item The quotient package is very modular. Definitions can be added
   127   \item The quotient package is very modular. Definitions can be added
   116     separately, rsp and prs can be proved separately and theorems can
   128     separately, rsp and prs can be proved separately, Quotients and maps
   117     be lifted on a need basis. (useful with type-classes). 
   129     can be defined separately and theorems can
       
   130     be lifted on a need basis. (useful with type-classes).
   118 
   131 
   119   \item Can be used both manually (attribute, separate tactics,
   132   \item Can be used both manually (attribute, separate tactics,
   120     rsp/prs databases) and programatically (automated definition of
   133     rsp/prs databases) and programatically (automated definition of
   121     lifted constants, the rsp proof obligations and theorem statement
   134     lifted constants, the rsp proof obligations and theorem statement
   122     translation according to given quotients).
   135     translation according to given quotients).
   201   \begin{itemize}
   214   \begin{itemize}
   202   \item @{text "ABS(\<alpha>\<^isub>1, \<alpha>\<^isub>2)"} = @{text "id"}
   215   \item @{text "ABS(\<alpha>\<^isub>1, \<alpha>\<^isub>2)"} = @{text "id"}
   203   \item @{text "REP(\<alpha>\<^isub>1, \<alpha>\<^isub>2)"}  =  @{text "id"}
   216   \item @{text "REP(\<alpha>\<^isub>1, \<alpha>\<^isub>2)"}  =  @{text "id"}
   204   \item @{text "ABS(\<sigma>, \<sigma>)"}  =  @{text "id"}
   217   \item @{text "ABS(\<sigma>, \<sigma>)"}  =  @{text "id"}
   205   \item @{text "REP(\<sigma>, \<sigma>)"}  =  @{text "id"}
   218   \item @{text "REP(\<sigma>, \<sigma>)"}  =  @{text "id"}
   206   \item @{text "ABS(\<sigma>\<^isub>1\<rightarrow>\<sigma>\<^isub>2,\<tau>\<^isub>1\<rightarrow>\<tau>\<^isub>2)"}  =  @{text "REP(\<sigma>\<^isub>1,\<tau>\<^isub>1) ---> ABS(\<sigma>\<^isub>2,\<tau>\<^isub>2)"}
   219   \item @{text "ABS(\<sigma>\<^isub>1\<rightarrow>\<sigma>\<^isub>2,\<tau>\<^isub>1\<rightarrow>\<tau>\<^isub>2)"}  =  @{text "REP(\<sigma>\<^isub>1,\<tau>\<^isub>1) \<longrightarrow> ABS(\<sigma>\<^isub>2,\<tau>\<^isub>2)"}
   207   \item @{text "REP(\<sigma>\<^isub>1\<rightarrow>\<sigma>\<^isub>2,\<tau>\<^isub>1\<rightarrow>\<tau>\<^isub>2)"}  =  @{text "ABS(\<sigma>\<^isub>1,\<tau>\<^isub>1) ---> REP(\<sigma>\<^isub>2,\<tau>\<^isub>2)"}
   220   \item @{text "REP(\<sigma>\<^isub>1\<rightarrow>\<sigma>\<^isub>2,\<tau>\<^isub>1\<rightarrow>\<tau>\<^isub>2)"}  =  @{text "ABS(\<sigma>\<^isub>1,\<tau>\<^isub>1) \<longrightarrow> REP(\<sigma>\<^isub>2,\<tau>\<^isub>2)"}
   208   \item @{text "ABS((\<sigma>\<^isub>1,\<dots>,\<sigma>\<^isub>n))\<kappa>, (\<tau>\<^isub>1,\<dots>,\<tau>\<^isub>n))\<kappa>)"}  =  @{text "(map \<kappa>) (ABS(\<sigma>\<^isub>1,\<tau>\<^isub>1)) \<dots> (ABS(\<sigma>\<^isub>n,\<tau>\<^isub>n))"}
   221   \item @{text "ABS((\<sigma>\<^isub>1,\<dots>,\<sigma>\<^isub>n))\<kappa>, (\<tau>\<^isub>1,\<dots>,\<tau>\<^isub>n))\<kappa>)"}  =  @{text "(map \<kappa>) (ABS(\<sigma>\<^isub>1,\<tau>\<^isub>1)) \<dots> (ABS(\<sigma>\<^isub>n,\<tau>\<^isub>n))"}
   209   \item @{text "REP((\<sigma>\<^isub>1,\<dots>,\<sigma>\<^isub>n))\<kappa>, (\<tau>\<^isub>1,\<dots>,\<tau>\<^isub>n))\<kappa>)"}  =  @{text "(map \<kappa>) (REP(\<sigma>\<^isub>1,\<tau>\<^isub>1)) \<dots> (REP(\<sigma>\<^isub>n,\<tau>\<^isub>n))"}
   222   \item @{text "REP((\<sigma>\<^isub>1,\<dots>,\<sigma>\<^isub>n))\<kappa>, (\<tau>\<^isub>1,\<dots>,\<tau>\<^isub>n))\<kappa>)"}  =  @{text "(map \<kappa>) (REP(\<sigma>\<^isub>1,\<tau>\<^isub>1)) \<dots> (REP(\<sigma>\<^isub>n,\<tau>\<^isub>n))"}
   210   \item @{text "ABS((\<sigma>\<^isub>1,\<dots>,\<sigma>\<^isub>n))\<kappa>\<^isub>1, (\<tau>\<^isub>1,\<dots>,\<tau>\<^isub>m))\<kappa>\<^isub>2)"}  =  @{text "Abs_\<kappa>\<^isub>2 \<circ> (map \<kappa>\<^isub>1) (ABS(\<rho>\<^isub>1,\<nu>\<^isub>1) \<dots> (ABS(\<rho>\<^isub>p,\<nu>\<^isub>p)"} provided @{text "\<eta> \<kappa>\<^isub>2 = (\<alpha>\<^isub>1\<dots>\<alpha>\<^isub>p)\<kappa>\<^isub>1 \<and> \<exists>s. s(\<sigma>s\<kappa>\<^isub>1)=\<rho>s\<kappa>\<^isub>1 \<and> s(\<tau>s\<kappa>\<^isub>2)=\<nu>s\<kappa>\<^isub>2"}
   223   \item @{text "ABS((\<sigma>\<^isub>1,\<dots>,\<sigma>\<^isub>n))\<kappa>\<^isub>1, (\<tau>\<^isub>1,\<dots>,\<tau>\<^isub>m))\<kappa>\<^isub>2)"}  =  @{text "Abs_\<kappa>\<^isub>2 \<circ> (map \<kappa>\<^isub>1) (ABS(\<rho>\<^isub>1,\<nu>\<^isub>1) \<dots> (ABS(\<rho>\<^isub>p,\<nu>\<^isub>p)"} provided @{text "\<eta> \<kappa>\<^isub>2 = (\<alpha>\<^isub>1\<dots>\<alpha>\<^isub>p)\<kappa>\<^isub>1 \<and> \<exists>s. s(\<sigma>s\<kappa>\<^isub>1)=\<rho>s\<kappa>\<^isub>1 \<and> s(\<tau>s\<kappa>\<^isub>2)=\<nu>s\<kappa>\<^isub>2"}
   211   \item @{text "REP((\<sigma>\<^isub>1,\<dots>,\<sigma>\<^isub>n))\<kappa>\<^isub>1, (\<tau>\<^isub>1,\<dots>,\<tau>\<^isub>m))\<kappa>\<^isub>2)"}  =  @{text "(map \<kappa>\<^isub>1) (REP(\<rho>\<^isub>1,\<nu>\<^isub>1) \<dots> (REP(\<rho>\<^isub>p,\<nu>\<^isub>p) \<circ> Rep_\<kappa>\<^isub>2"} provided @{text "\<eta> \<kappa>\<^isub>2 = (\<alpha>\<^isub>1\<dots>\<alpha>\<^isub>p)\<kappa>\<^isub>1 \<and> \<exists>s. s(\<sigma>s\<kappa>\<^isub>1)=\<rho>s\<kappa>\<^isub>1 \<and> s(\<tau>s\<kappa>\<^isub>2)=\<nu>s\<kappa>\<^isub>2"}
   224   \item @{text "REP((\<sigma>\<^isub>1,\<dots>,\<sigma>\<^isub>n))\<kappa>\<^isub>1, (\<tau>\<^isub>1,\<dots>,\<tau>\<^isub>m))\<kappa>\<^isub>2)"}  =  @{text "(map \<kappa>\<^isub>1) (REP(\<rho>\<^isub>1,\<nu>\<^isub>1) \<dots> (REP(\<rho>\<^isub>p,\<nu>\<^isub>p) \<circ> Rep_\<kappa>\<^isub>2"} provided @{text "\<eta> \<kappa>\<^isub>2 = (\<alpha>\<^isub>1\<dots>\<alpha>\<^isub>p)\<kappa>\<^isub>1 \<and> \<exists>s. s(\<sigma>s\<kappa>\<^isub>1)=\<rho>s\<kappa>\<^isub>1 \<and> s(\<tau>s\<kappa>\<^isub>2)=\<nu>s\<kappa>\<^isub>2"}
   212   \end{itemize}
   225   \end{itemize}
   213 
   226 
   214   Apart from the last 2 points the definition is same as the one implemented in
   227   Apart from the last 2 points the definition is same as the one implemented in
   215   in Homeier's HOL package, below is the definition of @{term fconcat}
   228   in Homeier's HOL package. Adding composition in last two cases is necessary
   216   that shows the last points:
   229   for compositional quotients. We ilustrate the different behaviour of the
       
   230   definition by showing the derived definition of @{term fconcat}:
   217 
   231 
   218   @{thm fconcat_def[no_vars]}
   232   @{thm fconcat_def[no_vars]}
   219 
   233 
   220   The aggregate @{term Abs} function takes a finite set of finite sets
   234   The aggregate @{term Abs} function takes a finite set of finite sets
   221   and applies @{term "map rep_fset"} composed with @{term rep_fset} to
   235   and applies @{term "map rep_fset"} composed with @{term rep_fset} to
   228 
   242 
   229 text {*
   243 text {*
   230 
   244 
   231   A respectfulness lemma for a constant states that the equivalence
   245   A respectfulness lemma for a constant states that the equivalence
   232   class returned by this constant depends only on the equivalence
   246   class returned by this constant depends only on the equivalence
   233   classes of the arguments applied to the constant. This can be
   247   classes of the arguments applied to the constant. To automatically
   234   expressed in terms of an aggregate relation between the constant
   248   lift a theorem that talks about a raw constant, to a theorem about
   235   and itself, for example the respectfullness for @{term "append"}
   249   the quotient type a respectfulness theorem is required.
       
   250 
       
   251   A respectfulness condition for a constant can be expressed in
       
   252   terms of an aggregate relation between the constant and itself,
       
   253   for example the respectfullness for @{term "append"}
   236   can be stated as:
   254   can be stated as:
   237 
   255 
   238   @{thm [display] append_rsp[no_vars]}
   256   @{thm [display] append_rsp[no_vars]}
   239 
   257 
   240   \noindent
   258   \noindent
   241   Which is equivalent to:
   259   Which after unfolding @{term "op \<Longrightarrow>"} is equivalent to:
   242 
   260 
   243   @{thm [display] append_rsp_unfolded[no_vars]}
   261   @{thm [display] append_rsp_unfolded[no_vars]}
   244 
   262 
   245   Below we show the algorithm for finding the aggregate relation.
   263   An aggregate relation is defined in terms of relation composition,
   246   This algorithm uses
   264   so we define it first:
   247   the relation composition which we define as:
       
   248 
   265 
   249   \begin{definition}[Composition of Relations]
   266   \begin{definition}[Composition of Relations]
   250   @{abbrev "rel_conj R1 R2"} where @{text OO} is the predicate
   267   @{abbrev "rel_conj R1 R2"} where @{text OO} is the predicate
   251   composition @{thm pred_compI[no_vars]}
   268   composition @{thm pred_compI[no_vars]}
   252   \end{definition}
   269   \end{definition}
   253 
   270 
   254   Given an aggregate raw type and quotient type:
   271   The aggregate relation for an aggregate raw type and quotient type
   255 
   272   is defined as:
   256   \begin{itemize}
   273 
   257   \item For equal types or free type variables return equality
   274   \begin{itemize}
   258 
   275   \item @{text "REL(\<alpha>\<^isub>1, \<alpha>\<^isub>2)"} = @{text "op ="}
   259   \item For equal type constructors use the appropriate rel
   276   \item @{text "REL(\<sigma>, \<sigma>)"}  =  @{text "op ="}
   260     function applied to the results for the argument pairs
   277   \item @{text "REL((\<sigma>\<^isub>1,\<dots>,\<sigma>\<^isub>n))\<kappa>, (\<tau>\<^isub>1,\<dots>,\<tau>\<^isub>n))\<kappa>)"}  =  @{text "(rel \<kappa>) (REL(\<sigma>\<^isub>1,\<tau>\<^isub>1)) \<dots> (REL(\<sigma>\<^isub>n,\<tau>\<^isub>n))"}
   261 
   278   \item @{text "REL((\<sigma>\<^isub>1,\<dots>,\<sigma>\<^isub>n))\<kappa>\<^isub>1, (\<tau>\<^isub>1,\<dots>,\<tau>\<^isub>m))\<kappa>\<^isub>2)"}  =  @{text "(rel \<kappa>\<^isub>1) (REL(\<rho>\<^isub>1,\<nu>\<^isub>1) \<dots> (REL(\<rho>\<^isub>p,\<nu>\<^isub>p) OOO Eqv_\<kappa>\<^isub>2"} provided @{text "\<eta> \<kappa>\<^isub>2 = (\<alpha>\<^isub>1\<dots>\<alpha>\<^isub>p)\<kappa>\<^isub>1 \<and> \<exists>s. s(\<sigma>s\<kappa>\<^isub>1)=\<rho>s\<kappa>\<^isub>1 \<and> s(\<tau>s\<kappa>\<^isub>2)=\<nu>s\<kappa>\<^isub>2"}
   262   \item For unequal type constructors, look in the quotients information
   279 
   263     for a quotient type that matches the type constructor, and instantiate
   280   \end{itemize}
   264     the type appropriately getting back an instantiation environment. We
   281 
   265     apply the environment to the arguments and recurse composing it with
   282   Again, the last case is novel, so lets look at the example of
   266     the aggregate relation function.
   283   respectfullness for @{term concat}. The statement according to
   267 
   284   the definition above is:
   268   \end{itemize}
       
   269 
       
   270   Again, the the behaviour of our algorithm in the last situation is
       
   271   novel, so lets look at the example of respectfullness for @{term concat}.
       
   272   The statement as computed by the algorithm above is:
       
   273 
   285 
   274   @{thm [display] concat_rsp[no_vars]}
   286   @{thm [display] concat_rsp[no_vars]}
   275 
   287 
   276   \noindent
   288   \noindent
   277   By unfolding the definition of relation composition and relation map
   289   By unfolding the definition of relation composition and relation map
   314 
   326 
   315 text {*
   327 text {*
   316   Given two quotients, one of which quotients a container, and the
   328   Given two quotients, one of which quotients a container, and the
   317   other quotients the type in the container, we can write the
   329   other quotients the type in the container, we can write the
   318   composition of those quotients. To compose two quotient theorems
   330   composition of those quotients. To compose two quotient theorems
   319   we compose the relations with relation composition
   331   we compose the relations with relation composition as defined above
   320   and the abstraction and relation functions with function composition.
   332   and the abstraction and relation functions are the ones of the sub
   321   The @{term "Rep"} and @{term "Abs"} functions that we obtain are
   333   quotients composed with the usual function composition.
   322   the same as the ones created by in the aggregate functions and the
   334   The @{term "Rep"} and @{term "Abs"} functions that we obtain agree
       
   335   with the definition of aggregate Abs/Rep functions and the
   323   relation is the same as the one given by aggregate relations.
   336   relation is the same as the one given by aggregate relations.
   324   This becomes especially interesting
   337   This becomes especially interesting
   325   when we compose the quotient with itself, as there is no simple
   338   when we compose the quotient with itself, as there is no simple
   326   intermediate step.
   339   intermediate step.
   327 
   340 
   328   Lets take again the example of @{term concat}. To be able to lift
   341   Lets take again the example of @{term concat}. To be able to lift
   329   theorems that talk about it we will first prove the composition
   342   theorems that talk about it we provide the composition quotient
   330   quotient theorems, which then lets us perform the lifting procedure
   343   theorems, which then lets us perform the lifting procedure in an
   331   in an unchanged way:
   344   unchanged way:
   332 
   345 
   333   @{thm [display] quotient_compose_list[no_vars]}
   346   @{thm [display] quotient_compose_list[no_vars]}
   334 *}
   347 *}
   335 
   348 
   336 
   349 
   338 
   351 
   339 text {*
   352 text {*
   340   The core of the quotient package takes an original theorem that
   353   The core of the quotient package takes an original theorem that
   341   talks about the raw types, and the statement of the theorem that
   354   talks about the raw types, and the statement of the theorem that
   342   it is supposed to produce. This is different from other existing
   355   it is supposed to produce. This is different from other existing
   343   quotient packages, where only the raw theorems was necessary.
   356   quotient packages, where only the raw theorems were necessary.
   344   We notice that in some cases only some occurrences of the raw
   357   We notice that in some cases only some occurrences of the raw
   345   types need to be lifted. This is for example the case in the
   358   types need to be lifted. This is for example the case in the
   346   new Nominal package, where a raw datatype that talks about
   359   new Nominal package, where a raw datatype that talks about
   347   pairs of natural numbers or strings (being lists of characters)
   360   pairs of natural numbers or strings (being lists of characters)
   348   should not be changed to a quotient datatype with constructors
   361   should not be changed to a quotient datatype with constructors
   357   implementation.
   370   implementation.
   358 
   371 
   359   We first define the statement of the regularized theorem based
   372   We first define the statement of the regularized theorem based
   360   on the original theorem and the goal theorem. Then we define
   373   on the original theorem and the goal theorem. Then we define
   361   the statement of the injected theorem, based on the regularized
   374   the statement of the injected theorem, based on the regularized
   362   theorem and the goal. We then show the 3 proofs, and all three
   375   theorem and the goal. We then show the 3 proofs, as all three
   363   can be performed independently from each other.
   376   can be performed independently from each other.
   364 
   377 
   365 *}
   378 *}
   366 
   379 
   367 subsection {* Regularization and Injection statements *}
   380 subsection {* Regularization and Injection statements *}
   368 
   381 
   369 text {*
   382 text {*
   370 
   383 
   371   The function that gives the statement of the regularized theorem
   384   We first define the function @{text REG}, which takes the statements
   372   takes the statement of the raw theorem (a term) and the statement
   385   of the raw theorem and the lifted theorem (both as terms) and
   373   of the lifted theorem. The intuition behind the procedure is that
   386   returns the statement of the regularized version. The intuition
   374   it replaces quantifiers and abstractions involving raw types
   387   behind this function is that it replaces quantifiers and
   375   by bounded ones, and equalities involving raw types are replaced
   388   abstractions involving raw types by bounded ones, and equalities
   376   by appropriate aggregate relations. It is defined as follows:
   389   involving raw types are replaced by appropriate aggregate
       
   390   relations. It is defined as follows:
   377 
   391 
   378   \begin{itemize}
   392   \begin{itemize}
   379   \item @{text "REG (\<lambda>x : \<sigma>. t, \<lambda>x : \<sigma>. s) = \<lambda>x : \<sigma>. REG (t, s)"}
   393   \item @{text "REG (\<lambda>x : \<sigma>. t, \<lambda>x : \<sigma>. s) = \<lambda>x : \<sigma>. REG (t, s)"}
   380   \item @{text "REG (\<lambda>x : \<sigma>. t, \<lambda>x : \<tau>. s) = \<lambda>x : \<sigma> \<in> Res (REL (\<sigma>, \<tau>)). REG (t, s)"}
   394   \item @{text "REG (\<lambda>x : \<sigma>. t, \<lambda>x : \<tau>. s) = \<lambda>x : \<sigma> \<in> Res (REL (\<sigma>, \<tau>)). REG (t, s)"}
   381   \item @{text "REG (\<forall>x : \<sigma>. t, \<forall>x : \<sigma>. s) = \<forall>x : \<sigma>. REG (t, s)"}
   395   \item @{text "REG (\<forall>x : \<sigma>. t, \<forall>x : \<sigma>. s) = \<forall>x : \<sigma>. REG (t, s)"}
   385   \item @{text "REG (t\<^isub>1 t\<^isub>2, s\<^isub>1 s\<^isub>2) = REG (t\<^isub>1, s\<^isub>1) REG (t\<^isub>2, s\<^isub>2)"}
   399   \item @{text "REG (t\<^isub>1 t\<^isub>2, s\<^isub>1 s\<^isub>2) = REG (t\<^isub>1, s\<^isub>1) REG (t\<^isub>2, s\<^isub>2)"}
   386   \item @{text "REG (v\<^isub>1, v\<^isub>2) = v\<^isub>1"}
   400   \item @{text "REG (v\<^isub>1, v\<^isub>2) = v\<^isub>1"}
   387   \item @{text "REG (c\<^isub>1, c\<^isub>2) = c\<^isub>1"}
   401   \item @{text "REG (c\<^isub>1, c\<^isub>2) = c\<^isub>1"}
   388   \end{itemize}
   402   \end{itemize}
   389 
   403 
   390   Existential quantifiers and unique existential quantifiers are defined
   404   In the above definition we ommited the cases for existential quantifiers
   391   similarily to the universal one.
   405   and unique existential quantifiers, as they are very similar to the cases
   392 
   406   for the universal quantifier.
   393   The function that gives the statment of the injected theorem
   407 
   394   takes the statement of the regularized theorems and the statement
   408   Next we define the function @{text INJ} which takes the statement of
   395   of the lifted theorem both as terms.
   409   the regularized theorems and the statement of the lifted theorem both as
       
   410   terms and returns the statment of the injected theorem:
   396 
   411 
   397   \begin{itemize}
   412   \begin{itemize}
   398   \item @{text "INJ ((\<lambda>x. t) : \<sigma>, (\<lambda>x. s) : \<sigma>) = \<lambda>x. (INJ (t, s)"}
   413   \item @{text "INJ ((\<lambda>x. t) : \<sigma>, (\<lambda>x. s) : \<sigma>) = \<lambda>x. (INJ (t, s)"}
   399   \item @{text "INJ ((\<lambda>x. t) : \<sigma>, (\<lambda>x. s) : \<tau>) = REP(\<sigma>,\<tau>) (ABS (\<sigma>,\<tau>) (\<lambda>x. (INJ (t, s))))"}
   414   \item @{text "INJ ((\<lambda>x. t) : \<sigma>, (\<lambda>x. s) : \<tau>) = REP(\<sigma>,\<tau>) (ABS (\<sigma>,\<tau>) (\<lambda>x. (INJ (t, s))))"}
   400   \item @{text "INJ ((\<lambda>x \<in> R. t) : \<sigma>, (\<lambda>x. s) : \<tau>) = REP(\<sigma>,\<tau>) (ABS (\<sigma>,\<tau>) (\<lambda>x \<in> R. (INJ (t, s))))"}
   415   \item @{text "INJ ((\<lambda>x \<in> R. t) : \<sigma>, (\<lambda>x. s) : \<tau>) = REP(\<sigma>,\<tau>) (ABS (\<sigma>,\<tau>) (\<lambda>x \<in> R. (INJ (t, s))))"}
   410   For existential quantifiers and unique existential quantifiers it is
   425   For existential quantifiers and unique existential quantifiers it is
   411   defined similarily to the universal one.
   426   defined similarily to the universal one.
   412 
   427 
   413 *}
   428 *}
   414 
   429 
   415 subsection {* Proof of Regularization *}
   430 subsection {* Proof procedure *}
   416 
   431 
   417 text {*
   432 (* In the below the type-guiding 'QuotTrue' assumption is removed; since we
   418   Example of non-regularizable theorem ($0 = 1$).
   433    present in a paper a version with typed-variables it is not necessary *)
   419 
   434 
   420 
   435 text {*
   421   Separtion of regularization from injection thanks to the following 2 lemmas:
   436 
   422   \begin{lemma}
   437   With the above definitions of @{text "REG"} and @{text "INJ"} we can show
   423   If @{term R2} is an equivalence relation, then:
   438   how the proof is performed. The first step is always the application of
   424   \begin{eqnarray}
   439   of the following lemma:
   425   @{thm (rhs) ball_reg_eqv_range[no_vars]} & = & @{thm (lhs) ball_reg_eqv_range[no_vars]}\\
   440 
   426   @{thm (rhs) bex_reg_eqv_range[no_vars]} & = & @{thm (lhs) bex_reg_eqv_range[no_vars]}
   441   @{term "[|A; A --> B; B = C; C = D|] ==> D"}
   427   \end{eqnarray}
   442 
   428   \end{lemma}
   443   With @{text A} instantiated to the original raw theorem, 
   429 
   444        @{text B} instantiated to @{text "REG(A)"},
   430   Other lemmas used in regularization:
   445        @{text C} instantiated to @{text "INJ(REG(A))"},
       
   446    and @{text D} instantiated to the statement of the lifted theorem.
       
   447   The first assumption can be immediately discharged using the original
       
   448   theorem and the three left subgoals are exactly the subgoals of regularization,
       
   449   injection and cleaning. The three can be proved independently by the
       
   450   framework and in case there are non-solved subgoals they can be left
       
   451   to the user.
       
   452 
       
   453   The injection and cleaning subgoals are always solved if the appropriate
       
   454   respectfulness and preservation theorems are given. It is not the case
       
   455   with regularization; sometimes a theorem given by the user does not
       
   456   imply a regularized version and a stronger one needs to be proved. This
       
   457   is outside of the scope of the quotient package, so the user is then left
       
   458   with such obligations. As an example lets see the simplest possible
       
   459   non-liftable theorem for integers: When we want to prove @{term "0 \<noteq> 1"}
       
   460   on integers the fact that @{term "\<not> (0, 0) = (1, 0)"} is not enough. It
       
   461   only shows that particular items in the equivalence classes are not equal,
       
   462   a more general statement saying that the classes are not equal is necessary.
       
   463 *}
       
   464 
       
   465 subsection {* Proving Regularization *}
       
   466 
       
   467 text {*
       
   468 
       
   469   Isabelle provides a set of \emph{mono} rules, that are used to split implications
       
   470   of similar statements into simpler implication subgoals. These are enchanced
       
   471   with special quotient theorem in the regularization goal. Below we only show
       
   472   the versions for the universal quantifier. For the existential quantifier
       
   473   and abstraction they are analoguous with some symmetry.
       
   474 
       
   475   First, bounded universal quantifiers can be removed on the right:
       
   476 
       
   477   @{thm [display] ball_reg_right[no_vars]}
       
   478 
       
   479   They can be removed anywhere if the relation is an equivalence relation:
       
   480 
   431   @{thm [display] ball_reg_eqv[no_vars]}
   481   @{thm [display] ball_reg_eqv[no_vars]}
       
   482 
       
   483   And finally it can be removed anywhere if @{term R2} is an equivalence relation, then:
       
   484   \[
       
   485   @{thm (rhs) ball_reg_eqv_range[no_vars]} = @{thm (lhs) ball_reg_eqv_range[no_vars]}
       
   486   \]
       
   487 
       
   488   The last theorem is new in comparison with Homeier's package; it allows separating
       
   489   regularization from injection.
       
   490 
       
   491 *}
       
   492 
       
   493 (*
       
   494   @{thm (rhs) bex_reg_eqv_range[no_vars]} = @{thm (lhs) bex_reg_eqv_range[no_vars]}
       
   495   @{thm [display] bex_reg_left[no_vars]}
       
   496   @{thm [display] bex1_bexeq_reg[no_vars]}
   432   @{thm [display] bex_reg_eqv[no_vars]}
   497   @{thm [display] bex_reg_eqv[no_vars]}
   433   @{thm [display] babs_reg_eqv[no_vars]}
   498   @{thm [display] babs_reg_eqv[no_vars]}
   434   @{thm [display] babs_simp[no_vars]}
   499   @{thm [display] babs_simp[no_vars]}
   435 
   500 *)
   436   @{thm [display] ball_reg_right[no_vars]}
       
   437   @{thm [display] bex_reg_left[no_vars]}
       
   438   @{thm [display] bex1_bexeq_reg[no_vars]}
       
   439 
       
   440 *}
       
   441 
   501 
   442 subsection {* Injection *}
   502 subsection {* Injection *}
   443 
   503 
   444 text {*
   504 text {*
   445 
   505   The injection proof starts with an equality between the regularized theorem
   446   The 2 key lemmas are:
   506   and the injected version. The proof again follows by the structure of the
       
   507   two term, and is defined for a goal being a relation between the two terms.
       
   508 
       
   509   \begin{itemize}
       
   510   \item For two constants, an appropriate constant respectfullness assumption is used.
       
   511   \item For two variables, the regularization assumptions state that they are related.
       
   512   \item For two abstractions, they are eta-expanded and beta-reduced.
       
   513   \end{itemize}
       
   514 
       
   515   Otherwise the two terms are applications. There are two cases: If there is a REP/ABS
       
   516   in the injected theorem we can use the theorem:
       
   517 
       
   518   @{thm [display] rep_abs_rsp[no_vars]}
       
   519 
       
   520   and continue the proof.
       
   521 
       
   522   Otherwise we introduce an appropriate relation between the subterms and continue with
       
   523   two subgoals using the lemma:
   447 
   524 
   448   @{thm [display] apply_rsp[no_vars]}
   525   @{thm [display] apply_rsp[no_vars]}
   449   @{thm [display] rep_abs_rsp[no_vars]}
   526 
   450 
   527 *}
   451 
       
   452 
       
   453 *}
       
   454 
       
   455 
       
   456 
       
   457 
   528 
   458 subsection {* Cleaning *}
   529 subsection {* Cleaning *}
   459 
   530 
   460 text {* Preservation of quantifiers, abstractions, relations, quotient-constants
   531 text {*
   461   (definitions) and user given constant preservation lemmas *}
   532   The @{text REG} and @{text INJ} functions have been defined in such a way
       
   533   that establishing the goal theorem now consists only on rewriting the
       
   534   injected theorem with the preservation theorems.
       
   535 
       
   536   \begin{itemize}
       
   537   \item First for lifted constants, their definitions are the preservation rules for
       
   538     them.
       
   539   \item For lambda abstractions lambda preservation establishes
       
   540     the equality between the injected theorem and the goal. This allows both
       
   541     abstraction and quantification over lifted types.
       
   542     @{thm [display] lambda_prs[no_vars]}
       
   543   \item Relations over lifted types are folded with:
       
   544     @{thm [display] Quotient_rel_rep[no_vars]}
       
   545   \item User given preservation theorems, that allow using higher level operations
       
   546     and containers of types being lifted. An example may be
       
   547     @{thm [display] map_prs(1)[no_vars]}
       
   548   \end{itemize}
       
   549 
       
   550  Preservation of relations and user given constant preservation lemmas *}
   462 
   551 
   463 section {* Examples *}
   552 section {* Examples *}
       
   553 
       
   554 (* Mention why equivalence *)
       
   555 
       
   556 text {*
       
   557 
       
   558   A user of our quotient package first needs to define an equivalence relation:
       
   559 
       
   560   @{text "fun \<approx> where (x, y) \<approx> (u, v) = (x + v = u + y)"}
       
   561 
       
   562   Then the user defines a quotient type:
       
   563 
       
   564   @{text "quotient_type int = (nat \<times> nat) / \<approx>"}
       
   565 
       
   566   Which leaves a proof obligation that the relation is an equivalence relation,
       
   567   that can be solved with the automatic tactic with two definitions.
       
   568 
       
   569   The user can then specify the constants on the quotient type:
       
   570 
       
   571   @{text "quotient_definition 0 \<Colon> int is (0\<Colon>nat, 0\<Colon>nat)"}
       
   572   @{text "fun plus_raw where plus_raw (x, y) (u, v) = (x + u, y + v)"}
       
   573   @{text "quotient_definition (op +) \<Colon> (int \<Rightarrow> int \<Rightarrow> int) is plus_raw"}
       
   574 
       
   575   Lets first take a simple theorem about addition on the raw level:
       
   576 
       
   577   @{text "lemma plus_zero_raw: plus_raw (0, 0) i \<approx> i"}
       
   578 
       
   579   When the user tries to lift a theorem about integer addition, the respectfulness
       
   580   proof obligation is left, so let us prove it first:
       
   581   
       
   582   @{text "lemma (op \<approx> \<Longrightarrow> op \<approx> \<Longrightarrow> op \<approx>) plus_raw plus_raw"}
       
   583 
       
   584   Can be proved automatically by the system just by unfolding the definition
       
   585   of @{term "op \<Longrightarrow>"}.
       
   586 
       
   587   Now the user can either prove a lifted lemma explicitely:
       
   588 
       
   589   @{text "lemma 0 + i = i by lifting plus_zero_raw"}
       
   590 
       
   591   Or in this simple case use the automated translation mechanism:
       
   592 
       
   593   @{text "thm plus_zero_raw[quot_lifted]"}
       
   594 
       
   595   obtaining the same result.
       
   596 *}
   464 
   597 
   465 section {* Related Work *}
   598 section {* Related Work *}
   466 
   599 
   467 text {*
   600 text {*
   468   \begin{itemize}
   601   \begin{itemize}
   486   \item Setoids in Coq and \cite{ChicliPS02}
   619   \item Setoids in Coq and \cite{ChicliPS02}
   487 
   620 
   488   \end{itemize}
   621   \end{itemize}
   489 *}
   622 *}
   490 
   623 
       
   624 section {* Conclusion *}
       
   625 
   491 (*<*)
   626 (*<*)
   492 end
   627 end
   493 (*>*)
   628 (*>*)