merged
authorwenzelm
Fri Nov 06 10:26:13 2009 +0100 (2009-11-06)
changeset 334668f2e102f6628
parent 33465 8c489493e65e
parent 33459 a4a38ed813f7
child 33467 c3971d3c6afd
child 33488 b8a7a3febe6b
merged
src/Pure/Isar/theory_target.ML
     1.1 --- a/src/HOL/Statespace/state_space.ML	Fri Nov 06 09:27:20 2009 +0100
     1.2 +++ b/src/HOL/Statespace/state_space.ML	Fri Nov 06 10:26:13 2009 +0100
     1.3 @@ -355,7 +355,7 @@
     1.4  fun add_declaration name decl thy =
     1.5    thy
     1.6    |> TheoryTarget.init name
     1.7 -  |> (fn lthy => LocalTheory.declaration (decl lthy) lthy)
     1.8 +  |> (fn lthy => LocalTheory.declaration false (decl lthy) lthy)
     1.9    |> LocalTheory.exit_global;
    1.10  
    1.11  fun parent_components thy (Ts, pname, renaming) =
     2.1 --- a/src/HOL/Tools/Datatype/datatype_abs_proofs.ML	Fri Nov 06 09:27:20 2009 +0100
     2.2 +++ b/src/HOL/Tools/Datatype/datatype_abs_proofs.ML	Fri Nov 06 10:26:13 2009 +0100
     2.3 @@ -338,8 +338,7 @@
     2.4            (DatatypeProp.make_cases new_type_names descr sorts thy2)
     2.5    in
     2.6      thy2
     2.7 -    |> Context.the_theory o fold (fold Nitpick_Simps.add_thm) case_thms
     2.8 -       o Context.Theory
     2.9 +    |> Context.theory_map ((fold o fold) Nitpick_Simps.add_thm case_thms)
    2.10      |> Sign.parent_path
    2.11      |> store_thmss "cases" new_type_names case_thms
    2.12      |-> (fn thmss => pair (thmss, case_names))
     3.1 --- a/src/HOL/Tools/Function/function.ML	Fri Nov 06 09:27:20 2009 +0100
     3.2 +++ b/src/HOL/Tools/Function/function.ML	Fri Nov 06 10:26:13 2009 +0100
     3.3 @@ -118,7 +118,7 @@
     3.4              else Specification.print_consts lthy (K false) (map fst fixes)
     3.5          in
     3.6            lthy
     3.7 -          |> LocalTheory.declaration (add_function_data o morph_function_data cdata)
     3.8 +          |> LocalTheory.declaration false (add_function_data o morph_function_data cdata)
     3.9          end
    3.10      in
    3.11        lthy
     4.1 --- a/src/HOL/Tools/inductive.ML	Fri Nov 06 09:27:20 2009 +0100
     4.2 +++ b/src/HOL/Tools/inductive.ML	Fri Nov 06 10:26:13 2009 +0100
     4.3 @@ -20,9 +20,11 @@
     4.4  
     4.5  signature BASIC_INDUCTIVE =
     4.6  sig
     4.7 -  type inductive_result
     4.8 +  type inductive_result =
     4.9 +    {preds: term list, elims: thm list, raw_induct: thm,
    4.10 +     induct: thm, intrs: thm list}
    4.11    val morph_result: morphism -> inductive_result -> inductive_result
    4.12 -  type inductive_info
    4.13 +  type inductive_info = {names: string list, coind: bool} * inductive_result
    4.14    val the_inductive: Proof.context -> string -> inductive_info
    4.15    val print_inductives: Proof.context -> unit
    4.16    val mono_add: attribute
    4.17 @@ -36,7 +38,9 @@
    4.18      thm list list * local_theory
    4.19    val inductive_cases_i: (Attrib.binding * term list) list -> local_theory ->
    4.20      thm list list * local_theory
    4.21 -  type inductive_flags
    4.22 +  type inductive_flags =
    4.23 +    {quiet_mode: bool, verbose: bool, kind: string, alt_name: binding,
    4.24 +     coind: bool, no_elim: bool, no_ind: bool, skip_mono: bool, fork_mono: bool}
    4.25    val add_inductive_i:
    4.26      inductive_flags -> ((binding * typ) * mixfix) list ->
    4.27      (string * typ) list -> (Attrib.binding * term) list -> thm list -> local_theory ->
    4.28 @@ -62,7 +66,11 @@
    4.29  signature INDUCTIVE =
    4.30  sig
    4.31    include BASIC_INDUCTIVE
    4.32 -  type add_ind_def
    4.33 +  type add_ind_def =
    4.34 +    inductive_flags ->
    4.35 +    term list -> (Attrib.binding * term) list -> thm list ->
    4.36 +    term list -> (binding * mixfix) list ->
    4.37 +    local_theory -> inductive_result * local_theory
    4.38    val declare_rules: string -> binding -> bool -> bool -> string list ->
    4.39      thm list -> binding list -> Attrib.src list list -> (thm * string list) list ->
    4.40      thm -> local_theory -> thm list * thm list * thm * local_theory
    4.41 @@ -592,19 +600,21 @@
    4.42  
    4.43  (** specification of (co)inductive predicates **)
    4.44  
    4.45 -fun mk_ind_def quiet_mode skip_mono fork_mono alt_name coind cs intr_ts monos params cnames_syn ctxt =
    4.46 -  let  (* FIXME proper naming convention: lthy *)
    4.47 +fun mk_ind_def quiet_mode skip_mono fork_mono alt_name coind
    4.48 +    cs intr_ts monos params cnames_syn lthy =
    4.49 +  let
    4.50      val fp_name = if coind then @{const_name Inductive.gfp} else @{const_name Inductive.lfp};
    4.51  
    4.52      val argTs = fold (combine (op =) o arg_types_of (length params)) cs [];
    4.53      val k = log 2 1 (length cs);
    4.54      val predT = replicate k HOLogic.boolT ---> argTs ---> HOLogic.boolT;
    4.55 -    val p :: xs = map Free (Variable.variant_frees ctxt intr_ts
    4.56 +    val p :: xs = map Free (Variable.variant_frees lthy intr_ts
    4.57        (("p", predT) :: (mk_names "x" (length argTs) ~~ argTs)));
    4.58 -    val bs = map Free (Variable.variant_frees ctxt (p :: xs @ intr_ts)
    4.59 +    val bs = map Free (Variable.variant_frees lthy (p :: xs @ intr_ts)
    4.60        (map (rpair HOLogic.boolT) (mk_names "b" k)));
    4.61  
    4.62 -    fun subst t = (case dest_predicate cs params t of
    4.63 +    fun subst t =
    4.64 +      (case dest_predicate cs params t of
    4.65          SOME (_, i, ts, (Ts, Us)) =>
    4.66            let
    4.67              val l = length Us;
    4.68 @@ -651,44 +661,44 @@
    4.69          Binding.name (space_implode "_" (map (Binding.name_of o fst) cnames_syn))
    4.70        else alt_name;
    4.71  
    4.72 -    val ((rec_const, (_, fp_def)), ctxt') = ctxt
    4.73 +    val ((rec_const, (_, fp_def)), lthy') = lthy
    4.74        |> LocalTheory.conceal
    4.75        |> LocalTheory.define Thm.internalK
    4.76          ((rec_name, case cnames_syn of [(_, syn)] => syn | _ => NoSyn),
    4.77           (Attrib.empty_binding, fold_rev lambda params
    4.78             (Const (fp_name, (predT --> predT) --> predT) $ fp_fun)))
    4.79 -      ||> LocalTheory.restore_naming ctxt;
    4.80 +      ||> LocalTheory.restore_naming lthy;
    4.81      val fp_def' = Simplifier.rewrite (HOL_basic_ss addsimps [fp_def])
    4.82 -      (cterm_of (ProofContext.theory_of ctxt') (list_comb (rec_const, params)));
    4.83 +      (cterm_of (ProofContext.theory_of lthy') (list_comb (rec_const, params)));
    4.84      val specs =
    4.85        if length cs < 2 then []
    4.86        else
    4.87          map_index (fn (i, (name_mx, c)) =>
    4.88            let
    4.89              val Ts = arg_types_of (length params) c;
    4.90 -            val xs = map Free (Variable.variant_frees ctxt intr_ts
    4.91 +            val xs = map Free (Variable.variant_frees lthy intr_ts
    4.92                (mk_names "x" (length Ts) ~~ Ts))
    4.93            in
    4.94              (name_mx, (Attrib.empty_binding, fold_rev lambda (params @ xs)
    4.95                (list_comb (rec_const, params @ make_bool_args' bs i @
    4.96                  make_args argTs (xs ~~ Ts)))))
    4.97            end) (cnames_syn ~~ cs);
    4.98 -    val (consts_defs, ctxt'') = ctxt'
    4.99 +    val (consts_defs, lthy'') = lthy'
   4.100        |> LocalTheory.conceal
   4.101        |> fold_map (LocalTheory.define Thm.internalK) specs
   4.102 -      ||> LocalTheory.restore_naming ctxt';
   4.103 +      ||> LocalTheory.restore_naming lthy';
   4.104      val preds = (case cs of [_] => [rec_const] | _ => map #1 consts_defs);
   4.105  
   4.106 -    val mono = prove_mono quiet_mode skip_mono fork_mono predT fp_fun monos ctxt'';
   4.107 -    val ((_, [mono']), ctxt''') =
   4.108 -      LocalTheory.note Thm.internalK (apfst Binding.conceal Attrib.empty_binding, [mono]) ctxt'';
   4.109 +    val mono = prove_mono quiet_mode skip_mono fork_mono predT fp_fun monos lthy'';
   4.110 +    val ((_, [mono']), lthy''') =
   4.111 +      LocalTheory.note Thm.internalK (apfst Binding.conceal Attrib.empty_binding, [mono]) lthy'';
   4.112  
   4.113 -  in (ctxt''', rec_name, mono', fp_def', map (#2 o #2) consts_defs,
   4.114 +  in (lthy''', rec_name, mono', fp_def', map (#2 o #2) consts_defs,
   4.115      list_comb (rec_const, params), preds, argTs, bs, xs)
   4.116    end;
   4.117  
   4.118 -fun declare_rules kind rec_binding coind no_ind cnames intrs intr_bindings intr_atts
   4.119 -      elims raw_induct ctxt =
   4.120 +fun declare_rules kind rec_binding coind no_ind cnames
   4.121 +      intrs intr_bindings intr_atts elims raw_induct lthy =
   4.122    let
   4.123      val rec_name = Binding.name_of rec_binding;
   4.124      fun rec_qualified qualified = Binding.qualify qualified rec_name;
   4.125 @@ -703,86 +713,91 @@
   4.126          (raw_induct, [ind_case_names, Rule_Cases.consumes 0])
   4.127        else (raw_induct RSN (2, rev_mp), [ind_case_names, Rule_Cases.consumes 1]);
   4.128  
   4.129 -    val (intrs', ctxt1) =
   4.130 -      ctxt |>
   4.131 +    val (intrs', lthy1) =
   4.132 +      lthy |>
   4.133        LocalTheory.notes kind
   4.134          (map (rec_qualified false) intr_bindings ~~ intr_atts ~~
   4.135            map (fn th => [([th],
   4.136             [Attrib.internal (K (Context_Rules.intro_query NONE)),
   4.137              Attrib.internal (K Nitpick_Intros.add)])]) intrs) |>>
   4.138        map (hd o snd);
   4.139 -    val (((_, elims'), (_, [induct'])), ctxt2) =
   4.140 -      ctxt1 |>
   4.141 +    val (((_, elims'), (_, [induct'])), lthy2) =
   4.142 +      lthy1 |>
   4.143        LocalTheory.note kind ((rec_qualified true (Binding.name "intros"), []), intrs') ||>>
   4.144        fold_map (fn (name, (elim, cases)) =>
   4.145 -        LocalTheory.note kind ((Binding.qualify true (Long_Name.base_name name) (Binding.name "cases"),
   4.146 -          [Attrib.internal (K (Rule_Cases.case_names cases)),
   4.147 -           Attrib.internal (K (Rule_Cases.consumes 1)),
   4.148 -           Attrib.internal (K (Induct.cases_pred name)),
   4.149 -           Attrib.internal (K (Context_Rules.elim_query NONE))]), [elim]) #>
   4.150 +        LocalTheory.note kind
   4.151 +          ((Binding.qualify true (Long_Name.base_name name) (Binding.name "cases"),
   4.152 +            [Attrib.internal (K (Rule_Cases.case_names cases)),
   4.153 +             Attrib.internal (K (Rule_Cases.consumes 1)),
   4.154 +             Attrib.internal (K (Induct.cases_pred name)),
   4.155 +             Attrib.internal (K (Context_Rules.elim_query NONE))]), [elim]) #>
   4.156          apfst (hd o snd)) (if null elims then [] else cnames ~~ elims) ||>>
   4.157        LocalTheory.note kind
   4.158          ((rec_qualified true (Binding.name (coind_prefix coind ^ "induct")),
   4.159            map (Attrib.internal o K) (#2 induct)), [rulify (#1 induct)]);
   4.160  
   4.161 -    val ctxt3 = if no_ind orelse coind then ctxt2 else
   4.162 -      let val inducts = cnames ~~ Project_Rule.projects ctxt2 (1 upto length cnames) induct'
   4.163 -      in
   4.164 -        ctxt2 |>
   4.165 -        LocalTheory.notes kind [((rec_qualified true (Binding.name "inducts"), []),
   4.166 -          inducts |> map (fn (name, th) => ([th],
   4.167 -            [Attrib.internal (K ind_case_names),
   4.168 -             Attrib.internal (K (Rule_Cases.consumes 1)),
   4.169 -             Attrib.internal (K (Induct.induct_pred name))])))] |> snd
   4.170 -      end
   4.171 -  in (intrs', elims', induct', ctxt3) end;
   4.172 +    val lthy3 =
   4.173 +      if no_ind orelse coind then lthy2
   4.174 +      else
   4.175 +        let val inducts = cnames ~~ Project_Rule.projects lthy2 (1 upto length cnames) induct' in
   4.176 +          lthy2 |>
   4.177 +          LocalTheory.notes kind [((rec_qualified true (Binding.name "inducts"), []),
   4.178 +            inducts |> map (fn (name, th) => ([th],
   4.179 +              [Attrib.internal (K ind_case_names),
   4.180 +               Attrib.internal (K (Rule_Cases.consumes 1)),
   4.181 +               Attrib.internal (K (Induct.induct_pred name))])))] |> snd
   4.182 +        end;
   4.183 +  in (intrs', elims', induct', lthy3) end;
   4.184  
   4.185  type inductive_flags =
   4.186    {quiet_mode: bool, verbose: bool, kind: string, alt_name: binding,
   4.187 -   coind: bool, no_elim: bool, no_ind: bool, skip_mono: bool, fork_mono: bool}
   4.188 +   coind: bool, no_elim: bool, no_ind: bool, skip_mono: bool, fork_mono: bool};
   4.189  
   4.190  type add_ind_def =
   4.191    inductive_flags ->
   4.192    term list -> (Attrib.binding * term) list -> thm list ->
   4.193    term list -> (binding * mixfix) list ->
   4.194 -  local_theory -> inductive_result * local_theory
   4.195 +  local_theory -> inductive_result * local_theory;
   4.196  
   4.197 -fun add_ind_def {quiet_mode, verbose, kind, alt_name, coind, no_elim, no_ind, skip_mono, fork_mono}
   4.198 -    cs intros monos params cnames_syn ctxt =
   4.199 +fun add_ind_def
   4.200 +    {quiet_mode, verbose, kind, alt_name, coind, no_elim, no_ind, skip_mono, fork_mono}
   4.201 +    cs intros monos params cnames_syn lthy =
   4.202    let
   4.203      val _ = null cnames_syn andalso error "No inductive predicates given";
   4.204      val names = map (Binding.name_of o fst) cnames_syn;
   4.205      val _ = message (quiet_mode andalso not verbose)
   4.206        ("Proofs for " ^ coind_prefix coind ^ "inductive predicate(s) " ^ commas_quote names);
   4.207  
   4.208 -    val cnames = map (LocalTheory.full_name ctxt o #1) cnames_syn;  (* FIXME *)
   4.209 +    val cnames = map (LocalTheory.full_name lthy o #1) cnames_syn;  (* FIXME *)
   4.210      val ((intr_names, intr_atts), intr_ts) =
   4.211 -      apfst split_list (split_list (map (check_rule ctxt cs params) intros));
   4.212 +      apfst split_list (split_list (map (check_rule lthy cs params) intros));
   4.213  
   4.214 -    val (ctxt1, rec_name, mono, fp_def, rec_preds_defs, rec_const, preds,
   4.215 +    val (lthy1, rec_name, mono, fp_def, rec_preds_defs, rec_const, preds,
   4.216        argTs, bs, xs) = mk_ind_def quiet_mode skip_mono fork_mono alt_name coind cs intr_ts
   4.217 -        monos params cnames_syn ctxt;
   4.218 +        monos params cnames_syn lthy;
   4.219  
   4.220      val (intrs, unfold) = prove_intrs quiet_mode coind mono fp_def (length bs + length xs)
   4.221 -      params intr_ts rec_preds_defs ctxt1;
   4.222 -    val elims = if no_elim then [] else
   4.223 -      prove_elims quiet_mode cs params intr_ts (map Binding.name_of intr_names)
   4.224 -        unfold rec_preds_defs ctxt1;
   4.225 +      params intr_ts rec_preds_defs lthy1;
   4.226 +    val elims =
   4.227 +      if no_elim then []
   4.228 +      else
   4.229 +        prove_elims quiet_mode cs params intr_ts (map Binding.name_of intr_names)
   4.230 +          unfold rec_preds_defs lthy1;
   4.231      val raw_induct = zero_var_indexes
   4.232 -      (if no_ind then Drule.asm_rl else
   4.233 -       if coind then
   4.234 +      (if no_ind then Drule.asm_rl
   4.235 +       else if coind then
   4.236           singleton (ProofContext.export
   4.237 -           (snd (Variable.add_fixes (map (fst o dest_Free) params) ctxt1)) ctxt1)
   4.238 +           (snd (Variable.add_fixes (map (fst o dest_Free) params) lthy1)) lthy1)
   4.239             (rotate_prems ~1 (ObjectLogic.rulify
   4.240               (fold_rule rec_preds_defs
   4.241                 (rewrite_rule simp_thms'''
   4.242                  (mono RS (fp_def RS @{thm def_coinduct}))))))
   4.243         else
   4.244           prove_indrule quiet_mode cs argTs bs xs rec_const params intr_ts mono fp_def
   4.245 -           rec_preds_defs ctxt1);
   4.246 +           rec_preds_defs lthy1);
   4.247  
   4.248 -    val (intrs', elims', induct, ctxt2) = declare_rules kind rec_name coind no_ind
   4.249 -      cnames intrs intr_names intr_atts elims raw_induct ctxt1;
   4.250 +    val (intrs', elims', induct, lthy2) = declare_rules kind rec_name coind no_ind
   4.251 +      cnames intrs intr_names intr_atts elims raw_induct lthy1;
   4.252  
   4.253      val result =
   4.254        {preds = preds,
   4.255 @@ -791,11 +806,11 @@
   4.256         raw_induct = rulify raw_induct,
   4.257         induct = induct};
   4.258  
   4.259 -    val ctxt3 = ctxt2
   4.260 -      |> LocalTheory.declaration (fn phi =>
   4.261 +    val lthy3 = lthy2
   4.262 +      |> LocalTheory.declaration false (fn phi =>
   4.263          let val result' = morph_result phi result;
   4.264          in put_inductives cnames (*global names!?*) ({names = cnames, coind = coind}, result') end);
   4.265 -  in (result, ctxt3) end;
   4.266 +  in (result, lthy3) end;
   4.267  
   4.268  
   4.269  (* external interfaces *)
   4.270 @@ -970,8 +985,13 @@
   4.271  
   4.272  val ind_decl = gen_ind_decl add_ind_def;
   4.273  
   4.274 -val _ = OuterSyntax.local_theory' "inductive" "define inductive predicates" K.thy_decl (ind_decl false);
   4.275 -val _ = OuterSyntax.local_theory' "coinductive" "define coinductive predicates" K.thy_decl (ind_decl true);
   4.276 +val _ =
   4.277 +  OuterSyntax.local_theory' "inductive" "define inductive predicates" K.thy_decl
   4.278 +    (ind_decl false);
   4.279 +
   4.280 +val _ =
   4.281 +  OuterSyntax.local_theory' "coinductive" "define coinductive predicates" K.thy_decl
   4.282 +    (ind_decl true);
   4.283  
   4.284  val _ =
   4.285    OuterSyntax.local_theory "inductive_cases"
     5.1 --- a/src/HOL/Tools/inductive_set.ML	Fri Nov 06 09:27:20 2009 +0100
     5.2 +++ b/src/HOL/Tools/inductive_set.ML	Fri Nov 06 10:26:13 2009 +0100
     5.3 @@ -406,11 +406,11 @@
     5.4  
     5.5  fun add_ind_set_def
     5.6      {quiet_mode, verbose, kind, alt_name, coind, no_elim, no_ind, skip_mono, fork_mono}
     5.7 -    cs intros monos params cnames_syn ctxt =
     5.8 -  let (* FIXME proper naming convention: lthy *)
     5.9 -    val thy = ProofContext.theory_of ctxt;
    5.10 +    cs intros monos params cnames_syn lthy =
    5.11 +  let
    5.12 +    val thy = ProofContext.theory_of lthy;
    5.13      val {set_arities, pred_arities, to_pred_simps, ...} =
    5.14 -      PredSetConvData.get (Context.Proof ctxt);
    5.15 +      PredSetConvData.get (Context.Proof lthy);
    5.16      fun infer (Abs (_, _, t)) = infer t
    5.17        | infer (Const ("op :", _) $ t $ u) =
    5.18            infer_arities thy set_arities (SOME (HOLogic.flat_tuple_paths t), u)
    5.19 @@ -446,9 +446,9 @@
    5.20          val (Us, U) = split_last (binder_types T);
    5.21          val _ = Us = paramTs orelse error (Pretty.string_of (Pretty.chunks
    5.22            [Pretty.str "Argument types",
    5.23 -           Pretty.block (Pretty.commas (map (Syntax.pretty_typ ctxt) Us)),
    5.24 +           Pretty.block (Pretty.commas (map (Syntax.pretty_typ lthy) Us)),
    5.25             Pretty.str ("of " ^ s ^ " do not agree with types"),
    5.26 -           Pretty.block (Pretty.commas (map (Syntax.pretty_typ ctxt) paramTs)),
    5.27 +           Pretty.block (Pretty.commas (map (Syntax.pretty_typ lthy) paramTs)),
    5.28             Pretty.str "of declared parameters"]));
    5.29          val Ts = HOLogic.strip_ptupleT fs U;
    5.30          val c' = Free (s ^ "p",
    5.31 @@ -474,29 +474,29 @@
    5.32          Pattern.rewrite_term thy [] [to_pred_proc thy eqns'] |>
    5.33          eta_contract (member op = cs' orf is_pred pred_arities))) intros;
    5.34      val cnames_syn' = map (fn (b, _) => (Binding.suffix_name "p" b, NoSyn)) cnames_syn;
    5.35 -    val monos' = map (to_pred [] (Context.Proof ctxt)) monos;
    5.36 -    val ({preds, intrs, elims, raw_induct, ...}, ctxt1) =
    5.37 +    val monos' = map (to_pred [] (Context.Proof lthy)) monos;
    5.38 +    val ({preds, intrs, elims, raw_induct, ...}, lthy1) =
    5.39        Inductive.add_ind_def
    5.40          {quiet_mode = quiet_mode, verbose = verbose, kind = kind, alt_name = Binding.empty,
    5.41            coind = coind, no_elim = no_elim, no_ind = no_ind,
    5.42            skip_mono = skip_mono, fork_mono = fork_mono}
    5.43 -        cs' intros' monos' params1 cnames_syn' ctxt;
    5.44 +        cs' intros' monos' params1 cnames_syn' lthy;
    5.45  
    5.46      (* define inductive sets using previously defined predicates *)
    5.47 -    val (defs, ctxt2) = ctxt1
    5.48 +    val (defs, lthy2) = lthy1
    5.49        |> LocalTheory.conceal  (* FIXME ?? *)
    5.50        |> fold_map (LocalTheory.define Thm.internalK)
    5.51          (map (fn ((c_syn, (fs, U, _)), p) => (c_syn, (Attrib.empty_binding,
    5.52             fold_rev lambda params (HOLogic.Collect_const U $
    5.53               HOLogic.mk_psplits fs U HOLogic.boolT (list_comb (p, params3))))))
    5.54             (cnames_syn ~~ cs_info ~~ preds))
    5.55 -      ||> LocalTheory.restore_naming ctxt1;
    5.56 +      ||> LocalTheory.restore_naming lthy1;
    5.57  
    5.58      (* prove theorems for converting predicate to set notation *)
    5.59 -    val ctxt3 = fold
    5.60 -      (fn (((p, c as Free (s, _)), (fs, U, Ts)), (_, (_, def))) => fn ctxt =>
    5.61 +    val lthy3 = fold
    5.62 +      (fn (((p, c as Free (s, _)), (fs, U, Ts)), (_, (_, def))) => fn lthy =>
    5.63          let val conv_thm =
    5.64 -          Goal.prove ctxt (map (fst o dest_Free) params) []
    5.65 +          Goal.prove lthy (map (fst o dest_Free) params) []
    5.66              (HOLogic.mk_Trueprop (HOLogic.mk_eq
    5.67                (list_comb (p, params3),
    5.68                 list_abs (map (pair "x") Ts, HOLogic.mk_mem
    5.69 @@ -505,29 +505,29 @@
    5.70              (K (REPEAT (rtac ext 1) THEN simp_tac (HOL_basic_ss addsimps
    5.71                [def, mem_Collect_eq, split_conv]) 1))
    5.72          in
    5.73 -          ctxt |> LocalTheory.note kind ((Binding.name (s ^ "p_" ^ s ^ "_eq"),
    5.74 +          lthy |> LocalTheory.note kind ((Binding.name (s ^ "p_" ^ s ^ "_eq"),
    5.75              [Attrib.internal (K pred_set_conv_att)]),
    5.76                [conv_thm]) |> snd
    5.77 -        end) (preds ~~ cs ~~ cs_info ~~ defs) ctxt2;
    5.78 +        end) (preds ~~ cs ~~ cs_info ~~ defs) lthy2;
    5.79  
    5.80      (* convert theorems to set notation *)
    5.81      val rec_name =
    5.82        if Binding.is_empty alt_name then
    5.83          Binding.name (space_implode "_" (map (Binding.name_of o fst) cnames_syn))
    5.84        else alt_name;
    5.85 -    val cnames = map (LocalTheory.full_name ctxt3 o #1) cnames_syn;  (* FIXME *)
    5.86 +    val cnames = map (LocalTheory.full_name lthy3 o #1) cnames_syn;  (* FIXME *)
    5.87      val (intr_names, intr_atts) = split_list (map fst intros);
    5.88 -    val raw_induct' = to_set [] (Context.Proof ctxt3) raw_induct;
    5.89 -    val (intrs', elims', induct, ctxt4) =
    5.90 +    val raw_induct' = to_set [] (Context.Proof lthy3) raw_induct;
    5.91 +    val (intrs', elims', induct, lthy4) =
    5.92        Inductive.declare_rules kind rec_name coind no_ind cnames
    5.93 -      (map (to_set [] (Context.Proof ctxt3)) intrs) intr_names intr_atts
    5.94 -      (map (fn th => (to_set [] (Context.Proof ctxt3) th,
    5.95 -         map fst (fst (Rule_Cases.get th)))) elims)
    5.96 -      raw_induct' ctxt3
    5.97 +        (map (to_set [] (Context.Proof lthy3)) intrs) intr_names intr_atts
    5.98 +        (map (fn th => (to_set [] (Context.Proof lthy3) th,
    5.99 +           map fst (fst (Rule_Cases.get th)))) elims)
   5.100 +        raw_induct' lthy3;
   5.101    in
   5.102      ({intrs = intrs', elims = elims', induct = induct,
   5.103        raw_induct = raw_induct', preds = map fst defs},
   5.104 -     ctxt4)
   5.105 +     lthy4)
   5.106    end;
   5.107  
   5.108  val add_inductive_i = Inductive.gen_add_inductive_i add_ind_set_def;
   5.109 @@ -544,8 +544,10 @@
   5.110  val setup =
   5.111    Attrib.setup @{binding pred_set_conv} (Scan.succeed pred_set_conv_att)
   5.112      "declare rules for converting between predicate and set notation" #>
   5.113 -  Attrib.setup @{binding to_set} (Attrib.thms >> to_set_att) "convert rule to set notation" #>
   5.114 -  Attrib.setup @{binding to_pred} (Attrib.thms >> to_pred_att) "convert rule to predicate notation" #>
   5.115 +  Attrib.setup @{binding to_set} (Attrib.thms >> to_set_att)
   5.116 +    "convert rule to set notation" #>
   5.117 +  Attrib.setup @{binding to_pred} (Attrib.thms >> to_pred_att)
   5.118 +    "convert rule to predicate notation" #>
   5.119    Attrib.setup @{binding code_ind_set}
   5.120      (Scan.lift (Scan.option (Args.$$$ "target" |-- Args.colon |-- Args.name) >> code_ind_att))
   5.121      "introduction rules for executable predicates" #>
   5.122 @@ -562,10 +564,12 @@
   5.123  val ind_set_decl = Inductive.gen_ind_decl add_ind_set_def;
   5.124  
   5.125  val _ =
   5.126 -  OuterSyntax.local_theory' "inductive_set" "define inductive sets" K.thy_decl (ind_set_decl false);
   5.127 +  OuterSyntax.local_theory' "inductive_set" "define inductive sets" K.thy_decl
   5.128 +    (ind_set_decl false);
   5.129  
   5.130  val _ =
   5.131 -  OuterSyntax.local_theory' "coinductive_set" "define coinductive sets" K.thy_decl (ind_set_decl true);
   5.132 +  OuterSyntax.local_theory' "coinductive_set" "define coinductive sets" K.thy_decl
   5.133 +    (ind_set_decl true);
   5.134  
   5.135  end;
   5.136  
     6.1 --- a/src/Pure/Isar/constdefs.ML	Fri Nov 06 09:27:20 2009 +0100
     6.2 +++ b/src/Pure/Isar/constdefs.ML	Fri Nov 06 10:26:13 2009 +0100
     6.3 @@ -44,7 +44,8 @@
     6.4            else ());
     6.5      val b = Binding.name c;
     6.6  
     6.7 -    val def = Term.subst_atomic [(Free (c, T), Const (Sign.full_bname thy c, T))] prop;
     6.8 +    val head = Const (Sign.full_bname thy c, T);
     6.9 +    val def = Term.subst_atomic [(Free (c, T), head)] prop;
    6.10      val name = Thm.def_binding_optional b raw_name;
    6.11      val atts = map (prep_att thy) raw_atts;
    6.12  
    6.13 @@ -52,7 +53,10 @@
    6.14        thy
    6.15        |> Sign.add_consts_i [(b, T, mx)]
    6.16        |> PureThy.add_defs false [((name, def), atts)]
    6.17 -      |-> (fn [thm] => Code.add_default_eqn thm #> Context.theory_map (Predicate_Compile_Preproc_Const_Defs.add_thm thm));
    6.18 +      |-> (fn [thm] =>  (* FIXME thm vs. atts !? *)
    6.19 +        Spec_Rules.add_global Spec_Rules.Equational ([Logic.varify head], [thm]) #>
    6.20 +        Code.add_default_eqn thm #>
    6.21 +        Context.theory_map (Predicate_Compile_Preproc_Const_Defs.add_thm thm));
    6.22    in ((c, T), thy') end;
    6.23  
    6.24  fun gen_constdefs prep_vars prep_prop prep_att (raw_structs, specs) thy =
     7.1 --- a/src/Pure/Isar/isar_cmd.ML	Fri Nov 06 09:27:20 2009 +0100
     7.2 +++ b/src/Pure/Isar/isar_cmd.ML	Fri Nov 06 10:26:13 2009 +0100
     7.3 @@ -16,7 +16,7 @@
     7.4    val oracle: bstring * Position.T -> Symbol_Pos.text * Position.T -> theory -> theory
     7.5    val add_axioms: ((binding * string) * Attrib.src list) list -> theory -> theory
     7.6    val add_defs: (bool * bool) * ((binding * string) * Attrib.src list) list -> theory -> theory
     7.7 -  val declaration: Symbol_Pos.text * Position.T -> local_theory -> local_theory
     7.8 +  val declaration: bool -> Symbol_Pos.text * Position.T -> local_theory -> local_theory
     7.9    val simproc_setup: string -> string list -> Symbol_Pos.text * Position.T -> string list ->
    7.10      local_theory -> local_theory
    7.11    val hide_names: bool -> string * xstring list -> theory -> theory
    7.12 @@ -178,10 +178,10 @@
    7.13  
    7.14  (* declarations *)
    7.15  
    7.16 -fun declaration (txt, pos) =
    7.17 +fun declaration pervasive (txt, pos) =
    7.18    txt |> ML_Context.expression pos
    7.19      "val declaration: Morphism.declaration"
    7.20 -    "Context.map_proof (LocalTheory.declaration declaration)"
    7.21 +    ("Context.map_proof (LocalTheory.declaration " ^ Bool.toString pervasive ^ " declaration)")
    7.22    |> Context.proof_map;
    7.23  
    7.24  
     8.1 --- a/src/Pure/Isar/isar_syn.ML	Fri Nov 06 09:27:20 2009 +0100
     8.2 +++ b/src/Pure/Isar/isar_syn.ML	Fri Nov 06 10:26:13 2009 +0100
     8.3 @@ -22,8 +22,9 @@
     8.4    "advanced", "and", "assumes", "attach", "begin", "binder",
     8.5    "constrains", "defines", "fixes", "for", "identifier", "if",
     8.6    "imports", "in", "infix", "infixl", "infixr", "is",
     8.7 -  "notes", "obtains", "open", "output", "overloaded", "shows",
     8.8 -  "structure", "unchecked", "uses", "where", "|"];
     8.9 +  "notes", "obtains", "open", "output", "overloaded", "pervasive",
    8.10 +  "shows", "structure", "unchecked", "uses", "where", "|"];
    8.11 +
    8.12  
    8.13  
    8.14  (** init and exit **)
    8.15 @@ -337,7 +338,7 @@
    8.16  
    8.17  val _ =
    8.18    OuterSyntax.local_theory "declaration" "generic ML declaration" (K.tag_ml K.thy_decl)
    8.19 -    (P.ML_source >> IsarCmd.declaration);
    8.20 +    (P.opt_keyword "pervasive" -- P.ML_source >> uncurry IsarCmd.declaration);
    8.21  
    8.22  val _ =
    8.23    OuterSyntax.local_theory "simproc_setup" "define simproc in ML" (K.tag_ml K.thy_decl)
     9.1 --- a/src/Pure/Isar/local_theory.ML	Fri Nov 06 09:27:20 2009 +0100
     9.2 +++ b/src/Pure/Isar/local_theory.ML	Fri Nov 06 10:26:13 2009 +0100
     9.3 @@ -27,6 +27,7 @@
     9.4    val map_contexts: (Context.generic -> Context.generic) -> local_theory -> local_theory
     9.5    val standard_morphism: local_theory -> Proof.context -> morphism
     9.6    val target_morphism: local_theory -> morphism
     9.7 +  val global_morphism: local_theory -> morphism
     9.8    val pretty: local_theory -> Pretty.T list
     9.9    val abbrev: Syntax.mode -> (binding * mixfix) * term -> local_theory ->
    9.10      (term * term) * local_theory
    9.11 @@ -35,9 +36,9 @@
    9.12    val note: string -> Attrib.binding * thm list -> local_theory -> (string * thm list) * local_theory
    9.13    val notes: string -> (Attrib.binding * (thm list * Attrib.src list) list) list ->
    9.14      local_theory -> (string * thm list) list * local_theory
    9.15 -  val type_syntax: declaration -> local_theory -> local_theory
    9.16 -  val term_syntax: declaration -> local_theory -> local_theory
    9.17 -  val declaration: declaration -> local_theory -> local_theory
    9.18 +  val type_syntax: bool -> declaration -> local_theory -> local_theory
    9.19 +  val term_syntax: bool -> declaration -> local_theory -> local_theory
    9.20 +  val declaration: bool -> declaration -> local_theory -> local_theory
    9.21    val notation: bool -> Syntax.mode -> (term * mixfix) list -> local_theory -> local_theory
    9.22    val init: string -> operations -> Proof.context -> local_theory
    9.23    val restore: local_theory -> local_theory
    9.24 @@ -65,9 +66,9 @@
    9.25    notes: string ->
    9.26      (Attrib.binding * (thm list * Attrib.src list) list) list ->
    9.27      local_theory -> (string * thm list) list * local_theory,
    9.28 -  type_syntax: declaration -> local_theory -> local_theory,
    9.29 -  term_syntax: declaration -> local_theory -> local_theory,
    9.30 -  declaration: declaration -> local_theory -> local_theory,
    9.31 +  type_syntax: bool -> declaration -> local_theory -> local_theory,
    9.32 +  term_syntax: bool -> declaration -> local_theory -> local_theory,
    9.33 +  declaration: bool -> declaration -> local_theory -> local_theory,
    9.34    reinit: local_theory -> local_theory,
    9.35    exit: local_theory -> Proof.context};
    9.36  
    9.37 @@ -174,27 +175,27 @@
    9.38    Morphism.binding_morphism (Name_Space.transform_binding (naming_of lthy));
    9.39  
    9.40  fun target_morphism lthy = standard_morphism lthy (target_of lthy);
    9.41 +fun global_morphism lthy = standard_morphism lthy (ProofContext.init (ProofContext.theory_of lthy));
    9.42  
    9.43  
    9.44  (* basic operations *)
    9.45  
    9.46  fun operation f lthy = f (#operations (get_lthy lthy)) lthy;
    9.47 -fun operation1 f x = operation (fn ops => f ops x);
    9.48  fun operation2 f x y lthy = operation (fn ops => f ops x y) lthy;
    9.49  
    9.50  val pretty = operation #pretty;
    9.51  val abbrev = apsnd checkpoint ooo operation2 #abbrev;
    9.52  val define = apsnd checkpoint ooo operation2 #define;
    9.53  val notes = apsnd checkpoint ooo operation2 #notes;
    9.54 -val type_syntax = checkpoint oo operation1 #type_syntax;
    9.55 -val term_syntax = checkpoint oo operation1 #term_syntax;
    9.56 -val declaration = checkpoint oo operation1 #declaration;
    9.57 +val type_syntax = checkpoint ooo operation2 #type_syntax;
    9.58 +val term_syntax = checkpoint ooo operation2 #term_syntax;
    9.59 +val declaration = checkpoint ooo operation2 #declaration;
    9.60  
    9.61  fun note kind (a, ths) = notes kind [(a, [(ths, [])])] #>> the_single;
    9.62  
    9.63  fun notation add mode raw_args lthy =
    9.64    let val args = map (apfst (Morphism.term (target_morphism lthy))) raw_args
    9.65 -  in term_syntax (ProofContext.target_notation add mode args) lthy end;
    9.66 +  in term_syntax false (ProofContext.target_notation add mode args) lthy end;
    9.67  
    9.68  
    9.69  (* init *)
    10.1 --- a/src/Pure/Isar/spec_rules.ML	Fri Nov 06 09:27:20 2009 +0100
    10.2 +++ b/src/Pure/Isar/spec_rules.ML	Fri Nov 06 10:26:13 2009 +0100
    10.3 @@ -1,18 +1,19 @@
    10.4  (*  Title:      Pure/Isar/spec_rules.ML
    10.5      Author:     Makarius
    10.6  
    10.7 -Rules that characterize functional/relational specifications.  NB: In
    10.8 -the face of arbitrary morphisms, the original shape of specifications
    10.9 -may get transformed almost arbitrarily.
   10.10 +Rules that characterize specifications, with rough classification.
   10.11 +NB: In the face of arbitrary morphisms, the original shape of
   10.12 +specifications may get lost.
   10.13  *)
   10.14  
   10.15  signature SPEC_RULES =
   10.16  sig
   10.17 -  datatype kind = Functional | Relational | Co_Relational
   10.18 -  val dest: Proof.context -> (kind * (term * thm list) list) list
   10.19 -  val dest_global: theory -> (kind * (term * thm list) list) list
   10.20 -  val add: kind * (term * thm list) list -> local_theory -> local_theory
   10.21 -  val add_global: kind * (term * thm list) list -> theory -> theory
   10.22 +  datatype rough_classification = Unknown | Equational | Inductive | Co_Inductive
   10.23 +  type spec = rough_classification * (term list * thm list)
   10.24 +  val get: Proof.context -> spec list
   10.25 +  val get_global: theory -> spec list
   10.26 +  val add: rough_classification -> term list * thm list -> local_theory -> local_theory
   10.27 +  val add_global: rough_classification -> term list * thm list -> theory -> theory
   10.28  end;
   10.29  
   10.30  structure Spec_Rules: SPEC_RULES =
   10.31 @@ -20,30 +21,34 @@
   10.32  
   10.33  (* maintain rules *)
   10.34  
   10.35 -datatype kind = Functional | Relational | Co_Relational;
   10.36 +datatype rough_classification = Unknown | Equational | Inductive | Co_Inductive;
   10.37 +type spec = rough_classification * (term list * thm list);
   10.38  
   10.39  structure Rules = GenericDataFun
   10.40  (
   10.41 -  type T = (kind * (term * thm list) list) Item_Net.T;
   10.42 +  type T = spec Item_Net.T;
   10.43    val empty : T =
   10.44      Item_Net.init
   10.45 -      (fn ((k1, spec1), (k2, spec2)) => k1 = k2 andalso
   10.46 -        eq_list (fn ((t1, ths1), (t2, ths2)) =>
   10.47 -          t1 aconv t2 andalso eq_list Thm.eq_thm_prop (ths1, ths2)) (spec1, spec2))
   10.48 -      (map #1 o #2);
   10.49 +      (fn ((class1, (ts1, ths1)), (class2, (ts2, ths2))) =>
   10.50 +        class1 = class2 andalso
   10.51 +        eq_list (op aconv) (ts1, ts2) andalso
   10.52 +        eq_list Thm.eq_thm_prop (ths1, ths2))
   10.53 +      (#1 o #2);
   10.54    val extend = I;
   10.55    fun merge _ = Item_Net.merge;
   10.56  );
   10.57  
   10.58 -val dest = Item_Net.content o Rules.get o Context.Proof;
   10.59 -val dest_global = Item_Net.content o Rules.get o Context.Theory;
   10.60 +val get = Item_Net.content o Rules.get o Context.Proof;
   10.61 +val get_global = Item_Net.content o Rules.get o Context.Theory;
   10.62  
   10.63 -fun add (kind, specs) = LocalTheory.declaration
   10.64 +fun add class (ts, ths) = LocalTheory.declaration true
   10.65    (fn phi =>
   10.66 -    let val specs' = map (fn (t, ths) => (Morphism.term phi t, Morphism.fact phi ths)) specs;
   10.67 -    in Rules.map (Item_Net.update (kind, specs')) end);
   10.68 +    let
   10.69 +      val ts' = map (Morphism.term phi) ts;
   10.70 +      val ths' = map (Morphism.thm phi) ths;
   10.71 +    in Rules.map (Item_Net.update (class, (ts', ths'))) end);
   10.72  
   10.73 -fun add_global entry =
   10.74 -  Context.theory_map (Rules.map (Item_Net.update entry));
   10.75 +fun add_global class spec =
   10.76 +  Context.theory_map (Rules.map (Item_Net.update (class, spec)));
   10.77  
   10.78  end;
    11.1 --- a/src/Pure/Isar/specification.ML	Fri Nov 06 09:27:20 2009 +0100
    11.2 +++ b/src/Pure/Isar/specification.ML	Fri Nov 06 10:26:13 2009 +0100
    11.3 @@ -201,19 +201,23 @@
    11.4                  Position.str_of (Binding.pos_of b));
    11.5            in (b, mx) end);
    11.6      val name = Thm.def_binding_optional b raw_name;
    11.7 -    val ((lhs, (_, th)), lthy2) = lthy
    11.8 +    val ((lhs, (_, raw_th)), lthy2) = lthy
    11.9        |> LocalTheory.define Thm.definitionK
   11.10          (var, ((Binding.suffix_name "_raw" name, []), rhs));
   11.11 -    val ((def_name, [th']), lthy3) = lthy2
   11.12 +
   11.13 +    val th = prove lthy2 raw_th;
   11.14 +    val lthy3 = lthy2 |> Spec_Rules.add Spec_Rules.Equational ([lhs], [th]);
   11.15 +
   11.16 +    val ((def_name, [th']), lthy4) = lthy3
   11.17        |> LocalTheory.note Thm.definitionK
   11.18 -        ((name, Predicate_Compile_Preproc_Const_Defs.add_attrib :: Code.add_default_eqn_attrib :: atts),
   11.19 -          [prove lthy2 th]);
   11.20 +        ((name, Predicate_Compile_Preproc_Const_Defs.add_attrib ::
   11.21 +            Code.add_default_eqn_attrib :: atts), [th]);
   11.22  
   11.23 -    val lhs' = Morphism.term (LocalTheory.target_morphism lthy3) lhs;
   11.24 +    val lhs' = Morphism.term (LocalTheory.target_morphism lthy4) lhs;
   11.25      val _ =
   11.26        if not do_print then ()
   11.27 -      else print_consts lthy3 (member (op =) (Term.add_frees lhs' [])) [(x, T)];
   11.28 -  in ((lhs, (def_name, th')), lthy3) end;
   11.29 +      else print_consts lthy4 (member (op =) (Term.add_frees lhs' [])) [(x, T)];
   11.30 +  in ((lhs, (def_name, th')), lthy4) end;
   11.31  
   11.32  val definition = gen_def false check_free_spec;
   11.33  val definition_cmd = gen_def true read_free_spec;
    12.1 --- a/src/Pure/Isar/theory_target.ML	Fri Nov 06 09:27:20 2009 +0100
    12.2 +++ b/src/Pure/Isar/theory_target.ML	Fri Nov 06 10:26:13 2009 +0100
    12.3 @@ -71,26 +71,38 @@
    12.4       else pretty_thy ctxt target is_class);
    12.5  
    12.6  
    12.7 -(* target declarations *)
    12.8 +(* generic declarations *)
    12.9 +
   12.10 +local
   12.11  
   12.12 -fun target_decl add (Target {target, ...}) d lthy =
   12.13 +fun direct_decl decl =
   12.14 +  let val decl0 = Morphism.form decl in
   12.15 +    LocalTheory.theory (Context.theory_map decl0) #>
   12.16 +    LocalTheory.target (Context.proof_map decl0)
   12.17 +  end;
   12.18 +
   12.19 +fun target_decl add (Target {target, ...}) pervasive decl lthy =
   12.20    let
   12.21 -    val d' = Morphism.transform (LocalTheory.target_morphism lthy) d;
   12.22 -    val d0 = Morphism.form d';
   12.23 +    val global_decl = Morphism.transform (LocalTheory.global_morphism lthy) decl;
   12.24 +    val target_decl = Morphism.transform (LocalTheory.target_morphism lthy) decl;
   12.25    in
   12.26      if target = "" then
   12.27        lthy
   12.28 -      |> LocalTheory.theory (Context.theory_map d0)
   12.29 -      |> LocalTheory.target (Context.proof_map d0)
   12.30 +      |> direct_decl target_decl
   12.31      else
   12.32        lthy
   12.33 -      |> LocalTheory.target (add target d')
   12.34 +      |> pervasive ? direct_decl global_decl
   12.35 +      |> LocalTheory.target (add target target_decl)
   12.36    end;
   12.37  
   12.38 +in
   12.39 +
   12.40  val type_syntax = target_decl Locale.add_type_syntax;
   12.41  val term_syntax = target_decl Locale.add_term_syntax;
   12.42  val declaration = target_decl Locale.add_declaration;
   12.43  
   12.44 +end;
   12.45 +
   12.46  fun class_target (Target {target, ...}) f =
   12.47    LocalTheory.raw_theory f #>
   12.48    LocalTheory.target (Class_Target.refresh_syntax target);
   12.49 @@ -221,7 +233,7 @@
   12.50      val t = Term.list_comb (const, map Free xs);
   12.51    in
   12.52      lthy'
   12.53 -    |> is_locale ? term_syntax ta (locale_const ta Syntax.mode_default ((b, mx2), t))
   12.54 +    |> is_locale ? term_syntax ta false (locale_const ta Syntax.mode_default ((b, mx2), t))
   12.55      |> is_class ? class_target ta (Class_Target.declare target ((b, mx1), t))
   12.56      |> LocalDefs.add_def ((b, NoSyn), t)
   12.57    end;
   12.58 @@ -246,7 +258,7 @@
   12.59          LocalTheory.theory_result (Sign.add_abbrev PrintMode.internal (b, global_rhs))
   12.60          #-> (fn (lhs, _) =>
   12.61            let val lhs' = Term.list_comb (Logic.unvarify lhs, xs) in
   12.62 -            term_syntax ta (locale_const ta prmode ((b, mx2), lhs')) #>
   12.63 +            term_syntax ta false (locale_const ta prmode ((b, mx2), lhs')) #>
   12.64              is_class ? class_target ta (Class_Target.abbrev target prmode ((b, mx1), t'))
   12.65            end)
   12.66        else
    13.1 --- a/src/Pure/Tools/named_thms.ML	Fri Nov 06 09:27:20 2009 +0100
    13.2 +++ b/src/Pure/Tools/named_thms.ML	Fri Nov 06 10:26:13 2009 +0100
    13.3 @@ -1,8 +1,7 @@
    13.4  (*  Title:      Pure/Tools/named_thms.ML
    13.5      Author:     Makarius
    13.6  
    13.7 -Named collections of theorems in canonical order.  Based on naive data
    13.8 -structures -- not scalable!
    13.9 +Named collections of theorems in canonical order.
   13.10  *)
   13.11  
   13.12  signature NAMED_THMS =
   13.13 @@ -20,22 +19,23 @@
   13.14  
   13.15  structure Data = GenericDataFun
   13.16  (
   13.17 -  type T = thm list;
   13.18 -  val empty = [];
   13.19 +  type T = thm Item_Net.T;
   13.20 +  val empty = Thm.full_rules;
   13.21    val extend = I;
   13.22 -  fun merge _ = Thm.merge_thms;
   13.23 +  fun merge _ = Item_Net.merge;
   13.24  );
   13.25  
   13.26 -val get = Data.get o Context.Proof;
   13.27 +val content = Item_Net.content o Data.get;
   13.28 +val get = content o Context.Proof;
   13.29  
   13.30 -val add_thm = Data.map o Thm.add_thm;
   13.31 -val del_thm = Data.map o Thm.del_thm;
   13.32 +val add_thm = Data.map o Item_Net.update;
   13.33 +val del_thm = Data.map o Item_Net.remove;
   13.34  
   13.35  val add = Thm.declaration_attribute add_thm;
   13.36  val del = Thm.declaration_attribute del_thm;
   13.37  
   13.38  val setup =
   13.39    Attrib.setup (Binding.name name) (Attrib.add_del add del) ("declaration of " ^ description) #>
   13.40 -  PureThy.add_thms_dynamic (Binding.name name, Data.get);
   13.41 +  PureThy.add_thms_dynamic (Binding.name name, content);
   13.42  
   13.43  end;
    14.1 --- a/src/Pure/more_thm.ML	Fri Nov 06 09:27:20 2009 +0100
    14.2 +++ b/src/Pure/more_thm.ML	Fri Nov 06 10:26:13 2009 +0100
    14.3 @@ -48,6 +48,7 @@
    14.4    val add_thm: thm -> thm list -> thm list
    14.5    val del_thm: thm -> thm list -> thm list
    14.6    val merge_thms: thm list * thm list -> thm list
    14.7 +  val full_rules: thm Item_Net.T
    14.8    val intro_rules: thm Item_Net.T
    14.9    val elim_rules: thm Item_Net.T
   14.10    val elim_implies: thm -> thm -> thm
   14.11 @@ -246,6 +247,7 @@
   14.12  val del_thm = remove eq_thm_prop;
   14.13  val merge_thms = merge eq_thm_prop;
   14.14  
   14.15 +val full_rules = Item_Net.init eq_thm_prop (single o Thm.full_prop_of);
   14.16  val intro_rules = Item_Net.init eq_thm_prop (single o Thm.concl_of);
   14.17  val elim_rules = Item_Net.init eq_thm_prop (single o Thm.major_prem_of);
   14.18  
    15.1 --- a/src/Pure/simplifier.ML	Fri Nov 06 09:27:20 2009 +0100
    15.2 +++ b/src/Pure/simplifier.ML	Fri Nov 06 10:26:13 2009 +0100
    15.3 @@ -192,7 +192,7 @@
    15.4         identifier = identifier}
    15.5        |> morph_simproc (LocalTheory.target_morphism lthy);
    15.6    in
    15.7 -    lthy |> LocalTheory.declaration (fn phi =>
    15.8 +    lthy |> LocalTheory.declaration false (fn phi =>
    15.9        let
   15.10          val b' = Morphism.binding phi b;
   15.11          val simproc' = morph_simproc phi simproc;