8 simplification). |
8 simplification). |
9 *) |
9 *) |
10 |
10 |
11 signature THM = |
11 signature THM = |
12 sig |
12 sig |
13 structure Envir : ENVIR |
13 structure Envir : ENVIR |
14 structure Sequence : SEQUENCE |
14 structure Sequence : SEQUENCE |
15 structure Sign : SIGN |
15 structure Sign : SIGN |
16 |
16 |
17 (*certified types*) |
17 (*certified types*) |
18 type ctyp |
18 type ctyp |
19 val rep_ctyp : ctyp -> {sign: Sign.sg, T: typ} |
19 val rep_ctyp : ctyp -> {sign: Sign.sg, T: typ} |
20 val typ_of : ctyp -> typ |
20 val typ_of : ctyp -> typ |
21 val ctyp_of : Sign.sg -> typ -> ctyp |
21 val ctyp_of : Sign.sg -> typ -> ctyp |
22 val read_ctyp : Sign.sg -> string -> ctyp |
22 val read_ctyp : Sign.sg -> string -> ctyp |
23 |
23 |
24 (*certified terms*) |
24 (*certified terms*) |
25 type cterm |
25 type cterm |
26 val rep_cterm : cterm -> {sign: Sign.sg, t: term, T: typ, maxidx: int} |
26 val rep_cterm : cterm -> {sign: Sign.sg, t: term, T: typ, maxidx: int} |
27 val term_of : cterm -> term |
27 val term_of : cterm -> term |
28 val cterm_of : Sign.sg -> term -> cterm |
28 val cterm_of : Sign.sg -> term -> cterm |
29 val read_cterm : Sign.sg -> string * typ -> cterm |
29 val read_cterm : Sign.sg -> string * typ -> cterm |
30 val cterm_fun : (term -> term) -> (cterm -> cterm) |
30 val cterm_fun : (term -> term) -> (cterm -> cterm) |
31 val dest_cimplies : cterm -> cterm * cterm |
31 val dest_cimplies : cterm -> cterm * cterm |
32 val read_def_cterm : |
32 val read_def_cterm : |
33 Sign.sg * (indexname -> typ option) * (indexname -> sort option) -> |
33 Sign.sg * (indexname -> typ option) * (indexname -> sort option) -> |
34 string list -> bool -> string * typ -> cterm * (indexname * typ) list |
34 string list -> bool -> string * typ -> cterm * (indexname * typ) list |
35 |
35 |
36 (*meta theorems*) |
36 (*meta theorems*) |
37 type thm |
37 type thm |
38 exception THM of string * int * thm list |
38 exception THM of string * int * thm list |
39 val rep_thm : thm -> {sign: Sign.sg, maxidx: int, |
39 val rep_thm : thm -> {sign: Sign.sg, maxidx: int, |
40 shyps: sort list, hyps: term list, prop: term} |
40 shyps: sort list, hyps: term list, prop: term} |
41 val stamps_of_thm : thm -> string ref list |
41 val stamps_of_thm : thm -> string ref list |
42 val tpairs_of : thm -> (term * term) list |
42 val tpairs_of : thm -> (term * term) list |
43 val prems_of : thm -> term list |
43 val prems_of : thm -> term list |
44 val nprems_of : thm -> int |
44 val nprems_of : thm -> int |
45 val concl_of : thm -> term |
45 val concl_of : thm -> term |
46 val cprop_of : thm -> cterm |
46 val cprop_of : thm -> cterm |
47 val cert_axm : Sign.sg -> string * term -> string * term |
47 val extra_shyps : thm -> sort list |
48 val read_axm : Sign.sg -> string * string -> string * term |
48 val force_strip_shyps : bool ref (* FIXME tmp *) |
49 val inferT_axm : Sign.sg -> string * term -> string * term |
49 val strip_shyps : thm -> thm |
|
50 val implies_intr_shyps: thm -> thm |
|
51 val cert_axm : Sign.sg -> string * term -> string * term |
|
52 val read_axm : Sign.sg -> string * string -> string * term |
|
53 val inferT_axm : Sign.sg -> string * term -> string * term |
50 |
54 |
51 (*theories*) |
55 (*theories*) |
52 type theory |
56 type theory |
53 exception THEORY of string * theory list |
57 exception THEORY of string * theory list |
54 val rep_theory : theory -> |
58 val rep_theory : theory -> |
55 {sign: Sign.sg, new_axioms: term Sign.Symtab.table, parents: theory list} |
59 {sign: Sign.sg, new_axioms: term Sign.Symtab.table, parents: theory list} |
56 val sign_of : theory -> Sign.sg |
60 val sign_of : theory -> Sign.sg |
57 val syn_of : theory -> Sign.Syntax.syntax |
61 val syn_of : theory -> Sign.Syntax.syntax |
58 val stamps_of_thy : theory -> string ref list |
62 val stamps_of_thy : theory -> string ref list |
59 val parents_of : theory -> theory list |
63 val parents_of : theory -> theory list |
60 val subthy : theory * theory -> bool |
64 val subthy : theory * theory -> bool |
61 val eq_thy : theory * theory -> bool |
65 val eq_thy : theory * theory -> bool |
62 val get_axiom : theory -> string -> thm |
66 val get_axiom : theory -> string -> thm |
63 val axioms_of : theory -> (string * thm) list |
67 val axioms_of : theory -> (string * thm) list |
64 val proto_pure_thy : theory |
68 val proto_pure_thy : theory |
65 val pure_thy : theory |
69 val pure_thy : theory |
66 val cpure_thy : theory |
70 val cpure_thy : theory |
67 local open Sign.Syntax in |
71 local open Sign.Syntax in |
68 val add_classes : (class * class list) list -> theory -> theory |
72 val add_classes : (class * class list) list -> theory -> theory |
69 val add_classrel : (class * class) list -> theory -> theory |
73 val add_classrel : (class * class) list -> theory -> theory |
70 val add_defsort : sort -> theory -> theory |
74 val add_defsort : sort -> theory -> theory |
71 val add_types : (string * int * mixfix) list -> theory -> theory |
75 val add_types : (string * int * mixfix) list -> theory -> theory |
72 val add_tyabbrs : (string * string list * string * mixfix) list |
76 val add_tyabbrs : (string * string list * string * mixfix) list |
73 -> theory -> theory |
77 -> theory -> theory |
74 val add_tyabbrs_i : (string * string list * typ * mixfix) list |
78 val add_tyabbrs_i : (string * string list * typ * mixfix) list |
75 -> theory -> theory |
79 -> theory -> theory |
76 val add_arities : (string * sort list * sort) list -> theory -> theory |
80 val add_arities : (string * sort list * sort) list -> theory -> theory |
77 val add_consts : (string * string * mixfix) list -> theory -> theory |
81 val add_consts : (string * string * mixfix) list -> theory -> theory |
78 val add_consts_i : (string * typ * mixfix) list -> theory -> theory |
82 val add_consts_i : (string * typ * mixfix) list -> theory -> theory |
79 val add_syntax : (string * string * mixfix) list -> theory -> theory |
83 val add_syntax : (string * string * mixfix) list -> theory -> theory |
80 val add_syntax_i : (string * typ * mixfix) list -> theory -> theory |
84 val add_syntax_i : (string * typ * mixfix) list -> theory -> theory |
81 val add_trfuns : |
85 val add_trfuns : |
82 (string * (ast list -> ast)) list * |
86 (string * (ast list -> ast)) list * |
83 (string * (term list -> term)) list * |
87 (string * (term list -> term)) list * |
84 (string * (term list -> term)) list * |
88 (string * (term list -> term)) list * |
85 (string * (ast list -> ast)) list -> theory -> theory |
89 (string * (ast list -> ast)) list -> theory -> theory |
86 val add_trrules : (string * string) trrule list -> theory -> theory |
90 val add_trrules : (string * string) trrule list -> theory -> theory |
87 val add_trrules_i : ast trrule list -> theory -> theory |
91 val add_trrules_i : ast trrule list -> theory -> theory |
88 val add_axioms : (string * string) list -> theory -> theory |
92 val add_axioms : (string * string) list -> theory -> theory |
89 val add_axioms_i : (string * term) list -> theory -> theory |
93 val add_axioms_i : (string * term) list -> theory -> theory |
90 val add_thyname : string -> theory -> theory |
94 val add_thyname : string -> theory -> theory |
91 end |
95 end |
92 val merge_theories : theory * theory -> theory |
96 val merge_theories : theory * theory -> theory |
93 val merge_thy_list : bool -> theory list -> theory |
97 val merge_thy_list : bool -> theory list -> theory |
94 |
98 |
95 (*meta rules*) |
99 (*meta rules*) |
96 val force_strip_shyps : bool ref (* FIXME tmp *) |
100 val assume : cterm -> thm |
97 val strip_shyps : thm -> thm |
101 val implies_intr : cterm -> thm -> thm |
98 val implies_intr_shyps: thm -> thm |
102 val implies_elim : thm -> thm -> thm |
99 val assume : cterm -> thm |
103 val forall_intr : cterm -> thm -> thm |
100 val implies_intr : cterm -> thm -> thm |
104 val forall_elim : cterm -> thm -> thm |
101 val implies_elim : thm -> thm -> thm |
105 val flexpair_def : thm |
102 val forall_intr : cterm -> thm -> thm |
106 val reflexive : cterm -> thm |
103 val forall_elim : cterm -> thm -> thm |
107 val symmetric : thm -> thm |
104 val flexpair_def : thm |
108 val transitive : thm -> thm -> thm |
105 val reflexive : cterm -> thm |
109 val beta_conversion : cterm -> thm |
106 val symmetric : thm -> thm |
110 val extensional : thm -> thm |
107 val transitive : thm -> thm -> thm |
111 val abstract_rule : string -> cterm -> thm -> thm |
108 val beta_conversion : cterm -> thm |
112 val combination : thm -> thm -> thm |
109 val extensional : thm -> thm |
113 val equal_intr : thm -> thm -> thm |
110 val abstract_rule : string -> cterm -> thm -> thm |
114 val equal_elim : thm -> thm -> thm |
111 val combination : thm -> thm -> thm |
115 val implies_intr_hyps : thm -> thm |
112 val equal_intr : thm -> thm -> thm |
116 val flexflex_rule : thm -> thm Sequence.seq |
113 val equal_elim : thm -> thm -> thm |
117 val instantiate : |
114 val implies_intr_hyps : thm -> thm |
|
115 val flexflex_rule : thm -> thm Sequence.seq |
|
116 val instantiate : |
|
117 (indexname * ctyp) list * (cterm * cterm) list -> thm -> thm |
118 (indexname * ctyp) list * (cterm * cterm) list -> thm -> thm |
118 val trivial : cterm -> thm |
119 val trivial : cterm -> thm |
119 val class_triv : theory -> class -> thm |
120 val class_triv : theory -> class -> thm |
120 val varifyT : thm -> thm |
121 val varifyT : thm -> thm |
121 val freezeT : thm -> thm |
122 val freezeT : thm -> thm |
122 val dest_state : thm * int -> |
123 val dest_state : thm * int -> |
123 (term * term) list * term list * term * term |
124 (term * term) list * term list * term * term |
124 val lift_rule : (thm * int) -> thm -> thm |
125 val lift_rule : (thm * int) -> thm -> thm |
125 val assumption : int -> thm -> thm Sequence.seq |
126 val assumption : int -> thm -> thm Sequence.seq |
126 val eq_assumption : int -> thm -> thm |
127 val eq_assumption : int -> thm -> thm |
127 val rename_params_rule: string list * int -> thm -> thm |
128 val rename_params_rule: string list * int -> thm -> thm |
128 val bicompose : bool -> bool * thm * int -> |
129 val bicompose : bool -> bool * thm * int -> |
129 int -> thm -> thm Sequence.seq |
130 int -> thm -> thm Sequence.seq |
130 val biresolution : bool -> (bool * thm) list -> |
131 val biresolution : bool -> (bool * thm) list -> |
131 int -> thm -> thm Sequence.seq |
132 int -> thm -> thm Sequence.seq |
132 |
133 |
133 (*meta simplification*) |
134 (*meta simplification*) |
134 type meta_simpset |
135 type meta_simpset |
135 exception SIMPLIFIER of string * thm |
136 exception SIMPLIFIER of string * thm |
136 val empty_mss : meta_simpset |
137 val empty_mss : meta_simpset |
137 val add_simps : meta_simpset * thm list -> meta_simpset |
138 val add_simps : meta_simpset * thm list -> meta_simpset |
138 val del_simps : meta_simpset * thm list -> meta_simpset |
139 val del_simps : meta_simpset * thm list -> meta_simpset |
139 val mss_of : thm list -> meta_simpset |
140 val mss_of : thm list -> meta_simpset |
140 val add_congs : meta_simpset * thm list -> meta_simpset |
141 val add_congs : meta_simpset * thm list -> meta_simpset |
141 val add_prems : meta_simpset * thm list -> meta_simpset |
142 val add_prems : meta_simpset * thm list -> meta_simpset |
142 val prems_of_mss : meta_simpset -> thm list |
143 val prems_of_mss : meta_simpset -> thm list |
143 val set_mk_rews : meta_simpset * (thm -> thm list) -> meta_simpset |
144 val set_mk_rews : meta_simpset * (thm -> thm list) -> meta_simpset |
144 val mk_rews_of_mss : meta_simpset -> thm -> thm list |
145 val mk_rews_of_mss : meta_simpset -> thm -> thm list |
145 val trace_simp : bool ref |
146 val trace_simp : bool ref |
146 val rewrite_cterm : bool * bool -> meta_simpset -> |
147 val rewrite_cterm : bool * bool -> meta_simpset -> |
147 (meta_simpset -> thm -> thm option) -> cterm -> thm |
148 (meta_simpset -> thm -> thm option) -> cterm -> thm |
148 end; |
149 end; |
149 |
150 |
150 functor ThmFun (structure Logic: LOGIC and Unify: UNIFY and Pattern: PATTERN |
151 functor ThmFun (structure Logic: LOGIC and Unify: UNIFY and Pattern: PATTERN |
151 and Net:NET sharing type Pattern.type_sig = Unify.Sign.Type.type_sig): THM = |
152 and Net:NET sharing type Pattern.type_sig = Unify.Sign.Type.type_sig): THM = |
284 fun concl_of (Thm {prop, ...}) = Logic.strip_imp_concl prop; |
261 fun concl_of (Thm {prop, ...}) = Logic.strip_imp_concl prop; |
285 |
262 |
286 (*the statement of any thm is a cterm*) |
263 (*the statement of any thm is a cterm*) |
287 fun cprop_of (Thm {sign, maxidx, prop, ...}) = |
264 fun cprop_of (Thm {sign, maxidx, prop, ...}) = |
288 Cterm {sign = sign, maxidx = maxidx, T = propT, t = prop}; |
265 Cterm {sign = sign, maxidx = maxidx, T = propT, t = prop}; |
|
266 |
|
267 |
|
268 |
|
269 (** sort contexts of theorems **) |
|
270 |
|
271 (* basic utils *) |
|
272 |
|
273 (*accumulate sorts suppressing duplicates; these are coded low level |
|
274 to improve efficiency a bit*) |
|
275 |
|
276 fun add_typ_sorts (Type (_, Ts), Ss) = add_typs_sorts (Ts, Ss) |
|
277 | add_typ_sorts (TFree (_, S), Ss) = S ins Ss |
|
278 | add_typ_sorts (TVar (_, S), Ss) = S ins Ss |
|
279 and add_typs_sorts ([], Ss) = Ss |
|
280 | add_typs_sorts (T :: Ts, Ss) = add_typs_sorts (Ts, add_typ_sorts (T, Ss)); |
|
281 |
|
282 fun add_term_sorts (Const (_, T), Ss) = add_typ_sorts (T, Ss) |
|
283 | add_term_sorts (Free (_, T), Ss) = add_typ_sorts (T, Ss) |
|
284 | add_term_sorts (Var (_, T), Ss) = add_typ_sorts (T, Ss) |
|
285 | add_term_sorts (Bound _, Ss) = Ss |
|
286 | add_term_sorts (Abs (_, T, t), Ss) = add_term_sorts (t, add_typ_sorts (T, Ss)) |
|
287 | add_term_sorts (t $ u, Ss) = add_term_sorts (t, add_term_sorts (u, Ss)); |
|
288 |
|
289 fun add_terms_sorts ([], Ss) = Ss |
|
290 | add_terms_sorts (t :: ts, Ss) = add_terms_sorts (ts, add_term_sorts (t, Ss)); |
|
291 |
|
292 fun add_thm_sorts (Thm {hyps, prop, ...}, Ss) = |
|
293 add_terms_sorts (hyps, add_term_sorts (prop, Ss)); |
|
294 |
|
295 fun add_thms_shyps ([], Ss) = Ss |
|
296 | add_thms_shyps (Thm {shyps, ...} :: ths, Ss) = |
|
297 add_thms_shyps (ths, shyps union Ss); |
|
298 |
|
299 |
|
300 (*get 'dangling' sort constraints of a thm*) |
|
301 fun extra_shyps (th as Thm {shyps, ...}) = |
|
302 shyps \\ add_thm_sorts (th, []); |
|
303 |
|
304 |
|
305 (* fix_shyps *) |
|
306 |
|
307 (*preserve sort contexts of rule premises and substituted types*) |
|
308 fun fix_shyps thms Ts thm = |
|
309 let |
|
310 val Thm {sign, maxidx, hyps, prop, ...} = thm; |
|
311 val shyps = |
|
312 add_thm_sorts (thm, add_typs_sorts (Ts, add_thms_shyps (thms, []))); |
|
313 in |
|
314 Thm {sign = sign, maxidx = maxidx, |
|
315 shyps = shyps, hyps = hyps, prop = prop} |
|
316 end; |
|
317 |
|
318 fun env_codT (Envir.Envir {iTs, ...}) = map snd iTs; |
|
319 |
|
320 |
|
321 (* strip_shyps *) (* FIXME improve? (e.g. only minimal extra sorts) *) |
|
322 |
|
323 val force_strip_shyps = ref true; (* FIXME tmp *) |
|
324 |
|
325 (*remove extra sorts that are known to be syntactically non-empty*) |
|
326 fun strip_shyps thm = |
|
327 let |
|
328 val Thm {sign, maxidx, shyps, hyps, prop} = thm; |
|
329 val sorts = add_thm_sorts (thm, []); |
|
330 val maybe_empty = not o Sign.nonempty_sort sign sorts; |
|
331 val shyps' = filter (fn S => S mem sorts orelse maybe_empty S) shyps; |
|
332 in |
|
333 Thm {sign = sign, maxidx = maxidx, |
|
334 shyps = |
|
335 (if eq_set (shyps', sorts) orelse not (! force_strip_shyps) then shyps' |
|
336 else (* FIXME tmp *) |
|
337 (writeln ("WARNING Removed sort hypotheses: " ^ |
|
338 commas (map Type.str_of_sort (shyps' \\ sorts))); |
|
339 writeln "WARNING Let's hope these sorts are non-empty!"; |
|
340 sorts)), |
|
341 hyps = hyps, prop = prop} |
|
342 end; |
|
343 |
|
344 |
|
345 (* implies_intr_shyps *) |
|
346 |
|
347 (*discharge all extra sort hypotheses*) |
|
348 fun implies_intr_shyps thm = |
|
349 (case extra_shyps thm of |
|
350 [] => thm |
|
351 | xshyps => |
|
352 let |
|
353 val Thm {sign, maxidx, shyps, hyps, prop} = thm; |
|
354 val shyps' = logicS ins (shyps \\ xshyps); |
|
355 val used_names = foldr add_term_tfree_names (prop :: hyps, []); |
|
356 val names = |
|
357 tl (variantlist (replicate (length xshyps + 1) "'", used_names)); |
|
358 val tfrees = map (TFree o rpair logicS) names; |
|
359 |
|
360 fun mk_insort (T, S) = map (Logic.mk_inclass o pair T) S; |
|
361 val sort_hyps = flat (map2 mk_insort (tfrees, xshyps)); |
|
362 in |
|
363 Thm {sign = sign, maxidx = maxidx, shyps = shyps', |
|
364 hyps = hyps, prop = Logic.list_implies (sort_hyps, prop)} |
|
365 end); |
289 |
366 |
290 |
367 |
291 |
368 |
292 (*** Theories ***) |
369 (*** Theories ***) |
293 |
370 |
460 |
538 |
461 |
539 |
462 |
540 |
463 (*** Meta rules ***) |
541 (*** Meta rules ***) |
464 |
542 |
465 (** sort contexts **) |
|
466 |
|
467 (*account for lost sort constraints*) |
|
468 fun fix_shyps ths Ts th = th; |
|
469 (* FIXME |
|
470 let |
|
471 fun thm_sorts (Thm {shyps, hyps, prop, ...}) = |
|
472 unions (shyps :: term_sorts prop :: map term_sorts hyps); |
|
473 val lost_sorts = |
|
474 unions (map thm_sorts ths @ map typ_sorts Ts) \\ thm_sorts th; |
|
475 val Thm {sign, maxidx, shyps, hyps, prop} = th; |
|
476 in |
|
477 Thm {sign = sign, maxidx = maxidx, |
|
478 shyps = lost_sorts @ shyps, hyps = hyps, prop = prop} |
|
479 end; |
|
480 *) |
|
481 (*remove sorts that are known to be non-empty (syntactically)*) |
|
482 val force_strip_shyps = ref true; (* FIXME tmp *) |
|
483 fun strip_shyps th = |
|
484 let |
|
485 fun sort_hyps_of t = |
|
486 term_tfrees t @ map (apfst Syntax.string_of_vname) (term_tvars t); |
|
487 |
|
488 val Thm {sign, maxidx, shyps, hyps, prop} = th; |
|
489 (* FIXME no varnames (?) *) |
|
490 val sort_hyps = unions (sort_hyps_of prop :: map sort_hyps_of hyps); |
|
491 (* FIXME improve (e.g. only minimal sorts) *) |
|
492 val shyps' = filter_out (Sign.nonempty_sort sign sort_hyps) shyps; |
|
493 in |
|
494 Thm {sign = sign, maxidx = maxidx, |
|
495 shyps = |
|
496 (if null shyps' orelse not (! force_strip_shyps) then shyps' |
|
497 else (* FIXME tmp *) |
|
498 (writeln ("WARNING Removed sort hypotheses: " ^ |
|
499 commas (map Type.str_of_sort shyps')); |
|
500 writeln "WARNING Let's hope these sorts are non-empty!"; |
|
501 [])), |
|
502 hyps = hyps, prop = prop} |
|
503 end; |
|
504 |
|
505 (*discharge all sort hypotheses*) |
|
506 fun implies_intr_shyps (th as Thm {shyps = [], ...}) = th |
|
507 | implies_intr_shyps (Thm {sign, maxidx, shyps, hyps, prop}) = |
|
508 let |
|
509 val used_names = foldr add_term_tfree_names (prop :: hyps, []); |
|
510 val names = |
|
511 tl (variantlist (replicate (length shyps + 1) "'", used_names)); |
|
512 val tfrees = map (TFree o rpair logicS) names; |
|
513 |
|
514 fun mk_insort (T, S) = map (Logic.mk_inclass o pair T) S; |
|
515 val sort_hyps = flat (map2 mk_insort (tfrees, shyps)); |
|
516 in |
|
517 Thm {sign = sign, maxidx = maxidx, shyps = [], |
|
518 hyps = hyps, prop = Logic.list_implies (sort_hyps, prop)} |
|
519 end; |
|
520 |
|
521 |
|
522 |
|
523 (** 'primitive' rules **) |
543 (** 'primitive' rules **) |
524 |
544 |
525 (*discharge all assumptions t from ts*) |
545 (*discharge all assumptions t from ts*) |
526 val disch = gen_rem (op aconv); |
546 val disch = gen_rem (op aconv); |
527 |
547 |
875 val sign = sign_of thy; |
904 val sign = sign_of thy; |
876 val Cterm {t, maxidx, ...} = |
905 val Cterm {t, maxidx, ...} = |
877 cterm_of sign (Logic.mk_inclass (TVar (("'a", 0), [c]), c)) |
906 cterm_of sign (Logic.mk_inclass (TVar (("'a", 0), [c]), c)) |
878 handle TERM (msg, _) => raise THM ("class_triv: " ^ msg, 0, []); |
907 handle TERM (msg, _) => raise THM ("class_triv: " ^ msg, 0, []); |
879 in |
908 in |
880 Thm {sign = sign, maxidx = maxidx, shyps = [], hyps = [], prop = t} |
909 fix_shyps [] [] |
|
910 (Thm {sign = sign, maxidx = maxidx, shyps = [], hyps = [], prop = t}) |
881 end; |
911 end; |
882 |
912 |
883 |
913 |
884 (* Replace all TFrees not in the hyps by new TVars *) |
914 (* Replace all TFrees not in the hyps by new TVars *) |
885 fun varifyT(Thm{sign,maxidx,shyps,hyps,prop}) = |
915 fun varifyT(Thm{sign,maxidx,shyps,hyps,prop}) = |
886 let val tfrees = foldr add_term_tfree_names (hyps,[]) |
916 let val tfrees = foldr add_term_tfree_names (hyps,[]) |
887 in Thm{sign=sign, maxidx=max[0,maxidx], shyps=shyps, hyps=hyps, |
917 in (*no fix_shyps*) |
888 prop= Type.varify(prop,tfrees)} |
918 Thm{sign=sign, maxidx=max[0,maxidx], shyps=shyps, hyps=hyps, |
|
919 prop= Type.varify(prop,tfrees)} |
889 end; |
920 end; |
890 |
921 |
891 (* Replace all TVars by new TFrees *) |
922 (* Replace all TVars by new TFrees *) |
892 fun freezeT(Thm{sign,maxidx,shyps,hyps,prop}) = |
923 fun freezeT(Thm{sign,maxidx,shyps,hyps,prop}) = |
893 let val prop' = Type.freeze prop |
924 let val prop' = Type.freeze prop |
894 in Thm{sign=sign, maxidx=maxidx_of_term prop', shyps=shyps, hyps=hyps, |
925 in (*no fix_shyps*) |
895 prop=prop'} |
926 Thm{sign=sign, maxidx=maxidx_of_term prop', shyps=shyps, hyps=hyps, |
|
927 prop=prop'} |
896 end; |
928 end; |
897 |
929 |
898 |
930 |
899 (*** Inference rules for tactics ***) |
931 (*** Inference rules for tactics ***) |
900 |
932 |
908 handle TERM _ => raise THM("dest_state", i, [state]); |
940 handle TERM _ => raise THM("dest_state", i, [state]); |
909 |
941 |
910 (*Increment variables and parameters of orule as required for |
942 (*Increment variables and parameters of orule as required for |
911 resolution with goal i of state. *) |
943 resolution with goal i of state. *) |
912 fun lift_rule (state, i) orule = |
944 fun lift_rule (state, i) orule = |
913 let val Thm{prop=sprop,maxidx=smax,...} = state; |
945 let val Thm{shyps=sshyps,prop=sprop,maxidx=smax,...} = state; |
914 val (Bi::_, _) = Logic.strip_prems(i, [], Logic.skip_flexpairs sprop) |
946 val (Bi::_, _) = Logic.strip_prems(i, [], Logic.skip_flexpairs sprop) |
915 handle TERM _ => raise THM("lift_rule", i, [orule,state]); |
947 handle TERM _ => raise THM("lift_rule", i, [orule,state]); |
916 val (lift_abs,lift_all) = Logic.lift_fns(Bi,smax+1); |
948 val (lift_abs,lift_all) = Logic.lift_fns(Bi,smax+1); |
917 val (Thm{sign,maxidx,hyps,prop,...}) = orule |
949 val (Thm{sign,maxidx,shyps,hyps,prop}) = orule |
918 val (tpairs,As,B) = Logic.strip_horn prop |
950 val (tpairs,As,B) = Logic.strip_horn prop |
919 in fix_shyps [state, orule] [] |
951 in (*no fix_shyps*) |
920 (Thm{hyps=hyps, sign= merge_thm_sgs(state,orule), |
952 Thm{hyps=hyps, sign= merge_thm_sgs(state,orule), |
921 shyps=[], maxidx= maxidx+smax+1, |
953 shyps=sshyps union shyps, maxidx= maxidx+smax+1, |
922 prop= Logic.rule_of(map (pairself lift_abs) tpairs, |
954 prop= Logic.rule_of(map (pairself lift_abs) tpairs, |
923 map lift_all As, lift_all B)}) |
955 map lift_all As, lift_all B)} |
924 end; |
956 end; |
925 |
957 |
926 (*Solve subgoal Bi of proof state B1...Bn/C by assumption. *) |
958 (*Solve subgoal Bi of proof state B1...Bn/C by assumption. *) |
927 fun assumption i state = |
959 fun assumption i state = |
928 let val Thm{sign,maxidx,hyps,prop,...} = state; |
960 let val Thm{sign,maxidx,hyps,prop,...} = state; |
1071 in |
1103 in |
1072 fun bicompose_aux match (state, (stpairs, Bs, Bi, C), lifted) |
1104 fun bicompose_aux match (state, (stpairs, Bs, Bi, C), lifted) |
1073 (eres_flg, orule, nsubgoal) = |
1105 (eres_flg, orule, nsubgoal) = |
1074 let val Thm{maxidx=smax, hyps=shyps, ...} = state |
1106 let val Thm{maxidx=smax, hyps=shyps, ...} = state |
1075 and Thm{maxidx=rmax, hyps=rhyps, prop=rprop,...} = orule |
1107 and Thm{maxidx=rmax, hyps=rhyps, prop=rprop,...} = orule |
1076 (*How many hyps to skip over during normalization*) |
1108 (*How many hyps to skip over during normalization*) |
1077 and nlift = Logic.count_prems(strip_all_body Bi, |
1109 and nlift = Logic.count_prems(strip_all_body Bi, |
1078 if eres_flg then ~1 else 0) |
1110 if eres_flg then ~1 else 0) |
1079 val sign = merge_thm_sgs(state,orule); |
1111 val sign = merge_thm_sgs(state,orule); |
1080 (** Add new theorem with prop = '[| Bs; As |] ==> C' to thq **) |
1112 (** Add new theorem with prop = '[| Bs; As |] ==> C' to thq **) |
1081 fun addth As ((env as Envir.Envir {maxidx, ...}, tpairs), thq) = |
1113 fun addth As ((env as Envir.Envir {maxidx, ...}, tpairs), thq) = |
1082 let val normt = Envir.norm_term env; |
1114 let val normt = Envir.norm_term env; |
1083 (*perform minimal copying here by examining env*) |
1115 (*perform minimal copying here by examining env*) |
1084 val normp = |
1116 val normp = |
1085 if Envir.is_empty env then (tpairs, Bs @ As, C) |
1117 if Envir.is_empty env then (tpairs, Bs @ As, C) |
1086 else |
1118 else |
1087 let val ntps = map (pairself normt) tpairs |
1119 let val ntps = map (pairself normt) tpairs |
1088 in if the (Envir.minidx env) > smax then |
1120 in if the (Envir.minidx env) > smax then |
1089 (*no assignments in state; normalize the rule only*) |
1121 (*no assignments in state; normalize the rule only*) |
1090 if lifted |
1122 if lifted |
1091 then (ntps, Bs @ map (norm_term_skip env nlift) As, C) |
1123 then (ntps, Bs @ map (norm_term_skip env nlift) As, C) |
1092 else (ntps, Bs @ map normt As, C) |
1124 else (ntps, Bs @ map normt As, C) |
1093 else if match then raise Bicompose |
1125 else if match then raise Bicompose |
1094 else (*normalize the new rule fully*) |
1126 else (*normalize the new rule fully*) |
1095 (ntps, map normt (Bs @ As), normt C) |
1127 (ntps, map normt (Bs @ As), normt C) |
1096 end |
1128 end |
1097 val th = |
1129 val th = (* FIXME improve *) |
1098 fix_shyps [state, orule] (env_codT env) |
1130 fix_shyps [state, orule] (env_codT env) |
1099 (Thm{sign=sign, shyps=[], hyps=rhyps union shyps, |
1131 (Thm{sign=sign, shyps=[], hyps=rhyps union shyps, |
1100 maxidx=maxidx, prop= Logic.rule_of normp}) |
1132 maxidx=maxidx, prop= Logic.rule_of normp}) |
1101 in cons(th, thq) end handle Bicompose => thq |
1133 in cons(th, thq) end handle Bicompose => thq |
1102 val (rtpairs,rhorn) = Logic.strip_flexpairs(rprop); |
1134 val (rtpairs,rhorn) = Logic.strip_flexpairs(rprop); |