author | wenzelm |
Sun, 10 Dec 2006 22:27:03 +0100 | |
changeset 21761 | d4fd9bb0ccd6 |
parent 21752 | 5b7644879373 |
child 21804 | 515499542d84 |
permissions | -rw-r--r-- |
20894 | 1 |
(* Title: Pure/Isar/theory_target.ML |
2 |
ID: $Id$ |
|
3 |
Author: Makarius |
|
4 |
||
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
5 |
Common theory/locale targets. |
20894 | 6 |
*) |
7 |
||
8 |
signature THEORY_TARGET = |
|
9 |
sig |
|
21006 | 10 |
val peek: local_theory -> string option |
21747 | 11 |
val is_class: local_theory -> bool |
20962 | 12 |
val begin: bstring -> Proof.context -> local_theory |
20894 | 13 |
val init: xstring option -> theory -> local_theory |
14 |
val init_i: string option -> theory -> local_theory |
|
15 |
end; |
|
16 |
||
21747 | 17 |
|
20894 | 18 |
structure TheoryTarget: THEORY_TARGET = |
19 |
struct |
|
20 |
||
21 |
(** locale targets **) |
|
22 |
||
21006 | 23 |
(* context data *) |
24 |
||
25 |
structure Data = ProofDataFun |
|
26 |
( |
|
27 |
val name = "Isar/theory_target"; |
|
28 |
type T = string option; |
|
29 |
fun init _ = NONE; |
|
30 |
fun print _ _ = (); |
|
31 |
); |
|
32 |
||
33 |
val _ = Context.add_setup Data.init; |
|
34 |
val peek = Data.get; |
|
35 |
||
21747 | 36 |
fun is_class lthy = (* FIXME approximation *) |
37 |
(case peek lthy of |
|
38 |
NONE => false |
|
39 |
| SOME loc => can (Sign.certify_class (ProofContext.theory_of lthy)) loc); |
|
40 |
||
21006 | 41 |
|
20894 | 42 |
(* pretty *) |
43 |
||
44 |
fun pretty loc ctxt = |
|
45 |
let |
|
46 |
val thy = ProofContext.theory_of ctxt; |
|
47 |
val fixes = map (fn (x, T) => (x, SOME T, NoSyn)) (#1 (ProofContext.inferred_fixes ctxt)); |
|
21585 | 48 |
val assumes = map (fn A => (("", []), [(A, [])])) (map Thm.term_of (Assumption.assms_of ctxt)); |
20894 | 49 |
val elems = |
50 |
(if null fixes then [] else [Element.Fixes fixes]) @ |
|
51 |
(if null assumes then [] else [Element.Assumes assumes]); |
|
52 |
in |
|
20984 | 53 |
if loc = "" then |
54 |
[Pretty.block |
|
55 |
[Pretty.str "theory", Pretty.brk 1, Pretty.str (Context.theory_name thy), |
|
56 |
Pretty.str " =", Pretty.brk 1, ThyInfo.pretty_theory thy]] |
|
57 |
else if null elems then [Pretty.str ("locale " ^ Locale.extern thy loc)] |
|
58 |
else |
|
59 |
[Pretty.big_list ("locale " ^ Locale.extern thy loc ^ " =") |
|
60 |
(map (Pretty.chunks o Element.pretty_ctxt ctxt) elems)] |
|
20894 | 61 |
end; |
62 |
||
63 |
||
21747 | 64 |
(* abbrev *) |
65 |
||
66 |
val internal_abbrev = |
|
67 |
LocalTheory.term_syntax o ProofContext.target_abbrev Syntax.internal_mode; |
|
68 |
||
69 |
fun occ_params ctxt ts = |
|
70 |
#1 (ProofContext.inferred_fixes ctxt) |
|
71 |
|> filter (member (op =) (fold (Variable.add_fixed ctxt) ts [])); |
|
72 |
||
73 |
fun abbrev is_loc prmode ((raw_c, mx), raw_t) lthy = |
|
74 |
let |
|
75 |
val thy_ctxt = ProofContext.init (ProofContext.theory_of lthy); |
|
76 |
val target = LocalTheory.target_of lthy; |
|
77 |
val target_morphism = LocalTheory.target_morphism lthy; |
|
78 |
||
79 |
val c = Morphism.name target_morphism raw_c; |
|
80 |
val t = Morphism.term target_morphism raw_t; |
|
81 |
val xs = map Free (occ_params target [t]); |
|
82 |
val u = fold_rev Term.lambda xs t; |
|
83 |
val u' = singleton (Variable.export_terms (Variable.declare_term u target) thy_ctxt) u; |
|
84 |
||
85 |
val ((const, _), lthy1) = lthy |
|
86 |
|> LocalTheory.theory_result (Sign.add_abbrev (#1 prmode) (c, u')); |
|
87 |
val v = Const (#1 const, Term.fastype_of u); |
|
88 |
val v' = Const const; |
|
21761 | 89 |
(* FIXME proper handling of mixfix !? *) |
21747 | 90 |
val mx' = if is_class lthy then NoSyn else Syntax.unlocalize_mixfix is_loc mx; |
91 |
in |
|
92 |
lthy1 |
|
93 |
|> LocalTheory.theory (Sign.add_notation prmode [(v', mx')]) |
|
21752 | 94 |
|> is_loc ? internal_abbrev ((c, mx), Term.list_comb (v, xs)) |
21747 | 95 |
end; |
96 |
||
97 |
||
20894 | 98 |
(* consts *) |
99 |
||
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
100 |
fun consts is_loc depends decls lthy = |
20894 | 101 |
let |
21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset
|
102 |
val xs = filter depends (#1 (ProofContext.inferred_fixes (LocalTheory.target_of lthy))); |
20894 | 103 |
|
104 |
fun const ((c, T), mx) thy = |
|
105 |
let |
|
106 |
val U = map #2 xs ---> T; |
|
21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset
|
107 |
val t = Term.list_comb (Const (Sign.full_name thy c, U), map Free xs); |
21761 | 108 |
(* FIXME proper handling of mixfix !? *) |
21747 | 109 |
val mx' = if is_class lthy then NoSyn else Syntax.unlocalize_mixfix is_loc mx; |
110 |
val thy' = Sign.add_consts_authentic [(c, U, mx')] thy; |
|
21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset
|
111 |
in (((c, mx), t), thy') end; |
20894 | 112 |
|
21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset
|
113 |
val (abbrs, lthy') = lthy |> LocalTheory.theory_result (fold_map const decls); |
21761 | 114 |
val defs = abbrs (* FIXME proper handling of mixfix !? *) |
115 |
|> map (fn ((c, mx), t) => ((c, if is_loc then mx else NoSyn), (("", []), t))); |
|
20894 | 116 |
in |
117 |
lthy' |
|
21747 | 118 |
|> is_loc ? fold internal_abbrev abbrs |
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
119 |
|> LocalDefs.add_defs defs |>> map (apsnd snd) |
20894 | 120 |
end; |
121 |
||
122 |
||
123 |
(* defs *) |
|
124 |
||
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
125 |
local |
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
126 |
|
21570 | 127 |
infix also; |
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
128 |
|
21570 | 129 |
fun eq1 also eq2 = |
130 |
eq2 COMP (eq1 COMP (Drule.incr_indexes2 eq1 eq2 transitive_thm)); |
|
131 |
||
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
132 |
fun expand_term ctxt t = |
21570 | 133 |
let |
134 |
val thy = ProofContext.theory_of ctxt; |
|
135 |
val thy_ctxt = ProofContext.init thy; |
|
136 |
val ct = Thm.cterm_of thy t; |
|
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
137 |
val (defs, ct') = LocalDefs.export ctxt thy_ctxt (Drule.mk_term ct) ||> Drule.dest_term; |
21708 | 138 |
in (Thm.term_of ct', MetaSimplifier.rewrite true defs ct) end; |
21570 | 139 |
|
20894 | 140 |
fun add_def (name, prop) = |
141 |
Theory.add_defs_i false false [(name, prop)] #> |
|
142 |
(fn thy => (Drule.unvarify (Thm.get_axiom_i thy (Sign.full_name thy name)), thy)); |
|
143 |
||
144 |
in |
|
145 |
||
21570 | 146 |
fun defs kind args lthy0 = |
20894 | 147 |
let |
21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset
|
148 |
fun def ((c, mx), ((name, atts), rhs)) lthy1 = |
20894 | 149 |
let |
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
150 |
val (rhs', rhs_conv) = expand_term lthy0 rhs; |
21570 | 151 |
val xs = Variable.add_fixed (LocalTheory.target_of lthy0) rhs' []; |
20894 | 152 |
|
21570 | 153 |
val ([(lhs, lhs_def)], lthy2) = lthy1 |
154 |
|> LocalTheory.consts (member (op =) xs) [((c, Term.fastype_of rhs), mx)]; |
|
155 |
val lhs' = #2 (Logic.dest_equals (Thm.prop_of lhs_def)); |
|
21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset
|
156 |
|
21570 | 157 |
val name' = Thm.def_name_optional c name; |
158 |
val (def, lthy3) = lthy2 |
|
20894 | 159 |
|> LocalTheory.theory_result (add_def (name', Logic.mk_equals (lhs', rhs'))); |
160 |
||
21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset
|
161 |
val eq = |
21570 | 162 |
(*c == loc.c xs*) lhs_def |
163 |
(*lhs' == rhs'*) also def |
|
164 |
(*rhs' == rhs*) also Thm.symmetric rhs_conv; |
|
20894 | 165 |
in ((lhs, ((name', atts), [([eq], [])])), lthy3) end; |
166 |
||
21570 | 167 |
val ((lhss, facts), lthy') = lthy0 |> fold_map def args |>> split_list; |
21433 | 168 |
val (res, lthy'') = lthy' |> LocalTheory.notes kind facts; |
20894 | 169 |
in (lhss ~~ map (apsnd the_single) res, lthy'') end; |
170 |
||
171 |
end; |
|
172 |
||
173 |
||
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
174 |
(* axioms *) |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
175 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
176 |
local |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
177 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
178 |
fun add_axiom hyps (name, prop) thy = |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
179 |
let |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
180 |
val name' = if name = "" then "axiom_" ^ serial_string () else name; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
181 |
val prop' = Logic.list_implies (hyps, prop); |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
182 |
val thy' = thy |> Theory.add_axioms_i [(name', prop')]; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
183 |
val axm = Drule.unvarify (Thm.get_axiom_i thy' (Sign.full_name thy' name')); |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
184 |
val prems = map (Thm.assume o Thm.cterm_of thy') hyps; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
185 |
in (Drule.implies_elim_list axm prems, thy') end; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
186 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
187 |
in |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
188 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
189 |
fun axioms kind specs lthy = |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
190 |
let |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
191 |
val hyps = map Thm.term_of (Assumption.assms_of lthy); |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
192 |
fun axiom ((name, atts), props) thy = thy |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
193 |
|> fold_map (add_axiom hyps) (PureThy.name_multi name props) |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
194 |
|-> (fn ths => pair ((name, atts), [(ths, [])])); |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
195 |
in |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
196 |
lthy |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
197 |
|> fold (fold Variable.declare_term o snd) specs |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
198 |
|> LocalTheory.theory_result (fold_map axiom specs) |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
199 |
|-> LocalTheory.notes kind |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
200 |
end; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
201 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
202 |
end; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
203 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
204 |
|
20894 | 205 |
(* notes *) |
206 |
||
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
207 |
fun import_export_proof ctxt (name, raw_th) = |
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
208 |
let |
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
209 |
val thy = ProofContext.theory_of ctxt; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
210 |
val thy_ctxt = ProofContext.init thy; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
211 |
val certT = Thm.ctyp_of thy; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
212 |
val cert = Thm.cterm_of thy; |
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
213 |
|
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
214 |
(*export assumes/defines*) |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
215 |
val th = Goal.norm_result raw_th; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
216 |
val (defs, th') = LocalDefs.export ctxt thy_ctxt th; |
21708 | 217 |
val concl_conv = MetaSimplifier.rewrite true defs (Thm.cprop_of th); |
218 |
val assms = map (MetaSimplifier.rewrite_rule defs o Thm.assume) (Assumption.assms_of ctxt); |
|
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
219 |
val nprems = Thm.nprems_of th' - Thm.nprems_of th; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
220 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
221 |
(*export fixes*) |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
222 |
val tfrees = map TFree (Drule.fold_terms Term.add_tfrees th' []); |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
223 |
val frees = map Free (Drule.fold_terms Term.add_frees th' []); |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
224 |
val (th'' :: vs) = (th' :: map (Drule.mk_term o cert) (map Logic.mk_type tfrees @ frees)) |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
225 |
|> Variable.export ctxt thy_ctxt |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
226 |
|> Drule.zero_var_indexes_list; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
227 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
228 |
(*thm definition*) |
21644 | 229 |
val result = th'' |
230 |
|> PureThy.name_thm true true "" |
|
231 |
|> Goal.close_result |
|
232 |
|> PureThy.name_thm true true name; |
|
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
233 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
234 |
(*import fixes*) |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
235 |
val (tvars, vars) = |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
236 |
chop (length tfrees) (map (Thm.term_of o Drule.dest_term) vs) |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
237 |
|>> map Logic.dest_type; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
238 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
239 |
val instT = map_filter (fn (TVar v, T) => SOME (v, T) | _ => NONE) (tvars ~~ tfrees); |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
240 |
val inst = filter (is_Var o fst) (vars ~~ frees); |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
241 |
val cinstT = map (pairself certT o apfst TVar) instT; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
242 |
val cinst = map (pairself (cert o Term.map_types (TermSubst.instantiateT instT))) inst; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
243 |
val result' = Thm.instantiate (cinstT, cinst) result; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
244 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
245 |
(*import assumes/defines*) |
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
246 |
val assm_tac = FIRST' (map (fn assm => Tactic.compose_tac (false, assm, 0)) assms); |
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
247 |
val result'' = |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
248 |
(case SINGLE (Seq.INTERVAL assm_tac 1 nprems) result' of |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
249 |
NONE => raise THM ("Failed to re-import result", 0, [result']) |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
250 |
| SOME res => res) COMP (concl_conv COMP_INCR Drule.equal_elim_rule2) |
21644 | 251 |
|> Goal.norm_result |
252 |
|> PureThy.name_thm false false name; |
|
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
253 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
254 |
in (result'', result) end; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
255 |
|
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
256 |
fun notes loc kind facts lthy = |
21585 | 257 |
let |
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
258 |
val is_loc = loc <> ""; |
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
259 |
val thy = ProofContext.theory_of lthy; |
21615
1bd558879c44
notes: proper naming of thm proof, activated import_export_proof;
wenzelm
parents:
21613
diff
changeset
|
260 |
val full = LocalTheory.full_name lthy; |
21585 | 261 |
|
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
262 |
val facts' = facts |
21615
1bd558879c44
notes: proper naming of thm proof, activated import_export_proof;
wenzelm
parents:
21613
diff
changeset
|
263 |
|> map (fn (a, bs) => (a, PureThy.burrow_fact (PureThy.name_multi (full (fst a))) bs)) |
1bd558879c44
notes: proper naming of thm proof, activated import_export_proof;
wenzelm
parents:
21613
diff
changeset
|
264 |
|> PureThy.map_facts (import_export_proof lthy); |
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
265 |
val local_facts = PureThy.map_facts #1 facts' |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
266 |
|> Attrib.map_facts (Attrib.attribute_i thy); |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
267 |
val target_facts = PureThy.map_facts #1 facts' |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
268 |
|> is_loc ? Element.facts_map (Element.morph_ctxt (LocalTheory.target_morphism lthy)); |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
269 |
val global_facts = PureThy.map_facts #2 facts' |
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
270 |
|> Attrib.map_facts (if is_loc then K I else Attrib.attribute_i thy); |
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
271 |
in |
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
272 |
lthy |> LocalTheory.theory |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
273 |
(Sign.qualified_names |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
274 |
#> PureThy.note_thmss_i kind global_facts #> snd |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
275 |
#> Sign.restore_naming thy) |
21585 | 276 |
|
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
277 |
|> is_loc ? LocalTheory.target (Locale.add_thmss loc kind target_facts) |
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
278 |
|
21433 | 279 |
|> ProofContext.set_stmt true |
20894 | 280 |
|> ProofContext.qualified_names |
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
281 |
|> ProofContext.note_thmss_i kind local_facts |
20894 | 282 |
||> ProofContext.restore_naming lthy |
21433 | 283 |
||> ProofContext.restore_stmt lthy |
20894 | 284 |
end; |
285 |
||
286 |
||
21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset
|
287 |
(* target declarations *) |
20894 | 288 |
|
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
289 |
fun target_decl _ "" f = |
21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset
|
290 |
LocalTheory.theory (Context.theory_map (f Morphism.identity)) #> |
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset
|
291 |
LocalTheory.target (Context.proof_map (f Morphism.identity)) |
21668 | 292 |
| target_decl add loc f = LocalTheory.target (add loc f); |
20894 | 293 |
|
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
294 |
val type_syntax = target_decl Locale.add_type_syntax; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
295 |
val term_syntax = target_decl Locale.add_term_syntax; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
296 |
val declaration = target_decl Locale.add_declaration; |
20894 | 297 |
|
21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset
|
298 |
fun target_morphism loc lthy = |
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
299 |
ProofContext.export_morphism lthy (LocalTheory.target_of lthy) $> |
21613
ae3bb930b50f
notes: more careful treatment of Goal.close_result;
wenzelm
parents:
21611
diff
changeset
|
300 |
Morphism.thm_morphism Goal.norm_result; |
21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset
|
301 |
|
21668 | 302 |
fun target_name loc lthy = |
303 |
(if loc = "" then Sign.naming_of (ProofContext.theory_of lthy) |
|
304 |
else ProofContext.naming_of (LocalTheory.target_of lthy)) |
|
305 |
|> NameSpace.qualified_names |
|
306 |
|> NameSpace.full; |
|
21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset
|
307 |
|
20894 | 308 |
|
309 |
(* init and exit *) |
|
310 |
||
21293 | 311 |
fun begin loc = |
21747 | 312 |
let val is_loc = loc <> "" in |
313 |
Data.put (if is_loc then SOME loc else NONE) #> |
|
314 |
LocalTheory.init (NameSpace.base loc) |
|
315 |
{pretty = pretty loc, |
|
316 |
consts = consts is_loc, |
|
317 |
axioms = axioms, |
|
318 |
abbrev = abbrev is_loc, |
|
319 |
defs = defs, |
|
320 |
notes = notes loc, |
|
321 |
type_syntax = type_syntax loc, |
|
322 |
term_syntax = term_syntax loc, |
|
323 |
declaration = declaration loc, |
|
324 |
target_morphism = target_morphism loc, |
|
325 |
target_name = target_name loc, |
|
326 |
reinit = fn _ => begin loc o (if is_loc then Locale.init loc else ProofContext.init), |
|
327 |
exit = LocalTheory.target_of} |
|
328 |
end; |
|
20894 | 329 |
|
20962 | 330 |
fun init_i NONE thy = begin "" (ProofContext.init thy) |
331 |
| init_i (SOME loc) thy = begin loc (Locale.init loc thy); |
|
20894 | 332 |
|
21276 | 333 |
fun init (SOME "-") thy = init_i NONE thy |
334 |
| init loc thy = init_i (Option.map (Locale.intern thy) loc) thy; |
|
20894 | 335 |
|
336 |
end; |