Thm.cterm_of and Thm.ctyp_of operate on local context;
authorwenzelm
Fri Mar 06 15:58:56 2015 +0100 (2015-03-06)
changeset 59621291934bac95e
parent 59620 92d7d8e4f1bf
child 59622 deae170e24a6
Thm.cterm_of and Thm.ctyp_of operate on local context;
NEWS
src/Doc/Implementation/Logic.thy
src/FOLP/simp.ML
src/HOL/Decision_Procs/Approximation.thy
src/HOL/Decision_Procs/Cooper.thy
src/HOL/Decision_Procs/Ferrack.thy
src/HOL/Decision_Procs/MIR.thy
src/HOL/Decision_Procs/Parametric_Ferrante_Rackoff.thy
src/HOL/Decision_Procs/approximation.ML
src/HOL/Decision_Procs/approximation_generator.ML
src/HOL/Decision_Procs/commutative_ring_tac.ML
src/HOL/Decision_Procs/cooper_tac.ML
src/HOL/Decision_Procs/ferrack_tac.ML
src/HOL/Decision_Procs/mir_tac.ML
src/HOL/HOL.thy
src/HOL/HOLCF/Tools/Domain/domain_constructors.ML
src/HOL/HOLCF/Tools/cont_proc.ML
src/HOL/HOLCF/Tools/fixrec.ML
src/HOL/Import/import_rule.ML
src/HOL/Library/Code_Abstract_Nat.thy
src/HOL/Library/Countable.thy
src/HOL/Library/Old_SMT/old_smt_normalize.ML
src/HOL/Library/Old_SMT/old_smt_real.ML
src/HOL/Library/Old_SMT/old_smt_solver.ML
src/HOL/Library/Old_SMT/old_smt_utils.ML
src/HOL/Library/Old_SMT/old_z3_interface.ML
src/HOL/Library/Old_SMT/old_z3_proof_literals.ML
src/HOL/Library/Old_SMT/old_z3_proof_methods.ML
src/HOL/Library/Old_SMT/old_z3_proof_parser.ML
src/HOL/Library/Old_SMT/old_z3_proof_reconstruction.ML
src/HOL/Library/Old_SMT/old_z3_proof_tools.ML
src/HOL/Library/Sum_of_Squares/positivstellensatz_tools.ML
src/HOL/Library/simps_case_conv.ML
src/HOL/Matrix_LP/Compute_Oracle/compute.ML
src/HOL/Matrix_LP/Compute_Oracle/linker.ML
src/HOL/Multivariate_Analysis/normarith.ML
src/HOL/Mutabelle/mutabelle_extra.ML
src/HOL/NSA/transfer.ML
src/HOL/Nominal/nominal_datatype.ML
src/HOL/Nominal/nominal_fresh_fun.ML
src/HOL/Nominal/nominal_induct.ML
src/HOL/Nominal/nominal_inductive.ML
src/HOL/Nominal/nominal_inductive2.ML
src/HOL/Nominal/nominal_permeq.ML
src/HOL/Nominal/nominal_primrec.ML
src/HOL/Nominal/nominal_thmdecls.ML
src/HOL/Num.thy
src/HOL/Probability/measurable.ML
src/HOL/Proofs/Lambda/WeakNorm.thy
src/HOL/Statespace/distinct_tree_prover.ML
src/HOL/Statespace/state_fun.ML
src/HOL/String.thy
src/HOL/TPTP/TPTP_Parser/tptp_reconstruct_library.ML
src/HOL/TPTP/TPTP_Proof_Reconstruction.thy
src/HOL/Tools/ATP/atp_problem_generate.ML
src/HOL/Tools/ATP/atp_util.ML
src/HOL/Tools/BNF/bnf_def.ML
src/HOL/Tools/BNF/bnf_fp_def_sugar.ML
src/HOL/Tools/BNF/bnf_fp_def_sugar_tactics.ML
src/HOL/Tools/BNF/bnf_fp_n2m.ML
src/HOL/Tools/BNF/bnf_fp_rec_sugar_transfer.ML
src/HOL/Tools/BNF/bnf_fp_util.ML
src/HOL/Tools/BNF/bnf_gfp.ML
src/HOL/Tools/BNF/bnf_gfp_rec_sugar_tactics.ML
src/HOL/Tools/BNF/bnf_lfp.ML
src/HOL/Tools/BNF/bnf_lfp_size.ML
src/HOL/Tools/Ctr_Sugar/ctr_sugar.ML
src/HOL/Tools/Ctr_Sugar/ctr_sugar_code.ML
src/HOL/Tools/Ctr_Sugar/ctr_sugar_util.ML
src/HOL/Tools/Function/fun_cases.ML
src/HOL/Tools/Function/function_common.ML
src/HOL/Tools/Function/function_context_tree.ML
src/HOL/Tools/Function/function_core.ML
src/HOL/Tools/Function/function_elims.ML
src/HOL/Tools/Function/function_lib.ML
src/HOL/Tools/Function/induction_schema.ML
src/HOL/Tools/Function/lexicographic_order.ML
src/HOL/Tools/Function/measure_functions.ML
src/HOL/Tools/Function/mutual.ML
src/HOL/Tools/Function/partial_function.ML
src/HOL/Tools/Function/pat_completeness.ML
src/HOL/Tools/Function/relation.ML
src/HOL/Tools/Function/scnp_reconstruct.ML
src/HOL/Tools/Function/termination.ML
src/HOL/Tools/Lifting/lifting_bnf.ML
src/HOL/Tools/Lifting/lifting_def.ML
src/HOL/Tools/Lifting/lifting_setup.ML
src/HOL/Tools/Lifting/lifting_term.ML
src/HOL/Tools/Meson/meson.ML
src/HOL/Tools/Meson/meson_clausify.ML
src/HOL/Tools/Metis/metis_reconstruct.ML
src/HOL/Tools/Metis/metis_tactic.ML
src/HOL/Tools/Nitpick/nitpick_hol.ML
src/HOL/Tools/Nitpick/nitpick_model.ML
src/HOL/Tools/Old_Datatype/old_datatype.ML
src/HOL/Tools/Old_Datatype/old_datatype_aux.ML
src/HOL/Tools/Old_Datatype/old_rep_datatype.ML
src/HOL/Tools/Predicate_Compile/core_data.ML
src/HOL/Tools/Predicate_Compile/predicate_compile_aux.ML
src/HOL/Tools/Predicate_Compile/predicate_compile_pred.ML
src/HOL/Tools/Qelim/cooper.ML
src/HOL/Tools/Quickcheck/narrowing_generators.ML
src/HOL/Tools/Quickcheck/random_generators.ML
src/HOL/Tools/Quotient/quotient_def.ML
src/HOL/Tools/Quotient/quotient_tacs.ML
src/HOL/Tools/SMT/smt_normalize.ML
src/HOL/Tools/SMT/smt_real.ML
src/HOL/Tools/SMT/smt_solver.ML
src/HOL/Tools/SMT/smt_util.ML
src/HOL/Tools/SMT/z3_interface.ML
src/HOL/Tools/SMT/z3_replay.ML
src/HOL/Tools/SMT/z3_replay_methods.ML
src/HOL/Tools/Sledgehammer/sledgehammer_mash.ML
src/HOL/Tools/TFL/casesplit.ML
src/HOL/Tools/TFL/dcterm.ML
src/HOL/Tools/TFL/post.ML
src/HOL/Tools/TFL/rules.ML
src/HOL/Tools/TFL/thry.ML
src/HOL/Tools/Transfer/transfer.ML
src/HOL/Tools/Transfer/transfer_bnf.ML
src/HOL/Tools/choice_specification.ML
src/HOL/Tools/cnf.ML
src/HOL/Tools/code_evaluation.ML
src/HOL/Tools/coinduction.ML
src/HOL/Tools/datatype_realizer.ML
src/HOL/Tools/inductive.ML
src/HOL/Tools/inductive_set.ML
src/HOL/Tools/int_arith.ML
src/HOL/Tools/legacy_transfer.ML
src/HOL/Tools/lin_arith.ML
src/HOL/Tools/monomorph.ML
src/HOL/Tools/numeral.ML
src/HOL/Tools/numeral_simprocs.ML
src/HOL/Tools/record.ML
src/HOL/Tools/reification.ML
src/HOL/Tools/sat.ML
src/HOL/Tools/set_comprehension_pointfree.ML
src/HOL/Tools/split_rule.ML
src/HOL/Word/WordBitwise.thy
src/HOL/ex/Iff_Oracle.thy
src/HOL/ex/SAT_Examples.thy
src/HOL/ex/SVC_Oracle.thy
src/Provers/Arith/fast_lin_arith.ML
src/Provers/hypsubst.ML
src/Provers/splitter.ML
src/Provers/trancl.ML
src/Pure/Isar/class_declaration.ML
src/Pure/Isar/code.ML
src/Pure/Isar/element.ML
src/Pure/Isar/expression.ML
src/Pure/Isar/generic_target.ML
src/Pure/Isar/local_defs.ML
src/Pure/Isar/obtain.ML
src/Pure/Isar/proof.ML
src/Pure/Isar/proof_context.ML
src/Pure/Isar/spec_rules.ML
src/Pure/ML/ml_antiquotations.ML
src/Pure/Proof/proof_checker.ML
src/Pure/Proof/proof_syntax.ML
src/Pure/Tools/rule_insts.ML
src/Pure/axclass.ML
src/Pure/conjunction.ML
src/Pure/drule.ML
src/Pure/goal.ML
src/Pure/more_thm.ML
src/Pure/raw_simplifier.ML
src/Pure/simplifier.ML
src/Pure/skip_proof.ML
src/Pure/subgoal.ML
src/Pure/thm.ML
src/Pure/variable.ML
src/Tools/Code/code_preproc.ML
src/Tools/Code/code_runtime.ML
src/Tools/Code/code_simp.ML
src/Tools/Code/code_thingol.ML
src/Tools/IsaPlanner/isand.ML
src/Tools/IsaPlanner/rw_inst.ML
src/Tools/atomize_elim.ML
src/Tools/coherent.ML
src/Tools/cong_tac.ML
src/Tools/eqsubst.ML
src/Tools/induct.ML
src/Tools/misc_legacy.ML
src/Tools/nbe.ML
src/ZF/Tools/cartprod.ML
src/ZF/Tools/ind_cases.ML
src/ZF/Tools/inductive_package.ML
     1.1 --- a/NEWS	Fri Mar 06 14:01:08 2015 +0100
     1.2 +++ b/NEWS	Fri Mar 06 15:58:56 2015 +0100
     1.3 @@ -263,6 +263,11 @@
     1.4  
     1.5  *** ML ***
     1.6  
     1.7 +* The main operations to certify logical entities are Thm.ctyp_of and
     1.8 +Thm.cterm_of with a local context; old-style global theory variants are
     1.9 +available as Thm.global_ctyp_of and Thm.global_cterm_of.
    1.10 +INCOMPATIBILITY.
    1.11 +
    1.12  * Elementary operations in module Thm are no longer pervasive.
    1.13  INCOMPATIBILITY, need to use qualified Thm.prop_of, Thm.cterm_of,
    1.14  Thm.term_of etc.
     2.1 --- a/src/Doc/Implementation/Logic.thy	Fri Mar 06 14:01:08 2015 +0100
     2.2 +++ b/src/Doc/Implementation/Logic.thy	Fri Mar 06 15:58:56 2015 +0100
     2.3 @@ -639,8 +639,8 @@
     2.4    \begin{mldecls}
     2.5    @{index_ML_type ctyp} \\
     2.6    @{index_ML_type cterm} \\
     2.7 -  @{index_ML Thm.ctyp_of: "theory -> typ -> ctyp"} \\
     2.8 -  @{index_ML Thm.cterm_of: "theory -> term -> cterm"} \\
     2.9 +  @{index_ML Thm.ctyp_of: "Proof.context -> typ -> ctyp"} \\
    2.10 +  @{index_ML Thm.cterm_of: "Proof.context -> term -> cterm"} \\
    2.11    @{index_ML Thm.apply: "cterm -> cterm -> cterm"} \\
    2.12    @{index_ML Thm.lambda: "cterm -> cterm -> cterm"} \\
    2.13    @{index_ML Thm.all: "cterm -> cterm -> cterm"} \\
    2.14 @@ -699,10 +699,11 @@
    2.15    are located in the @{ML_structure Thm} module, even though theorems are
    2.16    not yet involved at that stage.
    2.17  
    2.18 -  \item @{ML Thm.ctyp_of}~@{text "thy \<tau>"} and @{ML
    2.19 -  Thm.cterm_of}~@{text "thy t"} explicitly checks types and terms,
    2.20 +  \item @{ML Thm.ctyp_of}~@{text "ctxt \<tau>"} and @{ML
    2.21 +  Thm.cterm_of}~@{text "ctxt t"} explicitly check types and terms,
    2.22    respectively.  This also involves some basic normalizations, such
    2.23 -  expansion of type and term abbreviations from the theory context.
    2.24 +  expansion of type and term abbreviations from the underlying
    2.25 +  theory context.
    2.26    Full re-certification is relatively slow and should be avoided in
    2.27    tight reasoning loops.
    2.28  
     3.1 --- a/src/FOLP/simp.ML	Fri Mar 06 14:01:08 2015 +0100
     3.2 +++ b/src/FOLP/simp.ML	Fri Mar 06 15:58:56 2015 +0100
     3.3 @@ -436,7 +436,7 @@
     3.4        are represented by rules, generalized over their parameters*)
     3.5  fun add_asms(ss,thm,a,anet,ats,cs) =
     3.6      let val As = strip_varify(nth_subgoal i thm, a, []);
     3.7 -        val thms = map (Thm.trivial o Thm.cterm_of(Thm.theory_of_thm thm)) As;
     3.8 +        val thms = map (Thm.trivial o Thm.global_cterm_of(Thm.theory_of_thm thm)) As;
     3.9          val new_rws = maps mk_rew_rules thms;
    3.10          val rwrls = map mk_trans (maps mk_rew_rules thms);
    3.11          val anet' = fold_rev lhs_insert_thm rwrls anet;
    3.12 @@ -559,12 +559,12 @@
    3.13  fun mk_cong sg (f,aTs,rT) (refl,eq) =
    3.14  let val k = length aTs;
    3.15      fun ri((subst,va as Var(_,Ta),vb as Var(_,Tb),P),i,si,T,yik) =
    3.16 -        let val ca = Thm.cterm_of sg va
    3.17 -            and cx = Thm.cterm_of sg (eta_Var(("X"^si,0),T))
    3.18 -            val cb = Thm.cterm_of sg vb
    3.19 -            and cy = Thm.cterm_of sg (eta_Var(("Y"^si,0),T))
    3.20 -            val cP = Thm.cterm_of sg P
    3.21 -            and cp = Thm.cterm_of sg (Pinst(f,rT,eq,k,i,T,yik,aTs))
    3.22 +        let val ca = Thm.global_cterm_of sg va
    3.23 +            and cx = Thm.global_cterm_of sg (eta_Var(("X"^si,0),T))
    3.24 +            val cb = Thm.global_cterm_of sg vb
    3.25 +            and cy = Thm.global_cterm_of sg (eta_Var(("Y"^si,0),T))
    3.26 +            val cP = Thm.global_cterm_of sg P
    3.27 +            and cp = Thm.global_cterm_of sg (Pinst(f,rT,eq,k,i,T,yik,aTs))
    3.28          in cterm_instantiate [(ca,cx),(cb,cy),(cP,cp)] subst end;
    3.29      fun mk(c,T::Ts,i,yik) =
    3.30          let val si = radixstring(26,"a",i)
     4.1 --- a/src/HOL/Decision_Procs/Approximation.thy	Fri Mar 06 14:01:08 2015 +0100
     4.2 +++ b/src/HOL/Decision_Procs/Approximation.thy	Fri Mar 06 15:58:56 2015 +0100
     4.3 @@ -3582,7 +3582,7 @@
     4.4  
     4.5    val normalize = eval o Envir.beta_norm o Envir.eta_long [];
     4.6  
     4.7 -in Thm.cterm_of thy (Logic.mk_equals (t, normalize t)) end
     4.8 +in Thm.global_cterm_of thy (Logic.mk_equals (t, normalize t)) end
     4.9  *}
    4.10  
    4.11  ML {*
    4.12 @@ -3641,16 +3641,16 @@
    4.13                 |> HOLogic.dest_list
    4.14        val p = prec
    4.15                |> HOLogic.mk_number @{typ nat}
    4.16 -              |> Proof_Context.cterm_of ctxt
    4.17 +              |> Thm.cterm_of ctxt
    4.18      in case taylor
    4.19      of NONE => let
    4.20           val n = vs |> length
    4.21                   |> HOLogic.mk_number @{typ nat}
    4.22 -                 |> Proof_Context.cterm_of ctxt
    4.23 +                 |> Thm.cterm_of ctxt
    4.24           val s = vs
    4.25                   |> map lookup_splitting
    4.26                   |> HOLogic.mk_list @{typ nat}
    4.27 -                 |> Proof_Context.cterm_of ctxt
    4.28 +                 |> Thm.cterm_of ctxt
    4.29         in
    4.30           (rtac (Thm.instantiate ([], [(@{cpat "?n::nat"}, n),
    4.31                                       (@{cpat "?prec::nat"}, p),
    4.32 @@ -3665,9 +3665,9 @@
    4.33         else let
    4.34           val t = t
    4.35                |> HOLogic.mk_number @{typ nat}
    4.36 -              |> Proof_Context.cterm_of ctxt
    4.37 +              |> Thm.cterm_of ctxt
    4.38           val s = vs |> map lookup_splitting |> hd
    4.39 -              |> Proof_Context.cterm_of ctxt
    4.40 +              |> Thm.cterm_of ctxt
    4.41         in
    4.42           rtac (Thm.instantiate ([], [(@{cpat "?s::nat"}, s),
    4.43                                       (@{cpat "?t::nat"}, t),
     5.1 --- a/src/HOL/Decision_Procs/Cooper.thy	Fri Mar 06 14:01:08 2015 +0100
     5.2 +++ b/src/HOL/Decision_Procs/Cooper.thy	Fri Mar 06 15:58:56 2015 +0100
     5.3 @@ -2649,7 +2649,7 @@
     5.4        val vs = map_index swap fs;
     5.5        val ps = map_index swap bs;
     5.6        val t' = (term_of_fm ps vs o @{code pa} o fm_of_term ps vs) t;
     5.7 -    in Thm.cterm_of thy (HOLogic.mk_Trueprop (HOLogic.mk_eq (t, t'))) end
     5.8 +    in Thm.global_cterm_of thy (HOLogic.mk_Trueprop (HOLogic.mk_eq (t, t'))) end
     5.9  end;
    5.10  *}
    5.11  
     6.1 --- a/src/HOL/Decision_Procs/Ferrack.thy	Fri Mar 06 14:01:08 2015 +0100
     6.2 +++ b/src/HOL/Decision_Procs/Ferrack.thy	Fri Mar 06 15:58:56 2015 +0100
     6.3 @@ -1999,7 +1999,7 @@
     6.4    let 
     6.5      val vs = Term.add_frees t [];
     6.6      val t' = (term_of_fm vs o @{code linrqe} o fm_of_term vs) t;
     6.7 -  in (Proof_Context.cterm_of ctxt o HOLogic.mk_Trueprop o HOLogic.mk_eq) (t, t') end
     6.8 +  in (Thm.cterm_of ctxt o HOLogic.mk_Trueprop o HOLogic.mk_eq) (t, t') end
     6.9  end;
    6.10  *}
    6.11  
     7.1 --- a/src/HOL/Decision_Procs/MIR.thy	Fri Mar 06 14:01:08 2015 +0100
     7.2 +++ b/src/HOL/Decision_Procs/MIR.thy	Fri Mar 06 15:58:56 2015 +0100
     7.3 @@ -5655,7 +5655,7 @@
     7.4      val vs = map_index swap fs;
     7.5      val qe = if proofs then @{code mirlfrqe} else @{code mircfrqe};
     7.6      val t' = (term_of_fm vs o qe o fm_of_term vs) t;
     7.7 -  in (Thm.cterm_of thy o HOLogic.mk_Trueprop o HOLogic.mk_eq) (t, t') end
     7.8 +  in (Thm.global_cterm_of thy o HOLogic.mk_Trueprop o HOLogic.mk_eq) (t, t') end
     7.9  end;
    7.10  *}
    7.11  
     8.1 --- a/src/HOL/Decision_Procs/Parametric_Ferrante_Rackoff.thy	Fri Mar 06 14:01:08 2015 +0100
     8.2 +++ b/src/HOL/Decision_Procs/Parametric_Ferrante_Rackoff.thy	Fri Mar 06 15:58:56 2015 +0100
     8.3 @@ -4155,7 +4155,7 @@
     8.4  in
     8.5  
     8.6    fn (ctxt, alternative, ty, ps, ct) =>
     8.7 -    Proof_Context.cterm_of ctxt
     8.8 +    Thm.cterm_of ctxt
     8.9        (frpar_procedure alternative ty ps (Thm.term_of ct))
    8.10  
    8.11  end
     9.1 --- a/src/HOL/Decision_Procs/approximation.ML	Fri Mar 06 14:01:08 2015 +0100
     9.2 +++ b/src/HOL/Decision_Procs/approximation.ML	Fri Mar 06 15:58:56 2015 +0100
     9.3 @@ -92,7 +92,7 @@
     9.4    in t end
     9.5  
     9.6  fun apply_tactic ctxt term tactic =
     9.7 -  Proof_Context.cterm_of ctxt term
     9.8 +  Thm.cterm_of ctxt term
     9.9    |> Goal.init
    9.10    |> SINGLE tactic
    9.11    |> the |> Thm.prems_of |> hd
    9.12 @@ -120,7 +120,7 @@
    9.13           |> foldr1 HOLogic.mk_conj))
    9.14  
    9.15  fun approx_arith prec ctxt t = realify t
    9.16 -     |> Proof_Context.cterm_of ctxt
    9.17 +     |> Thm.cterm_of ctxt
    9.18       |> Reification.conv ctxt form_equations
    9.19       |> Thm.prop_of
    9.20       |> Logic.dest_equals |> snd
    10.1 --- a/src/HOL/Decision_Procs/approximation_generator.ML	Fri Mar 06 14:01:08 2015 +0100
    10.2 +++ b/src/HOL/Decision_Procs/approximation_generator.ML	Fri Mar 06 15:58:56 2015 +0100
    10.3 @@ -117,7 +117,7 @@
    10.4    }
    10.5  
    10.6  fun rewrite_with ctxt thms = Simplifier.rewrite (put_simpset HOL_basic_ss ctxt addsimps thms)
    10.7 -fun conv_term thy conv r = Thm.cterm_of thy r |> conv |> Thm.prop_of |> Logic.dest_equals |> snd
    10.8 +fun conv_term thy conv r = Thm.global_cterm_of thy r |> conv |> Thm.prop_of |> Logic.dest_equals |> snd
    10.9  
   10.10  fun approx_random ctxt prec eps frees e xs genuine_only size seed =
   10.11    let
    11.1 --- a/src/HOL/Decision_Procs/commutative_ring_tac.ML	Fri Mar 06 14:01:08 2015 +0100
    11.2 +++ b/src/HOL/Decision_Procs/commutative_ring_tac.ML	Fri Mar 06 15:58:56 2015 +0100
    11.3 @@ -78,10 +78,10 @@
    11.4          let
    11.5            val thy = Proof_Context.theory_of ctxt;
    11.6            val fs = Misc_Legacy.term_frees eq;
    11.7 -          val cvs = Thm.cterm_of thy (HOLogic.mk_list T fs);
    11.8 -          val clhs = Thm.cterm_of thy (reif_polex T fs lhs);
    11.9 -          val crhs = Thm.cterm_of thy (reif_polex T fs rhs);
   11.10 -          val ca = Thm.ctyp_of thy T;
   11.11 +          val cvs = Thm.global_cterm_of thy (HOLogic.mk_list T fs);
   11.12 +          val clhs = Thm.global_cterm_of thy (reif_polex T fs lhs);
   11.13 +          val crhs = Thm.global_cterm_of thy (reif_polex T fs rhs);
   11.14 +          val ca = Thm.global_ctyp_of thy T;
   11.15          in (ca, cvs, clhs, crhs) end
   11.16        else error ("reif_eq: not an equation over " ^ Syntax.string_of_sort ctxt cr_sort)
   11.17    | reif_eq _ _ = error "reif_eq: not an equation";
    12.1 --- a/src/HOL/Decision_Procs/cooper_tac.ML	Fri Mar 06 14:01:08 2015 +0100
    12.2 +++ b/src/HOL/Decision_Procs/cooper_tac.ML	Fri Mar 06 15:58:56 2015 +0100
    12.3 @@ -73,7 +73,7 @@
    12.4        |> fold Simplifier.add_cong @{thms conj_le_cong imp_le_cong}
    12.5      (* simp rules for elimination of abs *)
    12.6      val simpset3 = put_simpset HOL_basic_ss ctxt |> Splitter.add_split @{thm abs_split}
    12.7 -    val ct = Thm.cterm_of thy (HOLogic.mk_Trueprop t)
    12.8 +    val ct = Thm.global_cterm_of thy (HOLogic.mk_Trueprop t)
    12.9      (* Theorem for the nat --> int transformation *)
   12.10      val pre_thm = Seq.hd (EVERY
   12.11        [simp_tac mod_div_simpset 1, simp_tac simpset0 1,
   12.12 @@ -86,7 +86,7 @@
   12.13        (case Thm.prop_of pre_thm of
   12.14          Const (@{const_name Pure.imp}, _) $ (Const (@{const_name Trueprop}, _) $ t1) $ _ =>
   12.15            let
   12.16 -            val pth = linzqe_oracle (Thm.cterm_of thy (Envir.eta_long [] t1))
   12.17 +            val pth = linzqe_oracle (Thm.global_cterm_of thy (Envir.eta_long [] t1))
   12.18            in
   12.19              ((pth RS iffD2) RS pre_thm,
   12.20                assm_tac (i + 1) THEN (if q then I else TRY) (rtac TrueI i))
    13.1 --- a/src/HOL/Decision_Procs/ferrack_tac.ML	Fri Mar 06 14:01:08 2015 +0100
    13.2 +++ b/src/HOL/Decision_Procs/ferrack_tac.ML	Fri Mar 06 15:58:56 2015 +0100
    13.3 @@ -55,7 +55,7 @@
    13.4      val (t,np,nh) = prepare_for_linr q g
    13.5      (* Some simpsets for dealing with mod div abs and nat*)
    13.6      val simpset0 = put_simpset HOL_basic_ss ctxt addsimps comp_arith
    13.7 -    val ct = Thm.cterm_of thy (HOLogic.mk_Trueprop t)
    13.8 +    val ct = Thm.global_cterm_of thy (HOLogic.mk_Trueprop t)
    13.9      (* Theorem for the nat --> int transformation *)
   13.10     val pre_thm = Seq.hd (EVERY
   13.11        [simp_tac simpset0 1,
    14.1 --- a/src/HOL/Decision_Procs/mir_tac.ML	Fri Mar 06 14:01:08 2015 +0100
    14.2 +++ b/src/HOL/Decision_Procs/mir_tac.ML	Fri Mar 06 15:58:56 2015 +0100
    14.3 @@ -101,7 +101,7 @@
    14.4                  @{thm "int_0"}, @{thm "int_1"}]
    14.5        |> fold Simplifier.add_cong [@{thm "conj_le_cong"}, @{thm "imp_le_cong"}]
    14.6      (* simp rules for elimination of abs *)
    14.7 -    val ct = Thm.cterm_of thy (HOLogic.mk_Trueprop t)
    14.8 +    val ct = Thm.global_cterm_of thy (HOLogic.mk_Trueprop t)
    14.9      (* Theorem for the nat --> int transformation *)
   14.10      val pre_thm = Seq.hd (EVERY
   14.11        [simp_tac mod_div_simpset 1, simp_tac simpset0 1,
   14.12 @@ -116,8 +116,8 @@
   14.13      let val pth =
   14.14            (* If quick_and_dirty then run without proof generation as oracle*)
   14.15               if Config.get ctxt quick_and_dirty
   14.16 -             then mirfr_oracle (false, Thm.cterm_of thy (Envir.eta_long [] t1))
   14.17 -             else mirfr_oracle (true, Thm.cterm_of thy (Envir.eta_long [] t1))
   14.18 +             then mirfr_oracle (false, Thm.global_cterm_of thy (Envir.eta_long [] t1))
   14.19 +             else mirfr_oracle (true, Thm.global_cterm_of thy (Envir.eta_long [] t1))
   14.20      in 
   14.21         ((pth RS iffD2) RS pre_thm,
   14.22          assm_tac (i + 1) THEN (if q then I else TRY) (rtac TrueI i))
    15.1 --- a/src/HOL/HOL.thy	Fri Mar 06 14:01:08 2015 +0100
    15.2 +++ b/src/HOL/HOL.thy	Fri Mar 06 15:58:56 2015 +0100
    15.3 @@ -1194,13 +1194,13 @@
    15.4  let
    15.5    val (f_Let_unfold, x_Let_unfold) =
    15.6      let val [(_ $ (f $ x) $ _)] = Thm.prems_of @{thm Let_unfold}
    15.7 -    in (Thm.cterm_of @{theory} f, Thm.cterm_of @{theory} x) end
    15.8 +    in (Thm.global_cterm_of @{theory} f, Thm.global_cterm_of @{theory} x) end
    15.9    val (f_Let_folded, x_Let_folded) =
   15.10      let val [(_ $ (f $ x) $ _)] = Thm.prems_of @{thm Let_folded}
   15.11 -    in (Thm.cterm_of @{theory} f, Thm.cterm_of @{theory} x) end;
   15.12 +    in (Thm.global_cterm_of @{theory} f, Thm.global_cterm_of @{theory} x) end;
   15.13    val g_Let_folded =
   15.14      let val [(_ $ _ $ (g $ _))] = Thm.prems_of @{thm Let_folded}
   15.15 -    in Thm.cterm_of @{theory} g end;
   15.16 +    in Thm.global_cterm_of @{theory} g end;
   15.17    fun count_loose (Bound i) k = if i >= k then 1 else 0
   15.18      | count_loose (s $ t) k = count_loose s k + count_loose t k
   15.19      | count_loose (Abs (_, _, t)) k = count_loose  t (k + 1)
   15.20 @@ -1222,9 +1222,9 @@
   15.21        else
   15.22          let
   15.23            val n = case f of (Abs (x, _, _)) => x | _ => "x";
   15.24 -          val cx = Thm.cterm_of thy x;
   15.25 +          val cx = Thm.global_cterm_of thy x;
   15.26            val xT = Thm.typ_of_cterm cx;
   15.27 -          val cf = Thm.cterm_of thy f;
   15.28 +          val cf = Thm.global_cterm_of thy f;
   15.29            val fx_g = Simplifier.rewrite ctxt (Thm.apply cf cx);
   15.30            val (_ $ _ $ g) = Thm.prop_of fx_g;
   15.31            val g' = abstract_over (x,g);
   15.32 @@ -1238,10 +1238,10 @@
   15.33               else if (Envir.beta_eta_contract f) aconv (Envir.beta_eta_contract abs_g') then NONE (*avoid identity conversion*)
   15.34               else let
   15.35                     val g'x = abs_g'$x;
   15.36 -                   val g_g'x = Thm.symmetric (Thm.beta_conversion false (Thm.cterm_of thy g'x));
   15.37 +                   val g_g'x = Thm.symmetric (Thm.beta_conversion false (Thm.global_cterm_of thy g'x));
   15.38                     val rl = cterm_instantiate
   15.39 -                             [(f_Let_folded, Thm.cterm_of thy f), (x_Let_folded, cx),
   15.40 -                              (g_Let_folded, Thm.cterm_of thy abs_g')]
   15.41 +                             [(f_Let_folded, Thm.global_cterm_of thy f), (x_Let_folded, cx),
   15.42 +                              (g_Let_folded, Thm.global_cterm_of thy abs_g')]
   15.43                               @{thm Let_folded};
   15.44                   in SOME (rl OF [Thm.transitive fx_g g_g'x])
   15.45                   end)
    16.1 --- a/src/HOL/HOLCF/Tools/Domain/domain_constructors.ML	Fri Mar 06 14:01:08 2015 +0100
    16.2 +++ b/src/HOL/HOLCF/Tools/Domain/domain_constructors.ML	Fri Mar 06 15:58:56 2015 +0100
    16.3 @@ -211,7 +211,7 @@
    16.4              val (n1, t1) = args2typ n (snd con)
    16.5              val (n2, t2) = cons2typ n1 cons
    16.6            in (n2, mk_ssumT (t1, t2)) end
    16.7 -      val ct = Thm.ctyp_of thy (snd (cons2typ 1 spec'))
    16.8 +      val ct = Thm.global_ctyp_of thy (snd (cons2typ 1 spec'))
    16.9        val thm1 = instantiate' [SOME ct] [] @{thm exh_start}
   16.10        val thm2 = rewrite_rule (Proof_Context.init_global thy)
   16.11          (map mk_meta_eq @{thms ex_bottom_iffs}) thm1
    17.1 --- a/src/HOL/HOLCF/Tools/cont_proc.ML	Fri Mar 06 14:01:08 2015 +0100
    17.2 +++ b/src/HOL/HOLCF/Tools/cont_proc.ML	Fri Mar 06 15:58:56 2015 +0100
    17.3 @@ -122,7 +122,7 @@
    17.4    fun solve_cont ctxt t =
    17.5      let
    17.6        val thy = Proof_Context.theory_of ctxt
    17.7 -      val tr = instantiate' [] [SOME (Thm.cterm_of thy t)] @{thm Eq_TrueI}
    17.8 +      val tr = instantiate' [] [SOME (Thm.global_cterm_of thy t)] @{thm Eq_TrueI}
    17.9      in Option.map fst (Seq.pull (cont_tac ctxt 1 tr)) end
   17.10  in
   17.11    fun cont_proc thy =
    18.1 --- a/src/HOL/HOLCF/Tools/fixrec.ML	Fri Mar 06 14:01:08 2015 +0100
    18.2 +++ b/src/HOL/HOLCF/Tools/fixrec.ML	Fri Mar 06 15:58:56 2015 +0100
    18.3 @@ -153,7 +153,7 @@
    18.4      val P = Var (("P", 0), map Term.fastype_of lhss ---> HOLogic.boolT)
    18.5      val predicate = lambda_tuple lhss (list_comb (P, lhss))
    18.6      val tuple_induct_thm = (def_cont_fix_ind OF [tuple_fixdef_thm, cont_thm])
    18.7 -      |> Drule.instantiate' [] [SOME (Thm.cterm_of thy predicate)]
    18.8 +      |> Drule.instantiate' [] [SOME (Thm.global_cterm_of thy predicate)]
    18.9        |> Local_Defs.unfold lthy @{thms split_paired_all split_conv split_strict}
   18.10      val tuple_unfold_thm = (def_cont_fix_eq OF [tuple_fixdef_thm, cont_thm])
   18.11        |> Local_Defs.unfold lthy @{thms split_conv}
    19.1 --- a/src/HOL/Import/import_rule.ML	Fri Mar 06 14:01:08 2015 +0100
    19.2 +++ b/src/HOL/Import/import_rule.ML	Fri Mar 06 15:58:56 2015 +0100
    19.3 @@ -163,7 +163,7 @@
    19.4      val tfrees = map (fn ((t, _), s) => TFree (t, s)) tvars
    19.5      val tvars = map TVar tvars
    19.6      val thy = Thm.theory_of_thm thm
    19.7 -    fun inst ty = Thm.ctyp_of thy ty
    19.8 +    fun inst ty = Thm.global_ctyp_of thy ty
    19.9    in
   19.10      Thm.instantiate ((map inst tvars ~~ map inst tfrees), []) thm
   19.11    end
   19.12 @@ -206,8 +206,8 @@
   19.13      val [nty, oty] = Thm.dest_ctyp (Thm.ctyp_of_cterm rept)
   19.14    in
   19.15      Drule.instantiate' [SOME nty, SOME oty] [SOME rept, SOME abst, SOME P,
   19.16 -      SOME (Thm.cterm_of thy (Free ("a", Thm.typ_of nty))),
   19.17 -      SOME (Thm.cterm_of thy (Free ("r", Thm.typ_of oty)))] @{thm typedef_hol2hollight}
   19.18 +      SOME (Thm.global_cterm_of thy (Free ("a", Thm.typ_of nty))),
   19.19 +      SOME (Thm.global_cterm_of thy (Free ("r", Thm.typ_of oty)))] @{thm typedef_hol2hollight}
   19.20    end
   19.21  
   19.22  fun tydef' tycname abs_name rep_name cP ct td_th thy =
   19.23 @@ -233,8 +233,8 @@
   19.24      val typedef_th =
   19.25         Drule.instantiate'
   19.26            [SOME nty, SOME oty]
   19.27 -          [SOME rept, SOME abst, SOME cP, SOME (Thm.cterm_of thy' (Free ("a", aty))),
   19.28 -             SOME (Thm.cterm_of thy' (Free ("r", Thm.typ_of ctT)))]
   19.29 +          [SOME rept, SOME abst, SOME cP, SOME (Thm.global_cterm_of thy' (Free ("a", aty))),
   19.30 +             SOME (Thm.global_cterm_of thy' (Free ("r", Thm.typ_of ctT)))]
   19.31            @{thm typedef_hol2hollight}
   19.32      val th4 = typedef_th OF [#type_definition (#2 typedef_info)]
   19.33    in
   19.34 @@ -266,8 +266,8 @@
   19.35      val tys_after = Term.add_tvars (Thm.prop_of th1) []
   19.36      val tyinst = map2 (fn bef => fn iS =>
   19.37         (case try (assoc (TFree bef)) lambda of
   19.38 -              SOME cty => (Thm.ctyp_of thy (TVar iS), cty)
   19.39 -            | NONE => (Thm.ctyp_of thy (TVar iS), Thm.ctyp_of thy (TFree bef))
   19.40 +              SOME cty => (Thm.global_ctyp_of thy (TVar iS), cty)
   19.41 +            | NONE => (Thm.global_ctyp_of thy (TVar iS), Thm.global_ctyp_of thy (TFree bef))
   19.42         )) tys_before tys_after
   19.43    in
   19.44      Thm.instantiate (tyinst,[]) th1
   19.45 @@ -333,8 +333,8 @@
   19.46      val tns = map (fn (_, _) => "'") tvs
   19.47      val nms = fst (fold_map Name.variant tns (Variable.names_of (Proof_Context.init_global thy)))
   19.48      val vs = map TVar ((nms ~~ (map (snd o fst) tvs)) ~~ (map snd tvs))
   19.49 -    val cvs = map (Thm.ctyp_of thy) vs
   19.50 -    val ctvs = map (Thm.ctyp_of thy) (map TVar tvs)
   19.51 +    val cvs = map (Thm.global_ctyp_of thy) vs
   19.52 +    val ctvs = map (Thm.global_ctyp_of thy) (map TVar tvs)
   19.53      val thm' = Thm.instantiate ((ctvs ~~ cvs), []) thm
   19.54    in
   19.55      snd (Global_Theory.add_thm ((binding, thm'), []) thy)
   19.56 @@ -411,14 +411,14 @@
   19.57            end
   19.58        | process (thy, state) (#"Y", [name, _, _]) = setth (mtydef name thy) (thy, state)
   19.59        | process (thy, state) (#"t", [n]) =
   19.60 -          setty (Thm.ctyp_of thy (TFree ("'" ^ (transl_qm n), @{sort type}))) (thy, state)
   19.61 +          setty (Thm.global_ctyp_of thy (TFree ("'" ^ (transl_qm n), @{sort type}))) (thy, state)
   19.62        | process (thy, state) (#"a", n :: l) =
   19.63            fold_map getty l (thy, state) |>>
   19.64 -            (fn tys => Thm.ctyp_of thy (Type (gettyname n thy, map Thm.typ_of tys))) |-> setty
   19.65 +            (fn tys => Thm.global_ctyp_of thy (Type (gettyname n thy, map Thm.typ_of tys))) |-> setty
   19.66        | process (thy, state) (#"v", [n, ty]) =
   19.67 -          getty ty (thy, state) |>> (fn ty => Thm.cterm_of thy (Free (transl_dot n, Thm.typ_of ty))) |-> settm
   19.68 +          getty ty (thy, state) |>> (fn ty => Thm.global_cterm_of thy (Free (transl_dot n, Thm.typ_of ty))) |-> settm
   19.69        | process (thy, state) (#"c", [n, ty]) =
   19.70 -          getty ty (thy, state) |>> (fn ty => Thm.cterm_of thy (Const (getconstname n thy, Thm.typ_of ty))) |-> settm
   19.71 +          getty ty (thy, state) |>> (fn ty => Thm.global_cterm_of thy (Const (getconstname n thy, Thm.typ_of ty))) |-> settm
   19.72        | process tstate (#"f", [t1, t2]) =
   19.73            gettm t1 tstate ||>> gettm t2 |>> (fn (t1, t2) => Thm.apply t1 t2) |-> settm
   19.74        | process tstate (#"l", [t1, t2]) =
    20.1 --- a/src/HOL/Library/Code_Abstract_Nat.thy	Fri Mar 06 14:01:08 2015 +0100
    20.2 +++ b/src/HOL/Library/Code_Abstract_Nat.thy	Fri Mar 06 15:58:56 2015 +0100
    20.3 @@ -59,7 +59,7 @@
    20.4      val thy = Proof_Context.theory_of ctxt;
    20.5      val vname = singleton (Name.variant_list (map fst
    20.6        (fold (Term.add_var_names o Thm.full_prop_of) thms []))) "n";
    20.7 -    val cv = Thm.cterm_of thy (Var ((vname, 0), HOLogic.natT));
    20.8 +    val cv = Thm.global_cterm_of thy (Var ((vname, 0), HOLogic.natT));
    20.9      val lhs_of = snd o Thm.dest_comb o fst o Thm.dest_comb o Thm.cprop_of;
   20.10      val rhs_of = snd o Thm.dest_comb o Thm.cprop_of;
   20.11      fun find_vars ct = (case Thm.term_of ct of
    21.1 --- a/src/HOL/Library/Countable.thy	Fri Mar 06 14:01:08 2015 +0100
    21.2 +++ b/src/HOL/Library/Countable.thy	Fri Mar 06 15:58:56 2015 +0100
    21.3 @@ -181,7 +181,7 @@
    21.4          val induct_thm = the (AList.lookup (op =) alist pred_name)
    21.5          val vars = rev (Term.add_vars (Thm.prop_of induct_thm) [])
    21.6          val thy = Proof_Context.theory_of ctxt
    21.7 -        val insts = vars |> map (fn (_, T) => try (Thm.cterm_of thy)
    21.8 +        val insts = vars |> map (fn (_, T) => try (Thm.global_cterm_of thy)
    21.9            (Const (@{const_name Countable.finite_item}, T)))
   21.10          val induct_thm' = Drule.instantiate' [] insts induct_thm
   21.11          val rules = @{thms finite_item.intros}
    22.1 --- a/src/HOL/Library/Old_SMT/old_smt_normalize.ML	Fri Mar 06 14:01:08 2015 +0100
    22.2 +++ b/src/HOL/Library/Old_SMT/old_smt_normalize.ML	Fri Mar 06 15:58:56 2015 +0100
    22.3 @@ -30,7 +30,7 @@
    22.4   
    22.5  local
    22.6    val (cpfalse, cfalse) =
    22.7 -    `Old_SMT_Utils.mk_cprop (Thm.cterm_of @{theory} @{const False})
    22.8 +    `Old_SMT_Utils.mk_cprop (Thm.global_cterm_of @{theory} @{const False})
    22.9  
   22.10    fun inst f ct thm =
   22.11      let val cv = f (Drule.strip_imp_concl (Thm.cprop_of thm))
   22.12 @@ -203,7 +203,7 @@
   22.13      Old_SMT_Utils.mk_const_pat @{theory} @{const_name pat} Old_SMT_Utils.destT1
   22.14    fun mk_pat ct = Thm.apply (Old_SMT_Utils.instT' ct pat) ct
   22.15  
   22.16 -  fun mk_clist T = apply2 (Thm.cterm_of @{theory})
   22.17 +  fun mk_clist T = apply2 (Thm.global_cterm_of @{theory})
   22.18      (HOLogic.cons_const T, HOLogic.nil_const T)
   22.19    fun mk_list (ccons, cnil) f cts = fold_rev (Thm.mk_binop ccons o f) cts cnil
   22.20    val mk_pat_list = mk_list (mk_clist @{typ pattern})
    23.1 --- a/src/HOL/Library/Old_SMT/old_smt_real.ML	Fri Mar 06 14:01:08 2015 +0100
    23.2 +++ b/src/HOL/Library/Old_SMT/old_smt_real.ML	Fri Mar 06 15:58:56 2015 +0100
    23.3 @@ -64,14 +64,14 @@
    23.4    fun mk_nary _ cu [] = cu
    23.5      | mk_nary ct _ cts = uncurry (fold_rev (Thm.mk_binop ct)) (split_last cts)
    23.6  
    23.7 -  val mk_uminus = Thm.apply (Thm.cterm_of @{theory} @{const uminus (real)})
    23.8 -  val add = Thm.cterm_of @{theory} @{const plus (real)}
    23.9 +  val mk_uminus = Thm.apply (Thm.global_cterm_of @{theory} @{const uminus (real)})
   23.10 +  val add = Thm.global_cterm_of @{theory} @{const plus (real)}
   23.11    val real0 = Numeral.mk_cnumber @{ctyp real} 0
   23.12 -  val mk_sub = Thm.mk_binop (Thm.cterm_of @{theory} @{const minus (real)})
   23.13 -  val mk_mul = Thm.mk_binop (Thm.cterm_of @{theory} @{const times (real)})
   23.14 -  val mk_div = Thm.mk_binop (Thm.cterm_of @{theory} @{const divide (real)})
   23.15 -  val mk_lt = Thm.mk_binop (Thm.cterm_of @{theory} @{const less (real)})
   23.16 -  val mk_le = Thm.mk_binop (Thm.cterm_of @{theory} @{const less_eq (real)})
   23.17 +  val mk_sub = Thm.mk_binop (Thm.global_cterm_of @{theory} @{const minus (real)})
   23.18 +  val mk_mul = Thm.mk_binop (Thm.global_cterm_of @{theory} @{const times (real)})
   23.19 +  val mk_div = Thm.mk_binop (Thm.global_cterm_of @{theory} @{const divide (real)})
   23.20 +  val mk_lt = Thm.mk_binop (Thm.global_cterm_of @{theory} @{const less (real)})
   23.21 +  val mk_le = Thm.mk_binop (Thm.global_cterm_of @{theory} @{const less_eq (real)})
   23.22  
   23.23    fun z3_mk_builtin_fun (Old_Z3_Interface.Sym ("-", _)) [ct] = SOME (mk_uminus ct)
   23.24      | z3_mk_builtin_fun (Old_Z3_Interface.Sym ("+", _)) cts =
    24.1 --- a/src/HOL/Library/Old_SMT/old_smt_solver.ML	Fri Mar 06 14:01:08 2015 +0100
    24.2 +++ b/src/HOL/Library/Old_SMT/old_smt_solver.ML	Fri Mar 06 15:58:56 2015 +0100
    24.3 @@ -195,7 +195,7 @@
    24.4              const_defs = us})
    24.5          end)
    24.6  
    24.7 -  val cfalse = Thm.cterm_of @{theory} (@{const Trueprop} $ @{const False})
    24.8 +  val cfalse = Thm.global_cterm_of @{theory} (@{const Trueprop} $ @{const False})
    24.9  in
   24.10  
   24.11  fun add_solver cfg =
   24.12 @@ -268,7 +268,7 @@
   24.13  
   24.14  (* filter *)
   24.15  
   24.16 -val cnot = Thm.cterm_of @{theory} @{const Not}
   24.17 +val cnot = Thm.global_cterm_of @{theory} @{const Not}
   24.18  
   24.19  fun mk_result outcome xrules = { outcome = outcome, used_facts = xrules }
   24.20  
    25.1 --- a/src/HOL/Library/Old_SMT/old_smt_utils.ML	Fri Mar 06 14:01:08 2015 +0100
    25.2 +++ b/src/HOL/Library/Old_SMT/old_smt_utils.ML	Fri Mar 06 15:58:56 2015 +0100
    25.3 @@ -146,7 +146,7 @@
    25.4  (* patterns and instantiations *)
    25.5  
    25.6  fun mk_const_pat thy name destT =
    25.7 -  let val cpat = Thm.cterm_of thy (Const (name, Sign.the_const_type thy name))
    25.8 +  let val cpat = Thm.global_cterm_of thy (Const (name, Sign.the_const_type thy name))
    25.9    in (destT (Thm.ctyp_of_cterm cpat), cpat) end
   25.10  
   25.11  val destT1 = hd o Thm.dest_ctyp
   25.12 @@ -175,7 +175,7 @@
   25.13  
   25.14  val dest_all_cbinders = repeat_yield (try o dest_cbinder)
   25.15  
   25.16 -val mk_cprop = Thm.apply (Thm.cterm_of @{theory} @{const Trueprop})
   25.17 +val mk_cprop = Thm.apply (Thm.global_cterm_of @{theory} @{const Trueprop})
   25.18  
   25.19  fun dest_cprop ct =
   25.20    (case Thm.term_of ct of
    26.1 --- a/src/HOL/Library/Old_SMT/old_z3_interface.ML	Fri Mar 06 14:01:08 2015 +0100
    26.2 +++ b/src/HOL/Library/Old_SMT/old_z3_interface.ML	Fri Mar 06 15:58:56 2015 +0100
    26.3 @@ -137,13 +137,13 @@
    26.4    | mk_builtin_num ctxt i T =
    26.5        chained_mk_builtin_num ctxt (get_mk_builtins ctxt) i T
    26.6  
    26.7 -val mk_true = Thm.cterm_of @{theory} (@{const Not} $ @{const False})
    26.8 -val mk_false = Thm.cterm_of @{theory} @{const False}
    26.9 -val mk_not = Thm.apply (Thm.cterm_of @{theory} @{const Not})
   26.10 -val mk_implies = Thm.mk_binop (Thm.cterm_of @{theory} @{const HOL.implies})
   26.11 -val mk_iff = Thm.mk_binop (Thm.cterm_of @{theory} @{const HOL.eq (bool)})
   26.12 -val conj = Thm.cterm_of @{theory} @{const HOL.conj}
   26.13 -val disj = Thm.cterm_of @{theory} @{const HOL.disj}
   26.14 +val mk_true = Thm.global_cterm_of @{theory} (@{const Not} $ @{const False})
   26.15 +val mk_false = Thm.global_cterm_of @{theory} @{const False}
   26.16 +val mk_not = Thm.apply (Thm.global_cterm_of @{theory} @{const Not})
   26.17 +val mk_implies = Thm.mk_binop (Thm.global_cterm_of @{theory} @{const HOL.implies})
   26.18 +val mk_iff = Thm.mk_binop (Thm.global_cterm_of @{theory} @{const HOL.eq (bool)})
   26.19 +val conj = Thm.global_cterm_of @{theory} @{const HOL.conj}
   26.20 +val disj = Thm.global_cterm_of @{theory} @{const HOL.disj}
   26.21  
   26.22  fun mk_nary _ cu [] = cu
   26.23    | mk_nary ct _ cts = uncurry (fold_rev (Thm.mk_binop ct)) (split_last cts)
   26.24 @@ -184,15 +184,15 @@
   26.25      Thm.apply (Thm.mk_binop (Old_SMT_Utils.instTs cTs update) array index) value
   26.26    end
   26.27  
   26.28 -val mk_uminus = Thm.apply (Thm.cterm_of @{theory} @{const uminus (int)})
   26.29 -val add = Thm.cterm_of @{theory} @{const plus (int)}
   26.30 +val mk_uminus = Thm.apply (Thm.global_cterm_of @{theory} @{const uminus (int)})
   26.31 +val add = Thm.global_cterm_of @{theory} @{const plus (int)}
   26.32  val int0 = Numeral.mk_cnumber @{ctyp int} 0
   26.33 -val mk_sub = Thm.mk_binop (Thm.cterm_of @{theory} @{const minus (int)})
   26.34 -val mk_mul = Thm.mk_binop (Thm.cterm_of @{theory} @{const times (int)})
   26.35 -val mk_div = Thm.mk_binop (Thm.cterm_of @{theory} @{const z3div})
   26.36 -val mk_mod = Thm.mk_binop (Thm.cterm_of @{theory} @{const z3mod})
   26.37 -val mk_lt = Thm.mk_binop (Thm.cterm_of @{theory} @{const less (int)})
   26.38 -val mk_le = Thm.mk_binop (Thm.cterm_of @{theory} @{const less_eq (int)})
   26.39 +val mk_sub = Thm.mk_binop (Thm.global_cterm_of @{theory} @{const minus (int)})
   26.40 +val mk_mul = Thm.mk_binop (Thm.global_cterm_of @{theory} @{const times (int)})
   26.41 +val mk_div = Thm.mk_binop (Thm.global_cterm_of @{theory} @{const z3div})
   26.42 +val mk_mod = Thm.mk_binop (Thm.global_cterm_of @{theory} @{const z3mod})
   26.43 +val mk_lt = Thm.mk_binop (Thm.global_cterm_of @{theory} @{const less (int)})
   26.44 +val mk_le = Thm.mk_binop (Thm.global_cterm_of @{theory} @{const less_eq (int)})
   26.45  
   26.46  fun mk_builtin_fun ctxt sym cts =
   26.47    (case (sym, cts) of
    27.1 --- a/src/HOL/Library/Old_SMT/old_z3_proof_literals.ML	Fri Mar 06 14:01:08 2015 +0100
    27.2 +++ b/src/HOL/Library/Old_SMT/old_z3_proof_literals.ML	Fri Mar 06 15:58:56 2015 +0100
    27.3 @@ -82,7 +82,7 @@
    27.4        | NONE => false)
    27.5    in exists end
    27.6  
    27.7 -val negate = Thm.apply (Thm.cterm_of @{theory} @{const Not})
    27.8 +val negate = Thm.apply (Thm.global_cterm_of @{theory} @{const Not})
    27.9  
   27.10  
   27.11  
    28.1 --- a/src/HOL/Library/Old_SMT/old_z3_proof_methods.ML	Fri Mar 06 14:01:08 2015 +0100
    28.2 +++ b/src/HOL/Library/Old_SMT/old_z3_proof_methods.ML	Fri Mar 06 15:58:56 2015 +0100
    28.3 @@ -51,15 +51,15 @@
    28.4  fun mk_inv_of ctxt ct =
    28.5    let
    28.6      val (dT, rT) = Term.dest_funT (Thm.typ_of_cterm ct)
    28.7 -    val inv = Proof_Context.cterm_of ctxt (mk_inv_into dT rT)
    28.8 -    val univ = Proof_Context.cterm_of ctxt (mk_univ dT)
    28.9 +    val inv = Thm.cterm_of ctxt (mk_inv_into dT rT)
   28.10 +    val univ = Thm.cterm_of ctxt (mk_univ dT)
   28.11    in Thm.mk_binop inv univ ct end
   28.12  
   28.13  fun mk_inj_prop ctxt ct =
   28.14    let
   28.15      val (dT, rT) = Term.dest_funT (Thm.typ_of_cterm ct)
   28.16 -    val inj = Proof_Context.cterm_of ctxt (mk_inj_on dT rT)
   28.17 -    val univ = Proof_Context.cterm_of ctxt (mk_univ dT)
   28.18 +    val inj = Thm.cterm_of ctxt (mk_inj_on dT rT)
   28.19 +    val univ = Thm.cterm_of ctxt (mk_univ dT)
   28.20    in Old_SMT_Utils.mk_cprop (Thm.mk_binop inj ct univ) end
   28.21  
   28.22  
    29.1 --- a/src/HOL/Library/Old_SMT/old_z3_proof_parser.ML	Fri Mar 06 14:01:08 2015 +0100
    29.2 +++ b/src/HOL/Library/Old_SMT/old_z3_proof_parser.ML	Fri Mar 06 15:58:56 2015 +0100
    29.3 @@ -109,7 +109,7 @@
    29.4      val max = fold (Integer.max o fst) vars 0
    29.5      val ns = fst (Variable.variant_fixes (replicate (max + 1) var_prefix) ctxt)
    29.6      fun mk (i, v) =
    29.7 -      (v, Proof_Context.cterm_of ctxt (Free (nth ns i, Thm.typ_of_cterm v)))
    29.8 +      (v, Thm.cterm_of ctxt (Free (nth ns i, Thm.typ_of_cterm v)))
    29.9    in map mk vars end
   29.10  
   29.11  fun close ctxt (ct, vars) =
   29.12 @@ -120,7 +120,7 @@
   29.13  
   29.14  
   29.15  fun mk_bound ctxt (i, T) =
   29.16 -  let val ct = Proof_Context.cterm_of ctxt (Var ((Name.uu, 0), T))
   29.17 +  let val ct = Thm.cterm_of ctxt (Var ((Name.uu, 0), T))
   29.18    in (ct, [(i, ct)]) end
   29.19  
   29.20  local
   29.21 @@ -129,7 +129,7 @@
   29.22        val cv =
   29.23          (case AList.lookup (op =) vars 0 of
   29.24            SOME cv => cv
   29.25 -        | _ => Proof_Context.cterm_of ctxt (Var ((Name.uu, Thm.maxidx_of_cterm ct + 1), T)))
   29.26 +        | _ => Thm.cterm_of ctxt (Var ((Name.uu, Thm.maxidx_of_cterm ct + 1), T)))
   29.27        fun dec (i, v) = if i = 0 then NONE else SOME (i-1, v)
   29.28        val vars' = map_filter dec vars
   29.29      in (Thm.apply (Old_SMT_Utils.instT' cv q) (Thm.lambda cv ct), vars') end
   29.30 @@ -181,7 +181,7 @@
   29.31  
   29.32  (** parser context **)
   29.33  
   29.34 -val not_false = Thm.cterm_of @{theory} (@{const Not} $ @{const False})
   29.35 +val not_false = Thm.global_cterm_of @{theory} (@{const Not} $ @{const False})
   29.36  
   29.37  fun make_context ctxt typs terms =
   29.38    let
   29.39 @@ -191,7 +191,7 @@
   29.40        |> Symtab.fold (Variable.declare_term o snd) terms
   29.41  
   29.42      fun cert @{const True} = not_false
   29.43 -      | cert t = Proof_Context.cterm_of ctxt' t
   29.44 +      | cert t = Thm.cterm_of ctxt' t
   29.45  
   29.46    in (typs, Symtab.map (K cert) terms, Inttab.empty, [], [], ctxt') end
   29.47  
   29.48 @@ -207,7 +207,7 @@
   29.49    | NONE => cx |> fresh_name (decl_prefix ^ n)
   29.50        |> (fn (m, (typs, terms, exprs, steps, vars, ctxt)) =>
   29.51             let
   29.52 -             val upd = Symtab.update (n, Proof_Context.cterm_of ctxt (Free (m, T)))
   29.53 +             val upd = Symtab.update (n, Thm.cterm_of ctxt (Free (m, T)))
   29.54             in (typs, upd terms, exprs, steps, vars, ctxt) end))
   29.55  
   29.56  fun mk_typ (typs, _, _, _, _, ctxt) (s as Old_Z3_Interface.Sym (n, _)) = 
   29.57 @@ -381,7 +381,7 @@
   29.58  
   29.59  fun pats st = seps (par ((this ":pat" || this ":nopat") |-- seps1 id)) st
   29.60  
   29.61 -val ctrue = Thm.cterm_of @{theory} @{const True}
   29.62 +val ctrue = Thm.global_cterm_of @{theory} @{const True}
   29.63  
   29.64  fun pattern st = par (this "pattern" |-- Scan.repeat1 (sep arg) >>
   29.65    (the o mk_fun (K (SOME ctrue)))) st
    30.1 --- a/src/HOL/Library/Old_SMT/old_z3_proof_reconstruction.ML	Fri Mar 06 14:01:08 2015 +0100
    30.2 +++ b/src/HOL/Library/Old_SMT/old_z3_proof_reconstruction.ML	Fri Mar 06 15:58:56 2015 +0100
    30.3 @@ -617,7 +617,7 @@
    30.4    fun get_vars f mk pred ctxt t =
    30.5      Term.fold_aterms f t []
    30.6      |> map_filter (fn v =>
    30.7 -         if pred v then SOME (Proof_Context.cterm_of ctxt (mk v)) else NONE)
    30.8 +         if pred v then SOME (Thm.cterm_of ctxt (mk v)) else NONE)
    30.9  
   30.10    fun close vars f ct ctxt =
   30.11      let
    31.1 --- a/src/HOL/Library/Old_SMT/old_z3_proof_tools.ML	Fri Mar 06 14:01:08 2015 +0100
    31.2 +++ b/src/HOL/Library/Old_SMT/old_z3_proof_tools.ML	Fri Mar 06 15:58:56 2015 +0100
    31.3 @@ -156,7 +156,7 @@
    31.4      | NONE =>
    31.5          let
    31.6            val (n, ctxt') = yield_singleton Variable.variant_fixes "x" ctxt
    31.7 -          val cv = Proof_Context.cterm_of ctxt'
    31.8 +          val cv = Thm.cterm_of ctxt'
    31.9              (Free (n, map Thm.typ_of_cterm cvs' ---> Thm.typ_of_cterm ct))
   31.10            val cu = Drule.list_comb (cv, cvs')
   31.11            val e = (t, (cv, fold_rev Thm.lambda cvs' ct))
   31.12 @@ -229,7 +229,7 @@
   31.13              | _ => fresh_abstraction dcvs ct cx)))
   31.14    in abstr (depth, []) end
   31.15  
   31.16 -val cimp = Thm.cterm_of @{theory} @{const Pure.imp}
   31.17 +val cimp = Thm.global_cterm_of @{theory} @{const Pure.imp}
   31.18  
   31.19  fun deepen depth f x =
   31.20    if depth = 0 then f depth x
    32.1 --- a/src/HOL/Library/Sum_of_Squares/positivstellensatz_tools.ML	Fri Mar 06 14:01:08 2015 +0100
    32.2 +++ b/src/HOL/Library/Sum_of_Squares/positivstellensatz_tools.ML	Fri Mar 06 15:58:56 2015 +0100
    32.3 @@ -114,7 +114,7 @@
    32.4  val parse_id = Scan.one Symbol.is_letter ::: Scan.many Symbol.is_letdig >> implode
    32.5  
    32.6  fun parse_varpow ctxt = parse_id -- Scan.optional (str "^" |-- nat) 1 >>
    32.7 -  (fn (x, k) => (Proof_Context.cterm_of ctxt (Free (x, @{typ real})), k))
    32.8 +  (fn (x, k) => (Thm.cterm_of ctxt (Free (x, @{typ real})), k))
    32.9  
   32.10  fun parse_monomial ctxt = repeat_sep "*" (parse_varpow ctxt) >>
   32.11    (fn xs => fold FuncUtil.Ctermfunc.update xs FuncUtil.Ctermfunc.empty)
    33.1 --- a/src/HOL/Library/simps_case_conv.ML	Fri Mar 06 14:01:08 2015 +0100
    33.2 +++ b/src/HOL/Library/simps_case_conv.ML	Fri Mar 06 15:58:56 2015 +0100
    33.3 @@ -97,7 +97,7 @@
    33.4    | import (thm :: thms) ctxt =
    33.5      let
    33.6        val fun_ct = strip_eq #> fst #> strip_comb #> fst #> Logic.mk_term
    33.7 -        #> Proof_Context.cterm_of ctxt
    33.8 +        #> Thm.cterm_of ctxt
    33.9        val ct = fun_ct thm
   33.10        val cts = map fun_ct thms
   33.11        val pairs = map (fn s => (s,ct)) cts
    34.1 --- a/src/HOL/Matrix_LP/Compute_Oracle/compute.ML	Fri Mar 06 14:01:08 2015 +0100
    34.2 +++ b/src/HOL/Matrix_LP/Compute_Oracle/compute.ML	Fri Mar 06 15:58:56 2015 +0100
    34.3 @@ -362,13 +362,13 @@
    34.4                commas (map (Syntax.string_of_sort_global thy) shyps))
    34.5            else ()
    34.6      in
    34.7 -        Thm.cterm_of thy (fold_rev (fn hyp => fn p => Logic.mk_implies (hyp, p)) hyps prop)
    34.8 +        Thm.global_cterm_of thy (fold_rev (fn hyp => fn p => Logic.mk_implies (hyp, p)) hyps prop)
    34.9      end)));
   34.10  
   34.11  fun export_thm thy hyps shyps prop =
   34.12      let
   34.13          val th = export_oracle (thy, hyps, shyps, prop)
   34.14 -        val hyps = map (fn h => Thm.assume (Thm.cterm_of thy h)) hyps
   34.15 +        val hyps = map (fn h => Thm.assume (Thm.global_cterm_of thy h)) hyps
   34.16      in
   34.17          fold (fn h => fn p => Thm.implies_elim p h) hyps th 
   34.18      end
    35.1 --- a/src/HOL/Matrix_LP/Compute_Oracle/linker.ML	Fri Mar 06 14:01:08 2015 +0100
    35.2 +++ b/src/HOL/Matrix_LP/Compute_Oracle/linker.ML	Fri Mar 06 15:58:56 2015 +0100
    35.3 @@ -315,7 +315,7 @@
    35.4      end
    35.5  
    35.6  fun conv_subst thy (subst : Type.tyenv) =
    35.7 -    map (fn (iname, (sort, ty)) => (Thm.ctyp_of thy (TVar (iname, sort)), Thm.ctyp_of thy ty))
    35.8 +    map (fn (iname, (sort, ty)) => (Thm.global_ctyp_of thy (TVar (iname, sort)), Thm.global_ctyp_of thy ty))
    35.9        (Vartab.dest subst)
   35.10  
   35.11  fun add_monos thy monocs pats ths =
    36.1 --- a/src/HOL/Multivariate_Analysis/normarith.ML	Fri Mar 06 14:01:08 2015 +0100
    36.2 +++ b/src/HOL/Multivariate_Analysis/normarith.ML	Fri Mar 06 15:58:56 2015 +0100
    36.3 @@ -344,7 +344,7 @@
    36.4    fun instantiate_cterm' ty tms = Drule.cterm_rule (Drule.instantiate' ty tms)
    36.5    fun mk_norm t = Thm.apply (instantiate_cterm' [SOME (Thm.ctyp_of_cterm t)] [] @{cpat "norm :: (?'a :: real_normed_vector) => real"}) t
    36.6    fun mk_equals l r = Thm.apply (Thm.apply (instantiate_cterm' [SOME (Thm.ctyp_of_cterm l)] [] @{cpat "op == :: ?'a =>_"}) l) r
    36.7 -  val asl = map2 (fn (t,_) => fn n => Thm.assume (mk_equals (mk_norm t) (Proof_Context.cterm_of ctxt' (Free(n,@{typ real}))))) lctab fxns
    36.8 +  val asl = map2 (fn (t,_) => fn n => Thm.assume (mk_equals (mk_norm t) (Thm.cterm_of ctxt' (Free(n,@{typ real}))))) lctab fxns
    36.9    val replace_conv = try_conv (rewrs_conv asl)
   36.10    val replace_rule = fconv_rule (funpow 2 arg_conv (replacenegnorms replace_conv))
   36.11    val ges' =
    37.1 --- a/src/HOL/Mutabelle/mutabelle_extra.ML	Fri Mar 06 14:01:08 2015 +0100
    37.2 +++ b/src/HOL/Mutabelle/mutabelle_extra.ML	Fri Mar 06 15:58:56 2015 +0100
    37.3 @@ -401,7 +401,7 @@
    37.4            |> map Mutabelle.freeze |> map freezeT
    37.5  (*          |> filter (not o is_forbidden_mutant) *)
    37.6            |> map_filter (try (Sign.cert_term thy))
    37.7 -          |> filter (is_some o try (Thm.cterm_of thy))
    37.8 +          |> filter (is_some o try (Thm.global_cterm_of thy))
    37.9            |> filter (is_some o try (Syntax.check_term (Proof_Context.init_global thy)))
   37.10            |> take_random max_mutants
   37.11      val _ = map (fn t => writeln ("MUTANT: " ^ Syntax.string_of_term_global thy t)) mutants
    38.1 --- a/src/HOL/NSA/transfer.ML	Fri Mar 06 14:01:08 2015 +0100
    38.2 +++ b/src/HOL/NSA/transfer.ML	Fri Mar 06 15:58:56 2015 +0100
    38.3 @@ -57,7 +57,7 @@
    38.4      val meta = Local_Defs.meta_rewrite_rule ctxt;
    38.5      val ths' = map meta ths;
    38.6      val unfolds' = map meta unfolds and refolds' = map meta refolds;
    38.7 -    val (_$_$t') = Thm.concl_of (Raw_Simplifier.rewrite ctxt true unfolds' (Thm.cterm_of thy t))
    38.8 +    val (_$_$t') = Thm.concl_of (Raw_Simplifier.rewrite ctxt true unfolds' (Thm.global_cterm_of thy t))
    38.9      val u = unstar_term consts t'
   38.10      val tac =
   38.11        rewrite_goals_tac ctxt (ths' @ refolds' @ unfolds') THEN
    39.1 --- a/src/HOL/Nominal/nominal_datatype.ML	Fri Mar 06 14:01:08 2015 +0100
    39.2 +++ b/src/HOL/Nominal/nominal_datatype.ML	Fri Mar 06 15:58:56 2015 +0100
    39.3 @@ -108,9 +108,9 @@
    39.4              val cp = cp_inst_of thy a b;
    39.5              val dj = dj_thm_of thy b a;
    39.6              val dj_cp' = [cp, dj] MRS dj_cp;
    39.7 -            val cert = SOME o Thm.cterm_of thy
    39.8 +            val cert = SOME o Thm.global_cterm_of thy
    39.9            in
   39.10 -            SOME (mk_meta_eq (Drule.instantiate' [SOME (Thm.ctyp_of thy S)]
   39.11 +            SOME (mk_meta_eq (Drule.instantiate' [SOME (Thm.global_ctyp_of thy S)]
   39.12                [cert t, cert r, cert s] dj_cp'))
   39.13            end
   39.14          else NONE
   39.15 @@ -777,12 +777,12 @@
   39.16      fun dt_constr_defs ((((((_, (_, _, constrs)),
   39.17          (_, (_, _, constrs'))), tname), T), T'), constr_syntax) (thy, defs, eqns, dist_lemmas) =
   39.18        let
   39.19 -        val rep_const = Thm.cterm_of thy
   39.20 +        val rep_const = Thm.global_cterm_of thy
   39.21            (Const (Sign.intern_const thy ("Rep_" ^ tname), T --> T'));
   39.22          val dist =
   39.23            Drule.export_without_context
   39.24              (cterm_instantiate
   39.25 -              [(Thm.cterm_of thy distinct_f, rep_const)] Old_Datatype.distinct_lemma);
   39.26 +              [(Thm.global_cterm_of thy distinct_f, rep_const)] Old_Datatype.distinct_lemma);
   39.27          val (thy', defs', eqns') = fold (make_constr_def tname T T')
   39.28            (constrs ~~ constrs' ~~ constr_syntax) (Sign.add_path tname thy, defs, [])
   39.29        in
   39.30 @@ -1051,7 +1051,7 @@
   39.31      val frees = if length Ps = 1 then [Free ("P", snd (dest_Var (hd Ps)))] else
   39.32        map (Free o apfst fst o dest_Var) Ps;
   39.33      val indrule_lemma' = cterm_instantiate
   39.34 -      (map (Thm.cterm_of thy8) Ps ~~ map (Thm.cterm_of thy8) frees) indrule_lemma;
   39.35 +      (map (Thm.global_cterm_of thy8) Ps ~~ map (Thm.global_cterm_of thy8) frees) indrule_lemma;
   39.36  
   39.37      val Abs_inverse_thms' = map (fn r => r RS subst) Abs_inverse_thms;
   39.38  
   39.39 @@ -1268,7 +1268,7 @@
   39.40            | _ => false)) perm_fresh_fresh
   39.41        in
   39.42          Drule.instantiate' []
   39.43 -          [SOME (Thm.cterm_of thy a), NONE, SOME (Thm.cterm_of thy b)] th
   39.44 +          [SOME (Thm.global_cterm_of thy a), NONE, SOME (Thm.global_cterm_of thy b)] th
   39.45        end;
   39.46  
   39.47      val fs_cp_sort =
   39.48 @@ -1382,13 +1382,13 @@
   39.49  
   39.50      val induct_aux' = Thm.instantiate ([],
   39.51        map (fn (s, v as Var (_, T)) =>
   39.52 -        (Thm.cterm_of thy9 v, Thm.cterm_of thy9 (Free (s, T))))
   39.53 +        (Thm.global_cterm_of thy9 v, Thm.global_cterm_of thy9 (Free (s, T))))
   39.54            (pnames ~~ map head_of (HOLogic.dest_conj
   39.55               (HOLogic.dest_Trueprop (Thm.concl_of induct_aux)))) @
   39.56        map (fn (_, f) =>
   39.57          let val f' = Logic.varify_global f
   39.58 -        in (Thm.cterm_of thy9 f',
   39.59 -          Thm.cterm_of thy9 (Const (@{const_name Nominal.supp}, fastype_of f')))
   39.60 +        in (Thm.global_cterm_of thy9 f',
   39.61 +          Thm.global_cterm_of thy9 (Const (@{const_name Nominal.supp}, fastype_of f')))
   39.62          end) fresh_fs) induct_aux;
   39.63  
   39.64      val induct = Goal.prove_global_future thy9 []
   39.65 @@ -1551,8 +1551,8 @@
   39.66              (augment_sort thy1 pt_cp_sort
   39.67                (Logic.mk_implies (HOLogic.mk_Trueprop Q, HOLogic.mk_Trueprop P)))
   39.68              (fn {context = ctxt, ...} => dtac (Thm.instantiate ([],
   39.69 -                 [(Thm.cterm_of thy11 (Var (("pi", 0), permT)),
   39.70 -                   Thm.cterm_of thy11 (Const (@{const_name rev}, permT --> permT) $ pi))]) th) 1 THEN
   39.71 +                 [(Thm.global_cterm_of thy11 (Var (("pi", 0), permT)),
   39.72 +                   Thm.global_cterm_of thy11 (Const (@{const_name rev}, permT --> permT) $ pi))]) th) 1 THEN
   39.73                 NominalPermeq.perm_simp_tac (put_simpset HOL_ss ctxt) 1)) (ps ~~ ths)
   39.74        in (ths, ths') end) dt_atomTs);
   39.75  
   39.76 @@ -1630,8 +1630,8 @@
   39.77                     val tuple = foldr1 HOLogic.mk_prod (x :: rec_fns')
   39.78                   in EVERY
   39.79                     [rtac (Drule.cterm_instantiate
   39.80 -                      [(Thm.cterm_of thy11 S,
   39.81 -                        Thm.cterm_of thy11 (Const (@{const_name Nominal.supp},
   39.82 +                      [(Thm.global_cterm_of thy11 S,
   39.83 +                        Thm.global_cterm_of thy11 (Const (@{const_name Nominal.supp},
   39.84                            fastype_of tuple --> HOLogic.mk_setT aT) $ tuple))]
   39.85                        supports_fresh) 1,
   39.86                      simp_tac (put_simpset HOL_basic_ss context addsimps
   39.87 @@ -1642,8 +1642,8 @@
   39.88                      SUBPROOF (fn {prems = prems', params = [(_, a), (_, b)], ...} => EVERY
   39.89                        [cut_facts_tac [rec_prem] 1,
   39.90                         rtac (Thm.instantiate ([],
   39.91 -                         [(Thm.cterm_of thy11 (Var (("pi", 0), mk_permT aT)),
   39.92 -                           Thm.cterm_of thy11
   39.93 +                         [(Thm.global_cterm_of thy11 (Var (("pi", 0), mk_permT aT)),
   39.94 +                           Thm.global_cterm_of thy11
   39.95                              (perm_of_pair (Thm.term_of a, Thm.term_of b)))]) eqvt_th) 1,
   39.96                         asm_simp_tac (put_simpset HOL_ss context addsimps
   39.97                           (prems' @ perm_swap @ perm_fresh_fresh)) 1]) context 1,
   39.98 @@ -1671,7 +1671,7 @@
   39.99        (rec_unique_frees ~~ rec_result_Ts ~~ rec_sets);
  39.100  
  39.101      val induct_aux_rec = Drule.cterm_instantiate
  39.102 -      (map (apply2 (Thm.cterm_of thy11) o apsnd (augment_sort thy11 fs_cp_sort))
  39.103 +      (map (apply2 (Thm.global_cterm_of thy11) o apsnd (augment_sort thy11 fs_cp_sort))
  39.104           (map (fn (aT, f) => (Logic.varify_global f, Abs ("z", HOLogic.unitT,
  39.105              Const (@{const_name Nominal.supp}, fun_tupleT --> HOLogic.mk_setT aT) $ fun_tuple)))
  39.106                fresh_fs @
  39.107 @@ -1861,8 +1861,8 @@
  39.108                              val l = find_index (equal T) dt_atomTs;
  39.109                              val th = nth (nth rec_equiv_thms' l) k;
  39.110                              val th' = Thm.instantiate ([],
  39.111 -                              [(Thm.cterm_of thy11 (Var (("pi", 0), U)),
  39.112 -                                Thm.cterm_of thy11 p)]) th;
  39.113 +                              [(Thm.global_cterm_of thy11 (Var (("pi", 0), U)),
  39.114 +                                Thm.global_cterm_of thy11 p)]) th;
  39.115                            in rtac th' 1 end;
  39.116                          val th' = Goal.prove context'' [] []
  39.117                            (HOLogic.mk_Trueprop (S $ mk_pi x $ mk_pi y))
    40.1 --- a/src/HOL/Nominal/nominal_fresh_fun.ML	Fri Mar 06 14:01:08 2015 +0100
    40.2 +++ b/src/HOL/Nominal/nominal_fresh_fun.ML	Fri Mar 06 15:58:56 2015 +0100
    40.3 @@ -23,8 +23,8 @@
    40.4        (head_of (Logic.incr_indexes (Ts, j) t),
    40.5         fold_rev Term.abs ps u)) tinst;
    40.6      val th' = instf
    40.7 -      (map (apply2 (Thm.ctyp_of thy)) tyinst')
    40.8 -      (map (apply2 (Thm.cterm_of thy)) tinst')
    40.9 +      (map (apply2 (Thm.global_ctyp_of thy)) tyinst')
   40.10 +      (map (apply2 (Thm.global_cterm_of thy)) tinst')
   40.11        (Thm.lift_rule cgoal th)
   40.12    in
   40.13      compose_tac ctxt (elim, th', Thm.nprems_of th) i st
   40.14 @@ -149,7 +149,7 @@
   40.15         val thy = Thm.theory_of_thm st;
   40.16     in case subtract (op =) vars vars' of
   40.17       [x] =>
   40.18 -      Seq.single (Thm.instantiate ([], [(Thm.cterm_of thy x, Thm.cterm_of thy (fold_rev Term.abs params (Bound 0)))]) st)
   40.19 +      Seq.single (Thm.instantiate ([], [(Thm.global_cterm_of thy x, Thm.global_cterm_of thy (fold_rev Term.abs params (Bound 0)))]) st)
   40.20      | _ => error "fresh_fun_simp: Too many variables, please report."
   40.21     end
   40.22    in
    41.1 --- a/src/HOL/Nominal/nominal_induct.ML	Fri Mar 06 14:01:08 2015 +0100
    41.2 +++ b/src/HOL/Nominal/nominal_induct.ML	Fri Mar 06 15:58:56 2015 +0100
    41.3 @@ -54,7 +54,7 @@
    41.4        end;
    41.5       val substs =
    41.6         map2 subst insts concls |> flat |> distinct (op =)
    41.7 -       |> map (apply2 (Proof_Context.cterm_of ctxt));
    41.8 +       |> map (apply2 (Thm.cterm_of ctxt));
    41.9    in 
   41.10      (((cases, nconcls), consumes), Drule.cterm_instantiate substs joined_rule) 
   41.11    end;
   41.12 @@ -84,7 +84,7 @@
   41.13  fun nominal_induct_tac ctxt simp def_insts avoiding fixings rules facts =
   41.14    let
   41.15      val thy = Proof_Context.theory_of ctxt;
   41.16 -    val cert = Thm.cterm_of thy;
   41.17 +    val cert = Thm.global_cterm_of thy;
   41.18  
   41.19      val ((insts, defs), defs_ctxt) = fold_map Induct.add_defs def_insts ctxt |>> split_list;
   41.20      val atomized_defs = map (map (Conv.fconv_rule (Induct.atomize_cterm ctxt))) defs;
    42.1 --- a/src/HOL/Nominal/nominal_inductive.ML	Fri Mar 06 14:01:08 2015 +0100
    42.2 +++ b/src/HOL/Nominal/nominal_inductive.ML	Fri Mar 06 15:58:56 2015 +0100
    42.3 @@ -204,7 +204,7 @@
    42.4      val fsT = TFree (fs_ctxt_tyname, ind_sort);
    42.5  
    42.6      val inductive_forall_def' = Drule.instantiate'
    42.7 -      [SOME (Thm.ctyp_of thy fsT)] [] inductive_forall_def;
    42.8 +      [SOME (Thm.global_ctyp_of thy fsT)] [] inductive_forall_def;
    42.9  
   42.10      fun lift_pred' t (Free (s, T)) ts =
   42.11        list_comb (Free (s, fsT --> T), t :: ts);
   42.12 @@ -338,7 +338,7 @@
   42.13                   val pis'' = fold (concat_perm #> map) pis' pis;
   42.14                   val env = Pattern.first_order_match thy (ihypt, Thm.prop_of ihyp)
   42.15                     (Vartab.empty, Vartab.empty);
   42.16 -                 val ihyp' = Thm.instantiate ([], map (apply2 (Thm.cterm_of thy))
   42.17 +                 val ihyp' = Thm.instantiate ([], map (apply2 (Thm.global_cterm_of thy))
   42.18                     (map (Envir.subst_term env) vs ~~
   42.19                      map (fold_rev (NominalDatatype.mk_perm [])
   42.20                        (rev pis' @ pis)) params' @ [z])) ihyp;
   42.21 @@ -346,7 +346,7 @@
   42.22                     Simplifier.simplify (put_simpset HOL_basic_ss ctxt' addsimps [@{thm id_apply}]
   42.23                         addsimprocs [NominalDatatype.perm_simproc])
   42.24                       (Simplifier.simplify (put_simpset eqvt_ss ctxt')
   42.25 -                       (fold_rev (mk_perm_bool o Thm.cterm_of thy)
   42.26 +                       (fold_rev (mk_perm_bool o Thm.global_cterm_of thy)
   42.27                           (rev pis' @ pis) th));
   42.28                   val (gprems1, gprems2) = split_list
   42.29                     (map (fn (th, t) =>
   42.30 @@ -505,8 +505,8 @@
   42.31                    val freshs2' = NominalDatatype.mk_not_sym freshs2;
   42.32                    val pis = map (NominalDatatype.perm_of_pair)
   42.33                      ((freshs1 ~~ map fst qs) @ (params' ~~ freshs1));
   42.34 -                  val mk_pis = fold_rev mk_perm_bool (map (Thm.cterm_of thy) pis);
   42.35 -                  val obj = Thm.cterm_of thy (foldr1 HOLogic.mk_conj (map (map_aterms
   42.36 +                  val mk_pis = fold_rev mk_perm_bool (map (Thm.global_cterm_of thy) pis);
   42.37 +                  val obj = Thm.global_cterm_of thy (foldr1 HOLogic.mk_conj (map (map_aterms
   42.38                       (fn x as Free _ =>
   42.39                             if member (op =) args x then x
   42.40                             else (case AList.lookup op = tab x of
   42.41 @@ -630,9 +630,9 @@
   42.42              val prems' = map (fn th => the_default th (map_thm ctxt''
   42.43                (split_conj (K I) names) (etac conjunct2 1) monos NONE th)) prems;
   42.44              val prems'' = map (fn th => Simplifier.simplify eqvt_simpset
   42.45 -              (mk_perm_bool (Thm.cterm_of thy pi) th)) prems';
   42.46 -            val intr' = Drule.cterm_instantiate (map (Thm.cterm_of thy) vs ~~
   42.47 -               map (Thm.cterm_of thy o NominalDatatype.mk_perm [] pi o Thm.term_of o #2) params)
   42.48 +              (mk_perm_bool (Thm.global_cterm_of thy pi) th)) prems';
   42.49 +            val intr' = Drule.cterm_instantiate (map (Thm.global_cterm_of thy) vs ~~
   42.50 +               map (Thm.global_cterm_of thy o NominalDatatype.mk_perm [] pi o Thm.term_of o #2) params)
   42.51                 intr
   42.52            in (rtac intr' THEN_ALL_NEW (TRY o resolve_tac ctxt'' prems'')) 1
   42.53            end) ctxt' 1 st
    43.1 --- a/src/HOL/Nominal/nominal_inductive2.ML	Fri Mar 06 14:01:08 2015 +0100
    43.2 +++ b/src/HOL/Nominal/nominal_inductive2.ML	Fri Mar 06 15:58:56 2015 +0100
    43.3 @@ -147,7 +147,7 @@
    43.4    let val env = Pattern.first_order_match thy (p, Thm.prop_of th)
    43.5      (Vartab.empty, Vartab.empty)
    43.6    in Thm.instantiate ([],
    43.7 -    map (Envir.subst_term env #> Thm.cterm_of thy) vs ~~ cts) th
    43.8 +    map (Envir.subst_term env #> Thm.global_cterm_of thy) vs ~~ cts) th
    43.9    end;
   43.10  
   43.11  fun prove_strong_ind s alt_name avoids ctxt =
   43.12 @@ -230,7 +230,7 @@
   43.13      val fsT = TFree (fs_ctxt_tyname, ind_sort);
   43.14  
   43.15      val inductive_forall_def' = Drule.instantiate'
   43.16 -      [SOME (Thm.ctyp_of thy fsT)] [] inductive_forall_def;
   43.17 +      [SOME (Thm.global_ctyp_of thy fsT)] [] inductive_forall_def;
   43.18  
   43.19      fun lift_pred' t (Free (s, T)) ts =
   43.20        list_comb (Free (s, fsT --> T), t :: ts);
   43.21 @@ -319,7 +319,7 @@
   43.22          val fs_atom = Global_Theory.get_thm thy
   43.23            ("fs_" ^ Long_Name.base_name atom ^ "1");
   43.24          val avoid_th = Drule.instantiate'
   43.25 -          [SOME (Thm.ctyp_of thy (fastype_of p))] [SOME (Thm.cterm_of thy p)]
   43.26 +          [SOME (Thm.global_ctyp_of thy (fastype_of p))] [SOME (Thm.global_cterm_of thy p)]
   43.27            ([at_inst, fin, fs_atom] MRS @{thm at_set_avoiding});
   43.28          val (([(_, cx)], th1 :: th2 :: ths), ctxt') = Obtain.result
   43.29            (fn ctxt' => EVERY
   43.30 @@ -399,12 +399,12 @@
   43.31                   val pis'' = fold_rev (concat_perm #> map) pis' pis;
   43.32                   val ihyp' = inst_params thy vs_ihypt ihyp
   43.33                     (map (fold_rev (NominalDatatype.mk_perm [])
   43.34 -                      (pis' @ pis) #> Thm.cterm_of thy) params' @ [Thm.cterm_of thy z]);
   43.35 +                      (pis' @ pis) #> Thm.global_cterm_of thy) params' @ [Thm.global_cterm_of thy z]);
   43.36                   fun mk_pi th =
   43.37                     Simplifier.simplify (put_simpset HOL_basic_ss ctxt' addsimps [@{thm id_apply}]
   43.38                         addsimprocs [NominalDatatype.perm_simproc])
   43.39                       (Simplifier.simplify (put_simpset eqvt_ss ctxt')
   43.40 -                       (fold_rev (mk_perm_bool o Thm.cterm_of thy)
   43.41 +                       (fold_rev (mk_perm_bool o Thm.global_cterm_of thy)
   43.42                           (pis' @ pis) th));
   43.43                   val gprems2 = map (fn (th, t) =>
   43.44                     if null (preds_of ps t) then mk_pi th
    44.1 --- a/src/HOL/Nominal/nominal_permeq.ML	Fri Mar 06 14:01:08 2015 +0100
    44.2 +++ b/src/HOL/Nominal/nominal_permeq.ML	Fri Mar 06 15:58:56 2015 +0100
    44.3 @@ -203,14 +203,14 @@
    44.4        if pi1 <> pi2 then  (* only apply the composition rule in this case *)
    44.5          if T = U then    
    44.6            SOME (Drule.instantiate'
    44.7 -            [SOME (Thm.ctyp_of thy (fastype_of t))]
    44.8 -            [SOME (Thm.cterm_of thy pi1), SOME (Thm.cterm_of thy pi2), SOME (Thm.cterm_of thy t)]
    44.9 +            [SOME (Thm.global_ctyp_of thy (fastype_of t))]
   44.10 +            [SOME (Thm.global_cterm_of thy pi1), SOME (Thm.global_cterm_of thy pi2), SOME (Thm.global_cterm_of thy t)]
   44.11              (mk_meta_eq ([Global_Theory.get_thm thy ("pt_"^tname'^"_inst"),
   44.12               Global_Theory.get_thm thy ("at_"^tname'^"_inst")] MRS pt_perm_compose_aux)))
   44.13          else
   44.14            SOME (Drule.instantiate'
   44.15 -            [SOME (Thm.ctyp_of thy (fastype_of t))]
   44.16 -            [SOME (Thm.cterm_of thy pi1), SOME (Thm.cterm_of thy pi2), SOME (Thm.cterm_of thy t)]
   44.17 +            [SOME (Thm.global_ctyp_of thy (fastype_of t))]
   44.18 +            [SOME (Thm.global_cterm_of thy pi1), SOME (Thm.global_cterm_of thy pi2), SOME (Thm.global_cterm_of thy t)]
   44.19              (mk_meta_eq (Global_Theory.get_thm thy ("cp_"^tname'^"_"^uname'^"_inst") RS 
   44.20               cp1_aux)))
   44.21        else NONE
   44.22 @@ -296,7 +296,7 @@
   44.23        case Envir.eta_contract (Logic.strip_assums_concl (Thm.term_of goal)) of
   44.24            _ $ (Const (@{const_name finite}, _) $ (Const (@{const_name Nominal.supp}, T) $ x)) =>
   44.25            let
   44.26 -            val cert = Thm.cterm_of (Thm.theory_of_thm st);
   44.27 +            val cert = Thm.global_cterm_of (Thm.theory_of_thm st);
   44.28              val ps = Logic.strip_params (Thm.term_of goal);
   44.29              val Ts = rev (map snd ps);
   44.30              val vs = collect_vars 0 x [];
   44.31 @@ -340,7 +340,7 @@
   44.32        case Logic.strip_assums_concl (Thm.term_of goal) of
   44.33            _ $ (Const (@{const_name Nominal.fresh}, Type ("fun", [T, _])) $ _ $ t) => 
   44.34            let
   44.35 -            val cert = Thm.cterm_of (Thm.theory_of_thm st);
   44.36 +            val cert = Thm.global_cterm_of (Thm.theory_of_thm st);
   44.37              val ps = Logic.strip_params (Thm.term_of goal);
   44.38              val Ts = rev (map snd ps);
   44.39              val vs = collect_vars 0 t [];
    45.1 --- a/src/HOL/Nominal/nominal_primrec.ML	Fri Mar 06 14:01:08 2015 +0100
    45.2 +++ b/src/HOL/Nominal/nominal_primrec.ML	Fri Mar 06 15:58:56 2015 +0100
    45.3 @@ -281,7 +281,7 @@
    45.4      val qualify = Binding.qualify false
    45.5        (space_implode "_" (map (Long_Name.base_name o #1) defs));
    45.6      val names_atts' = map (apfst qualify) names_atts;
    45.7 -    val cert = Proof_Context.cterm_of lthy';
    45.8 +    val cert = Thm.cterm_of lthy';
    45.9  
   45.10      fun mk_idx eq =
   45.11        let
    46.1 --- a/src/HOL/Nominal/nominal_thmdecls.ML	Fri Mar 06 14:01:08 2015 +0100
    46.2 +++ b/src/HOL/Nominal/nominal_thmdecls.ML	Fri Mar 06 15:58:56 2015 +0100
    46.3 @@ -53,9 +53,9 @@
    46.4  fun prove_eqvt_tac ctxt orig_thm pi pi' =
    46.5    let
    46.6      val thy = Proof_Context.theory_of ctxt
    46.7 -    val mypi = Thm.cterm_of thy pi
    46.8 +    val mypi = Thm.global_cterm_of thy pi
    46.9      val T = fastype_of pi'
   46.10 -    val mypifree = Thm.cterm_of thy (Const (@{const_name "rev"}, T --> T) $ pi')
   46.11 +    val mypifree = Thm.global_cterm_of thy (Const (@{const_name "rev"}, T --> T) $ pi')
   46.12      val perm_pi_simp = Global_Theory.get_thms thy "perm_pi_simp"
   46.13    in
   46.14      EVERY1 [tactic ctxt ("iffI applied", rtac @{thm iffI}),
    47.1 --- a/src/HOL/Num.thy	Fri Mar 06 14:01:08 2015 +0100
    47.2 +++ b/src/HOL/Num.thy	Fri Mar 06 15:58:56 2015 +0100
    47.3 @@ -1198,7 +1198,7 @@
    47.4    fun number_of thy T n =
    47.5      if not (Sign.of_sort thy (T, @{sort numeral}))
    47.6      then raise CTERM ("number_of", [])
    47.7 -    else Numeral.mk_cnumber (Thm.ctyp_of thy T) n;
    47.8 +    else Numeral.mk_cnumber (Thm.global_ctyp_of thy T) n;
    47.9  in
   47.10    K (
   47.11      Lin_Arith.add_simps (@{thms arith_simps} @ @{thms more_arith_simps}
    48.1 --- a/src/HOL/Probability/measurable.ML	Fri Mar 06 14:01:08 2015 +0100
    48.2 +++ b/src/HOL/Probability/measurable.ML	Fri Mar 06 15:58:56 2015 +0100
    48.3 @@ -251,7 +251,7 @@
    48.4            val f = dest_measurable_fun (HOLogic.dest_Trueprop t)
    48.5            fun cert f = map (Option.map (f (Proof_Context.theory_of ctxt)))
    48.6            fun inst (ts, Ts) =
    48.7 -            Drule.instantiate' (cert Thm.ctyp_of Ts) (cert Thm.cterm_of ts)
    48.8 +            Drule.instantiate' (cert Thm.global_ctyp_of Ts) (cert Thm.global_cterm_of ts)
    48.9                @{thm measurable_compose_countable}
   48.10          in r_tac "split countable" (cnt_prefixes ctxt f |> map inst) i end
   48.11          handle TERM _ => no_tac) 1)
    49.1 --- a/src/HOL/Proofs/Lambda/WeakNorm.thy	Fri Mar 06 14:01:08 2015 +0100
    49.2 +++ b/src/HOL/Proofs/Lambda/WeakNorm.thy	Fri Mar 06 15:58:56 2015 +0100
    49.3 @@ -433,11 +433,11 @@
    49.4  
    49.5  val ct1 = @{cterm "%f. ((%f x. f (f (f x))) ((%f x. f (f (f (f x)))) f))"};
    49.6  val (dB1, _) = @{code type_NF} (typing_of_term [] dummyf (Thm.term_of ct1));
    49.7 -val ct1' = Thm.cterm_of @{theory} (term_of_dB [] (Thm.typ_of_cterm ct1) dB1);
    49.8 +val ct1' = Thm.global_cterm_of @{theory} (term_of_dB [] (Thm.typ_of_cterm ct1) dB1);
    49.9  
   49.10  val ct2 = @{cterm "%f x. (%x. f x x) ((%x. f x x) ((%x. f x x) ((%x. f x x) ((%x. f x x) ((%x. f x x) x)))))"};
   49.11  val (dB2, _) = @{code type_NF} (typing_of_term [] dummyf (Thm.term_of ct2));
   49.12 -val ct2' = Thm.cterm_of @{theory} (term_of_dB [] (Thm.typ_of_cterm ct2) dB2);
   49.13 +val ct2' = Thm.global_cterm_of @{theory} (term_of_dB [] (Thm.typ_of_cterm ct2) dB2);
   49.14  *}
   49.15  
   49.16  end
    50.1 --- a/src/HOL/Statespace/distinct_tree_prover.ML	Fri Mar 06 14:01:08 2015 +0100
    50.2 +++ b/src/HOL/Statespace/distinct_tree_prover.ML	Fri Mar 06 15:58:56 2015 +0100
    50.3 @@ -95,7 +95,7 @@
    50.4      fun mapT_and_recertify ct =
    50.5        let
    50.6          val thy = Thm.theory_of_cterm ct;
    50.7 -      in (Thm.cterm_of thy (Term.map_types (Term.map_type_tvar substT) (Thm.term_of ct))) end;
    50.8 +      in (Thm.global_cterm_of thy (Term.map_types (Term.map_type_tvar substT) (Thm.term_of ct))) end;
    50.9      val insts' = map (apfst mapT_and_recertify) insts;
   50.10    in Thm.instantiate (instTs, insts') end;
   50.11  
   50.12 @@ -150,10 +150,10 @@
   50.13  
   50.14      val tyinsts' =
   50.15        map (fn (v, (S, U)) =>
   50.16 -        (Thm.ctyp_of thy (TVar (v, S)), Thm.ctyp_of thy U)) tyinsts;
   50.17 +        (Thm.global_ctyp_of thy (TVar (v, S)), Thm.global_ctyp_of thy U)) tyinsts;
   50.18      val insts' =
   50.19        map (fn (idxn, ct) =>
   50.20 -        (Thm.cterm_of thy (Var (idxn, Thm.typ_of_cterm ct)), ct)) insts;
   50.21 +        (Thm.global_cterm_of thy (Var (idxn, Thm.typ_of_cterm ct)), ct)) insts;
   50.22      val rule' = Thm.instantiate (tyinsts', insts') rule;
   50.23    in fold Thm.elim_implies prems rule' end;
   50.24  
   50.25 @@ -298,8 +298,8 @@
   50.26          val [alphaI] = #2 (dest_Type T);
   50.27        in
   50.28          Thm.instantiate
   50.29 -          ([(alpha, Thm.ctyp_of thy alphaI)],
   50.30 -           [(Thm.cterm_of thy (Var (v, treeT alphaI)), ct')]) @{thm subtract_Tip}
   50.31 +          ([(alpha, Thm.global_ctyp_of thy alphaI)],
   50.32 +           [(Thm.global_cterm_of thy (Var (v, treeT alphaI)), ct')]) @{thm subtract_Tip}
   50.33        end
   50.34    | subtractProver (Const (@{const_name Node}, nT) $ l $ x $ d $ r) ct dist_thm =
   50.35        let
    51.1 --- a/src/HOL/Statespace/state_fun.ML	Fri Mar 06 14:01:08 2015 +0100
    51.2 +++ b/src/HOL/Statespace/state_fun.ML	Fri Mar 06 15:58:56 2015 +0100
    51.3 @@ -56,13 +56,13 @@
    51.4        let val thy = Proof_Context.theory_of ctxt in
    51.5          (case t of (Const (@{const_name HOL.conj},_) $ P $ Q) =>
    51.6            let
    51.7 -            val P_P' = Simplifier.rewrite ctxt (Thm.cterm_of thy P);
    51.8 +            val P_P' = Simplifier.rewrite ctxt (Thm.global_cterm_of thy P);
    51.9              val P' = P_P' |> Thm.prop_of |> Logic.dest_equals |> #2;
   51.10            in
   51.11              if isFalse P' then SOME (conj1_False OF [P_P'])
   51.12              else
   51.13                let
   51.14 -                val Q_Q' = Simplifier.rewrite ctxt (Thm.cterm_of thy Q);
   51.15 +                val Q_Q' = Simplifier.rewrite ctxt (Thm.global_cterm_of thy Q);
   51.16                  val Q' = Q_Q' |> Thm.prop_of |> Logic.dest_equals |> #2;
   51.17                in
   51.18                  if isFalse Q' then SOME (conj2_False OF [Q_Q'])
   51.19 @@ -141,7 +141,7 @@
   51.20              | mk_upds s = (Var (("s", mi + 1), sT), mi + 2);
   51.21  
   51.22            val ct =
   51.23 -            Thm.cterm_of thy (Const (@{const_name StateFun.lookup}, lT) $ destr $ n $ fst (mk_upds s));
   51.24 +            Thm.global_cterm_of thy (Const (@{const_name StateFun.lookup}, lT) $ destr $ n $ fst (mk_upds s));
   51.25            val basic_ss = #1 (Data.get (Context.Proof ctxt));
   51.26            val ctxt' = ctxt |> Config.put simp_depth_limit 100 |> put_simpset basic_ss;
   51.27            val thm = Simplifier.rewrite ctxt' ct;
    52.1 --- a/src/HOL/String.thy	Fri Mar 06 14:01:08 2015 +0100
    52.2 +++ b/src/HOL/String.thy	Fri Mar 06 15:58:56 2015 +0100
    52.3 @@ -248,7 +248,7 @@
    52.4  
    52.5  setup {*
    52.6  let
    52.7 -  val nibbles = map_range (Thm.cterm_of @{theory} o HOLogic.mk_nibble) 16;
    52.8 +  val nibbles = map_range (Thm.global_cterm_of @{theory} o HOLogic.mk_nibble) 16;
    52.9    val simpset =
   52.10      put_simpset HOL_ss @{context}
   52.11        addsimps @{thms nat_of_nibble.simps mult_0 mult_1 add_0 add_0_right arith_simps numeral_plus_one};
    53.1 --- a/src/HOL/TPTP/TPTP_Parser/tptp_reconstruct_library.ML	Fri Mar 06 14:01:08 2015 +0100
    53.2 +++ b/src/HOL/TPTP/TPTP_Parser/tptp_reconstruct_library.ML	Fri Mar 06 15:58:56 2015 +0100
    53.3 @@ -572,14 +572,14 @@
    53.4        diff thy (scheme_t, instance_t)
    53.5  
    53.6      (*valuation of type variables*)
    53.7 -    val typeval = map (apply2 (Thm.ctyp_of thy)) type_pairing
    53.8 +    val typeval = map (apply2 (Thm.global_ctyp_of thy)) type_pairing
    53.9  
   53.10      val typeval_env =
   53.11        map (apfst dest_TVar) type_pairing
   53.12      (*valuation of term variables*)
   53.13      val termval =
   53.14        map (apfst (type_devar typeval_env)) term_pairing
   53.15 -      |> map (apply2 (Thm.cterm_of thy))
   53.16 +      |> map (apply2 (Thm.global_cterm_of thy))
   53.17    in
   53.18      Thm.instantiate (typeval, termval) scheme_thm
   53.19    end
    54.1 --- a/src/HOL/TPTP/TPTP_Proof_Reconstruction.thy	Fri Mar 06 14:01:08 2015 +0100
    54.2 +++ b/src/HOL/TPTP/TPTP_Proof_Reconstruction.thy	Fri Mar 06 15:58:56 2015 +0100
    54.3 @@ -917,7 +917,7 @@
    54.4      (* val contextualise = fold absdummy (map snd params) *)
    54.5      val contextualise = fold absfree params
    54.6  
    54.7 -    val skolem_cts = map (contextualise #> Thm.cterm_of thy) skolem_terms
    54.8 +    val skolem_cts = map (contextualise #> Thm.global_cterm_of thy) skolem_terms
    54.9  
   54.10  
   54.11  (*now the instantiation code*)
   54.12 @@ -937,7 +937,7 @@
   54.13          fun make_var pre_var =
   54.14            the_single pre_var
   54.15            |> Var
   54.16 -          |> Thm.cterm_of thy
   54.17 +          |> Thm.global_cterm_of thy
   54.18            |> SOME
   54.19        in
   54.20          if null pre_var then NONE
   54.21 @@ -2003,7 +2003,7 @@
   54.22       thy
   54.23       prob_name (#meta pannot) n
   54.24        |> the
   54.25 -      |> (fn {inference_fmla, ...} => Thm.cterm_of thy inference_fmla)
   54.26 +      |> (fn {inference_fmla, ...} => Thm.global_cterm_of thy inference_fmla)
   54.27        |> oracle_iinterp
   54.28    end
   54.29  *}
    55.1 --- a/src/HOL/Tools/ATP/atp_problem_generate.ML	Fri Mar 06 14:01:08 2015 +0100
    55.2 +++ b/src/HOL/Tools/ATP/atp_problem_generate.ML	Fri Mar 06 15:58:56 2015 +0100
    55.3 @@ -760,7 +760,7 @@
    55.4  fun do_introduce_combinators ctxt Ts t =
    55.5    let val thy = Proof_Context.theory_of ctxt in
    55.6      t |> conceal_bounds Ts
    55.7 -      |> Thm.cterm_of thy
    55.8 +      |> Thm.global_cterm_of thy
    55.9        |> Meson_Clausify.introduce_combinators_in_cterm
   55.10        |> Thm.prop_of |> Logic.dest_equals |> snd
   55.11        |> reveal_bounds Ts
    56.1 --- a/src/HOL/Tools/ATP/atp_util.ML	Fri Mar 06 14:01:08 2015 +0100
    56.2 +++ b/src/HOL/Tools/ATP/atp_util.ML	Fri Mar 06 15:58:56 2015 +0100
    56.3 @@ -353,7 +353,7 @@
    56.4  fun abs_extensionalize_term ctxt t =
    56.5    if exists_Const is_fun_equality t then
    56.6      let val thy = Proof_Context.theory_of ctxt in
    56.7 -      t |> Thm.cterm_of thy |> Meson.abs_extensionalize_conv ctxt
    56.8 +      t |> Thm.global_cterm_of thy |> Meson.abs_extensionalize_conv ctxt
    56.9          |> Thm.prop_of |> Logic.dest_equals |> snd
   56.10      end
   56.11    else
    57.1 --- a/src/HOL/Tools/BNF/bnf_def.ML	Fri Mar 06 14:01:08 2015 +0100
    57.2 +++ b/src/HOL/Tools/BNF/bnf_def.ML	Fri Mar 06 15:58:56 2015 +0100
    57.3 @@ -1227,11 +1227,11 @@
    57.4                  val funTs = map (fn T => bdT --> T) ranTs;
    57.5                  val ran_bnfT = mk_bnf_T ranTs Calpha;
    57.6                  val (revTs, Ts) = `rev (bd_bnfT :: funTs);
    57.7 -                val cTs = map (SOME o Proof_Context.ctyp_of lthy) [ran_bnfT, Library.foldr1 HOLogic.mk_prodT Ts];
    57.8 +                val cTs = map (SOME o Thm.ctyp_of lthy) [ran_bnfT, Library.foldr1 HOLogic.mk_prodT Ts];
    57.9                  val tinst = fold (fn T => fn t => HOLogic.mk_split (Term.absdummy T t)) (tl revTs)
   57.10                    (Term.absdummy (hd revTs) (Term.list_comb (mk_bnf_map bdTs ranTs,
   57.11                      map Bound (live - 1 downto 0)) $ Bound live));
   57.12 -                val cts = [NONE, SOME (Proof_Context.cterm_of lthy tinst)];
   57.13 +                val cts = [NONE, SOME (Thm.cterm_of lthy tinst)];
   57.14                in
   57.15                  Drule.instantiate' cTs cts @{thm surj_imp_ordLeq}
   57.16                end);
   57.17 @@ -1346,7 +1346,7 @@
   57.18          fun mk_rel_flip () =
   57.19            let
   57.20              val rel_conversep_thm = Lazy.force rel_conversep;
   57.21 -            val cts = map (SOME o Proof_Context.cterm_of lthy) Rs;
   57.22 +            val cts = map (SOME o Thm.cterm_of lthy) Rs;
   57.23              val rel_conversep_thm' = cterm_instantiate_pos cts rel_conversep_thm;
   57.24            in
   57.25              unfold_thms lthy @{thms conversep_iff} (rel_conversep_thm' RS @{thm predicate2_eqD})
    58.1 --- a/src/HOL/Tools/BNF/bnf_fp_def_sugar.ML	Fri Mar 06 14:01:08 2015 +0100
    58.2 +++ b/src/HOL/Tools/BNF/bnf_fp_def_sugar.ML	Fri Mar 06 15:58:56 2015 +0100
    58.3 @@ -476,7 +476,7 @@
    58.4    let
    58.5      val Rs = Term.add_vars (Thm.prop_of thm) [];
    58.6      val Rs' = rev (drop (length Rs - n) Rs);
    58.7 -    val cRs = map (fn f => (Proof_Context.cterm_of lthy (Var f), Proof_Context.cterm_of lthy (mk_flip f))) Rs';
    58.8 +    val cRs = map (fn f => (Thm.cterm_of lthy (Var f), Thm.cterm_of lthy (mk_flip f))) Rs';
    58.9    in
   58.10      Drule.cterm_instantiate cRs thm
   58.11    end;
   58.12 @@ -598,14 +598,14 @@
   58.13            Drule.dummy_thm
   58.14          else
   58.15            let val ctor' = mk_ctor Bs ctor in
   58.16 -            cterm_instantiate_pos [NONE, NONE, SOME (Proof_Context.cterm_of lthy ctor')] arg_cong
   58.17 +            cterm_instantiate_pos [NONE, NONE, SOME (Thm.cterm_of lthy ctor')] arg_cong
   58.18            end;
   58.19  
   58.20        fun mk_cIn ctor k xs =
   58.21          let val absT = domain_type (fastype_of ctor) in
   58.22            mk_absumprod absT abs n k xs
   58.23            |> fp = Greatest_FP ? curry (op $) ctor
   58.24 -          |> Proof_Context.cterm_of lthy
   58.25 +          |> Thm.cterm_of lthy
   58.26          end;
   58.27  
   58.28        val cxIns = map2 (mk_cIn ctor) ks xss;
   58.29 @@ -615,7 +615,7 @@
   58.30          fold_thms lthy [ctr_def']
   58.31            (unfold_thms lthy (o_apply :: pre_map_def ::
   58.32                 (if fp = Least_FP then [] else [dtor_ctor]) @ sumprod_thms_map @ abs_inverses)
   58.33 -             (cterm_instantiate_pos (map (SOME o Proof_Context.cterm_of lthy) fs @ [SOME cxIn])
   58.34 +             (cterm_instantiate_pos (map (SOME o Thm.cterm_of lthy) fs @ [SOME cxIn])
   58.35                  (if fp = Least_FP then fp_map_thm
   58.36                   else fp_map_thm RS ctor_cong RS (ctor_dtor RS sym RS trans))))
   58.37          |> singleton (Proof_Context.export names_lthy lthy);
   58.38 @@ -643,7 +643,7 @@
   58.39            (unfold_thms lthy (pre_rel_def :: abs_inverses @
   58.40                 (if fp = Least_FP then [] else [dtor_ctor]) @ sumprod_thms_rel @
   58.41                 @{thms vimage2p_def sum.inject sum.distinct(1)[THEN eq_False[THEN iffD2]]})
   58.42 -             (cterm_instantiate_pos (map (SOME o Proof_Context.cterm_of lthy) Rs @ [SOME cxIn, SOME cyIn])
   58.43 +             (cterm_instantiate_pos (map (SOME o Thm.cterm_of lthy) Rs @ [SOME cxIn, SOME cyIn])
   58.44                  fp_rel_thm))
   58.45          |> postproc
   58.46          |> singleton (Proof_Context.export names_lthy lthy);
   58.47 @@ -734,7 +734,7 @@
   58.48                val goal = Logic.mk_implies (mk_Trueprop_mem (elem, set $ ta), thesis);
   58.49                val thm =
   58.50                  Goal.prove_sorry lthy [] (flat premss) goal (fn {context = ctxt, prems} =>
   58.51 -                  mk_set_cases_tac ctxt (Proof_Context.cterm_of ctxt ta) prems exhaust set_thms)
   58.52 +                  mk_set_cases_tac ctxt (Thm.cterm_of ctxt ta) prems exhaust set_thms)
   58.53                  |> singleton (Proof_Context.export names_lthy lthy)
   58.54                  |> Thm.close_derivation
   58.55                  |> rotate_prems ~1;
   58.56 @@ -812,7 +812,7 @@
   58.57  
   58.58            fun prove goal =
   58.59              Goal.prove_sorry lthy [] [] goal (fn {context = ctxt, prems = _} =>
   58.60 -              mk_rel_sel_tac ctxt (Proof_Context.cterm_of ctxt ta) (Proof_Context.cterm_of ctxt tb) exhaust (flat disc_thmss)
   58.61 +              mk_rel_sel_tac ctxt (Thm.cterm_of ctxt ta) (Thm.cterm_of ctxt tb) exhaust (flat disc_thmss)
   58.62                  (flat sel_thmss) rel_inject_thms distincts rel_distinct_thms live_nesting_rel_eqs)
   58.63              |> singleton (Proof_Context.export names_lthy lthy)
   58.64              |> Thm.close_derivation;
   58.65 @@ -846,7 +846,7 @@
   58.66            val goal = Logic.list_implies (HOLogic.mk_Trueprop rel_Rs_a_b :: assms, thesis);
   58.67            val thm =
   58.68              Goal.prove_sorry lthy [] [] goal (fn {context = ctxt, prems = _} =>
   58.69 -              mk_rel_cases_tac ctxt (Proof_Context.cterm_of ctxt ta) (Proof_Context.cterm_of ctxt tb) exhaust injects
   58.70 +              mk_rel_cases_tac ctxt (Thm.cterm_of ctxt ta) (Thm.cterm_of ctxt tb) exhaust injects
   58.71                  rel_inject_thms distincts rel_distinct_thms live_nesting_rel_eqs)
   58.72              |> singleton (Proof_Context.export names_lthy lthy)
   58.73              |> Thm.close_derivation;
   58.74 @@ -920,7 +920,7 @@
   58.75            else
   58.76              Goal.prove_sorry lthy [] [] (Logic.mk_conjunction_balanced goals)
   58.77                (fn {context = ctxt, prems = _} =>
   58.78 -                 mk_map_disc_iff_tac ctxt (Proof_Context.cterm_of ctxt ta) exhaust (flat disc_thmss) map_thms)
   58.79 +                 mk_map_disc_iff_tac ctxt (Thm.cterm_of ctxt ta) exhaust (flat disc_thmss) map_thms)
   58.80              |> Conjunction.elim_balanced (length goals)
   58.81              |> Proof_Context.export names_lthy lthy
   58.82              |> map Thm.close_derivation
   58.83 @@ -954,7 +954,7 @@
   58.84               else
   58.85                 Goal.prove_sorry lthy [] [] (Logic.mk_conjunction_balanced goals)
   58.86                   (fn {context = ctxt, prems = _} =>
   58.87 -                    mk_map_sel_tac ctxt (Proof_Context.cterm_of ctxt ta) exhaust (flat disc_thmss) map_thms
   58.88 +                    mk_map_sel_tac ctxt (Thm.cterm_of ctxt ta) exhaust (flat disc_thmss) map_thms
   58.89                        (flat sel_thmss) live_nesting_map_id0s)
   58.90                 |> Conjunction.elim_balanced (length goals)
   58.91                 |> Proof_Context.export names_lthy lthy
   58.92 @@ -1013,7 +1013,7 @@
   58.93               else
   58.94                 Goal.prove_sorry lthy [] [] (Logic.mk_conjunction_balanced goals)
   58.95                   (fn {context = ctxt, prems = _} =>
   58.96 -                    mk_set_sel_tac ctxt (Proof_Context.cterm_of ctxt ta) exhaust (flat disc_thmss)
   58.97 +                    mk_set_sel_tac ctxt (Thm.cterm_of ctxt ta) exhaust (flat disc_thmss)
   58.98                        (flat sel_thmss) set0_thms)
   58.99                 |> Conjunction.elim_balanced (length goals)
  58.100                 |> Proof_Context.export names_lthy lthy
  58.101 @@ -1302,7 +1302,7 @@
  58.102  
  58.103      val rel_induct0_thm =
  58.104        Goal.prove_sorry lthy [] prems goal (fn {context = ctxt, prems} =>
  58.105 -        mk_rel_induct0_tac ctxt ctor_rel_induct prems (map (Proof_Context.cterm_of ctxt) IRs) exhausts ctor_defss
  58.106 +        mk_rel_induct0_tac ctxt ctor_rel_induct prems (map (Thm.cterm_of ctxt) IRs) exhausts ctor_defss
  58.107            ctor_injects pre_rel_defs abs_inverses live_nesting_rel_eqs)
  58.108        |> singleton (Proof_Context.export names_lthy lthy)
  58.109        |> Thm.close_derivation;
  58.110 @@ -1560,7 +1560,7 @@
  58.111  
  58.112      val rel_coinduct0_thm =
  58.113        Goal.prove_sorry lthy [] prems goal (fn {context = ctxt, prems} =>
  58.114 -        mk_rel_coinduct0_tac ctxt dtor_rel_coinduct (map (Proof_Context.cterm_of ctxt) IRs) prems
  58.115 +        mk_rel_coinduct0_tac ctxt dtor_rel_coinduct (map (Thm.cterm_of ctxt) IRs) prems
  58.116            (map #exhaust ctr_sugars) (map (flat o #disc_thmss) ctr_sugars)
  58.117            (map (flat o #sel_thmss) ctr_sugars) ctor_defss dtor_ctors ctor_injects abs_injects
  58.118            rel_pre_defs abs_inverses live_nesting_rel_eqs)
  58.119 @@ -1644,7 +1644,7 @@
  58.120          val thm =
  58.121            Goal.prove_sorry lthy [] prems (HOLogic.mk_Trueprop concl)
  58.122              (fn {context = ctxt, prems} =>
  58.123 -               mk_set_induct0_tac ctxt (map (Proof_Context.cterm_of ctxt'') Ps) prems dtor_set_inducts exhausts
  58.124 +               mk_set_induct0_tac ctxt (map (Thm.cterm_of ctxt'') Ps) prems dtor_set_inducts exhausts
  58.125                   set_pre_defs ctor_defs dtor_ctors Abs_pre_inverses)
  58.126            |> singleton (Proof_Context.export ctxt'' ctxt)
  58.127            |> Thm.close_derivation;
  58.128 @@ -1819,7 +1819,7 @@
  58.129  
  58.130          val goalss = @{map 6} (map2 oooo mk_goal) cs cpss gcorecs ns kss discss;
  58.131  
  58.132 -        fun mk_case_split' cp = Drule.instantiate' [] [SOME (Proof_Context.cterm_of lthy cp)] @{thm case_split};
  58.133 +        fun mk_case_split' cp = Drule.instantiate' [] [SOME (Thm.cterm_of lthy cp)] @{thm case_split};
  58.134  
  58.135          val case_splitss' = map (map mk_case_split') cpss;
  58.136  
  58.137 @@ -1845,8 +1845,8 @@
  58.138        let
  58.139          val (domT, ranT) = dest_funT (fastype_of sel);
  58.140          val arg_cong' =
  58.141 -          Drule.instantiate' (map (SOME o Proof_Context.ctyp_of lthy) [domT, ranT])
  58.142 -            [NONE, NONE, SOME (Proof_Context.cterm_of lthy sel)] arg_cong
  58.143 +          Drule.instantiate' (map (SOME o Thm.ctyp_of lthy) [domT, ranT])
  58.144 +            [NONE, NONE, SOME (Thm.cterm_of lthy sel)] arg_cong
  58.145            |> Thm.varifyT_global;
  58.146          val sel_thm' = sel_thm RSN (2, trans);
  58.147        in
  58.148 @@ -2141,8 +2141,8 @@
  58.149                          (mk_Trueprop_eq (HOLogic.mk_eq (u, ctor $ w), HOLogic.mk_eq (dtor $ u, w)));
  58.150                    in
  58.151                      Goal.prove_sorry lthy [] [] goal (fn {context = ctxt, ...} =>
  58.152 -                      mk_ctor_iff_dtor_tac ctxt (map (SOME o Proof_Context.ctyp_of lthy) [ctr_absT, fpT])
  58.153 -                        (Proof_Context.cterm_of lthy ctor) (Proof_Context.cterm_of lthy dtor) ctor_dtor dtor_ctor)
  58.154 +                      mk_ctor_iff_dtor_tac ctxt (map (SOME o Thm.ctyp_of lthy) [ctr_absT, fpT])
  58.155 +                        (Thm.cterm_of lthy ctor) (Thm.cterm_of lthy dtor) ctor_dtor dtor_ctor)
  58.156                      |> Morphism.thm phi
  58.157                      |> Thm.close_derivation
  58.158                    end;
  58.159 @@ -2233,7 +2233,7 @@
  58.160        let val (Rs, Ss, goals, names_lthy) = mk_co_rec_transfer_goals lthy recs in
  58.161          Goal.prove_sorry lthy [] [] (Logic.mk_conjunction_balanced goals)
  58.162            (fn {context = ctxt, prems = _} =>
  58.163 -             mk_rec_transfer_tac ctxt nn ns (map (Proof_Context.cterm_of ctxt) Ss) (map (Proof_Context.cterm_of ctxt) Rs) xsssss
  58.164 +             mk_rec_transfer_tac ctxt nn ns (map (Thm.cterm_of ctxt) Ss) (map (Thm.cterm_of ctxt) Rs) xsssss
  58.165                 rec_defs xtor_co_rec_transfers pre_rel_defs live_nesting_rel_eqs)
  58.166          |> Conjunction.elim_balanced nn
  58.167          |> Proof_Context.export names_lthy lthy
  58.168 @@ -2385,7 +2385,7 @@
  58.169        in
  58.170          Goal.prove_sorry lthy [] [] (Logic.mk_conjunction_balanced goals)
  58.171            (fn {context = ctxt, prems = _} =>
  58.172 -             mk_corec_transfer_tac ctxt (map (Proof_Context.cterm_of ctxt) Ss) (map (Proof_Context.cterm_of ctxt) Rs)
  58.173 +             mk_corec_transfer_tac ctxt (map (Thm.cterm_of ctxt) Ss) (map (Thm.cterm_of ctxt) Rs)
  58.174                 type_definitions corec_defs xtor_co_rec_transfers pre_rel_defs
  58.175                 live_nesting_rel_eqs (flat pgss) pss qssss gssss)
  58.176          |> Conjunction.elim_balanced (length goals)
    59.1 --- a/src/HOL/Tools/BNF/bnf_fp_def_sugar_tactics.ML	Fri Mar 06 14:01:08 2015 +0100
    59.2 +++ b/src/HOL/Tools/BNF/bnf_fp_def_sugar_tactics.ML	Fri Mar 06 15:58:56 2015 +0100
    59.3 @@ -97,7 +97,7 @@
    59.4      val fs = Term.add_vars (Thm.prop_of thm) []
    59.5        |> filter (fn (_, Type (@{type_name fun}, [_, T'])) => T' <> HOLogic.boolT | _ => false);
    59.6      fun mk_cfp (f as (_, T)) =
    59.7 -      (Proof_Context.cterm_of ctxt (Var f), Proof_Context.cterm_of ctxt (mk_proj T (num_binder_types T) k));
    59.8 +      (Thm.cterm_of ctxt (Var f), Thm.cterm_of ctxt (mk_proj T (num_binder_types T) k));
    59.9      val cfps = map mk_cfp fs;
   59.10    in
   59.11      Drule.cterm_instantiate cfps thm
    60.1 --- a/src/HOL/Tools/BNF/bnf_fp_n2m.ML	Fri Mar 06 14:01:08 2015 +0100
    60.2 +++ b/src/HOL/Tools/BNF/bnf_fp_n2m.ML	Fri Mar 06 15:58:56 2015 +0100
    60.3 @@ -191,7 +191,7 @@
    60.4            case_fp fp (snd o Term.dest_comb) (snd o Term.dest_comb o fst o Term.dest_comb);
    60.5          val raw_phis = map (extract o HOLogic.dest_Trueprop o Thm.concl_of) rel_xtor_co_inducts;
    60.6          val thetas = AList.group (op =)
    60.7 -          (mutual_cliques ~~ map (apply2 (Proof_Context.cterm_of lthy)) (raw_phis ~~ pre_phis));
    60.8 +          (mutual_cliques ~~ map (apply2 (Thm.cterm_of lthy)) (raw_phis ~~ pre_phis));
    60.9        in
   60.10          map2 (Drule.cterm_instantiate o the o AList.lookup (op =) thetas)
   60.11          mutual_cliques rel_xtor_co_inducts
   60.12 @@ -214,7 +214,7 @@
   60.13              fun mk_Grp_id P =
   60.14                let val T = domain_type (fastype_of P);
   60.15                in mk_Grp (HOLogic.Collect_const T $ P) (HOLogic.id_const T) end;
   60.16 -            val cts = map (SOME o Proof_Context.cterm_of lthy) (map HOLogic.eq_const As @ map mk_Grp_id Ps);
   60.17 +            val cts = map (SOME o Thm.cterm_of lthy) (map HOLogic.eq_const As @ map mk_Grp_id Ps);
   60.18              fun mk_fp_type_copy_thms thm = map (curry op RS thm)
   60.19                @{thms type_copy_Abs_o_Rep type_copy_vimage2p_Grp_Rep};
   60.20              fun mk_type_copy_thms thm = map (curry op RS thm)
   60.21 @@ -235,7 +235,7 @@
   60.22            end
   60.23        | Greatest_FP =>
   60.24            let
   60.25 -            val cts = NONE :: map (SOME o Proof_Context.cterm_of lthy) (map HOLogic.eq_const As);
   60.26 +            val cts = NONE :: map (SOME o Thm.cterm_of lthy) (map HOLogic.eq_const As);
   60.27            in
   60.28              cterm_instantiate_pos cts xtor_rel_co_induct
   60.29              |> unfold_thms lthy (@{thms le_fun_def le_bool_def all_simps(1,2)[symmetric]} @
    61.1 --- a/src/HOL/Tools/BNF/bnf_fp_rec_sugar_transfer.ML	Fri Mar 06 14:01:08 2015 +0100
    61.2 +++ b/src/HOL/Tools/BNF/bnf_fp_rec_sugar_transfer.ML	Fri Mar 06 15:58:56 2015 +0100
    61.3 @@ -44,7 +44,7 @@
    61.4          val else_branch = Var (("e", j), T);
    61.5          val lam = Term.lambda cond (mk_If cond then_branch else_branch);
    61.6        in
    61.7 -        cterm_instantiate_pos [SOME (Proof_Context.cterm_of ctxt lam)] thm
    61.8 +        cterm_instantiate_pos [SOME (Thm.cterm_of ctxt lam)] thm
    61.9        end;
   61.10  
   61.11      val transfer_rules =
    62.1 --- a/src/HOL/Tools/BNF/bnf_fp_util.ML	Fri Mar 06 14:01:08 2015 +0100
    62.2 +++ b/src/HOL/Tools/BNF/bnf_fp_util.ML	Fri Mar 06 15:58:56 2015 +0100
    62.3 @@ -469,7 +469,7 @@
    62.4        val T = mk_tupleT_balanced tfrees;
    62.5      in
    62.6        @{thm asm_rl[of "ALL x. P x --> Q x" for P Q]}
    62.7 -      |> Drule.instantiate' [SOME (Thm.ctyp_of @{theory} T)] []
    62.8 +      |> Drule.instantiate' [SOME (Thm.global_ctyp_of @{theory} T)] []
    62.9        |> Raw_Simplifier.rewrite_goals_rule @{context} @{thms split_paired_All[THEN eq_reflection]}
   62.10        |> (fn thm => impI RS funpow n (fn th => allI RS th) thm)
   62.11        |> Thm.varifyT_global
   62.12 @@ -578,7 +578,7 @@
   62.13      val n = Thm.nprems_of coind;
   62.14      val m = Thm.nprems_of (hd rel_monos) - n;
   62.15      fun mk_inst phi = (phi, mk_union (phi, HOLogic.eq_const (fst (dest_pred2T (fastype_of phi)))))
   62.16 -      |> apply2 (Proof_Context.cterm_of ctxt);
   62.17 +      |> apply2 (Thm.cterm_of ctxt);
   62.18      val insts = Term.add_vars (Thm.prop_of coind) [] |> rev |> take n |> map (mk_inst o Var);
   62.19      fun mk_unfold rel_eq rel_mono =
   62.20        let
    63.1 --- a/src/HOL/Tools/BNF/bnf_gfp.ML	Fri Mar 06 14:01:08 2015 +0100
    63.2 +++ b/src/HOL/Tools/BNF/bnf_gfp.ML	Fri Mar 06 15:58:56 2015 +0100
    63.3 @@ -1080,7 +1080,7 @@
    63.4          val goal = list_all_free (kl :: zs)
    63.5            (Library.foldr1 HOLogic.mk_conj (map2 mk_conjunct ks zs));
    63.6  
    63.7 -        val cts = map (SOME o Proof_Context.cterm_of lthy) [Term.absfree nat' goal, nat];
    63.8 +        val cts = map (SOME o Thm.cterm_of lthy) [Term.absfree nat' goal, nat];
    63.9  
   63.10          val length_Lev =
   63.11            Goal.prove_sorry lthy [] [] (HOLogic.mk_Trueprop goal)
   63.12 @@ -1115,8 +1115,8 @@
   63.13              Library.foldr1 HOLogic.mk_conj
   63.14                (map2 (mk_conjunct i z) ks zs_copy)) ks zs));
   63.15  
   63.16 -        val cTs = [SOME (Proof_Context.ctyp_of lthy sum_sbdT)];
   63.17 -        val cts = map (SOME o Proof_Context.cterm_of lthy) [Term.absfree kl' goal, kl];
   63.18 +        val cTs = [SOME (Thm.ctyp_of lthy sum_sbdT)];
   63.19 +        val cts = map (SOME o Thm.cterm_of lthy) [Term.absfree kl' goal, kl];
   63.20  
   63.21          val rv_last =
   63.22            Goal.prove_sorry lthy [] [] (HOLogic.mk_Trueprop goal)
   63.23 @@ -1153,7 +1153,7 @@
   63.24          val goal = list_all_free (kl :: zs @ zs_copy @ zs_copy2)
   63.25            (Library.foldr1 HOLogic.mk_conj (map2 mk_conjunct ks zs));
   63.26  
   63.27 -        val cts = map (SOME o Proof_Context.cterm_of lthy) [Term.absfree nat' goal, nat];
   63.28 +        val cts = map (SOME o Thm.cterm_of lthy) [Term.absfree nat' goal, nat];
   63.29  
   63.30          val set_Lev =
   63.31            Goal.prove_sorry lthy [] [] (HOLogic.mk_Trueprop goal)
   63.32 @@ -1192,7 +1192,7 @@
   63.33          val goal = list_all_free (kl :: k :: zs @ zs_copy)
   63.34            (Library.foldr1 HOLogic.mk_conj (map2 mk_conjunct ks zs));
   63.35  
   63.36 -        val cts = map (SOME o Proof_Context.cterm_of lthy) [Term.absfree nat' goal, nat];
   63.37 +        val cts = map (SOME o Thm.cterm_of lthy) [Term.absfree nat' goal, nat];
   63.38  
   63.39          val set_image_Lev =
   63.40            Goal.prove_sorry lthy [] [] (HOLogic.mk_Trueprop goal)
   63.41 @@ -1867,7 +1867,7 @@
   63.42                    Logic.list_implies (prems, HOLogic.mk_Trueprop concl)) premss concls
   63.43  
   63.44                  val ctss =
   63.45 -                  map (fn phi => map (SOME o Proof_Context.cterm_of lthy) [Term.absfree nat' phi, nat]) concls;
   63.46 +                  map (fn phi => map (SOME o Thm.cterm_of lthy) [Term.absfree nat' phi, nat]) concls;
   63.47                in
   63.48                  @{map 4} (fn goal => fn cts => fn col_0s => fn col_Sucs =>
   63.49                    Goal.prove_sorry lthy [] [] goal
   63.50 @@ -1952,10 +1952,10 @@
   63.51                maps (map (fn thm => thm RS @{thm subset_Collect_iff})) dtor_Jset_incl_thmss @
   63.52                  @{thms subset_Collect_iff[OF subset_refl]};
   63.53  
   63.54 -            val cTs = map (SOME o Proof_Context.ctyp_of lthy) params';
   63.55 +            val cTs = map (SOME o Thm.ctyp_of lthy) params';
   63.56              fun mk_induct_tinst phis jsets y y' =
   63.57                @{map 4} (fn phi => fn jset => fn Jz => fn Jz' =>
   63.58 -                SOME (Proof_Context.cterm_of lthy (Term.absfree Jz' (HOLogic.mk_Collect (fst y', snd y',
   63.59 +                SOME (Thm.cterm_of lthy (Term.absfree Jz' (HOLogic.mk_Collect (fst y', snd y',
   63.60                    HOLogic.mk_conj (HOLogic.mk_mem (y, jset $ Jz), phi $ y $ Jz))))))
   63.61                phis jsets Jzs Jzs';
   63.62            in
   63.63 @@ -2024,7 +2024,7 @@
   63.64              val goals = @{map 3} mk_goal fs colss colss';
   63.65  
   63.66              val ctss =
   63.67 -              map (fn phi => map (SOME o Proof_Context.cterm_of lthy) [Term.absfree nat' phi, nat]) goals;
   63.68 +              map (fn phi => map (SOME o Thm.cterm_of lthy) [Term.absfree nat' phi, nat]) goals;
   63.69  
   63.70              val thms =
   63.71                @{map 4} (fn goal => fn cts => fn rec_0s => fn rec_Sucs =>
   63.72 @@ -2047,7 +2047,7 @@
   63.73  
   63.74              val goals = map (mk_goal Jbds) colss;
   63.75  
   63.76 -            val ctss = map (fn phi => map (SOME o Proof_Context.cterm_of lthy) [Term.absfree nat' phi, nat])
   63.77 +            val ctss = map (fn phi => map (SOME o Thm.cterm_of lthy) [Term.absfree nat' phi, nat])
   63.78                (map (mk_goal (replicate n sbd)) colss);
   63.79  
   63.80              val thms =
   63.81 @@ -2064,7 +2064,7 @@
   63.82  
   63.83          val map_cong0_thms =
   63.84            let
   63.85 -            val cTs = map (SOME o Proof_Context.ctyp_of lthy o
   63.86 +            val cTs = map (SOME o Thm.ctyp_of lthy o
   63.87                Term.typ_subst_atomic (passiveAs ~~ passiveBs) o TFree) coinduct_params;
   63.88  
   63.89              fun mk_prem z set f g y y' =
   63.90 @@ -2086,7 +2086,7 @@
   63.91                HOLogic.mk_exists (x, T, mk_coind_body sets z' z fmap gmap y y_copy)
   63.92                |> Term.absfree y'_copy
   63.93                |> Term.absfree y'
   63.94 -              |> Proof_Context.cterm_of lthy;
   63.95 +              |> Thm.cterm_of lthy;
   63.96  
   63.97              val cphis = @{map 9} mk_cphi
   63.98                Jsetss_by_bnf Jzs' Jzs fs_Jmaps fs_copy_Jmaps Jys' Jys Jys'_copy Jys_copy;
   63.99 @@ -2189,9 +2189,9 @@
  63.100                activeJphis Jzs Jz's_copy Jz's Jmap_snds zip_unfolds;
  63.101            fun mk_cts zs z's phis =
  63.102              @{map 3} (fn z => fn z' => fn phi =>
  63.103 -              SOME (Proof_Context.cterm_of lthy (fold_rev (Term.absfree o Term.dest_Free) [z', z] phi)))
  63.104 +              SOME (Thm.cterm_of lthy (fold_rev (Term.absfree o Term.dest_Free) [z', z] phi)))
  63.105              zs z's phis @
  63.106 -            map (SOME o Proof_Context.cterm_of lthy) (splice z's zs);
  63.107 +            map (SOME o Thm.cterm_of lthy) (splice z's zs);
  63.108            val cts1 = mk_cts Jzs Jzs_copy coind1_phis;
  63.109            val cts2 = mk_cts Jz's Jz's_copy coind2_phis;
  63.110  
  63.111 @@ -2228,9 +2228,9 @@
  63.112              Jphis abs fstABs sndABs;
  63.113            val ctss = map2 (fn ab' => fn phis =>
  63.114                map2 (fn z' => fn phi =>
  63.115 -                SOME (Proof_Context.cterm_of lthy (Term.absfree ab' (Term.absfree z' phi))))
  63.116 +                SOME (Thm.cterm_of lthy (Term.absfree ab' (Term.absfree z' phi))))
  63.117                zip_zs' phis @
  63.118 -              map (SOME o Proof_Context.cterm_of lthy) zip_zs)
  63.119 +              map (SOME o Thm.cterm_of lthy) zip_zs)
  63.120              abs' helper_ind_phiss;
  63.121            fun mk_helper_ind_concl ab' z ind_phi set =
  63.122              mk_Ball (set $ z) (Term.absfree ab' ind_phi);
    64.1 --- a/src/HOL/Tools/BNF/bnf_gfp_rec_sugar_tactics.ML	Fri Mar 06 14:01:08 2015 +0100
    64.2 +++ b/src/HOL/Tools/BNF/bnf_gfp_rec_sugar_tactics.ML	Fri Mar 06 15:58:56 2015 +0100
    64.3 @@ -43,7 +43,7 @@
    64.4      val fs = Term.add_vars (Thm.prop_of thm) [] |> filter (can dest_funT o snd);
    64.5      fun find s = find_index (curry (op =) s) frees;
    64.6      fun mk_cfp (f as ((s, _), T)) =
    64.7 -      (Proof_Context.cterm_of ctxt (Var f), Proof_Context.cterm_of ctxt (mk_proj T num_frees (find s)));
    64.8 +      (Thm.cterm_of ctxt (Var f), Thm.cterm_of ctxt (mk_proj T num_frees (find s)));
    64.9      val cfps = map mk_cfp fs;
   64.10    in
   64.11      Drule.cterm_instantiate cfps thm
   64.12 @@ -155,7 +155,7 @@
   64.13      let
   64.14        val s = Name.uu;
   64.15        val eq = Abs (Name.uu, T, HOLogic.mk_eq (Free (s, T), Bound 0));
   64.16 -      val split' = Drule.instantiate' [] [SOME (Proof_Context.cterm_of ctxt eq)] split;
   64.17 +      val split' = Drule.instantiate' [] [SOME (Thm.cterm_of ctxt eq)] split;
   64.18      in
   64.19        Thm.generalize ([], [s]) (Thm.maxidx_of split' + 1) split'
   64.20      end
    65.1 --- a/src/HOL/Tools/BNF/bnf_lfp.ML	Fri Mar 06 14:01:08 2015 +0100
    65.2 +++ b/src/HOL/Tools/BNF/bnf_lfp.ML	Fri Mar 06 15:58:56 2015 +0100
    65.3 @@ -607,8 +607,8 @@
    65.4  
    65.5          fun mk_card_conjunct min_alg = mk_ordLeq (mk_card_of min_alg) Asuc_bd;
    65.6          val card_conjunction = Library.foldr1 HOLogic.mk_conj (map mk_card_conjunct min_algss);
    65.7 -        val card_cT = Proof_Context.ctyp_of lthy suc_bdT;
    65.8 -        val card_ct = Proof_Context.cterm_of lthy (Term.absfree idx' card_conjunction);
    65.9 +        val card_cT = Thm.ctyp_of lthy suc_bdT;
   65.10 +        val card_ct = Thm.cterm_of lthy (Term.absfree idx' card_conjunction);
   65.11  
   65.12          val card_of =
   65.13            Goal.prove_sorry lthy [] []
   65.14 @@ -622,8 +622,8 @@
   65.15  
   65.16          val least_prem = HOLogic.mk_Trueprop (mk_alg Bs ss);
   65.17          val least_conjunction = Library.foldr1 HOLogic.mk_conj (map2 mk_leq min_algss Bs);
   65.18 -        val least_cT = Proof_Context.ctyp_of lthy suc_bdT;
   65.19 -        val least_ct = Proof_Context.cterm_of lthy (Term.absfree idx' least_conjunction);
   65.20 +        val least_cT = Thm.ctyp_of lthy suc_bdT;
   65.21 +        val least_ct = Thm.cterm_of lthy (Term.absfree idx' least_conjunction);
   65.22  
   65.23          val least =
   65.24            (Goal.prove_sorry lthy [] []
   65.25 @@ -779,7 +779,7 @@
   65.26  
   65.27      val car_inits = map (mk_min_alg str_inits) ks;
   65.28  
   65.29 -    val alg_init_thm = cterm_instantiate_pos (map (SOME o Proof_Context.cterm_of lthy) str_inits) alg_min_alg_thm;
   65.30 +    val alg_init_thm = cterm_instantiate_pos (map (SOME o Thm.cterm_of lthy) str_inits) alg_min_alg_thm;
   65.31  
   65.32      val alg_select_thm = Goal.prove_sorry lthy [] []
   65.33        (HOLogic.mk_Trueprop (mk_Ball II
   65.34 @@ -812,7 +812,7 @@
   65.35          fun mk_fun_eq f g x = HOLogic.mk_eq (f $ x, g $ x);
   65.36          val unique = HOLogic.mk_Trueprop
   65.37            (Library.foldr1 HOLogic.mk_conj (@{map 3} mk_fun_eq init_fs init_fs_copy init_xs));
   65.38 -        val cts = map (Proof_Context.cterm_of lthy) ss;
   65.39 +        val cts = map (Thm.cterm_of lthy) ss;
   65.40          val unique_mor =
   65.41            Goal.prove_sorry lthy [] [] (Logic.list_implies (prems @ mor_prems, unique))
   65.42              (K (mk_init_unique_mor_tac cts m alg_def alg_init_thm least_min_alg_thms
   65.43 @@ -946,7 +946,7 @@
   65.44            |> Thm.close_derivation;
   65.45  
   65.46          fun mk_ct initFT str abs = Term.absdummy initFT (abs $ (str $ Bound 0))
   65.47 -        val cts = @{map 3} (Proof_Context.cterm_of lthy ooo mk_ct) init_FTs str_inits Abs_Ts;
   65.48 +        val cts = @{map 3} (Thm.cterm_of lthy ooo mk_ct) init_FTs str_inits Abs_Ts;
   65.49  
   65.50          val mor_Abs =
   65.51            Goal.prove_sorry lthy [] []
   65.52 @@ -1020,8 +1020,8 @@
   65.53      val mor_fold_thm =
   65.54        let
   65.55          val mor_cong = mor_cong_thm OF (map (mk_nth_conv n) ks);
   65.56 -        val cT = Proof_Context.ctyp_of lthy foldT;
   65.57 -        val ct = Proof_Context.cterm_of lthy fold_fun
   65.58 +        val cT = Thm.ctyp_of lthy foldT;
   65.59 +        val ct = Thm.cterm_of lthy fold_fun
   65.60        in
   65.61          Goal.prove_sorry lthy [] []
   65.62            (HOLogic.mk_Trueprop (mk_mor UNIVs ctors active_UNIVs ss (map (mk_fold Ts ss) ks)))
   65.63 @@ -1244,7 +1244,7 @@
   65.64          rev (Term.add_tfrees goal []))
   65.65        end;
   65.66  
   65.67 -    val cTs = map (SOME o Proof_Context.ctyp_of lthy o TFree) induct_params;
   65.68 +    val cTs = map (SOME o Thm.ctyp_of lthy o TFree) induct_params;
   65.69  
   65.70      val weak_ctor_induct_thms =
   65.71        let fun insts i = (replicate (i - 1) TrueI) @ (asm_rl :: replicate (n - i) TrueI);
   65.72 @@ -1276,7 +1276,7 @@
   65.73            (@{map 3} mk_concl phi2s Izs1 Izs2));
   65.74          fun mk_t phi (z1, z1') (z2, z2') =
   65.75            Term.absfree z1' (HOLogic.mk_all (fst z2', snd z2', phi $ z1 $ z2));
   65.76 -        val cts = @{map 3} (SOME o Proof_Context.cterm_of lthy ooo mk_t) phi2s (Izs1 ~~ Izs1') (Izs2 ~~ Izs2');
   65.77 +        val cts = @{map 3} (SOME o Thm.cterm_of lthy ooo mk_t) phi2s (Izs1 ~~ Izs1') (Izs2 ~~ Izs2');
   65.78          val goal = Logic.list_implies (prems, concl);
   65.79        in
   65.80          (Goal.prove_sorry lthy [] [] goal
   65.81 @@ -1552,7 +1552,7 @@
   65.82  
   65.83          val timer = time (timer "set functions for the new datatypes");
   65.84  
   65.85 -        val cxs = map (SOME o Proof_Context.cterm_of lthy) Izs;
   65.86 +        val cxs = map (SOME o Thm.cterm_of lthy) Izs;
   65.87          val Isetss_by_range' =
   65.88            map (map (Term.subst_atomic_types (passiveAs ~~ passiveBs))) Isetss_by_range;
   65.89  
   65.90 @@ -1561,10 +1561,10 @@
   65.91              fun mk_set_map0 f map z set set' =
   65.92                HOLogic.mk_eq (mk_image f $ (set $ z), set' $ (map $ z));
   65.93  
   65.94 -            fun mk_cphi f map z set set' = Proof_Context.cterm_of lthy
   65.95 +            fun mk_cphi f map z set set' = Thm.cterm_of lthy
   65.96                (Term.absfree (dest_Free z) (mk_set_map0 f map z set set'));
   65.97  
   65.98 -            val csetss = map (map (Proof_Context.cterm_of lthy)) Isetss_by_range';
   65.99 +            val csetss = map (map (Thm.cterm_of lthy)) Isetss_by_range';
  65.100  
  65.101              val cphiss = @{map 3} (fn f => fn sets => fn sets' =>
  65.102                (@{map 4} (mk_cphi f) fs_Imaps Izs sets sets')) fs Isetss_by_range Isetss_by_range';
  65.103 @@ -1594,7 +1594,7 @@
  65.104            let
  65.105              fun mk_set_bd z bd set = mk_ordLeq (mk_card_of (set $ z)) bd;
  65.106  
  65.107 -            fun mk_cphi z set = Proof_Context.cterm_of lthy (Term.absfree (dest_Free z) (mk_set_bd z sbd0 set));
  65.108 +            fun mk_cphi z set = Thm.cterm_of lthy (Term.absfree (dest_Free z) (mk_set_bd z sbd0 set));
  65.109  
  65.110              val cphiss = map (map2 mk_cphi Izs) Isetss_by_range;
  65.111  
  65.112 @@ -1630,7 +1630,7 @@
  65.113                  HOLogic.mk_eq (fmap $ z, gmap $ z));
  65.114  
  65.115              fun mk_cphi sets z fmap gmap =
  65.116 -              Proof_Context.cterm_of lthy (Term.absfree (dest_Free z) (mk_map_cong0 sets z fmap gmap));
  65.117 +              Thm.cterm_of lthy (Term.absfree (dest_Free z) (mk_map_cong0 sets z fmap gmap));
  65.118  
  65.119              val cphis = @{map 4} mk_cphi Isetss_by_bnf Izs fs_Imaps fs_copy_Imaps;
  65.120  
  65.121 @@ -1691,9 +1691,9 @@
  65.122                  Irelpsi12 $ Iz1 $ Iz2);
  65.123              val goals = @{map 5} mk_le_Irel_OO Irelpsi1s Irelpsi2s Irelpsi12s Izs1 Izs2;
  65.124  
  65.125 -            val cTs = map (SOME o Proof_Context.ctyp_of lthy o TFree) induct2_params;
  65.126 -            val cxs = map (SOME o Proof_Context.cterm_of lthy) (splice Izs1 Izs2);
  65.127 -            fun mk_cphi z1 z2 goal = SOME (Proof_Context.cterm_of lthy (Term.absfree z1 (Term.absfree z2 goal)));
  65.128 +            val cTs = map (SOME o Thm.ctyp_of lthy o TFree) induct2_params;
  65.129 +            val cxs = map (SOME o Thm.cterm_of lthy) (splice Izs1 Izs2);
  65.130 +            fun mk_cphi z1 z2 goal = SOME (Thm.cterm_of lthy (Term.absfree z1 (Term.absfree z2 goal)));
  65.131              val cphis = @{map 3} mk_cphi Izs1' Izs2' goals;
  65.132              val induct = Drule.instantiate' cTs (cphis @ cxs) ctor_induct2_thm;
  65.133  
    66.1 --- a/src/HOL/Tools/BNF/bnf_lfp_size.ML	Fri Mar 06 14:01:08 2015 +0100
    66.2 +++ b/src/HOL/Tools/BNF/bnf_lfp_size.ML	Fri Mar 06 15:58:56 2015 +0100
    66.3 @@ -273,7 +273,7 @@
    66.4                HOLogic.mk_Trueprop (BNF_LFP_Util.mk_not_eq (list_comb (size, xs)) HOLogic.zero);
    66.5              val thm =
    66.6                Goal.prove_sorry lthy2 [] [] goal (fn {context = ctxt, ...} =>
    66.7 -                mk_size_neq ctxt (map (Proof_Context.cterm_of lthy2) xs)
    66.8 +                mk_size_neq ctxt (map (Thm.cterm_of lthy2) xs)
    66.9                  (#exhaust (#ctr_sugar (#fp_ctr_sugar fp_sugar))) size_thms)
   66.10                |> single
   66.11                |> Proof_Context.export names_lthy2 lthy2
    67.1 --- a/src/HOL/Tools/Ctr_Sugar/ctr_sugar.ML	Fri Mar 06 14:01:08 2015 +0100
    67.2 +++ b/src/HOL/Tools/Ctr_Sugar/ctr_sugar.ML	Fri Mar 06 15:58:56 2015 +0100
    67.3 @@ -679,10 +679,10 @@
    67.4        let
    67.5          val ((inject_thms, inject_thmss), half_distinct_thmss) = chop n thmss |>> `flat;
    67.6  
    67.7 -        val rho_As = map (apply2 (Proof_Context.ctyp_of lthy)) (map Logic.varifyT_global As ~~ As);
    67.8 +        val rho_As = map (apply2 (Thm.ctyp_of lthy)) (map Logic.varifyT_global As ~~ As);
    67.9  
   67.10          fun inst_thm t thm =
   67.11 -          Drule.instantiate' [] [SOME (Proof_Context.cterm_of lthy t)]
   67.12 +          Drule.instantiate' [] [SOME (Thm.cterm_of lthy t)]
   67.13              (Thm.instantiate (rho_As, []) (Drule.zero_var_indexes thm));
   67.14  
   67.15          val uexhaust_thm = inst_thm u exhaust_thm;
   67.16 @@ -997,7 +997,7 @@
   67.17                      mk_Trueprop_eq (udisc, list_comb (casexBool, mk_case_args n) $ u)) udiscs;
   67.18                  in
   67.19                    Goal.prove_sorry lthy [] [] (Logic.mk_conjunction_balanced goals)
   67.20 -                    (fn {context = ctxt, ...} => mk_disc_eq_case_tac ctxt (Proof_Context.cterm_of ctxt u)
   67.21 +                    (fn {context = ctxt, ...} => mk_disc_eq_case_tac ctxt (Thm.cterm_of ctxt u)
   67.22                         exhaust_thm (flat nontriv_disc_thmss) distinct_thms case_thms)
   67.23                    |> Conjunction.elim_balanced (length goals)
   67.24                    |> Proof_Context.export names_lthy lthy
   67.25 @@ -1020,7 +1020,7 @@
   67.26              val goal = mk_Trueprop_eq (h $ ufcase, list_comb (casexC, args) $ u);
   67.27            in
   67.28              Goal.prove_sorry lthy [] [] goal (fn {context = ctxt, ...} =>
   67.29 -              mk_case_distrib_tac ctxt (Proof_Context.cterm_of ctxt u) exhaust_thm case_thms)
   67.30 +              mk_case_distrib_tac ctxt (Thm.cterm_of ctxt u) exhaust_thm case_thms)
   67.31              |> singleton (Proof_Context.export names_lthy lthy)
   67.32              |> Thm.close_derivation
   67.33            end;
    68.1 --- a/src/HOL/Tools/Ctr_Sugar/ctr_sugar_code.ML	Fri Mar 06 14:01:08 2015 +0100
    68.2 +++ b/src/HOL/Tools/Ctr_Sugar/ctr_sugar_code.ML	Fri Mar 06 15:58:56 2015 +0100
    68.3 @@ -36,7 +36,7 @@
    68.4        |> Thm.prop_of |> Logic.dest_equals |> fst |> Term.strip_comb
    68.5        ||> fst o split_last |> list_comb;
    68.6      val lhs = Free (singleton (Name.variant_list params) "case", Term.fastype_of rhs);
    68.7 -    val assum = Thm.cterm_of thy (Logic.mk_equals (lhs, rhs));
    68.8 +    val assum = Thm.global_cterm_of thy (Logic.mk_equals (lhs, rhs));
    68.9    in
   68.10      thms
   68.11      |> Conjunction.intr_balanced
    69.1 --- a/src/HOL/Tools/Ctr_Sugar/ctr_sugar_util.ML	Fri Mar 06 14:01:08 2015 +0100
    69.2 +++ b/src/HOL/Tools/Ctr_Sugar/ctr_sugar_util.ML	Fri Mar 06 15:58:56 2015 +0100
    69.3 @@ -219,7 +219,7 @@
    69.4      val ps =
    69.5        map_filter
    69.6          (fn (_, NONE) => NONE
    69.7 -          | (var, SOME ct) => SOME (Thm.cterm_of thy (Var var), ct)) (vars' ~~ cts);
    69.8 +          | (var, SOME ct) => SOME (Thm.global_cterm_of thy (Var var), ct)) (vars' ~~ cts);
    69.9    in
   69.10      Drule.cterm_instantiate ps thm
   69.11    end;
    70.1 --- a/src/HOL/Tools/Function/fun_cases.ML	Fri Mar 06 14:01:08 2015 +0100
    70.2 +++ b/src/HOL/Tools/Function/fun_cases.ML	Fri Mar 06 15:58:56 2015 +0100
    70.3 @@ -29,7 +29,7 @@
    70.4      val info = Function.get_info ctxt f handle List.Empty => err ();
    70.5      val {elims, pelims, is_partial, ...} = info;
    70.6      val elims = if is_partial then pelims else the elims;
    70.7 -    val cprop = Proof_Context.cterm_of ctxt prop;
    70.8 +    val cprop = Thm.cterm_of ctxt prop;
    70.9      fun mk_elim rl =
   70.10        Thm.implies_intr cprop
   70.11          (Tactic.rule_by_tactic ctxt (Inductive.mk_cases_tac ctxt) (Thm.assume cprop RS rl))
    71.1 --- a/src/HOL/Tools/Function/function_common.ML	Fri Mar 06 14:01:08 2015 +0100
    71.2 +++ b/src/HOL/Tools/Function/function_common.ML	Fri Mar 06 15:58:56 2015 +0100
    71.3 @@ -327,7 +327,7 @@
    71.4  
    71.5  fun lift_morphism ctxt f =
    71.6    let
    71.7 -    fun term t = Thm.term_of (Drule.cterm_rule f (Proof_Context.cterm_of ctxt t))
    71.8 +    fun term t = Thm.term_of (Drule.cterm_rule f (Thm.cterm_of ctxt t))
    71.9    in
   71.10      Morphism.morphism "lift_morphism"
   71.11        {binding = [],
   71.12 @@ -338,11 +338,11 @@
   71.13  
   71.14  fun import_function_data t ctxt =
   71.15    let
   71.16 -    val ct = Proof_Context.cterm_of ctxt t
   71.17 +    val ct = Thm.cterm_of ctxt t
   71.18      val inst_morph = lift_morphism ctxt o Thm.instantiate
   71.19  
   71.20      fun match (trm, data) =
   71.21 -      SOME (transform_function_data data (inst_morph (Thm.match (Proof_Context.cterm_of ctxt trm, ct))))
   71.22 +      SOME (transform_function_data data (inst_morph (Thm.match (Thm.cterm_of ctxt trm, ct))))
   71.23          handle Pattern.MATCH => NONE
   71.24    in
   71.25      get_first match (Item_Net.retrieve (get_functions ctxt) t)
    72.1 --- a/src/HOL/Tools/Function/function_context_tree.ML	Fri Mar 06 14:01:08 2015 +0100
    72.2 +++ b/src/HOL/Tools/Function/function_context_tree.ML	Fri Mar 06 15:58:56 2015 +0100
    72.3 @@ -119,7 +119,7 @@
    72.4          val subst = Pattern.match thy (c, tt') (Vartab.empty, Vartab.empty)
    72.5          val branches = map (mk_branch ctxt o Envir.beta_norm o Envir.subst_term subst) subs
    72.6          val inst =
    72.7 -          map (fn v => apply2 (Proof_Context.cterm_of ctxt) (Var v, Envir.subst_term subst (Var v)))
    72.8 +          map (fn v => apply2 (Thm.cterm_of ctxt) (Var v, Envir.subst_term subst (Var v)))
    72.9              (Term.add_vars c [])
   72.10        in
   72.11          (cterm_instantiate inst r, dep, branches)
   72.12 @@ -147,7 +147,7 @@
   72.13              val (r, dep, branches) = find_cong_rule ctxt fvar h congs_deps t
   72.14              fun subtree (ctxt', fixes, assumes, st) =
   72.15                ((fixes,
   72.16 -                map (Thm.assume o Proof_Context.cterm_of ctxt) assumes),
   72.17 +                map (Thm.assume o Thm.cterm_of ctxt) assumes),
   72.18                 mk_tree' ctxt' st)
   72.19            in
   72.20              Cong (r, dep, map subtree branches)
   72.21 @@ -158,8 +158,8 @@
   72.22  
   72.23  fun inst_tree ctxt fvar f tr =
   72.24    let
   72.25 -    val cfvar = Proof_Context.cterm_of ctxt fvar
   72.26 -    val cf = Proof_Context.cterm_of ctxt f
   72.27 +    val cfvar = Thm.cterm_of ctxt fvar
   72.28 +    val cf = Thm.cterm_of ctxt f
   72.29  
   72.30      fun inst_term t =
   72.31        subst_bound(f, abstract_over (fvar, t))
   72.32 @@ -172,7 +172,7 @@
   72.33        | inst_tree_aux (RCall (t, str)) =
   72.34          RCall (inst_term t, inst_tree_aux str)
   72.35      and inst_branch ((fxs, assms), str) =
   72.36 -      ((fxs, map (Thm.assume o Proof_Context.cterm_of ctxt o inst_term o Thm.prop_of) assms),
   72.37 +      ((fxs, map (Thm.assume o Thm.cterm_of ctxt o inst_term o Thm.prop_of) assms),
   72.38         inst_tree_aux str)
   72.39    in
   72.40      inst_tree_aux tr
   72.41 @@ -188,10 +188,10 @@
   72.42  
   72.43  fun export_thm ctxt (fixes, assumes) =
   72.44   fold_rev (Thm.implies_intr o Thm.cprop_of) assumes
   72.45 - #> fold_rev (Thm.forall_intr o Proof_Context.cterm_of ctxt o Free) fixes
   72.46 + #> fold_rev (Thm.forall_intr o Thm.cterm_of ctxt o Free) fixes
   72.47  
   72.48  fun import_thm ctxt (fixes, athms) =
   72.49 - fold (Thm.forall_elim o Proof_Context.cterm_of ctxt o Free) fixes
   72.50 + fold (Thm.forall_elim o Thm.cterm_of ctxt o Free) fixes
   72.51   #> fold Thm.elim_implies athms
   72.52  
   72.53  
   72.54 @@ -240,7 +240,7 @@
   72.55  
   72.56  fun rewrite_by_tree ctxt h ih x tr =
   72.57    let
   72.58 -    fun rewrite_help _ _ x (Leaf t) = (Thm.reflexive (Proof_Context.cterm_of ctxt t), x)
   72.59 +    fun rewrite_help _ _ x (Leaf t) = (Thm.reflexive (Thm.cterm_of ctxt t), x)
   72.60        | rewrite_help fix h_as x (RCall (_ $ arg, st)) =
   72.61          let
   72.62            val (inner, (lRi,ha)::x') = rewrite_help fix h_as x st (* "a' = a" *)
   72.63 @@ -248,10 +248,10 @@
   72.64            val iha = import_thm ctxt (fix, h_as) ha (* (a', h a') : G *)
   72.65              |> Conv.fconv_rule (Conv.arg_conv (Conv.comb_conv (Conv.arg_conv (K inner))))
   72.66                                                      (* (a, h a) : G   *)
   72.67 -          val inst_ih = instantiate' [] [SOME (Proof_Context.cterm_of ctxt arg)] ih
   72.68 +          val inst_ih = instantiate' [] [SOME (Thm.cterm_of ctxt arg)] ih
   72.69            val eq = Thm.implies_elim (Thm.implies_elim inst_ih lRi) iha (* h a = f a *)
   72.70  
   72.71 -          val h_a'_eq_h_a = Thm.combination (Thm.reflexive (Proof_Context.cterm_of ctxt h)) inner
   72.72 +          val h_a'_eq_h_a = Thm.combination (Thm.reflexive (Thm.cterm_of ctxt h)) inner
   72.73            val h_a_eq_f_a = eq RS eq_reflection
   72.74            val result = Thm.transitive h_a'_eq_h_a h_a_eq_f_a
   72.75          in
    73.1 --- a/src/HOL/Tools/Function/function_core.ML	Fri Mar 06 14:01:08 2015 +0100
    73.2 +++ b/src/HOL/Tools/Function/function_core.ML	Fri Mar 06 15:58:56 2015 +0100
    73.3 @@ -150,11 +150,11 @@
    73.4      val lhs = inst pre_lhs
    73.5      val rhs = inst pre_rhs
    73.6  
    73.7 -    val cqs = map (Proof_Context.cterm_of ctxt') qs
    73.8 -    val ags = map (Thm.assume o Proof_Context.cterm_of ctxt') gs
    73.9 +    val cqs = map (Thm.cterm_of ctxt') qs
   73.10 +    val ags = map (Thm.assume o Thm.cterm_of ctxt') gs
   73.11  
   73.12      val case_hyp =
   73.13 -      Thm.assume (Proof_Context.cterm_of ctxt' (HOLogic.mk_Trueprop (mk_eq (x, lhs))))
   73.14 +      Thm.assume (Thm.cterm_of ctxt' (HOLogic.mk_Trueprop (mk_eq (x, lhs))))
   73.15    in
   73.16      ClauseContext { ctxt = ctxt', qs = qs, gs = gs, lhs = lhs, rhs = rhs,
   73.17        cqs = cqs, ags = ags, case_hyp = case_hyp }
   73.18 @@ -185,7 +185,7 @@
   73.19  
   73.20      (* Instantiate the GIntro thm with "f" and import into the clause context. *)
   73.21      val lGI = GIntro_thm
   73.22 -      |> Thm.forall_elim (Proof_Context.cterm_of ctxt f)
   73.23 +      |> Thm.forall_elim (Thm.cterm_of ctxt f)
   73.24        |> fold Thm.forall_elim cqs
   73.25        |> fold Thm.elim_implies ags
   73.26  
   73.27 @@ -193,7 +193,7 @@
   73.28        let
   73.29          val llRI = RI
   73.30            |> fold Thm.forall_elim cqs
   73.31 -          |> fold (Thm.forall_elim o Proof_Context.cterm_of ctxt o Free) rcfix
   73.32 +          |> fold (Thm.forall_elim o Thm.cterm_of ctxt o Free) rcfix
   73.33            |> fold Thm.elim_implies ags
   73.34            |> fold Thm.elim_implies rcassm
   73.35  
   73.36 @@ -233,7 +233,7 @@
   73.37      val ClauseContext {cqs=cqsi,ags=agsi,lhs=lhsi,...} = ctxi
   73.38      val ClauseContext {cqs=cqsj,ags=agsj,lhs=lhsj,...} = ctxj
   73.39  
   73.40 -    val lhsi_eq_lhsj = Thm.cterm_of thy (HOLogic.mk_Trueprop (mk_eq (lhsi, lhsj)))
   73.41 +    val lhsi_eq_lhsj = Thm.global_cterm_of thy (HOLogic.mk_Trueprop (mk_eq (lhsi, lhsj)))
   73.42    in if j < i then
   73.43      let
   73.44        val compat = lookup_compat_thm j i cts
   73.45 @@ -271,7 +271,7 @@
   73.46  
   73.47      val Ris = map (fn RCInfo {llRI, ...} => llRI) RCs
   73.48      val h_assums = map (fn RCInfo {h_assum, ...} =>
   73.49 -      Thm.assume (Proof_Context.cterm_of ctxt (subst_bounds (rev qs, h_assum)))) RCs
   73.50 +      Thm.assume (Thm.cterm_of ctxt (subst_bounds (rev qs, h_assum)))) RCs
   73.51  
   73.52      val (eql, _) =
   73.53        Function_Context_Tree.rewrite_by_tree ctxt h ih_elim_case (Ris ~~ h_assums) tree
   73.54 @@ -301,15 +301,15 @@
   73.55      val compat = get_compat_thm thy compat_store i j cctxi cctxj
   73.56      val Ghsj' =
   73.57        map (fn RCInfo {h_assum, ...} =>
   73.58 -        Thm.assume (Thm.cterm_of thy (subst_bounds (rev qsj', h_assum)))) RCsj
   73.59 +        Thm.assume (Thm.global_cterm_of thy (subst_bounds (rev qsj', h_assum)))) RCsj
   73.60  
   73.61      val RLj_import = RLj
   73.62        |> fold Thm.forall_elim cqsj'
   73.63        |> fold Thm.elim_implies agsj'
   73.64        |> fold Thm.elim_implies Ghsj'
   73.65  
   73.66 -    val y_eq_rhsj'h = Thm.assume (Thm.cterm_of thy (HOLogic.mk_Trueprop (mk_eq (y, rhsj'h))))
   73.67 -    val lhsi_eq_lhsj' = Thm.assume (Thm.cterm_of thy (HOLogic.mk_Trueprop (mk_eq (lhsi, lhsj'))))
   73.68 +    val y_eq_rhsj'h = Thm.assume (Thm.global_cterm_of thy (HOLogic.mk_Trueprop (mk_eq (y, rhsj'h))))
   73.69 +    val lhsi_eq_lhsj' = Thm.assume (Thm.global_cterm_of thy (HOLogic.mk_Trueprop (mk_eq (lhsi, lhsj'))))
   73.70         (* lhs_i = lhs_j' |-- lhs_i = lhs_j' *)
   73.71    in
   73.72      (trans OF [case_hyp, lhsi_eq_lhsj']) (* lhs_i = lhs_j' |-- x = lhs_j' *)
   73.73 @@ -324,7 +324,7 @@
   73.74        (* lhs_i = lhs_j' , y = rhs_j_h' |-- Gj', Rj1'...Rjk' ==> y = rhs_i_f *)
   73.75      |> Thm.implies_intr (Thm.cprop_of y_eq_rhsj'h)
   73.76      |> Thm.implies_intr (Thm.cprop_of lhsi_eq_lhsj')
   73.77 -    |> fold_rev Thm.forall_intr (Thm.cterm_of thy h :: cqsj')
   73.78 +    |> fold_rev Thm.forall_intr (Thm.global_cterm_of thy h :: cqsj')
   73.79    end
   73.80  
   73.81  
   73.82 @@ -340,12 +340,12 @@
   73.83  
   73.84      fun prep_RC (RCInfo {llRI, RIvs, CCas, ...}) = (llRI RS ih_intro_case)
   73.85        |> fold_rev (Thm.implies_intr o Thm.cprop_of) CCas
   73.86 -      |> fold_rev (Thm.forall_intr o Proof_Context.cterm_of ctxt o Free) RIvs
   73.87 +      |> fold_rev (Thm.forall_intr o Thm.cterm_of ctxt o Free) RIvs
   73.88  
   73.89      val existence = fold (curry op COMP o prep_RC) RCs lGI
   73.90  
   73.91 -    val P = Proof_Context.cterm_of ctxt (mk_eq (y, rhsC))
   73.92 -    val G_lhs_y = Thm.assume (Proof_Context.cterm_of ctxt (HOLogic.mk_Trueprop (G $ lhs $ y)))
   73.93 +    val P = Thm.cterm_of ctxt (mk_eq (y, rhsC))
   73.94 +    val G_lhs_y = Thm.assume (Thm.cterm_of ctxt (HOLogic.mk_Trueprop (G $ lhs $ y)))
   73.95  
   73.96      val unique_clauses =
   73.97        map2 (mk_uniqueness_clause thy globals compat_store clausei) clauses rep_lemmas
   73.98 @@ -356,21 +356,21 @@
   73.99        |> Seq.list_of |> the_single
  73.100  
  73.101      val uniqueness = G_cases
  73.102 -      |> Thm.forall_elim (Proof_Context.cterm_of ctxt lhs)
  73.103 -      |> Thm.forall_elim (Proof_Context.cterm_of ctxt y)
  73.104 +      |> Thm.forall_elim (Thm.cterm_of ctxt lhs)
  73.105 +      |> Thm.forall_elim (Thm.cterm_of ctxt y)
  73.106        |> Thm.forall_elim P
  73.107        |> Thm.elim_implies G_lhs_y
  73.108        |> fold elim_implies_eta unique_clauses
  73.109        |> Thm.implies_intr (Thm.cprop_of G_lhs_y)
  73.110 -      |> Thm.forall_intr (Proof_Context.cterm_of ctxt y)
  73.111 +      |> Thm.forall_intr (Thm.cterm_of ctxt y)
  73.112  
  73.113 -    val P2 = Proof_Context.cterm_of ctxt (lambda y (G $ lhs $ y)) (* P2 y := (lhs, y): G *)
  73.114 +    val P2 = Thm.cterm_of ctxt (lambda y (G $ lhs $ y)) (* P2 y := (lhs, y): G *)
  73.115  
  73.116      val exactly_one =
  73.117        @{thm ex1I}
  73.118        |> instantiate'
  73.119 -          [SOME (Proof_Context.ctyp_of ctxt ranT)]
  73.120 -          [SOME P2, SOME (Proof_Context.cterm_of ctxt rhsC)]
  73.121 +          [SOME (Thm.ctyp_of ctxt ranT)]
  73.122 +          [SOME P2, SOME (Thm.cterm_of ctxt rhsC)]
  73.123        |> curry (op COMP) existence
  73.124        |> curry (op COMP) uniqueness
  73.125        |> simplify (put_simpset HOL_basic_ss ctxt addsimps [case_hyp RS sym])
  73.126 @@ -382,8 +382,8 @@
  73.127        existence
  73.128        |> Thm.implies_intr ihyp
  73.129        |> Thm.implies_intr (Thm.cprop_of case_hyp)
  73.130 -      |> Thm.forall_intr (Proof_Context.cterm_of ctxt x)
  73.131 -      |> Thm.forall_elim (Proof_Context.cterm_of ctxt lhs)
  73.132 +      |> Thm.forall_intr (Thm.cterm_of ctxt x)
  73.133 +      |> Thm.forall_elim (Thm.cterm_of ctxt lhs)
  73.134        |> curry (op RS) refl
  73.135    in
  73.136      (exactly_one, function_value)
  73.137 @@ -399,12 +399,12 @@
  73.138        Logic.mk_implies (HOLogic.mk_Trueprop (R $ Bound 0 $ x),
  73.139          HOLogic.mk_Trueprop (Const (@{const_name Ex1}, (ranT --> boolT) --> boolT) $
  73.140            Abs ("y", ranT, G $ Bound 1 $ Bound 0))))
  73.141 -      |> Proof_Context.cterm_of ctxt
  73.142 +      |> Thm.cterm_of ctxt
  73.143  
  73.144      val ihyp_thm = Thm.assume ihyp |> Thm.forall_elim_vars 0
  73.145      val ih_intro = ihyp_thm RS (f_def RS ex1_implies_ex)
  73.146      val ih_elim = ihyp_thm RS (f_def RS ex1_implies_un)
  73.147 -      |> instantiate' [] [NONE, SOME (Proof_Context.cterm_of ctxt h)]
  73.148 +      |> instantiate' [] [NONE, SOME (Thm.cterm_of ctxt h)]
  73.149  
  73.150      val _ = trace_msg (K "Proving Replacement lemmas...")
  73.151      val repLemmas = map (mk_replacement_lemma ctxt h ih_elim) clauses
  73.152 @@ -421,11 +421,11 @@
  73.153        |> Thm.forall_elim_vars 0
  73.154        |> fold (curry op COMP) ex1s
  73.155        |> Thm.implies_intr (ihyp)
  73.156 -      |> Thm.implies_intr (Proof_Context.cterm_of ctxt (HOLogic.mk_Trueprop (mk_acc domT R $ x)))
  73.157 -      |> Thm.forall_intr (Proof_Context.cterm_of ctxt x)
  73.158 +      |> Thm.implies_intr (Thm.cterm_of ctxt (HOLogic.mk_Trueprop (mk_acc domT R $ x)))
  73.159 +      |> Thm.forall_intr (Thm.cterm_of ctxt x)
  73.160        |> (fn it => Drule.compose (it, 2, acc_induct_rule)) (* "EX! y. (?x,y):G" *)
  73.161        |> (fn it =>
  73.162 -          fold (Thm.forall_intr o Proof_Context.cterm_of ctxt o Var)
  73.163 +          fold (Thm.forall_intr o Thm.cterm_of ctxt o Var)
  73.164              (Term.add_vars (Thm.prop_of it) []) it)
  73.165  
  73.166      val goalstate =  Conjunction.intr graph_is_function complete
  73.167 @@ -466,7 +466,7 @@
  73.168            #> the_default ("", 0)
  73.169        in
  73.170          fold_rev (fn Free (n, T) =>
  73.171 -          forall_intr_rename (n, Proof_Context.cterm_of lthy (Var (varmap (n, T), T)))) qs thm
  73.172 +          forall_intr_rename (n, Thm.cterm_of lthy (Var (varmap (n, T), T)))) qs thm
  73.173        end
  73.174    in
  73.175      ((Rdef, map2 requantify intrs intrs_gen, forall_intr_vars elim_gen, induct), lthy)
  73.176 @@ -552,7 +552,7 @@
  73.177    let
  73.178      fun inst_term t = subst_bound(f, abstract_over (fvar, t))
  73.179    in
  73.180 -    (rcfix, map (Thm.assume o Thm.cterm_of thy o inst_term o Thm.prop_of) rcassm, inst_term rcarg)
  73.181 +    (rcfix, map (Thm.assume o Thm.global_cterm_of thy o inst_term o Thm.prop_of) rcassm, inst_term rcarg)
  73.182    end
  73.183  
  73.184  
  73.185 @@ -569,14 +569,14 @@
  73.186        (ClauseInfo {qglr = (oqs, _, _, _), cdata = ClauseContext {cqs, lhs, ags, ...}, ...}) valthm =
  73.187        let
  73.188          val lhs_acc =
  73.189 -          Proof_Context.cterm_of ctxt (HOLogic.mk_Trueprop (mk_acc domT R $ lhs)) (* "acc R lhs" *)
  73.190 +          Thm.cterm_of ctxt (HOLogic.mk_Trueprop (mk_acc domT R $ lhs)) (* "acc R lhs" *)
  73.191          val z_smaller =
  73.192 -          Proof_Context.cterm_of ctxt (HOLogic.mk_Trueprop (R $ z $ lhs)) (* "R z lhs" *)
  73.193 +          Thm.cterm_of ctxt (HOLogic.mk_Trueprop (R $ z $ lhs)) (* "R z lhs" *)
  73.194        in
  73.195          ((Thm.assume z_smaller) RS ((Thm.assume lhs_acc) RS acc_downward))
  73.196          |> (fn it => it COMP graph_is_function)
  73.197          |> Thm.implies_intr z_smaller
  73.198 -        |> Thm.forall_intr (Proof_Context.cterm_of ctxt  z)
  73.199 +        |> Thm.forall_intr (Thm.cterm_of ctxt  z)
  73.200          |> (fn it => it COMP valthm)
  73.201          |> Thm.implies_intr lhs_acc
  73.202          |> asm_simplify (put_simpset HOL_basic_ss ctxt addsimps [f_iff])
  73.203 @@ -599,23 +599,23 @@
  73.204      val Globals {domT, x, z, a, P, D, ...} = globals
  73.205      val acc_R = mk_acc domT R
  73.206  
  73.207 -    val x_D = Thm.assume (Thm.cterm_of thy (HOLogic.mk_Trueprop (D $ x)))
  73.208 -    val a_D = Thm.cterm_of thy (HOLogic.mk_Trueprop (D $ a))
  73.209 +    val x_D = Thm.assume (Thm.global_cterm_of thy (HOLogic.mk_Trueprop (D $ x)))
  73.210 +    val a_D = Thm.global_cterm_of thy (HOLogic.mk_Trueprop (D $ a))
  73.211  
  73.212 -    val D_subset = Thm.cterm_of thy (Logic.all x
  73.213 +    val D_subset = Thm.global_cterm_of thy (Logic.all x
  73.214        (Logic.mk_implies (HOLogic.mk_Trueprop (D $ x), HOLogic.mk_Trueprop (acc_R $ x))))
  73.215  
  73.216      val D_dcl = (* "!!x z. [| x: D; (z,x):R |] ==> z:D" *)
  73.217        Logic.all x (Logic.all z (Logic.mk_implies (HOLogic.mk_Trueprop (D $ x),
  73.218          Logic.mk_implies (HOLogic.mk_Trueprop (R $ z $ x),
  73.219            HOLogic.mk_Trueprop (D $ z)))))
  73.220 -      |> Thm.cterm_of thy
  73.221 +      |> Thm.global_cterm_of thy
  73.222  
  73.223      (* Inductive Hypothesis: !!z. (z,x):R ==> P z *)
  73.224      val ihyp = Logic.all_const domT $ Abs ("z", domT,
  73.225        Logic.mk_implies (HOLogic.mk_Trueprop (R $ Bound 0 $ x),
  73.226          HOLogic.mk_Trueprop (P $ Bound 0)))
  73.227 -      |> Thm.cterm_of thy
  73.228 +      |> Thm.global_cterm_of thy
  73.229  
  73.230      val aihyp = Thm.assume ihyp
  73.231  
  73.232 @@ -633,10 +633,10 @@
  73.233          end
  73.234  
  73.235          fun mk_Prec (RCInfo {llRI, RIvs, CCas, rcarg, ...}) = sih
  73.236 -          |> Thm.forall_elim (Thm.cterm_of thy rcarg)
  73.237 +          |> Thm.forall_elim (Thm.global_cterm_of thy rcarg)
  73.238            |> Thm.elim_implies llRI
  73.239            |> fold_rev (Thm.implies_intr o Thm.cprop_of) CCas
  73.240 -          |> fold_rev (Thm.forall_intr o Thm.cterm_of thy o Free) RIvs
  73.241 +          |> fold_rev (Thm.forall_intr o Thm.global_cterm_of thy o Free) RIvs
  73.242  
  73.243          val P_recs = map mk_Prec RCs   (*  [P rec1, P rec2, ... ]  *)
  73.244  
  73.245 @@ -645,7 +645,7 @@
  73.246            |> fold_rev (curry Logic.mk_implies) gs
  73.247            |> curry Logic.mk_implies (HOLogic.mk_Trueprop (D $ lhs))
  73.248            |> fold_rev mk_forall_rename (map fst oqs ~~ qs)
  73.249 -          |> Thm.cterm_of thy
  73.250 +          |> Thm.global_cterm_of thy
  73.251  
  73.252          val P_lhs = Thm.assume step
  73.253            |> fold Thm.forall_elim cqs
  73.254 @@ -653,7 +653,7 @@
  73.255            |> fold Thm.elim_implies ags
  73.256            |> fold Thm.elim_implies P_recs
  73.257  
  73.258 -        val res = Thm.cterm_of thy (HOLogic.mk_Trueprop (P $ x))
  73.259 +        val res = Thm.global_cterm_of thy (HOLogic.mk_Trueprop (P $ x))
  73.260            |> Conv.arg_conv (Conv.arg_conv case_hyp_conv)
  73.261            |> Thm.symmetric (* P lhs == P x *)
  73.262            |> (fn eql => Thm.equal_elim eql P_lhs) (* "P x" *)
  73.263 @@ -671,7 +671,7 @@
  73.264        |> fold (curry op COMP) cases (*  P x  *)
  73.265        |> Thm.implies_intr ihyp
  73.266        |> Thm.implies_intr (Thm.cprop_of x_D)
  73.267 -      |> Thm.forall_intr (Thm.cterm_of thy x)
  73.268 +      |> Thm.forall_intr (Thm.global_cterm_of thy x)
  73.269  
  73.270      val subset_induct_rule =
  73.271        acc_subset_induct
  73.272 @@ -686,16 +686,16 @@
  73.273  
  73.274      val simple_induct_rule =
  73.275        subset_induct_rule
  73.276 -      |> Thm.forall_intr (Thm.cterm_of thy D)
  73.277 -      |> Thm.forall_elim (Thm.cterm_of thy acc_R)
  73.278 +      |> Thm.forall_intr (Thm.global_cterm_of thy D)
  73.279 +      |> Thm.forall_elim (Thm.global_cterm_of thy acc_R)
  73.280        |> atac 1 |> Seq.hd
  73.281        |> (curry op COMP) (acc_downward
  73.282 -        |> (instantiate' [SOME (Thm.ctyp_of thy domT)]
  73.283 -             (map (SOME o Thm.cterm_of thy) [R, x, z]))
  73.284 -        |> Thm.forall_intr (Thm.cterm_of thy z)
  73.285 -        |> Thm.forall_intr (Thm.cterm_of thy x))
  73.286 -      |> Thm.forall_intr (Thm.cterm_of thy a)
  73.287 -      |> Thm.forall_intr (Thm.cterm_of thy P)
  73.288 +        |> (instantiate' [SOME (Thm.global_ctyp_of thy domT)]
  73.289 +             (map (SOME o Thm.global_cterm_of thy) [R, x, z]))
  73.290 +        |> Thm.forall_intr (Thm.global_cterm_of thy z)
  73.291 +        |> Thm.forall_intr (Thm.global_cterm_of thy x))
  73.292 +      |> Thm.forall_intr (Thm.global_cterm_of thy a)
  73.293 +      |> Thm.forall_intr (Thm.global_cterm_of thy P)
  73.294    in
  73.295      simple_induct_rule
  73.296    end
  73.297 @@ -708,7 +708,7 @@
  73.298        qglr = (oqs, _, _, _), ...} = clause
  73.299      val goal = HOLogic.mk_Trueprop (mk_acc domT R $ lhs)
  73.300        |> fold_rev (curry Logic.mk_implies) gs
  73.301 -      |> Proof_Context.cterm_of ctxt
  73.302 +      |> Thm.cterm_of ctxt
  73.303    in
  73.304      Goal.init goal
  73.305      |> (SINGLE (resolve_tac ctxt [accI] 1)) |> the
  73.306 @@ -744,7 +744,7 @@
  73.307            |> Function_Context_Tree.export_term (fixes, assumes)
  73.308            |> fold_rev (curry Logic.mk_implies o Thm.prop_of) ags
  73.309            |> fold_rev mk_forall_rename (map fst oqs ~~ qs)
  73.310 -          |> Proof_Context.cterm_of ctxt
  73.311 +          |> Thm.cterm_of ctxt
  73.312  
  73.313          val thm = Thm.assume hyp
  73.314            |> fold Thm.forall_elim cqs
  73.315 @@ -753,7 +753,7 @@
  73.316            |> fold Thm.elim_implies used (*  "(arg, lhs) : R'"  *)
  73.317  
  73.318          val z_eq_arg = HOLogic.mk_Trueprop (mk_eq (z, arg))
  73.319 -          |> Proof_Context.cterm_of ctxt |> Thm.assume
  73.320 +          |> Thm.cterm_of ctxt |> Thm.assume
  73.321  
  73.322          val acc = thm COMP ih_case
  73.323          val z_acc_local = acc
  73.324 @@ -788,42 +788,42 @@
  73.325  
  73.326      val wfR' = HOLogic.mk_Trueprop (Const (@{const_name Wellfounded.wfP},
  73.327        (domT --> domT --> boolT) --> boolT) $ R')
  73.328 -      |> Proof_Context.cterm_of ctxt (* "wf R'" *)
  73.329 +      |> Thm.cterm_of ctxt (* "wf R'" *)
  73.330  
  73.331      (* Inductive Hypothesis: !!z. (z,x):R' ==> z : acc R *)
  73.332      val ihyp = Logic.all_const domT $ Abs ("z", domT,
  73.333        Logic.mk_implies (HOLogic.mk_Trueprop (R' $ Bound 0 $ x),
  73.334          HOLogic.mk_Trueprop (acc_R $ Bound 0)))
  73.335 -      |> Proof_Context.cterm_of ctxt
  73.336 +      |> Thm.cterm_of ctxt
  73.337  
  73.338      val ihyp_a = Thm.assume ihyp |> Thm.forall_elim_vars 0
  73.339  
  73.340 -    val R_z_x = Proof_Context.cterm_of ctxt (HOLogic.mk_Trueprop (R $ z $ x))
  73.341 +    val R_z_x = Thm.cterm_of ctxt (HOLogic.mk_Trueprop (R $ z $ x))
  73.342  
  73.343      val (hyps, cases) = fold (mk_nest_term_case ctxt globals R' ihyp_a) clauses ([], [])
  73.344    in
  73.345      R_cases
  73.346 -    |> Thm.forall_elim (Proof_Context.cterm_of ctxt z)
  73.347 -    |> Thm.forall_elim (Proof_Context.cterm_of ctxt x)
  73.348 -    |> Thm.forall_elim (Proof_Context.cterm_of ctxt (acc_R $ z))
  73.349 +    |> Thm.forall_elim (Thm.cterm_of ctxt z)
  73.350 +    |> Thm.forall_elim (Thm.cterm_of ctxt x)
  73.351 +    |> Thm.forall_elim (Thm.cterm_of ctxt (acc_R $ z))
  73.352      |> curry op COMP (Thm.assume R_z_x)
  73.353      |> fold_rev (curry op COMP) cases
  73.354      |> Thm.implies_intr R_z_x
  73.355 -    |> Thm.forall_intr (Proof_Context.cterm_of ctxt z)
  73.356 +    |> Thm.forall_intr (Thm.cterm_of ctxt z)
  73.357      |> (fn it => it COMP accI)
  73.358      |> Thm.implies_intr ihyp
  73.359 -    |> Thm.forall_intr (Proof_Context.cterm_of ctxt x)
  73.360 +    |> Thm.forall_intr (Thm.cterm_of ctxt x)
  73.361      |> (fn it => Drule.compose (it, 2, wf_induct_rule))
  73.362      |> curry op RS (Thm.assume wfR')
  73.363      |> forall_intr_vars
  73.364      |> (fn it => it COMP allI)
  73.365      |> fold Thm.implies_intr hyps
  73.366      |> Thm.implies_intr wfR'
  73.367 -    |> Thm.forall_intr (Proof_Context.cterm_of ctxt R')
  73.368 -    |> Thm.forall_elim (Proof_Context.cterm_of ctxt (inrel_R))
  73.369 +    |> Thm.forall_intr (Thm.cterm_of ctxt R')
  73.370 +    |> Thm.forall_elim (Thm.cterm_of ctxt (inrel_R))
  73.371      |> curry op RS wf_in_rel
  73.372      |> full_simplify (put_simpset HOL_basic_ss ctxt addsimps [in_rel_def])
  73.373 -    |> Thm.forall_intr (Proof_Context.cterm_of ctxt Rrel)
  73.374 +    |> Thm.forall_intr (Thm.cterm_of ctxt Rrel)
  73.375    end
  73.376  
  73.377  
  73.378 @@ -878,11 +878,11 @@
  73.379          RCss GIntro_thms) RIntro_thmss
  73.380  
  73.381      val complete =
  73.382 -      mk_completeness globals clauses abstract_qglrs |> Proof_Context.cterm_of lthy |> Thm.assume
  73.383 +      mk_completeness globals clauses abstract_qglrs |> Thm.cterm_of lthy |> Thm.assume
  73.384  
  73.385      val compat =
  73.386        mk_compat_proof_obligations domT ranT fvar f abstract_qglrs
  73.387 -      |> map (Proof_Context.cterm_of lthy #> Thm.assume)
  73.388 +      |> map (Thm.cterm_of lthy #> Thm.assume)
  73.389  
  73.390      val compat_store = store_compat_thms n compat
  73.391  
    74.1 --- a/src/HOL/Tools/Function/function_elims.ML	Fri Mar 06 14:01:08 2015 +0100
    74.2 +++ b/src/HOL/Tools/Function/function_elims.ML	Fri Mar 06 15:58:56 2015 +0100
    74.3 @@ -115,12 +115,12 @@
    74.4          val args = HOLogic.mk_tuple arg_vars;
    74.5          val domT = R |> dest_Free |> snd |> hd o snd o dest_Type;
    74.6  
    74.7 -        val P = mk_var "P" @{typ "bool"} name_ctxt |> fst |> Proof_Context.cterm_of ctxt
    74.8 +        val P = mk_var "P" @{typ "bool"} name_ctxt |> fst |> Thm.cterm_of ctxt
    74.9          val sumtree_inj = Sum_Tree.mk_inj domT n_fs (idx+1) args;
   74.10  
   74.11 -        val cprop = Proof_Context.cterm_of ctxt prop;
   74.12 +        val cprop = Thm.cterm_of ctxt prop;
   74.13  
   74.14 -        val asms = [cprop, Proof_Context.cterm_of ctxt (HOLogic.mk_Trueprop (dom $ sumtree_inj))];
   74.15 +        val asms = [cprop, Thm.cterm_of ctxt (HOLogic.mk_Trueprop (dom $ sumtree_inj))];
   74.16          val asms_thms = map Thm.assume asms;
   74.17  
   74.18          fun prep_subgoal_tac i =
   74.19 @@ -133,10 +133,10 @@
   74.20          val elim_stripped =
   74.21            nth cases idx
   74.22            |> Thm.forall_elim P
   74.23 -          |> Thm.forall_elim (Proof_Context.cterm_of ctxt args)
   74.24 +          |> Thm.forall_elim (Thm.cterm_of ctxt args)
   74.25            |> Tactic.rule_by_tactic ctxt (ALLGOALS prep_subgoal_tac)
   74.26            |> fold_rev Thm.implies_intr asms
   74.27 -          |> Thm.forall_intr (Proof_Context.cterm_of ctxt rhs_var);
   74.28 +          |> Thm.forall_intr (Thm.cterm_of ctxt rhs_var);
   74.29  
   74.30          val bool_elims =
   74.31            (case ranT of
   74.32 @@ -145,7 +145,7 @@
   74.33  
   74.34          fun unstrip rl =
   74.35            rl
   74.36 -          |> fold_rev (Thm.forall_intr o Proof_Context.cterm_of ctxt) arg_vars
   74.37 +          |> fold_rev (Thm.forall_intr o Thm.cterm_of ctxt) arg_vars
   74.38            |> Thm.forall_intr P
   74.39        in
   74.40          map unstrip (elim_stripped :: bool_elims)
    75.1 --- a/src/HOL/Tools/Function/function_lib.ML	Fri Mar 06 14:01:08 2015 +0100
    75.2 +++ b/src/HOL/Tools/Function/function_lib.ML	Fri Mar 06 15:58:56 2015 +0100
    75.3 @@ -105,7 +105,7 @@
    75.4     val ty = fastype_of t
    75.5   in
    75.6     Goal.prove_internal ctxt []
    75.7 -     (Proof_Context.cterm_of ctxt
    75.8 +     (Thm.cterm_of ctxt
    75.9         (Logic.mk_equals (t,
   75.10            if null is
   75.11            then mk (Const (neu, ty), foldr1 mk (map (nth xs) js))
    76.1 --- a/src/HOL/Tools/Function/induction_schema.ML	Fri Mar 06 14:01:08 2015 +0100
    76.2 +++ b/src/HOL/Tools/Function/induction_schema.ML	Fri Mar 06 15:58:56 2015 +0100
    76.3 @@ -46,7 +46,7 @@
    76.4    (map meta (@{thm split_conv} :: @{thms sum.case}))
    76.5  
    76.6  fun term_conv thy cv t =
    76.7 -  cv (Thm.cterm_of thy t)
    76.8 +  cv (Thm.global_cterm_of thy t)
    76.9    |> Thm.prop_of |> Logic.dest_equals |> snd
   76.10  
   76.11  fun mk_relT T = HOLogic.mk_setT (HOLogic.mk_prodT (T, T))
   76.12 @@ -221,7 +221,7 @@
   76.13            $ (HOLogic.pair_const T T $ Bound 0 $ x)
   76.14            $ R),
   76.15           HOLogic.mk_Trueprop (P_comp $ Bound 0)))
   76.16 -      |> Proof_Context.cterm_of ctxt
   76.17 +      |> Thm.cterm_of ctxt
   76.18  
   76.19      val aihyp = Thm.assume ihyp
   76.20  
   76.21 @@ -235,9 +235,9 @@
   76.22        let
   76.23          val fxs = map Free xs
   76.24          val branch_hyp =
   76.25 -          Thm.assume (Proof_Context.cterm_of ctxt (HOLogic.mk_Trueprop (HOLogic.mk_eq (x, pat))))
   76.26 +          Thm.assume (Thm.cterm_of ctxt (HOLogic.mk_Trueprop (HOLogic.mk_eq (x, pat))))
   76.27  
   76.28 -        val C_hyps = map (Proof_Context.cterm_of ctxt #> Thm.assume) Cs
   76.29 +        val C_hyps = map (Thm.cterm_of ctxt #> Thm.assume) Cs
   76.30  
   76.31          val (relevant_cases, ineqss') =
   76.32            (scases_idx ~~ ineqss)
   76.33 @@ -247,11 +247,11 @@
   76.34          fun prove_case (cidx, SchemeCase {qs, gs, lhs, rs, ...}) ineq_press =
   76.35            let
   76.36              val case_hyps =
   76.37 -              map (Thm.assume o Proof_Context.cterm_of ctxt o HOLogic.mk_Trueprop o HOLogic.mk_eq)
   76.38 +              map (Thm.assume o Thm.cterm_of ctxt o HOLogic.mk_Trueprop o HOLogic.mk_eq)
   76.39                  (fxs ~~ lhs)
   76.40  
   76.41 -            val cqs = map (Proof_Context.cterm_of ctxt o Free) qs
   76.42 -            val ags = map (Thm.assume o Proof_Context.cterm_of ctxt) gs
   76.43 +            val cqs = map (Thm.cterm_of ctxt o Free) qs
   76.44 +            val ags = map (Thm.assume o Thm.cterm_of ctxt) gs
   76.45  
   76.46              val replace_x_simpset =
   76.47                put_simpset HOL_basic_ss ctxt addsimps (branch_hyp :: case_hyps)
   76.48 @@ -259,16 +259,16 @@
   76.49  
   76.50              fun mk_Prec (idx, Gvs, Gas, rcargs) (ineq, pres) =
   76.51                let
   76.52 -                val cGas = map (Thm.assume o Proof_Context.cterm_of ctxt) Gas
   76.53 -                val cGvs = map (Proof_Context.cterm_of ctxt o Free) Gvs
   76.54 +                val cGas = map (Thm.assume o Thm.cterm_of ctxt) Gas
   76.55 +                val cGvs = map (Thm.cterm_of ctxt o Free) Gvs
   76.56                  val import = fold Thm.forall_elim (cqs @ cGvs)
   76.57                    #> fold Thm.elim_implies (ags @ cGas)
   76.58                  val ipres = pres
   76.59 -                  |> Thm.forall_elim (Proof_Context.cterm_of ctxt (list_comb (P_of idx, rcargs)))
   76.60 +                  |> Thm.forall_elim (Thm.cterm_of ctxt (list_comb (P_of idx, rcargs)))
   76.61                    |> import
   76.62                in
   76.63                  sih
   76.64 -                |> Thm.forall_elim (Proof_Context.cterm_of ctxt (inject idx rcargs))
   76.65 +                |> Thm.forall_elim (Thm.cterm_of ctxt (inject idx rcargs))
   76.66                  |> Thm.elim_implies (import ineq) (* Psum rcargs *)
   76.67                  |> Conv.fconv_rule (sum_prod_conv ctxt)
   76.68                  |> Conv.fconv_rule (ind_rulify ctxt)
   76.69 @@ -283,7 +283,7 @@
   76.70                |> fold_rev (curry Logic.mk_implies o Thm.prop_of) P_recs
   76.71                |> fold_rev (curry Logic.mk_implies) gs
   76.72                |> fold_rev (Logic.all o Free) qs
   76.73 -              |> Proof_Context.cterm_of ctxt
   76.74 +              |> Thm.cterm_of ctxt
   76.75  
   76.76              val Plhs_to_Pxs_conv =
   76.77                foldl1 (uncurry Conv.combination_conv)
   76.78 @@ -303,15 +303,15 @@
   76.79          val (cases, steps) = split_list (map2 prove_case relevant_cases ineqss')
   76.80  
   76.81          val bstep = complete_thm
   76.82 -          |> Thm.forall_elim (Proof_Context.cterm_of ctxt (list_comb (P, fxs)))
   76.83 -          |> fold (Thm.forall_elim o Proof_Context.cterm_of ctxt) (fxs @ map Free ws)
   76.84 +          |> Thm.forall_elim (Thm.cterm_of ctxt (list_comb (P, fxs)))
   76.85 +          |> fold (Thm.forall_elim o Thm.cterm_of ctxt) (fxs @ map Free ws)
   76.86            |> fold Thm.elim_implies C_hyps
   76.87            |> fold Thm.elim_implies cases (* P xs *)
   76.88            |> fold_rev (Thm.implies_intr o Thm.cprop_of) C_hyps
   76.89 -          |> fold_rev (Thm.forall_intr o Proof_Context.cterm_of ctxt o Free) ws
   76.90 +          |> fold_rev (Thm.forall_intr o Thm.cterm_of ctxt o Free) ws
   76.91  
   76.92          val Pxs =
   76.93 -          Proof_Context.cterm_of ctxt (HOLogic.mk_Trueprop (P_comp $ x))
   76.94 +          Thm.cterm_of ctxt (HOLogic.mk_Trueprop (P_comp $ x))
   76.95            |> Goal.init
   76.96            |> (Simplifier.rewrite_goals_tac ctxt
   76.97                  (map meta (branch_hyp :: @{thm split_conv} :: @{thms sum.case}))
   76.98 @@ -320,7 +320,7 @@
   76.99            |> Thm.elim_implies (Conv.fconv_rule Drule.beta_eta_conversion bstep)
  76.100            |> Goal.finish ctxt
  76.101            |> Thm.implies_intr (Thm.cprop_of branch_hyp)
  76.102 -          |> fold_rev (Thm.forall_intr o Proof_Context.cterm_of ctxt) fxs
  76.103 +          |> fold_rev (Thm.forall_intr o Thm.cterm_of ctxt) fxs
  76.104        in
  76.105          (Pxs, steps)
  76.106        end
  76.107 @@ -332,7 +332,7 @@
  76.108      val istep = sum_split_rule
  76.109        |> fold (fn b => fn th => Drule.compose (b, 1, th)) branches
  76.110        |> Thm.implies_intr ihyp
  76.111 -      |> Thm.forall_intr (Proof_Context.cterm_of ctxt x) (* "!!x. (!!y<x. P y) ==> P x" *)
  76.112 +      |> Thm.forall_intr (Thm.cterm_of ctxt x) (* "!!x. (!!y<x. P y) ==> P x" *)
  76.113  
  76.114      val induct_rule =
  76.115        @{thm "wf_induct_rule"}
  76.116 @@ -357,11 +357,11 @@
  76.117  
  76.118      val ineqss =
  76.119        mk_ineqs R scheme
  76.120 -      |> map (map (apply2 (Thm.assume o Proof_Context.cterm_of ctxt'')))
  76.121 +      |> map (map (apply2 (Thm.assume o Thm.cterm_of ctxt'')))
  76.122      val complete =
  76.123 -      map_range (mk_completeness ctxt'' scheme #> Proof_Context.cterm_of ctxt'' #> Thm.assume)
  76.124 +      map_range (mk_completeness ctxt'' scheme #> Thm.cterm_of ctxt'' #> Thm.assume)
  76.125          (length branches)
  76.126 -    val wf_thm = mk_wf R scheme |> Proof_Context.cterm_of ctxt'' |> Thm.assume
  76.127 +    val wf_thm = mk_wf R scheme |> Thm.cterm_of ctxt'' |> Thm.assume
  76.128  
  76.129      val (descent, pres) = split_list (flat ineqss)
  76.130      val newgoals = complete @ pres @ wf_thm :: descent
  76.131 @@ -373,7 +373,7 @@
  76.132        let
  76.133          val inst = (foldr1 HOLogic.mk_prod (map Free xs))
  76.134            |> Sum_Tree.mk_inj ST (length branches) (i + 1)
  76.135 -          |> Proof_Context.cterm_of ctxt''
  76.136 +          |> Thm.cterm_of ctxt''
  76.137        in
  76.138          indthm
  76.139          |> Drule.instantiate' [] [SOME inst]
    77.1 --- a/src/HOL/Tools/Function/lexicographic_order.ML	Fri Mar 06 14:01:08 2015 +0100
    77.2 +++ b/src/HOL/Tools/Function/lexicographic_order.ML	Fri Mar 06 15:58:56 2015 +0100
    77.3 @@ -68,7 +68,7 @@
    77.4  
    77.5  fun mk_cell ctxt solve_tac (vars, prems, lhs, rhs) mfun = Lazy.lazy (fn _ =>
    77.6    let
    77.7 -    val goals = Proof_Context.cterm_of ctxt o mk_goal (vars, prems, mfun $ lhs, mfun $ rhs)
    77.8 +    val goals = Thm.cterm_of ctxt o mk_goal (vars, prems, mfun $ lhs, mfun $ rhs)
    77.9    in
   77.10      case try_proof (goals @{const_name Orderings.less}) solve_tac of
   77.11        Solved thm => Less thm
   77.12 @@ -201,7 +201,7 @@
   77.13    
   77.14          in (* 4: proof reconstruction *)
   77.15            st |>
   77.16 -          (PRIMITIVE (cterm_instantiate [apply2 (Proof_Context.cterm_of ctxt) (rel, relation)])
   77.17 +          (PRIMITIVE (cterm_instantiate [apply2 (Thm.cterm_of ctxt) (rel, relation)])
   77.18              THEN (REPEAT (rtac @{thm "wf_mlex"} 1))
   77.19              THEN (rtac @{thm "wf_empty"} 1)
   77.20              THEN EVERY (map prove_row clean_table))
    78.1 --- a/src/HOL/Tools/Function/measure_functions.ML	Fri Mar 06 14:01:08 2015 +0100
    78.2 +++ b/src/HOL/Tools/Function/measure_functions.ML	Fri Mar 06 15:58:56 2015 +0100
    78.3 @@ -20,7 +20,7 @@
    78.4  fun find_measures ctxt T =
    78.5    DEPTH_SOLVE (resolve_tac ctxt (rev (Named_Theorems.get ctxt @{named_theorems measure_function})) 1)
    78.6      (HOLogic.mk_Trueprop (mk_is_measure (Var (("f",0), T --> HOLogic.natT)))
    78.7 -     |> Proof_Context.cterm_of ctxt |> Goal.init)
    78.8 +     |> Thm.cterm_of ctxt |> Goal.init)
    78.9    |> Seq.map (Thm.prop_of #> (fn _ $ (_ $ (_ $ f)) => f))
   78.10    |> Seq.list_of
   78.11  
    79.1 --- a/src/HOL/Tools/Function/mutual.ML	Fri Mar 06 14:01:08 2015 +0100
    79.2 +++ b/src/HOL/Tools/Function/mutual.ML	Fri Mar 06 15:58:56 2015 +0100
    79.3 @@ -158,8 +158,8 @@
    79.4      val args = map inst pre_args
    79.5      val rhs = inst pre_rhs
    79.6  
    79.7 -    val cqs = map (Proof_Context.cterm_of ctxt) qs
    79.8 -    val ags = map (Thm.assume o Proof_Context.cterm_of ctxt) gs
    79.9 +    val cqs = map (Thm.cterm_of ctxt) qs
   79.10 +    val ags = map (Thm.assume o Thm.cterm_of ctxt) gs
   79.11  
   79.12      val import = fold Thm.forall_elim cqs
   79.13        #> fold Thm.elim_implies ags
   79.14 @@ -198,7 +198,7 @@
   79.15    let
   79.16      val xs =
   79.17        map_index (fn (i, T) =>
   79.18 -        Proof_Context.cterm_of ctxt
   79.19 +        Thm.cterm_of ctxt
   79.20            (Free ("x" ^ string_of_int i, T))) caTs (* FIXME: Bind xs properly *)
   79.21    in
   79.22      fold (fn x => fn thm => Thm.combination thm (Thm.reflexive x)) xs thm
   79.23 @@ -226,7 +226,7 @@
   79.24      val case_exp = Sum_Tree.mk_sumcases HOLogic.boolT Ps
   79.25  
   79.26      val induct_inst =
   79.27 -      Thm.forall_elim (Proof_Context.cterm_of ctxt case_exp) induct
   79.28 +      Thm.forall_elim (Thm.cterm_of ctxt case_exp) induct
   79.29        |> full_simplify (put_simpset Sum_Tree.sumcase_split_ss ctxt)
   79.30        |> full_simplify (put_simpset HOL_basic_ss ctxt addsimps all_f_defs)
   79.31  
   79.32 @@ -236,9 +236,9 @@
   79.33          val inj = Sum_Tree.mk_inj ST n i (foldr1 HOLogic.mk_prod afs)
   79.34        in
   79.35          (rule
   79.36 -         |> Thm.forall_elim (Proof_Context.cterm_of ctxt inj)
   79.37 +         |> Thm.forall_elim (Thm.cterm_of ctxt inj)
   79.38           |> full_simplify (put_simpset Sum_Tree.sumcase_split_ss ctxt)
   79.39 -         |> fold_rev (Thm.forall_intr o Proof_Context.cterm_of ctxt) (afs @ newPs),
   79.40 +         |> fold_rev (Thm.forall_intr o Thm.cterm_of ctxt) (afs @ newPs),
   79.41           k + length cargTs)
   79.42        end
   79.43    in
   79.44 @@ -258,7 +258,7 @@
   79.45      val argsT = fastype_of (HOLogic.mk_tuple arg_vars)
   79.46      val (args, name_ctxt) = mk_var "x" argsT name_ctxt
   79.47      
   79.48 -    val P = mk_var "P" @{typ "bool"} name_ctxt |> fst |> Proof_Context.cterm_of ctxt
   79.49 +    val P = mk_var "P" @{typ "bool"} name_ctxt |> fst |> Thm.cterm_of ctxt
   79.50      val sumtree_inj = Sum_Tree.mk_inj ST n i args
   79.51  
   79.52      val sum_elims =
   79.53 @@ -270,9 +270,9 @@
   79.54    in
   79.55      cases_rule
   79.56      |> Thm.forall_elim P
   79.57 -    |> Thm.forall_elim (Proof_Context.cterm_of ctxt sumtree_inj)
   79.58 +    |> Thm.forall_elim (Thm.cterm_of ctxt sumtree_inj)
   79.59      |> Tactic.rule_by_tactic ctxt (ALLGOALS prep_subgoal)
   79.60 -    |> Thm.forall_intr (Proof_Context.cterm_of ctxt args)
   79.61 +    |> Thm.forall_intr (Thm.cterm_of ctxt args)
   79.62      |> Thm.forall_intr P
   79.63    end
   79.64  
    80.1 --- a/src/HOL/Tools/Function/partial_function.ML	Fri Mar 06 14:01:08 2015 +0100
    80.2 +++ b/src/HOL/Tools/Function/partial_function.ML	Fri Mar 06 15:58:56 2015 +0100
    80.3 @@ -113,7 +113,7 @@
    80.4    let
    80.5      val thy = Thm.theory_of_thm thm;
    80.6      val vs = rev (Term.add_vars (Thm.prop_of thm) [])
    80.7 -      |> map (Thm.cterm_of thy o Var);
    80.8 +      |> map (Thm.global_cterm_of thy o Var);
    80.9    in
   80.10      cterm_instantiate (zip_options vs cts) thm
   80.11    end;
   80.12 @@ -168,7 +168,7 @@
   80.13    curry induction predicate *)
   80.14  fun specialize_fixp_induct ctxt args fT fT_uc F curry uncurry mono_thm f_def rule =
   80.15    let
   80.16 -    val cert = Proof_Context.cterm_of ctxt
   80.17 +    val cert = Thm.cterm_of ctxt
   80.18      val ([P], ctxt') = Variable.variant_fixes ["P"] ctxt
   80.19      val P_inst = Abs ("f", fT_uc, Free (P, fT --> HOLogic.boolT) $ (curry $ Bound 0))
   80.20    in 
   80.21 @@ -187,7 +187,7 @@
   80.22  
   80.23  fun mk_curried_induct args ctxt inst_rule =
   80.24    let
   80.25 -    val cert = Proof_Context.cterm_of ctxt
   80.26 +    val cert = Thm.cterm_of ctxt
   80.27      val ([P], ctxt') = Variable.variant_fixes ["P"] ctxt
   80.28  
   80.29      val split_paired_all_conv =
   80.30 @@ -234,7 +234,7 @@
   80.31      val ((f_binding, fT), mixfix) = the_single fixes;
   80.32      val fname = Binding.name_of f_binding;
   80.33  
   80.34 -    val cert = Proof_Context.cterm_of lthy;
   80.35 +    val cert = Thm.cterm_of lthy;
   80.36      val (lhs, rhs) = HOLogic.dest_eq (HOLogic.dest_Trueprop plain_eqn);
   80.37      val (head, args) = strip_comb lhs;
   80.38      val argnames = map (fst o dest_Free) args;
    81.1 --- a/src/HOL/Tools/Function/pat_completeness.ML	Fri Mar 06 14:01:08 2015 +0100
    81.2 +++ b/src/HOL/Tools/Function/pat_completeness.ML	Fri Mar 06 15:58:56 2015 +0100
    81.3 @@ -26,7 +26,7 @@
    81.4  fun inst_case_thm thy x P thm =
    81.5    let val [Pv, xv] = Term.add_vars (Thm.prop_of thm) []
    81.6    in
    81.7 -    thm |> cterm_instantiate (map (apply2 (Thm.cterm_of thy)) [(Var xv, x), (Var Pv, P)])
    81.8 +    thm |> cterm_instantiate (map (apply2 (Thm.global_cterm_of thy)) [(Var xv, x), (Var Pv, P)])
    81.9    end
   81.10  
   81.11  fun invent_vars constr i =
   81.12 @@ -45,7 +45,7 @@
   81.13    | filter_pats ctxt cons pvars (((pat as Free _) :: pats, thm) :: pts) =
   81.14      let val inst = list_comb (cons, pvars) in
   81.15        (inst :: pats,
   81.16 -        inst_free (Proof_Context.cterm_of ctxt pat) (Proof_Context.cterm_of ctxt inst) thm)
   81.17 +        inst_free (Thm.cterm_of ctxt pat) (Thm.cterm_of ctxt inst) thm)
   81.18          :: (filter_pats ctxt cons pvars pts)
   81.19      end
   81.20    | filter_pats thy cons pvars ((pat :: pats, thm) :: pts) =
   81.21 @@ -59,7 +59,7 @@
   81.22        let
   81.23          val (_, subps) = strip_comb pat
   81.24          val eqs =
   81.25 -          map (Proof_Context.cterm_of ctxt o HOLogic.mk_Trueprop o HOLogic.mk_eq) (avars ~~ subps)
   81.26 +          map (Thm.cterm_of ctxt o HOLogic.mk_Trueprop o HOLogic.mk_eq) (avars ~~ subps)
   81.27          val c_eq_pat =
   81.28            simplify (put_simpset HOL_basic_ss ctxt addsimps (map Thm.assume eqs)) c_assum
   81.29        in
   81.30 @@ -74,14 +74,14 @@
   81.31        let
   81.32          val (avars, pvars, newidx) = invent_vars cons idx
   81.33          val c_hyp =
   81.34 -          Proof_Context.cterm_of ctxt
   81.35 +          Thm.cterm_of ctxt
   81.36              (HOLogic.mk_Trueprop (HOLogic.mk_eq (v, list_comb (cons, avars))))
   81.37          val c_assum = Thm.assume c_hyp
   81.38          val newpats = map (transform_pat ctxt avars c_assum) (filter_pats ctxt cons pvars pats)
   81.39        in
   81.40          o_alg ctxt P newidx (avars @ vs) newpats
   81.41          |> Thm.implies_intr c_hyp
   81.42 -        |> fold_rev (Thm.forall_intr o Proof_Context.cterm_of ctxt) avars
   81.43 +        |> fold_rev (Thm.forall_intr o Thm.cterm_of ctxt) avars
   81.44        end
   81.45    | constr_case _ _ _ _ _ _ = raise Match
   81.46  and o_alg _ P idx [] (([], Pthm) :: _)  = Pthm
   81.47 @@ -91,8 +91,8 @@
   81.48        then o_alg ctxt P idx vs
   81.49               (map (fn (pv :: pats, thm) =>
   81.50                 (pats, refl RS
   81.51 -                (inst_free (Proof_Context.cterm_of ctxt pv)
   81.52 -                  (Proof_Context.cterm_of ctxt v) thm))) pts)
   81.53 +                (inst_free (Thm.cterm_of ctxt pv)
   81.54 +                  (Thm.cterm_of ctxt v) thm))) pts)
   81.55        else (* Cons case *)
   81.56          let
   81.57            val thy = Proof_Context.theory_of ctxt
   81.58 @@ -112,10 +112,10 @@
   81.59        HOLogic.mk_Trueprop P
   81.60        |> fold_rev (curry Logic.mk_implies o HOLogic.mk_Trueprop o HOLogic.mk_eq) (xs ~~ pats)
   81.61        |> fold_rev Logic.all qs
   81.62 -      |> Proof_Context.cterm_of ctxt
   81.63 +      |> Thm.cterm_of ctxt
   81.64  
   81.65      val hyps = map2 mk_assum qss patss
   81.66 -    fun inst_hyps hyp qs = fold (Thm.forall_elim o Proof_Context.cterm_of ctxt) qs (Thm.assume hyp)
   81.67 +    fun inst_hyps hyp qs = fold (Thm.forall_elim o Thm.cterm_of ctxt) qs (Thm.assume hyp)
   81.68      val assums = map2 inst_hyps hyps qss
   81.69      in
   81.70        o_alg ctxt P 2 xs (patss ~~ assums)
   81.71 @@ -142,7 +142,7 @@
   81.72  
   81.73      val patss = map (map snd) x_pats
   81.74      val complete_thm = prove_completeness ctxt xs thesis qss patss
   81.75 -      |> fold_rev (Thm.forall_intr o Proof_Context.cterm_of ctxt) vs
   81.76 +      |> fold_rev (Thm.forall_intr o Thm.cterm_of ctxt) vs
   81.77      in
   81.78        PRIMITIVE (fn st => Drule.compose (complete_thm, i, st))
   81.79    end
    82.1 --- a/src/HOL/Tools/Function/relation.ML	Fri Mar 06 14:01:08 2015 +0100
    82.2 +++ b/src/HOL/Tools/Function/relation.ML	Fri Mar 06 15:58:56 2015 +0100
    82.3 @@ -19,7 +19,7 @@
    82.4    (case Term.add_vars (Thm.prop_of st) [] of  (* FIXME tactic should not inspect main conclusion *)
    82.5      [v as (_, T)] =>
    82.6        let val thy = Thm.theory_of_thm st in
    82.7 -        PRIMITIVE (Thm.instantiate ([], [(Thm.cterm_of thy (Var v), Thm.cterm_of thy (inst T))])) st
    82.8 +        PRIMITIVE (Thm.instantiate ([], [(Thm.global_cterm_of thy (Var v), Thm.global_cterm_of thy (inst T))])) st
    82.9        end
   82.10    | _ => Seq.empty);
   82.11  
   82.12 @@ -38,9 +38,9 @@
   82.13            |> map_types Type_Infer.paramify_vars
   82.14            |> Type.constraint T
   82.15            |> Syntax.check_term ctxt
   82.16 -          |> Proof_Context.cterm_of ctxt;
   82.17 +          |> Thm.cterm_of ctxt;
   82.18        in
   82.19 -        PRIMITIVE (Thm.instantiate ([], [(Proof_Context.cterm_of ctxt (Var v), rel')])) st
   82.20 +        PRIMITIVE (Thm.instantiate ([], [(Thm.cterm_of ctxt (Var v), rel')])) st
   82.21        end
   82.22    | _ => Seq.empty);
   82.23  
    83.1 --- a/src/HOL/Tools/Function/scnp_reconstruct.ML	Fri Mar 06 14:01:08 2015 +0100
    83.2 +++ b/src/HOL/Tools/Function/scnp_reconstruct.ML	Fri Mar 06 15:58:56 2015 +0100
    83.3 @@ -272,7 +272,7 @@
    83.4      val level_mapping =
    83.5        map_index pt_lev lev
    83.6          |> Termination.mk_sumcases D (setT nat_pairT)
    83.7 -        |> Proof_Context.cterm_of ctxt
    83.8 +        |> Thm.cterm_of ctxt
    83.9      in
   83.10        PROFILE "Proof Reconstruction"
   83.11          (CONVERSION (Conv.arg_conv (Conv.arg_conv (Function_Lib.regroup_union_conv sl))) 1
    84.1 --- a/src/HOL/Tools/Function/termination.ML	Fri Mar 06 14:01:08 2015 +0100
    84.2 +++ b/src/HOL/Tools/Function/termination.ML	Fri Mar 06 15:58:56 2015 +0100
    84.3 @@ -144,7 +144,7 @@
    84.4          Const (@{const_abbrev Set.empty}, fastype_of c1))
    84.5        |> HOLogic.mk_Trueprop (* "C1 O C2 = {}" *)
    84.6    in
    84.7 -    case Function_Lib.try_proof (Proof_Context.cterm_of ctxt goal) chain_tac of
    84.8 +    case Function_Lib.try_proof (Thm.cterm_of ctxt goal) chain_tac of
    84.9        Function_Lib.Solved thm => SOME thm
   84.10      | _ => NONE
   84.11    end
   84.12 @@ -169,7 +169,7 @@
   84.13  fun mk_desc ctxt tac vs Gam l r m1 m2 =
   84.14    let
   84.15      fun try rel =
   84.16 -      try_proof (Proof_Context.cterm_of ctxt
   84.17 +      try_proof (Thm.cterm_of ctxt
   84.18          (Logic.list_all (vs,
   84.19             Logic.mk_implies (HOLogic.mk_Trueprop Gam,
   84.20               HOLogic.mk_Trueprop (Const (rel, @{typ "nat => nat => bool"})
   84.21 @@ -302,7 +302,7 @@
   84.22            THEN' (blast_tac ctxt)))    (* Solve rest of context... not very elegant *)
   84.23        ) i
   84.24    in
   84.25 -    (PRIMITIVE (Drule.cterm_instantiate [apply2 (Proof_Context.cterm_of ctxt) (rel, relation)])
   84.26 +    (PRIMITIVE (Drule.cterm_instantiate [apply2 (Thm.cterm_of ctxt) (rel, relation)])
   84.27       THEN ALLGOALS (fn i => if i = 1 then all_tac else solve_membership_tac i)
   84.28       THEN rewrite_goal_tac ctxt Un_aci_simps 1)  (* eliminate duplicates *)
   84.29    end) 1 st
    85.1 --- a/src/HOL/Tools/Lifting/lifting_bnf.ML	Fri Mar 06 14:01:08 2015 +0100
    85.2 +++ b/src/HOL/Tools/Lifting/lifting_bnf.ML	Fri Mar 06 15:58:56 2015 +0100
    85.3 @@ -23,7 +23,7 @@
    85.4      fun get_lhs thm = thm |> Thm.concl_of |> HOLogic.dest_Trueprop |> HOLogic.dest_eq |> fst
    85.5      val vars = get_lhs rel_Grp |> strip_comb |> snd |> map_filter (try (strip_comb #> snd #> hd))
    85.6      val UNIVs = map (fn var => HOLogic.mk_UNIV (var |> dest_Var |> snd |> dest_Type |> snd |> hd)) vars
    85.7 -    val inst = map2 (curry (apply2 (Proof_Context.cterm_of ctxt))) vars UNIVs
    85.8 +    val inst = map2 (curry (apply2 (Thm.cterm_of ctxt))) vars UNIVs
    85.9      val rel_Grp_UNIV_sym = rel_Grp |> Drule.instantiate_normalize ([], inst) 
   85.10        |> Local_Defs.unfold ctxt @{thms subset_UNIV[THEN eqTrueI] UNIV_def[symmetric] simp_thms(21)}
   85.11        |> (fn thm => thm RS sym)
    86.1 --- a/src/HOL/Tools/Lifting/lifting_def.ML	Fri Mar 06 14:01:08 2015 +0100
    86.2 +++ b/src/HOL/Tools/Lifting/lifting_def.ML	Fri Mar 06 15:58:56 2015 +0100
    86.3 @@ -57,7 +57,7 @@
    86.4  fun try_prove_reflexivity ctxt prop =
    86.5    let
    86.6      val thy = Proof_Context.theory_of ctxt
    86.7 -    val cprop = Thm.cterm_of thy prop
    86.8 +    val cprop = Thm.global_cterm_of thy prop
    86.9      val rule = @{thm ge_eq_refl}
   86.10      val concl_pat = Drule.strip_imp_concl (Thm.cprop_of rule)
   86.11      val insts = Thm.first_order_match (concl_pat, cprop)
   86.12 @@ -99,7 +99,7 @@
   86.13            end;
   86.14          
   86.15          val subst = fold make_subst free_vars [];
   86.16 -        val csubst = map (apply2 (Thm.cterm_of thy)) subst;
   86.17 +        val csubst = map (apply2 (Thm.global_cterm_of thy)) subst;
   86.18          val inst_thm = Drule.cterm_instantiate csubst thm;
   86.19        in
   86.20          Conv.fconv_rule 
   86.21 @@ -112,13 +112,13 @@
   86.22        let
   86.23          val t1 = (HOLogic.dest_Trueprop o Thm.concl_of) ant1
   86.24          val t2 = (HOLogic.dest_Trueprop o Thm.prop_of) ant2
   86.25 -        val fun1 = Thm.cterm_of thy (strip_args 2 t1)
   86.26 -        val args1 = map (Thm.cterm_of thy) (get_args 2 t1)
   86.27 -        val fun2 = Thm.cterm_of thy (strip_args 2 t2)
   86.28 -        val args2 = map (Thm.cterm_of thy) (get_args 1 t2)
   86.29 +        val fun1 = Thm.global_cterm_of thy (strip_args 2 t1)
   86.30 +        val args1 = map (Thm.global_cterm_of thy) (get_args 2 t1)
   86.31 +        val fun2 = Thm.global_cterm_of thy (strip_args 2 t2)
   86.32 +        val args2 = map (Thm.global_cterm_of thy) (get_args 1 t2)
   86.33          val relcomppI = Drule.incr_indexes2 ant1 ant2 @{thm relcomppI}
   86.34          val vars = (rev (Term.add_vars (Thm.prop_of relcomppI) []))
   86.35 -        val subst = map (apfst (Thm.cterm_of thy o Var)) (vars ~~ ([fun1] @ args1 @ [fun2] @ args2))
   86.36 +        val subst = map (apfst (Thm.global_cterm_of thy o Var)) (vars ~~ ([fun1] @ args1 @ [fun2] @ args2))
   86.37        in
   86.38          Drule.cterm_instantiate subst relcomppI
   86.39        end
   86.40 @@ -129,10 +129,10 @@
   86.41          fun mk_POS ty = Const (@{const_name POS}, ty --> ty --> HOLogic.boolT)
   86.42          val rel = (Thm.dest_fun2 o Thm.dest_arg o Thm.cprop_of) thm
   86.43          val typ = Thm.typ_of_cterm rel
   86.44 -        val POS_const = Thm.cterm_of thy (mk_POS typ)
   86.45 -        val var = Thm.cterm_of thy (Var (("X", Thm.maxidx_of_cterm rel + 1), typ))
   86.46 +        val POS_const = Thm.global_cterm_of thy (mk_POS typ)
   86.47 +        val var = Thm.global_cterm_of thy (Var (("X", Thm.maxidx_of_cterm rel + 1), typ))
   86.48          val goal =
   86.49 -          Thm.apply (Thm.cterm_of thy HOLogic.Trueprop) (Thm.apply (Thm.apply POS_const rel) var)
   86.50 +          Thm.apply (Thm.global_cterm_of thy HOLogic.Trueprop) (Thm.apply (Thm.apply POS_const rel) var)
   86.51        in
   86.52          [Lifting_Term.merge_transfer_relations ctxt goal, thm] MRSL @{thm POS_apply}
   86.53        end
   86.54 @@ -216,7 +216,7 @@
   86.55      val (var_name, T) = dest_abs (Thm.term_of rhs)
   86.56      val (new_var_names, ctxt') = Variable.variant_fixes [var_name] ctxt
   86.57      val thy = Proof_Context.theory_of ctxt'
   86.58 -    val refl_thm = Thm.reflexive (Thm.cterm_of thy (Free (hd new_var_names, T)))
   86.59 +    val refl_thm = Thm.reflexive (Thm.global_cterm_of thy (Free (hd new_var_names, T)))
   86.60    in
   86.61      Thm.combination def refl_thm |>
   86.62      singleton (Proof_Context.export ctxt' ctxt)
   86.63 @@ -301,7 +301,7 @@
   86.64            SOME mono_eq_thm =>
   86.65              let
   86.66                val rep_abs_eq = mono_eq_thm RS rep_abs_thm
   86.67 -              val rep = (Thm.cterm_of thy o quot_thm_rep) quot_thm
   86.68 +              val rep = (Thm.global_cterm_of thy o quot_thm_rep) quot_thm
   86.69                val rep_refl = Thm.reflexive rep RS @{thm meta_eq_to_obj_eq}
   86.70                val repped_eq = [rep_refl, unabs_def RS @{thm meta_eq_to_obj_eq}] MRSL @{thm cong}
   86.71                val code_cert = [repped_eq, rep_abs_eq] MRSL trans
   86.72 @@ -380,7 +380,7 @@
   86.73  local
   86.74    fun encode_code_eq thy abs_eq opt_rep_eq (rty, qty) = 
   86.75      let
   86.76 -      fun mk_type typ = typ |> Logic.mk_type |> Thm.cterm_of thy |> Drule.mk_term
   86.77 +      fun mk_type typ = typ |> Logic.mk_type |> Thm.global_cterm_of thy |> Drule.mk_term
   86.78      in
   86.79        Conjunction.intr_balanced [abs_eq, (the_default TrueI opt_rep_eq), mk_type rty, mk_type qty]
   86.80      end
   86.81 @@ -497,7 +497,7 @@
   86.82  in
   86.83  fun mk_readable_rsp_thm_eq tm lthy =
   86.84    let
   86.85 -    val ctm = Proof_Context.cterm_of lthy tm
   86.86 +    val ctm = Thm.cterm_of lthy tm
   86.87      
   86.88      fun assms_rewr_conv tactic rule ct =
   86.89        let
   86.90 @@ -622,7 +622,7 @@
   86.91      val cr_to_pcr_conv = HOLogic.Trueprop_conv (Conv.fun2_conv 
   86.92        (Raw_Simplifier.rewrite lthy false (get_cr_pcr_eqs lthy)))
   86.93      val (prsp_tm, rsp_prsp_eq) = HOLogic.mk_Trueprop (rsp_rel $ forced_rhs $ forced_rhs)
   86.94 -      |> Proof_Context.cterm_of lthy
   86.95 +      |> Thm.cterm_of lthy
   86.96        |> cr_to_pcr_conv
   86.97        |> `Thm.concl_of
   86.98        |>> Logic.dest_equals
    87.1 --- a/src/HOL/Tools/Lifting/lifting_setup.ML	Fri Mar 06 14:01:08 2015 +0100
    87.2 +++ b/src/HOL/Tools/Lifting/lifting_setup.ML	Fri Mar 06 15:58:56 2015 +0100
    87.3 @@ -109,7 +109,7 @@
    87.4            val (fresh_var, ctxt) = yield_singleton Variable.invent_types sort ctxt
    87.5            val thy = Proof_Context.theory_of ctxt
    87.6          in
    87.7 -          ((Thm.cterm_of thy var, Thm.cterm_of thy (HOLogic.eq_const (TFree fresh_var))), ctxt)
    87.8 +          ((Thm.global_cterm_of thy var, Thm.global_cterm_of thy (HOLogic.eq_const (TFree fresh_var))), ctxt)
    87.9          end
   87.10        
   87.11        val orig_lthy = lthy
   87.12 @@ -290,7 +290,7 @@
   87.13        val thy = Proof_Context.theory_of ctxt
   87.14        val orig_ctxt = ctxt
   87.15        val (fixed_goal, ctxt) = yield_singleton (import_terms_exclude not_fix) goal ctxt
   87.16 -      val init_goal = Goal.init (Thm.cterm_of thy fixed_goal)
   87.17 +      val init_goal = Goal.init (Thm.global_cterm_of thy fixed_goal)
   87.18      in
   87.19        (singleton (Variable.export ctxt orig_ctxt) o Goal.conclude) (the (SINGLE tac init_goal))
   87.20      end
   87.21 @@ -307,7 +307,7 @@
   87.22            val thy = Proof_Context.theory_of ctxt
   87.23            val orig_ctxt = ctxt
   87.24            val (fixed_goal, ctxt) = yield_singleton (Variable.import_terms true) goal ctxt
   87.25 -          val init_goal = Goal.init (Thm.cterm_of thy fixed_goal)
   87.26 +          val init_goal = Goal.init (Thm.global_cterm_of thy fixed_goal)
   87.27            val rules = Transfer.get_transfer_raw ctxt
   87.28            val rules = constraint :: OO_rules @ rules
   87.29            val tac =
   87.30 @@ -382,7 +382,7 @@
   87.31          |> Conv.fconv_rule(HOLogic.Trueprop_conv (Conv.arg_conv id_unfold then_conv Conv.arg1_conv id_unfold))
   87.32        val var = Var (hd (Term.add_vars (Thm.prop_of id_transfer) []))
   87.33        val thy = Proof_Context.theory_of lthy
   87.34 -      val inst = [(Thm.cterm_of thy var, Thm.cterm_of thy parametrized_relator)]
   87.35 +      val inst = [(Thm.global_cterm_of thy var, Thm.global_cterm_of thy parametrized_relator)]
   87.36        val id_par_thm = Drule.cterm_instantiate inst id_transfer
   87.37      in
   87.38        Lifting_Def.generate_parametric_transfer_rule lthy id_transfer_rule id_par_thm
    88.1 --- a/src/HOL/Tools/Lifting/lifting_term.ML	Fri Mar 06 14:01:08 2015 +0100
    88.2 +++ b/src/HOL/Tools/Lifting/lifting_term.ML	Fri Mar 06 15:58:56 2015 +0100
    88.3 @@ -278,7 +278,7 @@
    88.4      val (_, qty_schematic) = quot_thm_rty_qty quot_thm
    88.5      val match_env = Sign.typ_match thy (qty_schematic, qty) Vartab.empty
    88.6      fun prep_ty thy (x, (S, ty)) =
    88.7 -      (Thm.ctyp_of thy (TVar (x, S)), Thm.ctyp_of thy ty)
    88.8 +      (Thm.global_ctyp_of thy (TVar (x, S)), Thm.global_ctyp_of thy ty)
    88.9      val ty_inst = Vartab.fold (cons o (prep_ty thy)) match_env []
   88.10    in
   88.11      Thm.instantiate (ty_inst, []) quot_thm
   88.12 @@ -373,7 +373,7 @@
   88.13          let 
   88.14            val thy = Proof_Context.theory_of ctxt
   88.15            val instantiated_id_quot_thm =
   88.16 -            instantiate' [SOME (Thm.ctyp_of thy ty)] [] @{thm identity_quotient}
   88.17 +            instantiate' [SOME (Thm.global_ctyp_of thy ty)] [] @{thm identity_quotient}
   88.18          in
   88.19            (instantiated_id_quot_thm, (table, ctxt)) 
   88.20          end
   88.21 @@ -390,7 +390,7 @@
   88.22            let
   88.23              val thy = Proof_Context.theory_of ctxt
   88.24              val (Q_t, ctxt') = get_fresh_Q_t ctxt
   88.25 -            val Q_thm = Thm.assume (Thm.cterm_of thy Q_t)
   88.26 +            val Q_thm = Thm.assume (Thm.global_cterm_of thy Q_t)
   88.27              val table' = (ty, Q_thm)::table
   88.28            in
   88.29              (Q_thm, (table', ctxt'))
    89.1 --- a/src/HOL/Tools/Meson/meson.ML	Fri Mar 06 14:01:08 2015 +0100
    89.2 +++ b/src/HOL/Tools/Meson/meson.ML	Fri Mar 06 15:58:56 2015 +0100
    89.3 @@ -107,7 +107,7 @@
    89.4            val tenv =
    89.5              Pattern.first_order_match thy (tmB, tmA)
    89.6                                            (Vartab.empty, Vartab.empty) |> snd
    89.7 -          val ct_pairs = map (apply2 (Thm.cterm_of thy) o term_pair_of) (Vartab.dest tenv)
    89.8 +          val ct_pairs = map (apply2 (Thm.global_cterm_of thy) o term_pair_of) (Vartab.dest tenv)
    89.9        in  thA RS (cterm_instantiate ct_pairs thB)  end) () of
   89.10      SOME th => th
   89.11    | NONE => raise THM ("first_order_resolve", 0, [thA, thB]))
   89.12 @@ -174,7 +174,7 @@
   89.13    case (Thm.concl_of st, Thm.prop_of th) of
   89.14      (@{const Trueprop} $ (Var _ $ (c as Free _)), @{const Trueprop} $ _) =>
   89.15      let
   89.16 -      val cc = Thm.cterm_of (Thm.theory_of_thm th) c
   89.17 +      val cc = Thm.global_cterm_of (Thm.theory_of_thm th) c
   89.18        val ct = Thm.dest_arg (Thm.cprop_of th)
   89.19      in resolve_tac ctxt [th] i (Drule.instantiate' [] [SOME (Thm.lambda cc ct)] st) end
   89.20    | _ => resolve_tac ctxt [th] i st
   89.21 @@ -355,7 +355,7 @@
   89.22        val ([x], ctxt') =
   89.23          Variable.variant_fixes [name_of (HOLogic.dest_Trueprop (Thm.concl_of th))] ctxt;
   89.24        val spec' = spec
   89.25 -        |> Thm.instantiate ([], [(spec_var, Proof_Context.cterm_of ctxt' (Free (x, spec_varT)))]);
   89.26 +        |> Thm.instantiate ([], [(spec_var, Thm.cterm_of ctxt' (Free (x, spec_varT)))]);
   89.27      in (th RS spec', ctxt') end
   89.28  end;
   89.29  
   89.30 @@ -629,7 +629,7 @@
   89.31             $ (t as _ $ _) $ (u as _ $ _))) =>
   89.32      (case get_F_pattern T t u of
   89.33         SOME p =>
   89.34 -       let val inst = [apply2 (Thm.cterm_of thy) (F_ext_cong_neq, p)] in
   89.35 +       let val inst = [apply2 (Thm.global_cterm_of thy) (F_ext_cong_neq, p)] in
   89.36           th RS cterm_instantiate inst ext_cong_neq
   89.37         end
   89.38       | NONE => th)
    90.1 --- a/src/HOL/Tools/Meson/meson_clausify.ML	Fri Mar 06 14:01:08 2015 +0100
    90.2 +++ b/src/HOL/Tools/Meson/meson_clausify.ML	Fri Mar 06 15:58:56 2015 +0100
    90.3 @@ -35,8 +35,8 @@
    90.4  
    90.5  (**** Transformation of Elimination Rules into First-Order Formulas****)
    90.6  
    90.7 -val cfalse = Thm.cterm_of @{theory HOL} @{term False};
    90.8 -val ctp_false = Thm.cterm_of @{theory HOL} (HOLogic.mk_Trueprop @{term False});
    90.9 +val cfalse = Thm.global_cterm_of @{theory HOL} @{term False};
   90.10 +val ctp_false = Thm.global_cterm_of @{theory HOL} (HOLogic.mk_Trueprop @{term False});
   90.11  
   90.12  (* Converts an elim-rule into an equivalent theorem that does not have the
   90.13     predicate variable. Leaves other theorems unchanged. We simply instantiate
   90.14 @@ -45,9 +45,9 @@
   90.15  fun transform_elim_theorem th =
   90.16    (case Thm.concl_of th of    (*conclusion variable*)
   90.17      @{const Trueprop} $ (v as Var (_, @{typ bool})) =>
   90.18 -      Thm.instantiate ([], [(Thm.cterm_of @{theory HOL} v, cfalse)]) th
   90.19 +      Thm.instantiate ([], [(Thm.global_cterm_of @{theory HOL} v, cfalse)]) th
   90.20    | v as Var(_, @{typ prop}) =>
   90.21 -      Thm.instantiate ([], [(Thm.cterm_of @{theory HOL} v, ctp_false)]) th
   90.22 +      Thm.instantiate ([], [(Thm.global_cterm_of @{theory HOL} v, ctp_false)]) th
   90.23    | _ => th)
   90.24  
   90.25  
   90.26 @@ -94,9 +94,9 @@
   90.27    | is_quasi_lambda_free (Abs _) = false
   90.28    | is_quasi_lambda_free _ = true
   90.29  
   90.30 -val [f_B,g_B] = map (Thm.cterm_of @{theory}) (Misc_Legacy.term_vars (Thm.prop_of @{thm abs_B}));
   90.31 -val [g_C,f_C] = map (Thm.cterm_of @{theory}) (Misc_Legacy.term_vars (Thm.prop_of @{thm abs_C}));
   90.32 -val [f_S,g_S] = map (Thm.cterm_of @{theory}) (Misc_Legacy.term_vars (Thm.prop_of @{thm abs_S}));
   90.33 +val [f_B,g_B] = map (Thm.global_cterm_of @{theory}) (Misc_Legacy.term_vars (Thm.prop_of @{thm abs_B}));
   90.34 +val [g_C,f_C] = map (Thm.global_cterm_of @{theory}) (Misc_Legacy.term_vars (Thm.prop_of @{thm abs_C}));
   90.35 +val [f_S,g_S] = map (Thm.global_cterm_of @{theory}) (Misc_Legacy.term_vars (Thm.prop_of @{thm abs_S}));
   90.36  
   90.37  (* FIXME: Requires more use of cterm constructors. *)
   90.38  fun abstract ct =
   90.39 @@ -104,10 +104,10 @@
   90.40        val thy = Thm.theory_of_cterm ct
   90.41        val Abs(x,_,body) = Thm.term_of ct
   90.42        val Type (@{type_name fun}, [xT,bodyT]) = Thm.typ_of_cterm ct
   90.43 -      val cxT = Thm.ctyp_of thy xT
   90.44 -      val cbodyT = Thm.ctyp_of thy bodyT
   90.45 +      val cxT = Thm.global_ctyp_of thy xT
   90.46 +      val cbodyT = Thm.global_ctyp_of thy bodyT
   90.47        fun makeK () =
   90.48 -        instantiate' [SOME cxT, SOME cbodyT] [SOME (Thm.cterm_of thy body)]
   90.49 +        instantiate' [SOME cxT, SOME cbodyT] [SOME (Thm.global_cterm_of thy body)]
   90.50                       @{thm abs_K}
   90.51    in
   90.52        case body of
   90.53 @@ -118,17 +118,17 @@
   90.54          | rator$rand =>
   90.55              if Term.is_dependent rator then (*C or S*)
   90.56                 if Term.is_dependent rand then (*S*)
   90.57 -                 let val crator = Thm.cterm_of thy (Abs(x,xT,rator))
   90.58 -                     val crand = Thm.cterm_of thy (Abs(x,xT,rand))
   90.59 +                 let val crator = Thm.global_cterm_of thy (Abs(x,xT,rator))
   90.60 +                     val crand = Thm.global_cterm_of thy (Abs(x,xT,rand))
   90.61                       val abs_S' = cterm_instantiate [(f_S,crator),(g_S,crand)] @{thm abs_S}
   90.62                       val (_,rhs) = Thm.dest_equals (Thm.cprop_of abs_S')
   90.63                   in
   90.64                     Thm.transitive abs_S' (Conv.binop_conv abstract rhs)
   90.65                   end
   90.66                 else (*C*)
   90.67 -                 let val crator = Thm.cterm_of thy (Abs(x,xT,rator))
   90.68 +                 let val crator = Thm.global_cterm_of thy (Abs(x,xT,rator))
   90.69                       val abs_C' =
   90.70 -                      cterm_instantiate [(f_C,crator),(g_C,Thm.cterm_of thy rand)] @{thm abs_C}
   90.71 +                      cterm_instantiate [(f_C,crator),(g_C,Thm.global_cterm_of thy rand)] @{thm abs_C}
   90.72                       val (_,rhs) = Thm.dest_equals (Thm.cprop_of abs_C')
   90.73                   in
   90.74                     Thm.transitive abs_C' (Conv.fun_conv (Conv.arg_conv abstract) rhs)
   90.75 @@ -136,8 +136,8 @@
   90.76              else if Term.is_dependent rand then (*B or eta*)
   90.77                 if rand = Bound 0 then Thm.eta_conversion ct
   90.78                 else (*B*)
   90.79 -                 let val crand = Thm.cterm_of thy (Abs(x,xT,rand))
   90.80 -                     val crator = Thm.cterm_of thy rator
   90.81 +                 let val crand = Thm.global_cterm_of thy (Abs(x,xT,rand))
   90.82 +                     val crator = Thm.global_cterm_of thy rator
   90.83                       val abs_B' = cterm_instantiate [(f_B,crator),(g_B,crand)] @{thm abs_B}
   90.84                       val (_,rhs) = Thm.dest_equals (Thm.cprop_of abs_B')
   90.85                   in Thm.transitive abs_B' (Conv.arg_conv abstract rhs) end
   90.86 @@ -179,7 +179,7 @@
   90.87              TrueI)
   90.88  
   90.89  (*cterms are used throughout for efficiency*)
   90.90 -val cTrueprop = Thm.cterm_of @{theory HOL} HOLogic.Trueprop;
   90.91 +val cTrueprop = Thm.global_cterm_of @{theory HOL} HOLogic.Trueprop;
   90.92  
   90.93  (*Given an abstraction over n variables, replace the bound variables by free
   90.94    ones. Return the body, along with the list of free variables.*)
   90.95 @@ -194,7 +194,7 @@
   90.96  fun old_skolem_theorem_of_def ctxt rhs0 =
   90.97    let
   90.98      val thy = Proof_Context.theory_of ctxt
   90.99 -    val rhs = rhs0 |> Type.legacy_freeze_thaw |> #1 |> Thm.cterm_of thy
  90.100 +    val rhs = rhs0 |> Type.legacy_freeze_thaw |> #1 |> Thm.global_cterm_of thy
  90.101      val rhs' = rhs |> Thm.dest_comb |> snd
  90.102      val (ch, frees) = c_variant_abs_multi (rhs', [])
  90.103      val (hilbert, cabs) = ch |> Thm.dest_comb |>> Thm.term_of
  90.104 @@ -202,7 +202,7 @@
  90.105        case hilbert of
  90.106          Const (_, Type (@{type_name fun}, [_, T])) => T
  90.107        | _ => raise TERM ("old_skolem_theorem_of_def: expected \"Eps\"", [hilbert])
  90.108 -    val cex = Thm.cterm_of thy (HOLogic.exists_const T)
  90.109 +    val cex = Thm.global_cterm_of thy (HOLogic.exists_const T)
  90.110      val ex_tm = Thm.apply cTrueprop (Thm.apply cex cabs)
  90.111      val conc =
  90.112        Drule.list_comb (rhs, frees)
  90.113 @@ -334,7 +334,7 @@
  90.114            |> (if no_choice then
  90.115                  Skip_Proof.make_thm thy #> skolemize [cheat_choice] #> Thm.cprop_of
  90.116                else
  90.117 -                Thm.cterm_of thy)
  90.118 +                Thm.global_cterm_of thy)
  90.119            |> zap true
  90.120          val fixes =
  90.121            [] |> Term.add_free_names (Thm.prop_of zapped_th)
  90.122 @@ -350,7 +350,7 @@
  90.123            let
  90.124              val (fully_skolemized_ct, ctxt) =
  90.125                Variable.import_terms true [fully_skolemized_t] ctxt
  90.126 -              |>> the_single |>> Thm.cterm_of thy
  90.127 +              |>> the_single |>> Thm.global_cterm_of thy
  90.128            in
  90.129              (SOME (discharger_th, fully_skolemized_ct),
  90.130               (Thm.assume fully_skolemized_ct, ctxt))
  90.131 @@ -377,7 +377,7 @@
  90.132         th ctxt
  90.133      val (cnf_ths, ctxt) = clausify nnf_th
  90.134      fun intr_imp ct th =
  90.135 -      Thm.instantiate ([], map (apply2 (Thm.cterm_of thy))
  90.136 +      Thm.instantiate ([], map (apply2 (Thm.global_cterm_of thy))
  90.137                                 [(Var (("i", 0), @{typ nat}),
  90.138                                   HOLogic.mk_nat ax_no)])
  90.139                        (zero_var_indexes @{thm skolem_COMBK_D})
    91.1 --- a/src/HOL/Tools/Metis/metis_reconstruct.ML	Fri Mar 06 14:01:08 2015 +0100
    91.2 +++ b/src/HOL/Tools/Metis/metis_reconstruct.ML	Fri Mar 06 15:58:56 2015 +0100
    91.3 @@ -88,7 +88,7 @@
    91.4    the (AList.lookup (uncurry Metis_Thm.equal) th_pairs fth)
    91.5    handle Option.Option => raise Fail ("Failed to find Metis theorem " ^ Metis_Thm.toString fth)
    91.6  
    91.7 -fun cterm_incr_types thy idx = Thm.cterm_of thy o map_types (Logic.incr_tvar idx)
    91.8 +fun cterm_incr_types thy idx = Thm.global_cterm_of thy o map_types (Logic.incr_tvar idx)
    91.9  
   91.10  (* INFERENCE RULE: AXIOM *)
   91.11  
   91.12 @@ -104,7 +104,7 @@
   91.13    let
   91.14      val th = EXCLUDED_MIDDLE
   91.15      val [vx] = Term.add_vars (Thm.prop_of th) []
   91.16 -    val substs = [(Thm.cterm_of thy (Var vx), Thm.cterm_of thy i_atom)]
   91.17 +    val substs = [(Thm.global_cterm_of thy (Var vx), Thm.global_cterm_of thy i_atom)]
   91.18    in
   91.19      cterm_instantiate substs th
   91.20    end
   91.21 @@ -131,7 +131,7 @@
   91.22          (* We call "polish_hol_terms" below. *)
   91.23          val t = hol_term_of_metis ctxt type_enc sym_tab y
   91.24        in
   91.25 -        SOME (Thm.cterm_of thy (Var v), t)
   91.26 +        SOME (Thm.global_cterm_of thy (Var v), t)
   91.27        end
   91.28        handle Option.Option =>
   91.29               (trace_msg ctxt (fn () =>
   91.30 @@ -175,7 +175,7 @@
   91.31    let
   91.32      val tvs = Term.add_tvars (Thm.full_prop_of th) []
   91.33      val thy = Thm.theory_of_thm th
   91.34 -    fun inc_tvar ((a, i), s) = apply2 (Thm.ctyp_of thy) (TVar ((a, i), s), TVar ((a, i + inc), s))
   91.35 +    fun inc_tvar ((a, i), s) = apply2 (Thm.global_ctyp_of thy) (TVar ((a, i), s), TVar ((a, i + inc), s))
   91.36    in
   91.37      Thm.instantiate (map inc_tvar tvs, []) th
   91.38    end
   91.39 @@ -213,7 +213,7 @@
   91.40            |> rpair (Envir.empty ~1)
   91.41            |-> fold (Pattern.unify (Context.Proof ctxt))
   91.42            |> Envir.type_env |> Vartab.dest
   91.43 -          |> map (fn (x, (S, T)) => apply2 (Thm.ctyp_of thy) (TVar (x, S), T))
   91.44 +          |> map (fn (x, (S, T)) => apply2 (Thm.global_ctyp_of thy) (TVar (x, S), T))
   91.45        in
   91.46          (* The unifier, which is invoked from "Thm.bicompose", will sometimes refuse to unify
   91.47             "?a::?'a" with "?a::?'b" or "?a::nat" and throw a "TERM" exception (with "add_ffpair" as
   91.48 @@ -303,7 +303,7 @@
   91.49  
   91.50  val REFL_THM = Thm.incr_indexes 2 @{lemma "t ~= t ==> False" by simp}
   91.51  
   91.52 -val refl_x = Thm.cterm_of @{theory} (Var (hd (Term.add_vars (Thm.prop_of REFL_THM) [])));
   91.53 +val refl_x = Thm.global_cterm_of @{theory} (Var (hd (Term.add_vars (Thm.prop_of REFL_THM) [])));
   91.54  val refl_idx = 1 + Thm.maxidx_of REFL_THM;
   91.55  
   91.56  fun refl_inference ctxt type_enc concealed sym_tab t =
   91.57 @@ -374,7 +374,7 @@
   91.58        val imax = maxidx_of_term (i_tm $ tm_abs $ tm_subst)  (*ill-typed but gives right max*)
   91.59        val subst' = Thm.incr_indexes (imax+1) (if pos then subst_em else ssubst_em)
   91.60        val _ = trace_msg ctxt (fn () => "subst' " ^ Display.string_of_thm ctxt subst')
   91.61 -      val eq_terms = map (apply2 (Thm.cterm_of thy))
   91.62 +      val eq_terms = map (apply2 (Thm.global_cterm_of thy))
   91.63          (ListPair.zip (Misc_Legacy.term_vars (Thm.prop_of subst'), [tm_abs, tm_subst, i_tm]))
   91.64    in
   91.65      cterm_instantiate eq_terms subst'
   91.66 @@ -402,8 +402,8 @@
   91.67          val thy = Thm.theory_of_thm th
   91.68          val (tyenv, tenv) = fold (Pattern.first_order_match thy) pairs (Vartab.empty, Vartab.empty)
   91.69    
   91.70 -        fun mkT (v, (S, T)) = apply2 (Thm.ctyp_of thy) (TVar (v, S), T)
   91.71 -        fun mk (v, (T, t)) = apply2 (Thm.cterm_of thy) (Var (v, Envir.subst_type tyenv T), t)
   91.72 +        fun mkT (v, (S, T)) = apply2 (Thm.global_ctyp_of thy) (TVar (v, S), T)
   91.73 +        fun mk (v, (T, t)) = apply2 (Thm.global_cterm_of thy) (Var (v, Envir.subst_type tyenv T), t)
   91.74    
   91.75          val instsT = Vartab.fold (cons o mkT) tyenv []
   91.76          val insts = Vartab.fold (cons o mk) tenv []
   91.77 @@ -520,7 +520,7 @@
   91.78        | _ => I)
   91.79  
   91.80      val t_inst =
   91.81 -      [] |> try (unify_terms (prem, concl) #> map (apply2 (Thm.cterm_of thy)))
   91.82 +      [] |> try (unify_terms (prem, concl) #> map (apply2 (Thm.global_cterm_of thy)))
   91.83           |> the_default [] (* FIXME *)
   91.84    in
   91.85      cterm_instantiate t_inst th
   91.86 @@ -574,9 +574,9 @@
   91.87              Envir.Envir {maxidx = Vartab.fold (Integer.max o snd o fst) tyenv 0,
   91.88                tenv = Vartab.empty, tyenv = tyenv}
   91.89            val ty_inst =
   91.90 -            Vartab.fold (fn (x, (S, T)) => cons (apply2 (Thm.ctyp_of thy) (TVar (x, S), T)))
   91.91 +            Vartab.fold (fn (x, (S, T)) => cons (apply2 (Thm.global_ctyp_of thy) (TVar (x, S), T)))
   91.92                tyenv []
   91.93 -          val t_inst = [apply2 (Thm.cterm_of thy o Envir.norm_term env) (Var var, t')]
   91.94 +          val t_inst = [apply2 (Thm.global_cterm_of thy o Envir.norm_term env) (Var var, t')]
   91.95          in
   91.96            Drule.instantiate_normalize (ty_inst, t_inst) th
   91.97          end
    92.1 --- a/src/HOL/Tools/Metis/metis_tactic.ML	Fri Mar 06 14:01:08 2015 +0100
    92.2 +++ b/src/HOL/Tools/Metis/metis_tactic.ML	Fri Mar 06 15:58:56 2015 +0100
    92.3 @@ -48,12 +48,12 @@
    92.4      (case hol_clause_of_metis ctxt type_enc sym_tab concealed mth of
    92.5        Const (@{const_name HOL.eq}, _) $ _ $ t =>
    92.6        let
    92.7 -        val ct = Thm.cterm_of thy t
    92.8 +        val ct = Thm.global_cterm_of thy t
    92.9          val cT = Thm.ctyp_of_cterm ct
   92.10        in refl |> Drule.instantiate' [SOME cT] [SOME ct] end
   92.11      | Const (@{const_name disj}, _) $ t1 $ t2 =>
   92.12        (if can HOLogic.dest_not t1 then t2 else t1)
   92.13 -      |> HOLogic.mk_Trueprop |> Thm.cterm_of thy |> Thm.trivial
   92.14 +      |> HOLogic.mk_Trueprop |> Thm.global_cterm_of thy |> Thm.trivial
   92.15      | _ => raise Fail "expected reflexive or trivial clause")
   92.16    end
   92.17    |> Meson.make_meta_clause
   92.18 @@ -63,7 +63,7 @@
   92.19      val thy = Proof_Context.theory_of ctxt
   92.20      val tac = rewrite_goals_tac ctxt @{thms lambda_def [abs_def]} THEN resolve_tac ctxt [refl] 1
   92.21      val t = hol_clause_of_metis ctxt type_enc sym_tab concealed mth
   92.22 -    val ct = Thm.cterm_of thy (HOLogic.mk_Trueprop t)
   92.23 +    val ct = Thm.global_cterm_of thy (HOLogic.mk_Trueprop t)
   92.24    in Goal.prove_internal ctxt [] ct (K tac) |> Meson.make_meta_clause end
   92.25  
   92.26  fun add_vars_and_frees (t $ u) = fold (add_vars_and_frees) [t, u]
   92.27 @@ -91,7 +91,7 @@
   92.28                  |> (fn th => Meson.first_order_resolve th @{thm Metis.eq_lambdaI})
   92.29                | v :: _ =>
   92.30                  Abs (Name.uu, fastype_of v, abstract_over (v, Thm.term_of ct)) $ v
   92.31 -                |> Thm.cterm_of thy
   92.32 +                |> Thm.global_cterm_of thy
   92.33                  |> Conv.comb_conv (conv true ctxt))
   92.34              else
   92.35                Conv.abs_conv (conv false o snd) ctxt ct
   92.36 @@ -101,7 +101,7 @@
   92.37        (* We replace the equation's left-hand side with a beta-equivalent term
   92.38           so that "Thm.equal_elim" works below. *)
   92.39        val t0 $ _ $ t2 = Thm.prop_of eq_th
   92.40 -      val eq_ct = t0 $ Thm.prop_of th $ t2 |> Thm.cterm_of thy
   92.41 +      val eq_ct = t0 $ Thm.prop_of th $ t2 |> Thm.global_cterm_of thy
   92.42        val eq_th' = Goal.prove_internal ctxt [] eq_ct (K (resolve_tac ctxt [eq_th] 1))
   92.43      in Thm.equal_elim eq_th' th end
   92.44  
    93.1 --- a/src/HOL/Tools/Nitpick/nitpick_hol.ML	Fri Mar 06 14:01:08 2015 +0100
    93.2 +++ b/src/HOL/Tools/Nitpick/nitpick_hol.ML	Fri Mar 06 15:58:56 2015 +0100
    93.3 @@ -2149,7 +2149,7 @@
    93.4             SOME wf => wf
    93.5           | NONE =>
    93.6             let
    93.7 -             val goal = prop |> Thm.cterm_of thy |> Goal.init
    93.8 +             val goal = prop |> Thm.global_cterm_of thy |> Goal.init
    93.9               val wf = exists (terminates_by ctxt tac_timeout goal)
   93.10                               termination_tacs
   93.11             in Synchronized.change cached_wf_props (cons (prop, wf)); wf end
    94.1 --- a/src/HOL/Tools/Nitpick/nitpick_model.ML	Fri Mar 06 14:01:08 2015 +0100
    94.2 +++ b/src/HOL/Tools/Nitpick/nitpick_model.ML	Fri Mar 06 15:58:56 2015 +0100
    94.3 @@ -1062,7 +1062,7 @@
    94.4              |> writeln
    94.5            else
    94.6              ()
    94.7 -        val goal = prop |> Thm.cterm_of thy |> Goal.init
    94.8 +        val goal = prop |> Thm.global_cterm_of thy |> Goal.init
    94.9        in
   94.10          (goal |> SINGLE (DETERM_TIMEOUT auto_timeout (auto_tac ctxt))
   94.11                |> the |> Goal.finish ctxt; true)
    95.1 --- a/src/HOL/Tools/Old_Datatype/old_datatype.ML	Fri Mar 06 14:01:08 2015 +0100
    95.2 +++ b/src/HOL/Tools/Old_Datatype/old_datatype.ML	Fri Mar 06 15:58:56 2015 +0100
    95.3 @@ -247,9 +247,9 @@
    95.4          (thy, defs, eqns, rep_congs, dist_lemmas) =
    95.5        let
    95.6          val _ $ (_ $ (cong_f $ _) $ _) = Thm.concl_of arg_cong;
    95.7 -        val rep_const = Thm.cterm_of thy (Const (#Rep_name (#1 typedef), T --> Univ_elT));
    95.8 -        val cong' = cterm_instantiate [(Thm.cterm_of thy cong_f, rep_const)] arg_cong;
    95.9 -        val dist = cterm_instantiate [(Thm.cterm_of thy distinct_f, rep_const)] distinct_lemma;
   95.10 +        val rep_const = Thm.global_cterm_of thy (Const (#Rep_name (#1 typedef), T --> Univ_elT));
   95.11 +        val cong' = cterm_instantiate [(Thm.global_cterm_of thy cong_f, rep_const)] arg_cong;
   95.12 +        val dist = cterm_instantiate [(Thm.global_cterm_of thy distinct_f, rep_const)] distinct_lemma;
   95.13          val (thy', defs', eqns', _) =
   95.14            fold (make_constr_def typedef T (length constrs))
   95.15              (constrs ~~ constr_syntax) (Sign.add_path tname thy, defs, [], 1);
   95.16 @@ -390,7 +390,7 @@
   95.17      (* prove  inj Rep_dt_i  and  Rep_dt_i x : rep_set_dt_i *)
   95.18  
   95.19      val fun_congs =
   95.20 -      map (fn T => make_elim (Drule.instantiate' [SOME (Thm.ctyp_of thy5 T)] [] fun_cong)) branchTs;
   95.21 +      map (fn T => make_elim (Drule.instantiate' [SOME (Thm.global_ctyp_of thy5 T)] [] fun_cong)) branchTs;
   95.22  
   95.23      fun prove_iso_thms ds (inj_thms, elem_thms) =
   95.24        let
   95.25 @@ -626,7 +626,7 @@
   95.26        if length Ps = 1 then [Free ("P", snd (dest_Var (hd Ps)))]
   95.27        else map (Free o apfst fst o dest_Var) Ps;
   95.28      val indrule_lemma' =
   95.29 -      cterm_instantiate (map (Thm.cterm_of thy6) Ps ~~ map (Thm.cterm_of thy6) frees) indrule_lemma;
   95.30 +      cterm_instantiate (map (Thm.global_cterm_of thy6) Ps ~~ map (Thm.global_cterm_of thy6) frees) indrule_lemma;
   95.31  
   95.32      val dt_induct_prop = Old_Datatype_Prop.make_ind descr;
   95.33      val dt_induct =
    96.1 --- a/src/HOL/Tools/Old_Datatype/old_datatype_aux.ML	Fri Mar 06 14:01:08 2015 +0100
    96.2 +++ b/src/HOL/Tools/Old_Datatype/old_datatype_aux.ML	Fri Mar 06 15:58:56 2015 +0100
    96.3 @@ -149,7 +149,7 @@
    96.4          (case abstr (getP u) of
    96.5            NONE => NONE
    96.6          | SOME u' =>
    96.7 -            SOME (apply2 (Thm.cterm_of thy) (t |> getP |> snd |> head_of, u')))) (ts ~~ ts');
    96.8 +            SOME (apply2 (Thm.global_cterm_of thy) (t |> getP |> snd |> head_of, u')))) (ts ~~ ts');
    96.9      val indrule' = cterm_instantiate insts indrule;
   96.10    in resolve0_tac [indrule'] i end);
   96.11  
   96.12 @@ -166,7 +166,7 @@
   96.13      val _ $ (_ $ lhs $ _) = hd (rev (Logic.strip_assums_hyp prem'));
   96.14      val exhaustion' =
   96.15        cterm_instantiate
   96.16 -        [apply2 (Proof_Context.cterm_of ctxt)
   96.17 +        [apply2 (Thm.cterm_of ctxt)
   96.18            (head_of lhs, fold_rev (fn (_, T) => fn t => Abs ("z", T, t)) params (Bound 0))]
   96.19          exhaustion;
   96.20    in compose_tac ctxt (false, exhaustion', Thm.nprems_of exhaustion) i end);
    97.1 --- a/src/HOL/Tools/Old_Datatype/old_rep_datatype.ML	Fri Mar 06 14:01:08 2015 +0100
    97.2 +++ b/src/HOL/Tools/Old_Datatype/old_rep_datatype.ML	Fri Mar 06 15:58:56 2015 +0100
    97.3 @@ -46,7 +46,7 @@
    97.4            Abs ("z", T, HOLogic.imp $ HOLogic.mk_eq (Var (("a", maxidx + 1), T), Bound 0) $
    97.5              Var (("P", 0), HOLogic.boolT));
    97.6          val insts = take i dummyPs @ (P :: drop (i + 1) dummyPs);
    97.7 -        val insts' = map (Thm.cterm_of thy) induct_Ps ~~ map (Thm.cterm_of thy) insts;
    97.8 +        val insts' = map (Thm.global_cterm_of thy) induct_Ps ~~ map (Thm.global_cterm_of thy) insts;
    97.9          val induct' =
   97.10            refl RS
   97.11              (nth (Old_Datatype_Aux.split_conj_thm (cterm_instantiate insts' induct)) i
   97.12 @@ -208,7 +208,7 @@
   97.13              ((1 upto length recTs) ~~ recTs ~~ rec_unique_ts);
   97.14          val induct' = induct
   97.15            |> cterm_instantiate
   97.16 -            (map (Thm.cterm_of thy1) induct_Ps ~~ map (Thm.cterm_of thy1) insts);
   97.17 +            (map (Thm.global_cterm_of thy1) induct_Ps ~~ map (Thm.global_cterm_of thy1) insts);
   97.18        in
   97.19          Old_Datatype_Aux.split_conj_thm (Goal.prove_sorry_global thy1 [] []
   97.20            (HOLogic.mk_Trueprop (Old_Datatype_Aux.mk_conj rec_unique_ts))
   97.21 @@ -381,7 +381,7 @@
   97.22        let
   97.23          val _ $ (_ $ lhs $ _) = hd (Logic.strip_assums_hyp (hd (Thm.prems_of exhaustion)));
   97.24          val exhaustion' = exhaustion
   97.25 -          |> cterm_instantiate [apply2 (Thm.cterm_of thy) (lhs, Free ("x", T))];
   97.26 +          |> cterm_instantiate [apply2 (Thm.global_cterm_of thy) (lhs, Free ("x", T))];
   97.27          fun tac ctxt =
   97.28            EVERY [resolve_tac ctxt [exhaustion'] 1,
   97.29              ALLGOALS (asm_simp_tac
   97.30 @@ -453,7 +453,7 @@
   97.31          val nchotomy' = nchotomy RS spec;
   97.32          val [v] = Term.add_vars (Thm.concl_of nchotomy') [];
   97.33          val nchotomy'' =
   97.34 -          cterm_instantiate [apply2 (Thm.cterm_of thy) (Var v, Ma)] nchotomy';
   97.35 +          cterm_instantiate [apply2 (Thm.global_cterm_of thy) (Var v, Ma)] nchotomy';
   97.36        in
   97.37          Goal.prove_sorry_global thy [] (Logic.strip_imp_prems t) (Logic.strip_imp_concl t)
   97.38            (fn {context = ctxt, prems, ...} =>
    98.1 --- a/src/HOL/Tools/Predicate_Compile/core_data.ML	Fri Mar 06 14:01:08 2015 +0100
    98.2 +++ b/src/HOL/Tools/Predicate_Compile/core_data.ML	Fri Mar 06 15:58:56 2015 +0100
    98.3 @@ -235,7 +235,7 @@
    98.4          fun term_pair_of (ix, (ty, t)) = (Var (ix, ty), t)
    98.5          fun inst_of_matches tts =
    98.6            fold (Pattern.match thy) tts (Vartab.empty, Vartab.empty)
    98.7 -          |> snd |> Vartab.dest |> map (apply2 (Thm.cterm_of thy) o term_pair_of)
    98.8 +          |> snd |> Vartab.dest |> map (apply2 (Thm.global_cterm_of thy) o term_pair_of)
    98.9          val (cases, (eqs, prems1)) = apsnd (chop (nargs - nparams)) (chop n prems)
   98.10          val case_th =
   98.11            rewrite_rule ctxt2 (@{thm Predicate.eq_is_eq} :: map meta_eq_of eqs) (nth cases (i - 1))
    99.1 --- a/src/HOL/Tools/Predicate_Compile/predicate_compile_aux.ML	Fri Mar 06 14:01:08 2015 +0100
    99.2 +++ b/src/HOL/Tools/Predicate_Compile/predicate_compile_aux.ML	Fri Mar 06 15:58:56 2015 +0100
    99.3 @@ -877,7 +877,7 @@
    99.4      val (pats', intro_t', ctxt2) = rewrite_args args ([], intro_t, ctxt1)
    99.5      val (pats', _, ctxt3) = fold_atoms rewrite_prem intro_t' (pats', intro_t', ctxt2)
    99.6      fun rewrite_pat (ct1, ct2) =
    99.7 -      (ct1, Thm.cterm_of thy (Pattern.rewrite_term thy pats' [] (Thm.term_of ct2)))
    99.8 +      (ct1, Thm.global_cterm_of thy (Pattern.rewrite_term thy pats' [] (Thm.term_of ct2)))
    99.9      val t_insts' = map rewrite_pat t_insts
   99.10      val intro'' = Thm.instantiate (T_insts, t_insts') intro
   99.11      val [intro'''] = Variable.export ctxt3 ctxt [intro'']
   100.1 --- a/src/HOL/Tools/Predicate_Compile/predicate_compile_pred.ML	Fri Mar 06 14:01:08 2015 +0100
   100.2 +++ b/src/HOL/Tools/Predicate_Compile/predicate_compile_pred.ML	Fri Mar 06 15:58:56 2015 +0100
   100.3 @@ -158,14 +158,14 @@
   100.4            in
   100.5              (ps, Logic.list_implies (prems, HOLogic.mk_Trueprop lhs))
   100.6            end
   100.7 -        val x = (Thm.cterm_of thy o the_single o snd o strip_comb o HOLogic.dest_Trueprop o fst o
   100.8 +        val x = (Thm.global_cterm_of thy o the_single o snd o strip_comb o HOLogic.dest_Trueprop o fst o
   100.9            Logic.dest_implies o Thm.prop_of) @{thm exI}
  100.10          fun prove_introrule (index, (ps, introrule)) =
  100.11            let
  100.12              val tac = Simplifier.simp_tac (put_simpset HOL_basic_ss ctxt' addsimps [th]) 1
  100.13                THEN Inductive.select_disj_tac ctxt' (length disjuncts) (index + 1) 1
  100.14                THEN (EVERY (map (fn y =>
  100.15 -                rtac (Drule.cterm_instantiate [(x, Thm.cterm_of thy (Free y))] @{thm exI}) 1) ps))
  100.16 +                rtac (Drule.cterm_instantiate [(x, Thm.global_cterm_of thy (Free y))] @{thm exI}) 1) ps))
  100.17                THEN REPEAT_DETERM (rtac @{thm conjI} 1 THEN assume_tac ctxt' 1)
  100.18                THEN TRY (assume_tac ctxt' 1)
  100.19            in
   101.1 --- a/src/HOL/Tools/Qelim/cooper.ML	Fri Mar 06 14:01:08 2015 +0100
   101.2 +++ b/src/HOL/Tools/Qelim/cooper.ML	Fri Mar 06 15:58:56 2015 +0100
   101.3 @@ -694,7 +694,7 @@
   101.4  val (_, oracle) = Context.>>> (Context.map_theory_result
   101.5    (Thm.add_oracle (@{binding cooper},
   101.6      (fn (ctxt, t) =>
   101.7 -      (Proof_Context.cterm_of ctxt o Logic.mk_equals o apply2 HOLogic.mk_Trueprop)
   101.8 +      (Thm.cterm_of ctxt o Logic.mk_equals o apply2 HOLogic.mk_Trueprop)
   101.9          (t, procedure t)))));
  101.10  
  101.11  val comp_ss =
   102.1 --- a/src/HOL/Tools/Quickcheck/narrowing_generators.ML	Fri Mar 06 14:01:08 2015 +0100
   102.2 +++ b/src/HOL/Tools/Quickcheck/narrowing_generators.ML	Fri Mar 06 15:58:56 2015 +0100
   102.3 @@ -75,9 +75,9 @@
   102.4          (map mk_partial_term_of (frees ~~ tys))
   102.5          (@{term "Code_Evaluation.Const"} $ HOLogic.mk_literal c $ HOLogic.mk_typerep (tys ---> ty))
   102.6      val insts =
   102.7 -      map (SOME o Thm.cterm_of thy o Logic.unvarify_types_global o Logic.varify_global)
   102.8 +      map (SOME o Thm.global_cterm_of thy o Logic.unvarify_types_global o Logic.varify_global)
   102.9          [Free ("ty", Term.itselfT ty), narrowing_term, rhs]
  102.10 -    val cty = Thm.ctyp_of thy ty;
  102.11 +    val cty = Thm.global_ctyp_of thy ty;
  102.12    in
  102.13      @{thm partial_term_of_anything}
  102.14      |> Drule.instantiate' [SOME cty] insts
  102.15 @@ -94,12 +94,12 @@
  102.16        (fn TFree (v, _) => TFree (v, (the o AList.lookup (op =) vs) v)) raw_cs;
  102.17      val const = Axclass.param_of_inst thy (@{const_name partial_term_of}, tyco);
  102.18      val var_insts =
  102.19 -      map (SOME o Thm.cterm_of thy o Logic.unvarify_types_global o Logic.varify_global)
  102.20 +      map (SOME o Thm.global_cterm_of thy o Logic.unvarify_types_global o Logic.varify_global)
  102.21          [Free ("ty", Term.itselfT ty), @{term "Quickcheck_Narrowing.Narrowing_variable p tt"},
  102.22            @{term "Code_Evaluation.Free (STR ''_'')"} $ HOLogic.mk_typerep ty];
  102.23      val var_eq =
  102.24        @{thm partial_term_of_anything}
  102.25 -      |> Drule.instantiate' [SOME (Thm.ctyp_of thy ty)] var_insts
  102.26 +      |> Drule.instantiate' [SOME (Thm.global_ctyp_of thy ty)] var_insts
  102.27        |> Thm.varifyT_global
  102.28      val eqs = var_eq :: map_index (mk_partial_term_of_eq thy ty) cs;
  102.29   in
   103.1 --- a/src/HOL/Tools/Quickcheck/random_generators.ML	Fri Mar 06 14:01:08 2015 +0100
   103.2 +++ b/src/HOL/Tools/Quickcheck/random_generators.ML	Fri Mar 06 15:58:56 2015 +0100
   103.3 @@ -88,7 +88,7 @@
   103.4      val ((t_random_aux as Free (random_aux, T)) $ (t_k as Free (v, _)), proto_t_rhs) =
   103.5        (HOLogic.dest_eq o HOLogic.dest_Trueprop) eq;
   103.6      val Type (_, [_, iT]) = T;
   103.7 -    val icT = Thm.ctyp_of thy iT;
   103.8 +    val icT = Thm.global_ctyp_of thy iT;
   103.9      val inst = Thm.instantiate_cterm ([(aT, icT)], []);
  103.10      fun subst_v t' = map_aterms (fn t as Free (w, _) => if v = w then t' else t | t => t);
  103.11      val t_rhs = lambda t_k proto_t_rhs;
  103.12 @@ -103,7 +103,7 @@
  103.13      val rule = @{thm random_aux_rec}
  103.14        |> Drule.instantiate_normalize
  103.15          ([(aT, icT)],
  103.16 -          [(cT_random_aux, Thm.cterm_of thy t_random_aux), (cT_rhs, Thm.cterm_of thy t_rhs)]);
  103.17 +          [(cT_random_aux, Thm.global_cterm_of thy t_random_aux), (cT_rhs, Thm.global_cterm_of thy t_rhs)]);
  103.18      fun tac ctxt =
  103.19        ALLGOALS (rtac rule)
  103.20        THEN ALLGOALS (simp_tac (put_simpset rew_ss ctxt))
   104.1 --- a/src/HOL/Tools/Quotient/quotient_def.ML	Fri Mar 06 14:01:08 2015 +0100
   104.2 +++ b/src/HOL/Tools/Quotient/quotient_def.ML	Fri Mar 06 15:58:56 2015 +0100
   104.3 @@ -91,7 +91,7 @@
   104.4  
   104.5  fun mk_readable_rsp_thm_eq tm lthy =
   104.6    let
   104.7 -    val ctm = Proof_Context.cterm_of lthy tm
   104.8 +    val ctm = Thm.cterm_of lthy tm
   104.9      
  104.10      fun norm_fun_eq ctm = 
  104.11        let
   105.1 --- a/src/HOL/Tools/Quotient/quotient_tacs.ML	Fri Mar 06 14:01:08 2015 +0100
   105.2 +++ b/src/HOL/Tools/Quotient/quotient_tacs.ML	Fri Mar 06 15:58:56 2015 +0100
   105.3 @@ -73,10 +73,10 @@
   105.4  
   105.5  
   105.6  fun prep_trm thy (x, (T, t)) =
   105.7 -  (Thm.cterm_of thy (Var (x, T)), Thm.cterm_of thy t)
   105.8 +  (Thm.global_cterm_of thy (Var (x, T)), Thm.global_cterm_of thy t)
   105.9  
  105.10  fun prep_ty thy (x, (S, ty)) =
  105.11 -  (Thm.ctyp_of thy (TVar (x, S)), Thm.ctyp_of thy ty)
  105.12 +  (Thm.global_ctyp_of thy (TVar (x, S)), Thm.global_ctyp_of thy ty)
  105.13  
  105.14  fun get_match_inst thy pat trm =
  105.15    let
  105.16 @@ -100,8 +100,8 @@
  105.17    let
  105.18      val thy = Proof_Context.theory_of ctxt
  105.19      fun get_lhs thm = fst (Logic.dest_equals (Thm.concl_of thm))
  105.20 -    val ty_inst = map (SOME o Thm.ctyp_of thy) [domain_type (fastype_of R2)]
  105.21 -    val trm_inst = map (SOME o Thm.cterm_of thy) [R2, R1]
  105.22 +    val ty_inst = map (SOME o Thm.global_ctyp_of thy) [domain_type (fastype_of R2)]
  105.23 +    val trm_inst = map (SOME o Thm.global_cterm_of thy) [R2, R1]
  105.24    in
  105.25      (case try (Drule.instantiate' ty_inst trm_inst) ball_bex_thm of
  105.26        NONE => NONE
  105.27 @@ -199,10 +199,10 @@
  105.28        let
  105.29          val fx = fnctn x;
  105.30          val thy = Proof_Context.theory_of ctxt;
  105.31 -        val cx = Thm.cterm_of thy x;
  105.32 -        val cfx = Thm.cterm_of thy fx;
  105.33 -        val cxt = Thm.ctyp_of thy (fastype_of x);
  105.34 -        val cfxt = Thm.ctyp_of thy (fastype_of fx);
  105.35 +        val cx = Thm.global_cterm_of thy x;
  105.36 +        val cfx = Thm.global_cterm_of thy fx;
  105.37 +        val cxt = Thm.global_ctyp_of thy (fastype_of x);
  105.38 +        val cfxt = Thm.global_ctyp_of thy (fastype_of fx);
  105.39          val thm = Drule.instantiate' [SOME cxt, SOME cfxt] [SOME cx, SOME cfx] @{thm QT_imp}
  105.40        in
  105.41          Conv.rewr_conv thm ctrm
  105.42 @@ -251,8 +251,8 @@
  105.43                val ty_b = fastype_of qt_arg
  105.44                val ty_f = range_type (fastype_of f)
  105.45                val thy = Proof_Context.theory_of context
  105.46 -              val ty_inst = map (SOME o Thm.ctyp_of thy) [ty_x, ty_b, ty_f]
  105.47 -              val t_inst = map (SOME o Thm.cterm_of thy) [R2, f, g, x, y];
  105.48 +              val ty_inst = map (SOME o Thm.global_ctyp_of thy) [ty_x, ty_b, ty_f]
  105.49 +              val t_inst = map (SOME o Thm.global_cterm_of thy) [R2, f, g, x, y];
  105.50                val inst_thm = Drule.instantiate' ty_inst
  105.51                  ([NONE, NONE, NONE] @ t_inst) @{thm apply_rspQ3}
  105.52              in
  105.53 @@ -268,13 +268,13 @@
  105.54    let
  105.55      val thy = Proof_Context.theory_of ctxt
  105.56    in
  105.57 -    case try (Thm.cterm_of thy) R of (* There can be loose bounds in R *)
  105.58 +    case try (Thm.global_cterm_of thy) R of (* There can be loose bounds in R *)
  105.59        SOME ctm =>
  105.60          let
  105.61            val ty = domain_type (fastype_of R)
  105.62          in
  105.63 -          case try (Drule.instantiate' [SOME (Thm.ctyp_of thy ty)]
  105.64 -              [SOME (Thm.cterm_of thy R)]) @{thm equals_rsp} of
  105.65 +          case try (Drule.instantiate' [SOME (Thm.global_ctyp_of thy ty)]
  105.66 +              [SOME (Thm.global_cterm_of thy R)]) @{thm equals_rsp} of
  105.67              SOME thm => rtac thm THEN' quotient_tac ctxt
  105.68            | NONE => K no_tac
  105.69          end
  105.70 @@ -288,9 +288,9 @@
  105.71          (let
  105.72            val thy = Proof_Context.theory_of ctxt;
  105.73            val (ty_a, ty_b) = dest_funT (fastype_of abs);
  105.74 -          val ty_inst = map (SOME o Thm.ctyp_of thy) [ty_a, ty_b];
  105.75 +          val ty_inst = map (SOME o Thm.global_ctyp_of thy) [ty_a, ty_b];
  105.76          in
  105.77 -          case try (map (SOME o Thm.cterm_of thy)) [rel, abs, rep] of
  105.78 +          case try (map (SOME o Thm.global_cterm_of thy)) [rel, abs, rep] of
  105.79              SOME t_inst =>
  105.80                (case try (Drule.instantiate' ty_inst t_inst) @{thm rep_abs_rsp} of
  105.81                  SOME inst_thm => (rtac inst_thm THEN' quotient_tac ctxt) i
  105.82 @@ -478,8 +478,8 @@
  105.83          val thy = Proof_Context.theory_of ctxt
  105.84          val (ty_b, ty_a) = dest_funT (fastype_of r1)
  105.85          val (ty_c, ty_d) = dest_funT (fastype_of a2)
  105.86 -        val tyinst = map (SOME o Thm.ctyp_of thy) [ty_a, ty_b, ty_c, ty_d]
  105.87 -        val tinst = [NONE, NONE, SOME (Thm.cterm_of thy r1), NONE, SOME (Thm.cterm_of thy a2)]
  105.88 +        val tyinst = map (SOME o Thm.global_ctyp_of thy) [ty_a, ty_b, ty_c, ty_d]
  105.89 +        val tinst = [NONE, NONE, SOME (Thm.global_cterm_of thy r1), NONE, SOME (Thm.global_cterm_of thy a2)]
  105.90          val thm1 = Drule.instantiate' tyinst tinst @{thm lambda_prs[THEN eq_reflection]}
  105.91          val thm2 = solve_quotient_assm ctxt (solve_quotient_assm ctxt thm1)
  105.92          val thm3 = rewrite_rule ctxt @{thms id_apply[THEN eq_reflection]} thm2
  105.93 @@ -488,7 +488,7 @@
  105.94            then make_inst_id (Thm.term_of (Thm.lhs_of thm3)) (Thm.term_of ctrm)
  105.95            else make_inst (Thm.term_of (Thm.lhs_of thm3)) (Thm.term_of ctrm)
  105.96          val thm4 =
  105.97 -          Drule.instantiate_normalize ([], [(Thm.cterm_of thy insp, Thm.cterm_of thy inst)]) thm3
  105.98 +          Drule.instantiate_normalize ([], [(Thm.global_cterm_of thy insp, Thm.global_cterm_of thy inst)]) thm3
  105.99        in
 105.100          Conv.rewr_conv thm4 ctrm
 105.101        end
 105.102 @@ -557,7 +557,7 @@
 105.103      let
 105.104        val thy = Proof_Context.theory_of ctxt
 105.105        val vrs = Term.add_frees concl []
 105.106 -      val cvrs = map (Thm.cterm_of thy o Free) vrs
 105.107 +      val cvrs = map (Thm.global_cterm_of thy o Free) vrs
 105.108        val concl' = apply_under_Trueprop (all_list vrs) concl
 105.109        val goal = Logic.mk_implies (concl', concl)
 105.110        val rule = Goal.prove ctxt [] [] goal
 105.111 @@ -617,10 +617,10 @@
 105.112        handle Quotient_Term.LIFT_MATCH msg => lift_match_error ctxt msg rtrm qtrm
 105.113    in
 105.114      Drule.instantiate' []
 105.115 -      [SOME (Thm.cterm_of thy rtrm'),
 105.116 -       SOME (Thm.cterm_of thy reg_goal),
 105.117 +      [SOME (Thm.global_cterm_of thy rtrm'),
 105.118 +       SOME (Thm.global_cterm_of thy reg_goal),
 105.119         NONE,
 105.120 -       SOME (Thm.cterm_of thy inj_goal)] procedure_thm
 105.121 +       SOME (Thm.global_cterm_of thy inj_goal)] procedure_thm
 105.122    end
 105.123  
 105.124  
 105.125 @@ -677,9 +677,9 @@
 105.126        handle Quotient_Term.LIFT_MATCH msg => lift_match_error ctxt msg rtrm qtrm
 105.127    in
 105.128      Drule.instantiate' []
 105.129 -      [SOME (Thm.cterm_of thy reg_goal),
 105.130 +      [SOME (Thm.global_cterm_of thy reg_goal),
 105.131         NONE,
 105.132 -       SOME (Thm.cterm_of thy inj_goal)] partiality_procedure_thm
 105.133 +       SOME (Thm.global_cterm_of thy inj_goal)] partiality_procedure_thm
 105.134    end
 105.135  
 105.136  
   106.1 --- a/src/HOL/Tools/SMT/smt_normalize.ML	Fri Mar 06 14:01:08 2015 +0100
   106.2 +++ b/src/HOL/Tools/SMT/smt_normalize.ML	Fri Mar 06 15:58:56 2015 +0100
   106.3 @@ -31,7 +31,7 @@
   106.4  (** instantiate elimination rules **)
   106.5  
   106.6  local
   106.7 -  val (cpfalse, cfalse) = `SMT_Util.mk_cprop (Thm.cterm_of @{theory} @{const False})
   106.8 +  val (cpfalse, cfalse) = `SMT_Util.mk_cprop (Thm.global_cterm_of @{theory} @{const False})
   106.9  
  106.10    fun inst f ct thm =
  106.11      let val cv = f (Drule.strip_imp_concl (Thm.cprop_of thm))
  106.12 @@ -189,7 +189,7 @@
  106.13    fun mk_pat ct = Thm.apply (SMT_Util.instT' ct pat) ct
  106.14  
  106.15    fun mk_clist T =
  106.16 -    apply2 (Thm.cterm_of @{theory}) (SMT_Util.symb_cons_const T, SMT_Util.symb_nil_const T)
  106.17 +    apply2 (Thm.global_cterm_of @{theory}) (SMT_Util.symb_cons_const T, SMT_Util.symb_nil_const T)
  106.18    fun mk_list (ccons, cnil) f cts = fold_rev (Thm.mk_binop ccons o f) cts cnil
  106.19    val mk_pat_list = mk_list (mk_clist @{typ pattern})
  106.20    val mk_mpat_list = mk_list (mk_clist @{typ "pattern symb_list"})
   107.1 --- a/src/HOL/Tools/SMT/smt_real.ML	Fri Mar 06 14:01:08 2015 +0100
   107.2 +++ b/src/HOL/Tools/SMT/smt_real.ML	Fri Mar 06 15:58:56 2015 +0100
   107.3 @@ -64,14 +64,14 @@
   107.4    fun mk_nary _ cu [] = cu
   107.5      | mk_nary ct _ cts = uncurry (fold_rev (Thm.mk_binop ct)) (split_last cts)
   107.6  
   107.7 -  val mk_uminus = Thm.apply (Thm.cterm_of @{theory} @{const uminus (real)})
   107.8 -  val add = Thm.cterm_of @{theory} @{const plus (real)}
   107.9 +  val mk_uminus = Thm.apply (Thm.global_cterm_of @{theory} @{const uminus (real)})
  107.10 +  val add = Thm.global_cterm_of @{theory} @{const plus (real)}
  107.11    val real0 = Numeral.mk_cnumber @{ctyp real} 0
  107.12 -  val mk_sub = Thm.mk_binop (Thm.cterm_of @{theory} @{const minus (real)})
  107.13 -  val mk_mul = Thm.mk_binop (Thm.cterm_of @{theory} @{const times (real)})
  107.14 -  val mk_div = Thm.mk_binop (Thm.cterm_of @{theory} @{const divide (real)})
  107.15 -  val mk_lt = Thm.mk_binop (Thm.cterm_of @{theory} @{const less (real)})
  107.16 -  val mk_le = Thm.mk_binop (Thm.cterm_of @{theory} @{const less_eq (real)})
  107.17 +  val mk_sub = Thm.mk_binop (Thm.global_cterm_of @{theory} @{const minus (real)})
  107.18 +  val mk_mul = Thm.mk_binop (Thm.global_cterm_of @{theory} @{const times (real)})
  107.19 +  val mk_div = Thm.mk_binop (Thm.global_cterm_of @{theory} @{const divide (real)})
  107.20 +  val mk_lt = Thm.mk_binop (Thm.global_cterm_of @{theory} @{const less (real)})
  107.21 +  val mk_le = Thm.mk_binop (Thm.global_cterm_of @{theory} @{const less_eq (real)})
  107.22  
  107.23    fun z3_mk_builtin_fun (Z3_Interface.Sym ("-", _)) [ct] = SOME (mk_uminus ct)
  107.24      | z3_mk_builtin_fun (Z3_Interface.Sym ("+", _)) cts = SOME (mk_nary add real0 cts)
   108.1 --- a/src/HOL/Tools/SMT/smt_solver.ML	Fri Mar 06 14:01:08 2015 +0100
   108.2 +++ b/src/HOL/Tools/SMT/smt_solver.ML	Fri Mar 06 15:58:56 2015 +0100
   108.3 @@ -207,7 +207,7 @@
   108.4          else oracle ()
   108.5      | (result, _) => raise SMT_Failure.SMT (SMT_Failure.Counterexample (result = Sat)))
   108.6  
   108.7 -  val cfalse = Thm.cterm_of @{theory} @{prop False}
   108.8 +  val cfalse = Thm.global_cterm_of @{theory} @{prop False}
   108.9  in
  108.10  
  108.11  fun add_solver ({name, class, avail, command, options, smt_options, default_max_relevant, outcome,
   109.1 --- a/src/HOL/Tools/SMT/smt_util.ML	Fri Mar 06 14:01:08 2015 +0100
   109.2 +++ b/src/HOL/Tools/SMT/smt_util.ML	Fri Mar 06 15:58:56 2015 +0100
   109.3 @@ -165,7 +165,7 @@
   109.4  (* patterns and instantiations *)
   109.5  
   109.6  fun mk_const_pat thy name destT =
   109.7 -  let val cpat = Thm.cterm_of thy (Const (name, Sign.the_const_type thy name))
   109.8 +  let val cpat = Thm.global_cterm_of thy (Const (name, Sign.the_const_type thy name))
   109.9    in (destT (Thm.ctyp_of_cterm cpat), cpat) end
  109.10  
  109.11  val destT1 = hd o Thm.dest_ctyp
  109.12 @@ -194,7 +194,7 @@
  109.13  
  109.14  val dest_all_cbinders = repeat_yield (try o dest_cbinder)
  109.15  
  109.16 -val mk_cprop = Thm.apply (Thm.cterm_of @{theory} @{const Trueprop})
  109.17 +val mk_cprop = Thm.apply (Thm.global_cterm_of @{theory} @{const Trueprop})
  109.18  
  109.19  fun dest_cprop ct =
  109.20    (case Thm.term_of ct of
   110.1 --- a/src/HOL/Tools/SMT/z3_interface.ML	Fri Mar 06 14:01:08 2015 +0100
   110.2 +++ b/src/HOL/Tools/SMT/z3_interface.ML	Fri Mar 06 15:58:56 2015 +0100
   110.3 @@ -112,13 +112,13 @@
   110.4    | mk_builtin_num ctxt i T =
   110.5        chained_mk_builtin_num ctxt (get_mk_builtins ctxt) i T
   110.6  
   110.7 -val mk_true = Thm.cterm_of @{theory} (@{const Not} $ @{const False})
   110.8 -val mk_false = Thm.cterm_of @{theory} @{const False}
   110.9 -val mk_not = Thm.apply (Thm.cterm_of @{theory} @{const Not})
  110.10 -val mk_implies = Thm.mk_binop (Thm.cterm_of @{theory} @{const HOL.implies})
  110.11 -val mk_iff = Thm.mk_binop (Thm.cterm_of @{theory} @{const HOL.eq (bool)})
  110.12 -val conj = Thm.cterm_of @{theory} @{const HOL.conj}
  110.13 -val disj = Thm.cterm_of @{theory} @{const HOL.disj}
  110.14 +val mk_true = Thm.global_cterm_of @{theory} (@{const Not} $ @{const False})
  110.15 +val mk_false = Thm.global_cterm_of @{theory} @{const False}
  110.16 +val mk_not = Thm.apply (Thm.global_cterm_of @{theory} @{const Not})
  110.17 +val mk_implies = Thm.mk_binop (Thm.global_cterm_of @{theory} @{const HOL.implies})
  110.18 +val mk_iff = Thm.mk_binop (Thm.global_cterm_of @{theory} @{const HOL.eq (bool)})
  110.19 +val conj = Thm.global_cterm_of @{theory} @{const HOL.conj}
  110.20 +val disj = Thm.global_cterm_of @{theory} @{const HOL.disj}
  110.21  
  110.22  fun mk_nary _ cu [] = cu
  110.23    | mk_nary ct _ cts = uncurry (fold_rev (Thm.mk_binop ct)) (split_last cts)
  110.24 @@ -139,15 +139,15 @@
  110.25    let val cTs = Thm.dest_ctyp (Thm.ctyp_of_cterm array)
  110.26    in Thm.apply (Thm.mk_binop (SMT_Util.instTs cTs update) array index) value end
  110.27  
  110.28 -val mk_uminus = Thm.apply (Thm.cterm_of @{theory} @{const uminus (int)})
  110.29 -val add = Thm.cterm_of @{theory} @{const plus (int)}
  110.30 +val mk_uminus = Thm.apply (Thm.global_cterm_of @{theory} @{const uminus (int)})
  110.31 +val add = Thm.global_cterm_of @{theory} @{const plus (int)}
  110.32  val int0 = Numeral.mk_cnumber @{ctyp int} 0
  110.33 -val mk_sub = Thm.mk_binop (Thm.cterm_of @{theory} @{const minus (int)})
  110.34 -val mk_mul = Thm.mk_binop (Thm.cterm_of @{theory} @{const times (int)})
  110.35 -val mk_div = Thm.mk_binop (Thm.cterm_of @{theory} @{const z3div})
  110.36 -val mk_mod = Thm.mk_binop (Thm.cterm_of @{theory} @{const z3mod})
  110.37 -val mk_lt = Thm.mk_binop (Thm.cterm_of @{theory} @{const less (int)})
  110.38 -val mk_le = Thm.mk_binop (Thm.cterm_of @{theory} @{const less_eq (int)})
  110.39 +val mk_sub = Thm.mk_binop (Thm.global_cterm_of @{theory} @{const minus (int)})
  110.40 +val mk_mul = Thm.mk_binop (Thm.global_cterm_of @{theory} @{const times (int)})
  110.41 +val mk_div = Thm.mk_binop (Thm.global_cterm_of @{theory} @{const z3div})
  110.42 +val mk_mod = Thm.mk_binop (Thm.global_cterm_of @{theory} @{const z3mod})
  110.43 +val mk_lt = Thm.mk_binop (Thm.global_cterm_of @{theory} @{const less (int)})
  110.44 +val mk_le = Thm.mk_binop (Thm.global_cterm_of @{theory} @{const less_eq (int)})
  110.45  
  110.46  fun mk_builtin_fun ctxt sym cts =
  110.47    (case (sym, cts) of
   111.1 --- a/src/HOL/Tools/SMT/z3_replay.ML	Fri Mar 06 14:01:08 2015 +0100
   111.2 +++ b/src/HOL/Tools/SMT/z3_replay.ML	Fri Mar 06 15:58:56 2015 +0100
   111.3 @@ -23,7 +23,7 @@
   111.4      val maxidx = Thm.maxidx_of thm + 1
   111.5      val vs = params_of (Thm.prop_of thm)
   111.6      val vars = map_index (fn (i, (n, T)) => Var ((n, i + maxidx), T)) vs
   111.7 -  in Drule.forall_elim_list (map (Proof_Context.cterm_of ctxt) vars) thm end
   111.8 +  in Drule.forall_elim_list (map (Thm.cterm_of ctxt) vars) thm end
   111.9  
  111.10  fun add_paramTs names t =
  111.11    fold2 (fn n => fn (_, T) => AList.update (op =) (n, T)) names (params_of t)
  111.12 @@ -31,7 +31,7 @@
  111.13  fun new_fixes ctxt nTs =
  111.14    let
  111.15      val (ns, ctxt') = Variable.variant_fixes (replicate (length nTs) "") ctxt
  111.16 -    fun mk (n, T) n' = (n, Proof_Context.cterm_of ctxt' (Free (n', T)))
  111.17 +    fun mk (n, T) n' = (n, Thm.cterm_of ctxt' (Free (n', T)))
  111.18    in (ctxt', Symtab.make (map2 mk nTs ns)) end
  111.19  
  111.20  fun forall_elim_term ct (Const (@{const_name Pure.all}, _) $ (a as Abs _)) =
  111.21 @@ -60,7 +60,7 @@
  111.22    if Z3_Proof.is_assumption rule then
  111.23      (case Inttab.lookup assumed id of
  111.24        SOME (_, thm) => thm
  111.25 -    | NONE => Thm.assume (Proof_Context.cterm_of ctxt concl))
  111.26 +    | NONE => Thm.assume (Thm.cterm_of ctxt concl))
  111.27    else
  111.28      under_fixes (Z3_Replay_Methods.method_for rule) ctxt
  111.29        (if is_fix_step then (map snd nthms, []) else ([], nthms)) fixes concl
  111.30 @@ -123,7 +123,7 @@
  111.31          (cx as ((iidths, thms), (ctxt, ptab))) =
  111.32        if Z3_Proof.is_assumption rule andalso rule <> Z3_Proof.Hypothesis then
  111.33          let
  111.34 -          val ct = Proof_Context.cterm_of ctxt concl
  111.35 +          val ct = Thm.cterm_of ctxt concl
  111.36            val thm1 = Thm.trivial ct |> Conv.fconv_rule (Conv.arg1_conv (revert_conv outer_ctxt))
  111.37            val thm2 = singleton (Variable.export ctxt outer_ctxt) thm1
  111.38          in
   112.1 --- a/src/HOL/Tools/SMT/z3_replay_methods.ML	Fri Mar 06 14:01:08 2015 +0100
   112.2 +++ b/src/HOL/Tools/SMT/z3_replay_methods.ML	Fri Mar 06 15:58:56 2015 +0100
   112.3 @@ -88,7 +88,7 @@
   112.4  
   112.5  fun dest_thm thm = dest_prop (Thm.concl_of thm)
   112.6  
   112.7 -fun certify_prop ctxt t = Proof_Context.cterm_of ctxt (as_prop t)
   112.8 +fun certify_prop ctxt t = Thm.cterm_of ctxt (as_prop t)
   112.9  
  112.10  fun try_provers ctxt rule [] thms t = replay_rule_error ctxt rule thms t
  112.11    | try_provers ctxt rule ((name, prover) :: named_provers) thms t =
  112.12 @@ -108,12 +108,12 @@
  112.13  
  112.14  fun match_instantiateT ctxt t thm =
  112.15    if Term.exists_type (Term.exists_subtype Term.is_TVar) (dest_thm thm) then
  112.16 -    Thm.instantiate (gen_certify_inst fst TVar (Proof_Context.ctyp_of ctxt) ctxt thm t, []) thm
  112.17 +    Thm.instantiate (gen_certify_inst fst TVar (Thm.ctyp_of ctxt) ctxt thm t, []) thm
  112.18    else thm
  112.19  
  112.20  fun match_instantiate ctxt t thm =
  112.21    let val thm' = match_instantiateT ctxt t thm in
  112.22 -    Thm.instantiate ([], gen_certify_inst snd Var (Proof_Context.cterm_of ctxt) ctxt thm' t) thm'
  112.23 +    Thm.instantiate ([], gen_certify_inst snd Var (Thm.cterm_of ctxt) ctxt thm' t) thm'
  112.24    end
  112.25  
  112.26  fun apply_rule ctxt t =
  112.27 @@ -400,7 +400,7 @@
  112.28    end
  112.29  
  112.30  fun forall_intr ctxt t thm =
  112.31 -  let val ct = Proof_Context.cterm_of ctxt t
  112.32 +  let val ct = Thm.cterm_of ctxt t
  112.33    in Thm.forall_intr ct thm COMP_INCR @{thm iff_allI} end
  112.34  
  112.35  in
   113.1 --- a/src/HOL/Tools/Sledgehammer/sledgehammer_mash.ML	Fri Mar 06 14:01:08 2015 +0100
   113.2 +++ b/src/HOL/Tools/Sledgehammer/sledgehammer_mash.ML	Fri Mar 06 15:58:56 2015 +0100
   113.3 @@ -807,7 +807,7 @@
   113.4    | freeze (Free (s, T)) = Free (s, freezeT T)
   113.5    | freeze t = t
   113.6  
   113.7 -fun goal_of_thm thy = Thm.prop_of #> freeze #> Thm.cterm_of thy #> Goal.init
   113.8 +fun goal_of_thm thy = Thm.prop_of #> freeze #> Thm.global_cterm_of thy #> Goal.init
   113.9  
  113.10  fun run_prover_for_mash ctxt params prover goal_name facts goal =
  113.11    let
   114.1 --- a/src/HOL/Tools/TFL/casesplit.ML	Fri Mar 06 14:01:08 2015 +0100
   114.2 +++ b/src/HOL/Tools/TFL/casesplit.ML	Fri Mar 06 15:58:56 2015 +0100
   114.3 @@ -37,8 +37,8 @@
   114.4        val x = Free(vstr,ty)
   114.5        val abst = Abs(vstr, ty, Term.abstract_over (x, gt));
   114.6  
   114.7 -      val ctermify = Thm.cterm_of sgn;
   114.8 -      val ctypify = Thm.ctyp_of sgn;
   114.9 +      val ctermify = Thm.global_cterm_of sgn;
  114.10 +      val ctypify = Thm.global_ctyp_of sgn;
  114.11        val case_thm = case_thm_of_ty sgn ty;
  114.12  
  114.13        val abs_ct = ctermify abst;
   115.1 --- a/src/HOL/Tools/TFL/dcterm.ML	Fri Mar 06 14:01:08 2015 +0100
   115.2 +++ b/src/HOL/Tools/TFL/dcterm.ML	Fri Mar 06 15:58:56 2015 +0100
   115.3 @@ -67,7 +67,7 @@
   115.4   * Some simple constructor functions.
   115.5   *---------------------------------------------------------------------------*)
   115.6  
   115.7 -val mk_hol_const = Thm.cterm_of @{theory HOL} o Const;
   115.8 +val mk_hol_const = Thm.global_cterm_of @{theory HOL} o Const;
   115.9  
  115.10  fun mk_exists (r as (Bvar, Body)) =
  115.11    let val ty = Thm.typ_of_cterm Bvar
  115.12 @@ -181,7 +181,7 @@
  115.13      val t = Thm.term_of ctm;
  115.14    in
  115.15      if can HOLogic.dest_Trueprop t then ctm
  115.16 -    else Thm.cterm_of thy (HOLogic.mk_Trueprop t)
  115.17 +    else Thm.global_cterm_of thy (HOLogic.mk_Trueprop t)
  115.18    end
  115.19    handle TYPE (msg, _, _) => raise ERR "mk_prop" msg
  115.20      | TERM (msg, _) => raise ERR "mk_prop" msg;
   116.1 --- a/src/HOL/Tools/TFL/post.ML	Fri Mar 06 14:01:08 2015 +0100
   116.2 +++ b/src/HOL/Tools/TFL/post.ML	Fri Mar 06 15:58:56 2015 +0100
   116.3 @@ -73,7 +73,7 @@
   116.4  
   116.5  fun join_assums ctxt th =
   116.6    let val thy = Thm.theory_of_thm th
   116.7 -      val tych = Thm.cterm_of thy
   116.8 +      val tych = Thm.global_cterm_of thy
   116.9        val {lhs,rhs} = USyntax.dest_eq(#2 (USyntax.strip_forall (concl th)))
  116.10        val cntxtl = (#1 o USyntax.strip_imp) lhs  (* cntxtl should = cntxtr *)
  116.11        val cntxtr = (#1 o USyntax.strip_imp) rhs  (* but union is solider *)
  116.12 @@ -175,7 +175,7 @@
  116.13               (warning ("recdef (solve_eq): " ^ s); map (fn x => (x,i)) splitths);
  116.14  in
  116.15  fun derive_init_eqs ctxt rules eqs =
  116.16 -  map (Thm.trivial o Proof_Context.cterm_of ctxt o HOLogic.mk_Trueprop) eqs
  116.17 +  map (Thm.trivial o Thm.cterm_of ctxt o HOLogic.mk_Trueprop) eqs
  116.18    |> map_index (fn (i, e) => solve_eq ctxt (e, (get_related_thms i rules), i))
  116.19    |> flat;
  116.20  end;
   117.1 --- a/src/HOL/Tools/TFL/rules.ML	Fri Mar 06 14:01:08 2015 +0100
   117.2 +++ b/src/HOL/Tools/TFL/rules.ML	Fri Mar 06 15:58:56 2015 +0100
   117.3 @@ -161,7 +161,7 @@
   117.4  local val thy = Thm.theory_of_thm disjI1
   117.5        val prop = Thm.prop_of disjI1
   117.6        val [P,Q] = Misc_Legacy.term_vars prop
   117.7 -      val disj1 = Thm.forall_intr (Thm.cterm_of thy Q) disjI1
   117.8 +      val disj1 = Thm.forall_intr (Thm.global_cterm_of thy Q) disjI1
   117.9  in
  117.10  fun DISJ1 thm tm = thm RS (Thm.forall_elim (Dcterm.drop_prop tm) disj1)
  117.11    handle THM (msg, _, _) => raise RULES_ERR "DISJ1" msg;
  117.12 @@ -170,7 +170,7 @@
  117.13  local val thy = Thm.theory_of_thm disjI2
  117.14        val prop = Thm.prop_of disjI2
  117.15        val [P,Q] = Misc_Legacy.term_vars prop
  117.16 -      val disj2 = Thm.forall_intr (Thm.cterm_of thy P) disjI2
  117.17 +      val disj2 = Thm.forall_intr (Thm.global_cterm_of thy P) disjI2
  117.18  in
  117.19  fun DISJ2 tm thm = thm RS (Thm.forall_elim (Dcterm.drop_prop tm) disj2)
  117.20    handle THM (msg, _, _) => raise RULES_ERR "DISJ2" msg;
  117.21 @@ -265,8 +265,8 @@
  117.22        val thy = Thm.theory_of_thm spec
  117.23        val prop = Thm.prop_of spec
  117.24        val x = hd (tl (Misc_Legacy.term_vars prop))
  117.25 -      val cTV = Thm.ctyp_of thy (type_of x)
  117.26 -      val gspec = Thm.forall_intr (Thm.cterm_of thy x) spec
  117.27 +      val cTV = Thm.global_ctyp_of thy (type_of x)
  117.28 +      val gspec = Thm.forall_intr (Thm.global_cterm_of thy x) spec
  117.29  in
  117.30  fun SPEC tm thm =
  117.31     let val gspec' = Drule.instantiate_normalize ([(cTV, Thm.ctyp_of_cterm tm)], []) gspec
  117.32 @@ -282,10 +282,10 @@
  117.33  local val thy = Thm.theory_of_thm allI
  117.34        val prop = Thm.prop_of allI
  117.35        val [P] = Misc_Legacy.add_term_vars (prop, [])
  117.36 -      fun cty_theta s = map (fn (i, (S, ty)) => (Thm.ctyp_of s (TVar (i, S)), Thm.ctyp_of s ty))
  117.37 +      fun cty_theta s = map (fn (i, (S, ty)) => (Thm.global_ctyp_of s (TVar (i, S)), Thm.global_ctyp_of s ty))
  117.38        fun ctm_theta s = map (fn (i, (_, tm2)) =>
  117.39 -                             let val ctm2 = Thm.cterm_of s tm2
  117.40 -                             in (Thm.cterm_of s (Var(i, Thm.typ_of_cterm ctm2)), ctm2)
  117.41 +                             let val ctm2 = Thm.global_cterm_of s tm2
  117.42 +                             in (Thm.global_cterm_of s (Var(i, Thm.typ_of_cterm ctm2)), ctm2)
  117.43                               end)
  117.44        fun certify s (ty_theta,tm_theta) =
  117.45          (cty_theta s (Vartab.dest ty_theta),
  117.46 @@ -301,7 +301,7 @@
  117.47         val thm = Thm.implies_elim allI2 gth
  117.48         val tp $ (A $ Abs(_,_,M)) = Thm.prop_of thm
  117.49         val prop' = tp $ (A $ Abs(x,ty,M))
  117.50 -   in ALPHA thm (Thm.cterm_of thy prop')
  117.51 +   in ALPHA thm (Thm.global_cterm_of thy prop')
  117.52     end
  117.53  end;
  117.54  
  117.55 @@ -310,7 +310,7 @@
  117.56  fun GEN_ALL thm =
  117.57     let val thy = Thm.theory_of_thm thm
  117.58         val prop = Thm.prop_of thm
  117.59 -       val tycheck = Thm.cterm_of thy
  117.60 +       val tycheck = Thm.global_cterm_of thy
  117.61         val vlist = map tycheck (Misc_Legacy.add_term_vars (prop, []))
  117.62    in GENL vlist thm
  117.63    end;
  117.64 @@ -343,7 +343,7 @@
  117.65      val redex = Dcterm.capply lam fvar
  117.66      val thy = Thm.theory_of_cterm redex
  117.67      val t$u = Thm.term_of redex
  117.68 -    val residue = Thm.cterm_of thy (Term.betapply (t, u))
  117.69 +    val residue = Thm.global_cterm_of thy (Term.betapply (t, u))
  117.70    in
  117.71      GEN fvar (DISCH residue fact) RS (exth RS Thms.choose_thm)
  117.72        handle THM (msg, _, _) => raise RULES_ERR "CHOOSE" msg
  117.73 @@ -356,8 +356,8 @@
  117.74  fun EXISTS (template,witness) thm =
  117.75     let val thy = Thm.theory_of_thm thm
  117.76         val prop = Thm.prop_of thm
  117.77 -       val P' = Thm.cterm_of thy P
  117.78 -       val x' = Thm.cterm_of thy x
  117.79 +       val P' = Thm.global_cterm_of thy P
  117.80 +       val x' = Thm.global_cterm_of thy x
  117.81         val abstr = #2 (Dcterm.dest_comb template)
  117.82     in
  117.83     thm RS (cterm_instantiate[(P',abstr), (x',witness)] exI)
  117.84 @@ -389,9 +389,9 @@
  117.85  
  117.86  fun IT_EXISTS blist th =
  117.87     let val thy = Thm.theory_of_thm th
  117.88 -       val tych = Thm.cterm_of thy
  117.89 +       val tych = Thm.global_cterm_of thy
  117.90         val blist' = map (apply2 Thm.term_of) blist
  117.91 -       fun ex v M  = Thm.cterm_of thy (USyntax.mk_exists{Bvar=v,Body = M})
  117.92 +       fun ex v M  = Thm.global_cterm_of thy (USyntax.mk_exists{Bvar=v,Body = M})
  117.93  
  117.94    in
  117.95    fold_rev (fn (b as (r1,r2)) => fn thm =>
  117.96 @@ -511,7 +511,7 @@
  117.97  (* Note: Thm.rename_params_rule counts from 1, not 0 *)
  117.98  fun rename thm =
  117.99    let val thy = Thm.theory_of_thm thm
 117.100 -      val tych = Thm.cterm_of thy
 117.101 +      val tych = Thm.global_cterm_of thy
 117.102        val ants = Logic.strip_imp_prems (Thm.prop_of thm)
 117.103        val news = get (ants,1,[])
 117.104    in
 117.105 @@ -663,7 +663,7 @@
 117.106               val dummy = say (Display.string_of_thm ctxt thm)
 117.107               (* Unquantified eliminate *)
 117.108               fun uq_eliminate (thm,imp,thy) =
 117.109 -                 let val tych = Thm.cterm_of thy
 117.110 +                 let val tych = Thm.global_cterm_of thy
 117.111                       val dummy = print_cterm ctxt "To eliminate:" (tych imp)
 117.112                       val ants = map tych (Logic.strip_imp_prems imp)
 117.113                       val eq = Logic.strip_imp_concl imp
 117.114 @@ -683,7 +683,7 @@
 117.115                      orelse error "assertion failed in CONTEXT_REWRITE_RULE"
 117.116                    val imp_body1 = subst_free (ListPair.zip (args, vstrl))
 117.117                                               imp_body
 117.118 -                  val tych = Thm.cterm_of thy
 117.119 +                  val tych = Thm.global_cterm_of thy
 117.120                    val ants1 = map tych (Logic.strip_imp_prems imp_body1)
 117.121                    val eq1 = Logic.strip_imp_concl imp_body1
 117.122                    val Q = get_lhs eq1
 117.123 @@ -712,7 +712,7 @@
 117.124                in if (pbeta_redex Q) (length vlist)
 117.125                   then pq_eliminate (thm,thy,vlist,imp_body,Q)
 117.126                   else
 117.127 -                 let val tych = Thm.cterm_of thy
 117.128 +                 let val tych = Thm.global_cterm_of thy
 117.129                       val ants1 = map tych ants
 117.130                       val ctxt' = Simplifier.add_prems (map ASSUME ants1) ctxt
 117.131                       val Q_eeq_Q1 = Raw_Simplifier.rewrite_cterm
 117.132 @@ -763,13 +763,13 @@
 117.133                val antl = case rcontext of [] => []
 117.134                           | _   => [USyntax.list_mk_conj(map cncl rcontext)]
 117.135                val TC = genl(USyntax.list_mk_imp(antl, A))
 117.136 -              val dummy = print_cterm ctxt "func:" (Thm.cterm_of thy func)
 117.137 -              val dummy = print_cterm ctxt "TC:" (Thm.cterm_of thy (HOLogic.mk_Trueprop TC))
 117.138 +              val dummy = print_cterm ctxt "func:" (Thm.global_cterm_of thy func)
 117.139 +              val dummy = print_cterm ctxt "TC:" (Thm.global_cterm_of thy (HOLogic.mk_Trueprop TC))
 117.140                val dummy = tc_list := (TC :: !tc_list)
 117.141                val nestedp = is_some (USyntax.find_term is_func TC)
 117.142                val dummy = if nestedp then say "nested" else say "not_nested"
 117.143                val th' = if nestedp then raise RULES_ERR "solver" "nested function"
 117.144 -                        else let val cTC = Thm.cterm_of thy
 117.145 +                        else let val cTC = Thm.global_cterm_of thy
 117.146                                                (HOLogic.mk_Trueprop TC)
 117.147                               in case rcontext of
 117.148                                  [] => SPEC_ALL(ASSUME cTC)
   118.1 --- a/src/HOL/Tools/TFL/thry.ML	Fri Mar 06 14:01:08 2015 +0100
   118.2 +++ b/src/HOL/Tools/TFL/thry.ML	Fri Mar 06 15:58:56 2015 +0100
   118.3 @@ -48,7 +48,7 @@
   118.4   *---------------------------------------------------------------------------*)
   118.5  
   118.6  fun typecheck thry t =
   118.7 -  Thm.cterm_of thry t
   118.8 +  Thm.global_cterm_of thry t
   118.9      handle TYPE (msg, _, _) => raise THRY_ERR "typecheck" msg
  118.10        | TERM (msg, _) => raise THRY_ERR "typecheck" msg;
  118.11  
   119.1 --- a/src/HOL/Tools/Transfer/transfer.ML	Fri Mar 06 14:01:08 2015 +0100
   119.2 +++ b/src/HOL/Tools/Transfer/transfer.ML	Fri Mar 06 15:58:56 2015 +0100
   119.3 @@ -238,7 +238,7 @@
   119.4      val prems = map (HOLogic.mk_Trueprop o mk_is_equality) frees
   119.5      val prop1 = mk_prop' (Term.subst_atomic (eq_consts ~~ frees) t)
   119.6      val prop2 = fold Logic.all frees (Logic.list_implies (prems, prop1))
   119.7 -    val cprop = Thm.cterm_of thy prop2
   119.8 +    val cprop = Thm.global_cterm_of thy prop2
   119.9      val equal_thm = Raw_Simplifier.rewrite ctxt false [is_equality_lemma] cprop
  119.10      fun forall_elim thm = Thm.forall_elim_vars (Thm.maxidx_of thm + 1) thm
  119.11    in
  119.12 @@ -331,7 +331,7 @@
  119.13      val t' = subst_terms (fold Termtab.update (Domainp_tms ~~ frees) Termtab.empty) t
  119.14      val prop1 = fold Logic.all frees (Logic.list_implies (prems, mk_prop' t'))
  119.15      val prop2 = Logic.list_rename_params (rev names) prop1
  119.16 -    val cprop = Thm.cterm_of thy prop2
  119.17 +    val cprop = Thm.global_cterm_of thy prop2
  119.18      val equal_thm = Raw_Simplifier.rewrite ctxt false [Domainp_lemma] cprop
  119.19      fun forall_elim thm = Thm.forall_elim_vars (Thm.maxidx_of thm + 1) thm;
  119.20    in
  119.21 @@ -436,7 +436,7 @@
  119.22          let
  119.23            val ([x', y'], ctxt') = Variable.variant_fixes [x, y] ctxt
  119.24            val prop = mk_Rel (rel T U) $ Free (x', T) $ Free (y', U)
  119.25 -          val cprop = Thm.cterm_of thy (HOLogic.mk_Trueprop prop)
  119.26 +          val cprop = Thm.global_cterm_of thy (HOLogic.mk_Trueprop prop)
  119.27            val thm0 = Thm.assume cprop
  119.28            val (thm1, hyps) = zip ctxt' (thm0 :: thms) t u
  119.29            val ((r1, x), y) = apfst Thm.dest_comb (Thm.dest_comb (Thm.dest_arg cprop))
  119.30 @@ -462,13 +462,13 @@
  119.31            val T = fastype_of t
  119.32            val U = fastype_of u
  119.33            val prop = mk_Rel (rel T U) $ t $ u
  119.34 -          val cprop = Thm.cterm_of thy (HOLogic.mk_Trueprop prop)
  119.35 +          val cprop = Thm.global_cterm_of thy (HOLogic.mk_Trueprop prop)
  119.36          in
  119.37            (Thm.assume cprop, [cprop])
  119.38          end
  119.39      val r = mk_Rel (rel (fastype_of t) (fastype_of u))
  119.40      val goal = HOLogic.mk_Trueprop (r $ t $ u)
  119.41 -    val rename = Thm.trivial (Thm.cterm_of thy goal)
  119.42 +    val rename = Thm.trivial (Thm.global_cterm_of thy goal)
  119.43      val (thm, hyps) = zip ctxt [] t u
  119.44    in
  119.45      Drule.implies_intr_list hyps (thm RS rename)
  119.46 @@ -578,9 +578,9 @@
  119.47      val relT = @{typ "bool => bool => bool"}
  119.48      val idx = Thm.maxidx_of thm + 1
  119.49      val thy = Proof_Context.theory_of ctxt
  119.50 -    fun tinst (a, _) = (Thm.ctyp_of thy (TVar ((a, idx), @{sort type})), cbool)
  119.51 +    fun tinst (a, _) = (Thm.global_ctyp_of thy (TVar ((a, idx), @{sort type})), cbool)
  119.52      fun inst (a, t) =
  119.53 -      (Thm.cterm_of thy (Var (Name.clean_index (prep a, idx), relT)), Thm.cterm_of thy t)
  119.54 +      (Thm.global_cterm_of thy (Var (Name.clean_index (prep a, idx), relT)), Thm.global_cterm_of thy t)
  119.55    in
  119.56      thm
  119.57        |> Thm.generalize (tfrees, rnames @ frees) idx
  119.58 @@ -604,9 +604,9 @@
  119.59      val relT = @{typ "bool => bool => bool"}
  119.60      val idx = Thm.maxidx_of thm + 1
  119.61      val thy = Proof_Context.theory_of ctxt
  119.62 -    fun tinst (a, _) = (Thm.ctyp_of thy (TVar ((a, idx), @{sort type})), cbool)
  119.63 +    fun tinst (a, _) = (Thm.global_ctyp_of thy (TVar ((a, idx), @{sort type})), cbool)
  119.64      fun inst (a, t) =
  119.65 -      (Thm.cterm_of thy (Var (Name.clean_index (prep a, idx), relT)), Thm.cterm_of thy t)
  119.66 +      (Thm.global_cterm_of thy (Var (Name.clean_index (prep a, idx), relT)), Thm.global_cterm_of thy t)
  119.67    in
  119.68      thm
  119.69        |> Thm.generalize (tfrees, rnames @ frees) idx
   120.1 --- a/src/HOL/Tools/Transfer/transfer_bnf.ML	Fri Mar 06 14:01:08 2015 +0100
   120.2 +++ b/src/HOL/Tools/Transfer/transfer_bnf.ML	Fri Mar 06 15:58:56 2015 +0100
   120.3 @@ -344,8 +344,8 @@
   120.4      val predTs = map mk_pred1T As
   120.5      val (preds, lthy) = mk_Frees "P" predTs lthy
   120.6      val args = map mk_eq_onp preds
   120.7 -    val cTs = map (SOME o Proof_Context.ctyp_of lthy) (maps (replicate 2) As)
   120.8 -    val cts = map (SOME o Proof_Context.cterm_of lthy) args
   120.9 +    val cTs = map (SOME o Thm.ctyp_of lthy) (maps (replicate 2) As)
  120.10 +    val cts = map (SOME o Thm.cterm_of lthy) args
  120.11      fun get_rhs thm = thm |> Thm.concl_of |> HOLogic.dest_Trueprop |> HOLogic.dest_eq |> snd
  120.12      fun is_eqn thm = can get_rhs thm
  120.13      fun rel2pred_massage thm =
   121.1 --- a/src/HOL/Tools/choice_specification.ML	Fri Mar 06 14:01:08 2015 +0100
   121.2 +++ b/src/HOL/Tools/choice_specification.ML	Fri Mar 06 15:58:56 2015 +0100
   121.3 @@ -83,7 +83,7 @@
   121.4      val ctxt = Proof_Context.init_global thy
   121.5  
   121.6      val rew_imps = alt_props |>
   121.7 -      map (Object_Logic.atomize ctxt o Thm.cterm_of thy o Syntax.read_prop_global thy o snd)
   121.8 +      map (Object_Logic.atomize ctxt o Thm.global_cterm_of thy o Syntax.read_prop_global thy o snd)
   121.9      val props' = rew_imps |>
  121.10        map (HOLogic.dest_Trueprop o Thm.term_of o snd o Thm.dest_equals o Thm.cprop_of)
  121.11  
  121.12 @@ -136,7 +136,7 @@
  121.13        let
  121.14          fun inst_all thy v thm =
  121.15            let
  121.16 -            val cv = Thm.cterm_of thy v
  121.17 +            val cv = Thm.global_cterm_of thy v
  121.18              val cT = Thm.ctyp_of_cterm cv
  121.19              val spec' = instantiate' [SOME cT] [NONE, SOME cv] spec
  121.20            in thm RS spec' end
   122.1 --- a/src/HOL/Tools/cnf.ML	Fri Mar 06 14:01:08 2015 +0100
   122.2 +++ b/src/HOL/Tools/cnf.ML	Fri Mar 06 15:58:56 2015 +0100
   122.3 @@ -165,7 +165,7 @@
   122.4  (* ------------------------------------------------------------------------- *)
   122.5  
   122.6  fun inst_thm thy ts thm =
   122.7 -  instantiate' [] (map (SOME o Thm.cterm_of thy) ts) thm;
   122.8 +  instantiate' [] (map (SOME o Thm.global_cterm_of thy) ts) thm;
   122.9  
  122.10  (* ------------------------------------------------------------------------- *)
  122.11  (*                         Naive CNF transformation                          *)
  122.12 @@ -266,7 +266,7 @@
  122.13        | Abs _ => Conv.abs_conv (conv o snd) ctxt ct
  122.14        | Const _ => Conv.all_conv ct
  122.15        | t => make t RS eq_reflection)
  122.16 -  in conv ctxt (Thm.cterm_of thy t) RS meta_eq_to_obj_eq end
  122.17 +  in conv ctxt (Thm.global_cterm_of thy t) RS meta_eq_to_obj_eq end
  122.18  
  122.19  fun make_nnf_thm_under_quantifiers ctxt =
  122.20    make_under_quantifiers ctxt (make_nnf_thm (Proof_Context.theory_of ctxt))
  122.21 @@ -451,7 +451,7 @@
  122.22                        val thm1 = inst_thm thy [x', y'] make_cnfx_disj_ex_l   (* ((Ex x') | y') = (Ex (x' | y')) *)
  122.23                        val var = new_free ()
  122.24                        val thm2 = make_cnfx_disj_thm (betapply (x', var)) y'  (* (x' | y') = body' *)
  122.25 -                      val thm3 = Thm.forall_intr (Thm.cterm_of thy var) thm2 (* !!v. (x' | y') = body' *)
  122.26 +                      val thm3 = Thm.forall_intr (Thm.global_cterm_of thy var) thm2 (* !!v. (x' | y') = body' *)
  122.27                        val thm4 = Thm.strip_shyps (thm3 COMP allI)            (* ALL v. (x' | y') = body' *)
  122.28                        val thm5 = Thm.strip_shyps (thm4 RS make_cnfx_ex_cong) (* (EX v. (x' | y')) = (EX v. body') *)
  122.29                      in
  122.30 @@ -462,7 +462,7 @@
  122.31                        val thm1 = inst_thm thy [x', y'] make_cnfx_disj_ex_r   (* (x' | (Ex y')) = (Ex (x' | y')) *)
  122.32                        val var = new_free ()
  122.33                        val thm2 = make_cnfx_disj_thm x' (betapply (y', var))  (* (x' | y') = body' *)
  122.34 -                      val thm3 = Thm.forall_intr (Thm.cterm_of thy var) thm2 (* !!v. (x' | y') = body' *)
  122.35 +                      val thm3 = Thm.forall_intr (Thm.global_cterm_of thy var) thm2 (* !!v. (x' | y') = body' *)
  122.36                        val thm4 = Thm.strip_shyps (thm3 COMP allI)            (* ALL v. (x' | y') = body' *)
  122.37                        val thm5 = Thm.strip_shyps (thm4 RS make_cnfx_ex_cong) (* (EX v. (x' | y')) = (EX v. body') *)
  122.38                      in
  122.39 @@ -484,7 +484,7 @@
  122.40                val var = new_free ()
  122.41                val body = HOLogic.mk_conj (HOLogic.mk_disj (x, var), HOLogic.mk_disj (y, HOLogic.Not $ var))
  122.42                val thm2 = make_cnfx_thm_from_nnf body              (* (x | v) & (y | ~v) = body' *)
  122.43 -              val thm3 = Thm.forall_intr (Thm.cterm_of thy var) thm2 (* !!v. (x | v) & (y | ~v) = body' *)
  122.44 +              val thm3 = Thm.forall_intr (Thm.global_cterm_of thy var) thm2 (* !!v. (x | v) & (y | ~v) = body' *)
  122.45                val thm4 = Thm.strip_shyps (thm3 COMP allI)         (* ALL v. (x | v) & (y | ~v) = body' *)
  122.46                val thm5 = Thm.strip_shyps (thm4 RS make_cnfx_ex_cong)  (* (EX v. (x | v) & (y | ~v)) = (EX v. body') *)
  122.47              in
   123.1 --- a/src/HOL/Tools/code_evaluation.ML	Fri Mar 06 14:01:08 2015 +0100
   123.2 +++ b/src/HOL/Tools/code_evaluation.ML	Fri Mar 06 15:58:56 2015 +0100
   123.3 @@ -62,11 +62,11 @@
   123.4      val t = list_comb (Const (c, tys ---> ty),
   123.5        map Free (Name.invent_names Name.context "a" tys));
   123.6      val (arg, rhs) =
   123.7 -      apply2 (Thm.cterm_of thy o Logic.unvarify_types_global o Logic.varify_global)
   123.8 +      apply2 (Thm.global_cterm_of thy o Logic.unvarify_types_global o Logic.varify_global)
   123.9          (t,
  123.10            map_aterms (fn t as Free (_, ty) => HOLogic.mk_term_of ty t | t => t)
  123.11              (HOLogic.reflect_term t));
  123.12 -    val cty = Thm.ctyp_of thy ty;
  123.13 +    val cty = Thm.global_ctyp_of thy ty;
  123.14    in
  123.15      @{thm term_of_anything}
  123.16      |> Drule.instantiate' [SOME cty] [SOME arg, SOME rhs]
  123.17 @@ -102,11 +102,11 @@
  123.18      val arg = Var (("x", 0), ty);
  123.19      val rhs = Abs ("y", @{typ term}, HOLogic.reflect_term (Const (abs, ty_rep --> ty) $ Bound 0)) $
  123.20        (HOLogic.mk_term_of ty_rep (Const (proj, ty --> ty_rep) $ arg))
  123.21 -      |> Thm.cterm_of thy;
  123.22 -    val cty = Thm.ctyp_of thy ty;
  123.23 +      |> Thm.global_cterm_of thy;
  123.24 +    val cty = Thm.global_ctyp_of thy ty;
  123.25    in
  123.26      @{thm term_of_anything}
  123.27 -    |> Drule.instantiate' [SOME cty] [SOME (Thm.cterm_of thy arg), SOME rhs]
  123.28 +    |> Drule.instantiate' [SOME cty] [SOME (Thm.global_cterm_of thy arg), SOME rhs]
  123.29      |> Thm.varifyT_global
  123.30    end;
  123.31  
  123.32 @@ -207,10 +207,10 @@
  123.33      val t = Thm.term_of ct;
  123.34      val T = fastype_of t;
  123.35      val mk_eq =
  123.36 -      Thm.mk_binop (Proof_Context.cterm_of ctxt (Const (@{const_name Pure.eq}, T --> T --> propT)));
  123.37 +      Thm.mk_binop (Thm.cterm_of ctxt (Const (@{const_name Pure.eq}, T --> T --> propT)));
  123.38    in case value ctxt t
  123.39     of NONE => Thm.reflexive ct
  123.40 -    | SOME t' => conv ctxt (mk_eq ct (Proof_Context.cterm_of ctxt t')) RS @{thm eq_eq_TrueD}
  123.41 +    | SOME t' => conv ctxt (mk_eq ct (Thm.cterm_of ctxt t')) RS @{thm eq_eq_TrueD}
  123.42          handle THM _ =>
  123.43            error ("Failed to certify evaluation result of " ^ Syntax.string_of_term ctxt t)
  123.44    end;
   124.1 --- a/src/HOL/Tools/coinduction.ML	Fri Mar 06 14:01:08 2015 +0100
   124.2 +++ b/src/HOL/Tools/coinduction.ML	Fri Mar 06 15:58:56 2015 +0100
   124.3 @@ -79,7 +79,7 @@
   124.4              |> Ctr_Sugar_Util.list_exists_free vars
   124.5              |> Term.map_abs_vars (Variable.revert_fixed ctxt)
   124.6              |> fold_rev Term.absfree (names ~~ Ts)
   124.7 -            |> Proof_Context.cterm_of ctxt;
   124.8 +            |> Thm.cterm_of ctxt;
   124.9            val thm = Ctr_Sugar_Util.cterm_instantiate_pos [SOME phi] raw_thm;
  124.10            val e = length eqs;
  124.11            val p = length prems;
  124.12 @@ -88,7 +88,7 @@
  124.13              EVERY' (map (fn var =>
  124.14                resolve_tac ctxt
  124.15                  [Ctr_Sugar_Util.cterm_instantiate_pos
  124.16 -                  [NONE, SOME (Proof_Context.cterm_of ctxt var)] exI]) vars),
  124.17 +                  [NONE, SOME (Thm.cterm_of ctxt var)] exI]) vars),
  124.18              if p = 0 then Ctr_Sugar_Util.CONJ_WRAP' (K (resolve_tac ctxt [refl])) eqs
  124.19              else
  124.20                REPEAT_DETERM_N e o (resolve_tac ctxt [conjI] THEN' resolve_tac ctxt [refl]) THEN'
   125.1 --- a/src/HOL/Tools/datatype_realizer.ML	Fri Mar 06 14:01:08 2015 +0100
   125.2 +++ b/src/HOL/Tools/datatype_realizer.ML	Fri Mar 06 15:58:56 2015 +0100
   125.3 @@ -105,11 +105,11 @@
   125.4          (map (fn ((((i, _), T), U), tname) =>
   125.5            make_pred i U T (mk_proj i is r) (Free (tname, T)))
   125.6              (descr ~~ recTs ~~ rec_result_Ts ~~ tnames)));
   125.7 -    val inst = map (apply2 (Thm.cterm_of thy)) (map head_of (HOLogic.dest_conj
   125.8 +    val inst = map (apply2 (Thm.global_cterm_of thy)) (map head_of (HOLogic.dest_conj
   125.9        (HOLogic.dest_Trueprop (Thm.concl_of induct))) ~~ ps);
  125.10  
  125.11      val thm =
  125.12 -      Goal.prove_internal ctxt (map (Thm.cterm_of thy) prems) (Thm.cterm_of thy concl)
  125.13 +      Goal.prove_internal ctxt (map (Thm.global_cterm_of thy) prems) (Thm.global_cterm_of thy concl)
  125.14          (fn prems =>
  125.15             EVERY [
  125.16              rewrite_goals_tac ctxt (map mk_meta_eq [@{thm fst_conv}, @{thm snd_conv}]),
  125.17 @@ -185,12 +185,12 @@
  125.18      val y' = Free ("y", T);
  125.19  
  125.20      val thm =
  125.21 -      Goal.prove_internal ctxt (map (Thm.cterm_of thy) prems)
  125.22 -        (Thm.cterm_of thy
  125.23 +      Goal.prove_internal ctxt (map (Thm.global_cterm_of thy) prems)
  125.24 +        (Thm.global_cterm_of thy
  125.25            (HOLogic.mk_Trueprop (Free ("P", rT --> HOLogic.boolT) $ list_comb (r, rs @ [y']))))
  125.26          (fn prems =>
  125.27             EVERY [
  125.28 -            rtac (cterm_instantiate [apply2 (Thm.cterm_of thy) (y, y')] exhaust) 1,
  125.29 +            rtac (cterm_instantiate [apply2 (Thm.global_cterm_of thy) (y, y')] exhaust) 1,
  125.30              ALLGOALS (EVERY'
  125.31                [asm_simp_tac (put_simpset HOL_basic_ss ctxt addsimps case_rewrites),
  125.32                 resolve_tac ctxt prems, asm_simp_tac (put_simpset HOL_basic_ss ctxt)])])
   126.1 --- a/src/HOL/Tools/inductive.ML	Fri Mar 06 14:01:08 2015 +0100
   126.2 +++ b/src/HOL/Tools/inductive.ML	Fri Mar 06 15:58:56 2015 +0100
   126.3 @@ -573,7 +573,7 @@
   126.4  
   126.5      val elims = Induct.find_casesP ctxt prop;
   126.6  
   126.7 -    val cprop = Thm.cterm_of thy prop;
   126.8 +    val cprop = Thm.global_cterm_of thy prop;
   126.9      fun mk_elim rl =
  126.10        Thm.implies_intr cprop
  126.11          (Tactic.rule_by_tactic ctxt (mk_cases_tac ctxt) (Thm.assume cprop RS rl))
  126.12 @@ -636,7 +636,7 @@
  126.13        | _ => error
  126.14          ("equations matching pattern " ^ Syntax.string_of_term ctxt prop ^ " is not unique"));
  126.15      val inst =
  126.16 -      map (fn v => (Thm.cterm_of thy (Var v), Thm.cterm_of thy (Envir.subst_term subst (Var v))))
  126.17 +      map (fn v => (Thm.global_cterm_of thy (Var v), Thm.global_cterm_of thy (Envir.subst_term subst (Var v))))
  126.18          (Term.add_vars (lhs_of eq) []);
  126.19    in
  126.20      Drule.cterm_instantiate inst eq
  126.21 @@ -849,7 +849,7 @@
  126.22        ||> is_auxiliary ? Local_Theory.restore_naming lthy;
  126.23      val fp_def' =
  126.24        Simplifier.rewrite (put_simpset HOL_basic_ss lthy' addsimps [fp_def])
  126.25 -        (Proof_Context.cterm_of lthy' (list_comb (rec_const, params)));
  126.26 +        (Thm.cterm_of lthy' (list_comb (rec_const, params)));
  126.27      val specs =
  126.28        if length cs < 2 then []
  126.29        else
   127.1 --- a/src/HOL/Tools/inductive_set.ML	Fri Mar 06 14:01:08 2015 +0100
   127.2 +++ b/src/HOL/Tools/inductive_set.ML	Fri Mar 06 15:58:56 2015 +0100
   127.3 @@ -44,7 +44,7 @@
   127.4        val thy = Proof_Context.theory_of ctxt;
   127.5        fun close p t f =
   127.6          let val vs = Term.add_vars t []
   127.7 -        in Drule.instantiate' [] (rev (map (SOME o Thm.cterm_of thy o Var) vs))
   127.8 +        in Drule.instantiate' [] (rev (map (SOME o Thm.global_cterm_of thy o Var) vs))
   127.9            (p (fold (Logic.all o Var) vs t) f)
  127.10          end;
  127.11        fun mkop @{const_name HOL.conj} T x =
  127.12 @@ -93,8 +93,8 @@
  127.13              in
  127.14                if forall is_none rews then NONE
  127.15                else SOME (fold (fn th1 => fn th2 => Thm.combination th2 th1)
  127.16 -                (map2 (fn SOME r => K r | NONE => Thm.reflexive o Thm.cterm_of thy)
  127.17 -                   rews ts) (Thm.reflexive (Thm.cterm_of thy h)))
  127.18 +                (map2 (fn SOME r => K r | NONE => Thm.reflexive o Thm.global_cterm_of thy)
  127.19 +                   rews ts) (Thm.reflexive (Thm.global_cterm_of thy h)))
  127.20              end
  127.21          | NONE => NONE)
  127.22        | _ => NONE
  127.23 @@ -117,7 +117,7 @@
  127.24    Conv.fconv_rule (Conv.then_conv (Thm.beta_conversion true, fn ct =>
  127.25      Thm.transitive (Thm.eta_conversion ct)
  127.26        (Thm.symmetric (Thm.eta_conversion
  127.27 -        (Thm.cterm_of (Thm.theory_of_cterm ct) (eta_contract p (Thm.term_of ct)))))));
  127.28 +        (Thm.global_cterm_of (Thm.theory_of_cterm ct) (eta_contract p (Thm.term_of ct)))))));
  127.29  
  127.30  
  127.31  (***********************************************************)
  127.32 @@ -208,8 +208,8 @@
  127.33        val x' = map_type
  127.34          (K (Ts @ HOLogic.strip_ptupleT ps U ---> HOLogic.boolT)) x;
  127.35      in
  127.36 -      (Thm.cterm_of thy x,
  127.37 -       Thm.cterm_of thy (fold_rev (Term.abs o pair "x") Ts
  127.38 +      (Thm.global_cterm_of thy x,
  127.39 +       Thm.global_cterm_of thy (fold_rev (Term.abs o pair "x") Ts
  127.40           (HOLogic.Collect_const U $
  127.41              HOLogic.mk_psplits ps U HOLogic.boolT
  127.42                (list_comb (x', map Bound (length Ts - 1 downto 0))))))
  127.43 @@ -233,7 +233,7 @@
  127.44                Thm.dest_comb |> snd |> Drule.strip_comb |> snd |> hd |> Thm.dest_comb
  127.45            in
  127.46              thm' RS (Drule.cterm_instantiate [(arg_cong_f,
  127.47 -              Thm.cterm_of thy (Abs ("P", Ts ---> HOLogic.boolT,
  127.48 +              Thm.global_cterm_of thy (Abs ("P", Ts ---> HOLogic.boolT,
  127.49                  HOLogic.Collect_const U $ HOLogic.mk_psplits fs' U
  127.50                    HOLogic.boolT (Bound 0))))] arg_cong' RS sym)
  127.51            end)
  127.52 @@ -370,8 +370,8 @@
  127.53          val T = HOLogic.mk_ptupleT ps Us;
  127.54          val x' = map_type (K (Rs ---> HOLogic.mk_setT T)) x
  127.55        in
  127.56 -        (Thm.cterm_of thy x,
  127.57 -         Thm.cterm_of thy (fold_rev (Term.abs o pair "x") Ts
  127.58 +        (Thm.global_cterm_of thy x,
  127.59 +         Thm.global_cterm_of thy (fold_rev (Term.abs o pair "x") Ts
  127.60            (HOLogic.mk_mem (HOLogic.mk_ptuple ps T (map Bound (k downto 0)),
  127.61               list_comb (x', map Bound (l - 1 downto k + 1))))))
  127.62        end) fs;
   128.1 --- a/src/HOL/Tools/int_arith.ML	Fri Mar 06 14:01:08 2015 +0100
   128.2 +++ b/src/HOL/Tools/int_arith.ML	Fri Mar 06 15:58:56 2015 +0100
   128.3 @@ -82,7 +82,7 @@
   128.4  fun number_of thy T n =
   128.5    if not (Sign.of_sort thy (T, @{sort numeral}))
   128.6    then raise CTERM ("number_of", [])
   128.7 -  else Numeral.mk_cnumber (Thm.ctyp_of thy T) n;
   128.8 +  else Numeral.mk_cnumber (Thm.global_ctyp_of thy T) n;
   128.9  
  128.10  val setup =
  128.11    Lin_Arith.add_inj_thms [@{thm zle_int} RS iffD2, @{thm int_int_eq} RS iffD2]
   129.1 --- a/src/HOL/Tools/legacy_transfer.ML	Fri Mar 06 14:01:08 2015 +0100
   129.2 +++ b/src/HOL/Tools/legacy_transfer.ML	Fri Mar 06 15:58:56 2015 +0100
   129.3 @@ -59,8 +59,8 @@
   129.4  fun get_by_direction context (a, D) =
   129.5    let
   129.6      val ctxt = Context.proof_of context;
   129.7 -    val a0 = Proof_Context.cterm_of ctxt a;
   129.8 -    val D0 = Proof_Context.cterm_of ctxt D;
   129.9 +    val a0 = Thm.cterm_of ctxt a;
  129.10 +    val D0 = Thm.cterm_of ctxt D;
  129.11      fun eq_direction ((a, D), thm') =
  129.12        let
  129.13          val (a', D') = direction_of thm';
  129.14 @@ -118,9 +118,9 @@
  129.15        |> Variable.declare_term (Thm.term_of D);
  129.16      val vars = filter (fn ((v, _), T) => Type.could_unify (T, aT) andalso
  129.17        not (member (op =) leave v)) (Term.add_vars (Thm.prop_of thm) []);
  129.18 -    val c_vars = map (Proof_Context.cterm_of ctxt3 o Var) vars;
  129.19 +    val c_vars = map (Thm.cterm_of ctxt3 o Var) vars;
  129.20      val (vs', ctxt4) = Variable.variant_fixes (map (fst o fst) vars) ctxt3;
  129.21 -    val c_vars' = map (Proof_Context.cterm_of ctxt3 o (fn v => Free (v, bT))) vs';
  129.22 +    val c_vars' = map (Thm.cterm_of ctxt3 o (fn v => Free (v, bT))) vs';
  129.23      val c_exprs' = map (Thm.apply a) c_vars';
  129.24  
  129.25      (* transfer *)
   130.1 --- a/src/HOL/Tools/lin_arith.ML	Fri Mar 06 14:01:08 2015 +0100
   130.2 +++ b/src/HOL/Tools/lin_arith.ML	Fri Mar 06 15:58:56 2015 +0100
   130.3 @@ -62,8 +62,8 @@
   130.4  
   130.5  fun mk_nat_thm thy t =
   130.6    let
   130.7 -    val cn = Thm.cterm_of thy (Var (("n", 0), HOLogic.natT))
   130.8 -    and ct = Thm.cterm_of thy t
   130.9 +    val cn = Thm.global_cterm_of thy (Var (("n", 0), HOLogic.natT))
  130.10 +    and ct = Thm.global_cterm_of thy t
  130.11    in Drule.instantiate_normalize ([], [(cn, ct)]) @{thm le0} end;
  130.12  
  130.13  end;
   131.1 --- a/src/HOL/Tools/monomorph.ML	Fri Mar 06 14:01:08 2015 +0100
   131.2 +++ b/src/HOL/Tools/monomorph.ML	Fri Mar 06 15:58:56 2015 +0100
   131.3 @@ -159,7 +159,7 @@
   131.4  
   131.5  fun instantiate thy subst =
   131.6    let
   131.7 -    fun cert (ix, (S, T)) = apply2 (Thm.ctyp_of thy) (TVar (ix, S), T)
   131.8 +    fun cert (ix, (S, T)) = apply2 (Thm.global_ctyp_of thy) (TVar (ix, S), T)
   131.9      fun cert' subst = Vartab.fold (cons o cert) subst []
  131.10    in Thm.instantiate (cert' subst, []) end
  131.11  
   132.1 --- a/src/HOL/Tools/numeral.ML	Fri Mar 06 14:01:08 2015 +0100
   132.2 +++ b/src/HOL/Tools/numeral.ML	Fri Mar 06 15:58:56 2015 +0100
   132.3 @@ -44,10 +44,10 @@
   132.4  val oneT = Thm.ctyp_of_cterm one;
   132.5  
   132.6  val numeral = @{cpat "numeral"};
   132.7 -val numeralT = Thm.ctyp_of @{theory} (Term.range_type (Thm.typ_of_cterm numeral));
   132.8 +val numeralT = Thm.global_ctyp_of @{theory} (Term.range_type (Thm.typ_of_cterm numeral));
   132.9  
  132.10  val uminus = @{cpat "uminus"};
  132.11 -val uminusT = Thm.ctyp_of @{theory} (Term.range_type (Thm.typ_of_cterm uminus));
  132.12 +val uminusT = Thm.global_ctyp_of @{theory} (Term.range_type (Thm.typ_of_cterm uminus));
  132.13  
  132.14  fun instT T V = Thm.instantiate_cterm ([(V, T)], []);
  132.15  
   133.1 --- a/src/HOL/Tools/numeral_simprocs.ML	Fri Mar 06 14:01:08 2015 +0100
   133.2 +++ b/src/HOL/Tools/numeral_simprocs.ML	Fri Mar 06 15:58:56 2015 +0100
   133.3 @@ -483,7 +483,7 @@
   133.4      simplify_one ctxt (([th, cancel_th]) MRS trans);
   133.5  
   133.6  local
   133.7 -  val Tp_Eq = Thm.reflexive (Thm.cterm_of @{theory HOL} HOLogic.Trueprop)
   133.8 +  val Tp_Eq = Thm.reflexive (Thm.global_cterm_of @{theory HOL} HOLogic.Trueprop)
   133.9    fun Eq_True_elim Eq = 
  133.10      Thm.equal_elim (Thm.combination Tp_Eq (Thm.symmetric Eq)) @{thm TrueI}
  133.11  in
  133.12 @@ -494,7 +494,7 @@
  133.13        val pos = less $ zero $ t and neg = less $ t $ zero
  133.14        val thy = Proof_Context.theory_of ctxt
  133.15        fun prove p =
  133.16 -        SOME (Eq_True_elim (Simplifier.asm_rewrite ctxt (Thm.cterm_of thy p)))
  133.17 +        SOME (Eq_True_elim (Simplifier.asm_rewrite ctxt (Thm.global_cterm_of thy p)))
  133.18          handle THM _ => NONE
  133.19      in case prove pos of
  133.20           SOME th => SOME(th RS pos_th)
   134.1 --- a/src/HOL/Tools/record.ML	Fri Mar 06 14:01:08 2015 +0100
   134.2 +++ b/src/HOL/Tools/record.ML	Fri Mar 06 15:58:56 2015 +0100
   134.3 @@ -78,7 +78,7 @@
   134.4      fun match name ((name', _), _) = name = name';
   134.5      fun getvar name =
   134.6        (case find_first (match name) (Term.add_vars (Thm.prop_of thm) []) of
   134.7 -        SOME var => Thm.cterm_of (Thm.theory_of_thm thm) (Var var)
   134.8 +        SOME var => Thm.global_cterm_of (Thm.theory_of_thm thm) (Var var)
   134.9        | NONE => raise THM ("named_cterm_instantiate: " ^ name, 0, [thm]));
  134.10    in
  134.11      cterm_instantiate (map (apfst getvar) values) thm
  134.12 @@ -97,7 +97,7 @@
  134.13    let
  134.14      val exists_thm =
  134.15        UNIV_I
  134.16 -      |> Drule.instantiate' [SOME (Thm.ctyp_of thy (Logic.varifyT_global rep_type))] [];
  134.17 +      |> Drule.instantiate' [SOME (Thm.global_ctyp_of thy (Logic.varifyT_global rep_type))] [];
  134.18      val proj_constr = Abs_inverse OF [exists_thm];
  134.19      val absT = Type (tyco, map TFree vs);
  134.20    in
  134.21 @@ -141,7 +141,7 @@
  134.22      (*construct a type and body for the isomorphism constant by
  134.23        instantiating the theorem to which the definition will be applied*)
  134.24      val intro_inst =
  134.25 -      rep_inject RS named_cterm_instantiate [("abst", Thm.cterm_of typ_thy absC)] iso_tuple_intro;
  134.26 +      rep_inject RS named_cterm_instantiate [("abst", Thm.global_cterm_of typ_thy absC)] iso_tuple_intro;
  134.27      val (_, body) = Logic.dest_equals (List.last (Thm.prems_of intro_inst));
  134.28      val isomT = fastype_of body;
  134.29      val isom_binding = Binding.suffix_name isoN b;
  134.30 @@ -1121,7 +1121,7 @@
  134.31  
  134.32  fun get_upd_acc_cong_thm upd acc thy ss =
  134.33    let
  134.34 -    val insts = [("upd", Thm.cterm_of thy upd), ("ac", Thm.cterm_of thy acc)];
  134.35 +    val insts = [("upd", Thm.global_cterm_of thy upd), ("ac", Thm.global_cterm_of thy acc)];
  134.36      val prop = Thm.concl_of (named_cterm_instantiate insts updacc_cong_triv);
  134.37    in
  134.38      Goal.prove (Proof_Context.init_global thy) [] [] prop
  134.39 @@ -1375,9 +1375,9 @@
  134.40  
  134.41      fun mk_split_free_tac free induct_thm i =
  134.42        let
  134.43 -        val cfree = Thm.cterm_of thy free;
  134.44 +        val cfree = Thm.global_cterm_of thy free;
  134.45          val _$ (_ $ r) = Thm.concl_of induct_thm;
  134.46 -        val crec = Thm.cterm_of thy r;
  134.47 +        val crec = Thm.global_cterm_of thy r;
  134.48          val thm = cterm_instantiate [(crec, cfree)] induct_thm;
  134.49        in
  134.50          simp_tac (put_simpset HOL_basic_ss ctxt addsimps @{thms induct_atomize}) i THEN
  134.51 @@ -1473,7 +1473,7 @@
  134.52        | [x] => (head_of x, false));
  134.53      val rule'' =
  134.54        cterm_instantiate
  134.55 -        (map (apply2 (Proof_Context.cterm_of ctxt))
  134.56 +        (map (apply2 (Thm.cterm_of ctxt))
  134.57            (case rev params of
  134.58              [] =>
  134.59                (case AList.lookup (op =) (Term.add_frees g []) s of
  134.60 @@ -1606,7 +1606,7 @@
  134.61        (roughly) the definition of the accessor.*)
  134.62      val surject = timeit_msg ctxt "record extension surjective proof:" (fn () =>
  134.63        let
  134.64 -        val cterm_ext = Thm.cterm_of defs_thy ext;
  134.65 +        val cterm_ext = Thm.global_cterm_of defs_thy ext;
  134.66          val start = named_cterm_instantiate [("y", cterm_ext)] surject_assist_idE;
  134.67          val tactic1 =
  134.68            simp_tac (put_simpset HOL_basic_ss defs_ctxt addsimps [ext_def]) 1 THEN
  134.69 @@ -1756,7 +1756,7 @@
  134.70        fun mk_eq_refl thy =
  134.71          @{thm equal_refl}
  134.72          |> Thm.instantiate
  134.73 -          ([apply2 (Thm.ctyp_of thy) (TVar (("'a", 0), @{sort equal}), Logic.varifyT_global extT)], [])
  134.74 +          ([apply2 (Thm.global_ctyp_of thy) (TVar (("'a", 0), @{sort equal}), Logic.varifyT_global extT)], [])
  134.75          |> Axclass.unoverload thy;
  134.76        val ensure_random_record = ensure_sort_record (@{sort random}, mk_random_eq);
  134.77        val ensure_exhaustive_record =
  134.78 @@ -1943,8 +1943,8 @@
  134.79                fun to_Var (Free (c, T)) = Var ((c, 1), T);
  134.80              in mk_rec (map to_Var all_vars_more) 0 end;
  134.81  
  134.82 -          val cterm_rec = Thm.cterm_of ext_thy r_rec0;
  134.83 -          val cterm_vrs = Thm.cterm_of ext_thy r_rec0_Vars;
  134.84 +          val cterm_rec = Thm.global_cterm_of ext_thy r_rec0;
  134.85 +          val cterm_vrs = Thm.global_cterm_of ext_thy r_rec0_Vars;
  134.86            val insts = [("v", cterm_rec), ("v'", cterm_vrs)];
  134.87            val init_thm = named_cterm_instantiate insts updacc_eq_triv;
  134.88            val terminal = rtac updacc_eq_idI 1 THEN rtac refl 1;
   135.1 --- a/src/HOL/Tools/reification.ML	Fri Mar 06 14:01:08 2015 +0100
   135.2 +++ b/src/HOL/Tools/reification.ML	Fri Mar 06 15:58:56 2015 +0100
   135.3 @@ -27,7 +27,7 @@
   135.4    let
   135.5      val ct = case some_t
   135.6       of NONE => Thm.dest_arg concl
   135.7 -      | SOME t => Proof_Context.cterm_of ctxt t
   135.8 +      | SOME t => Thm.cterm_of ctxt t
   135.9      val thm = conv ct;
  135.10    in
  135.11      if Thm.is_reflexive thm then no_tac
  135.12 @@ -83,7 +83,7 @@
  135.13          (fn {context, prems, ...} =>
  135.14            Local_Defs.unfold_tac context (map tryext prems) THEN rtac th' 1)) RS sym;
  135.15      val (cong' :: vars') =
  135.16 -      Variable.export ctxt'' ctxt (cong :: map (Drule.mk_term o Proof_Context.cterm_of ctxt'') vs);
  135.17 +      Variable.export ctxt'' ctxt (cong :: map (Drule.mk_term o Thm.cterm_of ctxt'') vs);
  135.18      val vs' = map (fst o fst o Term.dest_Var o Thm.term_of o Drule.dest_term) vars';
  135.19  
  135.20    in (vs', cong') end;
  135.21 @@ -140,8 +140,8 @@
  135.22              val ([raw_xn], ctxt') = Variable.variant_fixes ["x"] ctxt;
  135.23              val (xn, ta) = Syntax_Trans.variant_abs (raw_xn, xT, ta);  (* FIXME !? *)
  135.24              val x = Free (xn, xT);
  135.25 -            val cx = Proof_Context.cterm_of ctxt' x;
  135.26 -            val cta = Proof_Context.cterm_of ctxt' ta;
  135.27 +            val cx = Thm.cterm_of ctxt' x;
  135.28 +            val cta = Thm.cterm_of ctxt' ta;
  135.29              val bds = (case AList.lookup Type.could_unify bds (HOLogic.listT xT) of
  135.30                  NONE => error "tryabsdecomp: Type not found in the Environement"
  135.31                | SOME (bsT, atsT) => AList.update Type.could_unify (HOLogic.listT xT,
  135.32 @@ -169,12 +169,12 @@
  135.33            val (fnvs, invs) = List.partition (fn ((vn, _),_) => member (op =) vns vn) (Vartab.dest tmenv);
  135.34            val (fts, its) =
  135.35              (map (snd o snd) fnvs,
  135.36 -             map (fn ((vn, vi), (tT, t)) => apply2 (Thm.cterm_of thy) (Var ((vn, vi), tT), t)) invs);
  135.37 +             map (fn ((vn, vi), (tT, t)) => apply2 (Thm.global_cterm_of thy) (Var ((vn, vi), tT), t)) invs);
  135.38            val ctyenv =
  135.39 -            map (fn ((vn, vi), (s, ty)) => apply2 (Thm.ctyp_of thy) (TVar ((vn, vi), s), ty))
  135.40 +            map (fn ((vn, vi), (s, ty)) => apply2 (Thm.global_ctyp_of thy) (TVar ((vn, vi), s), ty))
  135.41                (Vartab.dest tyenv);
  135.42          in
  135.43 -          ((map (Thm.cterm_of thy) fts ~~ replicate (length fts) ctxt,
  135.44 +          ((map (Thm.global_cterm_of thy) fts ~~ replicate (length fts) ctxt,
  135.45               apfst (FWD (Drule.instantiate_normalize (ctyenv, its) cong))), bds)
  135.46          end handle Pattern.MATCH => decomp_reify da congs (ct, ctxt) bds))
  135.47    end;
  135.48 @@ -203,14 +203,14 @@
  135.49          val sbst = Envir.subst_term (tyenv, tmenv);
  135.50          val sbsT = Envir.subst_type tyenv;
  135.51          val subst_ty =
  135.52 -          map (fn (n, (s, t)) => apply2 (Thm.ctyp_of thy) (TVar (n, s), t)) (Vartab.dest tyenv)
  135.53 +          map (fn (n, (s, t)) => apply2 (Thm.global_ctyp_of thy) (TVar (n, s), t)) (Vartab.dest tyenv)
  135.54          val tml = Vartab.dest tmenv;
  135.55          val (subst_ns, bds) = fold_map
  135.56            (fn (Const _ $ _ $ n, Var (xn0, _)) => fn bds =>
  135.57              let
  135.58                val name = snd (the (AList.lookup (op =) tml xn0));
  135.59                val (idx, bds) = index_of name bds;
  135.60 -            in (apply2 (Thm.cterm_of thy) (n, idx |> HOLogic.mk_nat), bds) end) subst bds;
  135.61 +            in (apply2 (Thm.global_cterm_of thy) (n, idx |> HOLogic.mk_nat), bds) end) subst bds;
  135.62          val subst_vs =
  135.63            let
  135.64              fun h (Const _ $ (vs as Var (_, lT)) $ _, Var (_, T)) =
  135.65 @@ -220,10 +220,10 @@
  135.66                  val (bsT, _) = the (AList.lookup Type.could_unify bds lT);
  135.67                  val vsn = the (AList.lookup (op =) vsns_map vs);
  135.68                  val vs' = fold_rev (fn x => fn xs => cns $ x $xs) bsT (Free (vsn, lT'));
  135.69 -              in apply2 (Thm.cterm_of thy) (vs, vs') end;
  135.70 +              in apply2 (Thm.global_cterm_of thy) (vs, vs') end;
  135.71            in map h subst end;
  135.72          val cts =
  135.73 -          map (fn ((vn, vi), (tT, t)) => apply2 (Thm.cterm_of thy) (Var ((vn, vi), tT), t))
  135.74 +          map (fn ((vn, vi), (tT, t)) => apply2 (Thm.global_cterm_of thy) (Var ((vn, vi), tT), t))
  135.75              (fold (AList.delete (fn (((a : string), _), (b, _)) => a = b))
  135.76                (map (fn n => (n, 0)) xns) tml);
  135.77          val substt =
  135.78 @@ -261,14 +261,14 @@
  135.79      val (vs, ctxt') = Variable.variant_fixes (replicate (length tys) "vs") ctxt;
  135.80      val subst =
  135.81        the o AList.lookup (op =)
  135.82 -        (map2 (fn T => fn v => (T, Proof_Context.cterm_of ctxt' (Free (v, T)))) tys vs);
  135.83 +        (map2 (fn T => fn v => (T, Thm.cterm_of ctxt' (Free (v, T)))) tys vs);
  135.84      fun prep_eq eq =
  135.85        let
  135.86          val (_, _ :: vs) = eq |> Thm.prop_of |> HOLogic.dest_Trueprop
  135.87            |> HOLogic.dest_eq |> fst |> strip_comb;
  135.88          val subst =
  135.89            map_filter
  135.90 -            (fn (v as Var (_, T)) => SOME (Proof_Context.cterm_of ctxt' v, subst T)
  135.91 +            (fn (v as Var (_, T)) => SOME (Thm.cterm_of ctxt' v, subst T)
  135.92                | _ => NONE) vs;
  135.93        in Thm.instantiate ([], subst) eq end;
  135.94      val (ps, congs) = map_split (mk_congeq ctxt' fs o prep_eq) eqs;
  135.95 @@ -287,7 +287,7 @@
  135.96        |> strip_comb |> snd |> filter is_list_var;
  135.97      val vs = map (fn v as Var (_, T) =>
  135.98        (v, the (AList.lookup Type.could_unify bds' T) |> snd |> HOLogic.mk_list (dest_listT T))) vars;
  135.99 -    val th' = Drule.instantiate_normalize ([], map (apply2 (Proof_Context.cterm_of ctxt)) vs) th;
 135.100 +    val th' = Drule.instantiate_normalize ([], map (apply2 (Thm.cterm_of ctxt)) vs) th;
 135.101      val th'' = Thm.symmetric (dereify ctxt [] (Thm.lhs_of th'));
 135.102    in Thm.transitive th'' th' end;
 135.103  
   136.1 --- a/src/HOL/Tools/sat.ML	Fri Mar 06 14:01:08 2015 +0100
   136.2 +++ b/src/HOL/Tools/sat.ML	Fri Mar 06 15:58:56 2015 +0100
   136.3 @@ -73,7 +73,7 @@
   136.4  val resolution_thm =
   136.5    @{lemma "(P ==> False) ==> (~ P ==> False) ==> False" by (rule case_split)}
   136.6  
   136.7 -val cP = Thm.cterm_of @{theory} (Var (("P", 0), HOLogic.boolT));
   136.8 +val cP = Thm.global_cterm_of @{theory} (Var (("P", 0), HOLogic.boolT));
   136.9  
  136.10  (* ------------------------------------------------------------------------- *)
  136.11  (* lit_ord: an order on integers that considers their absolute values only,  *)
   137.1 --- a/src/HOL/Tools/set_comprehension_pointfree.ML	Fri Mar 06 14:01:08 2015 +0100
   137.2 +++ b/src/HOL/Tools/set_comprehension_pointfree.ML	Fri Mar 06 15:58:56 2015 +0100
   137.3 @@ -468,7 +468,7 @@
   137.4  fun conv ctxt t =
   137.5    let
   137.6      val ([t'], ctxt') = Variable.import_terms true [t] (Variable.declare_term t ctxt)
   137.7 -    val ct = Proof_Context.cterm_of ctxt' t'
   137.8 +    val ct = Thm.cterm_of ctxt' t'
   137.9      fun unfold_conv thms =
  137.10        Raw_Simplifier.rewrite_cterm (false, false, false) (K (K NONE))
  137.11          (empty_simpset ctxt' addsimps thms)
  137.12 @@ -498,7 +498,7 @@
  137.13      val arg_cong = Thm.incr_indexes (maxidx_of_term pred + 1) @{thm arg_cong}
  137.14      val f $ _ = fst (HOLogic.dest_eq (HOLogic.dest_Trueprop (Thm.concl_of arg_cong)))
  137.15    in
  137.16 -    cterm_instantiate [(Proof_Context.cterm_of ctxt f, Proof_Context.cterm_of ctxt pred)] arg_cong
  137.17 +    cterm_instantiate [(Thm.cterm_of ctxt f, Thm.cterm_of ctxt pred)] arg_cong
  137.18    end;
  137.19  
  137.20  fun simproc ctxt redex =
   138.1 --- a/src/HOL/Tools/split_rule.ML	Fri Mar 06 14:01:08 2015 +0100
   138.2 +++ b/src/HOL/Tools/split_rule.ML	Fri Mar 06 15:58:56 2015 +0100
   138.3 @@ -42,7 +42,7 @@
   138.4  fun split_rule_var' (t as Var (v, Type ("fun", [T1, T2]))) rl =
   138.5        let val T' = HOLogic.flatten_tupleT T1 ---> T2;
   138.6            val newt = ap_split T1 T2 (Var (v, T'));
   138.7 -          val cterm = Thm.cterm_of (Thm.theory_of_thm rl);
   138.8 +          val cterm = Thm.global_cterm_of (Thm.theory_of_thm rl);
   138.9        in Thm.instantiate ([], [(cterm t, cterm newt)]) rl end
  138.10    | split_rule_var' _ rl = rl;
  138.11  
  138.12 @@ -56,7 +56,7 @@
  138.13  
  138.14  fun complete_split_rule_var (t as Var (v, T), ts) (rl, vs) =
  138.15        let
  138.16 -        val cterm = Thm.cterm_of (Thm.theory_of_thm rl)
  138.17 +        val cterm = Thm.global_cterm_of (Thm.theory_of_thm rl)
  138.18          val (Us', U') = strip_type T;
  138.19          val Us = take (length ts) Us';
  138.20          val U = drop (length ts) Us' ---> U';
  138.21 @@ -70,7 +70,7 @@
  138.22                end
  138.23            | mk_tuple _ x = x;
  138.24          val newt = ap_split' Us U (Var (v, T'));
  138.25 -        val cterm = Thm.cterm_of (Thm.theory_of_thm rl);
  138.26 +        val cterm = Thm.global_cterm_of (Thm.theory_of_thm rl);
  138.27          val (vs', insts) = fold mk_tuple ts (vs, []);
  138.28        in
  138.29          (Drule.instantiate_normalize ([], [(cterm t, cterm newt)] @ insts) rl, vs')
   139.1 --- a/src/HOL/Word/WordBitwise.thy	Fri Mar 06 14:01:08 2015 +0100
   139.2 +++ b/src/HOL/Word/WordBitwise.thy	Fri Mar 06 15:58:56 2015 +0100
   139.3 @@ -560,7 +560,7 @@
   139.4          (replicate i @{term Suc});
   139.5      val _ = if arg = arg' then raise TERM ("", []) else ();
   139.6      fun propfn g = HOLogic.mk_eq (g arg, g arg')
   139.7 -      |> HOLogic.mk_Trueprop |> Thm.cterm_of thy;
   139.8 +      |> HOLogic.mk_Trueprop |> Thm.global_cterm_of thy;
   139.9      val eq1 = Goal.prove_internal ctxt [] (propfn I)
  139.10        (K (simp_tac (put_simpset word_ss ctxt) 1));
  139.11    in Goal.prove_internal ctxt [] (propfn (curry (op $) f))
   140.1 --- a/src/HOL/ex/Iff_Oracle.thy	Fri Mar 06 14:01:08 2015 +0100
   140.2 +++ b/src/HOL/ex/Iff_Oracle.thy	Fri Mar 06 15:58:56 2015 +0100
   140.3 @@ -24,7 +24,7 @@
   140.4    in
   140.5      fn (thy, n) =>
   140.6        if n > 0 andalso n mod 2 = 0
   140.7 -      then Thm.cterm_of thy (HOLogic.mk_Trueprop (mk_iff n))
   140.8 +      then Thm.global_cterm_of thy (HOLogic.mk_Trueprop (mk_iff n))
   140.9        else raise Fail ("iff_oracle: " ^ string_of_int n)
  140.10    end
  140.11  \<close>
   141.1 --- a/src/HOL/ex/SAT_Examples.thy	Fri Mar 06 14:01:08 2015 +0100
   141.2 +++ b/src/HOL/ex/SAT_Examples.thy	Fri Mar 06 15:58:56 2015 +0100
   141.3 @@ -534,7 +534,7 @@
   141.4          | and_to_list fm acc = rev (fm :: acc)
   141.5        val clauses = and_to_list prop_fm []
   141.6        val terms = map (HOLogic.mk_Trueprop o Prop_Logic.term_of_prop_formula) clauses
   141.7 -      val cterms = map (Thm.cterm_of @{theory}) terms
   141.8 +      val cterms = map (Thm.global_cterm_of @{theory}) terms
   141.9        val start = Timing.start ()
  141.10        val _ = SAT.rawsat_thm @{context} cterms
  141.11      in
   142.1 --- a/src/HOL/ex/SVC_Oracle.thy	Fri Mar 06 14:01:08 2015 +0100
   142.2 +++ b/src/HOL/ex/SVC_Oracle.thy	Fri Mar 06 15:58:56 2015 +0100
   142.3 @@ -113,7 +113,7 @@
   142.4    let
   142.5      val thy = Thm.theory_of_cterm ct;
   142.6      val (abs_goal, _) = svc_abstract (Thm.term_of ct);
   142.7 -    val th = svc_oracle (Thm.cterm_of thy abs_goal);
   142.8 +    val th = svc_oracle (Thm.global_cterm_of thy abs_goal);
   142.9     in compose_tac ctxt (false, th, 0) i end
  142.10     handle TERM _ => no_tac);
  142.11  *}
   143.1 --- a/src/Provers/Arith/fast_lin_arith.ML	Fri Mar 06 14:01:08 2015 +0100
   143.2 +++ b/src/Provers/Arith/fast_lin_arith.ML	Fri Mar 06 15:58:56 2015 +0100
   143.3 @@ -905,7 +905,7 @@
   143.4    let
   143.5      val thy = Proof_Context.theory_of ctxt
   143.6      val nTconcl = LA_Logic.neg_prop Tconcl
   143.7 -    val cnTconcl = Thm.cterm_of thy nTconcl
   143.8 +    val cnTconcl = Thm.global_cterm_of thy nTconcl
   143.9      val nTconclthm = Thm.assume cnTconcl
  143.10      val tree = (if split_neq then splitasms ctxt else Tip) (thms @ [nTconclthm])
  143.11      val (Falsethm, _) = fwdproof ctxt tree js
   144.1 --- a/src/Provers/hypsubst.ML	Fri Mar 06 14:01:08 2015 +0100
   144.2 +++ b/src/Provers/hypsubst.ML	Fri Mar 06 15:58:56 2015 +0100
   144.3 @@ -184,10 +184,10 @@
   144.4              (case (if b then t else t') of
   144.5                Bound j => subst_bounds (map Bound ((1 upto j) @ 0 :: (j + 2 upto length ps)), Q)
   144.6              | t => Term.abstract_over (t, Term.incr_boundvars 1 Q));
   144.7 -        val (instT, _) = Thm.match (apply2 (Thm.cterm_of thy o Logic.mk_type) (V, U));
   144.8 +        val (instT, _) = Thm.match (apply2 (Thm.global_cterm_of thy o Logic.mk_type) (V, U));
   144.9        in
  144.10          compose_tac ctxt (true, Drule.instantiate_normalize (instT,
  144.11 -          map (apply2 (Thm.cterm_of thy))
  144.12 +          map (apply2 (Thm.global_cterm_of thy))
  144.13              [(Var (ixn, Ts ---> U --> body_type T), u),
  144.14               (Var (fst (dest_Var (head_of v1)), Ts ---> U), fold_rev Term.abs ps t),
  144.15               (Var (fst (dest_Var (head_of v2)), Ts ---> U), fold_rev Term.abs ps t')]) rl',
   145.1 --- a/src/Provers/splitter.ML	Fri Mar 06 14:01:08 2015 +0100
   145.2 +++ b/src/Provers/splitter.ML	Fri Mar 06 15:58:56 2015 +0100
   145.3 @@ -315,7 +315,7 @@
   145.4  
   145.5  fun inst_lift Ts t (T, U, pos) state i =
   145.6    let
   145.7 -    val cert = Thm.cterm_of (Thm.theory_of_thm state);
   145.8 +    val cert = Thm.global_cterm_of (Thm.theory_of_thm state);
   145.9      val (cntxt, u) = mk_cntxt t pos (T --> U);
  145.10      val trlift' = Thm.lift_rule (Thm.cprem_of state i)
  145.11        (Thm.rename_boundvars abs_lift u trlift);
  145.12 @@ -343,7 +343,7 @@
  145.13      val thm' = Thm.lift_rule (Thm.cprem_of state i) thm;
  145.14      val (P, _) = strip_comb (fst (Logic.dest_equals
  145.15        (Logic.strip_assums_concl (Thm.prop_of thm'))));
  145.16 -    val cert = Thm.cterm_of (Thm.theory_of_thm state);
  145.17 +    val cert = Thm.global_cterm_of (Thm.theory_of_thm state);
  145.18      val cntxt = mk_cntxt_splitthm t tt TB;
  145.19    in cterm_instantiate [(cert P, cert (abss Ts cntxt))] thm'
  145.20    end;
   146.1 --- a/src/Provers/trancl.ML	Fri Mar 06 14:01:08 2015 +0100
   146.2 +++ b/src/Provers/trancl.ML	Fri Mar 06 15:58:56 2015 +0100
   146.3 @@ -94,7 +94,7 @@
   146.4    let
   146.5      fun inst thm =
   146.6        let val SOME (_, _, r', _) = decomp (Thm.concl_of thm)
   146.7 -      in Drule.cterm_instantiate [(Thm.cterm_of thy r', Thm.cterm_of thy r)] thm end;
   146.8 +      in Drule.cterm_instantiate [(Thm.global_cterm_of thy r', Thm.global_cterm_of thy r)] thm end;
   146.9      fun pr (Asm i) = nth asms i
  146.10        | pr (Thm (prfs, thm)) = map pr prfs MRS inst thm;
  146.11    in pr end;
   147.1 --- a/src/Pure/Isar/class_declaration.ML	Fri Mar 06 14:01:08 2015 +0100
   147.2 +++ b/src/Pure/Isar/class_declaration.ML	Fri Mar 06 15:58:56 2015 +0100
   147.3 @@ -93,7 +93,7 @@
   147.4      val sup_of_classes = map (snd o Class.rules thy) sups;
   147.5      val loc_axiom_intros = map Drule.export_without_context_open (Locale.axioms_of thy class);
   147.6      val axclass_intro = #intro (Axclass.get_info thy class);
   147.7 -    val base_sort_trivs = Thm.of_sort (Thm.ctyp_of thy aT, base_sort);
   147.8 +    val base_sort_trivs = Thm.of_sort (Thm.global_ctyp_of thy aT, base_sort);
   147.9      fun tac ctxt =
  147.10        REPEAT (SOMEGOAL
  147.11          (match_tac ctxt (axclass_intro :: sup_of_classes @ loc_axiom_intros @ base_sort_trivs)
   148.1 --- a/src/Pure/Isar/code.ML	Fri Mar 06 14:01:08 2015 +0100
   148.2 +++ b/src/Pure/Isar/code.ML	Fri Mar 06 15:58:56 2015 +0100
   148.3 @@ -363,7 +363,7 @@
   148.4  
   148.5  fun analyze_constructor thy (c, ty) =
   148.6    let
   148.7 -    val _ = Thm.cterm_of thy (Const (c, ty));
   148.8 +    val _ = Thm.global_cterm_of thy (Const (c, ty));
   148.9      val ty_decl = devarify (const_typ thy c);
  148.10      fun last_typ c_ty ty =
  148.11        let
  148.12 @@ -611,7 +611,7 @@
  148.13      val vars = burrow_fst (Name.variant_list (map (fst o fst) (Term.add_vars lhs [])))
  148.14        raw_vars;
  148.15      fun expand (v, ty) thm = Drule.fun_cong_rule thm
  148.16 -      (Thm.cterm_of thy (Var ((v, 0), ty)));
  148.17 +      (Thm.global_cterm_of thy (Var ((v, 0), ty)));
  148.18    in
  148.19      thm
  148.20      |> fold expand vars
  148.21 @@ -681,7 +681,7 @@
  148.22  (* code equation certificates *)
  148.23  
  148.24  fun build_head thy (c, ty) =
  148.25 -  Thm.cterm_of thy (Logic.mk_equals (Free ("HEAD", ty), Const (c, ty)));
  148.26 +  Thm.global_cterm_of thy (Logic.mk_equals (Free ("HEAD", ty), Const (c, ty)));
  148.27  
  148.28  fun get_head thy cert_thm =
  148.29    let
  148.30 @@ -716,7 +716,7 @@
  148.31      val lhs = (fst o Logic.dest_equals o Thm.prop_of) abs_thm
  148.32      val ty = fastype_of lhs;
  148.33      val ty_abs = (fastype_of o snd o dest_comb) lhs;
  148.34 -    val abs = Thm.cterm_of thy (Const (c, ty --> ty_abs));
  148.35 +    val abs = Thm.global_cterm_of thy (Const (c, ty --> ty_abs));
  148.36      val raw_concrete_thm = Drule.transitive_thm OF [Thm.symmetric cert, Thm.combination (Thm.reflexive abs) abs_thm];
  148.37    in (c, (Thm.varifyT_global o zero_var_indexes) raw_concrete_thm) end;
  148.38  
  148.39 @@ -804,7 +804,7 @@
  148.40        |> constrain_thm thy vs sorts;
  148.41      val head' = Thm.term_of head
  148.42        |> subst
  148.43 -      |> Thm.cterm_of thy;
  148.44 +      |> Thm.global_cterm_of thy;
  148.45      val cert_thm'' = cert_thm'
  148.46        |> Thm.elim_implies (Thm.assume head');
  148.47    in cert_thm'' end;
   149.1 --- a/src/Pure/Isar/element.ML	Fri Mar 06 14:01:08 2015 +0100
   149.2 +++ b/src/Pure/Isar/element.ML	Fri Mar 06 15:58:56 2015 +0100
   149.3 @@ -203,7 +203,7 @@
   149.4        let
   149.5          val thy = Thm.theory_of_thm th;
   149.6          val thesis = Var ((Auto_Bind.thesisN, Thm.maxidx_of th + 1), fastype_of C);
   149.7 -        val th' = Thm.instantiate ([], [(Thm.cterm_of thy C, Thm.cterm_of thy thesis)]) th;
   149.8 +        val th' = Thm.instantiate ([], [(Thm.global_cterm_of thy C, Thm.global_cterm_of thy thesis)]) th;
   149.9        in (th', true) end
  149.10    | NONE => (th, false));
  149.11  
  149.12 @@ -339,7 +339,7 @@
  149.13  fun instantiate_tfrees thy subst th =
  149.14    let
  149.15      val idx = Thm.maxidx_of th + 1;
  149.16 -    fun cert_inst (a, (S, T)) = (Thm.ctyp_of thy (TVar ((a, idx), S)), Thm.ctyp_of thy T);
  149.17 +    fun cert_inst (a, (S, T)) = (Thm.global_ctyp_of thy (TVar ((a, idx), S)), Thm.global_ctyp_of thy T);
  149.18  
  149.19      fun add_inst (a, S) insts =
  149.20        if AList.defined (op =) insts a then insts
  149.21 @@ -354,8 +354,8 @@
  149.22    end;
  149.23  
  149.24  fun instantiate_frees thy subst =
  149.25 -  Drule.forall_intr_list (map (Thm.cterm_of thy o Free o fst) subst) #>
  149.26 -  Drule.forall_elim_list (map (Thm.cterm_of thy o snd) subst);
  149.27 +  Drule.forall_intr_list (map (Thm.global_cterm_of thy o Free o fst) subst) #>
  149.28 +  Drule.forall_elim_list (map (Thm.global_cterm_of thy o snd) subst);
  149.29  
  149.30  fun hyps_rule rule th =
  149.31    let val {hyps, ...} = Thm.crep_thm th in
   150.1 --- a/src/Pure/Isar/expression.ML	Fri Mar 06 14:01:08 2015 +0100
   150.2 +++ b/src/Pure/Isar/expression.ML	Fri Mar 06 15:58:56 2015 +0100
   150.3 @@ -629,8 +629,8 @@
   150.4      val bodyT = Term.fastype_of body;
   150.5    in
   150.6      if bodyT = propT
   150.7 -    then (t, propT, Thm.reflexive (Thm.cterm_of thy t))
   150.8 -    else (body, bodyT, Object_Logic.atomize (Proof_Context.init_global thy) (Thm.cterm_of thy t))
   150.9 +    then (t, propT, Thm.reflexive (Thm.global_cterm_of thy t))
  150.10 +    else (body, bodyT, Object_Logic.atomize (Proof_Context.init_global thy) (Thm.global_cterm_of thy t))
  150.11    end;
  150.12  
  150.13  (* achieve plain syntax for locale predicates (without "PROP") *)
  150.14 @@ -684,11 +684,11 @@
  150.15          compose_tac defs_ctxt (false, body_eq RS Drule.equal_elim_rule1, 1) 1 THEN
  150.16          compose_tac defs_ctxt
  150.17            (false,
  150.18 -            Conjunction.intr_balanced (map (Thm.assume o Thm.cterm_of defs_thy) norm_ts), 0) 1);
  150.19 +            Conjunction.intr_balanced (map (Thm.assume o Thm.global_cterm_of defs_thy) norm_ts), 0) 1);
  150.20  
  150.21      val conjuncts =
  150.22        (Drule.equal_elim_rule2 OF
  150.23 -        [body_eq, rewrite_rule defs_ctxt [pred_def] (Thm.assume (Thm.cterm_of defs_thy statement))])
  150.24 +        [body_eq, rewrite_rule defs_ctxt [pred_def] (Thm.assume (Thm.global_cterm_of defs_thy statement))])
  150.25        |> Conjunction.elim_balanced (length ts);
  150.26  
  150.27      val (_, axioms_ctxt) = defs_ctxt
  150.28 @@ -705,7 +705,7 @@
  150.29  fun define_preds binding parms (((exts, exts'), (ints, ints')), defs) thy =
  150.30    let
  150.31      val ctxt = Proof_Context.init_global thy;
  150.32 -    val defs' = map (Thm.cterm_of thy #> Assumption.assume ctxt #> Drule.abs_def) defs;
  150.33 +    val defs' = map (Thm.global_cterm_of thy #> Assumption.assume ctxt #> Drule.abs_def) defs;
  150.34  
  150.35      val (a_pred, a_intro, a_axioms, thy'') =
  150.36        if null exts then (NONE, NONE, [], thy)
  150.37 @@ -757,7 +757,7 @@
  150.38  
  150.39  fun defines_to_notes ctxt (Defines defs) =
  150.40        Notes ("", map (fn (a, (def, _)) =>
  150.41 -        (a, [([Assumption.assume ctxt (Proof_Context.cterm_of ctxt def)],
  150.42 +        (a, [([Assumption.assume ctxt (Thm.cterm_of ctxt def)],
  150.43            [(Attrib.internal o K) Locale.witness_add])])) defs)
  150.44    | defines_to_notes _ e = e;
  150.45  
  150.46 @@ -806,7 +806,7 @@
  150.47      val notes =
  150.48        if is_some asm then
  150.49          [("", [((Binding.conceal (Binding.suffix_name ("_" ^ axiomsN) binding), []),
  150.50 -          [([Assumption.assume pred_ctxt (Thm.cterm_of thy' (the asm))],
  150.51 +          [([Assumption.assume pred_ctxt (Thm.global_cterm_of thy' (the asm))],
  150.52              [(Attrib.internal o K) Locale.witness_add])])])]
  150.53        else [];
  150.54  
   151.1 --- a/src/Pure/Isar/generic_target.ML	Fri Mar 06 14:01:08 2015 +0100
   151.2 +++ b/src/Pure/Isar/generic_target.ML	Fri Mar 06 15:58:56 2015 +0100
   151.3 @@ -179,7 +179,7 @@
   151.4      val thy_ctxt = Proof_Context.init_global (Proof_Context.theory_of lthy);
   151.5  
   151.6      (*term and type parameters*)
   151.7 -    val ((defs, _), rhs') = Proof_Context.cterm_of lthy rhs
   151.8 +    val ((defs, _), rhs') = Thm.cterm_of lthy rhs
   151.9        |> Local_Defs.export_cterm lthy thy_ctxt ||> Thm.term_of;
  151.10  
  151.11      val xs = Variable.add_fixed lthy rhs' [];
  151.12 @@ -205,7 +205,7 @@
  151.13      (*result*)
  151.14      val def =
  151.15        Thm.transitive local_def global_def
  151.16 -      |> Local_Defs.contract lthy3 defs (Proof_Context.cterm_of lthy3 (Logic.mk_equals (lhs, rhs)));
  151.17 +      |> Local_Defs.contract lthy3 defs (Thm.cterm_of lthy3 (Logic.mk_equals (lhs, rhs)));
  151.18      val ([(res_name, [res])], lthy4) = lthy3
  151.19        |> Local_Theory.notes [((if internal then Binding.empty else b_def, atts), [([def], [])])];
  151.20    in ((lhs, (res_name, res)), lthy4) end;
  151.21 @@ -228,7 +228,7 @@
  151.22      val tfrees = map TFree (Thm.fold_terms Term.add_tfrees th' []);
  151.23      val frees = map Free (Thm.fold_terms Term.add_frees th' []);
  151.24      val (th'' :: vs) =
  151.25 -      (th' :: map (Drule.mk_term o Proof_Context.cterm_of ctxt) (map Logic.mk_type tfrees @ frees))
  151.26 +      (th' :: map (Drule.mk_term o Thm.cterm_of ctxt) (map Logic.mk_type tfrees @ frees))
  151.27        |> Variable.export ctxt thy_ctxt
  151.28        |> Drule.zero_var_indexes_list;
  151.29  
  151.30 @@ -243,9 +243,9 @@
  151.31      val instT = map_filter (fn (TVar v, T) => SOME (v, T) | _ => NONE) (tvars ~~ tfrees);
  151.32      val inst = filter (is_Var o fst) (vars ~~ frees);
  151.33      val cinstT = instT
  151.34 -      |> map (apply2 (Proof_Context.ctyp_of ctxt) o apfst TVar);
  151.35 +      |> map (apply2 (Thm.ctyp_of ctxt) o apfst TVar);
  151.36      val cinst = inst
  151.37 -      |> map (apply2 (Proof_Context.cterm_of ctxt o Term.map_types (Term_Subst.instantiateT instT)));
  151.38 +      |> map (apply2 (Thm.cterm_of ctxt o Term.map_types (Term_Subst.instantiateT instT)));
  151.39      val result' = Thm.instantiate (cinstT, cinst) result;
  151.40  
  151.41      (*import assumes/defines*)
   152.1 --- a/src/Pure/Isar/local_defs.ML	Fri Mar 06 14:01:08 2015 +0100
   152.2 +++ b/src/Pure/Isar/local_defs.ML	Fri Mar 06 15:58:56 2015 +0100
   152.3 @@ -214,7 +214,7 @@
   152.4  fun derived_def ctxt conditional prop =
   152.5    let
   152.6      val ((c, T), rhs) = prop
   152.7 -      |> Proof_Context.cterm_of ctxt
   152.8 +      |> Thm.cterm_of ctxt
   152.9        |> meta_rewrite_conv ctxt
  152.10        |> (snd o Logic.dest_equals o Thm.prop_of)
  152.11        |> conditional ? Logic.strip_imp_concl
   153.1 --- a/src/Pure/Isar/obtain.ML	Fri Mar 06 14:01:08 2015 +0100
   153.2 +++ b/src/Pure/Isar/obtain.ML	Fri Mar 06 15:58:56 2015 +0100
   153.3 @@ -129,7 +129,7 @@
   153.4      (*obtain parms*)
   153.5      val (Ts, parms_ctxt) = fold_map Proof_Context.inferred_param xs' asms_ctxt;
   153.6      val parms = map Free (xs' ~~ Ts);
   153.7 -    val cparms = map (Proof_Context.cterm_of ctxt) parms;
   153.8 +    val cparms = map (Thm.cterm_of ctxt) parms;
   153.9      val _ = Variable.warn_extra_tfrees fix_ctxt parms_ctxt;
  153.10  
  153.11      (*obtain statements*)
  153.12 @@ -187,17 +187,17 @@
  153.13  fun result tac facts ctxt =
  153.14    let
  153.15      val ((thesis_var, thesis), thesis_ctxt) = bind_judgment ctxt Auto_Bind.thesisN;
  153.16 -    val st = Goal.init (Proof_Context.cterm_of ctxt thesis);
  153.17 +    val st = Goal.init (Thm.cterm_of ctxt thesis);
  153.18      val rule =
  153.19        (case SINGLE (Method.insert_tac facts 1 THEN tac thesis_ctxt) st of
  153.20          NONE => raise THM ("Obtain.result: tactic failed", 0, facts)
  153.21        | SOME th =>
  153.22            check_result thesis_ctxt thesis (Raw_Simplifier.norm_hhf thesis_ctxt (Goal.conclude th)));
  153.23  
  153.24 -    val closed_rule = Thm.forall_intr (Proof_Context.cterm_of ctxt (Free thesis_var)) rule;
  153.25 +    val closed_rule = Thm.forall_intr (Thm.cterm_of ctxt (Free thesis_var)) rule;
  153.26      val ((_, [rule']), ctxt') = Variable.import false [closed_rule] ctxt;
  153.27      val obtain_rule =
  153.28 -      Thm.forall_elim (Proof_Context.cterm_of ctxt (Logic.varify_global (Free thesis_var))) rule';
  153.29 +      Thm.forall_elim (Thm.cterm_of ctxt (Logic.varify_global (Free thesis_var))) rule';
  153.30      val ((params, stmt), fix_ctxt) = Variable.focus_cterm (Thm.cprem_of obtain_rule 1) ctxt';
  153.31      val (prems, ctxt'') =
  153.32        Assumption.add_assms (obtain_export fix_ctxt obtain_rule (map #2 params))
  153.33 @@ -237,20 +237,20 @@
  153.34      val xs = map (apsnd norm_type o fst) vars;
  153.35      val ys = map (apsnd norm_type) (drop m params);
  153.36      val ys' = map Name.internal (Name.variant_list (map fst xs) (map fst ys)) ~~ map #2 ys;
  153.37 -    val terms = map (Drule.mk_term o Thm.cterm_of thy o Free) (xs @ ys');
  153.38 +    val terms = map (Drule.mk_term o Thm.global_cterm_of thy o Free) (xs @ ys');
  153.39  
  153.40      val instT =
  153.41        fold (Term.add_tvarsT o #2) params []
  153.42 -      |> map (TVar #> (fn T => (Thm.ctyp_of thy T, Thm.ctyp_of thy (norm_type T))));
  153.43 +      |> map (TVar #> (fn T => (Thm.global_ctyp_of thy T, Thm.global_ctyp_of thy (norm_type T))));
  153.44      val closed_rule = rule
  153.45 -      |> Thm.forall_intr (Thm.cterm_of thy (Free thesis_var))
  153.46 +      |> Thm.forall_intr (Thm.global_cterm_of thy (Free thesis_var))
  153.47        |> Thm.instantiate (instT, []);
  153.48  
  153.49      val ((_, rule' :: terms'), ctxt') = Variable.import false (closed_rule :: terms) ctxt;
  153.50      val vars' =
  153.51        map (dest_Free o Thm.term_of o Drule.dest_term) terms' ~~
  153.52        (map snd vars @ replicate (length ys) NoSyn);
  153.53 -    val rule'' = Thm.forall_elim (Thm.cterm_of thy (Logic.varify_global (Free thesis_var))) rule';
  153.54 +    val rule'' = Thm.forall_elim (Thm.global_cterm_of thy (Logic.varify_global (Free thesis_var))) rule';
  153.55    in ((vars', rule''), ctxt') end;
  153.56  
  153.57  fun inferred_type (binding, _, mx) ctxt =
  153.58 @@ -288,7 +288,7 @@
  153.59          |> Proof.map_context (K ctxt')
  153.60          |> Proof.fix (map (fn ((x, T), mx) => (Binding.name x, SOME T, mx)) parms)
  153.61          |> `Proof.context_of |-> (fn fix_ctxt => Proof.assm
  153.62 -          (obtain_export fix_ctxt rule (map (Proof_Context.cterm_of ctxt) ts))
  153.63 +          (obtain_export fix_ctxt rule (map (Thm.cterm_of ctxt) ts))
  153.64              [(Thm.empty_binding, asms)])
  153.65          |> Proof.bind_terms Auto_Bind.no_facts
  153.66        end;
  153.67 @@ -312,7 +312,7 @@
  153.68      |> Proof.local_goal print_result (K I) (pair o rpair I)
  153.69        "guess" (SOME before_qed) after_qed [(Thm.empty_binding, [Logic.mk_term goal, goal])]
  153.70      |> Proof.refine (Method.primitive_text (fn _ => fn _ =>
  153.71 -        Goal.init (Proof_Context.cterm_of ctxt thesis))) |> Seq.hd
  153.72 +        Goal.init (Thm.cterm_of ctxt thesis))) |> Seq.hd
  153.73    end;
  153.74  
  153.75  in
   154.1 --- a/src/Pure/Isar/proof.ML	Fri Mar 06 14:01:08 2015 +0100
   154.2 +++ b/src/Pure/Isar/proof.ML	Fri Mar 06 15:58:56 2015 +0100
   154.3 @@ -910,7 +910,7 @@
   154.4      val goal_propss = filter_out null propss';
   154.5      val goal =
   154.6        Logic.mk_conjunction_balanced (map Logic.mk_conjunction_balanced goal_propss)
   154.7 -      |> Proof_Context.cterm_of ctxt
   154.8 +      |> Thm.cterm_of ctxt
   154.9        |> Thm.weaken_sorts (Variable.sorts_of (context_of goal_state));
  154.10      val statement = ((kind, pos), propss', Thm.term_of goal);
  154.11      val after_qed' = after_qed |>> (fn after_local =>
   155.1 --- a/src/Pure/Isar/proof_context.ML	Fri Mar 06 14:01:08 2015 +0100
   155.2 +++ b/src/Pure/Isar/proof_context.ML	Fri Mar 06 15:58:56 2015 +0100
   155.3 @@ -11,8 +11,6 @@
   155.4    val theory_of: Proof.context -> theory
   155.5    val init_global: theory -> Proof.context
   155.6    val get_global: theory -> string -> Proof.context
   155.7 -  val cterm_of: Proof.context -> term -> cterm
   155.8 -  val ctyp_of: Proof.context -> typ -> ctyp
   155.9    type mode
  155.10    val mode_default: mode
  155.11    val mode_stmt: mode
  155.12 @@ -182,9 +180,6 @@
  155.13  val init_global = Proof_Context.init_global;
  155.14  val get_global = Proof_Context.get_global;
  155.15  
  155.16 -val cterm_of = Thm.cterm_of o theory_of;
  155.17 -val ctyp_of = Thm.ctyp_of o theory_of;
  155.18 -
  155.19  
  155.20  
  155.21  (** inner syntax mode **)
  155.22 @@ -1169,7 +1164,7 @@
  155.23      val ((propss, _), ctxt1) = prepp (map snd args) ctxt;
  155.24      val _ = Variable.warn_extra_tfrees ctxt ctxt1;
  155.25      val (premss, ctxt2) =
  155.26 -      fold_burrow (Assumption.add_assms exp o map (cterm_of ctxt)) propss ctxt1;
  155.27 +      fold_burrow (Assumption.add_assms exp o map (Thm.cterm_of ctxt)) propss ctxt1;
  155.28    in
  155.29      ctxt2
  155.30      |> auto_bind_facts (flat propss)
   156.1 --- a/src/Pure/Isar/spec_rules.ML	Fri Mar 06 14:01:08 2015 +0100
   156.2 +++ b/src/Pure/Isar/spec_rules.ML	Fri Mar 06 15:58:56 2015 +0100
   156.3 @@ -48,7 +48,7 @@
   156.4  
   156.5  fun add class (ts, ths) lthy =
   156.6    let
   156.7 -    val cts = map (Proof_Context.cterm_of lthy) ts;
   156.8 +    val cts = map (Thm.cterm_of lthy) ts;
   156.9    in
  156.10      lthy |> Local_Theory.declaration {syntax = false, pervasive = true}
  156.11        (fn phi =>
   157.1 --- a/src/Pure/ML/ml_antiquotations.ML	Fri Mar 06 14:01:08 2015 +0100
   157.2 +++ b/src/Pure/ML/ml_antiquotations.ML	Fri Mar 06 15:58:56 2015 +0100
   157.3 @@ -62,18 +62,18 @@
   157.4    ML_Antiquotation.inline @{binding prop} (Args.prop >> (ML_Syntax.atomic o ML_Syntax.print_term)) #>
   157.5  
   157.6    ML_Antiquotation.value @{binding ctyp} (Args.typ >> (fn T =>
   157.7 -    "Proof_Context.ctyp_of ML_context " ^ ML_Syntax.atomic (ML_Syntax.print_typ T))) #>
   157.8 +    "Thm.ctyp_of ML_context " ^ ML_Syntax.atomic (ML_Syntax.print_typ T))) #>
   157.9  
  157.10    ML_Antiquotation.value @{binding cterm} (Args.term >> (fn t =>
  157.11 -    "Proof_Context.cterm_of ML_context " ^ ML_Syntax.atomic (ML_Syntax.print_term t))) #>
  157.12 +    "Thm.cterm_of ML_context " ^ ML_Syntax.atomic (ML_Syntax.print_term t))) #>
  157.13  
  157.14    ML_Antiquotation.value @{binding cprop} (Args.prop >> (fn t =>
  157.15 -    "Proof_Context.cterm_of ML_context " ^ ML_Syntax.atomic (ML_Syntax.print_term t))) #>
  157.16 +    "Thm.cterm_of ML_context " ^ ML_Syntax.atomic (ML_Syntax.print_term t))) #>
  157.17  
  157.18    ML_Antiquotation.value @{binding cpat}
  157.19      (Args.context --
  157.20        Scan.lift Args.name_inner_syntax >> uncurry Proof_Context.read_term_pattern >> (fn t =>
  157.21 -        "Proof_Context.cterm_of ML_context " ^ ML_Syntax.atomic (ML_Syntax.print_term t))));
  157.22 +        "Thm.cterm_of ML_context " ^ ML_Syntax.atomic (ML_Syntax.print_term t))));
  157.23  
  157.24  
  157.25  (* type classes *)
   158.1 --- a/src/Pure/Proof/proof_checker.ML	Fri Mar 06 14:01:08 2015 +0100
   158.2 +++ b/src/Pure/Proof/proof_checker.ML	Fri Mar 06 15:58:56 2015 +0100
   158.3 @@ -78,7 +78,7 @@
   158.4            let
   158.5              val tvars = Term.add_tvars (Thm.full_prop_of thm) [] |> rev;
   158.6              val (fmap, thm') = Thm.varifyT_global' [] thm;
   158.7 -            val ctye = map (apply2 (Thm.ctyp_of thy))
   158.8 +            val ctye = map (apply2 (Thm.global_ctyp_of thy))
   158.9                (map TVar tvars @ map (fn ((_, S), ixn) => TVar (ixn, S)) fmap ~~ Ts)
  158.10            in
  158.11              Thm.instantiate (ctye, []) (forall_intr_vars (Thm.forall_intr_frees thm'))
  158.12 @@ -106,13 +106,13 @@
  158.13                  val (x, names') = Name.variant s names;
  158.14                  val thm = thm_of ((x, T) :: vs, names') Hs prf
  158.15                in
  158.16 -                Thm.forall_intr (Thm.cterm_of thy (Free (x, T))) thm
  158.17 +                Thm.forall_intr (Thm.global_cterm_of thy (Free (x, T))) thm
  158.18                end
  158.19  
  158.20            | thm_of (vs, names) Hs (prf % SOME t) =
  158.21                let
  158.22                  val thm = thm_of (vs, names) Hs prf;
  158.23 -                val ct = Thm.cterm_of thy (Term.subst_bounds (map Free vs, t));
  158.24 +                val ct = Thm.global_cterm_of thy (Term.subst_bounds (map Free vs, t));
  158.25                in
  158.26                  Thm.forall_elim ct thm
  158.27                  handle THM (s, _, _) => appl_error thy pretty_term vs Hs s prf t
  158.28 @@ -120,7 +120,7 @@
  158.29  
  158.30            | thm_of (vs, names) Hs (AbsP (s, SOME t, prf)) =
  158.31                let
  158.32 -                val ct = Thm.cterm_of thy (Term.subst_bounds (map Free vs, t));
  158.33 +                val ct = Thm.global_cterm_of thy (Term.subst_bounds (map Free vs, t));
  158.34                  val thm = thm_of (vs, names) (Thm.assume ct :: Hs) prf;
  158.35                in
  158.36                  Thm.implies_intr ct thm
  158.37 @@ -135,7 +135,7 @@
  158.38                  handle THM (s, _, _) => appl_error thy pretty_prf (fst vars) Hs s prf prf'
  158.39                end
  158.40  
  158.41 -          | thm_of _ _ (Hyp t) = Thm.assume (Thm.cterm_of thy t)
  158.42 +          | thm_of _ _ (Hyp t) = Thm.assume (Thm.global_cterm_of thy t)
  158.43  
  158.44            | thm_of _ _ _ = error "thm_of_proof: partial proof term";
  158.45  
   159.1 --- a/src/Pure/Proof/proof_syntax.ML	Fri Mar 06 14:01:08 2015 +0100
   159.2 +++ b/src/Pure/Proof/proof_syntax.ML	Fri Mar 06 15:58:56 2015 +0100
   159.3 @@ -197,7 +197,7 @@
   159.4        |> add_proof_atom_consts
   159.5          (map (Long_Name.append "axm") axm_names @ map (Long_Name.append "thm") thm_names);
   159.6    in
   159.7 -    (Thm.cterm_of thy' (term_of_proof prf), proof_of_term thy true o Thm.term_of)
   159.8 +    (Thm.global_cterm_of thy' (term_of_proof prf), proof_of_term thy true o Thm.term_of)
   159.9    end;
  159.10  
  159.11  fun read_term thy topsort =
   160.1 --- a/src/Pure/Tools/rule_insts.ML	Fri Mar 06 14:01:08 2015 +0100
   160.2 +++ b/src/Pure/Tools/rule_insts.ML	Fri Mar 06 15:58:56 2015 +0100
   160.3 @@ -116,8 +116,8 @@
   160.4      val inst_tvars = map_filter (make_instT (instT2 o instT1)) tvars;
   160.5      val inst_vars = map_filter (make_inst inst2) vars2;
   160.6    in
   160.7 -    (map (apply2 (Thm.ctyp_of thy)) inst_tvars,
   160.8 -     map (apply2 (Thm.cterm_of thy)) inst_vars)
   160.9 +    (map (apply2 (Thm.global_ctyp_of thy)) inst_tvars,
  160.10 +     map (apply2 (Thm.global_cterm_of thy)) inst_vars)
  160.11    end;
  160.12  
  160.13  fun where_rule ctxt mixed_insts fixes thm =
  160.14 @@ -250,7 +250,7 @@
  160.15          val cenv =
  160.16            map
  160.17              (fn (xi, t) =>
  160.18 -              apply2 (Thm.cterm_of thy) (Var (xi, fastype_of t), t))
  160.19 +              apply2 (Thm.global_cterm_of thy) (Var (xi, fastype_of t), t))
  160.20              (distinct
  160.21                (fn ((x1, t1), (x2, t2)) => x1 = x2 andalso t1 aconv t2)
  160.22                (xis ~~ ts));
  160.23 @@ -264,7 +264,7 @@
  160.24          fun liftterm t =
  160.25            fold_rev absfree (param_names ~~ paramTs) (Logic.incr_indexes (paramTs, inc) t);
  160.26          fun liftpair (cv, ct) = (cterm_fun liftvar cv, cterm_fun liftterm ct);
  160.27 -        val lifttvar = apply2 (Thm.ctyp_of thy o Logic.incr_tvar inc);
  160.28 +        val lifttvar = apply2 (Thm.global_ctyp_of thy o Logic.incr_tvar inc);
  160.29          val rule = Drule.instantiate_normalize
  160.30                (map lifttvar envT', map liftpair cenv)
  160.31                (Thm.lift_rule cgoal thm)
  160.32 @@ -283,7 +283,7 @@
  160.33    let
  160.34      val thy = Thm.theory_of_thm rl;
  160.35      val maxidx = Thm.maxidx_of rl;
  160.36 -    fun cvar xi = Thm.cterm_of thy (Var (xi, propT));
  160.37 +    fun cvar xi = Thm.global_cterm_of thy (Var (xi, propT));
  160.38      val revcut_rl' =
  160.39        Drule.instantiate_normalize ([], [(cvar ("V", 0), cvar ("V", maxidx + 1)),
  160.40          (cvar ("W", 0), cvar ("W", maxidx + 1))]) Drule.revcut_rl;
   161.1 --- a/src/Pure/axclass.ML	Fri Mar 06 14:01:08 2015 +0100
   161.2 +++ b/src/Pure/axclass.ML	Fri Mar 06 15:58:56 2015 +0100
   161.3 @@ -191,7 +191,7 @@
   161.4                thy2
   161.5                |> update_classrel ((c1, c2),
   161.6                  (the_classrel thy2 (c1, c) RS the_classrel thy2 (c, c2))
   161.7 -                |> Drule.instantiate' [SOME (Thm.ctyp_of thy2 (TVar ((Name.aT, 0), [])))] []
   161.8 +                |> Drule.instantiate' [SOME (Thm.global_ctyp_of thy2 (TVar ((Name.aT, 0), [])))] []
   161.9                  |> Thm.close_derivation));
  161.10  
  161.11          val proven = is_classrel thy1;
  161.12 @@ -228,7 +228,7 @@
  161.13              c1 = c2 andalso Sorts.sorts_le algebra (Ss2, Ss)) ars);
  161.14  
  161.15      val names = Name.invent Name.context Name.aT (length Ss);
  161.16 -    val std_vars = map (fn a => SOME (Thm.ctyp_of thy (TVar ((a, 0), [])))) names;
  161.17 +    val std_vars = map (fn a => SOME (Thm.global_ctyp_of thy (TVar ((a, 0), [])))) names;
  161.18  
  161.19      val completions = super_class_completions |> map (fn c1 =>
  161.20        let
  161.21 @@ -396,7 +396,7 @@
  161.22      val (th', thy') = Global_Theory.store_thm (binding, th) thy;
  161.23      val th'' = th'
  161.24        |> Thm.unconstrainT
  161.25 -      |> Drule.instantiate' [SOME (Thm.ctyp_of thy' (TVar ((Name.aT, 0), [])))] [];
  161.26 +      |> Drule.instantiate' [SOME (Thm.global_ctyp_of thy' (TVar ((Name.aT, 0), [])))] [];
  161.27    in
  161.28      thy'
  161.29      |> Sign.primitive_classrel (c1, c2)
  161.30 @@ -418,7 +418,7 @@
  161.31  
  161.32      val args = Name.invent_names Name.context Name.aT Ss;
  161.33      val T = Type (t, map TFree args);
  161.34 -    val std_vars = map (fn (a, S) => SOME (Thm.ctyp_of thy' (TVar ((a, 0), [])))) args;
  161.35 +    val std_vars = map (fn (a, S) => SOME (Thm.global_ctyp_of thy' (TVar ((a, 0), [])))) args;
  161.36  
  161.37      val missing_params = Sign.complete_sort thy' [c]
  161.38        |> maps (these o Option.map #params o try (get_info thy'))
   162.1 --- a/src/Pure/conjunction.ML	Fri Mar 06 14:01:08 2015 +0100
   162.2 +++ b/src/Pure/conjunction.ML	Fri Mar 06 15:58:56 2015 +0100
   162.3 @@ -29,7 +29,7 @@
   162.4  
   162.5  (** abstract syntax **)
   162.6  
   162.7 -fun certify t = Thm.cterm_of (Context.the_theory (Context.the_thread_data ())) t;
   162.8 +fun certify t = Thm.global_cterm_of (Context.the_theory (Context.the_thread_data ())) t;
   162.9  val read_prop = certify o Simple_Syntax.read_prop;
  162.10  
  162.11  val true_prop = certify Logic.true_prop;
  162.12 @@ -133,7 +133,7 @@
  162.13  local
  162.14  
  162.15  fun conjs thy n =
  162.16 -  let val As = map (fn A => Thm.cterm_of thy (Free (A, propT))) (Name.invent Name.context "A" n)
  162.17 +  let val As = map (fn A => Thm.global_cterm_of thy (Free (A, propT))) (Name.invent Name.context "A" n)
  162.18    in (As, mk_conjunction_balanced As) end;
  162.19  
  162.20  val B = read_prop "B";
   163.1 --- a/src/Pure/drule.ML	Fri Mar 06 14:01:08 2015 +0100
   163.2 +++ b/src/Pure/drule.ML	Fri Mar 06 15:58:56 2015 +0100
   163.3 @@ -132,10 +132,10 @@
   163.4  (*The premises of a theorem, as a cterm list*)
   163.5  val cprems_of = strip_imp_prems o Thm.cprop_of;
   163.6  
   163.7 -fun cterm_fun f ct = Thm.cterm_of (Thm.theory_of_cterm ct) (f (Thm.term_of ct));
   163.8 -fun ctyp_fun f cT = Thm.ctyp_of (Thm.theory_of_ctyp cT) (f (Thm.typ_of cT));
   163.9 +fun cterm_fun f ct = Thm.global_cterm_of (Thm.theory_of_cterm ct) (f (Thm.term_of ct));
  163.10 +fun ctyp_fun f cT = Thm.global_ctyp_of (Thm.theory_of_ctyp cT) (f (Thm.typ_of cT));
  163.11  
  163.12 -fun certify t = Thm.cterm_of (Context.the_theory (Context.the_thread_data ())) t;
  163.13 +fun certify t = Thm.global_cterm_of (Context.the_theory (Context.the_thread_data ())) t;
  163.14  
  163.15  val implies = certify Logic.implies;
  163.16  fun mk_implies (A, B) = Thm.apply (Thm.apply implies A) B;
  163.17 @@ -201,7 +201,7 @@
  163.18  (*Generalization over Vars -- canonical order*)
  163.19  fun forall_intr_vars th =
  163.20    fold Thm.forall_intr
  163.21 -    (map (Thm.cterm_of (Thm.theory_of_thm th) o Var) (Thm.fold_terms Term.add_vars th [])) th;
  163.22 +    (map (Thm.global_cterm_of (Thm.theory_of_thm th) o Var) (Thm.fold_terms Term.add_vars th [])) th;
  163.23  
  163.24  fun outer_params t =
  163.25    let val vs = Term.strip_all_vars t
  163.26 @@ -211,7 +211,7 @@
  163.27  fun gen_all th =
  163.28    let
  163.29      val {thy, prop, maxidx, ...} = Thm.rep_thm th;
  163.30 -    fun elim (x, T) = Thm.forall_elim (Thm.cterm_of thy (Var ((x, maxidx + 1), T)));
  163.31 +    fun elim (x, T) = Thm.forall_elim (Thm.global_cterm_of thy (Var ((x, maxidx + 1), T)));
  163.32    in fold elim (outer_params prop) th end;
  163.33  
  163.34  (*lift vars wrt. outermost goal parameters
  163.35 @@ -224,10 +224,10 @@
  163.36        |> map (fn (x, T) => Var ((x, maxidx + 1), Logic.incr_tvar (maxidx + 1) T));
  163.37      val Ts = map Term.fastype_of ps;
  163.38      val inst = Thm.fold_terms Term.add_vars th [] |> map (fn (xi, T) =>
  163.39 -      (Thm.cterm_of thy (Var (xi, T)), Thm.cterm_of thy (Term.list_comb (Var (xi, Ts ---> T), ps))));
  163.40 +      (Thm.global_cterm_of thy (Var (xi, T)), Thm.global_cterm_of thy (Term.list_comb (Var (xi, Ts ---> T), ps))));
  163.41    in
  163.42      th |> Thm.instantiate ([], inst)
  163.43 -    |> fold_rev (Thm.forall_intr o Thm.cterm_of thy) ps
  163.44 +    |> fold_rev (Thm.forall_intr o Thm.global_cterm_of thy) ps
  163.45    end;
  163.46  
  163.47  (*direct generalization*)
  163.48 @@ -248,8 +248,8 @@
  163.49        let
  163.50          val thy = Theory.merge_list (map Thm.theory_of_thm ths);
  163.51          val (instT, inst) = Term_Subst.zero_var_indexes_inst (map Thm.full_prop_of ths);
  163.52 -        val cinstT = map (fn (v, T) => (Thm.ctyp_of thy (TVar v), Thm.ctyp_of thy T)) instT;
  163.53 -        val cinst = map (fn (v, t) => (Thm.cterm_of thy (Var v), Thm.cterm_of thy t)) inst;
  163.54 +        val cinstT = map (fn (v, T) => (Thm.global_ctyp_of thy (TVar v), Thm.global_ctyp_of thy T)) instT;
  163.55 +        val cinst = map (fn (v, t) => (Thm.global_cterm_of thy (Var v), Thm.global_cterm_of thy t)) inst;
  163.56        in map (Thm.adjust_maxidx_thm ~1 o Thm.instantiate (cinstT, cinst)) ths end;
  163.57  
  163.58  val zero_var_indexes = singleton zero_var_indexes_list;
  163.59 @@ -644,9 +644,9 @@
  163.60    let
  163.61      val thy = Thm.theory_of_cterm ct;
  163.62      val T = Thm.typ_of_cterm ct;
  163.63 -    val a = Thm.ctyp_of thy (TVar (("'a", 0), []));
  163.64 -    val x = Thm.cterm_of thy (Var (("x", 0), T));
  163.65 -  in Thm.instantiate ([(a, Thm.ctyp_of thy T)], [(x, ct)]) termI end;
  163.66 +    val a = Thm.global_ctyp_of thy (TVar (("'a", 0), []));
  163.67 +    val x = Thm.global_cterm_of thy (Var (("x", 0), T));
  163.68 +  in Thm.instantiate ([(a, Thm.global_ctyp_of thy T)], [(x, ct)]) termI end;
  163.69  
  163.70  fun dest_term th =
  163.71    let val cprop = strip_imp_concl (Thm.cprop_of th) in
  163.72 @@ -789,7 +789,7 @@
  163.73          val (thy, tye, _) = fold_rev add_types ctpairs (Thm.theory_of_thm th, Vartab.empty, 0);
  163.74          val instT =
  163.75            Vartab.fold (fn (xi, (S, T)) =>
  163.76 -            cons (Thm.ctyp_of thy (TVar (xi, S)), Thm.ctyp_of thy (Envir.norm_type tye T))) tye [];
  163.77 +            cons (Thm.global_ctyp_of thy (TVar (xi, S)), Thm.global_ctyp_of thy (Envir.norm_type tye T))) tye [];
  163.78          val inst = map (apply2 (Thm.instantiate_cterm (instT, []))) ctpairs;
  163.79        in instantiate_normalize (instT, inst) th end
  163.80        handle TERM (msg, _) => raise THM (msg, 0, [th])
  163.81 @@ -807,11 +807,11 @@
  163.82          map_filter (Option.map Thm.term_of) cts);
  163.83  
  163.84      fun inst_of (v, ct) =
  163.85 -      (Thm.cterm_of (Thm.theory_of_cterm ct) (Var v), ct)
  163.86 +      (Thm.global_cterm_of (Thm.theory_of_cterm ct) (Var v), ct)
  163.87          handle TYPE (msg, _, _) => err msg;
  163.88  
  163.89      fun tyinst_of (v, cT) =
  163.90 -      (Thm.ctyp_of (Thm.theory_of_ctyp cT) (TVar v), cT)
  163.91 +      (Thm.global_ctyp_of (Thm.theory_of_ctyp cT) (TVar v), cT)
  163.92          handle TYPE (msg, _, _) => err msg;
  163.93  
  163.94      fun zip_vars xs ys =
  163.95 @@ -843,7 +843,7 @@
  163.96          fun ren (Abs (x, T, t)) = Abs (AList.lookup (op =) vs x |> the_default x, T, ren t)
  163.97            | ren (t $ u) = ren t $ ren u
  163.98            | ren t = t;
  163.99 -      in Thm.equal_elim (Thm.reflexive (Thm.cterm_of thy (ren (Thm.prop_of thm)))) thm end;
 163.100 +      in Thm.equal_elim (Thm.reflexive (Thm.global_cterm_of thy (ren (Thm.prop_of thm)))) thm end;
 163.101  
 163.102  
 163.103  (* renaming in left-to-right order *)
 163.104 @@ -864,7 +864,7 @@
 163.105        | rename xs t = (xs, t);
 163.106    in
 163.107      (case rename xs prop of
 163.108 -      ([], prop') => Thm.equal_elim (Thm.reflexive (Thm.cterm_of thy prop')) thm
 163.109 +      ([], prop') => Thm.equal_elim (Thm.reflexive (Thm.global_cterm_of thy prop')) thm
 163.110      | _ => error "More names than abstractions in theorem")
 163.111    end;
 163.112  
   164.1 --- a/src/Pure/goal.ML	Fri Mar 06 14:01:08 2015 +0100
   164.2 +++ b/src/Pure/goal.ML	Fri Mar 06 15:58:56 2015 +0100
   164.3 @@ -133,15 +133,15 @@
   164.4      val As = map Thm.term_of assms;
   164.5  
   164.6      val xs = map Free (fold Term.add_frees (prop :: As) []);
   164.7 -    val fixes = map (Thm.cterm_of thy) xs;
   164.8 +    val fixes = map (Thm.global_cterm_of thy) xs;
   164.9  
  164.10      val tfrees = fold Term.add_tfrees (prop :: As) [];
  164.11      val instT =
  164.12 -      map (fn (a, S) => (Thm.ctyp_of thy (TVar ((a, 0), S)), Thm.ctyp_of thy (TFree (a, S)))) tfrees;
  164.13 +      map (fn (a, S) => (Thm.global_ctyp_of thy (TVar ((a, 0), S)), Thm.global_ctyp_of thy (TFree (a, S)))) tfrees;
  164.14  
  164.15      val global_prop =
  164.16        Logic.varify_types_global (fold_rev Logic.all xs (Logic.list_implies (As, prop)))
  164.17 -      |> Thm.cterm_of thy
  164.18 +      |> Thm.global_cterm_of thy
  164.19        |> Thm.weaken_sorts (Variable.sorts_of ctxt);
  164.20      val global_result = result |> Future.map
  164.21        (Drule.flexflex_unique (SOME ctxt) #>
  164.22 @@ -191,7 +191,7 @@
  164.23          ("The error(s) above occurred for the goal statement" ^ Position.here pos ^ ":\n" ^
  164.24            Syntax.string_of_term ctxt (Logic.list_implies (asms, Logic.mk_conjunction_list props)));
  164.25  
  164.26 -    fun cert_safe t = Thm.cterm_of thy (Envir.beta_norm (Term.no_dummy_patterns t))
  164.27 +    fun cert_safe t = Thm.global_cterm_of thy (Envir.beta_norm (Term.no_dummy_patterns t))
  164.28        handle TERM (msg, _) => err msg | TYPE (msg, _, _) => err msg;
  164.29      val casms = map cert_safe asms;
  164.30      val cprops = map cert_safe props;
   165.1 --- a/src/Pure/more_thm.ML	Fri Mar 06 14:01:08 2015 +0100
   165.2 +++ b/src/Pure/more_thm.ML	Fri Mar 06 15:58:56 2015 +0100
   165.3 @@ -118,7 +118,7 @@
   165.4    let
   165.5      val thy = Thm.theory_of_cterm ct;
   165.6      val t = Thm.term_of ct;
   165.7 -  in Term.fold_aterms (fn v as Free _ => insert (op aconvc) (Thm.cterm_of thy v) | _ => I) t end;
   165.8 +  in Term.fold_aterms (fn v as Free _ => insert (op aconvc) (Thm.global_cterm_of thy v) | _ => I) t end;
   165.9  
  165.10  
  165.11  (* cterm constructors and destructors *)
  165.12 @@ -128,7 +128,7 @@
  165.13      val thy = Thm.theory_of_cterm t;
  165.14      val T = Thm.typ_of_cterm t;
  165.15    in
  165.16 -    Thm.apply (Thm.cterm_of thy (Const ("Pure.all", (T --> propT) --> propT)))
  165.17 +    Thm.apply (Thm.global_cterm_of thy (Const ("Pure.all", (T --> propT) --> propT)))
  165.18        (Thm.lambda_name (x, t) A)
  165.19    end;
  165.20  
  165.21 @@ -216,7 +216,7 @@
  165.22  (* type classes and sorts *)
  165.23  
  165.24  fun class_triv thy c =
  165.25 -  Thm.of_class (Thm.ctyp_of thy (TVar ((Name.aT, 0), [c])), c);
  165.26 +  Thm.of_class (Thm.global_ctyp_of thy (TVar ((Name.aT, 0), [c])), c);
  165.27  
  165.28  fun of_sort (T, S) = map (fn c => Thm.of_class (T, c)) S;
  165.29  
  165.30 @@ -331,7 +331,7 @@
  165.31      val used = fold (fn (t, u) => add_used t o add_used u) tpairs (add_used prop []);
  165.32      val vars = strip_vars prop;
  165.33      val cvars = (Name.variant_list used (map #1 vars), vars)
  165.34 -      |> ListPair.map (fn (x, (_, T)) => Thm.cterm_of thy (Var ((x, i), T)));
  165.35 +      |> ListPair.map (fn (x, (_, T)) => Thm.global_cterm_of thy (Var ((x, i), T)));
  165.36    in fold Thm.forall_elim cvars th end;
  165.37  
  165.38  in
  165.39 @@ -349,8 +349,8 @@
  165.40  (* certify_instantiate *)
  165.41  
  165.42  fun certify_inst thy (instT, inst) =
  165.43 -  (map (fn (v, T) => (Thm.ctyp_of thy (TVar v), Thm.ctyp_of thy T)) instT,
  165.44 -    map (fn (v, t) => (Thm.cterm_of thy (Var v), Thm.cterm_of thy t)) inst);
  165.45 +  (map (fn (v, T) => (Thm.global_ctyp_of thy (TVar v), Thm.global_ctyp_of thy T)) instT,
  165.46 +    map (fn (v, t) => (Thm.global_cterm_of thy (Var v), Thm.global_cterm_of thy t)) inst);
  165.47  
  165.48  fun certify_instantiate insts th =
  165.49    Thm.instantiate (certify_inst (Thm.theory_of_thm th) insts) th;
  165.50 @@ -365,7 +365,7 @@
  165.51      val fixed = fold Term.add_frees (Thm.terms_of_tpairs tpairs @ hyps) [];
  165.52      val frees = Term.fold_aterms (fn Free v =>
  165.53        if member (op =) fixed v then I else insert (op =) v | _ => I) prop [];
  165.54 -  in fold (Thm.forall_intr o Thm.cterm_of thy o Free) frees th end;
  165.55 +  in fold (Thm.forall_intr o Thm.global_cterm_of thy o Free) frees th end;
  165.56  
  165.57  
  165.58  (* unvarify_global: global schematic variables *)
  165.59 @@ -400,7 +400,7 @@
  165.60      val tfrees = rev (map TFree (Term.add_tfrees t []));
  165.61      val tfrees' = map (fn a => TFree (a, [])) (Name.invent Name.context Name.aT (length tfrees));
  165.62      val strip = tfrees ~~ tfrees';
  165.63 -    val recover = map (apply2 (Thm.ctyp_of thy o Logic.varifyT_global) o swap) strip;
  165.64 +    val recover = map (apply2 (Thm.global_ctyp_of thy o Logic.varifyT_global) o swap) strip;
  165.65      val t' = Term.map_types (Term.map_atyps (perhaps (AList.lookup (op =) strip))) t;
  165.66    in (strip, recover, t') end;
  165.67  
  165.68 @@ -409,7 +409,7 @@
  165.69      val _ = Sign.no_vars ctxt prop;
  165.70      val (strip, recover, prop') = stripped_sorts thy prop;
  165.71      val constraints = map (fn (TFree (_, S), T) => (T, S)) strip;
  165.72 -    val of_sorts = maps (fn (T as TFree (_, S), _) => of_sort (Thm.ctyp_of thy T, S)) strip;
  165.73 +    val of_sorts = maps (fn (T as TFree (_, S), _) => of_sort (Thm.global_ctyp_of thy T, S)) strip;
  165.74  
  165.75      val thy' = thy
  165.76        |> Theory.add_axiom ctxt (b, Logic.list_implies (maps Logic.mk_of_sort constraints, prop'));
  165.77 @@ -426,7 +426,7 @@
  165.78  fun add_def ctxt unchecked overloaded (b, prop) thy =
  165.79    let
  165.80      val _ = Sign.no_vars ctxt prop;
  165.81 -    val prems = map (Thm.cterm_of thy) (Logic.strip_imp_prems prop);
  165.82 +    val prems = map (Thm.global_cterm_of thy) (Logic.strip_imp_prems prop);
  165.83      val (_, recover, concl') = stripped_sorts thy (Logic.strip_imp_concl prop);
  165.84  
  165.85      val thy' = Theory.add_def ctxt unchecked overloaded (b, concl') thy;
   166.1 --- a/src/Pure/raw_simplifier.ML	Fri Mar 06 14:01:08 2015 +0100
   166.2 +++ b/src/Pure/raw_simplifier.ML	Fri Mar 06 15:58:56 2015 +0100
   166.3 @@ -684,7 +684,7 @@
   166.4      proc ctxt (Thm.term_of ct), identifier = []};
   166.5  
   166.6  (* FIXME avoid global thy and Logic.varify_global *)
   166.7 -fun simproc_global_i thy name = mk_simproc name o map (Thm.cterm_of thy o Logic.varify_global);
   166.8 +fun simproc_global_i thy name = mk_simproc name o map (Thm.global_cterm_of thy o Logic.varify_global);
   166.9  fun simproc_global thy name = simproc_global_i thy name o map (Syntax.read_term_global thy);
  166.10  
  166.11  
   167.1 --- a/src/Pure/simplifier.ML	Fri Mar 06 14:01:08 2015 +0100
   167.2 +++ b/src/Pure/simplifier.ML	Fri Mar 06 15:58:56 2015 +0100
   167.3 @@ -132,7 +132,7 @@
   167.4          let
   167.5            val lhss' = prep lthy lhss;
   167.6            val ctxt' = fold Variable.auto_fixes lhss' lthy;
   167.7 -        in Variable.export_terms ctxt' lthy lhss' end |> map (Proof_Context.cterm_of lthy),
   167.8 +        in Variable.export_terms ctxt' lthy lhss' end |> map (Thm.cterm_of lthy),
   167.9         proc = proc,
  167.10         identifier = identifier};
  167.11    in
   168.1 --- a/src/Pure/skip_proof.ML	Fri Mar 06 14:01:08 2015 +0100
   168.2 +++ b/src/Pure/skip_proof.ML	Fri Mar 06 15:58:56 2015 +0100
   168.3 @@ -32,7 +32,7 @@
   168.4    Context.>>>
   168.5      (Context.map_theory_result (Thm.add_oracle (Binding.make ("skip_proof", @{here}), I)));
   168.6  
   168.7 -fun make_thm thy prop = make_thm_cterm (Thm.cterm_of thy prop);
   168.8 +fun make_thm thy prop = make_thm_cterm (Thm.global_cterm_of thy prop);
   168.9  
  168.10  
  168.11  (* cheat_tac *)
   169.1 --- a/src/Pure/subgoal.ML	Fri Mar 06 14:01:08 2015 +0100
   169.2 +++ b/src/Pure/subgoal.ML	Fri Mar 06 15:58:56 2015 +0100
   169.3 @@ -86,7 +86,7 @@
   169.4          val u = Free (y, U);
   169.5          in ((Var v, list_comb (u, args)), (u, Var ((x, i + idx), U))) end;
   169.6      val (inst1, inst2) =
   169.7 -      split_list (map (apply2 (apply2 (Proof_Context.cterm_of ctxt))) (map2 var_inst vars ys));
   169.8 +      split_list (map (apply2 (apply2 (Thm.cterm_of ctxt))) (map2 var_inst vars ys));
   169.9  
  169.10      val th'' = Thm.instantiate ([], inst1) th';
  169.11    in ((inst2, th''), ctxt'') end;
   170.1 --- a/src/Pure/thm.ML	Fri Mar 06 14:01:08 2015 +0100
   170.2 +++ b/src/Pure/thm.ML	Fri Mar 06 15:58:56 2015 +0100
   170.3 @@ -23,7 +23,8 @@
   170.4    (*certified types*)
   170.5    val theory_of_ctyp: ctyp -> theory
   170.6    val typ_of: ctyp -> typ
   170.7 -  val ctyp_of: theory -> typ -> ctyp
   170.8 +  val global_ctyp_of: theory -> typ -> ctyp
   170.9 +  val ctyp_of: Proof.context -> typ -> ctyp
  170.10    val dest_ctyp: ctyp -> ctyp list
  170.11    (*certified terms*)
  170.12    val theory_of_cterm: cterm -> theory
  170.13 @@ -31,7 +32,8 @@
  170.14    val typ_of_cterm: cterm -> typ
  170.15    val ctyp_of_cterm: cterm -> ctyp
  170.16    val maxidx_of_cterm: cterm -> int
  170.17 -  val cterm_of: theory -> term -> cterm
  170.18 +  val global_cterm_of: theory -> term -> cterm
  170.19 +  val cterm_of: Proof.context -> term -> cterm
  170.20    val dest_comb: cterm -> cterm * cterm
  170.21    val dest_fun: cterm -> cterm
  170.22    val dest_arg: cterm -> cterm
  170.23 @@ -152,13 +154,15 @@
  170.24  fun theory_of_ctyp (Ctyp {thy, ...}) = thy;
  170.25  fun typ_of (Ctyp {T, ...}) = T;
  170.26  
  170.27 -fun ctyp_of thy raw_T =
  170.28 +fun global_ctyp_of thy raw_T =
  170.29    let
  170.30      val T = Sign.certify_typ thy raw_T;
  170.31      val maxidx = Term.maxidx_of_typ T;
  170.32      val sorts = Sorts.insert_typ T [];
  170.33    in Ctyp {thy = thy, T = T, maxidx = maxidx, sorts = sorts} end;
  170.34  
  170.35 +val ctyp_of = global_ctyp_of o Proof_Context.theory_of;
  170.36 +
  170.37  fun dest_ctyp (Ctyp {thy, T = Type (_, Ts), maxidx, sorts}) =
  170.38        map (fn T => Ctyp {thy = thy, T = T, maxidx = maxidx, sorts = sorts}) Ts
  170.39    | dest_ctyp cT = raise TYPE ("dest_ctyp", [typ_of cT], []);
  170.40 @@ -183,12 +187,14 @@
  170.41  
  170.42  fun maxidx_of_cterm (Cterm {maxidx, ...}) = maxidx;
  170.43  
  170.44 -fun cterm_of thy tm =
  170.45 +fun global_cterm_of thy tm =
  170.46    let
  170.47      val (t, T, maxidx) = Sign.certify_term thy tm;
  170.48      val sorts = Sorts.insert_term t [];
  170.49    in Cterm {thy = thy, t = t, T = T, maxidx = maxidx, sorts = sorts} end;
  170.50  
  170.51 +val cterm_of = global_cterm_of o Proof_Context.theory_of;
  170.52 +
  170.53  fun merge_thys0 (Cterm {thy = thy1, ...}) (Cterm {thy = thy2, ...}) =
  170.54    Theory.merge (thy1, thy2);
  170.55  
  170.56 @@ -1160,7 +1166,7 @@
  170.57    let
  170.58      val Ctyp {thy, T, ...} = cT;
  170.59      val c = Sign.certify_class thy raw_c;
  170.60 -    val Cterm {t = prop, maxidx, sorts, ...} = cterm_of thy (Logic.mk_of_class (T, c));
  170.61 +    val Cterm {t = prop, maxidx, sorts, ...} = global_cterm_of thy (Logic.mk_of_class (T, c));
  170.62    in
  170.63      if Sign.of_sort thy (T, [c]) then
  170.64        Thm (deriv_rule0 (Proofterm.OfClass (T, c)),
   171.1 --- a/src/Pure/variable.ML	Fri Mar 06 14:01:08 2015 +0100
   171.2 +++ b/src/Pure/variable.ML	Fri Mar 06 15:58:56 2015 +0100
   171.3 @@ -589,7 +589,7 @@
   171.4    let
   171.5      val thy = Thm.theory_of_cterm goal;
   171.6      val ((xs, ps), ctxt') = focus_params (Thm.term_of goal) ctxt;
   171.7 -    val ps' = map (Thm.cterm_of thy o Free) ps;
   171.8 +    val ps' = map (Thm.global_cterm_of thy o Free) ps;
   171.9      val goal' = fold forall_elim_prop ps' goal;
  171.10    in ((xs ~~ ps', goal'), ctxt') end;
  171.11  
   172.1 --- a/src/Tools/Code/code_preproc.ML	Fri Mar 06 14:01:08 2015 +0100
   172.2 +++ b/src/Tools/Code/code_preproc.ML	Fri Mar 06 15:58:56 2015 +0100
   172.3 @@ -153,7 +153,7 @@
   172.4  
   172.5  fun evaluation sandwich lift_postproc eval ctxt t =
   172.6    let
   172.7 -    val cert = Thm.cterm_of (Proof_Context.theory_of ctxt);
   172.8 +    val cert = Thm.global_cterm_of (Proof_Context.theory_of ctxt);
   172.9      val (postproc, ct') = sandwich ctxt (cert t);
  172.10    in
  172.11      Thm.term_of ct'
  172.12 @@ -168,7 +168,7 @@
  172.13  
  172.14  fun normalized_tfrees_sandwich ctxt ct =
  172.15    let
  172.16 -    val cert = Thm.cterm_of (Proof_Context.theory_of ctxt);
  172.17 +    val cert = Thm.global_cterm_of (Proof_Context.theory_of ctxt);
  172.18      val t = Thm.term_of ct;
  172.19      val vs_original = fold_term_types (K (fold_atyps (insert (eq_fst op =)
  172.20        o dest_TFree))) t [];
  172.21 @@ -185,7 +185,7 @@
  172.22  fun no_variables_sandwich ctxt ct =
  172.23    let
  172.24      val thy = Proof_Context.theory_of ctxt;
  172.25 -    val cert = Thm.cterm_of thy;
  172.26 +    val cert = Thm.global_cterm_of thy;
  172.27      val all_vars = fold_aterms (fn t as Free _ => insert (op aconvc) (cert t)
  172.28        | t as Var _ => insert (op aconvc) (cert t)
  172.29        | _ => I) (Thm.term_of ct) [];
   173.1 --- a/src/Tools/Code/code_runtime.ML	Fri Mar 06 14:01:08 2015 +0100
   173.2 +++ b/src/Tools/Code/code_runtime.ML	Fri Mar 06 15:58:56 2015 +0100
   173.3 @@ -177,7 +177,7 @@
   173.4      val _ = if fastype_of t <> propT
   173.5        then error ("Not a proposition: " ^ Syntax.string_of_term_global thy t)
   173.6        else ();
   173.7 -    val iff = Thm.cterm_of thy (Term.Const (@{const_name Pure.eq}, propT --> propT --> propT));
   173.8 +    val iff = Thm.global_cterm_of thy (Term.Const (@{const_name Pure.eq}, propT --> propT --> propT));
   173.9      val result = case partiality_as_none (evaluation truth_cookie ctxt evaluator vs_t [])
  173.10       of SOME Holds => true
  173.11        | _ => false;
   174.1 --- a/src/Tools/Code/code_simp.ML	Fri Mar 06 14:01:08 2015 +0100
   174.2 +++ b/src/Tools/Code/code_simp.ML	Fri Mar 06 15:58:56 2015 +0100
   174.3 @@ -83,7 +83,7 @@
   174.4    THEN' conclude_tac ctxt NONE ctxt;
   174.5  
   174.6  fun dynamic_value ctxt =
   174.7 -  snd o Logic.dest_equals o Thm.prop_of o dynamic_conv ctxt o Thm.cterm_of (Proof_Context.theory_of ctxt);
   174.8 +  snd o Logic.dest_equals o Thm.prop_of o dynamic_conv ctxt o Thm.global_cterm_of (Proof_Context.theory_of ctxt);
   174.9  
  174.10  val _ = Theory.setup 
  174.11    (Method.setup @{binding code_simp}
   175.1 --- a/src/Tools/Code/code_thingol.ML	Fri Mar 06 14:01:08 2015 +0100
   175.2 +++ b/src/Tools/Code/code_thingol.ML	Fri Mar 06 15:58:56 2015 +0100
   175.3 @@ -574,7 +574,7 @@
   175.4        let
   175.5          val raw_const = Const (c, map_type_tfree (K arity_typ') ty);
   175.6          val dom_length = length (fst (strip_type ty))
   175.7 -        val thm = Axclass.unoverload_conv thy (Thm.cterm_of thy raw_const);
   175.8 +        val thm = Axclass.unoverload_conv thy (Thm.global_cterm_of thy raw_const);
   175.9          val const = (apsnd Logic.unvarifyT_global o dest_Const o snd
  175.10            o Logic.dest_equals o Thm.prop_of) thm;
  175.11        in
   176.1 --- a/src/Tools/IsaPlanner/isand.ML	Fri Mar 06 14:01:08 2015 +0100
   176.2 +++ b/src/Tools/IsaPlanner/isand.ML	Fri Mar 06 15:58:56 2015 +0100
   176.3 @@ -91,7 +91,7 @@
   176.4  
   176.5  fun fix_alls_cterm ctxt i th =
   176.6    let
   176.7 -    val cert = Thm.cterm_of (Thm.theory_of_thm th);
   176.8 +    val cert = Thm.global_cterm_of (Thm.theory_of_thm th);
   176.9      val (fixedbody, fvs) = fix_alls_term ctxt i (Thm.prop_of th);
  176.10      val cfvs = rev (map cert fvs);
  176.11      val ct_body = cert fixedbody;
  176.12 @@ -140,7 +140,7 @@
  176.13  *)
  176.14  fun subgoal_thms th =
  176.15    let
  176.16 -    val cert = Thm.cterm_of (Thm.theory_of_thm th);
  176.17 +    val cert = Thm.global_cterm_of (Thm.theory_of_thm th);
  176.18  
  176.19      val t = Thm.prop_of th;
  176.20  
   177.1 --- a/src/Tools/IsaPlanner/rw_inst.ML	Fri Mar 06 14:01:08 2015 +0100
   177.2 +++ b/src/Tools/IsaPlanner/rw_inst.ML	Fri Mar 06 15:58:56 2015 +0100
   177.3 @@ -32,7 +32,7 @@
   177.4  *)
   177.5  fun allify_conditions Ts th =
   177.6    let
   177.7 -    val cert = Thm.cterm_of (Thm.theory_of_thm th);
   177.8 +    val cert = Thm.global_cterm_of (Thm.theory_of_thm th);
   177.9  
  177.10      fun allify (x, T) t =
  177.11        Logic.all_const T $ Abs (x, T, Term.abstract_over (Free (x, T), t));
  177.12 @@ -62,7 +62,7 @@
  177.13  (* Note, we take abstraction in the order of last abstraction first *)
  177.14  fun mk_abstractedrule ctxt TsFake Ts rule =
  177.15    let
  177.16 -    val cert = Thm.cterm_of (Thm.theory_of_thm rule);
  177.17 +    val cert = Thm.global_cterm_of (Thm.theory_of_thm rule);
  177.18  
  177.19      (* now we change the names of temporary free vars that represent
  177.20         bound vars with binders outside the redex *)
  177.21 @@ -172,8 +172,8 @@
  177.22  fun rw ctxt ((nonfixed_typinsts, unprepinsts), FakeTs, Ts, outerterm) rule target_thm =
  177.23    let
  177.24      val thy = Thm.theory_of_thm target_thm;
  177.25 -    val cert = Thm.cterm_of thy;
  177.26 -    val certT = Thm.ctyp_of thy;
  177.27 +    val cert = Thm.global_cterm_of thy;
  177.28 +    val certT = Thm.global_ctyp_of thy;
  177.29  
  177.30      (* fix all non-instantiated tvars *)
  177.31      val (fixtyinsts, othertfrees) = (* FIXME proper context!? *)
   178.1 --- a/src/Tools/atomize_elim.ML	Fri Mar 06 14:01:08 2015 +0100
   178.2 +++ b/src/Tools/atomize_elim.ML	Fri Mar 06 15:58:56 2015 +0100
   178.3 @@ -116,7 +116,7 @@
   178.4        val quantify_thesis =
   178.5            if is_Bound thesis then all_tac
   178.6            else let
   178.7 -              val cthesis = Thm.cterm_of thy thesis
   178.8 +              val cthesis = Thm.global_cterm_of thy thesis
   178.9                val rule = instantiate' [SOME (Thm.ctyp_of_cterm cthesis)] [NONE, SOME cthesis]
  178.10                           @{thm meta_spec}
  178.11              in
   179.1 --- a/src/Tools/coherent.ML	Fri Mar 06 14:01:08 2015 +0100
   179.2 +++ b/src/Tools/coherent.ML	Fri Mar 06 15:58:56 2015 +0100
   179.3 @@ -174,8 +174,8 @@
   179.4  fun thm_of_cl_prf ctxt goal asms (ClPrf (th, (tye, env), insts, is, prfs)) =
   179.5    let
   179.6      val thy = Proof_Context.theory_of ctxt;
   179.7 -    val cert = Thm.cterm_of thy;
   179.8 -    val certT = Thm.ctyp_of thy;
   179.9 +    val cert = Thm.global_cterm_of thy;
  179.10 +    val certT = Thm.global_ctyp_of thy;
  179.11      val _ =
  179.12        cond_trace ctxt (fn () =>
  179.13          Pretty.string_of (Pretty.big_list "asms:" (map (Display.pretty_thm ctxt) asms)));
  179.14 @@ -202,7 +202,7 @@
  179.15  and thm_of_case_prf ctxt goal asms ((params, prf), (_, asms')) =
  179.16    let
  179.17      val thy = Proof_Context.theory_of ctxt;
  179.18 -    val cert = Thm.cterm_of thy;
  179.19 +    val cert = Thm.global_cterm_of thy;
  179.20      val cparams = map cert params;
  179.21      val asms'' = map (cert o curry subst_bounds (rev params)) asms';
  179.22      val (prems'', ctxt') = fold_map Thm.assume_hyps asms'' ctxt;
   180.1 --- a/src/Tools/cong_tac.ML	Fri Mar 06 14:01:08 2015 +0100
   180.2 +++ b/src/Tools/cong_tac.ML	Fri Mar 06 15:58:56 2015 +0100
   180.3 @@ -14,7 +14,7 @@
   180.4  
   180.5  fun cong_tac ctxt cong = CSUBGOAL (fn (cgoal, i) =>
   180.6    let
   180.7 -    val cert = Thm.cterm_of (Thm.theory_of_cterm cgoal);
   180.8 +    val cert = Thm.global_cterm_of (Thm.theory_of_cterm cgoal);
   180.9      val goal = Thm.term_of cgoal;
  180.10    in
  180.11      (case Logic.strip_assums_concl goal of
   181.1 --- a/src/Tools/eqsubst.ML	Fri Mar 06 14:01:08 2015 +0100
   181.2 +++ b/src/Tools/eqsubst.ML	Fri Mar 06 15:58:56 2015 +0100
   181.3 @@ -260,7 +260,7 @@
   181.4      val tgt_term = Thm.prop_of th;
   181.5  
   181.6      val thy = Thm.theory_of_thm th;
   181.7 -    val cert = Thm.cterm_of thy;
   181.8 +    val cert = Thm.global_cterm_of thy;
   181.9  
  181.10      val (fixedbody, fvs) = IsaND.fix_alls_term ctxt i tgt_term;
  181.11      val cfvs = rev (map cert fvs);
  181.12 @@ -349,7 +349,7 @@
  181.13      val tgt_term = Thm.prop_of th;
  181.14  
  181.15      val thy = Thm.theory_of_thm th;
  181.16 -    val cert = Thm.cterm_of thy;
  181.17 +    val cert = Thm.global_cterm_of thy;
  181.18  
  181.19      val (fixedbody, fvs) = IsaND.fix_alls_term ctxt i tgt_term;
  181.20      val cfvs = rev (map cert fvs);
   182.1 --- a/src/Tools/induct.ML	Fri Mar 06 14:01:08 2015 +0100
   182.2 +++ b/src/Tools/induct.ML	Fri Mar 06 15:58:56 2015 +0100
   182.3 @@ -162,7 +162,7 @@
   182.4  
   182.5  val rearrange_eqs_simproc =
   182.6    Simplifier.simproc_global Pure.thy "rearrange_eqs" ["Pure.all t"]
   182.7 -    (fn ctxt => fn t => mk_swap_rrule ctxt (Thm.cterm_of (Proof_Context.theory_of ctxt) t));
   182.8 +    (fn ctxt => fn t => mk_swap_rrule ctxt (Thm.global_cterm_of (Proof_Context.theory_of ctxt) t));
   182.9  
  182.10  
  182.11  (* rotate k premises to the left by j, skipping over first j premises *)
  182.12 @@ -394,7 +394,7 @@
  182.13  
  182.14  fun prep_inst ctxt align tune (tm, ts) =
  182.15    let
  182.16 -    val cert = Thm.cterm_of (Proof_Context.theory_of ctxt);
  182.17 +    val cert = Thm.global_cterm_of (Proof_Context.theory_of ctxt);
  182.18      fun prep_var (x, SOME t) =
  182.19            let
  182.20              val cx = cert x;
  182.21 @@ -571,8 +571,8 @@
  182.22  
  182.23  fun dest_env thy env =
  182.24    let
  182.25 -    val cert = Thm.cterm_of thy;
  182.26 -    val certT = Thm.ctyp_of thy;
  182.27 +    val cert = Thm.global_cterm_of thy;
  182.28 +    val certT = Thm.global_ctyp_of thy;
  182.29      val pairs = Vartab.dest (Envir.term_env env);
  182.30      val types = Vartab.dest (Envir.type_env env);
  182.31      val ts = map (cert o Envir.norm_term env o #2 o #2) pairs;
  182.32 @@ -655,7 +655,7 @@
  182.33  fun meta_spec_tac ctxt n (x, T) = SUBGOAL (fn (goal, i) =>
  182.34    let
  182.35      val thy = Proof_Context.theory_of ctxt;
  182.36 -    val cert = Thm.cterm_of thy;
  182.37 +    val cert = Thm.global_cterm_of thy;
  182.38  
  182.39      val v = Free (x, T);
  182.40      fun spec_rule prfx (xs, body) =
   183.1 --- a/src/Tools/misc_legacy.ML	Fri Mar 06 14:01:08 2015 +0100
   183.2 +++ b/src/Tools/misc_legacy.ML	Fri Mar 06 15:58:56 2015 +0100
   183.3 @@ -161,7 +161,7 @@
   183.4  fun metahyps_aux_tac ctxt tacf (prem,gno) state =
   183.5    let val (insts,params,hyps,concl) = metahyps_split_prem prem
   183.6        val maxidx = Thm.maxidx_of state
   183.7 -      val cterm = Thm.cterm_of (Thm.theory_of_thm state)
   183.8 +      val cterm = Thm.global_cterm_of (Thm.theory_of_thm state)
   183.9        val chyps = map cterm hyps
  183.10        val hypths = map Thm.assume chyps
  183.11        val subprems = map (Thm.forall_elim_vars 0) hypths
  183.12 @@ -265,8 +265,8 @@
  183.13           let fun newName (ix,_) = (ix, gensym (string_of_indexname ix))
  183.14               val alist = map newName vars
  183.15               fun mk_inst (v,T) =
  183.16 -                 (Thm.cterm_of thy (Var(v,T)),
  183.17 -                  Thm.cterm_of thy (Free(((the o AList.lookup (op =) alist) v), T)))
  183.18 +                 (Thm.global_cterm_of thy (Var(v,T)),
  183.19 +                  Thm.global_cterm_of thy (Free(((the o AList.lookup (op =) alist) v), T)))
  183.20               val insts = map mk_inst vars
  183.21               fun thaw i th' = (*i is non-negative increment for Var indexes*)
  183.22                   th' |> forall_intr_list (map #2 insts)
  183.23 @@ -289,8 +289,8 @@
  183.24               val (alist, _) =
  183.25                   fold_rev newName vars ([], Thm.fold_terms Term.add_free_names fth [])
  183.26               fun mk_inst (v, T) =
  183.27 -                 (Thm.cterm_of thy (Var(v,T)),
  183.28 -                  Thm.cterm_of thy (Free(((the o AList.lookup (op =) alist) v), T)))
  183.29 +                 (Thm.global_cterm_of thy (Var(v,T)),
  183.30 +                  Thm.global_cterm_of thy (Free(((the o AList.lookup (op =) alist) v), T)))
  183.31               val insts = map mk_inst vars
  183.32               fun thaw th' =
  183.33                   th' |> forall_intr_list (map #2 insts)
   184.1 --- a/src/Tools/nbe.ML	Fri Mar 06 14:01:08 2015 +0100
   184.2 +++ b/src/Tools/nbe.ML	Fri Mar 06 15:58:56 2015 +0100
   184.3 @@ -78,7 +78,7 @@
   184.4  
   184.5  val (_, triv_of_class) = Context.>>> (Context.map_theory_result
   184.6    (Thm.add_oracle (@{binding triv_of_class}, fn (thy, T, class) =>
   184.7 -    Thm.cterm_of thy (Logic.mk_of_class (T, class)))));
   184.8 +    Thm.global_cterm_of thy (Logic.mk_of_class (T, class)))));
   184.9  
  184.10  in
  184.11  
  184.12 @@ -86,7 +86,7 @@
  184.13    let
  184.14      val thy = Proof_Context.theory_of ctxt;
  184.15      val algebra = Sign.classes_of thy;
  184.16 -    val certT = Thm.ctyp_of thy;
  184.17 +    val certT = Thm.global_ctyp_of thy;
  184.18      val triv_classes = get_triv_classes thy;
  184.19      fun additional_classes sort = filter_out (fn class => Sorts.sort_le algebra (sort, [class])) triv_classes;
  184.20      fun mk_entry (v, sort) =
  184.21 @@ -582,8 +582,8 @@
  184.22    let
  184.23      val thy = Proof_Context.theory_of ctxt;
  184.24      val ty = Thm.typ_of_cterm lhs;
  184.25 -    val eq = Thm.cterm_of thy (Term.Const (@{const_name Pure.eq}, ty --> ty --> propT));
  184.26 -    val rhs = Thm.cterm_of thy raw_rhs;
  184.27 +    val eq = Thm.global_cterm_of thy (Term.Const (@{const_name Pure.eq}, ty --> ty --> propT));
  184.28 +    val rhs = Thm.global_cterm_of thy raw_rhs;
  184.29    in Thm.mk_binop eq lhs rhs end;
  184.30  
  184.31  val (_, raw_oracle) = Context.>>> (Context.map_theory_result
   185.1 --- a/src/ZF/Tools/cartprod.ML	Fri Mar 06 14:01:08 2015 +0100
   185.2 +++ b/src/ZF/Tools/cartprod.ML	Fri Mar 06 15:58:56 2015 +0100
   185.3 @@ -106,7 +106,7 @@
   185.4  fun split_rule_var ctxt (Var(v,_), Type("fun",[T1,T2]), rl) =
   185.5        let val T' = factors T1 ---> T2
   185.6            val newt = ap_split T1 T2 (Var(v,T'))
   185.7 -          val cterm = Thm.cterm_of (Thm.theory_of_thm rl)
   185.8 +          val cterm = Thm.global_cterm_of (Thm.theory_of_thm rl)
   185.9        in
  185.10            remove_split ctxt (Drule.instantiate_normalize ([], [(cterm (Var(v, Ind_Syntax.iT-->T2)), 
  185.11                                             cterm newt)]) rl)
   186.1 --- a/src/ZF/Tools/ind_cases.ML	Fri Mar 06 14:01:08 2015 +0100
   186.2 +++ b/src/ZF/Tools/ind_cases.ML	Fri Mar 06 15:58:56 2015 +0100
   186.3 @@ -37,7 +37,7 @@
   186.4    in
   186.5      (case Symtab.lookup (IndCasesData.get thy) c of
   186.6        NONE => error ("Unknown inductive cases rule for set " ^ quote c)
   186.7 -    | SOME f => f ctxt (Thm.cterm_of thy A))
   186.8 +    | SOME f => f ctxt (Thm.global_cterm_of thy A))
   186.9    end;
  186.10  
  186.11  
   187.1 --- a/src/ZF/Tools/inductive_package.ML	Fri Mar 06 14:01:08 2015 +0100
   187.2 +++ b/src/ZF/Tools/inductive_package.ML	Fri Mar 06 15:58:56 2015 +0100
   187.3 @@ -494,8 +494,8 @@
   187.4         The name "x.1" comes from the "RS spec" !*)
   187.5       val inst =
   187.6           case elem_frees of [_] => I
   187.7 -            | _ => Drule.instantiate_normalize ([], [(Thm.cterm_of thy (Var(("x",1), Ind_Syntax.iT)),
   187.8 -                                      Thm.cterm_of thy elem_tuple)]);
   187.9 +            | _ => Drule.instantiate_normalize ([], [(Thm.global_cterm_of thy (Var(("x",1), Ind_Syntax.iT)),
  187.10 +                                      Thm.global_cterm_of thy elem_tuple)]);
  187.11  
  187.12       (*strip quantifier and the implication*)
  187.13       val induct0 = inst (quant_induct RS @{thm spec} RSN (2, @{thm rev_mp}));