proper naming convention lthy: local_theory, but ctxt: Proof.context for arbitrary context;
authorwenzelm
Thu Nov 05 22:59:57 2009 +0100 (2009-11-05)
changeset 33458ae1f5d89b082
parent 33457 0fc03a81c27c
child 33459 a4a38ed813f7
proper naming convention lthy: local_theory, but ctxt: Proof.context for arbitrary context;
tuned signature;
tuned;
src/HOL/Tools/inductive.ML
src/HOL/Tools/inductive_set.ML
     1.1 --- a/src/HOL/Tools/inductive.ML	Thu Nov 05 22:08:47 2009 +0100
     1.2 +++ b/src/HOL/Tools/inductive.ML	Thu Nov 05 22:59:57 2009 +0100
     1.3 @@ -20,9 +20,11 @@
     1.4  
     1.5  signature BASIC_INDUCTIVE =
     1.6  sig
     1.7 -  type inductive_result
     1.8 +  type inductive_result =
     1.9 +    {preds: term list, elims: thm list, raw_induct: thm,
    1.10 +     induct: thm, intrs: thm list}
    1.11    val morph_result: morphism -> inductive_result -> inductive_result
    1.12 -  type inductive_info
    1.13 +  type inductive_info = {names: string list, coind: bool} * inductive_result
    1.14    val the_inductive: Proof.context -> string -> inductive_info
    1.15    val print_inductives: Proof.context -> unit
    1.16    val mono_add: attribute
    1.17 @@ -36,7 +38,9 @@
    1.18      thm list list * local_theory
    1.19    val inductive_cases_i: (Attrib.binding * term list) list -> local_theory ->
    1.20      thm list list * local_theory
    1.21 -  type inductive_flags
    1.22 +  type inductive_flags =
    1.23 +    {quiet_mode: bool, verbose: bool, kind: string, alt_name: binding,
    1.24 +     coind: bool, no_elim: bool, no_ind: bool, skip_mono: bool, fork_mono: bool}
    1.25    val add_inductive_i:
    1.26      inductive_flags -> ((binding * typ) * mixfix) list ->
    1.27      (string * typ) list -> (Attrib.binding * term) list -> thm list -> local_theory ->
    1.28 @@ -62,7 +66,11 @@
    1.29  signature INDUCTIVE =
    1.30  sig
    1.31    include BASIC_INDUCTIVE
    1.32 -  type add_ind_def
    1.33 +  type add_ind_def =
    1.34 +    inductive_flags ->
    1.35 +    term list -> (Attrib.binding * term) list -> thm list ->
    1.36 +    term list -> (binding * mixfix) list ->
    1.37 +    local_theory -> inductive_result * local_theory
    1.38    val declare_rules: string -> binding -> bool -> bool -> string list ->
    1.39      thm list -> binding list -> Attrib.src list list -> (thm * string list) list ->
    1.40      thm -> local_theory -> thm list * thm list * thm * local_theory
    1.41 @@ -592,19 +600,21 @@
    1.42  
    1.43  (** specification of (co)inductive predicates **)
    1.44  
    1.45 -fun mk_ind_def quiet_mode skip_mono fork_mono alt_name coind cs intr_ts monos params cnames_syn ctxt =
    1.46 -  let  (* FIXME proper naming convention: lthy *)
    1.47 +fun mk_ind_def quiet_mode skip_mono fork_mono alt_name coind
    1.48 +    cs intr_ts monos params cnames_syn lthy =
    1.49 +  let
    1.50      val fp_name = if coind then @{const_name Inductive.gfp} else @{const_name Inductive.lfp};
    1.51  
    1.52      val argTs = fold (combine (op =) o arg_types_of (length params)) cs [];
    1.53      val k = log 2 1 (length cs);
    1.54      val predT = replicate k HOLogic.boolT ---> argTs ---> HOLogic.boolT;
    1.55 -    val p :: xs = map Free (Variable.variant_frees ctxt intr_ts
    1.56 +    val p :: xs = map Free (Variable.variant_frees lthy intr_ts
    1.57        (("p", predT) :: (mk_names "x" (length argTs) ~~ argTs)));
    1.58 -    val bs = map Free (Variable.variant_frees ctxt (p :: xs @ intr_ts)
    1.59 +    val bs = map Free (Variable.variant_frees lthy (p :: xs @ intr_ts)
    1.60        (map (rpair HOLogic.boolT) (mk_names "b" k)));
    1.61  
    1.62 -    fun subst t = (case dest_predicate cs params t of
    1.63 +    fun subst t =
    1.64 +      (case dest_predicate cs params t of
    1.65          SOME (_, i, ts, (Ts, Us)) =>
    1.66            let
    1.67              val l = length Us;
    1.68 @@ -651,44 +661,44 @@
    1.69          Binding.name (space_implode "_" (map (Binding.name_of o fst) cnames_syn))
    1.70        else alt_name;
    1.71  
    1.72 -    val ((rec_const, (_, fp_def)), ctxt') = ctxt
    1.73 +    val ((rec_const, (_, fp_def)), lthy') = lthy
    1.74        |> LocalTheory.conceal
    1.75        |> LocalTheory.define Thm.internalK
    1.76          ((rec_name, case cnames_syn of [(_, syn)] => syn | _ => NoSyn),
    1.77           (Attrib.empty_binding, fold_rev lambda params
    1.78             (Const (fp_name, (predT --> predT) --> predT) $ fp_fun)))
    1.79 -      ||> LocalTheory.restore_naming ctxt;
    1.80 +      ||> LocalTheory.restore_naming lthy;
    1.81      val fp_def' = Simplifier.rewrite (HOL_basic_ss addsimps [fp_def])
    1.82 -      (cterm_of (ProofContext.theory_of ctxt') (list_comb (rec_const, params)));
    1.83 +      (cterm_of (ProofContext.theory_of lthy') (list_comb (rec_const, params)));
    1.84      val specs =
    1.85        if length cs < 2 then []
    1.86        else
    1.87          map_index (fn (i, (name_mx, c)) =>
    1.88            let
    1.89              val Ts = arg_types_of (length params) c;
    1.90 -            val xs = map Free (Variable.variant_frees ctxt intr_ts
    1.91 +            val xs = map Free (Variable.variant_frees lthy intr_ts
    1.92                (mk_names "x" (length Ts) ~~ Ts))
    1.93            in
    1.94              (name_mx, (Attrib.empty_binding, fold_rev lambda (params @ xs)
    1.95                (list_comb (rec_const, params @ make_bool_args' bs i @
    1.96                  make_args argTs (xs ~~ Ts)))))
    1.97            end) (cnames_syn ~~ cs);
    1.98 -    val (consts_defs, ctxt'') = ctxt'
    1.99 +    val (consts_defs, lthy'') = lthy'
   1.100        |> LocalTheory.conceal
   1.101        |> fold_map (LocalTheory.define Thm.internalK) specs
   1.102 -      ||> LocalTheory.restore_naming ctxt';
   1.103 +      ||> LocalTheory.restore_naming lthy';
   1.104      val preds = (case cs of [_] => [rec_const] | _ => map #1 consts_defs);
   1.105  
   1.106 -    val mono = prove_mono quiet_mode skip_mono fork_mono predT fp_fun monos ctxt'';
   1.107 -    val ((_, [mono']), ctxt''') =
   1.108 -      LocalTheory.note Thm.internalK (apfst Binding.conceal Attrib.empty_binding, [mono]) ctxt'';
   1.109 +    val mono = prove_mono quiet_mode skip_mono fork_mono predT fp_fun monos lthy'';
   1.110 +    val ((_, [mono']), lthy''') =
   1.111 +      LocalTheory.note Thm.internalK (apfst Binding.conceal Attrib.empty_binding, [mono]) lthy'';
   1.112  
   1.113 -  in (ctxt''', rec_name, mono', fp_def', map (#2 o #2) consts_defs,
   1.114 +  in (lthy''', rec_name, mono', fp_def', map (#2 o #2) consts_defs,
   1.115      list_comb (rec_const, params), preds, argTs, bs, xs)
   1.116    end;
   1.117  
   1.118 -fun declare_rules kind rec_binding coind no_ind cnames intrs intr_bindings intr_atts
   1.119 -      elims raw_induct ctxt =
   1.120 +fun declare_rules kind rec_binding coind no_ind cnames
   1.121 +      intrs intr_bindings intr_atts elims raw_induct lthy =
   1.122    let
   1.123      val rec_name = Binding.name_of rec_binding;
   1.124      fun rec_qualified qualified = Binding.qualify qualified rec_name;
   1.125 @@ -703,86 +713,89 @@
   1.126          (raw_induct, [ind_case_names, Rule_Cases.consumes 0])
   1.127        else (raw_induct RSN (2, rev_mp), [ind_case_names, Rule_Cases.consumes 1]);
   1.128  
   1.129 -    val (intrs', ctxt1) =
   1.130 -      ctxt |>
   1.131 +    val (intrs', lthy1) =
   1.132 +      lthy |>
   1.133        LocalTheory.notes kind
   1.134          (map (rec_qualified false) intr_bindings ~~ intr_atts ~~
   1.135            map (fn th => [([th],
   1.136             [Attrib.internal (K (Context_Rules.intro_query NONE)),
   1.137              Attrib.internal (K Nitpick_Intros.add)])]) intrs) |>>
   1.138        map (hd o snd);
   1.139 -    val (((_, elims'), (_, [induct'])), ctxt2) =
   1.140 -      ctxt1 |>
   1.141 +    val (((_, elims'), (_, [induct'])), lthy2) =
   1.142 +      lthy1 |>
   1.143        LocalTheory.note kind ((rec_qualified true (Binding.name "intros"), []), intrs') ||>>
   1.144        fold_map (fn (name, (elim, cases)) =>
   1.145 -        LocalTheory.note kind ((Binding.qualify true (Long_Name.base_name name) (Binding.name "cases"),
   1.146 -          [Attrib.internal (K (Rule_Cases.case_names cases)),
   1.147 -           Attrib.internal (K (Rule_Cases.consumes 1)),
   1.148 -           Attrib.internal (K (Induct.cases_pred name)),
   1.149 -           Attrib.internal (K (Context_Rules.elim_query NONE))]), [elim]) #>
   1.150 +        LocalTheory.note kind
   1.151 +          ((Binding.qualify true (Long_Name.base_name name) (Binding.name "cases"),
   1.152 +            [Attrib.internal (K (Rule_Cases.case_names cases)),
   1.153 +             Attrib.internal (K (Rule_Cases.consumes 1)),
   1.154 +             Attrib.internal (K (Induct.cases_pred name)),
   1.155 +             Attrib.internal (K (Context_Rules.elim_query NONE))]), [elim]) #>
   1.156          apfst (hd o snd)) (if null elims then [] else cnames ~~ elims) ||>>
   1.157        LocalTheory.note kind
   1.158          ((rec_qualified true (Binding.name (coind_prefix coind ^ "induct")),
   1.159            map (Attrib.internal o K) (#2 induct)), [rulify (#1 induct)]);
   1.160  
   1.161 -    val ctxt3 = if no_ind orelse coind then ctxt2 else
   1.162 -      let val inducts = cnames ~~ Project_Rule.projects ctxt2 (1 upto length cnames) induct'
   1.163 -      in
   1.164 -        ctxt2 |>
   1.165 -        LocalTheory.notes kind [((rec_qualified true (Binding.name "inducts"), []),
   1.166 -          inducts |> map (fn (name, th) => ([th],
   1.167 -            [Attrib.internal (K ind_case_names),
   1.168 -             Attrib.internal (K (Rule_Cases.consumes 1)),
   1.169 -             Attrib.internal (K (Induct.induct_pred name))])))] |> snd
   1.170 -      end
   1.171 -  in (intrs', elims', induct', ctxt3) end;
   1.172 +    val lthy3 =
   1.173 +      if no_ind orelse coind then lthy2
   1.174 +      else
   1.175 +        let val inducts = cnames ~~ Project_Rule.projects lthy2 (1 upto length cnames) induct' in
   1.176 +          lthy2 |>
   1.177 +          LocalTheory.notes kind [((rec_qualified true (Binding.name "inducts"), []),
   1.178 +            inducts |> map (fn (name, th) => ([th],
   1.179 +              [Attrib.internal (K ind_case_names),
   1.180 +               Attrib.internal (K (Rule_Cases.consumes 1)),
   1.181 +               Attrib.internal (K (Induct.induct_pred name))])))] |> snd
   1.182 +        end;
   1.183 +  in (intrs', elims', induct', lthy3) end;
   1.184  
   1.185  type inductive_flags =
   1.186    {quiet_mode: bool, verbose: bool, kind: string, alt_name: binding,
   1.187 -   coind: bool, no_elim: bool, no_ind: bool, skip_mono: bool, fork_mono: bool}
   1.188 +   coind: bool, no_elim: bool, no_ind: bool, skip_mono: bool, fork_mono: bool};
   1.189  
   1.190  type add_ind_def =
   1.191    inductive_flags ->
   1.192    term list -> (Attrib.binding * term) list -> thm list ->
   1.193    term list -> (binding * mixfix) list ->
   1.194 -  local_theory -> inductive_result * local_theory
   1.195 +  local_theory -> inductive_result * local_theory;
   1.196  
   1.197 -fun add_ind_def {quiet_mode, verbose, kind, alt_name, coind, no_elim, no_ind, skip_mono, fork_mono}
   1.198 -    cs intros monos params cnames_syn ctxt =
   1.199 +fun add_ind_def
   1.200 +    {quiet_mode, verbose, kind, alt_name, coind, no_elim, no_ind, skip_mono, fork_mono}
   1.201 +    cs intros monos params cnames_syn lthy =
   1.202    let
   1.203      val _ = null cnames_syn andalso error "No inductive predicates given";
   1.204      val names = map (Binding.name_of o fst) cnames_syn;
   1.205      val _ = message (quiet_mode andalso not verbose)
   1.206        ("Proofs for " ^ coind_prefix coind ^ "inductive predicate(s) " ^ commas_quote names);
   1.207  
   1.208 -    val cnames = map (LocalTheory.full_name ctxt o #1) cnames_syn;  (* FIXME *)
   1.209 +    val cnames = map (LocalTheory.full_name lthy o #1) cnames_syn;  (* FIXME *)
   1.210      val ((intr_names, intr_atts), intr_ts) =
   1.211 -      apfst split_list (split_list (map (check_rule ctxt cs params) intros));
   1.212 +      apfst split_list (split_list (map (check_rule lthy cs params) intros));
   1.213  
   1.214 -    val (ctxt1, rec_name, mono, fp_def, rec_preds_defs, rec_const, preds,
   1.215 +    val (lthy1, rec_name, mono, fp_def, rec_preds_defs, rec_const, preds,
   1.216        argTs, bs, xs) = mk_ind_def quiet_mode skip_mono fork_mono alt_name coind cs intr_ts
   1.217 -        monos params cnames_syn ctxt;
   1.218 +        monos params cnames_syn lthy;
   1.219  
   1.220      val (intrs, unfold) = prove_intrs quiet_mode coind mono fp_def (length bs + length xs)
   1.221 -      params intr_ts rec_preds_defs ctxt1;
   1.222 +      params intr_ts rec_preds_defs lthy1;
   1.223      val elims = if no_elim then [] else
   1.224        prove_elims quiet_mode cs params intr_ts (map Binding.name_of intr_names)
   1.225 -        unfold rec_preds_defs ctxt1;
   1.226 +        unfold rec_preds_defs lthy1;
   1.227      val raw_induct = zero_var_indexes
   1.228        (if no_ind then Drule.asm_rl else
   1.229         if coind then
   1.230           singleton (ProofContext.export
   1.231 -           (snd (Variable.add_fixes (map (fst o dest_Free) params) ctxt1)) ctxt1)
   1.232 +           (snd (Variable.add_fixes (map (fst o dest_Free) params) lthy1)) lthy1)
   1.233             (rotate_prems ~1 (ObjectLogic.rulify
   1.234               (fold_rule rec_preds_defs
   1.235                 (rewrite_rule simp_thms'''
   1.236                  (mono RS (fp_def RS @{thm def_coinduct}))))))
   1.237         else
   1.238           prove_indrule quiet_mode cs argTs bs xs rec_const params intr_ts mono fp_def
   1.239 -           rec_preds_defs ctxt1);
   1.240 +           rec_preds_defs lthy1);
   1.241  
   1.242 -    val (intrs', elims', induct, ctxt2) = declare_rules kind rec_name coind no_ind
   1.243 -      cnames intrs intr_names intr_atts elims raw_induct ctxt1;
   1.244 +    val (intrs', elims', induct, lthy2) = declare_rules kind rec_name coind no_ind
   1.245 +      cnames intrs intr_names intr_atts elims raw_induct lthy1;
   1.246  
   1.247      val result =
   1.248        {preds = preds,
   1.249 @@ -791,11 +804,11 @@
   1.250         raw_induct = rulify raw_induct,
   1.251         induct = induct};
   1.252  
   1.253 -    val ctxt3 = ctxt2
   1.254 +    val lthy3 = lthy2
   1.255        |> LocalTheory.declaration false (fn phi =>
   1.256          let val result' = morph_result phi result;
   1.257          in put_inductives cnames (*global names!?*) ({names = cnames, coind = coind}, result') end);
   1.258 -  in (result, ctxt3) end;
   1.259 +  in (result, lthy3) end;
   1.260  
   1.261  
   1.262  (* external interfaces *)
   1.263 @@ -970,8 +983,13 @@
   1.264  
   1.265  val ind_decl = gen_ind_decl add_ind_def;
   1.266  
   1.267 -val _ = OuterSyntax.local_theory' "inductive" "define inductive predicates" K.thy_decl (ind_decl false);
   1.268 -val _ = OuterSyntax.local_theory' "coinductive" "define coinductive predicates" K.thy_decl (ind_decl true);
   1.269 +val _ =
   1.270 +  OuterSyntax.local_theory' "inductive" "define inductive predicates" K.thy_decl
   1.271 +    (ind_decl false);
   1.272 +
   1.273 +val _ =
   1.274 +  OuterSyntax.local_theory' "coinductive" "define coinductive predicates" K.thy_decl
   1.275 +    (ind_decl true);
   1.276  
   1.277  val _ =
   1.278    OuterSyntax.local_theory "inductive_cases"
     2.1 --- a/src/HOL/Tools/inductive_set.ML	Thu Nov 05 22:08:47 2009 +0100
     2.2 +++ b/src/HOL/Tools/inductive_set.ML	Thu Nov 05 22:59:57 2009 +0100
     2.3 @@ -406,11 +406,11 @@
     2.4  
     2.5  fun add_ind_set_def
     2.6      {quiet_mode, verbose, kind, alt_name, coind, no_elim, no_ind, skip_mono, fork_mono}
     2.7 -    cs intros monos params cnames_syn ctxt =
     2.8 -  let (* FIXME proper naming convention: lthy *)
     2.9 -    val thy = ProofContext.theory_of ctxt;
    2.10 +    cs intros monos params cnames_syn lthy =
    2.11 +  let
    2.12 +    val thy = ProofContext.theory_of lthy;
    2.13      val {set_arities, pred_arities, to_pred_simps, ...} =
    2.14 -      PredSetConvData.get (Context.Proof ctxt);
    2.15 +      PredSetConvData.get (Context.Proof lthy);
    2.16      fun infer (Abs (_, _, t)) = infer t
    2.17        | infer (Const ("op :", _) $ t $ u) =
    2.18            infer_arities thy set_arities (SOME (HOLogic.flat_tuple_paths t), u)
    2.19 @@ -446,9 +446,9 @@
    2.20          val (Us, U) = split_last (binder_types T);
    2.21          val _ = Us = paramTs orelse error (Pretty.string_of (Pretty.chunks
    2.22            [Pretty.str "Argument types",
    2.23 -           Pretty.block (Pretty.commas (map (Syntax.pretty_typ ctxt) Us)),
    2.24 +           Pretty.block (Pretty.commas (map (Syntax.pretty_typ lthy) Us)),
    2.25             Pretty.str ("of " ^ s ^ " do not agree with types"),
    2.26 -           Pretty.block (Pretty.commas (map (Syntax.pretty_typ ctxt) paramTs)),
    2.27 +           Pretty.block (Pretty.commas (map (Syntax.pretty_typ lthy) paramTs)),
    2.28             Pretty.str "of declared parameters"]));
    2.29          val Ts = HOLogic.strip_ptupleT fs U;
    2.30          val c' = Free (s ^ "p",
    2.31 @@ -474,29 +474,29 @@
    2.32          Pattern.rewrite_term thy [] [to_pred_proc thy eqns'] |>
    2.33          eta_contract (member op = cs' orf is_pred pred_arities))) intros;
    2.34      val cnames_syn' = map (fn (b, _) => (Binding.suffix_name "p" b, NoSyn)) cnames_syn;
    2.35 -    val monos' = map (to_pred [] (Context.Proof ctxt)) monos;
    2.36 -    val ({preds, intrs, elims, raw_induct, ...}, ctxt1) =
    2.37 +    val monos' = map (to_pred [] (Context.Proof lthy)) monos;
    2.38 +    val ({preds, intrs, elims, raw_induct, ...}, lthy1) =
    2.39        Inductive.add_ind_def
    2.40          {quiet_mode = quiet_mode, verbose = verbose, kind = kind, alt_name = Binding.empty,
    2.41            coind = coind, no_elim = no_elim, no_ind = no_ind,
    2.42            skip_mono = skip_mono, fork_mono = fork_mono}
    2.43 -        cs' intros' monos' params1 cnames_syn' ctxt;
    2.44 +        cs' intros' monos' params1 cnames_syn' lthy;
    2.45  
    2.46      (* define inductive sets using previously defined predicates *)
    2.47 -    val (defs, ctxt2) = ctxt1
    2.48 +    val (defs, lthy2) = lthy1
    2.49        |> LocalTheory.conceal  (* FIXME ?? *)
    2.50        |> fold_map (LocalTheory.define Thm.internalK)
    2.51          (map (fn ((c_syn, (fs, U, _)), p) => (c_syn, (Attrib.empty_binding,
    2.52             fold_rev lambda params (HOLogic.Collect_const U $
    2.53               HOLogic.mk_psplits fs U HOLogic.boolT (list_comb (p, params3))))))
    2.54             (cnames_syn ~~ cs_info ~~ preds))
    2.55 -      ||> LocalTheory.restore_naming ctxt1;
    2.56 +      ||> LocalTheory.restore_naming lthy1;
    2.57  
    2.58      (* prove theorems for converting predicate to set notation *)
    2.59 -    val ctxt3 = fold
    2.60 -      (fn (((p, c as Free (s, _)), (fs, U, Ts)), (_, (_, def))) => fn ctxt =>
    2.61 +    val lthy3 = fold
    2.62 +      (fn (((p, c as Free (s, _)), (fs, U, Ts)), (_, (_, def))) => fn lthy =>
    2.63          let val conv_thm =
    2.64 -          Goal.prove ctxt (map (fst o dest_Free) params) []
    2.65 +          Goal.prove lthy (map (fst o dest_Free) params) []
    2.66              (HOLogic.mk_Trueprop (HOLogic.mk_eq
    2.67                (list_comb (p, params3),
    2.68                 list_abs (map (pair "x") Ts, HOLogic.mk_mem
    2.69 @@ -505,29 +505,29 @@
    2.70              (K (REPEAT (rtac ext 1) THEN simp_tac (HOL_basic_ss addsimps
    2.71                [def, mem_Collect_eq, split_conv]) 1))
    2.72          in
    2.73 -          ctxt |> LocalTheory.note kind ((Binding.name (s ^ "p_" ^ s ^ "_eq"),
    2.74 +          lthy |> LocalTheory.note kind ((Binding.name (s ^ "p_" ^ s ^ "_eq"),
    2.75              [Attrib.internal (K pred_set_conv_att)]),
    2.76                [conv_thm]) |> snd
    2.77 -        end) (preds ~~ cs ~~ cs_info ~~ defs) ctxt2;
    2.78 +        end) (preds ~~ cs ~~ cs_info ~~ defs) lthy2;
    2.79  
    2.80      (* convert theorems to set notation *)
    2.81      val rec_name =
    2.82        if Binding.is_empty alt_name then
    2.83          Binding.name (space_implode "_" (map (Binding.name_of o fst) cnames_syn))
    2.84        else alt_name;
    2.85 -    val cnames = map (LocalTheory.full_name ctxt3 o #1) cnames_syn;  (* FIXME *)
    2.86 +    val cnames = map (LocalTheory.full_name lthy3 o #1) cnames_syn;  (* FIXME *)
    2.87      val (intr_names, intr_atts) = split_list (map fst intros);
    2.88 -    val raw_induct' = to_set [] (Context.Proof ctxt3) raw_induct;
    2.89 -    val (intrs', elims', induct, ctxt4) =
    2.90 +    val raw_induct' = to_set [] (Context.Proof lthy3) raw_induct;
    2.91 +    val (intrs', elims', induct, lthy4) =
    2.92        Inductive.declare_rules kind rec_name coind no_ind cnames
    2.93 -      (map (to_set [] (Context.Proof ctxt3)) intrs) intr_names intr_atts
    2.94 -      (map (fn th => (to_set [] (Context.Proof ctxt3) th,
    2.95 +      (map (to_set [] (Context.Proof lthy3)) intrs) intr_names intr_atts
    2.96 +      (map (fn th => (to_set [] (Context.Proof lthy3) th,
    2.97           map fst (fst (Rule_Cases.get th)))) elims)
    2.98 -      raw_induct' ctxt3
    2.99 +      raw_induct' lthy3
   2.100    in
   2.101      ({intrs = intrs', elims = elims', induct = induct,
   2.102        raw_induct = raw_induct', preds = map fst defs},
   2.103 -     ctxt4)
   2.104 +     lthy4)
   2.105    end;
   2.106  
   2.107  val add_inductive_i = Inductive.gen_add_inductive_i add_ind_set_def;
   2.108 @@ -544,8 +544,10 @@
   2.109  val setup =
   2.110    Attrib.setup @{binding pred_set_conv} (Scan.succeed pred_set_conv_att)
   2.111      "declare rules for converting between predicate and set notation" #>
   2.112 -  Attrib.setup @{binding to_set} (Attrib.thms >> to_set_att) "convert rule to set notation" #>
   2.113 -  Attrib.setup @{binding to_pred} (Attrib.thms >> to_pred_att) "convert rule to predicate notation" #>
   2.114 +  Attrib.setup @{binding to_set} (Attrib.thms >> to_set_att)
   2.115 +    "convert rule to set notation" #>
   2.116 +  Attrib.setup @{binding to_pred} (Attrib.thms >> to_pred_att)
   2.117 +    "convert rule to predicate notation" #>
   2.118    Attrib.setup @{binding code_ind_set}
   2.119      (Scan.lift (Scan.option (Args.$$$ "target" |-- Args.colon |-- Args.name) >> code_ind_att))
   2.120      "introduction rules for executable predicates" #>
   2.121 @@ -562,10 +564,12 @@
   2.122  val ind_set_decl = Inductive.gen_ind_decl add_ind_set_def;
   2.123  
   2.124  val _ =
   2.125 -  OuterSyntax.local_theory' "inductive_set" "define inductive sets" K.thy_decl (ind_set_decl false);
   2.126 +  OuterSyntax.local_theory' "inductive_set" "define inductive sets" K.thy_decl
   2.127 +    (ind_set_decl false);
   2.128  
   2.129  val _ =
   2.130 -  OuterSyntax.local_theory' "coinductive_set" "define coinductive sets" K.thy_decl (ind_set_decl true);
   2.131 +  OuterSyntax.local_theory' "coinductive_set" "define coinductive sets" K.thy_decl
   2.132 +    (ind_set_decl true);
   2.133  
   2.134  end;
   2.135