src/HOL/Tools/Lifting/lifting_term.ML
changeset 47852 0c3b8d036a5c
parent 47778 7bcdaa255a00
child 47853 c01ba36769f5
equal deleted inserted replaced
47851:dad2140c2a15 47852:0c3b8d036a5c
     9   exception QUOT_THM of typ * typ * Pretty.T
     9   exception QUOT_THM of typ * typ * Pretty.T
    10   exception CHECK_RTY of typ * typ
    10   exception CHECK_RTY of typ * typ
    11 
    11 
    12   val prove_quot_thm: Proof.context -> typ * typ -> thm
    12   val prove_quot_thm: Proof.context -> typ * typ -> thm
    13 
    13 
    14   val absrep_fun: Proof.context -> typ * typ -> term
    14   val abs_fun: Proof.context -> typ * typ -> term
    15 
       
    16   (* Allows Nitpick to represent quotient types as single elements from raw type *)
       
    17   (* val absrep_const_chk: Proof.context -> flag -> string -> term *)
       
    18 
    15 
    19   val equiv_relation: Proof.context -> typ * typ -> term
    16   val equiv_relation: Proof.context -> typ * typ -> term
    20 
    17 
    21   val quot_thm_rel: thm -> term
    18   val quot_thm_rel: thm -> term
    22   val quot_thm_abs: thm -> term
    19   val quot_thm_abs: thm -> term
    29 
    26 
    30 open Lifting_Util
    27 open Lifting_Util
    31 
    28 
    32 infix 0 MRSL
    29 infix 0 MRSL
    33 
    30 
    34 (* generation of the Quotient theorem  *)
       
    35 
       
    36 exception QUOT_THM_INTERNAL of Pretty.T
    31 exception QUOT_THM_INTERNAL of Pretty.T
    37 exception QUOT_THM of typ * typ * Pretty.T
    32 exception QUOT_THM of typ * typ * Pretty.T
    38 exception CHECK_RTY of typ * typ
    33 exception CHECK_RTY of typ * typ
    39 
    34 
    40 (* matches a type pattern with a type *)
       
    41 fun match ctxt err ty_pat ty =
    35 fun match ctxt err ty_pat ty =
    42   let
    36   let
    43     val thy = Proof_Context.theory_of ctxt
    37     val thy = Proof_Context.theory_of ctxt
    44   in
    38   in
    45     Sign.typ_match thy (ty_pat, ty) Vartab.empty
    39     Sign.typ_match thy (ty_pat, ty) Vartab.empty
    82        Pretty.brk 1,
    76        Pretty.brk 1,
    83        Pretty.str "found."]))
    77        Pretty.str "found."]))
    84   end
    78   end
    85 
    79 
    86 fun is_id_quot thm = (prop_of thm = prop_of @{thm identity_quotient})
    80 fun is_id_quot thm = (prop_of thm = prop_of @{thm identity_quotient})
       
    81 
       
    82 (*
       
    83   quot_thm_rel, quot_thm_abs, quot_thm_rep and quot_thm_rty_qty - simple functions
       
    84     for destructing quotient theorems (Quotient R Abs Rep T).
       
    85 *)
    87 
    86 
    88 fun quot_thm_rel quot_thm =
    87 fun quot_thm_rel quot_thm =
    89   case (dest_Quotient o HOLogic.dest_Trueprop o prop_of) quot_thm of
    88   case (dest_Quotient o HOLogic.dest_Trueprop o prop_of) quot_thm of
    90     (rel, _, _, _) => rel
    89     (rel, _, _, _) => rel
    91 
    90 
   240       handle Type.TYPE_MATCH => raise CHECK_RTY (rty_schematic, rty_forced)
   239       handle Type.TYPE_MATCH => raise CHECK_RTY (rty_schematic, rty_forced)
   241   in
   240   in
   242     ()
   241     ()
   243   end
   242   end
   244 
   243 
       
   244 (*
       
   245   The function tries to prove that rty and qty form a quotient.
       
   246 
       
   247   Returns: Quotient theorem; an abstract type of the theorem is exactly
       
   248     qty, a representation type of the theorem is an instance of rty in general.
       
   249 *)
       
   250 
   245 fun prove_quot_thm ctxt (rty, qty) =
   251 fun prove_quot_thm ctxt (rty, qty) =
   246   let
   252   let
   247     val thy = Proof_Context.theory_of ctxt
   253     val thy = Proof_Context.theory_of ctxt
   248     val schematic_quot_thm = prove_schematic_quot_thm ctxt (rty, qty)
   254     val schematic_quot_thm = prove_schematic_quot_thm ctxt (rty, qty)
   249     val quot_thm = force_qty_type thy qty schematic_quot_thm
   255     val quot_thm = force_qty_type thy qty schematic_quot_thm
   250     val _ = check_rty_type ctxt rty quot_thm
   256     val _ = check_rty_type ctxt rty quot_thm
   251   in
   257   in
   252     quot_thm
   258     quot_thm
   253   end
   259   end
   254 
   260 
   255 fun absrep_fun ctxt (rty, qty) =
   261 fun abs_fun ctxt (rty, qty) =
   256   quot_thm_abs (prove_quot_thm ctxt (rty, qty))
   262   quot_thm_abs (prove_quot_thm ctxt (rty, qty))
   257 
   263 
   258 fun equiv_relation ctxt (rty, qty) =
   264 fun equiv_relation ctxt (rty, qty) =
   259   quot_thm_rel (prove_quot_thm ctxt (rty, qty))
   265   quot_thm_rel (prove_quot_thm ctxt (rty, qty))
   260 
   266