src/HOL/Tools/Quotient/quotient_type.ML
changeset 47938 2924f37cb6b3
parent 47937 70375fa2679d
child 47983 a5e699834f2d
equal deleted inserted replaced
47937:70375fa2679d 47938:2924f37cb6b3
     4 Definition of a quotient type.
     4 Definition of a quotient type.
     5 *)
     5 *)
     6 
     6 
     7 signature QUOTIENT_TYPE =
     7 signature QUOTIENT_TYPE =
     8 sig
     8 sig
     9   val can_generate_code_cert: thm -> bool
       
    10   
       
    11   val add_quotient_type: ((string list * binding * mixfix) * (typ * term * bool) * 
     9   val add_quotient_type: ((string list * binding * mixfix) * (typ * term * bool) * 
    12     ((binding * binding) option * bool)) * thm -> local_theory -> Quotient_Info.quotients * local_theory
    10     ((binding * binding) option * bool)) * thm -> local_theory -> Quotient_Info.quotients * local_theory
    13 
    11 
    14   val quotient_type: ((string list * binding * mixfix) * (typ * term * bool) * 
    12   val quotient_type: ((string list * binding * mixfix) * (typ * term * bool) * 
    15     ((binding * binding) option * bool)) list -> Proof.context -> Proof.state
    13     ((binding * binding) option * bool)) list -> Proof.context -> Proof.state
    77   in
    75   in
    78     Goal.prove lthy [] [] goal
    76     Goal.prove lthy [] [] goal
    79       (K (typedef_quot_type_tac equiv_thm typedef_info))
    77       (K (typedef_quot_type_tac equiv_thm typedef_info))
    80   end
    78   end
    81    
    79    
    82 fun can_generate_code_cert quot_thm  =
       
    83    case Quotient_Term.get_rel_from_quot_thm quot_thm of
       
    84       Const (@{const_name HOL.eq}, _) => true
       
    85       | Const (@{const_name Lifting.invariant}, _) $ _  => true
       
    86       | _ => false
       
    87 
       
    88 fun define_abs_type quot_thm lthy =
       
    89   if can_generate_code_cert quot_thm then
       
    90     let
       
    91       val abs_type_thm = quot_thm RS @{thm Quotient3_abs_rep}
       
    92       val add_abstype_attribute = 
       
    93           Thm.declaration_attribute (fn thm => Context.mapping (Code.add_abstype thm) I)
       
    94         val add_abstype_attrib = Attrib.internal (K add_abstype_attribute);
       
    95     in
       
    96       lthy
       
    97         |> (snd oo Local_Theory.note) ((Binding.empty, [add_abstype_attrib]), [abs_type_thm])
       
    98     end
       
    99   else
       
   100     lthy
       
   101 
       
   102 open Lifting_Util
    80 open Lifting_Util
   103 
    81 
   104 infix 0 MRSL
    82 infix 0 MRSL
   105 
    83 
   106 fun define_cr_rel equiv_thm abs_fun lthy =
    84 fun define_cr_rel equiv_thm abs_fun lthy =
   167   in
   145   in
   168     lthy
   146     lthy
   169       |> Local_Theory.declaration {syntax = false, pervasive = true}
   147       |> Local_Theory.declaration {syntax = false, pervasive = true}
   170         (fn phi => Quotient_Info.update_quotients qty_full_name (quot_info phi)
   148         (fn phi => Quotient_Info.update_quotients qty_full_name (quot_info phi)
   171           #> Quotient_Info.update_abs_rep qty_full_name (abs_rep_info phi))
   149           #> Quotient_Info.update_abs_rep qty_full_name (abs_rep_info phi))
   172       |> define_abs_type quot_thm
       
   173       |> setup_lifting_package gen_code quot_thm equiv_thm
   150       |> setup_lifting_package gen_code quot_thm equiv_thm
   174   end
   151   end
   175 
   152 
   176 (* main function for constructing a quotient type *)
   153 (* main function for constructing a quotient type *)
   177 fun add_quotient_type (((vs, qty_name, mx), (rty, rel, partial), (opt_morphs, gen_code)), equiv_thm) lthy =
   154 fun add_quotient_type (((vs, qty_name, mx), (rty, rel, partial), (opt_morphs, gen_code)), equiv_thm) lthy =