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