| author | wenzelm | 
| Sat, 07 Sep 2013 16:33:10 +0200 | |
| changeset 53458 | ddefd18d5ed0 | 
| parent 53206 | 5d2fe75c6306 | 
| child 54984 | da70ab8531f4 | 
| permissions | -rw-r--r-- | 
| 22362 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 1 | (* Title: Pure/more_thm.ML | 
| 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 2 | Author: Makarius | 
| 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 3 | |
| 22907 | 4 | Further operations on type ctyp/cterm/thm, outside the inference kernel. | 
| 22362 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 5 | *) | 
| 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 6 | |
| 23169 | 7 | infix aconvc; | 
| 8 | ||
| 32842 | 9 | signature BASIC_THM = | 
| 10 | sig | |
| 11 | include BASIC_THM | |
| 12 | structure Ctermtab: TABLE | |
| 13 | structure Thmtab: TABLE | |
| 14 | val aconvc: cterm * cterm -> bool | |
| 45375 
7fe19930dfc9
more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
 wenzelm parents: 
43780diff
changeset | 15 | type attribute = Context.generic * thm -> Context.generic option * thm option | 
| 32842 | 16 | end; | 
| 17 | ||
| 22362 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 18 | signature THM = | 
| 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 19 | sig | 
| 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 20 | include THM | 
| 32842 | 21 | structure Ctermtab: TABLE | 
| 22 | structure Thmtab: TABLE | |
| 24948 | 23 | val aconvc: cterm * cterm -> bool | 
| 23491 | 24 | val add_cterm_frees: cterm -> cterm list -> cterm list | 
| 32198 | 25 | val all_name: string * cterm -> cterm -> cterm | 
| 26 | val all: cterm -> cterm -> cterm | |
| 22907 | 27 | val mk_binop: cterm -> cterm -> cterm -> cterm | 
| 28 | val dest_binop: cterm -> cterm * cterm | |
| 29 | val dest_implies: cterm -> cterm * cterm | |
| 30 | val dest_equals: cterm -> cterm * cterm | |
| 31 | val dest_equals_lhs: cterm -> cterm | |
| 32 | val dest_equals_rhs: cterm -> cterm | |
| 33 | val lhs_of: thm -> cterm | |
| 34 | val rhs_of: thm -> cterm | |
| 22362 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 35 | val thm_ord: thm * thm -> order | 
| 32842 | 36 | val cterm_cache: (cterm -> 'a) -> cterm -> 'a | 
| 37 | val thm_cache: (thm -> 'a) -> thm -> 'a | |
| 23599 | 38 | val is_reflexive: thm -> bool | 
| 22362 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 39 | val eq_thm: thm * thm -> bool | 
| 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 40 | val eq_thm_thy: thm * thm -> bool | 
| 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 41 | val eq_thm_prop: thm * thm -> bool | 
| 52683 
fb028440473e
more official Thm.eq_thm_strict, without demanding ML equality type;
 wenzelm parents: 
51316diff
changeset | 42 | val eq_thm_strict: thm * thm -> bool | 
| 22362 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 43 | val equiv_thm: thm * thm -> bool | 
| 31944 | 44 | val class_triv: theory -> class -> thm | 
| 45 | val of_sort: ctyp * sort -> thm list | |
| 28621 
a60164e8fff0
added check_shyps, which reject pending sort hypotheses;
 wenzelm parents: 
28116diff
changeset | 46 | val check_shyps: sort list -> thm -> thm | 
| 24048 
a12b4faff474
moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
 wenzelm parents: 
23599diff
changeset | 47 | val is_dummy: thm -> bool | 
| 22695 
17073e9b94f2
moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
 wenzelm parents: 
22682diff
changeset | 48 | val plain_prop_of: thm -> term | 
| 24048 
a12b4faff474
moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
 wenzelm parents: 
23599diff
changeset | 49 | val add_thm: thm -> thm list -> thm list | 
| 
a12b4faff474
moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
 wenzelm parents: 
23599diff
changeset | 50 | val del_thm: thm -> thm list -> thm list | 
| 
a12b4faff474
moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
 wenzelm parents: 
23599diff
changeset | 51 | val merge_thms: thm list * thm list -> thm list | 
| 33453 | 52 | val full_rules: thm Item_Net.T | 
| 30560 | 53 | val intro_rules: thm Item_Net.T | 
| 54 | val elim_rules: thm Item_Net.T | |
| 27866 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 55 | val elim_implies: thm -> thm -> thm | 
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 56 | val forall_elim_var: int -> thm -> thm | 
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 57 | val forall_elim_vars: int -> thm -> thm | 
| 32279 | 58 | val certify_inst: theory -> | 
| 59 | ((indexname * sort) * typ) list * ((indexname * typ) * term) list -> | |
| 60 | (ctyp * ctyp) list * (cterm * cterm) list | |
| 61 | val certify_instantiate: | |
| 62 | ((indexname * sort) * typ) list * ((indexname * typ) * term) list -> thm -> thm | |
| 35985 
0bbf0d2348f9
moved Drule.forall_intr_frees to Thm.forall_intr_frees (in more_thm.ML, which is loaded before pure_thy.ML);
 wenzelm parents: 
35857diff
changeset | 63 | val forall_intr_frees: thm -> thm | 
| 35845 
e5980f0ad025
renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
 wenzelm parents: 
35715diff
changeset | 64 | val unvarify_global: thm -> thm | 
| 27866 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 65 | val close_derivation: thm -> thm | 
| 42375 
774df7c59508
report Name_Space.declare/define, relatively to context;
 wenzelm parents: 
40238diff
changeset | 66 | val add_axiom: Proof.context -> binding * term -> theory -> (string * thm) * theory | 
| 
774df7c59508
report Name_Space.declare/define, relatively to context;
 wenzelm parents: 
40238diff
changeset | 67 | val add_axiom_global: binding * term -> theory -> (string * thm) * theory | 
| 
774df7c59508
report Name_Space.declare/define, relatively to context;
 wenzelm parents: 
40238diff
changeset | 68 | val add_def: Proof.context -> bool -> bool -> binding * term -> theory -> (string * thm) * theory | 
| 
774df7c59508
report Name_Space.declare/define, relatively to context;
 wenzelm parents: 
40238diff
changeset | 69 | val add_def_global: bool -> bool -> binding * term -> theory -> (string * thm) * theory | 
| 45375 
7fe19930dfc9
more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
 wenzelm parents: 
43780diff
changeset | 70 | type attribute = Context.generic * thm -> Context.generic option * thm option | 
| 30210 | 71 | type binding = binding * attribute list | 
| 72 | val empty_binding: binding | |
| 27866 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 73 | val rule_attribute: (Context.generic -> thm -> thm) -> attribute | 
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 74 | val declaration_attribute: (thm -> Context.generic -> Context.generic) -> attribute | 
| 45375 
7fe19930dfc9
more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
 wenzelm parents: 
43780diff
changeset | 75 | val mixed_attribute: (Context.generic * thm -> Context.generic * thm) -> attribute | 
| 46775 
6287653e63ec
canonical argument order for attribute application;
 wenzelm parents: 
46497diff
changeset | 76 | val apply_attribute: attribute -> thm -> Context.generic -> thm * Context.generic | 
| 45375 
7fe19930dfc9
more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
 wenzelm parents: 
43780diff
changeset | 77 | val attribute_declaration: attribute -> thm -> Context.generic -> Context.generic | 
| 46775 
6287653e63ec
canonical argument order for attribute application;
 wenzelm parents: 
46497diff
changeset | 78 | val theory_attributes: attribute list -> thm -> theory -> thm * theory | 
| 
6287653e63ec
canonical argument order for attribute application;
 wenzelm parents: 
46497diff
changeset | 79 | val proof_attributes: attribute list -> thm -> Proof.context -> thm * Proof.context | 
| 27866 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 80 | val no_attributes: 'a -> 'a * 'b list | 
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 81 |   val simple_fact: 'a -> ('a * 'b list) list
 | 
| 46830 | 82 | val tag_rule: string * string -> thm -> thm | 
| 27866 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 83 | val untag_rule: string -> thm -> thm | 
| 46830 | 84 | val tag: string * string -> attribute | 
| 27866 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 85 | val untag: string -> attribute | 
| 30342 | 86 | val def_name: string -> string | 
| 87 | val def_name_optional: string -> string -> string | |
| 35238 | 88 | val def_binding: Binding.binding -> Binding.binding | 
| 30433 
ce5138c92ca7
added def_binding_optional -- robust version of def_name_optional for bindings;
 wenzelm parents: 
30342diff
changeset | 89 | val def_binding_optional: Binding.binding -> Binding.binding -> Binding.binding | 
| 27866 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 90 | val has_name_hint: thm -> bool | 
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 91 | val get_name_hint: thm -> string | 
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 92 | val put_name_hint: string -> thm -> thm | 
| 22362 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 93 | val theoremK: string | 
| 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 94 | val lemmaK: string | 
| 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 95 | val corollaryK: string | 
| 42473 | 96 | val legacy_get_kind: thm -> string | 
| 27866 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 97 | val kind_rule: string -> thm -> thm | 
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 98 | val kind: string -> attribute | 
| 49062 
7e31dfd99ce7
discontinued complicated/unreliable notion of recent proofs within context;
 wenzelm parents: 
49058diff
changeset | 99 | val register_proofs: thm list -> theory -> theory | 
| 49011 
9c68e43502ce
some support for registering forked proofs within Proof.state, using its bottom context;
 wenzelm parents: 
49010diff
changeset | 100 | val join_theory_proofs: theory -> unit | 
| 22362 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 101 | end; | 
| 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 102 | |
| 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 103 | structure Thm: THM = | 
| 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 104 | struct | 
| 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 105 | |
| 22695 
17073e9b94f2
moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
 wenzelm parents: 
22682diff
changeset | 106 | (** basic operations **) | 
| 22362 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 107 | |
| 23491 | 108 | (* collecting cterms *) | 
| 109 | ||
| 110 | val op aconvc = op aconv o pairself Thm.term_of; | |
| 111 | ||
| 112 | fun add_cterm_frees ct = | |
| 113 | let | |
| 114 | val cert = Thm.cterm_of (Thm.theory_of_cterm ct); | |
| 115 | val t = Thm.term_of ct; | |
| 116 | in Term.fold_aterms (fn v as Free _ => insert (op aconvc) (cert v) | _ => I) t end; | |
| 117 | ||
| 118 | ||
| 22907 | 119 | (* cterm constructors and destructors *) | 
| 120 | ||
| 32198 | 121 | fun all_name (x, t) A = | 
| 122 | let | |
| 123 | val cert = Thm.cterm_of (Thm.theory_of_cterm t); | |
| 124 | val T = #T (Thm.rep_cterm t); | |
| 46497 
89ccf66aa73d
renamed Thm.capply to Thm.apply, and Thm.cabs to Thm.lambda in conformance with similar operations in structure Term and Logic;
 wenzelm parents: 
45382diff
changeset | 125 |   in Thm.apply (cert (Const ("all", (T --> propT) --> propT))) (Thm.lambda_name (x, t) A) end;
 | 
| 32198 | 126 | |
| 127 | fun all t A = all_name ("", t) A;
 | |
| 128 | ||
| 46497 
89ccf66aa73d
renamed Thm.capply to Thm.apply, and Thm.cabs to Thm.lambda in conformance with similar operations in structure Term and Logic;
 wenzelm parents: 
45382diff
changeset | 129 | fun mk_binop c a b = Thm.apply (Thm.apply c a) b; | 
| 22907 | 130 | fun dest_binop ct = (Thm.dest_arg1 ct, Thm.dest_arg ct); | 
| 131 | ||
| 132 | fun dest_implies ct = | |
| 133 | (case Thm.term_of ct of | |
| 134 |     Const ("==>", _) $ _ $ _ => dest_binop ct
 | |
| 135 |   | _ => raise TERM ("dest_implies", [Thm.term_of ct]));
 | |
| 136 | ||
| 137 | fun dest_equals ct = | |
| 138 | (case Thm.term_of ct of | |
| 139 |     Const ("==", _) $ _ $ _ => dest_binop ct
 | |
| 140 |   | _ => raise TERM ("dest_equals", [Thm.term_of ct]));
 | |
| 141 | ||
| 142 | fun dest_equals_lhs ct = | |
| 143 | (case Thm.term_of ct of | |
| 144 |     Const ("==", _) $ _ $ _ => Thm.dest_arg1 ct
 | |
| 145 |   | _ => raise TERM ("dest_equals_lhs", [Thm.term_of ct]));
 | |
| 146 | ||
| 147 | fun dest_equals_rhs ct = | |
| 148 | (case Thm.term_of ct of | |
| 149 |     Const ("==", _) $ _ $ _ => Thm.dest_arg ct
 | |
| 150 |   | _ => raise TERM ("dest_equals_rhs", [Thm.term_of ct]));
 | |
| 151 | ||
| 152 | val lhs_of = dest_equals_lhs o Thm.cprop_of; | |
| 153 | val rhs_of = dest_equals_rhs o Thm.cprop_of; | |
| 154 | ||
| 155 | ||
| 156 | (* thm order: ignores theory context! *) | |
| 22682 | 157 | |
| 22362 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 158 | fun thm_ord (th1, th2) = | 
| 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 159 | let | 
| 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 160 |     val {shyps = shyps1, hyps = hyps1, tpairs = tpairs1, prop = prop1, ...} = Thm.rep_thm th1;
 | 
| 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 161 |     val {shyps = shyps2, hyps = hyps2, tpairs = tpairs2, prop = prop2, ...} = Thm.rep_thm th2;
 | 
| 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 162 | in | 
| 35408 | 163 | (case Term_Ord.fast_term_ord (prop1, prop2) of | 
| 22362 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 164 | EQUAL => | 
| 35408 | 165 | (case list_ord (prod_ord Term_Ord.fast_term_ord Term_Ord.fast_term_ord) (tpairs1, tpairs2) of | 
| 22362 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 166 | EQUAL => | 
| 35408 | 167 | (case list_ord Term_Ord.fast_term_ord (hyps1, hyps2) of | 
| 168 | EQUAL => list_ord Term_Ord.sort_ord (shyps1, shyps2) | |
| 22362 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 169 | | ord => ord) | 
| 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 170 | | ord => ord) | 
| 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 171 | | ord => ord) | 
| 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 172 | end; | 
| 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 173 | |
| 22682 | 174 | |
| 32842 | 175 | (* tables and caches *) | 
| 176 | ||
| 35408 | 177 | structure Ctermtab = Table(type key = cterm val ord = Term_Ord.fast_term_ord o pairself Thm.term_of); | 
| 32842 | 178 | structure Thmtab = Table(type key = thm val ord = thm_ord); | 
| 179 | ||
| 180 | fun cterm_cache f = Cache.create Ctermtab.empty Ctermtab.lookup Ctermtab.update f; | |
| 181 | fun thm_cache f = Cache.create Thmtab.empty Thmtab.lookup Thmtab.update f; | |
| 182 | ||
| 183 | ||
| 22682 | 184 | (* equality *) | 
| 185 | ||
| 23599 | 186 | fun is_reflexive th = op aconv (Logic.dest_equals (Thm.prop_of th)) | 
| 187 | handle TERM _ => false; | |
| 188 | ||
| 22362 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 189 | fun eq_thm ths = | 
| 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 190 | Context.joinable (pairself Thm.theory_of_thm ths) andalso | 
| 26653 | 191 | is_equal (thm_ord ths); | 
| 22362 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 192 | |
| 26665 | 193 | val eq_thm_thy = Theory.eq_thy o pairself Thm.theory_of_thm; | 
| 22362 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 194 | val eq_thm_prop = op aconv o pairself Thm.full_prop_of; | 
| 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 195 | |
| 52683 
fb028440473e
more official Thm.eq_thm_strict, without demanding ML equality type;
 wenzelm parents: 
51316diff
changeset | 196 | fun eq_thm_strict ths = | 
| 
fb028440473e
more official Thm.eq_thm_strict, without demanding ML equality type;
 wenzelm parents: 
51316diff
changeset | 197 | eq_thm_thy ths andalso eq_thm ths andalso | 
| 
fb028440473e
more official Thm.eq_thm_strict, without demanding ML equality type;
 wenzelm parents: 
51316diff
changeset | 198 | let val (rep1, rep2) = pairself Thm.rep_thm ths | 
| 
fb028440473e
more official Thm.eq_thm_strict, without demanding ML equality type;
 wenzelm parents: 
51316diff
changeset | 199 | in #maxidx rep1 = #maxidx rep2 andalso #tags rep1 = #tags rep2 end; | 
| 
fb028440473e
more official Thm.eq_thm_strict, without demanding ML equality type;
 wenzelm parents: 
51316diff
changeset | 200 | |
| 22682 | 201 | |
| 202 | (* pattern equivalence *) | |
| 203 | ||
| 22362 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 204 | fun equiv_thm ths = | 
| 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 205 | Pattern.equiv (Theory.merge (pairself Thm.theory_of_thm ths)) (pairself Thm.full_prop_of ths); | 
| 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 206 | |
| 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 207 | |
| 31904 
a86896359ca4
renamed Drule.sort_triv to Thm.sort_triv (cf. more_thm.ML);
 wenzelm parents: 
31177diff
changeset | 208 | (* type classes and sorts *) | 
| 
a86896359ca4
renamed Drule.sort_triv to Thm.sort_triv (cf. more_thm.ML);
 wenzelm parents: 
31177diff
changeset | 209 | |
| 31944 | 210 | fun class_triv thy c = | 
| 211 | Thm.of_class (Thm.ctyp_of thy (TVar ((Name.aT, 0), [c])), c); | |
| 212 | ||
| 213 | fun of_sort (T, S) = map (fn c => Thm.of_class (T, c)) S; | |
| 28621 
a60164e8fff0
added check_shyps, which reject pending sort hypotheses;
 wenzelm parents: 
28116diff
changeset | 214 | |
| 
a60164e8fff0
added check_shyps, which reject pending sort hypotheses;
 wenzelm parents: 
28116diff
changeset | 215 | fun check_shyps sorts raw_th = | 
| 
a60164e8fff0
added check_shyps, which reject pending sort hypotheses;
 wenzelm parents: 
28116diff
changeset | 216 | let | 
| 
a60164e8fff0
added check_shyps, which reject pending sort hypotheses;
 wenzelm parents: 
28116diff
changeset | 217 | val th = Thm.strip_shyps raw_th; | 
| 
a60164e8fff0
added check_shyps, which reject pending sort hypotheses;
 wenzelm parents: 
28116diff
changeset | 218 | val prt_sort = Syntax.pretty_sort_global (Thm.theory_of_thm th); | 
| 
a60164e8fff0
added check_shyps, which reject pending sort hypotheses;
 wenzelm parents: 
28116diff
changeset | 219 | val pending = Sorts.subtract sorts (Thm.extra_shyps th); | 
| 
a60164e8fff0
added check_shyps, which reject pending sort hypotheses;
 wenzelm parents: 
28116diff
changeset | 220 | in | 
| 
a60164e8fff0
added check_shyps, which reject pending sort hypotheses;
 wenzelm parents: 
28116diff
changeset | 221 | if null pending then th | 
| 
a60164e8fff0
added check_shyps, which reject pending sort hypotheses;
 wenzelm parents: 
28116diff
changeset | 222 | else error (Pretty.string_of (Pretty.block (Pretty.str "Pending sort hypotheses:" :: | 
| 
a60164e8fff0
added check_shyps, which reject pending sort hypotheses;
 wenzelm parents: 
28116diff
changeset | 223 | Pretty.brk 1 :: Pretty.commas (map prt_sort pending)))) | 
| 
a60164e8fff0
added check_shyps, which reject pending sort hypotheses;
 wenzelm parents: 
28116diff
changeset | 224 | end; | 
| 
a60164e8fff0
added check_shyps, which reject pending sort hypotheses;
 wenzelm parents: 
28116diff
changeset | 225 | |
| 
a60164e8fff0
added check_shyps, which reject pending sort hypotheses;
 wenzelm parents: 
28116diff
changeset | 226 | |
| 22695 
17073e9b94f2
moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
 wenzelm parents: 
22682diff
changeset | 227 | (* misc operations *) | 
| 
17073e9b94f2
moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
 wenzelm parents: 
22682diff
changeset | 228 | |
| 24048 
a12b4faff474
moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
 wenzelm parents: 
23599diff
changeset | 229 | fun is_dummy thm = | 
| 
a12b4faff474
moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
 wenzelm parents: 
23599diff
changeset | 230 | (case try Logic.dest_term (Thm.concl_of thm) of | 
| 
a12b4faff474
moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
 wenzelm parents: 
23599diff
changeset | 231 | NONE => false | 
| 
a12b4faff474
moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
 wenzelm parents: 
23599diff
changeset | 232 | | SOME t => Term.is_dummy_pattern t); | 
| 
a12b4faff474
moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
 wenzelm parents: 
23599diff
changeset | 233 | |
| 22695 
17073e9b94f2
moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
 wenzelm parents: 
22682diff
changeset | 234 | fun plain_prop_of raw_thm = | 
| 
17073e9b94f2
moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
 wenzelm parents: 
22682diff
changeset | 235 | let | 
| 
17073e9b94f2
moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
 wenzelm parents: 
22682diff
changeset | 236 | val thm = Thm.strip_shyps raw_thm; | 
| 
17073e9b94f2
moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
 wenzelm parents: 
22682diff
changeset | 237 |     fun err msg = raise THM ("plain_prop_of: " ^ msg, 0, [thm]);
 | 
| 
17073e9b94f2
moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
 wenzelm parents: 
22682diff
changeset | 238 |     val {hyps, prop, tpairs, ...} = Thm.rep_thm thm;
 | 
| 
17073e9b94f2
moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
 wenzelm parents: 
22682diff
changeset | 239 | in | 
| 
17073e9b94f2
moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
 wenzelm parents: 
22682diff
changeset | 240 | if not (null hyps) then | 
| 
17073e9b94f2
moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
 wenzelm parents: 
22682diff
changeset | 241 | err "theorem may not contain hypotheses" | 
| 
17073e9b94f2
moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
 wenzelm parents: 
22682diff
changeset | 242 | else if not (null (Thm.extra_shyps thm)) then | 
| 
17073e9b94f2
moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
 wenzelm parents: 
22682diff
changeset | 243 | err "theorem may not contain sort hypotheses" | 
| 
17073e9b94f2
moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
 wenzelm parents: 
22682diff
changeset | 244 | else if not (null tpairs) then | 
| 
17073e9b94f2
moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
 wenzelm parents: 
22682diff
changeset | 245 | err "theorem may not contain flex-flex pairs" | 
| 
17073e9b94f2
moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
 wenzelm parents: 
22682diff
changeset | 246 | else prop | 
| 
17073e9b94f2
moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
 wenzelm parents: 
22682diff
changeset | 247 | end; | 
| 
17073e9b94f2
moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
 wenzelm parents: 
22682diff
changeset | 248 | |
| 
17073e9b94f2
moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
 wenzelm parents: 
22682diff
changeset | 249 | |
| 30564 | 250 | (* collections of theorems in canonical order *) | 
| 24048 
a12b4faff474
moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
 wenzelm parents: 
23599diff
changeset | 251 | |
| 
a12b4faff474
moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
 wenzelm parents: 
23599diff
changeset | 252 | val add_thm = update eq_thm_prop; | 
| 
a12b4faff474
moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
 wenzelm parents: 
23599diff
changeset | 253 | val del_thm = remove eq_thm_prop; | 
| 
a12b4faff474
moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
 wenzelm parents: 
23599diff
changeset | 254 | val merge_thms = merge eq_thm_prop; | 
| 
a12b4faff474
moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
 wenzelm parents: 
23599diff
changeset | 255 | |
| 33453 | 256 | val full_rules = Item_Net.init eq_thm_prop (single o Thm.full_prop_of); | 
| 33373 | 257 | val intro_rules = Item_Net.init eq_thm_prop (single o Thm.concl_of); | 
| 258 | val elim_rules = Item_Net.init eq_thm_prop (single o Thm.major_prem_of); | |
| 30560 | 259 | |
| 260 | ||
| 22682 | 261 | |
| 24980 
16a74cfca971
added elim_implies (more convenient argument order);
 wenzelm parents: 
24948diff
changeset | 262 | (** basic derived rules **) | 
| 
16a74cfca971
added elim_implies (more convenient argument order);
 wenzelm parents: 
24948diff
changeset | 263 | |
| 
16a74cfca971
added elim_implies (more convenient argument order);
 wenzelm parents: 
24948diff
changeset | 264 | (*Elimination of implication | 
| 
16a74cfca971
added elim_implies (more convenient argument order);
 wenzelm parents: 
24948diff
changeset | 265 | A A ==> B | 
| 
16a74cfca971
added elim_implies (more convenient argument order);
 wenzelm parents: 
24948diff
changeset | 266 | ------------ | 
| 
16a74cfca971
added elim_implies (more convenient argument order);
 wenzelm parents: 
24948diff
changeset | 267 | B | 
| 
16a74cfca971
added elim_implies (more convenient argument order);
 wenzelm parents: 
24948diff
changeset | 268 | *) | 
| 
16a74cfca971
added elim_implies (more convenient argument order);
 wenzelm parents: 
24948diff
changeset | 269 | fun elim_implies thA thAB = Thm.implies_elim thAB thA; | 
| 
16a74cfca971
added elim_implies (more convenient argument order);
 wenzelm parents: 
24948diff
changeset | 270 | |
| 26653 | 271 | |
| 272 | (* forall_elim_var(s) *) | |
| 273 | ||
| 274 | local | |
| 275 | ||
| 276 | fun forall_elim_vars_aux strip_vars i th = | |
| 277 | let | |
| 278 | val thy = Thm.theory_of_thm th; | |
| 279 |     val {tpairs, prop, ...} = Thm.rep_thm th;
 | |
| 280 | val add_used = Term.fold_aterms | |
| 281 | (fn Var ((x, j), _) => if i = j then insert (op =) x else I | _ => I); | |
| 282 | val used = fold (fn (t, u) => add_used t o add_used u) tpairs (add_used prop []); | |
| 283 | val vars = strip_vars prop; | |
| 284 | val cvars = (Name.variant_list used (map #1 vars), vars) | |
| 285 | |> ListPair.map (fn (x, (_, T)) => Thm.cterm_of thy (Var ((x, i), T))); | |
| 286 | in fold Thm.forall_elim cvars th end; | |
| 287 | ||
| 288 | in | |
| 289 | ||
| 290 | val forall_elim_vars = forall_elim_vars_aux Term.strip_all_vars; | |
| 291 | ||
| 33697 | 292 | fun forall_elim_var i th = | 
| 293 | forall_elim_vars_aux | |
| 294 |     (fn Const ("all", _) $ Abs (a, T, _) => [(a, T)]
 | |
| 295 |       | _ => raise THM ("forall_elim_vars", i, [th])) i th;
 | |
| 26653 | 296 | |
| 297 | end; | |
| 298 | ||
| 299 | ||
| 32279 | 300 | (* certify_instantiate *) | 
| 301 | ||
| 302 | fun certify_inst thy (instT, inst) = | |
| 303 | (map (fn (v, T) => (Thm.ctyp_of thy (TVar v), Thm.ctyp_of thy T)) instT, | |
| 304 | map (fn (v, t) => (Thm.cterm_of thy (Var v), Thm.cterm_of thy t)) inst); | |
| 305 | ||
| 306 | fun certify_instantiate insts th = | |
| 307 | Thm.instantiate (certify_inst (Thm.theory_of_thm th) insts) th; | |
| 308 | ||
| 309 | ||
| 35985 
0bbf0d2348f9
moved Drule.forall_intr_frees to Thm.forall_intr_frees (in more_thm.ML, which is loaded before pure_thy.ML);
 wenzelm parents: 
35857diff
changeset | 310 | (* forall_intr_frees: generalization over all suitable Free variables *) | 
| 
0bbf0d2348f9
moved Drule.forall_intr_frees to Thm.forall_intr_frees (in more_thm.ML, which is loaded before pure_thy.ML);
 wenzelm parents: 
35857diff
changeset | 311 | |
| 
0bbf0d2348f9
moved Drule.forall_intr_frees to Thm.forall_intr_frees (in more_thm.ML, which is loaded before pure_thy.ML);
 wenzelm parents: 
35857diff
changeset | 312 | fun forall_intr_frees th = | 
| 
0bbf0d2348f9
moved Drule.forall_intr_frees to Thm.forall_intr_frees (in more_thm.ML, which is loaded before pure_thy.ML);
 wenzelm parents: 
35857diff
changeset | 313 | let | 
| 
0bbf0d2348f9
moved Drule.forall_intr_frees to Thm.forall_intr_frees (in more_thm.ML, which is loaded before pure_thy.ML);
 wenzelm parents: 
35857diff
changeset | 314 | val thy = Thm.theory_of_thm th; | 
| 
0bbf0d2348f9
moved Drule.forall_intr_frees to Thm.forall_intr_frees (in more_thm.ML, which is loaded before pure_thy.ML);
 wenzelm parents: 
35857diff
changeset | 315 |     val {prop, hyps, tpairs, ...} = Thm.rep_thm th;
 | 
| 
0bbf0d2348f9
moved Drule.forall_intr_frees to Thm.forall_intr_frees (in more_thm.ML, which is loaded before pure_thy.ML);
 wenzelm parents: 
35857diff
changeset | 316 | val fixed = fold Term.add_frees (Thm.terms_of_tpairs tpairs @ hyps) []; | 
| 
0bbf0d2348f9
moved Drule.forall_intr_frees to Thm.forall_intr_frees (in more_thm.ML, which is loaded before pure_thy.ML);
 wenzelm parents: 
35857diff
changeset | 317 | val frees = Term.fold_aterms (fn Free v => | 
| 
0bbf0d2348f9
moved Drule.forall_intr_frees to Thm.forall_intr_frees (in more_thm.ML, which is loaded before pure_thy.ML);
 wenzelm parents: 
35857diff
changeset | 318 | if member (op =) fixed v then I else insert (op =) v | _ => I) prop []; | 
| 
0bbf0d2348f9
moved Drule.forall_intr_frees to Thm.forall_intr_frees (in more_thm.ML, which is loaded before pure_thy.ML);
 wenzelm parents: 
35857diff
changeset | 319 | in fold (Thm.forall_intr o Thm.cterm_of thy o Free) frees th end; | 
| 
0bbf0d2348f9
moved Drule.forall_intr_frees to Thm.forall_intr_frees (in more_thm.ML, which is loaded before pure_thy.ML);
 wenzelm parents: 
35857diff
changeset | 320 | |
| 
0bbf0d2348f9
moved Drule.forall_intr_frees to Thm.forall_intr_frees (in more_thm.ML, which is loaded before pure_thy.ML);
 wenzelm parents: 
35857diff
changeset | 321 | |
| 35845 
e5980f0ad025
renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
 wenzelm parents: 
35715diff
changeset | 322 | (* unvarify_global: global schematic variables *) | 
| 26653 | 323 | |
| 35845 
e5980f0ad025
renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
 wenzelm parents: 
35715diff
changeset | 324 | fun unvarify_global th = | 
| 24980 
16a74cfca971
added elim_implies (more convenient argument order);
 wenzelm parents: 
24948diff
changeset | 325 | let | 
| 
16a74cfca971
added elim_implies (more convenient argument order);
 wenzelm parents: 
24948diff
changeset | 326 | val prop = Thm.full_prop_of th; | 
| 35845 
e5980f0ad025
renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
 wenzelm parents: 
35715diff
changeset | 327 | val _ = map Logic.unvarify_global (prop :: Thm.hyps_of th) | 
| 24980 
16a74cfca971
added elim_implies (more convenient argument order);
 wenzelm parents: 
24948diff
changeset | 328 | handle TERM (msg, _) => raise THM (msg, 0, [th]); | 
| 
16a74cfca971
added elim_implies (more convenient argument order);
 wenzelm parents: 
24948diff
changeset | 329 | |
| 32279 | 330 | val instT = rev (Term.add_tvars prop []) |> map (fn v as ((a, _), S) => (v, TFree (a, S))); | 
| 24980 
16a74cfca971
added elim_implies (more convenient argument order);
 wenzelm parents: 
24948diff
changeset | 331 | val inst = rev (Term.add_vars prop []) |> map (fn ((a, i), T) => | 
| 32279 | 332 | let val T' = Term_Subst.instantiateT instT T | 
| 333 | in (((a, i), T'), Free ((a, T'))) end); | |
| 334 | in certify_instantiate (instT, inst) th end; | |
| 24980 
16a74cfca971
added elim_implies (more convenient argument order);
 wenzelm parents: 
24948diff
changeset | 335 | |
| 26653 | 336 | |
| 337 | (* close_derivation *) | |
| 338 | ||
| 26628 
63306cb94313
replaced Drule.close_derivation/Goal.close_result by Thm.close_derivation (removed obsolete compression);
 wenzelm parents: 
25518diff
changeset | 339 | fun close_derivation thm = | 
| 36744 
6e1f3d609a68
renamed Thm.get_name -> Thm.derivation_name and Thm.put_name -> Thm.name_derivation, to emphasize the true nature of these operations;
 wenzelm parents: 
36106diff
changeset | 340 | if Thm.derivation_name thm = "" then Thm.name_derivation "" thm | 
| 26628 
63306cb94313
replaced Drule.close_derivation/Goal.close_result by Thm.close_derivation (removed obsolete compression);
 wenzelm parents: 
25518diff
changeset | 341 | else thm; | 
| 
63306cb94313
replaced Drule.close_derivation/Goal.close_result by Thm.close_derivation (removed obsolete compression);
 wenzelm parents: 
25518diff
changeset | 342 | |
| 24980 
16a74cfca971
added elim_implies (more convenient argument order);
 wenzelm parents: 
24948diff
changeset | 343 | |
| 
16a74cfca971
added elim_implies (more convenient argument order);
 wenzelm parents: 
24948diff
changeset | 344 | |
| 
16a74cfca971
added elim_implies (more convenient argument order);
 wenzelm parents: 
24948diff
changeset | 345 | (** specification primitives **) | 
| 
16a74cfca971
added elim_implies (more convenient argument order);
 wenzelm parents: 
24948diff
changeset | 346 | |
| 30342 | 347 | (* rules *) | 
| 348 | ||
| 35855 
e7d004b89ca8
add_axiom: axiomatize "unconstrained" version, with explicit of_class premises;
 wenzelm parents: 
35853diff
changeset | 349 | fun stripped_sorts thy t = | 
| 
e7d004b89ca8
add_axiom: axiomatize "unconstrained" version, with explicit of_class premises;
 wenzelm parents: 
35853diff
changeset | 350 | let | 
| 
e7d004b89ca8
add_axiom: axiomatize "unconstrained" version, with explicit of_class premises;
 wenzelm parents: 
35853diff
changeset | 351 | val tfrees = rev (map TFree (Term.add_tfrees t [])); | 
| 43329 
84472e198515
tuned signature: Name.invent and Name.invent_names;
 wenzelm parents: 
42473diff
changeset | 352 | val tfrees' = map (fn a => TFree (a, [])) (Name.invent Name.context Name.aT (length tfrees)); | 
| 35855 
e7d004b89ca8
add_axiom: axiomatize "unconstrained" version, with explicit of_class premises;
 wenzelm parents: 
35853diff
changeset | 353 | val strip = tfrees ~~ tfrees'; | 
| 
e7d004b89ca8
add_axiom: axiomatize "unconstrained" version, with explicit of_class premises;
 wenzelm parents: 
35853diff
changeset | 354 | val recover = map (pairself (Thm.ctyp_of thy o Logic.varifyT_global) o swap) strip; | 
| 
e7d004b89ca8
add_axiom: axiomatize "unconstrained" version, with explicit of_class premises;
 wenzelm parents: 
35853diff
changeset | 355 | val t' = Term.map_types (Term.map_atyps (perhaps (AList.lookup (op =) strip))) t; | 
| 
e7d004b89ca8
add_axiom: axiomatize "unconstrained" version, with explicit of_class premises;
 wenzelm parents: 
35853diff
changeset | 356 | in (strip, recover, t') end; | 
| 
e7d004b89ca8
add_axiom: axiomatize "unconstrained" version, with explicit of_class premises;
 wenzelm parents: 
35853diff
changeset | 357 | |
| 42375 
774df7c59508
report Name_Space.declare/define, relatively to context;
 wenzelm parents: 
40238diff
changeset | 358 | fun add_axiom ctxt (b, prop) thy = | 
| 24980 
16a74cfca971
added elim_implies (more convenient argument order);
 wenzelm parents: 
24948diff
changeset | 359 | let | 
| 42375 
774df7c59508
report Name_Space.declare/define, relatively to context;
 wenzelm parents: 
40238diff
changeset | 360 | val _ = Sign.no_vars ctxt prop; | 
| 35855 
e7d004b89ca8
add_axiom: axiomatize "unconstrained" version, with explicit of_class premises;
 wenzelm parents: 
35853diff
changeset | 361 | val (strip, recover, prop') = stripped_sorts thy prop; | 
| 
e7d004b89ca8
add_axiom: axiomatize "unconstrained" version, with explicit of_class premises;
 wenzelm parents: 
35853diff
changeset | 362 | val constraints = map (fn (TFree (_, S), T) => (T, S)) strip; | 
| 
e7d004b89ca8
add_axiom: axiomatize "unconstrained" version, with explicit of_class premises;
 wenzelm parents: 
35853diff
changeset | 363 | val of_sorts = maps (fn (T as TFree (_, S), _) => of_sort (Thm.ctyp_of thy T, S)) strip; | 
| 36106 
19deea200358
Thm.add_axiom/add_def: return internal name of foundational axiom;
 wenzelm parents: 
35988diff
changeset | 364 | |
| 42375 
774df7c59508
report Name_Space.declare/define, relatively to context;
 wenzelm parents: 
40238diff
changeset | 365 | val thy' = thy | 
| 51316 
dfe469293eb4
discontinued empty name bindings in 'axiomatization';
 wenzelm parents: 
49062diff
changeset | 366 | |> Theory.add_axiom ctxt (b, Logic.list_implies (maps Logic.mk_of_sort constraints, prop')); | 
| 
dfe469293eb4
discontinued empty name bindings in 'axiomatization';
 wenzelm parents: 
49062diff
changeset | 367 | val axm_name = Sign.full_name thy' b; | 
| 36106 
19deea200358
Thm.add_axiom/add_def: return internal name of foundational axiom;
 wenzelm parents: 
35988diff
changeset | 368 | val axm' = Thm.axiom thy' axm_name; | 
| 35988 
76ca601c941e
disallow premises in primitive Theory.add_def -- handle in Thm.add_def;
 wenzelm parents: 
35985diff
changeset | 369 | val thm = | 
| 
76ca601c941e
disallow premises in primitive Theory.add_def -- handle in Thm.add_def;
 wenzelm parents: 
35985diff
changeset | 370 | Thm.instantiate (recover, []) axm' | 
| 
76ca601c941e
disallow premises in primitive Theory.add_def -- handle in Thm.add_def;
 wenzelm parents: 
35985diff
changeset | 371 | |> unvarify_global | 
| 
76ca601c941e
disallow premises in primitive Theory.add_def -- handle in Thm.add_def;
 wenzelm parents: 
35985diff
changeset | 372 | |> fold elim_implies of_sorts; | 
| 36106 
19deea200358
Thm.add_axiom/add_def: return internal name of foundational axiom;
 wenzelm parents: 
35988diff
changeset | 373 | in ((axm_name, thm), thy') end; | 
| 24980 
16a74cfca971
added elim_implies (more convenient argument order);
 wenzelm parents: 
24948diff
changeset | 374 | |
| 42375 
774df7c59508
report Name_Space.declare/define, relatively to context;
 wenzelm parents: 
40238diff
changeset | 375 | fun add_axiom_global arg thy = add_axiom (Syntax.init_pretty_global thy) arg thy; | 
| 
774df7c59508
report Name_Space.declare/define, relatively to context;
 wenzelm parents: 
40238diff
changeset | 376 | |
| 
774df7c59508
report Name_Space.declare/define, relatively to context;
 wenzelm parents: 
40238diff
changeset | 377 | fun add_def ctxt unchecked overloaded (b, prop) thy = | 
| 24980 
16a74cfca971
added elim_implies (more convenient argument order);
 wenzelm parents: 
24948diff
changeset | 378 | let | 
| 42375 
774df7c59508
report Name_Space.declare/define, relatively to context;
 wenzelm parents: 
40238diff
changeset | 379 | val _ = Sign.no_vars ctxt prop; | 
| 35988 
76ca601c941e
disallow premises in primitive Theory.add_def -- handle in Thm.add_def;
 wenzelm parents: 
35985diff
changeset | 380 | val prems = map (Thm.cterm_of thy) (Logic.strip_imp_prems prop); | 
| 
76ca601c941e
disallow premises in primitive Theory.add_def -- handle in Thm.add_def;
 wenzelm parents: 
35985diff
changeset | 381 | val (_, recover, concl') = stripped_sorts thy (Logic.strip_imp_concl prop); | 
| 36106 
19deea200358
Thm.add_axiom/add_def: return internal name of foundational axiom;
 wenzelm parents: 
35988diff
changeset | 382 | |
| 42375 
774df7c59508
report Name_Space.declare/define, relatively to context;
 wenzelm parents: 
40238diff
changeset | 383 | val thy' = Theory.add_def ctxt unchecked overloaded (b, concl') thy; | 
| 36106 
19deea200358
Thm.add_axiom/add_def: return internal name of foundational axiom;
 wenzelm parents: 
35988diff
changeset | 384 | val axm_name = Sign.full_name thy' b; | 
| 
19deea200358
Thm.add_axiom/add_def: return internal name of foundational axiom;
 wenzelm parents: 
35988diff
changeset | 385 | val axm' = Thm.axiom thy' axm_name; | 
| 35988 
76ca601c941e
disallow premises in primitive Theory.add_def -- handle in Thm.add_def;
 wenzelm parents: 
35985diff
changeset | 386 | val thm = | 
| 
76ca601c941e
disallow premises in primitive Theory.add_def -- handle in Thm.add_def;
 wenzelm parents: 
35985diff
changeset | 387 | Thm.instantiate (recover, []) axm' | 
| 
76ca601c941e
disallow premises in primitive Theory.add_def -- handle in Thm.add_def;
 wenzelm parents: 
35985diff
changeset | 388 | |> unvarify_global | 
| 
76ca601c941e
disallow premises in primitive Theory.add_def -- handle in Thm.add_def;
 wenzelm parents: 
35985diff
changeset | 389 | |> fold_rev Thm.implies_intr prems; | 
| 36106 
19deea200358
Thm.add_axiom/add_def: return internal name of foundational axiom;
 wenzelm parents: 
35988diff
changeset | 390 | in ((axm_name, thm), thy') end; | 
| 24980 
16a74cfca971
added elim_implies (more convenient argument order);
 wenzelm parents: 
24948diff
changeset | 391 | |
| 42375 
774df7c59508
report Name_Space.declare/define, relatively to context;
 wenzelm parents: 
40238diff
changeset | 392 | fun add_def_global unchecked overloaded arg thy = | 
| 
774df7c59508
report Name_Space.declare/define, relatively to context;
 wenzelm parents: 
40238diff
changeset | 393 | add_def (Syntax.init_pretty_global thy) unchecked overloaded arg thy; | 
| 
774df7c59508
report Name_Space.declare/define, relatively to context;
 wenzelm parents: 
40238diff
changeset | 394 | |
| 27866 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 395 | |
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 396 | |
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 397 | (** attributes **) | 
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 398 | |
| 40238 
edcdecd55655
type attribute is derived concept outside the kernel;
 wenzelm parents: 
39133diff
changeset | 399 | (*attributes subsume any kind of rules or context modifiers*) | 
| 45375 
7fe19930dfc9
more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
 wenzelm parents: 
43780diff
changeset | 400 | type attribute = Context.generic * thm -> Context.generic option * thm option; | 
| 40238 
edcdecd55655
type attribute is derived concept outside the kernel;
 wenzelm parents: 
39133diff
changeset | 401 | |
| 30210 | 402 | type binding = binding * attribute list; | 
| 403 | val empty_binding: binding = (Binding.empty, []); | |
| 404 | ||
| 45375 
7fe19930dfc9
more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
 wenzelm parents: 
43780diff
changeset | 405 | fun rule_attribute f (x, th) = (NONE, SOME (f x th)); | 
| 
7fe19930dfc9
more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
 wenzelm parents: 
43780diff
changeset | 406 | fun declaration_attribute f (x, th) = (SOME (f th x), NONE); | 
| 
7fe19930dfc9
more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
 wenzelm parents: 
43780diff
changeset | 407 | fun mixed_attribute f (x, th) = let val (x', th') = f (x, th) in (SOME x', SOME th') end; | 
| 
7fe19930dfc9
more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
 wenzelm parents: 
43780diff
changeset | 408 | |
| 46775 
6287653e63ec
canonical argument order for attribute application;
 wenzelm parents: 
46497diff
changeset | 409 | fun apply_attribute (att: attribute) th x = | 
| 53206 
5d2fe75c6306
always transfer thm where attributes are applied -- relevant for internal 'notes' (e.g. via bundle 'includes') in contrast to external 'notes' (cf. Proof_Context.retrieve_thms);
 wenzelm parents: 
52683diff
changeset | 410 | let val (x', th') = att (x, Thm.transfer (Context.theory_of x) th) | 
| 46775 
6287653e63ec
canonical argument order for attribute application;
 wenzelm parents: 
46497diff
changeset | 411 | in (the_default th th', the_default x x') end; | 
| 45375 
7fe19930dfc9
more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
 wenzelm parents: 
43780diff
changeset | 412 | |
| 46775 
6287653e63ec
canonical argument order for attribute application;
 wenzelm parents: 
46497diff
changeset | 413 | fun attribute_declaration att th x = #2 (apply_attribute att th x); | 
| 27866 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 414 | |
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 415 | fun apply_attributes mk dest = | 
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 416 | let | 
| 46775 
6287653e63ec
canonical argument order for attribute application;
 wenzelm parents: 
46497diff
changeset | 417 | fun app [] th x = (th, x) | 
| 
6287653e63ec
canonical argument order for attribute application;
 wenzelm parents: 
46497diff
changeset | 418 | | app (att :: atts) th x = apply_attribute att th (mk x) ||> dest |-> app atts; | 
| 27866 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 419 | in app end; | 
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 420 | |
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 421 | val theory_attributes = apply_attributes Context.Theory Context.the_theory; | 
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 422 | val proof_attributes = apply_attributes Context.Proof Context.the_proof; | 
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 423 | |
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 424 | fun no_attributes x = (x, []); | 
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 425 | fun simple_fact x = [(x, [])]; | 
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 426 | |
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 427 | |
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 428 | |
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 429 | (*** theorem tags ***) | 
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 430 | |
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 431 | (* add / delete tags *) | 
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 432 | |
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 433 | fun tag_rule tg = Thm.map_tags (insert (op =) tg); | 
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 434 | fun untag_rule s = Thm.map_tags (filter_out (fn (s', _) => s = s')); | 
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 435 | |
| 45375 
7fe19930dfc9
more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
 wenzelm parents: 
43780diff
changeset | 436 | fun tag tg = rule_attribute (K (tag_rule tg)); | 
| 
7fe19930dfc9
more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
 wenzelm parents: 
43780diff
changeset | 437 | fun untag s = rule_attribute (K (untag_rule s)); | 
| 27866 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 438 | |
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 439 | |
| 30342 | 440 | (* def_name *) | 
| 441 | ||
| 442 | fun def_name c = c ^ "_def"; | |
| 443 | ||
| 444 | fun def_name_optional c "" = def_name c | |
| 445 | | def_name_optional _ name = name; | |
| 446 | ||
| 35238 | 447 | val def_binding = Binding.map_name def_name; | 
| 448 | ||
| 30433 
ce5138c92ca7
added def_binding_optional -- robust version of def_name_optional for bindings;
 wenzelm parents: 
30342diff
changeset | 449 | fun def_binding_optional b name = | 
| 35238 | 450 | if Binding.is_empty name then def_binding b else name; | 
| 30433 
ce5138c92ca7
added def_binding_optional -- robust version of def_name_optional for bindings;
 wenzelm parents: 
30342diff
changeset | 451 | |
| 30342 | 452 | |
| 27866 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 453 | (* unofficial theorem names *) | 
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 454 | |
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 455 | fun the_name_hint thm = the (AList.lookup (op =) (Thm.get_tags thm) Markup.nameN); | 
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 456 | |
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 457 | val has_name_hint = can the_name_hint; | 
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 458 | val get_name_hint = the_default "??.unknown" o try the_name_hint; | 
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 459 | |
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 460 | fun put_name_hint name = untag_rule Markup.nameN #> tag_rule (Markup.nameN, name); | 
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 461 | |
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 462 | |
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 463 | (* theorem kinds *) | 
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 464 | |
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 465 | val theoremK = "theorem"; | 
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 466 | val lemmaK = "lemma"; | 
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 467 | val corollaryK = "corollary"; | 
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 468 | |
| 42473 | 469 | fun legacy_get_kind thm = the_default "" (Properties.get (Thm.get_tags thm) Markup.kindN); | 
| 27866 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 470 | |
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 471 | fun kind_rule k = tag_rule (Markup.kindN, k) o untag_rule Markup.kindN; | 
| 45375 
7fe19930dfc9
more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
 wenzelm parents: 
43780diff
changeset | 472 | fun kind k = rule_attribute (K (k <> "" ? kind_rule k)); | 
| 27866 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 473 | |
| 
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
 wenzelm parents: 
27255diff
changeset | 474 | |
| 49011 
9c68e43502ce
some support for registering forked proofs within Proof.state, using its bottom context;
 wenzelm parents: 
49010diff
changeset | 475 | (* forked proofs *) | 
| 49010 | 476 | |
| 49062 
7e31dfd99ce7
discontinued complicated/unreliable notion of recent proofs within context;
 wenzelm parents: 
49058diff
changeset | 477 | structure Proofs = Theory_Data | 
| 49010 | 478 | ( | 
| 49062 
7e31dfd99ce7
discontinued complicated/unreliable notion of recent proofs within context;
 wenzelm parents: 
49058diff
changeset | 479 | type T = thm list; | 
| 
7e31dfd99ce7
discontinued complicated/unreliable notion of recent proofs within context;
 wenzelm parents: 
49058diff
changeset | 480 | val empty = []; | 
| 49010 | 481 | fun extend _ = empty; | 
| 482 | fun merge _ = empty; | |
| 483 | ); | |
| 484 | ||
| 49062 
7e31dfd99ce7
discontinued complicated/unreliable notion of recent proofs within context;
 wenzelm parents: 
49058diff
changeset | 485 | fun register_proofs more_thms = Proofs.map (fn thms => fold cons more_thms thms); | 
| 
7e31dfd99ce7
discontinued complicated/unreliable notion of recent proofs within context;
 wenzelm parents: 
49058diff
changeset | 486 | val join_theory_proofs = Thm.join_proofs o rev o Proofs.get; | 
| 49010 | 487 | |
| 488 | ||
| 22362 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 489 | open Thm; | 
| 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 490 | |
| 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 491 | end; | 
| 
6470ce514b6e
Further operations on type thm, outside the inference kernel.
 wenzelm parents: diff
changeset | 492 | |
| 32842 | 493 | structure Basic_Thm: BASIC_THM = Thm; | 
| 494 | open Basic_Thm; | |
| 23170 | 495 |