author | wenzelm |
Mon, 06 Sep 2021 14:05:22 +0200 | |
changeset 74249 | 9d9e7ed01dbb |
parent 74247 | a88fda85bd25 |
child 74265 | 633fe7390c97 |
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 |
|
61268 | 12 |
val show_consts: bool Config.T |
13 |
val show_hyps: bool Config.T |
|
14 |
val show_tags: bool Config.T |
|
32842 | 15 |
structure Ctermtab: TABLE |
16 |
structure Thmtab: TABLE |
|
17 |
val aconvc: cterm * cterm -> bool |
|
45375
7fe19930dfc9
more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
wenzelm
parents:
43780
diff
changeset
|
18 |
type attribute = Context.generic * thm -> Context.generic option * thm option |
32842 | 19 |
end; |
20 |
||
22362
6470ce514b6e
Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff
changeset
|
21 |
signature THM = |
6470ce514b6e
Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff
changeset
|
22 |
sig |
6470ce514b6e
Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff
changeset
|
23 |
include THM |
32842 | 24 |
structure Ctermtab: TABLE |
25 |
structure Thmtab: TABLE |
|
60952
762cb38a3147
produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents:
60951
diff
changeset
|
26 |
val eq_ctyp: ctyp * ctyp -> bool |
24948 | 27 |
val aconvc: cterm * cterm -> bool |
74243 | 28 |
val add_tvars: thm -> ctyp Term_Subst.TVars.table -> ctyp Term_Subst.TVars.table |
29 |
val add_vars: thm -> cterm Term_Subst.Vars.table -> cterm Term_Subst.Vars.table |
|
70159 | 30 |
val dest_funT: ctyp -> ctyp * ctyp |
70152 | 31 |
val strip_type: ctyp -> ctyp list * ctyp |
60938 | 32 |
val all_name: Proof.context -> string * cterm -> cterm -> cterm |
33 |
val all: Proof.context -> cterm -> cterm -> cterm |
|
22907 | 34 |
val mk_binop: cterm -> cterm -> cterm -> cterm |
35 |
val dest_binop: cterm -> cterm * cterm |
|
36 |
val dest_implies: cterm -> cterm * cterm |
|
37 |
val dest_equals: cterm -> cterm * cterm |
|
38 |
val dest_equals_lhs: cterm -> cterm |
|
39 |
val dest_equals_rhs: cterm -> cterm |
|
40 |
val lhs_of: thm -> cterm |
|
41 |
val rhs_of: thm -> cterm |
|
70586 | 42 |
val fast_term_ord: cterm ord |
43 |
val term_ord: cterm ord |
|
44 |
val thm_ord: thm ord |
|
32842 | 45 |
val cterm_cache: (cterm -> 'a) -> cterm -> 'a |
46 |
val thm_cache: (thm -> 'a) -> thm -> 'a |
|
23599 | 47 |
val is_reflexive: thm -> bool |
22362
6470ce514b6e
Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff
changeset
|
48 |
val eq_thm: thm * thm -> bool |
6470ce514b6e
Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff
changeset
|
49 |
val eq_thm_prop: thm * thm -> bool |
52683
fb028440473e
more official Thm.eq_thm_strict, without demanding ML equality type;
wenzelm
parents:
51316
diff
changeset
|
50 |
val eq_thm_strict: thm * thm -> bool |
60817 | 51 |
val equiv_thm: theory -> thm * thm -> bool |
31944 | 52 |
val class_triv: theory -> class -> thm |
53 |
val of_sort: ctyp * sort -> thm list |
|
24048
a12b4faff474
moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents:
23599
diff
changeset
|
54 |
val is_dummy: thm -> bool |
a12b4faff474
moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents:
23599
diff
changeset
|
55 |
val add_thm: thm -> thm list -> thm list |
a12b4faff474
moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents:
23599
diff
changeset
|
56 |
val del_thm: thm -> thm list -> thm list |
a12b4faff474
moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents:
23599
diff
changeset
|
57 |
val merge_thms: thm list * thm list -> thm list |
74152 | 58 |
val item_net: thm Item_Net.T |
59 |
val item_net_intro: thm Item_Net.T |
|
60 |
val item_net_elim: thm Item_Net.T |
|
54984
da70ab8531f4
more elementary management of declared hyps, below structure Assumption;
wenzelm
parents:
53206
diff
changeset
|
61 |
val declare_hyps: cterm -> Proof.context -> Proof.context |
da70ab8531f4
more elementary management of declared hyps, below structure Assumption;
wenzelm
parents:
53206
diff
changeset
|
62 |
val assume_hyps: cterm -> Proof.context -> thm * Proof.context |
54993
625370769fc0
check_hyps for attribute application (still inactive, due to non-compliant tools);
wenzelm
parents:
54984
diff
changeset
|
63 |
val unchecked_hyps: Proof.context -> Proof.context |
625370769fc0
check_hyps for attribute application (still inactive, due to non-compliant tools);
wenzelm
parents:
54984
diff
changeset
|
64 |
val restore_hyps: Proof.context -> Proof.context -> Proof.context |
55633 | 65 |
val undeclared_hyps: Context.generic -> thm -> term list |
54993
625370769fc0
check_hyps for attribute application (still inactive, due to non-compliant tools);
wenzelm
parents:
54984
diff
changeset
|
66 |
val check_hyps: Context.generic -> thm -> thm |
61508 | 67 |
val declare_term_sorts: term -> Proof.context -> Proof.context |
61509
358dfae15d83
print thm wrt. local shyps (from full proof context);
wenzelm
parents:
61508
diff
changeset
|
68 |
val extra_shyps': Proof.context -> thm -> sort list |
61508 | 69 |
val check_shyps: Proof.context -> thm -> thm |
70 |
val weaken_sorts': Proof.context -> cterm -> cterm |
|
27866
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
wenzelm
parents:
27255
diff
changeset
|
71 |
val elim_implies: thm -> thm -> thm |
61339 | 72 |
val forall_intr_name: string * cterm -> thm -> thm |
27866
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
wenzelm
parents:
27255
diff
changeset
|
73 |
val forall_elim_var: int -> thm -> thm |
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
wenzelm
parents:
27255
diff
changeset
|
74 |
val forall_elim_vars: int -> thm -> thm |
67698
67caf783b9ee
explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents:
67671
diff
changeset
|
75 |
val instantiate_frees: ((string * sort) * ctyp) list * ((string * typ) * cterm) list -> thm -> thm |
60801 | 76 |
val instantiate': ctyp option list -> cterm option 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:
35857
diff
changeset
|
77 |
val forall_intr_frees: thm -> thm |
74245 | 78 |
val forall_intr_vars: thm -> thm |
60825 | 79 |
val unvarify_global: theory -> thm -> thm |
80 |
val unvarify_axiom: theory -> string -> thm |
|
59969
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
81 |
val rename_params_rule: string list * int -> thm -> thm |
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
82 |
val rename_boundvars: term -> term -> thm -> thm |
42375
774df7c59508
report Name_Space.declare/define, relatively to context;
wenzelm
parents:
40238
diff
changeset
|
83 |
val add_axiom: Proof.context -> binding * term -> theory -> (string * thm) * theory |
774df7c59508
report Name_Space.declare/define, relatively to context;
wenzelm
parents:
40238
diff
changeset
|
84 |
val add_axiom_global: binding * term -> theory -> (string * thm) * theory |
61261
ddb2da7cb2e4
more explicit Defs.context: use proper name spaces as far as possible;
wenzelm
parents:
61059
diff
changeset
|
85 |
val add_def: Defs.context -> bool -> bool -> binding * term -> theory -> (string * thm) * theory |
42375
774df7c59508
report Name_Space.declare/define, relatively to context;
wenzelm
parents:
40238
diff
changeset
|
86 |
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:
43780
diff
changeset
|
87 |
type attribute = Context.generic * thm -> Context.generic option * thm option |
30210 | 88 |
type binding = binding * attribute list |
46830 | 89 |
val tag_rule: string * string -> thm -> thm |
27866
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
wenzelm
parents:
27255
diff
changeset
|
90 |
val untag_rule: string -> thm -> thm |
61852 | 91 |
val is_free_dummy: thm -> bool |
92 |
val tag_free_dummy: thm -> thm |
|
30342 | 93 |
val def_name: string -> string |
94 |
val def_name_optional: string -> string -> string |
|
35238 | 95 |
val def_binding: Binding.binding -> Binding.binding |
30433
ce5138c92ca7
added def_binding_optional -- robust version of def_name_optional for bindings;
wenzelm
parents:
30342
diff
changeset
|
96 |
val def_binding_optional: Binding.binding -> Binding.binding -> Binding.binding |
62093 | 97 |
val make_def_binding: bool -> Binding.binding -> Binding.binding |
27866
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
wenzelm
parents:
27255
diff
changeset
|
98 |
val has_name_hint: thm -> bool |
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
wenzelm
parents:
27255
diff
changeset
|
99 |
val get_name_hint: thm -> string |
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
wenzelm
parents:
27255
diff
changeset
|
100 |
val put_name_hint: string -> thm -> thm |
22362
6470ce514b6e
Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff
changeset
|
101 |
val theoremK: string |
42473 | 102 |
val legacy_get_kind: thm -> string |
27866
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
wenzelm
parents:
27255
diff
changeset
|
103 |
val kind_rule: string -> thm -> thm |
61853
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
104 |
val rule_attribute: thm list -> (Context.generic -> thm -> thm) -> attribute |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
105 |
val declaration_attribute: (thm -> Context.generic -> Context.generic) -> attribute |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
106 |
val mixed_attribute: (Context.generic * thm -> Context.generic * thm) -> attribute |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
107 |
val apply_attribute: attribute -> thm -> Context.generic -> thm * Context.generic |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
108 |
val attribute_declaration: attribute -> thm -> Context.generic -> Context.generic |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
109 |
val theory_attributes: attribute list -> thm -> theory -> thm * theory |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
110 |
val proof_attributes: attribute list -> thm -> Proof.context -> thm * Proof.context |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
111 |
val no_attributes: 'a -> 'a * 'b list |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
112 |
val simple_fact: 'a -> ('a * 'b list) list |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
113 |
val tag: string * string -> attribute |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
114 |
val untag: string -> attribute |
27866
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
wenzelm
parents:
27255
diff
changeset
|
115 |
val kind: string -> attribute |
67671
857da80611ab
support for lazy notes in global/local context and Element.Lazy_Notes: name binding and fact without attributes;
wenzelm
parents:
67649
diff
changeset
|
116 |
val register_proofs: thm list lazy -> theory -> theory |
64574
1134e4d5e5b7
consolidate nested thms with persistent result, for improved performance;
wenzelm
parents:
64568
diff
changeset
|
117 |
val consolidate_theory: theory -> unit |
71023
35a8e15b7e03
more robust Thm.expose_theory -- ensure that PIDE export happens in the proper theory context;
wenzelm
parents:
71018
diff
changeset
|
118 |
val expose_theory: theory -> unit |
61268 | 119 |
val show_consts: bool Config.T |
120 |
val show_hyps: bool Config.T |
|
121 |
val show_tags: bool Config.T |
|
122 |
val pretty_thm_raw: Proof.context -> {quote: bool, show_hyps: bool} -> thm -> Pretty.T |
|
123 |
val pretty_thm: Proof.context -> thm -> Pretty.T |
|
124 |
val pretty_thm_item: Proof.context -> thm -> Pretty.T |
|
125 |
val pretty_thm_global: theory -> thm -> Pretty.T |
|
126 |
val string_of_thm: Proof.context -> thm -> string |
|
127 |
val string_of_thm_global: theory -> thm -> string |
|
22362
6470ce514b6e
Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff
changeset
|
128 |
end; |
6470ce514b6e
Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff
changeset
|
129 |
|
6470ce514b6e
Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff
changeset
|
130 |
structure Thm: THM = |
6470ce514b6e
Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff
changeset
|
131 |
struct |
6470ce514b6e
Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff
changeset
|
132 |
|
22695
17073e9b94f2
moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents:
22682
diff
changeset
|
133 |
(** basic operations **) |
22362
6470ce514b6e
Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff
changeset
|
134 |
|
60952
762cb38a3147
produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents:
60951
diff
changeset
|
135 |
(* collecting ctyps and cterms *) |
23491 | 136 |
|
60952
762cb38a3147
produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents:
60951
diff
changeset
|
137 |
val eq_ctyp = op = o apply2 Thm.typ_of; |
59058
a78612c67ec0
renamed "pairself" to "apply2", in accordance to @{apply 2};
wenzelm
parents:
58001
diff
changeset
|
138 |
val op aconvc = op aconv o apply2 Thm.term_of; |
23491 | 139 |
|
74241
eb265f54e3ce
more efficient operations: traverse hyps only when required;
wenzelm
parents:
74239
diff
changeset
|
140 |
val add_tvars = |
74244 | 141 |
Thm.fold_atomic_ctyps {hyps = false} Term.is_TVar (fn cT => fn tab => |
142 |
let val v = Term.dest_TVar (Thm.typ_of cT) |
|
143 |
in tab |> not (Term_Subst.TVars.defined tab v) ? Term_Subst.TVars.update (v, cT) end); |
|
74243 | 144 |
|
74241
eb265f54e3ce
more efficient operations: traverse hyps only when required;
wenzelm
parents:
74239
diff
changeset
|
145 |
val add_vars = |
74244 | 146 |
Thm.fold_atomic_cterms {hyps = false} Term.is_Var (fn ct => fn tab => |
147 |
let val v = Term.dest_Var (Thm.term_of ct) |
|
148 |
in tab |> not (Term_Subst.Vars.defined tab v) ? Term_Subst.Vars.update (v, ct) end); |
|
23491 | 149 |
|
150 |
||
70155 | 151 |
(* ctyp operations *) |
70152 | 152 |
|
70159 | 153 |
fun dest_funT cT = |
70155 | 154 |
(case Thm.typ_of cT of |
155 |
Type ("fun", _) => let val [A, B] = Thm.dest_ctyp cT in (A, B) end |
|
70159 | 156 |
| T => raise TYPE ("dest_funT", [T], [])); |
70152 | 157 |
|
158 |
(* ctyp version of strip_type: maps [T1,...,Tn]--->T to ([T1,T2,...,Tn], T) *) |
|
159 |
fun strip_type cT = |
|
160 |
(case Thm.typ_of cT of |
|
161 |
Type ("fun", _) => |
|
162 |
let |
|
70159 | 163 |
val (cT1, cT2) = dest_funT cT; |
70152 | 164 |
val (cTs, cT') = strip_type cT2 |
165 |
in (cT1 :: cTs, cT') end |
|
166 |
| _ => ([], cT)); |
|
167 |
||
168 |
||
70155 | 169 |
(* cterm operations *) |
22907 | 170 |
|
60938 | 171 |
fun all_name ctxt (x, t) A = |
32198 | 172 |
let |
59586 | 173 |
val T = Thm.typ_of_cterm t; |
60938 | 174 |
val all_const = Thm.cterm_of ctxt (Const ("Pure.all", (T --> propT) --> propT)); |
175 |
in Thm.apply all_const (Thm.lambda_name (x, t) A) end; |
|
32198 | 176 |
|
60938 | 177 |
fun all ctxt t A = all_name ctxt ("", t) A; |
32198 | 178 |
|
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:
45382
diff
changeset
|
179 |
fun mk_binop c a b = Thm.apply (Thm.apply c a) b; |
22907 | 180 |
fun dest_binop ct = (Thm.dest_arg1 ct, Thm.dest_arg ct); |
181 |
||
182 |
fun dest_implies ct = |
|
183 |
(case Thm.term_of ct of |
|
56245 | 184 |
Const ("Pure.imp", _) $ _ $ _ => dest_binop ct |
22907 | 185 |
| _ => raise TERM ("dest_implies", [Thm.term_of ct])); |
186 |
||
187 |
fun dest_equals ct = |
|
188 |
(case Thm.term_of ct of |
|
56245 | 189 |
Const ("Pure.eq", _) $ _ $ _ => dest_binop ct |
22907 | 190 |
| _ => raise TERM ("dest_equals", [Thm.term_of ct])); |
191 |
||
192 |
fun dest_equals_lhs ct = |
|
193 |
(case Thm.term_of ct of |
|
56245 | 194 |
Const ("Pure.eq", _) $ _ $ _ => Thm.dest_arg1 ct |
22907 | 195 |
| _ => raise TERM ("dest_equals_lhs", [Thm.term_of ct])); |
196 |
||
197 |
fun dest_equals_rhs ct = |
|
198 |
(case Thm.term_of ct of |
|
56245 | 199 |
Const ("Pure.eq", _) $ _ $ _ => Thm.dest_arg ct |
22907 | 200 |
| _ => raise TERM ("dest_equals_rhs", [Thm.term_of ct])); |
201 |
||
202 |
val lhs_of = dest_equals_lhs o Thm.cprop_of; |
|
203 |
val rhs_of = dest_equals_rhs o Thm.cprop_of; |
|
204 |
||
205 |
||
67559 | 206 |
(* certified term order *) |
207 |
||
208 |
val fast_term_ord = Term_Ord.fast_term_ord o apply2 Thm.term_of; |
|
209 |
val term_ord = Term_Ord.term_ord o apply2 Thm.term_of; |
|
210 |
||
211 |
||
22907 | 212 |
(* thm order: ignores theory context! *) |
22682 | 213 |
|
70464 | 214 |
val thm_ord = |
215 |
Term_Ord.fast_term_ord o apply2 Thm.prop_of |
|
73860 | 216 |
||| list_ord (prod_ord Term_Ord.fast_term_ord Term_Ord.fast_term_ord) o apply2 Thm.tpairs_of |
217 |
||| list_ord Term_Ord.fast_term_ord o apply2 Thm.hyps_of |
|
218 |
||| list_ord Term_Ord.sort_ord o apply2 Thm.shyps_of; |
|
22362
6470ce514b6e
Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff
changeset
|
219 |
|
22682 | 220 |
|
32842 | 221 |
(* tables and caches *) |
222 |
||
67559 | 223 |
structure Ctermtab = Table(type key = cterm val ord = fast_term_ord); |
32842 | 224 |
structure Thmtab = Table(type key = thm val ord = thm_ord); |
225 |
||
226 |
fun cterm_cache f = Cache.create Ctermtab.empty Ctermtab.lookup Ctermtab.update f; |
|
227 |
fun thm_cache f = Cache.create Thmtab.empty Thmtab.lookup Thmtab.update f; |
|
228 |
||
229 |
||
22682 | 230 |
(* equality *) |
231 |
||
23599 | 232 |
fun is_reflexive th = op aconv (Logic.dest_equals (Thm.prop_of th)) |
233 |
handle TERM _ => false; |
|
234 |
||
55547
384bfd19ee61
subtle change of semantics of Thm.eq_thm, e.g. relevant for merge of src/HOL/Tools/Predicate_Compile/core_data.ML (cf. HOL-IMP);
wenzelm
parents:
54996
diff
changeset
|
235 |
val eq_thm = is_equal o thm_ord; |
22362
6470ce514b6e
Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff
changeset
|
236 |
|
59058
a78612c67ec0
renamed "pairself" to "apply2", in accordance to @{apply 2};
wenzelm
parents:
58001
diff
changeset
|
237 |
val eq_thm_prop = op aconv o apply2 Thm.full_prop_of; |
22362
6470ce514b6e
Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff
changeset
|
238 |
|
52683
fb028440473e
more official Thm.eq_thm_strict, without demanding ML equality type;
wenzelm
parents:
51316
diff
changeset
|
239 |
fun eq_thm_strict ths = |
55547
384bfd19ee61
subtle change of semantics of Thm.eq_thm, e.g. relevant for merge of src/HOL/Tools/Predicate_Compile/core_data.ML (cf. HOL-IMP);
wenzelm
parents:
54996
diff
changeset
|
240 |
eq_thm ths andalso |
65458 | 241 |
Context.eq_thy_id (apply2 Thm.theory_id ths) andalso |
61040 | 242 |
op = (apply2 Thm.maxidx_of ths) andalso |
243 |
op = (apply2 Thm.get_tags ths); |
|
52683
fb028440473e
more official Thm.eq_thm_strict, without demanding ML equality type;
wenzelm
parents:
51316
diff
changeset
|
244 |
|
22682 | 245 |
|
246 |
(* pattern equivalence *) |
|
247 |
||
60817 | 248 |
fun equiv_thm thy ths = |
249 |
Pattern.equiv thy (apply2 (Thm.full_prop_of o Thm.transfer thy) ths); |
|
22362
6470ce514b6e
Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff
changeset
|
250 |
|
6470ce514b6e
Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff
changeset
|
251 |
|
31904
a86896359ca4
renamed Drule.sort_triv to Thm.sort_triv (cf. more_thm.ML);
wenzelm
parents:
31177
diff
changeset
|
252 |
(* type classes and sorts *) |
a86896359ca4
renamed Drule.sort_triv to Thm.sort_triv (cf. more_thm.ML);
wenzelm
parents:
31177
diff
changeset
|
253 |
|
31944 | 254 |
fun class_triv thy c = |
59621
291934bac95e
Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents:
59616
diff
changeset
|
255 |
Thm.of_class (Thm.global_ctyp_of thy (TVar ((Name.aT, 0), [c])), c); |
31944 | 256 |
|
257 |
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:
28116
diff
changeset
|
258 |
|
a60164e8fff0
added check_shyps, which reject pending sort hypotheses;
wenzelm
parents:
28116
diff
changeset
|
259 |
|
22695
17073e9b94f2
moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents:
22682
diff
changeset
|
260 |
(* misc operations *) |
17073e9b94f2
moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents:
22682
diff
changeset
|
261 |
|
24048
a12b4faff474
moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents:
23599
diff
changeset
|
262 |
fun is_dummy thm = |
a12b4faff474
moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents:
23599
diff
changeset
|
263 |
(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:
23599
diff
changeset
|
264 |
NONE => false |
58001
934d85f14d1d
more general dummy: may contain "parked arguments", for example;
wenzelm
parents:
56245
diff
changeset
|
265 |
| SOME t => Term.is_dummy_pattern (Term.head_of t)); |
24048
a12b4faff474
moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents:
23599
diff
changeset
|
266 |
|
22695
17073e9b94f2
moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents:
22682
diff
changeset
|
267 |
|
30564 | 268 |
(* collections of theorems in canonical order *) |
24048
a12b4faff474
moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents:
23599
diff
changeset
|
269 |
|
a12b4faff474
moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents:
23599
diff
changeset
|
270 |
val add_thm = update eq_thm_prop; |
a12b4faff474
moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents:
23599
diff
changeset
|
271 |
val del_thm = remove eq_thm_prop; |
a12b4faff474
moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents:
23599
diff
changeset
|
272 |
val merge_thms = merge eq_thm_prop; |
a12b4faff474
moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents:
23599
diff
changeset
|
273 |
|
74152 | 274 |
val item_net = Item_Net.init eq_thm_prop (single o Thm.full_prop_of); |
275 |
val item_net_intro = Item_Net.init eq_thm_prop (single o Thm.concl_of); |
|
276 |
val item_net_elim = Item_Net.init eq_thm_prop (single o Thm.major_prem_of); |
|
30560 | 277 |
|
278 |
||
22682 | 279 |
|
61508 | 280 |
(** declared hyps and sort hyps **) |
54984
da70ab8531f4
more elementary management of declared hyps, below structure Assumption;
wenzelm
parents:
53206
diff
changeset
|
281 |
|
da70ab8531f4
more elementary management of declared hyps, below structure Assumption;
wenzelm
parents:
53206
diff
changeset
|
282 |
structure Hyps = Proof_Data |
da70ab8531f4
more elementary management of declared hyps, below structure Assumption;
wenzelm
parents:
53206
diff
changeset
|
283 |
( |
61508 | 284 |
type T = {checked_hyps: bool, hyps: Termtab.set, shyps: sort Ord_List.T}; |
285 |
fun init _ : T = {checked_hyps = true, hyps = Termtab.empty, shyps = []}; |
|
54984
da70ab8531f4
more elementary management of declared hyps, below structure Assumption;
wenzelm
parents:
53206
diff
changeset
|
286 |
); |
da70ab8531f4
more elementary management of declared hyps, below structure Assumption;
wenzelm
parents:
53206
diff
changeset
|
287 |
|
61508 | 288 |
fun map_hyps f = Hyps.map (fn {checked_hyps, hyps, shyps} => |
289 |
let val (checked_hyps', hyps', shyps') = f (checked_hyps, hyps, shyps) |
|
290 |
in {checked_hyps = checked_hyps', hyps = hyps', shyps = shyps'} end); |
|
291 |
||
292 |
||
293 |
(* hyps *) |
|
294 |
||
295 |
fun declare_hyps raw_ct ctxt = ctxt |> map_hyps (fn (checked_hyps, hyps, shyps) => |
|
296 |
let |
|
297 |
val ct = Thm.transfer_cterm (Proof_Context.theory_of ctxt) raw_ct; |
|
298 |
val hyps' = Termtab.update (Thm.term_of ct, ()) hyps; |
|
299 |
in (checked_hyps, hyps', shyps) end); |
|
54984
da70ab8531f4
more elementary management of declared hyps, below structure Assumption;
wenzelm
parents:
53206
diff
changeset
|
300 |
|
da70ab8531f4
more elementary management of declared hyps, below structure Assumption;
wenzelm
parents:
53206
diff
changeset
|
301 |
fun assume_hyps ct ctxt = (Thm.assume ct, declare_hyps ct ctxt); |
da70ab8531f4
more elementary management of declared hyps, below structure Assumption;
wenzelm
parents:
53206
diff
changeset
|
302 |
|
61508 | 303 |
val unchecked_hyps = map_hyps (fn (_, hyps, shyps) => (false, hyps, shyps)); |
304 |
||
305 |
fun restore_hyps ctxt = |
|
306 |
map_hyps (fn (_, hyps, shyps) => (#checked_hyps (Hyps.get ctxt), hyps, shyps)); |
|
54993
625370769fc0
check_hyps for attribute application (still inactive, due to non-compliant tools);
wenzelm
parents:
54984
diff
changeset
|
307 |
|
55633 | 308 |
fun undeclared_hyps context th = |
309 |
Thm.hyps_of th |
|
310 |
|> filter_out |
|
311 |
(case context of |
|
312 |
Context.Theory _ => K false |
|
313 |
| Context.Proof ctxt => |
|
314 |
(case Hyps.get ctxt of |
|
61508 | 315 |
{checked_hyps = false, ...} => K true |
316 |
| {hyps, ...} => Termtab.defined hyps)); |
|
55633 | 317 |
|
54993
625370769fc0
check_hyps for attribute application (still inactive, due to non-compliant tools);
wenzelm
parents:
54984
diff
changeset
|
318 |
fun check_hyps context th = |
55633 | 319 |
(case undeclared_hyps context th of |
320 |
[] => th |
|
321 |
| undeclared => |
|
61263 | 322 |
error (Pretty.string_of (Pretty.big_list "Undeclared hyps:" |
323 |
(map (Pretty.item o single o Syntax.pretty_term (Syntax.init_pretty context)) undeclared)))); |
|
54984
da70ab8531f4
more elementary management of declared hyps, below structure Assumption;
wenzelm
parents:
53206
diff
changeset
|
324 |
|
da70ab8531f4
more elementary management of declared hyps, below structure Assumption;
wenzelm
parents:
53206
diff
changeset
|
325 |
|
61508 | 326 |
(* shyps *) |
327 |
||
328 |
fun declare_term_sorts t = |
|
329 |
map_hyps (fn (checked_hyps, hyps, shyps) => |
|
330 |
(checked_hyps, hyps, Sorts.insert_term t shyps)); |
|
331 |
||
61509
358dfae15d83
print thm wrt. local shyps (from full proof context);
wenzelm
parents:
61508
diff
changeset
|
332 |
fun extra_shyps' ctxt th = |
358dfae15d83
print thm wrt. local shyps (from full proof context);
wenzelm
parents:
61508
diff
changeset
|
333 |
Sorts.subtract (#shyps (Hyps.get ctxt)) (Thm.extra_shyps th); |
358dfae15d83
print thm wrt. local shyps (from full proof context);
wenzelm
parents:
61508
diff
changeset
|
334 |
|
61508 | 335 |
fun check_shyps ctxt raw_th = |
336 |
let |
|
337 |
val th = Thm.strip_shyps raw_th; |
|
61509
358dfae15d83
print thm wrt. local shyps (from full proof context);
wenzelm
parents:
61508
diff
changeset
|
338 |
val extra_shyps = extra_shyps' ctxt th; |
61508 | 339 |
in |
61509
358dfae15d83
print thm wrt. local shyps (from full proof context);
wenzelm
parents:
61508
diff
changeset
|
340 |
if null extra_shyps then th |
61508 | 341 |
else error (Pretty.string_of (Pretty.block (Pretty.str "Pending sort hypotheses:" :: |
61509
358dfae15d83
print thm wrt. local shyps (from full proof context);
wenzelm
parents:
61508
diff
changeset
|
342 |
Pretty.brk 1 :: Pretty.commas (map (Syntax.pretty_sort ctxt) extra_shyps)))) |
61508 | 343 |
end; |
344 |
||
345 |
val weaken_sorts' = Thm.weaken_sorts o #shyps o Hyps.get; |
|
346 |
||
347 |
||
54984
da70ab8531f4
more elementary management of declared hyps, below structure Assumption;
wenzelm
parents:
53206
diff
changeset
|
348 |
|
24980
16a74cfca971
added elim_implies (more convenient argument order);
wenzelm
parents:
24948
diff
changeset
|
349 |
(** basic derived rules **) |
16a74cfca971
added elim_implies (more convenient argument order);
wenzelm
parents:
24948
diff
changeset
|
350 |
|
16a74cfca971
added elim_implies (more convenient argument order);
wenzelm
parents:
24948
diff
changeset
|
351 |
(*Elimination of implication |
67721 | 352 |
A A \<Longrightarrow> B |
24980
16a74cfca971
added elim_implies (more convenient argument order);
wenzelm
parents:
24948
diff
changeset
|
353 |
------------ |
16a74cfca971
added elim_implies (more convenient argument order);
wenzelm
parents:
24948
diff
changeset
|
354 |
B |
16a74cfca971
added elim_implies (more convenient argument order);
wenzelm
parents:
24948
diff
changeset
|
355 |
*) |
16a74cfca971
added elim_implies (more convenient argument order);
wenzelm
parents:
24948
diff
changeset
|
356 |
fun elim_implies thA thAB = Thm.implies_elim thAB thA; |
16a74cfca971
added elim_implies (more convenient argument order);
wenzelm
parents:
24948
diff
changeset
|
357 |
|
26653 | 358 |
|
61339 | 359 |
(* forall_intr_name *) |
360 |
||
361 |
fun forall_intr_name (a, x) th = |
|
362 |
let |
|
363 |
val th' = Thm.forall_intr x th; |
|
364 |
val prop' = (case Thm.prop_of th' of all $ Abs (_, T, b) => all $ Abs (a, T, b)); |
|
365 |
in Thm.renamed_prop prop' th' end; |
|
366 |
||
367 |
||
26653 | 368 |
(* forall_elim_var(s) *) |
369 |
||
370 |
local |
|
371 |
||
60951
b70c4db3874f
produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents:
60950
diff
changeset
|
372 |
fun dest_all ct = |
b70c4db3874f
produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents:
60950
diff
changeset
|
373 |
(case Thm.term_of ct of |
b70c4db3874f
produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents:
60950
diff
changeset
|
374 |
Const ("Pure.all", _) $ Abs (a, _, _) => |
b70c4db3874f
produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents:
60950
diff
changeset
|
375 |
let val (x, ct') = Thm.dest_abs NONE (Thm.dest_arg ct) |
b70c4db3874f
produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents:
60950
diff
changeset
|
376 |
in SOME ((a, Thm.ctyp_of_cterm x), ct') end |
b70c4db3874f
produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents:
60950
diff
changeset
|
377 |
| _ => NONE); |
b70c4db3874f
produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents:
60950
diff
changeset
|
378 |
|
b70c4db3874f
produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents:
60950
diff
changeset
|
379 |
fun dest_all_list ct = |
b70c4db3874f
produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents:
60950
diff
changeset
|
380 |
(case dest_all ct of |
b70c4db3874f
produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents:
60950
diff
changeset
|
381 |
NONE => [] |
b70c4db3874f
produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents:
60950
diff
changeset
|
382 |
| SOME (v, ct') => v :: dest_all_list ct'); |
b70c4db3874f
produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents:
60950
diff
changeset
|
383 |
|
b70c4db3874f
produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents:
60950
diff
changeset
|
384 |
fun forall_elim_vars_list vars i th = |
26653 | 385 |
let |
60950 | 386 |
val used = |
74241
eb265f54e3ce
more efficient operations: traverse hyps only when required;
wenzelm
parents:
74239
diff
changeset
|
387 |
(Thm.fold_terms {hyps = false} o Term.fold_aterms) |
60950 | 388 |
(fn Var ((x, j), _) => if i = j then insert (op =) x else I | _ => I) th []; |
60951
b70c4db3874f
produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents:
60950
diff
changeset
|
389 |
val vars' = (Name.variant_list used (map #1 vars), vars) |
b70c4db3874f
produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents:
60950
diff
changeset
|
390 |
|> ListPair.map (fn (x, (_, T)) => Thm.var ((x, i), T)); |
b70c4db3874f
produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents:
60950
diff
changeset
|
391 |
in fold Thm.forall_elim vars' th end; |
26653 | 392 |
|
393 |
in |
|
394 |
||
60950 | 395 |
fun forall_elim_vars i th = |
60951
b70c4db3874f
produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents:
60950
diff
changeset
|
396 |
forall_elim_vars_list (dest_all_list (Thm.cprop_of th)) i th; |
26653 | 397 |
|
33697 | 398 |
fun forall_elim_var i th = |
60950 | 399 |
let |
400 |
val vars = |
|
60951
b70c4db3874f
produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents:
60950
diff
changeset
|
401 |
(case dest_all (Thm.cprop_of th) of |
b70c4db3874f
produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents:
60950
diff
changeset
|
402 |
SOME (v, _) => [v] |
b70c4db3874f
produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents:
60950
diff
changeset
|
403 |
| NONE => raise THM ("forall_elim_var", i, [th])); |
b70c4db3874f
produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents:
60950
diff
changeset
|
404 |
in forall_elim_vars_list vars i th end; |
26653 | 405 |
|
406 |
end; |
|
407 |
||
408 |
||
67698
67caf783b9ee
explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents:
67671
diff
changeset
|
409 |
(* instantiate frees *) |
67caf783b9ee
explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents:
67671
diff
changeset
|
410 |
|
67caf783b9ee
explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents:
67671
diff
changeset
|
411 |
fun instantiate_frees ([], []) th = th |
67caf783b9ee
explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents:
67671
diff
changeset
|
412 |
| instantiate_frees (instT, inst) th = |
67caf783b9ee
explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents:
67671
diff
changeset
|
413 |
let |
67caf783b9ee
explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents:
67671
diff
changeset
|
414 |
val idx = Thm.maxidx_of th + 1; |
67caf783b9ee
explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents:
67671
diff
changeset
|
415 |
fun index ((a, A), b) = (((a, idx), A), b); |
67caf783b9ee
explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents:
67671
diff
changeset
|
416 |
val insts = (map index instT, map index inst); |
74232 | 417 |
val tfrees = Symtab.build (fold (Symtab.insert_set o #1 o #1) instT); |
418 |
val frees = Symtab.build (fold (Symtab.insert_set o #1 o #1) inst); |
|
67698
67caf783b9ee
explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents:
67671
diff
changeset
|
419 |
|
67caf783b9ee
explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents:
67671
diff
changeset
|
420 |
val hyps = Thm.chyps_of th; |
67caf783b9ee
explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents:
67671
diff
changeset
|
421 |
val inst_cterm = |
74200
17090e27aae9
more scalable data structure (but: rarely used with > 5 arguments);
wenzelm
parents:
74152
diff
changeset
|
422 |
Thm.generalize_cterm (tfrees, frees) idx #> |
67698
67caf783b9ee
explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents:
67671
diff
changeset
|
423 |
Thm.instantiate_cterm insts; |
67caf783b9ee
explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents:
67671
diff
changeset
|
424 |
in |
67caf783b9ee
explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents:
67671
diff
changeset
|
425 |
th |
67caf783b9ee
explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents:
67671
diff
changeset
|
426 |
|> fold_rev Thm.implies_intr hyps |
74200
17090e27aae9
more scalable data structure (but: rarely used with > 5 arguments);
wenzelm
parents:
74152
diff
changeset
|
427 |
|> Thm.generalize (tfrees, frees) idx |
67698
67caf783b9ee
explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents:
67671
diff
changeset
|
428 |
|> Thm.instantiate insts |
67caf783b9ee
explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents:
67671
diff
changeset
|
429 |
|> fold (elim_implies o Thm.assume o inst_cterm) hyps |
67caf783b9ee
explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents:
67671
diff
changeset
|
430 |
end; |
67caf783b9ee
explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents:
67671
diff
changeset
|
431 |
|
67caf783b9ee
explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents:
67671
diff
changeset
|
432 |
|
60801 | 433 |
(* instantiate by left-to-right occurrence of variables *) |
434 |
||
435 |
fun instantiate' cTs cts thm = |
|
436 |
let |
|
437 |
fun err msg = |
|
438 |
raise TYPE ("instantiate': " ^ msg, |
|
439 |
map_filter (Option.map Thm.typ_of) cTs, |
|
440 |
map_filter (Option.map Thm.term_of) cts); |
|
441 |
||
442 |
fun zip_vars xs ys = |
|
443 |
zip_options xs ys handle ListPair.UnequalLengths => |
|
444 |
err "more instantiations than variables in thm"; |
|
445 |
||
74241
eb265f54e3ce
more efficient operations: traverse hyps only when required;
wenzelm
parents:
74239
diff
changeset
|
446 |
val instT = zip_vars (build_rev (Thm.fold_terms {hyps = false} Term.add_tvars thm)) cTs; |
eb265f54e3ce
more efficient operations: traverse hyps only when required;
wenzelm
parents:
74239
diff
changeset
|
447 |
val thm' = Thm.instantiate (instT, []) thm; |
eb265f54e3ce
more efficient operations: traverse hyps only when required;
wenzelm
parents:
74239
diff
changeset
|
448 |
val inst = zip_vars (build_rev (Thm.fold_terms {hyps = false} Term.add_vars thm')) cts; |
eb265f54e3ce
more efficient operations: traverse hyps only when required;
wenzelm
parents:
74239
diff
changeset
|
449 |
in Thm.instantiate ([], inst) thm' end; |
60801 | 450 |
|
451 |
||
74245 | 452 |
(* implicit generalization over variables -- canonical order *) |
453 |
||
454 |
fun forall_intr_vars th = |
|
74247 | 455 |
let |
456 |
val (_, vars) = |
|
457 |
(th, (Term_Subst.Vars.empty, [])) |-> Thm.fold_atomic_cterms {hyps = false} Term.is_Var |
|
458 |
(fn ct => fn (seen, vars) => |
|
459 |
let val v = Term.dest_Var (Thm.term_of ct) in |
|
460 |
if not (Term_Subst.Vars.defined seen v) |
|
461 |
then (Term_Subst.Vars.add (v, ()) seen, ct :: vars) |
|
462 |
else (seen, vars) |
|
463 |
end); |
|
464 |
in fold Thm.forall_intr vars th end; |
|
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:
35857
diff
changeset
|
465 |
|
0bbf0d2348f9
moved Drule.forall_intr_frees to Thm.forall_intr_frees (in more_thm.ML, which is loaded before pure_thy.ML);
wenzelm
parents:
35857
diff
changeset
|
466 |
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:
35857
diff
changeset
|
467 |
let |
74246 | 468 |
val fixed = |
74232 | 469 |
Term_Subst.Frees.build |
470 |
(fold Term_Subst.add_frees (Thm.terms_of_tpairs (Thm.tpairs_of th)) #> |
|
471 |
fold Term_Subst.add_frees (Thm.hyps_of th)); |
|
74237 | 472 |
val (_, frees) = |
74246 | 473 |
(th, (fixed, [])) |-> Thm.fold_atomic_cterms {hyps = false} Term.is_Free |
474 |
(fn ct => fn (seen, frees) => |
|
74244 | 475 |
let val v = Term.dest_Free (Thm.term_of ct) in |
74246 | 476 |
if not (Term_Subst.Frees.defined seen v) |
477 |
then (Term_Subst.Frees.add (v, ()) seen, ct :: frees) |
|
478 |
else (seen, frees) |
|
74244 | 479 |
end); |
60821 | 480 |
in fold Thm.forall_intr frees th end; |
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:
35857
diff
changeset
|
481 |
|
0bbf0d2348f9
moved Drule.forall_intr_frees to Thm.forall_intr_frees (in more_thm.ML, which is loaded before pure_thy.ML);
wenzelm
parents:
35857
diff
changeset
|
482 |
|
35845
e5980f0ad025
renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
wenzelm
parents:
35715
diff
changeset
|
483 |
(* unvarify_global: global schematic variables *) |
26653 | 484 |
|
60825 | 485 |
fun unvarify_global thy th = |
24980
16a74cfca971
added elim_implies (more convenient argument order);
wenzelm
parents:
24948
diff
changeset
|
486 |
let |
16a74cfca971
added elim_implies (more convenient argument order);
wenzelm
parents:
24948
diff
changeset
|
487 |
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:
35715
diff
changeset
|
488 |
val _ = map Logic.unvarify_global (prop :: Thm.hyps_of th) |
24980
16a74cfca971
added elim_implies (more convenient argument order);
wenzelm
parents:
24948
diff
changeset
|
489 |
handle TERM (msg, _) => raise THM (msg, 0, [th]); |
16a74cfca971
added elim_implies (more convenient argument order);
wenzelm
parents:
24948
diff
changeset
|
490 |
|
74230 | 491 |
val cert = Thm.global_cterm_of thy; |
492 |
val certT = Thm.global_ctyp_of thy; |
|
493 |
||
494 |
val instT = |
|
74232 | 495 |
Term_Subst.TVars.build (prop |> (Term.fold_types o Term.fold_atyps) |
74230 | 496 |
(fn T => fn instT => |
497 |
(case T of |
|
498 |
TVar (v as ((a, _), S)) => |
|
499 |
if Term_Subst.TVars.defined instT v then instT |
|
500 |
else Term_Subst.TVars.update (v, TFree (a, S)) instT |
|
74232 | 501 |
| _ => instT))); |
74230 | 502 |
val cinstT = Term_Subst.TVars.map (K certT) instT; |
503 |
val cinst = |
|
74232 | 504 |
Term_Subst.Vars.build (prop |> Term.fold_aterms |
74230 | 505 |
(fn t => fn inst => |
506 |
(case t of |
|
507 |
Var ((x, i), T) => |
|
508 |
let val T' = Term_Subst.instantiateT instT T |
|
509 |
in Term_Subst.Vars.update (((x, i), T'), cert (Free ((x, T')))) inst end |
|
74232 | 510 |
| _ => inst))); |
74230 | 511 |
in Thm.instantiate (Term_Subst.TVars.dest cinstT, Term_Subst.Vars.dest cinst) th end; |
24980
16a74cfca971
added elim_implies (more convenient argument order);
wenzelm
parents:
24948
diff
changeset
|
512 |
|
60825 | 513 |
fun unvarify_axiom thy = unvarify_global thy o Thm.axiom thy; |
514 |
||
26653 | 515 |
|
59969
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
516 |
(* user renaming of parameters in a subgoal *) |
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
517 |
|
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
518 |
(*The names, if distinct, are used for the innermost parameters of subgoal i; |
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
519 |
preceding parameters may be renamed to make all parameters distinct.*) |
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
520 |
fun rename_params_rule (names, i) st = |
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
521 |
let |
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
522 |
val (_, Bs, Bi, C) = Thm.dest_state (st, i); |
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
523 |
val params = map #1 (Logic.strip_params Bi); |
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
524 |
val short = length params - length names; |
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
525 |
val names' = |
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
526 |
if short < 0 then error "More names than parameters in subgoal!" |
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
527 |
else Name.variant_list names (take short params) @ names; |
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
528 |
val free_names = Term.fold_aterms (fn Free (x, _) => insert (op =) x | _ => I) Bi []; |
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
529 |
val Bi' = Logic.list_rename_params names' Bi; |
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
530 |
in |
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
531 |
(case duplicates (op =) names of |
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
532 |
a :: _ => (warning ("Can't rename. Bound variables not distinct: " ^ a); st) |
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
533 |
| [] => |
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
534 |
(case inter (op =) names free_names of |
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
535 |
a :: _ => (warning ("Can't rename. Bound/Free variable clash: " ^ a); st) |
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
536 |
| [] => Thm.renamed_prop (Logic.list_implies (Bs @ [Bi'], C)) st)) |
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
537 |
end; |
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
538 |
|
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
539 |
|
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
540 |
(* preservation of bound variable names *) |
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
541 |
|
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
542 |
fun rename_boundvars pat obj th = |
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
543 |
(case Term.rename_abs pat obj (Thm.prop_of th) of |
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
544 |
NONE => th |
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
545 |
| SOME prop' => Thm.renamed_prop prop' th); |
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
546 |
|
bcccad156236
explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents:
59623
diff
changeset
|
547 |
|
24980
16a74cfca971
added elim_implies (more convenient argument order);
wenzelm
parents:
24948
diff
changeset
|
548 |
|
16a74cfca971
added elim_implies (more convenient argument order);
wenzelm
parents:
24948
diff
changeset
|
549 |
(** specification primitives **) |
16a74cfca971
added elim_implies (more convenient argument order);
wenzelm
parents:
24948
diff
changeset
|
550 |
|
30342 | 551 |
(* rules *) |
552 |
||
35855
e7d004b89ca8
add_axiom: axiomatize "unconstrained" version, with explicit of_class premises;
wenzelm
parents:
35853
diff
changeset
|
553 |
fun stripped_sorts thy t = |
e7d004b89ca8
add_axiom: axiomatize "unconstrained" version, with explicit of_class premises;
wenzelm
parents:
35853
diff
changeset
|
554 |
let |
74235 | 555 |
val tfrees = build_rev (Term.add_tfrees t); |
70922
539dfd4c166b
more conservative type names, e.g. relevant for Isabelle/MMT export;
wenzelm
parents:
70915
diff
changeset
|
556 |
val tfrees' = map (fn a => (a, [])) (Name.variant_list [] (map #1 tfrees)); |
60642
48dd1cefb4ae
simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents:
60367
diff
changeset
|
557 |
val recover = |
48dd1cefb4ae
simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents:
60367
diff
changeset
|
558 |
map2 (fn (a', S') => fn (a, S) => (((a', 0), S'), Thm.global_ctyp_of thy (TVar ((a, 0), S)))) |
48dd1cefb4ae
simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents:
60367
diff
changeset
|
559 |
tfrees' tfrees; |
48dd1cefb4ae
simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents:
60367
diff
changeset
|
560 |
val strip = map (apply2 TFree) (tfrees ~~ tfrees'); |
35855
e7d004b89ca8
add_axiom: axiomatize "unconstrained" version, with explicit of_class premises;
wenzelm
parents:
35853
diff
changeset
|
561 |
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:
35853
diff
changeset
|
562 |
in (strip, recover, t') end; |
e7d004b89ca8
add_axiom: axiomatize "unconstrained" version, with explicit of_class premises;
wenzelm
parents:
35853
diff
changeset
|
563 |
|
42375
774df7c59508
report Name_Space.declare/define, relatively to context;
wenzelm
parents:
40238
diff
changeset
|
564 |
fun add_axiom ctxt (b, prop) thy = |
24980
16a74cfca971
added elim_implies (more convenient argument order);
wenzelm
parents:
24948
diff
changeset
|
565 |
let |
42375
774df7c59508
report Name_Space.declare/define, relatively to context;
wenzelm
parents:
40238
diff
changeset
|
566 |
val _ = Sign.no_vars ctxt prop; |
35855
e7d004b89ca8
add_axiom: axiomatize "unconstrained" version, with explicit of_class premises;
wenzelm
parents:
35853
diff
changeset
|
567 |
val (strip, recover, prop') = stripped_sorts thy prop; |
e7d004b89ca8
add_axiom: axiomatize "unconstrained" version, with explicit of_class premises;
wenzelm
parents:
35853
diff
changeset
|
568 |
val constraints = map (fn (TFree (_, S), T) => (T, S)) strip; |
60367 | 569 |
val of_sorts = maps (fn (T as TFree (_, S), _) => of_sort (Thm.ctyp_of ctxt T, S)) strip; |
36106
19deea200358
Thm.add_axiom/add_def: return internal name of foundational axiom;
wenzelm
parents:
35988
diff
changeset
|
570 |
|
42375
774df7c59508
report Name_Space.declare/define, relatively to context;
wenzelm
parents:
40238
diff
changeset
|
571 |
val thy' = thy |
51316
dfe469293eb4
discontinued empty name bindings in 'axiomatization';
wenzelm
parents:
49062
diff
changeset
|
572 |
|> Theory.add_axiom ctxt (b, Logic.list_implies (maps Logic.mk_of_sort constraints, prop')); |
dfe469293eb4
discontinued empty name bindings in 'axiomatization';
wenzelm
parents:
49062
diff
changeset
|
573 |
val axm_name = Sign.full_name thy' b; |
36106
19deea200358
Thm.add_axiom/add_def: return internal name of foundational axiom;
wenzelm
parents:
35988
diff
changeset
|
574 |
val axm' = Thm.axiom thy' axm_name; |
35988
76ca601c941e
disallow premises in primitive Theory.add_def -- handle in Thm.add_def;
wenzelm
parents:
35985
diff
changeset
|
575 |
val thm = |
76ca601c941e
disallow premises in primitive Theory.add_def -- handle in Thm.add_def;
wenzelm
parents:
35985
diff
changeset
|
576 |
Thm.instantiate (recover, []) axm' |
60825 | 577 |
|> unvarify_global thy' |
35988
76ca601c941e
disallow premises in primitive Theory.add_def -- handle in Thm.add_def;
wenzelm
parents:
35985
diff
changeset
|
578 |
|> fold elim_implies of_sorts; |
36106
19deea200358
Thm.add_axiom/add_def: return internal name of foundational axiom;
wenzelm
parents:
35988
diff
changeset
|
579 |
in ((axm_name, thm), thy') end; |
24980
16a74cfca971
added elim_implies (more convenient argument order);
wenzelm
parents:
24948
diff
changeset
|
580 |
|
42375
774df7c59508
report Name_Space.declare/define, relatively to context;
wenzelm
parents:
40238
diff
changeset
|
581 |
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:
40238
diff
changeset
|
582 |
|
61261
ddb2da7cb2e4
more explicit Defs.context: use proper name spaces as far as possible;
wenzelm
parents:
61059
diff
changeset
|
583 |
fun add_def (context as (ctxt, _)) unchecked overloaded (b, prop) thy = |
24980
16a74cfca971
added elim_implies (more convenient argument order);
wenzelm
parents:
24948
diff
changeset
|
584 |
let |
42375
774df7c59508
report Name_Space.declare/define, relatively to context;
wenzelm
parents:
40238
diff
changeset
|
585 |
val _ = Sign.no_vars ctxt prop; |
60367 | 586 |
val prems = map (Thm.cterm_of ctxt) (Logic.strip_imp_prems prop); |
35988
76ca601c941e
disallow premises in primitive Theory.add_def -- handle in Thm.add_def;
wenzelm
parents:
35985
diff
changeset
|
587 |
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:
35988
diff
changeset
|
588 |
|
61261
ddb2da7cb2e4
more explicit Defs.context: use proper name spaces as far as possible;
wenzelm
parents:
61059
diff
changeset
|
589 |
val thy' = Theory.add_def context unchecked overloaded (b, concl') thy; |
36106
19deea200358
Thm.add_axiom/add_def: return internal name of foundational axiom;
wenzelm
parents:
35988
diff
changeset
|
590 |
val axm_name = Sign.full_name thy' b; |
19deea200358
Thm.add_axiom/add_def: return internal name of foundational axiom;
wenzelm
parents:
35988
diff
changeset
|
591 |
val axm' = Thm.axiom thy' axm_name; |
35988
76ca601c941e
disallow premises in primitive Theory.add_def -- handle in Thm.add_def;
wenzelm
parents:
35985
diff
changeset
|
592 |
val thm = |
76ca601c941e
disallow premises in primitive Theory.add_def -- handle in Thm.add_def;
wenzelm
parents:
35985
diff
changeset
|
593 |
Thm.instantiate (recover, []) axm' |
60825 | 594 |
|> unvarify_global thy' |
35988
76ca601c941e
disallow premises in primitive Theory.add_def -- handle in Thm.add_def;
wenzelm
parents:
35985
diff
changeset
|
595 |
|> fold_rev Thm.implies_intr prems; |
36106
19deea200358
Thm.add_axiom/add_def: return internal name of foundational axiom;
wenzelm
parents:
35988
diff
changeset
|
596 |
in ((axm_name, thm), thy') end; |
24980
16a74cfca971
added elim_implies (more convenient argument order);
wenzelm
parents:
24948
diff
changeset
|
597 |
|
42375
774df7c59508
report Name_Space.declare/define, relatively to context;
wenzelm
parents:
40238
diff
changeset
|
598 |
fun add_def_global unchecked overloaded arg thy = |
61262
7bd1eb4b056e
tuned signature: eliminated pointless type Context.pretty;
wenzelm
parents:
61261
diff
changeset
|
599 |
add_def (Defs.global_context thy) unchecked overloaded arg thy; |
42375
774df7c59508
report Name_Space.declare/define, relatively to context;
wenzelm
parents:
40238
diff
changeset
|
600 |
|
27866
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
wenzelm
parents:
27255
diff
changeset
|
601 |
|
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
wenzelm
parents:
27255
diff
changeset
|
602 |
|
70443 | 603 |
(** theorem tags **) |
27866
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
wenzelm
parents:
27255
diff
changeset
|
604 |
|
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
wenzelm
parents:
27255
diff
changeset
|
605 |
(* add / delete tags *) |
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
wenzelm
parents:
27255
diff
changeset
|
606 |
|
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
wenzelm
parents:
27255
diff
changeset
|
607 |
fun tag_rule tg = Thm.map_tags (insert (op =) tg); |
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
wenzelm
parents:
27255
diff
changeset
|
608 |
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:
27255
diff
changeset
|
609 |
|
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
wenzelm
parents:
27255
diff
changeset
|
610 |
|
61852 | 611 |
(* free dummy thm -- for abstract closure *) |
612 |
||
613 |
val free_dummyN = "free_dummy"; |
|
614 |
fun is_free_dummy thm = Properties.defined (Thm.get_tags thm) free_dummyN; |
|
615 |
val tag_free_dummy = tag_rule (free_dummyN, ""); |
|
616 |
||
617 |
||
30342 | 618 |
(* def_name *) |
619 |
||
620 |
fun def_name c = c ^ "_def"; |
|
621 |
||
622 |
fun def_name_optional c "" = def_name c |
|
623 |
| def_name_optional _ name = name; |
|
624 |
||
63041
cb495c4807b3
clarified def binding position: reset for implicit/derived binding, keep for explicit binding;
wenzelm
parents:
62093
diff
changeset
|
625 |
val def_binding = Binding.map_name def_name #> Binding.reset_pos; |
cb495c4807b3
clarified def binding position: reset for implicit/derived binding, keep for explicit binding;
wenzelm
parents:
62093
diff
changeset
|
626 |
fun def_binding_optional b name = if Binding.is_empty name then def_binding b else name; |
cb495c4807b3
clarified def binding position: reset for implicit/derived binding, keep for explicit binding;
wenzelm
parents:
62093
diff
changeset
|
627 |
fun make_def_binding cond b = if cond then def_binding b else Binding.empty; |
62093 | 628 |
|
30342 | 629 |
|
27866
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
wenzelm
parents:
27255
diff
changeset
|
630 |
(* unofficial theorem names *) |
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
wenzelm
parents:
27255
diff
changeset
|
631 |
|
68036
4c9e79aeadf0
tuned -- avoid spurious exception trace for "the";
wenzelm
parents:
67778
diff
changeset
|
632 |
fun has_name_hint thm = AList.defined (op =) (Thm.get_tags thm) Markup.nameN; |
27866
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
wenzelm
parents:
27255
diff
changeset
|
633 |
fun the_name_hint thm = the (AList.lookup (op =) (Thm.get_tags thm) Markup.nameN); |
68036
4c9e79aeadf0
tuned -- avoid spurious exception trace for "the";
wenzelm
parents:
67778
diff
changeset
|
634 |
fun get_name_hint thm = if has_name_hint thm then the_name_hint thm else "??.unknown"; |
27866
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
wenzelm
parents:
27255
diff
changeset
|
635 |
|
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
wenzelm
parents:
27255
diff
changeset
|
636 |
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:
27255
diff
changeset
|
637 |
|
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
wenzelm
parents:
27255
diff
changeset
|
638 |
|
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
wenzelm
parents:
27255
diff
changeset
|
639 |
(* theorem kinds *) |
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
wenzelm
parents:
27255
diff
changeset
|
640 |
|
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
wenzelm
parents:
27255
diff
changeset
|
641 |
val theoremK = "theorem"; |
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
wenzelm
parents:
27255
diff
changeset
|
642 |
|
42473 | 643 |
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:
27255
diff
changeset
|
644 |
|
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
wenzelm
parents:
27255
diff
changeset
|
645 |
fun kind_rule k = tag_rule (Markup.kindN, k) o untag_rule Markup.kindN; |
61853
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
646 |
|
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
647 |
|
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
648 |
|
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
649 |
(** attributes **) |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
650 |
|
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
651 |
(*attributes subsume any kind of rules or context modifiers*) |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
652 |
type attribute = Context.generic * thm -> Context.generic option * thm option; |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
653 |
|
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
654 |
type binding = binding * attribute list; |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
655 |
|
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
656 |
fun rule_attribute ths f (x, th) = |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
657 |
(NONE, |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
658 |
(case find_first is_free_dummy (th :: ths) of |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
659 |
SOME th' => SOME th' |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
660 |
| NONE => SOME (f x th))); |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
661 |
|
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
662 |
fun declaration_attribute f (x, th) = |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
663 |
(if is_free_dummy th then NONE else SOME (f th x), NONE); |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
664 |
|
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
665 |
fun mixed_attribute f (x, th) = |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
666 |
let val (x', th') = f (x, th) in (SOME x', SOME th') end; |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
667 |
|
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
668 |
fun apply_attribute (att: attribute) th x = |
67649 | 669 |
let val (x', th') = att (x, check_hyps x (Thm.transfer'' x th)) |
61853
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
670 |
in (the_default th th', the_default x x') end; |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
671 |
|
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
672 |
fun attribute_declaration att th x = #2 (apply_attribute att th x); |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
673 |
|
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
674 |
fun apply_attributes mk dest = |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
675 |
let |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
676 |
fun app [] th x = (th, x) |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
677 |
| app (att :: atts) th x = apply_attribute att th (mk x) ||> dest |-> app atts; |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
678 |
in app end; |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
679 |
|
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
680 |
val theory_attributes = apply_attributes Context.Theory Context.the_theory; |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
681 |
val proof_attributes = apply_attributes Context.Proof Context.the_proof; |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
682 |
|
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
683 |
fun no_attributes x = (x, []); |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
684 |
fun simple_fact x = [(x, [])]; |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
685 |
|
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
686 |
fun tag tg = rule_attribute [] (K (tag_rule tg)); |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
687 |
fun untag s = rule_attribute [] (K (untag_rule s)); |
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents:
61852
diff
changeset
|
688 |
fun kind k = rule_attribute [] (K (k <> "" ? kind_rule k)); |
27866
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
wenzelm
parents:
27255
diff
changeset
|
689 |
|
c721ea6e0eb4
moved basic thm operations from structure PureThy to Thm;
wenzelm
parents:
27255
diff
changeset
|
690 |
|
70443 | 691 |
|
692 |
(** forked proofs **) |
|
49010 | 693 |
|
49062
7e31dfd99ce7
discontinued complicated/unreliable notion of recent proofs within context;
wenzelm
parents:
49058
diff
changeset
|
694 |
structure Proofs = Theory_Data |
49010 | 695 |
( |
72048
d3b8c8b2d1fc
more thorough extend/merge (for Theory.join_theory);
wenzelm
parents:
71088
diff
changeset
|
696 |
type T = thm list lazy Inttab.table; |
d3b8c8b2d1fc
more thorough extend/merge (for Theory.join_theory);
wenzelm
parents:
71088
diff
changeset
|
697 |
val empty = Inttab.empty; |
d3b8c8b2d1fc
more thorough extend/merge (for Theory.join_theory);
wenzelm
parents:
71088
diff
changeset
|
698 |
val extend = I; |
d3b8c8b2d1fc
more thorough extend/merge (for Theory.join_theory);
wenzelm
parents:
71088
diff
changeset
|
699 |
val merge = Inttab.merge (K true); |
49010 | 700 |
); |
701 |
||
72048
d3b8c8b2d1fc
more thorough extend/merge (for Theory.join_theory);
wenzelm
parents:
71088
diff
changeset
|
702 |
fun reset_proofs thy = |
d3b8c8b2d1fc
more thorough extend/merge (for Theory.join_theory);
wenzelm
parents:
71088
diff
changeset
|
703 |
if Inttab.is_empty (Proofs.get thy) then NONE |
d3b8c8b2d1fc
more thorough extend/merge (for Theory.join_theory);
wenzelm
parents:
71088
diff
changeset
|
704 |
else SOME (Proofs.put Inttab.empty thy); |
d3b8c8b2d1fc
more thorough extend/merge (for Theory.join_theory);
wenzelm
parents:
71088
diff
changeset
|
705 |
|
d3b8c8b2d1fc
more thorough extend/merge (for Theory.join_theory);
wenzelm
parents:
71088
diff
changeset
|
706 |
val _ = Theory.setup (Theory.at_begin reset_proofs); |
61059 | 707 |
|
72048
d3b8c8b2d1fc
more thorough extend/merge (for Theory.join_theory);
wenzelm
parents:
71088
diff
changeset
|
708 |
fun register_proofs ths thy = |
d3b8c8b2d1fc
more thorough extend/merge (for Theory.join_theory);
wenzelm
parents:
71088
diff
changeset
|
709 |
let val entry = (serial (), Lazy.map_finished (map Thm.trim_context) ths) |
d3b8c8b2d1fc
more thorough extend/merge (for Theory.join_theory);
wenzelm
parents:
71088
diff
changeset
|
710 |
in (Proofs.map o Inttab.update) entry thy end; |
d3b8c8b2d1fc
more thorough extend/merge (for Theory.join_theory);
wenzelm
parents:
71088
diff
changeset
|
711 |
|
d3b8c8b2d1fc
more thorough extend/merge (for Theory.join_theory);
wenzelm
parents:
71088
diff
changeset
|
712 |
fun force_proofs thy = |
d3b8c8b2d1fc
more thorough extend/merge (for Theory.join_theory);
wenzelm
parents:
71088
diff
changeset
|
713 |
Proofs.get thy |> Inttab.dest |> maps (map (Thm.transfer thy) o Lazy.force o #2); |
71023
35a8e15b7e03
more robust Thm.expose_theory -- ensure that PIDE export happens in the proper theory context;
wenzelm
parents:
71018
diff
changeset
|
714 |
|
35a8e15b7e03
more robust Thm.expose_theory -- ensure that PIDE export happens in the proper theory context;
wenzelm
parents:
71018
diff
changeset
|
715 |
val consolidate_theory = Thm.consolidate o force_proofs; |
35a8e15b7e03
more robust Thm.expose_theory -- ensure that PIDE export happens in the proper theory context;
wenzelm
parents:
71018
diff
changeset
|
716 |
|
35a8e15b7e03
more robust Thm.expose_theory -- ensure that PIDE export happens in the proper theory context;
wenzelm
parents:
71018
diff
changeset
|
717 |
fun expose_theory thy = |
35a8e15b7e03
more robust Thm.expose_theory -- ensure that PIDE export happens in the proper theory context;
wenzelm
parents:
71018
diff
changeset
|
718 |
if Proofterm.export_enabled () |
35a8e15b7e03
more robust Thm.expose_theory -- ensure that PIDE export happens in the proper theory context;
wenzelm
parents:
71018
diff
changeset
|
719 |
then Thm.expose_proofs thy (force_proofs thy) else (); |
49010 | 720 |
|
721 |
||
61268 | 722 |
|
723 |
(** print theorems **) |
|
724 |
||
725 |
(* options *) |
|
726 |
||
69575 | 727 |
val show_consts = Config.declare_option_bool ("show_consts", \<^here>); |
728 |
val show_hyps = Config.declare_bool ("show_hyps", \<^here>) (K false); |
|
729 |
val show_tags = Config.declare_bool ("show_tags", \<^here>) (K false); |
|
61268 | 730 |
|
731 |
||
732 |
(* pretty_thm etc. *) |
|
733 |
||
734 |
fun pretty_tag (name, arg) = Pretty.strs [name, quote arg]; |
|
735 |
val pretty_tags = Pretty.list "[" "]" o map pretty_tag; |
|
736 |
||
737 |
fun pretty_thm_raw ctxt {quote, show_hyps = show_hyps'} raw_th = |
|
738 |
let |
|
739 |
val show_tags = Config.get ctxt show_tags; |
|
740 |
val show_hyps = Config.get ctxt show_hyps; |
|
741 |
||
742 |
val th = raw_th |
|
67649 | 743 |
|> perhaps (try (Thm.transfer' ctxt)) |
61268 | 744 |
|> perhaps (try Thm.strip_shyps); |
745 |
||
746 |
val hyps = if show_hyps then Thm.hyps_of th else undeclared_hyps (Context.Proof ctxt) th; |
|
61509
358dfae15d83
print thm wrt. local shyps (from full proof context);
wenzelm
parents:
61508
diff
changeset
|
747 |
val extra_shyps = extra_shyps' ctxt th; |
61268 | 748 |
val tags = Thm.get_tags th; |
749 |
val tpairs = Thm.tpairs_of th; |
|
750 |
||
751 |
val q = if quote then Pretty.quote else I; |
|
752 |
val prt_term = q o Syntax.pretty_term ctxt; |
|
753 |
||
754 |
||
755 |
val hlen = length extra_shyps + length hyps + length tpairs; |
|
756 |
val hsymbs = |
|
757 |
if hlen = 0 then [] |
|
758 |
else if show_hyps orelse show_hyps' then |
|
759 |
[Pretty.brk 2, Pretty.list "[" "]" |
|
70443 | 760 |
(map (q o Syntax.pretty_flexpair ctxt) tpairs @ map prt_term hyps @ |
61268 | 761 |
map (Syntax.pretty_sort ctxt) extra_shyps)] |
762 |
else [Pretty.brk 2, Pretty.str ("[" ^ replicate_string hlen "." ^ "]")]; |
|
763 |
val tsymbs = |
|
764 |
if null tags orelse not show_tags then [] |
|
765 |
else [Pretty.brk 1, pretty_tags tags]; |
|
766 |
in Pretty.block (prt_term (Thm.prop_of th) :: (hsymbs @ tsymbs)) end; |
|
767 |
||
768 |
fun pretty_thm ctxt = pretty_thm_raw ctxt {quote = false, show_hyps = true}; |
|
769 |
fun pretty_thm_item ctxt th = Pretty.item [pretty_thm ctxt th]; |
|
770 |
||
771 |
fun pretty_thm_global thy = |
|
772 |
pretty_thm_raw (Syntax.init_pretty_global thy) {quote = false, show_hyps = false}; |
|
773 |
||
774 |
val string_of_thm = Pretty.string_of oo pretty_thm; |
|
775 |
val string_of_thm_global = Pretty.string_of oo pretty_thm_global; |
|
776 |
||
777 |
||
22362
6470ce514b6e
Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff
changeset
|
778 |
open Thm; |
6470ce514b6e
Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff
changeset
|
779 |
|
6470ce514b6e
Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff
changeset
|
780 |
end; |
6470ce514b6e
Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff
changeset
|
781 |
|
32842 | 782 |
structure Basic_Thm: BASIC_THM = Thm; |
783 |
open Basic_Thm; |