author | haftmann |
Fri, 05 Dec 2008 18:43:42 +0100 | |
changeset 29006 | abe0f11cfa4e |
parent 28965 | 1de908189869 |
child 29215 | f98862eb0591 |
permissions | -rw-r--r-- |
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
1 |
(* Title: Pure/Isar/element.ML |
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
3 |
|
19777 | 4 |
Explicit data structures for some Isar language elements, with derived |
5 |
logical operations. |
|
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
6 |
*) |
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
7 |
|
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
8 |
signature ELEMENT = |
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
9 |
sig |
19259 | 10 |
datatype ('typ, 'term) stmt = |
28084
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents:
28079
diff
changeset
|
11 |
Shows of (Attrib.binding * ('term * 'term list) list) list | |
28965 | 12 |
Obtains of (Binding.T * ((Binding.T * 'typ option) list * 'term list)) list |
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
25739
diff
changeset
|
13 |
type statement = (string, string) stmt |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
25739
diff
changeset
|
14 |
type statement_i = (typ, term) stmt |
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
15 |
datatype ('typ, 'term, 'fact) ctxt = |
28965 | 16 |
Fixes of (Binding.T * 'typ option * mixfix) list | |
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
17 |
Constrains of (string * 'typ) list | |
28084
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents:
28079
diff
changeset
|
18 |
Assumes of (Attrib.binding * ('term * 'term list) list) list | |
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents:
28079
diff
changeset
|
19 |
Defines of (Attrib.binding * ('term * 'term list)) list | |
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents:
28079
diff
changeset
|
20 |
Notes of string * (Attrib.binding * ('fact * Attrib.src list) list) list |
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
25739
diff
changeset
|
21 |
type context = (string, string, Facts.ref) ctxt |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
25739
diff
changeset
|
22 |
type context_i = (typ, term, thm list) ctxt |
21581 | 23 |
val facts_map: (('typ, 'term, 'fact) ctxt -> ('a, 'b, 'c) ctxt) -> |
28084
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents:
28079
diff
changeset
|
24 |
(Attrib.binding * ('fact * Attrib.src list) list) list -> |
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents:
28079
diff
changeset
|
25 |
(Attrib.binding * ('c * Attrib.src list) list) list |
28965 | 26 |
val map_ctxt: {binding: Binding.T -> Binding.T, |
27 |
var: Binding.T * mixfix -> Binding.T * mixfix, |
|
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
28 |
typ: 'typ -> 'a, term: 'term -> 'b, fact: 'fact -> 'c, |
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
29 |
attrib: Attrib.src -> Attrib.src} -> ('typ, 'term, 'fact) ctxt -> ('a, 'b, 'c) ctxt |
21528 | 30 |
val map_ctxt_attrib: (Attrib.src -> Attrib.src) -> |
31 |
('typ, 'term, 'fact) ctxt -> ('typ, 'term, 'fact) ctxt |
|
21481 | 32 |
val morph_ctxt: morphism -> context_i -> context_i |
19808 | 33 |
val params_of: context_i -> (string * typ) list |
34 |
val prems_of: context_i -> term list |
|
28084
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents:
28079
diff
changeset
|
35 |
val facts_of: theory -> context_i -> (Attrib.binding * (thm list * Attrib.src list) list) list |
19777 | 36 |
val pretty_stmt: Proof.context -> statement_i -> Pretty.T list |
37 |
val pretty_ctxt: Proof.context -> context_i -> Pretty.T list |
|
38 |
val pretty_statement: Proof.context -> string -> thm -> Pretty.T |
|
39 |
type witness |
|
40 |
val map_witness: (term * thm -> term * thm) -> witness -> witness |
|
21481 | 41 |
val morph_witness: morphism -> witness -> witness |
19777 | 42 |
val witness_prop: witness -> term |
43 |
val witness_hyps: witness -> term list |
|
44 |
val assume_witness: theory -> term -> witness |
|
20058 | 45 |
val prove_witness: Proof.context -> term -> tactic -> witness |
25624 | 46 |
val close_witness: witness -> witness |
19777 | 47 |
val conclude_witness: witness -> thm |
48 |
val mark_witness: term -> term |
|
49 |
val make_witness: term -> thm -> witness |
|
19931
fb32b43e7f80
Restructured locales with predicates: import is now an interpretation.
ballarin
parents:
19897
diff
changeset
|
50 |
val dest_witness: witness -> term * thm |
20068
19c7361db4a3
New function transfer_witness lifting Thm.transfer to witnesses.
ballarin
parents:
20058
diff
changeset
|
51 |
val transfer_witness: theory -> witness -> witness |
19808 | 52 |
val refine_witness: Proof.state -> Proof.state Seq.seq |
22658
263d42253f53
Experimental interpretation code for definitions.
ballarin
parents:
22568
diff
changeset
|
53 |
val pretty_witness: Proof.context -> witness -> Pretty.T |
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
54 |
val rename: (string * (string * mixfix option)) list -> string -> string |
28079
955c42c8a5e4
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27865
diff
changeset
|
55 |
val rename_var_name: (string * (string * mixfix option)) list -> |
955c42c8a5e4
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27865
diff
changeset
|
56 |
string * mixfix -> string * mixfix |
955c42c8a5e4
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27865
diff
changeset
|
57 |
val rename_var: (string * (string * mixfix option)) list -> |
28965 | 58 |
Binding.T * mixfix -> Binding.T * mixfix |
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
59 |
val rename_term: (string * (string * mixfix option)) list -> term -> term |
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
60 |
val rename_thm: (string * (string * mixfix option)) list -> thm -> thm |
21481 | 61 |
val rename_morphism: (string * (string * mixfix option)) list -> morphism |
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
62 |
val instT_type: typ Symtab.table -> typ -> typ |
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
63 |
val instT_term: typ Symtab.table -> term -> term |
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
64 |
val instT_thm: theory -> typ Symtab.table -> thm -> thm |
21481 | 65 |
val instT_morphism: theory -> typ Symtab.table -> morphism |
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
66 |
val inst_term: typ Symtab.table * term Symtab.table -> term -> term |
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
67 |
val inst_thm: theory -> typ Symtab.table * term Symtab.table -> thm -> thm |
21481 | 68 |
val inst_morphism: theory -> typ Symtab.table * term Symtab.table -> morphism |
19777 | 69 |
val satisfy_thm: witness list -> thm -> thm |
21481 | 70 |
val satisfy_morphism: witness list -> morphism |
20264 | 71 |
val satisfy_facts: witness list -> |
28084
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents:
28079
diff
changeset
|
72 |
(Attrib.binding * (thm list * Attrib.src list) list) list -> |
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents:
28079
diff
changeset
|
73 |
(Attrib.binding * (thm list * Attrib.src list) list) list |
21581 | 74 |
val generalize_facts: Proof.context -> Proof.context -> |
28084
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents:
28079
diff
changeset
|
75 |
(Attrib.binding * (thm list * Attrib.src list) list) list -> |
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents:
28079
diff
changeset
|
76 |
(Attrib.binding * (thm list * Attrib.src list) list) list |
28850 | 77 |
val activate: (typ, term, Facts.ref) ctxt list -> Proof.context -> |
28965 | 78 |
(context_i list * (Binding.T * Thm.thm list) list) * Proof.context |
28832 | 79 |
val activate_i: context_i list -> Proof.context -> |
28965 | 80 |
(context_i list * (Binding.T * Thm.thm list) list) * Proof.context |
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
81 |
end; |
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
82 |
|
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
83 |
structure Element: ELEMENT = |
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
84 |
struct |
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
85 |
|
19777 | 86 |
(** language elements **) |
87 |
||
88 |
(* statement *) |
|
19259 | 89 |
|
90 |
datatype ('typ, 'term) stmt = |
|
28084
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents:
28079
diff
changeset
|
91 |
Shows of (Attrib.binding * ('term * 'term list) list) list | |
28965 | 92 |
Obtains of (Binding.T * ((Binding.T * 'typ option) list * 'term list)) list; |
19259 | 93 |
|
94 |
type statement = (string, string) stmt; |
|
95 |
type statement_i = (typ, term) stmt; |
|
96 |
||
97 |
||
19777 | 98 |
(* context *) |
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
99 |
|
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
100 |
datatype ('typ, 'term, 'fact) ctxt = |
28965 | 101 |
Fixes of (Binding.T * 'typ option * mixfix) list | |
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
102 |
Constrains of (string * 'typ) list | |
28084
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents:
28079
diff
changeset
|
103 |
Assumes of (Attrib.binding * ('term * 'term list) list) list | |
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents:
28079
diff
changeset
|
104 |
Defines of (Attrib.binding * ('term * 'term list)) list | |
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents:
28079
diff
changeset
|
105 |
Notes of string * (Attrib.binding * ('fact * Attrib.src list) list) list; |
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
106 |
|
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
25739
diff
changeset
|
107 |
type context = (string, string, Facts.ref) ctxt; |
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
108 |
type context_i = (typ, term, thm list) ctxt; |
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
109 |
|
21581 | 110 |
fun facts_map f facts = Notes ("", facts) |> f |> (fn Notes (_, facts') => facts'); |
111 |
||
28965 | 112 |
fun map_ctxt {binding, var, typ, term, fact, attrib} = |
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
113 |
fn Fixes fixes => Fixes (fixes |> map (fn (x, T, mx) => |
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
114 |
let val (x', mx') = var (x, mx) in (x', Option.map typ T, mx') end)) |
28079
955c42c8a5e4
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27865
diff
changeset
|
115 |
| Constrains xs => Constrains (xs |> map (fn (x, T) => |
29006 | 116 |
let val x' = Binding.base_name (#1 (var (Binding.name x, NoSyn))) in (x', typ T) end)) |
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
117 |
| Assumes asms => Assumes (asms |> map (fn ((a, atts), propps) => |
28965 | 118 |
((binding a, map attrib atts), propps |> map (fn (t, ps) => (term t, map term ps))))) |
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
119 |
| Defines defs => Defines (defs |> map (fn ((a, atts), (t, ps)) => |
28965 | 120 |
((binding a, map attrib atts), (term t, map term ps)))) |
21440 | 121 |
| Notes (kind, facts) => Notes (kind, facts |> map (fn ((a, atts), bs) => |
28965 | 122 |
((binding a, map attrib atts), bs |> map (fn (ths, btts) => (fact ths, map attrib btts))))); |
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
123 |
|
21528 | 124 |
fun map_ctxt_attrib attrib = |
28965 | 125 |
map_ctxt {binding = I, var = I, typ = I, term = I, fact = I, attrib = attrib}; |
21528 | 126 |
|
21481 | 127 |
fun morph_ctxt phi = map_ctxt |
28965 | 128 |
{binding = Morphism.binding phi, |
21481 | 129 |
var = Morphism.var phi, |
130 |
typ = Morphism.typ phi, |
|
131 |
term = Morphism.term phi, |
|
21521 | 132 |
fact = Morphism.fact phi, |
21481 | 133 |
attrib = Args.morph_values phi}; |
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
134 |
|
19808 | 135 |
|
136 |
(* logical content *) |
|
137 |
||
19777 | 138 |
fun params_of (Fixes fixes) = fixes |> map |
29006 | 139 |
(fn (x, SOME T, _) => (Binding.base_name x, T) |
28965 | 140 |
| (x, _, _) => raise TERM ("Untyped context element parameter " ^ quote (Binding.display x), [])) |
19777 | 141 |
| params_of _ = []; |
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
142 |
|
19777 | 143 |
fun prems_of (Assumes asms) = maps (map fst o snd) asms |
144 |
| prems_of (Defines defs) = map (fst o snd) defs |
|
145 |
| prems_of _ = []; |
|
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
146 |
|
20233 | 147 |
fun assume thy t = Assumption.assume (Thm.cterm_of thy t); |
19808 | 148 |
|
149 |
fun facts_of thy (Assumes asms) = map (apsnd (map (fn (t, _) => ([assume thy t], [])))) asms |
|
150 |
| facts_of thy (Defines defs) = map (apsnd (fn (t, _) => [([assume thy t], [])])) defs |
|
21440 | 151 |
| facts_of _ (Notes (_, facts)) = facts |
19808 | 152 |
| facts_of _ _ = []; |
153 |
||
18894 | 154 |
|
155 |
||
19259 | 156 |
(** pretty printing **) |
157 |
||
19267 | 158 |
fun pretty_items _ _ [] = [] |
159 |
| pretty_items keyword sep (x :: ys) = |
|
160 |
Pretty.block [Pretty.keyword keyword, Pretty.brk 1, x] :: |
|
161 |
map (fn y => Pretty.block [Pretty.str " ", Pretty.keyword sep, Pretty.brk 1, y]) ys; |
|
19259 | 162 |
|
28862 | 163 |
fun pretty_name_atts ctxt (b, atts) sep = |
28733 | 164 |
let |
28965 | 165 |
val name = Binding.display b; |
28733 | 166 |
in if name = "" andalso null atts then [] |
28079
955c42c8a5e4
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27865
diff
changeset
|
167 |
else [Pretty.block |
955c42c8a5e4
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27865
diff
changeset
|
168 |
(Pretty.breaks (Pretty.str name :: Attrib.pretty_attribs ctxt atts @ [Pretty.str sep]))] |
955c42c8a5e4
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27865
diff
changeset
|
169 |
end; |
19259 | 170 |
|
171 |
||
172 |
(* pretty_stmt *) |
|
173 |
||
174 |
fun pretty_stmt ctxt = |
|
175 |
let |
|
24920 | 176 |
val prt_typ = Pretty.quote o Syntax.pretty_typ ctxt; |
177 |
val prt_term = Pretty.quote o Syntax.pretty_term ctxt; |
|
19267 | 178 |
val prt_terms = separate (Pretty.keyword "and") o map prt_term; |
19259 | 179 |
val prt_name_atts = pretty_name_atts ctxt; |
180 |
||
181 |
fun prt_show (a, ts) = |
|
19267 | 182 |
Pretty.block (Pretty.breaks (prt_name_atts a ":" @ prt_terms (map fst ts))); |
19259 | 183 |
|
28079
955c42c8a5e4
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27865
diff
changeset
|
184 |
fun prt_var (x, SOME T) = Pretty.block |
29006 | 185 |
[Pretty.str (Binding.base_name x ^ " ::"), Pretty.brk 1, prt_typ T] |
186 |
| prt_var (x, NONE) = Pretty.str (Binding.base_name x); |
|
26721 | 187 |
val prt_vars = separate (Pretty.keyword "and") o map prt_var; |
19259 | 188 |
|
19267 | 189 |
fun prt_obtain (_, ([], ts)) = Pretty.block (Pretty.breaks (prt_terms ts)) |
19259 | 190 |
| prt_obtain (_, (xs, ts)) = Pretty.block (Pretty.breaks |
19585 | 191 |
(prt_vars xs @ [Pretty.keyword "where"] @ prt_terms ts)); |
19259 | 192 |
in |
19267 | 193 |
fn Shows shows => pretty_items "shows" "and" (map prt_show shows) |
194 |
| Obtains obtains => pretty_items "obtains" "|" (map prt_obtain obtains) |
|
19259 | 195 |
end; |
196 |
||
18894 | 197 |
|
19259 | 198 |
(* pretty_ctxt *) |
199 |
||
200 |
fun pretty_ctxt ctxt = |
|
201 |
let |
|
24920 | 202 |
val prt_typ = Pretty.quote o Syntax.pretty_typ ctxt; |
203 |
val prt_term = Pretty.quote o Syntax.pretty_term ctxt; |
|
19259 | 204 |
val prt_thm = Pretty.backquote o ProofContext.pretty_thm ctxt; |
205 |
val prt_name_atts = pretty_name_atts ctxt; |
|
206 |
||
19267 | 207 |
fun prt_mixfix NoSyn = [] |
208 |
| prt_mixfix mx = [Pretty.brk 2, Syntax.pretty_mixfix mx]; |
|
209 |
||
29006 | 210 |
fun prt_fix (x, SOME T, mx) = Pretty.block (Pretty.str (Binding.base_name x ^ " ::") :: |
28079
955c42c8a5e4
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27865
diff
changeset
|
211 |
Pretty.brk 1 :: prt_typ T :: Pretty.brk 1 :: prt_mixfix mx) |
29006 | 212 |
| prt_fix (x, NONE, mx) = Pretty.block (Pretty.str (Binding.base_name x) :: |
28079
955c42c8a5e4
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27865
diff
changeset
|
213 |
Pretty.brk 1 :: prt_mixfix mx); |
28965 | 214 |
fun prt_constrain (x, T) = prt_fix (Binding.name x, SOME T, NoSyn); |
18894 | 215 |
|
19259 | 216 |
fun prt_asm (a, ts) = |
217 |
Pretty.block (Pretty.breaks (prt_name_atts a ":" @ map (prt_term o fst) ts)); |
|
218 |
fun prt_def (a, (t, _)) = |
|
219 |
Pretty.block (Pretty.breaks (prt_name_atts a ":" @ [prt_term t])); |
|
220 |
||
221 |
fun prt_fact (ths, []) = map prt_thm ths |
|
222 |
| prt_fact (ths, atts) = Pretty.enclose "(" ")" |
|
21032 | 223 |
(Pretty.breaks (map prt_thm ths)) :: Attrib.pretty_attribs ctxt atts; |
19259 | 224 |
fun prt_note (a, ths) = |
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19466
diff
changeset
|
225 |
Pretty.block (Pretty.breaks (flat (prt_name_atts a "=" :: map prt_fact ths))); |
19259 | 226 |
in |
19267 | 227 |
fn Fixes fixes => pretty_items "fixes" "and" (map prt_fix fixes) |
228 |
| Constrains xs => pretty_items "constrains" "and" (map prt_constrain xs) |
|
229 |
| Assumes asms => pretty_items "assumes" "and" (map prt_asm asms) |
|
230 |
| Defines defs => pretty_items "defines" "and" (map prt_def defs) |
|
21440 | 231 |
| Notes ("", facts) => pretty_items "notes" "and" (map prt_note facts) |
232 |
| Notes (kind, facts) => pretty_items ("notes " ^ kind) "and" (map prt_note facts) |
|
19259 | 233 |
end; |
18894 | 234 |
|
19267 | 235 |
|
236 |
(* pretty_statement *) |
|
237 |
||
238 |
local |
|
239 |
||
240 |
fun thm_name kind th prts = |
|
241 |
let val head = |
|
27865
27a8ad9612a3
moved basic thm operations from structure PureThy to Thm (cf. more_thm.ML);
wenzelm
parents:
26721
diff
changeset
|
242 |
if Thm.has_name_hint th then |
21965
7120ef5bc378
pretty_statement: more careful handling of name_hint;
wenzelm
parents:
21646
diff
changeset
|
243 |
Pretty.block [Pretty.command kind, |
27865
27a8ad9612a3
moved basic thm operations from structure PureThy to Thm (cf. more_thm.ML);
wenzelm
parents:
26721
diff
changeset
|
244 |
Pretty.brk 1, Pretty.str (Sign.base_name (Thm.get_name_hint th) ^ ":")] |
21965
7120ef5bc378
pretty_statement: more careful handling of name_hint;
wenzelm
parents:
21646
diff
changeset
|
245 |
else Pretty.command kind |
19267 | 246 |
in Pretty.block (Pretty.fbreaks (head :: prts)) end; |
247 |
||
28965 | 248 |
fun fix (x, T) = (Binding.name x, SOME T); |
28079
955c42c8a5e4
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27865
diff
changeset
|
249 |
|
19267 | 250 |
fun obtain prop ctxt = |
251 |
let |
|
20150 | 252 |
val ((xs, prop'), ctxt') = Variable.focus prop ctxt; |
253 |
val As = Logic.strip_imp_prems (Thm.term_of prop'); |
|
28965 | 254 |
in ((Binding.empty, (map (fix o Term.dest_Free o Thm.term_of) xs, As)), ctxt') end; |
19267 | 255 |
|
256 |
in |
|
257 |
||
258 |
fun pretty_statement ctxt kind raw_th = |
|
259 |
let |
|
260 |
val thy = ProofContext.theory_of ctxt; |
|
20150 | 261 |
val cert = Thm.cterm_of thy; |
262 |
||
21605 | 263 |
val th = MetaSimplifier.norm_hhf raw_th; |
20150 | 264 |
val is_elim = ObjectLogic.is_elim th; |
19267 | 265 |
|
26716
8690e75e1395
print_statement: reset body mode, i.e. invent global frees (no need for revert_skolem);
wenzelm
parents:
26628
diff
changeset
|
266 |
val ((_, [th']), ctxt') = Variable.import_thms true [th] (Variable.set_body false ctxt); |
20150 | 267 |
val prop = Thm.prop_of th'; |
268 |
val (prems, concl) = Logic.strip_horn prop; |
|
269 |
val concl_term = ObjectLogic.drop_judgment thy concl; |
|
19267 | 270 |
|
20150 | 271 |
val fixes = fold_aterms (fn v as Free (x, T) => |
272 |
if Variable.newly_fixed ctxt' ctxt x andalso not (v aconv concl_term) |
|
26716
8690e75e1395
print_statement: reset body mode, i.e. invent global frees (no need for revert_skolem);
wenzelm
parents:
26628
diff
changeset
|
273 |
then insert (op =) (x, T) else I | _ => I) prop [] |> rev; |
20150 | 274 |
val (assumes, cases) = take_suffix (fn prem => |
275 |
is_elim andalso concl aconv Logic.strip_assums_concl prem) prems; |
|
19267 | 276 |
in |
28965 | 277 |
pretty_ctxt ctxt' (Fixes (map (fn (x, T) => (Binding.name x, SOME T, NoSyn)) fixes)) @ |
278 |
pretty_ctxt ctxt' (Assumes (map (fn t => (Attrib.empty_binding, [(t, [])])) assumes)) @ |
|
279 |
(if null cases then pretty_stmt ctxt' (Shows [(Attrib.empty_binding, [(concl, [])])]) |
|
26716
8690e75e1395
print_statement: reset body mode, i.e. invent global frees (no need for revert_skolem);
wenzelm
parents:
26628
diff
changeset
|
280 |
else |
8690e75e1395
print_statement: reset body mode, i.e. invent global frees (no need for revert_skolem);
wenzelm
parents:
26628
diff
changeset
|
281 |
let val (clauses, ctxt'') = fold_map (obtain o cert) cases ctxt' |
8690e75e1395
print_statement: reset body mode, i.e. invent global frees (no need for revert_skolem);
wenzelm
parents:
26628
diff
changeset
|
282 |
in pretty_stmt ctxt'' (Obtains clauses) end) |
19267 | 283 |
end |> thm_name kind raw_th; |
284 |
||
18140
691c64d615a5
Explicit data structures for some Isar language elements.
wenzelm
parents:
diff
changeset
|
285 |
end; |
19267 | 286 |
|
19777 | 287 |
|
288 |
||
289 |
(** logical operations **) |
|
290 |
||
291 |
(* witnesses -- hypotheses as protected facts *) |
|
292 |
||
293 |
datatype witness = Witness of term * thm; |
|
294 |
||
295 |
fun map_witness f (Witness witn) = Witness (f witn); |
|
296 |
||
21481 | 297 |
fun morph_witness phi = map_witness (fn (t, th) => (Morphism.term phi t, Morphism.thm phi th)); |
298 |
||
19777 | 299 |
fun witness_prop (Witness (t, _)) = t; |
300 |
fun witness_hyps (Witness (_, th)) = #hyps (Thm.rep_thm th); |
|
301 |
||
302 |
fun assume_witness thy t = |
|
303 |
Witness (t, Goal.protect (Thm.assume (Thm.cterm_of thy t))); |
|
304 |
||
20058 | 305 |
fun prove_witness ctxt t tac = |
26628
63306cb94313
replaced Drule.close_derivation/Goal.close_result by Thm.close_derivation (removed obsolete compression);
wenzelm
parents:
26336
diff
changeset
|
306 |
Witness (t, Thm.close_derivation (Goal.prove ctxt [] [] (Logic.protect t) (fn _ => |
25202
3a539d9995fb
proven witness: proper Goal.close_result save huge amounts of resources when using proof terms;
wenzelm
parents:
24920
diff
changeset
|
307 |
Tactic.rtac Drule.protectI 1 THEN tac))); |
19777 | 308 |
|
26628
63306cb94313
replaced Drule.close_derivation/Goal.close_result by Thm.close_derivation (removed obsolete compression);
wenzelm
parents:
26336
diff
changeset
|
309 |
val close_witness = map_witness (fn (t, th) => (t, Thm.close_derivation th)); |
25624 | 310 |
|
25202
3a539d9995fb
proven witness: proper Goal.close_result save huge amounts of resources when using proof terms;
wenzelm
parents:
24920
diff
changeset
|
311 |
fun conclude_witness (Witness (_, th)) = |
26628
63306cb94313
replaced Drule.close_derivation/Goal.close_result by Thm.close_derivation (removed obsolete compression);
wenzelm
parents:
26336
diff
changeset
|
312 |
Thm.close_derivation (MetaSimplifier.norm_hhf_protect (Goal.conclude th)); |
19777 | 313 |
|
25302 | 314 |
fun compose_witness (Witness (_, th)) r = |
315 |
let |
|
316 |
val th' = Goal.conclude th; |
|
317 |
val A = Thm.cprem_of r 1; |
|
25739 | 318 |
in |
319 |
Thm.implies_elim |
|
320 |
(Conv.gconv_rule Drule.beta_eta_conversion 1 r) |
|
321 |
(Conv.fconv_rule Drule.beta_eta_conversion |
|
322 |
(Thm.instantiate (Thm.match (Thm.cprop_of th', A)) th')) |
|
323 |
end; |
|
25302 | 324 |
|
19777 | 325 |
val mark_witness = Logic.protect; |
326 |
||
327 |
fun make_witness t th = Witness (t, th); |
|
19931
fb32b43e7f80
Restructured locales with predicates: import is now an interpretation.
ballarin
parents:
19897
diff
changeset
|
328 |
fun dest_witness (Witness w) = w; |
fb32b43e7f80
Restructured locales with predicates: import is now an interpretation.
ballarin
parents:
19897
diff
changeset
|
329 |
|
20068
19c7361db4a3
New function transfer_witness lifting Thm.transfer to witnesses.
ballarin
parents:
20058
diff
changeset
|
330 |
fun transfer_witness thy (Witness (t, th)) = Witness (t, Thm.transfer thy th); |
19c7361db4a3
New function transfer_witness lifting Thm.transfer to witnesses.
ballarin
parents:
20058
diff
changeset
|
331 |
|
19777 | 332 |
val refine_witness = |
333 |
Proof.refine (Method.Basic (K (Method.RAW_METHOD |
|
334 |
(K (ALLGOALS |
|
23414
927203ad4b3a
tuned conjunction tactics: slightly smaller proof terms;
wenzelm
parents:
23351
diff
changeset
|
335 |
(CONJUNCTS (ALLGOALS |
927203ad4b3a
tuned conjunction tactics: slightly smaller proof terms;
wenzelm
parents:
23351
diff
changeset
|
336 |
(CONJUNCTS (TRYALL (Tactic.rtac Drule.protectI)))))))), Position.none)); |
19777 | 337 |
|
22658
263d42253f53
Experimental interpretation code for definitions.
ballarin
parents:
22568
diff
changeset
|
338 |
fun pretty_witness ctxt witn = |
24920 | 339 |
let val prt_term = Pretty.quote o Syntax.pretty_term ctxt in |
22658
263d42253f53
Experimental interpretation code for definitions.
ballarin
parents:
22568
diff
changeset
|
340 |
Pretty.block (prt_term (witness_prop witn) :: |
263d42253f53
Experimental interpretation code for definitions.
ballarin
parents:
22568
diff
changeset
|
341 |
(if ! show_hyps then [Pretty.brk 2, Pretty.list "[" "]" |
263d42253f53
Experimental interpretation code for definitions.
ballarin
parents:
22568
diff
changeset
|
342 |
(map prt_term (witness_hyps witn))] else [])) |
263d42253f53
Experimental interpretation code for definitions.
ballarin
parents:
22568
diff
changeset
|
343 |
end; |
263d42253f53
Experimental interpretation code for definitions.
ballarin
parents:
22568
diff
changeset
|
344 |
|
19777 | 345 |
|
346 |
(* derived rules *) |
|
347 |
||
20007 | 348 |
fun instantiate_tfrees thy subst th = |
19777 | 349 |
let |
350 |
val certT = Thm.ctyp_of thy; |
|
20007 | 351 |
val idx = Thm.maxidx_of th + 1; |
352 |
fun cert_inst (a, (S, T)) = (certT (TVar ((a, idx), S)), certT T); |
|
353 |
||
354 |
fun add_inst (a, S) insts = |
|
355 |
if AList.defined (op =) insts a then insts |
|
356 |
else (case AList.lookup (op =) subst a of NONE => insts | SOME T => (a, (S, T)) :: insts); |
|
357 |
val insts = |
|
358 |
Term.fold_types (Term.fold_atyps (fn TFree v => add_inst v | _ => I)) |
|
359 |
(Thm.full_prop_of th) []; |
|
19777 | 360 |
in |
20007 | 361 |
th |
362 |
|> Thm.generalize (map fst insts, []) idx |
|
363 |
|> Thm.instantiate (map cert_inst insts, []) |
|
19777 | 364 |
end; |
365 |
||
366 |
fun instantiate_frees thy subst = |
|
367 |
let val cert = Thm.cterm_of thy in |
|
368 |
Drule.forall_intr_list (map (cert o Free o fst) subst) #> |
|
369 |
Drule.forall_elim_list (map (cert o snd) subst) |
|
370 |
end; |
|
371 |
||
372 |
fun hyps_rule rule th = |
|
21521 | 373 |
let val {hyps, ...} = Thm.crep_thm th in |
19777 | 374 |
Drule.implies_elim_list |
375 |
(rule (Drule.implies_intr_list hyps th)) |
|
21521 | 376 |
(map (Thm.assume o Drule.cterm_rule rule) hyps) |
19777 | 377 |
end; |
378 |
||
379 |
||
380 |
(* rename *) |
|
381 |
||
382 |
fun rename ren x = |
|
383 |
(case AList.lookup (op =) ren (x: string) of |
|
384 |
NONE => x |
|
385 |
| SOME (x', _) => x'); |
|
386 |
||
28079
955c42c8a5e4
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27865
diff
changeset
|
387 |
fun rename_var_name ren (x, mx) = |
955c42c8a5e4
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27865
diff
changeset
|
388 |
(case (AList.lookup (op =) ren x, mx) of |
19777 | 389 |
(NONE, _) => (x, mx) |
390 |
| (SOME (x', NONE), Structure) => (x', mx) |
|
391 |
| (SOME (x', SOME _), Structure) => |
|
392 |
error ("Attempt to change syntax of structure parameter " ^ quote x) |
|
393 |
| (SOME (x', NONE), _) => (x', NoSyn) |
|
394 |
| (SOME (x', SOME mx'), _) => (x', mx')); |
|
395 |
||
28862 | 396 |
fun rename_var ren (b, mx) = |
28079
955c42c8a5e4
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27865
diff
changeset
|
397 |
let |
29006 | 398 |
val x = Binding.base_name b; |
28079
955c42c8a5e4
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27865
diff
changeset
|
399 |
val (x', mx') = rename_var_name ren (x, mx); |
28965 | 400 |
in (Binding.name x', mx') end; |
28079
955c42c8a5e4
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27865
diff
changeset
|
401 |
|
19777 | 402 |
fun rename_term ren (Free (x, T)) = Free (rename ren x, T) |
403 |
| rename_term ren (t $ u) = rename_term ren t $ rename_term ren u |
|
404 |
| rename_term ren (Abs (x, T, t)) = Abs (x, T, rename_term ren t) |
|
405 |
| rename_term _ a = a; |
|
406 |
||
407 |
fun rename_thm ren th = |
|
408 |
let |
|
20304 | 409 |
val thy = Thm.theory_of_thm th; |
22691 | 410 |
val subst = (Thm.fold_terms o Term.fold_aterms) |
20304 | 411 |
(fn Free (x, T) => |
19777 | 412 |
let val x' = rename ren x |
20304 | 413 |
in if x = x' then I else insert (eq_fst (op =)) ((x, T), Free (x', T)) end |
414 |
| _ => I) th []; |
|
19777 | 415 |
in |
416 |
if null subst then th |
|
20304 | 417 |
else th |> hyps_rule (instantiate_frees thy subst) |
19777 | 418 |
end; |
419 |
||
21481 | 420 |
fun rename_morphism ren = Morphism.morphism |
28965 | 421 |
{binding = I, var = rename_var ren, typ = I, term = rename_term ren, fact = map (rename_thm ren)}; |
19777 | 422 |
|
423 |
||
424 |
(* instantiate types *) |
|
425 |
||
426 |
fun instT_type env = |
|
427 |
if Symtab.is_empty env then I |
|
428 |
else Term.map_type_tfree (fn (x, S) => the_default (TFree (x, S)) (Symtab.lookup env x)); |
|
429 |
||
430 |
fun instT_term env = |
|
431 |
if Symtab.is_empty env then I |
|
20548
8ef25fe585a8
renamed Term.map_term_types to Term.map_types (cf. Term.fold_types);
wenzelm
parents:
20304
diff
changeset
|
432 |
else Term.map_types (instT_type env); |
19777 | 433 |
|
22691 | 434 |
fun instT_subst env th = (Thm.fold_terms o Term.fold_types o Term.fold_atyps) |
20304 | 435 |
(fn T as TFree (a, _) => |
436 |
let val T' = the_default T (Symtab.lookup env a) |
|
437 |
in if T = T' then I else insert (op =) (a, T') end |
|
438 |
| _ => I) th []; |
|
19777 | 439 |
|
440 |
fun instT_thm thy env th = |
|
441 |
if Symtab.is_empty env then th |
|
442 |
else |
|
443 |
let val subst = instT_subst env th |
|
444 |
in if null subst then th else th |> hyps_rule (instantiate_tfrees thy subst) end; |
|
445 |
||
22672
777af26d5713
inst(T)_morphism: avoid reference to static theory value;
wenzelm
parents:
22658
diff
changeset
|
446 |
fun instT_morphism thy env = |
24137
8d7896398147
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23414
diff
changeset
|
447 |
let val thy_ref = Theory.check_thy thy in |
22672
777af26d5713
inst(T)_morphism: avoid reference to static theory value;
wenzelm
parents:
22658
diff
changeset
|
448 |
Morphism.morphism |
28965 | 449 |
{binding = I, var = I, |
22672
777af26d5713
inst(T)_morphism: avoid reference to static theory value;
wenzelm
parents:
22658
diff
changeset
|
450 |
typ = instT_type env, |
777af26d5713
inst(T)_morphism: avoid reference to static theory value;
wenzelm
parents:
22658
diff
changeset
|
451 |
term = instT_term env, |
777af26d5713
inst(T)_morphism: avoid reference to static theory value;
wenzelm
parents:
22658
diff
changeset
|
452 |
fact = map (fn th => instT_thm (Theory.deref thy_ref) env th)} |
777af26d5713
inst(T)_morphism: avoid reference to static theory value;
wenzelm
parents:
22658
diff
changeset
|
453 |
end; |
19777 | 454 |
|
455 |
||
456 |
(* instantiate types and terms *) |
|
457 |
||
458 |
fun inst_term (envT, env) = |
|
459 |
if Symtab.is_empty env then instT_term envT |
|
460 |
else |
|
461 |
let |
|
462 |
val instT = instT_type envT; |
|
463 |
fun inst (Const (x, T)) = Const (x, instT T) |
|
464 |
| inst (Free (x, T)) = |
|
465 |
(case Symtab.lookup env x of |
|
466 |
NONE => Free (x, instT T) |
|
467 |
| SOME t => t) |
|
468 |
| inst (Var (xi, T)) = Var (xi, instT T) |
|
469 |
| inst (b as Bound _) = b |
|
470 |
| inst (Abs (x, T, t)) = Abs (x, instT T, inst t) |
|
471 |
| inst (t $ u) = inst t $ inst u; |
|
472 |
in Envir.beta_norm o inst end; |
|
473 |
||
474 |
fun inst_thm thy (envT, env) th = |
|
475 |
if Symtab.is_empty env then instT_thm thy envT th |
|
476 |
else |
|
477 |
let |
|
478 |
val substT = instT_subst envT th; |
|
22691 | 479 |
val subst = (Thm.fold_terms o Term.fold_aterms) |
20304 | 480 |
(fn Free (x, T) => |
19777 | 481 |
let |
482 |
val T' = instT_type envT T; |
|
483 |
val t = Free (x, T'); |
|
484 |
val t' = the_default t (Symtab.lookup env x); |
|
20304 | 485 |
in if t aconv t' then I else insert (eq_fst (op =)) ((x, T'), t') end |
486 |
| _ => I) th []; |
|
19777 | 487 |
in |
488 |
if null substT andalso null subst then th |
|
489 |
else th |> hyps_rule |
|
490 |
(instantiate_tfrees thy substT #> |
|
491 |
instantiate_frees thy subst #> |
|
22900 | 492 |
Conv.fconv_rule (Thm.beta_conversion true)) |
19777 | 493 |
end; |
494 |
||
22672
777af26d5713
inst(T)_morphism: avoid reference to static theory value;
wenzelm
parents:
22658
diff
changeset
|
495 |
fun inst_morphism thy envs = |
24137
8d7896398147
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23414
diff
changeset
|
496 |
let val thy_ref = Theory.check_thy thy in |
22672
777af26d5713
inst(T)_morphism: avoid reference to static theory value;
wenzelm
parents:
22658
diff
changeset
|
497 |
Morphism.morphism |
28965 | 498 |
{binding = I, var = I, |
22672
777af26d5713
inst(T)_morphism: avoid reference to static theory value;
wenzelm
parents:
22658
diff
changeset
|
499 |
typ = instT_type (#1 envs), |
777af26d5713
inst(T)_morphism: avoid reference to static theory value;
wenzelm
parents:
22658
diff
changeset
|
500 |
term = inst_term envs, |
777af26d5713
inst(T)_morphism: avoid reference to static theory value;
wenzelm
parents:
22658
diff
changeset
|
501 |
fact = map (fn th => inst_thm (Theory.deref thy_ref) envs th)} |
777af26d5713
inst(T)_morphism: avoid reference to static theory value;
wenzelm
parents:
22658
diff
changeset
|
502 |
end; |
19777 | 503 |
|
504 |
||
505 |
(* satisfy hypotheses *) |
|
506 |
||
507 |
fun satisfy_thm witns thm = thm |> fold (fn hyp => |
|
508 |
(case find_first (fn Witness (t, _) => Thm.term_of hyp aconv t) witns of |
|
509 |
NONE => I |
|
25302 | 510 |
| SOME w => Thm.implies_intr hyp #> compose_witness w)) (#hyps (Thm.crep_thm thm)); |
19777 | 511 |
|
21497 | 512 |
fun satisfy_morphism witns = Morphism.thm_morphism (satisfy_thm witns); |
19843 | 513 |
|
21581 | 514 |
fun satisfy_facts witns = facts_map (morph_ctxt (satisfy_morphism witns)); |
20264 | 515 |
|
516 |
||
517 |
(* generalize type/term parameters *) |
|
518 |
||
519 |
val maxidx_atts = fold Args.maxidx_values; |
|
520 |
||
21581 | 521 |
fun generalize_facts inner outer facts = |
20264 | 522 |
let |
523 |
val thy = ProofContext.theory_of inner; |
|
524 |
val maxidx = |
|
525 |
fold (fn ((_, atts), bs) => maxidx_atts atts #> fold (maxidx_atts o #2) bs) facts ~1; |
|
21581 | 526 |
val exp_fact = map (Thm.adjust_maxidx_thm maxidx) #> Variable.export inner outer; |
21521 | 527 |
val exp_term = Drule.term_rule thy (singleton exp_fact); |
528 |
val exp_typ = Logic.type_map exp_term; |
|
529 |
val morphism = |
|
28965 | 530 |
Morphism.morphism {binding = I, var = I, typ = exp_typ, term = exp_term, fact = exp_fact}; |
21581 | 531 |
in facts_map (morph_ctxt morphism) facts end; |
20886
f26672c248ee
replaced generalize_facts by full export_(standard_)facts;
wenzelm
parents:
20548
diff
changeset
|
532 |
|
28832 | 533 |
|
534 |
(** activate in context, return elements and facts **) |
|
535 |
||
536 |
local |
|
537 |
||
538 |
fun activate_elem (Fixes fixes) ctxt = |
|
539 |
([], ctxt |> ProofContext.add_fixes_i fixes |> snd) |
|
540 |
| activate_elem (Constrains _) ctxt = |
|
541 |
([], ctxt) |
|
542 |
| activate_elem (Assumes asms) ctxt = |
|
543 |
let |
|
544 |
val asms' = Attrib.map_specs (Attrib.attribute_i (ProofContext.theory_of ctxt)) asms; |
|
545 |
val ts = maps (map #1 o #2) asms'; |
|
546 |
val (_, ctxt') = |
|
547 |
ctxt |> fold Variable.auto_fixes ts |
|
28888 | 548 |
|> ProofContext.add_assms_i Assumption.presume_export asms'; |
28832 | 549 |
in ([], ctxt') end |
550 |
| activate_elem (Defines defs) ctxt = |
|
551 |
let |
|
552 |
val defs' = Attrib.map_specs (Attrib.attribute_i (ProofContext.theory_of ctxt)) defs; |
|
553 |
val asms = defs' |> map (fn ((name, atts), (t, ps)) => |
|
554 |
let val ((c, _), t') = LocalDefs.cert_def ctxt t |
|
28965 | 555 |
in (t', ((Binding.map_base (Thm.def_name_optional c) name, atts), [(t', ps)])) end); |
28832 | 556 |
val (_, ctxt') = |
557 |
ctxt |> fold (Variable.auto_fixes o #1) asms |
|
558 |
|> ProofContext.add_assms_i LocalDefs.def_export (map #2 asms); |
|
559 |
in ([], ctxt') end |
|
560 |
| activate_elem (Notes (kind, facts)) ctxt = |
|
561 |
let |
|
562 |
val facts' = Attrib.map_facts (Attrib.attribute_i (ProofContext.theory_of ctxt)) facts; |
|
563 |
val (res, ctxt') = ctxt |> ProofContext.note_thmss_i kind facts'; |
|
564 |
in ((map (#1 o #1) facts' ~~ map #2 res), ctxt') end; |
|
565 |
||
566 |
fun gen_activate prep_facts raw_elems ctxt = |
|
567 |
let |
|
568 |
val elems = map (map_ctxt_attrib Args.assignable o prep_facts ctxt) raw_elems; |
|
569 |
val (res, ctxt') = fold_map activate_elem elems (ProofContext.qualified_names ctxt); |
|
570 |
val elems' = elems |> map (map_ctxt_attrib Args.closure); |
|
571 |
in ((elems', flat res), ProofContext.restore_naming ctxt ctxt') end; |
|
572 |
||
573 |
fun check_name name = |
|
574 |
if NameSpace.is_qualified name then error ("Illegal qualified name: " ^ quote name) |
|
575 |
else name; |
|
576 |
||
577 |
fun prep_facts prep_name get intern ctxt elem = elem |> map_ctxt |
|
578 |
{var = I, typ = I, term = I, |
|
28965 | 579 |
binding = Binding.map_base prep_name, |
28832 | 580 |
fact = get ctxt, |
581 |
attrib = intern (ProofContext.theory_of ctxt)}; |
|
582 |
||
583 |
in |
|
584 |
||
585 |
fun activate x = gen_activate (prep_facts check_name ProofContext.get_fact Attrib.intern_src) x; |
|
586 |
fun activate_i x = gen_activate (K I) x; |
|
587 |
||
19267 | 588 |
end; |
28832 | 589 |
|
590 |
end; |