113 val cabs: cterm -> cterm -> cterm |
113 val cabs: cterm -> cterm -> cterm |
114 val adjust_maxidx_cterm: int -> cterm -> cterm |
114 val adjust_maxidx_cterm: int -> cterm -> cterm |
115 val incr_indexes_cterm: int -> cterm -> cterm |
115 val incr_indexes_cterm: int -> cterm -> cterm |
116 val match: cterm * cterm -> (ctyp * ctyp) list * (cterm * cterm) list |
116 val match: cterm * cterm -> (ctyp * ctyp) list * (cterm * cterm) list |
117 val first_order_match: cterm * cterm -> (ctyp * ctyp) list * (cterm * cterm) list |
117 val first_order_match: cterm * cterm -> (ctyp * ctyp) list * (cterm * cterm) list |
|
118 val fold_terms: (term -> 'a -> 'a) -> thm -> 'a -> 'a |
118 val terms_of_tpairs: (term * term) list -> term list |
119 val terms_of_tpairs: (term * term) list -> term list |
119 val full_prop_of: thm -> term |
120 val full_prop_of: thm -> term |
120 val maxidx_of: thm -> int |
121 val maxidx_of: thm -> int |
121 val maxidx_thm: thm -> int -> int |
122 val maxidx_thm: thm -> int -> int |
122 val hyps_of: thm -> term list |
123 val hyps_of: thm -> term list |
365 hyps = map (cterm ~1) hyps, |
366 hyps = map (cterm ~1) hyps, |
366 tpairs = map (pairself (cterm maxidx)) tpairs, |
367 tpairs = map (pairself (cterm maxidx)) tpairs, |
367 prop = cterm maxidx prop} |
368 prop = cterm maxidx prop} |
368 end; |
369 end; |
369 |
370 |
|
371 fun fold_terms f (Thm (_, {tpairs, prop, hyps, ...})) = |
|
372 fold (fn (t, u) => f t #> f u) tpairs #> f prop #> fold f hyps; |
|
373 |
370 fun terms_of_tpairs tpairs = fold_rev (fn (t, u) => cons t o cons u) tpairs []; |
374 fun terms_of_tpairs tpairs = fold_rev (fn (t, u) => cons t o cons u) tpairs []; |
371 |
375 |
372 fun eq_tpairs ((t, u), (t', u')) = t aconv t' andalso u aconv u'; |
376 fun eq_tpairs ((t, u), (t', u')) = t aconv t' andalso u aconv u'; |
373 fun union_tpairs ts us = Library.merge eq_tpairs (ts, us); |
377 fun union_tpairs ts us = Library.merge eq_tpairs (ts, us); |
374 val maxidx_tpairs = fold (fn (t, u) => Term.maxidx_term t #> Term.maxidx_term u); |
378 val maxidx_tpairs = fold (fn (t, u) => Term.maxidx_term t #> Term.maxidx_term u); |
471 |
475 |
472 |
476 |
473 |
477 |
474 (** sort contexts of theorems **) |
478 (** sort contexts of theorems **) |
475 |
479 |
476 fun present_sorts (Thm (_, {hyps, tpairs, prop, ...})) = |
480 (*remove extra sorts that are witnessed by type signature information*) |
477 fold (fn (t, u) => Sorts.insert_term t o Sorts.insert_term u) tpairs |
|
478 (Sorts.insert_terms hyps (Sorts.insert_term prop [])); |
|
479 |
|
480 (*remove extra sorts that are non-empty by virtue of type signature information*) |
|
481 fun strip_shyps (thm as Thm (_, {shyps = [], ...})) = thm |
481 fun strip_shyps (thm as Thm (_, {shyps = [], ...})) = thm |
482 | strip_shyps (thm as Thm (der, {thy_ref, tags, maxidx, shyps, hyps, tpairs, prop})) = |
482 | strip_shyps (thm as Thm (der, {thy_ref, tags, maxidx, shyps, hyps, tpairs, prop})) = |
483 let |
483 let |
484 val thy = Theory.deref thy_ref; |
484 val thy = Theory.deref thy_ref; |
485 val present = present_sorts thm; |
485 val present = |
486 val extra = Sorts.subtract present shyps; |
486 (fold_terms o fold_types o fold_atyps) |
487 val extra' = |
487 (fn T as TFree (_, S) => insert (eq_snd op =) (T, S) |
488 Sorts.subtract (map #2 (Sign.witness_sorts thy present extra)) extra |
488 | T as TVar (_, S) => insert (eq_snd op =) (T, S)) thm []; |
|
489 val extra = fold (Sorts.remove_sort o #2) present shyps; |
|
490 val witnessed = Sign.witness_sorts thy present extra; |
|
491 val extra' = fold (Sorts.remove_sort o #2) witnessed extra |
489 |> Sorts.minimal_sorts (Sign.classes_of thy); |
492 |> Sorts.minimal_sorts (Sign.classes_of thy); |
490 val shyps' = Sorts.union present extra' |
493 val shyps' = fold (Sorts.insert_sort o #2) present extra'; |
491 |> Sorts.remove_sort []; |
|
492 in |
494 in |
493 Thm (der, {thy_ref = Theory.check_thy thy, tags = tags, maxidx = maxidx, |
495 Thm (der, {thy_ref = Theory.check_thy thy, tags = tags, maxidx = maxidx, |
494 shyps = shyps', hyps = hyps, tpairs = tpairs, prop = prop}) |
496 shyps = shyps', hyps = hyps, tpairs = tpairs, prop = prop}) |
495 end; |
497 end; |
496 |
498 |
497 (*dangling sort constraints of a thm*) |
499 (*dangling sort constraints of a thm*) |
498 fun extra_shyps (th as Thm (_, {shyps, ...})) = Sorts.subtract (present_sorts th) shyps; |
500 fun extra_shyps (th as Thm (_, {shyps, ...})) = |
|
501 Sorts.subtract (fold_terms Sorts.insert_term th []) shyps; |
499 |
502 |
500 |
503 |
501 |
504 |
502 (** derivations **) |
505 (** derivations **) |
503 |
506 |