1.1 --- a/src/Pure/IsaMakefile Tue Aug 10 13:58:26 2010 +0200
1.2 +++ b/src/Pure/IsaMakefile Tue Aug 10 14:06:38 2010 +0200
1.3 @@ -62,10 +62,10 @@
1.4 General/yxml.ML Isar/args.ML Isar/attrib.ML Isar/auto_bind.ML \
1.5 Isar/calculation.ML Isar/class.ML Isar/class_target.ML Isar/code.ML \
1.6 Isar/constdefs.ML Isar/context_rules.ML Isar/element.ML \
1.7 - Isar/expression.ML Isar/isar_cmd.ML Isar/isar_document.ML \
1.8 - Isar/isar_syn.ML Isar/keyword.ML Isar/local_defs.ML \
1.9 - Isar/local_syntax.ML Isar/local_theory.ML Isar/locale.ML \
1.10 - Isar/method.ML Isar/object_logic.ML Isar/obtain.ML \
1.11 + Isar/expression.ML Isar/generic_target.ML Isar/isar_cmd.ML \
1.12 + Isar/isar_document.ML Isar/isar_syn.ML Isar/keyword.ML \
1.13 + Isar/local_defs.ML Isar/local_syntax.ML Isar/local_theory.ML \
1.14 + Isar/locale.ML Isar/method.ML Isar/object_logic.ML Isar/obtain.ML \
1.15 Isar/outer_syntax.ML Isar/overloading.ML Isar/parse.ML \
1.16 Isar/parse_spec.ML Isar/parse_value.ML Isar/proof.ML \
1.17 Isar/proof_context.ML Isar/proof_display.ML Isar/proof_node.ML \
2.1 --- a/src/Pure/Isar/theory_target.ML Tue Aug 10 13:58:26 2010 +0200
2.2 +++ b/src/Pure/Isar/theory_target.ML Tue Aug 10 14:06:38 2010 +0200
2.3 @@ -5,163 +5,6 @@
2.4 Common theory/locale/class/instantiation/overloading targets.
2.5 *)
2.6
2.7 -signature GENERIC_TARGET =
2.8 -sig
2.9 - val notes: (string
2.10 - -> (Attrib.binding * (thm list * Args.src list) list) list
2.11 - -> (Attrib.binding * (thm list * Args.src list) list) list
2.12 - -> local_theory -> local_theory)
2.13 - -> string -> (Attrib.binding * (thm list * Args.src list) list) list
2.14 - -> local_theory -> (string * thm list) list * local_theory
2.15 - val define: (((binding * typ) * mixfix) * term -> binding -> term list
2.16 - -> (string * sort) list * term list -> local_theory -> (term * thm) * local_theory)
2.17 - -> (binding * mixfix) * (Attrib.binding * term) -> local_theory
2.18 - -> (term * (string * thm)) * local_theory
2.19 - val abbrev: (string * bool -> binding * mixfix -> term * term -> (string * sort) list * term list
2.20 - -> local_theory -> local_theory)
2.21 - -> string * bool -> (binding * mixfix) * term -> local_theory -> (term * term) * local_theory
2.22 -end;
2.23 -
2.24 -structure Generic_Target: GENERIC_TARGET =
2.25 -struct
2.26 -
2.27 -(* notes *)
2.28 -
2.29 -fun import_export_proof ctxt (name, raw_th) =
2.30 - let
2.31 - val thy = ProofContext.theory_of ctxt;
2.32 - val thy_ctxt = ProofContext.init_global thy;
2.33 - val certT = Thm.ctyp_of thy;
2.34 - val cert = Thm.cterm_of thy;
2.35 -
2.36 - (*export assumes/defines*)
2.37 - val th = Goal.norm_result raw_th;
2.38 - val (defs, th') = Local_Defs.export ctxt thy_ctxt th;
2.39 - val assms = map (MetaSimplifier.rewrite_rule defs o Thm.assume) (Assumption.all_assms_of ctxt);
2.40 - val nprems = Thm.nprems_of th' - Thm.nprems_of th;
2.41 -
2.42 - (*export fixes*)
2.43 - val tfrees = map TFree (Thm.fold_terms Term.add_tfrees th' []);
2.44 - val frees = map Free (Thm.fold_terms Term.add_frees th' []);
2.45 - val (th'' :: vs) = (th' :: map (Drule.mk_term o cert) (map Logic.mk_type tfrees @ frees))
2.46 - |> Variable.export ctxt thy_ctxt
2.47 - |> Drule.zero_var_indexes_list;
2.48 -
2.49 - (*thm definition*)
2.50 - val result = PureThy.name_thm true true name th'';
2.51 -
2.52 - (*import fixes*)
2.53 - val (tvars, vars) =
2.54 - chop (length tfrees) (map (Thm.term_of o Drule.dest_term) vs)
2.55 - |>> map Logic.dest_type;
2.56 -
2.57 - val instT = map_filter (fn (TVar v, T) => SOME (v, T) | _ => NONE) (tvars ~~ tfrees);
2.58 - val inst = filter (is_Var o fst) (vars ~~ frees);
2.59 - val cinstT = map (pairself certT o apfst TVar) instT;
2.60 - val cinst = map (pairself (cert o Term.map_types (Term_Subst.instantiateT instT))) inst;
2.61 - val result' = Thm.instantiate (cinstT, cinst) result;
2.62 -
2.63 - (*import assumes/defines*)
2.64 - val assm_tac = FIRST' (map (fn assm => Tactic.compose_tac (false, assm, 0)) assms);
2.65 - val result'' =
2.66 - (case SINGLE (Seq.INTERVAL assm_tac 1 nprems) result' of
2.67 - NONE => raise THM ("Failed to re-import result", 0, [result'])
2.68 - | SOME res => Local_Defs.contract ctxt defs (Thm.cprop_of th) res)
2.69 - |> Goal.norm_result
2.70 - |> PureThy.name_thm false false name;
2.71 -
2.72 - in (result'', result) end;
2.73 -
2.74 -fun notes target_notes kind facts lthy =
2.75 - let
2.76 - val thy = ProofContext.theory_of lthy;
2.77 - val facts' = facts
2.78 - |> map (fn (a, bs) => (a, PureThy.burrow_fact (PureThy.name_multi
2.79 - (Local_Theory.full_name lthy (fst a))) bs))
2.80 - |> PureThy.map_facts (import_export_proof lthy);
2.81 - val local_facts = PureThy.map_facts #1 facts';
2.82 - val global_facts = PureThy.map_facts #2 facts';
2.83 - in
2.84 - lthy
2.85 - |> target_notes kind global_facts local_facts
2.86 - |> ProofContext.note_thmss kind (Attrib.map_facts (Attrib.attribute_i thy) local_facts)
2.87 - end;
2.88 -
2.89 -
2.90 -(* define *)
2.91 -
2.92 -fun define foundation ((b, mx), ((name, atts), rhs)) lthy =
2.93 - let
2.94 - val thy = ProofContext.theory_of lthy;
2.95 - val thy_ctxt = ProofContext.init_global thy;
2.96 -
2.97 - val name' = Thm.def_binding_optional b name;
2.98 -
2.99 - (*term and type parameters*)
2.100 - val crhs = Thm.cterm_of thy rhs;
2.101 - val (defs, rhs') = Local_Defs.export_cterm lthy thy_ctxt crhs ||> Thm.term_of;
2.102 - val rhs_conv = MetaSimplifier.rewrite true defs crhs;
2.103 -
2.104 - val xs = Variable.add_fixed (Local_Theory.target_of lthy) rhs' [];
2.105 - val T = Term.fastype_of rhs;
2.106 - val tfreesT = Term.add_tfreesT T (fold (Term.add_tfreesT o #2) xs []);
2.107 - val extra_tfrees = rev (subtract (op =) tfreesT (Term.add_tfrees rhs []));
2.108 -
2.109 - val type_params = map (Logic.mk_type o TFree) extra_tfrees;
2.110 - val term_params =
2.111 - rev (Variable.fixes_of (Local_Theory.target_of lthy))
2.112 - |> map_filter (fn (_, x) =>
2.113 - (case AList.lookup (op =) xs x of
2.114 - SOME T => SOME (Free (x, T))
2.115 - | NONE => NONE));
2.116 - val params = type_params @ term_params;
2.117 -
2.118 - val U = map Term.fastype_of params ---> T;
2.119 -
2.120 - (*foundation*)
2.121 - val ((lhs', global_def), lthy3) = foundation
2.122 - (((b, U), mx), rhs') name' params (extra_tfrees, type_params) lthy;
2.123 -
2.124 - (*local definition*)
2.125 - val ((lhs, local_def), lthy4) = lthy3
2.126 - |> Local_Defs.add_def ((b, NoSyn), lhs');
2.127 - val def = Local_Defs.trans_terms lthy4
2.128 - [(*c == global.c xs*) local_def,
2.129 - (*global.c xs == rhs'*) global_def,
2.130 - (*rhs' == rhs*) Thm.symmetric rhs_conv];
2.131 -
2.132 - (*note*)
2.133 - val ([(res_name, [res])], lthy5) = lthy4
2.134 - |> Local_Theory.notes_kind "" [((name', atts), [([def], [])])];
2.135 - in ((lhs, (res_name, res)), lthy5) end;
2.136 -
2.137 -
2.138 -(* abbrev *)
2.139 -
2.140 -fun abbrev target_abbrev prmode ((b, mx), t) lthy =
2.141 - let
2.142 - val thy_ctxt = ProofContext.init_global (ProofContext.theory_of lthy);
2.143 - val target_ctxt = Local_Theory.target_of lthy;
2.144 -
2.145 - val t' = Assumption.export_term lthy target_ctxt t;
2.146 - val xs = map Free (rev (Variable.add_fixed target_ctxt t' []));
2.147 - val u = fold_rev lambda xs t';
2.148 -
2.149 - val extra_tfrees =
2.150 - subtract (op =) (Term.add_tfreesT (Term.fastype_of u) []) (Term.add_tfrees u []);
2.151 -
2.152 - val global_rhs =
2.153 - singleton (Variable.export_terms (Variable.declare_term u target_ctxt) thy_ctxt) u;
2.154 - in
2.155 - lthy
2.156 - |> target_abbrev prmode (b, mx) (global_rhs, t') (extra_tfrees, xs)
2.157 - |> ProofContext.add_abbrev Print_Mode.internal (b, t) |> snd
2.158 - |> Local_Defs.fixed_abbrev ((b, NoSyn), t)
2.159 - end;
2.160 -
2.161 -end;
2.162 -
2.163 -
2.164 signature THEORY_TARGET =
2.165 sig
2.166 val peek: local_theory ->
3.1 --- a/src/Pure/ROOT.ML Tue Aug 10 13:58:26 2010 +0200
3.2 +++ b/src/Pure/ROOT.ML Tue Aug 10 14:06:38 2010 +0200
3.3 @@ -204,6 +204,7 @@
3.4
3.5 (*local theories and targets*)
3.6 use "Isar/local_theory.ML";
3.7 +use "Isar/generic_target.ML";
3.8 use "Isar/overloading.ML";
3.9 use "Isar/locale.ML";
3.10 use "axclass.ML";