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