author | wenzelm |
Wed, 26 Sep 2007 22:21:02 +0200 | |
changeset 24734 | ff617b6711f4 |
parent 24657 | 185502d54c3d |
child 24748 | ee0a0eb6b738 |
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 |
22353 | 11 |
val begin: bstring -> Proof.context -> local_theory |
20894 | 12 |
val init: xstring option -> theory -> local_theory |
13 |
val init_i: string option -> theory -> local_theory |
|
14 |
end; |
|
15 |
||
16 |
structure TheoryTarget: THEORY_TARGET = |
|
17 |
struct |
|
18 |
||
19 |
(** locale targets **) |
|
20 |
||
21006 | 21 |
(* context data *) |
22 |
||
23 |
structure Data = ProofDataFun |
|
24 |
( |
|
25 |
type T = string option; |
|
26 |
fun init _ = NONE; |
|
27 |
); |
|
28 |
||
29 |
val peek = Data.get; |
|
30 |
||
31 |
||
20894 | 32 |
(* pretty *) |
33 |
||
34 |
fun pretty loc ctxt = |
|
35 |
let |
|
36 |
val thy = ProofContext.theory_of ctxt; |
|
37 |
val fixes = map (fn (x, T) => (x, SOME T, NoSyn)) (#1 (ProofContext.inferred_fixes ctxt)); |
|
21585 | 38 |
val assumes = map (fn A => (("", []), [(A, [])])) (map Thm.term_of (Assumption.assms_of ctxt)); |
20894 | 39 |
val elems = |
40 |
(if null fixes then [] else [Element.Fixes fixes]) @ |
|
41 |
(if null assumes then [] else [Element.Assumes assumes]); |
|
42 |
in |
|
20984 | 43 |
if loc = "" then |
44 |
[Pretty.block |
|
45 |
[Pretty.str "theory", Pretty.brk 1, Pretty.str (Context.theory_name thy), |
|
46 |
Pretty.str " =", Pretty.brk 1, ThyInfo.pretty_theory thy]] |
|
47 |
else if null elems then [Pretty.str ("locale " ^ Locale.extern thy loc)] |
|
48 |
else |
|
49 |
[Pretty.big_list ("locale " ^ Locale.extern thy loc ^ " =") |
|
50 |
(map (Pretty.chunks o Element.pretty_ctxt ctxt) elems)] |
|
20894 | 51 |
end; |
52 |
||
53 |
||
21804 | 54 |
(* consts *) |
55 |
||
23205
b12f1c03cc9a
added target/local_abbrev (from proof_context.ML);
wenzelm
parents:
23087
diff
changeset
|
56 |
fun target_abbrev prmode ((c, mx), rhs) phi = |
b12f1c03cc9a
added target/local_abbrev (from proof_context.ML);
wenzelm
parents:
23087
diff
changeset
|
57 |
let |
b12f1c03cc9a
added target/local_abbrev (from proof_context.ML);
wenzelm
parents:
23087
diff
changeset
|
58 |
val c' = Morphism.name phi c; |
b12f1c03cc9a
added target/local_abbrev (from proof_context.ML);
wenzelm
parents:
23087
diff
changeset
|
59 |
val rhs' = Morphism.term phi rhs; |
b12f1c03cc9a
added target/local_abbrev (from proof_context.ML);
wenzelm
parents:
23087
diff
changeset
|
60 |
val arg' = (c', rhs'); |
b12f1c03cc9a
added target/local_abbrev (from proof_context.ML);
wenzelm
parents:
23087
diff
changeset
|
61 |
val eq_heads = |
b12f1c03cc9a
added target/local_abbrev (from proof_context.ML);
wenzelm
parents:
23087
diff
changeset
|
62 |
(case pairself Term.head_of (rhs, rhs') of |
b12f1c03cc9a
added target/local_abbrev (from proof_context.ML);
wenzelm
parents:
23087
diff
changeset
|
63 |
(Const (a, _), Const (a', _)) => a = a' |
b12f1c03cc9a
added target/local_abbrev (from proof_context.ML);
wenzelm
parents:
23087
diff
changeset
|
64 |
| _ => false); |
b12f1c03cc9a
added target/local_abbrev (from proof_context.ML);
wenzelm
parents:
23087
diff
changeset
|
65 |
in |
b12f1c03cc9a
added target/local_abbrev (from proof_context.ML);
wenzelm
parents:
23087
diff
changeset
|
66 |
eq_heads ? (Context.mapping_result |
b12f1c03cc9a
added target/local_abbrev (from proof_context.ML);
wenzelm
parents:
23087
diff
changeset
|
67 |
(Sign.add_abbrev Syntax.internalM arg') (ProofContext.add_abbrev Syntax.internalM arg') |
b12f1c03cc9a
added target/local_abbrev (from proof_context.ML);
wenzelm
parents:
23087
diff
changeset
|
68 |
#-> (fn (lhs, _) => |
b12f1c03cc9a
added target/local_abbrev (from proof_context.ML);
wenzelm
parents:
23087
diff
changeset
|
69 |
Term.equiv_types (rhs, rhs') ? |
b12f1c03cc9a
added target/local_abbrev (from proof_context.ML);
wenzelm
parents:
23087
diff
changeset
|
70 |
Morphism.form (ProofContext.target_notation prmode [(lhs, mx)]))) |
b12f1c03cc9a
added target/local_abbrev (from proof_context.ML);
wenzelm
parents:
23087
diff
changeset
|
71 |
end; |
b12f1c03cc9a
added target/local_abbrev (from proof_context.ML);
wenzelm
parents:
23087
diff
changeset
|
72 |
|
21825 | 73 |
fun internal_abbrev prmode ((c, mx), t) = |
22380 | 74 |
(* FIXME really permissive *) |
23205
b12f1c03cc9a
added target/local_abbrev (from proof_context.ML);
wenzelm
parents:
23087
diff
changeset
|
75 |
LocalTheory.term_syntax (perhaps o try o target_abbrev prmode ((c, mx), t)) |
23087 | 76 |
#> ProofContext.add_abbrev Syntax.internalM (c, t) #> snd; |
21804 | 77 |
|
22353 | 78 |
fun consts is_loc some_class depends decls lthy = |
21804 | 79 |
let |
80 |
val xs = filter depends (#1 (ProofContext.inferred_fixes (LocalTheory.target_of lthy))); |
|
21747 | 81 |
|
21804 | 82 |
fun const ((c, T), mx) thy = |
83 |
let |
|
84 |
val U = map #2 xs ---> T; |
|
85 |
val t = Term.list_comb (Const (Sign.full_name thy c, U), map Free xs); |
|
24218 | 86 |
val (mx1, mx2) = Class.fork_mixfix is_loc some_class mx; |
21804 | 87 |
val thy' = Sign.add_consts_authentic [(c, U, mx1)] thy; |
88 |
in (((c, mx2), t), thy') end; |
|
89 |
||
23087 | 90 |
fun const_class (SOME class) ((c, _), mx) (_, t) = |
24218 | 91 |
Class.add_const_in_class class ((c, t), mx) |
23087 | 92 |
| const_class NONE _ _ = I; |
24657 | 93 |
fun hide_abbrev (SOME class) abbrs thy = |
94 |
let |
|
95 |
val raw_cs = map (fst o fst) abbrs; |
|
96 |
val prfx = (Logic.const_of_class o NameSpace.base) class; |
|
97 |
fun mk_name c = |
|
98 |
let |
|
99 |
val n1 = Sign.full_name thy c; |
|
100 |
val n2 = NameSpace.qualifier n1; |
|
101 |
val n3 = NameSpace.base n1; |
|
102 |
in NameSpace.implode [n2, prfx, prfx, n3] end; |
|
103 |
val cs = map mk_name raw_cs; |
|
104 |
in |
|
105 |
Sign.hide_consts_i true cs thy |
|
106 |
end |
|
107 |
| hide_abbrev NONE _ thy = thy; |
|
23087 | 108 |
val (abbrs, lthy') = lthy |
109 |
|> LocalTheory.theory_result (fold_map const decls) |
|
21804 | 110 |
val defs = map (apsnd (pair ("", []))) abbrs; |
24657 | 111 |
|
21804 | 112 |
in |
113 |
lthy' |
|
24657 | 114 |
|> LocalTheory.raw_theory (fold2 (const_class some_class) decls abbrs) |
21825 | 115 |
|> is_loc ? fold (internal_abbrev Syntax.default_mode) abbrs |
24657 | 116 |
|> LocalTheory.raw_theory (hide_abbrev some_class abbrs) |
117 |
(*FIXME abbreviations should never occur*) |
|
23087 | 118 |
|> LocalDefs.add_defs defs |
119 |
|>> map (apsnd snd) |
|
21804 | 120 |
end; |
121 |
||
122 |
||
123 |
(* abbrev *) |
|
21747 | 124 |
|
125 |
fun occ_params ctxt ts = |
|
126 |
#1 (ProofContext.inferred_fixes ctxt) |
|
127 |
|> filter (member (op =) (fold (Variable.add_fixed ctxt) ts [])); |
|
128 |
||
23205
b12f1c03cc9a
added target/local_abbrev (from proof_context.ML);
wenzelm
parents:
23087
diff
changeset
|
129 |
fun local_abbrev (x, rhs) = |
b12f1c03cc9a
added target/local_abbrev (from proof_context.ML);
wenzelm
parents:
23087
diff
changeset
|
130 |
Variable.add_fixes [x] #-> (fn [x'] => |
b12f1c03cc9a
added target/local_abbrev (from proof_context.ML);
wenzelm
parents:
23087
diff
changeset
|
131 |
let |
b12f1c03cc9a
added target/local_abbrev (from proof_context.ML);
wenzelm
parents:
23087
diff
changeset
|
132 |
val T = Term.fastype_of rhs; |
b12f1c03cc9a
added target/local_abbrev (from proof_context.ML);
wenzelm
parents:
23087
diff
changeset
|
133 |
val lhs = Free (x', T); |
b12f1c03cc9a
added target/local_abbrev (from proof_context.ML);
wenzelm
parents:
23087
diff
changeset
|
134 |
in |
b12f1c03cc9a
added target/local_abbrev (from proof_context.ML);
wenzelm
parents:
23087
diff
changeset
|
135 |
Variable.declare_term lhs #> |
b12f1c03cc9a
added target/local_abbrev (from proof_context.ML);
wenzelm
parents:
23087
diff
changeset
|
136 |
Variable.declare_term rhs #> |
b12f1c03cc9a
added target/local_abbrev (from proof_context.ML);
wenzelm
parents:
23087
diff
changeset
|
137 |
Assumption.add_assms (K (K (I, Envir.expand_term_frees [((x', T), rhs)]))) [] #> snd #> |
b12f1c03cc9a
added target/local_abbrev (from proof_context.ML);
wenzelm
parents:
23087
diff
changeset
|
138 |
pair (lhs, rhs) |
b12f1c03cc9a
added target/local_abbrev (from proof_context.ML);
wenzelm
parents:
23087
diff
changeset
|
139 |
end); |
b12f1c03cc9a
added target/local_abbrev (from proof_context.ML);
wenzelm
parents:
23087
diff
changeset
|
140 |
|
23087 | 141 |
fun abbrev is_loc some_class prmode ((raw_c, mx), raw_t) lthy = |
21747 | 142 |
let |
143 |
val thy_ctxt = ProofContext.init (ProofContext.theory_of lthy); |
|
144 |
val target = LocalTheory.target_of lthy; |
|
145 |
val target_morphism = LocalTheory.target_morphism lthy; |
|
146 |
||
147 |
val c = Morphism.name target_morphism raw_c; |
|
148 |
val t = Morphism.term target_morphism raw_t; |
|
149 |
val xs = map Free (occ_params target [t]); |
|
150 |
val u = fold_rev Term.lambda xs t; |
|
21804 | 151 |
val U = Term.fastype_of u; |
21747 | 152 |
val u' = singleton (Variable.export_terms (Variable.declare_term u target) thy_ctxt) u; |
153 |
||
21804 | 154 |
val ((lhs as Const (full_c, _), rhs), lthy1) = lthy |
21747 | 155 |
|> LocalTheory.theory_result (Sign.add_abbrev (#1 prmode) (c, u')); |
24218 | 156 |
val (mx1, mx2) = Class.fork_mixfix is_loc some_class mx; |
21747 | 157 |
in |
158 |
lthy1 |
|
21804 | 159 |
|> LocalTheory.theory (Sign.add_notation prmode [(lhs, mx1)]) |
21825 | 160 |
|> is_loc ? internal_abbrev prmode ((c, mx2), Term.list_comb (Const (full_c, U), xs)) |
23205
b12f1c03cc9a
added target/local_abbrev (from proof_context.ML);
wenzelm
parents:
23087
diff
changeset
|
161 |
|> local_abbrev (c, rhs) |
21747 | 162 |
end; |
163 |
||
164 |
||
20894 | 165 |
(* defs *) |
166 |
||
21845 | 167 |
local |
21570 | 168 |
|
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
169 |
fun expand_term ctxt t = |
21570 | 170 |
let |
171 |
val thy = ProofContext.theory_of ctxt; |
|
172 |
val thy_ctxt = ProofContext.init thy; |
|
173 |
val ct = Thm.cterm_of thy t; |
|
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
174 |
val (defs, ct') = LocalDefs.export ctxt thy_ctxt (Drule.mk_term ct) ||> Drule.dest_term; |
21708 | 175 |
in (Thm.term_of ct', MetaSimplifier.rewrite true defs ct) end; |
21570 | 176 |
|
20894 | 177 |
fun add_def (name, prop) = |
178 |
Theory.add_defs_i false false [(name, prop)] #> |
|
179 |
(fn thy => (Drule.unvarify (Thm.get_axiom_i thy (Sign.full_name thy name)), thy)); |
|
180 |
||
181 |
in |
|
182 |
||
24303 | 183 |
fun defs kind args lthy0 = |
20894 | 184 |
let |
21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset
|
185 |
fun def ((c, mx), ((name, atts), rhs)) lthy1 = |
20894 | 186 |
let |
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
187 |
val (rhs', rhs_conv) = expand_term lthy0 rhs; |
21570 | 188 |
val xs = Variable.add_fixed (LocalTheory.target_of lthy0) rhs' []; |
23087 | 189 |
val T = Term.fastype_of rhs; |
20894 | 190 |
|
21570 | 191 |
val ([(lhs, lhs_def)], lthy2) = lthy1 |
23087 | 192 |
|> LocalTheory.consts (member (op =) xs) [((c, T), mx)]; |
21570 | 193 |
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
|
194 |
|
21570 | 195 |
val name' = Thm.def_name_optional c name; |
196 |
val (def, lthy3) = lthy2 |
|
20894 | 197 |
|> LocalTheory.theory_result (add_def (name', Logic.mk_equals (lhs', rhs'))); |
21845 | 198 |
val eq = LocalDefs.trans_terms lthy3 |
199 |
[(*c == loc.c xs*) lhs_def, |
|
200 |
(*lhs' == rhs'*) def, |
|
201 |
(*rhs' == rhs*) Thm.symmetric rhs_conv]; |
|
23087 | 202 |
in ((lhs, ((name', atts), [([eq], [])])), lthy3) end; |
20894 | 203 |
|
21570 | 204 |
val ((lhss, facts), lthy') = lthy0 |> fold_map def args |>> split_list; |
21433 | 205 |
val (res, lthy'') = lthy' |> LocalTheory.notes kind facts; |
22424 | 206 |
|
20894 | 207 |
in (lhss ~~ map (apsnd the_single) res, lthy'') end; |
208 |
||
209 |
end; |
|
210 |
||
211 |
||
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
212 |
(* axioms *) |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
213 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
214 |
local |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
215 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
216 |
fun add_axiom hyps (name, prop) thy = |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
217 |
let |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
218 |
val name' = if name = "" then "axiom_" ^ serial_string () else name; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
219 |
val prop' = Logic.list_implies (hyps, prop); |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
220 |
val thy' = thy |> Theory.add_axioms_i [(name', prop')]; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
221 |
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
|
222 |
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
|
223 |
in (Drule.implies_elim_list axm prems, thy') end; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
224 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
225 |
in |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
226 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
227 |
fun axioms kind specs lthy = |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
228 |
let |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
229 |
val hyps = map Thm.term_of (Assumption.assms_of lthy); |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
230 |
fun axiom ((name, atts), props) thy = thy |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
231 |
|> fold_map (add_axiom hyps) (PureThy.name_multi name props) |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
232 |
|-> (fn ths => pair ((name, atts), [(ths, [])])); |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
233 |
in |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
234 |
lthy |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
235 |
|> fold (fold Variable.declare_term o snd) specs |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
236 |
|> LocalTheory.theory_result (fold_map axiom specs) |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
237 |
|-> LocalTheory.notes kind |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
238 |
end; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
239 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
240 |
end; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
241 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
242 |
|
20894 | 243 |
(* notes *) |
244 |
||
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
245 |
fun import_export_proof ctxt (name, raw_th) = |
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
246 |
let |
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
247 |
val thy = ProofContext.theory_of ctxt; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
248 |
val thy_ctxt = ProofContext.init thy; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
249 |
val certT = Thm.ctyp_of thy; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
250 |
val cert = Thm.cterm_of thy; |
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
251 |
|
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
252 |
(*export assumes/defines*) |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
253 |
val th = Goal.norm_result raw_th; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
254 |
val (defs, th') = LocalDefs.export ctxt thy_ctxt th; |
21708 | 255 |
val concl_conv = MetaSimplifier.rewrite true defs (Thm.cprop_of th); |
256 |
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
|
257 |
val nprems = Thm.nprems_of th' - Thm.nprems_of th; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
258 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
259 |
(*export fixes*) |
22692 | 260 |
val tfrees = map TFree (Thm.fold_terms Term.add_tfrees th' []); |
261 |
val frees = map Free (Thm.fold_terms Term.add_frees th' []); |
|
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
262 |
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
|
263 |
|> Variable.export ctxt thy_ctxt |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
264 |
|> Drule.zero_var_indexes_list; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
265 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
266 |
(*thm definition*) |
21644 | 267 |
val result = th'' |
268 |
|> PureThy.name_thm true true "" |
|
269 |
|> Goal.close_result |
|
270 |
|> PureThy.name_thm true true name; |
|
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
271 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
272 |
(*import fixes*) |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
273 |
val (tvars, vars) = |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
274 |
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
|
275 |
|>> map Logic.dest_type; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
276 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
277 |
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
|
278 |
val inst = filter (is_Var o fst) (vars ~~ frees); |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
279 |
val cinstT = map (pairself certT o apfst TVar) instT; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
280 |
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
|
281 |
val result' = Thm.instantiate (cinstT, cinst) result; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
282 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
283 |
(*import assumes/defines*) |
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
284 |
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
|
285 |
val result'' = |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
286 |
(case SINGLE (Seq.INTERVAL assm_tac 1 nprems) result' of |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
287 |
NONE => raise THM ("Failed to re-import result", 0, [result']) |
21845 | 288 |
| SOME res => LocalDefs.trans_props ctxt [res, Thm.symmetric concl_conv]) |
21644 | 289 |
|> Goal.norm_result |
290 |
|> PureThy.name_thm false false name; |
|
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
291 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
292 |
in (result'', result) end; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
293 |
|
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
294 |
fun notes loc kind facts lthy = |
21585 | 295 |
let |
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
296 |
val is_loc = loc <> ""; |
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
297 |
val thy = ProofContext.theory_of lthy; |
21615
1bd558879c44
notes: proper naming of thm proof, activated import_export_proof;
wenzelm
parents:
21613
diff
changeset
|
298 |
val full = LocalTheory.full_name lthy; |
21585 | 299 |
|
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
300 |
val facts' = facts |
21615
1bd558879c44
notes: proper naming of thm proof, activated import_export_proof;
wenzelm
parents:
21613
diff
changeset
|
301 |
|> 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
|
302 |
|> PureThy.map_facts (import_export_proof lthy); |
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
303 |
val local_facts = PureThy.map_facts #1 facts' |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
304 |
|> Attrib.map_facts (Attrib.attribute_i thy); |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
305 |
val target_facts = PureThy.map_facts #1 facts' |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
306 |
|> 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
|
307 |
val global_facts = PureThy.map_facts #2 facts' |
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
308 |
|> 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
|
309 |
in |
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
310 |
lthy |> LocalTheory.theory |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
311 |
(Sign.qualified_names |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
312 |
#> PureThy.note_thmss_i kind global_facts #> snd |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
313 |
#> Sign.restore_naming thy) |
21585 | 314 |
|
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
315 |
|> 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
|
316 |
|
21433 | 317 |
|> ProofContext.set_stmt true |
20894 | 318 |
|> ProofContext.qualified_names |
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
319 |
|> ProofContext.note_thmss_i kind local_facts |
20894 | 320 |
||> ProofContext.restore_naming lthy |
24389 | 321 |
||> ProofContext.restore_mode lthy |
20894 | 322 |
end; |
323 |
||
324 |
||
21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset
|
325 |
(* target declarations *) |
20894 | 326 |
|
22673 | 327 |
fun target_decl add loc d lthy = |
328 |
let |
|
329 |
val d' = Morphism.transform (LocalTheory.target_morphism lthy) d; |
|
330 |
val d0 = Morphism.form d'; |
|
331 |
in |
|
332 |
if loc = "" then |
|
333 |
lthy |
|
334 |
|> LocalTheory.theory (Context.theory_map d0) |
|
335 |
|> LocalTheory.target (Context.proof_map d0) |
|
336 |
else |
|
337 |
lthy |
|
338 |
|> LocalTheory.target (add loc d') |
|
339 |
end; |
|
20894 | 340 |
|
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
341 |
val type_syntax = target_decl Locale.add_type_syntax; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
342 |
val term_syntax = target_decl Locale.add_term_syntax; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
343 |
val declaration = target_decl Locale.add_declaration; |
20894 | 344 |
|
21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset
|
345 |
fun target_morphism loc lthy = |
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
346 |
ProofContext.export_morphism lthy (LocalTheory.target_of lthy) $> |
21613
ae3bb930b50f
notes: more careful treatment of Goal.close_result;
wenzelm
parents:
21611
diff
changeset
|
347 |
Morphism.thm_morphism Goal.norm_result; |
21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset
|
348 |
|
22203 | 349 |
fun target_naming loc lthy = |
21668 | 350 |
(if loc = "" then Sign.naming_of (ProofContext.theory_of lthy) |
351 |
else ProofContext.naming_of (LocalTheory.target_of lthy)) |
|
22203 | 352 |
|> NameSpace.qualified_names; |
21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset
|
353 |
|
20894 | 354 |
|
355 |
(* init and exit *) |
|
356 |
||
22353 | 357 |
fun begin loc ctxt = |
358 |
let |
|
359 |
val thy = ProofContext.theory_of ctxt; |
|
360 |
val is_loc = loc <> ""; |
|
24218 | 361 |
val some_class = Class.class_of_locale thy loc; |
24657 | 362 |
fun class_init_exit (SOME class) = |
363 |
Class.init class |
|
364 |
| class_init_exit NONE = |
|
365 |
pair I; |
|
22353 | 366 |
in |
367 |
ctxt |
|
368 |
|> Data.put (if is_loc then SOME loc else NONE) |
|
24657 | 369 |
|> class_init_exit some_class |
370 |
|-> (fn exit => LocalTheory.init (NameSpace.base loc) |
|
21747 | 371 |
{pretty = pretty loc, |
22353 | 372 |
consts = consts is_loc some_class, |
21747 | 373 |
axioms = axioms, |
22353 | 374 |
abbrev = abbrev is_loc some_class, |
24303 | 375 |
defs = defs, |
21747 | 376 |
notes = notes loc, |
377 |
type_syntax = type_syntax loc, |
|
378 |
term_syntax = term_syntax loc, |
|
379 |
declaration = declaration loc, |
|
380 |
target_morphism = target_morphism loc, |
|
22203 | 381 |
target_naming = target_naming loc, |
21804 | 382 |
reinit = fn _ => |
24657 | 383 |
(if is_loc then Locale.init loc else ProofContext.init) |
384 |
#> begin loc, |
|
385 |
exit = LocalTheory.target_of #> ProofContext.theory exit }) |
|
21747 | 386 |
end; |
20894 | 387 |
|
22353 | 388 |
fun init_i NONE thy = begin "" (ProofContext.init thy) |
389 |
| init_i (SOME loc) thy = begin loc (Locale.init loc thy); |
|
20894 | 390 |
|
21276 | 391 |
fun init (SOME "-") thy = init_i NONE thy |
392 |
| init loc thy = init_i (Option.map (Locale.intern thy) loc) thy; |
|
20894 | 393 |
|
394 |
end; |