95 val join_transfer: theory -> thm -> thm |
95 val join_transfer: theory -> thm -> thm |
96 val join_transfer_context: Proof.context * thm -> Proof.context * thm |
96 val join_transfer_context: Proof.context * thm -> Proof.context * thm |
97 val renamed_prop: term -> thm -> thm |
97 val renamed_prop: term -> thm -> thm |
98 val weaken: cterm -> thm -> thm |
98 val weaken: cterm -> thm -> thm |
99 val weaken_sorts: sort list -> cterm -> cterm |
99 val weaken_sorts: sort list -> cterm -> cterm |
100 val extra_shyps: thm -> sort list |
|
101 val proof_bodies_of: thm list -> proof_body list |
100 val proof_bodies_of: thm list -> proof_body list |
102 val proof_body_of: thm -> proof_body |
101 val proof_body_of: thm -> proof_body |
103 val proof_of: thm -> proof |
102 val proof_of: thm -> proof |
104 val reconstruct_proof_of: thm -> Proofterm.proof |
103 val reconstruct_proof_of: thm -> Proofterm.proof |
105 val consolidate: thm list -> unit |
104 val consolidate: thm list -> unit |
106 val expose_proofs: theory -> thm list -> unit |
105 val expose_proofs: theory -> thm list -> unit |
107 val expose_proof: theory -> thm -> unit |
106 val expose_proof: theory -> thm -> unit |
108 val future: thm future -> cterm -> thm |
107 val future: thm future -> cterm -> thm |
109 val thm_deps: thm -> Proofterm.thm Ord_List.T |
108 val thm_deps: thm -> Proofterm.thm Ord_List.T |
|
109 val extra_shyps: thm -> sort list |
|
110 val strip_shyps: thm -> thm |
110 val derivation_closed: thm -> bool |
111 val derivation_closed: thm -> bool |
111 val derivation_name: thm -> string |
112 val derivation_name: thm -> string |
112 val derivation_id: thm -> Proofterm.thm_id option |
113 val derivation_id: thm -> Proofterm.thm_id option |
113 val raw_derivation_name: thm -> string |
114 val raw_derivation_name: thm -> string |
114 val expand_name: thm -> Proofterm.thm_header -> string option |
115 val expand_name: thm -> Proofterm.thm_header -> string option |
157 thm -> thm |
158 thm -> thm |
158 val instantiate_cterm: ((indexname * sort) * ctyp) list * ((indexname * typ) * cterm) list -> |
159 val instantiate_cterm: ((indexname * sort) * ctyp) list * ((indexname * typ) * cterm) list -> |
159 cterm -> cterm |
160 cterm -> cterm |
160 val trivial: cterm -> thm |
161 val trivial: cterm -> thm |
161 val of_class: ctyp * class -> thm |
162 val of_class: ctyp * class -> thm |
162 val strip_shyps: thm -> thm |
|
163 val unconstrainT: thm -> thm |
163 val unconstrainT: thm -> thm |
164 val varifyT_global': (string * sort) list -> thm -> ((string * sort) * indexname) list * thm |
164 val varifyT_global': (string * sort) list -> thm -> ((string * sort) * indexname) list * thm |
165 val varifyT_global: thm -> thm |
165 val varifyT_global: thm -> thm |
166 val legacy_freezeT: thm -> thm |
166 val legacy_freezeT: thm -> thm |
167 val plain_prop_of: thm -> term |
167 val plain_prop_of: thm -> term |
697 val thy = theory_of_cterm ct; |
697 val thy = theory_of_cterm ct; |
698 val more_sorts = Sorts.make (map (Sign.certify_sort thy) raw_sorts); |
698 val more_sorts = Sorts.make (map (Sign.certify_sort thy) raw_sorts); |
699 val sorts' = Sorts.union sorts more_sorts; |
699 val sorts' = Sorts.union sorts more_sorts; |
700 in Cterm {cert = cert, t = t, T = T, maxidx = maxidx, sorts = sorts'} end; |
700 in Cterm {cert = cert, t = t, T = T, maxidx = maxidx, sorts = sorts'} end; |
701 |
701 |
702 (*dangling sort constraints of a thm*) |
|
703 fun extra_shyps (th as Thm (_, {shyps, ...})) = |
|
704 Sorts.subtract (fold_terms Sorts.insert_term th []) shyps; |
|
705 |
|
706 |
702 |
707 |
703 |
708 (** derivations and promised proofs **) |
704 (** derivations and promised proofs **) |
709 |
705 |
710 fun make_deriv promises oracles thms proof = |
706 fun make_deriv promises oracles thms proof = |
985 {constraints = [], cert = cert, tags = tags, maxidx = maxidx, |
981 {constraints = [], cert = cert, tags = tags, maxidx = maxidx, |
986 shyps = shyps, hyps = hyps, tpairs = tpairs, prop = prop}) |
982 shyps = shyps, hyps = hyps, tpairs = tpairs, prop = prop}) |
987 end; |
983 end; |
988 |
984 |
989 end; |
985 end; |
|
986 |
|
987 (*Dangling sort constraints of a thm*) |
|
988 fun extra_shyps (th as Thm (_, {shyps, ...})) = |
|
989 Sorts.subtract (fold_terms Sorts.insert_term th []) shyps; |
|
990 |
|
991 (*Remove extra sorts that are witnessed by type signature information*) |
|
992 fun strip_shyps thm = |
|
993 (case thm of |
|
994 Thm (_, {shyps = [], ...}) => thm |
|
995 | Thm (der, {cert, tags, maxidx, constraints, shyps, hyps, tpairs, prop}) => |
|
996 let |
|
997 val thy = theory_of_thm thm; |
|
998 |
|
999 val algebra = Sign.classes_of thy; |
|
1000 val minimize = Sorts.minimize_sort algebra; |
|
1001 val le = Sorts.sort_le algebra; |
|
1002 fun lt (S1, S2) = le (S1, S2) andalso not (le (S2, S1)); |
|
1003 fun rel (S1, S2) = if S1 = S2 then [] else [(Term.aT S1, S2)]; |
|
1004 |
|
1005 val present = (fold_terms o fold_types o fold_atyps_sorts) (insert (eq_fst op =)) thm []; |
|
1006 val extra = fold (Sorts.remove_sort o #2) present shyps; |
|
1007 val witnessed = Sign.witness_sorts thy present extra; |
|
1008 val non_witnessed = fold (Sorts.remove_sort o #2) witnessed extra |> map (`minimize); |
|
1009 |
|
1010 val extra' = |
|
1011 non_witnessed |> map_filter (fn (S, _) => |
|
1012 if non_witnessed |> exists (fn (S', _) => lt (S', S)) then NONE else SOME S) |
|
1013 |> Sorts.make; |
|
1014 |
|
1015 val constrs' = |
|
1016 non_witnessed |> maps (fn (S1, S2) => |
|
1017 let val S0 = the (find_first (fn S => le (S, S1)) extra') |
|
1018 in rel (S0, S1) @ rel (S1, S2) end); |
|
1019 |
|
1020 val constraints' = fold (insert_constraints thy) (witnessed @ constrs') constraints; |
|
1021 val shyps' = fold (Sorts.insert_sort o #2) present extra'; |
|
1022 in |
|
1023 Thm (deriv_rule_unconditional |
|
1024 (Proofterm.strip_shyps_proof algebra present witnessed extra') der, |
|
1025 {cert = cert, tags = tags, maxidx = maxidx, constraints = constraints', |
|
1026 shyps = shyps', hyps = hyps, tpairs = tpairs, prop = prop}) |
|
1027 end) |
|
1028 |> solve_constraints; |
990 |
1029 |
991 |
1030 |
992 |
1031 |
993 (*** Closed theorems with official name ***) |
1032 (*** Closed theorems with official name ***) |
994 |
1033 |
1690 hyps = [], |
1729 hyps = [], |
1691 tpairs = [], |
1730 tpairs = [], |
1692 prop = prop}) |
1731 prop = prop}) |
1693 else raise THM ("of_class: type not of class " ^ Syntax.string_of_sort_global thy [c], 0, []) |
1732 else raise THM ("of_class: type not of class " ^ Syntax.string_of_sort_global thy [c], 0, []) |
1694 end |> solve_constraints; |
1733 end |> solve_constraints; |
1695 |
|
1696 (*Remove extra sorts that are witnessed by type signature information*) |
|
1697 fun strip_shyps thm = |
|
1698 (case thm of |
|
1699 Thm (_, {shyps = [], ...}) => thm |
|
1700 | Thm (der, {cert, tags, maxidx, constraints, shyps, hyps, tpairs, prop}) => |
|
1701 let |
|
1702 val thy = theory_of_thm thm; |
|
1703 |
|
1704 val algebra = Sign.classes_of thy; |
|
1705 val minimize = Sorts.minimize_sort algebra; |
|
1706 val le = Sorts.sort_le algebra; |
|
1707 fun lt (S1, S2) = le (S1, S2) andalso not (le (S2, S1)); |
|
1708 fun rel (S1, S2) = if S1 = S2 then [] else [(Term.aT S1, S2)]; |
|
1709 |
|
1710 val present = (fold_terms o fold_types o fold_atyps_sorts) (insert (eq_fst op =)) thm []; |
|
1711 val extra = fold (Sorts.remove_sort o #2) present shyps; |
|
1712 val witnessed = Sign.witness_sorts thy present extra; |
|
1713 val non_witnessed = fold (Sorts.remove_sort o #2) witnessed extra |> map (`minimize); |
|
1714 |
|
1715 val extra' = |
|
1716 non_witnessed |> map_filter (fn (S, _) => |
|
1717 if non_witnessed |> exists (fn (S', _) => lt (S', S)) then NONE else SOME S) |
|
1718 |> Sorts.make; |
|
1719 |
|
1720 val constrs' = |
|
1721 non_witnessed |> maps (fn (S1, S2) => |
|
1722 let val S0 = the (find_first (fn S => le (S, S1)) extra') |
|
1723 in rel (S0, S1) @ rel (S1, S2) end); |
|
1724 |
|
1725 val constraints' = fold (insert_constraints thy) (witnessed @ constrs') constraints; |
|
1726 val shyps' = fold (Sorts.insert_sort o #2) present extra'; |
|
1727 in |
|
1728 Thm (deriv_rule_unconditional |
|
1729 (Proofterm.strip_shyps_proof algebra present witnessed extra') der, |
|
1730 {cert = cert, tags = tags, maxidx = maxidx, constraints = constraints', |
|
1731 shyps = shyps', hyps = hyps, tpairs = tpairs, prop = prop}) |
|
1732 end) |
|
1733 |> solve_constraints; |
|
1734 |
|
1735 |
1734 |
1736 (*Internalize sort constraints of type variables*) |
1735 (*Internalize sort constraints of type variables*) |
1737 val unconstrainT = |
1736 val unconstrainT = |
1738 solve_constraints #> (fn thm as Thm (der, args) => |
1737 solve_constraints #> (fn thm as Thm (der, args) => |
1739 let |
1738 let |