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