{r,e,d,f}tac with proper context in BNF
authortraytel
Thu Jul 16 12:23:22 2015 +0200 (2015-07-16)
changeset 6072826ffdb966759
parent 60727 53697011b03a
child 60734 6aaa9b95cf47
child 60735 cf291b55f3d1
{r,e,d,f}tac with proper context in BNF
src/HOL/Library/bnf_lfp_countable.ML
src/HOL/Tools/BNF/bnf_comp.ML
src/HOL/Tools/BNF/bnf_comp_tactics.ML
src/HOL/Tools/BNF/bnf_def.ML
src/HOL/Tools/BNF/bnf_def_tactics.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_n2m_tactics.ML
src/HOL/Tools/BNF/bnf_gfp.ML
src/HOL/Tools/BNF/bnf_gfp_rec_sugar_tactics.ML
src/HOL/Tools/BNF/bnf_gfp_tactics.ML
src/HOL/Tools/BNF/bnf_lfp.ML
src/HOL/Tools/BNF/bnf_lfp_compat.ML
src/HOL/Tools/BNF/bnf_lfp_rec_sugar.ML
src/HOL/Tools/BNF/bnf_lfp_size.ML
src/HOL/Tools/BNF/bnf_lfp_tactics.ML
src/HOL/Tools/BNF/bnf_tactics.ML
src/HOL/Tools/Ctr_Sugar/ctr_sugar.ML
src/HOL/Tools/Ctr_Sugar/ctr_sugar_tactics.ML
src/HOL/Tools/Ctr_Sugar/ctr_sugar_util.ML
src/HOL/Tools/Lifting/lifting_bnf.ML
src/HOL/Tools/Lifting/lifting_def_code_dt.ML
src/HOL/Tools/Transfer/transfer_bnf.ML
     1.1 --- a/src/HOL/Library/bnf_lfp_countable.ML	Thu Jul 16 10:48:20 2015 +0200
     1.2 +++ b/src/HOL/Library/bnf_lfp_countable.ML	Thu Jul 16 12:23:22 2015 +0200
     1.3 @@ -23,17 +23,17 @@
     1.4  
     1.5  val countableS = @{sort countable};
     1.6  
     1.7 -fun nchotomy_tac nchotomy =
     1.8 -  HEADGOAL (rtac (nchotomy RS @{thm all_reg[rotated]}) THEN'
     1.9 +fun nchotomy_tac ctxt nchotomy =
    1.10 +  HEADGOAL (rtac ctxt (nchotomy RS @{thm all_reg[rotated]}) THEN'
    1.11      REPEAT_ALL_NEW (resolve0_tac [allI, impI] ORELSE' eresolve0_tac [exE, disjE]));
    1.12  
    1.13 -fun meta_spec_mp_tac 0 = K all_tac
    1.14 -  | meta_spec_mp_tac depth =
    1.15 -    dtac meta_spec THEN' meta_spec_mp_tac (depth - 1) THEN' dtac meta_mp THEN' atac;
    1.16 +fun meta_spec_mp_tac ctxt 0 = K all_tac
    1.17 +  | meta_spec_mp_tac ctxt depth =
    1.18 +    dtac ctxt meta_spec THEN' meta_spec_mp_tac ctxt (depth - 1) THEN' dtac ctxt meta_mp THEN' atac;
    1.19  
    1.20 -val use_induction_hypothesis_tac =
    1.21 +fun use_induction_hypothesis_tac ctxt =
    1.22    DEEPEN (1, 64 (* large number *))
    1.23 -    (fn depth => meta_spec_mp_tac depth THEN' etac allE THEN' etac impE THEN' atac THEN' atac) 0;
    1.24 +    (fn depth => meta_spec_mp_tac ctxt depth THEN' etac ctxt allE THEN' etac ctxt impE THEN' atac THEN' atac) 0;
    1.25  
    1.26  val same_ctr_simps = @{thms sum_encode_eq prod_encode_eq sum.inject prod.inject to_nat_split
    1.27    id_apply snd_conv simp_thms};
    1.28 @@ -42,29 +42,29 @@
    1.29  fun same_ctr_tac ctxt injects recs map_congs' inj_map_strongs' =
    1.30    HEADGOAL (asm_full_simp_tac
    1.31        (ss_only (injects @ recs @ map_congs' @ same_ctr_simps) ctxt) THEN_MAYBE'
    1.32 -    TRY o REPEAT_ALL_NEW (rtac conjI) THEN_ALL_NEW
    1.33 +    TRY o REPEAT_ALL_NEW (rtac ctxt conjI) THEN_ALL_NEW
    1.34      REPEAT_ALL_NEW (eresolve_tac ctxt (conjE :: inj_map_strongs')) THEN_ALL_NEW
    1.35 -    (atac ORELSE' use_induction_hypothesis_tac));
    1.36 +    (atac ORELSE' use_induction_hypothesis_tac ctxt));
    1.37  
    1.38  fun distinct_ctrs_tac ctxt recs =
    1.39    HEADGOAL (asm_full_simp_tac (ss_only (recs @ distinct_ctrs_simps) ctxt));
    1.40  
    1.41  fun mk_encode_injective_tac ctxt n nchotomy injects recs map_comps' inj_map_strongs' =
    1.42    let val ks = 1 upto n in
    1.43 -    EVERY (maps (fn k => nchotomy_tac nchotomy :: map (fn k' =>
    1.44 +    EVERY (maps (fn k => nchotomy_tac ctxt nchotomy :: map (fn k' =>
    1.45        if k = k' then same_ctr_tac ctxt injects recs map_comps' inj_map_strongs'
    1.46        else distinct_ctrs_tac ctxt recs) ks) ks)
    1.47    end;
    1.48  
    1.49  fun mk_encode_injectives_tac ctxt ns induct nchotomys injectss recss map_comps' inj_map_strongs' =
    1.50 -  HEADGOAL (rtac induct) THEN
    1.51 +  HEADGOAL (rtac ctxt induct) THEN
    1.52    EVERY (@{map 4} (fn n => fn nchotomy => fn injects => fn recs =>
    1.53        mk_encode_injective_tac ctxt n nchotomy injects recs map_comps' inj_map_strongs')
    1.54      ns nchotomys injectss recss);
    1.55  
    1.56  fun endgame_tac ctxt encode_injectives =
    1.57    unfold_thms_tac ctxt @{thms inj_on_def ball_UNIV} THEN
    1.58 -  ALLGOALS (rtac exI THEN' rtac allI THEN' resolve_tac ctxt encode_injectives);
    1.59 +  ALLGOALS (rtac ctxt exI THEN' rtac ctxt allI THEN' resolve_tac ctxt encode_injectives);
    1.60  
    1.61  fun encode_sumN n k t =
    1.62    Balanced_Tree.access {init = t,
     2.1 --- a/src/HOL/Tools/BNF/bnf_comp.ML	Thu Jul 16 10:48:20 2015 +0200
     2.2 +++ b/src/HOL/Tools/BNF/bnf_comp.ML	Thu Jul 16 12:23:22 2015 +0200
     2.3 @@ -253,12 +253,12 @@
     2.4        else
     2.5          (bd, NONE);
     2.6  
     2.7 -    fun map_id0_tac _ =
     2.8 -      mk_comp_map_id0_tac (map_id0_of_bnf outer) (map_cong0_of_bnf outer)
     2.9 +    fun map_id0_tac ctxt =
    2.10 +      mk_comp_map_id0_tac ctxt (map_id0_of_bnf outer) (map_cong0_of_bnf outer)
    2.11          (map map_id0_of_bnf inners);
    2.12  
    2.13 -    fun map_comp0_tac _ =
    2.14 -      mk_comp_map_comp0_tac (map_comp0_of_bnf outer) (map_cong0_of_bnf outer)
    2.15 +    fun map_comp0_tac ctxt =
    2.16 +      mk_comp_map_comp0_tac ctxt (map_comp0_of_bnf outer) (map_cong0_of_bnf outer)
    2.17          (map map_comp0_of_bnf inners);
    2.18  
    2.19      fun mk_single_set_map0_tac i ctxt =
    2.20 @@ -268,11 +268,11 @@
    2.21  
    2.22      val set_map0_tacs = map mk_single_set_map0_tac (0 upto ilive - 1);
    2.23  
    2.24 -    fun bd_card_order_tac _ =
    2.25 -      mk_comp_bd_card_order_tac (map bd_card_order_of_bnf inners) (bd_card_order_of_bnf outer);
    2.26 +    fun bd_card_order_tac ctxt =
    2.27 +      mk_comp_bd_card_order_tac ctxt (map bd_card_order_of_bnf inners) (bd_card_order_of_bnf outer);
    2.28  
    2.29 -    fun bd_cinfinite_tac _ =
    2.30 -      mk_comp_bd_cinfinite_tac (bd_cinfinite_of_bnf inner) (bd_cinfinite_of_bnf outer);
    2.31 +    fun bd_cinfinite_tac ctxt =
    2.32 +      mk_comp_bd_cinfinite_tac ctxt (bd_cinfinite_of_bnf inner) (bd_cinfinite_of_bnf outer);
    2.33  
    2.34      val set_alt_thms =
    2.35        if Config.get lthy quick_and_dirty then
    2.36 @@ -319,7 +319,7 @@
    2.37          |> Thm.close_derivation
    2.38        end;
    2.39  
    2.40 -    fun le_rel_OO_tac _ = mk_le_rel_OO_tac (le_rel_OO_of_bnf outer) (rel_mono_of_bnf outer)
    2.41 +    fun le_rel_OO_tac ctxt = mk_le_rel_OO_tac ctxt (le_rel_OO_of_bnf outer) (rel_mono_of_bnf outer)
    2.42        (map le_rel_OO_of_bnf inners);
    2.43  
    2.44      fun rel_OO_Grp_tac ctxt =
    2.45 @@ -334,7 +334,7 @@
    2.46                 trans OF [rel_OO_of_bnf outer RS sym, outer_rel_cong OF
    2.47                   (map (fn bnf => rel_OO_Grp_of_bnf bnf RS sym) inners)]]] RS sym);
    2.48        in
    2.49 -        unfold_thms_tac ctxt set'_eq_sets THEN rtac thm 1
    2.50 +        unfold_thms_tac ctxt set'_eq_sets THEN rtac ctxt thm 1
    2.51        end;
    2.52  
    2.53      val tacs = zip_axioms map_id0_tac map_comp0_tac map_cong0_tac set_map0_tacs bd_card_order_tac
    2.54 @@ -408,16 +408,16 @@
    2.55  
    2.56      val bd = mk_bd_of_bnf Ds As bnf;
    2.57  
    2.58 -    fun map_id0_tac _ = rtac (map_id0_of_bnf bnf) 1;
    2.59 +    fun map_id0_tac ctxt = rtac ctxt (map_id0_of_bnf bnf) 1;
    2.60      fun map_comp0_tac ctxt =
    2.61        unfold_thms_tac ctxt ((map_comp0_of_bnf bnf RS sym) ::
    2.62 -        @{thms comp_assoc id_comp comp_id}) THEN rtac refl 1;
    2.63 +        @{thms comp_assoc id_comp comp_id}) THEN rtac ctxt refl 1;
    2.64      fun map_cong0_tac ctxt =
    2.65        mk_kill_map_cong0_tac ctxt n (live - n) (map_cong0_of_bnf bnf);
    2.66 -    val set_map0_tacs = map (fn thm => fn _ => rtac thm 1) (drop n (set_map0_of_bnf bnf));
    2.67 -    fun bd_card_order_tac _ = rtac (bd_card_order_of_bnf bnf) 1;
    2.68 -    fun bd_cinfinite_tac _ = rtac (bd_cinfinite_of_bnf bnf) 1;
    2.69 -    val set_bd_tacs = map (fn thm => fn _ => rtac thm 1) (drop n (set_bd_of_bnf bnf));
    2.70 +    val set_map0_tacs = map (fn thm => fn ctxt => rtac ctxt thm 1) (drop n (set_map0_of_bnf bnf));
    2.71 +    fun bd_card_order_tac ctxt = rtac ctxt (bd_card_order_of_bnf bnf) 1;
    2.72 +    fun bd_cinfinite_tac ctxt = rtac ctxt (bd_cinfinite_of_bnf bnf) 1;
    2.73 +    val set_bd_tacs = map (fn thm => fn ctxt => rtac ctxt thm 1) (drop n (set_bd_of_bnf bnf));
    2.74  
    2.75      val in_alt_thm =
    2.76        let
    2.77 @@ -425,14 +425,15 @@
    2.78          val in_alt = mk_in (map HOLogic.mk_UNIV killedAs @ Asets) bnf_sets T;
    2.79          val goal = fold_rev Logic.all Asets (mk_Trueprop_eq (inx, in_alt));
    2.80        in
    2.81 -        Goal.prove_sorry lthy [] [] goal (K kill_in_alt_tac) |> Thm.close_derivation
    2.82 +        Goal.prove_sorry lthy [] [] goal (fn {context = ctxt, prems = _} =>
    2.83 +          kill_in_alt_tac ctxt) |> Thm.close_derivation
    2.84        end;
    2.85  
    2.86      fun le_rel_OO_tac ctxt =
    2.87 -      EVERY' [rtac @{thm ord_le_eq_trans}, rtac (le_rel_OO_of_bnf bnf)] 1 THEN
    2.88 -      unfold_thms_tac ctxt @{thms eq_OO} THEN rtac refl 1;
    2.89 +      EVERY' [rtac ctxt @{thm ord_le_eq_trans}, rtac ctxt (le_rel_OO_of_bnf bnf)] 1 THEN
    2.90 +      unfold_thms_tac ctxt @{thms eq_OO} THEN rtac ctxt refl 1;
    2.91  
    2.92 -    fun rel_OO_Grp_tac _ =
    2.93 +    fun rel_OO_Grp_tac ctxt =
    2.94        let
    2.95          val rel_Grp = rel_Grp_of_bnf bnf RS sym
    2.96          val thm =
    2.97 @@ -444,7 +445,7 @@
    2.98                  (replicate n @{thm trans[OF Grp_UNIV_id[OF refl] eq_alt[symmetric]]} @
    2.99                   replicate (live - n) @{thm Grp_fst_snd})]]] RS sym);
   2.100        in
   2.101 -        rtac thm 1
   2.102 +        rtac ctxt thm 1
   2.103        end;
   2.104  
   2.105      val tacs = zip_axioms map_id0_tac map_comp0_tac map_cong0_tac set_map0_tacs bd_card_order_tac
   2.106 @@ -506,26 +507,26 @@
   2.107  
   2.108      val bd = mk_bd_of_bnf Ds As bnf;
   2.109  
   2.110 -    fun map_id0_tac _ = rtac (map_id0_of_bnf bnf) 1;
   2.111 +    fun map_id0_tac ctxt = rtac ctxt (map_id0_of_bnf bnf) 1;
   2.112      fun map_comp0_tac ctxt =
   2.113        unfold_thms_tac ctxt ((map_comp0_of_bnf bnf RS sym) ::
   2.114 -        @{thms comp_assoc id_comp comp_id}) THEN rtac refl 1;
   2.115 +        @{thms comp_assoc id_comp comp_id}) THEN rtac ctxt refl 1;
   2.116      fun map_cong0_tac ctxt =
   2.117 -      rtac (map_cong0_of_bnf bnf) 1 THEN REPEAT_DETERM_N live (Goal.assume_rule_tac ctxt 1);
   2.118 +      rtac ctxt (map_cong0_of_bnf bnf) 1 THEN REPEAT_DETERM_N live (Goal.assume_rule_tac ctxt 1);
   2.119      val set_map0_tacs =
   2.120        if Config.get lthy quick_and_dirty then
   2.121          replicate (n + live) (K all_tac)
   2.122        else
   2.123 -        replicate n (K empty_natural_tac) @
   2.124 -        map (fn thm => fn _ => rtac thm 1) (set_map0_of_bnf bnf);
   2.125 -    fun bd_card_order_tac _ = rtac (bd_card_order_of_bnf bnf) 1;
   2.126 -    fun bd_cinfinite_tac _ = rtac (bd_cinfinite_of_bnf bnf) 1;
   2.127 +        replicate n empty_natural_tac @
   2.128 +        map (fn thm => fn ctxt => rtac ctxt thm 1) (set_map0_of_bnf bnf);
   2.129 +    fun bd_card_order_tac ctxt = rtac ctxt (bd_card_order_of_bnf bnf) 1;
   2.130 +    fun bd_cinfinite_tac ctxt = rtac ctxt (bd_cinfinite_of_bnf bnf) 1;
   2.131      val set_bd_tacs =
   2.132        if Config.get lthy quick_and_dirty then
   2.133          replicate (n + live) (K all_tac)
   2.134        else
   2.135 -        replicate n (K (mk_lift_set_bd_tac (bd_Card_order_of_bnf bnf))) @
   2.136 -        (map (fn thm => fn _ => rtac thm 1) (set_bd_of_bnf bnf));
   2.137 +        replicate n (fn ctxt => mk_lift_set_bd_tac ctxt (bd_Card_order_of_bnf bnf)) @
   2.138 +        (map (fn thm => fn ctxt => rtac ctxt thm 1) (set_bd_of_bnf bnf));
   2.139  
   2.140      val in_alt_thm =
   2.141        let
   2.142 @@ -533,12 +534,13 @@
   2.143          val in_alt = mk_in (drop n Asets) bnf_sets T;
   2.144          val goal = fold_rev Logic.all Asets (mk_Trueprop_eq (inx, in_alt));
   2.145        in
   2.146 -        Goal.prove_sorry lthy [] [] goal (K lift_in_alt_tac) |> Thm.close_derivation
   2.147 +        Goal.prove_sorry lthy [] [] goal (fn {context = ctxt, prems = _} => lift_in_alt_tac ctxt)
   2.148 +        |> Thm.close_derivation
   2.149        end;
   2.150  
   2.151 -    fun le_rel_OO_tac _ = rtac (le_rel_OO_of_bnf bnf) 1;
   2.152 +    fun le_rel_OO_tac ctxt = rtac ctxt (le_rel_OO_of_bnf bnf) 1;
   2.153  
   2.154 -    fun rel_OO_Grp_tac _ = mk_simple_rel_OO_Grp_tac (rel_OO_Grp_of_bnf bnf) in_alt_thm;
   2.155 +    fun rel_OO_Grp_tac ctxt = mk_simple_rel_OO_Grp_tac ctxt (rel_OO_Grp_of_bnf bnf) in_alt_thm;
   2.156  
   2.157      val tacs = zip_axioms map_id0_tac map_comp0_tac map_cong0_tac set_map0_tacs bd_card_order_tac
   2.158        bd_cinfinite_tac set_bd_tacs le_rel_OO_tac rel_OO_Grp_tac;
   2.159 @@ -598,14 +600,14 @@
   2.160  
   2.161      val bd = mk_bd_of_bnf Ds As bnf;
   2.162  
   2.163 -    fun map_id0_tac _ = rtac (map_id0_of_bnf bnf) 1;
   2.164 -    fun map_comp0_tac _ = rtac (map_comp0_of_bnf bnf) 1;
   2.165 +    fun map_id0_tac ctxt = rtac ctxt (map_id0_of_bnf bnf) 1;
   2.166 +    fun map_comp0_tac ctxt = rtac ctxt (map_comp0_of_bnf bnf) 1;
   2.167      fun map_cong0_tac ctxt =
   2.168 -      rtac (map_cong0_of_bnf bnf) 1 THEN REPEAT_DETERM_N live (Goal.assume_rule_tac ctxt 1);
   2.169 -    val set_map0_tacs = permute (map (fn thm => fn _ => rtac thm 1) (set_map0_of_bnf bnf));
   2.170 -    fun bd_card_order_tac _ = rtac (bd_card_order_of_bnf bnf) 1;
   2.171 -    fun bd_cinfinite_tac _ = rtac (bd_cinfinite_of_bnf bnf) 1;
   2.172 -    val set_bd_tacs = permute (map (fn thm => fn _ => rtac thm 1) (set_bd_of_bnf bnf));
   2.173 +      rtac ctxt (map_cong0_of_bnf bnf) 1 THEN REPEAT_DETERM_N live (Goal.assume_rule_tac ctxt 1);
   2.174 +    val set_map0_tacs = permute (map (fn thm => fn ctxt => rtac ctxt thm 1) (set_map0_of_bnf bnf));
   2.175 +    fun bd_card_order_tac ctxt = rtac ctxt (bd_card_order_of_bnf bnf) 1;
   2.176 +    fun bd_cinfinite_tac ctxt = rtac ctxt (bd_cinfinite_of_bnf bnf) 1;
   2.177 +    val set_bd_tacs = permute (map (fn thm => fn ctxt => rtac ctxt thm 1) (set_bd_of_bnf bnf));
   2.178  
   2.179      val in_alt_thm =
   2.180        let
   2.181 @@ -613,13 +615,14 @@
   2.182          val in_alt = mk_in (unpermute Asets) bnf_sets T;
   2.183          val goal = fold_rev Logic.all Asets (mk_Trueprop_eq (inx, in_alt));
   2.184        in
   2.185 -        Goal.prove_sorry lthy [] [] goal (K (mk_permute_in_alt_tac src dest))
   2.186 +        Goal.prove_sorry lthy [] [] goal (fn {context = ctxt, prems = _} =>
   2.187 +          mk_permute_in_alt_tac ctxt src dest)
   2.188          |> Thm.close_derivation
   2.189        end;
   2.190  
   2.191 -    fun le_rel_OO_tac _ = rtac (le_rel_OO_of_bnf bnf) 1;
   2.192 +    fun le_rel_OO_tac ctxt = rtac ctxt (le_rel_OO_of_bnf bnf) 1;
   2.193  
   2.194 -    fun rel_OO_Grp_tac _ = mk_simple_rel_OO_Grp_tac (rel_OO_Grp_of_bnf bnf) in_alt_thm;
   2.195 +    fun rel_OO_Grp_tac ctxt = mk_simple_rel_OO_Grp_tac ctxt (rel_OO_Grp_of_bnf bnf) in_alt_thm;
   2.196  
   2.197      val tacs = zip_axioms map_id0_tac map_comp0_tac map_cong0_tac set_map0_tacs bd_card_order_tac
   2.198        bd_cinfinite_tac set_bd_tacs le_rel_OO_tac rel_OO_Grp_tac;
   2.199 @@ -796,7 +799,7 @@
   2.200         else inter (op =) (Term.add_tfreesT repTA []) all_TA_params_in_order);
   2.201      val ((TA, (Rep_name, Abs_name, type_definition, Abs_inverse, Abs_inject, _)), lthy) =
   2.202        maybe_typedef lthy has_live_phantoms (T_bind, TA_params, NoSyn) (HOLogic.mk_UNIV repTA) NONE
   2.203 -        (fn _ => EVERY' [rtac exI, rtac UNIV_I] 1) lthy;
   2.204 +        (fn ctxt => EVERY' [rtac ctxt exI, rtac ctxt UNIV_I] 1) lthy;
   2.205  
   2.206      val repTB = mk_T_of_bnf Ds Bs bnf;
   2.207      val TB = Term.typ_subst_atomic (As ~~ Bs) TA;
   2.208 @@ -826,7 +829,7 @@
   2.209  
   2.210      val ((bdT, (_, Abs_bd_name, _, _, Abs_bdT_inject, Abs_bdT_cases)), lthy) =
   2.211        maybe_typedef lthy false (bdT_bind, params, NoSyn)
   2.212 -        (HOLogic.mk_UNIV bd_repT) NONE (fn _ => EVERY' [rtac exI, rtac UNIV_I] 1) lthy;
   2.213 +        (HOLogic.mk_UNIV bd_repT) NONE (fn ctxt => EVERY' [rtac ctxt exI, rtac ctxt UNIV_I] 1) lthy;
   2.214  
   2.215      val (bnf_bd', bd_ordIso, bd_card_order, bd_cinfinite) =
   2.216        if bdT = bd_repT then (bnf_bd, bd_Card_order_of_bnf bnf RS @{thm ordIso_refl},
   2.217 @@ -847,31 +850,32 @@
   2.218            (bnf_bd', bd_ordIso, bd_card_order, bd_cinfinite)
   2.219          end;
   2.220  
   2.221 -    fun map_id0_tac _ =
   2.222 -      rtac (@{thm type_copy_map_id0} OF [type_definition, map_id0_of_bnf bnf]) 1;
   2.223 -    fun map_comp0_tac _ =
   2.224 -      rtac (@{thm type_copy_map_comp0} OF [type_definition, map_comp0_of_bnf bnf]) 1;
   2.225 -    fun map_cong0_tac _ =
   2.226 -      EVERY' (rtac @{thm type_copy_map_cong0} :: rtac (map_cong0_of_bnf bnf) ::
   2.227 -        map (fn i => EVERY' [select_prem_tac live (dtac meta_spec) i, etac meta_mp,
   2.228 -          etac (o_apply RS equalityD2 RS set_mp)]) (1 upto live)) 1;
   2.229 -    fun set_map0_tac thm _ =
   2.230 -      rtac (@{thm type_copy_set_map0} OF [type_definition, thm]) 1;
   2.231 -    val set_bd_tacs = map (fn thm => fn _ => rtac (@{thm ordLeq_ordIso_trans} OF
   2.232 +    fun map_id0_tac ctxt =
   2.233 +      rtac ctxt (@{thm type_copy_map_id0} OF [type_definition, map_id0_of_bnf bnf]) 1;
   2.234 +    fun map_comp0_tac ctxt =
   2.235 +      rtac ctxt (@{thm type_copy_map_comp0} OF [type_definition, map_comp0_of_bnf bnf]) 1;
   2.236 +    fun map_cong0_tac ctxt =
   2.237 +      EVERY' (rtac ctxt @{thm type_copy_map_cong0} :: rtac ctxt (map_cong0_of_bnf bnf) ::
   2.238 +        map (fn i => EVERY' [select_prem_tac ctxt live (dtac ctxt meta_spec) i, etac ctxt meta_mp,
   2.239 +          etac ctxt (o_apply RS equalityD2 RS set_mp)]) (1 upto live)) 1;
   2.240 +    fun set_map0_tac thm ctxt =
   2.241 +      rtac ctxt (@{thm type_copy_set_map0} OF [type_definition, thm]) 1;
   2.242 +    val set_bd_tacs = map (fn thm => fn ctxt => rtac ctxt (@{thm ordLeq_ordIso_trans} OF
   2.243          [thm, bd_ordIso] RS @{thm type_copy_set_bd}) 1) (set_bd_of_bnf bnf);
   2.244 -    fun le_rel_OO_tac _ =
   2.245 -      rtac (le_rel_OO_of_bnf bnf RS @{thm vimage2p_relcompp_mono}) 1;
   2.246 +    fun le_rel_OO_tac ctxt =
   2.247 +      rtac ctxt (le_rel_OO_of_bnf bnf RS @{thm vimage2p_relcompp_mono}) 1;
   2.248      fun rel_OO_Grp_tac ctxt =
   2.249 -      (rtac (rel_OO_Grp_of_bnf bnf RS @{thm vimage2p_cong} RS trans) THEN'
   2.250 +      (rtac ctxt (rel_OO_Grp_of_bnf bnf RS @{thm vimage2p_cong} RS trans) THEN'
   2.251         (if has_live_phantoms then subst_tac ctxt NONE else SELECT_GOAL o unfold_thms_tac ctxt)
   2.252           [type_definition RS @{thm vimage2p_relcompp_converse}] THEN'
   2.253         SELECT_GOAL (unfold_thms_tac ctxt [o_apply,
   2.254           type_definition RS @{thm type_copy_vimage2p_Grp_Rep},
   2.255           type_definition RS @{thm vimage2p_relcompp_converse}]) THEN'
   2.256 -       rtac refl) 1;
   2.257 +       rtac ctxt refl) 1;
   2.258  
   2.259      val tacs = zip_axioms map_id0_tac map_comp0_tac map_cong0_tac
   2.260 -      (map set_map0_tac (set_map0_of_bnf bnf)) (K (rtac bd_card_order 1)) (K (rtac bd_cinfinite 1))
   2.261 +      (map set_map0_tac (set_map0_of_bnf bnf))
   2.262 +      (fn ctxt => rtac ctxt bd_card_order 1) (fn ctxt => rtac ctxt bd_cinfinite 1)
   2.263        set_bd_tacs le_rel_OO_tac rel_OO_Grp_tac;
   2.264  
   2.265      val bnf_wits = map (fn (I, t) =>
   2.266 @@ -879,7 +883,7 @@
   2.267            (AbsA $ Term.list_comb (t, map Bound (0 upto length I - 1))))
   2.268        (mk_wits_of_bnf (replicate nwits Ds) (replicate nwits As) bnf);
   2.269  
   2.270 -    fun wit_tac _ = ALLGOALS (dtac (type_definition RS @{thm type_copy_wit})) THEN
   2.271 +    fun wit_tac ctxt = ALLGOALS (dtac ctxt (type_definition RS @{thm type_copy_wit})) THEN
   2.272        mk_simple_wit_tac (wit_thms_of_bnf bnf);
   2.273  
   2.274      val (bnf', lthy') =
     3.1 --- a/src/HOL/Tools/BNF/bnf_comp_tactics.ML	Thu Jul 16 10:48:20 2015 +0200
     3.2 +++ b/src/HOL/Tools/BNF/bnf_comp_tactics.ML	Thu Jul 16 12:23:22 2015 +0200
     3.3 @@ -8,28 +8,28 @@
     3.4  
     3.5  signature BNF_COMP_TACTICS =
     3.6  sig
     3.7 -  val mk_comp_bd_card_order_tac: thm list -> thm -> tactic
     3.8 -  val mk_comp_bd_cinfinite_tac: thm -> thm -> tactic
     3.9 +  val mk_comp_bd_card_order_tac: Proof.context -> thm list -> thm -> tactic
    3.10 +  val mk_comp_bd_cinfinite_tac: Proof.context -> thm -> thm -> tactic
    3.11    val mk_comp_in_alt_tac: Proof.context -> thm list -> tactic
    3.12 -  val mk_comp_map_comp0_tac: thm -> thm -> thm list -> tactic
    3.13 +  val mk_comp_map_comp0_tac: Proof.context -> thm -> thm -> thm list -> tactic
    3.14    val mk_comp_map_cong0_tac: Proof.context -> thm list -> thm list -> thm -> thm list -> tactic
    3.15 -  val mk_comp_map_id0_tac: thm -> thm -> thm list -> tactic
    3.16 +  val mk_comp_map_id0_tac: Proof.context -> thm -> thm -> thm list -> tactic
    3.17    val mk_comp_set_alt_tac: Proof.context -> thm -> tactic
    3.18    val mk_comp_set_bd_tac: Proof.context -> thm -> thm option -> thm -> thm list -> tactic
    3.19    val mk_comp_set_map0_tac: Proof.context -> thm -> thm -> thm -> thm -> thm list -> tactic
    3.20    val mk_comp_wit_tac: Proof.context -> thm list -> thm list -> thm -> thm list -> tactic
    3.21  
    3.22 -  val kill_in_alt_tac: tactic
    3.23 +  val kill_in_alt_tac: Proof.context -> tactic
    3.24    val mk_kill_map_cong0_tac: Proof.context -> int -> int -> thm -> tactic
    3.25  
    3.26 -  val empty_natural_tac: tactic
    3.27 -  val lift_in_alt_tac: tactic
    3.28 -  val mk_lift_set_bd_tac: thm -> tactic
    3.29 +  val empty_natural_tac: Proof.context -> tactic
    3.30 +  val lift_in_alt_tac: Proof.context -> tactic
    3.31 +  val mk_lift_set_bd_tac: Proof.context -> thm -> tactic
    3.32  
    3.33 -  val mk_permute_in_alt_tac: ''a list -> ''a list -> tactic
    3.34 +  val mk_permute_in_alt_tac: Proof.context -> ''a list -> ''a list -> tactic
    3.35  
    3.36 -  val mk_le_rel_OO_tac: thm -> thm -> thm list -> tactic
    3.37 -  val mk_simple_rel_OO_Grp_tac: thm -> thm -> tactic
    3.38 +  val mk_le_rel_OO_tac: Proof.context -> thm -> thm -> thm list -> tactic
    3.39 +  val mk_simple_rel_OO_Grp_tac: Proof.context -> thm -> thm -> tactic
    3.40    val mk_simple_wit_tac: thm list -> tactic
    3.41    val mk_simplified_set_tac: Proof.context -> thm -> tactic
    3.42    val bd_ordIso_natLeq_tac: tactic
    3.43 @@ -52,96 +52,96 @@
    3.44  fun mk_comp_set_alt_tac ctxt collect_set_map =
    3.45    unfold_thms_tac ctxt @{thms comp_assoc} THEN
    3.46    unfold_thms_tac ctxt [collect_set_map RS sym] THEN
    3.47 -  rtac refl 1;
    3.48 +  rtac ctxt refl 1;
    3.49  
    3.50 -fun mk_comp_map_id0_tac Gmap_id0 Gmap_cong0 map_id0s =
    3.51 -  EVERY' ([rtac @{thm ext}, rtac (Gmap_cong0 RS trans)] @
    3.52 -    map (fn thm => rtac (thm RS fun_cong)) map_id0s @ [rtac (Gmap_id0 RS fun_cong)]) 1;
    3.53 +fun mk_comp_map_id0_tac ctxt Gmap_id0 Gmap_cong0 map_id0s =
    3.54 +  EVERY' ([rtac ctxt @{thm ext}, rtac ctxt (Gmap_cong0 RS trans)] @
    3.55 +    map (fn thm => rtac ctxt (thm RS fun_cong)) map_id0s @ [rtac ctxt (Gmap_id0 RS fun_cong)]) 1;
    3.56  
    3.57 -fun mk_comp_map_comp0_tac Gmap_comp0 Gmap_cong0 map_comp0s =
    3.58 -  EVERY' ([rtac @{thm ext}, rtac sym, rtac trans_o_apply,
    3.59 -    rtac (Gmap_comp0 RS sym RS comp_eq_dest_lhs RS trans), rtac Gmap_cong0] @
    3.60 -    map (fn thm => rtac (thm RS sym RS fun_cong)) map_comp0s) 1;
    3.61 +fun mk_comp_map_comp0_tac ctxt Gmap_comp0 Gmap_cong0 map_comp0s =
    3.62 +  EVERY' ([rtac ctxt @{thm ext}, rtac ctxt sym, rtac ctxt trans_o_apply,
    3.63 +    rtac ctxt (Gmap_comp0 RS sym RS comp_eq_dest_lhs RS trans), rtac ctxt Gmap_cong0] @
    3.64 +    map (fn thm => rtac ctxt (thm RS sym RS fun_cong)) map_comp0s) 1;
    3.65  
    3.66  fun mk_comp_set_map0_tac ctxt set'_eq_set Gmap_comp0 Gmap_cong0 Gset_map0 set_map0s =
    3.67    unfold_thms_tac ctxt [set'_eq_set] THEN
    3.68 -  EVERY' ([rtac @{thm ext}] @
    3.69 -    replicate 3 (rtac trans_o_apply) @
    3.70 -    [rtac (arg_cong_Union RS trans),
    3.71 -     rtac (@{thm arg_cong2[of _ _ _ _ collect, OF refl]} RS trans),
    3.72 -     rtac (Gmap_comp0 RS sym RS comp_eq_dest_lhs RS trans),
    3.73 -     rtac Gmap_cong0] @
    3.74 -     map (fn thm => rtac (thm RS fun_cong)) set_map0s @
    3.75 -     [rtac (Gset_map0 RS comp_eq_dest_lhs), rtac sym, rtac trans_o_apply,
    3.76 -     rtac trans_image_cong_o_apply, rtac trans_image_cong_o_apply,
    3.77 -     rtac (@{thm image_cong} OF [Gset_map0 RS comp_eq_dest_lhs RS arg_cong_Union, refl] RS trans),
    3.78 -     rtac @{thm trans[OF comp_eq_dest[OF Union_natural[symmetric]]]}, rtac arg_cong_Union,
    3.79 -     rtac @{thm trans[OF comp_eq_dest_lhs[OF image_o_collect[symmetric]]]},
    3.80 -     rtac @{thm fun_cong[OF arg_cong[of _ _ collect]]}] @
    3.81 -     [REPEAT_DETERM_N (length set_map0s) o EVERY' [rtac @{thm trans[OF image_insert]},
    3.82 -        rtac @{thm arg_cong2[of _ _ _ _ insert]}, rtac @{thm ext}, rtac trans_o_apply,
    3.83 -        rtac trans_image_cong_o_apply, rtac @{thm trans[OF image_image]},
    3.84 -        rtac @{thm sym[OF trans[OF o_apply]]}, rtac @{thm image_cong[OF refl o_apply]}],
    3.85 -     rtac @{thm image_empty}]) 1;
    3.86 +  EVERY' ([rtac ctxt @{thm ext}] @
    3.87 +    replicate 3 (rtac ctxt trans_o_apply) @
    3.88 +    [rtac ctxt (arg_cong_Union RS trans),
    3.89 +     rtac ctxt (@{thm arg_cong2[of _ _ _ _ collect, OF refl]} RS trans),
    3.90 +     rtac ctxt (Gmap_comp0 RS sym RS comp_eq_dest_lhs RS trans),
    3.91 +     rtac ctxt Gmap_cong0] @
    3.92 +     map (fn thm => rtac ctxt (thm RS fun_cong)) set_map0s @
    3.93 +     [rtac ctxt (Gset_map0 RS comp_eq_dest_lhs), rtac ctxt sym, rtac ctxt trans_o_apply,
    3.94 +     rtac ctxt trans_image_cong_o_apply, rtac ctxt trans_image_cong_o_apply,
    3.95 +     rtac ctxt (@{thm image_cong} OF [Gset_map0 RS comp_eq_dest_lhs RS arg_cong_Union, refl] RS trans),
    3.96 +     rtac ctxt @{thm trans[OF comp_eq_dest[OF Union_natural[symmetric]]]}, rtac ctxt arg_cong_Union,
    3.97 +     rtac ctxt @{thm trans[OF comp_eq_dest_lhs[OF image_o_collect[symmetric]]]},
    3.98 +     rtac ctxt @{thm fun_cong[OF arg_cong[of _ _ collect]]}] @
    3.99 +     [REPEAT_DETERM_N (length set_map0s) o EVERY' [rtac ctxt @{thm trans[OF image_insert]},
   3.100 +        rtac ctxt @{thm arg_cong2[of _ _ _ _ insert]}, rtac ctxt @{thm ext}, rtac ctxt trans_o_apply,
   3.101 +        rtac ctxt trans_image_cong_o_apply, rtac ctxt @{thm trans[OF image_image]},
   3.102 +        rtac ctxt @{thm sym[OF trans[OF o_apply]]}, rtac ctxt @{thm image_cong[OF refl o_apply]}],
   3.103 +     rtac ctxt @{thm image_empty}]) 1;
   3.104  
   3.105  fun mk_comp_map_cong0_tac ctxt set'_eq_sets comp_set_alts map_cong0 map_cong0s =
   3.106    let
   3.107       val n = length comp_set_alts;
   3.108    in
   3.109      unfold_thms_tac ctxt set'_eq_sets THEN
   3.110 -    (if n = 0 then rtac refl 1
   3.111 -    else rtac map_cong0 1 THEN
   3.112 +    (if n = 0 then rtac ctxt refl 1
   3.113 +    else rtac ctxt map_cong0 1 THEN
   3.114        EVERY' (map_index (fn (i, map_cong0) =>
   3.115 -        rtac map_cong0 THEN' EVERY' (map_index (fn (k, set_alt) =>
   3.116 -          EVERY' [select_prem_tac n (dtac @{thm meta_spec}) (k + 1), etac meta_mp,
   3.117 -            rtac (equalityD2 RS set_mp), rtac (set_alt RS fun_cong RS trans),
   3.118 -            rtac trans_o_apply, rtac (@{thm collect_def} RS arg_cong_Union),
   3.119 -            rtac @{thm UnionI}, rtac @{thm UN_I}, REPEAT_DETERM_N i o rtac @{thm insertI2},
   3.120 -            rtac @{thm insertI1}, rtac (o_apply RS equalityD2 RS set_mp),
   3.121 -            etac @{thm imageI}, atac])
   3.122 +        rtac ctxt map_cong0 THEN' EVERY' (map_index (fn (k, set_alt) =>
   3.123 +          EVERY' [select_prem_tac ctxt n (dtac ctxt @{thm meta_spec}) (k + 1), etac ctxt meta_mp,
   3.124 +            rtac ctxt (equalityD2 RS set_mp), rtac ctxt (set_alt RS fun_cong RS trans),
   3.125 +            rtac ctxt trans_o_apply, rtac ctxt (@{thm collect_def} RS arg_cong_Union),
   3.126 +            rtac ctxt @{thm UnionI}, rtac ctxt @{thm UN_I}, REPEAT_DETERM_N i o rtac ctxt @{thm insertI2},
   3.127 +            rtac ctxt @{thm insertI1}, rtac ctxt (o_apply RS equalityD2 RS set_mp),
   3.128 +            etac ctxt @{thm imageI}, atac])
   3.129            comp_set_alts))
   3.130        map_cong0s) 1)
   3.131    end;
   3.132  
   3.133 -fun mk_comp_bd_card_order_tac Fbd_card_orders Gbd_card_order =
   3.134 -  rtac @{thm natLeq_card_order} 1 ORELSE
   3.135 +fun mk_comp_bd_card_order_tac ctxt Fbd_card_orders Gbd_card_order =
   3.136 +  rtac ctxt @{thm natLeq_card_order} 1 ORELSE
   3.137    let
   3.138      val (card_orders, last_card_order) = split_last Fbd_card_orders;
   3.139 -    fun gen_before thm = rtac @{thm card_order_csum} THEN' rtac thm;
   3.140 +    fun gen_before thm = rtac ctxt @{thm card_order_csum} THEN' rtac ctxt thm;
   3.141    in
   3.142 -    (rtac @{thm card_order_cprod} THEN'
   3.143 -    WRAP' gen_before (K (K all_tac)) card_orders (rtac last_card_order) THEN'
   3.144 -    rtac Gbd_card_order) 1
   3.145 +    (rtac ctxt @{thm card_order_cprod} THEN'
   3.146 +    WRAP' gen_before (K (K all_tac)) card_orders (rtac ctxt last_card_order) THEN'
   3.147 +    rtac ctxt Gbd_card_order) 1
   3.148    end;
   3.149  
   3.150 -fun mk_comp_bd_cinfinite_tac Fbd_cinfinite Gbd_cinfinite =
   3.151 -  (rtac @{thm natLeq_cinfinite} ORELSE'
   3.152 -   rtac @{thm cinfinite_cprod} THEN'
   3.153 -   ((K (TRY ((rtac @{thm cinfinite_csum} THEN' rtac disjI1) 1)) THEN'
   3.154 -     ((rtac @{thm cinfinite_csum} THEN' rtac disjI1 THEN' rtac Fbd_cinfinite) ORELSE'
   3.155 -      rtac Fbd_cinfinite)) ORELSE'
   3.156 -    rtac Fbd_cinfinite) THEN'
   3.157 -   rtac Gbd_cinfinite) 1;
   3.158 +fun mk_comp_bd_cinfinite_tac ctxt Fbd_cinfinite Gbd_cinfinite =
   3.159 +  (rtac ctxt @{thm natLeq_cinfinite} ORELSE'
   3.160 +   rtac ctxt @{thm cinfinite_cprod} THEN'
   3.161 +   ((K (TRY ((rtac ctxt @{thm cinfinite_csum} THEN' rtac ctxt disjI1) 1)) THEN'
   3.162 +     ((rtac ctxt @{thm cinfinite_csum} THEN' rtac ctxt disjI1 THEN' rtac ctxt Fbd_cinfinite) ORELSE'
   3.163 +      rtac ctxt Fbd_cinfinite)) ORELSE'
   3.164 +    rtac ctxt Fbd_cinfinite) THEN'
   3.165 +   rtac ctxt Gbd_cinfinite) 1;
   3.166  
   3.167  fun mk_comp_set_bd_tac ctxt set'_eq_set bd_ordIso_natLeq_opt comp_set_alt Gset_Fset_bds =
   3.168    let
   3.169      val (bds, last_bd) = split_last Gset_Fset_bds;
   3.170      fun gen_before bd =
   3.171 -      rtac ctrans THEN' rtac @{thm Un_csum} THEN'
   3.172 -      rtac ctrans THEN' rtac @{thm csum_mono} THEN'
   3.173 -      rtac bd;
   3.174 -    fun gen_after _ = rtac @{thm ordIso_imp_ordLeq} THEN' rtac @{thm cprod_csum_distrib1};
   3.175 +      rtac ctxt ctrans THEN' rtac ctxt @{thm Un_csum} THEN'
   3.176 +      rtac ctxt ctrans THEN' rtac ctxt @{thm csum_mono} THEN'
   3.177 +      rtac ctxt bd;
   3.178 +    fun gen_after _ = rtac ctxt @{thm ordIso_imp_ordLeq} THEN' rtac ctxt @{thm cprod_csum_distrib1};
   3.179    in
   3.180      (case bd_ordIso_natLeq_opt of
   3.181 -      SOME thm => rtac (thm RSN (2, @{thm ordLeq_ordIso_trans})) 1
   3.182 +      SOME thm => rtac ctxt (thm RSN (2, @{thm ordLeq_ordIso_trans})) 1
   3.183      | NONE => all_tac) THEN
   3.184      unfold_thms_tac ctxt [set'_eq_set, comp_set_alt] THEN
   3.185 -    rtac @{thm comp_set_bd_Union_o_collect} 1 THEN
   3.186 +    rtac ctxt @{thm comp_set_bd_Union_o_collect} 1 THEN
   3.187      unfold_thms_tac ctxt @{thms Union_image_insert Union_image_empty Union_Un_distrib o_apply} THEN
   3.188 -    (rtac ctrans THEN'
   3.189 -     WRAP' gen_before gen_after bds (rtac last_bd) THEN'
   3.190 -     rtac @{thm ordIso_imp_ordLeq} THEN'
   3.191 -     rtac @{thm cprod_com}) 1
   3.192 +    (rtac ctxt ctrans THEN'
   3.193 +     WRAP' gen_before gen_after bds (rtac ctxt last_bd) THEN'
   3.194 +     rtac ctxt @{thm ordIso_imp_ordLeq} THEN'
   3.195 +     rtac ctxt @{thm cprod_com}) 1
   3.196    end;
   3.197  
   3.198  val comp_in_alt_thms = @{thms o_apply collect_def image_insert image_empty Union_insert UN_insert
   3.199 @@ -152,84 +152,85 @@
   3.200    unfold_thms_tac ctxt comp_set_alts THEN
   3.201    unfold_thms_tac ctxt comp_in_alt_thms THEN
   3.202    unfold_thms_tac ctxt @{thms set_eq_subset} THEN
   3.203 -  rtac conjI 1 THEN
   3.204 +  rtac ctxt conjI 1 THEN
   3.205    REPEAT_DETERM (
   3.206 -    rtac @{thm subsetI} 1 THEN
   3.207 +    rtac ctxt @{thm subsetI} 1 THEN
   3.208      unfold_thms_tac ctxt @{thms mem_Collect_eq Ball_def} THEN
   3.209 -    (REPEAT_DETERM (CHANGED (etac conjE 1)) THEN
   3.210 +    (REPEAT_DETERM (CHANGED (etac ctxt conjE 1)) THEN
   3.211       REPEAT_DETERM (CHANGED ((
   3.212 -       (rtac conjI THEN' (atac ORELSE' rtac subset_UNIV)) ORELSE'
   3.213 +       (rtac ctxt conjI THEN' (atac ORELSE' rtac ctxt subset_UNIV)) ORELSE'
   3.214         atac ORELSE'
   3.215 -       (rtac subset_UNIV)) 1)) ORELSE rtac subset_UNIV 1));
   3.216 +       (rtac ctxt subset_UNIV)) 1)) ORELSE rtac ctxt subset_UNIV 1));
   3.217  
   3.218  val comp_wit_thms = @{thms Union_empty_conv o_apply collect_def UN_insert UN_empty Un_empty_right
   3.219    Union_image_insert Union_image_empty};
   3.220  
   3.221  fun mk_comp_wit_tac ctxt set'_eq_sets Gwit_thms collect_set_map Fwit_thms =
   3.222    unfold_thms_tac ctxt set'_eq_sets THEN
   3.223 -  ALLGOALS (dtac @{thm in_Union_o_assoc}) THEN
   3.224 +  ALLGOALS (dtac ctxt @{thm in_Union_o_assoc}) THEN
   3.225    unfold_thms_tac ctxt [collect_set_map] THEN
   3.226    unfold_thms_tac ctxt comp_wit_thms THEN
   3.227    REPEAT_DETERM ((atac ORELSE'
   3.228      REPEAT_DETERM o eresolve_tac ctxt @{thms UnionE UnE} THEN'
   3.229 -    etac imageE THEN' TRY o dresolve_tac ctxt Gwit_thms THEN'
   3.230 -    (etac FalseE ORELSE'
   3.231 +    etac ctxt imageE THEN' TRY o dresolve_tac ctxt Gwit_thms THEN'
   3.232 +    (etac ctxt FalseE ORELSE'
   3.233      hyp_subst_tac ctxt THEN'
   3.234      dresolve_tac ctxt Fwit_thms THEN'
   3.235 -    (etac FalseE ORELSE' atac))) 1);
   3.236 +    (etac ctxt FalseE ORELSE' atac))) 1);
   3.237  
   3.238  
   3.239  (* Kill operation *)
   3.240  
   3.241  fun mk_kill_map_cong0_tac ctxt n m map_cong0 =
   3.242 -  (rtac map_cong0 THEN' EVERY' (replicate n (rtac refl)) THEN'
   3.243 +  (rtac ctxt map_cong0 THEN' EVERY' (replicate n (rtac ctxt refl)) THEN'
   3.244      EVERY' (replicate m (Goal.assume_rule_tac ctxt))) 1;
   3.245  
   3.246 -val kill_in_alt_tac =
   3.247 -  ((rtac @{thm Collect_cong} THEN' rtac iffI) 1 THEN
   3.248 -  REPEAT_DETERM (CHANGED (etac conjE 1)) THEN
   3.249 -  REPEAT_DETERM (CHANGED ((etac conjI ORELSE'
   3.250 -    rtac conjI THEN' rtac subset_UNIV) 1)) THEN
   3.251 -  (rtac subset_UNIV ORELSE' atac) 1 THEN
   3.252 -  REPEAT_DETERM (CHANGED (etac conjE 1)) THEN
   3.253 -  REPEAT_DETERM (CHANGED ((etac conjI ORELSE' atac) 1))) ORELSE
   3.254 -  ((rtac @{thm UNIV_eq_I} THEN' rtac CollectI) 1 THEN
   3.255 -    REPEAT_DETERM (TRY (rtac conjI 1) THEN rtac subset_UNIV 1));
   3.256 +fun kill_in_alt_tac ctxt =
   3.257 +  ((rtac ctxt @{thm Collect_cong} THEN' rtac ctxt iffI) 1 THEN
   3.258 +  REPEAT_DETERM (CHANGED (etac ctxt conjE 1)) THEN
   3.259 +  REPEAT_DETERM (CHANGED ((etac ctxt conjI ORELSE'
   3.260 +    rtac ctxt conjI THEN' rtac ctxt subset_UNIV) 1)) THEN
   3.261 +  (rtac ctxt subset_UNIV ORELSE' atac) 1 THEN
   3.262 +  REPEAT_DETERM (CHANGED (etac ctxt conjE 1)) THEN
   3.263 +  REPEAT_DETERM (CHANGED ((etac ctxt conjI ORELSE' atac) 1))) ORELSE
   3.264 +  ((rtac ctxt @{thm UNIV_eq_I} THEN' rtac ctxt CollectI) 1 THEN
   3.265 +    REPEAT_DETERM (TRY (rtac ctxt conjI 1) THEN rtac ctxt subset_UNIV 1));
   3.266  
   3.267  
   3.268  (* Lift operation *)
   3.269  
   3.270 -val empty_natural_tac = rtac @{thm empty_natural} 1;
   3.271 +fun empty_natural_tac ctxt = rtac ctxt @{thm empty_natural} 1;
   3.272  
   3.273 -fun mk_lift_set_bd_tac bd_Card_order = (rtac @{thm Card_order_empty} THEN' rtac bd_Card_order) 1;
   3.274 +fun mk_lift_set_bd_tac ctxt bd_Card_order =
   3.275 +  (rtac ctxt @{thm Card_order_empty} THEN' rtac ctxt bd_Card_order) 1;
   3.276  
   3.277 -val lift_in_alt_tac =
   3.278 -  ((rtac @{thm Collect_cong} THEN' rtac iffI) 1 THEN
   3.279 -  REPEAT_DETERM (CHANGED (etac conjE 1)) THEN
   3.280 -  REPEAT_DETERM (CHANGED ((etac conjI ORELSE' atac) 1)) THEN
   3.281 -  REPEAT_DETERM (CHANGED (etac conjE 1)) THEN
   3.282 -  REPEAT_DETERM (CHANGED ((etac conjI ORELSE'
   3.283 -    rtac conjI THEN' rtac @{thm empty_subsetI}) 1)) THEN
   3.284 -  (rtac @{thm empty_subsetI} ORELSE' atac) 1) ORELSE
   3.285 -  ((rtac sym THEN' rtac @{thm UNIV_eq_I} THEN' rtac CollectI) 1 THEN
   3.286 -    REPEAT_DETERM (TRY (rtac conjI 1) THEN rtac @{thm empty_subsetI} 1));
   3.287 +fun lift_in_alt_tac ctxt =
   3.288 +  ((rtac ctxt @{thm Collect_cong} THEN' rtac ctxt iffI) 1 THEN
   3.289 +  REPEAT_DETERM (CHANGED (etac ctxt conjE 1)) THEN
   3.290 +  REPEAT_DETERM (CHANGED ((etac ctxt conjI ORELSE' atac) 1)) THEN
   3.291 +  REPEAT_DETERM (CHANGED (etac ctxt conjE 1)) THEN
   3.292 +  REPEAT_DETERM (CHANGED ((etac ctxt conjI ORELSE'
   3.293 +    rtac ctxt conjI THEN' rtac ctxt @{thm empty_subsetI}) 1)) THEN
   3.294 +  (rtac ctxt @{thm empty_subsetI} ORELSE' atac) 1) ORELSE
   3.295 +  ((rtac ctxt sym THEN' rtac ctxt @{thm UNIV_eq_I} THEN' rtac ctxt CollectI) 1 THEN
   3.296 +    REPEAT_DETERM (TRY (rtac ctxt conjI 1) THEN rtac ctxt @{thm empty_subsetI} 1));
   3.297  
   3.298  
   3.299  (* Permute operation *)
   3.300  
   3.301 -fun mk_permute_in_alt_tac src dest =
   3.302 -  (rtac @{thm Collect_cong} THEN'
   3.303 -  mk_rotate_eq_tac (rtac refl) trans @{thm conj_assoc} @{thm conj_commute} @{thm conj_cong}
   3.304 +fun mk_permute_in_alt_tac ctxt src dest =
   3.305 +  (rtac ctxt @{thm Collect_cong} THEN'
   3.306 +  mk_rotate_eq_tac ctxt (rtac ctxt refl) trans @{thm conj_assoc} @{thm conj_commute} @{thm conj_cong}
   3.307      dest src) 1;
   3.308  
   3.309  
   3.310  (* Miscellaneous *)
   3.311  
   3.312 -fun mk_le_rel_OO_tac outer_le_rel_OO outer_rel_mono inner_le_rel_OOs =
   3.313 -  EVERY' (map rtac (@{thm order_trans} :: outer_le_rel_OO :: outer_rel_mono :: inner_le_rel_OOs)) 1;
   3.314 +fun mk_le_rel_OO_tac ctxt outer_le_rel_OO outer_rel_mono inner_le_rel_OOs =
   3.315 +  EVERY' (map (rtac ctxt) (@{thm order_trans} :: outer_le_rel_OO :: outer_rel_mono :: inner_le_rel_OOs)) 1;
   3.316  
   3.317 -fun mk_simple_rel_OO_Grp_tac rel_OO_Grp in_alt_thm =
   3.318 -  rtac (trans OF [rel_OO_Grp, in_alt_thm RS @{thm OO_Grp_cong} RS sym]) 1;
   3.319 +fun mk_simple_rel_OO_Grp_tac ctxt rel_OO_Grp in_alt_thm =
   3.320 +  rtac ctxt (trans OF [rel_OO_Grp, in_alt_thm RS @{thm OO_Grp_cong} RS sym]) 1;
   3.321  
   3.322  fun mk_simple_wit_tac wit_thms = ALLGOALS (atac ORELSE' eresolve0_tac (@{thm emptyE} :: wit_thms));
   3.323  
   3.324 @@ -244,7 +245,7 @@
   3.325  
   3.326  fun mk_simplified_set_tac ctxt collect_set_map =
   3.327    unfold_thms_tac ctxt (collect_set_map :: @{thms comp_assoc}) THEN
   3.328 -  unfold_thms_tac ctxt simplified_set_simps THEN rtac refl 1;
   3.329 +  unfold_thms_tac ctxt simplified_set_simps THEN rtac ctxt refl 1;
   3.330  
   3.331  val bd_ordIso_natLeq_tac =
   3.332    HEADGOAL (REPEAT_DETERM o resolve0_tac
     4.1 --- a/src/HOL/Tools/BNF/bnf_def.ML	Thu Jul 16 10:48:20 2015 +0200
     4.2 +++ b/src/HOL/Tools/BNF/bnf_def.ML	Thu Jul 16 12:23:22 2015 +0200
     4.3 @@ -1154,7 +1154,8 @@
     4.4              (*collect {set1 ... setm} o map f1 ... fm = collect {f1` o set1 ... fm` o setm}*)
     4.5              val goal = fold_rev Logic.all hs (mk_Trueprop_eq (collect_map, image_collect));
     4.6            in
     4.7 -            Goal.prove_sorry lthy [] [] goal (K (mk_collect_set_map_tac (#set_map0 axioms)))
     4.8 +            Goal.prove_sorry lthy [] [] goal (fn {context = ctxt, prems = _} => 
     4.9 +              mk_collect_set_map_tac ctxt (#set_map0 axioms))
    4.10              |> Thm.close_derivation
    4.11            end;
    4.12  
    4.13 @@ -1168,7 +1169,8 @@
    4.14                  (Logic.list_implies (prems_mono, HOLogic.mk_Trueprop
    4.15                    (mk_leq (mk_in As bnf_sets_As CA') (mk_in As_copy bnf_sets_As CA'))));
    4.16            in
    4.17 -            Goal.prove_sorry lthy [] [] in_mono_goal (K (mk_in_mono_tac live))
    4.18 +            Goal.prove_sorry lthy [] [] in_mono_goal (fn {context = ctxt, prems = _} =>
    4.19 +              mk_in_mono_tac ctxt live)
    4.20              |> Thm.close_derivation
    4.21            end;
    4.22  
    4.23 @@ -1183,7 +1185,7 @@
    4.24                    mk_Trueprop_eq (mk_in As bnf_sets_As CA', mk_in As_copy bnf_sets_As CA')));
    4.25            in
    4.26              Goal.prove_sorry lthy [] [] in_cong_goal
    4.27 -              (K ((TRY o hyp_subst_tac lthy THEN' rtac refl) 1))
    4.28 +              (fn {context = ctxt, prems = _} => (TRY o hyp_subst_tac ctxt THEN' rtac ctxt refl) 1)
    4.29              |> Thm.close_derivation
    4.30            end;
    4.31  
    4.32 @@ -1217,8 +1219,9 @@
    4.33              val concl = HOLogic.mk_Trueprop (mk_inj (Term.list_comb (bnf_map_AsBs, fs)));
    4.34              val goal = fold_rev Logic.all fs (Logic.list_implies (prems, concl));
    4.35            in
    4.36 -            Goal.prove_sorry lthy [] [] goal (fn _ => mk_inj_map_tac live (Lazy.force map_id)
    4.37 -              (Lazy.force map_comp) (#map_cong0 axioms) (Lazy.force map_cong))
    4.38 +            Goal.prove_sorry lthy [] [] goal (fn {context = ctxt, prems = _} =>
    4.39 +              mk_inj_map_tac ctxt live (Lazy.force map_id) (Lazy.force map_comp) (#map_cong0 axioms)
    4.40 +                (Lazy.force map_cong))
    4.41              |> Thm.close_derivation
    4.42            end;
    4.43  
    4.44 @@ -1295,7 +1298,8 @@
    4.45            in
    4.46              Goal.prove_sorry lthy [] []
    4.47                (fold_rev Logic.all (Rs @ Rs_copy) (Logic.list_implies (mono_prems, mono_concl)))
    4.48 -              (K (mk_rel_mono_tac rel_OO_Grps (Lazy.force in_mono)))
    4.49 +              (fn {context = ctxt, prems = _} =>
    4.50 +                mk_rel_mono_tac ctxt rel_OO_Grps (Lazy.force in_mono))
    4.51              |> Thm.close_derivation
    4.52            end;
    4.53  
    4.54 @@ -1306,7 +1310,7 @@
    4.55            in
    4.56              Goal.prove_sorry lthy [] []
    4.57                (fold_rev Logic.all (Rs @ Rs_copy) (Logic.list_implies (cong_prems, cong_concl)))
    4.58 -              (fn _ => (TRY o hyp_subst_tac lthy THEN' rtac refl) 1)
    4.59 +              (fn {context = ctxt, prems = _} => (TRY o hyp_subst_tac ctxt THEN' rtac ctxt refl) 1)
    4.60              |> Thm.close_derivation
    4.61            end;
    4.62  
    4.63 @@ -1317,7 +1321,8 @@
    4.64            Goal.prove_sorry lthy [] []
    4.65              (mk_Trueprop_eq (Term.list_comb (relAsAs, map HOLogic.eq_const As'),
    4.66                HOLogic.eq_const CA'))
    4.67 -            (K (mk_rel_eq_tac live (Lazy.force rel_Grp) (Lazy.force rel_cong) (#map_id0 axioms)))
    4.68 +            (fn {context = ctxt, prems = _} =>
    4.69 +              mk_rel_eq_tac ctxt live (Lazy.force rel_Grp) (Lazy.force rel_cong) (#map_id0 axioms))
    4.70            |> Thm.close_derivation;
    4.71  
    4.72          val rel_eq = Lazy.lazy mk_rel_eq;
    4.73 @@ -1336,7 +1341,8 @@
    4.74              val goal = fold_rev Logic.all Rs (mk_Trueprop_eq (lhs, rhs));
    4.75            in
    4.76              Goal.prove_sorry lthy [] [] goal
    4.77 -              (K (mk_rel_conversep_tac le_thm (Lazy.force rel_mono)))
    4.78 +              (fn {context = ctxt, prems = _} =>
    4.79 +                mk_rel_conversep_tac ctxt le_thm (Lazy.force rel_mono))
    4.80              |> Thm.close_derivation
    4.81            end;
    4.82  
     5.1 --- a/src/HOL/Tools/BNF/bnf_def_tactics.ML	Thu Jul 16 10:48:20 2015 +0200
     5.2 +++ b/src/HOL/Tools/BNF/bnf_def_tactics.ML	Thu Jul 16 12:23:22 2015 +0200
     5.3 @@ -9,10 +9,10 @@
     5.4  
     5.5  signature BNF_DEF_TACTICS =
     5.6  sig
     5.7 -  val mk_collect_set_map_tac: thm list -> tactic
     5.8 -  val mk_in_mono_tac: int -> tactic
     5.9 +  val mk_collect_set_map_tac: Proof.context -> thm list -> tactic
    5.10 +  val mk_in_mono_tac: Proof.context -> int -> tactic
    5.11    val mk_inj_map_strong_tac: Proof.context -> thm -> thm list -> thm -> tactic
    5.12 -  val mk_inj_map_tac: int -> thm -> thm -> thm -> thm -> tactic
    5.13 +  val mk_inj_map_tac: Proof.context -> int -> thm -> thm -> thm -> thm -> tactic
    5.14    val mk_map_id: thm -> thm
    5.15    val mk_map_ident: Proof.context -> thm -> thm
    5.16    val mk_map_comp: thm -> thm
    5.17 @@ -21,12 +21,12 @@
    5.18    val mk_set_transfer_tac: Proof.context -> thm -> thm list -> tactic
    5.19  
    5.20    val mk_rel_Grp_tac: Proof.context -> thm list -> thm -> thm -> thm -> thm -> thm list -> tactic
    5.21 -  val mk_rel_eq_tac: int -> thm -> thm -> thm -> tactic
    5.22 +  val mk_rel_eq_tac: Proof.context -> int -> thm -> thm -> thm -> tactic
    5.23    val mk_rel_OO_le_tac: Proof.context -> thm list -> thm -> thm -> thm -> thm list -> tactic
    5.24 -  val mk_rel_conversep_tac: thm -> thm -> tactic
    5.25 +  val mk_rel_conversep_tac: Proof.context -> thm -> thm -> tactic
    5.26    val mk_rel_conversep_le_tac: Proof.context -> thm list -> thm -> thm -> thm -> thm list -> tactic
    5.27    val mk_rel_map0_tac: Proof.context -> int -> thm -> thm -> thm -> thm -> tactic
    5.28 -  val mk_rel_mono_tac: thm list -> thm -> tactic
    5.29 +  val mk_rel_mono_tac: Proof.context -> thm list -> thm -> tactic
    5.30    val mk_rel_mono_strong0_tac: Proof.context -> thm -> thm list -> tactic
    5.31    val mk_rel_transfer_tac: Proof.context -> thm -> thm list -> thm -> tactic
    5.32  
    5.33 @@ -52,24 +52,24 @@
    5.34  fun mk_map_ident ctxt = unfold_thms ctxt @{thms id_def};
    5.35  fun mk_map_comp comp = @{thm comp_eq_dest_lhs} OF [mk_sym comp];
    5.36  fun mk_map_cong_tac ctxt cong0 =
    5.37 -  (hyp_subst_tac ctxt THEN' rtac cong0 THEN'
    5.38 -   REPEAT_DETERM o (dtac meta_spec THEN' etac meta_mp THEN' atac)) 1;
    5.39 +  (hyp_subst_tac ctxt THEN' rtac ctxt cong0 THEN'
    5.40 +   REPEAT_DETERM o (dtac ctxt meta_spec THEN' etac ctxt meta_mp THEN' atac)) 1;
    5.41  fun mk_set_map set_map0 = set_map0 RS @{thm comp_eq_dest};
    5.42 -fun mk_in_mono_tac n = if n = 0 then rtac subset_UNIV 1
    5.43 -  else (rtac subsetI THEN'
    5.44 -  rtac CollectI) 1 THEN
    5.45 +fun mk_in_mono_tac ctxt n = if n = 0 then rtac ctxt subset_UNIV 1
    5.46 +  else (rtac ctxt subsetI THEN'
    5.47 +  rtac ctxt CollectI) 1 THEN
    5.48    REPEAT_DETERM (eresolve0_tac [CollectE, conjE] 1) THEN
    5.49    REPEAT_DETERM_N (n - 1)
    5.50 -    ((rtac conjI THEN' etac subset_trans THEN' atac) 1) THEN
    5.51 -  (etac subset_trans THEN' atac) 1;
    5.52 +    ((rtac ctxt conjI THEN' etac ctxt subset_trans THEN' atac) 1) THEN
    5.53 +  (etac ctxt subset_trans THEN' atac) 1;
    5.54  
    5.55 -fun mk_inj_map_tac n map_id map_comp map_cong0 map_cong =
    5.56 +fun mk_inj_map_tac ctxt n map_id map_comp map_cong0 map_cong =
    5.57    let
    5.58      val map_cong' = map_cong OF (asm_rl :: replicate n refl);
    5.59      val map_cong0' = map_cong0 OF (replicate n @{thm the_inv_f_o_f_id});
    5.60    in
    5.61 -    HEADGOAL (rtac @{thm injI} THEN' etac (map_cong' RS box_equals) THEN'
    5.62 -      REPEAT_DETERM_N 2 o (rtac (box_equals OF [map_cong0', map_comp RS sym, map_id]) THEN'
    5.63 +    HEADGOAL (rtac ctxt @{thm injI} THEN' etac ctxt (map_cong' RS box_equals) THEN'
    5.64 +      REPEAT_DETERM_N 2 o (rtac ctxt (box_equals OF [map_cong0', map_comp RS sym, map_id]) THEN'
    5.65          REPEAT_DETERM_N n o atac))
    5.66    end;
    5.67  
    5.68 @@ -78,150 +78,150 @@
    5.69      val rel_eq' = rel_eq RS @{thm predicate2_eqD};
    5.70      val rel_maps' = map (fn thm => thm RS iffD1) rel_maps;
    5.71    in
    5.72 -    HEADGOAL (dtac (rel_eq' RS iffD2) THEN' rtac (rel_eq' RS iffD1)) THEN
    5.73 -    EVERY (map (HEADGOAL o dtac) rel_maps') THEN
    5.74 -    HEADGOAL (etac rel_mono_strong) THEN
    5.75 +    HEADGOAL (dtac ctxt (rel_eq' RS iffD2) THEN' rtac ctxt (rel_eq' RS iffD1)) THEN
    5.76 +    EVERY (map (HEADGOAL o dtac ctxt) rel_maps') THEN
    5.77 +    HEADGOAL (etac ctxt rel_mono_strong) THEN
    5.78      TRYALL (Goal.assume_rule_tac ctxt)
    5.79    end;
    5.80  
    5.81 -fun mk_collect_set_map_tac set_map0s =
    5.82 -  (rtac (@{thm collect_comp} RS trans) THEN' rtac @{thm arg_cong[of _ _ collect]} THEN'
    5.83 +fun mk_collect_set_map_tac ctxt set_map0s =
    5.84 +  (rtac ctxt (@{thm collect_comp} RS trans) THEN' rtac ctxt @{thm arg_cong[of _ _ collect]} THEN'
    5.85    EVERY' (map (fn set_map0 =>
    5.86 -    rtac (mk_trans @{thm image_insert} @{thm arg_cong2[of _ _ _ _ insert]}) THEN'
    5.87 -    rtac set_map0) set_map0s) THEN'
    5.88 -  rtac @{thm image_empty}) 1;
    5.89 +    rtac ctxt (mk_trans @{thm image_insert} @{thm arg_cong2[of _ _ _ _ insert]}) THEN'
    5.90 +    rtac ctxt set_map0) set_map0s) THEN'
    5.91 +  rtac ctxt @{thm image_empty}) 1;
    5.92  
    5.93  fun mk_rel_Grp_tac ctxt rel_OO_Grps map_id0 map_cong0 map_id map_comp set_maps =
    5.94    let
    5.95      val n = length set_maps;
    5.96 -    val rel_OO_Grps_tac = if null rel_OO_Grps then K all_tac else rtac (hd rel_OO_Grps RS trans);
    5.97 +    val rel_OO_Grps_tac = if null rel_OO_Grps then K all_tac else rtac ctxt (hd rel_OO_Grps RS trans);
    5.98    in
    5.99      if null set_maps then
   5.100        unfold_thms_tac ctxt ((map_id0 RS @{thm Grp_UNIV_id}) :: rel_OO_Grps) THEN
   5.101 -      rtac @{thm Grp_UNIV_idI[OF refl]} 1
   5.102 +      rtac ctxt @{thm Grp_UNIV_idI[OF refl]} 1
   5.103      else
   5.104 -      EVERY' [rel_OO_Grps_tac, rtac @{thm antisym}, rtac @{thm predicate2I},
   5.105 +      EVERY' [rel_OO_Grps_tac, rtac ctxt @{thm antisym}, rtac ctxt @{thm predicate2I},
   5.106          REPEAT_DETERM o
   5.107            eresolve_tac ctxt [CollectE, exE, conjE, @{thm GrpE}, @{thm relcomppE}, @{thm conversepE}],
   5.108 -        hyp_subst_tac ctxt, rtac @{thm GrpI}, rtac trans, rtac map_comp, rtac map_cong0,
   5.109 -        REPEAT_DETERM_N n o EVERY' [rtac @{thm Collect_split_Grp_eqD}, etac @{thm set_mp}, atac],
   5.110 -        rtac CollectI,
   5.111 -        CONJ_WRAP' (fn thm => EVERY' [rtac (thm RS ord_eq_le_trans),
   5.112 -          rtac @{thm image_subsetI}, rtac @{thm Collect_split_Grp_inD}, etac @{thm set_mp}, atac])
   5.113 +        hyp_subst_tac ctxt, rtac ctxt @{thm GrpI}, rtac ctxt trans, rtac ctxt map_comp, rtac ctxt map_cong0,
   5.114 +        REPEAT_DETERM_N n o EVERY' [rtac ctxt @{thm Collect_split_Grp_eqD}, etac ctxt @{thm set_mp}, atac],
   5.115 +        rtac ctxt CollectI,
   5.116 +        CONJ_WRAP' (fn thm => EVERY' [rtac ctxt (thm RS ord_eq_le_trans),
   5.117 +          rtac ctxt @{thm image_subsetI}, rtac ctxt @{thm Collect_split_Grp_inD}, etac ctxt @{thm set_mp}, atac])
   5.118          set_maps,
   5.119 -        rtac @{thm predicate2I}, REPEAT_DETERM o eresolve_tac ctxt [@{thm GrpE}, exE, conjE],
   5.120 +        rtac ctxt @{thm predicate2I}, REPEAT_DETERM o eresolve_tac ctxt [@{thm GrpE}, exE, conjE],
   5.121          hyp_subst_tac ctxt,
   5.122 -        rtac @{thm relcomppI}, rtac @{thm conversepI},
   5.123 +        rtac ctxt @{thm relcomppI}, rtac ctxt @{thm conversepI},
   5.124          EVERY' (map2 (fn convol => fn map_id0 =>
   5.125 -          EVERY' [rtac @{thm GrpI},
   5.126 -            rtac (@{thm box_equals} OF [map_cong0, map_comp RS sym, map_id0]),
   5.127 -            REPEAT_DETERM_N n o rtac (convol RS fun_cong),
   5.128 +          EVERY' [rtac ctxt @{thm GrpI},
   5.129 +            rtac ctxt (@{thm box_equals} OF [map_cong0, map_comp RS sym, map_id0]),
   5.130 +            REPEAT_DETERM_N n o rtac ctxt (convol RS fun_cong),
   5.131              REPEAT_DETERM o eresolve_tac ctxt [CollectE, conjE],
   5.132 -            rtac CollectI,
   5.133 +            rtac ctxt CollectI,
   5.134              CONJ_WRAP' (fn thm =>
   5.135 -              EVERY' [rtac ord_eq_le_trans, rtac thm, rtac @{thm image_subsetI},
   5.136 -                rtac @{thm convol_mem_GrpI}, etac set_mp, atac])
   5.137 +              EVERY' [rtac ctxt ord_eq_le_trans, rtac ctxt thm, rtac ctxt @{thm image_subsetI},
   5.138 +                rtac ctxt @{thm convol_mem_GrpI}, etac ctxt set_mp, atac])
   5.139              set_maps])
   5.140            @{thms fst_convol snd_convol} [map_id, refl])] 1
   5.141    end;
   5.142  
   5.143 -fun mk_rel_eq_tac n rel_Grp rel_cong map_id0 =
   5.144 -  (EVERY' (rtac (rel_cong RS trans) :: replicate n (rtac @{thm eq_alt})) THEN'
   5.145 -  rtac (rel_Grp RSN (2, @{thm box_equals[OF _ sym sym[OF eq_alt]]})) THEN'
   5.146 -  (if n = 0 then rtac refl
   5.147 -  else EVERY' [rtac @{thm arg_cong2[of _ _ _ _ "Grp"]},
   5.148 -    rtac @{thm equalityI}, rtac subset_UNIV, rtac subsetI, rtac CollectI,
   5.149 -    CONJ_WRAP' (K (rtac subset_UNIV)) (1 upto n), rtac map_id0])) 1;
   5.150 +fun mk_rel_eq_tac ctxt n rel_Grp rel_cong map_id0 =
   5.151 +  (EVERY' (rtac ctxt (rel_cong RS trans) :: replicate n (rtac ctxt @{thm eq_alt})) THEN'
   5.152 +  rtac ctxt (rel_Grp RSN (2, @{thm box_equals[OF _ sym sym[OF eq_alt]]})) THEN'
   5.153 +  (if n = 0 then rtac ctxt refl
   5.154 +  else EVERY' [rtac ctxt @{thm arg_cong2[of _ _ _ _ "Grp"]},
   5.155 +    rtac ctxt @{thm equalityI}, rtac ctxt subset_UNIV, rtac ctxt subsetI, rtac ctxt CollectI,
   5.156 +    CONJ_WRAP' (K (rtac ctxt subset_UNIV)) (1 upto n), rtac ctxt map_id0])) 1;
   5.157  
   5.158  fun mk_rel_map0_tac ctxt live rel_compp rel_conversep rel_Grp map_id =
   5.159    if live = 0 then
   5.160      HEADGOAL (Goal.conjunction_tac) THEN
   5.161      unfold_thms_tac ctxt @{thms id_apply} THEN
   5.162 -    ALLGOALS (rtac refl)
   5.163 +    ALLGOALS (rtac ctxt refl)
   5.164    else
   5.165      let
   5.166        val ks = 1 upto live;
   5.167      in
   5.168        Goal.conjunction_tac 1 THEN
   5.169        unfold_thms_tac ctxt [rel_compp, rel_conversep, rel_Grp, @{thm vimage2p_Grp}] THEN
   5.170 -      TRYALL (EVERY' [rtac iffI, rtac @{thm relcomppI}, rtac @{thm GrpI},
   5.171 -        resolve_tac ctxt [map_id, refl], rtac CollectI,
   5.172 -        CONJ_WRAP' (K (rtac @{thm subset_UNIV})) ks, rtac @{thm relcomppI}, atac,
   5.173 -        rtac @{thm conversepI}, rtac @{thm GrpI}, resolve_tac ctxt [map_id, refl], rtac CollectI,
   5.174 -        CONJ_WRAP' (K (rtac @{thm subset_UNIV})) ks,
   5.175 +      TRYALL (EVERY' [rtac ctxt iffI, rtac ctxt @{thm relcomppI}, rtac ctxt @{thm GrpI},
   5.176 +        resolve_tac ctxt [map_id, refl], rtac ctxt CollectI,
   5.177 +        CONJ_WRAP' (K (rtac ctxt @{thm subset_UNIV})) ks, rtac ctxt @{thm relcomppI}, atac,
   5.178 +        rtac ctxt @{thm conversepI}, rtac ctxt @{thm GrpI}, resolve_tac ctxt [map_id, refl], rtac ctxt CollectI,
   5.179 +        CONJ_WRAP' (K (rtac ctxt @{thm subset_UNIV})) ks,
   5.180          REPEAT_DETERM o eresolve_tac ctxt @{thms relcomppE conversepE GrpE},
   5.181 -        dtac (trans OF [sym, map_id]), hyp_subst_tac ctxt, atac])
   5.182 +        dtac ctxt (trans OF [sym, map_id]), hyp_subst_tac ctxt, atac])
   5.183      end;
   5.184  
   5.185 -fun mk_rel_mono_tac rel_OO_Grps in_mono =
   5.186 +fun mk_rel_mono_tac ctxt rel_OO_Grps in_mono =
   5.187    let
   5.188      val rel_OO_Grps_tac = if null rel_OO_Grps then K all_tac
   5.189 -      else rtac (hd rel_OO_Grps RS ord_eq_le_trans) THEN'
   5.190 -        rtac (hd rel_OO_Grps RS sym RSN (2, ord_le_eq_trans));
   5.191 +      else rtac ctxt (hd rel_OO_Grps RS ord_eq_le_trans) THEN'
   5.192 +        rtac ctxt (hd rel_OO_Grps RS sym RSN (2, ord_le_eq_trans));
   5.193    in
   5.194 -    EVERY' [rel_OO_Grps_tac, rtac @{thm relcompp_mono}, rtac @{thm iffD2[OF conversep_mono]},
   5.195 -      rtac @{thm Grp_mono}, rtac in_mono, REPEAT_DETERM o etac @{thm Collect_split_mono},
   5.196 -      rtac @{thm Grp_mono}, rtac in_mono, REPEAT_DETERM o etac @{thm Collect_split_mono}] 1
   5.197 +    EVERY' [rel_OO_Grps_tac, rtac ctxt @{thm relcompp_mono}, rtac ctxt @{thm iffD2[OF conversep_mono]},
   5.198 +      rtac ctxt @{thm Grp_mono}, rtac ctxt in_mono, REPEAT_DETERM o etac ctxt @{thm Collect_split_mono},
   5.199 +      rtac ctxt @{thm Grp_mono}, rtac ctxt in_mono, REPEAT_DETERM o etac ctxt @{thm Collect_split_mono}] 1
   5.200    end;
   5.201  
   5.202  fun mk_rel_conversep_le_tac ctxt rel_OO_Grps rel_eq map_cong0 map_comp set_maps =
   5.203    let
   5.204      val n = length set_maps;
   5.205      val rel_OO_Grps_tac = if null rel_OO_Grps then K all_tac
   5.206 -      else rtac (hd rel_OO_Grps RS ord_eq_le_trans) THEN'
   5.207 -        rtac (hd rel_OO_Grps RS sym RS @{thm arg_cong[of _ _ conversep]} RSN (2, ord_le_eq_trans));
   5.208 +      else rtac ctxt (hd rel_OO_Grps RS ord_eq_le_trans) THEN'
   5.209 +        rtac ctxt (hd rel_OO_Grps RS sym RS @{thm arg_cong[of _ _ conversep]} RSN (2, ord_le_eq_trans));
   5.210    in
   5.211 -    if null set_maps then rtac (rel_eq RS @{thm leq_conversepI}) 1
   5.212 +    if null set_maps then rtac ctxt (rel_eq RS @{thm leq_conversepI}) 1
   5.213      else
   5.214 -      EVERY' [rel_OO_Grps_tac, rtac @{thm predicate2I},
   5.215 +      EVERY' [rel_OO_Grps_tac, rtac ctxt @{thm predicate2I},
   5.216          REPEAT_DETERM o
   5.217            eresolve_tac ctxt [CollectE, exE, conjE, @{thm GrpE}, @{thm relcomppE}, @{thm conversepE}],
   5.218 -        hyp_subst_tac ctxt, rtac @{thm conversepI}, rtac @{thm relcomppI}, rtac @{thm conversepI},
   5.219 -        EVERY' (map (fn thm => EVERY' [rtac @{thm GrpI}, rtac sym, rtac trans,
   5.220 -          rtac map_cong0, REPEAT_DETERM_N n o rtac thm,
   5.221 -          rtac (map_comp RS sym), rtac CollectI,
   5.222 -          CONJ_WRAP' (fn thm => EVERY' [rtac (thm RS ord_eq_le_trans),
   5.223 -            etac @{thm flip_pred}]) set_maps]) [@{thm snd_fst_flip}, @{thm fst_snd_flip}])] 1
   5.224 +        hyp_subst_tac ctxt, rtac ctxt @{thm conversepI}, rtac ctxt @{thm relcomppI}, rtac ctxt @{thm conversepI},
   5.225 +        EVERY' (map (fn thm => EVERY' [rtac ctxt @{thm GrpI}, rtac ctxt sym, rtac ctxt trans,
   5.226 +          rtac ctxt map_cong0, REPEAT_DETERM_N n o rtac ctxt thm,
   5.227 +          rtac ctxt (map_comp RS sym), rtac ctxt CollectI,
   5.228 +          CONJ_WRAP' (fn thm => EVERY' [rtac ctxt (thm RS ord_eq_le_trans),
   5.229 +            etac ctxt @{thm flip_pred}]) set_maps]) [@{thm snd_fst_flip}, @{thm fst_snd_flip}])] 1
   5.230    end;
   5.231  
   5.232 -fun mk_rel_conversep_tac le_conversep rel_mono =
   5.233 -  EVERY' [rtac @{thm antisym}, rtac le_conversep, rtac @{thm xt1(6)}, rtac conversep_shift,
   5.234 -    rtac le_conversep, rtac @{thm iffD2[OF conversep_mono]}, rtac rel_mono,
   5.235 -    REPEAT_DETERM o rtac @{thm eq_refl[OF sym[OF conversep_conversep]]}] 1;
   5.236 +fun mk_rel_conversep_tac ctxt le_conversep rel_mono =
   5.237 +  EVERY' [rtac ctxt @{thm antisym}, rtac ctxt le_conversep, rtac ctxt @{thm xt1(6)}, rtac ctxt conversep_shift,
   5.238 +    rtac ctxt le_conversep, rtac ctxt @{thm iffD2[OF conversep_mono]}, rtac ctxt rel_mono,
   5.239 +    REPEAT_DETERM o rtac ctxt @{thm eq_refl[OF sym[OF conversep_conversep]]}] 1;
   5.240  
   5.241  fun mk_rel_OO_le_tac ctxt rel_OO_Grps rel_eq map_cong0 map_comp set_maps =
   5.242    let
   5.243      val n = length set_maps;
   5.244 -    fun in_tac nthO_in = rtac CollectI THEN'
   5.245 -        CONJ_WRAP' (fn thm => EVERY' [rtac (thm RS ord_eq_le_trans),
   5.246 -          rtac @{thm image_subsetI}, rtac nthO_in, etac set_mp, atac]) set_maps;
   5.247 +    fun in_tac nthO_in = rtac ctxt CollectI THEN'
   5.248 +        CONJ_WRAP' (fn thm => EVERY' [rtac ctxt (thm RS ord_eq_le_trans),
   5.249 +          rtac ctxt @{thm image_subsetI}, rtac ctxt nthO_in, etac ctxt set_mp, atac]) set_maps;
   5.250      val rel_OO_Grps_tac = if null rel_OO_Grps then K all_tac
   5.251 -      else rtac (hd rel_OO_Grps RS ord_eq_le_trans) THEN'
   5.252 -        rtac (@{thm arg_cong2[of _ _ _ _ "op OO"]} OF (replicate 2 (hd rel_OO_Grps RS sym)) RSN
   5.253 +      else rtac ctxt (hd rel_OO_Grps RS ord_eq_le_trans) THEN'
   5.254 +        rtac ctxt (@{thm arg_cong2[of _ _ _ _ "op OO"]} OF (replicate 2 (hd rel_OO_Grps RS sym)) RSN
   5.255            (2, ord_le_eq_trans));
   5.256    in
   5.257 -    if null set_maps then rtac (rel_eq RS @{thm leq_OOI}) 1
   5.258 +    if null set_maps then rtac ctxt (rel_eq RS @{thm leq_OOI}) 1
   5.259      else
   5.260 -      EVERY' [rel_OO_Grps_tac, rtac @{thm predicate2I},
   5.261 +      EVERY' [rel_OO_Grps_tac, rtac ctxt @{thm predicate2I},
   5.262          REPEAT_DETERM o
   5.263            eresolve_tac ctxt [CollectE, exE, conjE, @{thm GrpE}, @{thm relcomppE}, @{thm conversepE}],
   5.264          hyp_subst_tac ctxt,
   5.265 -        rtac @{thm relcomppI}, rtac @{thm relcomppI}, rtac @{thm conversepI}, rtac @{thm GrpI},
   5.266 -        rtac trans, rtac map_comp, rtac sym, rtac map_cong0,
   5.267 -        REPEAT_DETERM_N n o rtac @{thm fst_fstOp},
   5.268 +        rtac ctxt @{thm relcomppI}, rtac ctxt @{thm relcomppI}, rtac ctxt @{thm conversepI}, rtac ctxt @{thm GrpI},
   5.269 +        rtac ctxt trans, rtac ctxt map_comp, rtac ctxt sym, rtac ctxt map_cong0,
   5.270 +        REPEAT_DETERM_N n o rtac ctxt @{thm fst_fstOp},
   5.271          in_tac @{thm fstOp_in},
   5.272 -        rtac @{thm GrpI}, rtac trans, rtac map_comp, rtac map_cong0,
   5.273 -        REPEAT_DETERM_N n o EVERY' [rtac trans, rtac o_apply,
   5.274 -          rtac ballE, rtac subst,
   5.275 -          rtac @{thm csquare_def}, rtac @{thm csquare_fstOp_sndOp}, atac, etac notE,
   5.276 -          etac set_mp, atac],
   5.277 +        rtac ctxt @{thm GrpI}, rtac ctxt trans, rtac ctxt map_comp, rtac ctxt map_cong0,
   5.278 +        REPEAT_DETERM_N n o EVERY' [rtac ctxt trans, rtac ctxt o_apply,
   5.279 +          rtac ctxt ballE, rtac ctxt subst,
   5.280 +          rtac ctxt @{thm csquare_def}, rtac ctxt @{thm csquare_fstOp_sndOp}, atac, etac ctxt notE,
   5.281 +          etac ctxt set_mp, atac],
   5.282          in_tac @{thm fstOp_in},
   5.283 -        rtac @{thm relcomppI}, rtac @{thm conversepI}, rtac @{thm GrpI},
   5.284 -        rtac trans, rtac map_comp, rtac map_cong0,
   5.285 -        REPEAT_DETERM_N n o rtac o_apply,
   5.286 +        rtac ctxt @{thm relcomppI}, rtac ctxt @{thm conversepI}, rtac ctxt @{thm GrpI},
   5.287 +        rtac ctxt trans, rtac ctxt map_comp, rtac ctxt map_cong0,
   5.288 +        REPEAT_DETERM_N n o rtac ctxt o_apply,
   5.289          in_tac @{thm sndOp_in},
   5.290 -        rtac @{thm GrpI}, rtac trans, rtac map_comp, rtac sym, rtac map_cong0,
   5.291 -        REPEAT_DETERM_N n o rtac @{thm snd_sndOp},
   5.292 +        rtac ctxt @{thm GrpI}, rtac ctxt trans, rtac ctxt map_comp, rtac ctxt sym, rtac ctxt map_cong0,
   5.293 +        REPEAT_DETERM_N n o rtac ctxt @{thm snd_sndOp},
   5.294          in_tac @{thm sndOp_in}] 1
   5.295    end;
   5.296  
   5.297 @@ -231,51 +231,51 @@
   5.298      unfold_tac ctxt [in_rel] THEN
   5.299      REPEAT_DETERM (eresolve_tac ctxt [exE, CollectE, conjE] 1) THEN
   5.300      hyp_subst_tac ctxt 1 THEN
   5.301 -    EVERY' [rtac exI, rtac @{thm conjI[OF CollectI conjI[OF refl refl]]},
   5.302 +    EVERY' [rtac ctxt exI, rtac ctxt @{thm conjI[OF CollectI conjI[OF refl refl]]},
   5.303        CONJ_WRAP' (fn thm =>
   5.304 -        (etac (@{thm Collect_split_mono_strong} OF [thm, thm]) THEN' atac))
   5.305 +        (etac ctxt (@{thm Collect_split_mono_strong} OF [thm, thm]) THEN' atac))
   5.306        set_maps] 1;
   5.307  
   5.308  fun mk_rel_transfer_tac ctxt in_rel rel_map rel_mono_strong =
   5.309    let
   5.310      fun last_tac iffD =
   5.311 -      HEADGOAL (etac rel_mono_strong) THEN
   5.312 -      REPEAT_DETERM (HEADGOAL (etac (@{thm predicate2_transferD} RS iffD) THEN'
   5.313 +      HEADGOAL (etac ctxt rel_mono_strong) THEN
   5.314 +      REPEAT_DETERM (HEADGOAL (etac ctxt (@{thm predicate2_transferD} RS iffD) THEN'
   5.315          REPEAT_DETERM o atac));
   5.316    in
   5.317 -    REPEAT_DETERM (HEADGOAL (rtac rel_funI)) THEN
   5.318 -    (HEADGOAL (hyp_subst_tac ctxt THEN' rtac refl) ORELSE
   5.319 +    REPEAT_DETERM (HEADGOAL (rtac ctxt rel_funI)) THEN
   5.320 +    (HEADGOAL (hyp_subst_tac ctxt THEN' rtac ctxt refl) ORELSE
   5.321       REPEAT_DETERM (HEADGOAL (eresolve_tac ctxt (Tactic.make_elim (in_rel RS iffD1) ::
   5.322         @{thms exE conjE CollectE}))) THEN
   5.323 -     HEADGOAL (hyp_subst_tac ctxt) THEN unfold_thms_tac ctxt rel_map THEN HEADGOAL (rtac iffI) THEN
   5.324 +     HEADGOAL (hyp_subst_tac ctxt) THEN unfold_thms_tac ctxt rel_map THEN HEADGOAL (rtac ctxt iffI) THEN
   5.325       last_tac iffD1 THEN last_tac iffD2)
   5.326    end;
   5.327  
   5.328  fun mk_map_transfer_tac ctxt rel_mono in_rel set_maps map_cong0 map_comp =
   5.329    let
   5.330      val n = length set_maps;
   5.331 -    val in_tac = if n = 0 then rtac UNIV_I else
   5.332 -      rtac CollectI THEN' CONJ_WRAP' (fn thm =>
   5.333 -        etac (thm RS
   5.334 +    val in_tac = if n = 0 then rtac ctxt UNIV_I else
   5.335 +      rtac ctxt CollectI THEN' CONJ_WRAP' (fn thm =>
   5.336 +        etac ctxt (thm RS
   5.337            @{thm ord_eq_le_trans[OF _ subset_trans[OF image_mono convol_image_vimage2p]]}))
   5.338        set_maps;
   5.339    in
   5.340 -    REPEAT_DETERM_N n (HEADGOAL (rtac rel_funI)) THEN
   5.341 +    REPEAT_DETERM_N n (HEADGOAL (rtac ctxt rel_funI)) THEN
   5.342      unfold_thms_tac ctxt @{thms rel_fun_iff_leq_vimage2p} THEN
   5.343 -    HEADGOAL (EVERY' [rtac @{thm order_trans}, rtac rel_mono, REPEAT_DETERM_N n o atac,
   5.344 -      rtac @{thm predicate2I}, dtac (in_rel RS iffD1),
   5.345 +    HEADGOAL (EVERY' [rtac ctxt @{thm order_trans}, rtac ctxt rel_mono, REPEAT_DETERM_N n o atac,
   5.346 +      rtac ctxt @{thm predicate2I}, dtac ctxt (in_rel RS iffD1),
   5.347        REPEAT_DETERM o eresolve_tac ctxt [exE, CollectE, conjE], hyp_subst_tac ctxt,
   5.348 -      rtac @{thm vimage2pI}, rtac (in_rel RS iffD2), rtac exI, rtac conjI, in_tac,
   5.349 -      rtac conjI,
   5.350 +      rtac ctxt @{thm vimage2pI}, rtac ctxt (in_rel RS iffD2), rtac ctxt exI, rtac ctxt conjI, in_tac,
   5.351 +      rtac ctxt conjI,
   5.352        EVERY' (map (fn convol =>
   5.353 -        rtac (@{thm box_equals} OF [map_cong0, map_comp RS sym, map_comp RS sym]) THEN'
   5.354 -        REPEAT_DETERM_N n o rtac (convol RS fun_cong)) @{thms fst_convol snd_convol})])
   5.355 +        rtac ctxt (@{thm box_equals} OF [map_cong0, map_comp RS sym, map_comp RS sym]) THEN'
   5.356 +        REPEAT_DETERM_N n o rtac ctxt (convol RS fun_cong)) @{thms fst_convol snd_convol})])
   5.357    end;
   5.358  
   5.359  fun mk_in_bd_tac ctxt live surj_imp_ordLeq_inst map_comp map_id map_cong0 set_maps set_bds
   5.360    bd_card_order bd_Card_order bd_Cinfinite bd_Cnotzero =
   5.361    if live = 0 then
   5.362 -    rtac @{thm ordLeq_transitive[OF ordLeq_csum2[OF card_of_Card_order]
   5.363 +    rtac ctxt @{thm ordLeq_transitive[OF ordLeq_csum2[OF card_of_Card_order]
   5.364        ordLeq_cexp2[OF ordLeq_refl[OF Card_order_ctwo] Card_order_csum]]} 1
   5.365    else
   5.366      let
   5.367 @@ -286,67 +286,67 @@
   5.368              [set_bd, bd_Card_order RS @{thm card_of_Field_ordIso} RS @{thm ordIso_symmetric}]])
   5.369          set_bds;
   5.370      in
   5.371 -      EVERY' [rtac (Drule.rotate_prems 1 ctrans), rtac @{thm cprod_cinfinite_bound},
   5.372 -        rtac (ctrans OF @{thms ordLeq_csum2 ordLeq_cexp2}), rtac @{thm card_of_Card_order},
   5.373 -        rtac @{thm ordLeq_csum2}, rtac @{thm Card_order_ctwo}, rtac @{thm Card_order_csum},
   5.374 -        rtac @{thm ordIso_ordLeq_trans}, rtac @{thm cexp_cong1},
   5.375 -        if live = 1 then rtac @{thm ordIso_refl[OF Card_order_csum]}
   5.376 +      EVERY' [rtac ctxt (Drule.rotate_prems 1 ctrans), rtac ctxt @{thm cprod_cinfinite_bound},
   5.377 +        rtac ctxt (ctrans OF @{thms ordLeq_csum2 ordLeq_cexp2}), rtac ctxt @{thm card_of_Card_order},
   5.378 +        rtac ctxt @{thm ordLeq_csum2}, rtac ctxt @{thm Card_order_ctwo}, rtac ctxt @{thm Card_order_csum},
   5.379 +        rtac ctxt @{thm ordIso_ordLeq_trans}, rtac ctxt @{thm cexp_cong1},
   5.380 +        if live = 1 then rtac ctxt @{thm ordIso_refl[OF Card_order_csum]}
   5.381          else
   5.382 -          REPEAT_DETERM_N (live - 2) o rtac @{thm ordIso_transitive[OF csum_cong2]} THEN'
   5.383 -          REPEAT_DETERM_N (live - 1) o rtac @{thm csum_csum},
   5.384 -        rtac bd_Card_order, rtac (@{thm cexp_mono2_Cnotzero} RS ctrans), rtac @{thm ordLeq_csum1},
   5.385 -        rtac bd_Card_order, rtac @{thm Card_order_csum}, rtac bd_Cnotzero,
   5.386 -        rtac @{thm csum_Cfinite_cexp_Cinfinite},
   5.387 -        rtac (if live = 1 then @{thm card_of_Card_order} else @{thm Card_order_csum}),
   5.388 -        CONJ_WRAP_GEN' (rtac @{thm Cfinite_csum}) (K (rtac @{thm Cfinite_cone})) set_maps,
   5.389 -        rtac bd'_Cinfinite, rtac @{thm card_of_Card_order},
   5.390 -        rtac @{thm Card_order_cexp}, rtac @{thm Cinfinite_cexp}, rtac @{thm ordLeq_csum2},
   5.391 -        rtac @{thm Card_order_ctwo}, rtac bd'_Cinfinite,
   5.392 -        rtac (Drule.rotate_prems 1 (@{thm cprod_mono2} RSN (2, ctrans))),
   5.393 +          REPEAT_DETERM_N (live - 2) o rtac ctxt @{thm ordIso_transitive[OF csum_cong2]} THEN'
   5.394 +          REPEAT_DETERM_N (live - 1) o rtac ctxt @{thm csum_csum},
   5.395 +        rtac ctxt bd_Card_order, rtac ctxt (@{thm cexp_mono2_Cnotzero} RS ctrans), rtac ctxt @{thm ordLeq_csum1},
   5.396 +        rtac ctxt bd_Card_order, rtac ctxt @{thm Card_order_csum}, rtac ctxt bd_Cnotzero,
   5.397 +        rtac ctxt @{thm csum_Cfinite_cexp_Cinfinite},
   5.398 +        rtac ctxt (if live = 1 then @{thm card_of_Card_order} else @{thm Card_order_csum}),
   5.399 +        CONJ_WRAP_GEN' (rtac ctxt @{thm Cfinite_csum}) (K (rtac ctxt @{thm Cfinite_cone})) set_maps,
   5.400 +        rtac ctxt bd'_Cinfinite, rtac ctxt @{thm card_of_Card_order},
   5.401 +        rtac ctxt @{thm Card_order_cexp}, rtac ctxt @{thm Cinfinite_cexp}, rtac ctxt @{thm ordLeq_csum2},
   5.402 +        rtac ctxt @{thm Card_order_ctwo}, rtac ctxt bd'_Cinfinite,
   5.403 +        rtac ctxt (Drule.rotate_prems 1 (@{thm cprod_mono2} RSN (2, ctrans))),
   5.404          REPEAT_DETERM_N (live - 1) o
   5.405 -          (rtac (bd_Cinfinite RS @{thm cprod_cexp_csum_cexp_Cinfinite} RSN (2, ctrans)) THEN'
   5.406 -           rtac @{thm ordLeq_ordIso_trans[OF cprod_mono2 ordIso_symmetric[OF cprod_cexp]]}),
   5.407 -        rtac @{thm ordLeq_refl[OF Card_order_cexp]}] 1 THEN
   5.408 +          (rtac ctxt (bd_Cinfinite RS @{thm cprod_cexp_csum_cexp_Cinfinite} RSN (2, ctrans)) THEN'
   5.409 +           rtac ctxt @{thm ordLeq_ordIso_trans[OF cprod_mono2 ordIso_symmetric[OF cprod_cexp]]}),
   5.410 +        rtac ctxt @{thm ordLeq_refl[OF Card_order_cexp]}] 1 THEN
   5.411        unfold_thms_tac ctxt [bd_card_order RS @{thm card_order_csum_cone_cexp_def}] THEN
   5.412        unfold_thms_tac ctxt @{thms cprod_def Field_card_of} THEN
   5.413 -      EVERY' [rtac (Drule.rotate_prems 1 ctrans), rtac surj_imp_ordLeq_inst, rtac subsetI,
   5.414 -        Method.insert_tac inserts, REPEAT_DETERM o dtac meta_spec,
   5.415 -        REPEAT_DETERM o eresolve_tac ctxt [exE, Tactic.make_elim conjunct1], etac CollectE,
   5.416 +      EVERY' [rtac ctxt (Drule.rotate_prems 1 ctrans), rtac ctxt surj_imp_ordLeq_inst, rtac ctxt subsetI,
   5.417 +        Method.insert_tac inserts, REPEAT_DETERM o dtac ctxt meta_spec,
   5.418 +        REPEAT_DETERM o eresolve_tac ctxt [exE, Tactic.make_elim conjunct1], etac ctxt CollectE,
   5.419          if live = 1 then K all_tac
   5.420 -        else REPEAT_DETERM_N (live - 2) o (etac conjE THEN' rotate_tac ~1) THEN' etac conjE,
   5.421 -        rtac (Drule.rotate_prems 1 @{thm image_eqI}), rtac @{thm SigmaI}, rtac @{thm UNIV_I},
   5.422 -        CONJ_WRAP_GEN' (rtac @{thm SigmaI})
   5.423 -          (K (etac @{thm If_the_inv_into_in_Func} THEN' atac)) set_maps,
   5.424 -        rtac sym,
   5.425 -        rtac (Drule.rotate_prems 1
   5.426 +        else REPEAT_DETERM_N (live - 2) o (etac ctxt conjE THEN' rotate_tac ~1) THEN' etac ctxt conjE,
   5.427 +        rtac ctxt (Drule.rotate_prems 1 @{thm image_eqI}), rtac ctxt @{thm SigmaI}, rtac ctxt @{thm UNIV_I},
   5.428 +        CONJ_WRAP_GEN' (rtac ctxt @{thm SigmaI})
   5.429 +          (K (etac ctxt @{thm If_the_inv_into_in_Func} THEN' atac)) set_maps,
   5.430 +        rtac ctxt sym,
   5.431 +        rtac ctxt (Drule.rotate_prems 1
   5.432             ((@{thm box_equals} OF [map_cong0 OF replicate live @{thm If_the_inv_into_f_f},
   5.433               map_comp RS sym, map_id]) RSN (2, trans))),
   5.434          REPEAT_DETERM_N (2 * live) o atac,
   5.435 -        REPEAT_DETERM_N live o rtac (@{thm prod.case} RS trans),
   5.436 -        rtac refl,
   5.437 -        rtac @{thm surj_imp_ordLeq}, rtac subsetI, rtac (Drule.rotate_prems 1 @{thm image_eqI}),
   5.438 -        REPEAT_DETERM o eresolve_tac ctxt [CollectE, conjE], rtac CollectI,
   5.439 +        REPEAT_DETERM_N live o rtac ctxt (@{thm prod.case} RS trans),
   5.440 +        rtac ctxt refl,
   5.441 +        rtac ctxt @{thm surj_imp_ordLeq}, rtac ctxt subsetI, rtac ctxt (Drule.rotate_prems 1 @{thm image_eqI}),
   5.442 +        REPEAT_DETERM o eresolve_tac ctxt [CollectE, conjE], rtac ctxt CollectI,
   5.443          CONJ_WRAP' (fn thm =>
   5.444 -          rtac (thm RS ord_eq_le_trans) THEN' etac @{thm subset_trans[OF image_mono Un_upper1]})
   5.445 +          rtac ctxt (thm RS ord_eq_le_trans) THEN' etac ctxt @{thm subset_trans[OF image_mono Un_upper1]})
   5.446          set_maps,
   5.447 -        rtac sym,
   5.448 -        rtac (@{thm box_equals} OF [map_cong0 OF replicate live @{thm fun_cong[OF case_sum_o_inj(1)]},
   5.449 +        rtac ctxt sym,
   5.450 +        rtac ctxt (@{thm box_equals} OF [map_cong0 OF replicate live @{thm fun_cong[OF case_sum_o_inj(1)]},
   5.451             map_comp RS sym, map_id])] 1
   5.452    end;
   5.453  
   5.454  fun mk_trivial_wit_tac ctxt wit_defs set_maps =
   5.455    unfold_thms_tac ctxt wit_defs THEN HEADGOAL (EVERY' (map (fn thm =>
   5.456 -    dtac (thm RS equalityD1 RS set_mp) THEN' etac imageE THEN' atac) set_maps)) THEN ALLGOALS atac;
   5.457 +    dtac ctxt (thm RS equalityD1 RS set_mp) THEN' etac ctxt imageE THEN' atac) set_maps)) THEN ALLGOALS atac;
   5.458  
   5.459  fun mk_set_transfer_tac ctxt in_rel set_maps =
   5.460    Goal.conjunction_tac 1 THEN
   5.461 -  EVERY (map (fn set_map => HEADGOAL (rtac rel_funI) THEN
   5.462 +  EVERY (map (fn set_map => HEADGOAL (rtac ctxt rel_funI) THEN
   5.463    REPEAT_DETERM (HEADGOAL (eresolve_tac ctxt (Tactic.make_elim (in_rel RS iffD1) ::
   5.464      @{thms exE conjE CollectE}))) THEN
   5.465 -  HEADGOAL (hyp_subst_tac ctxt THEN' rtac (@{thm iffD2[OF arg_cong2]} OF [set_map, set_map]) THEN'
   5.466 -    rtac @{thm rel_setI}) THEN
   5.467 -  REPEAT (HEADGOAL (etac imageE THEN' dtac @{thm set_mp} THEN' atac THEN'
   5.468 +  HEADGOAL (hyp_subst_tac ctxt THEN' rtac ctxt (@{thm iffD2[OF arg_cong2]} OF [set_map, set_map]) THEN'
   5.469 +    rtac ctxt @{thm rel_setI}) THEN
   5.470 +  REPEAT (HEADGOAL (etac ctxt imageE THEN' dtac ctxt @{thm set_mp} THEN' atac THEN'
   5.471      REPEAT_DETERM o (eresolve_tac ctxt @{thms CollectE case_prodE}) THEN' hyp_subst_tac ctxt THEN'
   5.472 -    rtac bexI THEN' etac @{thm subst_Pair[OF _ refl]} THEN' etac imageI))) set_maps);
   5.473 +    rtac ctxt bexI THEN' etac ctxt @{thm subst_Pair[OF _ refl]} THEN' etac ctxt imageI))) set_maps);
   5.474  
   5.475  end;
     6.1 --- a/src/HOL/Tools/BNF/bnf_fp_def_sugar.ML	Thu Jul 16 10:48:20 2015 +0200
     6.2 +++ b/src/HOL/Tools/BNF/bnf_fp_def_sugar.ML	Thu Jul 16 12:23:22 2015 +0200
     6.3 @@ -896,8 +896,8 @@
     6.4              []
     6.5            else
     6.6              Goal.prove_sorry lthy [] [] (Logic.mk_conjunction_balanced goals)
     6.7 -              (K (mk_disc_transfer_tac (the_single rel_sel_thms) (the_single exhaust_discs)
     6.8 -                 (flat (flat distinct_discsss))))
     6.9 +              (fn {context = ctxt, prems = _} => mk_disc_transfer_tac ctxt (the_single rel_sel_thms)
    6.10 +                 (the_single exhaust_discs) (flat (flat distinct_discsss)))
    6.11              |> Conjunction.elim_balanced (length goals)
    6.12              |> Proof_Context.export names_lthy lthy
    6.13              |> map Thm.close_derivation
     7.1 --- a/src/HOL/Tools/BNF/bnf_fp_def_sugar_tactics.ML	Thu Jul 16 10:48:20 2015 +0200
     7.2 +++ b/src/HOL/Tools/BNF/bnf_fp_def_sugar_tactics.ML	Thu Jul 16 12:23:22 2015 +0200
     7.3 @@ -27,7 +27,7 @@
     7.4    val mk_ctor_iff_dtor_tac: Proof.context -> ctyp option list -> cterm -> cterm -> thm -> thm ->
     7.5      tactic
     7.6    val mk_ctr_transfer_tac: Proof.context -> thm list -> thm list -> tactic
     7.7 -  val mk_disc_transfer_tac: thm -> thm -> thm list -> tactic
     7.8 +  val mk_disc_transfer_tac: Proof.context -> thm -> thm -> thm list -> tactic
     7.9    val mk_exhaust_tac: Proof.context -> int -> thm list -> thm -> thm -> tactic
    7.10    val mk_half_distinct_tac: Proof.context -> thm -> thm -> thm list -> tactic
    7.11    val mk_induct_tac: Proof.context -> int -> int list -> int list list -> int list list list ->
    7.12 @@ -107,55 +107,55 @@
    7.13  
    7.14  fun mk_case_transfer_tac ctxt rel_cases cases =
    7.15    let val n = length (tl (Thm.prems_of rel_cases)) in
    7.16 -    REPEAT_DETERM (HEADGOAL (rtac rel_funI)) THEN
    7.17 -    HEADGOAL (etac rel_cases) THEN
    7.18 +    REPEAT_DETERM (HEADGOAL (rtac ctxt rel_funI)) THEN
    7.19 +    HEADGOAL (etac ctxt rel_cases) THEN
    7.20      ALLGOALS (hyp_subst_tac ctxt) THEN
    7.21      unfold_thms_tac ctxt cases THEN
    7.22 -    ALLGOALS (fn k => (select_prem_tac n (dtac asm_rl) k) k) THEN
    7.23 -    ALLGOALS (REPEAT_DETERM o (rotate_tac ~1 THEN' dtac rel_funD THEN'
    7.24 -      (atac THEN' etac thin_rl ORELSE' rtac refl)) THEN' atac)
    7.25 +    ALLGOALS (fn k => (select_prem_tac ctxt n (dtac ctxt asm_rl) k) k) THEN
    7.26 +    ALLGOALS (REPEAT_DETERM o (rotate_tac ~1 THEN' dtac ctxt rel_funD THEN'
    7.27 +      (atac THEN' etac ctxt thin_rl ORELSE' rtac ctxt refl)) THEN' atac)
    7.28    end;
    7.29  
    7.30  fun mk_ctr_transfer_tac ctxt rel_intros rel_eqs =
    7.31    HEADGOAL Goal.conjunction_tac THEN
    7.32    ALLGOALS (REPEAT o (resolve_tac ctxt (rel_funI :: rel_intros) THEN'
    7.33      TRY o (REPEAT_DETERM1 o (atac ORELSE'
    7.34 -      K (unfold_thms_tac ctxt rel_eqs) THEN' hyp_subst_tac ctxt THEN' rtac refl))));
    7.35 +      K (unfold_thms_tac ctxt rel_eqs) THEN' hyp_subst_tac ctxt THEN' rtac ctxt refl))));
    7.36  
    7.37 -fun mk_disc_transfer_tac rel_sel exhaust_disc distinct_disc =
    7.38 +fun mk_disc_transfer_tac ctxt rel_sel exhaust_disc distinct_disc =
    7.39    let
    7.40      fun last_disc_tac iffD =
    7.41 -      HEADGOAL (rtac (rotate_prems ~1 exhaust_disc) THEN' atac THEN'
    7.42 -      REPEAT_DETERM o (rotate_tac ~1 THEN' dtac (rotate_prems 1 iffD) THEN' atac THEN'
    7.43 -        rotate_tac ~1 THEN' etac (rotate_prems 1 notE) THEN' eresolve0_tac distinct_disc));
    7.44 +      HEADGOAL (rtac ctxt (rotate_prems ~1 exhaust_disc) THEN' atac THEN'
    7.45 +      REPEAT_DETERM o (rotate_tac ~1 THEN' dtac ctxt (rotate_prems 1 iffD) THEN' atac THEN'
    7.46 +        rotate_tac ~1 THEN' etac ctxt (rotate_prems 1 notE) THEN' eresolve0_tac distinct_disc));
    7.47    in
    7.48      HEADGOAL Goal.conjunction_tac THEN
    7.49 -    REPEAT_DETERM (HEADGOAL (rtac rel_funI THEN' dtac (rel_sel RS iffD1) THEN'
    7.50 -      REPEAT_DETERM o (etac conjE) THEN' (atac ORELSE' rtac iffI))) THEN
    7.51 +    REPEAT_DETERM (HEADGOAL (rtac ctxt rel_funI THEN' dtac ctxt (rel_sel RS iffD1) THEN'
    7.52 +      REPEAT_DETERM o (etac ctxt conjE) THEN' (atac ORELSE' rtac ctxt iffI))) THEN
    7.53      TRY (last_disc_tac iffD2) THEN TRY (last_disc_tac iffD1)
    7.54    end;
    7.55  
    7.56  fun mk_exhaust_tac ctxt n ctr_defs ctor_iff_dtor sumEN' =
    7.57 -  unfold_thms_tac ctxt (ctor_iff_dtor :: ctr_defs) THEN HEADGOAL (rtac sumEN') THEN
    7.58 -  HEADGOAL (EVERY' (maps (fn k => [select_prem_tac n (rotate_tac 1) k,
    7.59 -    REPEAT_DETERM o dtac meta_spec, etac meta_mp, atac]) (1 upto n)));
    7.60 +  unfold_thms_tac ctxt (ctor_iff_dtor :: ctr_defs) THEN HEADGOAL (rtac ctxt sumEN') THEN
    7.61 +  HEADGOAL (EVERY' (maps (fn k => [select_prem_tac ctxt n (rotate_tac 1) k,
    7.62 +    REPEAT_DETERM o dtac ctxt meta_spec, etac ctxt meta_mp, atac]) (1 upto n)));
    7.63  
    7.64  fun mk_ctor_iff_dtor_tac ctxt cTs cctor cdtor ctor_dtor dtor_ctor =
    7.65 -  HEADGOAL (rtac iffI THEN'
    7.66 +  HEADGOAL (rtac ctxt iffI THEN'
    7.67      EVERY' (@{map 3} (fn cTs => fn cx => fn th =>
    7.68 -      dtac (Drule.instantiate' cTs [NONE, NONE, SOME cx] arg_cong) THEN'
    7.69 +      dtac ctxt (Drule.instantiate' cTs [NONE, NONE, SOME cx] arg_cong) THEN'
    7.70        SELECT_GOAL (unfold_thms_tac ctxt [th]) THEN'
    7.71        atac) [rev cTs, cTs] [cdtor, cctor] [dtor_ctor, ctor_dtor]));
    7.72  
    7.73  fun mk_half_distinct_tac ctxt ctor_inject abs_inject ctr_defs =
    7.74    unfold_thms_tac ctxt (ctor_inject :: abs_inject :: @{thms sum.inject} @ ctr_defs) THEN
    7.75 -  HEADGOAL (rtac @{thm sum.distinct(1)});
    7.76 +  HEADGOAL (rtac ctxt @{thm sum.distinct(1)});
    7.77  
    7.78  fun mk_inject_tac ctxt ctr_def ctor_inject abs_inject =
    7.79    unfold_thms_tac ctxt [ctr_def] THEN
    7.80 -  HEADGOAL (rtac (ctor_inject RS ssubst)) THEN
    7.81 +  HEADGOAL (rtac ctxt (ctor_inject RS ssubst)) THEN
    7.82    unfold_thms_tac ctxt (abs_inject :: @{thms sum.inject prod.inject conj_assoc}) THEN
    7.83 -  HEADGOAL (rtac refl);
    7.84 +  HEADGOAL (rtac ctxt refl);
    7.85  
    7.86  val rec_unfold_thms =
    7.87    @{thms comp_def convol_def fst_conv id_def case_prod_Pair_iden snd_conv split_conv
    7.88 @@ -168,7 +168,7 @@
    7.89        if_distrib[THEN sym]};
    7.90    in
    7.91      HEADGOAL (subst_tac ctxt (SOME [1, 2]) [co_rec_def] THEN'
    7.92 -      rtac (xtor_co_rec_o_map RS trans) THEN'
    7.93 +      rtac ctxt (xtor_co_rec_o_map RS trans) THEN'
    7.94        CONVERSION Thm.eta_long_conversion THEN'
    7.95        asm_simp_tac (ss_only (pre_map_defs @ distinct Thm.eq_thm_prop (map_ident0s @ abs_inverses) @
    7.96          rec_o_map_simps) ctxt))
    7.97 @@ -178,7 +178,7 @@
    7.98    HEADGOAL ((if is_def_looping ctr_def then subst_tac ctxt NONE
    7.99      else SELECT_GOAL o unfold_thms_tac ctxt) [ctr_def]) THEN
   7.100    unfold_thms_tac ctxt (ctor_rec :: fp_abs_inverse :: abs_inverse :: rec_defs @
   7.101 -    pre_map_defs @ map_ident0s @ rec_unfold_thms) THEN HEADGOAL (rtac refl);
   7.102 +    pre_map_defs @ map_ident0s @ rec_unfold_thms) THEN HEADGOAL (rtac ctxt refl);
   7.103  
   7.104  fun mk_rec_transfer_tac ctxt nn ns actives passives xssss rec_defs ctor_rec_transfers rel_pre_T_defs
   7.105      rel_eqs =
   7.106 @@ -190,19 +190,19 @@
   7.107    in
   7.108      HEADGOAL Goal.conjunction_tac THEN
   7.109      EVERY (map (fn ctor_rec_transfer =>
   7.110 -        REPEAT_DETERM (HEADGOAL (rtac rel_funI)) THEN
   7.111 +        REPEAT_DETERM (HEADGOAL (rtac ctxt rel_funI)) THEN
   7.112          unfold_thms_tac ctxt rec_defs THEN
   7.113 -        HEADGOAL (etac (mk_rel_funDN_rotated (nn + 1) ctor_rec_transfer)) THEN
   7.114 +        HEADGOAL (etac ctxt (mk_rel_funDN_rotated (nn + 1) ctor_rec_transfer)) THEN
   7.115          unfold_thms_tac ctxt rel_pre_T_defs THEN
   7.116          EVERY (fst (@{fold_map 2} (fn k => fn xsss => fn acc =>
   7.117              rpair (k + acc)
   7.118 -            (HEADGOAL (rtac (mk_rel_funDN_rotated 2 @{thm comp_transfer})) THEN
   7.119 -             HEADGOAL (rtac @{thm vimage2p_rel_fun}) THEN
   7.120 +            (HEADGOAL (rtac ctxt (mk_rel_funDN_rotated 2 @{thm comp_transfer})) THEN
   7.121 +             HEADGOAL (rtac ctxt @{thm vimage2p_rel_fun}) THEN
   7.122               unfold_thms_tac ctxt rel_eqs THEN
   7.123               EVERY (@{map 2} (fn n => fn xss =>
   7.124                   REPEAT_DETERM (HEADGOAL (resolve_tac ctxt
   7.125                     [mk_rel_funDN 2 case_sum_transfer_eq, mk_rel_funDN 2 case_sum_transfer])) THEN
   7.126 -                 HEADGOAL (select_prem_tac total_n (dtac asm_rl) (acc + n)) THEN
   7.127 +                 HEADGOAL (select_prem_tac ctxt total_n (dtac ctxt asm_rl) (acc + n)) THEN
   7.128                   HEADGOAL (SELECT_GOAL (HEADGOAL
   7.129                     (REPEAT_DETERM o (atac ORELSE' resolve_tac ctxt
   7.130                         [mk_rel_funDN 1 case_prod_transfer_eq,
   7.131 @@ -212,7 +212,7 @@
   7.132                         let val thm = prems
   7.133                           |> permute_like (op =) (True :: flat xss) (True :: flat_rec_arg_args xss)
   7.134                           |> Library.foldl1 (fn (acc, elem) => elem RS (acc RS rel_funD))
   7.135 -                       in HEADGOAL (rtac thm) end) ctxt)))))
   7.136 +                       in HEADGOAL (rtac ctxt thm) end) ctxt)))))
   7.137                 (1 upto k) xsss)))
   7.138            ns xssss 0)))
   7.139        ctor_rec_transfers')
   7.140 @@ -226,16 +226,16 @@
   7.141        @{thms o_apply vimage2p_def if_True if_False}) ctxt;
   7.142    in
   7.143      unfold_thms_tac ctxt (ctr_def :: corec_defs) THEN
   7.144 -    HEADGOAL (rtac (ctor_dtor_corec RS trans) THEN' asm_simp_tac ss) THEN_MAYBE
   7.145 -    HEADGOAL (rtac refl ORELSE' rtac (@{thm unit_eq} RS arg_cong))
   7.146 +    HEADGOAL (rtac ctxt (ctor_dtor_corec RS trans) THEN' asm_simp_tac ss) THEN_MAYBE
   7.147 +    HEADGOAL (rtac ctxt refl ORELSE' rtac ctxt (@{thm unit_eq} RS arg_cong))
   7.148    end;
   7.149  
   7.150  fun mk_corec_disc_iff_tac case_splits' corecs discs ctxt =
   7.151    EVERY (@{map 3} (fn case_split_tac => fn corec_thm => fn disc =>
   7.152        HEADGOAL case_split_tac THEN unfold_thms_tac ctxt [corec_thm] THEN
   7.153        HEADGOAL (asm_simp_tac (ss_only basic_simp_thms ctxt)) THEN
   7.154 -      (if is_refl disc then all_tac else HEADGOAL (rtac disc)))
   7.155 -    (map rtac case_splits' @ [K all_tac]) corecs discs);
   7.156 +      (if is_refl disc then all_tac else HEADGOAL (rtac ctxt disc)))
   7.157 +    (map (rtac ctxt) case_splits' @ [K all_tac]) corecs discs);
   7.158  
   7.159  fun mk_corec_transfer_tac ctxt actives passives type_definitions corec_defs dtor_corec_transfers
   7.160      rel_pre_T_defs rel_eqs pgs pss qssss gssss =
   7.161 @@ -253,24 +253,24 @@
   7.162  
   7.163      fun mk_unfold_If_tac total pos =
   7.164        HEADGOAL (Inl_Inr_Pair_tac THEN'
   7.165 -        rtac (mk_rel_funDN 3 @{thm If_transfer}) THEN'
   7.166 -        select_prem_tac total (dtac asm_rl) pos THEN'
   7.167 -        dtac rel_funD THEN' atac THEN' atac);
   7.168 +        rtac ctxt (mk_rel_funDN 3 @{thm If_transfer}) THEN'
   7.169 +        select_prem_tac ctxt total (dtac ctxt asm_rl) pos THEN'
   7.170 +        dtac ctxt rel_funD THEN' atac THEN' atac);
   7.171  
   7.172      fun mk_unfold_Inl_Inr_Pair_tac total pos =
   7.173        HEADGOAL (Inl_Inr_Pair_tac THEN'
   7.174 -        select_prem_tac total (dtac asm_rl) pos THEN'
   7.175 -        dtac rel_funD THEN' atac THEN' atac);
   7.176 +        select_prem_tac ctxt total (dtac ctxt asm_rl) pos THEN'
   7.177 +        dtac ctxt rel_funD THEN' atac THEN' atac);
   7.178  
   7.179      fun mk_unfold_arg_tac qs gs =
   7.180        EVERY (map (mk_unfold_If_tac num_pgs o prem_no_of) qs) THEN
   7.181        EVERY (map (mk_unfold_Inl_Inr_Pair_tac num_pgs o prem_no_of) gs);
   7.182  
   7.183      fun mk_unfold_ctr_tac type_definition qss gss =
   7.184 -      HEADGOAL (rtac (mk_rel_funDN 1 (@{thm Abs_transfer} OF
   7.185 +      HEADGOAL (rtac ctxt (mk_rel_funDN 1 (@{thm Abs_transfer} OF
   7.186          [type_definition, type_definition])) THEN' Inl_Inr_Pair_tac) THEN
   7.187        (case (qss, gss) of
   7.188 -        ([], []) => HEADGOAL (rtac refl)
   7.189 +        ([], []) => HEADGOAL (rtac ctxt refl)
   7.190        | _ => EVERY (map2 mk_unfold_arg_tac qss gss));
   7.191  
   7.192      fun mk_unfold_type_tac type_definition ps qsss gsss =
   7.193 @@ -281,7 +281,7 @@
   7.194            | mk_unfold_ty (p_tac :: p_tacs) (qg_tac :: qg_tacs) =
   7.195              p_tac THEN qg_tac THEN mk_unfold_ty p_tacs qg_tacs
   7.196        in
   7.197 -        HEADGOAL (rtac rel_funI) THEN mk_unfold_ty p_tacs qg_tacs
   7.198 +        HEADGOAL (rtac ctxt rel_funI) THEN mk_unfold_ty p_tacs qg_tacs
   7.199        end;
   7.200  
   7.201      fun mk_unfold_corec_type_tac dtor_corec_transfer corec_def =
   7.202 @@ -290,9 +290,9 @@
   7.203          val dtor_corec_transfer' = cterm_instantiate_pos
   7.204            (SOME active :: map SOME passives @ map SOME actives') dtor_corec_transfer;
   7.205        in
   7.206 -        HEADGOAL Goal.conjunction_tac THEN REPEAT_DETERM (HEADGOAL (rtac rel_funI)) THEN
   7.207 +        HEADGOAL Goal.conjunction_tac THEN REPEAT_DETERM (HEADGOAL (rtac ctxt rel_funI)) THEN
   7.208          unfold_thms_tac ctxt [corec_def] THEN
   7.209 -        HEADGOAL (etac (mk_rel_funDN_rotated (1 + length actives) dtor_corec_transfer')) THEN
   7.210 +        HEADGOAL (etac ctxt (mk_rel_funDN_rotated (1 + length actives) dtor_corec_transfer')) THEN
   7.211          unfold_thms_tac ctxt (rel_pre_T_defs @ rel_eqs)
   7.212        end;
   7.213  
   7.214 @@ -305,13 +305,13 @@
   7.215    end;
   7.216  
   7.217  fun solve_prem_prem_tac ctxt =
   7.218 -  REPEAT o (eresolve_tac ctxt @{thms bexE rev_bexI} ORELSE' rtac @{thm rev_bexI[OF UNIV_I]} ORELSE'
   7.219 +  REPEAT o (eresolve_tac ctxt @{thms bexE rev_bexI} ORELSE' rtac ctxt @{thm rev_bexI[OF UNIV_I]} ORELSE'
   7.220      hyp_subst_tac ctxt ORELSE' resolve_tac ctxt @{thms disjI1 disjI2}) THEN'
   7.221 -  (rtac refl ORELSE' atac ORELSE' rtac @{thm singletonI});
   7.222 +  (rtac ctxt refl ORELSE' atac ORELSE' rtac ctxt @{thm singletonI});
   7.223  
   7.224  fun mk_induct_leverage_prem_prems_tac ctxt nn kks fp_abs_inverses abs_inverses set_maps
   7.225      pre_set_defs =
   7.226 -  HEADGOAL (EVERY' (maps (fn kk => [select_prem_tac nn (dtac meta_spec) kk, etac meta_mp,
   7.227 +  HEADGOAL (EVERY' (maps (fn kk => [select_prem_tac ctxt nn (dtac ctxt meta_spec) kk, etac ctxt meta_mp,
   7.228      SELECT_GOAL (unfold_thms_tac ctxt (pre_set_defs @ fp_abs_inverses @ abs_inverses @ set_maps @
   7.229        sumprod_thms_set)),
   7.230      solve_prem_prem_tac ctxt]) (rev kks)));
   7.231 @@ -319,10 +319,10 @@
   7.232  fun mk_induct_discharge_prem_tac ctxt nn n fp_abs_inverses abs_inverses set_maps pre_set_defs m k
   7.233      kks =
   7.234    let val r = length kks in
   7.235 -    HEADGOAL (EVERY' [select_prem_tac n (rotate_tac 1) k, rotate_tac ~1, hyp_subst_tac ctxt,
   7.236 -      REPEAT_DETERM_N m o (dtac meta_spec THEN' rotate_tac ~1)]) THEN
   7.237 +    HEADGOAL (EVERY' [select_prem_tac ctxt n (rotate_tac 1) k, rotate_tac ~1, hyp_subst_tac ctxt,
   7.238 +      REPEAT_DETERM_N m o (dtac ctxt meta_spec THEN' rotate_tac ~1)]) THEN
   7.239      EVERY [REPEAT_DETERM_N r
   7.240 -        (HEADGOAL (rotate_tac ~1 THEN' dtac meta_mp THEN' rotate_tac 1) THEN prefer_tac 2),
   7.241 +        (HEADGOAL (rotate_tac ~1 THEN' dtac ctxt meta_mp THEN' rotate_tac 1) THEN prefer_tac 2),
   7.242        if r > 0 then ALLGOALS (Goal.norm_hhf_tac ctxt) else all_tac, HEADGOAL atac,
   7.243        mk_induct_leverage_prem_prems_tac ctxt nn kks fp_abs_inverses abs_inverses set_maps
   7.244          pre_set_defs]
   7.245 @@ -335,7 +335,7 @@
   7.246         EVERY (map (fn def => HEADGOAL (subst_asm_tac ctxt NONE [def])) ctr_defs)
   7.247       else
   7.248         unfold_thms_tac ctxt ctr_defs) THEN
   7.249 -    HEADGOAL (rtac ctor_induct') THEN co_induct_inst_as_projs_tac ctxt 0 THEN
   7.250 +    HEADGOAL (rtac ctxt ctor_induct') THEN co_induct_inst_as_projs_tac ctxt 0 THEN
   7.251      EVERY (@{map 4} (EVERY oooo @{map 3} o
   7.252          mk_induct_discharge_prem_tac ctxt nn n fp_abs_inverses abs_inverses set_maps)
   7.253        pre_set_defss mss (unflat mss (1 upto n)) kkss)
   7.254 @@ -349,9 +349,9 @@
   7.255    SELECT_GOAL (unfold_thms_tac ctxt (pre_rel_def :: dtor_ctor :: sels)) THEN'
   7.256    SELECT_GOAL (unfold_thms_tac ctxt (pre_rel_def :: fp_abs_inverse :: abs_inverse :: dtor_ctor ::
   7.257      sels @ sumprod_thms_rel @ @{thms o_apply vimage2p_def})) THEN'
   7.258 -  (atac ORELSE' REPEAT o etac conjE THEN'
   7.259 +  (atac ORELSE' REPEAT o etac ctxt conjE THEN'
   7.260       full_simp_tac (ss_only (no_refl discs @ rel_eqs @ more_simp_thms) ctxt) THEN'
   7.261 -     REPEAT o etac conjE THEN_MAYBE' REPEAT o hyp_subst_tac ctxt THEN'
   7.262 +     REPEAT o etac ctxt conjE THEN_MAYBE' REPEAT o hyp_subst_tac ctxt THEN'
   7.263       REPEAT o (resolve_tac ctxt [refl, conjI] ORELSE' atac));
   7.264  
   7.265  fun mk_coinduct_distinct_ctrs_tac ctxt discs discs' =
   7.266 @@ -359,18 +359,18 @@
   7.267      val discs'' = map (perhaps (try (fn th => th RS @{thm notnotD}))) (discs @ discs')
   7.268        |> distinct Thm.eq_thm_prop;
   7.269    in
   7.270 -    hyp_subst_tac ctxt THEN' REPEAT o etac conjE THEN'
   7.271 +    hyp_subst_tac ctxt THEN' REPEAT o etac ctxt conjE THEN'
   7.272      full_simp_tac (ss_only (refl :: no_refl discs'' @ basic_simp_thms) ctxt)
   7.273    end;
   7.274  
   7.275  fun mk_coinduct_discharge_prem_tac ctxt rel_eqs' nn kk n pre_rel_def fp_abs_inverse abs_inverse
   7.276      dtor_ctor exhaust ctr_defs discss selss =
   7.277    let val ks = 1 upto n in
   7.278 -    EVERY' ([rtac allI, rtac allI, rtac impI, select_prem_tac nn (dtac meta_spec) kk,
   7.279 -        dtac meta_spec, dtac meta_mp, atac, rtac exhaust, K (co_induct_inst_as_projs_tac ctxt 0),
   7.280 +    EVERY' ([rtac ctxt allI, rtac ctxt allI, rtac ctxt impI, select_prem_tac ctxt nn (dtac ctxt meta_spec) kk,
   7.281 +        dtac ctxt meta_spec, dtac ctxt meta_mp, atac, rtac ctxt exhaust, K (co_induct_inst_as_projs_tac ctxt 0),
   7.282          hyp_subst_tac ctxt] @
   7.283        @{map 4} (fn k => fn ctr_def => fn discs => fn sels =>
   7.284 -        EVERY' ([rtac exhaust, K (co_induct_inst_as_projs_tac ctxt 1)] @
   7.285 +        EVERY' ([rtac ctxt exhaust, K (co_induct_inst_as_projs_tac ctxt 1)] @
   7.286            map2 (fn k' => fn discs' =>
   7.287              if k' = k then
   7.288                mk_coinduct_same_ctr_tac ctxt rel_eqs' pre_rel_def fp_abs_inverse abs_inverse
   7.289 @@ -381,82 +381,82 @@
   7.290  
   7.291  fun mk_coinduct_tac ctxt rel_eqs' nn ns dtor_coinduct' pre_rel_defs fp_abs_inverses abs_inverses
   7.292      dtor_ctors exhausts ctr_defss discsss selsss =
   7.293 -  HEADGOAL (rtac dtor_coinduct' THEN'
   7.294 +  HEADGOAL (rtac ctxt dtor_coinduct' THEN'
   7.295      EVERY' (@{map 10} (mk_coinduct_discharge_prem_tac ctxt rel_eqs' nn)
   7.296        (1 upto nn) ns pre_rel_defs fp_abs_inverses abs_inverses dtor_ctors exhausts ctr_defss discsss
   7.297        selsss));
   7.298  
   7.299  fun mk_map_disc_iff_tac ctxt ct exhaust discs maps =
   7.300    TRYALL Goal.conjunction_tac THEN
   7.301 -  ALLGOALS (rtac (cterm_instantiate_pos [SOME ct] exhaust) THEN_ALL_NEW
   7.302 +  ALLGOALS (rtac ctxt (cterm_instantiate_pos [SOME ct] exhaust) THEN_ALL_NEW
   7.303      REPEAT_DETERM o hyp_subst_tac ctxt) THEN
   7.304    unfold_thms_tac ctxt maps THEN
   7.305    unfold_thms_tac ctxt (map (fn thm => thm RS eqFalseI
   7.306      handle THM _ => thm RS eqTrueI) discs) THEN
   7.307 -  ALLGOALS (rtac refl ORELSE' rtac TrueI);
   7.308 +  ALLGOALS (rtac ctxt refl ORELSE' rtac ctxt TrueI);
   7.309  
   7.310  fun mk_map_sel_tac ctxt ct exhaust discs maps sels map_id0s =
   7.311    TRYALL Goal.conjunction_tac THEN
   7.312 -    ALLGOALS (rtac (cterm_instantiate_pos [SOME ct] exhaust) THEN_ALL_NEW
   7.313 +    ALLGOALS (rtac ctxt (cterm_instantiate_pos [SOME ct] exhaust) THEN_ALL_NEW
   7.314        REPEAT_DETERM o hyp_subst_tac ctxt) THEN
   7.315      unfold_thms_tac ctxt ((discs RL [eqTrueI, eqFalseI]) @
   7.316        @{thms not_True_eq_False not_False_eq_True}) THEN
   7.317 -    TRYALL (etac FalseE ORELSE' etac @{thm TrueE}) THEN
   7.318 +    TRYALL (etac ctxt FalseE ORELSE' etac ctxt @{thm TrueE}) THEN
   7.319      unfold_thms_tac ctxt (@{thm id_apply} :: maps @ sels @ map_id0s) THEN
   7.320 -    ALLGOALS (rtac refl);
   7.321 +    ALLGOALS (rtac ctxt refl);
   7.322  
   7.323  fun mk_rel_cases_tac ctxt ct1 ct2 exhaust injects rel_injects distincts rel_distincts rel_eqs=
   7.324 -  HEADGOAL (rtac (cterm_instantiate_pos [SOME ct1] exhaust) THEN_ALL_NEW
   7.325 -    rtac (cterm_instantiate_pos [SOME ct2] exhaust) THEN_ALL_NEW
   7.326 +  HEADGOAL (rtac ctxt (cterm_instantiate_pos [SOME ct1] exhaust) THEN_ALL_NEW
   7.327 +    rtac ctxt (cterm_instantiate_pos [SOME ct2] exhaust) THEN_ALL_NEW
   7.328        hyp_subst_tac ctxt) THEN
   7.329    unfold_thms_tac ctxt (rel_eqs @ injects @ rel_injects @ @{thms conj_imp_eq_imp_imp simp_thms(6)
   7.330      True_implies_equals conj_imp_eq_imp_imp} @
   7.331      map (fn thm => thm RS eqFalseI) (distincts @ rel_distincts) @
   7.332      map (fn thm => thm RS eqTrueI) rel_injects) THEN
   7.333 -  TRYALL (atac ORELSE' etac FalseE ORELSE'
   7.334 -    (REPEAT_DETERM o dtac @{thm meta_spec} THEN'
   7.335 +  TRYALL (atac ORELSE' etac ctxt FalseE ORELSE'
   7.336 +    (REPEAT_DETERM o dtac ctxt @{thm meta_spec} THEN'
   7.337       TRY o filter_prems_tac ctxt
   7.338         (forall (curry (op <>) (HOLogic.mk_Trueprop @{term False})) o Logic.strip_imp_prems) THEN'
   7.339 -     REPEAT_DETERM o (dtac @{thm meta_mp} THEN' rtac refl) THEN' Goal.assume_rule_tac ctxt));
   7.340 +     REPEAT_DETERM o (dtac ctxt @{thm meta_mp} THEN' rtac ctxt refl) THEN' Goal.assume_rule_tac ctxt));
   7.341  
   7.342  fun mk_rel_coinduct0_tac ctxt dtor_rel_coinduct cts assms exhausts discss selss ctor_defss
   7.343      dtor_ctors ctor_injects abs_injects rel_pre_defs abs_inverses nesting_rel_eqs =
   7.344 -  rtac dtor_rel_coinduct 1 THEN
   7.345 +  rtac ctxt dtor_rel_coinduct 1 THEN
   7.346     EVERY (@{map 11} (fn ct => fn assm => fn exhaust => fn discs => fn sels => fn ctor_defs =>
   7.347       fn dtor_ctor => fn ctor_inject => fn abs_inject => fn rel_pre_def => fn abs_inverse =>
   7.348 -      (rtac exhaust THEN_ALL_NEW (rtac exhaust THEN_ALL_NEW
   7.349 -         (dtac (rotate_prems ~1 (cterm_instantiate_pos [NONE, NONE, NONE, NONE, SOME ct]
   7.350 +      (rtac ctxt exhaust THEN_ALL_NEW (rtac ctxt exhaust THEN_ALL_NEW
   7.351 +         (dtac ctxt (rotate_prems ~1 (cterm_instantiate_pos [NONE, NONE, NONE, NONE, SOME ct]
   7.352              @{thm arg_cong2} RS iffD1)) THEN'
   7.353 -          atac THEN' atac THEN' hyp_subst_tac ctxt THEN' dtac assm THEN'
   7.354 -          REPEAT_DETERM o etac conjE))) 1 THEN
   7.355 +          atac THEN' atac THEN' hyp_subst_tac ctxt THEN' dtac ctxt assm THEN'
   7.356 +          REPEAT_DETERM o etac ctxt conjE))) 1 THEN
   7.357        unfold_thms_tac ctxt ((discs RL [eqTrueI, eqFalseI]) @ sels @ simp_thms') THEN
   7.358        unfold_thms_tac ctxt (dtor_ctor :: rel_pre_def :: abs_inverse :: ctor_inject ::
   7.359          abs_inject :: ctor_defs @ nesting_rel_eqs @ simp_thms' @
   7.360          @{thms id_bnf_def rel_sum_simps rel_prod_apply vimage2p_def Inl_Inr_False
   7.361            iffD2[OF eq_False Inr_not_Inl] sum.inject prod.inject}) THEN
   7.362 -      REPEAT_DETERM (HEADGOAL ((REPEAT_DETERM o etac conjE) THEN' (REPEAT_DETERM o rtac conjI) THEN'
   7.363 -        (rtac refl ORELSE' atac))))
   7.364 +      REPEAT_DETERM (HEADGOAL ((REPEAT_DETERM o etac ctxt conjE) THEN' (REPEAT_DETERM o rtac ctxt conjI) THEN'
   7.365 +        (rtac ctxt refl ORELSE' atac))))
   7.366      cts assms exhausts discss selss ctor_defss dtor_ctors ctor_injects abs_injects rel_pre_defs
   7.367        abs_inverses);
   7.368  
   7.369  fun mk_rel_induct0_tac ctxt ctor_rel_induct assms cterms exhausts ctor_defss ctor_injects
   7.370      rel_pre_list_defs Abs_inverses nesting_rel_eqs =
   7.371 -  rtac ctor_rel_induct 1 THEN EVERY (@{map 6} (fn cterm => fn exhaust => fn ctor_defs =>
   7.372 +  rtac ctxt ctor_rel_induct 1 THEN EVERY (@{map 6} (fn cterm => fn exhaust => fn ctor_defs =>
   7.373        fn ctor_inject => fn rel_pre_list_def => fn Abs_inverse =>
   7.374 -        HEADGOAL (rtac exhaust THEN_ALL_NEW (rtac exhaust THEN_ALL_NEW
   7.375 -          (rtac (cterm_instantiate_pos (replicate 4 NONE @ [SOME cterm]) @{thm arg_cong2} RS iffD2)
   7.376 +        HEADGOAL (rtac ctxt exhaust THEN_ALL_NEW (rtac ctxt exhaust THEN_ALL_NEW
   7.377 +          (rtac ctxt (cterm_instantiate_pos (replicate 4 NONE @ [SOME cterm]) @{thm arg_cong2} RS iffD2)
   7.378              THEN' atac THEN' atac THEN' TRY o resolve_tac ctxt assms))) THEN
   7.379          unfold_thms_tac ctxt (ctor_inject :: rel_pre_list_def :: ctor_defs @ nesting_rel_eqs @
   7.380            @{thms id_bnf_def vimage2p_def}) THEN
   7.381          TRYALL (hyp_subst_tac ctxt) THEN
   7.382          unfold_thms_tac ctxt (Abs_inverse :: @{thms rel_sum_simps rel_prod_apply Inl_Inr_False
   7.383            Inr_Inl_False  sum.inject prod.inject}) THEN
   7.384 -        TRYALL (rtac refl ORELSE' etac FalseE ORELSE' (REPEAT_DETERM o etac conjE) THEN' atac))
   7.385 +        TRYALL (rtac ctxt refl ORELSE' etac ctxt FalseE ORELSE' (REPEAT_DETERM o etac ctxt conjE) THEN' atac))
   7.386      cterms exhausts ctor_defss ctor_injects rel_pre_list_defs Abs_inverses);
   7.387  
   7.388  fun mk_rel_sel_tac ctxt ct1 ct2 exhaust discs sels rel_injects distincts rel_distincts rel_eqs =
   7.389 -  HEADGOAL (rtac (cterm_instantiate_pos [SOME ct1] exhaust) THEN_ALL_NEW
   7.390 -    rtac (cterm_instantiate_pos [SOME ct2] exhaust) THEN_ALL_NEW
   7.391 +  HEADGOAL (rtac ctxt (cterm_instantiate_pos [SOME ct1] exhaust) THEN_ALL_NEW
   7.392 +    rtac ctxt (cterm_instantiate_pos [SOME ct2] exhaust) THEN_ALL_NEW
   7.393        hyp_subst_tac ctxt) THEN
   7.394    unfold_thms_tac ctxt (sels @ rel_injects @ rel_eqs @
   7.395      @{thms simp_thms(6,7,8,11,12,15,16,21,22,24)} @ ((discs @ distincts) RL [eqTrueI, eqFalseI]) @
   7.396 @@ -466,24 +466,24 @@
   7.397  fun mk_sel_transfer_tac ctxt n sel_defs case_transfer =
   7.398    TRYALL Goal.conjunction_tac THEN
   7.399    unfold_thms_tac ctxt (map (Drule.abs_def o Local_Defs.meta_rewrite_rule ctxt) sel_defs) THEN
   7.400 -  ALLGOALS (rtac (mk_rel_funDN n case_transfer) THEN_ALL_NEW
   7.401 -    REPEAT_DETERM o (atac ORELSE' rtac rel_funI));
   7.402 +  ALLGOALS (rtac ctxt (mk_rel_funDN n case_transfer) THEN_ALL_NEW
   7.403 +    REPEAT_DETERM o (atac ORELSE' rtac ctxt rel_funI));
   7.404  
   7.405  fun mk_set_sel_tac ctxt ct exhaust discs sels sets =
   7.406    TRYALL Goal.conjunction_tac THEN
   7.407 -    ALLGOALS (rtac (cterm_instantiate_pos [SOME ct] exhaust) THEN_ALL_NEW
   7.408 +    ALLGOALS (rtac ctxt (cterm_instantiate_pos [SOME ct] exhaust) THEN_ALL_NEW
   7.409        REPEAT_DETERM o hyp_subst_tac ctxt) THEN
   7.410      unfold_thms_tac ctxt ((discs RL [eqTrueI, eqFalseI]) @
   7.411        @{thms not_True_eq_False not_False_eq_True}) THEN
   7.412 -    TRYALL (etac FalseE ORELSE' etac @{thm TrueE}) THEN
   7.413 +    TRYALL (etac ctxt FalseE ORELSE' etac ctxt @{thm TrueE}) THEN
   7.414      unfold_thms_tac ctxt (sels @ sets) THEN
   7.415      ALLGOALS (REPEAT o (resolve_tac ctxt @{thms UnI1 UnI2 imageI} ORELSE'
   7.416          eresolve_tac ctxt @{thms UN_I UN_I[rotated] imageE} ORELSE'
   7.417          hyp_subst_tac ctxt) THEN'
   7.418 -      (rtac @{thm singletonI} ORELSE' atac));
   7.419 +      (rtac ctxt @{thm singletonI} ORELSE' atac));
   7.420  
   7.421  fun mk_set_cases_tac ctxt ct assms exhaust sets =
   7.422 -  HEADGOAL (rtac (cterm_instantiate_pos [SOME ct] exhaust) THEN_ALL_NEW hyp_subst_tac ctxt) THEN
   7.423 +  HEADGOAL (rtac ctxt (cterm_instantiate_pos [SOME ct] exhaust) THEN_ALL_NEW hyp_subst_tac ctxt) THEN
   7.424    unfold_thms_tac ctxt sets THEN
   7.425    REPEAT_DETERM (HEADGOAL
   7.426      (eresolve_tac ctxt @{thms FalseE emptyE singletonE UnE UN_E insertE} ORELSE'
   7.427 @@ -494,7 +494,7 @@
   7.428    TRYALL Goal.conjunction_tac THEN unfold_thms_tac ctxt sets THEN
   7.429    TRYALL (REPEAT o
   7.430      (resolve_tac ctxt @{thms UnI1 UnI2} ORELSE'
   7.431 -     eresolve_tac ctxt @{thms UN_I UN_I[rotated]}) THEN' (rtac @{thm singletonI} ORELSE' atac));
   7.432 +     eresolve_tac ctxt @{thms UN_I UN_I[rotated]}) THEN' (rtac ctxt @{thm singletonI} ORELSE' atac));
   7.433  
   7.434  fun mk_set_induct0_tac ctxt cts assms dtor_set_inducts exhausts set_pre_defs ctor_defs dtor_ctors
   7.435      Abs_pre_inverses =
   7.436 @@ -502,8 +502,8 @@
   7.437      val assms_tac =
   7.438        let val assms' = map (unfold_thms ctxt (@{thm id_bnf_def} :: ctor_defs)) assms in
   7.439          fold (curry (op ORELSE')) (map (fn thm =>
   7.440 -            funpow (length (Thm.prems_of thm)) (fn tac => tac THEN' atac) (rtac thm)) assms')
   7.441 -          (etac FalseE)
   7.442 +            funpow (length (Thm.prems_of thm)) (fn tac => tac THEN' atac) (rtac ctxt thm)) assms')
   7.443 +          (etac ctxt FalseE)
   7.444        end;
   7.445      val exhausts' = map (fn thm => thm RS @{thm asm_rl[of "P x y" for P x y]}) exhausts
   7.446        |> map2 (fn ct => cterm_instantiate_pos [NONE, SOME ct]) cts;
     8.1 --- a/src/HOL/Tools/BNF/bnf_fp_n2m.ML	Thu Jul 16 10:48:20 2015 +0200
     8.2 +++ b/src/HOL/Tools/BNF/bnf_fp_n2m.ML	Thu Jul 16 12:23:22 2015 +0200
     8.3 @@ -462,7 +462,7 @@
     8.4            unfold_thms_tac ctxt (flat [rec_thms, raw_co_rec_defs, pre_map_defs,
     8.5              fp_pre_map_defs, fp_xtor_co_recs, fp_rec_o_maps, map_thms, fp_Rep_o_Abss,
     8.6              Rep_o_Abss]) THEN
     8.7 -          CONJ_WRAP (K (HEADGOAL (rtac refl))) bnfs;
     8.8 +          CONJ_WRAP (K (HEADGOAL (rtac ctxt refl))) bnfs;
     8.9        in
    8.10          Library.foldr1 HOLogic.mk_conj goals
    8.11          |> HOLogic.mk_Trueprop
     9.1 --- a/src/HOL/Tools/BNF/bnf_fp_n2m_tactics.ML	Thu Jul 16 10:48:20 2015 +0200
     9.2 +++ b/src/HOL/Tools/BNF/bnf_fp_n2m_tactics.ML	Thu Jul 16 12:23:22 2015 +0200
     9.3 @@ -40,10 +40,10 @@
     9.4        folded_C_IHs rel_monos unfolds;
     9.5    in
     9.6      unfold_thms_tac ctxt vimage2p_unfolds THEN
     9.7 -    HEADGOAL (CONJ_WRAP_GEN' (rtac @{thm context_conjI})
     9.8 -      (fn thm => rtac thm THEN_ALL_NEW (rotate_tac ~1 THEN'
     9.9 +    HEADGOAL (CONJ_WRAP_GEN' (rtac ctxt @{thm context_conjI})
    9.10 +      (fn thm => rtac ctxt thm THEN_ALL_NEW (rotate_tac ~1 THEN'
    9.11           REPEAT_ALL_NEW (FIRST' [eresolve_tac ctxt C_IHs, eresolve_tac ctxt C_IH_monos,
    9.12 -           SELECT_GOAL (unfold_thms_tac ctxt nesting_rel_eqs) THEN' rtac @{thm order_refl},
    9.13 +           SELECT_GOAL (unfold_thms_tac ctxt nesting_rel_eqs) THEN' rtac ctxt @{thm order_refl},
    9.14             assume_tac ctxt, resolve_tac ctxt co_inducts,
    9.15             resolve_tac ctxt C_IH_monos THEN' REPEAT_ALL_NEW (eresolve_tac ctxt nesting_rel_monos)])))
    9.16      co_inducts)
    10.1 --- a/src/HOL/Tools/BNF/bnf_gfp.ML	Thu Jul 16 10:48:20 2015 +0200
    10.2 +++ b/src/HOL/Tools/BNF/bnf_gfp.ML	Thu Jul 16 12:23:22 2015 +0200
    10.3 @@ -257,7 +257,7 @@
    10.4          val goal = mk_Trueprop_eq (Term.list_comb (mapAsAs, passive_ids @ self_fs) $ x, x);
    10.5        in
    10.6          Goal.prove_sorry lthy [] [] (Logic.list_implies (prems, goal))
    10.7 -          (K (mk_map_cong0L_tac m map_cong0 map_id))
    10.8 +          (fn {context = ctxt, prems = _} => mk_map_cong0L_tac ctxt m map_cong0 map_id)
    10.9          |> Thm.close_derivation
   10.10          |> singleton (Proof_Context.export names_lthy lthy)
   10.11        end;
   10.12 @@ -276,7 +276,8 @@
   10.13          val goals = map2 (fn prem => fn concl => Logic.mk_implies (prem, concl)) prems concls;
   10.14        in
   10.15          map (fn goal =>
   10.16 -          Goal.prove_sorry lthy [] [] goal (K ((hyp_subst_tac lthy THEN' rtac refl) 1))
   10.17 +          Goal.prove_sorry lthy [] [] goal (fn {context = ctxt, prems = _} =>
   10.18 +            (hyp_subst_tac ctxt THEN' rtac ctxt refl) 1)
   10.19            |> Thm.close_derivation
   10.20            |> singleton (Proof_Context.export names_lthy lthy)) goals
   10.21        end;
   10.22 @@ -335,7 +336,8 @@
   10.23            Logic.list_implies (coalg_prem :: [prem], concl)) concls) prems conclss;
   10.24        in
   10.25          map (fn goals => map (fn goal =>
   10.26 -          Goal.prove_sorry lthy [] [] goal (K (mk_coalg_set_tac coalg_def))
   10.27 +          Goal.prove_sorry lthy [] [] goal (fn {context = ctxt, prems = _} =>
   10.28 +            mk_coalg_set_tac ctxt coalg_def)
   10.29            |> Thm.close_derivation
   10.30            |> singleton (Proof_Context.export names_lthy lthy)) goals) goalss
   10.31        end;
   10.32 @@ -347,9 +349,9 @@
   10.33          val goal = HOLogic.mk_Trueprop (mk_tcoalg activeAs ss)
   10.34        in
   10.35          Goal.prove_sorry lthy [] [] goal
   10.36 -          (K (rtac (coalg_def RS iffD2) 1 THEN CONJ_WRAP
   10.37 -            (K (EVERY' [rtac ballI, rtac CollectI,
   10.38 -              CONJ_WRAP' (K (EVERY' [rtac @{thm subset_UNIV}])) allAs] 1)) ss))
   10.39 +          (fn {context = ctxt, prems = _} => (rtac ctxt (coalg_def RS iffD2) 1 THEN CONJ_WRAP
   10.40 +            (K (EVERY' [rtac ctxt ballI, rtac ctxt CollectI,
   10.41 +              CONJ_WRAP' (K (EVERY' [rtac ctxt @{thm subset_UNIV}])) allAs] 1)) ss))
   10.42          |> Thm.close_derivation
   10.43          |> singleton (Proof_Context.export names_lthy lthy)
   10.44        end;
   10.45 @@ -409,7 +411,8 @@
   10.46              mk_Trueprop_eq (Term.list_comb (mapAsBs, passive_ids @ fs @ [s $ x]), s' $ (f $ x)));
   10.47          val elim_goals = @{map 6} mk_elim_goal Bs mapsAsBs fs ss s's zs;
   10.48          fun prove goal =
   10.49 -          Goal.prove_sorry lthy [] [] goal (K (mk_mor_elim_tac mor_def))
   10.50 +          Goal.prove_sorry lthy [] [] goal (fn {context = ctxt, prems = _} =>
   10.51 +            mk_mor_elim_tac ctxt mor_def)
   10.52            |> Thm.close_derivation
   10.53            |> singleton (Proof_Context.export names_lthy lthy);
   10.54        in
   10.55 @@ -424,7 +427,7 @@
   10.56          val concl = HOLogic.mk_Trueprop (mk_mor Bs ss Bs_copy ss active_ids);
   10.57        in
   10.58          Goal.prove_sorry lthy [] [] (Logic.list_implies (prems, concl))
   10.59 -          (K (mk_mor_incl_tac mor_def map_ids))
   10.60 +          (fn {context = ctxt, prems = _} => mk_mor_incl_tac ctxt mor_def map_ids)
   10.61          |> Thm.close_derivation
   10.62          |> singleton (Proof_Context.export names_lthy lthy)
   10.63        end;
   10.64 @@ -466,7 +469,7 @@
   10.65          val rhs = Library.foldr1 HOLogic.mk_conj (@{map 4} mk_conjunct mapsAsBs fs ss s's);
   10.66        in
   10.67          Goal.prove_sorry lthy [] [] (mk_Trueprop_eq (lhs, rhs))
   10.68 -          (K (mk_mor_UNIV_tac morE_thms mor_def))
   10.69 +          (fn {context = ctxt, prems = _} => mk_mor_UNIV_tac ctxt morE_thms mor_def)
   10.70          |> Thm.close_derivation
   10.71          |> singleton (Proof_Context.export names_lthy lthy)
   10.72        end;
   10.73 @@ -478,7 +481,7 @@
   10.74        in
   10.75          Goal.prove_sorry lthy [] []
   10.76            (HOLogic.mk_Trueprop (mk_mor active_UNIVs ss (map HOLogic.mk_UNIV FTsAs) maps ss))
   10.77 -          (K (mk_mor_str_tac ks mor_UNIV_thm))
   10.78 +          (fn {context = ctxt, prems = _} => mk_mor_str_tac ctxt ks mor_UNIV_thm)
   10.79          |> Thm.close_derivation
   10.80          |> singleton (Proof_Context.export names_lthy lthy)
   10.81        end;
   10.82 @@ -491,7 +494,7 @@
   10.83        in
   10.84          Goal.prove_sorry lthy [] []
   10.85            (HOLogic.mk_Trueprop (mk_mor (map HOLogic.mk_UNIV activeBs) s's sum_UNIVs maps Inls))
   10.86 -          (K (mk_mor_case_sum_tac ks mor_UNIV_thm))
   10.87 +          (fn {context = ctxt, prems = _} => mk_mor_case_sum_tac ctxt ks mor_UNIV_thm)
   10.88          |> Thm.close_derivation
   10.89          |> singleton (Proof_Context.export names_lthy lthy)
   10.90        end;
   10.91 @@ -567,7 +570,8 @@
   10.92              (@{map 6} mk_conjunct Rs ss s's zs z's relsAsBs))
   10.93        in
   10.94          Goal.prove_sorry lthy [] [] (mk_Trueprop_eq (mk_bis Bs ss B's s's Rs, rhs))
   10.95 -          (K (mk_bis_rel_tac m bis_def in_rels map_comps map_cong0s set_mapss))
   10.96 +          (fn {context = ctxt, prems = _} => mk_bis_rel_tac ctxt m bis_def in_rels map_comps
   10.97 +            map_cong0s set_mapss)
   10.98          |> Thm.close_derivation
   10.99          |> singleton (Proof_Context.export names_lthy lthy)
  10.100        end;
  10.101 @@ -576,7 +580,8 @@
  10.102        Goal.prove_sorry lthy [] []
  10.103          (Logic.mk_implies (HOLogic.mk_Trueprop (mk_bis Bs ss B's s's Rs),
  10.104            HOLogic.mk_Trueprop (mk_bis B's s's Bs ss (map mk_converse Rs))))
  10.105 -        (K (mk_bis_converse_tac m bis_rel_thm rel_congs rel_converseps))
  10.106 +        (fn {context = ctxt, prems = _} => mk_bis_converse_tac ctxt m bis_rel_thm rel_congs
  10.107 +          rel_converseps)
  10.108        |> Thm.close_derivation
  10.109        |> singleton (Proof_Context.export names_lthy lthy);
  10.110  
  10.111 @@ -686,7 +691,8 @@
  10.112          val goals = map2 (fn i => fn R => Logic.mk_implies (sbis_prem, mk_concl i R)) ks sRs;
  10.113        in
  10.114          @{map 3} (fn goal => fn i => fn def =>
  10.115 -          Goal.prove_sorry lthy [] [] goal (K (mk_incl_lsbis_tac n i def))
  10.116 +          Goal.prove_sorry lthy [] [] goal (fn {context = ctxt, prems = _} =>
  10.117 +            mk_incl_lsbis_tac ctxt n i def)
  10.118            |> Thm.close_derivation
  10.119            |> singleton (Proof_Context.export names_lthy lthy)) goals ks lsbis_defs
  10.120        end;
  10.121 @@ -698,8 +704,8 @@
  10.122        in
  10.123          @{map 3} (fn goal => fn l_incl => fn incl_l =>
  10.124            Goal.prove_sorry lthy [] [] goal
  10.125 -            (K (mk_equiv_lsbis_tac sbis_lsbis_thm l_incl incl_l
  10.126 -              bis_Id_on_thm bis_converse_thm bis_O_thm))
  10.127 +            (fn {context = ctxt, prems = _} => mk_equiv_lsbis_tac ctxt sbis_lsbis_thm l_incl incl_l
  10.128 +              bis_Id_on_thm bis_converse_thm bis_O_thm)
  10.129            |> Thm.close_derivation
  10.130            |> singleton (Proof_Context.export names_lthy lthy))
  10.131          goals lsbis_incl_thms incl_lsbis_thms
  10.132 @@ -719,7 +725,8 @@
  10.133  
  10.134            val ((sbdT_name, (sbdT_glob_info, sbdT_loc_info)), lthy) =
  10.135              typedef (sbdT_bind, sum_bdT_params', NoSyn)
  10.136 -              (HOLogic.mk_UNIV sum_bdT) NONE (fn _ => EVERY' [rtac exI, rtac UNIV_I] 1) lthy;
  10.137 +              (HOLogic.mk_UNIV sum_bdT) NONE (fn ctxt =>
  10.138 +                EVERY' [rtac ctxt exI, rtac ctxt UNIV_I] 1) lthy;
  10.139  
  10.140            val sbdT = Type (sbdT_name, sum_bdT_params);
  10.141            val Abs_sbdT = Const (#Abs_name sbdT_glob_info, sum_bdT --> sbdT);
  10.142 @@ -1097,7 +1104,8 @@
  10.143          val goals = map2 mk_goal ks zs;
  10.144  
  10.145          val length_Levs' = map2 (fn goal => fn length_Lev =>
  10.146 -          Goal.prove_sorry lthy [] [] goal (K (mk_length_Lev'_tac length_Lev))
  10.147 +          Goal.prove_sorry lthy [] [] goal (fn {context = ctxt, prems = _} =>
  10.148 +            mk_length_Lev'_tac ctxt length_Lev)
  10.149            |> Thm.close_derivation
  10.150            |> singleton (Proof_Context.export names_lthy lthy)) goals length_Levs;
  10.151        in
  10.152 @@ -1120,7 +1128,7 @@
  10.153  
  10.154          val rv_last =
  10.155            Goal.prove_sorry lthy [] [] (HOLogic.mk_Trueprop goal)
  10.156 -            (K (mk_rv_last_tac cTs cts rv_Nils rv_Conss))
  10.157 +            (fn {context = ctxt, prems = _} => mk_rv_last_tac ctxt cTs cts rv_Nils rv_Conss)
  10.158            |> Thm.close_derivation
  10.159            |> singleton (Proof_Context.export names_lthy lthy);
  10.160  
  10.161 @@ -1244,20 +1252,22 @@
  10.162        in
  10.163          @{map 4} (fn goal => fn lsbisE => fn map_comp_id => fn map_cong0 =>
  10.164            Goal.prove_sorry lthy [] [] goal
  10.165 -            (K (mk_congruent_str_final_tac m lsbisE map_comp_id map_cong0 equiv_LSBIS_thms))
  10.166 +            (fn {context = ctxt, prems = _} => mk_congruent_str_final_tac ctxt m lsbisE map_comp_id
  10.167 +              map_cong0 equiv_LSBIS_thms)
  10.168            |> Thm.close_derivation)
  10.169          goals lsbisE_thms map_comp_id_thms map_cong0s
  10.170        end;
  10.171  
  10.172      val coalg_final_thm = Goal.prove_sorry lthy [] []
  10.173        (HOLogic.mk_Trueprop (mk_coalg car_finals str_finals))
  10.174 -      (K (mk_coalg_final_tac m coalg_def congruent_str_final_thms equiv_LSBIS_thms
  10.175 -        set_mapss coalgT_set_thmss))
  10.176 +      (fn {context = ctxt, prems = _} => mk_coalg_final_tac ctxt m coalg_def
  10.177 +        congruent_str_final_thms equiv_LSBIS_thms set_mapss coalgT_set_thmss)
  10.178        |> Thm.close_derivation;
  10.179  
  10.180      val mor_T_final_thm = Goal.prove_sorry lthy [] []
  10.181        (HOLogic.mk_Trueprop (mk_mor carTAs strTAs car_finals str_finals (map mk_proj lsbisAs)))
  10.182 -      (K (mk_mor_T_final_tac mor_def congruent_str_final_thms equiv_LSBIS_thms))
  10.183 +      (fn {context = ctxt, prems = _} => mk_mor_T_final_tac ctxt mor_def congruent_str_final_thms
  10.184 +        equiv_LSBIS_thms)
  10.185        |> Thm.close_derivation;
  10.186  
  10.187      val mor_final_thm = mor_comp_thm OF [mor_beh_thm, mor_T_final_thm];
  10.188 @@ -1268,8 +1278,9 @@
  10.189      val ((T_names, (T_glob_infos, T_loc_infos)), lthy) =
  10.190        lthy
  10.191        |> @{fold_map 4} (fn b => fn mx => fn car_final => fn in_car_final =>
  10.192 -        typedef (b, params, mx) car_final NONE
  10.193 -          (fn _ => EVERY' [rtac exI, rtac in_car_final] 1)) bs mixfixes car_finals in_car_final_thms
  10.194 +          typedef (b, params, mx) car_final NONE
  10.195 +            (fn ctxt => EVERY' [rtac ctxt exI, rtac ctxt in_car_final] 1))
  10.196 +        bs mixfixes car_finals in_car_final_thms
  10.197        |>> apsnd split_list o split_list;
  10.198  
  10.199      val Ts = map (fn name => Type (name, params')) T_names;
  10.200 @@ -1397,8 +1408,8 @@
  10.201        in
  10.202          Goal.prove_sorry lthy [] []
  10.203            (HOLogic.mk_Trueprop (mk_mor active_UNIVs ss UNIVs dtors (map (mk_unfold Ts ss) ks)))
  10.204 -          (K (mk_mor_unfold_tac m mor_UNIV_thm dtor_defs unfold_defs Abs_inverses' morEs'
  10.205 -            map_comp_id_thms map_cong0s))
  10.206 +          (fn {context = ctxt, prems = _} => mk_mor_unfold_tac ctxt m mor_UNIV_thm dtor_defs
  10.207 +            unfold_defs Abs_inverses' morEs' map_comp_id_thms map_cong0s)
  10.208          |> Thm.close_derivation
  10.209          |> singleton (Proof_Context.export names_lthy lthy)
  10.210        end;
  10.211 @@ -1411,9 +1422,9 @@
  10.212            (map2 (fn R => fn T => mk_leq R (Id_const T)) TRs Ts));
  10.213        in
  10.214          `split_conj_thm (Goal.prove_sorry lthy [] [] (Logic.mk_implies (prem, concl))
  10.215 -          (K (mk_raw_coind_tac bis_def bis_cong_thm bis_O_thm bis_converse_thm bis_Gr_thm
  10.216 -            tcoalg_thm coalgT_thm mor_T_final_thm sbis_lsbis_thm
  10.217 -            lsbis_incl_thms incl_lsbis_thms equiv_LSBIS_thms mor_Rep_thm Rep_injects))
  10.218 +          (fn {context = ctxt, prems = _} => mk_raw_coind_tac ctxt bis_def bis_cong_thm bis_O_thm
  10.219 +            bis_converse_thm bis_Gr_thm tcoalg_thm coalgT_thm mor_T_final_thm sbis_lsbis_thm
  10.220 +            lsbis_incl_thms incl_lsbis_thms equiv_LSBIS_thms mor_Rep_thm Rep_injects)
  10.221            |> Thm.close_derivation
  10.222            |> singleton (Proof_Context.export names_lthy lthy))
  10.223        end;
  10.224 @@ -1429,7 +1440,8 @@
  10.225          val mor_thm = mor_comp_thm OF [mor_final_thm, mor_Abs_thm];
  10.226  
  10.227          val unique_mor = Goal.prove_sorry lthy [] [] (Logic.mk_implies (prem, unique))
  10.228 -          (K (mk_unfold_unique_mor_tac raw_coind_thms bis_thm mor_thm unfold_defs))
  10.229 +          (fn {context = ctxt, prems = _} => mk_unfold_unique_mor_tac ctxt raw_coind_thms
  10.230 +            bis_thm mor_thm unfold_defs)
  10.231            |> Thm.close_derivation
  10.232            |> singleton (Proof_Context.export names_lthy lthy);
  10.233        in
  10.234 @@ -1629,7 +1641,8 @@
  10.235  
  10.236          val dtor_coinduct =
  10.237            Goal.prove_sorry lthy [] [] dtor_coinduct_goal
  10.238 -            (K (mk_dtor_coinduct_tac m raw_coind_thm bis_rel_thm rel_congs))
  10.239 +            (fn {context = ctxt, prems = _} => mk_dtor_coinduct_tac ctxt m raw_coind_thm bis_rel_thm
  10.240 +              rel_congs)
  10.241            |> Thm.close_derivation
  10.242            |> singleton (Proof_Context.export names_lthy lthy);
  10.243        in
  10.244 @@ -1664,7 +1677,7 @@
  10.245        mk_xtor_rel_co_induct_thm Greatest_FP rels activeJphis (map HOLogic.eq_const Ts) Jphis
  10.246          Jzs Jz's dtors dtor's (fn {context = ctxt, prems} =>
  10.247            (unfold_thms_tac ctxt @{thms le_fun_def le_bool_def all_simps(1,2)[symmetric]} THEN
  10.248 -          REPEAT_DETERM (rtac allI 1) THEN rtac (dtor_coinduct_thm OF prems) 1)) lthy;
  10.249 +          REPEAT_DETERM (rtac ctxt allI 1) THEN rtac ctxt (dtor_coinduct_thm OF prems) 1)) lthy;
  10.250  
  10.251      (*register new codatatypes as BNFs*)
  10.252      val (timer, Jbnfs, (dtor_Jmap_o_thms, dtor_Jmap_thms), dtor_Jmap_unique_thms, dtor_Jset_thmss',
  10.253 @@ -1800,7 +1813,7 @@
  10.254                @{map 5} (fn goal => fn unfold => fn map_comp => fn map_cong0 => fn map_arg_cong =>
  10.255                  Goal.prove_sorry lthy [] [] goal
  10.256                    (fn {context = ctxt, prems = _} => unfold_thms_tac ctxt Jmap_defs THEN
  10.257 -                     mk_map_tac m n map_arg_cong unfold map_comp map_cong0)
  10.258 +                     mk_map_tac ctxt m n map_arg_cong unfold map_comp map_cong0)
  10.259                  |> Thm.close_derivation
  10.260                  |> singleton (Proof_Context.export names_lthy lthy))
  10.261                goals dtor_unfold_thms map_comps map_cong0s map_arg_cong_thms;
  10.262 @@ -1833,7 +1846,8 @@
  10.263                fs_Jmaps gs_Jmaps fgs_Jmaps))
  10.264            in
  10.265              split_conj_thm (Goal.prove_sorry lthy [] [] goal
  10.266 -              (K (mk_map_comp0_tac Jmap_thms map_comp0s dtor_Jmap_unique_thm))
  10.267 +              (fn {context = ctxt, prems = _} =>
  10.268 +                mk_map_comp0_tac ctxt Jmap_thms map_comp0s dtor_Jmap_unique_thm)
  10.269                |> Thm.close_derivation
  10.270                |> singleton (Proof_Context.export names_lthy lthy))
  10.271            end;
  10.272 @@ -1920,7 +1934,7 @@
  10.273                map2 (fn goal => fn rec_Suc =>
  10.274                  Goal.prove_sorry lthy [] [] goal
  10.275                    (fn {context = ctxt, prems = _} => unfold_thms_tac ctxt Jset_defs THEN
  10.276 -                    mk_set_incl_Jset_tac rec_Suc)
  10.277 +                    mk_set_incl_Jset_tac ctxt rec_Suc)
  10.278                  |> Thm.close_derivation
  10.279                  |> singleton (Proof_Context.export names_lthy lthy))
  10.280                goals rec_Sucs)
  10.281 @@ -1930,7 +1944,7 @@
  10.282                  map2 (fn goal => fn rec_Suc =>
  10.283                    Goal.prove_sorry lthy [] [] goal
  10.284                      (fn {context = ctxt, prems = _} => unfold_thms_tac ctxt Jset_defs THEN
  10.285 -                      mk_set_Jset_incl_Jset_tac n rec_Suc k)
  10.286 +                      mk_set_Jset_incl_Jset_tac ctxt n rec_Suc k)
  10.287                    |> Thm.close_derivation
  10.288                    |> singleton (Proof_Context.export names_lthy lthy))
  10.289                  goals rec_Sucs)
  10.290 @@ -1966,7 +1980,7 @@
  10.291                  (replicate n ballI @
  10.292                    maps (map (fn thm => thm RS @{thm subset_CollectI})) set_set_inclss))
  10.293                |> singleton (Proof_Context.export names_lthy lthy)
  10.294 -              |> rule_by_tactic lthy (ALLGOALS (TRY o etac asm_rl)))
  10.295 +              |> rule_by_tactic lthy (ALLGOALS (TRY o etac lthy asm_rl)))
  10.296              Jset_minimal_thms set_Jset_incl_Jset_thmsss' Jsetss_by_range ys ys' dtor_set_induct_phiss
  10.297            end;
  10.298  
  10.299 @@ -1988,7 +2002,8 @@
  10.300              val set_le_thmss = map split_conj_thm
  10.301                (@{map 4} (fn goal => fn Jset_minimal => fn set_Jsets => fn set_Jset_Jsetss =>
  10.302                  Goal.prove_sorry lthy [] [] goal
  10.303 -                  (K (mk_set_le_tac n Jset_minimal set_Jsets set_Jset_Jsetss))
  10.304 +                  (fn {context = ctxt, prems = _} =>
  10.305 +                    mk_set_le_tac ctxt n Jset_minimal set_Jsets set_Jset_Jsetss)
  10.306                  |> Thm.close_derivation
  10.307                  |> singleton (Proof_Context.export names_lthy lthy))
  10.308                le_goals Jset_minimal_thms set_Jset_thmss' set_Jset_Jset_thmsss');
  10.309 @@ -1997,7 +2012,8 @@
  10.310              val set_ge_thmss =
  10.311                @{map 3} (@{map 3} (fn goal => fn set_incl_Jset => fn set_Jset_incl_Jsets =>
  10.312                  Goal.prove_sorry lthy [] [] goal
  10.313 -                  (K (mk_set_ge_tac n set_incl_Jset set_Jset_incl_Jsets))
  10.314 +                  (fn {context = ctxt, prems = _} =>
  10.315 +                    mk_set_ge_tac ctxt n set_incl_Jset set_Jset_incl_Jsets)
  10.316                  |> Thm.close_derivation
  10.317                  |> singleton (Proof_Context.export names_lthy lthy)))
  10.318                ge_goalss set_incl_Jset_thmss' set_Jset_incl_Jset_thmsss'
  10.319 @@ -2054,7 +2070,7 @@
  10.320                @{map 5} (fn j => fn goal => fn cts => fn rec_0s => fn rec_Sucs =>
  10.321                  Goal.prove_sorry lthy [] [] (HOLogic.mk_Trueprop goal)
  10.322                    (fn {context = ctxt, prems = _} => unfold_thms_tac ctxt Jbd_defs THEN
  10.323 -                    mk_col_bd_tac m j cts rec_0s rec_Sucs sbd_Card_order sbd_Cinfinite set_sbdss)
  10.324 +                    mk_col_bd_tac ctxt m j cts rec_0s rec_Sucs sbd_Card_order sbd_Cinfinite set_sbdss)
  10.325                  |> Thm.close_derivation
  10.326                  |> singleton (Proof_Context.export names_lthy lthy))
  10.327                ls goals ctss col_0ss' col_Sucss';
  10.328 @@ -2099,8 +2115,9 @@
  10.329  
  10.330              val thm =
  10.331                Goal.prove_sorry lthy [] [] goal
  10.332 -                (K (mk_mcong_tac lthy m (rtac coinduct) map_comps dtor_Jmap_thms map_cong0s
  10.333 -                  set_mapss set_Jset_thmss set_Jset_Jset_thmsss in_rels))
  10.334 +                (fn {context = ctxt, prems = _} => mk_mcong_tac ctxt m (rtac ctxt coinduct) map_comps
  10.335 +                  dtor_Jmap_thms map_cong0s
  10.336 +                  set_mapss set_Jset_thmss set_Jset_Jset_thmsss in_rels)
  10.337                |> Thm.close_derivation
  10.338                |>  singleton (Proof_Context.export names_lthy lthy);
  10.339            in
  10.340 @@ -2268,8 +2285,8 @@
  10.341  
  10.342              val goal = HOLogic.mk_Trueprop (Library.foldr1 HOLogic.mk_conj goals);
  10.343            in
  10.344 -            Goal.prove_sorry lthy [] [] goal
  10.345 -              (K (mk_le_rel_OO_tac Jrel_coinduct_thm dtor_Jrel_thms le_rel_OOs))
  10.346 +            Goal.prove_sorry lthy [] [] goal (fn {context = ctxt, prems = _} =>
  10.347 +              mk_le_rel_OO_tac ctxt Jrel_coinduct_thm dtor_Jrel_thms le_rel_OOs)
  10.348              |> Thm.close_derivation
  10.349              |> singleton (Proof_Context.export names_lthy lthy)
  10.350            end;
  10.351 @@ -2412,27 +2429,31 @@
  10.352          val timer = time (timer "witnesses");
  10.353  
  10.354          val map_id0_tacs =
  10.355 -          map2 (K oo mk_map_id0_tac Jmap_thms) dtor_unfold_unique_thms unfold_dtor_thms;
  10.356 -        val map_comp0_tacs = map (fn thm => K (rtac (thm RS sym) 1)) Jmap_comp0_thms;
  10.357 +          map2 (fn thm => fn thm' => fn ctxt =>
  10.358 +            mk_map_id0_tac ctxt Jmap_thms thm thm')
  10.359 +          dtor_unfold_unique_thms unfold_dtor_thms;
  10.360 +        val map_comp0_tacs = map (fn thm => fn ctxt => rtac ctxt (thm RS sym) 1) Jmap_comp0_thms;
  10.361          val map_cong0_tacs = map (fn thm => fn ctxt => mk_map_cong0_tac ctxt m thm) map_cong0_thms;
  10.362          val set_map0_tacss =
  10.363 -          map (map (fn col => fn ctxt => unfold_thms_tac ctxt Jset_defs THEN mk_set_map0_tac col))
  10.364 -            (transpose col_natural_thmss);
  10.365 +          map (map (fn col => fn ctxt =>
  10.366 +            unfold_thms_tac ctxt Jset_defs THEN mk_set_map0_tac ctxt col))
  10.367 +          (transpose col_natural_thmss);
  10.368  
  10.369          val Jbd_card_orders = map (fn def => fold_thms lthy [def] sbd_card_order) Jbd_defs;
  10.370          val Jbd_Cinfinites = map (fn def => fold_thms lthy [def] sbd_Cinfinite) Jbd_defs;
  10.371  
  10.372 -        val bd_co_tacs = map (fn thm => K (rtac thm 1)) Jbd_card_orders;
  10.373 -        val bd_cinf_tacs = map (fn thm => K (rtac (thm RS conjunct1) 1)) Jbd_Cinfinites;
  10.374 +        val bd_co_tacs = map (fn thm => fn ctxt => rtac ctxt thm 1) Jbd_card_orders;
  10.375 +        val bd_cinf_tacs = map (fn thm => fn ctxt => rtac ctxt (thm RS conjunct1) 1) Jbd_Cinfinites;
  10.376  
  10.377          val set_bd_tacss =
  10.378            map2 (fn Cinf => map (fn col => fn ctxt =>
  10.379 -            unfold_thms_tac ctxt Jset_defs THEN mk_set_bd_tac Cinf col))
  10.380 +            unfold_thms_tac ctxt Jset_defs THEN mk_set_bd_tac ctxt Cinf col))
  10.381            Jbd_Cinfinites (transpose col_bd_thmss);
  10.382  
  10.383 -        val le_rel_OO_tacs = map (fn i => K (rtac (le_Jrel_OO_thm RS mk_conjunctN n i) 1)) ks;
  10.384 +        val le_rel_OO_tacs = map (fn i => fn ctxt =>
  10.385 +          rtac ctxt (le_Jrel_OO_thm RS mk_conjunctN n i) 1) ks;
  10.386  
  10.387 -        val rel_OO_Grp_tacs = map (fn def => K (rtac def 1)) Jrel_unabs_defs;
  10.388 +        val rel_OO_Grp_tacs = map (fn def => fn ctxt => rtac ctxt def 1) Jrel_unabs_defs;
  10.389  
  10.390          val tacss = @{map 9} zip_axioms map_id0_tacs map_comp0_tacs map_cong0_tacs set_map0_tacss
  10.391            bd_co_tacs bd_cinf_tacs set_bd_tacss le_rel_OO_tacs rel_OO_Grp_tacs;
    11.1 --- a/src/HOL/Tools/BNF/bnf_gfp_rec_sugar_tactics.ML	Thu Jul 16 10:48:20 2015 +0200
    11.2 +++ b/src/HOL/Tools/BNF/bnf_gfp_rec_sugar_tactics.ML	Thu Jul 16 12:23:22 2015 +0200
    11.3 @@ -65,9 +65,9 @@
    11.4        cut_tac nchotomy THEN'
    11.5        K (exhaust_inst_as_projs_tac ctxt frees) THEN'
    11.6        EVERY' (map (fn k =>
    11.7 -          (if k < n then etac disjE else K all_tac) THEN'
    11.8 -          REPEAT o (dtac meta_mp THEN' atac ORELSE'
    11.9 -            etac conjE THEN' dtac meta_mp THEN' atac ORELSE'
   11.10 +          (if k < n then etac ctxt disjE else K all_tac) THEN'
   11.11 +          REPEAT o (dtac ctxt meta_mp THEN' atac ORELSE'
   11.12 +            etac ctxt conjE THEN' dtac ctxt meta_mp THEN' atac ORELSE'
   11.13              atac))
   11.14          ks))
   11.15    end;
   11.16 @@ -75,26 +75,26 @@
   11.17  fun mk_primcorec_assumption_tac ctxt discIs =
   11.18    SELECT_GOAL (unfold_thms_tac ctxt @{thms fst_conv snd_conv not_not not_False_eq_True
   11.19        not_True_eq_False de_Morgan_conj de_Morgan_disj} THEN
   11.20 -    SOLVE (HEADGOAL (REPEAT o (rtac refl ORELSE' atac ORELSE' etac conjE ORELSE'
   11.21 +    SOLVE (HEADGOAL (REPEAT o (rtac ctxt refl ORELSE' atac ORELSE' etac ctxt conjE ORELSE'
   11.22      eresolve_tac ctxt falseEs ORELSE'
   11.23      resolve_tac ctxt @{thms TrueI conjI disjI1 disjI2} ORELSE'
   11.24      dresolve_tac ctxt discIs THEN' atac ORELSE'
   11.25 -    etac notE THEN' atac ORELSE'
   11.26 -    etac disjE))));
   11.27 +    etac ctxt notE THEN' atac ORELSE'
   11.28 +    etac ctxt disjE))));
   11.29  
   11.30  fun ss_fst_snd_conv ctxt = simpset_of (ss_only @{thms fst_conv snd_conv} ctxt);
   11.31  
   11.32  fun case_atac ctxt = simp_tac (put_simpset (ss_fst_snd_conv ctxt) ctxt);
   11.33  
   11.34  fun same_case_tac ctxt m =
   11.35 -  HEADGOAL (if m = 0 then rtac TrueI
   11.36 -    else REPEAT_DETERM_N (m - 1) o (rtac conjI THEN' case_atac ctxt) THEN' case_atac ctxt);
   11.37 +  HEADGOAL (if m = 0 then rtac ctxt TrueI
   11.38 +    else REPEAT_DETERM_N (m - 1) o (rtac ctxt conjI THEN' case_atac ctxt) THEN' case_atac ctxt);
   11.39  
   11.40  fun different_case_tac ctxt m exclude =
   11.41    HEADGOAL (if m = 0 then
   11.42        mk_primcorec_assumption_tac ctxt []
   11.43      else
   11.44 -      dtac exclude THEN' (REPEAT_DETERM_N (m - 1) o case_atac ctxt) THEN'
   11.45 +      dtac ctxt exclude THEN' (REPEAT_DETERM_N (m - 1) o case_atac ctxt) THEN'
   11.46        mk_primcorec_assumption_tac ctxt []);
   11.47  
   11.48  fun cases_tac ctxt k m excludesss =
   11.49 @@ -105,51 +105,51 @@
   11.50    end;
   11.51  
   11.52  fun prelude_tac ctxt defs thm =
   11.53 -  unfold_thms_tac ctxt defs THEN HEADGOAL (rtac thm) THEN unfold_thms_tac ctxt unfold_lets;
   11.54 +  unfold_thms_tac ctxt defs THEN HEADGOAL (rtac ctxt thm) THEN unfold_thms_tac ctxt unfold_lets;
   11.55  
   11.56  fun mk_primcorec_disc_tac ctxt defs corec_disc k m excludesss =
   11.57    prelude_tac ctxt defs corec_disc THEN cases_tac ctxt k m excludesss;
   11.58  
   11.59  fun mk_primcorec_disc_iff_tac ctxt fun_exhaust_frees fun_exhaust fun_discs fun_discss
   11.60      distinct_discs =
   11.61 -  HEADGOAL (rtac iffI THEN'
   11.62 -    rtac fun_exhaust THEN'
   11.63 +  HEADGOAL (rtac ctxt iffI THEN'
   11.64 +    rtac ctxt fun_exhaust THEN'
   11.65      K (exhaust_inst_as_projs_tac ctxt fun_exhaust_frees) THEN'
   11.66 -    EVERY' (map (fn [] => etac FalseE
   11.67 +    EVERY' (map (fn [] => etac ctxt FalseE
   11.68          | fun_discs' as [fun_disc'] =>
   11.69            if eq_list Thm.eq_thm (fun_discs', fun_discs) then
   11.70 -            REPEAT_DETERM o etac conjI THEN' (atac ORELSE' rtac TrueI)
   11.71 +            REPEAT_DETERM o etac ctxt conjI THEN' (atac ORELSE' rtac ctxt TrueI)
   11.72            else
   11.73 -            rtac FalseE THEN'
   11.74 -            (rotate_tac 1 THEN' dtac fun_disc' THEN' REPEAT o atac ORELSE'
   11.75 +            rtac ctxt FalseE THEN'
   11.76 +            (rotate_tac 1 THEN' dtac ctxt fun_disc' THEN' REPEAT o atac ORELSE'
   11.77               cut_tac fun_disc') THEN'
   11.78 -            dresolve_tac ctxt distinct_discs THEN' etac notE THEN' atac)
   11.79 +            dresolve_tac ctxt distinct_discs THEN' etac ctxt notE THEN' atac)
   11.80        fun_discss) THEN'
   11.81 -    (etac FalseE ORELSE'
   11.82 +    (etac ctxt FalseE ORELSE'
   11.83       resolve_tac ctxt (map (unfold_thms ctxt [atomize_conjL]) fun_discs) THEN_MAYBE' atac));
   11.84  
   11.85  fun mk_primcorec_sel_tac ctxt defs distincts splits split_asms mapsx map_ident0s map_comps fun_sel k
   11.86      m excludesss =
   11.87    prelude_tac ctxt defs (fun_sel RS trans) THEN
   11.88    cases_tac ctxt k m excludesss THEN
   11.89 -  HEADGOAL (REPEAT_DETERM o (rtac refl ORELSE'
   11.90 +  HEADGOAL (REPEAT_DETERM o (rtac ctxt refl ORELSE'
   11.91      eresolve_tac ctxt falseEs ORELSE'
   11.92      resolve_tac ctxt split_connectI ORELSE'
   11.93      Splitter.split_asm_tac ctxt (split_if_asm :: split_asms) ORELSE'
   11.94      Splitter.split_tac ctxt (split_if :: splits) ORELSE'
   11.95      eresolve_tac ctxt (map (fn thm => thm RS neq_eq_eq_contradict) distincts) THEN' atac ORELSE'
   11.96 -    etac notE THEN' atac ORELSE'
   11.97 +    etac ctxt notE THEN' atac ORELSE'
   11.98      (CHANGED o SELECT_GOAL (unfold_thms_tac ctxt (@{thms fst_conv snd_conv id_def comp_def split_def
   11.99           sum.case sum.sel sum.distinct[THEN eq_False[THEN iffD2]]} @
  11.100         mapsx @ map_ident0s @ map_comps))) ORELSE'
  11.101 -    fo_rtac @{thm cong} ctxt ORELSE'
  11.102 -    rtac @{thm ext} ORELSE'
  11.103 +    fo_rtac ctxt @{thm cong} ORELSE'
  11.104 +    rtac ctxt @{thm ext} ORELSE'
  11.105      mk_primcorec_assumption_tac ctxt []));
  11.106  
  11.107  fun mk_primcorec_ctr_tac ctxt m collapse disc_fun_opt sel_funs =
  11.108 -  HEADGOAL (rtac ((if null sel_funs then collapse else collapse RS sym) RS trans) THEN'
  11.109 -    (the_default (K all_tac) (Option.map rtac disc_fun_opt)) THEN' REPEAT_DETERM_N m o atac) THEN
  11.110 -  unfold_thms_tac ctxt (@{thm split_def} :: unfold_lets @ sel_funs) THEN HEADGOAL (rtac refl);
  11.111 +  HEADGOAL (rtac ctxt ((if null sel_funs then collapse else collapse RS sym) RS trans) THEN'
  11.112 +    (the_default (K all_tac) (Option.map (rtac ctxt) disc_fun_opt)) THEN' REPEAT_DETERM_N m o atac) THEN
  11.113 +  unfold_thms_tac ctxt (@{thm split_def} :: unfold_lets @ sel_funs) THEN HEADGOAL (rtac ctxt refl);
  11.114  
  11.115  fun inst_split_eq ctxt split =
  11.116    (case Thm.prop_of split of
  11.117 @@ -172,13 +172,13 @@
  11.118      prelude_tac ctxt [] (fun_ctr RS trans) THEN
  11.119      HEADGOAL ((REPEAT_DETERM_N m o mk_primcorec_assumption_tac ctxt discIs) THEN'
  11.120        SELECT_GOAL (SOLVE (HEADGOAL (REPEAT_DETERM o
  11.121 -      (rtac refl ORELSE' atac ORELSE'
  11.122 +      (rtac ctxt refl ORELSE' atac ORELSE'
  11.123         resolve_tac ctxt (@{thm Code.abort_def} :: split_connectI) ORELSE'
  11.124         Splitter.split_tac ctxt (split_if :: splits) ORELSE'
  11.125         Splitter.split_asm_tac ctxt (split_if_asm :: split_asms) ORELSE'
  11.126         mk_primcorec_assumption_tac ctxt discIs ORELSE'
  11.127         distinct_in_prems_tac distincts ORELSE'
  11.128 -       (TRY o dresolve_tac ctxt discIs) THEN' etac notE THEN' atac)))))
  11.129 +       (TRY o dresolve_tac ctxt discIs) THEN' etac ctxt notE THEN' atac)))))
  11.130    end;
  11.131  
  11.132  fun rulify_nchotomy n = funpow (n - 1) (fn thm => thm RS @{thm Meson.make_pos_rule'});
  11.133 @@ -203,13 +203,13 @@
  11.134    end;
  11.135  
  11.136  fun mk_primcorec_code_tac ctxt distincts splits raw =
  11.137 -  HEADGOAL (rtac raw ORELSE' rtac (raw RS trans) THEN'
  11.138 +  HEADGOAL (rtac ctxt raw ORELSE' rtac ctxt (raw RS trans) THEN'
  11.139      SELECT_GOAL (unfold_thms_tac ctxt unfold_lets) THEN' REPEAT_DETERM o
  11.140 -    (rtac refl ORELSE' atac ORELSE'
  11.141 +    (rtac ctxt refl ORELSE' atac ORELSE'
  11.142       resolve_tac ctxt split_connectI ORELSE'
  11.143       Splitter.split_tac ctxt (split_if :: splits) ORELSE'
  11.144       distinct_in_prems_tac distincts ORELSE'
  11.145 -     rtac sym THEN' atac ORELSE'
  11.146 -     etac notE THEN' atac));
  11.147 +     rtac ctxt sym THEN' atac ORELSE'
  11.148 +     etac ctxt notE THEN' atac));
  11.149  
  11.150  end;
    12.1 --- a/src/HOL/Tools/BNF/bnf_gfp_tactics.ML	Thu Jul 16 10:48:20 2015 +0200
    12.2 +++ b/src/HOL/Tools/BNF/bnf_gfp_tactics.ML	Thu Jul 16 12:23:22 2015 +0200
    12.3 @@ -12,82 +12,83 @@
    12.4    val mk_bis_Gr_tac: Proof.context -> thm -> thm list -> thm list -> thm list -> thm list -> tactic
    12.5    val mk_bis_O_tac: Proof.context -> int -> thm -> thm list -> thm list -> tactic
    12.6    val mk_bis_Union_tac: Proof.context -> thm -> thm list -> tactic
    12.7 -  val mk_bis_converse_tac: int -> thm -> thm list -> thm list -> tactic
    12.8 -  val mk_bis_rel_tac: int -> thm -> thm list -> thm list -> thm list ->
    12.9 +  val mk_bis_converse_tac: Proof.context -> int -> thm -> thm list -> thm list -> tactic
   12.10 +  val mk_bis_rel_tac: Proof.context -> int -> thm -> thm list -> thm list -> thm list ->
   12.11      thm list list -> tactic
   12.12    val mk_coalgT_tac: Proof.context -> int -> thm list -> thm list -> thm list list -> tactic
   12.13 -  val mk_coalg_final_tac: int -> thm -> thm list -> thm list -> thm list list -> thm list list ->
   12.14 -    tactic
   12.15 -  val mk_coalg_set_tac: thm -> tactic
   12.16 +  val mk_coalg_final_tac: Proof.context -> int -> thm -> thm list -> thm list -> thm list list ->
   12.17 +    thm list list -> tactic
   12.18 +  val mk_coalg_set_tac: Proof.context -> thm -> tactic
   12.19    val mk_coind_wit_tac: Proof.context -> thm -> thm list -> thm list -> thm list -> tactic
   12.20 -  val mk_col_bd_tac: int -> int -> cterm option list -> thm list -> thm list -> thm -> thm ->
   12.21 -    thm list list -> tactic
   12.22 +  val mk_col_bd_tac: Proof.context -> int -> int -> cterm option list -> thm list -> thm list ->
   12.23 +    thm -> thm -> thm list list -> tactic
   12.24    val mk_col_natural_tac: Proof.context -> cterm option list -> thm list -> thm list -> thm list ->
   12.25      thm list list -> tactic
   12.26 -  val mk_congruent_str_final_tac: int -> thm -> thm -> thm -> thm list -> tactic
   12.27 +  val mk_congruent_str_final_tac: Proof.context -> int -> thm -> thm -> thm -> thm list -> tactic
   12.28    val mk_corec_tac: Proof.context -> int -> thm list -> thm -> thm -> thm list -> tactic
   12.29    val mk_corec_unique_mor_tac: Proof.context -> thm list -> thm list -> thm -> tactic
   12.30 -  val mk_dtor_coinduct_tac: int -> thm -> thm -> thm list -> tactic
   12.31 +  val mk_dtor_coinduct_tac: Proof.context -> int -> thm -> thm -> thm list -> tactic
   12.32    val mk_dtor_corec_transfer_tac: Proof.context -> int -> int -> thm list -> thm list -> thm list ->
   12.33      thm list -> tactic
   12.34    val mk_dtor_rel_tac: Proof.context -> thm list -> int -> thm -> thm -> thm -> thm -> thm list ->
   12.35      thm -> thm -> thm list -> thm list -> thm list list -> tactic
   12.36    val mk_dtor_o_ctor_tac: Proof.context -> thm -> thm -> thm -> thm -> thm list -> tactic
   12.37 -  val mk_equiv_lsbis_tac: thm -> thm -> thm -> thm -> thm -> thm -> tactic
   12.38 +  val mk_equiv_lsbis_tac: Proof.context -> thm -> thm -> thm -> thm -> thm -> thm -> tactic
   12.39    val mk_Jset_minimal_tac: Proof.context -> int -> thm -> tactic
   12.40    val mk_col_minimal_tac: Proof.context -> int -> cterm option list -> thm list -> thm list ->
   12.41      tactic
   12.42 -  val mk_incl_lsbis_tac: int -> int -> thm -> tactic
   12.43 -  val mk_length_Lev'_tac: thm -> tactic
   12.44 +  val mk_incl_lsbis_tac: Proof.context -> int -> int -> thm -> tactic
   12.45 +  val mk_length_Lev'_tac: Proof.context -> thm -> tactic
   12.46    val mk_length_Lev_tac: Proof.context -> cterm option list -> thm list -> thm list -> tactic
   12.47 -  val mk_map_comp0_tac: thm list -> thm list -> thm -> tactic
   12.48 +  val mk_map_comp0_tac: Proof.context -> thm list -> thm list -> thm -> tactic
   12.49    val mk_mcong_tac: Proof.context -> int -> (int -> tactic) -> thm list -> thm list -> thm list ->
   12.50      thm list list -> thm list list -> thm list list list -> thm list -> tactic
   12.51 -  val mk_map_id0_tac: thm list -> thm -> thm -> tactic
   12.52 -  val mk_map_tac: int -> int -> thm -> thm -> thm -> thm -> tactic
   12.53 +  val mk_map_id0_tac: Proof.context -> thm list -> thm -> thm -> tactic
   12.54 +  val mk_map_tac: Proof.context -> int -> int -> thm -> thm -> thm -> thm -> tactic
   12.55    val mk_dtor_map_unique_tac: Proof.context -> thm -> thm list -> tactic
   12.56    val mk_mor_Abs_tac: Proof.context -> thm list -> thm list -> tactic
   12.57    val mk_mor_Rep_tac: Proof.context -> thm list -> thm list -> thm list -> thm list list ->
   12.58      thm list -> thm list -> tactic
   12.59 -  val mk_mor_T_final_tac: thm -> thm list -> thm list -> tactic
   12.60 -  val mk_mor_UNIV_tac: thm list -> thm -> tactic
   12.61 +  val mk_mor_T_final_tac: Proof.context -> thm -> thm list -> thm list -> tactic
   12.62 +  val mk_mor_UNIV_tac: Proof.context -> thm list -> thm -> tactic
   12.63    val mk_mor_beh_tac: Proof.context -> int -> thm -> thm -> thm list -> thm list -> thm list ->
   12.64      thm list -> thm list list -> thm list list -> thm list -> thm list -> thm list -> thm list ->
   12.65      thm list -> thm list -> thm list list -> thm list list list -> thm list list list ->
   12.66      thm list list -> thm list -> thm list -> tactic
   12.67 -  val mk_mor_case_sum_tac: 'a list -> thm -> tactic
   12.68 +  val mk_mor_case_sum_tac: Proof.context -> 'a list -> thm -> tactic
   12.69    val mk_mor_comp_tac: Proof.context -> thm -> thm list -> thm list -> thm list -> tactic
   12.70 -  val mk_mor_elim_tac: thm -> tactic
   12.71 -  val mk_mor_col_tac: int -> int -> cterm option list -> int -> thm list -> thm list ->
   12.72 -    thm list -> thm list list -> thm list list -> tactic
   12.73 -  val mk_mor_incl_tac: thm -> thm list -> tactic
   12.74 -  val mk_mor_str_tac: 'a list -> thm -> tactic
   12.75 -  val mk_mor_unfold_tac: int -> thm -> thm list -> thm list -> thm list -> thm list -> thm list ->
   12.76 -    thm list -> tactic
   12.77 -  val mk_raw_coind_tac: thm -> thm -> thm -> thm -> thm -> thm -> thm -> thm -> thm -> thm list ->
   12.78 -    thm list -> thm list -> thm -> thm list -> tactic
   12.79 +  val mk_mor_elim_tac: Proof.context -> thm -> tactic
   12.80 +  val mk_mor_col_tac: Proof.context -> int -> int -> cterm option list -> int -> thm list ->
   12.81 +    thm list -> thm list -> thm list list -> thm list list -> tactic
   12.82 +  val mk_mor_incl_tac: Proof.context -> thm -> thm list -> tactic
   12.83 +  val mk_mor_str_tac: Proof.context -> 'a list -> thm -> tactic
   12.84 +  val mk_mor_unfold_tac: Proof.context -> int -> thm -> thm list -> thm list -> thm list ->
   12.85 +    thm list -> thm list -> thm list -> tactic
   12.86 +  val mk_raw_coind_tac: Proof.context -> thm -> thm -> thm -> thm -> thm -> thm -> thm -> thm ->
   12.87 +    thm -> thm list -> thm list -> thm list -> thm -> thm list -> tactic
   12.88    val mk_rel_coinduct_tac: Proof.context -> thm list -> thm list -> thm list -> thm list list ->
   12.89      thm list -> thm list -> tactic
   12.90    val mk_rel_coinduct_coind_tac: Proof.context -> bool -> int -> thm -> int list -> thm list ->
   12.91      thm list -> thm list -> thm list list -> thm list -> thm list -> thm list -> tactic
   12.92    val mk_rel_coinduct_ind_tac: Proof.context -> int -> int list -> thm list -> thm list list ->
   12.93      int -> thm -> tactic
   12.94 -  val mk_rv_last_tac: ctyp option list -> cterm option list -> thm list -> thm list -> tactic
   12.95 +  val mk_rv_last_tac: Proof.context -> ctyp option list -> cterm option list -> thm list ->
   12.96 +    thm list -> tactic
   12.97    val mk_sbis_lsbis_tac: Proof.context -> thm list -> thm -> thm -> tactic
   12.98    val mk_set_Lev_tac: Proof.context -> cterm option list -> thm list -> thm list -> thm list ->
   12.99      thm list -> thm list list -> tactic
  12.100 -  val mk_set_bd_tac: thm -> thm -> tactic
  12.101 -  val mk_set_Jset_incl_Jset_tac: int -> thm -> int -> tactic
  12.102 +  val mk_set_bd_tac: Proof.context -> thm -> thm -> tactic
  12.103 +  val mk_set_Jset_incl_Jset_tac: Proof.context -> int -> thm -> int -> tactic
  12.104    val mk_set_image_Lev_tac: Proof.context -> cterm option list -> thm list -> thm list ->
  12.105      thm list -> thm list -> thm list list -> thm list list -> tactic
  12.106 -  val mk_set_incl_Jset_tac: thm -> tactic
  12.107 -  val mk_set_ge_tac: int  -> thm -> thm list -> tactic
  12.108 -  val mk_set_le_tac: int -> thm -> thm list -> thm list list -> tactic
  12.109 -  val mk_set_map0_tac: thm -> tactic
  12.110 -  val mk_unfold_unique_mor_tac: thm list -> thm -> thm -> thm list -> tactic
  12.111 +  val mk_set_incl_Jset_tac: Proof.context -> thm -> tactic
  12.112 +  val mk_set_ge_tac: Proof.context -> int  -> thm -> thm list -> tactic
  12.113 +  val mk_set_le_tac: Proof.context -> int -> thm -> thm list -> thm list list -> tactic
  12.114 +  val mk_set_map0_tac: Proof.context -> thm -> tactic
  12.115 +  val mk_unfold_unique_mor_tac: Proof.context -> thm list -> thm -> thm -> thm list -> tactic
  12.116    val mk_unfold_transfer_tac: Proof.context -> int -> thm -> thm list -> thm list -> tactic
  12.117    val mk_wit_tac: Proof.context -> int -> thm list -> thm list -> thm list -> thm list -> tactic
  12.118 -  val mk_le_rel_OO_tac: thm -> thm list -> thm list -> tactic
  12.119 +  val mk_le_rel_OO_tac: Proof.context -> thm -> thm list -> thm list -> tactic
  12.120  end;
  12.121  
  12.122  structure BNF_GFP_Tactics : BNF_GFP_TACTICS =
  12.123 @@ -112,196 +113,196 @@
  12.124  val Un_cong = @{thm arg_cong2[of _ _ _ _ "op \<union>"]};
  12.125  val converse_shift = @{thm converse_subset_swap} RS iffD1;
  12.126  
  12.127 -fun mk_coalg_set_tac coalg_def =
  12.128 -  dtac (coalg_def RS iffD1) 1 THEN
  12.129 -  REPEAT_DETERM (etac conjE 1) THEN
  12.130 -  EVERY' [dtac rev_bspec, atac] 1 THEN
  12.131 +fun mk_coalg_set_tac ctxt coalg_def =
  12.132 +  dtac ctxt (coalg_def RS iffD1) 1 THEN
  12.133 +  REPEAT_DETERM (etac ctxt conjE 1) THEN
  12.134 +  EVERY' [dtac ctxt rev_bspec, atac] 1 THEN
  12.135    REPEAT_DETERM (eresolve0_tac [CollectE, conjE] 1) THEN atac 1;
  12.136  
  12.137 -fun mk_mor_elim_tac mor_def =
  12.138 -  (dtac (mor_def RS iffD1) THEN'
  12.139 -  REPEAT o etac conjE THEN'
  12.140 -  TRY o rtac @{thm image_subsetI} THEN'
  12.141 -  etac bspec THEN'
  12.142 +fun mk_mor_elim_tac ctxt mor_def =
  12.143 +  (dtac ctxt (mor_def RS iffD1) THEN'
  12.144 +  REPEAT o etac ctxt conjE THEN'
  12.145 +  TRY o rtac ctxt @{thm image_subsetI} THEN'
  12.146 +  etac ctxt bspec THEN'
  12.147    atac) 1;
  12.148  
  12.149 -fun mk_mor_incl_tac mor_def map_ids =
  12.150 -  (rtac (mor_def RS iffD2) THEN'
  12.151 -  rtac conjI THEN'
  12.152 -  CONJ_WRAP' (K (EVERY' [rtac ballI, etac set_mp, etac (id_apply RS @{thm ssubst_mem})]))
  12.153 +fun mk_mor_incl_tac ctxt mor_def map_ids =
  12.154 +  (rtac ctxt (mor_def RS iffD2) THEN'
  12.155 +  rtac ctxt conjI THEN'
  12.156 +  CONJ_WRAP' (K (EVERY' [rtac ctxt ballI, etac ctxt set_mp, etac ctxt (id_apply RS @{thm ssubst_mem})]))
  12.157      map_ids THEN'
  12.158    CONJ_WRAP' (fn thm =>
  12.159 -    (EVERY' [rtac ballI, rtac (thm RS trans), rtac sym, rtac (id_apply RS arg_cong)])) map_ids) 1;
  12.160 +    (EVERY' [rtac ctxt ballI, rtac ctxt (thm RS trans), rtac ctxt sym, rtac ctxt (id_apply RS arg_cong)])) map_ids) 1;
  12.161  
  12.162  fun mk_mor_comp_tac ctxt mor_def mor_images morEs map_comp_ids =
  12.163    let
  12.164 -    fun fbetw_tac image = EVERY' [rtac ballI, rtac (o_apply RS @{thm ssubst_mem}), etac image,
  12.165 -      etac image, atac];
  12.166 +    fun fbetw_tac image = EVERY' [rtac ctxt ballI, rtac ctxt (o_apply RS @{thm ssubst_mem}), etac ctxt image,
  12.167 +      etac ctxt image, atac];
  12.168      fun mor_tac ((mor_image, morE), map_comp_id) =
  12.169 -      EVERY' [rtac ballI, stac ctxt o_apply, rtac trans, rtac (map_comp_id RS sym), rtac trans,
  12.170 -        etac (morE RS arg_cong), atac, etac morE, etac mor_image, atac];
  12.171 +      EVERY' [rtac ctxt ballI, stac ctxt o_apply, rtac ctxt trans, rtac ctxt (map_comp_id RS sym), rtac ctxt trans,
  12.172 +        etac ctxt (morE RS arg_cong), atac, etac ctxt morE, etac ctxt mor_image, atac];
  12.173    in
  12.174 -    (rtac (mor_def RS iffD2) THEN' rtac conjI THEN'
  12.175 +    (rtac ctxt (mor_def RS iffD2) THEN' rtac ctxt conjI THEN'
  12.176      CONJ_WRAP' fbetw_tac mor_images THEN'
  12.177      CONJ_WRAP' mor_tac ((mor_images ~~ morEs) ~~ map_comp_ids)) 1
  12.178    end;
  12.179  
  12.180 -fun mk_mor_UNIV_tac morEs mor_def =
  12.181 +fun mk_mor_UNIV_tac ctxt morEs mor_def =
  12.182    let
  12.183      val n = length morEs;
  12.184 -    fun mor_tac morE = EVERY' [rtac @{thm ext}, rtac trans, rtac o_apply, rtac trans, etac morE,
  12.185 -      rtac UNIV_I, rtac sym, rtac o_apply];
  12.186 +    fun mor_tac morE = EVERY' [rtac ctxt @{thm ext}, rtac ctxt trans, rtac ctxt o_apply, rtac ctxt trans, etac ctxt morE,
  12.187 +      rtac ctxt UNIV_I, rtac ctxt sym, rtac ctxt o_apply];
  12.188    in
  12.189 -    EVERY' [rtac iffI, CONJ_WRAP' mor_tac morEs,
  12.190 -    rtac (mor_def RS iffD2), rtac conjI, CONJ_WRAP' (K (rtac ballI THEN' rtac UNIV_I)) morEs,
  12.191 +    EVERY' [rtac ctxt iffI, CONJ_WRAP' mor_tac morEs,
  12.192 +    rtac ctxt (mor_def RS iffD2), rtac ctxt conjI, CONJ_WRAP' (K (rtac ctxt ballI THEN' rtac ctxt UNIV_I)) morEs,
  12.193      CONJ_WRAP' (fn i =>
  12.194 -      EVERY' [dtac (mk_conjunctN n i), rtac ballI, etac @{thm comp_eq_dest}]) (1 upto n)] 1
  12.195 +      EVERY' [dtac ctxt (mk_conjunctN n i), rtac ctxt ballI, etac ctxt @{thm comp_eq_dest}]) (1 upto n)] 1
  12.196    end;
  12.197  
  12.198 -fun mk_mor_str_tac ks mor_UNIV =
  12.199 -  (rtac (mor_UNIV RS iffD2) THEN' CONJ_WRAP' (K (rtac refl)) ks) 1;
  12.200 +fun mk_mor_str_tac ctxt ks mor_UNIV =
  12.201 +  (rtac ctxt (mor_UNIV RS iffD2) THEN' CONJ_WRAP' (K (rtac ctxt refl)) ks) 1;
  12.202  
  12.203 -fun mk_mor_case_sum_tac ks mor_UNIV =
  12.204 -  (rtac (mor_UNIV RS iffD2) THEN' CONJ_WRAP' (K (rtac @{thm case_sum_o_inj(1)[symmetric]})) ks) 1;
  12.205 +fun mk_mor_case_sum_tac ctxt ks mor_UNIV =
  12.206 +  (rtac ctxt (mor_UNIV RS iffD2) THEN' CONJ_WRAP' (K (rtac ctxt @{thm case_sum_o_inj(1)[symmetric]})) ks) 1;
  12.207  
  12.208 -fun mk_set_incl_Jset_tac rec_Suc =
  12.209 -  EVERY' (map rtac [@{thm SUP_upper2}, UNIV_I, @{thm ord_le_eq_trans}, @{thm Un_upper1}, sym,
  12.210 +fun mk_set_incl_Jset_tac ctxt rec_Suc =
  12.211 +  EVERY' (map (rtac ctxt) [@{thm SUP_upper2}, UNIV_I, @{thm ord_le_eq_trans}, @{thm Un_upper1}, sym,
  12.212      rec_Suc]) 1;
  12.213  
  12.214 -fun mk_set_Jset_incl_Jset_tac n rec_Suc i =
  12.215 -  EVERY' (map rtac [@{thm UN_least}, subsetI, @{thm UN_I}, UNIV_I, set_mp, equalityD2, rec_Suc,
  12.216 -      UnI2, mk_UnIN n i] @ [etac @{thm UN_I}, atac]) 1;
  12.217 +fun mk_set_Jset_incl_Jset_tac ctxt n rec_Suc i =
  12.218 +  EVERY' (map (rtac ctxt) [@{thm UN_least}, subsetI, @{thm UN_I}, UNIV_I, set_mp, equalityD2,
  12.219 +    rec_Suc, UnI2, mk_UnIN n i] @ [etac ctxt @{thm UN_I}, atac]) 1;
  12.220  
  12.221  fun mk_col_minimal_tac ctxt m cts rec_0s rec_Sucs =
  12.222 -  EVERY' [rtac (Drule.instantiate' [] cts nat_induct),
  12.223 -    REPEAT_DETERM o rtac allI,
  12.224 +  EVERY' [rtac ctxt (Drule.instantiate' [] cts nat_induct),
  12.225 +    REPEAT_DETERM o rtac ctxt allI,
  12.226      CONJ_WRAP' (fn thm => EVERY'
  12.227 -      [rtac ord_eq_le_trans, rtac thm, rtac @{thm empty_subsetI}]) rec_0s,
  12.228 -    REPEAT_DETERM o rtac allI,
  12.229 +      [rtac ctxt ord_eq_le_trans, rtac ctxt thm, rtac ctxt @{thm empty_subsetI}]) rec_0s,
  12.230 +    REPEAT_DETERM o rtac ctxt allI,
  12.231      CONJ_WRAP' (fn rec_Suc => EVERY'
  12.232 -      [rtac ord_eq_le_trans, rtac rec_Suc,
  12.233 +      [rtac ctxt ord_eq_le_trans, rtac ctxt rec_Suc,
  12.234          if m = 0 then K all_tac
  12.235 -        else (rtac @{thm Un_least} THEN' Goal.assume_rule_tac ctxt),
  12.236 -        CONJ_WRAP_GEN' (rtac (Thm.permute_prems 0 1 @{thm Un_least}))
  12.237 -          (K (EVERY' [rtac @{thm UN_least}, REPEAT_DETERM o eresolve_tac ctxt [allE, conjE],
  12.238 -            rtac subset_trans, atac, Goal.assume_rule_tac ctxt])) rec_0s])
  12.239 +        else (rtac ctxt @{thm Un_least} THEN' Goal.assume_rule_tac ctxt),
  12.240 +        CONJ_WRAP_GEN' (rtac ctxt (Thm.permute_prems 0 1 @{thm Un_least}))
  12.241 +          (K (EVERY' [rtac ctxt @{thm UN_least}, REPEAT_DETERM o eresolve_tac ctxt [allE, conjE],
  12.242 +            rtac ctxt subset_trans, atac, Goal.assume_rule_tac ctxt])) rec_0s])
  12.243        rec_Sucs] 1;
  12.244  
  12.245  fun mk_Jset_minimal_tac ctxt n col_minimal =
  12.246 -  (CONJ_WRAP' (K (EVERY' [rtac @{thm UN_least}, rtac rev_mp, rtac col_minimal,
  12.247 -    EVERY' (replicate ((n + 1) * n) (Goal.assume_rule_tac ctxt)), rtac impI,
  12.248 +  (CONJ_WRAP' (K (EVERY' [rtac ctxt @{thm UN_least}, rtac ctxt rev_mp, rtac ctxt col_minimal,
  12.249 +    EVERY' (replicate ((n + 1) * n) (Goal.assume_rule_tac ctxt)), rtac ctxt impI,
  12.250      REPEAT_DETERM o eresolve_tac ctxt [allE, conjE], atac])) (1 upto n)) 1
  12.251  
  12.252 -fun mk_mor_col_tac m n cts j rec_0s rec_Sucs morEs set_map0ss coalg_setss =
  12.253 -  EVERY' [rtac (Drule.instantiate' [] cts nat_induct),
  12.254 -    REPEAT_DETERM o rtac allI,
  12.255 -    CONJ_WRAP' (fn thm => EVERY' (map rtac [impI, thm RS trans, thm RS sym])) rec_0s,
  12.256 -    REPEAT_DETERM o rtac allI,
  12.257 +fun mk_mor_col_tac ctxt m n cts j rec_0s rec_Sucs morEs set_map0ss coalg_setss =
  12.258 +  EVERY' [rtac ctxt (Drule.instantiate' [] cts nat_induct),
  12.259 +    REPEAT_DETERM o rtac ctxt allI,
  12.260 +    CONJ_WRAP' (fn thm => EVERY' (map (rtac ctxt) [impI, thm RS trans, thm RS sym])) rec_0s,
  12.261 +    REPEAT_DETERM o rtac ctxt allI,
  12.262      CONJ_WRAP'
  12.263        (fn (rec_Suc, (morE, ((passive_set_map0s, active_set_map0s), coalg_sets))) =>
  12.264 -        EVERY' [rtac impI, rtac (rec_Suc RS trans), rtac (rec_Suc RS trans RS sym),
  12.265 +        EVERY' [rtac ctxt impI, rtac ctxt (rec_Suc RS trans), rtac ctxt (rec_Suc RS trans RS sym),
  12.266            if m = 0 then K all_tac
  12.267 -          else EVERY' [rtac Un_cong, rtac @{thm box_equals},
  12.268 -            rtac (nth passive_set_map0s (j - 1) RS sym),
  12.269 -            rtac trans_fun_cong_image_id_id_apply, etac (morE RS arg_cong), atac],
  12.270 -          CONJ_WRAP_GEN' (rtac (Thm.permute_prems 0 1 Un_cong))
  12.271 +          else EVERY' [rtac ctxt Un_cong, rtac ctxt @{thm box_equals},
  12.272 +            rtac ctxt (nth passive_set_map0s (j - 1) RS sym),
  12.273 +            rtac ctxt trans_fun_cong_image_id_id_apply, etac ctxt (morE RS arg_cong), atac],
  12.274 +          CONJ_WRAP_GEN' (rtac ctxt (Thm.permute_prems 0 1 Un_cong))
  12.275              (fn (i, (set_map0, coalg_set)) =>
  12.276 -              EVERY' [rtac sym, rtac trans, rtac (refl RSN (2, @{thm SUP_cong})),
  12.277 -                etac (morE RS sym RS arg_cong RS trans), atac, rtac set_map0,
  12.278 -                rtac (@{thm UN_simps(10)} RS trans), rtac (refl RS @{thm SUP_cong}),
  12.279 -                ftac coalg_set, atac, dtac set_mp, atac, rtac mp, rtac (mk_conjunctN n i),
  12.280 -                REPEAT_DETERM o etac allE, atac, atac])
  12.281 +              EVERY' [rtac ctxt sym, rtac ctxt trans, rtac ctxt (refl RSN (2, @{thm SUP_cong})),
  12.282 +                etac ctxt (morE RS sym RS arg_cong RS trans), atac, rtac ctxt set_map0,
  12.283 +                rtac ctxt (@{thm UN_simps(10)} RS trans), rtac ctxt (refl RS @{thm SUP_cong}),
  12.284 +                ftac ctxt coalg_set, atac, dtac ctxt set_mp, atac, rtac ctxt mp, rtac ctxt (mk_conjunctN n i),
  12.285 +                REPEAT_DETERM o etac ctxt allE, atac, atac])
  12.286              (rev ((1 upto n) ~~ (active_set_map0s ~~ coalg_sets)))])
  12.287        (rec_Sucs ~~ (morEs ~~ (map (chop m) set_map0ss ~~ map (drop m) coalg_setss)))] 1;
  12.288  
  12.289 -fun mk_bis_rel_tac m bis_def in_rels map_comp0s map_cong0s set_map0ss =
  12.290 +fun mk_bis_rel_tac ctxt m bis_def in_rels map_comp0s map_cong0s set_map0ss =
  12.291    let
  12.292      val n = length in_rels;
  12.293      val thms = ((1 upto n) ~~ map_comp0s ~~ map_cong0s ~~ set_map0ss ~~ in_rels);
  12.294  
  12.295      fun mk_if_tac ((((i, map_comp0), map_cong0), set_map0s), in_rel) =
  12.296 -      EVERY' [rtac allI, rtac allI, rtac impI, dtac (mk_conjunctN n i),
  12.297 -        etac allE, etac allE, etac impE, atac, etac bexE,
  12.298 +      EVERY' [rtac ctxt allI, rtac ctxt allI, rtac ctxt impI, dtac ctxt (mk_conjunctN n i),
  12.299 +        etac ctxt allE, etac ctxt allE, etac ctxt impE, atac, etac ctxt bexE,
  12.300          REPEAT_DETERM o eresolve0_tac [CollectE, conjE],
  12.301 -        rtac (in_rel RS iffD2), rtac exI, rtac (Drule.rotate_prems 1 conjI),
  12.302 -        CONJ_WRAP' (fn thm => EVERY' [rtac trans, rtac trans, rtac map_comp0, rtac map_cong0,
  12.303 -          REPEAT_DETERM_N m o rtac thm, REPEAT_DETERM_N n o rtac (@{thm comp_id} RS fun_cong),
  12.304 +        rtac ctxt (in_rel RS iffD2), rtac ctxt exI, rtac ctxt (Drule.rotate_prems 1 conjI),
  12.305 +        CONJ_WRAP' (fn thm => EVERY' [rtac ctxt trans, rtac ctxt trans, rtac ctxt map_comp0, rtac ctxt map_cong0,
  12.306 +          REPEAT_DETERM_N m o rtac ctxt thm, REPEAT_DETERM_N n o rtac ctxt (@{thm comp_id} RS fun_cong),
  12.307            atac])
  12.308          @{thms fst_diag_id snd_diag_id},
  12.309 -        rtac CollectI,
  12.310 +        rtac ctxt CollectI,
  12.311          CONJ_WRAP' (fn (i, thm) =>
  12.312            if i <= m
  12.313 -          then EVERY' [rtac ord_eq_le_trans, rtac thm, rtac subset_trans,
  12.314 -            etac @{thm image_mono}, rtac @{thm image_subsetI}, rtac CollectI,
  12.315 -            rtac @{thm case_prodI}, rtac refl]
  12.316 -          else EVERY' [rtac ord_eq_le_trans, rtac trans, rtac thm,
  12.317 -            rtac trans_fun_cong_image_id_id_apply, etac @{thm Collect_split_in_rel_leI}])
  12.318 +          then EVERY' [rtac ctxt ord_eq_le_trans, rtac ctxt thm, rtac ctxt subset_trans,
  12.319 +            etac ctxt @{thm image_mono}, rtac ctxt @{thm image_subsetI}, rtac ctxt CollectI,
  12.320 +            rtac ctxt @{thm case_prodI}, rtac ctxt refl]
  12.321 +          else EVERY' [rtac ctxt ord_eq_le_trans, rtac ctxt trans, rtac ctxt thm,
  12.322 +            rtac ctxt trans_fun_cong_image_id_id_apply, etac ctxt @{thm Collect_split_in_rel_leI}])
  12.323          (1 upto (m + n) ~~ set_map0s)];
  12.324  
  12.325      fun mk_only_if_tac ((((i, map_comp0), map_cong0), set_map0s), in_rel) =
  12.326 -      EVERY' [dtac (mk_conjunctN n i), rtac allI, rtac allI, rtac impI,
  12.327 -        etac allE, etac allE, etac impE, atac,
  12.328 -        dtac (in_rel RS @{thm iffD1}),
  12.329 +      EVERY' [dtac ctxt (mk_conjunctN n i), rtac ctxt allI, rtac ctxt allI, rtac ctxt impI,
  12.330 +        etac ctxt allE, etac ctxt allE, etac ctxt impE, atac,
  12.331 +        dtac ctxt (in_rel RS @{thm iffD1}),
  12.332          REPEAT_DETERM o eresolve0_tac ([CollectE, conjE, exE] @
  12.333            @{thms CollectE Collect_split_in_rel_leE}),
  12.334 -        rtac bexI, rtac conjI, rtac trans, rtac map_comp0, rtac trans, rtac map_cong0,
  12.335 -        REPEAT_DETERM_N m o rtac (@{thm id_comp} RS fun_cong),
  12.336 -        REPEAT_DETERM_N n o rtac (@{thm comp_id} RS fun_cong),
  12.337 -        atac, rtac trans, rtac map_comp0, rtac trans, rtac map_cong0,
  12.338 -        REPEAT_DETERM_N m o rtac (@{thm id_comp} RS fun_cong),
  12.339 -        REPEAT_DETERM_N n o rtac (@{thm comp_id} RS fun_cong),
  12.340 -        rtac trans, rtac map_cong0,
  12.341 -        REPEAT_DETERM_N m o EVERY' [rtac @{thm Collect_splitD}, etac set_mp, atac],
  12.342 -        REPEAT_DETERM_N n o rtac refl,
  12.343 -        atac, rtac CollectI,
  12.344 +        rtac ctxt bexI, rtac ctxt conjI, rtac ctxt trans, rtac ctxt map_comp0, rtac ctxt trans, rtac ctxt map_cong0,
  12.345 +        REPEAT_DETERM_N m o rtac ctxt (@{thm id_comp} RS fun_cong),
  12.346 +        REPEAT_DETERM_N n o rtac ctxt (@{thm comp_id} RS fun_cong),
  12.347 +        atac, rtac ctxt trans, rtac ctxt map_comp0, rtac ctxt trans, rtac ctxt map_cong0,
  12.348 +        REPEAT_DETERM_N m o rtac ctxt (@{thm id_comp} RS fun_cong),
  12.349 +        REPEAT_DETERM_N n o rtac ctxt (@{thm comp_id} RS fun_cong),
  12.350 +        rtac ctxt trans, rtac ctxt map_cong0,
  12.351 +        REPEAT_DETERM_N m o EVERY' [rtac ctxt @{thm Collect_splitD}, etac ctxt set_mp, atac],
  12.352 +        REPEAT_DETERM_N n o rtac ctxt refl,
  12.353 +        atac, rtac ctxt CollectI,
  12.354          CONJ_WRAP' (fn (i, thm) =>
  12.355 -          if i <= m then rtac subset_UNIV
  12.356 -          else EVERY' [rtac ord_eq_le_trans, rtac trans, rtac thm,
  12.357 -            rtac trans_fun_cong_image_id_id_apply, atac])
  12.358 +          if i <= m then rtac ctxt subset_UNIV
  12.359 +          else EVERY' [rtac ctxt ord_eq_le_trans, rtac ctxt trans, rtac ctxt thm,
  12.360 +            rtac ctxt trans_fun_cong_image_id_id_apply, atac])
  12.361          (1 upto (m + n) ~~ set_map0s)];
  12.362    in
  12.363 -    EVERY' [rtac (bis_def RS trans),
  12.364 -      rtac iffI, etac conjE, etac conjI, CONJ_WRAP' mk_if_tac thms,
  12.365 -      etac conjE, etac conjI, CONJ_WRAP' mk_only_if_tac thms] 1
  12.366 +    EVERY' [rtac ctxt (bis_def RS trans),
  12.367 +      rtac ctxt iffI, etac ctxt conjE, etac ctxt conjI, CONJ_WRAP' mk_if_tac thms,
  12.368 +      etac ctxt conjE, etac ctxt conjI, CONJ_WRAP' mk_only_if_tac thms] 1
  12.369    end;
  12.370  
  12.371 -fun mk_bis_converse_tac m bis_rel rel_congs rel_converseps =
  12.372 -  EVERY' [rtac (bis_rel RS iffD2), dtac (bis_rel RS iffD1),
  12.373 -    REPEAT_DETERM o etac conjE, rtac conjI,
  12.374 -    CONJ_WRAP' (K (EVERY' [rtac converse_shift, etac subset_trans,
  12.375 -      rtac equalityD2, rtac @{thm converse_Times}])) rel_congs,
  12.376 +fun mk_bis_converse_tac ctxt m bis_rel rel_congs rel_converseps =
  12.377 +  EVERY' [rtac ctxt (bis_rel RS iffD2), dtac ctxt (bis_rel RS iffD1),
  12.378 +    REPEAT_DETERM o etac ctxt conjE, rtac ctxt conjI,
  12.379 +    CONJ_WRAP' (K (EVERY' [rtac ctxt converse_shift, etac ctxt subset_trans,
  12.380 +      rtac ctxt equalityD2, rtac ctxt @{thm converse_Times}])) rel_congs,
  12.381      CONJ_WRAP' (fn (rel_cong, rel_conversep) =>
  12.382 -      EVERY' [rtac allI, rtac allI, rtac impI,
  12.383 -        rtac (rel_cong RS @{thm eq_refl} RS @{thm predicate2D}),
  12.384 -        REPEAT_DETERM_N m o rtac @{thm conversep_eq},
  12.385 -        REPEAT_DETERM_N (length rel_congs) o rtac @{thm conversep_in_rel},
  12.386 -        rtac (rel_conversep RS sym RS @{thm eq_refl} RS @{thm predicate2D}),
  12.387 -        REPEAT_DETERM o etac allE,
  12.388 -        rtac @{thm conversepI}, etac mp, etac @{thm converseD}]) (rel_congs ~~ rel_converseps)] 1;
  12.389 +      EVERY' [rtac ctxt allI, rtac ctxt allI, rtac ctxt impI,
  12.390 +        rtac ctxt (rel_cong RS @{thm eq_refl} RS @{thm predicate2D}),
  12.391 +        REPEAT_DETERM_N m o rtac ctxt @{thm conversep_eq},
  12.392 +        REPEAT_DETERM_N (length rel_congs) o rtac ctxt @{thm conversep_in_rel},
  12.393 +        rtac ctxt (rel_conversep RS sym RS @{thm eq_refl} RS @{thm predicate2D}),
  12.394 +        REPEAT_DETERM o etac ctxt allE,
  12.395 +        rtac ctxt @{thm conversepI}, etac ctxt mp, etac ctxt @{thm converseD}]) (rel_congs ~~ rel_converseps)] 1;
  12.396  
  12.397  fun mk_bis_O_tac ctxt m bis_rel rel_congs le_rel_OOs =
  12.398 -  EVERY' [rtac (bis_rel RS iffD2), REPEAT_DETERM o dtac (bis_rel RS iffD1),
  12.399 -    REPEAT_DETERM o etac conjE, rtac conjI,
  12.400 -    CONJ_WRAP' (K (EVERY' [etac @{thm relcomp_subset_Sigma}, atac])) rel_congs,
  12.401 +  EVERY' [rtac ctxt (bis_rel RS iffD2), REPEAT_DETERM o dtac ctxt (bis_rel RS iffD1),
  12.402 +    REPEAT_DETERM o etac ctxt conjE, rtac ctxt conjI,
  12.403 +    CONJ_WRAP' (K (EVERY' [etac ctxt @{thm relcomp_subset_Sigma}, atac])) rel_congs,
  12.404      CONJ_WRAP' (fn (rel_cong, le_rel_OO) =>
  12.405 -      EVERY' [rtac allI, rtac allI, rtac impI,
  12.406 -        rtac (rel_cong RS @{thm eq_refl} RS @{thm predicate2D}),
  12.407 -        REPEAT_DETERM_N m o rtac @{thm eq_OO},
  12.408 -        REPEAT_DETERM_N (length rel_congs) o rtac @{thm relcompp_in_rel},
  12.409 -        rtac (le_rel_OO RS @{thm predicate2D}),
  12.410 -        etac @{thm relcompE},
  12.411 -        REPEAT_DETERM o dtac prod_injectD,
  12.412 -        etac conjE, hyp_subst_tac ctxt,
  12.413 -        REPEAT_DETERM o etac allE, rtac @{thm relcomppI},
  12.414 -        etac mp, atac, etac mp, atac]) (rel_congs ~~ le_rel_OOs)] 1;
  12.415 +      EVERY' [rtac ctxt allI, rtac ctxt allI, rtac ctxt impI,
  12.416 +        rtac ctxt (rel_cong RS @{thm eq_refl} RS @{thm predicate2D}),
  12.417 +        REPEAT_DETERM_N m o rtac ctxt @{thm eq_OO},
  12.418 +        REPEAT_DETERM_N (length rel_congs) o rtac ctxt @{thm relcompp_in_rel},
  12.419 +        rtac ctxt (le_rel_OO RS @{thm predicate2D}),
  12.420 +        etac ctxt @{thm relcompE},
  12.421 +        REPEAT_DETERM o dtac ctxt prod_injectD,
  12.422 +        etac ctxt conjE, hyp_subst_tac ctxt,
  12.423 +        REPEAT_DETERM o etac ctxt allE, rtac ctxt @{thm relcomppI},
  12.424 +        etac ctxt mp, atac, etac ctxt mp, atac]) (rel_congs ~~ le_rel_OOs)] 1;
  12.425  
  12.426  fun mk_bis_Gr_tac ctxt bis_rel rel_Grps mor_images morEs coalg_ins =
  12.427    unfold_thms_tac ctxt (bis_rel :: @{thm eq_alt} :: @{thm in_rel_Gr} :: rel_Grps) THEN
  12.428 -  EVERY' [rtac conjI,
  12.429 -    CONJ_WRAP' (fn thm => rtac (@{thm Gr_incl} RS iffD2) THEN' etac thm) mor_images,
  12.430 +  EVERY' [rtac ctxt conjI,
  12.431 +    CONJ_WRAP' (fn thm => rtac ctxt (@{thm Gr_incl} RS iffD2) THEN' etac ctxt thm) mor_images,
  12.432      CONJ_WRAP' (fn (coalg_in, morE) =>
  12.433 -      EVERY' [rtac allI, rtac allI, rtac impI, rtac @{thm GrpI}, etac (morE RS trans),
  12.434 -        etac @{thm GrD1}, etac (@{thm GrD2} RS arg_cong), etac coalg_in, etac @{thm GrD1}])
  12.435 +      EVERY' [rtac ctxt allI, rtac ctxt allI, rtac ctxt impI, rtac ctxt @{thm GrpI}, etac ctxt (morE RS trans),
  12.436 +        etac ctxt @{thm GrD1}, etac ctxt (@{thm GrD2} RS arg_cong), etac ctxt coalg_in, etac ctxt @{thm GrD1}])
  12.437      (coalg_ins ~~ morEs)] 1;
  12.438  
  12.439  fun mk_bis_Union_tac ctxt bis_def in_monos =
  12.440 @@ -310,15 +311,15 @@
  12.441      val ks = 1 upto n;
  12.442    in
  12.443      unfold_thms_tac ctxt [bis_def] THEN
  12.444 -    EVERY' [rtac conjI,
  12.445 +    EVERY' [rtac ctxt conjI,
  12.446        CONJ_WRAP' (fn i =>
  12.447 -        EVERY' [rtac @{thm UN_least}, dtac bspec, atac,
  12.448 -          dtac conjunct1, etac (mk_conjunctN n i)]) ks,
  12.449 +        EVERY' [rtac ctxt @{thm UN_least}, dtac ctxt bspec, atac,
  12.450 +          dtac ctxt conjunct1, etac ctxt (mk_conjunctN n i)]) ks,
  12.451        CONJ_WRAP' (fn (i, in_mono) =>
  12.452 -        EVERY' [rtac allI, rtac allI, rtac impI, etac @{thm UN_E}, dtac bspec, atac,
  12.453 -          dtac conjunct2, dtac (mk_conjunctN n i), etac allE, etac allE, dtac mp,
  12.454 -          atac, etac bexE, rtac bexI, atac, rtac in_mono,
  12.455 -          REPEAT_DETERM_N n o etac @{thm SUP_upper2[OF _ subset_refl]},
  12.456 +        EVERY' [rtac ctxt allI, rtac ctxt allI, rtac ctxt impI, etac ctxt @{thm UN_E}, dtac ctxt bspec, atac,
  12.457 +          dtac ctxt conjunct2, dtac ctxt (mk_conjunctN n i), etac ctxt allE, etac ctxt allE, dtac ctxt mp,
  12.458 +          atac, etac ctxt bexE, rtac ctxt bexI, atac, rtac ctxt in_mono,
  12.459 +          REPEAT_DETERM_N n o etac ctxt @{thm SUP_upper2[OF _ subset_refl]},
  12.460            atac]) (ks ~~ in_monos)] 1
  12.461    end;
  12.462  
  12.463 @@ -326,65 +327,65 @@
  12.464    let
  12.465      val n = length lsbis_defs;
  12.466    in
  12.467 -    EVERY' [rtac (Thm.permute_prems 0 1 bis_cong), EVERY' (map rtac lsbis_defs),
  12.468 -      rtac bis_Union, rtac ballI, REPEAT_DETERM o eresolve_tac ctxt [CollectE, conjE, exE],
  12.469 -      hyp_subst_tac ctxt, etac bis_cong, EVERY' (map (rtac o mk_nth_conv n) (1 upto n))] 1
  12.470 +    EVERY' [rtac ctxt (Thm.permute_prems 0 1 bis_cong), EVERY' (map (rtac ctxt) lsbis_defs),
  12.471 +      rtac ctxt bis_Union, rtac ctxt ballI, REPEAT_DETERM o eresolve_tac ctxt [CollectE, conjE, exE],
  12.472 +      hyp_subst_tac ctxt, etac ctxt bis_cong, EVERY' (map (rtac ctxt o mk_nth_conv n) (1 upto n))] 1
  12.473    end;
  12.474  
  12.475 -fun mk_incl_lsbis_tac n i lsbis_def =
  12.476 -  EVERY' [rtac @{thm xt1(3)}, rtac lsbis_def, rtac @{thm SUP_upper2}, rtac CollectI,
  12.477 -    REPEAT_DETERM_N n o rtac exI, rtac conjI, rtac refl, atac, rtac equalityD2,
  12.478 -    rtac (mk_nth_conv n i)] 1;
  12.479 +fun mk_incl_lsbis_tac ctxt n i lsbis_def =
  12.480 +  EVERY' [rtac ctxt @{thm xt1(3)}, rtac ctxt lsbis_def, rtac ctxt @{thm SUP_upper2}, rtac ctxt CollectI,
  12.481 +    REPEAT_DETERM_N n o rtac ctxt exI, rtac ctxt conjI, rtac ctxt refl, atac, rtac ctxt equalityD2,
  12.482 +    rtac ctxt (mk_nth_conv n i)] 1;
  12.483  
  12.484 -fun mk_equiv_lsbis_tac sbis_lsbis lsbis_incl incl_lsbis bis_Id_on bis_converse bis_O =
  12.485 -  EVERY' [rtac (@{thm equiv_def} RS iffD2),
  12.486 +fun mk_equiv_lsbis_tac ctxt sbis_lsbis lsbis_incl incl_lsbis bis_Id_on bis_converse bis_O =
  12.487 +  EVERY' [rtac ctxt (@{thm equiv_def} RS iffD2),
  12.488  
  12.489 -    rtac conjI, rtac (@{thm refl_on_def} RS iffD2),
  12.490 -    rtac conjI, rtac lsbis_incl, rtac ballI, rtac set_mp,
  12.491 -    rtac incl_lsbis, rtac bis_Id_on, atac, etac @{thm Id_onI},
  12.492 +    rtac ctxt conjI, rtac ctxt (@{thm refl_on_def} RS iffD2),
  12.493 +    rtac ctxt conjI, rtac ctxt lsbis_incl, rtac ctxt ballI, rtac ctxt set_mp,
  12.494 +    rtac ctxt incl_lsbis, rtac ctxt bis_Id_on, atac, etac ctxt @{thm Id_onI},
  12.495  
  12.496 -    rtac conjI, rtac (@{thm sym_def} RS iffD2),
  12.497 -    rtac allI, rtac allI, rtac impI, rtac set_mp,
  12.498 -    rtac incl_lsbis, rtac bis_converse, rtac sbis_lsbis, etac @{thm converseI},
  12.499 +    rtac ctxt conjI, rtac ctxt (@{thm sym_def} RS iffD2),
  12.500 +    rtac ctxt allI, rtac ctxt allI, rtac ctxt impI, rtac ctxt set_mp,
  12.501 +    rtac ctxt incl_lsbis, rtac ctxt bis_converse, rtac ctxt sbis_lsbis, etac ctxt @{thm converseI},
  12.502  
  12.503 -    rtac (@{thm trans_def} RS iffD2),
  12.504 -    rtac allI, rtac allI, rtac allI, rtac impI, rtac impI, rtac set_mp,
  12.505 -    rtac incl_lsbis, rtac bis_O, rtac sbis_lsbis, rtac sbis_lsbis,
  12.506 -    etac @{thm relcompI}, atac] 1;
  12.507 +    rtac ctxt (@{thm trans_def} RS iffD2),
  12.508 +    rtac ctxt allI, rtac ctxt allI, rtac ctxt allI, rtac ctxt impI, rtac ctxt impI, rtac ctxt set_mp,
  12.509 +    rtac ctxt incl_lsbis, rtac ctxt bis_O, rtac ctxt sbis_lsbis, rtac ctxt sbis_lsbis,
  12.510 +    etac ctxt @{thm relcompI}, atac] 1;
  12.511  
  12.512  fun mk_coalgT_tac ctxt m defs strT_defs set_map0ss =
  12.513    let
  12.514      val n = length strT_defs;
  12.515      val ks = 1 upto n;
  12.516      fun coalg_tac (i, (active_sets, def)) =
  12.517 -      EVERY' [rtac ballI, REPEAT_DETERM o eresolve_tac ctxt [CollectE, exE, conjE],
  12.518 -        hyp_subst_tac ctxt, rtac (def RS trans RS @{thm ssubst_mem}), etac (arg_cong RS trans),
  12.519 -        rtac (mk_sum_caseN n i), rtac CollectI,
  12.520 -        REPEAT_DETERM_N m o EVERY' [rtac conjI, rtac subset_UNIV],
  12.521 -        CONJ_WRAP' (fn (i, thm) => EVERY' [rtac (thm RS ord_eq_le_trans),
  12.522 -          rtac @{thm image_subsetI}, rtac CollectI, rtac exI, rtac exI, rtac conjI, rtac refl,
  12.523 -          rtac conjI,
  12.524 -          rtac conjI, etac @{thm empty_Shift}, dtac set_rev_mp,
  12.525 -            etac equalityD1, etac CollectD,
  12.526 -          rtac ballI,
  12.527 -            CONJ_WRAP' (fn i => EVERY' [rtac ballI, etac CollectE, dtac @{thm ShiftD},
  12.528 -              dtac bspec, etac thin_rl, atac, dtac (mk_conjunctN n i),
  12.529 -              dtac bspec, rtac CollectI, etac @{thm set_mp[OF equalityD1[OF Succ_Shift]]},
  12.530 -              REPEAT_DETERM o eresolve_tac ctxt [exE, conjE], rtac exI,
  12.531 -              rtac conjI, rtac (@{thm shift_def} RS fun_cong RS trans),
  12.532 -              rtac (@{thm append_Cons} RS sym RS arg_cong RS trans), atac,
  12.533 -              CONJ_WRAP' (K (EVERY' [etac trans, rtac @{thm Collect_cong},
  12.534 -                rtac @{thm eqset_imp_iff}, rtac sym, rtac trans, rtac @{thm Succ_Shift},
  12.535 -                rtac (@{thm append_Cons} RS sym RS arg_cong)])) ks]) ks,
  12.536 -          dtac bspec, atac, dtac (mk_conjunctN n i), dtac bspec,
  12.537 -          etac @{thm set_mp[OF equalityD1]}, atac,
  12.538 -          REPEAT_DETERM o eresolve_tac ctxt [exE, conjE], rtac exI,
  12.539 -          rtac conjI, rtac (@{thm shift_def} RS fun_cong RS trans),
  12.540 -          etac (@{thm append_Nil} RS sym RS arg_cong RS trans),
  12.541 -          REPEAT_DETERM_N m o (rtac conjI THEN' atac),
  12.542 -          CONJ_WRAP' (K (EVERY' [etac trans, rtac @{thm Collect_cong},
  12.543 -            rtac @{thm eqset_imp_iff}, rtac sym, rtac trans, rtac @{thm Succ_Shift},
  12.544 -            rtac (@{thm append_Nil} RS sym RS arg_cong)])) ks]) (ks ~~ active_sets)];
  12.545 +      EVERY' [rtac ctxt ballI, REPEAT_DETERM o eresolve_tac ctxt [CollectE, exE, conjE],
  12.546 +        hyp_subst_tac ctxt, rtac ctxt (def RS trans RS @{thm ssubst_mem}), etac ctxt (arg_cong RS trans),
  12.547 +        rtac ctxt (mk_sum_caseN n i), rtac ctxt CollectI,
  12.548 +        REPEAT_DETERM_N m o EVERY' [rtac ctxt conjI, rtac ctxt subset_UNIV],
  12.549 +        CONJ_WRAP' (fn (i, thm) => EVERY' [rtac ctxt (thm RS ord_eq_le_trans),
  12.550 +          rtac ctxt @{thm image_subsetI}, rtac ctxt CollectI, rtac ctxt exI, rtac ctxt exI, rtac ctxt conjI, rtac ctxt refl,
  12.551 +          rtac ctxt conjI,
  12.552 +          rtac ctxt conjI, etac ctxt @{thm empty_Shift}, dtac ctxt set_rev_mp,
  12.553 +            etac ctxt equalityD1, etac ctxt CollectD,
  12.554 +          rtac ctxt ballI,
  12.555 +            CONJ_WRAP' (fn i => EVERY' [rtac ctxt ballI, etac ctxt CollectE, dtac ctxt @{thm ShiftD},
  12.556 +              dtac ctxt bspec, etac ctxt thin_rl, atac, dtac ctxt (mk_conjunctN n i),
  12.557 +              dtac ctxt bspec, rtac ctxt CollectI, etac ctxt @{thm set_mp[OF equalityD1[OF Succ_Shift]]},
  12.558 +              REPEAT_DETERM o eresolve_tac ctxt [exE, conjE], rtac ctxt exI,
  12.559 +              rtac ctxt conjI, rtac ctxt (@{thm shift_def} RS fun_cong RS trans),
  12.560 +              rtac ctxt (@{thm append_Cons} RS sym RS arg_cong RS trans), atac,
  12.561 +              CONJ_WRAP' (K (EVERY' [etac ctxt trans, rtac ctxt @{thm Collect_cong},
  12.562 +                rtac ctxt @{thm eqset_imp_iff}, rtac ctxt sym, rtac ctxt trans, rtac ctxt @{thm Succ_Shift},
  12.563 +                rtac ctxt (@{thm append_Cons} RS sym RS arg_cong)])) ks]) ks,
  12.564 +          dtac ctxt bspec, atac, dtac ctxt (mk_conjunctN n i), dtac ctxt bspec,
  12.565 +          etac ctxt @{thm set_mp[OF equalityD1]}, atac,
  12.566 +          REPEAT_DETERM o eresolve_tac ctxt [exE, conjE], rtac ctxt exI,
  12.567 +          rtac ctxt conjI, rtac ctxt (@{thm shift_def} RS fun_cong RS trans),
  12.568 +          etac ctxt (@{thm append_Nil} RS sym RS arg_cong RS trans),
  12.569 +          REPEAT_DETERM_N m o (rtac ctxt conjI THEN' atac),
  12.570 +          CONJ_WRAP' (K (EVERY' [etac ctxt trans, rtac ctxt @{thm Collect_cong},
  12.571 +            rtac ctxt @{thm eqset_imp_iff}, rtac ctxt sym, rtac ctxt trans, rtac ctxt @{thm Succ_Shift},
  12.572 +            rtac ctxt (@{thm append_Nil} RS sym RS arg_cong)])) ks]) (ks ~~ active_sets)];
  12.573    in
  12.574      unfold_thms_tac ctxt defs THEN
  12.575      CONJ_WRAP' coalg_tac (ks ~~ (map (drop m) set_map0ss ~~ strT_defs)) 1
  12.576 @@ -395,45 +396,45 @@
  12.577      val n = length Lev_0s;
  12.578      val ks = n downto 1;
  12.579    in
  12.580 -    EVERY' [rtac (Drule.instantiate' [] cts nat_induct),
  12.581 -      REPEAT_DETERM o rtac allI,
  12.582 +    EVERY' [rtac ctxt (Drule.instantiate' [] cts nat_induct),
  12.583 +      REPEAT_DETERM o rtac ctxt allI,
  12.584        CONJ_WRAP' (fn Lev_0 =>
  12.585 -        EVERY' [rtac impI, dtac (Lev_0 RS equalityD1 RS set_mp),
  12.586 -          etac @{thm singletonE}, etac ssubst, rtac @{thm list.size(3)}]) Lev_0s,
  12.587 -      REPEAT_DETERM o rtac allI,
  12.588 +        EVERY' [rtac ctxt impI, dtac ctxt (Lev_0 RS equalityD1 RS set_mp),
  12.589 +          etac ctxt @{thm singletonE}, etac ctxt ssubst, rtac ctxt @{thm list.size(3)}]) Lev_0s,
  12.590 +      REPEAT_DETERM o rtac ctxt allI,
  12.591        CONJ_WRAP' (fn Lev_Suc =>
  12.592 -        EVERY' [rtac impI, dtac (Lev_Suc RS equalityD1 RS set_mp),
  12.593 -          CONJ_WRAP_GEN' (etac (Thm.permute_prems 1 1 UnE))
  12.594 +        EVERY' [rtac ctxt impI, dtac ctxt (Lev_Suc RS equalityD1 RS set_mp),
  12.595 +          CONJ_WRAP_GEN' (etac ctxt (Thm.permute_prems 1 1 UnE))
  12.596              (fn i =>
  12.597                EVERY' [REPEAT_DETERM o eresolve_tac ctxt [CollectE, exE, conjE], hyp_subst_tac ctxt,
  12.598 -                rtac trans, rtac @{thm length_Cons}, rtac @{thm arg_cong[of _ _ Suc]},
  12.599 -                REPEAT_DETERM o etac allE, dtac (mk_conjunctN n i), etac mp, atac]) ks])
  12.600 +                rtac ctxt trans, rtac ctxt @{thm length_Cons}, rtac ctxt @{thm arg_cong[of _ _ Suc]},
  12.601 +                REPEAT_DETERM o etac ctxt allE, dtac ctxt (mk_conjunctN n i), etac ctxt mp, atac]) ks])
  12.602        Lev_Sucs] 1
  12.603    end;
  12.604  
  12.605 -fun mk_length_Lev'_tac length_Lev =
  12.606 -  EVERY' [ftac length_Lev, etac ssubst, atac] 1;
  12.607 +fun mk_length_Lev'_tac ctxt length_Lev =
  12.608 +  EVERY' [ftac ctxt length_Lev, etac ctxt ssubst, atac] 1;
  12.609  
  12.610 -fun mk_rv_last_tac cTs cts rv_Nils rv_Conss =
  12.611 +fun mk_rv_last_tac ctxt cTs cts rv_Nils rv_Conss =
  12.612    let
  12.613      val n = length rv_Nils;
  12.614      val ks = 1 upto n;
  12.615    in
  12.616 -    EVERY' [rtac (Drule.instantiate' cTs cts @{thm list.induct}),
  12.617 -      REPEAT_DETERM o rtac allI,
  12.618 +    EVERY' [rtac ctxt (Drule.instantiate' cTs cts @{thm list.induct}),
  12.619 +      REPEAT_DETERM o rtac ctxt allI,
  12.620        CONJ_WRAP' (fn rv_Cons =>
  12.621 -        CONJ_WRAP' (fn (i, rv_Nil) => (EVERY' [rtac exI,
  12.622 -          rtac (@{thm append_Nil} RS arg_cong RS trans),
  12.623 -          rtac (rv_Cons RS trans), rtac (mk_sum_caseN n i RS trans), rtac rv_Nil]))
  12.624 +        CONJ_WRAP' (fn (i, rv_Nil) => (EVERY' [rtac ctxt exI,
  12.625 +          rtac ctxt (@{thm append_Nil} RS arg_cong RS trans),
  12.626 +          rtac ctxt (rv_Cons RS trans), rtac ctxt (mk_sum_caseN n i RS trans), rtac ctxt rv_Nil]))
  12.627          (ks ~~ rv_Nils))
  12.628        rv_Conss,
  12.629 -      REPEAT_DETERM o rtac allI, rtac (mk_sumEN n),
  12.630 +      REPEAT_DETERM o rtac ctxt allI, rtac ctxt (mk_sumEN n),
  12.631        EVERY' (map (fn i =>
  12.632 -        CONJ_WRAP' (fn rv_Cons => EVERY' [REPEAT_DETERM o etac allE, dtac (mk_conjunctN n i),
  12.633 -          CONJ_WRAP' (fn i' => EVERY' [dtac (mk_conjunctN n i'), etac exE, rtac exI,
  12.634 -            rtac (@{thm append_Cons} RS arg_cong RS trans), rtac (rv_Cons RS trans),
  12.635 -            if n = 1 then K all_tac else etac (sum_case_cong_weak RS trans),
  12.636 -            rtac (mk_sum_caseN n i RS trans), atac])
  12.637 +        CONJ_WRAP' (fn rv_Cons => EVERY' [REPEAT_DETERM o etac ctxt allE, dtac ctxt (mk_conjunctN n i),
  12.638 +          CONJ_WRAP' (fn i' => EVERY' [dtac ctxt (mk_conjunctN n i'), etac ctxt exE, rtac ctxt exI,
  12.639 +            rtac ctxt (@{thm append_Cons} RS arg_cong RS trans), rtac ctxt (rv_Cons RS trans),
  12.640 +            if n = 1 then K all_tac else etac ctxt (sum_case_cong_weak RS trans),
  12.641 +            rtac ctxt (mk_sum_caseN n i RS trans), atac])
  12.642            ks])
  12.643          rv_Conss)
  12.644        ks)] 1
  12.645 @@ -444,41 +445,41 @@
  12.646      val n = length Lev_0s;
  12.647      val ks = 1 upto n;
  12.648    in
  12.649 -    EVERY' [rtac (Drule.instantiate' [] cts nat_induct),
  12.650 -      REPEAT_DETERM o rtac allI,
  12.651 +    EVERY' [rtac ctxt (Drule.instantiate' [] cts nat_induct),
  12.652 +      REPEAT_DETERM o rtac ctxt allI,
  12.653        CONJ_WRAP' (fn ((i, (Lev_0, Lev_Suc)), rv_Nil) =>
  12.654 -        EVERY' [rtac impI, dtac (Lev_0 RS equalityD1 RS set_mp),
  12.655 -          etac @{thm singletonE}, hyp_subst_tac ctxt,
  12.656 -          CONJ_WRAP' (fn i' => rtac impI THEN' dtac (sym RS trans) THEN' rtac rv_Nil THEN'
  12.657 +        EVERY' [rtac ctxt impI, dtac ctxt (Lev_0 RS equalityD1 RS set_mp),
  12.658 +          etac ctxt @{thm singletonE}, hyp_subst_tac ctxt,
  12.659 +          CONJ_WRAP' (fn i' => rtac ctxt impI THEN' dtac ctxt (sym RS trans) THEN' rtac ctxt rv_Nil THEN'
  12.660              (if i = i'
  12.661 -            then EVERY' [dtac (mk_InN_inject n i), hyp_subst_tac ctxt,
  12.662 +            then EVERY' [dtac ctxt (mk_InN_inject n i), hyp_subst_tac ctxt,
  12.663                CONJ_WRAP' (fn (i'', Lev_0'') =>
  12.664 -                EVERY' [rtac impI, rtac @{thm ssubst_mem[OF append_Nil]},
  12.665 -                  rtac (Lev_Suc RS equalityD2 RS set_mp), rtac (mk_UnIN n i''),
  12.666 -                  rtac CollectI, REPEAT_DETERM o rtac exI, rtac conjI, rtac refl,
  12.667 -                  etac conjI, rtac (Lev_0'' RS equalityD2 RS set_mp),
  12.668 -                  rtac @{thm singletonI}])
  12.669 +                EVERY' [rtac ctxt impI, rtac ctxt @{thm ssubst_mem[OF append_Nil]},
  12.670 +                  rtac ctxt (Lev_Suc RS equalityD2 RS set_mp), rtac ctxt (mk_UnIN n i''),
  12.671 +                  rtac ctxt CollectI, REPEAT_DETERM o rtac ctxt exI, rtac ctxt conjI, rtac ctxt refl,
  12.672 +                  etac ctxt conjI, rtac ctxt (Lev_0'' RS equalityD2 RS set_mp),
  12.673 +                  rtac ctxt @{thm singletonI}])
  12.674                (ks ~~ Lev_0s)]
  12.675 -            else etac (mk_InN_not_InM i' i RS notE)))
  12.676 +            else etac ctxt (mk_InN_not_InM i' i RS notE)))
  12.677            ks])
  12.678        ((ks ~~ (Lev_0s ~~ Lev_Sucs)) ~~ rv_Nils),
  12.679 -      REPEAT_DETERM o rtac allI,
  12.680 +      REPEAT_DETERM o rtac ctxt allI,
  12.681        CONJ_WRAP' (fn ((Lev_Suc, rv_Cons), from_to_sbds) =>
  12.682 -        EVERY' [rtac impI, dtac (Lev_Suc RS equalityD1 RS set_mp),
  12.683 -          CONJ_WRAP_GEN' (etac (Thm.permute_prems 1 1 UnE))
  12.684 +        EVERY' [rtac ctxt impI, dtac ctxt (Lev_Suc RS equalityD1 RS set_mp),
  12.685 +          CONJ_WRAP_GEN' (etac ctxt (Thm.permute_prems 1 1 UnE))
  12.686              (fn (i, from_to_sbd) =>
  12.687                EVERY' [REPEAT_DETERM o eresolve_tac ctxt [CollectE, exE, conjE], hyp_subst_tac ctxt,
  12.688 -                CONJ_WRAP' (fn i' => rtac impI THEN'
  12.689 +                CONJ_WRAP' (fn i' => rtac ctxt impI THEN'
  12.690                    CONJ_WRAP' (fn i'' =>
  12.691 -                    EVERY' [rtac impI, rtac (Lev_Suc RS equalityD2 RS set_mp),
  12.692 -                      rtac @{thm ssubst_mem[OF append_Cons]}, rtac (mk_UnIN n i),
  12.693 -                      rtac CollectI, REPEAT_DETERM o rtac exI, rtac conjI, rtac refl,
  12.694 -                      rtac conjI, atac, dtac (sym RS trans RS sym),
  12.695 -                      rtac (rv_Cons RS trans), rtac (mk_sum_caseN n i RS trans),
  12.696 -                      etac (from_to_sbd RS arg_cong), REPEAT_DETERM o etac allE,
  12.697 -                      dtac (mk_conjunctN n i), dtac mp, atac,
  12.698 -                      dtac (mk_conjunctN n i'), dtac mp, atac,
  12.699 -                      dtac (mk_conjunctN n i''), etac mp, atac])
  12.700 +                    EVERY' [rtac ctxt impI, rtac ctxt (Lev_Suc RS equalityD2 RS set_mp),
  12.701 +                      rtac ctxt @{thm ssubst_mem[OF append_Cons]}, rtac ctxt (mk_UnIN n i),
  12.702 +                      rtac ctxt CollectI, REPEAT_DETERM o rtac ctxt exI, rtac ctxt conjI, rtac ctxt refl,
  12.703 +                      rtac ctxt conjI, atac, dtac ctxt (sym RS trans RS sym),
  12.704 +                      rtac ctxt (rv_Cons RS trans), rtac ctxt (mk_sum_caseN n i RS trans),
  12.705 +                      etac ctxt (from_to_sbd RS arg_cong), REPEAT_DETERM o etac ctxt allE,
  12.706 +                      dtac ctxt (mk_conjunctN n i), dtac ctxt mp, atac,
  12.707 +                      dtac ctxt (mk_conjunctN n i'), dtac ctxt mp, atac,
  12.708 +                      dtac ctxt (mk_conjunctN n i''), etac ctxt mp, atac])
  12.709                    ks)
  12.710                  ks])
  12.711            (rev (ks ~~ from_to_sbds))])
  12.712 @@ -490,54 +491,54 @@
  12.713      val n = length Lev_0s;
  12.714      val ks = 1 upto n;
  12.715    in
  12.716 -    EVERY' [rtac (Drule.instantiate' [] cts nat_induct),
  12.717 -      REPEAT_DETERM o rtac allI,
  12.718 +    EVERY' [rtac ctxt (Drule.instantiate' [] cts nat_induct),
  12.719 +      REPEAT_DETERM o rtac ctxt allI,
  12.720        CONJ_WRAP' (fn ((i, (Lev_0, Lev_Suc)), rv_Nil) =>
  12.721 -        EVERY' [rtac impI, dtac (Lev_0 RS equalityD1 RS set_mp),
  12.722 -          etac @{thm singletonE}, hyp_subst_tac ctxt,
  12.723 -          CONJ_WRAP' (fn i' => rtac impI THEN'
  12.724 -            CONJ_WRAP' (fn i'' => rtac impI  THEN' dtac (sym RS trans) THEN' rtac rv_Nil THEN'
  12.725 +        EVERY' [rtac ctxt impI, dtac ctxt (Lev_0 RS equalityD1 RS set_mp),
  12.726 +          etac ctxt @{thm singletonE}, hyp_subst_tac ctxt,
  12.727 +          CONJ_WRAP' (fn i' => rtac ctxt impI THEN'
  12.728 +            CONJ_WRAP' (fn i'' => rtac ctxt impI  THEN' dtac ctxt (sym RS trans) THEN' rtac ctxt rv_Nil THEN'
  12.729                (if i = i''
  12.730 -              then EVERY' [dtac @{thm ssubst_mem[OF sym[OF append_Nil]]},
  12.731 -                dtac (Lev_Suc RS equalityD1 RS set_mp), dtac (mk_InN_inject n i),
  12.732 +              then EVERY' [dtac ctxt @{thm ssubst_mem[OF sym[OF append_Nil]]},
  12.733 +                dtac ctxt (Lev_Suc RS equalityD1 RS set_mp), dtac ctxt (mk_InN_inject n i),
  12.734                  hyp_subst_tac ctxt,
  12.735 -                CONJ_WRAP_GEN' (etac (Thm.permute_prems 1 1 UnE))
  12.736 +                CONJ_WRAP_GEN' (etac ctxt (Thm.permute_prems 1 1 UnE))
  12.737                    (fn k => REPEAT_DETERM o eresolve_tac ctxt [CollectE, exE, conjE] THEN'
  12.738 -                    dtac list_inject_iffD1 THEN' etac conjE THEN'
  12.739 +                    dtac ctxt list_inject_iffD1 THEN' etac ctxt conjE THEN'
  12.740                      (if k = i'
  12.741 -                    then EVERY' [dtac (mk_InN_inject n k), hyp_subst_tac ctxt, etac imageI]
  12.742 -                    else etac (mk_InN_not_InM i' k RS notE)))
  12.743 +                    then EVERY' [dtac ctxt (mk_InN_inject n k), hyp_subst_tac ctxt, etac ctxt imageI]
  12.744 +                    else etac ctxt (mk_InN_not_InM i' k RS notE)))
  12.745                  (rev ks)]
  12.746 -              else etac (mk_InN_not_InM i'' i RS notE)))
  12.747 +              else etac ctxt (mk_InN_not_InM i'' i RS notE)))
  12.748              ks)
  12.749            ks])
  12.750        ((ks ~~ (Lev_0s ~~ Lev_Sucs)) ~~ rv_Nils),
  12.751 -      REPEAT_DETERM o rtac allI,
  12.752 +      REPEAT_DETERM o rtac ctxt allI,
  12.753        CONJ_WRAP' (fn ((Lev_Suc, rv_Cons), (from_to_sbds, to_sbd_injs)) =>
  12.754 -        EVERY' [rtac impI, dtac (Lev_Suc RS equalityD1 RS set_mp),
  12.755 -          CONJ_WRAP_GEN' (etac (Thm.permute_prems 1 1 UnE))
  12.756 +        EVERY' [rtac ctxt impI, dtac ctxt (Lev_Suc RS equalityD1 RS set_mp),
  12.757 +          CONJ_WRAP_GEN' (etac ctxt (Thm.permute_prems 1 1 UnE))
  12.758              (fn (i, (from_to_sbd, to_sbd_inj)) =>
  12.759                REPEAT_DETERM o eresolve_tac ctxt [CollectE, exE, conjE] THEN' hyp_subst_tac ctxt THEN'
  12.760 -              CONJ_WRAP' (fn i' => rtac impI THEN'
  12.761 -                dtac @{thm ssubst_mem[OF sym[OF append_Cons]]} THEN'
  12.762 -                dtac (Lev_Suc RS equalityD1 RS set_mp) THEN'
  12.763 -                CONJ_WRAP_GEN' (etac (Thm.permute_prems 1 1 UnE)) (fn k =>
  12.764 +              CONJ_WRAP' (fn i' => rtac ctxt impI THEN'
  12.765 +                dtac ctxt @{thm ssubst_mem[OF sym[OF append_Cons]]} THEN'
  12.766 +                dtac ctxt (Lev_Suc RS equalityD1 RS set_mp) THEN'
  12.767 +                CONJ_WRAP_GEN' (etac ctxt (Thm.permute_prems 1 1 UnE)) (fn k =>
  12.768                    REPEAT_DETERM o eresolve_tac ctxt [CollectE, exE, conjE] THEN'
  12.769 -                  dtac list_inject_iffD1 THEN' etac conjE THEN'
  12.770 +                  dtac ctxt list_inject_iffD1 THEN' etac ctxt conjE THEN'
  12.771                    (if k = i
  12.772 -                  then EVERY' [dtac (mk_InN_inject n i),
  12.773 -                    dtac (Thm.permute_prems 0 2 (to_sbd_inj RS iffD1)),
  12.774 +                  then EVERY' [dtac ctxt (mk_InN_inject n i),
  12.775 +                    dtac ctxt (Thm.permute_prems 0 2 (to_sbd_inj RS iffD1)),
  12.776                      atac, atac, hyp_subst_tac ctxt] THEN'
  12.777                      CONJ_WRAP' (fn i'' =>
  12.778 -                      EVERY' [rtac impI, dtac (sym RS trans),
  12.779 -                        rtac (rv_Cons RS trans), rtac (mk_sum_caseN n i RS arg_cong RS trans),
  12.780 -                        etac (from_to_sbd RS arg_cong),
  12.781 -                        REPEAT_DETERM o etac allE,
  12.782 -                        dtac (mk_conjunctN n i), dtac mp, atac,
  12.783 -                        dtac (mk_conjunctN n i'), dtac mp, atac,
  12.784 -                        dtac (mk_conjunctN n i''), etac mp, etac sym])
  12.785 +                      EVERY' [rtac ctxt impI, dtac ctxt (sym RS trans),
  12.786 +                        rtac ctxt (rv_Cons RS trans), rtac ctxt (mk_sum_caseN n i RS arg_cong RS trans),
  12.787 +                        etac ctxt (from_to_sbd RS arg_cong),
  12.788 +                        REPEAT_DETERM o etac ctxt allE,
  12.789 +                        dtac ctxt (mk_conjunctN n i), dtac ctxt mp, atac,
  12.790 +                        dtac ctxt (mk_conjunctN n i'), dtac ctxt mp, atac,
  12.791 +                        dtac ctxt (mk_conjunctN n i''), etac ctxt mp, etac ctxt sym])
  12.792                      ks
  12.793 -                  else etac (mk_InN_not_InM i k RS notE)))
  12.794 +                  else etac ctxt (mk_InN_not_InM i k RS notE)))
  12.795                  (rev ks))
  12.796                ks)
  12.797            (rev (ks ~~ (from_to_sbds ~~ to_sbd_injs)))])
  12.798 @@ -553,90 +554,90 @@
  12.799  
  12.800      fun fbetw_tac (i, (carT_def, (isNode_def, (Lev_0, (rv_Nil, ((length_Lev, length_Lev'),
  12.801        (rv_lasts, (set_map0s, (set_Levss, set_image_Levss))))))))) =
  12.802 -      EVERY' [rtac ballI, rtac (carT_def RS equalityD2 RS set_mp),
  12.803 -        rtac CollectI, REPEAT_DETERM o rtac exI, rtac conjI, rtac refl, rtac conjI,
  12.804 -        rtac conjI,
  12.805 -          rtac @{thm UN_I}, rtac UNIV_I, rtac (Lev_0 RS equalityD2 RS set_mp),
  12.806 -          rtac @{thm singletonI},
  12.807 +      EVERY' [rtac ctxt ballI, rtac ctxt (carT_def RS equalityD2 RS set_mp),
  12.808 +        rtac ctxt CollectI, REPEAT_DETERM o rtac ctxt exI, rtac ctxt conjI, rtac ctxt refl, rtac ctxt conjI,
  12.809 +        rtac ctxt conjI,
  12.810 +          rtac ctxt @{thm UN_I}, rtac ctxt UNIV_I, rtac ctxt (Lev_0 RS equalityD2 RS set_mp),
  12.811 +          rtac ctxt @{thm singletonI},
  12.812          (**)
  12.813 -          rtac ballI, etac @{thm UN_E},
  12.814 +          rtac ctxt ballI, etac ctxt @{thm UN_E},
  12.815            CONJ_WRAP' (fn (i, (rv_last, (isNode_def, (set_map0s,
  12.816              (set_Levs, set_image_Levs))))) =>
  12.817 -            EVERY' [rtac ballI,
  12.818 +            EVERY' [rtac ctxt ballI,
  12.819                REPEAT_DETERM o eresolve_tac ctxt [CollectE, @{thm SuccE}, @{thm UN_E}],
  12.820 -              rtac (rev_mp OF [rv_last, impI]), etac exE, rtac (isNode_def RS iffD2),
  12.821 -              rtac exI, rtac conjI,
  12.822 -              if n = 1 then rtac refl
  12.823 -              else etac (sum_case_cong_weak RS trans) THEN' rtac (mk_sum_caseN n i),
  12.824 +              rtac ctxt (rev_mp OF [rv_last, impI]), etac ctxt exE, rtac ctxt (isNode_def RS iffD2),
  12.825 +              rtac ctxt exI, rtac ctxt conjI,
  12.826 +              if n = 1 then rtac ctxt refl
  12.827 +              else etac ctxt (sum_case_cong_weak RS trans) THEN' rtac ctxt (mk_sum_caseN n i),
  12.828                CONJ_WRAP' (fn (set_map0, (set_Lev, set_image_Lev)) =>
  12.829 -                EVERY' [rtac (set_map0 RS trans), rtac equalityI, rtac @{thm image_subsetI},
  12.830 -                  rtac CollectI, rtac @{thm SuccI}, rtac @{thm UN_I}, rtac UNIV_I, etac set_Lev,
  12.831 -                  if n = 1 then rtac refl else atac, atac, rtac subsetI,
  12.832 +                EVERY' [rtac ctxt (set_map0 RS trans), rtac ctxt equalityI, rtac ctxt @{thm image_subsetI},
  12.833 +                  rtac ctxt CollectI, rtac ctxt @{thm SuccI}, rtac ctxt @{thm UN_I}, rtac ctxt UNIV_I, etac ctxt set_Lev,
  12.834 +                  if n = 1 then rtac ctxt refl else atac, atac, rtac ctxt subsetI,
  12.835                    REPEAT_DETERM o eresolve_tac ctxt [CollectE, @{thm SuccE}, @{thm UN_E}],
  12.836 -                  REPEAT_DETERM_N 4 o etac thin_rl,
  12.837 -                  rtac set_image_Lev,
  12.838 -                  atac, dtac length_Lev, hyp_subst_tac ctxt, dtac length_Lev',
  12.839 -                  etac @{thm set_mp[OF equalityD1[OF arg_cong[OF length_append_singleton]]]},
  12.840 -                  if n = 1 then rtac refl else atac])
  12.841 +                  REPEAT_DETERM_N 4 o etac ctxt thin_rl,
  12.842 +                  rtac ctxt set_image_Lev,
  12.843 +                  atac, dtac ctxt length_Lev, hyp_subst_tac ctxt, dtac ctxt length_Lev',
  12.844 +                  etac ctxt @{thm set_mp[OF equalityD1[OF arg_cong[OF length_append_singleton]]]},
  12.845 +                  if n = 1 then rtac ctxt refl else atac])
  12.846                (drop m set_map0s ~~ (set_Levs ~~ set_image_Levs))])
  12.847            (ks ~~ (rv_lasts ~~ (isNode_defs ~~ (set_map0ss ~~
  12.848              (set_Levss ~~ set_image_Levss))))),
  12.849          (*root isNode*)
  12.850 -          rtac (isNode_def RS iffD2), rtac exI, rtac conjI,
  12.851 +          rtac ctxt (isNode_def RS iffD2), rtac ctxt exI, rtac ctxt conjI,
  12.852            CONVERSION (Conv.top_conv
  12.853              (K (Conv.try_conv (Conv.rewr_conv (rv_Nil RS eq_reflection)))) ctxt),
  12.854 -          if n = 1 then rtac refl else rtac (mk_sum_caseN n i),
  12.855 +          if n = 1 then rtac ctxt refl else rtac ctxt (mk_sum_caseN n i),
  12.856            CONJ_WRAP' (fn (set_map0, (set_Lev, set_image_Lev)) =>
  12.857 -            EVERY' [rtac (set_map0 RS trans), rtac equalityI, rtac @{thm image_subsetI},
  12.858 -              rtac CollectI, rtac @{thm SuccI}, rtac @{thm UN_I}, rtac UNIV_I, rtac set_Lev,
  12.859 -              rtac (Lev_0 RS equalityD2 RS set_mp), rtac @{thm singletonI}, rtac rv_Nil,
  12.860 -              atac, rtac subsetI,
  12.861 +            EVERY' [rtac ctxt (set_map0 RS trans), rtac ctxt equalityI, rtac ctxt @{thm image_subsetI},
  12.862 +              rtac ctxt CollectI, rtac ctxt @{thm SuccI}, rtac ctxt @{thm UN_I}, rtac ctxt UNIV_I, rtac ctxt set_Lev,
  12.863 +              rtac ctxt (Lev_0 RS equalityD2 RS set_mp), rtac ctxt @{thm singletonI}, rtac ctxt rv_Nil,
  12.864 +              atac, rtac ctxt subsetI,
  12.865                REPEAT_DETERM o eresolve_tac ctxt [CollectE, @{thm SuccE}, @{thm UN_E}],
  12.866 -              rtac set_image_Lev, rtac (Lev_0 RS equalityD2 RS set_mp),
  12.867 -              rtac @{thm singletonI}, dtac length_Lev',
  12.868 -              etac @{thm set_mp[OF equalityD1[OF arg_cong[OF
  12.869 +              rtac ctxt set_image_Lev, rtac ctxt (Lev_0 RS equalityD2 RS set_mp),
  12.870 +              rtac ctxt @{thm singletonI}, dtac ctxt length_Lev',
  12.871 +              etac ctxt @{thm set_mp[OF equalityD1[OF arg_cong[OF
  12.872                  trans[OF length_append_singleton arg_cong[of _ _ Suc, OF list.size(3)]]]]]},
  12.873 -              rtac rv_Nil])
  12.874 +              rtac ctxt rv_Nil])
  12.875            (drop m set_map0s ~~ (nth set_Levss (i - 1) ~~ nth set_image_Levss (i - 1)))];
  12.876  
  12.877      fun mor_tac (i, (strT_def, ((Lev_Suc, (rv_Nil, rv_Cons)),
  12.878        ((map_comp_id, map_cong0), (length_Lev', (from_to_sbds, to_sbd_injs)))))) =
  12.879 -      EVERY' [rtac ballI, rtac sym, rtac trans, rtac strT_def,
  12.880 +      EVERY' [rtac ctxt ballI, rtac ctxt sym, rtac ctxt trans, rtac ctxt strT_def,
  12.881          CONVERSION (Conv.top_conv
  12.882            (K (Conv.try_conv (Conv.rewr_conv (rv_Nil RS eq_reflection)))) ctxt),
  12.883          if n = 1 then K all_tac
  12.884 -        else (rtac (sum_case_cong_weak RS trans) THEN'
  12.885 -          rtac (mk_sum_caseN n i) THEN' rtac (mk_sum_caseN n i RS trans)),
  12.886 -        rtac (map_comp_id RS trans), rtac (map_cong0 OF replicate m refl),
  12.887 +        else (rtac ctxt (sum_case_cong_weak RS trans) THEN'
  12.888 +          rtac ctxt (mk_sum_caseN n i) THEN' rtac ctxt (mk_sum_caseN n i RS trans)),
  12.889 +        rtac ctxt (map_comp_id RS trans), rtac ctxt (map_cong0 OF replicate m refl),
  12.890          EVERY' (@{map 3} (fn i' => fn to_sbd_inj => fn from_to_sbd =>
  12.891 -          DETERM o EVERY' [rtac trans, rtac o_apply, rtac prod_injectI, rtac conjI,
  12.892 -            rtac trans, rtac @{thm Shift_def},
  12.893 -            rtac equalityI, rtac subsetI, etac thin_rl,
  12.894 -            REPEAT_DETERM o eresolve_tac ctxt [CollectE, @{thm UN_E}], dtac length_Lev', dtac asm_rl,
  12.895 -            etac thin_rl, dtac @{thm set_rev_mp[OF _ equalityD1]},
  12.896 -            rtac (@{thm length_Cons} RS arg_cong RS trans), rtac Lev_Suc,
  12.897 -            CONJ_WRAP_GEN' (etac (Thm.permute_prems 1 1 UnE)) (fn i'' =>
  12.898 +          DETERM o EVERY' [rtac ctxt trans, rtac ctxt o_apply, rtac ctxt prod_injectI, rtac ctxt conjI,
  12.899 +            rtac ctxt trans, rtac ctxt @{thm Shift_def},
  12.900 +            rtac ctxt equalityI, rtac ctxt subsetI, etac ctxt thin_rl,
  12.901 +            REPEAT_DETERM o eresolve_tac ctxt [CollectE, @{thm UN_E}], dtac ctxt length_Lev', dtac ctxt asm_rl,
  12.902 +            etac ctxt thin_rl, dtac ctxt @{thm set_rev_mp[OF _ equalityD1]},
  12.903 +            rtac ctxt (@{thm length_Cons} RS arg_cong RS trans), rtac ctxt Lev_Suc,
  12.904 +            CONJ_WRAP_GEN' (etac ctxt (Thm.permute_prems 1 1 UnE)) (fn i'' =>
  12.905                EVERY' [REPEAT_DETERM o eresolve_tac ctxt [CollectE, exE, conjE],
  12.906 -                dtac list_inject_iffD1, etac conjE,
  12.907 -                if i' = i'' then EVERY' [dtac (mk_InN_inject n i'),
  12.908 -                  dtac (Thm.permute_prems 0 2 (to_sbd_inj RS iffD1)),
  12.909 -                  atac, atac, hyp_subst_tac ctxt, etac @{thm UN_I[OF UNIV_I]}]
  12.910 -                else etac (mk_InN_not_InM i' i'' RS notE)])
  12.911 +                dtac ctxt list_inject_iffD1, etac ctxt conjE,
  12.912 +                if i' = i'' then EVERY' [dtac ctxt (mk_InN_inject n i'),
  12.913 +                  dtac ctxt (Thm.permute_prems 0 2 (to_sbd_inj RS iffD1)),
  12.914 +                  atac, atac, hyp_subst_tac ctxt, etac ctxt @{thm UN_I[OF UNIV_I]}]
  12.915 +                else etac ctxt (mk_InN_not_InM i' i'' RS notE)])
  12.916              (rev ks),
  12.917 -            rtac @{thm UN_least}, rtac subsetI, rtac CollectI, rtac @{thm UN_I[OF UNIV_I]},
  12.918 -            rtac (Lev_Suc RS equalityD2 RS set_mp), rtac (mk_UnIN n i'), rtac CollectI,
  12.919 -            REPEAT_DETERM o rtac exI, rtac conjI, rtac refl, etac conjI, atac,
  12.920 -            rtac trans, rtac @{thm shift_def}, rtac iffD2, rtac @{thm fun_eq_iff}, rtac allI,
  12.921 +            rtac ctxt @{thm UN_least}, rtac ctxt subsetI, rtac ctxt CollectI, rtac ctxt @{thm UN_I[OF UNIV_I]},
  12.922 +            rtac ctxt (Lev_Suc RS equalityD2 RS set_mp), rtac ctxt (mk_UnIN n i'), rtac ctxt CollectI,
  12.923 +            REPEAT_DETERM o rtac ctxt exI, rtac ctxt conjI, rtac ctxt refl, etac ctxt conjI, atac,
  12.924 +            rtac ctxt trans, rtac ctxt @{thm shift_def}, rtac ctxt iffD2, rtac ctxt @{thm fun_eq_iff}, rtac ctxt allI,
  12.925              CONVERSION (Conv.top_conv
  12.926                (K (Conv.try_conv (Conv.rewr_conv (rv_Cons RS eq_reflection)))) ctxt),
  12.927              if n = 1 then K all_tac
  12.928 -            else rtac sum_case_cong_weak THEN' rtac (mk_sum_caseN n i' RS trans),
  12.929 -            SELECT_GOAL (unfold_thms_tac ctxt [from_to_sbd]), rtac refl])
  12.930 +            else rtac ctxt sum_case_cong_weak THEN' rtac ctxt (mk_sum_caseN n i' RS trans),
  12.931 +            SELECT_GOAL (unfold_thms_tac ctxt [from_to_sbd]), rtac ctxt refl])
  12.932          ks to_sbd_injs from_to_sbds)];
  12.933    in
  12.934 -    (rtac mor_cong THEN'
  12.935 -    EVERY' (map (fn thm => rtac (thm RS @{thm ext})) beh_defs) THEN'
  12.936 -    rtac (mor_def RS iffD2) THEN' rtac conjI THEN'
  12.937 +    (rtac ctxt mor_cong THEN'
  12.938 +    EVERY' (map (fn thm => rtac ctxt (thm RS @{thm ext})) beh_defs) THEN'
  12.939 +    rtac ctxt (mor_def RS iffD2) THEN' rtac ctxt conjI THEN'
  12.940      CONJ_WRAP' fbetw_tac
  12.941        (ks ~~ (carT_defs ~~ (isNode_defs ~~ (Lev_0s ~~ (rv_Nils ~~ ((length_Levs ~~ length_Lev's) ~~
  12.942          (rv_lastss ~~ (set_map0ss ~~ (set_Levsss ~~ set_image_Levsss))))))))) THEN'
  12.943 @@ -646,162 +647,162 @@
  12.944            (length_Lev's ~~ (from_to_sbdss ~~ to_sbd_injss))))))) 1
  12.945    end;
  12.946  
  12.947 -fun mk_congruent_str_final_tac m lsbisE map_comp_id map_cong0 equiv_LSBISs =
  12.948 -  EVERY' [rtac @{thm congruentI}, dtac lsbisE,
  12.949 -    REPEAT_DETERM o eresolve0_tac [CollectE, conjE, bexE], rtac (o_apply RS trans),
  12.950 -    etac (sym RS arg_cong RS trans), rtac (map_comp_id RS trans),
  12.951 -    rtac (map_cong0 RS trans), REPEAT_DETERM_N m o rtac refl,
  12.952 +fun mk_congruent_str_final_tac ctxt m lsbisE map_comp_id map_cong0 equiv_LSBISs =
  12.953 +  EVERY' [rtac ctxt @{thm congruentI}, dtac ctxt lsbisE,
  12.954 +    REPEAT_DETERM o eresolve0_tac [CollectE, conjE, bexE], rtac ctxt (o_apply RS trans),
  12.955 +    etac ctxt (sym RS arg_cong RS trans), rtac ctxt (map_comp_id RS trans),
  12.956 +    rtac ctxt (map_cong0 RS trans), REPEAT_DETERM_N m o rtac ctxt refl,
  12.957      EVERY' (map (fn equiv_LSBIS =>
  12.958 -      EVERY' [rtac @{thm equiv_proj}, rtac equiv_LSBIS, etac set_mp, atac])
  12.959 -    equiv_LSBISs), rtac sym, rtac (o_apply RS trans),
  12.960 -    etac (sym RS arg_cong RS trans), rtac map_comp_id] 1;
  12.961 +      EVERY' [rtac ctxt @{thm equiv_proj}, rtac ctxt equiv_LSBIS, etac ctxt set_mp, atac])
  12.962 +    equiv_LSBISs), rtac ctxt sym, rtac ctxt (o_apply RS trans),
  12.963 +    etac ctxt (sym RS arg_cong RS trans), rtac ctxt map_comp_id] 1;
  12.964  
  12.965 -fun mk_coalg_final_tac m coalg_def congruent_str_finals equiv_LSBISs set_map0ss coalgT_setss =
  12.966 -  EVERY' [rtac (coalg_def RS iffD2),
  12.967 +fun mk_coalg_final_tac ctxt m coalg_def congruent_str_finals equiv_LSBISs set_map0ss coalgT_setss =
  12.968 +  EVERY' [rtac ctxt (coalg_def RS iffD2),
  12.969      CONJ_WRAP' (fn ((set_map0s, coalgT_sets), (equiv_LSBIS, congruent_str_final)) =>
  12.970 -      EVERY' [rtac @{thm univ_preserves}, rtac equiv_LSBIS, rtac congruent_str_final,
  12.971 -        rtac ballI, rtac @{thm ssubst_mem}, rtac o_apply, rtac CollectI,
  12.972 -        REPEAT_DETERM_N m o EVERY' [rtac conjI, rtac subset_UNIV],
  12.973 +      EVERY' [rtac ctxt @{thm univ_preserves}, rtac ctxt equiv_LSBIS, rtac ctxt congruent_str_final,
  12.974 +        rtac ctxt ballI, rtac ctxt @{thm ssubst_mem}, rtac ctxt o_apply, rtac ctxt CollectI,
  12.975 +        REPEAT_DETERM_N m o EVERY' [rtac ctxt conjI, rtac ctxt subset_UNIV],
  12.976          CONJ_WRAP' (fn (equiv_LSBIS, (set_map0, coalgT_set)) =>
  12.977 -          EVERY' [rtac (set_map0 RS ord_eq_le_trans),
  12.978 -            rtac @{thm image_subsetI}, rtac iffD2, rtac @{thm proj_in_iff},
  12.979 -            rtac equiv_LSBIS, etac set_rev_mp, etac coalgT_set])
  12.980 +          EVERY' [rtac ctxt (set_map0 RS ord_eq_le_trans),
  12.981 +            rtac ctxt @{thm image_subsetI}, rtac ctxt iffD2, rtac ctxt @{thm proj_in_iff},
  12.982 +            rtac ctxt equiv_LSBIS, etac ctxt set_rev_mp, etac ctxt coalgT_set])
  12.983          (equiv_LSBISs ~~ (drop m set_map0s ~~ coalgT_sets))])
  12.984      ((set_map0ss ~~ coalgT_setss) ~~ (equiv_LSBISs ~~ congruent_str_finals))] 1;
  12.985  
  12.986 -fun mk_mor_T_final_tac mor_def congruent_str_finals equiv_LSBISs =
  12.987 -  EVERY' [rtac (mor_def RS iffD2), rtac conjI,
  12.988 +fun mk_mor_T_final_tac ctxt mor_def congruent_str_finals equiv_LSBISs =
  12.989 +  EVERY' [rtac ctxt (mor_def RS iffD2), rtac ctxt conjI,
  12.990      CONJ_WRAP' (fn equiv_LSBIS =>
  12.991 -      EVERY' [rtac ballI, rtac iffD2, rtac @{thm proj_in_iff}, rtac equiv_LSBIS, atac])
  12.992 +      EVERY' [rtac ctxt ballI, rtac ctxt iffD2, rtac ctxt @{thm proj_in_iff}, rtac ctxt equiv_LSBIS, atac])
  12.993      equiv_LSBISs,
  12.994      CONJ_WRAP' (fn (equiv_LSBIS, congruent_str_final) =>
  12.995 -      EVERY' [rtac ballI, rtac sym, rtac trans, rtac @{thm univ_commute}, rtac equiv_LSBIS,
  12.996 -        rtac congruent_str_final, atac, rtac o_apply])
  12.997 +      EVERY' [rtac ctxt ballI, rtac ctxt sym, rtac ctxt trans, rtac ctxt @{thm univ_commute}, rtac ctxt equiv_LSBIS,
  12.998 +        rtac ctxt congruent_str_final, atac, rtac ctxt o_apply])
  12.999      (equiv_LSBISs ~~ congruent_str_finals)] 1;
 12.1000  
 12.1001  fun mk_mor_Rep_tac ctxt defs Reps Abs_inverses coalg_final_setss map_comp_ids map_cong0Ls =
 12.1002    unfold_thms_tac ctxt defs THEN
 12.1003 -  EVERY' [rtac conjI,
 12.1004 -    CONJ_WRAP' (fn thm => rtac ballI THEN' rtac thm) Reps,
 12.1005 +  EVERY' [rtac ctxt conjI,
 12.1006 +    CONJ_WRAP' (fn thm => rtac ctxt ballI THEN' rtac ctxt thm) Reps,
 12.1007      CONJ_WRAP' (fn (Rep, ((map_comp_id, map_cong0L), coalg_final_sets)) =>
 12.1008 -      EVERY' [rtac ballI, rtac (map_comp_id RS trans), rtac map_cong0L,
 12.1009 +      EVERY' [rtac ctxt ballI, rtac ctxt (map_comp_id RS trans), rtac ctxt map_cong0L,
 12.1010          EVERY' (map2 (fn Abs_inverse => fn coalg_final_set =>
 12.1011 -          EVERY' [rtac ballI, rtac (o_apply RS trans), rtac Abs_inverse,
 12.1012 -            etac set_rev_mp, rtac coalg_final_set, rtac Rep])
 12.1013 +          EVERY' [rtac ctxt ballI, rtac ctxt (o_apply RS trans), rtac ctxt Abs_inverse,
 12.1014 +            etac ctxt set_rev_mp, rtac ctxt coalg_final_set, rtac ctxt Rep])
 12.1015          Abs_inverses coalg_final_sets)])
 12.1016      (Reps ~~ ((map_comp_ids ~~ map_cong0Ls) ~~ coalg_final_setss))] 1;
 12.1017  
 12.1018  fun mk_mor_Abs_tac ctxt defs Abs_inverses =
 12.1019    unfold_thms_tac ctxt defs THEN
 12.1020 -  EVERY' [rtac conjI,
 12.1021 -    CONJ_WRAP' (K (rtac ballI THEN' rtac UNIV_I)) Abs_inverses,
 12.1022 -    CONJ_WRAP' (fn thm => rtac ballI THEN' etac (thm RS arg_cong RS sym)) Abs_inverses] 1;
 12.1023 +  EVERY' [rtac ctxt conjI,
 12.1024 +    CONJ_WRAP' (K (rtac ctxt ballI THEN' rtac ctxt UNIV_I)) Abs_inverses,
 12.1025 +    CONJ_WRAP' (fn thm => rtac ctxt ballI THEN' etac ctxt (thm RS arg_cong RS sym)) Abs_inverses] 1;
 12.1026  
 12.1027 -fun mk_mor_unfold_tac m mor_UNIV dtor_defs unfold_defs Abs_inverses morEs map_comp_ids map_cong0s =
 12.1028 -  EVERY' [rtac iffD2, rtac mor_UNIV,
 12.1029 +fun mk_mor_unfold_tac ctxt m mor_UNIV dtor_defs unfold_defs Abs_inverses morEs map_comp_ids map_cong0s =
 12.1030 +  EVERY' [rtac ctxt iffD2, rtac ctxt mor_UNIV,
 12.1031      CONJ_WRAP' (fn ((Abs_inverse, morE), ((dtor_def, unfold_def), (map_comp_id, map_cong0))) =>
 12.1032 -      EVERY' [rtac @{thm ext}, rtac (o_apply RS trans RS sym), rtac (dtor_def RS trans),
 12.1033 -        rtac (unfold_def RS arg_cong RS trans), rtac (Abs_inverse RS arg_cong RS trans),
 12.1034 -        rtac (morE RS arg_cong RS trans), rtac (map_comp_id RS trans),
 12.1035 -        rtac (o_apply RS trans RS sym), rtac map_cong0,
 12.1036 -        REPEAT_DETERM_N m o rtac refl,
 12.1037 -        EVERY' (map (fn thm => rtac (thm RS trans) THEN' rtac (o_apply RS sym)) unfold_defs)])
 12.1038 +      EVERY' [rtac ctxt @{thm ext}, rtac ctxt (o_apply RS trans RS sym), rtac ctxt (dtor_def RS trans),
 12.1039 +        rtac ctxt (unfold_def RS arg_cong RS trans), rtac ctxt (Abs_inverse RS arg_cong RS trans),
 12.1040 +        rtac ctxt (morE RS arg_cong RS trans), rtac ctxt (map_comp_id RS trans),
 12.1041 +        rtac ctxt (o_apply RS trans RS sym), rtac ctxt map_cong0,
 12.1042 +        REPEAT_DETERM_N m o rtac ctxt refl,
 12.1043 +        EVERY' (map (fn thm => rtac ctxt (thm RS trans) THEN' rtac ctxt (o_apply RS sym)) unfold_defs)])
 12.1044      ((Abs_inverses ~~ morEs) ~~ ((dtor_defs ~~ unfold_defs) ~~ (map_comp_ids ~~ map_cong0s)))] 1;
 12.1045  
 12.1046 -fun mk_raw_coind_tac bis_def bis_cong bis_O bis_converse bis_Gr tcoalg coalgT mor_T_final
 12.1047 +fun mk_raw_coind_tac ctxt bis_def bis_cong bis_O bis_converse bis_Gr tcoalg coalgT mor_T_final
 12.1048    sbis_lsbis lsbis_incls incl_lsbiss equiv_LSBISs mor_Rep Rep_injects =
 12.1049    let
 12.1050      val n = length Rep_injects;
 12.1051    in
 12.1052 -    EVERY' [rtac rev_mp, ftac (bis_def RS iffD1),
 12.1053 -      REPEAT_DETERM o etac conjE, rtac bis_cong, rtac bis_O, rtac bis_converse,
 12.1054 -      rtac bis_Gr, rtac tcoalg, rtac mor_Rep, rtac bis_O, atac, rtac bis_Gr, rtac tcoalg,
 12.1055 -      rtac mor_Rep, REPEAT_DETERM_N n o etac @{thm relImage_Gr},
 12.1056 -      rtac impI, rtac rev_mp, rtac bis_cong, rtac bis_O, rtac bis_Gr, rtac coalgT,
 12.1057 -      rtac mor_T_final, rtac bis_O, rtac sbis_lsbis, rtac bis_converse, rtac bis_Gr, rtac coalgT,
 12.1058 -      rtac mor_T_final, EVERY' (map (fn thm => rtac (thm RS @{thm relInvImage_Gr})) lsbis_incls),
 12.1059 -      rtac impI,
 12.1060 +    EVERY' [rtac ctxt rev_mp, ftac ctxt (bis_def RS iffD1),
 12.1061 +      REPEAT_DETERM o etac ctxt conjE, rtac ctxt bis_cong, rtac ctxt bis_O, rtac ctxt bis_converse,
 12.1062 +      rtac ctxt bis_Gr, rtac ctxt tcoalg, rtac ctxt mor_Rep, rtac ctxt bis_O, atac, rtac ctxt bis_Gr, rtac ctxt tcoalg,
 12.1063 +      rtac ctxt mor_Rep, REPEAT_DETERM_N n o etac ctxt @{thm relImage_Gr},
 12.1064 +      rtac ctxt impI, rtac ctxt rev_mp, rtac ctxt bis_cong, rtac ctxt bis_O, rtac ctxt bis_Gr, rtac ctxt coalgT,
 12.1065 +      rtac ctxt mor_T_final, rtac ctxt bis_O, rtac ctxt sbis_lsbis, rtac ctxt bis_converse, rtac ctxt bis_Gr, rtac ctxt coalgT,
 12.1066 +      rtac ctxt mor_T_final, EVERY' (map (fn thm => rtac ctxt (thm RS @{thm relInvImage_Gr})) lsbis_incls),
 12.1067 +      rtac ctxt impI,
 12.1068        CONJ_WRAP' (fn (Rep_inject, (equiv_LSBIS , (incl_lsbis, lsbis_incl))) =>
 12.1069 -        EVERY' [rtac subset_trans, rtac @{thm relInvImage_UNIV_relImage}, rtac subset_trans,
 12.1070 -          rtac @{thm relInvImage_mono}, rtac subset_trans, etac incl_lsbis,
 12.1071 -          rtac ord_eq_le_trans, rtac @{thm sym[OF relImage_relInvImage]},
 12.1072 -          rtac @{thm xt1(3)}, rtac @{thm Sigma_cong},
 12.1073 -          rtac @{thm proj_image}, rtac @{thm proj_image}, rtac lsbis_incl,
 12.1074 -          rtac subset_trans, rtac @{thm relImage_mono}, rtac incl_lsbis, atac,
 12.1075 -          rtac @{thm relImage_proj}, rtac equiv_LSBIS, rtac @{thm relInvImage_Id_on},
 12.1076 -          rtac Rep_inject])
 12.1077 +        EVERY' [rtac ctxt subset_trans, rtac ctxt @{thm relInvImage_UNIV_relImage}, rtac ctxt subset_trans,
 12.1078 +          rtac ctxt @{thm relInvImage_mono}, rtac ctxt subset_trans, etac ctxt incl_lsbis,
 12.1079 +          rtac ctxt ord_eq_le_trans, rtac ctxt @{thm sym[OF relImage_relInvImage]},
 12.1080 +          rtac ctxt @{thm xt1(3)}, rtac ctxt @{thm Sigma_cong},
 12.1081 +          rtac ctxt @{thm proj_image}, rtac ctxt @{thm proj_image}, rtac ctxt lsbis_incl,
 12.1082 +          rtac ctxt subset_trans, rtac ctxt @{thm relImage_mono}, rtac ctxt incl_lsbis, atac,
 12.1083 +          rtac ctxt @{thm relImage_proj}, rtac ctxt equiv_LSBIS, rtac ctxt @{thm relInvImage_Id_on},
 12.1084 +          rtac ctxt Rep_inject])
 12.1085        (Rep_injects ~~ (equiv_LSBISs ~~ (incl_lsbiss ~~ lsbis_incls)))] 1
 12.1086    end;
 12.1087  
 12.1088 -fun mk_unfold_unique_mor_tac raw_coinds bis mor unfold_defs =
 12.1089 +fun mk_unfold_unique_mor_tac ctxt raw_coinds bis mor unfold_defs =
 12.1090    CONJ_WRAP' (fn (raw_coind, unfold_def) =>
 12.1091 -    EVERY' [rtac @{thm ext}, etac (bis RS raw_coind RS set_mp RS @{thm IdD}), rtac mor,
 12.1092 -      rtac @{thm image2_eqI}, rtac refl, rtac (unfold_def RS arg_cong RS trans),
 12.1093 -      rtac (o_apply RS sym), rtac UNIV_I]) (raw_coinds ~~ unfold_defs) 1;
 12.1094 +    EVERY' [rtac ctxt @{thm ext}, etac ctxt (bis RS raw_coind RS set_mp RS @{thm IdD}), rtac ctxt mor,
 12.1095 +      rtac ctxt @{thm image2_eqI}, rtac ctxt refl, rtac ctxt (unfold_def RS arg_cong RS trans),
 12.1096 +      rtac ctxt (o_apply RS sym), rtac ctxt UNIV_I]) (raw_coinds ~~ unfold_defs) 1;
 12.1097  
 12.1098  fun mk_dtor_o_ctor_tac ctxt ctor_def unfold map_comp_id map_cong0L unfold_o_dtors =
 12.1099 -  unfold_thms_tac ctxt [ctor_def] THEN EVERY' [rtac @{thm ext}, rtac trans, rtac o_apply,
 12.1100 -    rtac trans, rtac unfold, rtac trans, rtac map_comp_id, rtac trans, rtac map_cong0L,
 12.1101 +  unfold_thms_tac ctxt [ctor_def] THEN EVERY' [rtac ctxt @{thm ext}, rtac ctxt trans, rtac ctxt o_apply,
 12.1102 +    rtac ctxt trans, rtac ctxt unfold, rtac ctxt trans, rtac ctxt map_comp_id, rtac ctxt trans, rtac ctxt map_cong0L,
 12.1103      EVERY' (map (fn thm =>
 12.1104 -      rtac ballI THEN' rtac (trans OF [thm RS fun_cong, id_apply])) unfold_o_dtors),
 12.1105 -    rtac sym, rtac id_apply] 1;
 12.1106 +      rtac ctxt ballI THEN' rtac ctxt (trans OF [thm RS fun_cong, id_apply])) unfold_o_dtors),
 12.1107 +    rtac ctxt sym, rtac ctxt id_apply] 1;
 12.1108  
 12.1109  fun mk_corec_tac ctxt m corec_defs unfold map_cong0 corec_Inls =
 12.1110 -  unfold_thms_tac ctxt corec_defs THEN EVERY' [rtac trans, rtac (o_apply RS arg_cong),
 12.1111 -    rtac trans, rtac unfold, fo_rtac (@{thm sum.case(2)} RS arg_cong RS trans) ctxt, rtac map_cong0,
 12.1112 -    REPEAT_DETERM_N m o rtac refl,
 12.1113 -    EVERY' (map (fn thm => rtac @{thm case_sum_expand_Inr} THEN' rtac thm) corec_Inls)] 1;
 12.1114 +  unfold_thms_tac ctxt corec_defs THEN EVERY' [rtac ctxt trans, rtac ctxt (o_apply RS arg_cong),
 12.1115 +    rtac ctxt trans, rtac ctxt unfold, fo_rtac ctxt (@{thm sum.case(2)} RS arg_cong RS trans),
 12.1116 +    rtac ctxt map_cong0, REPEAT_DETERM_N m o rtac ctxt refl,
 12.1117 +    EVERY' (map (fn thm => rtac ctxt @{thm case_sum_expand_Inr} THEN' rtac ctxt thm) corec_Inls)] 1;
 12.1118  
 12.1119  fun mk_corec_unique_mor_tac ctxt corec_defs corec_Inls unfold_unique_mor =
 12.1120    unfold_thms_tac ctxt
 12.1121      (corec_defs @ map (fn thm => thm RS @{thm case_sum_expand_Inr'}) corec_Inls) THEN
 12.1122 -  etac unfold_unique_mor 1;
 12.1123 +  etac ctxt unfold_unique_mor 1;
 12.1124  
 12.1125 -fun mk_dtor_coinduct_tac m raw_coind bis_rel rel_congs =
 12.1126 -  EVERY' [rtac rev_mp, rtac raw_coind, rtac iffD2, rtac bis_rel, rtac conjI,
 12.1127 -    CONJ_WRAP' (K (rtac @{thm ord_le_eq_trans[OF subset_UNIV UNIV_Times_UNIV[THEN sym]]}))
 12.1128 +fun mk_dtor_coinduct_tac ctxt m raw_coind bis_rel rel_congs =
 12.1129 +  EVERY' [rtac ctxt rev_mp, rtac ctxt raw_coind, rtac ctxt iffD2, rtac ctxt bis_rel, rtac ctxt conjI,
 12.1130 +    CONJ_WRAP' (K (rtac ctxt @{thm ord_le_eq_trans[OF subset_UNIV UNIV_Times_UNIV[THEN sym]]}))
 12.1131      rel_congs,
 12.1132 -    CONJ_WRAP' (fn rel_cong => EVERY' [rtac allI, rtac allI, rtac impI,
 12.1133 -      REPEAT_DETERM o etac allE, rtac (rel_cong RS @{thm eq_refl} RS @{thm predicate2D}),
 12.1134 -      REPEAT_DETERM_N m o rtac refl,
 12.1135 -      REPEAT_DETERM_N (length rel_congs) o rtac @{thm in_rel_Collect_split_eq[symmetric]},
 12.1136 -      etac mp, etac CollectE, etac @{thm splitD}])
 12.1137 +    CONJ_WRAP' (fn rel_cong => EVERY' [rtac ctxt allI, rtac ctxt allI, rtac ctxt impI,
 12.1138 +      REPEAT_DETERM o etac ctxt allE, rtac ctxt (rel_cong RS @{thm eq_refl} RS @{thm predicate2D}),
 12.1139 +      REPEAT_DETERM_N m o rtac ctxt refl,
 12.1140 +      REPEAT_DETERM_N (length rel_congs) o rtac ctxt @{thm in_rel_Collect_split_eq[symmetric]},
 12.1141 +      etac ctxt mp, etac ctxt CollectE, etac ctxt @{thm splitD}])
 12.1142      rel_congs,
 12.1143 -    rtac impI, REPEAT_DETERM o etac conjE,
 12.1144 -    CONJ_WRAP' (K (EVERY' [rtac impI, rtac @{thm IdD}, etac set_mp,
 12.1145 -      rtac CollectI, etac @{thm case_prodI}])) rel_congs] 1;
 12.1146 +    rtac ctxt impI, REPEAT_DETERM o etac ctxt conjE,
 12.1147 +    CONJ_WRAP' (K (EVERY' [rtac ctxt impI, rtac ctxt @{thm IdD}, etac ctxt set_mp,
 12.1148 +      rtac ctxt CollectI, etac ctxt @{thm case_prodI}])) rel_congs] 1;
 12.1149  
 12.1150 -fun mk_map_tac m n map_arg_cong unfold map_comp map_cong0 =
 12.1151 -  EVERY' [rtac @{thm ext}, rtac (o_apply RS trans RS sym), rtac (o_apply RS trans RS sym),
 12.1152 -    rtac (unfold RS trans), rtac (Thm.permute_prems 0 1 (map_comp RS @{thm box_equals})),
 12.1153 -    rtac map_cong0,
 12.1154 -    REPEAT_DETERM_N m o rtac (@{thm id_comp} RS fun_cong),
 12.1155 -    REPEAT_DETERM_N n o rtac (@{thm comp_id} RS fun_cong),
 12.1156 -    rtac map_arg_cong, rtac (o_apply RS sym)] 1;
 12.1157 +fun mk_map_tac ctxt m n map_arg_cong unfold map_comp map_cong0 =
 12.1158 +  EVERY' [rtac ctxt @{thm ext}, rtac ctxt (o_apply RS trans RS sym), rtac ctxt (o_apply RS trans RS sym),
 12.1159 +    rtac ctxt (unfold RS trans), rtac ctxt (Thm.permute_prems 0 1 (map_comp RS @{thm box_equals})),
 12.1160 +    rtac ctxt map_cong0,
 12.1161 +    REPEAT_DETERM_N m o rtac ctxt (@{thm id_comp} RS fun_cong),
 12.1162 +    REPEAT_DETERM_N n o rtac ctxt (@{thm comp_id} RS fun_cong),
 12.1163 +    rtac ctxt map_arg_cong, rtac ctxt (o_apply RS sym)] 1;
 12.1164  
 12.1165 -fun mk_set_le_tac n Jset_minimal set_Jsets set_Jset_Jsetss =
 12.1166 -  EVERY' [rtac Jset_minimal,
 12.1167 -    REPEAT_DETERM_N n o rtac @{thm Un_upper1},
 12.1168 +fun mk_set_le_tac ctxt n Jset_minimal set_Jsets set_Jset_Jsetss =
 12.1169 +  EVERY' [rtac ctxt Jset_minimal,
 12.1170 +    REPEAT_DETERM_N n o rtac ctxt @{thm Un_upper1},
 12.1171      REPEAT_DETERM_N n o
 12.1172        EVERY' (@{map 3} (fn i => fn set_Jset => fn set_Jset_Jsets =>
 12.1173 -        EVERY' [rtac subsetI, rtac @{thm UnI2}, rtac (mk_UnIN n i), etac @{thm UN_I},
 12.1174 -          etac UnE, etac set_Jset, REPEAT_DETERM_N (n - 1) o etac UnE,
 12.1175 -          EVERY' (map (fn thm => EVERY' [etac @{thm UN_E}, etac thm, atac]) set_Jset_Jsets)])
 12.1176 +        EVERY' [rtac ctxt subsetI, rtac ctxt @{thm UnI2}, rtac ctxt (mk_UnIN n i), etac ctxt @{thm UN_I},
 12.1177 +          etac ctxt UnE, etac ctxt set_Jset, REPEAT_DETERM_N (n - 1) o etac ctxt UnE,
 12.1178 +          EVERY' (map (fn thm => EVERY' [etac ctxt @{thm UN_E}, etac ctxt thm, atac]) set_Jset_Jsets)])
 12.1179        (1 upto n) set_Jsets set_Jset_Jsetss)] 1;
 12.1180  
 12.1181 -fun mk_set_ge_tac n set_incl_Jset set_Jset_incl_Jsets =
 12.1182 -  EVERY' [rtac @{thm Un_least}, rtac set_incl_Jset,
 12.1183 -    REPEAT_DETERM_N (n - 1) o rtac @{thm Un_least},
 12.1184 -    EVERY' (map (fn thm => rtac @{thm UN_least} THEN' etac thm) set_Jset_incl_Jsets)] 1;
 12.1185 +fun mk_set_ge_tac ctxt n set_incl_Jset set_Jset_incl_Jsets =
 12.1186 +  EVERY' [rtac ctxt @{thm Un_least}, rtac ctxt set_incl_Jset,
 12.1187 +    REPEAT_DETERM_N (n - 1) o rtac ctxt @{thm Un_least},
 12.1188 +    EVERY' (map (fn thm => rtac ctxt @{thm UN_least} THEN' etac ctxt thm) set_Jset_incl_Jsets)] 1;
 12.1189  
 12.1190 -fun mk_map_id0_tac maps unfold_unique unfold_dtor =
 12.1191 -  EVERY' [rtac (unfold_unique RS trans), EVERY' (map (rtac o mk_sym) maps),
 12.1192 -    rtac unfold_dtor] 1;
 12.1193 +fun mk_map_id0_tac ctxt maps unfold_unique unfold_dtor =
 12.1194 +  EVERY' [rtac ctxt (unfold_unique RS trans), EVERY' (map (rtac ctxt o mk_sym) maps),
 12.1195 +    rtac ctxt unfold_dtor] 1;
 12.1196  
 12.1197 -fun mk_map_comp0_tac maps map_comp0s map_unique =
 12.1198 -  EVERY' [rtac map_unique,
 12.1199 +fun mk_map_comp0_tac ctxt maps map_comp0s map_unique =
 12.1200 +  EVERY' [rtac ctxt map_unique,
 12.1201      EVERY' (map2 (fn map_thm => fn map_comp0 =>
 12.1202 -      EVERY' (map rtac
 12.1203 +      EVERY' (map (rtac ctxt)
 12.1204          [@{thm comp_assoc[symmetric]} RS trans,
 12.1205          @{thm arg_cong2[of _ _ _ _ "op o"]} OF [map_thm, refl] RS trans,
 12.1206          @{thm comp_assoc[symmetric]} RS sym RS trans, map_thm RS arg_cong RS trans,
 12.1207 @@ -815,136 +816,136 @@
 12.1208      val n = length map_comps;
 12.1209      val ks = 1 upto n;
 12.1210    in
 12.1211 -    EVERY' ([rtac rev_mp, coinduct_tac] @
 12.1212 +    EVERY' ([rtac ctxt rev_mp, coinduct_tac] @
 12.1213        maps (fn ((((((map_comp_trans, dtor_maps_trans), map_cong0), set_map0s), set_Jsets),
 12.1214          set_Jset_Jsetss), in_rel) =>
 12.1215          [REPEAT_DETERM o resolve_tac ctxt [allI, impI, in_rel RS iffD2],
 12.1216 -         REPEAT_DETERM o eresolve_tac ctxt [exE, conjE], hyp_subst_tac ctxt, rtac exI,
 12.1217 -         rtac (Drule.rotate_prems 1 conjI),
 12.1218 -         rtac conjI, rtac map_comp_trans, rtac sym, rtac dtor_maps_trans, rtac map_cong0,
 12.1219 -         REPEAT_DETERM_N m o (rtac o_apply_trans_sym THEN' rtac @{thm fst_conv}),
 12.1220 -         REPEAT_DETERM_N n o rtac fst_convol_fun_cong_sym,
 12.1221 -         rtac map_comp_trans, rtac sym, rtac dtor_maps_trans, rtac map_cong0,
 12.1222 +         REPEAT_DETERM o eresolve_tac ctxt [exE, conjE], hyp_subst_tac ctxt, rtac ctxt exI,
 12.1223 +         rtac ctxt (Drule.rotate_prems 1 conjI),
 12.1224 +         rtac ctxt conjI, rtac ctxt map_comp_trans, rtac ctxt sym, rtac ctxt dtor_maps_trans, rtac ctxt map_cong0,
 12.1225 +         REPEAT_DETERM_N m o (rtac ctxt o_apply_trans_sym THEN' rtac ctxt @{thm fst_conv}),
 12.1226 +         REPEAT_DETERM_N n o rtac ctxt fst_convol_fun_cong_sym,
 12.1227 +         rtac ctxt map_comp_trans, rtac ctxt sym, rtac ctxt dtor_maps_trans, rtac ctxt map_cong0,
 12.1228           EVERY' (maps (fn set_Jset =>
 12.1229 -           [rtac o_apply_trans_sym, rtac (@{thm snd_conv} RS trans), etac CollectE,
 12.1230 -           REPEAT_DETERM o etac conjE, etac bspec, etac set_Jset]) set_Jsets),
 12.1231 -         REPEAT_DETERM_N n o rtac snd_convol_fun_cong_sym,
 12.1232 -         rtac CollectI,
 12.1233 -         EVERY' (map (fn set_map0 => EVERY' [rtac conjI, rtac ord_eq_le_trans, rtac set_map0,
 12.1234 -           rtac @{thm image_subsetI}, rtac CollectI, rtac @{thm case_prodI}, rtac refl])
 12.1235 +           [rtac ctxt o_apply_trans_sym, rtac ctxt (@{thm snd_conv} RS trans), etac ctxt CollectE,
 12.1236 +           REPEAT_DETERM o etac ctxt conjE, etac ctxt bspec, etac ctxt set_Jset]) set_Jsets),
 12.1237 +         REPEAT_DETERM_N n o rtac ctxt snd_convol_fun_cong_sym,
 12.1238 +         rtac ctxt CollectI,
 12.1239 +         EVERY' (map (fn set_map0 => EVERY' [rtac ctxt conjI, rtac ctxt ord_eq_le_trans, rtac ctxt set_map0,
 12.1240 +           rtac ctxt @{thm image_subsetI}, rtac ctxt CollectI, rtac ctxt @{thm case_prodI}, rtac ctxt refl])
 12.1241          (take m set_map0s)),
 12.1242           CONJ_WRAP' (fn (set_map0, set_Jset_Jsets) =>
 12.1243 -           EVERY' [rtac ord_eq_le_trans, rtac set_map0,
 12.1244 -             rtac @{thm image_subsetI}, rtac CollectI, rtac @{thm case_prodI}, rtac exI, rtac conjI,
 12.1245 -             rtac CollectI, etac CollectE,
 12.1246 -             REPEAT_DETERM o etac conjE,
 12.1247 +           EVERY' [rtac ctxt ord_eq_le_trans, rtac ctxt set_map0,
 12.1248 +             rtac ctxt @{thm image_subsetI}, rtac ctxt CollectI, rtac ctxt @{thm case_prodI}, rtac ctxt exI, rtac ctxt conjI,
 12.1249 +             rtac ctxt CollectI, etac ctxt CollectE,
 12.1250 +             REPEAT_DETERM o etac ctxt conjE,
 12.1251               CONJ_WRAP' (fn set_Jset_Jset =>
 12.1252 -               EVERY' [rtac ballI, etac bspec, etac set_Jset_Jset, atac]) set_Jset_Jsets,
 12.1253 -             rtac (conjI OF [refl, refl])])
 12.1254 +               EVERY' [rtac ctxt ballI, etac ctxt bspec, etac ctxt set_Jset_Jset, atac]) set_Jset_Jsets,
 12.1255 +             rtac ctxt (conjI OF [refl, refl])])
 12.1256             (drop m set_map0s ~~ set_Jset_Jsetss)])
 12.1257          (map (fn th => th RS trans) map_comps ~~ map (fn th => th RS trans) dtor_maps ~~
 12.1258            map_cong0s ~~ set_map0ss ~~ set_Jsetss ~~ set_Jset_Jsetsss ~~ in_rels) @
 12.1259 -      [rtac impI,
 12.1260 +      [rtac ctxt impI,
 12.1261         CONJ_WRAP' (fn k =>
 12.1262 -         EVERY' [rtac impI, dtac (mk_conjunctN n k), etac mp, rtac exI, rtac conjI, etac CollectI,
 12.1263 -           rtac conjI, rtac refl, rtac refl]) ks]) 1
 12.1264 +         EVERY' [rtac ctxt impI, dtac ctxt (mk_conjunctN n k), etac ctxt mp, rtac ctxt exI, rtac ctxt conjI, etac ctxt CollectI,
 12.1265 +           rtac ctxt conjI, rtac ctxt refl, rtac ctxt refl]) ks]) 1
 12.1266    end
 12.1267  
 12.1268  fun mk_dtor_map_unique_tac ctxt unfold_unique sym_map_comps =
 12.1269 -  rtac unfold_unique 1 THEN
 12.1270 +  rtac ctxt unfold_unique 1 THEN
 12.1271    unfold_thms_tac ctxt (sym_map_comps @ @{thms comp_assoc[symmetric] id_comp comp_id}) THEN
 12.1272 -  ALLGOALS (etac sym);
 12.1273 +  ALLGOALS (etac ctxt sym);
 12.1274  
 12.1275  fun mk_col_natural_tac ctxt cts rec_0s rec_Sucs dtor_maps set_map0ss =
 12.1276    let
 12.1277      val n = length dtor_maps;
 12.1278    in
 12.1279 -    EVERY' [rtac (Drule.instantiate' [] cts nat_induct),
 12.1280 -      REPEAT_DETERM o rtac allI, SELECT_GOAL (unfold_thms_tac ctxt rec_0s),
 12.1281 -      CONJ_WRAP' (K (rtac @{thm image_empty})) rec_0s,
 12.1282 -      REPEAT_DETERM o rtac allI,
 12.1283 +    EVERY' [rtac ctxt (Drule.instantiate' [] cts nat_induct),
 12.1284 +      REPEAT_DETERM o rtac ctxt allI, SELECT_GOAL (unfold_thms_tac ctxt rec_0s),
 12.1285 +      CONJ_WRAP' (K (rtac ctxt @{thm image_empty})) rec_0s,
 12.1286 +      REPEAT_DETERM o rtac ctxt allI,
 12.1287        CONJ_WRAP' (fn (rec_Suc, (dtor_map, set_nats)) => EVERY'
 12.1288          [SELECT_GOAL (unfold_thms_tac ctxt
 12.1289            (rec_Suc :: dtor_map :: set_nats @ @{thms image_Un image_UN UN_simps(10)})),
 12.1290 -        rtac Un_cong, rtac refl,
 12.1291 -        CONJ_WRAP_GEN' (rtac (Thm.permute_prems 0 1 Un_cong))
 12.1292 -          (fn i => EVERY' [rtac @{thm SUP_cong[OF refl]},
 12.1293 -            REPEAT_DETERM o etac allE, etac (mk_conjunctN n i)]) (n downto 1)])
 12.1294 +        rtac ctxt Un_cong, rtac ctxt refl,
 12.1295 +        CONJ_WRAP_GEN' (rtac ctxt (Thm.permute_prems 0 1 Un_cong))
 12.1296 +          (fn i => EVERY' [rtac ctxt @{thm SUP_cong[OF refl]},
 12.1297 +            REPEAT_DETERM o etac ctxt allE, etac ctxt (mk_conjunctN n i)]) (n downto 1)])
 12.1298        (rec_Sucs ~~ (dtor_maps ~~ set_map0ss))] 1
 12.1299    end;
 12.1300  
 12.1301 -fun mk_set_map0_tac col_natural =
 12.1302 -  EVERY' (map rtac [@{thm ext}, o_apply RS trans, sym, o_apply RS trans, @{thm image_UN} RS trans,
 12.1303 -    refl RS @{thm SUP_cong}, col_natural]) 1;
 12.1304 +fun mk_set_map0_tac ctxt col_natural =
 12.1305 +  EVERY' (map (rtac ctxt) [@{thm ext}, o_apply RS trans, sym, o_apply RS trans,
 12.1306 +    @{thm image_UN} RS trans, refl RS @{thm SUP_cong}, col_natural]) 1;
 12.1307  
 12.1308 -fun mk_col_bd_tac m j cts rec_0s rec_Sucs sbd_Card_order sbd_Cinfinite set_sbdss =
 12.1309 +fun mk_col_bd_tac ctxt m j cts rec_0s rec_Sucs sbd_Card_order sbd_Cinfinite set_sbdss =
 12.1310    let
 12.1311      val n = length rec_0s;
 12.1312    in
 12.1313 -    EVERY' [rtac (Drule.instantiate' [] cts nat_induct),
 12.1314 -      REPEAT_DETERM o rtac allI,
 12.1315 -      CONJ_WRAP' (fn rec_0 => EVERY' (map rtac [ordIso_ordLeq_trans,
 12.1316 +    EVERY' [rtac ctxt (Drule.instantiate' [] cts nat_induct),
 12.1317 +      REPEAT_DETERM o rtac ctxt allI,
 12.1318 +      CONJ_WRAP' (fn rec_0 => EVERY' (map (rtac ctxt) [ordIso_ordLeq_trans,
 12.1319          @{thm card_of_ordIso_subst}, rec_0, @{thm Card_order_empty}, sbd_Card_order])) rec_0s,
 12.1320 -      REPEAT_DETERM o rtac allI,
 12.1321 +      REPEAT_DETERM o rtac ctxt allI,
 12.1322        CONJ_WRAP' (fn (rec_Suc, set_sbds) => EVERY'
 12.1323 -        [rtac ordIso_ordLeq_trans, rtac @{thm card_of_ordIso_subst}, rtac rec_Suc,
 12.1324 -        rtac (sbd_Cinfinite RSN (3, @{thm Un_Cinfinite_bound})), rtac (nth set_sbds (j - 1)),
 12.1325 -        REPEAT_DETERM_N (n - 1) o rtac (sbd_Cinfinite RSN (3, @{thm Un_Cinfinite_bound})),
 12.1326 -        EVERY' (map2 (fn i => fn set_sbd => EVERY' [rtac @{thm UNION_Cinfinite_bound},
 12.1327 -          rtac set_sbd, rtac ballI, REPEAT_DETERM o etac allE,
 12.1328 -          etac (mk_conjunctN n i), rtac sbd_Cinfinite]) (1 upto n) (drop m set_sbds))])
 12.1329 +        [rtac ctxt ordIso_ordLeq_trans, rtac ctxt @{thm card_of_ordIso_subst}, rtac ctxt rec_Suc,
 12.1330 +        rtac ctxt (sbd_Cinfinite RSN (3, @{thm Un_Cinfinite_bound})), rtac ctxt (nth set_sbds (j - 1)),
 12.1331 +        REPEAT_DETERM_N (n - 1) o rtac ctxt (sbd_Cinfinite RSN (3, @{thm Un_Cinfinite_bound})),
 12.1332 +        EVERY' (map2 (fn i => fn set_sbd => EVERY' [rtac ctxt @{thm UNION_Cinfinite_bound},
 12.1333 +          rtac ctxt set_sbd, rtac ctxt ballI, REPEAT_DETERM o etac ctxt allE,
 12.1334 +          etac ctxt (mk_conjunctN n i), rtac ctxt sbd_Cinfinite]) (1 upto n) (drop m set_sbds))])
 12.1335        (rec_Sucs ~~ set_sbdss)] 1
 12.1336    end;
 12.1337  
 12.1338 -fun mk_set_bd_tac sbd_Cinfinite col_bd =
 12.1339 -  EVERY' (map rtac [@{thm UNION_Cinfinite_bound}, ordIso_ordLeq_trans, @{thm card_of_nat},
 12.1340 +fun mk_set_bd_tac ctxt sbd_Cinfinite col_bd =
 12.1341 +  EVERY' (map (rtac ctxt) [@{thm UNION_Cinfinite_bound}, ordIso_ordLeq_trans, @{thm card_of_nat},
 12.1342      @{thm natLeq_ordLeq_cinfinite}, sbd_Cinfinite, ballI, col_bd, sbd_Cinfinite]) 1;
 12.1343  
 12.1344 -fun mk_le_rel_OO_tac coinduct rel_Jrels le_rel_OOs =
 12.1345 -  EVERY' (rtac coinduct :: map2 (fn rel_Jrel => fn le_rel_OO =>
 12.1346 +fun mk_le_rel_OO_tac ctxt coinduct rel_Jrels le_rel_OOs =
 12.1347 +  EVERY' (rtac ctxt coinduct :: map2 (fn rel_Jrel => fn le_rel_OO =>
 12.1348      let val Jrel_imp_rel = rel_Jrel RS iffD1;
 12.1349      in
 12.1350 -      EVERY' [rtac (le_rel_OO RS @{thm predicate2D}), etac @{thm relcomppE},
 12.1351 -      rtac @{thm relcomppI}, etac Jrel_imp_rel, etac Jrel_imp_rel]
 12.1352 +      EVERY' [rtac ctxt (le_rel_OO RS @{thm predicate2D}), etac ctxt @{thm relcomppE},
 12.1353 +      rtac ctxt @{thm relcomppI}, etac ctxt Jrel_imp_rel, etac ctxt Jrel_imp_rel]
 12.1354      end)
 12.1355    rel_Jrels le_rel_OOs) 1;
 12.1356  
 12.1357  fun mk_wit_tac ctxt n dtor_ctors dtor_set wit coind_wits =
 12.1358 -  ALLGOALS (TRY o (eresolve_tac ctxt coind_wits THEN' rtac refl)) THEN
 12.1359 +  ALLGOALS (TRY o (eresolve_tac ctxt coind_wits THEN' rtac ctxt refl)) THEN
 12.1360    REPEAT_DETERM (atac 1 ORELSE
 12.1361 -    EVERY' [dtac set_rev_mp, rtac equalityD1, resolve_tac ctxt dtor_set,
 12.1362 +    EVERY' [dtac ctxt set_rev_mp, rtac ctxt equalityD1, resolve_tac ctxt dtor_set,
 12.1363      K (unfold_thms_tac ctxt dtor_ctors),
 12.1364 -    REPEAT_DETERM_N n o etac UnE,
 12.1365 +    REPEAT_DETERM_N n o etac ctxt UnE,
 12.1366      REPEAT_DETERM o
 12.1367 -      (TRY o REPEAT_DETERM o etac UnE THEN' TRY o etac @{thm UN_E} THEN'
 12.1368 +      (TRY o REPEAT_DETERM o etac ctxt UnE THEN' TRY o etac ctxt @{thm UN_E} THEN'
 12.1369          (eresolve_tac ctxt wit ORELSE'
 12.1370          (dresolve_tac ctxt wit THEN'
 12.1371 -          (etac FalseE ORELSE'
 12.1372 -          EVERY' [hyp_subst_tac ctxt, dtac set_rev_mp, rtac equalityD1, resolve_tac ctxt dtor_set,
 12.1373 -            K (unfold_thms_tac ctxt dtor_ctors), REPEAT_DETERM_N n o etac UnE]))))] 1);
 12.1374 +          (etac ctxt FalseE ORELSE'
 12.1375 +          EVERY' [hyp_subst_tac ctxt, dtac ctxt set_rev_mp, rtac ctxt equalityD1, resolve_tac ctxt dtor_set,
 12.1376 +            K (unfold_thms_tac ctxt dtor_ctors), REPEAT_DETERM_N n o etac ctxt UnE]))))] 1);
 12.1377  
 12.1378  fun mk_coind_wit_tac ctxt induct unfolds set_nats wits =
 12.1379 -  rtac induct 1 THEN ALLGOALS (TRY o rtac impI THEN' TRY o hyp_subst_tac ctxt) THEN
 12.1380 +  rtac ctxt induct 1 THEN ALLGOALS (TRY o rtac ctxt impI THEN' TRY o hyp_subst_tac ctxt) THEN
 12.1381    unfold_thms_tac ctxt (unfolds @ set_nats @ @{thms image_id id_apply}) THEN
 12.1382 -  ALLGOALS (REPEAT_DETERM o etac imageE THEN' TRY o hyp_subst_tac ctxt) THEN
 12.1383 +  ALLGOALS (REPEAT_DETERM o etac ctxt imageE THEN' TRY o hyp_subst_tac ctxt) THEN
 12.1384    ALLGOALS (TRY o
 12.1385 -    FIRST' [rtac TrueI, rtac refl, etac (refl RSN (2, mp)), dresolve_tac ctxt wits THEN' etac FalseE]);
 12.1386 +    FIRST' [rtac ctxt TrueI, rtac ctxt refl, etac ctxt (refl RSN (2, mp)), dresolve_tac ctxt wits THEN' etac ctxt FalseE]);
 12.1387  
 12.1388  fun mk_dtor_corec_transfer_tac ctxt n m dtor_corec_defs dtor_unfold_transfer pre_T_map_transfers
 12.1389      dtor_rels =
 12.1390    CONJ_WRAP (fn (dtor_corec_def, dtor_unfold_transfer) =>
 12.1391 -      REPEAT_DETERM (HEADGOAL (rtac rel_funI)) THEN
 12.1392 +      REPEAT_DETERM (HEADGOAL (rtac ctxt rel_funI)) THEN
 12.1393        unfold_thms_tac ctxt [dtor_corec_def, o_apply] THEN
 12.1394 -      HEADGOAL (rtac (mk_rel_funDN (n + 1) dtor_unfold_transfer) THEN'
 12.1395 +      HEADGOAL (rtac ctxt (mk_rel_funDN (n + 1) dtor_unfold_transfer) THEN'
 12.1396          EVERY' (map2 (fn pre_T_map_transfer => fn dtor_rel =>
 12.1397 -          etac (mk_rel_funDN_rotated 2 @{thm case_sum_transfer}) THEN'
 12.1398 -          rtac (mk_rel_funDN 2 @{thm comp_transfer}) THEN'
 12.1399 -          rtac (mk_rel_funDN (m + n) pre_T_map_transfer) THEN'
 12.1400 -          REPEAT_DETERM_N m o rtac @{thm id_transfer} THEN'
 12.1401 -          REPEAT_DETERM_N n o rtac @{thm Inl_transfer} THEN'
 12.1402 -          rtac rel_funI THEN'
 12.1403 -          etac (dtor_rel RS iffD1)) pre_T_map_transfers dtor_rels) THEN'
 12.1404 -        etac (mk_rel_funDN 1 @{thm Inr_transfer})))
 12.1405 +          etac ctxt (mk_rel_funDN_rotated 2 @{thm case_sum_transfer}) THEN'
 12.1406 +          rtac ctxt (mk_rel_funDN 2 @{thm comp_transfer}) THEN'
 12.1407 +          rtac ctxt (mk_rel_funDN (m + n) pre_T_map_transfer) THEN'
 12.1408 +          REPEAT_DETERM_N m o rtac ctxt @{thm id_transfer} THEN'
 12.1409 +          REPEAT_DETERM_N n o rtac ctxt @{thm Inl_transfer} THEN'
 12.1410 +          rtac ctxt rel_funI THEN'
 12.1411 +          etac ctxt (dtor_rel RS iffD1)) pre_T_map_transfers dtor_rels) THEN'
 12.1412 +        etac ctxt (mk_rel_funDN 1 @{thm Inr_transfer})))
 12.1413      (dtor_corec_defs ~~ dtor_unfold_transfer);
 12.1414  
 12.1415  fun mk_dtor_rel_tac ctxt in_Jrels i in_rel map_comp0 map_cong0 dtor_map dtor_sets dtor_inject
 12.1416 @@ -955,59 +956,59 @@
 12.1417      val (passive_set_map0s, active_set_map0s) = chop m set_map0s;
 12.1418      val in_Jrel = nth in_Jrels (i - 1);
 12.1419      val if_tac =
 12.1420 -      EVERY' [dtac (in_Jrel RS iffD1), REPEAT_DETERM o eresolve_tac ctxt [exE, conjE, CollectE],
 12.1421 -        rtac (in_rel RS iffD2), rtac exI, rtac conjI, rtac CollectI,
 12.1422 +      EVERY' [dtac ctxt (in_Jrel RS iffD1), REPEAT_DETERM o eresolve_tac ctxt [exE, conjE, CollectE],
 12.1423 +        rtac ctxt (in_rel RS iffD2), rtac ctxt exI, rtac ctxt conjI, rtac ctxt CollectI,
 12.1424          EVERY' (map2 (fn set_map0 => fn set_incl =>
 12.1425 -          EVERY' [rtac conjI, rtac ord_eq_le_trans, rtac set_map0,
 12.1426 -            rtac ord_eq_le_trans, rtac trans_fun_cong_image_id_id_apply,
 12.1427 -            etac (set_incl RS @{thm subset_trans})])
 12.1428 +          EVERY' [rtac ctxt conjI, rtac ctxt ord_eq_le_trans, rtac ctxt set_map0,
 12.1429 +            rtac ctxt ord_eq_le_trans, rtac ctxt trans_fun_cong_image_id_id_apply,
 12.1430 +            etac ctxt (set_incl RS @{thm subset_trans})])
 12.1431          passive_set_map0s dtor_set_incls),
 12.1432          CONJ_WRAP' (fn (in_Jrel, (set_map0, dtor_set_set_incls)) =>
 12.1433 -          EVERY' [rtac ord_eq_le_trans, rtac set_map0, rtac @{thm image_subsetI}, rtac CollectI,
 12.1434 -            rtac @{thm case_prodI}, rtac (in_Jrel RS iffD2), rtac exI, rtac conjI, rtac CollectI,
 12.1435 -            CONJ_WRAP' (fn thm => etac (thm RS @{thm subset_trans}) THEN' atac) dtor_set_set_incls,
 12.1436 -            rtac conjI, rtac refl, rtac refl])
 12.1437 +          EVERY' [rtac ctxt ord_eq_le_trans, rtac ctxt set_map0, rtac ctxt @{thm image_subsetI}, rtac ctxt CollectI,
 12.1438 +            rtac ctxt @{thm case_prodI}, rtac ctxt (in_Jrel RS iffD2), rtac ctxt exI, rtac ctxt conjI, rtac ctxt CollectI,
 12.1439 +            CONJ_WRAP' (fn thm => etac ctxt (thm RS @{thm subset_trans}) THEN' atac) dtor_set_set_incls,
 12.1440 +            rtac ctxt conjI, rtac ctxt refl, rtac ctxt refl])
 12.1441          (in_Jrels ~~ (active_set_map0s ~~ dtor_set_set_inclss)),
 12.1442          CONJ_WRAP' (fn conv =>
 12.1443 -          EVERY' [rtac trans, rtac map_comp0, rtac trans, rtac map_cong0,
 12.1444 -          REPEAT_DETERM_N m o rtac @{thm fun_cong[OF comp_id]},
 12.1445 -          REPEAT_DETERM_N n o EVERY' (map rtac [trans, o_apply, conv]),
 12.1446 -          rtac trans, rtac sym, rtac dtor_map, rtac (dtor_inject RS iffD2), atac])
 12.1447 +          EVERY' [rtac ctxt trans, rtac ctxt map_comp0, rtac ctxt trans, rtac ctxt map_cong0,
 12.1448 +          REPEAT_DETERM_N m o rtac ctxt @{thm fun_cong[OF comp_id]},
 12.1449 +          REPEAT_DETERM_N n o EVERY' (map (rtac ctxt) [trans, o_apply, conv]),
 12.1450 +          rtac ctxt trans, rtac ctxt sym, rtac ctxt dtor_map, rtac ctxt (dtor_inject RS iffD2), atac])
 12.1451          @{thms fst_conv snd_conv}];
 12.1452      val only_if_tac =
 12.1453 -      EVERY' [dtac (in_rel RS iffD1), REPEAT_DETERM o eresolve_tac ctxt [exE, conjE, CollectE],
 12.1454 -        rtac (in_Jrel RS iffD2), rtac exI, rtac conjI, rtac CollectI,
 12.1455 +      EVERY' [dtac ctxt (in_rel RS iffD1), REPEAT_DETERM o eresolve_tac ctxt [exE, conjE, CollectE],
 12.1456 +        rtac ctxt (in_Jrel RS iffD2), rtac ctxt exI, rtac ctxt conjI, rtac ctxt CollectI,
 12.1457          CONJ_WRAP' (fn (dtor_set, passive_set_map0) =>
 12.1458 -          EVERY' [rtac ord_eq_le_trans, rtac dtor_set, rtac @{thm Un_least},
 12.1459 -            rtac ord_eq_le_trans, rtac @{thm box_equals}, rtac passive_set_map0,
 12.1460 -            rtac (dtor_ctor RS sym RS arg_cong), rtac trans_fun_cong_image_id_id_apply, atac,
 12.1461 -            CONJ_WRAP_GEN' (rtac (Thm.permute_prems 0 1 @{thm Un_least}))
 12.1462 -              (fn (active_set_map0, in_Jrel) => EVERY' [rtac ord_eq_le_trans,
 12.1463 -                rtac @{thm SUP_cong[OF _ refl]}, rtac @{thm box_equals[OF _ _ refl]},
 12.1464 -                rtac active_set_map0, rtac (dtor_ctor RS sym RS arg_cong), rtac @{thm UN_least},
 12.1465 -                dtac set_rev_mp, etac @{thm image_mono}, etac imageE,
 12.1466 -                dtac @{thm ssubst_mem[OF pair_collapse]},
 12.1467 +          EVERY' [rtac ctxt ord_eq_le_trans, rtac ctxt dtor_set, rtac ctxt @{thm Un_least},
 12.1468 +            rtac ctxt ord_eq_le_trans, rtac ctxt @{thm box_equals}, rtac ctxt passive_set_map0,
 12.1469 +            rtac ctxt (dtor_ctor RS sym RS arg_cong), rtac ctxt trans_fun_cong_image_id_id_apply, atac,
 12.1470 +            CONJ_WRAP_GEN' (rtac ctxt (Thm.permute_prems 0 1 @{thm Un_least}))
 12.1471 +              (fn (active_set_map0, in_Jrel) => EVERY' [rtac ctxt ord_eq_le_trans,
 12.1472 +                rtac ctxt @{thm SUP_cong[OF _ refl]}, rtac ctxt @{thm box_equals[OF _ _ refl]},
 12.1473 +                rtac ctxt active_set_map0, rtac ctxt (dtor_ctor RS sym RS arg_cong), rtac ctxt @{thm UN_least},
 12.1474 +                dtac ctxt set_rev_mp, etac ctxt @{thm image_mono}, etac ctxt imageE,
 12.1475 +                dtac ctxt @{thm ssubst_mem[OF pair_collapse]},
 12.1476                  REPEAT_DETERM o eresolve_tac ctxt (CollectE :: conjE ::
 12.1477                    @{thms case_prodE iffD1[OF prod.inject, elim_format]}),
 12.1478                  hyp_subst_tac ctxt,
 12.1479 -                dtac (in_Jrel RS iffD1),
 12.1480 -                dtac @{thm someI_ex}, REPEAT_DETERM o etac conjE,
 12.1481 +                dtac ctxt (in_Jrel RS iffD1),
 12.1482 +                dtac ctxt @{thm someI_ex}, REPEAT_DETERM o etac ctxt conjE,
 12.1483                  REPEAT_DETERM o eresolve_tac ctxt [CollectE, conjE], atac])
 12.1484              (rev (active_set_map0s ~~ in_Jrels))])
 12.1485          (dtor_sets ~~ passive_set_map0s),
 12.1486 -        rtac conjI,
 12.1487 -        REPEAT_DETERM_N 2 o EVERY'[rtac (dtor_inject RS iffD1), rtac trans, rtac dtor_map,
 12.1488 -          rtac @{thm box_equals}, rtac map_comp0, rtac (dtor_ctor RS sym RS arg_cong), rtac trans,
 12.1489 -          rtac map_cong0, REPEAT_DETERM_N m o rtac @{thm fun_cong[OF comp_id]},
 12.1490 -          EVERY' (map (fn in_Jrel => EVERY' [rtac trans, rtac o_apply, dtac set_rev_mp, atac,
 12.1491 -            dtac @{thm ssubst_mem[OF pair_collapse]},
 12.1492 +        rtac ctxt conjI,
 12.1493 +        REPEAT_DETERM_N 2 o EVERY'[rtac ctxt (dtor_inject RS iffD1), rtac ctxt trans, rtac ctxt dtor_map,
 12.1494 +          rtac ctxt @{thm box_equals}, rtac ctxt map_comp0, rtac ctxt (dtor_ctor RS sym RS arg_cong), rtac ctxt trans,
 12.1495 +          rtac ctxt map_cong0, REPEAT_DETERM_N m o rtac ctxt @{thm fun_cong[OF comp_id]},
 12.1496 +          EVERY' (map (fn in_Jrel => EVERY' [rtac ctxt trans, rtac ctxt o_apply, dtac ctxt set_rev_mp, atac,
 12.1497 +            dtac ctxt @{thm ssubst_mem[OF pair_collapse]},
 12.1498              REPEAT_DETERM o eresolve_tac ctxt (CollectE :: conjE ::
 12.1499                @{thms case_prodE iffD1[OF prod.inject, elim_format]}),
 12.1500 -            hyp_subst_tac ctxt, dtac (in_Jrel RS iffD1),
 12.1501 -            dtac @{thm someI_ex}, REPEAT_DETERM o etac conjE, atac]) in_Jrels),
 12.1502 +            hyp_subst_tac ctxt, dtac ctxt (in_Jrel RS iffD1),
 12.1503 +            dtac ctxt @{thm someI_ex}, REPEAT_DETERM o etac ctxt conjE, atac]) in_Jrels),
 12.1504            atac]]
 12.1505    in
 12.1506 -    EVERY' [rtac iffI, if_tac, only_if_tac] 1
 12.1507 +    EVERY' [rtac ctxt iffI, if_tac, only_if_tac] 1
 12.1508    end;
 12.1509  
 12.1510  fun mk_rel_coinduct_coind_tac ctxt fst m coinduct ks map_comp0s map_congs map_arg_congs set_map0ss
 12.1511 @@ -1017,29 +1018,29 @@
 12.1512      val fst_diag_nth = if fst then @{thm fst_diag_fst} else @{thm fst_diag_snd};
 12.1513      val snd_diag_nth = if fst then @{thm snd_diag_fst} else @{thm snd_diag_snd};
 12.1514    in
 12.1515 -    EVERY' [rtac coinduct,
 12.1516 +    EVERY' [rtac ctxt coinduct,
 12.1517        EVERY' (@{map 8} (fn i => fn map_comp0 => fn map_cong => fn map_arg_cong => fn set_map0s =>
 12.1518            fn dtor_unfold => fn dtor_map => fn in_rel =>
 12.1519          EVERY' [REPEAT_DETERM o resolve_tac ctxt [allI, impI, in_rel RS iffD2],
 12.1520            REPEAT_DETERM o eresolve_tac ctxt [exE, conjE],
 12.1521 -          select_prem_tac (length ks) (dtac @{thm spec2}) i, dtac mp, atac,
 12.1522 +          select_prem_tac ctxt (length ks) (dtac ctxt @{thm spec2}) i, dtac ctxt mp, atac,
 12.1523            REPEAT_DETERM o eresolve_tac ctxt [CollectE, conjE], hyp_subst_tac ctxt,
 12.1524 -          rtac exI, rtac (Drule.rotate_prems 1 conjI), rtac conjI,
 12.1525 -          rtac (map_comp0 RS trans), rtac (dtor_map RS trans RS sym),
 12.1526 -          rtac (dtor_unfold RS map_arg_cong RS trans), rtac (trans OF [map_comp0, map_cong]),
 12.1527 -          REPEAT_DETERM_N m o rtac (fst_diag_nth RS @{thm fun_cong[OF trans[OF o_id sym]]}),
 12.1528 -          REPEAT_DETERM_N n o (rtac @{thm sym[OF trans[OF o_apply]]} THEN' rtac @{thm fst_conv}),
 12.1529 -          rtac (map_comp0 RS trans), rtac (map_cong RS trans),
 12.1530 -          REPEAT_DETERM_N m o rtac (snd_diag_nth RS fun_cong),
 12.1531 -          REPEAT_DETERM_N n o (rtac @{thm trans[OF o_apply]} THEN' rtac @{thm snd_conv}),
 12.1532 -          etac (@{thm prod.case} RS map_arg_cong RS trans),
 12.1533 +          rtac ctxt exI, rtac ctxt (Drule.rotate_prems 1 conjI), rtac ctxt conjI,
 12.1534 +          rtac ctxt (map_comp0 RS trans), rtac ctxt (dtor_map RS trans RS sym),
 12.1535 +          rtac ctxt (dtor_unfold RS map_arg_cong RS trans), rtac ctxt (trans OF [map_comp0, map_cong]),
 12.1536 +          REPEAT_DETERM_N m o rtac ctxt (fst_diag_nth RS @{thm fun_cong[OF trans[OF o_id sym]]}),
 12.1537 +          REPEAT_DETERM_N n o (rtac ctxt @{thm sym[OF trans[OF o_apply]]} THEN' rtac ctxt @{thm fst_conv}),
 12.1538 +          rtac ctxt (map_comp0 RS trans), rtac ctxt (map_cong RS trans),
 12.1539 +          REPEAT_DETERM_N m o rtac ctxt (snd_diag_nth RS fun_cong),
 12.1540 +          REPEAT_DETERM_N n o (rtac ctxt @{thm trans[OF o_apply]} THEN' rtac ctxt @{thm snd_conv}),
 12.1541 +          etac ctxt (@{thm prod.case} RS map_arg_cong RS trans),
 12.1542            SELECT_GOAL (unfold_thms_tac ctxt @{thms prod.case o_def fst_conv snd_conv}),
 12.1543 -          rtac CollectI,
 12.1544 +          rtac ctxt CollectI,
 12.1545            CONJ_WRAP' (fn set_map0 =>
 12.1546 -            EVERY' [rtac (set_map0 RS ord_eq_le_trans),
 12.1547 -              rtac @{thm image_subsetI}, rtac CollectI, rtac @{thm case_prodI},
 12.1548 -              FIRST' [rtac refl, EVERY'[rtac exI, rtac conjI, etac Collect_splitD_set_mp, atac,
 12.1549 -                rtac (@{thm surjective_pairing} RS arg_cong)]]])
 12.1550 +            EVERY' [rtac ctxt (set_map0 RS ord_eq_le_trans),
 12.1551 +              rtac ctxt @{thm image_subsetI}, rtac ctxt CollectI, rtac ctxt @{thm case_prodI},
 12.1552 +              FIRST' [rtac ctxt refl, EVERY'[rtac ctxt exI, rtac ctxt conjI, etac ctxt Collect_splitD_set_mp, atac,
 12.1553 +                rtac ctxt (@{thm surjective_pairing} RS arg_cong)]]])
 12.1554            set_map0s])
 12.1555        ks map_comp0s map_congs map_arg_congs set_map0ss dtor_unfolds dtor_maps in_rels)] 1
 12.1556    end;
 12.1557 @@ -1049,23 +1050,23 @@
 12.1558  fun mk_rel_coinduct_ind_tac ctxt m ks unfolds set_map0ss j set_induct =
 12.1559    let val n = length ks;
 12.1560    in
 12.1561 -    rtac set_induct 1 THEN
 12.1562 +    rtac ctxt set_induct 1 THEN
 12.1563      EVERY' (@{map 3} (fn unfold => fn set_map0s => fn i =>
 12.1564 -      EVERY' [REPEAT_DETERM o resolve_tac ctxt [allI, impI], etac conjE,
 12.1565 -        select_prem_tac n (dtac @{thm spec2}) i, dtac mp, atac,
 12.1566 +      EVERY' [REPEAT_DETERM o resolve_tac ctxt [allI, impI], etac ctxt conjE,
 12.1567 +        select_prem_tac ctxt n (dtac ctxt @{thm spec2}) i, dtac ctxt mp, atac,
 12.1568          REPEAT_DETERM o eresolve_tac ctxt [CollectE, conjE, Collect_splitD_set_mp, set_rev_mp],
 12.1569          hyp_subst_tac ctxt,
 12.1570          SELECT_GOAL (unfold_thms_tac ctxt ([unfold, nth set_map0s (j - 1)] @ split_id_unfolds)),
 12.1571 -        rtac subset_refl])
 12.1572 +        rtac ctxt subset_refl])
 12.1573      unfolds set_map0ss ks) 1 THEN
 12.1574      EVERY' (@{map 3} (fn unfold => fn set_map0s => fn i =>
 12.1575        EVERY' (map (fn set_map0 =>
 12.1576 -        EVERY' [REPEAT_DETERM o resolve_tac ctxt [allI, impI], etac conjE,
 12.1577 -        select_prem_tac n (dtac @{thm spec2}) i, dtac mp, atac,
 12.1578 +        EVERY' [REPEAT_DETERM o resolve_tac ctxt [allI, impI], etac ctxt conjE,
 12.1579 +        select_prem_tac ctxt n (dtac ctxt @{thm spec2}) i, dtac ctxt mp, atac,
 12.1580          REPEAT_DETERM o eresolve_tac ctxt [CollectE, conjE], hyp_subst_tac ctxt,
 12.1581          SELECT_GOAL (unfold_thms_tac ctxt ([unfold, set_map0] @ split_id_unfolds)),
 12.1582 -        etac imageE, hyp_subst_tac ctxt, REPEAT_DETERM o eresolve_tac ctxt [allE, mp],
 12.1583 -        rtac conjI, etac Collect_splitD_set_mp, atac, rtac (@{thm surjective_pairing} RS arg_cong)])
 12.1584 +        etac ctxt imageE, hyp_subst_tac ctxt, REPEAT_DETERM o eresolve_tac ctxt [allE, mp],
 12.1585 +        rtac ctxt conjI, etac ctxt Collect_splitD_set_mp, atac, rtac ctxt (@{thm surjective_pairing} RS arg_cong)])
 12.1586        (drop m set_map0s)))
 12.1587      unfolds set_map0ss ks) 1
 12.1588    end;
 12.1589 @@ -1075,23 +1076,23 @@
 12.1590    in
 12.1591      Method.insert_tac CIHs 1 THEN
 12.1592      unfold_thms_tac ctxt (@{thm choice_iff} :: @{thm ex_simps(6)[symmetric]} :: in_rels) THEN
 12.1593 -    REPEAT_DETERM (etac exE 1) THEN
 12.1594 +    REPEAT_DETERM (etac ctxt exE 1) THEN
 12.1595      CONJ_WRAP' (fn (in_Jrel, (helper_inds, (helper_coind1, helper_coind2))) =>
 12.1596 -      EVERY' [rtac @{thm predicate2I}, rtac (in_Jrel RS iffD2), rtac exI, rtac conjI,
 12.1597 -        if null helper_inds then rtac UNIV_I
 12.1598 -        else rtac CollectI THEN'
 12.1599 +      EVERY' [rtac ctxt @{thm predicate2I}, rtac ctxt (in_Jrel RS iffD2), rtac ctxt exI, rtac ctxt conjI,
 12.1600 +        if null helper_inds then rtac ctxt UNIV_I
 12.1601 +        else rtac ctxt CollectI THEN'
 12.1602            CONJ_WRAP' (fn helper_ind =>
 12.1603 -            EVERY' [rtac (helper_ind RS rev_mp), REPEAT_DETERM_N n o atac,
 12.1604 -              REPEAT_DETERM_N n o etac thin_rl, rtac impI,
 12.1605 +            EVERY' [rtac ctxt (helper_ind RS rev_mp), REPEAT_DETERM_N n o atac,
 12.1606 +              REPEAT_DETERM_N n o etac ctxt thin_rl, rtac ctxt impI,
 12.1607                REPEAT_DETERM o resolve_tac ctxt [subsetI, CollectI, @{thm iffD2[OF split_beta]}],
 12.1608 -              dtac bspec, atac, REPEAT_DETERM o eresolve_tac ctxt [allE, mp, conjE],
 12.1609 -              etac (refl RSN (2, conjI))])
 12.1610 +              dtac ctxt bspec, atac, REPEAT_DETERM o eresolve_tac ctxt [allE, mp, conjE],
 12.1611 +              etac ctxt (refl RSN (2, conjI))])
 12.1612            helper_inds,
 12.1613 -        rtac conjI,
 12.1614 -        rtac (helper_coind1 RS rev_mp), REPEAT_DETERM_N n o atac, REPEAT_DETERM_N n o etac thin_rl,
 12.1615 -        rtac impI, etac mp, rtac exI, etac (refl RSN (2, conjI)),
 12.1616 -        rtac (helper_coind2 RS rev_mp), REPEAT_DETERM_N n o atac, REPEAT_DETERM_N n o etac thin_rl,
 12.1617 -        rtac impI, etac mp, rtac exI, etac (refl RSN (2, conjI))])
 12.1618 +        rtac ctxt conjI,
 12.1619 +        rtac ctxt (helper_coind1 RS rev_mp), REPEAT_DETERM_N n o atac, REPEAT_DETERM_N n o etac ctxt thin_rl,
 12.1620 +        rtac ctxt impI, etac ctxt mp, rtac ctxt exI, etac ctxt (refl RSN (2, conjI)),
 12.1621 +        rtac ctxt (helper_coind2 RS rev_mp), REPEAT_DETERM_N n o atac, REPEAT_DETERM_N n o etac ctxt thin_rl,
 12.1622 +        rtac ctxt impI, etac ctxt mp, rtac ctxt exI, etac ctxt (refl RSN (2, conjI))])
 12.1623      (in_Jrels ~~ (helper_indss ~~ (helper_coind1s ~~ helper_coind2s))) 1
 12.1624    end;
 12.1625  
 12.1626 @@ -1103,14 +1104,14 @@
 12.1627        @{thms rel_fun_def_butlast all_conj_distrib[symmetric] imp_conjR[symmetric]} THEN
 12.1628      unfold_thms_tac ctxt @{thms rel_fun_iff_geq_image2p} THEN
 12.1629      HEADGOAL (EVERY'
 12.1630 -      [REPEAT_DETERM o resolve_tac ctxt [allI, impI], rtac ctor_rel_coinduct,
 12.1631 +      [REPEAT_DETERM o resolve_tac ctxt [allI, impI], rtac ctxt ctor_rel_coinduct,
 12.1632        EVERY' (map (fn map_transfer => EVERY'
 12.1633 -        [REPEAT_DETERM o resolve_tac ctxt [allI, impI], etac @{thm image2pE}, hyp_subst_tac ctxt,
 12.1634 +        [REPEAT_DETERM o resolve_tac ctxt [allI, impI], etac ctxt @{thm image2pE}, hyp_subst_tac ctxt,
 12.1635          SELECT_GOAL (unfold_thms_tac ctxt unfolds),
 12.1636 -        rtac (funpow (m + n + 1) (fn thm => thm RS rel_funD) map_transfer),
 12.1637 -        REPEAT_DETERM_N m o rtac @{thm id_transfer},
 12.1638 -        REPEAT_DETERM_N n o rtac @{thm rel_fun_image2p},
 12.1639 -        etac @{thm predicate2D}, etac @{thm image2pI}])
 12.1640 +        rtac ctxt (funpow (m + n + 1) (fn thm => thm RS rel_funD) map_transfer),
 12.1641 +        REPEAT_DETERM_N m o rtac ctxt @{thm id_transfer},
 12.1642 +        REPEAT_DETERM_N n o rtac ctxt @{thm rel_fun_image2p},
 12.1643 +        etac ctxt @{thm predicate2D}, etac ctxt @{thm image2pI}])
 12.1644        map_transfers)])
 12.1645    end;
 12.1646  
    13.1 --- a/src/HOL/Tools/BNF/bnf_lfp.ML	Thu Jul 16 10:48:20 2015 +0200
    13.2 +++ b/src/HOL/Tools/BNF/bnf_lfp.ML	Thu Jul 16 12:23:22 2015 +0200
    13.3 @@ -221,7 +221,7 @@
    13.4          val goal = mk_Trueprop_eq (Term.list_comb (mapAsAs, passive_ids @ self_fs) $ x, x);
    13.5        in
    13.6          Goal.prove_sorry lthy [] [] (Logic.list_implies (prems, goal))
    13.7 -          (K (mk_map_cong0L_tac m map_cong0 map_id))
    13.8 +          (fn {context = ctxt, prems = _} => mk_map_cong0L_tac ctxt m map_cong0 map_id)
    13.9          |> Thm.close_derivation
   13.10          |> singleton (Proof_Context.export names_lthy lthy)
   13.11        end;
   13.12 @@ -278,7 +278,8 @@
   13.13            Logic.list_implies (alg_prem :: prems, concl)) premss concls;
   13.14        in
   13.15          map (fn goal =>
   13.16 -          Goal.prove_sorry lthy [] [] goal (K (mk_alg_set_tac alg_def))
   13.17 +          Goal.prove_sorry lthy [] [] goal (fn {context = ctxt, prems = _} =>
   13.18 +            mk_alg_set_tac ctxt alg_def)
   13.19            |> Thm.close_derivation
   13.20            |> singleton (Proof_Context.export names_lthy lthy))
   13.21          goals
   13.22 @@ -355,7 +356,8 @@
   13.23            Logic.list_implies ([prem, mk_elim_prem sets x T],
   13.24              mk_Trueprop_eq (f $ (s $ x), s' $ Term.list_comb (mapAsBs, passive_ids @ fs @ [x])));
   13.25          val elim_goals = @{map 7} mk_elim_goal setssAs mapsAsBs fs ss s's xFs FTsAs;
   13.26 -        fun prove goal = Goal.prove_sorry lthy [] [] goal (K (mk_mor_elim_tac mor_def))
   13.27 +        fun prove goal = Goal.prove_sorry lthy [] [] goal (fn {context = ctxt, prems = _} =>
   13.28 +            mk_mor_elim_tac ctxt mor_def)
   13.29            |> Thm.close_derivation
   13.30            |> singleton (Proof_Context.export names_lthy lthy);
   13.31        in
   13.32 @@ -368,7 +370,7 @@
   13.33          val concl = HOLogic.mk_Trueprop (mk_mor Bs ss Bs_copy ss active_ids);
   13.34        in
   13.35          Goal.prove_sorry lthy [] [] (Logic.list_implies (prems, concl))
   13.36 -          (fn {context = ctxt, ...} => mk_mor_incl_tac ctxt mor_def map_ids)
   13.37 +          (fn {context = ctxt, prems = _} => mk_mor_incl_tac ctxt mor_def map_ids)
   13.38          |> Thm.close_derivation
   13.39          |> singleton (Proof_Context.export names_lthy lthy)
   13.40        end;
   13.41 @@ -382,7 +384,7 @@
   13.42            HOLogic.mk_Trueprop (mk_mor Bs ss B''s s''s (map2 (curry HOLogic.mk_comp) gs fs));
   13.43        in
   13.44          Goal.prove_sorry lthy [] [] (Logic.list_implies (prems, concl))
   13.45 -          (K (mk_mor_comp_tac mor_def set_mapss map_comp_id_thms))
   13.46 +          (fn {context = ctxt, prems = _} => mk_mor_comp_tac ctxt mor_def set_mapss map_comp_id_thms)
   13.47          |> Thm.close_derivation
   13.48          |> singleton (Proof_Context.export names_lthy lthy)
   13.49        end;
   13.50 @@ -394,7 +396,7 @@
   13.51          val concl = HOLogic.mk_Trueprop (mk_mor Bs ss B's s's fs_copy);
   13.52        in
   13.53          Goal.prove_sorry lthy [] [] (Logic.list_implies (prems, concl))
   13.54 -          (K ((hyp_subst_tac lthy THEN' assume_tac lthy) 1))
   13.55 +          (fn {context = ctxt, prems = _} => (hyp_subst_tac ctxt THEN' assume_tac ctxt) 1)
   13.56          |> Thm.close_derivation
   13.57          |> singleton (Proof_Context.export names_lthy lthy)
   13.58        end;
   13.59 @@ -407,7 +409,7 @@
   13.60          Goal.prove_sorry lthy [] []
   13.61            (HOLogic.mk_Trueprop
   13.62              (mk_mor (map HOLogic.mk_UNIV FTsAs) maps active_UNIVs ss ss))
   13.63 -          (K (mk_mor_str_tac ks mor_def))
   13.64 +          (fn {context = ctxt, prems = _} => mk_mor_str_tac ctxt ks mor_def)
   13.65          |> Thm.close_derivation
   13.66          |> singleton (Proof_Context.export names_lthy lthy)
   13.67        end;
   13.68 @@ -421,7 +423,7 @@
   13.69          Goal.prove_sorry lthy [] []
   13.70            (HOLogic.mk_Trueprop
   13.71              (mk_mor prod_UNIVs maps (map HOLogic.mk_UNIV activeBs) s's fsts))
   13.72 -          (K (mk_mor_convol_tac ks mor_def))
   13.73 +          (fn {context = ctxt, prems = _} => mk_mor_convol_tac ctxt ks mor_def)
   13.74          |> Thm.close_derivation
   13.75          |> singleton (Proof_Context.export names_lthy lthy)
   13.76        end;
   13.77 @@ -435,7 +437,7 @@
   13.78          val rhs = Library.foldr1 HOLogic.mk_conj (@{map 4} mk_conjunct mapsAsBs fs ss s's);
   13.79        in
   13.80          Goal.prove_sorry lthy [] [] (mk_Trueprop_eq (lhs, rhs))
   13.81 -          (K (mk_mor_UNIV_tac m morE_thms mor_def))
   13.82 +          (fn {context = ctxt, prems = _} => mk_mor_UNIV_tac ctxt m morE_thms mor_def)
   13.83          |> Thm.close_derivation
   13.84          |> singleton (Proof_Context.export names_lthy lthy)
   13.85        end;
   13.86 @@ -457,7 +459,8 @@
   13.87  
   13.88            val ((sbdT_name, (sbdT_glob_info, sbdT_loc_info)), lthy) =
   13.89              typedef (sbdT_bind, sum_bdT_params', NoSyn)
   13.90 -              (HOLogic.mk_UNIV sum_bdT) NONE (fn _ => EVERY' [rtac exI, rtac UNIV_I] 1) lthy;
   13.91 +              (HOLogic.mk_UNIV sum_bdT) NONE (fn ctxt =>
   13.92 +                EVERY' [rtac ctxt exI, rtac ctxt UNIV_I] 1) lthy;
   13.93  
   13.94            val sbdT = Type (sbdT_name, sum_bdT_params);
   13.95            val Abs_sbdT = Const (#Abs_name sbdT_glob_info, sum_bdT --> sbdT);
   13.96 @@ -548,7 +551,7 @@
   13.97            (Term.absfree jdx' (Library.foldr1 HOLogic.mk_conj (map mk_conjunct idxs))));
   13.98        in
   13.99          Goal.prove_sorry lthy [] [] (Logic.list_implies ([prem], concl))
  13.100 -          (K (mk_bd_limit_tac n suc_bd_Cinfinite))
  13.101 +          (fn {context = ctxt, prems = _} => mk_bd_limit_tac ctxt n suc_bd_Cinfinite)
  13.102          |> Thm.close_derivation
  13.103          |> singleton (Proof_Context.export names_lthy lthy)
  13.104        end;
  13.105 @@ -589,7 +592,7 @@
  13.106          val goal = Logic.mk_implies (HOLogic.mk_Trueprop i_field, concl);
  13.107  
  13.108          val min_algs_thm = Goal.prove_sorry lthy [] [] goal
  13.109 -          (K (mk_min_algs_tac suc_bd_worel in_cong'_thms))
  13.110 +          (fn {context = ctxt, prems = _} => mk_min_algs_tac ctxt suc_bd_worel in_cong'_thms)
  13.111            |> Thm.close_derivation
  13.112            |> singleton (Proof_Context.export names_lthy lthy);
  13.113  
  13.114 @@ -613,10 +616,10 @@
  13.115          val card_of =
  13.116            Goal.prove_sorry lthy [] []
  13.117              (HOLogic.mk_Trueprop (HOLogic.mk_imp (i_field, card_conjunction)))
  13.118 -            (K (mk_min_algs_card_of_tac card_cT card_ct
  13.119 +            (fn {context = ctxt, prems = _} => mk_min_algs_card_of_tac ctxt card_cT card_ct
  13.120                m suc_bd_worel min_algs_thms in_sbds
  13.121                sbd_Card_order sbd_Cnotzero suc_bd_Card_order suc_bd_Cinfinite suc_bd_Cnotzero
  13.122 -              suc_bd_Asuc_bd Asuc_bd_Cinfinite))
  13.123 +              suc_bd_Asuc_bd Asuc_bd_Cinfinite)
  13.124            |> Thm.close_derivation
  13.125            |> singleton (Proof_Context.export names_lthy lthy);
  13.126  
  13.127 @@ -629,8 +632,8 @@
  13.128            (Goal.prove_sorry lthy [] []
  13.129              (Logic.mk_implies (least_prem,
  13.130                HOLogic.mk_Trueprop (HOLogic.mk_imp (i_field, least_conjunction))))
  13.131 -            (K (mk_min_algs_least_tac least_cT least_ct
  13.132 -              suc_bd_worel min_algs_thms alg_set_thms)))
  13.133 +            (fn {context = ctxt, prems = _} => mk_min_algs_least_tac ctxt least_cT least_ct
  13.134 +              suc_bd_worel min_algs_thms alg_set_thms))
  13.135            |> Thm.close_derivation
  13.136            |> singleton (Proof_Context.export names_lthy lthy);
  13.137        in
  13.138 @@ -678,21 +681,21 @@
  13.139        let
  13.140          val goal = HOLogic.mk_Trueprop (mk_alg min_algs ss);
  13.141          val alg_min_alg = Goal.prove_sorry lthy [] [] goal
  13.142 -          (K (mk_alg_min_alg_tac m alg_def min_alg_defs suc_bd_limit_thm sbd_Cinfinite
  13.143 -            set_sbdss min_algs_thms min_algs_mono_thms))
  13.144 +          (fn {context = ctxt, prems = _} => mk_alg_min_alg_tac ctxt m alg_def min_alg_defs
  13.145 +            suc_bd_limit_thm sbd_Cinfinite set_sbdss min_algs_thms min_algs_mono_thms)
  13.146            |> Thm.close_derivation
  13.147            |> singleton (Proof_Context.export names_lthy lthy);
  13.148  
  13.149          fun mk_card_of_thm min_alg def = Goal.prove_sorry lthy [] []
  13.150            (HOLogic.mk_Trueprop (mk_ordLeq (mk_card_of min_alg) Asuc_bd))
  13.151 -          (K (mk_card_of_min_alg_tac def card_of_min_algs_thm
  13.152 -            suc_bd_Card_order suc_bd_Asuc_bd Asuc_bd_Cinfinite))
  13.153 +          (fn {context = ctxt, prems = _} => mk_card_of_min_alg_tac ctxt def card_of_min_algs_thm
  13.154 +            suc_bd_Card_order suc_bd_Asuc_bd Asuc_bd_Cinfinite)
  13.155            |> Thm.close_derivation;
  13.156  
  13.157          val least_prem = HOLogic.mk_Trueprop (mk_alg Bs ss);
  13.158          fun mk_least_thm min_alg B def = Goal.prove_sorry lthy [] []
  13.159            (Logic.mk_implies (least_prem, HOLogic.mk_Trueprop (mk_leq min_alg B)))
  13.160 -          (K (mk_least_min_alg_tac def least_min_algs_thm))
  13.161 +          (fn {context = ctxt, prems = _} => mk_least_min_alg_tac ctxt def least_min_algs_thm)
  13.162            |> Thm.close_derivation
  13.163            |> singleton (Proof_Context.export names_lthy lthy);
  13.164  
  13.165 @@ -702,7 +705,8 @@
  13.166          val incl = Goal.prove_sorry lthy [] []
  13.167            (Logic.mk_implies (incl_prem,
  13.168                HOLogic.mk_Trueprop (mk_mor min_algs ss Bs ss active_ids)))
  13.169 -          (K (EVERY' (rtac mor_incl_thm :: map etac leasts) 1))
  13.170 +          (fn {context = ctxt, prems = _} =>
  13.171 +            EVERY' (rtac ctxt mor_incl_thm :: map (etac ctxt) leasts) 1)
  13.172            |> Thm.close_derivation
  13.173            |> singleton (Proof_Context.export names_lthy lthy);
  13.174        in
  13.175 @@ -716,7 +720,7 @@
  13.176  
  13.177      val ((IIT_name, (IIT_glob_info, IIT_loc_info)), lthy) =
  13.178        typedef (IIT_bind, params, NoSyn)
  13.179 -        (HOLogic.mk_UNIV II_repT) NONE (fn _ => EVERY' [rtac exI, rtac UNIV_I] 1) lthy;
  13.180 +        (HOLogic.mk_UNIV II_repT) NONE (fn ctxt => EVERY' [rtac ctxt exI, rtac ctxt UNIV_I] 1) lthy;
  13.181  
  13.182      val IIT = Type (IIT_name, params');
  13.183      val Abs_IIT = Const (#Abs_name IIT_glob_info, II_repT --> IIT);
  13.184 @@ -797,8 +801,9 @@
  13.185              (map (fn f => HOLogic.mk_comp (f, mk_rapp iidx Asuc_bdT)) Asuc_fs));
  13.186        in
  13.187          Goal.prove_sorry lthy [] [] (Logic.list_implies (prems, concl))
  13.188 -          (K (mk_mor_select_tac mor_def mor_cong_thm mor_comp_thm mor_incl_min_alg_thm alg_def
  13.189 -            alg_select_thm alg_set_thms set_mapss str_init_defs))
  13.190 +          (fn {context = ctxt, prems = _} => mk_mor_select_tac ctxt mor_def mor_cong_thm
  13.191 +            mor_comp_thm mor_incl_min_alg_thm alg_def alg_select_thm alg_set_thms set_mapss
  13.192 +            str_init_defs)
  13.193          |> Thm.close_derivation
  13.194          |> singleton (Proof_Context.export names_lthy lthy)
  13.195        end;
  13.196 @@ -815,8 +820,8 @@
  13.197          val cts = map (Thm.cterm_of lthy) ss;
  13.198          val unique_mor =
  13.199            Goal.prove_sorry lthy [] [] (Logic.list_implies (prems @ mor_prems, unique))
  13.200 -            (K (mk_init_unique_mor_tac cts m alg_def alg_init_thm least_min_alg_thms
  13.201 -              in_mono'_thms alg_set_thms morE_thms map_cong0s))
  13.202 +            (fn {context = ctxt, prems = _} => mk_init_unique_mor_tac ctxt cts m alg_def
  13.203 +              alg_init_thm least_min_alg_thms in_mono'_thms alg_set_thms morE_thms map_cong0s)
  13.204            |> Thm.close_derivation
  13.205            |> singleton (Proof_Context.export names_lthy lthy);
  13.206        in
  13.207 @@ -849,7 +854,8 @@
  13.208            (map2 mk_Ball car_inits init_phis));
  13.209        in
  13.210          Goal.prove_sorry lthy [] [] (Logic.mk_implies (prem, concl))
  13.211 -          (K (mk_init_induct_tac m alg_def alg_init_thm least_min_alg_thms alg_set_thms))
  13.212 +          (fn {context = ctxt, prems = _} => mk_init_induct_tac ctxt m alg_def alg_init_thm
  13.213 +            least_min_alg_thms alg_set_thms)
  13.214          |> Thm.close_derivation
  13.215          |> singleton (Proof_Context.export names_lthy lthy)
  13.216        end;
  13.217 @@ -861,8 +867,8 @@
  13.218        |> @{fold_map 3} (fn b => fn mx => fn car_init =>
  13.219          typedef (b, params, mx) car_init NONE
  13.220            (fn ctxt =>
  13.221 -            EVERY' [rtac iffD2, rtac @{thm ex_in_conv}, resolve_tac ctxt alg_not_empty_thms,
  13.222 -            rtac alg_init_thm] 1)) bs mixfixes car_inits
  13.223 +            EVERY' [rtac ctxt iffD2, rtac ctxt @{thm ex_in_conv}, resolve_tac ctxt alg_not_empty_thms,
  13.224 +            rtac ctxt alg_init_thm] 1)) bs mixfixes car_inits
  13.225        |>> apsnd split_list o split_list;
  13.226  
  13.227      val Ts = map (fn name => Type (name, params')) T_names;
  13.228 @@ -999,7 +1005,8 @@
  13.229            (HOLogic.mk_conj (mk_alg B's s's, mk_mor B's s's Bs ss inv_fs)));
  13.230        in
  13.231          Goal.prove_sorry lthy [] [] (Logic.list_implies (prems, concl))
  13.232 -          (K (mk_copy_tac m alg_def mor_def alg_set_thms set_mapss))
  13.233 +          (fn {context = ctxt, prems = _} => mk_copy_tac ctxt m alg_def mor_def alg_set_thms
  13.234 +            set_mapss)
  13.235            |> Thm.close_derivation
  13.236            |> singleton (Proof_Context.export names_lthy lthy)
  13.237        end;
  13.238 @@ -1032,7 +1039,7 @@
  13.239        end;
  13.240  
  13.241      val ctor_fold_thms = map (fn morE => rule_by_tactic lthy
  13.242 -      ((rtac CollectI THEN' CONJ_WRAP' (K (rtac @{thm subset_UNIV})) (1 upto m + n)) 1)
  13.243 +      ((rtac lthy CollectI THEN' CONJ_WRAP' (K (rtac lthy @{thm subset_UNIV})) (1 upto m + n)) 1)
  13.244        (mor_fold_thm RS morE)) morE_thms;
  13.245  
  13.246      val (fold_unique_mor_thms, fold_unique_mor_thm) =
  13.247 @@ -1041,8 +1048,8 @@
  13.248          fun mk_fun_eq f i = HOLogic.mk_eq (f, mk_fold Ts ss i);
  13.249          val unique = HOLogic.mk_Trueprop (Library.foldr1 HOLogic.mk_conj (map2 mk_fun_eq fs ks));
  13.250          val unique_mor = Goal.prove_sorry lthy [] [] (Logic.mk_implies (prem, unique))
  13.251 -          (K (mk_fold_unique_mor_tac type_defs init_unique_mor_thms Reps
  13.252 -            mor_comp_thm mor_Abs_thm mor_fold_thm))
  13.253 +          (fn {context = ctxt, prems = _} => mk_fold_unique_mor_tac ctxt type_defs
  13.254 +            init_unique_mor_thms Reps mor_comp_thm mor_Abs_thm mor_fold_thm)
  13.255            |> Thm.close_derivation
  13.256            |> singleton (Proof_Context.export names_lthy lthy);
  13.257        in
  13.258 @@ -1100,7 +1107,8 @@
  13.259        in
  13.260          @{map 5} (fn goal => fn dtor_def => fn foldx => fn map_comp_id => fn map_cong0L =>
  13.261            Goal.prove_sorry lthy [] [] goal
  13.262 -            (K (mk_dtor_o_ctor_tac dtor_def foldx map_comp_id map_cong0L ctor_o_fold_thms))
  13.263 +            (fn {context = ctxt, prems = _} => mk_dtor_o_ctor_tac ctxt dtor_def foldx map_comp_id
  13.264 +              map_cong0L ctor_o_fold_thms)
  13.265            |> Thm.close_derivation)
  13.266          goals dtor_defs ctor_fold_thms map_comp_id_thms map_cong0L_thms
  13.267        end;
  13.268 @@ -1395,7 +1403,8 @@
  13.269  
  13.270                val ((sbd0T_name, (sbd0T_glob_info, sbd0T_loc_info)), lthy) =
  13.271                  typedef (sbd0T_bind, sum_bd0T_params', NoSyn)
  13.272 -                  (HOLogic.mk_UNIV sum_bd0T) NONE (fn _ => EVERY' [rtac exI, rtac UNIV_I] 1) lthy;
  13.273 +                  (HOLogic.mk_UNIV sum_bd0T) NONE (fn ctxt =>
  13.274 +                    EVERY' [rtac ctxt exI, rtac ctxt UNIV_I] 1) lthy;
  13.275  
  13.276                val sbd0T = Type (sbd0T_name, sum_bd0T_params);
  13.277                val Abs_sbd0T = Const (#Abs_name sbd0T_glob_info, sum_bd0T --> sbd0T);
  13.278 @@ -1481,7 +1490,7 @@
  13.279                @{map 4} (fn goal => fn foldx => fn map_comp_id => fn map_cong0 =>
  13.280                  Goal.prove_sorry lthy [] [] goal
  13.281                    (fn {context = ctxt, prems = _} => unfold_thms_tac ctxt Imap_defs THEN
  13.282 -                    mk_map_tac m n foldx map_comp_id map_cong0)
  13.283 +                    mk_map_tac ctxt m n foldx map_comp_id map_cong0)
  13.284                  |> Thm.close_derivation
  13.285                  |> singleton (Proof_Context.export names_lthy lthy))
  13.286                goals ctor_fold_thms map_comp_id_thms map_cong0s;
  13.287 @@ -1519,7 +1528,7 @@
  13.288                  Isetss_by_range colss map_setss;
  13.289              val setss = map (map2 (fn foldx => fn goal =>
  13.290                  Goal.prove_sorry lthy [] [] goal (fn {context = ctxt, prems = _} =>
  13.291 -                  unfold_thms_tac ctxt Iset_defs THEN mk_set_tac foldx)
  13.292 +                  unfold_thms_tac ctxt Iset_defs THEN mk_set_tac ctxt foldx)
  13.293                  |> Thm.close_derivation)
  13.294                ctor_fold_thms) goalss;
  13.295  
  13.296 @@ -1535,7 +1544,8 @@
  13.297  
  13.298              val ctor_setss = @{map 3} (fn i => @{map 3} (fn set_nats => fn goal => fn set =>
  13.299                  Goal.prove_sorry lthy [] [] goal
  13.300 -                  (K (mk_ctor_set_tac set (nth set_nats (i - 1)) (drop m set_nats)))
  13.301 +                  (fn {context = ctxt, prems = _} =>
  13.302 +                    mk_ctor_set_tac ctxt set (nth set_nats (i - 1)) (drop m set_nats))
  13.303                  |> Thm.close_derivation
  13.304                  |> singleton (Proof_Context.export names_lthy lthy))
  13.305                set_mapss) ls simp_goalss setss;
  13.306 @@ -1578,7 +1588,7 @@
  13.307                    (@{map 4} (mk_set_map0 f) fs_Imaps Izs sets sets')))
  13.308                    fs Isetss_by_range Isetss_by_range';
  13.309  
  13.310 -            fun mk_tac ctxt induct = mk_set_nat_tac ctxt m (rtac induct) set_mapss ctor_Imap_thms;
  13.311 +            fun mk_tac ctxt induct = mk_set_nat_tac ctxt m (rtac ctxt induct) set_mapss ctor_Imap_thms;
  13.312              val thms =
  13.313                @{map 5} (fn goal => fn csets => fn ctor_sets => fn induct => fn i =>
  13.314                  Goal.prove_sorry lthy [] [] goal
  13.315 @@ -1606,7 +1616,7 @@
  13.316                  HOLogic.mk_Trueprop (Library.foldr1 HOLogic.mk_conj
  13.317                    (@{map 3} mk_set_bd Izs Ibds sets))) Isetss_by_range;
  13.318  
  13.319 -            fun mk_tac ctxt induct = mk_set_bd_tac ctxt m (rtac induct) sbd0_Cinfinite set_sbd0ss;
  13.320 +            fun mk_tac ctxt induct = mk_set_bd_tac ctxt m (rtac ctxt induct) sbd0_Cinfinite set_sbd0ss;
  13.321              val thms =
  13.322                @{map 4} (fn goal => fn ctor_sets => fn induct => fn i =>
  13.323                  Goal.prove_sorry lthy [] [] goal
  13.324 @@ -1641,7 +1651,7 @@
  13.325                  (@{map 4} mk_map_cong0 Isetss_by_bnf Izs fs_Imaps fs_copy_Imaps));
  13.326  
  13.327              val thm = Goal.prove_sorry lthy [] [] goal
  13.328 -                (fn {context = ctxt, prems = _} => mk_mcong_tac ctxt (rtac induct) set_Iset_thmsss
  13.329 +                (fn {context = ctxt, prems = _} => mk_mcong_tac ctxt (rtac ctxt induct) set_Iset_thmsss
  13.330                    map_cong0s ctor_Imap_thms)
  13.331                |> Thm.close_derivation
  13.332                |> singleton (Proof_Context.export names_lthy lthy);
  13.333 @@ -1708,20 +1718,24 @@
  13.334  
  13.335          val timer = time (timer "helpers for BNF properties");
  13.336  
  13.337 -        val map_id0_tacs = map (K o mk_map_id0_tac map_id0s) ctor_Imap_unique_thms;
  13.338 +        val map_id0_tacs = map (fn thm => fn ctxt => mk_map_id0_tac ctxt map_id0s thm)
  13.339 +          ctor_Imap_unique_thms;
  13.340          val map_comp0_tacs =
  13.341 -          map2 (K oo mk_map_comp0_tac map_comps ctor_Imap_thms) ctor_Imap_unique_thms ks;
  13.342 +          map2 (fn thm => fn i => fn ctxt =>
  13.343 +            mk_map_comp0_tac ctxt map_comps ctor_Imap_thms thm i)
  13.344 +          ctor_Imap_unique_thms ks;
  13.345          val map_cong0_tacs = map (fn thm => fn ctxt => mk_map_cong0_tac ctxt m thm) Imap_cong0_thms;
  13.346 -        val set_map0_tacss = map (map (K o mk_set_map0_tac)) (transpose Iset_Imap0_thmss);
  13.347 +        val set_map0_tacss = map (map (fn thm => fn ctxt => mk_set_map0_tac ctxt thm))
  13.348 +          (transpose Iset_Imap0_thmss);
  13.349          val bd_co_tacs = replicate n (fn ctxt =>
  13.350 -          unfold_thms_tac ctxt Ibd_defs THEN rtac sbd0_card_order 1);
  13.351 +          unfold_thms_tac ctxt Ibd_defs THEN rtac ctxt sbd0_card_order 1);
  13.352          val bd_cinf_tacs = replicate n (fn ctxt =>
  13.353 -          unfold_thms_tac ctxt Ibd_defs THEN rtac (sbd0_Cinfinite RS conjunct1) 1);
  13.354 -        val set_bd_tacss = map (map (fn thm => K (rtac thm 1))) (transpose Iset_bd_thmss);
  13.355 -        val le_rel_OO_tacs = map (fn i =>
  13.356 -          K ((rtac @{thm predicate2I} THEN' etac (le_Irel_OO_thm RS mk_conjunctN n i RS mp)) 1)) ks;
  13.357 +          unfold_thms_tac ctxt Ibd_defs THEN rtac ctxt (sbd0_Cinfinite RS conjunct1) 1);
  13.358 +        val set_bd_tacss = map (map (fn thm => fn ctxt => rtac ctxt thm 1)) (transpose Iset_bd_thmss);
  13.359 +        val le_rel_OO_tacs = map (fn i => fn ctxt =>
  13.360 +          (rtac ctxt @{thm predicate2I} THEN' etac ctxt (le_Irel_OO_thm RS mk_conjunctN n i RS mp)) 1) ks;
  13.361  
  13.362 -        val rel_OO_Grp_tacs = map (fn def => K (rtac def 1)) Irel_unabs_defs;
  13.363 +        val rel_OO_Grp_tacs = map (fn def => fn ctxt => rtac ctxt def 1) Irel_unabs_defs;
  13.364  
  13.365          val tacss = @{map 9} zip_axioms map_id0_tacs map_comp0_tacs map_cong0_tacs set_map0_tacss
  13.366            bd_co_tacs bd_cinf_tacs set_bd_tacss le_rel_OO_tacs rel_OO_Grp_tacs;
    14.1 --- a/src/HOL/Tools/BNF/bnf_lfp_compat.ML	Thu Jul 16 10:48:20 2015 +0200
    14.2 +++ b/src/HOL/Tools/BNF/bnf_lfp_compat.ML	Thu Jul 16 12:23:22 2015 +0200
    14.3 @@ -153,7 +153,7 @@
    14.4  
    14.5      fun tac ctxt =
    14.6        unfold_thms_tac ctxt (@{thms o_apply fst_conv snd_conv} @ rec_defs @ flat rec0_thmss) THEN
    14.7 -      HEADGOAL (rtac refl);
    14.8 +      HEADGOAL (rtac ctxt refl);
    14.9  
   14.10      fun prove goal =
   14.11        Goal.prove_sorry ctxt [] [] goal (tac o #context)
    15.1 --- a/src/HOL/Tools/BNF/bnf_lfp_rec_sugar.ML	Thu Jul 16 10:48:20 2015 +0200
    15.2 +++ b/src/HOL/Tools/BNF/bnf_lfp_rec_sugar.ML	Thu Jul 16 12:23:22 2015 +0200
    15.3 @@ -493,9 +493,9 @@
    15.4  
    15.5  fun mk_primrec_tac ctxt num_extra_args map_ident0s map_comps fun_defs recx =
    15.6    unfold_thms_tac ctxt fun_defs THEN
    15.7 -  HEADGOAL (rtac (funpow num_extra_args (fn thm => thm RS fun_cong) recx RS trans)) THEN
    15.8 +  HEADGOAL (rtac ctxt (funpow num_extra_args (fn thm => thm RS fun_cong) recx RS trans)) THEN
    15.9    unfold_thms_tac ctxt (nested_simps ctxt @ map_ident0s @ map_comps) THEN
   15.10 -  HEADGOAL (rtac refl);
   15.11 +  HEADGOAL (rtac ctxt refl);
   15.12  
   15.13  fun prepare_primrec plugins nonexhaustives transfers fixes specs lthy0 =
   15.14    let
    16.1 --- a/src/HOL/Tools/BNF/bnf_lfp_size.ML	Thu Jul 16 10:48:20 2015 +0200
    16.2 +++ b/src/HOL/Tools/BNF/bnf_lfp_size.ML	Thu Jul 16 12:23:22 2015 +0200
    16.3 @@ -63,15 +63,15 @@
    16.4  
    16.5  fun mk_size_gen_o_map_tac ctxt size_def rec_o_map inj_maps size_maps =
    16.6    unfold_thms_tac ctxt [size_def] THEN
    16.7 -  HEADGOAL (rtac (rec_o_map RS trans) THEN'
    16.8 +  HEADGOAL (rtac ctxt (rec_o_map RS trans) THEN'
    16.9      asm_simp_tac (ss_only (inj_maps @ size_maps @ size_gen_o_map_simps) ctxt)) THEN
   16.10 -  IF_UNSOLVED (unfold_thms_tac ctxt @{thms id_def o_def} THEN HEADGOAL (rtac refl));
   16.11 +  IF_UNSOLVED (unfold_thms_tac ctxt @{thms id_def o_def} THEN HEADGOAL (rtac ctxt refl));
   16.12  
   16.13  fun mk_size_neq ctxt cts exhaust sizes =
   16.14 -  HEADGOAL (rtac (Ctr_Sugar_Util.cterm_instantiate_pos (map SOME cts) exhaust)) THEN
   16.15 +  HEADGOAL (rtac ctxt (Ctr_Sugar_Util.cterm_instantiate_pos (map SOME cts) exhaust)) THEN
   16.16    ALLGOALS (hyp_subst_tac ctxt) THEN
   16.17    Ctr_Sugar_Tactics.unfold_thms_tac ctxt (@{thm neq0_conv} :: sizes) THEN
   16.18 -  ALLGOALS (REPEAT_DETERM o (rtac @{thm zero_less_Suc} ORELSE' rtac @{thm trans_less_add2}));
   16.19 +  ALLGOALS (REPEAT_DETERM o (rtac ctxt @{thm zero_less_Suc} ORELSE' rtac ctxt @{thm trans_less_add2}));
   16.20  
   16.21  fun generate_datatype_size (fp_sugars as ({T = Type (_, As), BT = Type (_, Bs), fp = Least_FP,
   16.22          fp_res = {bnfs = fp_bnfs, ...}, fp_nesting_bnfs, live_nesting_bnfs, ...} : fp_sugar) :: _)
    17.1 --- a/src/HOL/Tools/BNF/bnf_lfp_tactics.ML	Thu Jul 16 10:48:20 2015 +0200
    17.2 +++ b/src/HOL/Tools/BNF/bnf_lfp_tactics.ML	Thu Jul 16 12:23:22 2015 +0200
    17.3 @@ -8,59 +8,60 @@
    17.4  
    17.5  signature BNF_LFP_TACTICS =
    17.6  sig
    17.7 -  val mk_alg_min_alg_tac: int -> thm -> thm list -> thm -> thm -> thm list list -> thm list ->
    17.8 -    thm list -> tactic
    17.9 +  val mk_alg_min_alg_tac: Proof.context -> int -> thm -> thm list -> thm -> thm -> thm list list ->
   17.10 +    thm list -> thm list -> tactic
   17.11    val mk_alg_not_empty_tac: Proof.context -> thm -> thm list -> thm list -> tactic
   17.12    val mk_alg_select_tac: Proof.context -> thm -> tactic
   17.13 -  val mk_alg_set_tac: thm -> tactic
   17.14 -  val mk_bd_card_order_tac: thm list -> tactic
   17.15 -  val mk_bd_limit_tac: int -> thm -> tactic
   17.16 -  val mk_card_of_min_alg_tac: thm -> thm -> thm -> thm -> thm -> tactic
   17.17 -  val mk_copy_tac: int -> thm -> thm -> thm list -> thm list list -> tactic
   17.18 +  val mk_alg_set_tac: Proof.context -> thm -> tactic
   17.19 +  val mk_bd_card_order_tac: Proof.context -> thm list -> tactic
   17.20 +  val mk_bd_limit_tac: Proof.context -> int -> thm -> tactic
   17.21 +  val mk_card_of_min_alg_tac: Proof.context -> thm -> thm -> thm -> thm -> thm -> tactic
   17.22 +  val mk_copy_tac: Proof.context -> int -> thm -> thm -> thm list -> thm list list -> tactic
   17.23    val mk_ctor_induct_tac: Proof.context -> int -> thm list list -> thm -> thm list -> thm ->
   17.24      thm list -> thm list -> thm list -> tactic
   17.25    val mk_ctor_induct2_tac: Proof.context -> ctyp option list -> cterm option list -> thm ->
   17.26      thm list -> tactic
   17.27 -  val mk_ctor_set_tac: thm -> thm -> thm list -> tactic
   17.28 +  val mk_ctor_set_tac: Proof.context -> thm -> thm -> thm list -> tactic
   17.29    val mk_ctor_rec_transfer_tac: Proof.context -> int -> int -> thm list -> thm list -> thm list ->
   17.30      thm list -> tactic
   17.31    val mk_ctor_rel_tac: Proof.context -> thm list -> int -> thm -> thm -> thm -> thm -> thm list ->
   17.32      thm -> thm -> thm list -> thm list -> thm list list -> tactic
   17.33 -  val mk_dtor_o_ctor_tac: thm -> thm -> thm -> thm -> thm list -> tactic
   17.34 +  val mk_dtor_o_ctor_tac: Proof.context -> thm -> thm -> thm -> thm -> thm list -> tactic
   17.35    val mk_init_ex_mor_tac: Proof.context -> thm -> thm -> thm list -> thm -> thm -> thm -> thm ->
   17.36      tactic
   17.37 -  val mk_init_induct_tac: int -> thm -> thm -> thm list -> thm list -> tactic
   17.38 -  val mk_init_unique_mor_tac: cterm list -> int -> thm -> thm -> thm list -> thm list -> thm list ->
   17.39 -    thm list -> thm list -> tactic
   17.40 -  val mk_fold_unique_mor_tac: thm list -> thm list -> thm list -> thm -> thm -> thm -> tactic
   17.41 +  val mk_init_induct_tac: Proof.context -> int -> thm -> thm -> thm list -> thm list -> tactic
   17.42 +  val mk_init_unique_mor_tac: Proof.context -> cterm list -> int -> thm -> thm -> thm list ->
   17.43 +    thm list -> thm list -> thm list -> thm list -> tactic
   17.44 +  val mk_fold_unique_mor_tac: Proof.context -> thm list -> thm list -> thm list -> thm -> thm ->
   17.45 +    thm -> tactic
   17.46    val mk_fold_transfer_tac: Proof.context -> int -> thm -> thm list -> thm list -> tactic
   17.47 -  val mk_least_min_alg_tac: thm -> thm -> tactic
   17.48 +  val mk_least_min_alg_tac: Proof.context -> thm -> thm -> tactic
   17.49    val mk_le_rel_OO_tac: Proof.context -> int -> thm -> thm list -> thm list -> thm list ->
   17.50      thm list -> tactic
   17.51 -  val mk_map_comp0_tac: thm list -> thm list -> thm -> int -> tactic
   17.52 -  val mk_map_id0_tac: thm list -> thm -> tactic
   17.53 -  val mk_map_tac: int -> int -> thm -> thm -> thm -> tactic
   17.54 +  val mk_map_comp0_tac: Proof.context -> thm list -> thm list -> thm -> int -> tactic
   17.55 +  val mk_map_id0_tac: Proof.context -> thm list -> thm -> tactic
   17.56 +  val mk_map_tac: Proof.context -> int -> int -> thm -> thm -> thm -> tactic
   17.57    val mk_ctor_map_unique_tac: Proof.context -> thm -> thm list -> tactic
   17.58    val mk_mcong_tac: Proof.context -> (int -> tactic) -> thm list list list -> thm list ->
   17.59      thm list -> tactic
   17.60 -  val mk_min_algs_card_of_tac: ctyp -> cterm -> int -> thm -> thm list -> thm list -> thm -> thm ->
   17.61 -    thm -> thm -> thm -> thm -> thm -> tactic
   17.62 -  val mk_min_algs_least_tac: ctyp -> cterm -> thm -> thm list -> thm list -> tactic
   17.63 +  val mk_min_algs_card_of_tac: Proof.context -> ctyp -> cterm -> int -> thm -> thm list ->
   17.64 +    thm list -> thm -> thm -> thm -> thm -> thm -> thm -> thm -> tactic
   17.65 +  val mk_min_algs_least_tac: Proof.context -> ctyp -> cterm -> thm -> thm list -> thm list -> tactic
   17.66    val mk_min_algs_mono_tac: Proof.context -> thm -> tactic
   17.67 -  val mk_min_algs_tac: thm -> thm list -> tactic
   17.68 +  val mk_min_algs_tac: Proof.context -> thm -> thm list -> tactic
   17.69    val mk_mor_Abs_tac: Proof.context -> cterm list -> thm list -> thm list -> thm list -> thm list ->
   17.70      tactic
   17.71    val mk_mor_Rep_tac: Proof.context -> int -> thm list -> thm list -> thm list -> thm -> thm list ->
   17.72      thm list list -> tactic
   17.73 -  val mk_mor_UNIV_tac: int -> thm list -> thm -> tactic
   17.74 -  val mk_mor_comp_tac: thm -> thm list list -> thm list -> tactic
   17.75 -  val mk_mor_convol_tac: 'a list -> thm -> tactic
   17.76 -  val mk_mor_elim_tac: thm -> tactic
   17.77 +  val mk_mor_UNIV_tac: Proof.context -> int -> thm list -> thm -> tactic
   17.78 +  val mk_mor_comp_tac: Proof.context -> thm -> thm list list -> thm list -> tactic
   17.79 +  val mk_mor_convol_tac: Proof.context -> 'a list -> thm -> tactic
   17.80 +  val mk_mor_elim_tac: Proof.context -> thm -> tactic
   17.81    val mk_mor_incl_tac: Proof.context -> thm -> thm list -> tactic
   17.82    val mk_mor_fold_tac: Proof.context -> ctyp -> cterm -> thm list -> thm -> thm -> tactic
   17.83 -  val mk_mor_select_tac: thm -> thm -> thm -> thm -> thm -> thm -> thm list -> thm list list ->
   17.84 -    thm list -> tactic
   17.85 -  val mk_mor_str_tac: 'a list -> thm -> tactic
   17.86 +  val mk_mor_select_tac: Proof.context -> thm -> thm -> thm -> thm -> thm -> thm -> thm list ->
   17.87 +    thm list list -> thm list -> tactic
   17.88 +  val mk_mor_str_tac: Proof.context -> 'a list -> thm -> tactic
   17.89    val mk_rel_induct_tac: Proof.context -> thm list -> int -> thm -> int list -> thm list ->
   17.90      thm list -> tactic
   17.91    val mk_rec_tac: Proof.context -> thm list -> thm -> thm list -> tactic
   17.92 @@ -69,8 +70,8 @@
   17.93      int -> tactic
   17.94    val mk_set_nat_tac: Proof.context -> int -> (int -> tactic) -> thm list list -> thm list ->
   17.95      cterm list -> thm list -> int -> tactic
   17.96 -  val mk_set_map0_tac: thm -> tactic
   17.97 -  val mk_set_tac: thm -> tactic
   17.98 +  val mk_set_map0_tac: Proof.context -> thm -> tactic
   17.99 +  val mk_set_tac: Proof.context -> thm -> tactic
  17.100    val mk_wit_tac: Proof.context -> int -> thm list -> thm list -> tactic
  17.101  end;
  17.102  
  17.103 @@ -89,132 +90,132 @@
  17.104  val Un_cong = @{thm arg_cong2[of _ _ _ _ "op \<union>"]};
  17.105  val relChainD = @{thm iffD2[OF meta_eq_to_obj_eq[OF relChain_def]]};
  17.106  
  17.107 -fun mk_alg_set_tac alg_def =
  17.108 -  EVERY' [dtac (alg_def RS iffD1), REPEAT_DETERM o etac conjE, etac bspec, rtac CollectI,
  17.109 -   REPEAT_DETERM o (rtac (subset_UNIV RS conjI) ORELSE' etac conjI), atac] 1;
  17.110 +fun mk_alg_set_tac ctxt alg_def =
  17.111 +  EVERY' [dtac ctxt (alg_def RS iffD1), REPEAT_DETERM o etac ctxt conjE, etac ctxt bspec, rtac ctxt CollectI,
  17.112 +   REPEAT_DETERM o (rtac ctxt (subset_UNIV RS conjI) ORELSE' etac ctxt conjI), atac] 1;
  17.113  
  17.114  fun mk_alg_not_empty_tac ctxt alg_set alg_sets wits =
  17.115 -  (EVERY' [rtac notI, hyp_subst_tac ctxt, forward_tac ctxt [alg_set]] THEN'
  17.116 +  (EVERY' [rtac ctxt notI, hyp_subst_tac ctxt, forward_tac ctxt [alg_set]] THEN'
  17.117    REPEAT_DETERM o FIRST'
  17.118 -    [EVERY' [rtac @{thm subset_emptyI}, eresolve_tac ctxt wits],
  17.119 -    EVERY' [rtac subsetI, rtac FalseE, eresolve_tac ctxt wits],
  17.120 -    EVERY' [rtac subsetI, dresolve_tac ctxt wits, hyp_subst_tac ctxt,
  17.121 -      FIRST' (map (fn thm => rtac thm THEN' atac) alg_sets)]] THEN'
  17.122 -  etac @{thm emptyE}) 1;
  17.123 +    [EVERY' [rtac ctxt @{thm subset_emptyI}, eresolve_tac ctxt wits],
  17.124 +    EVERY' [rtac ctxt subsetI, rtac ctxt FalseE, eresolve_tac ctxt wits],
  17.125 +    EVERY' [rtac ctxt subsetI, dresolve_tac ctxt wits, hyp_subst_tac ctxt,
  17.126 +      FIRST' (map (fn thm => rtac ctxt thm THEN' atac) alg_sets)]] THEN'
  17.127 +  etac ctxt @{thm emptyE}) 1;
  17.128  
  17.129 -fun mk_mor_elim_tac mor_def =
  17.130 -  (dtac (mor_def RS iffD1) THEN'
  17.131 -  REPEAT o etac conjE THEN'
  17.132 -  TRY o rtac @{thm image_subsetI} THEN'
  17.133 -  etac bspec THEN'
  17.134 +fun mk_mor_elim_tac ctxt mor_def =
  17.135 +  (dtac ctxt (mor_def RS iffD1) THEN'
  17.136 +  REPEAT o etac ctxt conjE THEN'
  17.137 +  TRY o rtac ctxt @{thm image_subsetI} THEN'
  17.138 +  etac ctxt bspec THEN'
  17.139    atac) 1;
  17.140  
  17.141  fun mk_mor_incl_tac ctxt mor_def map_ids =
  17.142 -  (rtac (mor_def RS iffD2) THEN'
  17.143 -  rtac conjI THEN'
  17.144 -  CONJ_WRAP' (K (EVERY' [rtac ballI, etac set_mp, etac (id_apply RS @{thm ssubst_mem})]))
  17.145 +  (rtac ctxt (mor_def RS iffD2) THEN'
  17.146 +  rtac ctxt conjI THEN'
  17.147 +  CONJ_WRAP' (K (EVERY' [rtac ctxt ballI, etac ctxt set_mp, etac ctxt (id_apply RS @{thm ssubst_mem})]))
  17.148      map_ids THEN'
  17.149    CONJ_WRAP' (fn thm =>
  17.150 -    (EVERY' [rtac ballI, rtac trans, rtac id_apply, stac ctxt thm, rtac refl])) map_ids) 1;
  17.151 +    (EVERY' [rtac ctxt ballI, rtac ctxt trans, rtac ctxt id_apply, stac ctxt thm, rtac ctxt refl])) map_ids) 1;
  17.152  
  17.153 -fun mk_mor_comp_tac mor_def set_maps map_comp_ids =
  17.154 +fun mk_mor_comp_tac ctxt mor_def set_maps map_comp_ids =
  17.155    let
  17.156      val fbetw_tac =
  17.157 -      EVERY' [rtac ballI, rtac (o_apply RS @{thm ssubst_mem}), etac bspec, etac bspec, atac];
  17.158 +      EVERY' [rtac ctxt ballI, rtac ctxt (o_apply RS @{thm ssubst_mem}), etac ctxt bspec, etac ctxt bspec, atac];
  17.159      fun mor_tac (set_map, map_comp_id) =
  17.160 -      EVERY' [rtac ballI, rtac (o_apply RS trans), rtac trans,
  17.161 -        rtac trans, dtac rev_bspec, atac, etac arg_cong,
  17.162 -         REPEAT o eresolve0_tac [CollectE, conjE], etac bspec, rtac CollectI] THEN'
  17.163 +      EVERY' [rtac ctxt ballI, rtac ctxt (o_apply RS trans), rtac ctxt trans,
  17.164 +        rtac ctxt trans, dtac ctxt rev_bspec, atac, etac ctxt arg_cong,
  17.165 +         REPEAT o eresolve0_tac [CollectE, conjE], etac ctxt bspec, rtac ctxt CollectI] THEN'
  17.166        CONJ_WRAP' (fn thm =>
  17.167 -        FIRST' [rtac subset_UNIV,
  17.168 -          (EVERY' [rtac ord_eq_le_trans, rtac thm, rtac @{thm image_subsetI},
  17.169 -            etac bspec, etac set_mp, atac])]) set_map THEN'
  17.170 -      rtac (map_comp_id RS arg_cong);
  17.171 +        FIRST' [rtac ctxt subset_UNIV,
  17.172 +          (EVERY' [rtac ctxt ord_eq_le_trans, rtac ctxt thm, rtac ctxt @{thm image_subsetI},
  17.173 +            etac ctxt bspec, etac ctxt set_mp, atac])]) set_map THEN'
  17.174 +      rtac ctxt (map_comp_id RS arg_cong);
  17.175    in
  17.176 -    (dtac (mor_def RS iffD1) THEN' dtac (mor_def RS iffD1) THEN' rtac (mor_def RS iffD2) THEN'
  17.177 -    REPEAT o etac conjE THEN'
  17.178 -    rtac conjI THEN'
  17.179 +    (dtac ctxt (mor_def RS iffD1) THEN' dtac ctxt (mor_def RS iffD1) THEN' rtac ctxt (mor_def RS iffD2) THEN'
  17.180 +    REPEAT o etac ctxt conjE THEN'
  17.181 +    rtac ctxt conjI THEN'
  17.182      CONJ_WRAP' (K fbetw_tac) set_maps THEN'
  17.183      CONJ_WRAP' mor_tac (set_maps ~~ map_comp_ids)) 1
  17.184    end;
  17.185  
  17.186 -fun mk_mor_str_tac ks mor_def =
  17.187 -  (rtac (mor_def RS iffD2) THEN' rtac conjI THEN'
  17.188 -  CONJ_WRAP' (K (EVERY' [rtac ballI, rtac UNIV_I])) ks THEN'
  17.189 -  CONJ_WRAP' (K (EVERY' [rtac ballI, rtac refl])) ks) 1;
  17.190 +fun mk_mor_str_tac ctxt ks mor_def =
  17.191 +  (rtac ctxt (mor_def RS iffD2) THEN' rtac ctxt conjI THEN'
  17.192 +  CONJ_WRAP' (K (EVERY' [rtac ctxt ballI, rtac ctxt UNIV_I])) ks THEN'
  17.193 +  CONJ_WRAP' (K (EVERY' [rtac ctxt ballI, rtac ctxt refl])) ks) 1;
  17.194  
  17.195 -fun mk_mor_convol_tac ks mor_def =
  17.196 -  (rtac (mor_def RS iffD2) THEN' rtac conjI THEN'
  17.197 -  CONJ_WRAP' (K (EVERY' [rtac ballI, rtac UNIV_I])) ks THEN'
  17.198 -  CONJ_WRAP' (K (EVERY' [rtac ballI, rtac trans, rtac @{thm fst_convol'}, rtac o_apply])) ks) 1;
  17.199 +fun mk_mor_convol_tac ctxt ks mor_def =
  17.200 +  (rtac ctxt (mor_def RS iffD2) THEN' rtac ctxt conjI THEN'
  17.201 +  CONJ_WRAP' (K (EVERY' [rtac ctxt ballI, rtac ctxt UNIV_I])) ks THEN'
  17.202 +  CONJ_WRAP' (K (EVERY' [rtac ctxt ballI, rtac ctxt trans, rtac ctxt @{thm fst_convol'}, rtac ctxt o_apply])) ks) 1;
  17.203  
  17.204 -fun mk_mor_UNIV_tac m morEs mor_def =
  17.205 +fun mk_mor_UNIV_tac ctxt m morEs mor_def =
  17.206    let
  17.207      val n = length morEs;
  17.208 -    fun mor_tac morE = EVERY' [rtac @{thm ext}, rtac trans, rtac o_apply, rtac trans, etac morE,
  17.209 -      rtac CollectI, CONJ_WRAP' (K (rtac subset_UNIV)) (1 upto m + n),
  17.210 -      rtac sym, rtac o_apply];
  17.211 +    fun mor_tac morE = EVERY' [rtac ctxt @{thm ext}, rtac ctxt trans, rtac ctxt o_apply, rtac ctxt trans, etac ctxt morE,
  17.212 +      rtac ctxt CollectI, CONJ_WRAP' (K (rtac ctxt subset_UNIV)) (1 upto m + n),
  17.213 +      rtac ctxt sym, rtac ctxt o_apply];
  17.214    in
  17.215 -    EVERY' [rtac iffI, CONJ_WRAP' mor_tac morEs,
  17.216 -    rtac (mor_def RS iffD2), rtac conjI, CONJ_WRAP' (K (rtac ballI THEN' rtac UNIV_I)) morEs,
  17.217 -    REPEAT_DETERM o etac conjE, REPEAT_DETERM_N n o dtac (@{thm fun_eq_iff} RS iffD1),
  17.218 -    CONJ_WRAP' (K (EVERY' [rtac ballI, REPEAT_DETERM o etac allE, rtac trans,
  17.219 -      etac (o_apply RS sym RS trans), rtac o_apply])) morEs] 1
  17.220 +    EVERY' [rtac ctxt iffI, CONJ_WRAP' mor_tac morEs,
  17.221 +    rtac ctxt (mor_def RS iffD2), rtac ctxt conjI, CONJ_WRAP' (K (rtac ctxt ballI THEN' rtac ctxt UNIV_I)) morEs,
  17.222 +    REPEAT_DETERM o etac ctxt conjE, REPEAT_DETERM_N n o dtac ctxt (@{thm fun_eq_iff} RS iffD1),
  17.223 +    CONJ_WRAP' (K (EVERY' [rtac ctxt ballI, REPEAT_DETERM o etac ctxt allE, rtac ctxt trans,
  17.224 +      etac ctxt (o_apply RS sym RS trans), rtac ctxt o_apply])) morEs] 1
  17.225    end;
  17.226  
  17.227 -fun mk_copy_tac m alg_def mor_def alg_sets set_mapss =
  17.228 +fun mk_copy_tac ctxt m alg_def mor_def alg_sets set_mapss =
  17.229    let
  17.230      val n = length alg_sets;
  17.231      fun set_tac thm =
  17.232 -      EVERY' [rtac ord_eq_le_trans, rtac thm, rtac subset_trans, etac @{thm image_mono},
  17.233 -        rtac equalityD1, etac @{thm bij_betw_imageE}];
  17.234 +      EVERY' [rtac ctxt ord_eq_le_trans, rtac ctxt thm, rtac ctxt subset_trans, etac ctxt @{thm image_mono},
  17.235 +        rtac ctxt equalityD1, etac ctxt @{thm bij_betw_imageE}];
  17.236      val alg_tac =
  17.237        CONJ_WRAP' (fn (set_maps, alg_set) =>
  17.238 -        EVERY' [rtac ballI, REPEAT_DETERM o eresolve0_tac [CollectE, conjE], rtac set_mp,
  17.239 -          rtac equalityD1, etac @{thm bij_betw_imageE[OF bij_betw_the_inv_into]},
  17.240 -          rtac imageI, etac alg_set, EVERY' (map set_tac (drop m set_maps))])
  17.241 +        EVERY' [rtac ctxt ballI, REPEAT_DETERM o eresolve0_tac [CollectE, conjE], rtac ctxt set_mp,
  17.242 +          rtac ctxt equalityD1, etac ctxt @{thm bij_betw_imageE[OF bij_betw_the_inv_into]},
  17.243 +          rtac ctxt imageI, etac ctxt alg_set, EVERY' (map set_tac (drop m set_maps))])
  17.244        (set_mapss ~~ alg_sets);
  17.245  
  17.246 -    val mor_tac = rtac conjI THEN' CONJ_WRAP' (K (etac @{thm bij_betwE})) alg_sets THEN'
  17.247 +    val mor_tac = rtac ctxt conjI THEN' CONJ_WRAP' (K (etac ctxt @{thm bij_betwE})) alg_sets THEN'
  17.248        CONJ_WRAP' (fn (set_maps, alg_set) =>
  17.249 -        EVERY' [rtac ballI, REPEAT_DETERM o eresolve0_tac [CollectE, conjE],
  17.250 -          etac @{thm f_the_inv_into_f_bij_betw}, etac alg_set,
  17.251 +        EVERY' [rtac ctxt ballI, REPEAT_DETERM o eresolve0_tac [CollectE, conjE],
  17.252 +          etac ctxt @{thm f_the_inv_into_f_bij_betw}, etac ctxt alg_set,
  17.253            EVERY' (map set_tac (drop m set_maps))])
  17.254        (set_mapss ~~ alg_sets);
  17.255    in
  17.256 -    (REPEAT_DETERM_N n o rtac exI THEN' rtac conjI THEN'
  17.257 -    rtac (alg_def RS iffD2) THEN' alg_tac THEN' rtac (mor_def RS iffD2) THEN' mor_tac) 1
  17.258 +    (REPEAT_DETERM_N n o rtac ctxt exI THEN' rtac ctxt conjI THEN'
  17.259 +    rtac ctxt (alg_def RS iffD2) THEN' alg_tac THEN' rtac ctxt (mor_def RS iffD2) THEN' mor_tac) 1
  17.260    end;
  17.261  
  17.262 -fun mk_bd_limit_tac n bd_Cinfinite =
  17.263 -  EVERY' [REPEAT_DETERM o etac conjE, rtac rev_mp, rtac @{thm Cinfinite_limit_finite},
  17.264 -    REPEAT_DETERM_N n o rtac @{thm finite.insertI}, rtac @{thm finite.emptyI},
  17.265 -    REPEAT_DETERM_N n o etac @{thm insert_subsetI}, rtac @{thm empty_subsetI},
  17.266 -    rtac bd_Cinfinite, rtac impI, etac bexE, rtac bexI,
  17.267 +fun mk_bd_limit_tac ctxt n bd_Cinfinite =
  17.268 +  EVERY' [REPEAT_DETERM o etac ctxt conjE, rtac ctxt rev_mp, rtac ctxt @{thm Cinfinite_limit_finite},
  17.269 +    REPEAT_DETERM_N n o rtac ctxt @{thm finite.insertI}, rtac ctxt @{thm finite.emptyI},
  17.270 +    REPEAT_DETERM_N n o etac ctxt @{thm insert_subsetI}, rtac ctxt @{thm empty_subsetI},
  17.271 +    rtac ctxt bd_Cinfinite, rtac ctxt impI, etac ctxt bexE, rtac ctxt bexI,
  17.272      CONJ_WRAP' (fn i =>
  17.273 -      EVERY' [etac bspec, REPEAT_DETERM_N i o rtac @{thm insertI2}, rtac @{thm insertI1}])
  17.274 +      EVERY' [etac ctxt bspec, REPEAT_DETERM_N i o rtac ctxt @{thm insertI2}, rtac ctxt @{thm insertI1}])
  17.275        (0 upto n - 1),
  17.276      atac] 1;
  17.277  
  17.278 -fun mk_min_algs_tac worel in_congs =
  17.279 +fun mk_min_algs_tac ctxt worel in_congs =
  17.280    let
  17.281 -    val minG_tac = EVERY' [rtac @{thm SUP_cong}, rtac refl, dtac bspec, atac, etac arg_cong];
  17.282 +    val minG_tac = EVERY' [rtac ctxt @{thm SUP_cong}, rtac ctxt refl, dtac ctxt bspec, atac, etac ctxt arg_cong];
  17.283      fun minH_tac thm =
  17.284 -      EVERY' [rtac Un_cong, minG_tac, rtac @{thm image_cong}, rtac thm,
  17.285 -        REPEAT_DETERM_N (length in_congs) o minG_tac, rtac refl];
  17.286 +      EVERY' [rtac ctxt Un_cong, minG_tac, rtac ctxt @{thm image_cong}, rtac ctxt thm,
  17.287 +        REPEAT_DETERM_N (length in_congs) o minG_tac, rtac ctxt refl];
  17.288    in
  17.289 -    (rtac (worel RS (@{thm wo_rel.worec_fixpoint} RS fun_cong)) THEN' rtac iffD2 THEN'
  17.290 -    rtac meta_eq_to_obj_eq THEN' rtac (worel RS @{thm wo_rel.adm_wo_def}) THEN'
  17.291 -    REPEAT_DETERM_N 3 o rtac allI THEN' rtac impI THEN'
  17.292 -    CONJ_WRAP_GEN' (EVERY' [rtac prod_injectI, rtac conjI]) minH_tac in_congs) 1
  17.293 +    (rtac ctxt (worel RS (@{thm wo_rel.worec_fixpoint} RS fun_cong)) THEN' rtac ctxt iffD2 THEN'
  17.294 +    rtac ctxt meta_eq_to_obj_eq THEN' rtac ctxt (worel RS @{thm wo_rel.adm_wo_def}) THEN'
  17.295 +    REPEAT_DETERM_N 3 o rtac ctxt allI THEN' rtac ctxt impI THEN'
  17.296 +    CONJ_WRAP_GEN' (EVERY' [rtac ctxt prod_injectI, rtac ctxt conjI]) minH_tac in_congs) 1
  17.297    end;
  17.298  
  17.299 -fun mk_min_algs_mono_tac ctxt min_algs = EVERY' [rtac relChainD, rtac allI, rtac allI, rtac impI,
  17.300 -  rtac @{thm case_split}, rtac @{thm xt1(3)}, rtac min_algs, etac @{thm FieldI2}, rtac subsetI,
  17.301 -  rtac UnI1, rtac @{thm UN_I}, etac @{thm underS_I}, atac, atac, rtac equalityD1,
  17.302 -  dtac @{thm notnotD}, hyp_subst_tac ctxt, rtac refl] 1;
  17.303 +fun mk_min_algs_mono_tac ctxt min_algs = EVERY' [rtac ctxt relChainD, rtac ctxt allI, rtac ctxt allI, rtac ctxt impI,
  17.304 +  rtac ctxt @{thm case_split}, rtac ctxt @{thm xt1(3)}, rtac ctxt min_algs, etac ctxt @{thm FieldI2}, rtac ctxt subsetI,
  17.305 +  rtac ctxt UnI1, rtac ctxt @{thm UN_I}, etac ctxt @{thm underS_I}, atac, atac, rtac ctxt equalityD1,
  17.306 +  dtac ctxt @{thm notnotD}, hyp_subst_tac ctxt, rtac ctxt refl] 1;
  17.307  
  17.308 -fun mk_min_algs_card_of_tac cT ct m worel min_algs in_bds bd_Card_order bd_Cnotzero
  17.309 +fun mk_min_algs_card_of_tac ctxt cT ct m worel min_algs in_bds bd_Card_order bd_Cnotzero
  17.310    suc_Card_order suc_Cinfinite suc_Cnotzero suc_Asuc Asuc_Cinfinite =
  17.311    let
  17.312      val induct = worel RS
  17.313 @@ -222,121 +223,121 @@
  17.314      val src = 1 upto m + 1;
  17.315      val dest = (m + 1) :: (1 upto m);
  17.316      val absorbAs_tac = if m = 0 then K (all_tac)
  17.317 -      else EVERY' [rtac @{thm ordIso_transitive}, rtac @{thm csum_cong1},
  17.318 -        rtac @{thm ordIso_transitive},
  17.319 -        BNF_Tactics.mk_rotate_eq_tac (rtac @{thm ordIso_refl} THEN'
  17.320 -          FIRST' [rtac @{thm card_of_Card_order}, rtac @{thm Card_order_csum},
  17.321 -            rtac @{thm Card_order_cexp}])
  17.322 +      else EVERY' [rtac ctxt @{thm ordIso_transitive}, rtac ctxt @{thm csum_cong1},
  17.323 +        rtac ctxt @{thm ordIso_transitive},
  17.324 +        BNF_Tactics.mk_rotate_eq_tac ctxt (rtac ctxt @{thm ordIso_refl} THEN'
  17.325 +          FIRST' [rtac ctxt @{thm card_of_Card_order}, rtac ctxt @{thm Card_order_csum},
  17.326 +            rtac ctxt @{thm Card_order_cexp}])
  17.327          @{thm ordIso_transitive} @{thm csum_assoc} @{thm csum_com} @{thm csum_cong}
  17.328          src dest,
  17.329 -        rtac @{thm csum_absorb1}, rtac Asuc_Cinfinite, rtac ctrans, rtac @{thm ordLeq_csum1},
  17.330 -        FIRST' [rtac @{thm Card_order_csum}, rtac @{thm card_of_Card_order}],
  17.331 -        rtac @{thm ordLeq_cexp1}, rtac suc_Cnotzero, rtac @{thm Card_order_csum}];
  17.332 +        rtac ctxt @{thm csum_absorb1}, rtac ctxt Asuc_Cinfinite, rtac ctxt ctrans, rtac ctxt @{thm ordLeq_csum1},
  17.333 +        FIRST' [rtac ctxt @{thm Card_order_csum}, rtac ctxt @{thm card_of_Card_order}],
  17.334 +        rtac ctxt @{thm ordLeq_cexp1}, rtac ctxt suc_Cnotzero, rtac ctxt @{thm Card_order_csum}];
  17.335  
  17.336 -    val minG_tac = EVERY' [rtac @{thm UNION_Cinfinite_bound}, rtac @{thm ordLess_imp_ordLeq},
  17.337 -      rtac @{thm ordLess_transitive}, rtac @{thm card_of_underS}, rtac suc_Card_order,
  17.338 -      atac, rtac suc_Asuc, rtac ballI, etac allE, dtac mp, etac @{thm underS_E},
  17.339 -      dtac mp, etac @{thm underS_Field}, REPEAT o etac conjE, atac, rtac Asuc_Cinfinite]
  17.340 +    val minG_tac = EVERY' [rtac ctxt @{thm UNION_Cinfinite_bound}, rtac ctxt @{thm ordLess_imp_ordLeq},
  17.341 +      rtac ctxt @{thm ordLess_transitive}, rtac ctxt @{thm card_of_underS}, rtac ctxt suc_Card_order,
  17.342 +      atac, rtac ctxt suc_Asuc, rtac ctxt ballI, etac ctxt allE, dtac ctxt mp, etac ctxt @{thm underS_E},
  17.343 +      dtac ctxt mp, etac ctxt @{thm underS_Field}, REPEAT o etac ctxt conjE, atac, rtac ctxt Asuc_Cinfinite]
  17.344  
  17.345 -    fun mk_minH_tac (min_alg, in_bd) = EVERY' [rtac @{thm ordIso_ordLeq_trans},
  17.346 -      rtac @{thm card_of_ordIso_subst}, etac min_alg, rtac @{thm Un_Cinfinite_bound},
  17.347 -      minG_tac, rtac ctrans, rtac @{thm card_of_image}, rtac ctrans, rtac in_bd, rtac ctrans,
  17.348 -      rtac @{thm cexp_mono1}, rtac @{thm csum_mono1},
  17.349 -      REPEAT_DETERM_N m o rtac @{thm csum_mono2},
  17.350 -      CONJ_WRAP_GEN' (rtac @{thm csum_cinfinite_bound}) (K minG_tac) min_algs,
  17.351 +    fun mk_minH_tac (min_alg, in_bd) = EVERY' [rtac ctxt @{thm ordIso_ordLeq_trans},
  17.352 +      rtac ctxt @{thm card_of_ordIso_subst}, etac ctxt min_alg, rtac ctxt @{thm Un_Cinfinite_bound},
  17.353 +      minG_tac, rtac ctxt ctrans, rtac ctxt @{thm card_of_image}, rtac ctxt ctrans, rtac ctxt in_bd, rtac ctxt ctrans,
  17.354 +      rtac ctxt @{thm cexp_mono1}, rtac ctxt @{thm csum_mono1},
  17.355 +      REPEAT_DETERM_N m o rtac ctxt @{thm csum_mono2},
  17.356 +      CONJ_WRAP_GEN' (rtac ctxt @{thm csum_cinfinite_bound}) (K minG_tac) min_algs,
  17.357        REPEAT_DETERM o FIRST'
  17.358 -        [rtac @{thm card_of_Card_order}, rtac @{thm Card_order_csum},
  17.359 -        rtac Asuc_Cinfinite, rtac bd_Card_order],
  17.360 -      rtac @{thm ordIso_ordLeq_trans}, rtac @{thm cexp_cong1}, absorbAs_tac,
  17.361 -      rtac @{thm csum_absorb1}, rtac Asuc_Cinfinite, rtac @{thm ctwo_ordLeq_Cinfinite},
  17.362 -      rtac Asuc_Cinfinite, rtac bd_Card_order,
  17.363 -      rtac @{thm ordIso_imp_ordLeq}, rtac @{thm cexp_cprod_ordLeq},
  17.364 -      resolve0_tac @{thms Card_order_csum Card_order_ctwo}, rtac suc_Cinfinite,
  17.365 -      rtac bd_Cnotzero, rtac @{thm cardSuc_ordLeq}, rtac bd_Card_order, rtac Asuc_Cinfinite];
  17.366 +        [rtac ctxt @{thm card_of_Card_order}, rtac ctxt @{thm Card_order_csum},
  17.367 +        rtac ctxt Asuc_Cinfinite, rtac ctxt bd_Card_order],
  17.368 +      rtac ctxt @{thm ordIso_ordLeq_trans}, rtac ctxt @{thm cexp_cong1}, absorbAs_tac,
  17.369 +      rtac ctxt @{thm csum_absorb1}, rtac ctxt Asuc_Cinfinite, rtac ctxt @{thm ctwo_ordLeq_Cinfinite},
  17.370 +      rtac ctxt Asuc_Cinfinite, rtac ctxt bd_Card_order,
  17.371 +      rtac ctxt @{thm ordIso_imp_ordLeq}, rtac ctxt @{thm cexp_cprod_ordLeq},
  17.372 +      resolve0_tac @{thms Card_order_csum Card_order_ctwo}, rtac ctxt suc_Cinfinite,
  17.373 +      rtac ctxt bd_Cnotzero, rtac ctxt @{thm cardSuc_ordLeq}, rtac ctxt bd_Card_order, rtac ctxt Asuc_Cinfinite];
  17.374    in
  17.375 -    (rtac induct THEN'
  17.376 -    rtac impI THEN'
  17.377 +    (rtac ctxt induct THEN'
  17.378 +    rtac ctxt impI THEN'
  17.379      CONJ_WRAP' mk_minH_tac (min_algs ~~ in_bds)) 1
  17.380    end;
  17.381  
  17.382 -fun mk_min_algs_least_tac cT ct worel min_algs alg_sets =
  17.383 +fun mk_min_algs_least_tac ctxt cT ct worel min_algs alg_sets =
  17.384    let
  17.385      val induct = worel RS
  17.386        Drule.instantiate' [SOME cT] [NONE, SOME ct] @{thm well_order_induct_imp};
  17.387  
  17.388 -    val minG_tac = EVERY' [rtac @{thm UN_least}, etac allE, dtac mp, etac @{thm underS_E},
  17.389 -      dtac mp, etac @{thm underS_Field}, REPEAT_DETERM o etac conjE, atac];
  17.390 +    val minG_tac = EVERY' [rtac ctxt @{thm UN_least}, etac ctxt allE, dtac ctxt mp, etac ctxt @{thm underS_E},
  17.391 +      dtac ctxt mp, etac ctxt @{thm underS_Field}, REPEAT_DETERM o etac ctxt conjE, atac];
  17.392  
  17.393 -    fun mk_minH_tac (min_alg, alg_set) = EVERY' [rtac ord_eq_le_trans, etac min_alg,
  17.394 -      rtac @{thm Un_least}, minG_tac, rtac @{thm image_subsetI},
  17.395 -      REPEAT_DETERM o eresolve0_tac [CollectE, conjE], etac alg_set,
  17.396 -      REPEAT_DETERM o (etac subset_trans THEN' minG_tac)];
  17.397 +    fun mk_minH_tac (min_alg, alg_set) = EVERY' [rtac ctxt ord_eq_le_trans, etac ctxt min_alg,
  17.398 +      rtac ctxt @{thm Un_least}, minG_tac, rtac ctxt @{thm image_subsetI},
  17.399 +      REPEAT_DETERM o eresolve0_tac [CollectE, conjE], etac ctxt alg_set,
  17.400 +      REPEAT_DETERM o (etac ctxt subset_trans THEN' minG_tac)];
  17.401    in
  17.402 -    (rtac induct THEN'
  17.403 -    rtac impI THEN'
  17.404 +    (rtac ctxt induct THEN'
  17.405 +    rtac ctxt impI THEN'
  17.406      CONJ_WRAP' mk_minH_tac (min_algs ~~ alg_sets)) 1
  17.407    end;
  17.408  
  17.409 -fun mk_alg_min_alg_tac m alg_def min_alg_defs bd_limit bd_Cinfinite
  17.410 +fun mk_alg_min_alg_tac ctxt m alg_def min_alg_defs bd_limit bd_Cinfinite
  17.411      set_bdss min_algs min_alg_monos =
  17.412    let
  17.413      val n = length min_algs;
  17.414      fun mk_cardSuc_UNION_tac set_bds (mono, def) = EVERY'
  17.415 -      [rtac bexE, rtac @{thm cardSuc_UNION_Cinfinite}, rtac bd_Cinfinite, rtac mono,
  17.416 -       etac (def RSN (2, @{thm subset_trans[OF _ equalityD1]})), resolve0_tac set_bds];
  17.417 +      [rtac ctxt bexE, rtac ctxt @{thm cardSuc_UNION_Cinfinite}, rtac ctxt bd_Cinfinite, rtac ctxt mono,
  17.418 +       etac ctxt (def RSN (2, @{thm subset_trans[OF _ equalityD1]})), resolve0_tac set_bds];
  17.419      fun mk_conjunct_tac (set_bds, (min_alg, min_alg_def)) =
  17.420 -      EVERY' [rtac ballI, REPEAT_DETERM o eresolve0_tac [CollectE, conjE],
  17.421 -        EVERY' (map (mk_cardSuc_UNION_tac set_bds) (min_alg_monos ~~ min_alg_defs)), rtac bexE,
  17.422 -        rtac bd_limit, REPEAT_DETERM_N (n - 1) o etac conjI, atac,
  17.423 -        rtac (min_alg_def RS @{thm set_mp[OF equalityD2]}),
  17.424 -        rtac @{thm UN_I}, REPEAT_DETERM_N (m + 3 * n) o etac thin_rl, atac, rtac set_mp,
  17.425 -        rtac equalityD2, rtac min_alg, atac, rtac UnI2, rtac @{thm image_eqI}, rtac refl,
  17.426 -        rtac CollectI, REPEAT_DETERM_N m o dtac asm_rl, REPEAT_DETERM_N n o etac thin_rl,
  17.427 -        REPEAT_DETERM o etac conjE,
  17.428 +      EVERY' [rtac ctxt ballI, REPEAT_DETERM o eresolve0_tac [CollectE, conjE],
  17.429 +        EVERY' (map (mk_cardSuc_UNION_tac set_bds) (min_alg_monos ~~ min_alg_defs)), rtac ctxt bexE,
  17.430 +        rtac ctxt bd_limit, REPEAT_DETERM_N (n - 1) o etac ctxt conjI, atac,
  17.431 +        rtac ctxt (min_alg_def RS @{thm set_mp[OF equalityD2]}),
  17.432 +        rtac ctxt @{thm UN_I}, REPEAT_DETERM_N (m + 3 * n) o etac ctxt thin_rl, atac, rtac ctxt set_mp,
  17.433 +        rtac ctxt equalityD2, rtac ctxt min_alg, atac, rtac ctxt UnI2, rtac ctxt @{thm image_eqI}, rtac ctxt refl,
  17.434 +        rtac ctxt CollectI, REPEAT_DETERM_N m o dtac ctxt asm_rl, REPEAT_DETERM_N n o etac ctxt thin_rl,
  17.435 +        REPEAT_DETERM o etac ctxt conjE,
  17.436          CONJ_WRAP' (K (FIRST' [atac,
  17.437 -          EVERY' [etac subset_trans, rtac subsetI, rtac @{thm UN_I},
  17.438 -            etac @{thm underS_I}, atac, atac]]))
  17.439 +          EVERY' [etac ctxt subset_trans, rtac ctxt subsetI, rtac ctxt @{thm UN_I},
  17.440 +            etac ctxt @{thm underS_I}, atac, atac]]))
  17.441            set_bds];
  17.442    in
  17.443 -    (rtac (alg_def RS iffD2) THEN'
  17.444 +    (rtac ctxt (alg_def RS iffD2) THEN'
  17.445      CONJ_WRAP' mk_conjunct_tac (set_bdss ~~ (min_algs ~~ min_alg_defs))) 1
  17.446    end;
  17.447  
  17.448 -fun mk_card_of_min_alg_tac min_alg_def card_of suc_Card_order suc_Asuc Asuc_Cinfinite =
  17.449 -  EVERY' [rtac @{thm ordIso_ordLeq_trans}, rtac (min_alg_def RS @{thm card_of_ordIso_subst}),
  17.450 -    rtac @{thm UNION_Cinfinite_bound}, rtac @{thm ordIso_ordLeq_trans},
  17.451 -    rtac @{thm card_of_Field_ordIso}, rtac suc_Card_order, rtac @{thm ordLess_imp_ordLeq},
  17.452 -    rtac suc_Asuc, rtac ballI, dtac rev_mp, rtac card_of,  REPEAT_DETERM o etac conjE, atac,
  17.453 -    rtac Asuc_Cinfinite] 1;
  17.454 +fun mk_card_of_min_alg_tac ctxt min_alg_def card_of suc_Card_order suc_Asuc Asuc_Cinfinite =
  17.455 +  EVERY' [rtac ctxt @{thm ordIso_ordLeq_trans}, rtac ctxt (min_alg_def RS @{thm card_of_ordIso_subst}),
  17.456 +    rtac ctxt @{thm UNION_Cinfinite_bound}, rtac ctxt @{thm ordIso_ordLeq_trans},
  17.457 +    rtac ctxt @{thm card_of_Field_ordIso}, rtac ctxt suc_Card_order, rtac ctxt @{thm ordLess_imp_ordLeq},
  17.458 +    rtac ctxt suc_Asuc, rtac ctxt ballI, dtac ctxt rev_mp, rtac ctxt card_of,  REPEAT_DETERM o etac ctxt conjE, atac,
  17.459 +    rtac ctxt Asuc_Cinfinite] 1;
  17.460  
  17.461 -fun mk_least_min_alg_tac min_alg_def least =
  17.462 -  EVERY' [rtac (min_alg_def RS ord_eq_le_trans), rtac @{thm UN_least}, dtac least, dtac mp, atac,
  17.463 -    REPEAT_DETERM o etac conjE, atac] 1;
  17.464 +fun mk_least_min_alg_tac ctxt min_alg_def least =
  17.465 +  EVERY' [rtac ctxt (min_alg_def RS ord_eq_le_trans), rtac ctxt @{thm UN_least}, dtac ctxt least, dtac ctxt mp, atac,
  17.466 +    REPEAT_DETERM o etac ctxt conjE, atac] 1;
  17.467  
  17.468  fun mk_alg_select_tac ctxt Abs_inverse =
  17.469 -  EVERY' [rtac ballI,
  17.470 +  EVERY' [rtac ctxt ballI,
  17.471      REPEAT_DETERM o eresolve_tac ctxt [CollectE, exE, conjE], hyp_subst_tac ctxt] 1 THEN
  17.472    unfold_thms_tac ctxt (Abs_inverse :: fst_snd_convs) THEN atac 1;
  17.473  
  17.474 -fun mk_mor_select_tac mor_def mor_cong mor_comp mor_incl_min_alg alg_def alg_select alg_sets
  17.475 +fun mk_mor_select_tac ctxt mor_def mor_cong mor_comp mor_incl_min_alg alg_def alg_select alg_sets
  17.476      set_maps str_init_defs =
  17.477    let
  17.478      val n = length alg_sets;
  17.479      val fbetw_tac =
  17.480 -      CONJ_WRAP' (K (EVERY' [rtac ballI, etac rev_bspec, etac CollectE, atac])) alg_sets;
  17.481 +      CONJ_WRAP' (K (EVERY' [rtac ctxt ballI, etac ctxt rev_bspec, etac ctxt CollectE, atac])) alg_sets;
  17.482      val mor_tac =
  17.483 -      CONJ_WRAP' (fn thm => EVERY' [rtac ballI, rtac thm]) str_init_defs;
  17.484 +      CONJ_WRAP' (fn thm => EVERY' [rtac ctxt ballI, rtac ctxt thm]) str_init_defs;
  17.485      fun alg_epi_tac ((alg_set, str_init_def), set_map) =
  17.486 -      EVERY' [rtac ballI, REPEAT_DETERM o eresolve0_tac [CollectE, conjE], rtac CollectI,
  17.487 -        rtac ballI, ftac (alg_select RS bspec), rtac (str_init_def RS @{thm ssubst_mem}),
  17.488 -        etac alg_set, REPEAT_DETERM o EVERY' [rtac ord_eq_le_trans, resolve0_tac set_map,
  17.489 -          rtac subset_trans, etac @{thm image_mono}, rtac @{thm image_Collect_subsetI}, etac bspec,
  17.490 +      EVERY' [rtac ctxt ballI, REPEAT_DETERM o eresolve0_tac [CollectE, conjE], rtac ctxt CollectI,
  17.491 +        rtac ctxt ballI, ftac ctxt (alg_select RS bspec), rtac ctxt (str_init_def RS @{thm ssubst_mem}),
  17.492 +        etac ctxt alg_set, REPEAT_DETERM o EVERY' [rtac ctxt ord_eq_le_trans, resolve0_tac set_map,
  17.493 +          rtac ctxt subset_trans, etac ctxt @{thm image_mono}, rtac ctxt @{thm image_Collect_subsetI}, etac ctxt bspec,
  17.494            atac]];
  17.495    in
  17.496 -    EVERY' [rtac mor_cong, REPEAT_DETERM_N n o (rtac sym THEN' rtac @{thm comp_id}),
  17.497 -      rtac (Thm.permute_prems 0 1 mor_comp), etac (Thm.permute_prems 0 1 mor_comp),
  17.498 -      rtac (mor_def RS iffD2), rtac conjI, fbetw_tac, mor_tac, rtac mor_incl_min_alg,
  17.499 -      rtac (alg_def RS iffD2), CONJ_WRAP' alg_epi_tac ((alg_sets ~~ str_init_defs) ~~ set_maps)] 1
  17.500 +    EVERY' [rtac ctxt mor_cong, REPEAT_DETERM_N n o (rtac ctxt sym THEN' rtac ctxt @{thm comp_id}),
  17.501 +      rtac ctxt (Thm.permute_prems 0 1 mor_comp), etac ctxt (Thm.permute_prems 0 1 mor_comp),
  17.502 +      rtac ctxt (mor_def RS iffD2), rtac ctxt conjI, fbetw_tac, mor_tac, rtac ctxt mor_incl_min_alg,
  17.503 +      rtac ctxt (alg_def RS iffD2), CONJ_WRAP' alg_epi_tac ((alg_sets ~~ str_init_defs) ~~ set_maps)] 1
  17.504    end;
  17.505  
  17.506  fun mk_init_ex_mor_tac ctxt Abs_inverse copy card_of_min_algs mor_Rep mor_comp mor_select mor_incl =
  17.507 @@ -344,59 +345,59 @@
  17.508      val n = length card_of_min_algs;
  17.509    in
  17.510      EVERY' [Method.insert_tac (map (fn thm => thm RS @{thm ex_bij_betw}) card_of_min_algs),
  17.511 -      REPEAT_DETERM o etac exE, rtac rev_mp, rtac copy, REPEAT_DETERM_N n o atac,
  17.512 -      rtac impI, REPEAT_DETERM o eresolve0_tac [exE, conjE], REPEAT_DETERM_N n o rtac exI,
  17.513 -      rtac mor_comp, rtac mor_Rep, rtac mor_select, rtac CollectI, REPEAT_DETERM o rtac exI,
  17.514 -      rtac conjI, rtac refl, atac,
  17.515 +      REPEAT_DETERM o etac ctxt exE, rtac ctxt rev_mp, rtac ctxt copy, REPEAT_DETERM_N n o atac,
  17.516 +      rtac ctxt impI, REPEAT_DETERM o eresolve0_tac [exE, conjE], REPEAT_DETERM_N n o rtac ctxt exI,
  17.517 +      rtac ctxt mor_comp, rtac ctxt mor_Rep, rtac ctxt mor_select, rtac ctxt CollectI, REPEAT_DETERM o rtac ctxt exI,
  17.518 +      rtac ctxt conjI, rtac ctxt refl, atac,
  17.519        SELECT_GOAL (unfold_thms_tac ctxt (Abs_inverse :: fst_snd_convs)),
  17.520 -      etac mor_comp, rtac mor_incl, REPEAT_DETERM_N n o rtac subset_UNIV] 1
  17.521 +      etac ctxt mor_comp, rtac ctxt mor_incl, REPEAT_DETERM_N n o rtac ctxt subset_UNIV] 1
  17.522    end;
  17.523  
  17.524 -fun mk_init_unique_mor_tac cts m
  17.525 +fun mk_init_unique_mor_tac ctxt cts m
  17.526      alg_def alg_min_alg least_min_algs in_monos alg_sets morEs map_cong0s =
  17.527    let
  17.528      val n = length least_min_algs;
  17.529      val ks = (1 upto n);
  17.530  
  17.531 -    fun mor_tac morE in_mono = EVERY' [etac morE, rtac set_mp, rtac in_mono,
  17.532 -      REPEAT_DETERM_N n o rtac @{thm Collect_restrict}, rtac CollectI,
  17.533 -      REPEAT_DETERM_N (m + n) o (TRY o rtac conjI THEN' atac)];
  17.534 +    fun mor_tac morE in_mono = EVERY' [etac ctxt morE, rtac ctxt set_mp, rtac ctxt in_mono,
  17.535 +      REPEAT_DETERM_N n o rtac ctxt @{thm Collect_restrict}, rtac ctxt CollectI,
  17.536 +      REPEAT_DETERM_N (m + n) o (TRY o rtac ctxt conjI THEN' atac)];
  17.537      fun cong_tac ct map_cong0 = EVERY'
  17.538 -      [rtac (map_cong0 RS cterm_instantiate_pos [NONE, NONE, SOME ct] arg_cong),
  17.539 -      REPEAT_DETERM_N m o rtac refl,
  17.540 -      REPEAT_DETERM_N n o (etac @{thm prop_restrict} THEN' atac)];
  17.541 +      [rtac ctxt (map_cong0 RS cterm_instantiate_pos [NONE, NONE, SOME ct] arg_cong),
  17.542 +      REPEAT_DETERM_N m o rtac ctxt refl,
  17.543 +      REPEAT_DETERM_N n o (etac ctxt @{thm prop_restrict} THEN' atac)];
  17.544  
  17.545      fun mk_alg_tac (ct, (alg_set, (in_mono, (morE, map_cong0)))) =
  17.546 -      EVERY' [rtac ballI, rtac CollectI,
  17.547 -        REPEAT_DETERM o eresolve0_tac [CollectE, conjE], rtac conjI, rtac (alg_min_alg RS alg_set),
  17.548 -        REPEAT_DETERM_N n o (etac subset_trans THEN' rtac @{thm Collect_restrict}),
  17.549 -        rtac trans, mor_tac morE in_mono,
  17.550 -        rtac trans, cong_tac ct map_cong0,
  17.551 -        rtac sym, mor_tac morE in_mono];
  17.552 +      EVERY' [rtac ctxt ballI, rtac ctxt CollectI,
  17.553 +        REPEAT_DETERM o eresolve0_tac [CollectE, conjE], rtac ctxt conjI, rtac ctxt (alg_min_alg RS alg_set),
  17.554 +        REPEAT_DETERM_N n o (etac ctxt subset_trans THEN' rtac ctxt @{thm Collect_restrict}),
  17.555 +        rtac ctxt trans, mor_tac morE in_mono,
  17.556 +        rtac ctxt trans, cong_tac ct map_cong0,
  17.557 +        rtac ctxt sym, mor_tac morE in_mono];
  17.558  
  17.559      fun mk_unique_tac (k, least_min_alg) =
  17.560 -      select_prem_tac n (etac @{thm prop_restrict}) k THEN' rtac least_min_alg THEN'
  17.561 -      rtac (alg_def RS iffD2) THEN'
  17.562 +      select_prem_tac ctxt n (etac ctxt @{thm prop_restrict}) k THEN' rtac ctxt least_min_alg THEN'
  17.563 +      rtac ctxt (alg_def RS iffD2) THEN'
  17.564        CONJ_WRAP' mk_alg_tac (cts ~~ (alg_sets ~~ (in_monos ~~ (morEs ~~ map_cong0s))));
  17.565    in
  17.566      CONJ_WRAP' mk_unique_tac (ks ~~ least_min_algs) 1
  17.567    end;
  17.568  
  17.569 -fun mk_init_induct_tac m alg_def alg_min_alg least_min_algs alg_sets =
  17.570 +fun mk_init_induct_tac ctxt m alg_def alg_min_alg least_min_algs alg_sets =
  17.571    let
  17.572      val n = length least_min_algs;
  17.573  
  17.574 -    fun mk_alg_tac alg_set = EVERY' [rtac ballI, rtac CollectI,
  17.575 -      REPEAT_DETERM o eresolve0_tac [CollectE, conjE], rtac conjI, rtac (alg_min_alg RS alg_set),
  17.576 -      REPEAT_DETERM_N n o (etac subset_trans THEN' rtac @{thm Collect_restrict}),
  17.577 -      rtac mp, etac bspec, rtac CollectI,
  17.578 -      REPEAT_DETERM_N m o (rtac conjI THEN' atac),
  17.579 -      CONJ_WRAP' (K (etac subset_trans THEN' rtac @{thm Collect_restrict})) alg_sets,
  17.580 -      CONJ_WRAP' (K (rtac ballI THEN' etac @{thm prop_restrict} THEN' atac)) alg_sets];
  17.581 +    fun mk_alg_tac alg_set = EVERY' [rtac ctxt ballI, rtac ctxt CollectI,
  17.582 +      REPEAT_DETERM o eresolve0_tac [CollectE, conjE], rtac ctxt conjI, rtac ctxt (alg_min_alg RS alg_set),
  17.583 +      REPEAT_DETERM_N n o (etac ctxt subset_trans THEN' rtac ctxt @{thm Collect_restrict}),
  17.584 +      rtac ctxt mp, etac ctxt bspec, rtac ctxt CollectI,
  17.585 +      REPEAT_DETERM_N m o (rtac ctxt conjI THEN' atac),
  17.586 +      CONJ_WRAP' (K (etac ctxt subset_trans THEN' rtac ctxt @{thm Collect_restrict})) alg_sets,
  17.587 +      CONJ_WRAP' (K (rtac ctxt ballI THEN' etac ctxt @{thm prop_restrict} THEN' atac)) alg_sets];
  17.588  
  17.589      fun mk_induct_tac least_min_alg =
  17.590 -      rtac ballI THEN' etac @{thm prop_restrict} THEN' rtac least_min_alg THEN'
  17.591 -      rtac (alg_def RS iffD2) THEN'
  17.592 +      rtac ctxt ballI THEN' etac ctxt @{thm prop_restrict} THEN' rtac ctxt least_min_alg THEN'
  17.593 +      rtac ctxt (alg_def RS iffD2) THEN'
  17.594        CONJ_WRAP' mk_alg_tac alg_sets;
  17.595    in
  17.596      CONJ_WRAP' mk_induct_tac least_min_algs 1
  17.597 @@ -404,61 +405,61 @@
  17.598  
  17.599  fun mk_mor_Rep_tac ctxt m defs Reps Abs_inverses alg_min_alg alg_sets set_mapss =
  17.600    unfold_thms_tac ctxt (@{thm o_apply} :: defs) THEN
  17.601 -  EVERY' [rtac conjI,
  17.602 -    CONJ_WRAP' (fn thm => rtac ballI THEN' rtac thm) Reps,
  17.603 +  EVERY' [rtac ctxt conjI,
  17.604 +    CONJ_WRAP' (fn thm => rtac ctxt ballI THEN' rtac ctxt thm) Reps,
  17.605      CONJ_WRAP' (fn (Abs_inverse, (set_maps, alg_set)) =>
  17.606 -      EVERY' [rtac ballI, rtac Abs_inverse, rtac (alg_min_alg RS alg_set),
  17.607 +      EVERY' [rtac ctxt ballI, rtac ctxt Abs_inverse, rtac ctxt (alg_min_alg RS alg_set),
  17.608          EVERY' (map2 (fn Rep => fn set_map =>
  17.609 -          EVERY' [rtac (set_map RS ord_eq_le_trans), rtac @{thm image_subsetI}, rtac Rep])
  17.610 +          EVERY' [rtac ctxt (set_map RS ord_eq_le_trans), rtac ctxt @{thm image_subsetI}, rtac ctxt Rep])
  17.611          Reps (drop m set_maps))])
  17.612      (Abs_inverses ~~ (set_mapss ~~ alg_sets))] 1;
  17.613  
  17.614  fun mk_mor_Abs_tac ctxt cts defs Abs_inverses map_comp_ids map_congLs =
  17.615    unfold_thms_tac ctxt (@{thm o_apply} :: defs) THEN
  17.616 -  EVERY' [rtac conjI,
  17.617 -    CONJ_WRAP' (K (rtac ballI THEN' rtac UNIV_I)) Abs_inverses,
  17.618 +  EVERY' [rtac ctxt conjI,
  17.619 +    CONJ_WRAP' (K (rtac ctxt ballI THEN' rtac ctxt UNIV_I)) Abs_inverses,
  17.620      CONJ_WRAP' (fn (ct, thm) =>
  17.621 -      EVERY' [rtac ballI, REPEAT_DETERM o eresolve_tac ctxt [CollectE, conjE],
  17.622 -        rtac (thm RS (cterm_instantiate_pos [NONE, NONE, SOME ct] arg_cong) RS sym),
  17.623 +      EVERY' [rtac ctxt ballI, REPEAT_DETERM o eresolve_tac ctxt [CollectE, conjE],
  17.624 +        rtac ctxt (thm RS (cterm_instantiate_pos [NONE, NONE, SOME ct] arg_cong) RS sym),
  17.625          EVERY' (map (fn Abs_inverse =>
  17.626 -          EVERY' [rtac (o_apply RS trans RS ballI), etac (set_mp RS Abs_inverse), atac])
  17.627 +          EVERY' [rtac ctxt (o_apply RS trans RS ballI), etac ctxt (set_mp RS Abs_inverse), atac])
  17.628          Abs_inverses)])
  17.629      (cts ~~ map2 mk_trans map_comp_ids map_congLs)] 1;;
  17.630  
  17.631  fun mk_mor_fold_tac ctxt cT ct fold_defs ex_mor mor =
  17.632 -  (EVERY' (map (stac ctxt) fold_defs) THEN' EVERY' [rtac rev_mp, rtac ex_mor, rtac impI] THEN'
  17.633 -  REPEAT_DETERM_N (length fold_defs) o etac exE THEN'
  17.634 -  rtac (Drule.instantiate' [SOME cT] [SOME ct] @{thm someI}) THEN' etac mor) 1;
  17.635 +  (EVERY' (map (stac ctxt) fold_defs) THEN' EVERY' [rtac ctxt rev_mp, rtac ctxt ex_mor, rtac ctxt impI] THEN'
  17.636 +  REPEAT_DETERM_N (length fold_defs) o etac ctxt exE THEN'
  17.637 +  rtac ctxt (Drule.instantiate' [SOME cT] [SOME ct] @{thm someI}) THEN' etac ctxt mor) 1;
  17.638  
  17.639 -fun mk_fold_unique_mor_tac type_defs init_unique_mors Reps mor_comp mor_Abs mor_fold =
  17.640 +fun mk_fold_unique_mor_tac ctxt type_defs init_unique_mors Reps mor_comp mor_Abs mor_fold =
  17.641    let
  17.642      fun mk_unique type_def =
  17.643 -      EVERY' [rtac @{thm surj_fun_eq}, rtac (type_def RS @{thm type_definition.Abs_image}),
  17.644 -        rtac ballI, resolve0_tac init_unique_mors,
  17.645 -        EVERY' (map (fn thm => atac ORELSE' rtac thm) Reps),
  17.646 -        rtac mor_comp, rtac mor_Abs, atac,
  17.647 -        rtac mor_comp, rtac mor_Abs, rtac mor_fold];
  17.648 +      EVERY' [rtac ctxt @{thm surj_fun_eq}, rtac ctxt (type_def RS @{thm type_definition.Abs_image}),
  17.649 +        rtac ctxt ballI, resolve0_tac init_unique_mors,
  17.650 +        EVERY' (map (fn thm => atac ORELSE' rtac ctxt thm) Reps),
  17.651 +        rtac ctxt mor_comp, rtac ctxt mor_Abs, atac,
  17.652 +        rtac ctxt mor_comp, rtac ctxt mor_Abs, rtac ctxt mor_fold];
  17.653    in
  17.654      CONJ_WRAP' mk_unique type_defs 1
  17.655    end;
  17.656  
  17.657 -fun mk_dtor_o_ctor_tac dtor_def foldx map_comp_id map_cong0L ctor_o_folds =
  17.658 -  EVERY' [rtac @{thm ext}, rtac trans, rtac o_apply, rtac (dtor_def RS fun_cong RS trans),
  17.659 -    rtac trans, rtac foldx, rtac trans, rtac map_comp_id, rtac trans, rtac map_cong0L,
  17.660 -    EVERY' (map (fn thm => rtac ballI THEN' rtac (trans OF [thm RS fun_cong, id_apply]))
  17.661 +fun mk_dtor_o_ctor_tac ctxt dtor_def foldx map_comp_id map_cong0L ctor_o_folds =
  17.662 +  EVERY' [rtac ctxt @{thm ext}, rtac ctxt trans, rtac ctxt o_apply, rtac ctxt (dtor_def RS fun_cong RS trans),
  17.663 +    rtac ctxt trans, rtac ctxt foldx, rtac ctxt trans, rtac ctxt map_comp_id, rtac ctxt trans, rtac ctxt map_cong0L,
  17.664 +    EVERY' (map (fn thm => rtac ctxt ballI THEN' rtac ctxt (trans OF [thm RS fun_cong, id_apply]))
  17.665        ctor_o_folds),
  17.666 -    rtac sym, rtac id_apply] 1;
  17.667 +    rtac ctxt sym, rtac ctxt id_apply] 1;
  17.668  
  17.669  fun mk_rec_tac ctxt rec_defs foldx fst_recs =
  17.670    unfold_thms_tac ctxt
  17.671      (rec_defs @ map (fn thm => thm RS @{thm convol_expand_snd}) fst_recs) THEN
  17.672 -  EVERY' [rtac trans, rtac o_apply, rtac trans, rtac (foldx RS @{thm arg_cong[of _ _ snd]}),
  17.673 -    rtac @{thm snd_convol'}] 1;
  17.674 +  EVERY' [rtac ctxt trans, rtac ctxt o_apply, rtac ctxt trans, rtac ctxt (foldx RS @{thm arg_cong[of _ _ snd]}),
  17.675 +    rtac ctxt @{thm snd_convol'}] 1;
  17.676  
  17.677  fun mk_rec_unique_mor_tac ctxt rec_defs fst_recs fold_unique_mor =
  17.678    unfold_thms_tac ctxt
  17.679      (rec_defs @ map (fn thm => thm RS @{thm convol_expand_snd'}) fst_recs) THEN
  17.680 -  etac fold_unique_mor 1;
  17.681 +  etac ctxt fold_unique_mor 1;
  17.682  
  17.683  fun mk_ctor_induct_tac ctxt m set_mapss init_induct morEs mor_Abs Rep_invs Abs_invs Reps =
  17.684    let
  17.685 @@ -466,22 +467,22 @@
  17.686      val ks = 1 upto n;
  17.687  
  17.688      fun mk_IH_tac Rep_inv Abs_inv set_map =
  17.689 -      DETERM o EVERY' [dtac meta_mp, rtac (Rep_inv RS arg_cong RS iffD1), etac bspec,
  17.690 -        dtac set_rev_mp, rtac equalityD1, rtac set_map, etac imageE,
  17.691 -        hyp_subst_tac ctxt, rtac (Abs_inv RS @{thm ssubst_mem}), etac set_mp, atac, atac];
  17.692 +      DETERM o EVERY' [dtac ctxt meta_mp, rtac ctxt (Rep_inv RS arg_cong RS iffD1), etac ctxt bspec,
  17.693 +        dtac ctxt set_rev_mp, rtac ctxt equalityD1, rtac ctxt set_map, etac ctxt imageE,
  17.694 +        hyp_subst_tac ctxt, rtac ctxt (Abs_inv RS @{thm ssubst_mem}), etac ctxt set_mp, atac, atac];
  17.695  
  17.696      fun mk_closed_tac (k, (morE, set_maps)) =
  17.697 -      EVERY' [select_prem_tac n (dtac asm_rl) k, rtac ballI, rtac impI,
  17.698 -        rtac (mor_Abs RS morE RS arg_cong RS iffD2), atac,
  17.699 -        REPEAT_DETERM o eresolve_tac ctxt [CollectE, conjE], dtac @{thm meta_spec},
  17.700 +      EVERY' [select_prem_tac ctxt n (dtac ctxt asm_rl) k, rtac ctxt ballI, rtac ctxt impI,
  17.701 +        rtac ctxt (mor_Abs RS morE RS arg_cong RS iffD2), atac,
  17.702 +        REPEAT_DETERM o eresolve_tac ctxt [CollectE, conjE], dtac ctxt @{thm meta_spec},
  17.703          EVERY' (@{map 3} mk_IH_tac Rep_invs Abs_invs (drop m set_maps)), atac];
  17.704  
  17.705      fun mk_induct_tac (Rep, Rep_inv) =
  17.706 -      EVERY' [rtac (Rep_inv RS arg_cong RS iffD1), etac (Rep RSN (2, bspec))];
  17.707 +      EVERY' [rtac ctxt (Rep_inv RS arg_cong RS iffD1), etac ctxt (Rep RSN (2, bspec))];
  17.708    in
  17.709 -    (rtac mp THEN' rtac impI THEN'
  17.710 -    DETERM o CONJ_WRAP_GEN' (etac conjE THEN' rtac conjI) mk_induct_tac (Reps ~~ Rep_invs) THEN'
  17.711 -    rtac init_induct THEN'
  17.712 +    (rtac ctxt mp THEN' rtac ctxt impI THEN'
  17.713 +    DETERM o CONJ_WRAP_GEN' (etac ctxt conjE THEN' rtac ctxt conjI) mk_induct_tac (Reps ~~ Rep_invs) THEN'
  17.714 +    rtac ctxt init_induct THEN'
  17.715      DETERM o CONJ_WRAP' mk_closed_tac (ks ~~ (morEs ~~ set_mapss))) 1
  17.716    end;
  17.717  
  17.718 @@ -490,44 +491,44 @@
  17.719      val n = length weak_ctor_inducts;
  17.720      val ks = 1 upto n;
  17.721      fun mk_inner_induct_tac induct i =
  17.722 -      EVERY' [rtac allI, fo_rtac induct ctxt,
  17.723 -        select_prem_tac n (dtac @{thm meta_spec2}) i,
  17.724 +      EVERY' [rtac ctxt allI, fo_rtac ctxt induct,
  17.725 +        select_prem_tac ctxt n (dtac ctxt @{thm meta_spec2}) i,
  17.726          REPEAT_DETERM_N n o
  17.727 -          EVERY' [dtac meta_mp THEN_ALL_NEW Goal.norm_hhf_tac ctxt,
  17.728 -            REPEAT_DETERM o dtac @{thm meta_spec}, etac (spec RS meta_mp), atac],
  17.729 +          EVERY' [dtac ctxt meta_mp THEN_ALL_NEW Goal.norm_hhf_tac ctxt,
  17.730 +            REPEAT_DETERM o dtac ctxt @{thm meta_spec}, etac ctxt (spec RS meta_mp), atac],
  17.731          atac];
  17.732    in
  17.733 -    EVERY' [rtac rev_mp, rtac (Drule.instantiate' cTs cts ctor_induct),
  17.734 -      EVERY' (map2 mk_inner_induct_tac weak_ctor_inducts ks), rtac impI,
  17.735 +    EVERY' [rtac ctxt rev_mp, rtac ctxt (Drule.instantiate' cTs cts ctor_induct),
  17.736 +      EVERY' (map2 mk_inner_induct_tac weak_ctor_inducts ks), rtac ctxt impI,
  17.737        REPEAT_DETERM o eresolve_tac ctxt [conjE, allE],
  17.738        CONJ_WRAP' (K atac) ks] 1
  17.739    end;
  17.740  
  17.741 -fun mk_map_tac m n foldx map_comp_id map_cong0 =
  17.742 -  EVERY' [rtac @{thm ext}, rtac trans, rtac o_apply, rtac trans, rtac foldx, rtac trans,
  17.743 -    rtac o_apply,
  17.744 -    rtac trans, rtac (map_comp_id RS arg_cong), rtac trans, rtac (map_cong0 RS arg_cong),
  17.745 -    REPEAT_DETERM_N m o rtac refl,
  17.746 -    REPEAT_DETERM_N n o (EVERY' (map rtac [trans, o_apply, id_apply])),
  17.747 -    rtac sym, rtac o_apply] 1;
  17.748 +fun mk_map_tac ctxt m n foldx map_comp_id map_cong0 =
  17.749 +  EVERY' [rtac ctxt @{thm ext}, rtac ctxt trans, rtac ctxt o_apply, rtac ctxt trans, rtac ctxt foldx, rtac ctxt trans,
  17.750 +    rtac ctxt o_apply,
  17.751 +    rtac ctxt trans, rtac ctxt (map_comp_id RS arg_cong), rtac ctxt trans, rtac ctxt (map_cong0 RS arg_cong),
  17.752 +    REPEAT_DETERM_N m o rtac ctxt refl,
  17.753 +    REPEAT_DETERM_N n o (EVERY' (map (rtac ctxt) [trans, o_apply, id_apply])),
  17.754 +    rtac ctxt sym, rtac ctxt o_apply] 1;
  17.755  
  17.756  fun mk_ctor_map_unique_tac ctxt fold_unique sym_map_comps =
  17.757 -  rtac fold_unique 1 THEN
  17.758 +  rtac ctxt fold_unique 1 THEN
  17.759    unfold_thms_tac ctxt (sym_map_comps @ @{thms comp_assoc id_comp comp_id}) THEN
  17.760    ALLGOALS atac;
  17.761  
  17.762 -fun mk_set_tac foldx = EVERY' [rtac @{thm ext}, rtac trans, rtac o_apply,
  17.763 -  rtac trans, rtac foldx, rtac sym, rtac o_apply] 1;
  17.764 +fun mk_set_tac ctxt foldx = EVERY' [rtac ctxt @{thm ext}, rtac ctxt trans, rtac ctxt o_apply,
  17.765 +  rtac ctxt trans, rtac ctxt foldx, rtac ctxt sym, rtac ctxt o_apply] 1;
  17.766  
  17.767 -fun mk_ctor_set_tac set set_map set_maps =
  17.768 +fun mk_ctor_set_tac ctxt set set_map set_maps =
  17.769    let
  17.770      val n = length set_maps;
  17.771 -    fun mk_UN thm = rtac (thm RS @{thm arg_cong[of _ _ Union]} RS trans) THEN'
  17.772 -      rtac @{thm Union_image_eq};
  17.773 +    fun mk_UN thm = rtac ctxt (thm RS @{thm arg_cong[of _ _ Union]} RS trans) THEN'
  17.774 +      rtac ctxt @{thm Union_image_eq};
  17.775    in
  17.776 -    EVERY' [rtac (set RS @{thm comp_eq_dest} RS trans), rtac Un_cong,
  17.777 -      rtac (trans OF [set_map, trans_fun_cong_image_id_id_apply]),
  17.778 -      REPEAT_DETERM_N (n - 1) o rtac Un_cong,
  17.779 +    EVERY' [rtac ctxt (set RS @{thm comp_eq_dest} RS trans), rtac ctxt Un_cong,
  17.780 +      rtac ctxt (trans OF [set_map, trans_fun_cong_image_id_id_apply]),
  17.781 +      REPEAT_DETERM_N (n - 1) o rtac ctxt Un_cong,
  17.782        EVERY' (map mk_UN set_maps)] 1
  17.783    end;
  17.784  
  17.785 @@ -535,17 +536,17 @@
  17.786    let
  17.787      val n = length ctor_maps;
  17.788  
  17.789 -    fun useIH set_nat = EVERY' [rtac trans, rtac @{thm image_UN}, rtac trans, rtac @{thm SUP_cong},
  17.790 -      rtac refl, Goal.assume_rule_tac ctxt, rtac sym, rtac trans, rtac @{thm SUP_cong},
  17.791 -      rtac set_nat, rtac refl, rtac @{thm UN_simps(10)}];
  17.792 +    fun useIH set_nat = EVERY' [rtac ctxt trans, rtac ctxt @{thm image_UN}, rtac ctxt trans, rtac ctxt @{thm SUP_cong},
  17.793 +      rtac ctxt refl, Goal.assume_rule_tac ctxt, rtac ctxt sym, rtac ctxt trans, rtac ctxt @{thm SUP_cong},
  17.794 +      rtac ctxt set_nat, rtac ctxt refl, rtac ctxt @{thm UN_simps(10)}];
  17.795  
  17.796      fun mk_set_nat cset ctor_map ctor_set set_nats =
  17.797 -      EVERY' [rtac trans, rtac @{thm image_cong}, rtac ctor_set, rtac refl, rtac sym,
  17.798 -        rtac (trans OF [ctor_map RS cterm_instantiate_pos [NONE, NONE, SOME cset] arg_cong,
  17.799 +      EVERY' [rtac ctxt trans, rtac ctxt @{thm image_cong}, rtac ctxt ctor_set, rtac ctxt refl, rtac ctxt sym,
  17.800 +        rtac ctxt (trans OF [ctor_map RS cterm_instantiate_pos [NONE, NONE, SOME cset] arg_cong,
  17.801            ctor_set RS trans]),
  17.802 -        rtac sym, EVERY' (map rtac [trans, @{thm image_Un}, Un_cong]),
  17.803 -        rtac sym, rtac (nth set_nats (i - 1)),
  17.804 -        REPEAT_DETERM_N (n - 1) o EVERY' (map rtac [trans, @{thm image_Un}, Un_cong]),
  17.805 +        rtac ctxt sym, EVERY' (map (rtac ctxt) [trans, @{thm image_Un}, Un_cong]),
  17.806 +        rtac ctxt sym, rtac ctxt (nth set_nats (i - 1)),
  17.807 +        REPEAT_DETERM_N (n - 1) o EVERY' (map (rtac ctxt) [trans, @{thm image_Un}, Un_cong]),
  17.808          EVERY' (map useIH (drop m set_nats))];
  17.809    in
  17.810      (induct_tac THEN' EVERY' (@{map 4} mk_set_nat csets ctor_maps ctor_sets set_mapss)) 1
  17.811 @@ -555,13 +556,13 @@
  17.812    let
  17.813      val n = length ctor_sets;
  17.814  
  17.815 -    fun useIH set_bd = EVERY' [rtac @{thm UNION_Cinfinite_bound}, rtac set_bd, rtac ballI,
  17.816 -      Goal.assume_rule_tac ctxt, rtac bd_Cinfinite];
  17.817 +    fun useIH set_bd = EVERY' [rtac ctxt @{thm UNION_Cinfinite_bound}, rtac ctxt set_bd, rtac ctxt ballI,
  17.818 +      Goal.assume_rule_tac ctxt, rtac ctxt bd_Cinfinite];
  17.819  
  17.820      fun mk_set_nat ctor_set set_bds =
  17.821 -      EVERY' [rtac @{thm ordIso_ordLeq_trans}, rtac @{thm card_of_ordIso_subst}, rtac ctor_set,
  17.822 -        rtac (bd_Cinfinite RSN (3, @{thm Un_Cinfinite_bound})), rtac (nth set_bds (i - 1)),
  17.823 -        REPEAT_DETERM_N (n - 1) o rtac (bd_Cinfinite RSN (3, @{thm Un_Cinfinite_bound})),
  17.824 +      EVERY' [rtac ctxt @{thm ordIso_ordLeq_trans}, rtac ctxt @{thm card_of_ordIso_subst}, rtac ctxt ctor_set,
  17.825 +        rtac ctxt (bd_Cinfinite RSN (3, @{thm Un_Cinfinite_bound})), rtac ctxt (nth set_bds (i - 1)),
  17.826 +        REPEAT_DETERM_N (n - 1) o rtac ctxt (bd_Cinfinite RSN (3, @{thm Un_Cinfinite_bound})),
  17.827          EVERY' (map useIH (drop m set_bds))];
  17.828    in
  17.829      (induct_tac THEN' EVERY' (map2 mk_set_nat ctor_sets set_bdss)) 1
  17.830 @@ -569,72 +570,72 @@
  17.831  
  17.832  fun mk_mcong_tac ctxt induct_tac set_setsss map_cong0s ctor_maps =
  17.833    let
  17.834 -    fun use_asm thm = EVERY' [etac bspec, etac set_rev_mp, rtac thm];
  17.835 +    fun use_asm thm = EVERY' [etac ctxt bspec, etac ctxt set_rev_mp, rtac ctxt thm];
  17.836  
  17.837 -    fun useIH set_sets = EVERY' [rtac mp, Goal.assume_rule_tac ctxt,
  17.838 +    fun useIH set_sets = EVERY' [rtac ctxt mp, Goal.assume_rule_tac ctxt,
  17.839        CONJ_WRAP' (fn thm =>
  17.840 -        EVERY' [rtac ballI, etac bspec, etac set_rev_mp, etac thm]) set_sets];
  17.841 +        EVERY' [rtac ctxt ballI, etac ctxt bspec, etac ctxt set_rev_mp, etac ctxt thm]) set_sets];
  17.842  
  17.843      fun mk_map_cong0 ctor_map map_cong0 set_setss =
  17.844 -      EVERY' [rtac impI, REPEAT_DETERM o etac conjE,
  17.845 -        rtac trans, rtac ctor_map, rtac trans, rtac (map_cong0 RS arg_cong),
  17.846 +      EVERY' [rtac ctxt impI, REPEAT_DETERM o etac ctxt conjE,
  17.847 +        rtac ctxt trans, rtac ctxt ctor_map, rtac ctxt trans, rtac ctxt (map_cong0 RS arg_cong),
  17.848          EVERY' (map use_asm (map hd set_setss)),
  17.849          EVERY' (map useIH (transpose (map tl set_setss))),
  17.850 -        rtac sym, rtac ctor_map];
  17.851 +        rtac ctxt sym, rtac ctxt ctor_map];
  17.852    in
  17.853      (induct_tac THEN' EVERY' (@{map 3} mk_map_cong0 ctor_maps map_cong0s set_setsss)) 1
  17.854    end;
  17.855  
  17.856  fun mk_le_rel_OO_tac ctxt m induct ctor_nchotomys ctor_Irels rel_mono_strong0s le_rel_OOs =
  17.857 -  EVERY' (rtac induct ::
  17.858 +  EVERY' (rtac ctxt induct ::
  17.859    @{map 4} (fn nchotomy => fn Irel => fn rel_mono => fn le_rel_OO =>
  17.860 -    EVERY' [rtac impI, etac (nchotomy RS @{thm nchotomy_relcomppE}),
  17.861 -      REPEAT_DETERM_N 2 o dtac (Irel RS iffD1), rtac (Irel RS iffD2),
  17.862 -      rtac rel_mono, rtac (le_rel_OO RS @{thm predicate2D}),
  17.863 -      rtac @{thm relcomppI}, atac, atac,
  17.864 -      REPEAT_DETERM_N m o EVERY' [rtac ballI, rtac ballI, rtac impI, atac],
  17.865 +    EVERY' [rtac ctxt impI, etac ctxt (nchotomy RS @{thm nchotomy_relcomppE}),
  17.866 +      REPEAT_DETERM_N 2 o dtac ctxt (Irel RS iffD1), rtac ctxt (Irel RS iffD2),
  17.867 +      rtac ctxt rel_mono, rtac ctxt (le_rel_OO RS @{thm predicate2D}),
  17.868 +      rtac ctxt @{thm relcomppI}, atac, atac,
  17.869 +      REPEAT_DETERM_N m o EVERY' [rtac ctxt ballI, rtac ctxt ballI, rtac ctxt impI, atac],
  17.870        REPEAT_DETERM_N (length le_rel_OOs) o
  17.871 -        EVERY' [rtac ballI, rtac ballI, Goal.assume_rule_tac ctxt]])
  17.872 +        EVERY' [rtac ctxt ballI, rtac ctxt ballI, Goal.assume_rule_tac ctxt]])
  17.873    ctor_nchotomys ctor_Irels rel_mono_strong0s le_rel_OOs) 1;
  17.874  
  17.875  (* BNF tactics *)
  17.876  
  17.877 -fun mk_map_id0_tac map_id0s unique =
  17.878 -  (rtac sym THEN' rtac unique THEN'
  17.879 +fun mk_map_id0_tac ctxt map_id0s unique =
  17.880 +  (rtac ctxt sym THEN' rtac ctxt unique THEN'
  17.881    EVERY' (map (fn thm =>
  17.882 -    EVERY' [rtac trans, rtac @{thm id_comp}, rtac trans, rtac sym, rtac @{thm comp_id},
  17.883 -      rtac (thm RS sym RS arg_cong)]) map_id0s)) 1;
  17.884 +    EVERY' [rtac ctxt trans, rtac ctxt @{thm id_comp}, rtac ctxt trans, rtac ctxt sym, rtac ctxt @{thm comp_id},
  17.885 +      rtac ctxt (thm RS sym RS arg_cong)]) map_id0s)) 1;
  17.886  
  17.887 -fun mk_map_comp0_tac map_comp0s ctor_maps unique iplus1 =
  17.888 +fun mk_map_comp0_tac ctxt map_comp0s ctor_maps unique iplus1 =
  17.889    let
  17.890      val i = iplus1 - 1;
  17.891      val unique' = Thm.permute_prems 0 i unique;
  17.892      val map_comp0s' = drop i map_comp0s @ take i map_comp0s;
  17.893      val ctor_maps' = drop i ctor_maps @ take i ctor_maps;
  17.894      fun mk_comp comp simp =
  17.895 -      EVERY' [rtac @{thm ext}, rtac trans, rtac o_apply, rtac trans, rtac o_apply,
  17.896 -        rtac trans, rtac (simp RS arg_cong), rtac trans, rtac simp,
  17.897 -        rtac trans, rtac (comp RS arg_cong), rtac sym, rtac o_apply];
  17.898 +      EVERY' [rtac ctxt @{thm ext}, rtac ctxt trans, rtac ctxt o_apply, rtac ctxt trans, rtac ctxt o_apply,
  17.899 +        rtac ctxt trans, rtac ctxt (simp RS arg_cong), rtac ctxt trans, rtac ctxt simp,
  17.900 +        rtac ctxt trans, rtac ctxt (comp RS arg_cong), rtac ctxt sym, rtac ctxt o_apply];
  17.901    in
  17.902 -    (rtac sym THEN' rtac unique' THEN' EVERY' (map2 mk_comp map_comp0s' ctor_maps')) 1
  17.903 +    (rtac ctxt sym THEN' rtac ctxt unique' THEN' EVERY' (map2 mk_comp map_comp0s' ctor_maps')) 1
  17.904    end;
  17.905  
  17.906 -fun mk_set_map0_tac set_nat =
  17.907 -  EVERY' (map rtac [@{thm ext}, trans, o_apply, sym, trans, o_apply, set_nat]) 1;
  17.908 +fun mk_set_map0_tac ctxt set_nat =
  17.909 +  EVERY' (map (rtac ctxt) [@{thm ext}, trans, o_apply, sym, trans, o_apply, set_nat]) 1;
  17.910  
  17.911 -fun mk_bd_card_order_tac bd_card_orders =
  17.912 -  CONJ_WRAP_GEN' (rtac @{thm card_order_csum}) rtac bd_card_orders 1;
  17.913 +fun mk_bd_card_order_tac ctxt bd_card_orders =
  17.914 +  CONJ_WRAP_GEN' (rtac ctxt @{thm card_order_csum}) (rtac ctxt) bd_card_orders 1;
  17.915  
  17.916  fun mk_wit_tac ctxt n ctor_set wit =
  17.917    REPEAT_DETERM (atac 1 ORELSE
  17.918 -    EVERY' [dtac set_rev_mp, rtac equalityD1, resolve_tac ctxt ctor_set,
  17.919 +    EVERY' [dtac ctxt set_rev_mp, rtac ctxt equalityD1, resolve_tac ctxt ctor_set,
  17.920      REPEAT_DETERM o
  17.921 -      (TRY o REPEAT_DETERM o etac UnE THEN' TRY o etac @{thm UN_E} THEN'
  17.922 +      (TRY o REPEAT_DETERM o etac ctxt UnE THEN' TRY o etac ctxt @{thm UN_E} THEN'
  17.923          (eresolve_tac ctxt wit ORELSE'
  17.924          (dresolve_tac ctxt wit THEN'
  17.925 -          (etac FalseE ORELSE'
  17.926 -          EVERY' [hyp_subst_tac ctxt, dtac set_rev_mp, rtac equalityD1, resolve_tac ctxt ctor_set,
  17.927 -            REPEAT_DETERM_N n o etac UnE]))))] 1);
  17.928 +          (etac ctxt FalseE ORELSE'
  17.929 +          EVERY' [hyp_subst_tac ctxt, dtac ctxt set_rev_mp, rtac ctxt equalityD1, resolve_tac ctxt ctor_set,
  17.930 +            REPEAT_DETERM_N n o etac ctxt UnE]))))] 1);
  17.931  
  17.932  fun mk_ctor_rel_tac ctxt in_Irels i in_rel map_comp0 map_cong0 ctor_map ctor_sets ctor_inject
  17.933    ctor_dtor set_map0s ctor_set_incls ctor_set_set_inclss =
  17.934 @@ -647,91 +648,91 @@
  17.935      val le_arg_cong_ctor_dtor = ctor_dtor RS arg_cong RS ord_eq_le_trans;
  17.936      val eq_arg_cong_ctor_dtor = ctor_dtor RS arg_cong RS trans;
  17.937      val if_tac =
  17.938 -      EVERY' [dtac (in_Irel RS iffD1), REPEAT_DETERM o eresolve_tac ctxt [exE, conjE, CollectE],
  17.939 -        rtac (in_rel RS iffD2), rtac exI, rtac conjI, rtac CollectI,
  17.940 +      EVERY' [dtac ctxt (in_Irel RS iffD1), REPEAT_DETERM o eresolve_tac ctxt [exE, conjE, CollectE],
  17.941 +        rtac ctxt (in_rel RS iffD2), rtac ctxt exI, rtac ctxt conjI, rtac ctxt CollectI,
  17.942          EVERY' (map2 (fn set_map0 => fn ctor_set_incl =>
  17.943 -          EVERY' [rtac conjI, rtac ord_eq_le_trans, rtac set_map0,
  17.944 -            rtac ord_eq_le_trans, rtac trans_fun_cong_image_id_id_apply,
  17.945 -            rtac (ctor_set_incl RS subset_trans), etac le_arg_cong_ctor_dtor])
  17.946 +          EVERY' [rtac ctxt conjI, rtac ctxt ord_eq_le_trans, rtac ctxt set_map0,
  17.947 +            rtac ctxt ord_eq_le_trans, rtac ctxt trans_fun_cong_image_id_id_apply,
  17.948 +            rtac ctxt (ctor_set_incl RS subset_trans), etac ctxt le_arg_cong_ctor_dtor])
  17.949          passive_set_map0s ctor_set_incls),
  17.950          CONJ_WRAP' (fn (in_Irel, (set_map0, ctor_set_set_incls)) =>
  17.951 -          EVERY' [rtac ord_eq_le_trans, rtac set_map0, rtac @{thm image_subsetI}, rtac CollectI,
  17.952 -            rtac @{thm case_prodI}, rtac (in_Irel RS iffD2), rtac exI, rtac conjI, rtac CollectI,
  17.953 +          EVERY' [rtac ctxt ord_eq_le_trans, rtac ctxt set_map0, rtac ctxt @{thm image_subsetI}, rtac ctxt CollectI,
  17.954 +            rtac ctxt @{thm case_prodI}, rtac ctxt (in_Irel RS iffD2), rtac ctxt exI, rtac ctxt conjI, rtac ctxt CollectI,
  17.955              CONJ_WRAP' (fn thm =>
  17.956 -              EVERY' (map etac [thm RS subset_trans, le_arg_cong_ctor_dtor]))
  17.957 +              EVERY' (map (etac ctxt) [thm RS subset_trans, le_arg_cong_ctor_dtor]))
  17.958              ctor_set_set_incls,
  17.959 -            rtac conjI, rtac refl, rtac refl])
  17.960 +            rtac ctxt conjI, rtac ctxt refl, rtac ctxt refl])
  17.961          (in_Irels ~~ (active_set_map0s ~~ ctor_set_set_inclss)),
  17.962          CONJ_WRAP' (fn conv =>
  17.963 -          EVERY' [rtac trans, rtac map_comp0, rtac trans, rtac map_cong0,
  17.964 -          REPEAT_DETERM_N m o rtac @{thm fun_cong[OF comp_id]},
  17.965 -          REPEAT_DETERM_N n o EVERY' (map rtac [trans, o_apply, conv]),
  17.966 -          rtac (ctor_inject RS iffD1), rtac trans, rtac sym, rtac ctor_map,
  17.967 -          etac eq_arg_cong_ctor_dtor])
  17.968 +          EVERY' [rtac ctxt trans, rtac ctxt map_comp0, rtac ctxt trans, rtac ctxt map_cong0,
  17.969 +          REPEAT_DETERM_N m o rtac ctxt @{thm fun_cong[OF comp_id]},
  17.970 +          REPEAT_DETERM_N n o EVERY' (map (rtac ctxt) [trans, o_apply, conv]),
  17.971 +          rtac ctxt (ctor_inject RS iffD1), rtac ctxt trans, rtac ctxt sym, rtac ctxt ctor_map,
  17.972 +          etac ctxt eq_arg_cong_ctor_dtor])
  17.973          fst_snd_convs];
  17.974      val only_if_tac =
  17.975 -      EVERY' [dtac (in_rel RS iffD1), REPEAT_DETERM o eresolve_tac ctxt [exE, conjE, CollectE],
  17.976 -        rtac (in_Irel RS iffD2), rtac exI, rtac conjI, rtac CollectI,
  17.977 +      EVERY' [dtac ctxt (in_rel RS iffD1), REPEAT_DETERM o eresolve_tac ctxt [exE, conjE, CollectE],
  17.978 +        rtac ctxt (in_Irel RS iffD2), rtac ctxt exI, rtac ctxt conjI, rtac ctxt CollectI,
  17.979          CONJ_WRAP' (fn (ctor_set, passive_set_map0) =>
  17.980 -          EVERY' [rtac ord_eq_le_trans, rtac ctor_set, rtac @{thm Un_least},
  17.981 -            rtac ord_eq_le_trans, rtac @{thm box_equals[OF _ refl]},
  17.982 -            rtac passive_set_map0, rtac trans_fun_cong_image_id_id_apply, atac,
  17.983 -            CONJ_WRAP_GEN' (rtac (Thm.permute_prems 0 1 @{thm Un_least}))
  17.984 -              (fn (active_set_map0, in_Irel) => EVERY' [rtac ord_eq_le_trans,
  17.985 -                rtac @{thm SUP_cong[OF _ refl]}, rtac active_set_map0, rtac @{thm UN_least},
  17.986 -                dtac set_rev_mp, etac @{thm image_mono}, etac imageE,
  17.987 -                dtac @{thm ssubst_mem[OF pair_collapse]},
  17.988 +          EVERY' [rtac ctxt ord_eq_le_trans, rtac ctxt ctor_set, rtac ctxt @{thm Un_least},
  17.989 +            rtac ctxt ord_eq_le_trans, rtac ctxt @{thm box_equals[OF _ refl]},
  17.990 +            rtac ctxt passive_set_map0, rtac ctxt trans_fun_cong_image_id_id_apply, atac,
  17.991 +            CONJ_WRAP_GEN' (rtac ctxt (Thm.permute_prems 0 1 @{thm Un_least}))
  17.992 +              (fn (active_set_map0, in_Irel) => EVERY' [rtac ctxt ord_eq_le_trans,
  17.993 +                rtac ctxt @{thm SUP_cong[OF _ refl]}, rtac ctxt active_set_map0, rtac ctxt @{thm UN_least},
  17.994 +                dtac ctxt set_rev_mp, etac ctxt @{thm image_mono}, etac ctxt imageE,
  17.995 +                dtac ctxt @{thm ssubst_mem[OF pair_collapse]},
  17.996                  REPEAT_DETERM o eresolve_tac ctxt (CollectE :: conjE ::
  17.997                    @{thms case_prodE iffD1[OF prod.inject, elim_format]}),
  17.998                  hyp_subst_tac ctxt,
  17.999 -                dtac (in_Irel RS iffD1), dtac @{thm someI_ex}, REPEAT_DETERM o etac conjE,
 17.1000 +                dtac ctxt (in_Irel RS iffD1), dtac ctxt @{thm someI_ex}, REPEAT_DETERM o etac ctxt conjE,
 17.1001                  REPEAT_DETERM o eresolve_tac ctxt [CollectE, conjE], atac])
 17.1002              (rev (active_set_map0s ~~ in_Irels))])
 17.1003          (ctor_sets ~~ passive_set_map0s),
 17.1004 -        rtac conjI,
 17.1005 -        REPEAT_DETERM_N 2 o EVERY' [rtac trans, rtac ctor_map, rtac (ctor_inject RS iffD2),
 17.1006 -          rtac trans, rtac map_comp0, rtac trans, rtac map_cong0,
 17.1007 -          REPEAT_DETERM_N m o rtac @{thm fun_cong[OF comp_id]},
 17.1008 -          EVERY' (map (fn in_Irel => EVERY' [rtac trans, rtac o_apply, dtac set_rev_mp, atac,
 17.1009 -            dtac @{thm ssubst_mem[OF pair_collapse]},
 17.1010 +        rtac ctxt conjI,
 17.1011 +        REPEAT_DETERM_N 2 o EVERY' [rtac ctxt trans, rtac ctxt ctor_map, rtac ctxt (ctor_inject RS iffD2),
 17.1012 +          rtac ctxt trans, rtac ctxt map_comp0, rtac ctxt trans, rtac ctxt map_cong0,
 17.1013 +          REPEAT_DETERM_N m o rtac ctxt @{thm fun_cong[OF comp_id]},
 17.1014 +          EVERY' (map (fn in_Irel => EVERY' [rtac ctxt trans, rtac ctxt o_apply, dtac ctxt set_rev_mp, atac,
 17.1015 +            dtac ctxt @{thm ssubst_mem[OF pair_collapse]},
 17.1016              REPEAT_DETERM o eresolve_tac ctxt (CollectE :: conjE ::
 17.1017                @{thms case_prodE iffD1[OF prod.inject, elim_format]}),
 17.1018              hyp_subst_tac ctxt,
 17.1019 -            dtac (in_Irel RS iffD1), dtac @{thm someI_ex}, REPEAT_DETERM o etac conjE, atac])
 17.1020 +            dtac ctxt (in_Irel RS iffD1), dtac ctxt @{thm someI_ex}, REPEAT_DETERM o etac ctxt conjE, atac])
 17.1021            in_Irels),
 17.1022            atac]]
 17.1023    in
 17.1024 -    EVERY' [rtac iffI, if_tac, only_if_tac] 1
 17.1025 +    EVERY' [rtac ctxt iffI, if_tac, only_if_tac] 1
 17.1026    end;
 17.1027  
 17.1028  fun mk_ctor_rec_transfer_tac ctxt n m ctor_rec_defs ctor_fold_transfers pre_T_map_transfers
 17.1029      ctor_rels =
 17.1030    CONJ_WRAP (fn (ctor_rec_def, ctor_fold_transfer) =>
 17.1031 -      REPEAT_DETERM (HEADGOAL (rtac rel_funI)) THEN
 17.1032 +      REPEAT_DETERM (HEADGOAL (rtac ctxt rel_funI)) THEN
 17.1033        unfold_thms_tac ctxt [ctor_rec_def, o_apply] THEN
 17.1034 -      HEADGOAL (rtac @{thm rel_funD[OF snd_transfer]} THEN'
 17.1035 -        etac (mk_rel_funDN_rotated (n + 1) ctor_fold_transfer) THEN'
 17.1036 +      HEADGOAL (rtac ctxt @{thm rel_funD[OF snd_transfer]} THEN'
 17.1037 +        etac ctxt (mk_rel_funDN_rotated (n + 1) ctor_fold_transfer) THEN'
 17.1038          EVERY' (map2 (fn pre_T_map_transfer => fn ctor_rel =>
 17.1039 -          etac (mk_rel_funDN_rotated 2 @{thm convol_transfer}) THEN'
 17.1040 -          rtac (mk_rel_funDN_rotated 2 @{thm comp_transfer}) THEN'
 17.1041 -          rtac (mk_rel_funDN (m + n) pre_T_map_transfer) THEN'
 17.1042 -          REPEAT_DETERM_N m o rtac @{thm id_transfer} THEN'
 17.1043 -          REPEAT_DETERM o rtac @{thm fst_transfer} THEN'
 17.1044 -          rtac rel_funI THEN'
 17.1045 -          etac (ctor_rel RS iffD2)) pre_T_map_transfers ctor_rels)))
 17.1046 +          etac ctxt (mk_rel_funDN_rotated 2 @{thm convol_transfer}) THEN'
 17.1047 +          rtac ctxt (mk_rel_funDN_rotated 2 @{thm comp_transfer}) THEN'
 17.1048 +          rtac ctxt (mk_rel_funDN (m + n) pre_T_map_transfer) THEN'
 17.1049 +          REPEAT_DETERM_N m o rtac ctxt @{thm id_transfer} THEN'
 17.1050 +          REPEAT_DETERM o rtac ctxt @{thm fst_transfer} THEN'
 17.1051 +          rtac ctxt rel_funI THEN'
 17.1052 +          etac ctxt (ctor_rel RS iffD2)) pre_T_map_transfers ctor_rels)))
 17.1053      (ctor_rec_defs ~~ ctor_fold_transfers);
 17.1054  
 17.1055  fun mk_rel_induct_tac ctxt IHs m ctor_induct2 ks ctor_rels rel_mono_strong0s =
 17.1056    let val n = length ks;
 17.1057    in
 17.1058      unfold_tac ctxt @{thms le_fun_def le_bool_def all_simps(1,2)[symmetric]} THEN
 17.1059 -    EVERY' [REPEAT_DETERM o rtac allI, rtac ctor_induct2,
 17.1060 +    EVERY' [REPEAT_DETERM o rtac ctxt allI, rtac ctxt ctor_induct2,
 17.1061        EVERY' (@{map 3} (fn IH => fn ctor_rel => fn rel_mono_strong0 =>
 17.1062 -        EVERY' [rtac impI, dtac (ctor_rel RS iffD1), rtac (IH RS @{thm spec2} RS mp),
 17.1063 -          etac rel_mono_strong0,
 17.1064 -          REPEAT_DETERM_N m o rtac @{thm ballI[OF ballI[OF imp_refl]]},
 17.1065 +        EVERY' [rtac ctxt impI, dtac ctxt (ctor_rel RS iffD1), rtac ctxt (IH RS @{thm spec2} RS mp),
 17.1066 +          etac ctxt rel_mono_strong0,
 17.1067 +          REPEAT_DETERM_N m o rtac ctxt @{thm ballI[OF ballI[OF imp_refl]]},
 17.1068            EVERY' (map (fn j =>
 17.1069 -            EVERY' [select_prem_tac n (dtac asm_rl) j, rtac @{thm ballI[OF ballI]},
 17.1070 +            EVERY' [select_prem_tac ctxt n (dtac ctxt asm_rl) j, rtac ctxt @{thm ballI[OF ballI]},
 17.1071                Goal.assume_rule_tac ctxt]) ks)])
 17.1072        IHs ctor_rels rel_mono_strong0s)] 1
 17.1073    end;
 17.1074 @@ -744,14 +745,14 @@
 17.1075        @{thms rel_fun_def_butlast all_conj_distrib[symmetric] imp_conjR[symmetric]} THEN
 17.1076      unfold_thms_tac ctxt @{thms rel_fun_iff_leq_vimage2p} THEN
 17.1077      HEADGOAL (EVERY'
 17.1078 -      [REPEAT_DETERM o resolve_tac ctxt [allI, impI], rtac ctor_rel_induct,
 17.1079 +      [REPEAT_DETERM o resolve_tac ctxt [allI, impI], rtac ctxt ctor_rel_induct,
 17.1080        EVERY' (map (fn map_transfer => EVERY'
 17.1081          [REPEAT_DETERM o resolve_tac ctxt [allI, impI, @{thm vimage2pI}],
 17.1082          SELECT_GOAL (unfold_thms_tac ctxt folds),
 17.1083 -        etac @{thm predicate2D_vimage2p},
 17.1084 -        rtac (funpow (m + n + 1) (fn thm => thm RS rel_funD) map_transfer),
 17.1085 -        REPEAT_DETERM_N m o rtac @{thm id_transfer},
 17.1086 -        REPEAT_DETERM_N n o rtac @{thm vimage2p_rel_fun},
 17.1087 +        etac ctxt @{thm predicate2D_vimage2p},
 17.1088 +        rtac ctxt (funpow (m + n + 1) (fn thm => thm RS rel_funD) map_transfer),
 17.1089 +        REPEAT_DETERM_N m o rtac ctxt @{thm id_transfer},
 17.1090 +        REPEAT_DETERM_N n o rtac ctxt @{thm vimage2p_rel_fun},
 17.1091          atac])
 17.1092        map_transfers)])
 17.1093    end;
    18.1 --- a/src/HOL/Tools/BNF/bnf_tactics.ML	Thu Jul 16 10:48:20 2015 +0200
    18.2 +++ b/src/HOL/Tools/BNF/bnf_tactics.ML	Thu Jul 16 12:23:22 2015 +0200
    18.3 @@ -10,12 +10,12 @@
    18.4  sig
    18.5    include CTR_SUGAR_GENERAL_TACTICS
    18.6  
    18.7 -  val fo_rtac: thm -> Proof.context -> int -> tactic
    18.8 +  val fo_rtac: Proof.context -> thm -> int -> tactic
    18.9    val subst_tac: Proof.context -> int list option -> thm list -> int -> tactic
   18.10    val subst_asm_tac: Proof.context -> int list option -> thm list -> int -> tactic
   18.11  
   18.12 -  val mk_rotate_eq_tac: (int -> tactic) -> thm -> thm -> thm -> thm -> ''a list -> ''a list ->
   18.13 -    int -> tactic
   18.14 +  val mk_rotate_eq_tac: Proof.context -> (int -> tactic) -> thm -> thm -> thm -> thm -> ''a list ->
   18.15 +    ''a list -> int -> tactic
   18.16  
   18.17    val mk_pointfree: Proof.context -> thm -> thm
   18.18  
   18.19 @@ -24,7 +24,7 @@
   18.20  
   18.21    val mk_map_comp_id_tac: Proof.context -> thm -> tactic
   18.22    val mk_map_cong0_tac: Proof.context -> int -> thm -> tactic
   18.23 -  val mk_map_cong0L_tac: int -> thm -> thm -> tactic
   18.24 +  val mk_map_cong0L_tac: Proof.context -> int -> thm -> thm -> tactic
   18.25  end;
   18.26  
   18.27  structure BNF_Tactics : BNF_TACTICS =
   18.28 @@ -34,14 +34,14 @@
   18.29  open BNF_Util
   18.30  
   18.31  (*stolen from Christian Urban's Cookbook (and adapted slightly)*)
   18.32 -fun fo_rtac thm = Subgoal.FOCUS (fn {concl, ...} =>
   18.33 +fun fo_rtac ctxt thm = Subgoal.FOCUS (fn {concl, context = ctxt, ...} =>
   18.34    let
   18.35      val concl_pat = Drule.strip_imp_concl (Thm.cprop_of thm)
   18.36      val insts = Thm.first_order_match (concl_pat, concl)
   18.37    in
   18.38 -    rtac (Drule.instantiate_normalize insts thm) 1
   18.39 +    rtac ctxt (Drule.instantiate_normalize insts thm) 1
   18.40    end
   18.41 -  handle Pattern.MATCH => no_tac);
   18.42 +  handle Pattern.MATCH => no_tac) ctxt;
   18.43  
   18.44  (*unlike "unfold_thms_tac", it succeed when the RHS contains schematic variables not in the LHS*)
   18.45  fun subst_tac ctxt = EqSubst.eqsubst_tac ctxt o the_default [0];
   18.46 @@ -54,16 +54,16 @@
   18.47    |> apply2 (dest_comb #> apsnd (dest_comb #> fst) #> HOLogic.mk_comp)
   18.48    |> mk_Trueprop_eq
   18.49    |> (fn goal => Goal.prove_sorry ctxt [] [] goal
   18.50 -    (K (rtac @{thm ext} 1 THEN
   18.51 +    (K (rtac ctxt @{thm ext} 1 THEN
   18.52          unfold_thms_tac ctxt ([o_apply, unfold_thms ctxt [o_apply] (mk_sym thm)]) THEN
   18.53 -        rtac refl 1)))
   18.54 +        rtac ctxt refl 1)))
   18.55    |> Thm.close_derivation;
   18.56  
   18.57  
   18.58  (* Theorems for open typedefs with UNIV as representing set *)
   18.59  
   18.60  fun mk_Abs_inj_thm inj = inj OF (replicate 2 UNIV_I);
   18.61 -fun mk_Abs_bij_thm ctxt Abs_inj_thm surj = rule_by_tactic ctxt ((rtac surj THEN' etac exI) 1)
   18.62 +fun mk_Abs_bij_thm ctxt Abs_inj_thm surj = rule_by_tactic ctxt ((rtac ctxt surj THEN' etac ctxt exI) 1)
   18.63    (Abs_inj_thm RS @{thm bijI'});
   18.64  
   18.65  
   18.66 @@ -71,20 +71,20 @@
   18.67  (* General tactic generators *)
   18.68  
   18.69  (*applies assoc rule to the lhs of an equation as long as possible*)
   18.70 -fun mk_flatten_assoc_tac refl_tac trans assoc cong = rtac trans 1 THEN
   18.71 -  REPEAT_DETERM (CHANGED ((FIRST' [rtac trans THEN' rtac assoc, rtac cong THEN' refl_tac]) 1)) THEN
   18.72 +fun mk_flatten_assoc_tac ctxt refl_tac trans assoc cong = rtac ctxt trans 1 THEN
   18.73 +  REPEAT_DETERM (CHANGED ((FIRST' [rtac ctxt trans THEN' rtac ctxt assoc, rtac ctxt cong THEN' refl_tac]) 1)) THEN
   18.74    refl_tac 1;
   18.75  
   18.76  (*proves two sides of an equation to be equal assuming both are flattened and rhs can be obtained
   18.77  from lhs by the given permutation of monoms*)
   18.78 -fun mk_rotate_eq_tac refl_tac trans assoc com cong =
   18.79 +fun mk_rotate_eq_tac ctxt refl_tac trans assoc com cong =
   18.80    let
   18.81      fun gen_tac [] [] = K all_tac
   18.82        | gen_tac [x] [y] = if x = y then refl_tac else error "mk_rotate_eq_tac: different lists"
   18.83        | gen_tac (x :: xs) (y :: ys) = if x = y
   18.84 -        then rtac cong THEN' refl_tac THEN' gen_tac xs ys
   18.85 -        else rtac trans THEN' rtac com THEN'
   18.86 -          K (mk_flatten_assoc_tac refl_tac trans assoc cong) THEN'
   18.87 +        then rtac ctxt cong THEN' refl_tac THEN' gen_tac xs ys
   18.88 +        else rtac ctxt trans THEN' rtac ctxt com THEN'
   18.89 +          K (mk_flatten_assoc_tac ctxt refl_tac trans assoc cong) THEN'
   18.90            gen_tac (xs @ [x]) (y :: ys)
   18.91        | gen_tac _ _ = error "mk_rotate_eq_tac: different lists";
   18.92    in
   18.93 @@ -92,15 +92,15 @@
   18.94    end;
   18.95  
   18.96  fun mk_map_comp_id_tac ctxt map_comp0 =
   18.97 -  (rtac trans THEN' rtac map_comp0 THEN' K (unfold_thms_tac ctxt @{thms comp_id}) THEN' rtac refl) 1;
   18.98 +  (rtac ctxt trans THEN' rtac ctxt map_comp0 THEN' K (unfold_thms_tac ctxt @{thms comp_id}) THEN' rtac ctxt refl) 1;
   18.99  
  18.100  fun mk_map_cong0_tac ctxt m map_cong0 =
  18.101 -  EVERY' [rtac mp, rtac map_cong0,
  18.102 -    CONJ_WRAP' (K (rtac ballI THEN' Goal.assume_rule_tac ctxt)) (1 upto m)] 1;
  18.103 +  EVERY' [rtac ctxt mp, rtac ctxt map_cong0,
  18.104 +    CONJ_WRAP' (K (rtac ctxt ballI THEN' Goal.assume_rule_tac ctxt)) (1 upto m)] 1;
  18.105  
  18.106 -fun mk_map_cong0L_tac passive map_cong0 map_id =
  18.107 -  (rtac trans THEN' rtac map_cong0 THEN' EVERY' (replicate passive (rtac refl))) 1 THEN
  18.108 -  REPEAT_DETERM (EVERY' [rtac trans, etac bspec, atac, rtac sym, rtac @{thm id_apply}] 1) THEN
  18.109 -  rtac map_id 1;
  18.110 +fun mk_map_cong0L_tac ctxt passive map_cong0 map_id =
  18.111 +  (rtac ctxt trans THEN' rtac ctxt map_cong0 THEN' EVERY' (replicate passive (rtac ctxt refl))) 1 THEN
  18.112 +  REPEAT_DETERM (EVERY' [rtac ctxt trans, etac ctxt bspec, atac, rtac ctxt sym, rtac ctxt @{thm id_apply}] 1) THEN
  18.113 +  rtac ctxt map_id 1;
  18.114  
  18.115  end;
    19.1 --- a/src/HOL/Tools/Ctr_Sugar/ctr_sugar.ML	Thu Jul 16 10:48:20 2015 +0200
    19.2 +++ b/src/HOL/Tools/Ctr_Sugar/ctr_sugar.ML	Thu Jul 16 12:23:22 2015 +0200
    19.3 @@ -708,7 +708,8 @@
    19.4                HOLogic.mk_Trueprop (HOLogic.mk_all (fst u', snd u',
    19.5                  Library.foldr1 HOLogic.mk_disj exist_xs_u_eq_ctrs));
    19.6            in
    19.7 -            Goal.prove_sorry lthy [] [] goal (fn _ => mk_nchotomy_tac n exhaust_thm)
    19.8 +            Goal.prove_sorry lthy [] [] goal (fn {context = ctxt, prems = _} =>
    19.9 +              mk_nchotomy_tac ctxt n exhaust_thm)
   19.10              |> Thm.close_derivation
   19.11            end;
   19.12  
   19.13 @@ -737,7 +738,8 @@
   19.14              val weak_goal = Logic.mk_implies (uv_eq, mk_Trueprop_eq (ufcase, vfcase));
   19.15            in
   19.16              (Goal.prove_sorry lthy [] [] goal (fn _ => mk_case_cong_tac lthy uexhaust_thm case_thms),
   19.17 -             Goal.prove_sorry lthy [] [] weak_goal (K (etac arg_cong 1)))
   19.18 +             Goal.prove_sorry lthy [] [] weak_goal (fn {context = ctxt, prems = _} =>
   19.19 +               etac ctxt arg_cong 1))
   19.20              |> apply2 (singleton (Proof_Context.export names_lthy lthy) #>
   19.21                Thm.close_derivation)
   19.22            end;
   19.23 @@ -823,7 +825,8 @@
   19.24                    val m = the_single ms;
   19.25                    val goal = mk_Trueprop_eq (mk_uu_eq (), the_single exist_xs_u_eq_ctrs);
   19.26                  in
   19.27 -                  Goal.prove_sorry lthy [] [] goal (fn _ => mk_unique_disc_def_tac m uexhaust_thm)
   19.28 +                  Goal.prove_sorry lthy [] [] goal (fn {context = ctxt, prems = _} =>
   19.29 +                    mk_unique_disc_def_tac ctxt m uexhaust_thm)
   19.30                    |> singleton (Proof_Context.export names_lthy lthy)
   19.31                    |> Thm.close_derivation
   19.32                  end;
   19.33 @@ -886,7 +889,7 @@
   19.34                           HOLogic.mk_Trueprop (HOLogic.mk_not udisc')))];
   19.35  
   19.36                    fun prove tac goal =
   19.37 -                    Goal.prove_sorry lthy [] [] goal (K tac)
   19.38 +                    Goal.prove_sorry lthy [] [] goal (fn {context = ctxt, prems = _} => tac ctxt)
   19.39                      |> Thm.close_derivation;
   19.40  
   19.41                    val half_pairss = mk_half_pairss (`I (ms ~~ discD_thms ~~ udiscs));
   19.42 @@ -894,12 +897,14 @@
   19.43                    val half_goalss = map mk_goal half_pairss;
   19.44                    val half_thmss =
   19.45                      @{map 3} (fn [] => K (K []) | [goal] => fn [(((m, discD), _), _)] =>
   19.46 -                        fn disc_thm => [prove (mk_half_distinct_disc_tac lthy m discD disc_thm) goal])
   19.47 +                        fn disc_thm => [prove (fn ctxt =>
   19.48 +                          mk_half_distinct_disc_tac ctxt m discD disc_thm) goal])
   19.49                        half_goalss half_pairss (flat disc_thmss');
   19.50  
   19.51                    val other_half_goalss = map (mk_goal o map swap) half_pairss;
   19.52                    val other_half_thmss =
   19.53 -                    map2 (map2 (prove o mk_other_half_distinct_disc_tac)) half_thmss
   19.54 +                    map2 (map2 (fn thm => prove (fn ctxt =>
   19.55 +                        mk_other_half_distinct_disc_tac ctxt thm))) half_thmss
   19.56                        other_half_goalss;
   19.57                  in
   19.58                    join_halves n half_thmss other_half_thmss ||> `transpose
   19.59 @@ -911,8 +916,8 @@
   19.60                    fun mk_prem udisc = mk_imp_p [HOLogic.mk_Trueprop udisc];
   19.61                    val goal = fold_rev Logic.all [p, u] (mk_imp_p (map mk_prem udiscs));
   19.62                  in
   19.63 -                  Goal.prove_sorry lthy [] [] goal (fn _ =>
   19.64 -                    mk_exhaust_disc_tac n exhaust_thm discI_thms)
   19.65 +                  Goal.prove_sorry lthy [] [] goal (fn {context = ctxt, prems = _} =>
   19.66 +                    mk_exhaust_disc_tac ctxt n exhaust_thm discI_thms)
   19.67                    |> Thm.close_derivation
   19.68                  end;
   19.69  
   19.70 @@ -946,8 +951,8 @@
   19.71                    fun mk_prem usel_ctr = mk_imp_p [mk_Trueprop_eq (u, usel_ctr)];
   19.72                    val goal = fold_rev Logic.all [p, u] (mk_imp_p (map mk_prem usel_ctrs));
   19.73                  in
   19.74 -                  Goal.prove_sorry lthy [] [] goal (fn _ =>
   19.75 -                    mk_exhaust_sel_tac n exhaust_disc_thm swapped_all_collapse_thms)
   19.76 +                  Goal.prove_sorry lthy [] [] goal (fn {context = ctxt, prems = _} =>
   19.77 +                    mk_exhaust_sel_tac ctxt n exhaust_disc_thm swapped_all_collapse_thms)
   19.78                    |> Thm.close_derivation
   19.79                  end;
   19.80  
    20.1 --- a/src/HOL/Tools/Ctr_Sugar/ctr_sugar_tactics.ML	Thu Jul 16 10:48:20 2015 +0200
    20.2 +++ b/src/HOL/Tools/Ctr_Sugar/ctr_sugar_tactics.ML	Thu Jul 16 12:23:22 2015 +0200
    20.3 @@ -7,7 +7,7 @@
    20.4  
    20.5  signature CTR_SUGAR_GENERAL_TACTICS =
    20.6  sig
    20.7 -  val select_prem_tac: int -> (int -> tactic) -> int -> int -> tactic
    20.8 +  val select_prem_tac: Proof.context -> int -> (int -> tactic) -> int -> int -> tactic
    20.9    val unfold_thms_tac: Proof.context -> thm list -> tactic
   20.10  end;
   20.11  
   20.12 @@ -24,17 +24,17 @@
   20.13    val mk_collapse_tac: Proof.context -> int -> thm -> thm list -> tactic
   20.14    val mk_disc_eq_case_tac: Proof.context -> cterm -> thm -> thm list -> thm list -> thm list ->
   20.15      tactic
   20.16 -  val mk_exhaust_disc_tac: int -> thm -> thm list -> tactic
   20.17 -  val mk_exhaust_sel_tac: int -> thm -> thm list -> tactic
   20.18 +  val mk_exhaust_disc_tac: Proof.context -> int -> thm -> thm list -> tactic
   20.19 +  val mk_exhaust_sel_tac: Proof.context -> int -> thm -> thm list -> tactic
   20.20    val mk_expand_tac: Proof.context -> int -> int list -> thm -> thm -> thm list ->
   20.21      thm list list list -> thm list list list -> tactic
   20.22    val mk_half_distinct_disc_tac: Proof.context -> int -> thm -> thm -> tactic
   20.23 -  val mk_nchotomy_tac: int -> thm -> tactic
   20.24 -  val mk_other_half_distinct_disc_tac: thm -> tactic
   20.25 +  val mk_nchotomy_tac: Proof.context -> int -> thm -> tactic
   20.26 +  val mk_other_half_distinct_disc_tac: Proof.context -> thm -> tactic
   20.27    val mk_split_tac: Proof.context -> int list -> thm -> thm list -> thm list list ->
   20.28      thm list list -> thm list list list -> tactic
   20.29    val mk_split_asm_tac: Proof.context -> thm -> tactic
   20.30 -  val mk_unique_disc_def_tac: int -> thm -> tactic
   20.31 +  val mk_unique_disc_def_tac: Proof.context -> int -> thm -> tactic
   20.32  end;
   20.33  
   20.34  structure Ctr_Sugar_Tactics : CTR_SUGAR_TACTICS =
   20.35 @@ -44,57 +44,58 @@
   20.36  
   20.37  val meta_mp = @{thm meta_mp};
   20.38  
   20.39 -fun select_prem_tac n tac k = DETERM o (EVERY' [REPEAT_DETERM_N (k - 1) o etac thin_rl,
   20.40 -  tac, REPEAT_DETERM_N (n - k) o etac thin_rl]);
   20.41 +fun select_prem_tac ctxt n tac k = DETERM o (EVERY' [REPEAT_DETERM_N (k - 1) o etac ctxt thin_rl,
   20.42 +  tac, REPEAT_DETERM_N (n - k) o etac ctxt thin_rl]);
   20.43  
   20.44  fun unfold_thms_tac _ [] = all_tac
   20.45    | unfold_thms_tac ctxt thms = Local_Defs.unfold_tac ctxt (distinct Thm.eq_thm_prop thms);
   20.46  
   20.47  fun if_P_or_not_P_OF pos thm = thm RS (if pos then @{thm if_P} else @{thm if_not_P});
   20.48  
   20.49 -fun mk_nchotomy_tac n exhaust =
   20.50 -  HEADGOAL (rtac allI THEN' rtac exhaust THEN'
   20.51 -    EVERY' (maps (fn k => [rtac (mk_disjIN n k), REPEAT_DETERM o rtac exI, atac]) (1 upto n)));
   20.52 +fun mk_nchotomy_tac ctxt n exhaust =
   20.53 +  HEADGOAL (rtac ctxt allI THEN' rtac ctxt exhaust THEN'
   20.54 +    EVERY' (maps (fn k => [rtac ctxt (mk_disjIN n k), REPEAT_DETERM o rtac ctxt exI, atac]) (1 upto n)));
   20.55  
   20.56 -fun mk_unique_disc_def_tac m uexhaust =
   20.57 -  HEADGOAL (EVERY' [rtac iffI, rtac uexhaust, REPEAT_DETERM_N m o rtac exI, atac, rtac refl]);
   20.58 +fun mk_unique_disc_def_tac ctxt m uexhaust =
   20.59 +  HEADGOAL (EVERY' [rtac ctxt iffI, rtac ctxt uexhaust, REPEAT_DETERM_N m o rtac ctxt exI, atac, rtac ctxt refl]);
   20.60  
   20.61  fun mk_alternate_disc_def_tac ctxt k other_disc_def distinct uexhaust =
   20.62 -  HEADGOAL (EVERY' ([rtac (other_disc_def RS @{thm arg_cong[of _ _ Not]} RS trans),
   20.63 -    rtac @{thm iffI_np}, REPEAT_DETERM o etac exE,
   20.64 -    hyp_subst_tac ctxt, SELECT_GOAL (unfold_thms_tac ctxt [not_ex]), REPEAT_DETERM o rtac allI,
   20.65 -    rtac distinct, rtac uexhaust] @
   20.66 -    (([etac notE, REPEAT_DETERM o rtac exI, atac], [REPEAT_DETERM o rtac exI, atac])
   20.67 +  HEADGOAL (EVERY' ([rtac ctxt (other_disc_def RS @{thm arg_cong[of _ _ Not]} RS trans),
   20.68 +    rtac ctxt @{thm iffI_np}, REPEAT_DETERM o etac ctxt exE,
   20.69 +    hyp_subst_tac ctxt, SELECT_GOAL (unfold_thms_tac ctxt [not_ex]), REPEAT_DETERM o rtac ctxt allI,
   20.70 +    rtac ctxt distinct, rtac ctxt uexhaust] @
   20.71 +    (([etac ctxt notE, REPEAT_DETERM o rtac ctxt exI, atac], [REPEAT_DETERM o rtac ctxt exI, atac])
   20.72       |> k = 1 ? swap |> op @)));
   20.73  
   20.74  fun mk_half_distinct_disc_tac ctxt m discD disc' =
   20.75 -  HEADGOAL (dtac discD THEN' REPEAT_DETERM_N m o etac exE THEN' hyp_subst_tac ctxt THEN'
   20.76 -    rtac disc');
   20.77 -
   20.78 -fun mk_other_half_distinct_disc_tac half = HEADGOAL (etac @{thm contrapos_pn} THEN' etac half);
   20.79 +  HEADGOAL (dtac ctxt discD THEN' REPEAT_DETERM_N m o etac ctxt exE THEN' hyp_subst_tac ctxt THEN'
   20.80 +    rtac ctxt disc');
   20.81  
   20.82 -fun mk_exhaust_disc_or_sel_tac n exhaust destIs =
   20.83 -  HEADGOAL (rtac exhaust THEN'
   20.84 -    EVERY' (map2 (fn k => fn destI => dtac destI THEN'
   20.85 -      select_prem_tac n (etac meta_mp) k THEN' atac) (1 upto n) destIs));
   20.86 +fun mk_other_half_distinct_disc_tac ctxt half =
   20.87 +  HEADGOAL (etac ctxt @{thm contrapos_pn} THEN' etac ctxt half);
   20.88 +
   20.89 +fun mk_exhaust_disc_or_sel_tac ctxt n exhaust destIs =
   20.90 +  HEADGOAL (rtac ctxt exhaust THEN'
   20.91 +    EVERY' (map2 (fn k => fn destI => dtac ctxt destI THEN'
   20.92 +      select_prem_tac ctxt n (etac ctxt meta_mp) k THEN' atac) (1 upto n) destIs));
   20.93  
   20.94  val mk_exhaust_disc_tac = mk_exhaust_disc_or_sel_tac;
   20.95  
   20.96 -fun mk_exhaust_sel_tac n exhaust_disc collapses =
   20.97 -  mk_exhaust_disc_or_sel_tac n exhaust_disc collapses ORELSE
   20.98 -  HEADGOAL (etac meta_mp THEN' resolve0_tac collapses);
   20.99 +fun mk_exhaust_sel_tac ctxt n exhaust_disc collapses =
  20.100 +  mk_exhaust_disc_or_sel_tac ctxt n exhaust_disc collapses ORELSE
  20.101 +  HEADGOAL (etac ctxt meta_mp THEN' resolve0_tac collapses);
  20.102  
  20.103  fun mk_collapse_tac ctxt m discD sels =
  20.104 -  HEADGOAL (dtac discD THEN'
  20.105 +  HEADGOAL (dtac ctxt discD THEN'
  20.106      (if m = 0 then
  20.107         atac
  20.108       else
  20.109 -       REPEAT_DETERM_N m o etac exE THEN' hyp_subst_tac ctxt THEN'
  20.110 -       SELECT_GOAL (unfold_thms_tac ctxt sels) THEN' rtac refl));
  20.111 +       REPEAT_DETERM_N m o etac ctxt exE THEN' hyp_subst_tac ctxt THEN'
  20.112 +       SELECT_GOAL (unfold_thms_tac ctxt sels) THEN' rtac ctxt refl));
  20.113  
  20.114  fun mk_disc_eq_case_tac ctxt ct exhaust discs distincts cases =
  20.115    HEADGOAL Goal.conjunction_tac THEN
  20.116 -  ALLGOALS (rtac (cterm_instantiate_pos [SOME ct] exhaust) THEN_ALL_NEW
  20.117 +  ALLGOALS (rtac ctxt (cterm_instantiate_pos [SOME ct] exhaust) THEN_ALL_NEW
  20.118      (hyp_subst_tac ctxt THEN'
  20.119       SELECT_GOAL (unfold_thms_tac ctxt (@{thms not_True_eq_False not_False_eq_True} @ cases @
  20.120         ((refl :: discs @ distincts) RL [eqTrueI, eqFalseI]))) THEN'
  20.121 @@ -103,87 +104,87 @@
  20.122  fun mk_expand_tac ctxt n ms uexhaust_disc vexhaust_disc uncollapses distinct_discsss
  20.123      distinct_discsss' =
  20.124    if ms = [0] then
  20.125 -    HEADGOAL (rtac (@{thm trans_sym} OF (replicate 2 (the_single uncollapses))) THEN'
  20.126 -      TRY o EVERY' [rtac uexhaust_disc, atac, rtac vexhaust_disc, atac])
  20.127 +    HEADGOAL (rtac ctxt (@{thm trans_sym} OF (replicate 2 (the_single uncollapses))) THEN'
  20.128 +      TRY o EVERY' [rtac ctxt uexhaust_disc, atac, rtac ctxt vexhaust_disc, atac])
  20.129    else
  20.130      let val ks = 1 upto n in
  20.131 -      HEADGOAL (rtac uexhaust_disc THEN'
  20.132 +      HEADGOAL (rtac ctxt uexhaust_disc THEN'
  20.133          EVERY' (@{map 5} (fn k => fn m => fn distinct_discss => fn distinct_discss' => fn uuncollapse =>
  20.134 -          EVERY' [rtac (uuncollapse RS trans) THEN' TRY o atac, rtac sym, rtac vexhaust_disc,
  20.135 +          EVERY' [rtac ctxt (uuncollapse RS trans) THEN' TRY o atac, rtac ctxt sym, rtac ctxt vexhaust_disc,
  20.136              EVERY' (@{map 4} (fn k' => fn distinct_discs => fn distinct_discs' => fn vuncollapse =>
  20.137                EVERY'
  20.138                  (if k' = k then
  20.139 -                   [rtac (vuncollapse RS trans), TRY o atac] @
  20.140 +                   [rtac ctxt (vuncollapse RS trans), TRY o atac] @
  20.141                     (if m = 0 then
  20.142 -                      [rtac refl]
  20.143 +                      [rtac ctxt refl]
  20.144                      else
  20.145 -                      [if n = 1 then K all_tac else EVERY' [dtac meta_mp, atac, dtac meta_mp, atac],
  20.146 -                       REPEAT_DETERM_N (Int.max (0, m - 1)) o etac conjE,
  20.147 +                      [if n = 1 then K all_tac else EVERY' [dtac ctxt meta_mp, atac, dtac ctxt meta_mp, atac],
  20.148 +                       REPEAT_DETERM_N (Int.max (0, m - 1)) o etac ctxt conjE,
  20.149                         asm_simp_tac (ss_only [] ctxt)])
  20.150                   else
  20.151 -                   [dtac (the_single (if k = n then distinct_discs else distinct_discs')),
  20.152 -                    etac (if k = n then @{thm iff_contradict(1)} else @{thm iff_contradict(2)}),
  20.153 +                   [dtac ctxt (the_single (if k = n then distinct_discs else distinct_discs')),
  20.154 +                    etac ctxt (if k = n then @{thm iff_contradict(1)} else @{thm iff_contradict(2)}),
  20.155                      atac, atac]))
  20.156                ks distinct_discss distinct_discss' uncollapses)])
  20.157            ks ms distinct_discsss distinct_discsss' uncollapses))
  20.158      end;
  20.159  
  20.160  fun mk_case_same_ctr_tac ctxt injects =
  20.161 -  REPEAT_DETERM o etac exE THEN' etac conjE THEN'
  20.162 +  REPEAT_DETERM o etac ctxt exE THEN' etac ctxt conjE THEN'
  20.163      (case injects of
  20.164        [] => atac
  20.165 -    | [inject] => dtac (inject RS iffD1) THEN' REPEAT_DETERM o etac conjE THEN'
  20.166 -        hyp_subst_tac ctxt THEN' rtac refl);
  20.167 +    | [inject] => dtac ctxt (inject RS iffD1) THEN' REPEAT_DETERM o etac ctxt conjE THEN'
  20.168 +        hyp_subst_tac ctxt THEN' rtac ctxt refl);
  20.169  
  20.170  fun mk_case_distinct_ctrs_tac ctxt distincts =
  20.171 -  REPEAT_DETERM o etac exE THEN' etac conjE THEN' full_simp_tac (ss_only distincts ctxt);
  20.172 +  REPEAT_DETERM o etac ctxt exE THEN' etac ctxt conjE THEN' full_simp_tac (ss_only distincts ctxt);
  20.173  
  20.174  fun mk_case_tac ctxt n k case_def injects distinctss =
  20.175    let
  20.176      val case_def' = mk_unabs_def (n + 1) (case_def RS meta_eq_to_obj_eq);
  20.177      val ks = 1 upto n;
  20.178    in
  20.179 -    HEADGOAL (rtac (case_def' RS trans) THEN' rtac @{thm the_equality} THEN'
  20.180 -      rtac (mk_disjIN n k) THEN' REPEAT_DETERM o rtac exI THEN' rtac conjI THEN' rtac refl THEN'
  20.181 -      rtac refl THEN'
  20.182 +    HEADGOAL (rtac ctxt (case_def' RS trans) THEN' rtac ctxt @{thm the_equality} THEN'
  20.183 +      rtac ctxt (mk_disjIN n k) THEN' REPEAT_DETERM o rtac ctxt exI THEN' rtac ctxt conjI THEN' rtac ctxt refl THEN'
  20.184 +      rtac ctxt refl THEN'
  20.185        EVERY' (map2 (fn k' => fn distincts =>
  20.186 -        (if k' < n then etac disjE else K all_tac) THEN'
  20.187 +        (if k' < n then etac ctxt disjE else K all_tac) THEN'
  20.188          (if k' = k then mk_case_same_ctr_tac ctxt injects
  20.189           else mk_case_distinct_ctrs_tac ctxt distincts)) ks distinctss))
  20.190    end;
  20.191  
  20.192  fun mk_case_distrib_tac ctxt ct exhaust cases =
  20.193 -  HEADGOAL (rtac (cterm_instantiate_pos [SOME ct] exhaust)) THEN
  20.194 -  ALLGOALS (hyp_subst_tac ctxt THEN' SELECT_GOAL (unfold_thms_tac ctxt cases) THEN' rtac refl);
  20.195 +  HEADGOAL (rtac ctxt (cterm_instantiate_pos [SOME ct] exhaust)) THEN
  20.196 +  ALLGOALS (hyp_subst_tac ctxt THEN' SELECT_GOAL (unfold_thms_tac ctxt cases) THEN' rtac ctxt refl);
  20.197  
  20.198  fun mk_case_cong_tac ctxt uexhaust cases =
  20.199 -  HEADGOAL (rtac uexhaust THEN'
  20.200 -    EVERY' (maps (fn casex => [dtac sym, asm_simp_tac (ss_only [casex] ctxt)]) cases));
  20.201 +  HEADGOAL (rtac ctxt uexhaust THEN'
  20.202 +    EVERY' (maps (fn casex => [dtac ctxt sym, asm_simp_tac (ss_only [casex] ctxt)]) cases));
  20.203  
  20.204  fun mk_case_eq_if_tac ctxt n uexhaust cases discss' selss =
  20.205 -  HEADGOAL (rtac uexhaust THEN'
  20.206 +  HEADGOAL (rtac ctxt uexhaust THEN'
  20.207      EVERY' (@{map 3} (fn casex => fn if_discs => fn sels =>
  20.208          EVERY' [hyp_subst_tac ctxt, SELECT_GOAL (unfold_thms_tac ctxt (if_discs @ sels)),
  20.209 -          rtac casex])
  20.210 +          rtac ctxt casex])
  20.211        cases (map2 (seq_conds if_P_or_not_P_OF n) (1 upto n) discss') selss));
  20.212  
  20.213  fun mk_split_tac ctxt ms uexhaust cases selss injectss distinctsss =
  20.214    let val depth = fold Integer.max ms 0 in
  20.215 -    HEADGOAL (rtac uexhaust) THEN
  20.216 +    HEADGOAL (rtac ctxt uexhaust) THEN
  20.217      ALLGOALS (fn k => (hyp_subst_tac ctxt THEN'
  20.218         simp_tac (ss_only (@{thms simp_thms} @ cases @ nth selss (k - 1) @ nth injectss (k - 1) @
  20.219           flat (nth distinctsss (k - 1))) ctxt)) k) THEN
  20.220 -    ALLGOALS (etac thin_rl THEN' rtac iffI THEN'
  20.221 -      REPEAT_DETERM o rtac allI THEN' rtac impI THEN' REPEAT_DETERM o etac conjE THEN'
  20.222 -      hyp_subst_tac ctxt THEN' atac THEN' REPEAT_DETERM o etac allE THEN' etac impE THEN'
  20.223 -      REPEAT_DETERM o (rtac conjI THEN' rtac refl) THEN' rtac refl THEN' atac)
  20.224 +    ALLGOALS (etac ctxt thin_rl THEN' rtac ctxt iffI THEN'
  20.225 +      REPEAT_DETERM o rtac ctxt allI THEN' rtac ctxt impI THEN' REPEAT_DETERM o etac ctxt conjE THEN'
  20.226 +      hyp_subst_tac ctxt THEN' atac THEN' REPEAT_DETERM o etac ctxt allE THEN' etac ctxt impE THEN'
  20.227 +      REPEAT_DETERM o (rtac ctxt conjI THEN' rtac ctxt refl) THEN' rtac ctxt refl THEN' atac)
  20.228    end;
  20.229  
  20.230  val split_asm_thms = @{thms imp_conv_disj de_Morgan_conj de_Morgan_disj not_not not_ex};
  20.231  
  20.232  fun mk_split_asm_tac ctxt split =
  20.233 -  HEADGOAL (rtac (split RS trans)) THEN unfold_thms_tac ctxt split_asm_thms THEN
  20.234 -  HEADGOAL (rtac refl);
  20.235 +  HEADGOAL (rtac ctxt (split RS trans)) THEN unfold_thms_tac ctxt split_asm_thms THEN
  20.236 +  HEADGOAL (rtac ctxt refl);
  20.237  
  20.238  end;
  20.239  
    21.1 --- a/src/HOL/Tools/Ctr_Sugar/ctr_sugar_util.ML	Thu Jul 16 10:48:20 2015 +0200
    21.2 +++ b/src/HOL/Tools/Ctr_Sugar/ctr_sugar_util.ML	Thu Jul 16 12:23:22 2015 +0200
    21.3 @@ -54,6 +54,11 @@
    21.4  
    21.5    val rapp: term -> term -> term
    21.6  
    21.7 +  val rtac: Proof.context -> thm -> int -> tactic
    21.8 +  val etac: Proof.context -> thm -> int -> tactic
    21.9 +  val dtac: Proof.context -> thm -> int -> tactic
   21.10 +  val ftac: Proof.context -> thm -> int -> tactic
   21.11 +
   21.12    val list_all_free: term list -> term -> term
   21.13    val list_exists_free: term list -> term -> term
   21.14  
   21.15 @@ -273,4 +278,9 @@
   21.16  fun CONJ_WRAP gen_tac = CONJ_WRAP_GEN (rtac conjI 1) gen_tac;
   21.17  fun CONJ_WRAP' gen_tac = CONJ_WRAP_GEN' (rtac conjI) gen_tac;
   21.18  
   21.19 +fun rtac ctxt thm = resolve_tac ctxt [thm];
   21.20 +fun etac ctxt thm = eresolve_tac ctxt [thm];
   21.21 +fun dtac ctxt thm = dresolve_tac ctxt [thm];
   21.22 +fun ftac ctxt thm = forward_tac ctxt [thm];
   21.23 +
   21.24  end;
    22.1 --- a/src/HOL/Tools/Lifting/lifting_bnf.ML	Thu Jul 16 10:48:20 2015 +0200
    22.2 +++ b/src/HOL/Tools/Lifting/lifting_bnf.ML	Thu Jul 16 12:23:22 2015 +0200
    22.3 @@ -31,11 +31,11 @@
    22.4      val rel_conversep_sym = rel_conversep_of_bnf bnf RS sym
    22.5    in
    22.6      EVERY' [SELECT_GOAL (Local_Defs.unfold_tac ctxt [@{thm Quotient_alt_def5}]), 
    22.7 -      REPEAT_DETERM o (etac conjE), rtac conjI, SELECT_GOAL (Local_Defs.unfold_tac ctxt [rel_Grp_UNIV_sym]),
    22.8 -      rtac rel_mono THEN_ALL_NEW assume_tac ctxt, rtac conjI, SELECT_GOAL (Local_Defs.unfold_tac ctxt
    22.9 -        [rel_conversep_sym, rel_Grp_UNIV_sym]), rtac rel_mono THEN_ALL_NEW assume_tac ctxt,
   22.10 +      REPEAT_DETERM o (etac ctxt conjE), rtac ctxt conjI, SELECT_GOAL (Local_Defs.unfold_tac ctxt [rel_Grp_UNIV_sym]),
   22.11 +      rtac ctxt rel_mono THEN_ALL_NEW assume_tac ctxt, rtac ctxt conjI, SELECT_GOAL (Local_Defs.unfold_tac ctxt
   22.12 +        [rel_conversep_sym, rel_Grp_UNIV_sym]), rtac ctxt rel_mono THEN_ALL_NEW assume_tac ctxt,
   22.13        SELECT_GOAL (Local_Defs.unfold_tac ctxt [rel_conversep_sym, rel_OO_of_bnf bnf RS sym]),
   22.14 -      hyp_subst_tac ctxt, rtac refl] i
   22.15 +      hyp_subst_tac ctxt, rtac ctxt refl] i
   22.16    end
   22.17  
   22.18  fun mk_Quotient args =
    23.1 --- a/src/HOL/Tools/Lifting/lifting_def_code_dt.ML	Thu Jul 16 10:48:20 2015 +0200
    23.2 +++ b/src/HOL/Tools/Lifting/lifting_def_code_dt.ML	Thu Jul 16 12:23:22 2015 +0200
    23.3 @@ -218,7 +218,7 @@
    23.4    end;
    23.5  
    23.6  fun case_tac rule ctxt i st =
    23.7 -  (Subgoal.FOCUS_PARAMS (fn {params, ...} => HEADGOAL(rtac
    23.8 +  (Subgoal.FOCUS_PARAMS (fn {params, ...} => HEADGOAL(rtac ctxt
    23.9      (Ctr_Sugar_Util.cterm_instantiate_pos [SOME (params |> hd |> snd)] rule))) ctxt i st);
   23.10  
   23.11  fun bundle_name_of_bundle_binding binding phi context  =
   23.12 @@ -283,7 +283,8 @@
   23.13              val rsp_norm = Conv.fconv_rule rel_eq_onps_conv rsp
   23.14              val f'_rsp_goal = HOLogic.mk_Trueprop (f'_rsp_rel $ rhs $ rhs);
   23.15              val f'_rsp = Goal.prove_sorry lthy [] [] f'_rsp_goal
   23.16 -              (K (HEADGOAL (CONVERSION (rel_eq_onps_conv) THEN' rtac rsp_norm)))
   23.17 +              (fn {context = ctxt, prems = _} =>
   23.18 +                HEADGOAL (CONVERSION (rel_eq_onps_conv) THEN' rtac ctxt rsp_norm))
   23.19                |> Thm.close_derivation
   23.20              val (f'_lift_def, lthy) = add_lift_def ld_no_notes f'_var f'_qty rhs f'_rsp [] lthy
   23.21              val f'_lift_def = inst_of_lift_def lthy f'_qty f'_lift_def
   23.22 @@ -295,7 +296,7 @@
   23.23              val f_alt_def_goal = HOLogic.mk_Trueprop (HOLogic.mk_eq (f_alt_def_goal_lhs, f_alt_def_goal_rhs));
   23.24              fun f_alt_def_tac ctxt i =
   23.25                EVERY' [Transfer.gen_frees_tac [] ctxt, DETERM o Transfer.transfer_tac true ctxt,
   23.26 -                SELECT_GOAL (Local_Defs.unfold_tac ctxt [id_apply]), rtac refl] i;
   23.27 +                SELECT_GOAL (Local_Defs.unfold_tac ctxt [id_apply]), rtac ctxt refl] i;
   23.28              val rep_isom_transfer = transfer_of_rep_isom_data rep_isom_data
   23.29              val (_, transfer_lthy) = Proof_Context.note_thmss "" [((Binding.empty, []),
   23.30                [([rep_isom_transfer], [Transfer.transfer_add])])] lthy
   23.31 @@ -322,7 +323,7 @@
   23.32      fun eq_onp_to_top_tac ctxt = SELECT_GOAL (Local_Defs.unfold_tac ctxt 
   23.33        (@{thm eq_onp_top_eq_eq[symmetric]} :: Lifting_Info.get_relator_eq_onp_rules ctxt))
   23.34      fun lift_isom_tac ctxt = HEADGOAL (eq_onp_to_top_tac ctxt
   23.35 -      THEN' (rtac @{thm id_transfer}));
   23.36 +      THEN' (rtac ctxt @{thm id_transfer}));
   23.37  
   23.38      val (rep_isom_lift_def, lthy) = lift_def ld_no_notes (Binding.qualified true "Rep_isom" uTname, NoSyn)
   23.39        (qty_isom --> qty) (HOLogic.id_const rty) lift_isom_tac [] lthy
   23.40 @@ -408,11 +409,11 @@
   23.41      fun lift_sel_tac exhaust_rule dt_rules wits ctxt i =
   23.42          (Method.insert_tac wits THEN' 
   23.43           eq_onp_to_top_tac ctxt THEN' (* normalize *)
   23.44 -         rtac unfold_lift_sel_rsp THEN'
   23.45 +         rtac ctxt unfold_lift_sel_rsp THEN'
   23.46           case_tac exhaust_rule ctxt THEN_ALL_NEW (
   23.47          EVERY' [hyp_subst_tac ctxt, (* does not kill wits because = was rewritten to eq_onp top *)
   23.48          Raw_Simplifier.rewrite_goal_tac ctxt (map safe_mk_meta_eq dt_rules), 
   23.49 -        REPEAT_DETERM o etac conjE, atac])) i
   23.50 +        REPEAT_DETERM o etac ctxt conjE, atac])) i
   23.51      val pred_simps = Transfer.lookup_pred_data lthy (Tname rty) |> the |> Transfer.pred_simps
   23.52      val sel_tac = lift_sel_tac (#exhaust ctr_sugar) (#case_thms ctr_sugar @ pred_simps)
   23.53      val sel_names = map (fn (k, xs) => map (fn k' => Binding.qualified true
   23.54 @@ -437,7 +438,7 @@
   23.55            SELECT_GOAL (Local_Defs.unfold_tac ctxt @{thms eq_onp_top_eq_eq}) (* normalize *), 
   23.56            Raw_Simplifier.rewrite_goal_tac ctxt 
   23.57            (map safe_mk_meta_eq @{thms id_apply simp_thms Ball_def}),
   23.58 -         rtac TrueI] i;
   23.59 +         rtac ctxt TrueI] i;
   23.60  
   23.61      val (_, transfer_lthy) = Proof_Context.note_thmss "" [((Binding.empty, []),
   23.62        [(@{thms right_total_UNIV_transfer},[Transfer.transfer_add]),
   23.63 @@ -508,7 +509,7 @@
   23.64          in
   23.65            EVERY' [Transfer.gen_frees_tac [] ctxt, DETERM o (Transfer.transfer_tac true ctxt),
   23.66              case_tac exhaust ctxt THEN_ALL_NEW EVERY' [hyp_subst_tac ctxt,
   23.67 -              Raw_Simplifier.rewrite_goal_tac ctxt simp_rules, rtac TrueI ]] i
   23.68 +              Raw_Simplifier.rewrite_goal_tac ctxt simp_rules, rtac ctxt TrueI ]] i
   23.69          end
   23.70      end
   23.71      
   23.72 @@ -777,7 +778,7 @@
   23.73                let
   23.74                  val internal_rsp_thm = Goal.prove lthy [] [] prsp_tm 
   23.75                      (fn {context = ctxt, ...} =>
   23.76 -                      rtac readable_rsp_thm_eq 1 THEN Proof_Context.fact_tac ctxt [thm] 1)
   23.77 +                      rtac ctxt readable_rsp_thm_eq 1 THEN Proof_Context.fact_tac ctxt [thm] 1)
   23.78                in
   23.79                  after_qed internal_rsp_thm lthy
   23.80                end
    24.1 --- a/src/HOL/Tools/Transfer/transfer_bnf.ML	Thu Jul 16 10:48:20 2015 +0200
    24.2 +++ b/src/HOL/Tools/Transfer/transfer_bnf.ML	Thu Jul 16 12:23:22 2015 +0200
    24.3 @@ -84,14 +84,14 @@
    24.4      val thms = constr_defs @ map mk_sym [rel_eq_of_bnf bnf, rel_conversep_of_bnf bnf,
    24.5        rel_OO_of_bnf bnf]
    24.6    in
    24.7 -    (SELECT_GOAL (Local_Defs.unfold_tac ctxt thms) THEN' rtac (rel_mono_of_bnf bnf)
    24.8 +    (SELECT_GOAL (Local_Defs.unfold_tac ctxt thms) THEN' rtac ctxt (rel_mono_of_bnf bnf)
    24.9        THEN_ALL_NEW assume_tac ctxt) i
   24.10    end
   24.11  
   24.12  fun bi_constraint_tac constr_iff sided_constr_intros ctxt i =
   24.13    (SELECT_GOAL (Local_Defs.unfold_tac ctxt [constr_iff]) THEN'
   24.14 -    CONJ_WRAP' (fn thm => rtac thm THEN_ALL_NEW
   24.15 -      (REPEAT_DETERM o etac conjE THEN' assume_tac ctxt)) sided_constr_intros) i
   24.16 +    CONJ_WRAP' (fn thm => rtac ctxt thm THEN_ALL_NEW
   24.17 +      (REPEAT_DETERM o etac ctxt conjE THEN' assume_tac ctxt)) sided_constr_intros) i
   24.18  
   24.19  fun generate_relation_constraint_goal ctxt bnf constraint_def =
   24.20    let
   24.21 @@ -204,24 +204,24 @@
   24.22      val n = live_of_bnf bnf
   24.23      val set_map's = set_map_of_bnf bnf
   24.24    in
   24.25 -    EVERY' [rtac ext, SELECT_GOAL (Local_Defs.unfold_tac ctxt [@{thm Domainp.simps},
   24.26 -        in_rel_of_bnf bnf, pred_def]), rtac iffI,
   24.27 +    EVERY' [rtac ctxt ext, SELECT_GOAL (Local_Defs.unfold_tac ctxt [@{thm Domainp.simps},
   24.28 +        in_rel_of_bnf bnf, pred_def]), rtac ctxt iffI,
   24.29          REPEAT_DETERM o eresolve_tac ctxt [exE, conjE, CollectE], hyp_subst_tac ctxt,
   24.30 -        CONJ_WRAP' (fn set_map => EVERY' [rtac ballI, dtac (set_map RS equalityD1 RS set_mp),
   24.31 -          etac imageE, dtac set_rev_mp, assume_tac ctxt,
   24.32 +        CONJ_WRAP' (fn set_map => EVERY' [rtac ctxt ballI, dtac ctxt (set_map RS equalityD1 RS set_mp),
   24.33 +          etac ctxt imageE, dtac ctxt set_rev_mp, assume_tac ctxt,
   24.34            REPEAT_DETERM o eresolve_tac ctxt [CollectE, @{thm case_prodE}],
   24.35 -          hyp_subst_tac ctxt, rtac @{thm iffD2[OF arg_cong2[of _ _ _ _ Domainp, OF refl fst_conv]]},
   24.36 -          etac @{thm DomainPI}]) set_map's,
   24.37 -        REPEAT_DETERM o etac conjE,
   24.38 +          hyp_subst_tac ctxt, rtac ctxt @{thm iffD2[OF arg_cong2[of _ _ _ _ Domainp, OF refl fst_conv]]},
   24.39 +          etac ctxt @{thm DomainPI}]) set_map's,
   24.40 +        REPEAT_DETERM o etac ctxt conjE,
   24.41          REPEAT_DETERM o resolve_tac ctxt [exI, (refl RS conjI), rotate_prems 1 conjI],
   24.42 -        rtac refl, rtac (box_equals OF [map_cong0_of_bnf bnf, map_comp_of_bnf bnf RS sym,
   24.43 +        rtac ctxt refl, rtac ctxt (box_equals OF [map_cong0_of_bnf bnf, map_comp_of_bnf bnf RS sym,
   24.44            map_id_of_bnf bnf]),
   24.45 -        REPEAT_DETERM_N n o (EVERY' [rtac @{thm box_equals[OF _ sym[OF o_apply] sym[OF id_apply]]},
   24.46 -          rtac @{thm fst_conv}]), rtac CollectI,
   24.47 -        CONJ_WRAP' (fn set_map => EVERY' [rtac (set_map RS @{thm ord_eq_le_trans}),
   24.48 +        REPEAT_DETERM_N n o (EVERY' [rtac ctxt @{thm box_equals[OF _ sym[OF o_apply] sym[OF id_apply]]},
   24.49 +          rtac ctxt @{thm fst_conv}]), rtac ctxt CollectI,
   24.50 +        CONJ_WRAP' (fn set_map => EVERY' [rtac ctxt (set_map RS @{thm ord_eq_le_trans}),
   24.51            REPEAT_DETERM o resolve_tac ctxt [@{thm image_subsetI}, CollectI, @{thm case_prodI}],
   24.52 -          dtac (rotate_prems 1 bspec), assume_tac ctxt,
   24.53 -          etac @{thm DomainpE}, etac @{thm someI}]) set_map's
   24.54 +          dtac ctxt (rotate_prems 1 bspec), assume_tac ctxt,
   24.55 +          etac ctxt @{thm DomainpE}, etac ctxt @{thm someI}]) set_map's
   24.56        ] i
   24.57    end
   24.58  
   24.59 @@ -251,7 +251,7 @@
   24.60  fun pred_eq_onp_tac bnf pred_def ctxt i =
   24.61    (SELECT_GOAL (Local_Defs.unfold_tac ctxt [@{thm eq_onp_Grp},
   24.62      @{thm Ball_Collect}, pred_def]) THEN' CONVERSION (subst_conv (map_id0_of_bnf bnf RS sym))
   24.63 -  THEN' rtac (rel_Grp_of_bnf bnf)) i
   24.64 +  THEN' rtac ctxt (rel_Grp_of_bnf bnf)) i
   24.65  
   24.66  fun prove_rel_eq_onp ctxt bnf pred_def =
   24.67    let