src/HOL/Tools/Quotient/quotient_term.ML
changeset 47096 3ea48c19673e
parent 47095 b43ddeea727f
child 47106 dfa5ed8d94b4
equal deleted inserted replaced
47095:b43ddeea727f 47096:3ea48c19673e
    17   (* Allows Nitpick to represent quotient types as single elements from raw type *)
    17   (* Allows Nitpick to represent quotient types as single elements from raw type *)
    18   val absrep_const_chk: Proof.context -> flag -> string -> term
    18   val absrep_const_chk: Proof.context -> flag -> string -> term
    19 
    19 
    20   val equiv_relation: Proof.context -> typ * typ -> term
    20   val equiv_relation: Proof.context -> typ * typ -> term
    21   val equiv_relation_chk: Proof.context -> typ * typ -> term
    21   val equiv_relation_chk: Proof.context -> typ * typ -> term
       
    22 
       
    23   val get_rel_from_quot_thm: thm -> term
       
    24   val prove_quot_theorem: Proof.context -> typ * typ -> thm
    22 
    25 
    23   val regularize_trm: Proof.context -> term * term -> term
    26   val regularize_trm: Proof.context -> term * term -> term
    24   val regularize_trm_chk: Proof.context -> term * term -> term
    27   val regularize_trm_chk: Proof.context -> term * term -> term
    25 
    28 
    26   val inj_repabs_trm: Proof.context -> term * term -> term
    29   val inj_repabs_trm: Proof.context -> term * term -> term
   329 
   332 
   330 fun equiv_relation_chk ctxt (rty, qty) =
   333 fun equiv_relation_chk ctxt (rty, qty) =
   331   equiv_relation ctxt (rty, qty)
   334   equiv_relation ctxt (rty, qty)
   332   |> Syntax.check_term ctxt
   335   |> Syntax.check_term ctxt
   333 
   336 
       
   337 (* generation of the Quotient theorem  *)
       
   338 
       
   339 fun get_quot_thm ctxt s =
       
   340   let
       
   341     val thy = Proof_Context.theory_of ctxt
       
   342   in
       
   343     (case Quotient_Info.lookup_quotients_global thy s of
       
   344       SOME qdata => #quot_thm qdata
       
   345     | NONE => raise LIFT_MATCH ("No quotient type " ^ quote s ^ " found."))
       
   346   end
       
   347 
       
   348 fun get_rel_quot_thm thy s =
       
   349   (case Quotient_Info.lookup_quotmaps thy s of
       
   350     SOME map_data => #quot_thm map_data
       
   351   | NONE => raise LIFT_MATCH ("get_relmap (no relation map function found for type " ^ s ^ ")"));
       
   352 
       
   353 fun is_id_quot thm = (prop_of thm = prop_of @{thm identity_quotient})
       
   354 
       
   355 infix 0 MRSL
       
   356 
       
   357 fun ants MRSL thm = fold (fn rl => fn thm => rl RS thm) ants thm
       
   358 
       
   359 exception NOT_IMPL of string
       
   360 
       
   361 fun get_rel_from_quot_thm quot_thm = 
       
   362   let
       
   363     val (_ $ rel $ _ $ _) = (HOLogic.dest_Trueprop o prop_of) quot_thm
       
   364   in
       
   365     rel
       
   366   end
       
   367 
       
   368 fun mk_quot_thm_compose (rel_quot_thm, quot_thm) = 
       
   369   let
       
   370     val quot_thm_rel = get_rel_from_quot_thm quot_thm
       
   371   in
       
   372     if is_eq quot_thm_rel then [rel_quot_thm, quot_thm] MRSL @{thm OOO_eq_quotient}
       
   373     else raise NOT_IMPL "nested quotients: not implemented yet"
       
   374   end
       
   375 
       
   376 fun prove_quot_theorem ctxt (rty, qty) =
       
   377   if rty = qty
       
   378   then @{thm identity_quotient}
       
   379   else
       
   380     case (rty, qty) of
       
   381       (Type (s, tys), Type (s', tys')) =>
       
   382         if s = s'
       
   383         then
       
   384           let
       
   385             val args = map (prove_quot_theorem ctxt) (tys ~~ tys')
       
   386           in
       
   387             args MRSL (get_rel_quot_thm ctxt s)
       
   388           end
       
   389         else
       
   390           let
       
   391             val (Type (_, rtys), qty_pat) = get_rty_qty ctxt s'
       
   392             val qtyenv = match ctxt equiv_match_err qty_pat qty
       
   393             val rtys' = map (Envir.subst_type qtyenv) rtys
       
   394             val args = map (prove_quot_theorem ctxt) (tys ~~ rtys')
       
   395             val quot_thm = get_quot_thm ctxt s'
       
   396           in
       
   397             if forall is_id_quot args
       
   398             then
       
   399               quot_thm
       
   400             else
       
   401               let
       
   402                 val rel_quot_thm = args MRSL (get_rel_quot_thm ctxt s)
       
   403               in
       
   404                 mk_quot_thm_compose (rel_quot_thm, quot_thm)
       
   405              end
       
   406           end
       
   407     | _ => @{thm identity_quotient}
       
   408 
   334 
   409 
   335 
   410 
   336 (*** Regularization ***)
   411 (*** Regularization ***)
   337 
   412 
   338 (* Regularizing an rtrm means:
   413 (* Regularizing an rtrm means: