author | wenzelm |
Thu, 18 Aug 2005 12:07:33 +0200 | |
changeset 17118 | 1ff59b7b35b7 |
parent 17072 | 501c28052aea |
child 17184 | 3d80209e9a53 |
permissions | -rw-r--r-- |
5819 | 1 |
(* Title: Pure/Isar/proof_context.ML |
2 |
ID: $Id$ |
|
3 |
Author: Markus Wenzel, TU Muenchen |
|
4 |
||
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
5 |
The key concept of Isar proof contexts. |
5819 | 6 |
*) |
7 |
||
14707 | 8 |
val show_structs = ref false; |
9 |
||
5819 | 10 |
signature PROOF_CONTEXT = |
11 |
sig |
|
12 |
type context |
|
9470 | 13 |
type exporter |
5819 | 14 |
exception CONTEXT of string * context |
15 |
val theory_of: context -> theory |
|
16458 | 16 |
val sign_of: context -> theory (*obsolete*) |
14828 | 17 |
val is_fixed: context -> string -> bool |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
18 |
val is_known: context -> string -> bool |
12057 | 19 |
val fixed_names_of: context -> string list |
20 |
val assumptions_of: context -> (cterm list * exporter) list |
|
7557 | 21 |
val prems_of: context -> thm list |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
22 |
val fact_index_of: context -> FactIndex.T |
5874 | 23 |
val init: theory -> context |
17072 | 24 |
val transfer: theory -> context -> context |
14828 | 25 |
val pretty_term: context -> term -> Pretty.T |
26 |
val pretty_typ: context -> typ -> Pretty.T |
|
27 |
val pretty_sort: context -> sort -> Pretty.T |
|
28 |
val pp: context -> Pretty.pp |
|
29 |
val pretty_thm: context -> thm -> Pretty.T |
|
30 |
val pretty_thms: context -> thm list -> Pretty.T |
|
31 |
val pretty_fact: context -> string * thm list -> Pretty.T |
|
17072 | 32 |
val pretty_proof: context -> Proofterm.proof -> Pretty.T |
33 |
val pretty_proof_of: context -> bool -> thm -> Pretty.T |
|
14828 | 34 |
val string_of_term: context -> term -> string |
12414 | 35 |
val default_type: context -> string -> typ option |
12504 | 36 |
val used_types: context -> string list |
5819 | 37 |
val read_typ: context -> string -> typ |
16348 | 38 |
val read_typ_syntax: context -> string -> typ |
39 |
val read_typ_abbrev: context -> string -> typ |
|
5819 | 40 |
val cert_typ: context -> typ -> typ |
16348 | 41 |
val cert_typ_syntax: context -> typ -> typ |
42 |
val cert_typ_abbrev: context -> typ -> typ |
|
10583 | 43 |
val get_skolem: context -> string -> string |
9133 | 44 |
val extern_skolem: context -> term -> term |
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
45 |
val read_termTs: context -> (string -> bool) -> (indexname -> typ option) |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
46 |
-> (indexname -> sort option) -> string list -> (string * typ) list |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
47 |
-> term list * (indexname * typ) list |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
48 |
val read_termTs_schematic: context -> (string -> bool) -> (indexname -> typ option) |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
49 |
-> (indexname -> sort option) -> string list -> (string * typ) list |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
50 |
-> term list * (indexname * typ) list |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
51 |
val read_term_liberal: context -> string -> term |
5819 | 52 |
val read_term: context -> string -> term |
53 |
val read_prop: context -> string -> term |
|
11925 | 54 |
val read_prop_schematic: context -> string -> term |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
55 |
val read_terms: context -> string list -> term list |
8096 | 56 |
val read_term_pats: typ -> context -> string list -> term list |
57 |
val read_prop_pats: context -> string list -> term list |
|
5819 | 58 |
val cert_term: context -> term -> term |
59 |
val cert_prop: context -> term -> term |
|
8096 | 60 |
val cert_term_pats: typ -> context -> term list -> term list |
61 |
val cert_prop_pats: context -> term list -> term list |
|
5819 | 62 |
val declare_term: term -> context -> context |
15703 | 63 |
val read_tyname: context -> string -> typ |
64 |
val read_const: context -> string -> term |
|
7925 | 65 |
val warn_extra_tfrees: context -> context -> context |
12550
32843ad8160a
generalize type variables properly: start with occurrences in objects
wenzelm
parents:
12530
diff
changeset
|
66 |
val generalize: context -> context -> term list -> term list |
9470 | 67 |
val find_free: term -> string -> term option |
12008 | 68 |
val export: bool -> context -> context -> thm -> thm Seq.seq |
13415 | 69 |
val export_standard: cterm list -> context -> context -> thm -> thm |
15696 | 70 |
val export_plain: cterm list -> context -> context -> thm -> thm |
10810 | 71 |
val drop_schematic: indexname * term option -> indexname * term option |
72 |
val add_binds: (indexname * string option) list -> context -> context |
|
73 |
val add_binds_i: (indexname * term option) list -> context -> context |
|
12147 | 74 |
val auto_bind_goal: term list -> context -> context |
75 |
val auto_bind_facts: term list -> context -> context |
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
76 |
val match_bind: bool -> (string list * string) list -> context -> context |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
77 |
val match_bind_i: bool -> (term list * term) list -> context -> context |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
78 |
val read_propp: context * (string * (string list * string list)) list list |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
79 |
-> context * (term * (term list * term list)) list list |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
80 |
val cert_propp: context * (term * (term list * term list)) list list |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
81 |
-> context * (term * (term list * term list)) list list |
10554 | 82 |
val read_propp_schematic: context * (string * (string list * string list)) list list |
83 |
-> context * (term * (term list * term list)) list list |
|
84 |
val cert_propp_schematic: context * (term * (term list * term list)) list list |
|
85 |
-> context * (term * (term list * term list)) list list |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
86 |
val bind_propp: context * (string * (string list * string list)) list list |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
87 |
-> context * (term list list * (context -> context)) |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
88 |
val bind_propp_i: context * (term * (term list * term list)) list list |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
89 |
-> context * (term list list * (context -> context)) |
10554 | 90 |
val bind_propp_schematic: context * (string * (string list * string list)) list list |
91 |
-> context * (term list list * (context -> context)) |
|
92 |
val bind_propp_schematic_i: context * (term * (term list * term list)) list list |
|
93 |
-> context * (term list list * (context -> context)) |
|
15456
956d6acacf89
Specific theorems in a named list of theorems can now be referred to
berghofe
parents:
15452
diff
changeset
|
94 |
val get_thm: context -> thmref -> thm |
956d6acacf89
Specific theorems in a named list of theorems can now be referred to
berghofe
parents:
15452
diff
changeset
|
95 |
val get_thm_closure: context -> thmref -> thm |
956d6acacf89
Specific theorems in a named list of theorems can now be referred to
berghofe
parents:
15452
diff
changeset
|
96 |
val get_thms: context -> thmref -> thm list |
956d6acacf89
Specific theorems in a named list of theorems can now be referred to
berghofe
parents:
15452
diff
changeset
|
97 |
val get_thms_closure: context -> thmref -> thm list |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
98 |
val valid_thms: context -> string * thm list -> bool |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
99 |
val lthms_containing: context -> FactIndex.spec -> (string * thm list) list |
16348 | 100 |
val extern_thm: context -> string -> xstring |
16147 | 101 |
val qualified_names: context -> context |
102 |
val no_base_names: context -> context |
|
103 |
val custom_accesses: (string list -> string list list) -> context -> context |
|
104 |
val restore_naming: context -> context -> context |
|
13425
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
105 |
val hide_thms: bool -> string list -> context -> context |
6091 | 106 |
val put_thm: string * thm -> context -> context |
107 |
val put_thms: string * thm list -> context -> context |
|
108 |
val put_thmss: (string * thm list) list -> context -> context |
|
7606 | 109 |
val reset_thms: string -> context -> context |
14564 | 110 |
val note_thmss: |
16147 | 111 |
((bstring * context attribute list) * (thmref * context attribute list) list) list -> |
112 |
context -> context * (bstring * thm list) list |
|
14564 | 113 |
val note_thmss_i: |
16147 | 114 |
((bstring * context attribute list) * (thm list * context attribute list) list) list -> |
115 |
context -> context * (bstring * thm list) list |
|
11918
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
116 |
val export_assume: exporter |
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
117 |
val export_presume: exporter |
12086 | 118 |
val cert_def: context -> term -> string * term |
11918
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
119 |
val export_def: exporter |
9470 | 120 |
val assume: exporter |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
121 |
-> ((string * context attribute list) * (string * (string list * string list)) list) list |
12835 | 122 |
-> context -> context * (bstring * thm list) list |
9470 | 123 |
val assume_i: exporter |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
124 |
-> ((string * context attribute list) * (term * (term list * term list)) list) list |
12835 | 125 |
-> context -> context * (bstring * thm list) list |
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
126 |
val read_vars: context * (string list * string option) |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
127 |
-> context * (string list * typ option) |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
128 |
val cert_vars: context * (string list * typ option) |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
129 |
-> context * (string list * typ option) |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
130 |
val read_vars_liberal: context * (string list * string option) |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
131 |
-> context * (string list * typ option) |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
132 |
val cert_vars_liberal: context * (string list * typ option) |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
133 |
-> context * (string list * typ option) |
7411 | 134 |
val fix: (string list * string option) list -> context -> context |
7663 | 135 |
val fix_i: (string list * typ option) list -> context -> context |
14643 | 136 |
val add_fixes: (string * typ option * Syntax.mixfix option) list -> context -> context |
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
137 |
val add_fixes_liberal: (string * typ option * Syntax.mixfix option) list -> context -> context |
12016 | 138 |
val fix_frees: term list -> context -> context |
9291
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
139 |
val bind_skolem: context -> string list -> term -> term |
13425
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
140 |
val apply_case: RuleCases.T -> context |
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
141 |
-> context * ((indexname * term option) list * (string * term list) list) |
16147 | 142 |
val get_case: context -> string -> string option list -> RuleCases.T |
143 |
val add_cases: (string * RuleCases.T option) list -> context -> context |
|
10810 | 144 |
val verbose: bool ref |
145 |
val setmp_verbose: ('a -> 'b) -> 'a -> 'b |
|
12072
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
146 |
val print_syntax: context -> unit |
10810 | 147 |
val print_binds: context -> unit |
12057 | 148 |
val print_lthms: context -> unit |
10810 | 149 |
val print_cases: context -> unit |
150 |
val prems_limit: int ref |
|
12057 | 151 |
val pretty_asms: context -> Pretty.T list |
10810 | 152 |
val pretty_context: context -> Pretty.T list |
5819 | 153 |
end; |
154 |
||
16540 | 155 |
structure ProofContext: PROOF_CONTEXT = |
5819 | 156 |
struct |
157 |
||
16540 | 158 |
(** generic proof contexts **) |
9470 | 159 |
|
16540 | 160 |
type context = Context.proof; |
17072 | 161 |
exception CONTEXT = Context.PROOF; |
5819 | 162 |
|
16540 | 163 |
val theory_of = Context.theory_of_proof; |
16458 | 164 |
val sign_of = theory_of; |
5819 | 165 |
|
16540 | 166 |
val init = Context.init_proof; |
12057 | 167 |
|
7270 | 168 |
|
5819 | 169 |
|
16540 | 170 |
(** Isar proof context information **) |
5819 | 171 |
|
16540 | 172 |
type exporter = bool -> cterm list -> thm -> thm Seq.seq; |
5819 | 173 |
|
16540 | 174 |
datatype ctxt = |
175 |
Ctxt of |
|
17072 | 176 |
{syntax: (Syntax.syntax * Syntax.syntax * (Syntax.syntax -> Syntax.syntax)) * |
177 |
string list * string list, (*global/local syntax with structs and mixfixed*) |
|
16540 | 178 |
asms: |
17072 | 179 |
((cterm list * exporter) list * (*assumes: A ==> _*) |
180 |
(string * thm list) list) * (*prems: A |- A *) |
|
181 |
(string * string) list, (*fixes: !!x. _*) |
|
182 |
binds: (term * typ) Vartab.table, (*term bindings*) |
|
183 |
thms: NameSpace.naming * (*local thms*) |
|
16540 | 184 |
thm list NameSpace.table * FactIndex.T, |
17072 | 185 |
cases: (string * RuleCases.T) list, (*local contexts*) |
16540 | 186 |
defs: |
17072 | 187 |
typ Vartab.table * (*type constraints*) |
188 |
sort Vartab.table * (*default sorts*) |
|
189 |
string list * (*used type variables*) |
|
190 |
term list Symtab.table}; (*type variable occurrences*) |
|
5819 | 191 |
|
16540 | 192 |
fun make_ctxt (syntax, asms, binds, thms, cases, defs) = |
193 |
Ctxt {syntax = syntax, asms = asms, binds = binds, thms = thms, cases = cases, defs = defs}; |
|
5819 | 194 |
|
16540 | 195 |
structure ContextData = ProofDataFun |
16458 | 196 |
(struct |
16540 | 197 |
val name = "Isar/context"; |
198 |
type T = ctxt; |
|
199 |
fun init thy = |
|
17072 | 200 |
make_ctxt (((Sign.syn_of thy, Sign.syn_of thy, I), [], []), (([], []), []), |
201 |
Vartab.empty, (NameSpace.default_naming, NameSpace.empty_table, FactIndex.empty), [], |
|
16540 | 202 |
(Vartab.empty, Vartab.empty, [], Symtab.empty)); |
203 |
fun print _ _ = (); |
|
16458 | 204 |
end); |
5819 | 205 |
|
16540 | 206 |
val _ = Context.add_setup [ContextData.init]; |
5819 | 207 |
|
16540 | 208 |
fun rep_context ctxt = ContextData.get ctxt |> (fn Ctxt args => args); |
5819 | 209 |
|
16540 | 210 |
fun map_context f = ContextData.map (fn Ctxt {syntax, asms, binds, thms, cases, defs} => |
211 |
make_ctxt (f (syntax, asms, binds, thms, cases, defs))); |
|
5819 | 212 |
|
16540 | 213 |
val syntax_of = #syntax o rep_context; |
5819 | 214 |
|
16540 | 215 |
val assumptions_of = #1 o #1 o #asms o rep_context; |
216 |
val prems_of = List.concat o map #2 o #2 o #1 o #asms o rep_context; |
|
217 |
val fixes_of = #2 o #asms o rep_context; |
|
218 |
val fixed_names_of = map #2 o fixes_of; |
|
5819 | 219 |
|
16540 | 220 |
val binds_of = #binds o rep_context; |
5819 | 221 |
|
16540 | 222 |
val thms_of = #thms o rep_context; |
223 |
val fact_index_of = #3 o thms_of; |
|
224 |
||
225 |
val cases_of = #cases o rep_context; |
|
5819 | 226 |
|
16540 | 227 |
val defaults_of = #defs o rep_context; |
228 |
val type_occs_of = #4 o defaults_of; |
|
5819 | 229 |
|
16540 | 230 |
fun is_fixed ctxt x = exists (equal x o #2) (fixes_of ctxt); |
16894 | 231 |
fun is_known ctxt x = Vartab.defined (#1 (defaults_of ctxt)) (x, ~1) orelse is_fixed ctxt x; |
5819 | 232 |
|
233 |
||
8096 | 234 |
|
12093 | 235 |
(** local syntax **) |
236 |
||
237 |
val fixedN = "\\<^fixed>"; |
|
238 |
val structN = "\\<^struct>"; |
|
239 |
||
12100 | 240 |
|
14697 | 241 |
(* translation functions *) |
14665
d2e5df3d1201
index syntax: support for general expressions (input only);
wenzelm
parents:
14643
diff
changeset
|
242 |
|
d2e5df3d1201
index syntax: support for general expressions (input only);
wenzelm
parents:
14643
diff
changeset
|
243 |
fun fixed_tr x = (fixedN ^ x, curry Term.list_comb (Syntax.free x)); |
d2e5df3d1201
index syntax: support for general expressions (input only);
wenzelm
parents:
14643
diff
changeset
|
244 |
|
12100 | 245 |
fun context_tr' ctxt = |
246 |
let |
|
247 |
val (_, structs, mixfixed) = syntax_of ctxt; |
|
248 |
||
249 |
fun tr' (t $ u) = tr' t $ tr' u |
|
250 |
| tr' (Abs (x, T, t)) = Abs (x, T, tr' t) |
|
251 |
| tr' (t as Free (x, T)) = |
|
14697 | 252 |
let val i = Library.find_index_eq x structs + 1 in |
253 |
if i = 0 andalso x mem_string mixfixed then Const (fixedN ^ x, T) |
|
14707 | 254 |
else if i = 1 andalso not (! show_structs) then |
255 |
Syntax.const "_struct" $ Syntax.const "_indexdefault" |
|
12100 | 256 |
else t |
257 |
end |
|
258 |
| tr' a = a; |
|
259 |
in tr' end; |
|
260 |
||
261 |
||
12576
9fd10052c3f7
added add_fixes: derives mssing type scheme from mixfix;
wenzelm
parents:
12550
diff
changeset
|
262 |
(* add syntax *) |
9fd10052c3f7
added add_fixes: derives mssing type scheme from mixfix;
wenzelm
parents:
12550
diff
changeset
|
263 |
|
9fd10052c3f7
added add_fixes: derives mssing type scheme from mixfix;
wenzelm
parents:
12550
diff
changeset
|
264 |
fun mixfix_type mx = replicate (Syntax.mixfix_args mx) TypeInfer.logicT ---> TypeInfer.logicT; |
12093 | 265 |
|
266 |
local |
|
267 |
||
15531 | 268 |
fun mixfix x NONE mx = (fixedN ^ x, mixfix_type mx, Syntax.fix_mixfix x mx) |
269 |
| mixfix x (SOME T) mx = (fixedN ^ x, T, Syntax.fix_mixfix x mx); |
|
12093 | 270 |
|
15531 | 271 |
fun prep_mixfix (_, _, NONE) = NONE |
272 |
| prep_mixfix (x, opt_T, SOME mx) = SOME (mixfix x opt_T mx); |
|
12093 | 273 |
|
15531 | 274 |
fun prep_mixfix' (_, _, NONE) = NONE |
275 |
| prep_mixfix' (x, _, SOME Syntax.NoSyn) = NONE |
|
276 |
| prep_mixfix' (x, opt_T, _) = SOME (x, mixfix x opt_T (Syntax.literal x)); |
|
12093 | 277 |
|
15531 | 278 |
fun prep_struct (x, _, NONE) = SOME x |
279 |
| prep_struct _ = NONE; |
|
12093 | 280 |
|
15750 | 281 |
fun mk trs = map Syntax.mk_trfun trs; |
282 |
||
17072 | 283 |
fun extend_syntax thy extend (global_syn, syn, mk_syn) = |
284 |
let |
|
285 |
val thy_syn = Sign.syn_of thy; |
|
286 |
val mk_syn' = extend o mk_syn; |
|
287 |
val (global_syn', syn') = |
|
288 |
if Syntax.eq_syntax (global_syn, thy_syn) |
|
289 |
then (global_syn, extend syn) |
|
290 |
else (thy_syn, mk_syn' thy_syn); (*potentially expensive*) |
|
291 |
in (global_syn', syn', mk_syn') end; |
|
292 |
||
12093 | 293 |
in |
294 |
||
17072 | 295 |
fun add_syntax decls ctxt = ctxt |> map_context (fn (syntax, asms, binds, thms, cases, defs) => |
296 |
let |
|
297 |
val (syns, structs, mixfixed) = syntax; |
|
298 |
val thy = theory_of ctxt; |
|
299 |
||
300 |
val is_logtype = Sign.is_logtype thy; |
|
301 |
val structs' = structs @ List.mapPartial prep_struct decls; |
|
302 |
val mxs = List.mapPartial prep_mixfix decls; |
|
303 |
val (fixed, mxs_output) = Library.split_list (List.mapPartial prep_mixfix' decls); |
|
304 |
val trs = map fixed_tr fixed; |
|
12093 | 305 |
|
17072 | 306 |
val extend = |
307 |
Syntax.extend_const_gram is_logtype ("", false) mxs_output |
|
308 |
#> Syntax.extend_const_gram is_logtype ("", true) mxs |
|
309 |
#> Syntax.extend_trfuns ([], mk trs, [], []); |
|
310 |
val syns' = extend_syntax thy extend syns; |
|
311 |
in ((syns', structs', fixed @ mixfixed), asms, binds, thms, cases, defs) end); |
|
312 |
||
313 |
fun syn_of' thy ctxt = |
|
16540 | 314 |
let |
17072 | 315 |
val (syns, structs, _) = syntax_of ctxt; |
16540 | 316 |
val (atrs, trs, trs', atrs') = Syntax.struct_trfuns structs; |
17072 | 317 |
val extend = Syntax.extend_trfuns (mk atrs, mk trs, mk trs', mk atrs'); |
318 |
in #2 (extend_syntax thy extend syns) end; |
|
319 |
||
320 |
fun syn_of ctxt = syn_of' (theory_of ctxt) ctxt; |
|
14697 | 321 |
|
12093 | 322 |
end; |
323 |
||
17072 | 324 |
fun transfer thy = add_syntax [] o Context.transfer_proof thy; |
325 |
||
12093 | 326 |
|
327 |
||
14828 | 328 |
(** pretty printing **) |
329 |
||
17072 | 330 |
fun pretty_term' thy ctxt t = Sign.pretty_term' (syn_of' thy ctxt) thy (context_tr' ctxt t); |
331 |
fun pretty_term ctxt t = pretty_term' (theory_of ctxt) ctxt (context_tr' ctxt t); |
|
16458 | 332 |
fun pretty_typ ctxt T = Sign.pretty_typ (theory_of ctxt) T; |
333 |
fun pretty_sort ctxt S = Sign.pretty_sort (theory_of ctxt) S; |
|
334 |
fun pretty_classrel ctxt cs = Sign.pretty_classrel (theory_of ctxt) cs; |
|
335 |
fun pretty_arity ctxt ar = Sign.pretty_arity (theory_of ctxt) ar; |
|
14828 | 336 |
|
14974
b1ecb7859c99
avoid premature evaluation of syn_of (wastes time in conjunction with pp);
wenzelm
parents:
14901
diff
changeset
|
337 |
fun pp ctxt = Pretty.pp (pretty_term ctxt, pretty_typ ctxt, pretty_sort ctxt, |
b1ecb7859c99
avoid premature evaluation of syn_of (wastes time in conjunction with pp);
wenzelm
parents:
14901
diff
changeset
|
338 |
pretty_classrel ctxt, pretty_arity ctxt); |
14828 | 339 |
|
340 |
val string_of_term = Pretty.string_of oo pretty_term; |
|
341 |
||
342 |
fun pretty_thm ctxt thm = |
|
343 |
if ! Display.show_hyps then |
|
14876 | 344 |
Display.pretty_thm_aux (pp ctxt) false thm |
14828 | 345 |
else pretty_term ctxt (Thm.prop_of thm); |
346 |
||
347 |
fun pretty_thms ctxt [th] = pretty_thm ctxt th |
|
348 |
| pretty_thms ctxt ths = Pretty.blk (0, Pretty.fbreaks (map (pretty_thm ctxt) ths)); |
|
349 |
||
350 |
fun pretty_fact ctxt ("", ths) = pretty_thms ctxt ths |
|
351 |
| pretty_fact ctxt (a, [th]) = |
|
352 |
Pretty.block [Pretty.str (a ^ ":"), Pretty.brk 1, pretty_thm ctxt th] |
|
353 |
| pretty_fact ctxt (a, ths) = |
|
354 |
Pretty.block (Pretty.fbreaks (Pretty.str (a ^ ":") :: map (pretty_thm ctxt) ths)); |
|
355 |
||
17072 | 356 |
fun pretty_proof ctxt prf = |
357 |
pretty_term' (ProofSyntax.proof_syntax prf (theory_of ctxt)) ctxt |
|
358 |
(ProofSyntax.term_of_proof prf); |
|
359 |
||
360 |
fun pretty_proof_of ctxt full th = |
|
361 |
pretty_proof ctxt (ProofSyntax.proof_of full th); |
|
362 |
||
14828 | 363 |
|
364 |
||
7663 | 365 |
(** default sorts and types **) |
366 |
||
16540 | 367 |
fun def_sort ctxt xi = Vartab.lookup (#2 (defaults_of ctxt), xi); |
7663 | 368 |
|
16540 | 369 |
fun def_type ctxt pattern xi = |
370 |
let val {binds, defs = (types, _, _, _), ...} = rep_context ctxt in |
|
371 |
(case Vartab.lookup (types, xi) of |
|
372 |
NONE => |
|
373 |
if pattern then NONE |
|
374 |
else Vartab.lookup (binds, xi) |> Option.map (TypeInfer.polymorphicT o #2) |
|
375 |
| some => some) |
|
376 |
end; |
|
7663 | 377 |
|
16540 | 378 |
fun default_type ctxt x = Vartab.lookup (#1 (defaults_of ctxt), (x, ~1)); |
379 |
val used_types = #3 o defaults_of; |
|
12414 | 380 |
|
7663 | 381 |
|
5819 | 382 |
|
383 |
(** prepare types **) |
|
384 |
||
9504 | 385 |
local |
386 |
||
387 |
fun read_typ_aux read ctxt s = |
|
16458 | 388 |
transform_error (read (syn_of ctxt) (theory_of ctxt, def_sort ctxt)) s |
7663 | 389 |
handle ERROR_MESSAGE msg => raise CONTEXT (msg, ctxt); |
5819 | 390 |
|
10554 | 391 |
fun cert_typ_aux cert ctxt raw_T = |
16458 | 392 |
cert (theory_of ctxt) raw_T |
10554 | 393 |
handle TYPE (msg, _, _) => raise CONTEXT (msg, ctxt); |
9504 | 394 |
|
395 |
in |
|
396 |
||
16348 | 397 |
val read_typ = read_typ_aux Sign.read_typ'; |
398 |
val read_typ_syntax = read_typ_aux Sign.read_typ_syntax'; |
|
399 |
val read_typ_abbrev = read_typ_aux Sign.read_typ_abbrev'; |
|
400 |
val cert_typ = cert_typ_aux Sign.certify_typ; |
|
401 |
val cert_typ_syntax = cert_typ_aux Sign.certify_typ_syntax; |
|
402 |
val cert_typ_abbrev = cert_typ_aux Sign.certify_typ_abbrev; |
|
9504 | 403 |
|
404 |
end; |
|
405 |
||
5819 | 406 |
|
7679 | 407 |
(* internalize Skolem constants *) |
408 |
||
10583 | 409 |
fun lookup_skolem ctxt x = assoc (fixes_of ctxt, x); |
15974 | 410 |
fun get_skolem ctxt x = if_none (lookup_skolem ctxt x) x; |
7679 | 411 |
|
12504 | 412 |
fun no_skolem internal ctxt x = |
9291
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
413 |
if can Syntax.dest_skolem x then |
7679 | 414 |
raise CONTEXT ("Illegal reference to internal Skolem constant: " ^ quote x, ctxt) |
12504 | 415 |
else if not internal andalso can Syntax.dest_internal x then |
9291
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
416 |
raise CONTEXT ("Illegal reference to internal variable: " ^ quote x, ctxt) |
7679 | 417 |
else x; |
418 |
||
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
419 |
fun intern_skolem ctxt internal = |
7679 | 420 |
let |
421 |
fun intern (t as Free (x, T)) = |
|
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
422 |
if internal x then t |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
423 |
else |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
424 |
(case lookup_skolem ctxt (no_skolem false ctxt x) of |
15531 | 425 |
SOME x' => Free (x', T) |
426 |
| NONE => t) |
|
7679 | 427 |
| intern (t $ u) = intern t $ intern u |
428 |
| intern (Abs (x, T, t)) = Abs (x, T, intern t) |
|
429 |
| intern a = a; |
|
430 |
in intern end; |
|
431 |
||
432 |
||
9133 | 433 |
(* externalize Skolem constants -- for printing purposes only *) |
434 |
||
435 |
fun extern_skolem ctxt = |
|
436 |
let |
|
437 |
val rev_fixes = map Library.swap (fixes_of ctxt); |
|
438 |
||
439 |
fun extern (t as Free (x, T)) = |
|
440 |
(case assoc (rev_fixes, x) of |
|
15531 | 441 |
SOME x' => Free (if lookup_skolem ctxt x' = SOME x then x' else NameSpace.hidden x', T) |
442 |
| NONE => t) |
|
9133 | 443 |
| extern (t $ u) = extern t $ extern u |
444 |
| extern (Abs (x, T, t)) = Abs (x, T, extern t) |
|
445 |
| extern a = a; |
|
446 |
in extern end |
|
447 |
||
8096 | 448 |
|
5819 | 449 |
(** prepare terms and propositions **) |
450 |
||
451 |
(* |
|
16501 | 452 |
(1) read / certify wrt. theory of context |
5819 | 453 |
(2) intern Skolem constants |
454 |
(3) expand term bindings |
|
455 |
*) |
|
456 |
||
457 |
||
16501 | 458 |
(* read wrt. theory *) (*exception ERROR*) |
5819 | 459 |
|
16458 | 460 |
fun read_def_termTs freeze pp syn thy (types, sorts, used) sTs = |
461 |
Sign.read_def_terms' pp (Sign.is_logtype thy) syn (thy, types, sorts) used freeze sTs; |
|
5874 | 462 |
|
16458 | 463 |
fun read_def_termT freeze pp syn thy defs sT = |
464 |
apfst hd (read_def_termTs freeze pp syn thy defs [sT]); |
|
14828 | 465 |
|
16458 | 466 |
fun read_term_thy freeze pp syn thy defs s = |
467 |
#1 (read_def_termT freeze pp syn thy defs (s, TypeInfer.logicT)); |
|
5874 | 468 |
|
16458 | 469 |
fun read_prop_thy freeze pp syn thy defs s = |
470 |
#1 (read_def_termT freeze pp syn thy defs (s, propT)); |
|
12072
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
471 |
|
16458 | 472 |
fun read_terms_thy freeze pp syn thy defs = |
473 |
#1 o read_def_termTs freeze pp syn thy defs o map (rpair TypeInfer.logicT); |
|
12072
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
474 |
|
16458 | 475 |
fun read_props_thy freeze pp syn thy defs = |
476 |
#1 o read_def_termTs freeze pp syn thy defs o map (rpair propT); |
|
5819 | 477 |
|
478 |
||
479 |
(* norm_term *) |
|
480 |
||
481 |
(*beta normal form for terms (not eta normal form), chase variables in |
|
482 |
bindings environment (code taken from Pure/envir.ML)*) |
|
483 |
||
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
484 |
fun unifyT ctxt (T, U) = |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
485 |
let val maxidx = Int.max (Term.maxidx_of_typ T, Term.maxidx_of_typ U) |
16948 | 486 |
in #1 (Sign.typ_unify (theory_of ctxt) (T, U) (Vartab.empty, maxidx)) end; |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
487 |
|
16540 | 488 |
fun norm_term ctxt schematic = |
5819 | 489 |
let |
490 |
(*raised when norm has no effect on a term, to do sharing instead of copying*) |
|
491 |
exception SAME; |
|
492 |
||
16540 | 493 |
val binds = binds_of ctxt; |
5819 | 494 |
fun norm (t as Var (xi, T)) = |
495 |
(case Vartab.lookup (binds, xi) of |
|
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
496 |
SOME (u, U) => |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
497 |
let |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
498 |
val env = unifyT ctxt (T, U) handle Type.TUNIFY => |
14174
f3cafd2929d5
Methods rule_tac etc support static (Isar) contexts.
ballarin
parents:
13629
diff
changeset
|
499 |
raise TYPE ("norm_term: ill-typed variable assignment", [T, U], [t, u]); |
15798
016f3be5a5ec
Adapted to new interface of instantiation and unification / matching functions.
berghofe
parents:
15758
diff
changeset
|
500 |
val u' = Envir.subst_TVars env u; |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
501 |
in norm u' handle SAME => u' end |
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
502 |
| NONE => |
10554 | 503 |
if schematic then raise SAME |
504 |
else raise CONTEXT ("Unbound schematic variable: " ^ Syntax.string_of_vname xi, ctxt)) |
|
5819 | 505 |
| norm (Abs (a, T, body)) = Abs (a, T, norm body) |
506 |
| norm (Abs (_, _, body) $ t) = normh (subst_bound (t, body)) |
|
507 |
| norm (f $ t) = |
|
508 |
((case norm f of |
|
509 |
Abs (_, _, body) => normh (subst_bound (t, body)) |
|
510 |
| nf => nf $ (norm t handle SAME => t)) handle SAME => f $ norm t) |
|
511 |
| norm _ = raise SAME |
|
512 |
and normh t = norm t handle SAME => t |
|
513 |
in normh end; |
|
514 |
||
515 |
||
6550 | 516 |
(* dummy patterns *) |
517 |
||
9540 | 518 |
fun prepare_dummies t = #2 (Term.replace_dummy_patterns (1, t)); |
6762 | 519 |
|
9540 | 520 |
fun reject_dummies ctxt t = Term.no_dummy_patterns t |
521 |
handle TERM _ => raise CONTEXT ("Illegal dummy pattern(s) in term", ctxt); |
|
6550 | 522 |
|
523 |
||
5819 | 524 |
(* read terms *) |
525 |
||
10554 | 526 |
local |
527 |
||
15531 | 528 |
fun append_env e1 e2 x = (case e2 x of NONE => e1 x | some => some); |
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
529 |
|
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
530 |
fun gen_read' read app pattern schematic |
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
531 |
ctxt internal more_types more_sorts more_used s = |
14174
f3cafd2929d5
Methods rule_tac etc support static (Isar) contexts.
ballarin
parents:
13629
diff
changeset
|
532 |
let |
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
533 |
val types = append_env (def_type ctxt pattern) more_types; |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
534 |
val sorts = append_env (def_sort ctxt) more_sorts; |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
535 |
val used = used_types ctxt @ more_used; |
14174
f3cafd2929d5
Methods rule_tac etc support static (Isar) contexts.
ballarin
parents:
13629
diff
changeset
|
536 |
in |
16458 | 537 |
(transform_error (read (pp ctxt) (syn_of ctxt) (theory_of ctxt) (types, sorts, used)) s |
14174
f3cafd2929d5
Methods rule_tac etc support static (Isar) contexts.
ballarin
parents:
13629
diff
changeset
|
538 |
handle TERM (msg, _) => raise CONTEXT (msg, ctxt) |
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
539 |
| ERROR_MESSAGE msg => raise CONTEXT (msg, ctxt)) |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
540 |
|> app (intern_skolem ctxt internal) |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
541 |
|> app (if pattern then I else norm_term ctxt schematic) |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
542 |
|> app (if pattern then prepare_dummies else reject_dummies ctxt) |
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
543 |
end; |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
544 |
|
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
545 |
fun gen_read read app pattern schematic ctxt = |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
546 |
gen_read' read app pattern schematic ctxt (K false) (K NONE) (K NONE) []; |
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
547 |
|
10554 | 548 |
in |
549 |
||
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
550 |
val read_termTs = gen_read' (read_def_termTs false) (apfst o map) false false; |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
551 |
val read_termTs_schematic = gen_read' (read_def_termTs false) (apfst o map) false true; |
8096 | 552 |
|
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
553 |
fun read_term_pats T ctxt = |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
554 |
#1 o gen_read (read_def_termTs false) (apfst o map) true false ctxt o map (rpair T); |
8096 | 555 |
val read_prop_pats = read_term_pats propT; |
556 |
||
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
557 |
fun read_term_liberal ctxt = |
16458 | 558 |
gen_read' (read_term_thy true) I false false ctxt (K true) (K NONE) (K NONE) []; |
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
559 |
|
16458 | 560 |
val read_term = gen_read (read_term_thy true) I false false; |
561 |
val read_prop = gen_read (read_prop_thy true) I false false; |
|
562 |
val read_prop_schematic = gen_read (read_prop_thy true) I false true; |
|
563 |
val read_terms = gen_read (read_terms_thy true) map false false; |
|
564 |
fun read_props schematic = gen_read (read_props_thy true) map false schematic; |
|
5819 | 565 |
|
10554 | 566 |
end; |
567 |
||
5819 | 568 |
|
569 |
(* certify terms *) |
|
570 |
||
10554 | 571 |
local |
572 |
||
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
573 |
fun gen_cert cert pattern schematic ctxt t = t |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
574 |
|> (if pattern then I else norm_term ctxt schematic) |
16458 | 575 |
|> (fn t' => cert (pp ctxt) (theory_of ctxt) t' |
16501 | 576 |
handle TYPE (msg, _, _) => raise CONTEXT (msg, ctxt) |
577 |
| TERM (msg, _) => raise CONTEXT (msg, ctxt)); |
|
578 |
||
579 |
val certify_term = #1 ooo Sign.certify_term; |
|
580 |
val certify_prop = #1 ooo Sign.certify_prop; |
|
5819 | 581 |
|
10554 | 582 |
in |
8096 | 583 |
|
16501 | 584 |
val cert_term = gen_cert certify_term false false; |
585 |
val cert_prop = gen_cert certify_prop false false; |
|
586 |
val cert_props = map oo gen_cert certify_prop false; |
|
10554 | 587 |
|
16501 | 588 |
fun cert_term_pats _ = map o gen_cert certify_term true false; |
589 |
val cert_prop_pats = map o gen_cert certify_prop true false; |
|
10554 | 590 |
|
591 |
end; |
|
5819 | 592 |
|
593 |
||
594 |
(* declare terms *) |
|
595 |
||
10381 | 596 |
local |
597 |
||
16861 | 598 |
val ins_types = fold_aterms |
599 |
(fn Free (x, T) => curry Vartab.update ((x, ~1), T) |
|
600 |
| Var v => curry Vartab.update v |
|
601 |
| _ => I); |
|
5819 | 602 |
|
16861 | 603 |
val ins_sorts = fold_types (fold_atyps |
604 |
(fn TFree (x, S) => curry Vartab.update ((x, ~1), S) |
|
605 |
| TVar v => curry Vartab.update v |
|
606 |
| _ => I)); |
|
5819 | 607 |
|
16861 | 608 |
val ins_used = fold_term_types (fn t => |
609 |
fold_atyps (fn TFree (x, _) => insert (op =) x | _ => I)); |
|
12291 | 610 |
|
16861 | 611 |
val ins_occs = fold_term_types (fn t => |
612 |
fold_atyps (fn TFree (x, _) => curry Symtab.update_multi (x, t) | _ => I)); |
|
5819 | 613 |
|
16861 | 614 |
fun ins_skolem def_ty = fold_rev (fn (x, x') => |
615 |
(case def_ty x' of |
|
616 |
SOME T => curry Vartab.update ((x, ~1), T) |
|
617 |
| NONE => I)); |
|
5994 | 618 |
|
16540 | 619 |
fun map_defaults f = map_context (fn (syntax, asms, binds, thms, cases, defs) => |
620 |
(syntax, asms, binds, thms, cases, f defs)); |
|
5819 | 621 |
|
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
622 |
in |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
623 |
|
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
624 |
fun declare_term_syntax t ctxt = |
5819 | 625 |
ctxt |
16861 | 626 |
|> map_defaults (fn (types, sorts, used, occ) => (ins_types t types, sorts, used, occ)) |
627 |
|> map_defaults (fn (types, sorts, used, occ) => (types, ins_sorts t sorts, used, occ)) |
|
628 |
|> map_defaults (fn (types, sorts, used, occ) => (types, sorts, ins_used t used, occ)); |
|
10381 | 629 |
|
16540 | 630 |
fun declare_term t ctxt = |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
631 |
ctxt |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
632 |
|> declare_term_syntax t |
16861 | 633 |
|> map_defaults (fn (types, sorts, used, occ) => (types, sorts, used, ins_occs t occ)) |
12291 | 634 |
|> map_defaults (fn (types, sorts, used, occ) => |
16861 | 635 |
(ins_skolem (fn x => Vartab.lookup (types, (x, ~1))) (fixes_of ctxt) types, |
636 |
sorts, used, occ)); |
|
5819 | 637 |
|
10381 | 638 |
end; |
5819 | 639 |
|
640 |
||
15703 | 641 |
(* type and constant names *) |
642 |
||
643 |
fun read_tyname ctxt c = |
|
644 |
if c mem_string used_types ctxt then |
|
16458 | 645 |
TFree (c, if_none (def_sort ctxt (c, ~1)) (Sign.defaultS (theory_of ctxt))) |
646 |
else Sign.read_tyname (theory_of ctxt) c; |
|
15703 | 647 |
|
648 |
fun read_const ctxt c = |
|
649 |
(case lookup_skolem ctxt c of |
|
650 |
SOME c' => Free (c', dummyT) |
|
16458 | 651 |
| NONE => Sign.read_const (theory_of ctxt) c); |
15703 | 652 |
|
653 |
||
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
654 |
|
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
655 |
(** Hindley-Milner polymorphism **) |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
656 |
|
7925 | 657 |
(* warn_extra_tfrees *) |
658 |
||
16540 | 659 |
fun warn_extra_tfrees ctxt1 ctxt2 = |
12130
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
660 |
let |
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
661 |
fun known_tfree a (Type (_, Ts)) = exists (known_tfree a) Ts |
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
662 |
| known_tfree a (TFree (a', _)) = a = a' |
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
663 |
| known_tfree _ _ = false; |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
664 |
|
12130
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
665 |
val extras = |
16540 | 666 |
Library.gen_rems Library.eq_fst (pairself (Symtab.dest o type_occs_of) (ctxt1, ctxt2)) |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
667 |
|> map (fn (a, ts) => map (pair a) (List.mapPartial (try (#1 o Term.dest_Free)) ts)) |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
668 |
|> List.concat |
15570 | 669 |
|> List.mapPartial (fn (a, x) => |
15531 | 670 |
(case def_type ctxt1 false (x, ~1) of NONE => SOME (a, x) |
671 |
| SOME T => if known_tfree a T then NONE else SOME (a, x))); |
|
12130
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
672 |
val tfrees = map #1 extras |> Library.sort_strings |> Library.unique_strings; |
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
673 |
val frees = map #2 extras |> Library.sort_strings |> Library.unique_strings; |
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
674 |
in |
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
675 |
if null extras then () |
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
676 |
else warning ("Just introduced free type variable(s): " ^ commas tfrees ^ " in " ^ |
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
677 |
space_implode " or " frees); |
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
678 |
ctxt2 |
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
679 |
end; |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
680 |
|
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
681 |
|
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
682 |
(* generalize type variables *) |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
683 |
|
12550
32843ad8160a
generalize type variables properly: start with occurrences in objects
wenzelm
parents:
12530
diff
changeset
|
684 |
fun generalize_tfrees inner outer = |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
685 |
let |
12057 | 686 |
val extra_fixes = fixed_names_of inner \\ fixed_names_of outer; |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
687 |
fun still_fixed (Free (x, _)) = not (x mem_string extra_fixes) |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
688 |
| still_fixed _ = false; |
16540 | 689 |
val occs_inner = type_occs_of inner; |
690 |
val occs_outer = type_occs_of outer; |
|
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
691 |
fun add a gen = |
16894 | 692 |
if Symtab.defined occs_outer a orelse |
12550
32843ad8160a
generalize type variables properly: start with occurrences in objects
wenzelm
parents:
12530
diff
changeset
|
693 |
exists still_fixed (Symtab.lookup_multi (occs_inner, a)) |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
694 |
then gen else a :: gen; |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
695 |
in fn tfrees => fold add tfrees [] end; |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
696 |
|
12550
32843ad8160a
generalize type variables properly: start with occurrences in objects
wenzelm
parents:
12530
diff
changeset
|
697 |
fun generalize inner outer ts = |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
698 |
let |
15574
b1d1b5bfc464
Removed practically all references to Library.foldr.
skalberg
parents:
15570
diff
changeset
|
699 |
val tfrees = generalize_tfrees inner outer (foldr Term.add_term_tfree_names [] ts); |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
700 |
fun gen (x, S) = if x mem_string tfrees then TVar ((x, 0), S) else TFree (x, S); |
12550
32843ad8160a
generalize type variables properly: start with occurrences in objects
wenzelm
parents:
12530
diff
changeset
|
701 |
in map (Term.map_term_types (Term.map_type_tfree gen)) ts end; |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
702 |
|
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
703 |
|
9553 | 704 |
|
705 |
(** export theorems **) |
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
706 |
|
16861 | 707 |
fun get_free x (t as Free (y, _)) NONE = if x = y then SOME t else NONE |
708 |
| get_free _ _ opt = opt; |
|
16790 | 709 |
|
16861 | 710 |
fun find_free t x = fold_aterms (get_free x) t NONE; |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
711 |
|
13415 | 712 |
fun export_view view is_goal inner outer = |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
713 |
let |
12550
32843ad8160a
generalize type variables properly: start with occurrences in objects
wenzelm
parents:
12530
diff
changeset
|
714 |
val gen = generalize_tfrees inner outer; |
12057 | 715 |
val fixes = fixed_names_of inner \\ fixed_names_of outer; |
716 |
val asms = Library.drop (length (assumptions_of outer), assumptions_of inner); |
|
11816 | 717 |
val exp_asms = map (fn (cprops, exp) => exp is_goal cprops) asms; |
16948 | 718 |
in |
719 |
Tactic.norm_hhf_rule |
|
720 |
#> Seq.EVERY (rev exp_asms) |
|
721 |
#> Seq.map (Drule.implies_intr_list view) |
|
722 |
#> Seq.map (fn rule => |
|
11816 | 723 |
let |
16992 | 724 |
val thy = Thm.theory_of_thm rule; |
725 |
val prop = Thm.full_prop_of rule; |
|
16458 | 726 |
val frees = map (Thm.cterm_of thy) (List.mapPartial (find_free prop) fixes); |
12550
32843ad8160a
generalize type variables properly: start with occurrences in objects
wenzelm
parents:
12530
diff
changeset
|
727 |
val tfrees = gen (Term.add_term_tfree_names (prop, [])); |
11816 | 728 |
in |
729 |
rule |
|
730 |
|> Drule.forall_intr_list frees |
|
12804 | 731 |
|> Tactic.norm_hhf_rule |
12504 | 732 |
|> (#1 o Drule.tvars_intr_list tfrees) |
11816 | 733 |
end) |
734 |
end; |
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
735 |
|
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
736 |
(*without varification*) |
15696 | 737 |
fun export_view' view is_goal inner outer = |
738 |
let |
|
739 |
val asms = Library.drop (length (assumptions_of outer), assumptions_of inner); |
|
740 |
val exp_asms = map (fn (cprops, exp) => exp is_goal cprops) asms; |
|
16948 | 741 |
in |
742 |
Tactic.norm_hhf_plain |
|
743 |
#> Seq.EVERY (rev exp_asms) |
|
744 |
#> Seq.map (Drule.implies_intr_list view) |
|
745 |
#> Seq.map Tactic.norm_hhf_plain |
|
15696 | 746 |
end; |
747 |
||
13415 | 748 |
val export = export_view []; |
13399
c136276dc847
support locale ``views'' (for cumulative predicates);
wenzelm
parents:
13378
diff
changeset
|
749 |
|
15696 | 750 |
fun gen_export_std exp_view view inner outer = |
751 |
let val exp = exp_view view false inner outer in |
|
13378 | 752 |
fn th => |
753 |
(case Seq.pull (exp th) of |
|
15531 | 754 |
SOME (th', _) => th' |> Drule.local_standard |
16850 | 755 |
| NONE => sys_error "Failed to export theorem") |
13378 | 756 |
end; |
12704 | 757 |
|
15696 | 758 |
val export_standard = gen_export_std export_view; |
759 |
val export_plain = gen_export_std export_view'; |
|
7925 | 760 |
|
5819 | 761 |
|
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
762 |
|
5819 | 763 |
(** bindings **) |
764 |
||
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
765 |
(* delete_update_binds *) |
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
766 |
|
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
767 |
local |
5819 | 768 |
|
16540 | 769 |
fun del_bind xi = map_context (fn (syntax, asms, binds, thms, cases, defs) => |
770 |
(syntax, asms, Vartab.delete_safe xi binds, thms, cases, defs)); |
|
7606 | 771 |
|
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
772 |
fun upd_bind ((x, i), t) = |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
773 |
let |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
774 |
val T = Term.fastype_of t; |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
775 |
val t' = |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
776 |
if null (Term.term_tvars t \\ Term.typ_tvars T) then t |
8637 | 777 |
else Var ((x ^ "_has_extra_type_vars_on_rhs", i), T); |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
778 |
in |
16540 | 779 |
map_context (fn (syntax, asms, binds, thms, cases, defs) => |
780 |
(syntax, asms, Vartab.update (((x, i), (t', T)), binds), thms, cases, defs)) |
|
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
781 |
o declare_term t' |
5819 | 782 |
end; |
783 |
||
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
784 |
fun del_upd_bind (xi, NONE) = del_bind xi |
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
785 |
| del_upd_bind (xi, SOME t) = upd_bind (xi, t); |
7606 | 786 |
|
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
787 |
in |
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
788 |
|
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
789 |
val delete_update_binds = fold del_upd_bind; |
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
790 |
|
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
791 |
end; |
7606 | 792 |
|
5819 | 793 |
|
8096 | 794 |
(* simult_matches *) |
795 |
||
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
796 |
fun simult_matches ctxt [] = [] |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
797 |
| simult_matches ctxt pairs = |
8096 | 798 |
let |
10554 | 799 |
fun fail () = raise CONTEXT ("Pattern match failed!", ctxt); |
800 |
||
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
801 |
val maxidx = fold (fn (t1, t2) => fn i => |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
802 |
Int.max (Int.max (Term.maxidx_of_term t1, Term.maxidx_of_term t2), i)) pairs ~1; |
16458 | 803 |
val envs = Unify.smash_unifiers (theory_of ctxt, Envir.empty maxidx, |
10554 | 804 |
map swap pairs); (*prefer assignment of variables from patterns*) |
805 |
val env = |
|
8096 | 806 |
(case Seq.pull envs of |
15531 | 807 |
NONE => fail () |
808 |
| SOME (env, _) => env); (*ignore further results*) |
|
12309
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
809 |
val domain = |
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
810 |
filter_out Term.is_replaced_dummy_pattern (map #1 (Drule.vars_of_terms (map #1 pairs))); |
10554 | 811 |
val _ = (*may not assign variables from text*) |
12309
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
812 |
if null (map #1 (Envir.alist_of env) inter (map #1 (Drule.vars_of_terms (map #2 pairs)))) |
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
813 |
then () else fail (); |
16948 | 814 |
fun norm_bind (xi, (_, t)) = |
815 |
if mem_ix (xi, domain) then SOME (xi, Envir.norm_term env t) else NONE; |
|
15570 | 816 |
in List.mapPartial norm_bind (Envir.alist_of env) end; |
8096 | 817 |
|
818 |
||
819 |
(* add_binds(_i) *) |
|
5819 | 820 |
|
7925 | 821 |
local |
822 |
||
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
823 |
fun gen_bind prep (xi as (x, _), raw_t) ctxt = |
15570 | 824 |
ctxt |> delete_update_binds [(xi, Option.map (prep ctxt) raw_t)]; |
5819 | 825 |
|
10810 | 826 |
in |
827 |
||
15531 | 828 |
fun drop_schematic (b as (xi, SOME t)) = if null (Term.term_vars t) then b else (xi, NONE) |
10554 | 829 |
| drop_schematic b = b; |
830 |
||
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
831 |
val add_binds = fold (gen_bind read_term); |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
832 |
val add_binds_i = fold (gen_bind cert_term); |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
833 |
|
16458 | 834 |
fun auto_bind f ts ctxt = ctxt |> add_binds_i (map drop_schematic (f (theory_of ctxt) ts)); |
12147 | 835 |
val auto_bind_goal = auto_bind AutoBind.goal; |
836 |
val auto_bind_facts = auto_bind AutoBind.facts; |
|
7925 | 837 |
|
838 |
end; |
|
5819 | 839 |
|
840 |
||
8096 | 841 |
(* match_bind(_i) *) |
5819 | 842 |
|
8096 | 843 |
local |
844 |
||
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
845 |
fun prep_bind prep_pats (ctxt, (raw_pats, t)) = |
5819 | 846 |
let |
8096 | 847 |
val ctxt' = declare_term t ctxt; |
848 |
val pats = prep_pats (fastype_of t) ctxt' raw_pats; |
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
849 |
val binds = simult_matches ctxt' (map (rpair t) pats); |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
850 |
in (ctxt', binds) end; |
7670 | 851 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
852 |
fun gen_binds prep_terms prep_pats gen raw_binds ctxt = |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
853 |
let |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
854 |
val ts = prep_terms ctxt (map snd raw_binds); |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
855 |
val (ctxt', binds) = |
15570 | 856 |
apsnd List.concat (foldl_map (prep_bind prep_pats) (ctxt, map fst raw_binds ~~ ts)); |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
857 |
val binds' = |
12550
32843ad8160a
generalize type variables properly: start with occurrences in objects
wenzelm
parents:
12530
diff
changeset
|
858 |
if gen then map #1 binds ~~ generalize ctxt' ctxt (map #2 binds) |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
859 |
else binds; |
15531 | 860 |
val binds'' = map (apsnd SOME) binds'; |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
861 |
in |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
862 |
warn_extra_tfrees ctxt |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
863 |
(if gen then |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
864 |
ctxt (*sic!*) |> fold declare_term (map #2 binds') |> add_binds_i binds'' |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
865 |
else ctxt' |> add_binds_i binds'') |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
866 |
end; |
8096 | 867 |
|
868 |
in |
|
5935 | 869 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
870 |
val match_bind = gen_binds read_terms read_term_pats; |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
871 |
val match_bind_i = gen_binds (map o cert_term) cert_term_pats; |
8096 | 872 |
|
873 |
end; |
|
5935 | 874 |
|
875 |
||
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
876 |
(* propositions with patterns *) |
5935 | 877 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
878 |
local |
8096 | 879 |
|
10554 | 880 |
fun prep_propp schematic prep_props prep_pats (context, args) = |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
881 |
let |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
882 |
fun prep ((ctxt, prop :: props), (_, (raw_pats1, raw_pats2))) = |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
883 |
let |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
884 |
val ctxt' = declare_term prop ctxt; |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
885 |
val pats = prep_pats ctxt' (raw_pats1 @ raw_pats2); (*simultaneous type inference!*) |
13629 | 886 |
in ((ctxt', props), (prop, splitAt(length raw_pats1, pats))) end |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
887 |
| prep _ = sys_error "prep_propp"; |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
888 |
val ((context', _), propp) = foldl_map (foldl_map prep) |
15570 | 889 |
((context, prep_props schematic context (List.concat (map (map fst) args))), args); |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
890 |
in (context', propp) end; |
5935 | 891 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
892 |
fun matches ctxt (prop, (pats1, pats2)) = |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
893 |
simult_matches ctxt (map (rpair prop) pats1 @ map (rpair (Logic.strip_imp_concl prop)) pats2); |
8096 | 894 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
895 |
fun gen_bind_propp prepp (ctxt, raw_args) = |
8096 | 896 |
let |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
897 |
val (ctxt', args) = prepp (ctxt, raw_args); |
15570 | 898 |
val binds = List.concat (List.concat (map (map (matches ctxt')) args)); |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
899 |
val propss = map (map #1) args; |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
900 |
|
10554 | 901 |
(*generalize result: context evaluated now, binds added later*) |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
902 |
val gen = generalize ctxt' ctxt; |
15531 | 903 |
fun gen_binds c = c |> add_binds_i (map #1 binds ~~ map SOME (gen (map #2 binds))); |
904 |
in (ctxt' |> add_binds_i (map (apsnd SOME) binds), (propss, gen_binds)) end; |
|
8096 | 905 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
906 |
in |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
907 |
|
11925 | 908 |
val read_propp = prep_propp false read_props read_prop_pats; |
909 |
val cert_propp = prep_propp false cert_props cert_prop_pats; |
|
10554 | 910 |
val read_propp_schematic = prep_propp true read_props read_prop_pats; |
911 |
val cert_propp_schematic = prep_propp true cert_props cert_prop_pats; |
|
912 |
||
11925 | 913 |
val bind_propp = gen_bind_propp read_propp; |
914 |
val bind_propp_i = gen_bind_propp cert_propp; |
|
915 |
val bind_propp_schematic = gen_bind_propp read_propp_schematic; |
|
10554 | 916 |
val bind_propp_schematic_i = gen_bind_propp cert_propp_schematic; |
6789 | 917 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
918 |
end; |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
919 |
|
6789 | 920 |
|
5819 | 921 |
|
922 |
(** theorems **) |
|
923 |
||
6091 | 924 |
(* get_thm(s) *) |
5819 | 925 |
|
9566 | 926 |
(*beware of proper order of evaluation!*) |
16540 | 927 |
fun retrieve_thms from_thy pick ctxt = |
928 |
let |
|
929 |
val thy_ref = Theory.self_ref (theory_of ctxt); |
|
930 |
val (_, (space, tab), _) = thms_of ctxt; |
|
931 |
in |
|
16501 | 932 |
fn xthmref => |
933 |
let |
|
16540 | 934 |
val thy = Theory.deref thy_ref; |
16501 | 935 |
val thmref = PureThy.map_name_of_thmref (NameSpace.intern space) xthmref; |
936 |
val name = PureThy.name_of_thmref thmref; |
|
937 |
in |
|
938 |
(case Symtab.lookup (tab, name) of |
|
16540 | 939 |
SOME ths => map (Thm.transfer thy) (PureThy.select_thm thmref ths) |
940 |
| NONE => from_thy thy xthmref) |> pick name |
|
16501 | 941 |
end |
9566 | 942 |
end; |
5819 | 943 |
|
9566 | 944 |
val get_thm = retrieve_thms PureThy.get_thms PureThy.single_thm; |
945 |
val get_thm_closure = retrieve_thms PureThy.get_thms_closure PureThy.single_thm; |
|
946 |
val get_thms = retrieve_thms PureThy.get_thms (K I); |
|
947 |
val get_thms_closure = retrieve_thms PureThy.get_thms_closure (K I); |
|
5819 | 948 |
|
949 |
||
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
950 |
(* valid_thms *) |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
951 |
|
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
952 |
fun valid_thms ctxt (name, ths) = |
16501 | 953 |
(case try (transform_error (fn () => get_thms ctxt (Name name))) () of |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
954 |
NONE => false |
16147 | 955 |
| SOME ths' => Thm.eq_thms (ths, ths')); |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
956 |
|
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
957 |
|
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
958 |
(* lthms_containing *) |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
959 |
|
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
960 |
fun lthms_containing ctxt spec = |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
961 |
FactIndex.find (fact_index_of ctxt) spec |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
962 |
|> List.filter (valid_thms ctxt) |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
963 |
|> gen_distinct eq_fst; |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
964 |
|
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
965 |
|
13425
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
966 |
(* name space operations *) |
12309
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
967 |
|
16540 | 968 |
val extern_thm = NameSpace.extern o #1 o #2 o thms_of; |
12309
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
969 |
|
16540 | 970 |
fun map_naming f = map_context (fn (syntax, asms, binds, |
16348 | 971 |
(naming, table, index), cases, defs) => |
16540 | 972 |
(syntax, asms, binds, (f naming, table, index), cases, defs)); |
12309
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
973 |
|
16147 | 974 |
val qualified_names = map_naming NameSpace.qualified_names; |
975 |
val no_base_names = map_naming NameSpace.no_base_names; |
|
976 |
val custom_accesses = map_naming o NameSpace.custom_accesses; |
|
16540 | 977 |
val restore_naming = map_naming o K o #1 o thms_of; |
12309
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
978 |
|
16348 | 979 |
fun hide_thms fully names = map_context |
16540 | 980 |
(fn (syntax, asms, binds, (naming, (space, tab), index), cases, defs) => |
981 |
(syntax, asms, binds, |
|
16348 | 982 |
(naming, (fold (NameSpace.hide fully) names space, tab), index), cases, defs)); |
13425
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
983 |
|
12309
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
984 |
|
6091 | 985 |
(* put_thm(s) *) |
5819 | 986 |
|
16147 | 987 |
fun put_thms ("", _) ctxt = ctxt |
988 |
| put_thms (bname, ths) ctxt = ctxt |> map_context |
|
16540 | 989 |
(fn (syntax, asms, binds, (naming, (space, tab), index), cases, defs) => |
16147 | 990 |
let |
991 |
val name = NameSpace.full naming bname; |
|
992 |
val space' = NameSpace.declare naming name space; |
|
993 |
val tab' = Symtab.update ((name, ths), tab); |
|
994 |
val index' = FactIndex.add (is_known ctxt) (name, ths) index; |
|
16540 | 995 |
in (syntax, asms, binds, (naming, (space', tab'), index'), cases, defs) end); |
5819 | 996 |
|
16147 | 997 |
fun put_thm (name, th) = put_thms (name, [th]); |
998 |
val put_thmss = fold put_thms; |
|
5819 | 999 |
|
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
1000 |
|
7606 | 1001 |
(* reset_thms *) |
1002 |
||
17072 | 1003 |
fun reset_thms name = |
16540 | 1004 |
map_context (fn (syntax, asms, binds, (q, (space, tab), index), cases, defs) => |
1005 |
(syntax, asms, binds, (q, (space, Symtab.delete_safe name tab), index), cases, defs)); |
|
7606 | 1006 |
|
1007 |
||
14564 | 1008 |
(* note_thmss *) |
5819 | 1009 |
|
12711 | 1010 |
local |
16147 | 1011 |
|
1012 |
fun gen_note_thss get (ctxt, ((name, more_attrs), ths_attrs)) = |
|
5819 | 1013 |
let |
1014 |
fun app ((ct, ths), (th, attrs)) = |
|
12711 | 1015 |
let val (ct', th') = Thm.applys_attributes ((ct, get ctxt th), attrs @ more_attrs) |
1016 |
in (ct', th' :: ths) end; |
|
15570 | 1017 |
val (ctxt', rev_thms) = Library.foldl app ((ctxt, []), ths_attrs); |
1018 |
val thms = List.concat (rev rev_thms); |
|
16147 | 1019 |
in (ctxt' |> put_thms (name, thms), (name, thms)) end; |
5819 | 1020 |
|
16147 | 1021 |
fun gen_note_thmss get args ctxt = |
1022 |
foldl_map (gen_note_thss get) (ctxt, args); |
|
12711 | 1023 |
|
1024 |
in |
|
1025 |
||
16147 | 1026 |
val note_thmss = gen_note_thmss get_thms; |
1027 |
val note_thmss_i = gen_note_thmss (K I); |
|
15696 | 1028 |
|
1029 |
val note_thmss_accesses = gen_note_thmss get_thms; |
|
1030 |
val note_thmss_accesses_i = gen_note_thmss (K I); |
|
12711 | 1031 |
|
1032 |
end; |
|
9196 | 1033 |
|
5819 | 1034 |
|
1035 |
||
1036 |
(** assumptions **) |
|
1037 |
||
11918
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1038 |
(* basic exporters *) |
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1039 |
|
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1040 |
fun export_assume true = Seq.single oo Drule.implies_intr_goals |
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1041 |
| export_assume false = Seq.single oo Drule.implies_intr_list; |
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1042 |
|
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1043 |
fun export_presume _ = export_assume false; |
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1044 |
|
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1045 |
|
12057 | 1046 |
(* defs *) |
1047 |
||
12066 | 1048 |
fun cert_def ctxt eq = |
12016 | 1049 |
let |
12057 | 1050 |
fun err msg = raise CONTEXT (msg ^ |
1051 |
"\nThe error(s) above occurred in local definition: " ^ string_of_term ctxt eq, ctxt); |
|
1052 |
val (lhs, rhs) = Logic.dest_equals (Term.strip_all_body eq) |
|
1053 |
handle TERM _ => err "Not a meta-equality (==)"; |
|
12086 | 1054 |
val (f, xs) = Term.strip_comb lhs; |
1055 |
val (c, _) = Term.dest_Free f handle TERM _ => |
|
13430 | 1056 |
err "Head of lhs must be a free/fixed variable"; |
12057 | 1057 |
|
12086 | 1058 |
fun is_free (Free (x, _)) = not (is_fixed ctxt x) |
1059 |
| is_free _ = false; |
|
15570 | 1060 |
val extra_frees = List.filter is_free (term_frees rhs) \\ xs; |
12016 | 1061 |
in |
12086 | 1062 |
conditional (not (forall (is_Bound orf is_free) xs andalso null (duplicates xs))) (fn () => |
13430 | 1063 |
err "Arguments of lhs must be distinct free/bound variables"); |
12086 | 1064 |
conditional (f mem Term.term_frees rhs) (fn () => |
1065 |
err "Element to be defined occurs on rhs"); |
|
1066 |
conditional (not (null extra_frees)) (fn () => |
|
1067 |
err ("Extra free variables on rhs: " ^ commas_quote (map (#1 o dest_Free) extra_frees))); |
|
15570 | 1068 |
(c, Term.list_all_free (List.mapPartial (try Term.dest_Free) xs, eq)) |
12057 | 1069 |
end; |
1070 |
||
1071 |
fun head_of_def cprop = |
|
1072 |
#1 (Term.strip_comb (#1 (Logic.dest_equals (Term.strip_all_body (Thm.term_of cprop))))) |
|
16458 | 1073 |
|> Thm.cterm_of (Thm.theory_of_cterm cprop); |
11918
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1074 |
|
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1075 |
fun export_def _ cprops thm = |
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1076 |
thm |
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1077 |
|> Drule.implies_intr_list cprops |
12057 | 1078 |
|> Drule.forall_intr_list (map head_of_def cprops) |
11918
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1079 |
|> Drule.forall_elim_vars 0 |
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1080 |
|> RANGE (replicate (length cprops) (Tactic.rtac Drule.reflexive_thm)) 1; |
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1081 |
|
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1082 |
|
5819 | 1083 |
(* assume *) |
1084 |
||
7270 | 1085 |
local |
6797 | 1086 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
1087 |
fun add_assm (ctxt, ((name, attrs), props)) = |
5819 | 1088 |
let |
16458 | 1089 |
val cprops = map (Thm.cterm_of (theory_of ctxt)) props; |
12804 | 1090 |
val asms = map (Tactic.norm_hhf_rule o Thm.assume) cprops; |
5919 | 1091 |
|
1092 |
val ths = map (fn th => ([th], [])) asms; |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
1093 |
val (ctxt', [(_, thms)]) = |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
1094 |
ctxt |
12147 | 1095 |
|> auto_bind_facts props |
14564 | 1096 |
|> note_thmss_i [((name, attrs), ths)]; |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
1097 |
in (ctxt', (cprops, (name, asms), (name, thms))) end; |
5819 | 1098 |
|
9470 | 1099 |
fun gen_assms prepp exp args ctxt = |
1100 |
let |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
1101 |
val (ctxt1, propss) = prepp (ctxt, map snd args); |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
1102 |
val (ctxt2, results) = foldl_map add_assm (ctxt1, map fst args ~~ propss); |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
1103 |
|
15570 | 1104 |
val cprops = List.concat (map #1 results); |
9470 | 1105 |
val asmss = map #2 results; |
1106 |
val thmss = map #3 results; |
|
12072
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
1107 |
val ctxt3 = ctxt2 |> map_context |
16540 | 1108 |
(fn (syntax, ((asms_ct, asms_th), fixes), binds, thms, cases, defs) => |
1109 |
(syntax, ((asms_ct @ [(cprops, exp)], asms_th @ asmss), fixes), binds, thms, |
|
15735 | 1110 |
cases, defs)); |
11925 | 1111 |
val ctxt4 = ctxt3 |> put_thms ("prems", prems_of ctxt3); |
1112 |
in (warn_extra_tfrees ctxt ctxt4, thmss) end; |
|
5819 | 1113 |
|
7270 | 1114 |
in |
1115 |
||
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
1116 |
val assume = gen_assms (apsnd #1 o bind_propp); |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
1117 |
val assume_i = gen_assms (apsnd #1 o bind_propp_i); |
7270 | 1118 |
|
1119 |
end; |
|
5819 | 1120 |
|
1121 |
||
8096 | 1122 |
(* variables *) |
1123 |
||
10381 | 1124 |
local |
1125 |
||
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
1126 |
fun prep_vars prep_typ internal liberal (ctxt, (xs, raw_T)) = |
8096 | 1127 |
let |
12504 | 1128 |
fun cond_tvars T = |
1129 |
if internal then T |
|
1130 |
else Type.no_tvars T handle TYPE (msg, _, _) => raise CONTEXT (msg, ctxt); |
|
1131 |
||
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
1132 |
val _ = if liberal then () else |
15570 | 1133 |
(case List.filter (not o Syntax.is_identifier) (map (no_skolem internal ctxt) xs) of |
8096 | 1134 |
[] => () | bads => raise CONTEXT ("Bad variable name(s): " ^ commas_quote bads, ctxt)); |
1135 |
||
15570 | 1136 |
val opt_T = Option.map (cond_tvars o prep_typ ctxt) raw_T; |
15974 | 1137 |
val T = if_none opt_T TypeInfer.logicT; |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
1138 |
val ctxt' = ctxt |> fold declare_term_syntax (map (fn x => Free (x, T)) xs); |
8096 | 1139 |
in (ctxt', (xs, opt_T)) end; |
1140 |
||
10381 | 1141 |
in |
1142 |
||
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
1143 |
val read_vars = prep_vars read_typ false false; |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
1144 |
val cert_vars = prep_vars cert_typ true false; |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
1145 |
val read_vars_liberal = prep_vars read_typ false true; |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
1146 |
val cert_vars_liberal = prep_vars cert_typ true true; |
8096 | 1147 |
|
10381 | 1148 |
end; |
1149 |
||
8096 | 1150 |
|
5819 | 1151 |
(* fix *) |
1152 |
||
8096 | 1153 |
local |
1154 |
||
12309
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
1155 |
fun map_fixes f = |
16540 | 1156 |
map_context (fn (syntax, (assumes, fixes), binds, thms, cases, defs) => |
1157 |
(syntax, (assumes, f fixes), binds, thms, cases, defs)); |
|
5819 | 1158 |
|
11925 | 1159 |
fun err_dups ctxt xs = raise CONTEXT ("Duplicate variable(s): " ^ commas_quote xs, ctxt); |
1160 |
||
12130
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
1161 |
val declare = |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
1162 |
fold declare_term_syntax o |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
1163 |
List.mapPartial (fn (_, NONE) => NONE | (x, SOME T) => SOME (Free (x, T))); |
12130
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
1164 |
|
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
1165 |
fun add_vars xs Ts ctxt = |
12309
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
1166 |
let val xs' = Term.variantlist (map Syntax.skolem xs, map #2 (fixes_of ctxt)) in |
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
1167 |
ctxt |
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
1168 |
|> declare (xs' ~~ Ts) |
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
1169 |
|> map_fixes (fn fixes => (xs ~~ xs') @ fixes) |
12130
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
1170 |
end; |
11925 | 1171 |
|
12130
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
1172 |
fun add_vars_direct xs Ts ctxt = |
12309
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
1173 |
ctxt |
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
1174 |
|> declare (xs ~~ Ts) |
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
1175 |
|> map_fixes (fn fixes => |
12130
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
1176 |
(case xs inter_string map #1 fixes of |
12309
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
1177 |
[] => (xs ~~ xs) @ fixes |
12130
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
1178 |
| dups => err_dups ctxt dups)); |
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
1179 |
|
11925 | 1180 |
|
1181 |
fun gen_fix prep add raw_vars ctxt = |
|
8096 | 1182 |
let |
1183 |
val (ctxt', varss) = foldl_map prep (ctxt, raw_vars); |
|
15570 | 1184 |
val vars = rev (List.concat (map (fn (xs, T) => map (rpair T) xs) varss)); |
12130
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
1185 |
val xs = map #1 vars; |
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
1186 |
val Ts = map #2 vars; |
8096 | 1187 |
in |
11925 | 1188 |
(case Library.duplicates xs of [] => () | dups => err_dups ctxt dups); |
12130
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
1189 |
ctxt' |> add xs Ts |
8096 | 1190 |
end; |
5819 | 1191 |
|
15531 | 1192 |
fun prep_type (x, NONE, SOME mx) = ([x], SOME (mixfix_type mx)) |
12576
9fd10052c3f7
added add_fixes: derives mssing type scheme from mixfix;
wenzelm
parents:
12550
diff
changeset
|
1193 |
| prep_type (x, opt_T, _) = ([x], opt_T); |
9fd10052c3f7
added add_fixes: derives mssing type scheme from mixfix;
wenzelm
parents:
12550
diff
changeset
|
1194 |
|
8096 | 1195 |
in |
7679 | 1196 |
|
11925 | 1197 |
val fix = gen_fix read_vars add_vars; |
1198 |
val fix_i = gen_fix cert_vars add_vars; |
|
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
1199 |
|
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
1200 |
fun fix_direct liberal = |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
1201 |
gen_fix (if liberal then cert_vars_liberal else cert_vars) add_vars_direct; |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
1202 |
|
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
1203 |
fun add_fixes decls = add_syntax decls o fix_direct false (map prep_type decls); |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
1204 |
fun add_fixes_liberal decls = add_syntax decls o fix_direct true (map prep_type decls); |
8096 | 1205 |
|
1206 |
end; |
|
5819 | 1207 |
|
12048 | 1208 |
fun fix_frees ts ctxt = |
1209 |
let |
|
16861 | 1210 |
val frees = fold Term.add_frees ts []; |
15531 | 1211 |
fun new (x, T) = if is_fixed ctxt x then NONE else SOME ([x], SOME T); |
15570 | 1212 |
in fix_direct false (rev (List.mapPartial new frees)) ctxt end; |
12016 | 1213 |
|
6895 | 1214 |
|
9291
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1215 |
(*Note: improper use may result in variable capture / dynamic scoping!*) |
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1216 |
fun bind_skolem ctxt xs = |
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1217 |
let |
15531 | 1218 |
val ctxt' = ctxt |> fix_i [(xs, NONE)]; |
9291
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1219 |
fun bind (t as Free (x, T)) = |
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1220 |
if x mem_string xs then |
15531 | 1221 |
(case lookup_skolem ctxt' x of SOME x' => Free (x', T) | NONE => t) |
9291
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1222 |
else t |
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1223 |
| bind (t $ u) = bind t $ bind u |
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1224 |
| bind (Abs (x, T, t)) = Abs (x, T, bind t) |
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1225 |
| bind a = a; |
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1226 |
in bind end; |
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1227 |
|
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1228 |
|
5819 | 1229 |
|
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1230 |
(** cases **) |
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1231 |
|
16147 | 1232 |
fun apply_case ({fixes, assumes, binds}: RuleCases.T) ctxt = |
1233 |
let |
|
1234 |
fun bind (c, (x, T)) = (c |> fix_i [([x], SOME T)], bind_skolem c [x] (Free (x, T))); |
|
1235 |
val (ctxt', xs) = foldl_map bind (ctxt, fixes); |
|
1236 |
fun app t = Library.foldl Term.betapply (t, xs); |
|
1237 |
in (ctxt', (map (apsnd (Option.map app)) binds, map (apsnd (map app)) assumes)) end; |
|
1238 |
||
1239 |
local |
|
1240 |
||
11793
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
1241 |
fun prep_case ctxt name xs {fixes, assumes, binds} = |
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
1242 |
let |
15974 | 1243 |
fun replace (opt_x :: xs) ((y, T) :: ys) = (if_none opt_x y, T) :: replace xs ys |
11793
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
1244 |
| replace [] ys = ys |
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
1245 |
| replace (_ :: _) [] = raise CONTEXT ("Too many parameters for case " ^ quote name, ctxt); |
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
1246 |
in |
15574
b1d1b5bfc464
Removed practically all references to Library.foldr.
skalberg
parents:
15570
diff
changeset
|
1247 |
if null (foldr Term.add_typ_tvars [] (map snd fixes)) andalso |
b1d1b5bfc464
Removed practically all references to Library.foldr.
skalberg
parents:
15570
diff
changeset
|
1248 |
null (foldr Term.add_term_vars [] (List.concat (map snd assumes))) then |
11793
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
1249 |
{fixes = replace xs fixes, assumes = assumes, binds = map drop_schematic binds} |
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
1250 |
else raise CONTEXT ("Illegal schematic variable(s) in case " ^ quote name, ctxt) |
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
1251 |
end; |
8403 | 1252 |
|
16668 | 1253 |
fun rem_case name = remove (fn (x: string, (y, _)) => x = y) name; |
16147 | 1254 |
|
1255 |
fun add_case ("", _) cases = cases |
|
1256 |
| add_case (name, NONE) cases = rem_case name cases |
|
1257 |
| add_case (name, SOME c) cases = (name, c) :: rem_case name cases; |
|
1258 |
||
1259 |
in |
|
1260 |
||
16540 | 1261 |
fun get_case ctxt name xs = |
1262 |
(case assoc_string (cases_of ctxt, name) of |
|
15531 | 1263 |
NONE => raise CONTEXT ("Unknown case: " ^ quote name, ctxt) |
1264 |
| SOME c => prep_case ctxt name xs c); |
|
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1265 |
|
16540 | 1266 |
fun add_cases xs = map_context (fn (syntax, asms, binds, thms, cases, defs) => |
1267 |
(syntax, asms, binds, thms, fold add_case xs cases, defs)); |
|
8384 | 1268 |
|
16147 | 1269 |
end; |
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1270 |
|
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1271 |
|
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1272 |
|
10810 | 1273 |
(** print context information **) |
1274 |
||
1275 |
val verbose = ref false; |
|
1276 |
fun verb f x = if ! verbose then f (x ()) else []; |
|
1277 |
fun verb_single x = verb Library.single x; |
|
1278 |
||
1279 |
fun setmp_verbose f x = Library.setmp verbose true f x; |
|
1280 |
||
1281 |
fun pretty_items prt name items = |
|
1282 |
let |
|
1283 |
fun prt_itms (name, [x]) = Pretty.block [Pretty.str (name ^ ":"), Pretty.brk 1, prt x] |
|
1284 |
| prt_itms (name, xs) = Pretty.big_list (name ^ ":") (map prt xs); |
|
1285 |
in |
|
1286 |
if null items andalso not (! verbose) then [] |
|
1287 |
else [Pretty.big_list name (map prt_itms items)] |
|
1288 |
end; |
|
1289 |
||
1290 |
||
12072
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
1291 |
(* local syntax *) |
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
1292 |
|
12093 | 1293 |
val print_syntax = Syntax.print_syntax o syn_of; |
12072
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
1294 |
|
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
1295 |
|
10810 | 1296 |
(* term bindings *) |
1297 |
||
16540 | 1298 |
fun pretty_binds ctxt = |
10810 | 1299 |
let |
16540 | 1300 |
val binds = binds_of ctxt; |
12057 | 1301 |
fun prt_bind (xi, (t, T)) = pretty_term ctxt (Logic.mk_equals (Var (xi, T), t)); |
10810 | 1302 |
in |
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
1303 |
if Vartab.is_empty binds andalso not (! verbose) then [] |
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
1304 |
else [Pretty.big_list "term bindings:" (map prt_bind (Vartab.dest binds))] |
10810 | 1305 |
end; |
1306 |
||
1307 |
val print_binds = Pretty.writeln o Pretty.chunks o pretty_binds; |
|
1308 |
||
1309 |
||
1310 |
(* local theorems *) |
|
1311 |
||
16540 | 1312 |
fun pretty_lthms ctxt = |
1313 |
pretty_items (pretty_thm ctxt) "facts:" (NameSpace.extern_table (#2 (thms_of ctxt))); |
|
10810 | 1314 |
|
12057 | 1315 |
val print_lthms = Pretty.writeln o Pretty.chunks o pretty_lthms; |
10810 | 1316 |
|
1317 |
||
1318 |
(* local contexts *) |
|
1319 |
||
16540 | 1320 |
fun pretty_cases ctxt = |
10810 | 1321 |
let |
12057 | 1322 |
val prt_term = pretty_term ctxt; |
1323 |
||
10810 | 1324 |
fun prt_let (xi, t) = Pretty.block |
10818 | 1325 |
[Pretty.quote (prt_term (Var (xi, Term.fastype_of t))), Pretty.str " =", Pretty.brk 1, |
10810 | 1326 |
Pretty.quote (prt_term t)]; |
1327 |
||
13425
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
1328 |
fun prt_asm (a, ts) = Pretty.block (Pretty.breaks |
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
1329 |
((if a = "" then [] else [Pretty.str (a ^ ":")]) @ map (Pretty.quote o prt_term) ts)); |
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
1330 |
|
10810 | 1331 |
fun prt_sect _ _ _ [] = [] |
1332 |
| prt_sect s sep prt xs = [Pretty.block (Pretty.breaks (Pretty.str s :: |
|
15570 | 1333 |
List.concat (Library.separate sep (map (Library.single o prt) xs))))]; |
10810 | 1334 |
|
10830 | 1335 |
fun prt_case (name, (fixes, (lets, asms))) = Pretty.block (Pretty.fbreaks |
10810 | 1336 |
(Pretty.str (name ^ ":") :: |
11915 | 1337 |
prt_sect "fix" [] (Pretty.str o fst) fixes @ |
10810 | 1338 |
prt_sect "let" [Pretty.str "and"] prt_let |
15570 | 1339 |
(List.mapPartial (fn (xi, SOME t) => SOME (xi, t) | _ => NONE) lets) @ |
13425
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
1340 |
(if forall (null o #2) asms then [] |
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
1341 |
else prt_sect "assume" [Pretty.str "and"] prt_asm asms))); |
16540 | 1342 |
|
1343 |
val cases = cases_of ctxt; |
|
10810 | 1344 |
in |
1345 |
if null cases andalso not (! verbose) then [] |
|
10830 | 1346 |
else [Pretty.big_list "cases:" |
16147 | 1347 |
(map (prt_case o apsnd (fn c => (#fixes c, #2 (apply_case c ctxt)))) (rev cases))] |
10810 | 1348 |
end; |
1349 |
||
1350 |
val print_cases = Pretty.writeln o Pretty.chunks o pretty_cases; |
|
1351 |
||
1352 |
||
12057 | 1353 |
(* core context *) |
10810 | 1354 |
|
1355 |
val prems_limit = ref 10; |
|
1356 |
||
12057 | 1357 |
fun pretty_asms ctxt = |
10810 | 1358 |
let |
12057 | 1359 |
val prt_term = pretty_term ctxt; |
1360 |
||
12093 | 1361 |
(*structures*) |
1362 |
val (_, structs, _) = syntax_of ctxt; |
|
1363 |
val prt_structs = if null structs then [] |
|
1364 |
else [Pretty.block (Pretty.str "structures:" :: Pretty.brk 1 :: |
|
1365 |
Pretty.commas (map Pretty.str structs))]; |
|
1366 |
||
12057 | 1367 |
(*fixes*) |
1368 |
fun prt_fix (x, x') = |
|
1369 |
if x = x' then Pretty.str x |
|
1370 |
else Pretty.block [Pretty.str x, Pretty.str " =", Pretty.brk 1, prt_term (Syntax.free x')]; |
|
12093 | 1371 |
val fixes = rev (filter_out |
1372 |
((can Syntax.dest_internal o #1) orf (fn (_, x') => x' mem_string structs)) (fixes_of ctxt)); |
|
1373 |
val prt_fixes = if null fixes then [] |
|
1374 |
else [Pretty.block (Pretty.str "fixed variables:" :: Pretty.brk 1 :: |
|
1375 |
Pretty.commas (map prt_fix fixes))]; |
|
12057 | 1376 |
|
1377 |
(*prems*) |
|
10810 | 1378 |
val limit = ! prems_limit; |
1379 |
val prems = prems_of ctxt; |
|
1380 |
val len = length prems; |
|
12093 | 1381 |
val prt_prems = if null prems then [] |
1382 |
else [Pretty.big_list "prems:" ((if len <= limit then [] else [Pretty.str "..."]) @ |
|
1383 |
map (pretty_thm ctxt) (Library.drop (len - limit, prems)))]; |
|
1384 |
||
1385 |
in prt_structs @ prt_fixes @ prt_prems end; |
|
10810 | 1386 |
|
1387 |
||
1388 |
(* main context *) |
|
1389 |
||
16540 | 1390 |
fun pretty_context ctxt = |
10810 | 1391 |
let |
12057 | 1392 |
val prt_term = pretty_term ctxt; |
1393 |
val prt_typ = pretty_typ ctxt; |
|
1394 |
val prt_sort = pretty_sort ctxt; |
|
10810 | 1395 |
|
1396 |
(*theory*) |
|
12057 | 1397 |
val pretty_thy = Pretty.block |
16458 | 1398 |
[Pretty.str "Theory:", Pretty.brk 1, Context.pretty_thy (theory_of ctxt)]; |
10810 | 1399 |
|
1400 |
(*defaults*) |
|
1401 |
fun prt_atom prt prtT (x, X) = Pretty.block |
|
1402 |
[prt x, Pretty.str " ::", Pretty.brk 1, prtT X]; |
|
1403 |
||
1404 |
fun prt_var (x, ~1) = prt_term (Syntax.free x) |
|
1405 |
| prt_var xi = prt_term (Syntax.var xi); |
|
1406 |
||
1407 |
fun prt_varT (x, ~1) = prt_typ (TFree (x, [])) |
|
1408 |
| prt_varT xi = prt_typ (TVar (xi, [])); |
|
1409 |
||
1410 |
val prt_defT = prt_atom prt_var prt_typ; |
|
1411 |
val prt_defS = prt_atom prt_varT prt_sort; |
|
16540 | 1412 |
|
1413 |
val (types, sorts, used, _) = defaults_of ctxt; |
|
10810 | 1414 |
in |
1415 |
verb_single (K pretty_thy) @ |
|
12057 | 1416 |
pretty_asms ctxt @ |
10810 | 1417 |
verb pretty_binds (K ctxt) @ |
12057 | 1418 |
verb pretty_lthms (K ctxt) @ |
10810 | 1419 |
verb pretty_cases (K ctxt) @ |
1420 |
verb_single (fn () => Pretty.big_list "type constraints:" (map prt_defT (Vartab.dest types))) @ |
|
1421 |
verb_single (fn () => Pretty.big_list "default sorts:" (map prt_defS (Vartab.dest sorts))) @ |
|
1422 |
verb_single (fn () => Pretty.strs ("used type variable names:" :: used)) |
|
1423 |
end; |
|
1424 |
||
5819 | 1425 |
end; |