src/Pure/thm.ML
changeset 70156 5d8833499c4a
parent 70153 8a23083ac011
child 70159 57503fe1b0ff
equal deleted inserted replaced
70155:169d167554bd 70156:5d8833499c4a
    24   val typ_of: ctyp -> typ
    24   val typ_of: ctyp -> typ
    25   val global_ctyp_of: theory -> typ -> ctyp
    25   val global_ctyp_of: theory -> typ -> ctyp
    26   val ctyp_of: Proof.context -> typ -> ctyp
    26   val ctyp_of: Proof.context -> typ -> ctyp
    27   val dest_ctyp: ctyp -> ctyp list
    27   val dest_ctyp: ctyp -> ctyp list
    28   val dest_ctyp_nth: int -> ctyp -> ctyp
    28   val dest_ctyp_nth: int -> ctyp -> ctyp
       
    29   val make_ctyp: ctyp -> ctyp list -> ctyp
    29   (*certified terms*)
    30   (*certified terms*)
    30   val term_of: cterm -> term
    31   val term_of: cterm -> term
    31   val typ_of_cterm: cterm -> typ
    32   val typ_of_cterm: cterm -> typ
    32   val ctyp_of_cterm: cterm -> ctyp
    33   val ctyp_of_cterm: cterm -> ctyp
    33   val maxidx_of_cterm: cterm -> int
    34   val maxidx_of_cterm: cterm -> int
    79   val theory_of_cterm: cterm -> theory
    80   val theory_of_cterm: cterm -> theory
    80   val theory_of_thm: thm -> theory
    81   val theory_of_thm: thm -> theory
    81   val trim_context_ctyp: ctyp -> ctyp
    82   val trim_context_ctyp: ctyp -> ctyp
    82   val trim_context_cterm: cterm -> cterm
    83   val trim_context_cterm: cterm -> cterm
    83   val trim_context: thm -> thm
    84   val trim_context: thm -> thm
       
    85   val transfer_ctyp: theory -> ctyp -> ctyp
    84   val transfer_cterm: theory -> cterm -> cterm
    86   val transfer_cterm: theory -> cterm -> cterm
    85   val transfer: theory -> thm -> thm
    87   val transfer: theory -> thm -> thm
    86   val transfer': Proof.context -> thm -> thm
    88   val transfer': Proof.context -> thm -> thm
    87   val transfer'': Context.generic -> thm -> thm
    89   val transfer'': Context.generic -> thm -> thm
    88   val renamed_prop: term -> thm -> thm
    90   val renamed_prop: term -> thm -> thm
   182         Ctyp {cert = cert, T = nth Ts i handle General.Subscript => err (),
   184         Ctyp {cert = cert, T = nth Ts i handle General.Subscript => err (),
   183           maxidx = maxidx, sorts = sorts}
   185           maxidx = maxidx, sorts = sorts}
   184     | _ => err ())
   186     | _ => err ())
   185   end;
   187   end;
   186 
   188 
       
   189 fun join_certificate_ctyp (Ctyp {cert, ...}) cert0 = Context.join_certificate (cert0, cert);
       
   190 fun union_sorts_ctyp (Ctyp {sorts, ...}) sorts0 = Sorts.union sorts0 sorts;
       
   191 fun maxidx_ctyp (Ctyp {maxidx, ...}) maxidx0 = Int.max (maxidx0, maxidx);
       
   192 
       
   193 fun make_ctyp (Ctyp {cert, T, maxidx = _, sorts = _}) cargs =
       
   194   let
       
   195     val As = map typ_of cargs;
       
   196     fun err () = raise TYPE ("make_ctyp", T :: As, []);
       
   197   in
       
   198     (case T of
       
   199       Type (a, args) =>
       
   200         Ctyp {
       
   201           cert = fold join_certificate_ctyp cargs cert,
       
   202           maxidx = fold maxidx_ctyp cargs ~1,
       
   203           sorts = fold union_sorts_ctyp cargs [],
       
   204           T = if length args = length cargs then Type (a, As) else err ()}
       
   205     | _ => err ())
       
   206   end;
       
   207 
   187 
   208 
   188 
   209 
   189 (** certified terms **)
   210 (** certified terms **)
   190 
   211 
   191 (*certified terms with checked typ, maxidx, and sorts*)
   212 (*certified terms with checked typ, maxidx, and sorts*)
   451     Thm (_, {cert = Context.Certificate_Id _, ...}) => th
   472     Thm (_, {cert = Context.Certificate_Id _, ...}) => th
   452   | Thm (der, {cert = Context.Certificate thy, tags, maxidx, shyps, hyps, tpairs, prop}) =>
   473   | Thm (der, {cert = Context.Certificate thy, tags, maxidx, shyps, hyps, tpairs, prop}) =>
   453       Thm (der,
   474       Thm (der,
   454        {cert = Context.Certificate_Id (Context.theory_id thy),
   475        {cert = Context.Certificate_Id (Context.theory_id thy),
   455         tags = tags, maxidx = maxidx, shyps = shyps, hyps = hyps, tpairs = tpairs, prop = prop}));
   476         tags = tags, maxidx = maxidx, shyps = shyps, hyps = hyps, tpairs = tpairs, prop = prop}));
       
   477 
       
   478 fun transfer_ctyp thy' cT =
       
   479   let
       
   480     val Ctyp {cert, T, maxidx, sorts} = cT;
       
   481     val _ =
       
   482       Context.subthy_id (Context.certificate_theory_id cert, Context.theory_id thy') orelse
       
   483         raise CONTEXT ("Cannot transfer: not a super theory", [cT], [], [],
       
   484           SOME (Context.Theory thy'));
       
   485     val cert' = Context.join_certificate (Context.Certificate thy', cert);
       
   486   in
       
   487     if Context.eq_certificate (cert, cert') then cT
       
   488     else Ctyp {cert = cert', T = T, maxidx = maxidx, sorts = sorts}
       
   489   end;
   456 
   490 
   457 fun transfer_cterm thy' ct =
   491 fun transfer_cterm thy' ct =
   458   let
   492   let
   459     val Cterm {cert, t, T, maxidx, sorts} = ct;
   493     val Cterm {cert, t, T, maxidx, sorts} = ct;
   460     val _ =
   494     val _ =