author | wenzelm |
Mon, 05 Nov 2001 21:01:59 +0100 | |
changeset 12057 | 9b1e67278f07 |
parent 12048 | d38b5388e695 |
child 12066 | 31337dd5f596 |
permissions | -rw-r--r-- |
5819 | 1 |
(* Title: Pure/Isar/proof_context.ML |
2 |
ID: $Id$ |
|
3 |
Author: Markus Wenzel, TU Muenchen |
|
8807 | 4 |
License: GPL (GNU GENERAL PUBLIC LICENSE) |
5819 | 5 |
|
6 |
Proof context information. |
|
7 |
*) |
|
8 |
||
9 |
signature PROOF_CONTEXT = |
|
10 |
sig |
|
11 |
type context |
|
9470 | 12 |
type exporter |
5819 | 13 |
exception CONTEXT of string * context |
14 |
val theory_of: context -> theory |
|
15 |
val sign_of: context -> Sign.sg |
|
12057 | 16 |
val fixed_names_of: context -> string list |
17 |
val assumptions_of: context -> (cterm list * exporter) list |
|
7557 | 18 |
val prems_of: context -> thm list |
5819 | 19 |
val print_proof_data: theory -> unit |
5874 | 20 |
val init: theory -> context |
12057 | 21 |
val is_fixed: context -> string -> bool |
5819 | 22 |
val read_typ: context -> string -> typ |
9504 | 23 |
val read_typ_no_norm: context -> string -> typ |
5819 | 24 |
val cert_typ: context -> typ -> typ |
9504 | 25 |
val cert_typ_no_norm: context -> typ -> typ |
10583 | 26 |
val get_skolem: context -> string -> string |
9291
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
27 |
val intern_skolem: context -> term -> term |
9133 | 28 |
val extern_skolem: context -> term -> term |
5874 | 29 |
val read_termTs: context -> (string * typ) list -> term list * (indexname * typ) list |
5819 | 30 |
val read_term: context -> string -> term |
31 |
val read_prop: context -> string -> term |
|
11925 | 32 |
val read_prop_schematic: context -> string -> term |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
33 |
val read_terms: context -> string list -> term list |
8096 | 34 |
val read_termT_pats: context -> (string * typ) list -> term list |
35 |
val read_term_pats: typ -> context -> string list -> term list |
|
36 |
val read_prop_pats: context -> string list -> term list |
|
5819 | 37 |
val cert_term: context -> term -> term |
38 |
val cert_prop: context -> term -> term |
|
8096 | 39 |
val cert_term_pats: typ -> context -> term list -> term list |
40 |
val cert_prop_pats: context -> term list -> term list |
|
5819 | 41 |
val declare_term: term -> context -> context |
42 |
val declare_terms: term list -> context -> context |
|
7925 | 43 |
val warn_extra_tfrees: context -> context -> context |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
44 |
val generalizeT: context -> context -> typ -> typ |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
45 |
val generalize: context -> context -> term -> term |
9470 | 46 |
val find_free: term -> string -> term option |
12008 | 47 |
val export: bool -> context -> context -> thm -> thm Seq.seq |
10810 | 48 |
val drop_schematic: indexname * term option -> indexname * term option |
49 |
val add_binds: (indexname * string option) list -> context -> context |
|
50 |
val add_binds_i: (indexname * term option) list -> context -> context |
|
7925 | 51 |
val auto_bind_goal: term -> context -> context |
52 |
val auto_bind_facts: string -> term list -> context -> context |
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
53 |
val match_bind: bool -> (string list * string) list -> context -> context |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
54 |
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
|
55 |
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
|
56 |
-> context * (term * (term list * term list)) list list |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
57 |
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
|
58 |
-> context * (term * (term list * term list)) list list |
10554 | 59 |
val read_propp_schematic: context * (string * (string list * string list)) list list |
60 |
-> context * (term * (term list * term list)) list list |
|
61 |
val cert_propp_schematic: context * (term * (term list * term list)) list list |
|
62 |
-> context * (term * (term list * term list)) list list |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
63 |
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
|
64 |
-> context * (term list list * (context -> context)) |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
65 |
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
|
66 |
-> context * (term list list * (context -> context)) |
10554 | 67 |
val bind_propp_schematic: context * (string * (string list * string list)) list list |
68 |
-> context * (term list list * (context -> context)) |
|
69 |
val bind_propp_schematic_i: context * (term * (term list * term list)) list list |
|
70 |
-> context * (term list list * (context -> context)) |
|
6091 | 71 |
val get_thm: context -> string -> thm |
9566 | 72 |
val get_thm_closure: context -> string -> thm |
6091 | 73 |
val get_thms: context -> string -> thm list |
9566 | 74 |
val get_thms_closure: context -> string -> thm list |
6091 | 75 |
val put_thm: string * thm -> context -> context |
76 |
val put_thms: string * thm list -> context -> context |
|
77 |
val put_thmss: (string * thm list) list -> context -> context |
|
7606 | 78 |
val reset_thms: string -> context -> context |
9196 | 79 |
val have_thmss: |
80 |
((string * context attribute list) * (thm list * context attribute list) list) list -> |
|
81 |
context -> context * (string * thm list) list |
|
11918
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
82 |
val export_assume: exporter |
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
83 |
val export_presume: exporter |
12057 | 84 |
val cert_def: context -> term -> term |
11918
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
85 |
val export_def: exporter |
9470 | 86 |
val assume: exporter |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
87 |
-> ((string * context attribute list) * (string * (string list * string list)) list) list |
11925 | 88 |
-> context -> context * (string * thm list) list |
9470 | 89 |
val assume_i: exporter |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
90 |
-> ((string * context attribute list) * (term * (term list * term list)) list) list |
11925 | 91 |
-> context -> context * (string * thm list) list |
8096 | 92 |
val read_vars: context * (string list * string option) -> context * (string list * typ option) |
93 |
val cert_vars: context * (string list * typ option) -> context * (string list * typ option) |
|
7411 | 94 |
val fix: (string list * string option) list -> context -> context |
7663 | 95 |
val fix_i: (string list * typ option) list -> context -> context |
11925 | 96 |
val fix_direct: (string list * typ option) list -> context -> context |
12016 | 97 |
val fix_frees: term list -> context -> context |
9291
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
98 |
val bind_skolem: context -> string list -> term -> term |
11793
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
99 |
val get_case: context -> string -> string option list -> RuleCases.T |
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
100 |
val add_cases: (string * RuleCases.T) list -> context -> context |
10830 | 101 |
val apply_case: RuleCases.T -> context -> context * ((indexname * term option) list * term list) |
10810 | 102 |
val show_hyps: bool ref |
12057 | 103 |
val pretty_term: context -> term -> Pretty.T |
104 |
val pretty_typ: context -> typ -> Pretty.T |
|
105 |
val pretty_sort: context -> sort -> Pretty.T |
|
106 |
val pretty_thm: context -> thm -> Pretty.T |
|
107 |
val pretty_thms: context -> thm list -> Pretty.T |
|
108 |
val string_of_term: context -> term -> string |
|
10810 | 109 |
val verbose: bool ref |
110 |
val setmp_verbose: ('a -> 'b) -> 'a -> 'b |
|
111 |
val print_binds: context -> unit |
|
12057 | 112 |
val print_lthms: context -> unit |
10810 | 113 |
val print_cases: context -> unit |
114 |
val prems_limit: int ref |
|
12057 | 115 |
val pretty_asms: context -> Pretty.T list |
10810 | 116 |
val pretty_context: context -> Pretty.T list |
5819 | 117 |
val setup: (theory -> theory) list |
118 |
end; |
|
119 |
||
8151 | 120 |
signature PRIVATE_PROOF_CONTEXT = |
5819 | 121 |
sig |
122 |
include PROOF_CONTEXT |
|
123 |
val init_data: Object.kind -> (theory -> Object.T) * (context -> Object.T -> unit) |
|
124 |
-> theory -> theory |
|
125 |
val print_data: Object.kind -> context -> unit |
|
126 |
val get_data: Object.kind -> (Object.T -> 'a) -> context -> 'a |
|
127 |
val put_data: Object.kind -> ('a -> Object.T) -> 'a -> context -> context |
|
128 |
end; |
|
129 |
||
8151 | 130 |
structure ProofContext: PRIVATE_PROOF_CONTEXT = |
5819 | 131 |
struct |
132 |
||
133 |
||
134 |
(** datatype context **) |
|
135 |
||
11816 | 136 |
type exporter = bool -> cterm list -> thm -> thm Seq.seq; |
9470 | 137 |
|
5819 | 138 |
datatype context = |
139 |
Context of |
|
6847
f175f56c57a6
tuned output: print_context replaced by strings_of_context;
wenzelm
parents:
6797
diff
changeset
|
140 |
{thy: theory, (*current theory*) |
f175f56c57a6
tuned output: print_context replaced by strings_of_context;
wenzelm
parents:
6797
diff
changeset
|
141 |
data: Object.T Symtab.table, (*user data*) |
5819 | 142 |
asms: |
9470 | 143 |
((cterm list * exporter) list * (*assumes: A ==> _*) |
6931 | 144 |
(string * thm list) list) * |
6847
f175f56c57a6
tuned output: print_context replaced by strings_of_context;
wenzelm
parents:
6797
diff
changeset
|
145 |
((string * string) list * string list), (*fixes: !!x. _*) |
7606 | 146 |
binds: (term * typ) option Vartab.table, (*term bindings*) |
147 |
thms: thm list option Symtab.table, (*local thms*) |
|
8426 | 148 |
cases: (string * RuleCases.T) list, (*local contexts*) |
5819 | 149 |
defs: |
6847
f175f56c57a6
tuned output: print_context replaced by strings_of_context;
wenzelm
parents:
6797
diff
changeset
|
150 |
typ Vartab.table * (*type constraints*) |
f175f56c57a6
tuned output: print_context replaced by strings_of_context;
wenzelm
parents:
6797
diff
changeset
|
151 |
sort Vartab.table * (*default sorts*) |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
152 |
(string list * term list Symtab.table)}; (*used type variables*) |
5819 | 153 |
|
154 |
exception CONTEXT of string * context; |
|
155 |
||
156 |
||
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
157 |
fun make_context (thy, data, asms, binds, thms, cases, defs) = |
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
158 |
Context {thy = thy, data = data, asms = asms, binds = binds, thms = thms, |
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
159 |
cases = cases, defs = defs}; |
5819 | 160 |
|
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
161 |
fun map_context f (Context {thy, data, asms, binds, thms, cases, defs}) = |
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
162 |
make_context (f (thy, data, asms, binds, thms, cases, defs)); |
5819 | 163 |
|
164 |
fun theory_of (Context {thy, ...}) = thy; |
|
165 |
val sign_of = Theory.sign_of o theory_of; |
|
166 |
||
12057 | 167 |
fun fixes_of (Context {asms = (_, (fixes, _)), ...}) = fixes; |
168 |
val fixed_names_of = map #2 o fixes_of; |
|
169 |
fun is_fixed (Context {asms = (_, (fixes, _)), ...}) x = exists (equal x o #2) fixes; |
|
170 |
fun used_table (Context {defs = (_, _, (_, tab)), ...}) = tab; |
|
171 |
||
172 |
fun assumptions_of (Context {asms = ((asms, _), _), ...}) = asms; |
|
173 |
fun prems_of (Context {asms = ((_, prems), _), ...}) = flat (map #2 prems); |
|
174 |
||
7270 | 175 |
|
5819 | 176 |
|
177 |
(** user data **) |
|
178 |
||
179 |
(* errors *) |
|
180 |
||
181 |
fun of_theory thy = "\nof theory " ^ Sign.str_of_sg (Theory.sign_of thy); |
|
182 |
||
183 |
fun err_inconsistent kinds = |
|
184 |
error ("Attempt to merge different versions of " ^ commas_quote kinds ^ " proof data"); |
|
185 |
||
186 |
fun err_dup_init thy kind = |
|
187 |
error ("Duplicate initialization of " ^ quote kind ^ " proof data" ^ of_theory thy); |
|
188 |
||
189 |
fun err_undef ctxt kind = |
|
190 |
raise CONTEXT ("Tried to access undefined " ^ quote kind ^ " proof data", ctxt); |
|
191 |
||
192 |
fun err_uninit ctxt kind = |
|
193 |
raise CONTEXT ("Tried to access uninitialized " ^ quote kind ^ " proof data" ^ |
|
194 |
of_theory (theory_of ctxt), ctxt); |
|
195 |
||
196 |
fun err_access ctxt kind = |
|
197 |
raise CONTEXT ("Unauthorized access to " ^ quote kind ^ " proof data" ^ |
|
198 |
of_theory (theory_of ctxt), ctxt); |
|
199 |
||
200 |
||
201 |
(* data kind 'Isar/proof_data' *) |
|
202 |
||
203 |
structure ProofDataDataArgs = |
|
204 |
struct |
|
205 |
val name = "Isar/proof_data"; |
|
206 |
type T = (Object.kind * ((theory -> Object.T) * (context -> Object.T -> unit))) Symtab.table; |
|
207 |
||
208 |
val empty = Symtab.empty; |
|
6550 | 209 |
val copy = I; |
5819 | 210 |
val prep_ext = I; |
211 |
fun merge tabs = Symtab.merge (Object.eq_kind o pairself fst) tabs |
|
212 |
handle Symtab.DUPS kinds => err_inconsistent kinds; |
|
213 |
fun print _ tab = Pretty.writeln (Pretty.strs (map #1 (Symtab.dest tab))); |
|
214 |
end; |
|
215 |
||
216 |
structure ProofDataData = TheoryDataFun(ProofDataDataArgs); |
|
217 |
val print_proof_data = ProofDataData.print; |
|
218 |
||
219 |
||
220 |
(* init proof data *) |
|
221 |
||
222 |
fun init_data kind meths thy = |
|
223 |
let |
|
224 |
val name = Object.name_of_kind kind; |
|
225 |
val tab = Symtab.update_new ((name, (kind, meths)), ProofDataData.get thy) |
|
226 |
handle Symtab.DUP _ => err_dup_init thy name; |
|
227 |
in thy |> ProofDataData.put tab end; |
|
228 |
||
229 |
||
230 |
(* access data *) |
|
231 |
||
232 |
fun lookup_data (ctxt as Context {data, ...}) kind = |
|
233 |
let |
|
234 |
val thy = theory_of ctxt; |
|
235 |
val name = Object.name_of_kind kind; |
|
236 |
in |
|
237 |
(case Symtab.lookup (ProofDataData.get thy, name) of |
|
238 |
Some (k, meths) => |
|
239 |
if Object.eq_kind (kind, k) then |
|
240 |
(case Symtab.lookup (data, name) of |
|
241 |
Some x => (x, meths) |
|
242 |
| None => err_undef ctxt name) |
|
243 |
else err_access ctxt name |
|
244 |
| None => err_uninit ctxt name) |
|
245 |
end; |
|
246 |
||
247 |
fun get_data kind f ctxt = |
|
248 |
let val (x, _) = lookup_data ctxt kind |
|
249 |
in f x handle Match => Object.kind_error kind end; |
|
250 |
||
251 |
fun print_data kind ctxt = |
|
252 |
let val (x, (_, prt)) = lookup_data ctxt kind |
|
253 |
in prt ctxt x end; |
|
254 |
||
255 |
fun put_data kind f x ctxt = |
|
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
256 |
(lookup_data ctxt kind; |
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
257 |
ctxt |> map_context (fn (thy, data, asms, binds, thms, cases, defs) => |
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
258 |
(thy, Symtab.update ((Object.name_of_kind kind, f x), data), asms, binds, thms, cases, defs))); |
5819 | 259 |
|
260 |
||
261 |
(* init context *) |
|
262 |
||
5874 | 263 |
fun init thy = |
264 |
let val data = Symtab.map (fn (_, (f, _)) => f thy) (ProofDataData.get thy) in |
|
8426 | 265 |
make_context (thy, data, (([], []), ([], [])), Vartab.empty, Symtab.empty, [], |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
266 |
(Vartab.empty, Vartab.empty, ([], Symtab.empty))) |
5819 | 267 |
end; |
268 |
||
269 |
||
8096 | 270 |
|
7663 | 271 |
(** default sorts and types **) |
272 |
||
7670 | 273 |
fun def_sort (Context {defs = (_, sorts, _), ...}) xi = Vartab.lookup (sorts, xi); |
7663 | 274 |
|
7670 | 275 |
fun def_type (Context {binds, defs = (types, _, _), ...}) is_pat xi = |
7663 | 276 |
(case Vartab.lookup (types, xi) of |
277 |
None => |
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
278 |
if is_pat then None else |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
279 |
(case Vartab.lookup (binds, xi) of |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
280 |
Some (Some (_, T)) => Some (TypeInfer.polymorphicT T) |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
281 |
| _ => None) |
7663 | 282 |
| some => some); |
283 |
||
284 |
||
5819 | 285 |
|
286 |
(** prepare types **) |
|
287 |
||
9504 | 288 |
local |
289 |
||
290 |
fun read_typ_aux read ctxt s = |
|
291 |
transform_error (read (sign_of ctxt, def_sort ctxt)) s |
|
7663 | 292 |
handle ERROR_MESSAGE msg => raise CONTEXT (msg, ctxt); |
5819 | 293 |
|
10554 | 294 |
fun cert_typ_aux cert ctxt raw_T = |
295 |
cert (sign_of ctxt) raw_T |
|
296 |
handle TYPE (msg, _, _) => raise CONTEXT (msg, ctxt); |
|
9504 | 297 |
|
298 |
in |
|
299 |
||
11925 | 300 |
val read_typ = read_typ_aux Sign.read_typ; |
9504 | 301 |
val read_typ_no_norm = read_typ_aux Sign.read_typ_no_norm; |
11925 | 302 |
val cert_typ = cert_typ_aux Sign.certify_typ; |
9504 | 303 |
val cert_typ_no_norm = cert_typ_aux Sign.certify_typ_no_norm; |
304 |
||
305 |
end; |
|
306 |
||
5819 | 307 |
|
7679 | 308 |
(* internalize Skolem constants *) |
309 |
||
10583 | 310 |
fun lookup_skolem ctxt x = assoc (fixes_of ctxt, x); |
311 |
fun get_skolem ctxt x = if_none (lookup_skolem ctxt x) x; |
|
7679 | 312 |
|
9325 | 313 |
fun no_skolem no_internal ctxt x = |
9291
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
314 |
if can Syntax.dest_skolem x then |
7679 | 315 |
raise CONTEXT ("Illegal reference to internal Skolem constant: " ^ quote x, ctxt) |
9325 | 316 |
else if no_internal andalso can Syntax.dest_internal x then |
9291
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
317 |
raise CONTEXT ("Illegal reference to internal variable: " ^ quote x, ctxt) |
7679 | 318 |
else x; |
319 |
||
9291
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
320 |
fun intern_skolem ctxt = |
7679 | 321 |
let |
322 |
fun intern (t as Free (x, T)) = |
|
10583 | 323 |
(case lookup_skolem ctxt (no_skolem true ctxt x) of |
7679 | 324 |
Some x' => Free (x', T) |
325 |
| None => t) |
|
326 |
| intern (t $ u) = intern t $ intern u |
|
327 |
| intern (Abs (x, T, t)) = Abs (x, T, intern t) |
|
328 |
| intern a = a; |
|
329 |
in intern end; |
|
330 |
||
331 |
||
9133 | 332 |
(* externalize Skolem constants -- for printing purposes only *) |
333 |
||
334 |
fun extern_skolem ctxt = |
|
335 |
let |
|
336 |
val rev_fixes = map Library.swap (fixes_of ctxt); |
|
337 |
||
338 |
fun extern (t as Free (x, T)) = |
|
339 |
(case assoc (rev_fixes, x) of |
|
10583 | 340 |
Some x' => Free (if lookup_skolem ctxt x' = Some x then x' else NameSpace.hidden x', T) |
9133 | 341 |
| None => t) |
342 |
| extern (t $ u) = extern t $ extern u |
|
343 |
| extern (Abs (x, T, t)) = Abs (x, T, extern t) |
|
344 |
| extern a = a; |
|
345 |
in extern end |
|
346 |
||
8096 | 347 |
|
5819 | 348 |
(** prepare terms and propositions **) |
349 |
||
350 |
(* |
|
351 |
(1) read / certify wrt. signature of context |
|
352 |
(2) intern Skolem constants |
|
353 |
(3) expand term bindings |
|
354 |
*) |
|
355 |
||
356 |
||
357 |
(* read / certify wrt. signature *) (*exception ERROR*) (*exception TERM*) |
|
358 |
||
5874 | 359 |
fun read_def_termTs freeze sg (types, sorts, used) sTs = |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
360 |
Sign.read_def_terms (sg, types, sorts) used freeze sTs; |
5874 | 361 |
|
362 |
fun read_def_termT freeze sg defs sT = apfst hd (read_def_termTs freeze sg defs [sT]); |
|
363 |
||
8096 | 364 |
fun read_term_sg freeze sg defs s = #1 (read_def_termT freeze sg defs (s, TypeInfer.logicT)); |
365 |
fun read_prop_sg freeze sg defs s = #1 (read_def_termT freeze sg defs (s, propT)); |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
366 |
fun read_terms_sg freeze sg defs = |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
367 |
#1 o read_def_termTs freeze sg defs o map (rpair TypeInfer.logicT); |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
368 |
fun read_props_sg freeze sg defs = #1 o read_def_termTs freeze sg defs o map (rpair propT); |
5819 | 369 |
|
370 |
||
371 |
fun cert_term_sg sg t = Thm.term_of (Thm.cterm_of sg t); |
|
372 |
||
373 |
fun cert_prop_sg sg tm = |
|
374 |
let |
|
375 |
val ctm = Thm.cterm_of sg tm; |
|
376 |
val {t, T, ...} = Thm.rep_cterm ctm; |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
377 |
in if T = propT then t else raise TERM ("Term not of type prop", [t]) end; |
5819 | 378 |
|
379 |
||
380 |
(* norm_term *) |
|
381 |
||
382 |
(*beta normal form for terms (not eta normal form), chase variables in |
|
383 |
bindings environment (code taken from Pure/envir.ML)*) |
|
384 |
||
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
385 |
fun unifyT ctxt (T, U) = |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
386 |
let val maxidx = Int.max (Term.maxidx_of_typ T, Term.maxidx_of_typ U) |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
387 |
in #1 (Type.unify (Sign.tsig_of (sign_of ctxt)) maxidx Vartab.empty (T, U)) end; |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
388 |
|
10554 | 389 |
fun norm_term (ctxt as Context {binds, ...}) schematic = |
5819 | 390 |
let |
391 |
(*raised when norm has no effect on a term, to do sharing instead of copying*) |
|
392 |
exception SAME; |
|
393 |
||
394 |
fun norm (t as Var (xi, T)) = |
|
395 |
(case Vartab.lookup (binds, xi) of |
|
7606 | 396 |
Some (Some (u, U)) => |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
397 |
let |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
398 |
val env = unifyT ctxt (T, U) handle Type.TUNIFY => |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
399 |
raise TYPE ("norm_term: ill-typed variable assigment", [T, U], [t, u]); |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
400 |
val u' = Term.subst_TVars_Vartab env u; |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
401 |
in norm u' handle SAME => u' end |
10554 | 402 |
| _ => |
403 |
if schematic then raise SAME |
|
404 |
else raise CONTEXT ("Unbound schematic variable: " ^ Syntax.string_of_vname xi, ctxt)) |
|
5819 | 405 |
| norm (Abs (a, T, body)) = Abs (a, T, norm body) |
406 |
| norm (Abs (_, _, body) $ t) = normh (subst_bound (t, body)) |
|
407 |
| norm (f $ t) = |
|
408 |
((case norm f of |
|
409 |
Abs (_, _, body) => normh (subst_bound (t, body)) |
|
410 |
| nf => nf $ (norm t handle SAME => t)) handle SAME => f $ norm t) |
|
411 |
| norm _ = raise SAME |
|
412 |
and normh t = norm t handle SAME => t |
|
413 |
in normh end; |
|
414 |
||
415 |
||
6550 | 416 |
(* dummy patterns *) |
417 |
||
9540 | 418 |
fun prepare_dummies t = #2 (Term.replace_dummy_patterns (1, t)); |
6762 | 419 |
|
9540 | 420 |
fun reject_dummies ctxt t = Term.no_dummy_patterns t |
421 |
handle TERM _ => raise CONTEXT ("Illegal dummy pattern(s) in term", ctxt); |
|
6550 | 422 |
|
423 |
||
5819 | 424 |
(* read terms *) |
425 |
||
10554 | 426 |
local |
427 |
||
428 |
fun gen_read read app is_pat schematic (ctxt as Context {defs = (_, _, (used, _)), ...}) s = |
|
7663 | 429 |
(transform_error (read (sign_of ctxt) (def_type ctxt is_pat, def_sort ctxt, used)) s |
430 |
handle TERM (msg, _) => raise CONTEXT (msg, ctxt) |
|
431 |
| ERROR_MESSAGE msg => raise CONTEXT (msg, ctxt)) |
|
9291
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
432 |
|> app (intern_skolem ctxt) |
10554 | 433 |
|> app (if is_pat then I else norm_term ctxt schematic) |
7663 | 434 |
|> app (if is_pat then prepare_dummies else (reject_dummies ctxt)); |
5819 | 435 |
|
10554 | 436 |
in |
437 |
||
438 |
val read_termTs = gen_read (read_def_termTs false) (apfst o map) false false; |
|
439 |
val read_termT_pats = #1 oo gen_read (read_def_termTs false) (apfst o map) true false; |
|
8096 | 440 |
|
441 |
fun read_term_pats T ctxt pats = read_termT_pats ctxt (map (rpair T) pats); |
|
442 |
val read_prop_pats = read_term_pats propT; |
|
443 |
||
10554 | 444 |
val read_term = gen_read (read_term_sg true) I false false; |
445 |
val read_prop = gen_read (read_prop_sg true) I false false; |
|
11925 | 446 |
val read_prop_schematic = gen_read (read_prop_sg true) I false true; |
10554 | 447 |
val read_terms = gen_read (read_terms_sg true) map false false; |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
448 |
val read_props = gen_read (read_props_sg true) map false; |
5819 | 449 |
|
10554 | 450 |
end; |
451 |
||
5819 | 452 |
|
453 |
(* certify terms *) |
|
454 |
||
10554 | 455 |
local |
456 |
||
457 |
fun gen_cert cert is_pat schematic ctxt t = t |
|
458 |
|> (if is_pat then I else norm_term ctxt schematic) |
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
459 |
|> (fn t' => cert (sign_of ctxt) t' handle TERM (msg, _) => raise CONTEXT (msg, ctxt)); |
5819 | 460 |
|
10554 | 461 |
in |
8096 | 462 |
|
10554 | 463 |
val cert_term = gen_cert cert_term_sg false false; |
464 |
val cert_prop = gen_cert cert_prop_sg false false; |
|
465 |
val cert_props = map oo gen_cert cert_prop_sg false; |
|
466 |
||
467 |
fun cert_term_pats _ = map o gen_cert cert_term_sg true false; |
|
468 |
val cert_prop_pats = map o gen_cert cert_prop_sg true false; |
|
469 |
||
470 |
end; |
|
5819 | 471 |
|
472 |
||
473 |
(* declare terms *) |
|
474 |
||
10381 | 475 |
local |
476 |
||
5819 | 477 |
val ins_types = foldl_aterms |
478 |
(fn (types, Free (x, T)) => Vartab.update (((x, ~1), T), types) |
|
479 |
| (types, Var v) => Vartab.update (v, types) |
|
480 |
| (types, _) => types); |
|
481 |
||
482 |
val ins_sorts = foldl_types (foldl_atyps |
|
483 |
(fn (sorts, TFree (x, S)) => Vartab.update (((x, ~1), S), sorts) |
|
484 |
| (sorts, TVar v) => Vartab.update (v, sorts) |
|
485 |
| (sorts, _) => sorts)); |
|
486 |
||
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
487 |
val ins_used = foldl_term_types (fn t => foldl_atyps |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
488 |
(fn ((used, tab), TFree (x, _)) => (x ins used, Symtab.update_multi ((x, t), tab)) |
5819 | 489 |
| (used, _) => used)); |
490 |
||
7663 | 491 |
fun ins_skolem def_ty = foldr |
5994 | 492 |
(fn ((x, x'), types) => |
7663 | 493 |
(case def_ty x' of |
5994 | 494 |
Some T => Vartab.update (((x, ~1), T), types) |
495 |
| None => types)); |
|
496 |
||
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
497 |
fun map_defaults f = map_context (fn (thy, data, asms, binds, thms, cases, defs) => |
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
498 |
(thy, data, asms, binds, thms, cases, f defs)); |
5819 | 499 |
|
10381 | 500 |
fun declare_syn (ctxt, t) = |
5819 | 501 |
ctxt |
7670 | 502 |
|> map_defaults (fn (types, sorts, used) => (ins_types (types, t), sorts, used)) |
10381 | 503 |
|> map_defaults (fn (types, sorts, used) => (types, ins_sorts (sorts, t), used)); |
504 |
||
505 |
fun declare_occ (ctxt as Context {asms = (_, (fixes, _)), ...}, t) = |
|
506 |
declare_syn (ctxt, t) |
|
7670 | 507 |
|> map_defaults (fn (types, sorts, used) => (types, sorts, ins_used (used, t))) |
508 |
|> map_defaults (fn (types, sorts, used) => |
|
509 |
(ins_skolem (fn x => Vartab.lookup (types, (x, ~1))) (fixes, types), sorts, used)); |
|
5819 | 510 |
|
10381 | 511 |
in |
5819 | 512 |
|
10381 | 513 |
fun declare_term t ctxt = declare_occ (ctxt, t); |
514 |
fun declare_terms ts ctxt = foldl declare_occ (ctxt, ts); |
|
515 |
fun predeclare_terms ts ctxt = foldl declare_syn (ctxt, ts); |
|
516 |
||
517 |
end; |
|
5819 | 518 |
|
519 |
||
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
520 |
|
12057 | 521 |
(** pretty printing **) (* FIXME observe local syntax *) |
522 |
||
523 |
val pretty_term = Sign.pretty_term o sign_of; |
|
524 |
val pretty_typ = Sign.pretty_typ o sign_of; |
|
525 |
val pretty_sort = Sign.pretty_sort o sign_of; |
|
526 |
||
527 |
val string_of_term = Pretty.string_of oo pretty_term; |
|
528 |
||
529 |
val show_hyps = ref false; |
|
530 |
||
531 |
fun pretty_thm ctxt thm = |
|
532 |
if ! show_hyps then setmp Display.show_hyps true Display.pretty_thm_no_quote thm |
|
533 |
else pretty_term ctxt (#prop (Thm.rep_thm thm)); |
|
534 |
||
535 |
fun pretty_thms ctxt [th] = pretty_thm ctxt th |
|
536 |
| pretty_thms ctxt ths = Pretty.blk (0, Pretty.fbreaks (map (pretty_thm ctxt) ths)); |
|
537 |
||
538 |
||
539 |
||
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
540 |
(** Hindley-Milner polymorphism **) |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
541 |
|
7925 | 542 |
(* warn_extra_tfrees *) |
543 |
||
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
544 |
local |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
545 |
|
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
546 |
fun used_free (a, ts) = |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
547 |
(case mapfilter (fn Free (x, _) => Some x | _ => None) ts of |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
548 |
[] => None |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
549 |
| xs => Some (a, xs)); |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
550 |
|
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
551 |
fun warn_extra (names1: string list, tab1) (names2, tab2) = |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
552 |
if names1 = names2 then () |
7925 | 553 |
else |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
554 |
let |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
555 |
val extra = |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
556 |
Library.gen_rems Library.eq_fst (Symtab.dest tab2, Symtab.dest tab1) |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
557 |
|> mapfilter used_free; |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
558 |
val tfrees = map #1 extra; |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
559 |
val frees = Library.sort_strings (Library.distinct (flat (map #2 extra))); |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
560 |
in |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
561 |
if null extra then () |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
562 |
else warning ("Danger! Just introduced free type variable(s): " ^ commas tfrees ^ " in " ^ |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
563 |
space_implode " or " frees) |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
564 |
end; |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
565 |
|
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
566 |
in |
7925 | 567 |
|
568 |
fun warn_extra_tfrees (ctxt1 as Context {defs = (_, _, used1), ...}) |
|
569 |
(ctxt2 as Context {defs = (_, _, used2), ...}) = (warn_extra used1 used2; ctxt2); |
|
570 |
||
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
571 |
end; |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
572 |
|
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
573 |
|
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
574 |
(* generalize type variables *) |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
575 |
|
12008 | 576 |
fun gen_tfrees inner outer = |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
577 |
let |
12057 | 578 |
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
|
579 |
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
|
580 |
| still_fixed _ = false; |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
581 |
fun add (gen, (a, xs)) = |
12008 | 582 |
if is_some (Symtab.lookup (used_table outer, a)) orelse exists still_fixed xs |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
583 |
then gen else a :: gen; |
12008 | 584 |
in Symtab.foldl add ([], used_table inner) end; |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
585 |
|
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
586 |
fun generalizeT inner outer = |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
587 |
let |
12008 | 588 |
val tfrees = gen_tfrees inner outer; |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
589 |
fun gen (x, S) = if x mem_string tfrees then TVar ((x, 0), S) else TFree (x, S); |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
590 |
in Term.map_type_tfree gen end; |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
591 |
|
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
592 |
val generalize = Term.map_term_types oo generalizeT; |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
593 |
|
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
594 |
|
9553 | 595 |
|
596 |
(** export theorems **) |
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
597 |
|
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
598 |
fun get_free x (None, t as Free (y, _)) = if x = y then Some t else None |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
599 |
| get_free _ (opt, _) = opt; |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
600 |
|
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
601 |
fun find_free t x = foldl_aterms (get_free x) (None, t); |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
602 |
|
12008 | 603 |
fun export is_goal inner outer = |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
604 |
let |
12008 | 605 |
val tfrees = gen_tfrees inner outer; |
12057 | 606 |
val fixes = fixed_names_of inner \\ fixed_names_of outer; |
607 |
val asms = Library.drop (length (assumptions_of outer), assumptions_of inner); |
|
11816 | 608 |
val exp_asms = map (fn (cprops, exp) => exp is_goal cprops) asms; |
609 |
in fn thm => |
|
610 |
thm |
|
611 |
|> Tactic.norm_hhf |
|
612 |
|> Seq.EVERY (rev exp_asms) |
|
613 |
|> Seq.map (fn rule => |
|
614 |
let |
|
615 |
val {sign, prop, ...} = Thm.rep_thm rule; |
|
616 |
val frees = map (Thm.cterm_of sign) (mapfilter (find_free prop) fixes); |
|
617 |
in |
|
618 |
rule |
|
619 |
|> Drule.forall_intr_list frees |
|
620 |
|> Tactic.norm_hhf |
|
621 |
|> Drule.tvars_intr_list tfrees |
|
622 |
end) |
|
623 |
end; |
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
624 |
|
7925 | 625 |
|
5819 | 626 |
|
627 |
(** bindings **) |
|
628 |
||
629 |
(* update_binds *) |
|
630 |
||
7606 | 631 |
fun del_bind (ctxt, xi) = |
632 |
ctxt |
|
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
633 |
|> map_context (fn (thy, data, asms, binds, thms, cases, defs) => |
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
634 |
(thy, data, asms, Vartab.update ((xi, None), binds), thms, cases, defs)); |
7606 | 635 |
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
636 |
fun upd_bind (ctxt, ((x, i), t)) = |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
637 |
let |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
638 |
val T = Term.fastype_of t; |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
639 |
val t' = |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
640 |
if null (Term.term_tvars t \\ Term.typ_tvars T) then t |
8637 | 641 |
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
|
642 |
in |
5819 | 643 |
ctxt |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
644 |
|> declare_term t' |
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
645 |
|> map_context (fn (thy, data, asms, binds, thms, cases, defs) => |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
646 |
(thy, data, asms, Vartab.update (((x, i), Some (t', T)), binds), thms, cases, defs)) |
5819 | 647 |
end; |
648 |
||
7606 | 649 |
fun del_upd_bind (ctxt, (xi, None)) = del_bind (ctxt, xi) |
650 |
| del_upd_bind (ctxt, (xi, Some t)) = upd_bind (ctxt, (xi, t)); |
|
651 |
||
5819 | 652 |
fun update_binds bs ctxt = foldl upd_bind (ctxt, bs); |
7606 | 653 |
fun delete_update_binds bs ctxt = foldl del_upd_bind (ctxt, bs); |
654 |
||
5819 | 655 |
|
8096 | 656 |
(* simult_matches *) |
657 |
||
10554 | 658 |
local |
659 |
||
660 |
val add_vars = Term.foldl_aterms (fn (vs, Var (xi, _)) => xi ins vs | (vs, _) => vs); |
|
661 |
fun vars_of ts = foldl add_vars ([], ts); |
|
662 |
||
663 |
in |
|
664 |
||
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
665 |
fun simult_matches ctxt [] = [] |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
666 |
| simult_matches ctxt pairs = |
8096 | 667 |
let |
10554 | 668 |
fun fail () = raise CONTEXT ("Pattern match failed!", ctxt); |
669 |
||
8096 | 670 |
val maxidx = foldl (fn (i, (t1, t2)) => |
671 |
Int.max (i, Int.max (Term.maxidx_of_term t1, Term.maxidx_of_term t2))) (~1, pairs); |
|
10554 | 672 |
val envs = Unify.smash_unifiers (sign_of ctxt, Envir.empty maxidx, |
673 |
map swap pairs); (*prefer assignment of variables from patterns*) |
|
674 |
val env = |
|
8096 | 675 |
(case Seq.pull envs of |
10554 | 676 |
None => fail () |
677 |
| Some (env, _) => env); (*ignore further results*) |
|
678 |
val domain = filter_out Term.is_replaced_dummy_pattern (vars_of (map #1 pairs)); |
|
679 |
val _ = (*may not assign variables from text*) |
|
680 |
if null (map #1 (Envir.alist_of env) inter vars_of (map #2 pairs)) then () |
|
681 |
else fail (); |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
682 |
fun norm_bind (xi, t) = if xi mem domain then Some (xi, Envir.norm_term env t) else None; |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
683 |
in mapfilter norm_bind (Envir.alist_of env) end; |
8096 | 684 |
|
10554 | 685 |
end; |
686 |
||
8096 | 687 |
|
688 |
(* add_binds(_i) *) |
|
5819 | 689 |
|
7925 | 690 |
local |
691 |
||
5819 | 692 |
fun gen_bind prep (ctxt, (xi as (x, _), raw_t)) = |
7606 | 693 |
ctxt |> delete_update_binds [(xi, apsome (prep ctxt) raw_t)]; |
5819 | 694 |
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
695 |
fun gen_binds prep binds ctxt = foldl (gen_bind prep) (ctxt, binds); |
7925 | 696 |
|
10810 | 697 |
in |
698 |
||
10554 | 699 |
fun drop_schematic (b as (xi, Some t)) = if null (Term.term_vars t) then b else (xi, None) |
700 |
| drop_schematic b = b; |
|
701 |
||
5819 | 702 |
val add_binds = gen_binds read_term; |
703 |
val add_binds_i = gen_binds cert_term; |
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
704 |
|
11764 | 705 |
fun auto_bind_goal t ctxt = |
706 |
ctxt |> add_binds_i (map drop_schematic (AutoBind.goal (sign_of ctxt) t)); |
|
707 |
||
708 |
fun auto_bind_facts name ts ctxt = |
|
709 |
ctxt |> add_binds_i (map drop_schematic (AutoBind.facts (sign_of ctxt) name ts)); |
|
7925 | 710 |
|
711 |
end; |
|
5819 | 712 |
|
713 |
||
8096 | 714 |
(* match_bind(_i) *) |
5819 | 715 |
|
8096 | 716 |
local |
717 |
||
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
718 |
fun prep_bind prep_pats (ctxt, (raw_pats, t)) = |
5819 | 719 |
let |
8096 | 720 |
val ctxt' = declare_term t ctxt; |
721 |
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
|
722 |
val binds = simult_matches ctxt' (map (rpair t) pats); |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
723 |
in (ctxt', binds) end; |
7670 | 724 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
725 |
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
|
726 |
let |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
727 |
val ts = prep_terms ctxt (map snd raw_binds); |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
728 |
val (ctxt', binds) = |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
729 |
apsnd flat (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
|
730 |
val binds' = |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
731 |
if gen then map (apsnd (generalize ctxt' ctxt)) binds |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
732 |
else binds; |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
733 |
val binds'' = map (apsnd Some) binds'; |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
734 |
in |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
735 |
warn_extra_tfrees ctxt |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
736 |
(if gen then ctxt (*sic!*) |> declare_terms (map #2 binds') |> add_binds_i binds'' |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
737 |
else ctxt' |> add_binds_i binds'') |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
738 |
end; |
8096 | 739 |
|
740 |
in |
|
5935 | 741 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
742 |
val match_bind = gen_binds read_terms read_term_pats; |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
743 |
val match_bind_i = gen_binds (map o cert_term) cert_term_pats; |
8096 | 744 |
|
745 |
end; |
|
5935 | 746 |
|
747 |
||
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
748 |
(* propositions with patterns *) |
5935 | 749 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
750 |
local |
8096 | 751 |
|
10554 | 752 |
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
|
753 |
let |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
754 |
fun prep ((ctxt, prop :: props), (_, (raw_pats1, raw_pats2))) = |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
755 |
let |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
756 |
val ctxt' = declare_term prop ctxt; |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
757 |
val pats = prep_pats ctxt' (raw_pats1 @ raw_pats2); (*simultaneous type inference!*) |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
758 |
val len1 = length raw_pats1; |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
759 |
in ((ctxt', props), (prop, (take (len1, pats), drop (len1, pats)))) end |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
760 |
| prep _ = sys_error "prep_propp"; |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
761 |
val ((context', _), propp) = foldl_map (foldl_map prep) |
10554 | 762 |
((context, prep_props schematic context (flat (map (map fst) args))), args); |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
763 |
in (context', propp) end; |
5935 | 764 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
765 |
fun matches ctxt (prop, (pats1, pats2)) = |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
766 |
simult_matches ctxt (map (rpair prop) pats1 @ map (rpair (Logic.strip_imp_concl prop)) pats2); |
8096 | 767 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
768 |
fun gen_bind_propp prepp (ctxt, raw_args) = |
8096 | 769 |
let |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
770 |
val (ctxt', args) = prepp (ctxt, raw_args); |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
771 |
val binds = flat (flat (map (map (matches ctxt')) args)); |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
772 |
val propss = map (map #1) args; |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
773 |
|
10554 | 774 |
(*generalize result: context evaluated now, binds added later*) |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
775 |
val gen = generalize ctxt' ctxt; |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
776 |
fun gen_binds c = c |> add_binds_i (map (apsnd (Some o gen)) binds); |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
777 |
in (ctxt' |> add_binds_i (map (apsnd Some) binds), (propss, gen_binds)) end; |
8096 | 778 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
779 |
in |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
780 |
|
11925 | 781 |
val read_propp = prep_propp false read_props read_prop_pats; |
782 |
val cert_propp = prep_propp false cert_props cert_prop_pats; |
|
10554 | 783 |
val read_propp_schematic = prep_propp true read_props read_prop_pats; |
784 |
val cert_propp_schematic = prep_propp true cert_props cert_prop_pats; |
|
785 |
||
11925 | 786 |
val bind_propp = gen_bind_propp read_propp; |
787 |
val bind_propp_i = gen_bind_propp cert_propp; |
|
788 |
val bind_propp_schematic = gen_bind_propp read_propp_schematic; |
|
10554 | 789 |
val bind_propp_schematic_i = gen_bind_propp cert_propp_schematic; |
6789 | 790 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
791 |
end; |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
792 |
|
6789 | 793 |
|
5819 | 794 |
|
795 |
(** theorems **) |
|
796 |
||
6091 | 797 |
(* get_thm(s) *) |
5819 | 798 |
|
9566 | 799 |
(*beware of proper order of evaluation!*) |
5819 | 800 |
|
9566 | 801 |
fun retrieve_thms f g (ctxt as Context {thy, thms, ...}) = |
802 |
let |
|
803 |
val sg_ref = Sign.self_ref (Theory.sign_of thy); |
|
804 |
val get_from_thy = f thy; |
|
805 |
in |
|
806 |
fn name => |
|
807 |
(case Symtab.lookup (thms, name) of |
|
808 |
Some (Some ths) => map (Thm.transfer_sg (Sign.deref sg_ref)) ths |
|
809 |
| _ => get_from_thy name) |> g name |
|
810 |
end; |
|
5819 | 811 |
|
9566 | 812 |
val get_thm = retrieve_thms PureThy.get_thms PureThy.single_thm; |
813 |
val get_thm_closure = retrieve_thms PureThy.get_thms_closure PureThy.single_thm; |
|
814 |
val get_thms = retrieve_thms PureThy.get_thms (K I); |
|
815 |
val get_thms_closure = retrieve_thms PureThy.get_thms_closure (K I); |
|
5819 | 816 |
|
817 |
||
6091 | 818 |
(* put_thm(s) *) |
5819 | 819 |
|
7479 | 820 |
fun put_thms ("", _) = I |
821 |
| put_thms (name, ths) = map_context |
|
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
822 |
(fn (thy, data, asms, binds, thms, cases, defs) => |
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
823 |
(thy, data, asms, binds, Symtab.update ((name, Some ths), thms), cases, defs)); |
5819 | 824 |
|
6091 | 825 |
fun put_thm (name, th) = put_thms (name, [th]); |
5819 | 826 |
|
6091 | 827 |
fun put_thmss [] ctxt = ctxt |
828 |
| put_thmss (th :: ths) ctxt = ctxt |> put_thms th |> put_thmss ths; |
|
5819 | 829 |
|
830 |
||
7606 | 831 |
(* reset_thms *) |
832 |
||
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
833 |
fun reset_thms name = map_context (fn (thy, data, asms, binds, thms, cases, defs) => |
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
834 |
(thy, data, asms, binds, Symtab.update ((name, None), thms), cases, defs)); |
7606 | 835 |
|
836 |
||
6091 | 837 |
(* have_thmss *) |
5819 | 838 |
|
9196 | 839 |
fun have_thss (ctxt, ((name, more_attrs), ths_attrs)) = |
5819 | 840 |
let |
841 |
fun app ((ct, ths), (th, attrs)) = |
|
6091 | 842 |
let val (ct', th') = Thm.applys_attributes ((ct, th), attrs @ more_attrs) |
5819 | 843 |
in (ct', th' :: ths) end |
844 |
val (ctxt', rev_thms) = foldl app ((ctxt, []), ths_attrs); |
|
9196 | 845 |
val thms = flat (rev rev_thms); |
6091 | 846 |
in (ctxt' |> put_thms (name, thms), (name, thms)) end; |
5819 | 847 |
|
9196 | 848 |
fun have_thmss args ctxt = foldl_map have_thss (ctxt, args); |
849 |
||
5819 | 850 |
|
851 |
||
852 |
(** assumptions **) |
|
853 |
||
11918
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
854 |
(* basic exporters *) |
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
855 |
|
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
856 |
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
|
857 |
| 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
|
858 |
|
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
859 |
fun export_presume _ = export_assume false; |
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
860 |
|
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
861 |
|
12057 | 862 |
(* defs *) |
863 |
||
864 |
fun cert_def ctxt eq = (* FIXME proper treatment of extra type variables *) |
|
12016 | 865 |
let |
12057 | 866 |
fun err msg = raise CONTEXT (msg ^ |
867 |
"\nThe error(s) above occurred in local definition: " ^ string_of_term ctxt eq, ctxt); |
|
868 |
val (lhs, rhs) = Logic.dest_equals (Term.strip_all_body eq) |
|
869 |
handle TERM _ => err "Not a meta-equality (==)"; |
|
870 |
val (head, args) = Term.strip_comb lhs; |
|
871 |
||
872 |
fun fixed_free (Free (x, _)) = is_fixed ctxt x |
|
873 |
| fixed_free _ = false; |
|
12016 | 874 |
in |
12057 | 875 |
Term.dest_Free head handle TERM _ => |
876 |
err "Head of lhs must be a variable (free or fixed)"; |
|
877 |
conditional (not (forall (fixed_free orf is_Bound) args andalso null (duplicates args))) |
|
878 |
(fn () => err "Arguments of lhs must be distinct variables (free or fixed)"); |
|
879 |
conditional (head mem Term.term_frees rhs) |
|
880 |
(fn () => err "Element to be defined occurs on rhs"); |
|
881 |
conditional (not (null (filter_out fixed_free (term_frees rhs) \\ args))) |
|
882 |
(fn () => err "Extra free variables on rhs"); |
|
883 |
Term.list_all_free (mapfilter (try Term.dest_Free) args, eq) |
|
884 |
end; |
|
885 |
||
886 |
fun head_of_def cprop = |
|
887 |
#1 (Term.strip_comb (#1 (Logic.dest_equals (Term.strip_all_body (Thm.term_of cprop))))) |
|
888 |
|> Thm.cterm_of (Thm.sign_of_cterm cprop); |
|
11918
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
889 |
|
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
890 |
fun export_def _ cprops thm = |
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
891 |
thm |
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
892 |
|> Drule.implies_intr_list cprops |
12057 | 893 |
|> 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
|
894 |
|> Drule.forall_elim_vars 0 |
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
895 |
|> 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
|
896 |
|
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
897 |
|
5819 | 898 |
(* assume *) |
899 |
||
7270 | 900 |
local |
6797 | 901 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
902 |
fun add_assm (ctxt, ((name, attrs), props)) = |
5819 | 903 |
let |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
904 |
val cprops = map (Thm.cterm_of (sign_of ctxt)) props; |
11816 | 905 |
val asms = map (Tactic.norm_hhf o Thm.assume) cprops; |
5919 | 906 |
|
907 |
val ths = map (fn th => ([th], [])) asms; |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
908 |
val (ctxt', [(_, thms)]) = |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
909 |
ctxt |
6797 | 910 |
|> auto_bind_facts name props |
11526 | 911 |
|> have_thmss [((name, attrs), ths)]; |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
912 |
in (ctxt', (cprops, (name, asms), (name, thms))) end; |
5819 | 913 |
|
9470 | 914 |
fun gen_assms prepp exp args ctxt = |
915 |
let |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
916 |
val (ctxt1, propss) = prepp (ctxt, map snd args); |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
917 |
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
|
918 |
|
9470 | 919 |
val cprops = flat (map #1 results); |
920 |
val asmss = map #2 results; |
|
921 |
val thmss = map #3 results; |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
922 |
val ctxt3 = |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
923 |
ctxt2 |
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
924 |
|> map_context (fn (thy, data, ((asms_ct, asms_th), fixes), binds, thms, cases, defs) => |
9470 | 925 |
(thy, data, ((asms_ct @ [(cprops, exp)], asms_th @ asmss), fixes), binds, thms, |
926 |
cases, defs)); |
|
11925 | 927 |
val ctxt4 = ctxt3 |> put_thms ("prems", prems_of ctxt3); |
928 |
in (warn_extra_tfrees ctxt ctxt4, thmss) end; |
|
5819 | 929 |
|
7270 | 930 |
in |
931 |
||
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
932 |
val assume = gen_assms (apsnd #1 o bind_propp); |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
933 |
val assume_i = gen_assms (apsnd #1 o bind_propp_i); |
7270 | 934 |
|
935 |
end; |
|
5819 | 936 |
|
937 |
||
8096 | 938 |
(* variables *) |
939 |
||
10381 | 940 |
local |
941 |
||
11925 | 942 |
fun prep_vars prep_typ no_internal (ctxt, (xs, raw_T)) = |
8096 | 943 |
let |
11925 | 944 |
val _ = (case filter (not o Syntax.is_identifier) (map (no_skolem no_internal ctxt) xs) of |
8096 | 945 |
[] => () | bads => raise CONTEXT ("Bad variable name(s): " ^ commas_quote bads, ctxt)); |
946 |
||
947 |
val opt_T = apsome (prep_typ ctxt) raw_T; |
|
948 |
val T = if_none opt_T TypeInfer.logicT; |
|
10381 | 949 |
val ctxt' = ctxt |> predeclare_terms (map (fn x => Free (x, T)) xs); |
8096 | 950 |
in (ctxt', (xs, opt_T)) end; |
951 |
||
10381 | 952 |
in |
953 |
||
11925 | 954 |
val read_vars = prep_vars read_typ true; |
955 |
val cert_vars = prep_vars cert_typ false; |
|
8096 | 956 |
|
10381 | 957 |
end; |
958 |
||
8096 | 959 |
|
5819 | 960 |
(* fix *) |
961 |
||
8096 | 962 |
local |
963 |
||
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
964 |
fun map_vars f = map_context (fn (thy, data, (assumes, vars), binds, thms, cases, defs) => |
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
965 |
(thy, data, (assumes, f vars), binds, thms, cases, defs)); |
5819 | 966 |
|
11925 | 967 |
fun err_dups ctxt xs = raise CONTEXT ("Duplicate variable(s): " ^ commas_quote xs, ctxt); |
968 |
||
969 |
fun add_vars _ xs (fixes, used) = |
|
970 |
let |
|
971 |
val xs' = variantlist (xs, used); |
|
972 |
val fixes' = (xs ~~ map Syntax.skolem xs') @ fixes; |
|
973 |
val used' = xs' @ used; |
|
974 |
in (fixes', used') end; |
|
975 |
||
976 |
fun add_vars_direct ctxt xs (fixes, used) = |
|
977 |
(case xs inter_string map #1 fixes of |
|
978 |
[] => ((xs ~~ xs) @ fixes, xs @ used) |
|
979 |
| dups => err_dups ctxt dups); |
|
980 |
||
981 |
fun gen_fix prep add raw_vars ctxt = |
|
8096 | 982 |
let |
983 |
val (ctxt', varss) = foldl_map prep (ctxt, raw_vars); |
|
984 |
val xs = flat (map fst varss); |
|
985 |
in |
|
11925 | 986 |
(case Library.duplicates xs of [] => () | dups => err_dups ctxt dups); |
12048 | 987 |
ctxt' |> map_vars (add ctxt (rev xs)) |
8096 | 988 |
end; |
5819 | 989 |
|
8096 | 990 |
in |
7679 | 991 |
|
11925 | 992 |
val fix = gen_fix read_vars add_vars; |
993 |
val fix_i = gen_fix cert_vars add_vars; |
|
994 |
val fix_direct = gen_fix cert_vars add_vars_direct; |
|
8096 | 995 |
|
996 |
end; |
|
5819 | 997 |
|
12048 | 998 |
fun fix_frees ts ctxt = |
999 |
let |
|
12057 | 1000 |
val frees = foldl Drule.add_frees ([], ts); |
1001 |
fun new (x, T) = if is_fixed ctxt x then None else Some ([x], Some T); |
|
12048 | 1002 |
in fix_direct (mapfilter new frees) ctxt end; |
12016 | 1003 |
|
6895 | 1004 |
|
9291
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1005 |
(*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
|
1006 |
fun bind_skolem ctxt xs = |
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1007 |
let |
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1008 |
val ctxt' = ctxt |> fix_i [(xs, None)]; |
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1009 |
fun bind (t as Free (x, T)) = |
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1010 |
if x mem_string xs then |
10583 | 1011 |
(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
|
1012 |
else t |
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1013 |
| bind (t $ u) = bind t $ bind u |
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1014 |
| 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
|
1015 |
| bind a = a; |
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1016 |
in bind end; |
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1017 |
|
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1018 |
|
5819 | 1019 |
|
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1020 |
(** cases **) |
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1021 |
|
11793
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
1022 |
fun prep_case ctxt name xs {fixes, assumes, binds} = |
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
1023 |
let |
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
1024 |
fun replace (opt_x :: xs) ((y, T) :: ys) = (if_none opt_x y, T) :: replace xs ys |
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
1025 |
| replace [] ys = ys |
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
1026 |
| replace (_ :: _) [] = raise CONTEXT ("Too many parameters for case " ^ quote name, ctxt); |
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
1027 |
in |
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
1028 |
if null (foldr Term.add_typ_tvars (map snd fixes, [])) andalso |
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
1029 |
null (foldr Term.add_term_vars (assumes, [])) then |
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
1030 |
{fixes = replace xs fixes, assumes = assumes, binds = map drop_schematic binds} |
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
1031 |
else raise CONTEXT ("Illegal schematic variable(s) in case " ^ quote name, ctxt) |
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
1032 |
end; |
8403 | 1033 |
|
11793
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
1034 |
fun get_case (ctxt as Context {cases, ...}) name xs = |
8426 | 1035 |
(case assoc (cases, name) of |
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1036 |
None => raise CONTEXT ("Unknown case: " ^ quote name, ctxt) |
11793
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
1037 |
| 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
|
1038 |
|
8384 | 1039 |
|
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1040 |
fun add_cases xs = map_context (fn (thy, data, asms, binds, thms, cases, defs) => |
8426 | 1041 |
(thy, data, asms, binds, thms, rev (filter_out (equal "" o #1) xs) @ cases, defs)); |
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1042 |
|
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1043 |
|
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1044 |
|
10810 | 1045 |
(** print context information **) |
1046 |
||
1047 |
val verbose = ref false; |
|
1048 |
fun verb f x = if ! verbose then f (x ()) else []; |
|
1049 |
fun verb_single x = verb Library.single x; |
|
1050 |
||
1051 |
fun setmp_verbose f x = Library.setmp verbose true f x; |
|
1052 |
||
1053 |
fun pretty_items prt name items = |
|
1054 |
let |
|
1055 |
fun prt_itms (name, [x]) = Pretty.block [Pretty.str (name ^ ":"), Pretty.brk 1, prt x] |
|
1056 |
| prt_itms (name, xs) = Pretty.big_list (name ^ ":") (map prt xs); |
|
1057 |
in |
|
1058 |
if null items andalso not (! verbose) then [] |
|
1059 |
else [Pretty.big_list name (map prt_itms items)] |
|
1060 |
end; |
|
1061 |
||
1062 |
||
1063 |
(* term bindings *) |
|
1064 |
||
1065 |
val smash_option = fn (_, None) => None | (xi, Some b) => Some (xi, b); |
|
1066 |
||
1067 |
fun pretty_binds (ctxt as Context {binds, ...}) = |
|
1068 |
let |
|
12057 | 1069 |
fun prt_bind (xi, (t, T)) = pretty_term ctxt (Logic.mk_equals (Var (xi, T), t)); |
10810 | 1070 |
val bs = mapfilter smash_option (Vartab.dest binds); |
1071 |
in |
|
1072 |
if null bs andalso not (! verbose) then [] |
|
1073 |
else [Pretty.big_list "term bindings:" (map prt_bind bs)] |
|
1074 |
end; |
|
1075 |
||
1076 |
val print_binds = Pretty.writeln o Pretty.chunks o pretty_binds; |
|
1077 |
||
1078 |
||
1079 |
(* local theorems *) |
|
1080 |
||
12057 | 1081 |
fun pretty_lthms (ctxt as Context {thms, ...}) = |
1082 |
pretty_items (pretty_thm ctxt) "facts:" (mapfilter smash_option (Symtab.dest thms)); |
|
10810 | 1083 |
|
12057 | 1084 |
val print_lthms = Pretty.writeln o Pretty.chunks o pretty_lthms; |
10810 | 1085 |
|
1086 |
||
1087 |
(* local contexts *) |
|
1088 |
||
10830 | 1089 |
fun apply_case ({fixes, assumes, binds}: RuleCases.T) ctxt = |
10810 | 1090 |
let |
10830 | 1091 |
fun bind (c, (x, T)) = (c |> fix_i [([x], Some T)], bind_skolem c [x] (Free (x, T))); |
1092 |
val (ctxt', xs) = foldl_map bind (ctxt, fixes); |
|
10810 | 1093 |
fun app t = foldl Term.betapply (t, xs); |
10830 | 1094 |
in (ctxt', (map (apsnd (apsome app)) binds, map app assumes)) end; |
10810 | 1095 |
|
1096 |
fun pretty_cases (ctxt as Context {cases, ...}) = |
|
1097 |
let |
|
12057 | 1098 |
val prt_term = pretty_term ctxt; |
1099 |
||
10810 | 1100 |
fun prt_let (xi, t) = Pretty.block |
10818 | 1101 |
[Pretty.quote (prt_term (Var (xi, Term.fastype_of t))), Pretty.str " =", Pretty.brk 1, |
10810 | 1102 |
Pretty.quote (prt_term t)]; |
1103 |
||
1104 |
fun prt_sect _ _ _ [] = [] |
|
1105 |
| prt_sect s sep prt xs = [Pretty.block (Pretty.breaks (Pretty.str s :: |
|
1106 |
flat (Library.separate sep (map (Library.single o prt) xs))))]; |
|
1107 |
||
10830 | 1108 |
fun prt_case (name, (fixes, (lets, asms))) = Pretty.block (Pretty.fbreaks |
10810 | 1109 |
(Pretty.str (name ^ ":") :: |
11915 | 1110 |
prt_sect "fix" [] (Pretty.str o fst) fixes @ |
10810 | 1111 |
prt_sect "let" [Pretty.str "and"] prt_let |
1112 |
(mapfilter (fn (xi, Some t) => Some (xi, t) | _ => None) lets) @ |
|
1113 |
prt_sect "assume" [] (Pretty.quote o prt_term) asms)); |
|
1114 |
||
1115 |
val cases' = rev (Library.gen_distinct Library.eq_fst cases); |
|
1116 |
in |
|
1117 |
if null cases andalso not (! verbose) then [] |
|
10830 | 1118 |
else [Pretty.big_list "cases:" |
1119 |
(map (prt_case o apsnd (fn c => (#fixes c, #2 (apply_case c ctxt)))) cases')] |
|
10810 | 1120 |
end; |
1121 |
||
1122 |
val print_cases = Pretty.writeln o Pretty.chunks o pretty_cases; |
|
1123 |
||
1124 |
||
12057 | 1125 |
(* core context *) |
10810 | 1126 |
|
1127 |
val prems_limit = ref 10; |
|
1128 |
||
12057 | 1129 |
fun pretty_asms ctxt = |
10810 | 1130 |
let |
12057 | 1131 |
val prt_term = pretty_term ctxt; |
1132 |
||
1133 |
(*fixes*) |
|
1134 |
fun prt_fix (x, x') = |
|
1135 |
if x = x' then Pretty.str x |
|
1136 |
else Pretty.block [Pretty.str x, Pretty.str " =", Pretty.brk 1, prt_term (Syntax.free x')]; |
|
1137 |
fun prt_fixes [] = [] |
|
1138 |
| prt_fixes xs = [Pretty.block (Pretty.str "fixed variables:" :: Pretty.brk 1 :: |
|
1139 |
Pretty.commas (map prt_fix xs))]; |
|
1140 |
||
1141 |
(*prems*) |
|
10810 | 1142 |
val limit = ! prems_limit; |
1143 |
val prems = prems_of ctxt; |
|
1144 |
val len = length prems; |
|
1145 |
val prt_prems = |
|
1146 |
(if len <= limit then [] else [Pretty.str "..."]) @ |
|
12057 | 1147 |
map (pretty_thm ctxt) (Library.drop (len - limit, prems)); |
1148 |
in |
|
1149 |
prt_fixes (rev (filter_out (can Syntax.dest_internal o #1) (fixes_of ctxt))) @ |
|
1150 |
(if null prems then [] else [Pretty.big_list "prems:" prt_prems]) |
|
1151 |
end; |
|
10810 | 1152 |
|
1153 |
||
1154 |
(* main context *) |
|
1155 |
||
12057 | 1156 |
fun pretty_context (ctxt as Context {cases, defs = (types, sorts, (used, _)), ...}) = |
10810 | 1157 |
let |
12057 | 1158 |
val prt_term = pretty_term ctxt; |
1159 |
val prt_typ = pretty_typ ctxt; |
|
1160 |
val prt_sort = pretty_sort ctxt; |
|
10810 | 1161 |
|
1162 |
(*theory*) |
|
12057 | 1163 |
val pretty_thy = Pretty.block |
1164 |
[Pretty.str "Theory:", Pretty.brk 1, Sign.pretty_sg (sign_of ctxt)]; |
|
10810 | 1165 |
|
1166 |
(*defaults*) |
|
1167 |
fun prt_atom prt prtT (x, X) = Pretty.block |
|
1168 |
[prt x, Pretty.str " ::", Pretty.brk 1, prtT X]; |
|
1169 |
||
1170 |
fun prt_var (x, ~1) = prt_term (Syntax.free x) |
|
1171 |
| prt_var xi = prt_term (Syntax.var xi); |
|
1172 |
||
1173 |
fun prt_varT (x, ~1) = prt_typ (TFree (x, [])) |
|
1174 |
| prt_varT xi = prt_typ (TVar (xi, [])); |
|
1175 |
||
1176 |
val prt_defT = prt_atom prt_var prt_typ; |
|
1177 |
val prt_defS = prt_atom prt_varT prt_sort; |
|
1178 |
in |
|
1179 |
verb_single (K pretty_thy) @ |
|
12057 | 1180 |
pretty_asms ctxt @ |
10810 | 1181 |
verb pretty_binds (K ctxt) @ |
12057 | 1182 |
verb pretty_lthms (K ctxt) @ |
10810 | 1183 |
verb pretty_cases (K ctxt) @ |
1184 |
verb_single (fn () => Pretty.big_list "type constraints:" (map prt_defT (Vartab.dest types))) @ |
|
1185 |
verb_single (fn () => Pretty.big_list "default sorts:" (map prt_defS (Vartab.dest sorts))) @ |
|
1186 |
verb_single (fn () => Pretty.strs ("used type variable names:" :: used)) |
|
1187 |
end; |
|
1188 |
||
1189 |
||
1190 |
||
5819 | 1191 |
(** theory setup **) |
1192 |
||
1193 |
val setup = [ProofDataData.init]; |
|
1194 |
||
1195 |
end; |