author | wenzelm |
Thu, 25 Sep 2008 13:21:13 +0200 | |
changeset 28354 | c5fe7372ae4e |
parent 28330 | 7e803c392342 |
child 28356 | ac4498f95d1c |
permissions | -rw-r--r-- |
250 | 1 |
(* Title: Pure/thm.ML |
0 | 2 |
ID: $Id$ |
250 | 3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
225
diff
changeset
|
4 |
Copyright 1994 University of Cambridge |
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
225
diff
changeset
|
5 |
|
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
6 |
The very core of Isabelle's Meta Logic: certified types and terms, |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
7 |
derivations, theorems, framework rules (including lifting and |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
8 |
resolution), oracles. |
0 | 9 |
*) |
10 |
||
6089 | 11 |
signature BASIC_THM = |
1503 | 12 |
sig |
1160 | 13 |
(*certified types*) |
387
69f4356d915d
new datatype theory, supports 'draft theories' and incremental extension:
wenzelm
parents:
309
diff
changeset
|
14 |
type ctyp |
16656 | 15 |
val rep_ctyp: ctyp -> |
26631
d6b6c74a8bcf
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26424
diff
changeset
|
16 |
{thy_ref: theory_ref, |
16656 | 17 |
T: typ, |
20512 | 18 |
maxidx: int, |
28354 | 19 |
sorts: sort OrdList.T} |
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
20 |
val theory_of_ctyp: ctyp -> theory |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
21 |
val typ_of: ctyp -> typ |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
22 |
val ctyp_of: theory -> typ -> ctyp |
1160 | 23 |
|
24 |
(*certified terms*) |
|
25 |
type cterm |
|
22584 | 26 |
exception CTERM of string * cterm list |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
27 |
val rep_cterm: cterm -> |
26631
d6b6c74a8bcf
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26424
diff
changeset
|
28 |
{thy_ref: theory_ref, |
16656 | 29 |
t: term, |
30 |
T: typ, |
|
31 |
maxidx: int, |
|
28354 | 32 |
sorts: sort OrdList.T} |
33 |
val crep_cterm: cterm -> |
|
34 |
{thy_ref: theory_ref, t: term, T: ctyp, maxidx: int, sorts: sort OrdList.T} |
|
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
35 |
val theory_of_cterm: cterm -> theory |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
36 |
val term_of: cterm -> term |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
37 |
val cterm_of: theory -> term -> cterm |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
38 |
val ctyp_of_term: cterm -> ctyp |
1160 | 39 |
|
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
40 |
(*theorems*) |
1160 | 41 |
type thm |
23601 | 42 |
type conv = cterm -> thm |
43 |
type attribute = Context.generic * thm -> Context.generic * thm |
|
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
44 |
val rep_thm: thm -> |
26631
d6b6c74a8bcf
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26424
diff
changeset
|
45 |
{thy_ref: theory_ref, |
28017 | 46 |
tags: Properties.T, |
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
47 |
maxidx: int, |
28354 | 48 |
shyps: sort OrdList.T, |
49 |
hyps: term OrdList.T, |
|
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
50 |
tpairs: (term * term) list, |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
51 |
prop: term} |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
52 |
val crep_thm: thm -> |
26631
d6b6c74a8bcf
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26424
diff
changeset
|
53 |
{thy_ref: theory_ref, |
28017 | 54 |
tags: Properties.T, |
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
55 |
maxidx: int, |
28354 | 56 |
shyps: sort OrdList.T, |
57 |
hyps: cterm OrdList.T, |
|
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
58 |
tpairs: (cterm * cterm) list, |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
59 |
prop: cterm} |
6089 | 60 |
exception THM of string * int * thm list |
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
61 |
val theory_of_thm: thm -> theory |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
62 |
val prop_of: thm -> term |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
63 |
val tpairs_of: thm -> (term * term) list |
16656 | 64 |
val concl_of: thm -> term |
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
65 |
val prems_of: thm -> term list |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
66 |
val nprems_of: thm -> int |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
67 |
val cprop_of: thm -> cterm |
18145 | 68 |
val cprem_of: thm -> int -> cterm |
16656 | 69 |
val transfer: theory -> thm -> thm |
16945 | 70 |
val weaken: cterm -> thm -> thm |
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
71 |
val extra_shyps: thm -> sort list |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
72 |
val strip_shyps: thm -> thm |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
73 |
val get_axiom_i: theory -> string -> thm |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
74 |
val get_axiom: theory -> xstring -> thm |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
75 |
val def_name: string -> string |
20884 | 76 |
val def_name_optional: string -> string -> string |
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
77 |
val get_def: theory -> xstring -> thm |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
78 |
val axioms_of: theory -> (string * thm) list |
1160 | 79 |
|
80 |
(*meta rules*) |
|
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
81 |
val assume: cterm -> thm |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
82 |
val implies_intr: cterm -> thm -> thm |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
83 |
val implies_elim: thm -> thm -> thm |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
84 |
val forall_intr: cterm -> thm -> thm |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
85 |
val forall_elim: cterm -> thm -> thm |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
86 |
val reflexive: cterm -> thm |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
87 |
val symmetric: thm -> thm |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
88 |
val transitive: thm -> thm -> thm |
23601 | 89 |
val beta_conversion: bool -> conv |
90 |
val eta_conversion: conv |
|
91 |
val eta_long_conversion: conv |
|
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
92 |
val abstract_rule: string -> cterm -> thm -> thm |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
93 |
val combination: thm -> thm -> thm |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
94 |
val equal_intr: thm -> thm -> thm |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
95 |
val equal_elim: thm -> thm -> thm |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
96 |
val flexflex_rule: thm -> thm Seq.seq |
19910 | 97 |
val generalize: string list * string list -> int -> thm -> thm |
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
98 |
val instantiate: (ctyp * ctyp) list * (cterm * cterm) list -> thm -> thm |
22584 | 99 |
val instantiate_cterm: (ctyp * ctyp) list * (cterm * cterm) list -> cterm -> cterm |
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
100 |
val trivial: cterm -> thm |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
101 |
val class_triv: theory -> class -> thm |
19505 | 102 |
val unconstrainT: ctyp -> thm -> thm |
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
103 |
val dest_state: thm * int -> (term * term) list * term list * term * term |
18035 | 104 |
val lift_rule: cterm -> thm -> thm |
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
105 |
val incr_indexes: int -> thm -> thm |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
106 |
val assumption: int -> thm -> thm Seq.seq |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
107 |
val eq_assumption: int -> thm -> thm |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
108 |
val rotate_rule: int -> int -> thm -> thm |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
109 |
val permute_prems: int -> int -> thm -> thm |
1160 | 110 |
val rename_params_rule: string list * int -> thm -> thm |
18501
915105af2e80
turned bicompose_no_flatten into compose_no_flatten, without elimination;
wenzelm
parents:
18486
diff
changeset
|
111 |
val compose_no_flatten: bool -> thm * int -> int -> thm -> thm Seq.seq |
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
112 |
val bicompose: bool -> bool * thm * int -> int -> thm -> thm Seq.seq |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
113 |
val biresolution: bool -> (bool * thm) list -> int -> thm -> thm Seq.seq |
250 | 114 |
end; |
0 | 115 |
|
6089 | 116 |
signature THM = |
117 |
sig |
|
118 |
include BASIC_THM |
|
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
119 |
val dest_ctyp: ctyp -> ctyp list |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
120 |
val dest_comb: cterm -> cterm * cterm |
22909 | 121 |
val dest_fun: cterm -> cterm |
20580
6fb75df09253
added dest_arg, i.e. a tuned version of #2 o dest_comb;
wenzelm
parents:
20548
diff
changeset
|
122 |
val dest_arg: cterm -> cterm |
22909 | 123 |
val dest_fun2: cterm -> cterm |
124 |
val dest_arg1: cterm -> cterm |
|
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
125 |
val dest_abs: string option -> cterm -> cterm * cterm |
20261 | 126 |
val adjust_maxidx_cterm: int -> cterm -> cterm |
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
127 |
val capply: cterm -> cterm -> cterm |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
128 |
val cabs: cterm -> cterm -> cterm |
28330 | 129 |
val dest_deriv: thm -> |
130 |
{oracle: bool, |
|
131 |
proof: Proofterm.proof, |
|
28354 | 132 |
promises: (serial * (thm Future.T * theory * sort OrdList.T * term)) OrdList.T} |
28330 | 133 |
val oracle_of: thm -> bool |
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
134 |
val major_prem_of: thm -> term |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
135 |
val no_prems: thm -> bool |
16945 | 136 |
val terms_of_tpairs: (term * term) list -> term list |
19881 | 137 |
val maxidx_of: thm -> int |
19910 | 138 |
val maxidx_thm: thm -> int -> int |
19881 | 139 |
val hyps_of: thm -> term list |
16945 | 140 |
val full_prop_of: thm -> term |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
141 |
val get_name: thm -> string |
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
142 |
val put_name: string -> thm -> thm |
28017 | 143 |
val get_tags: thm -> Properties.T |
144 |
val map_tags: (Properties.T -> Properties.T) -> thm -> thm |
|
23781
ab793a6ddf9f
Added function norm_proof for normalizing the proof term
berghofe
parents:
23657
diff
changeset
|
145 |
val norm_proof: thm -> thm |
20261 | 146 |
val adjust_maxidx_thm: int -> thm -> thm |
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
147 |
val rename_boundvars: term -> term -> thm -> thm |
22909 | 148 |
val match: cterm * cterm -> (ctyp * ctyp) list * (cterm * cterm) list |
149 |
val first_order_match: cterm * cterm -> (ctyp * ctyp) list * (cterm * cterm) list |
|
150 |
val incr_indexes_cterm: int -> cterm -> cterm |
|
20002 | 151 |
val varifyT: thm -> thm |
152 |
val varifyT': (string * sort) list -> thm -> ((string * sort) * indexname) list * thm |
|
19881 | 153 |
val freezeT: thm -> thm |
28330 | 154 |
val promise: thm Future.T -> cterm -> thm |
155 |
val fulfill: thm -> thm |
|
156 |
val proof_of: thm -> Proofterm.proof |
|
157 |
val extern_oracles: theory -> xstring list |
|
158 |
val add_oracle: bstring * ('a -> cterm) -> theory -> (string * ('a -> thm)) * theory |
|
6089 | 159 |
end; |
160 |
||
3550 | 161 |
structure Thm: THM = |
0 | 162 |
struct |
250 | 163 |
|
22237
bb9b1c8a8a95
old-fashioned abstype ctyp/cterm/thm prevents accidental equality tests;
wenzelm
parents:
21975
diff
changeset
|
164 |
structure Pt = Proofterm; |
bb9b1c8a8a95
old-fashioned abstype ctyp/cterm/thm prevents accidental equality tests;
wenzelm
parents:
21975
diff
changeset
|
165 |
|
16656 | 166 |
|
387
69f4356d915d
new datatype theory, supports 'draft theories' and incremental extension:
wenzelm
parents:
309
diff
changeset
|
167 |
(*** Certified terms and types ***) |
69f4356d915d
new datatype theory, supports 'draft theories' and incremental extension:
wenzelm
parents:
309
diff
changeset
|
168 |
|
250 | 169 |
(** certified types **) |
170 |
||
22237
bb9b1c8a8a95
old-fashioned abstype ctyp/cterm/thm prevents accidental equality tests;
wenzelm
parents:
21975
diff
changeset
|
171 |
abstype ctyp = Ctyp of |
20512 | 172 |
{thy_ref: theory_ref, |
173 |
T: typ, |
|
174 |
maxidx: int, |
|
28354 | 175 |
sorts: sort OrdList.T} |
22237
bb9b1c8a8a95
old-fashioned abstype ctyp/cterm/thm prevents accidental equality tests;
wenzelm
parents:
21975
diff
changeset
|
176 |
with |
250 | 177 |
|
26631
d6b6c74a8bcf
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26424
diff
changeset
|
178 |
fun rep_ctyp (Ctyp args) = args; |
16656 | 179 |
fun theory_of_ctyp (Ctyp {thy_ref, ...}) = Theory.deref thy_ref; |
250 | 180 |
fun typ_of (Ctyp {T, ...}) = T; |
181 |
||
16656 | 182 |
fun ctyp_of thy raw_T = |
24143
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
183 |
let |
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
184 |
val T = Sign.certify_typ thy raw_T; |
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
185 |
val maxidx = Term.maxidx_of_typ T; |
26640
92e6d3ec91bd
simplified handling of sorts, removed unnecessary universal witness;
wenzelm
parents:
26631
diff
changeset
|
186 |
val sorts = Sorts.insert_typ T []; |
24143
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
187 |
in Ctyp {thy_ref = Theory.check_thy thy, T = T, maxidx = maxidx, sorts = sorts} end; |
250 | 188 |
|
20512 | 189 |
fun dest_ctyp (Ctyp {thy_ref, T = Type (s, Ts), maxidx, sorts}) = |
190 |
map (fn T => Ctyp {thy_ref = thy_ref, T = T, maxidx = maxidx, sorts = sorts}) Ts |
|
16679 | 191 |
| dest_ctyp cT = raise TYPE ("dest_ctyp", [typ_of cT], []); |
15087 | 192 |
|
229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
225
diff
changeset
|
193 |
|
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
225
diff
changeset
|
194 |
|
250 | 195 |
(** certified terms **) |
229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
225
diff
changeset
|
196 |
|
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
197 |
(*certified terms with checked typ, maxidx, and sorts*) |
22237
bb9b1c8a8a95
old-fashioned abstype ctyp/cterm/thm prevents accidental equality tests;
wenzelm
parents:
21975
diff
changeset
|
198 |
abstype cterm = Cterm of |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
199 |
{thy_ref: theory_ref, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
200 |
t: term, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
201 |
T: typ, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
202 |
maxidx: int, |
28354 | 203 |
sorts: sort OrdList.T} |
22237
bb9b1c8a8a95
old-fashioned abstype ctyp/cterm/thm prevents accidental equality tests;
wenzelm
parents:
21975
diff
changeset
|
204 |
with |
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
205 |
|
22584 | 206 |
exception CTERM of string * cterm list; |
16679 | 207 |
|
26631
d6b6c74a8bcf
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26424
diff
changeset
|
208 |
fun rep_cterm (Cterm args) = args; |
229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
225
diff
changeset
|
209 |
|
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
210 |
fun crep_cterm (Cterm {thy_ref, t, T, maxidx, sorts}) = |
26631
d6b6c74a8bcf
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26424
diff
changeset
|
211 |
{thy_ref = thy_ref, t = t, maxidx = maxidx, sorts = sorts, |
d6b6c74a8bcf
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26424
diff
changeset
|
212 |
T = Ctyp {thy_ref = thy_ref, T = T, maxidx = maxidx, sorts = sorts}}; |
3967
edd5ff9371f8
sg_ref: automatic adjustment of thms of draft theories;
wenzelm
parents:
3895
diff
changeset
|
213 |
|
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
214 |
fun theory_of_cterm (Cterm {thy_ref, ...}) = Theory.deref thy_ref; |
250 | 215 |
fun term_of (Cterm {t, ...}) = t; |
229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
225
diff
changeset
|
216 |
|
20512 | 217 |
fun ctyp_of_term (Cterm {thy_ref, T, maxidx, sorts, ...}) = |
218 |
Ctyp {thy_ref = thy_ref, T = T, maxidx = maxidx, sorts = sorts}; |
|
2671 | 219 |
|
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
220 |
fun cterm_of thy tm = |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
221 |
let |
18969 | 222 |
val (t, T, maxidx) = Sign.certify_term thy tm; |
26640
92e6d3ec91bd
simplified handling of sorts, removed unnecessary universal witness;
wenzelm
parents:
26631
diff
changeset
|
223 |
val sorts = Sorts.insert_term t []; |
24143
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
224 |
in Cterm {thy_ref = Theory.check_thy thy, t = t, T = T, maxidx = maxidx, sorts = sorts} end; |
229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
225
diff
changeset
|
225 |
|
20057 | 226 |
fun merge_thys0 (Cterm {thy_ref = r1, t = t1, ...}) (Cterm {thy_ref = r2, t = t2, ...}) = |
23601 | 227 |
Theory.merge_refs (r1, r2); |
16656 | 228 |
|
20580
6fb75df09253
added dest_arg, i.e. a tuned version of #2 o dest_comb;
wenzelm
parents:
20548
diff
changeset
|
229 |
|
22909 | 230 |
(* destructors *) |
231 |
||
232 |
fun dest_comb (ct as Cterm {t = c $ a, T, thy_ref, maxidx, sorts}) = |
|
233 |
let val A = Term.argument_type_of c 0 in |
|
234 |
(Cterm {t = c, T = A --> T, thy_ref = thy_ref, maxidx = maxidx, sorts = sorts}, |
|
235 |
Cterm {t = a, T = A, thy_ref = thy_ref, maxidx = maxidx, sorts = sorts}) |
|
1493
e936723cb94d
added dest_comb, dest_abs and mk_prop for manipulating cterms
clasohm
parents:
1460
diff
changeset
|
236 |
end |
22584 | 237 |
| dest_comb ct = raise CTERM ("dest_comb", [ct]); |
1493
e936723cb94d
added dest_comb, dest_abs and mk_prop for manipulating cterms
clasohm
parents:
1460
diff
changeset
|
238 |
|
22909 | 239 |
fun dest_fun (ct as Cterm {t = c $ _, T, thy_ref, maxidx, sorts}) = |
240 |
let val A = Term.argument_type_of c 0 |
|
241 |
in Cterm {t = c, T = A --> T, thy_ref = thy_ref, maxidx = maxidx, sorts = sorts} end |
|
242 |
| dest_fun ct = raise CTERM ("dest_fun", [ct]); |
|
243 |
||
244 |
fun dest_arg (ct as Cterm {t = c $ a, T = _, thy_ref, maxidx, sorts}) = |
|
245 |
let val A = Term.argument_type_of c 0 |
|
246 |
in Cterm {t = a, T = A, thy_ref = thy_ref, maxidx = maxidx, sorts = sorts} end |
|
22584 | 247 |
| dest_arg ct = raise CTERM ("dest_arg", [ct]); |
20580
6fb75df09253
added dest_arg, i.e. a tuned version of #2 o dest_comb;
wenzelm
parents:
20548
diff
changeset
|
248 |
|
22909 | 249 |
|
250 |
fun dest_fun2 (Cterm {t = c $ a $ b, T, thy_ref, maxidx, sorts}) = |
|
251 |
let |
|
252 |
val A = Term.argument_type_of c 0; |
|
253 |
val B = Term.argument_type_of c 1; |
|
254 |
in Cterm {t = c, T = A --> B --> T, thy_ref = thy_ref, maxidx = maxidx, sorts = sorts} end |
|
255 |
| dest_fun2 ct = raise CTERM ("dest_fun2", [ct]); |
|
256 |
||
257 |
fun dest_arg1 (Cterm {t = c $ a $ _, T = _, thy_ref, maxidx, sorts}) = |
|
258 |
let val A = Term.argument_type_of c 0 |
|
259 |
in Cterm {t = a, T = A, thy_ref = thy_ref, maxidx = maxidx, sorts = sorts} end |
|
260 |
| dest_arg1 ct = raise CTERM ("dest_arg1", [ct]); |
|
20673 | 261 |
|
22584 | 262 |
fun dest_abs a (ct as |
263 |
Cterm {t = Abs (x, T, t), T = Type ("fun", [_, U]), thy_ref, maxidx, sorts}) = |
|
18944 | 264 |
let val (y', t') = Term.dest_abs (the_default x a, T, t) in |
16679 | 265 |
(Cterm {t = Free (y', T), T = T, thy_ref = thy_ref, maxidx = maxidx, sorts = sorts}, |
266 |
Cterm {t = t', T = U, thy_ref = thy_ref, maxidx = maxidx, sorts = sorts}) |
|
1493
e936723cb94d
added dest_comb, dest_abs and mk_prop for manipulating cterms
clasohm
parents:
1460
diff
changeset
|
267 |
end |
22584 | 268 |
| dest_abs _ ct = raise CTERM ("dest_abs", [ct]); |
1493
e936723cb94d
added dest_comb, dest_abs and mk_prop for manipulating cterms
clasohm
parents:
1460
diff
changeset
|
269 |
|
22909 | 270 |
|
271 |
(* constructors *) |
|
272 |
||
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
273 |
fun capply |
16656 | 274 |
(cf as Cterm {t = f, T = Type ("fun", [dty, rty]), maxidx = maxidx1, sorts = sorts1, ...}) |
275 |
(cx as Cterm {t = x, T, maxidx = maxidx2, sorts = sorts2, ...}) = |
|
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
276 |
if T = dty then |
16656 | 277 |
Cterm {thy_ref = merge_thys0 cf cx, |
278 |
t = f $ x, |
|
279 |
T = rty, |
|
280 |
maxidx = Int.max (maxidx1, maxidx2), |
|
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
281 |
sorts = Sorts.union sorts1 sorts2} |
22584 | 282 |
else raise CTERM ("capply: types don't agree", [cf, cx]) |
283 |
| capply cf cx = raise CTERM ("capply: first arg is not a function", [cf, cx]); |
|
250 | 284 |
|
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
285 |
fun cabs |
16656 | 286 |
(ct1 as Cterm {t = t1, T = T1, maxidx = maxidx1, sorts = sorts1, ...}) |
287 |
(ct2 as Cterm {t = t2, T = T2, maxidx = maxidx2, sorts = sorts2, ...}) = |
|
21975
1152dc45d591
Term.lambda: abstract over arbitrary closed terms;
wenzelm
parents:
21798
diff
changeset
|
288 |
let val t = Term.lambda t1 t2 in |
16656 | 289 |
Cterm {thy_ref = merge_thys0 ct1 ct2, |
290 |
t = t, T = T1 --> T2, |
|
291 |
maxidx = Int.max (maxidx1, maxidx2), |
|
292 |
sorts = Sorts.union sorts1 sorts2} |
|
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
293 |
end; |
229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
225
diff
changeset
|
294 |
|
20580
6fb75df09253
added dest_arg, i.e. a tuned version of #2 o dest_comb;
wenzelm
parents:
20548
diff
changeset
|
295 |
|
22909 | 296 |
(* indexes *) |
297 |
||
20580
6fb75df09253
added dest_arg, i.e. a tuned version of #2 o dest_comb;
wenzelm
parents:
20548
diff
changeset
|
298 |
fun adjust_maxidx_cterm i (ct as Cterm {thy_ref, t, T, maxidx, sorts}) = |
6fb75df09253
added dest_arg, i.e. a tuned version of #2 o dest_comb;
wenzelm
parents:
20548
diff
changeset
|
299 |
if maxidx = i then ct |
6fb75df09253
added dest_arg, i.e. a tuned version of #2 o dest_comb;
wenzelm
parents:
20548
diff
changeset
|
300 |
else if maxidx < i then |
6fb75df09253
added dest_arg, i.e. a tuned version of #2 o dest_comb;
wenzelm
parents:
20548
diff
changeset
|
301 |
Cterm {maxidx = i, thy_ref = thy_ref, t = t, T = T, sorts = sorts} |
6fb75df09253
added dest_arg, i.e. a tuned version of #2 o dest_comb;
wenzelm
parents:
20548
diff
changeset
|
302 |
else |
6fb75df09253
added dest_arg, i.e. a tuned version of #2 o dest_comb;
wenzelm
parents:
20548
diff
changeset
|
303 |
Cterm {maxidx = Int.max (maxidx_of_term t, i), thy_ref = thy_ref, t = t, T = T, sorts = sorts}; |
6fb75df09253
added dest_arg, i.e. a tuned version of #2 o dest_comb;
wenzelm
parents:
20548
diff
changeset
|
304 |
|
22909 | 305 |
fun incr_indexes_cterm i (ct as Cterm {thy_ref, t, T, maxidx, sorts}) = |
306 |
if i < 0 then raise CTERM ("negative increment", [ct]) |
|
307 |
else if i = 0 then ct |
|
308 |
else Cterm {thy_ref = thy_ref, t = Logic.incr_indexes ([], i) t, |
|
309 |
T = Logic.incr_tvar i T, maxidx = maxidx + i, sorts = sorts}; |
|
310 |
||
311 |
||
312 |
(* matching *) |
|
313 |
||
314 |
local |
|
315 |
||
316 |
fun gen_match match |
|
20512 | 317 |
(ct1 as Cterm {t = t1, sorts = sorts1, ...}, |
20815 | 318 |
ct2 as Cterm {t = t2, sorts = sorts2, maxidx = maxidx2, ...}) = |
10416
5b33e732e459
- Moved rewriting functions to meta_simplifier.ML
berghofe
parents:
10348
diff
changeset
|
319 |
let |
24143
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
320 |
val thy = Theory.deref (merge_thys0 ct1 ct2); |
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
321 |
val (Tinsts, tinsts) = match thy (t1, t2) (Vartab.empty, Vartab.empty); |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
322 |
val sorts = Sorts.union sorts1 sorts2; |
20512 | 323 |
fun mk_cTinst ((a, i), (S, T)) = |
24143
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
324 |
(Ctyp {T = TVar ((a, i), S), thy_ref = Theory.check_thy thy, maxidx = i, sorts = sorts}, |
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
325 |
Ctyp {T = T, thy_ref = Theory.check_thy thy, maxidx = maxidx2, sorts = sorts}); |
20512 | 326 |
fun mk_ctinst ((x, i), (T, t)) = |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
327 |
let val T = Envir.typ_subst_TVars Tinsts T in |
24143
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
328 |
(Cterm {t = Var ((x, i), T), T = T, thy_ref = Theory.check_thy thy, |
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
329 |
maxidx = i, sorts = sorts}, |
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
330 |
Cterm {t = t, T = T, thy_ref = Theory.check_thy thy, maxidx = maxidx2, sorts = sorts}) |
10416
5b33e732e459
- Moved rewriting functions to meta_simplifier.ML
berghofe
parents:
10348
diff
changeset
|
331 |
end; |
16656 | 332 |
in (Vartab.fold (cons o mk_cTinst) Tinsts [], Vartab.fold (cons o mk_ctinst) tinsts []) end; |
10416
5b33e732e459
- Moved rewriting functions to meta_simplifier.ML
berghofe
parents:
10348
diff
changeset
|
333 |
|
22909 | 334 |
in |
10416
5b33e732e459
- Moved rewriting functions to meta_simplifier.ML
berghofe
parents:
10348
diff
changeset
|
335 |
|
22909 | 336 |
val match = gen_match Pattern.match; |
337 |
val first_order_match = gen_match Pattern.first_order_match; |
|
338 |
||
339 |
end; |
|
10416
5b33e732e459
- Moved rewriting functions to meta_simplifier.ML
berghofe
parents:
10348
diff
changeset
|
340 |
|
2509 | 341 |
|
342 |
||
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
343 |
(*** Derivations and Theorems ***) |
229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
225
diff
changeset
|
344 |
|
28330 | 345 |
abstype thm = Thm of |
28354 | 346 |
deriv * (*derivation*) |
347 |
{thy_ref: theory_ref, (*dynamic reference to theory*) |
|
348 |
tags: Properties.T, (*additional annotations/comments*) |
|
349 |
maxidx: int, (*maximum index of any Var or TVar*) |
|
350 |
shyps: sort OrdList.T, (*sort hypotheses*) |
|
351 |
hyps: term OrdList.T, (*hypotheses*) |
|
352 |
tpairs: (term * term) list, (*flex-flex pairs*) |
|
353 |
prop: term} (*conclusion*) |
|
354 |
and deriv = Deriv of |
|
355 |
{oracle: bool, (*oracle occurrence flag*) |
|
356 |
proof: Pt.proof, (*proof term*) |
|
357 |
promises: (serial * promise) OrdList.T} (*promised derivations*) |
|
28330 | 358 |
and promise = Promise of |
28354 | 359 |
thm Future.T * theory * sort OrdList.T * term |
22237
bb9b1c8a8a95
old-fashioned abstype ctyp/cterm/thm prevents accidental equality tests;
wenzelm
parents:
21975
diff
changeset
|
360 |
with |
0 | 361 |
|
23601 | 362 |
type conv = cterm -> thm; |
363 |
||
22365 | 364 |
(*attributes subsume any kind of rules or context modifiers*) |
365 |
type attribute = Context.generic * thm -> Context.generic * thm; |
|
366 |
||
16725 | 367 |
(*errors involving theorems*) |
368 |
exception THM of string * int * thm list; |
|
13658
c9ad3e64ddcf
Changed handling of flex-flex constraints: now stored in separate
berghofe
parents:
13642
diff
changeset
|
369 |
|
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
370 |
fun rep_thm (Thm (_, args)) = args; |
0 | 371 |
|
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
372 |
fun crep_thm (Thm (_, {thy_ref, tags, maxidx, shyps, hyps, tpairs, prop})) = |
26631
d6b6c74a8bcf
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26424
diff
changeset
|
373 |
let fun cterm max t = Cterm {thy_ref = thy_ref, t = t, T = propT, maxidx = max, sorts = shyps} in |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
374 |
{thy_ref = thy_ref, tags = tags, maxidx = maxidx, shyps = shyps, |
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
375 |
hyps = map (cterm ~1) hyps, |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
376 |
tpairs = map (pairself (cterm maxidx)) tpairs, |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
377 |
prop = cterm maxidx prop} |
1517 | 378 |
end; |
379 |
||
16725 | 380 |
fun terms_of_tpairs tpairs = fold_rev (fn (t, u) => cons t o cons u) tpairs []; |
381 |
||
382 |
fun eq_tpairs ((t, u), (t', u')) = t aconv t' andalso u aconv u'; |
|
18944 | 383 |
fun union_tpairs ts us = Library.merge eq_tpairs (ts, us); |
16884
1678a796b6b2
tuned instantiate (avoid subst_atomic, subst_atomic_types);
wenzelm
parents:
16847
diff
changeset
|
384 |
val maxidx_tpairs = fold (fn (t, u) => Term.maxidx_term t #> Term.maxidx_term u); |
16725 | 385 |
|
386 |
fun attach_tpairs tpairs prop = |
|
387 |
Logic.list_implies (map Logic.mk_equals tpairs, prop); |
|
388 |
||
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
389 |
fun full_prop_of (Thm (_, {tpairs, prop, ...})) = attach_tpairs tpairs prop; |
16945 | 390 |
|
22365 | 391 |
val union_hyps = OrdList.union Term.fast_term_ord; |
28354 | 392 |
val insert_hyps = OrdList.insert Term.fast_term_ord; |
393 |
val remove_hyps = OrdList.remove Term.fast_term_ord; |
|
22365 | 394 |
|
16945 | 395 |
|
24143
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
396 |
(* merge theories of cterms/thms -- trivial absorption only *) |
16945 | 397 |
|
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
398 |
fun merge_thys1 (Cterm {thy_ref = r1, ...}) (th as Thm (_, {thy_ref = r2, ...})) = |
23601 | 399 |
Theory.merge_refs (r1, r2); |
16945 | 400 |
|
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
401 |
fun merge_thys2 (th1 as Thm (_, {thy_ref = r1, ...})) (th2 as Thm (_, {thy_ref = r2, ...})) = |
23601 | 402 |
Theory.merge_refs (r1, r2); |
16945 | 403 |
|
0 | 404 |
|
22365 | 405 |
(* basic components *) |
16135 | 406 |
|
28330 | 407 |
fun dest_deriv (Thm (Deriv {oracle, proof, promises}, _)) = |
408 |
{oracle = oracle, proof = proof, promises = map (fn (i, Promise args) => (i, args)) promises}; |
|
409 |
||
410 |
fun oracle_of (Thm (Deriv {oracle, ...}, _)) = oracle; |
|
411 |
||
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
412 |
val theory_of_thm = Theory.deref o #thy_ref o rep_thm; |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
413 |
val maxidx_of = #maxidx o rep_thm; |
19910 | 414 |
fun maxidx_thm th i = Int.max (maxidx_of th, i); |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
415 |
val hyps_of = #hyps o rep_thm; |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
416 |
val prop_of = #prop o rep_thm; |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
417 |
val tpairs_of = #tpairs o rep_thm; |
0 | 418 |
|
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
419 |
val concl_of = Logic.strip_imp_concl o prop_of; |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
420 |
val prems_of = Logic.strip_imp_prems o prop_of; |
21576 | 421 |
val nprems_of = Logic.count_prems o prop_of; |
19305 | 422 |
fun no_prems th = nprems_of th = 0; |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
423 |
|
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
424 |
fun major_prem_of th = |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
425 |
(case prems_of th of |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
426 |
prem :: _ => Logic.strip_assums_concl prem |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
427 |
| [] => raise THM ("major_prem_of: rule with no premises", 0, [th])); |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
428 |
|
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
429 |
(*the statement of any thm is a cterm*) |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
430 |
fun cprop_of (Thm (_, {thy_ref, maxidx, shyps, prop, ...})) = |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
431 |
Cterm {thy_ref = thy_ref, maxidx = maxidx, T = propT, t = prop, sorts = shyps}; |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
432 |
|
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
433 |
fun cprem_of (th as Thm (_, {thy_ref, maxidx, shyps, prop, ...})) i = |
18035 | 434 |
Cterm {thy_ref = thy_ref, maxidx = maxidx, T = propT, sorts = shyps, |
18145 | 435 |
t = Logic.nth_prem (i, prop) handle TERM _ => raise THM ("cprem_of", i, [th])}; |
18035 | 436 |
|
16656 | 437 |
(*explicit transfer to a super theory*) |
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
438 |
fun transfer thy' thm = |
3895 | 439 |
let |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
440 |
val Thm (der, {thy_ref, tags, maxidx, shyps, hyps, tpairs, prop}) = thm; |
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
441 |
val thy = Theory.deref thy_ref; |
26665 | 442 |
val _ = Theory.subthy (thy, thy') orelse raise THM ("transfer: not a super theory", 0, [thm]); |
443 |
val is_eq = Theory.eq_thy (thy, thy'); |
|
24143
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
444 |
val _ = Theory.check_thy thy; |
3895 | 445 |
in |
24143
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
446 |
if is_eq then thm |
16945 | 447 |
else |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
448 |
Thm (der, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
449 |
{thy_ref = Theory.check_thy thy', |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
450 |
tags = tags, |
16945 | 451 |
maxidx = maxidx, |
452 |
shyps = shyps, |
|
453 |
hyps = hyps, |
|
454 |
tpairs = tpairs, |
|
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
455 |
prop = prop}) |
3895 | 456 |
end; |
387
69f4356d915d
new datatype theory, supports 'draft theories' and incremental extension:
wenzelm
parents:
309
diff
changeset
|
457 |
|
16945 | 458 |
(*explicit weakening: maps |- B to A |- B*) |
459 |
fun weaken raw_ct th = |
|
460 |
let |
|
20261 | 461 |
val ct as Cterm {t = A, T, sorts, maxidx = maxidxA, ...} = adjust_maxidx_cterm ~1 raw_ct; |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
462 |
val Thm (der, {tags, maxidx, shyps, hyps, tpairs, prop, ...}) = th; |
16945 | 463 |
in |
464 |
if T <> propT then |
|
465 |
raise THM ("weaken: assumptions must have type prop", 0, []) |
|
466 |
else if maxidxA <> ~1 then |
|
467 |
raise THM ("weaken: assumptions may not contain schematic variables", maxidxA, []) |
|
468 |
else |
|
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
469 |
Thm (der, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
470 |
{thy_ref = merge_thys1 ct th, |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
471 |
tags = tags, |
16945 | 472 |
maxidx = maxidx, |
473 |
shyps = Sorts.union sorts shyps, |
|
28354 | 474 |
hyps = insert_hyps A hyps, |
16945 | 475 |
tpairs = tpairs, |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
476 |
prop = prop}) |
16945 | 477 |
end; |
16656 | 478 |
|
479 |
||
0 | 480 |
|
1238 | 481 |
(** sort contexts of theorems **) |
482 |
||
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
483 |
fun present_sorts (Thm (_, {hyps, tpairs, prop, ...})) = |
16656 | 484 |
fold (fn (t, u) => Sorts.insert_term t o Sorts.insert_term u) tpairs |
485 |
(Sorts.insert_terms hyps (Sorts.insert_term prop [])); |
|
1238 | 486 |
|
7642 | 487 |
(*remove extra sorts that are non-empty by virtue of type signature information*) |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
488 |
fun strip_shyps (thm as Thm (_, {shyps = [], ...})) = thm |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
489 |
| strip_shyps (thm as Thm (der, {thy_ref, tags, maxidx, shyps, hyps, tpairs, prop})) = |
7642 | 490 |
let |
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
491 |
val thy = Theory.deref thy_ref; |
26640
92e6d3ec91bd
simplified handling of sorts, removed unnecessary universal witness;
wenzelm
parents:
26631
diff
changeset
|
492 |
val present = present_sorts thm; |
92e6d3ec91bd
simplified handling of sorts, removed unnecessary universal witness;
wenzelm
parents:
26631
diff
changeset
|
493 |
val extra = Sorts.subtract present shyps; |
92e6d3ec91bd
simplified handling of sorts, removed unnecessary universal witness;
wenzelm
parents:
26631
diff
changeset
|
494 |
val shyps' = Sorts.subtract (map #2 (Sign.witness_sorts thy present extra)) shyps; |
7642 | 495 |
in |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
496 |
Thm (der, {thy_ref = Theory.check_thy thy, tags = tags, maxidx = maxidx, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
497 |
shyps = shyps', hyps = hyps, tpairs = tpairs, prop = prop}) |
7642 | 498 |
end; |
1238 | 499 |
|
16656 | 500 |
(*dangling sort constraints of a thm*) |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
501 |
fun extra_shyps (th as Thm (_, {shyps, ...})) = Sorts.subtract (present_sorts th) shyps; |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
502 |
|
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
503 |
|
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
504 |
|
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
505 |
(** derivations **) |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
506 |
|
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
507 |
fun make_deriv oracle promises proof = |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
508 |
Deriv {oracle = oracle, promises = promises, proof = proof}; |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
509 |
|
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
510 |
val empty_deriv = make_deriv false [] Pt.min_proof; |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
511 |
|
28330 | 512 |
|
28354 | 513 |
(* inference rules *) |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
514 |
|
28330 | 515 |
fun promise_ord ((i, Promise _), (j, Promise _)) = int_ord (j, i); |
516 |
||
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
517 |
fun deriv_rule2 f |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
518 |
(Deriv {oracle = ora1, promises = ps1, proof = prf1}) |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
519 |
(Deriv {oracle = ora2, promises = ps2, proof = prf2}) = |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
520 |
let |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
521 |
val ora = ora1 orelse ora2; |
28330 | 522 |
val ps = OrdList.union promise_ord ps1 ps2; |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
523 |
val prf = |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
524 |
(case ! Pt.proofs of |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
525 |
2 => f prf1 prf2 |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
526 |
| 1 => MinProof (([], [], []) |> Pt.mk_min_proof prf1 |> Pt.mk_min_proof prf2) |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
527 |
| 0 => |
28330 | 528 |
if ora then MinProof ([], [], [] |> Pt.add_oracles ora1 prf1 |> Pt.add_oracles ora2 prf2) |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
529 |
else Pt.min_proof |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
530 |
| i => error ("Illegal level of detail for proof objects: " ^ string_of_int i)); |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
531 |
in make_deriv ora ps prf end; |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
532 |
|
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
533 |
fun deriv_rule1 f = deriv_rule2 (K f) empty_deriv; |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
534 |
fun deriv_rule0 prf = deriv_rule1 I (make_deriv false [] prf); |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
535 |
|
1238 | 536 |
|
537 |
||
1529 | 538 |
(** Axioms **) |
387
69f4356d915d
new datatype theory, supports 'draft theories' and incremental extension:
wenzelm
parents:
309
diff
changeset
|
539 |
|
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
540 |
(*look up the named axiom in the theory or its ancestors*) |
15672 | 541 |
fun get_axiom_i theory name = |
387
69f4356d915d
new datatype theory, supports 'draft theories' and incremental extension:
wenzelm
parents:
309
diff
changeset
|
542 |
let |
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
543 |
fun get_ax thy = |
22685 | 544 |
Symtab.lookup (Theory.axiom_table thy) name |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
545 |
|> Option.map (fn prop => |
24143
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
546 |
let |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
547 |
val der = deriv_rule0 (Pt.axm_proof name prop); |
24143
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
548 |
val maxidx = maxidx_of_term prop; |
26640
92e6d3ec91bd
simplified handling of sorts, removed unnecessary universal witness;
wenzelm
parents:
26631
diff
changeset
|
549 |
val shyps = Sorts.insert_term prop []; |
24143
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
550 |
in |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
551 |
Thm (der, {thy_ref = Theory.check_thy thy, tags = [], |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
552 |
maxidx = maxidx, shyps = shyps, hyps = [], tpairs = [], prop = prop}) |
24143
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
553 |
end); |
387
69f4356d915d
new datatype theory, supports 'draft theories' and incremental extension:
wenzelm
parents:
309
diff
changeset
|
554 |
in |
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
555 |
(case get_first get_ax (theory :: Theory.ancestors_of theory) of |
15531 | 556 |
SOME thm => thm |
557 |
| NONE => raise THEORY ("No axiom " ^ quote name, [theory])) |
|
387
69f4356d915d
new datatype theory, supports 'draft theories' and incremental extension:
wenzelm
parents:
309
diff
changeset
|
558 |
end; |
69f4356d915d
new datatype theory, supports 'draft theories' and incremental extension:
wenzelm
parents:
309
diff
changeset
|
559 |
|
16352 | 560 |
fun get_axiom thy = |
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
561 |
get_axiom_i thy o NameSpace.intern (Theory.axiom_space thy); |
15672 | 562 |
|
20884 | 563 |
fun def_name c = c ^ "_def"; |
564 |
||
565 |
fun def_name_optional c "" = def_name c |
|
566 |
| def_name_optional _ name = name; |
|
567 |
||
6368 | 568 |
fun get_def thy = get_axiom thy o def_name; |
4847 | 569 |
|
1529 | 570 |
|
776
df8f91c0e57c
improved axioms_of: returns thms as the manual says;
wenzelm
parents:
721
diff
changeset
|
571 |
(*return additional axioms of this theory node*) |
df8f91c0e57c
improved axioms_of: returns thms as the manual says;
wenzelm
parents:
721
diff
changeset
|
572 |
fun axioms_of thy = |
22685 | 573 |
map (fn s => (s, get_axiom_i thy s)) (Symtab.keys (Theory.axiom_table thy)); |
776
df8f91c0e57c
improved axioms_of: returns thms as the manual says;
wenzelm
parents:
721
diff
changeset
|
574 |
|
6089 | 575 |
|
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
576 |
(* official name and additional tags *) |
6089 | 577 |
|
28330 | 578 |
fun get_name (Thm (Deriv {proof, ...}, {hyps, prop, ...})) = Pt.get_name hyps prop proof; |
4018 | 579 |
|
28330 | 580 |
fun put_name name thm = |
581 |
let |
|
582 |
val Thm (Deriv {oracle, promises, proof}, args as {thy_ref, hyps, prop, tpairs, ...}) = thm; |
|
583 |
val _ = null tpairs orelse raise THM ("name_thm: unsolved flex-flex constraints", 0, [thm]); |
|
584 |
val thy = Theory.deref thy_ref; |
|
585 |
val der' = make_deriv oracle promises (Pt.thm_proof thy name hyps prop proof); |
|
586 |
val _ = Theory.check_thy thy; |
|
587 |
in Thm (der', args) end; |
|
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
588 |
|
6089 | 589 |
|
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
590 |
val get_tags = #tags o rep_thm; |
6089 | 591 |
|
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
592 |
fun map_tags f (Thm (der, {thy_ref, tags, maxidx, shyps, hyps, tpairs, prop})) = |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
593 |
Thm (der, {thy_ref = thy_ref, tags = f tags, maxidx = maxidx, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
594 |
shyps = shyps, hyps = hyps, tpairs = tpairs, prop = prop}); |
0 | 595 |
|
596 |
||
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
597 |
fun norm_proof (Thm (der, args as {thy_ref, ...})) = |
24143
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
598 |
let |
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
599 |
val thy = Theory.deref thy_ref; |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
600 |
val der' = deriv_rule1 (Pt.rew_proof thy) der; |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
601 |
val _ = Theory.check_thy thy; |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
602 |
in Thm (der', args) end; |
23781
ab793a6ddf9f
Added function norm_proof for normalizing the proof term
berghofe
parents:
23657
diff
changeset
|
603 |
|
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
604 |
fun adjust_maxidx_thm i (th as Thm (der, {thy_ref, tags, maxidx, shyps, hyps, tpairs, prop})) = |
20261 | 605 |
if maxidx = i then th |
606 |
else if maxidx < i then |
|
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
607 |
Thm (der, {maxidx = i, thy_ref = thy_ref, tags = tags, shyps = shyps, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
608 |
hyps = hyps, tpairs = tpairs, prop = prop}) |
20261 | 609 |
else |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
610 |
Thm (der, {maxidx = Int.max (maxidx_tpairs tpairs (maxidx_of_term prop), i), thy_ref = thy_ref, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
611 |
tags = tags, shyps = shyps, hyps = hyps, tpairs = tpairs, prop = prop}); |
564 | 612 |
|
387
69f4356d915d
new datatype theory, supports 'draft theories' and incremental extension:
wenzelm
parents:
309
diff
changeset
|
613 |
|
2509 | 614 |
|
1529 | 615 |
(*** Meta rules ***) |
0 | 616 |
|
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
617 |
(** primitive rules **) |
0 | 618 |
|
16656 | 619 |
(*The assumption rule A |- A*) |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
620 |
fun assume raw_ct = |
20261 | 621 |
let val Cterm {thy_ref, t = prop, T, maxidx, sorts} = adjust_maxidx_cterm ~1 raw_ct in |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
622 |
if T <> propT then |
19230 | 623 |
raise THM ("assume: prop", 0, []) |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
624 |
else if maxidx <> ~1 then |
19230 | 625 |
raise THM ("assume: variables", maxidx, []) |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
626 |
else Thm (deriv_rule0 (Pt.Hyp prop), |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
627 |
{thy_ref = thy_ref, |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
628 |
tags = [], |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
629 |
maxidx = ~1, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
630 |
shyps = sorts, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
631 |
hyps = [prop], |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
632 |
tpairs = [], |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
633 |
prop = prop}) |
0 | 634 |
end; |
635 |
||
1220 | 636 |
(*Implication introduction |
3529 | 637 |
[A] |
638 |
: |
|
639 |
B |
|
1220 | 640 |
------- |
641 |
A ==> B |
|
642 |
*) |
|
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
643 |
fun implies_intr |
16679 | 644 |
(ct as Cterm {t = A, T, maxidx = maxidxA, sorts, ...}) |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
645 |
(th as Thm (der, {maxidx, hyps, shyps, tpairs, prop, ...})) = |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
646 |
if T <> propT then |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
647 |
raise THM ("implies_intr: assumptions must have type prop", 0, [th]) |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
648 |
else |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
649 |
Thm (deriv_rule1 (Pt.implies_intr_proof A) der, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
650 |
{thy_ref = merge_thys1 ct th, |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
651 |
tags = [], |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
652 |
maxidx = Int.max (maxidxA, maxidx), |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
653 |
shyps = Sorts.union sorts shyps, |
28354 | 654 |
hyps = remove_hyps A hyps, |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
655 |
tpairs = tpairs, |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
656 |
prop = Logic.mk_implies (A, prop)}); |
0 | 657 |
|
1529 | 658 |
|
1220 | 659 |
(*Implication elimination |
660 |
A ==> B A |
|
661 |
------------ |
|
662 |
B |
|
663 |
*) |
|
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
664 |
fun implies_elim thAB thA = |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
665 |
let |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
666 |
val Thm (derA, {maxidx = maxA, hyps = hypsA, shyps = shypsA, tpairs = tpairsA, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
667 |
prop = propA, ...}) = thA |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
668 |
and Thm (der, {maxidx, hyps, shyps, tpairs, prop, ...}) = thAB; |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
669 |
fun err () = raise THM ("implies_elim: major premise", 0, [thAB, thA]); |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
670 |
in |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
671 |
case prop of |
20512 | 672 |
Const ("==>", _) $ A $ B => |
673 |
if A aconv propA then |
|
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
674 |
Thm (deriv_rule2 (curry Pt.%%) der derA, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
675 |
{thy_ref = merge_thys2 thAB thA, |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
676 |
tags = [], |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
677 |
maxidx = Int.max (maxA, maxidx), |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
678 |
shyps = Sorts.union shypsA shyps, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
679 |
hyps = union_hyps hypsA hyps, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
680 |
tpairs = union_tpairs tpairsA tpairs, |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
681 |
prop = B}) |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
682 |
else err () |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
683 |
| _ => err () |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
684 |
end; |
250 | 685 |
|
1220 | 686 |
(*Forall introduction. The Free or Var x must not be free in the hypotheses. |
16656 | 687 |
[x] |
688 |
: |
|
689 |
A |
|
690 |
------ |
|
691 |
!!x. A |
|
1220 | 692 |
*) |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
693 |
fun forall_intr |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
694 |
(ct as Cterm {t = x, T, sorts, ...}) |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
695 |
(th as Thm (der, {maxidx, shyps, hyps, tpairs, prop, ...})) = |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
696 |
let |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
697 |
fun result a = |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
698 |
Thm (deriv_rule1 (Pt.forall_intr_proof x a) der, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
699 |
{thy_ref = merge_thys1 ct th, |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
700 |
tags = [], |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
701 |
maxidx = maxidx, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
702 |
shyps = Sorts.union sorts shyps, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
703 |
hyps = hyps, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
704 |
tpairs = tpairs, |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
705 |
prop = Term.all T $ Abs (a, T, abstract_over (x, prop))}); |
21798 | 706 |
fun check_occs a x ts = |
16847
8fc160b12e73
invoke_oracle: do not keep theory value, but theory_ref;
wenzelm
parents:
16725
diff
changeset
|
707 |
if exists (fn t => Logic.occs (x, t)) ts then |
21798 | 708 |
raise THM ("forall_intr: variable " ^ quote a ^ " free in assumptions", 0, [th]) |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
709 |
else (); |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
710 |
in |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
711 |
case x of |
21798 | 712 |
Free (a, _) => (check_occs a x hyps; check_occs a x (terms_of_tpairs tpairs); result a) |
713 |
| Var ((a, _), _) => (check_occs a x (terms_of_tpairs tpairs); result a) |
|
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
714 |
| _ => raise THM ("forall_intr: not a variable", 0, [th]) |
0 | 715 |
end; |
716 |
||
1220 | 717 |
(*Forall elimination |
16656 | 718 |
!!x. A |
1220 | 719 |
------ |
720 |
A[t/x] |
|
721 |
*) |
|
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
722 |
fun forall_elim |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
723 |
(ct as Cterm {t, T, maxidx = maxt, sorts, ...}) |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
724 |
(th as Thm (der, {maxidx, shyps, hyps, tpairs, prop, ...})) = |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
725 |
(case prop of |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
726 |
Const ("all", Type ("fun", [Type ("fun", [qary, _]), _])) $ A => |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
727 |
if T <> qary then |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
728 |
raise THM ("forall_elim: type mismatch", 0, [th]) |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
729 |
else |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
730 |
Thm (deriv_rule1 (Pt.% o rpair (SOME t)) der, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
731 |
{thy_ref = merge_thys1 ct th, |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
732 |
tags = [], |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
733 |
maxidx = Int.max (maxidx, maxt), |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
734 |
shyps = Sorts.union sorts shyps, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
735 |
hyps = hyps, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
736 |
tpairs = tpairs, |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
737 |
prop = Term.betapply (A, t)}) |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
738 |
| _ => raise THM ("forall_elim: not quantified", 0, [th])); |
0 | 739 |
|
740 |
||
1220 | 741 |
(* Equality *) |
0 | 742 |
|
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
743 |
(*Reflexivity |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
744 |
t == t |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
745 |
*) |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
746 |
fun reflexive (ct as Cterm {thy_ref, t, T, maxidx, sorts}) = |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
747 |
Thm (deriv_rule0 Pt.reflexive, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
748 |
{thy_ref = thy_ref, |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
749 |
tags = [], |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
750 |
maxidx = maxidx, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
751 |
shyps = sorts, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
752 |
hyps = [], |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
753 |
tpairs = [], |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
754 |
prop = Logic.mk_equals (t, t)}); |
0 | 755 |
|
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
756 |
(*Symmetry |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
757 |
t == u |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
758 |
------ |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
759 |
u == t |
1220 | 760 |
*) |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
761 |
fun symmetric (th as Thm (der, {thy_ref, maxidx, shyps, hyps, tpairs, prop, ...})) = |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
762 |
(case prop of |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
763 |
(eq as Const ("==", Type (_, [T, _]))) $ t $ u => |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
764 |
Thm (deriv_rule1 Pt.symmetric der, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
765 |
{thy_ref = thy_ref, |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
766 |
tags = [], |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
767 |
maxidx = maxidx, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
768 |
shyps = shyps, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
769 |
hyps = hyps, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
770 |
tpairs = tpairs, |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
771 |
prop = eq $ u $ t}) |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
772 |
| _ => raise THM ("symmetric", 0, [th])); |
0 | 773 |
|
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
774 |
(*Transitivity |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
775 |
t1 == u u == t2 |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
776 |
------------------ |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
777 |
t1 == t2 |
1220 | 778 |
*) |
0 | 779 |
fun transitive th1 th2 = |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
780 |
let |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
781 |
val Thm (der1, {maxidx = max1, hyps = hyps1, shyps = shyps1, tpairs = tpairs1, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
782 |
prop = prop1, ...}) = th1 |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
783 |
and Thm (der2, {maxidx = max2, hyps = hyps2, shyps = shyps2, tpairs = tpairs2, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
784 |
prop = prop2, ...}) = th2; |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
785 |
fun err msg = raise THM ("transitive: " ^ msg, 0, [th1, th2]); |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
786 |
in |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
787 |
case (prop1, prop2) of |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
788 |
((eq as Const ("==", Type (_, [T, _]))) $ t1 $ u, Const ("==", _) $ u' $ t2) => |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
789 |
if not (u aconv u') then err "middle term" |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
790 |
else |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
791 |
Thm (deriv_rule2 (Pt.transitive u T) der1 der2, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
792 |
{thy_ref = merge_thys2 th1 th2, |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
793 |
tags = [], |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
794 |
maxidx = Int.max (max1, max2), |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
795 |
shyps = Sorts.union shyps1 shyps2, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
796 |
hyps = union_hyps hyps1 hyps2, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
797 |
tpairs = union_tpairs tpairs1 tpairs2, |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
798 |
prop = eq $ t1 $ t2}) |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
799 |
| _ => err "premises" |
0 | 800 |
end; |
801 |
||
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
802 |
(*Beta-conversion |
16656 | 803 |
(%x. t)(u) == t[u/x] |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
804 |
fully beta-reduces the term if full = true |
10416
5b33e732e459
- Moved rewriting functions to meta_simplifier.ML
berghofe
parents:
10348
diff
changeset
|
805 |
*) |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
806 |
fun beta_conversion full (Cterm {thy_ref, t, T, maxidx, sorts}) = |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
807 |
let val t' = |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
808 |
if full then Envir.beta_norm t |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
809 |
else |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
810 |
(case t of Abs (_, _, bodt) $ u => subst_bound (u, bodt) |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
811 |
| _ => raise THM ("beta_conversion: not a redex", 0, [])); |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
812 |
in |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
813 |
Thm (deriv_rule0 Pt.reflexive, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
814 |
{thy_ref = thy_ref, |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
815 |
tags = [], |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
816 |
maxidx = maxidx, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
817 |
shyps = sorts, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
818 |
hyps = [], |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
819 |
tpairs = [], |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
820 |
prop = Logic.mk_equals (t, t')}) |
10416
5b33e732e459
- Moved rewriting functions to meta_simplifier.ML
berghofe
parents:
10348
diff
changeset
|
821 |
end; |
5b33e732e459
- Moved rewriting functions to meta_simplifier.ML
berghofe
parents:
10348
diff
changeset
|
822 |
|
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
823 |
fun eta_conversion (Cterm {thy_ref, t, T, maxidx, sorts}) = |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
824 |
Thm (deriv_rule0 Pt.reflexive, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
825 |
{thy_ref = thy_ref, |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
826 |
tags = [], |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
827 |
maxidx = maxidx, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
828 |
shyps = sorts, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
829 |
hyps = [], |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
830 |
tpairs = [], |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
831 |
prop = Logic.mk_equals (t, Envir.eta_contract t)}); |
0 | 832 |
|
23493 | 833 |
fun eta_long_conversion (Cterm {thy_ref, t, T, maxidx, sorts}) = |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
834 |
Thm (deriv_rule0 Pt.reflexive, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
835 |
{thy_ref = thy_ref, |
23493 | 836 |
tags = [], |
837 |
maxidx = maxidx, |
|
838 |
shyps = sorts, |
|
839 |
hyps = [], |
|
840 |
tpairs = [], |
|
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
841 |
prop = Logic.mk_equals (t, Pattern.eta_long [] t)}); |
23493 | 842 |
|
0 | 843 |
(*The abstraction rule. The Free or Var x must not be free in the hypotheses. |
844 |
The bound variable will be named "a" (since x will be something like x320) |
|
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
845 |
t == u |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
846 |
-------------- |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
847 |
%x. t == %x. u |
1220 | 848 |
*) |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
849 |
fun abstract_rule a |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
850 |
(Cterm {t = x, T, sorts, ...}) |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
851 |
(th as Thm (der, {thy_ref, maxidx, hyps, shyps, tpairs, prop, ...})) = |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
852 |
let |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
853 |
val (t, u) = Logic.dest_equals prop |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
854 |
handle TERM _ => raise THM ("abstract_rule: premise not an equality", 0, [th]); |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
855 |
val result = |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
856 |
Thm (deriv_rule1 (Pt.abstract_rule x a) der, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
857 |
{thy_ref = thy_ref, |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
858 |
tags = [], |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
859 |
maxidx = maxidx, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
860 |
shyps = Sorts.union sorts shyps, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
861 |
hyps = hyps, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
862 |
tpairs = tpairs, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
863 |
prop = Logic.mk_equals |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
864 |
(Abs (a, T, abstract_over (x, t)), Abs (a, T, abstract_over (x, u)))}); |
21798 | 865 |
fun check_occs a x ts = |
16847
8fc160b12e73
invoke_oracle: do not keep theory value, but theory_ref;
wenzelm
parents:
16725
diff
changeset
|
866 |
if exists (fn t => Logic.occs (x, t)) ts then |
21798 | 867 |
raise THM ("abstract_rule: variable " ^ quote a ^ " free in assumptions", 0, [th]) |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
868 |
else (); |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
869 |
in |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
870 |
case x of |
21798 | 871 |
Free (a, _) => (check_occs a x hyps; check_occs a x (terms_of_tpairs tpairs); result) |
872 |
| Var ((a, _), _) => (check_occs a x (terms_of_tpairs tpairs); result) |
|
873 |
| _ => raise THM ("abstract_rule: not a variable", 0, [th]) |
|
0 | 874 |
end; |
875 |
||
876 |
(*The combination rule |
|
3529 | 877 |
f == g t == u |
878 |
-------------- |
|
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
879 |
f t == g u |
1220 | 880 |
*) |
0 | 881 |
fun combination th1 th2 = |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
882 |
let |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
883 |
val Thm (der1, {maxidx = max1, shyps = shyps1, hyps = hyps1, tpairs = tpairs1, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
884 |
prop = prop1, ...}) = th1 |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
885 |
and Thm (der2, {maxidx = max2, shyps = shyps2, hyps = hyps2, tpairs = tpairs2, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
886 |
prop = prop2, ...}) = th2; |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
887 |
fun chktypes fT tT = |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
888 |
(case fT of |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
889 |
Type ("fun", [T1, T2]) => |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
890 |
if T1 <> tT then |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
891 |
raise THM ("combination: types", 0, [th1, th2]) |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
892 |
else () |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
893 |
| _ => raise THM ("combination: not function type", 0, [th1, th2])); |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
894 |
in |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
895 |
case (prop1, prop2) of |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
896 |
(Const ("==", Type ("fun", [fT, _])) $ f $ g, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
897 |
Const ("==", Type ("fun", [tT, _])) $ t $ u) => |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
898 |
(chktypes fT tT; |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
899 |
Thm (deriv_rule2 (Pt.combination f g t u fT) der1 der2, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
900 |
{thy_ref = merge_thys2 th1 th2, |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
901 |
tags = [], |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
902 |
maxidx = Int.max (max1, max2), |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
903 |
shyps = Sorts.union shyps1 shyps2, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
904 |
hyps = union_hyps hyps1 hyps2, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
905 |
tpairs = union_tpairs tpairs1 tpairs2, |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
906 |
prop = Logic.mk_equals (f $ t, g $ u)})) |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
907 |
| _ => raise THM ("combination: premises", 0, [th1, th2]) |
0 | 908 |
end; |
909 |
||
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
910 |
(*Equality introduction |
3529 | 911 |
A ==> B B ==> A |
912 |
---------------- |
|
913 |
A == B |
|
1220 | 914 |
*) |
0 | 915 |
fun equal_intr th1 th2 = |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
916 |
let |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
917 |
val Thm (der1, {maxidx = max1, shyps = shyps1, hyps = hyps1, tpairs = tpairs1, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
918 |
prop = prop1, ...}) = th1 |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
919 |
and Thm (der2, {maxidx = max2, shyps = shyps2, hyps = hyps2, tpairs = tpairs2, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
920 |
prop = prop2, ...}) = th2; |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
921 |
fun err msg = raise THM ("equal_intr: " ^ msg, 0, [th1, th2]); |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
922 |
in |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
923 |
case (prop1, prop2) of |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
924 |
(Const("==>", _) $ A $ B, Const("==>", _) $ B' $ A') => |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
925 |
if A aconv A' andalso B aconv B' then |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
926 |
Thm (deriv_rule2 (Pt.equal_intr A B) der1 der2, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
927 |
{thy_ref = merge_thys2 th1 th2, |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
928 |
tags = [], |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
929 |
maxidx = Int.max (max1, max2), |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
930 |
shyps = Sorts.union shyps1 shyps2, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
931 |
hyps = union_hyps hyps1 hyps2, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
932 |
tpairs = union_tpairs tpairs1 tpairs2, |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
933 |
prop = Logic.mk_equals (A, B)}) |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
934 |
else err "not equal" |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
935 |
| _ => err "premises" |
1529 | 936 |
end; |
937 |
||
938 |
(*The equal propositions rule |
|
3529 | 939 |
A == B A |
1529 | 940 |
--------- |
941 |
B |
|
942 |
*) |
|
943 |
fun equal_elim th1 th2 = |
|
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
944 |
let |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
945 |
val Thm (der1, {maxidx = max1, shyps = shyps1, hyps = hyps1, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
946 |
tpairs = tpairs1, prop = prop1, ...}) = th1 |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
947 |
and Thm (der2, {maxidx = max2, shyps = shyps2, hyps = hyps2, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
948 |
tpairs = tpairs2, prop = prop2, ...}) = th2; |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
949 |
fun err msg = raise THM ("equal_elim: " ^ msg, 0, [th1, th2]); |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
950 |
in |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
951 |
case prop1 of |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
952 |
Const ("==", _) $ A $ B => |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
953 |
if prop2 aconv A then |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
954 |
Thm (deriv_rule2 (Pt.equal_elim A B) der1 der2, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
955 |
{thy_ref = merge_thys2 th1 th2, |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
956 |
tags = [], |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
957 |
maxidx = Int.max (max1, max2), |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
958 |
shyps = Sorts.union shyps1 shyps2, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
959 |
hyps = union_hyps hyps1 hyps2, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
960 |
tpairs = union_tpairs tpairs1 tpairs2, |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
961 |
prop = B}) |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
962 |
else err "not equal" |
1529 | 963 |
| _ => err"major premise" |
964 |
end; |
|
0 | 965 |
|
1220 | 966 |
|
967 |
||
0 | 968 |
(**** Derived rules ****) |
969 |
||
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
970 |
(*Smash unifies the list of term pairs leaving no flex-flex pairs. |
24143
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
971 |
Instantiates the theorem and deletes trivial tpairs. Resulting |
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
972 |
sequence may contain multiple elements if the tpairs are not all |
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
973 |
flex-flex.*) |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
974 |
fun flexflex_rule (th as Thm (der, {thy_ref, maxidx, shyps, hyps, tpairs, prop, ...})) = |
24143
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
975 |
let val thy = Theory.deref thy_ref in |
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
976 |
Unify.smash_unifiers thy tpairs (Envir.empty maxidx) |
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
977 |
|> Seq.map (fn env => |
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
978 |
if Envir.is_empty env then th |
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
979 |
else |
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
980 |
let |
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
981 |
val tpairs' = tpairs |> map (pairself (Envir.norm_term env)) |
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
982 |
(*remove trivial tpairs, of the form t==t*) |
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
983 |
|> filter_out (op aconv); |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
984 |
val der' = deriv_rule1 (Pt.norm_proof' env) der; |
24143
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
985 |
val prop' = Envir.norm_term env prop; |
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
986 |
val maxidx = maxidx_tpairs tpairs' (maxidx_of_term prop'); |
26640
92e6d3ec91bd
simplified handling of sorts, removed unnecessary universal witness;
wenzelm
parents:
26631
diff
changeset
|
987 |
val shyps = Envir.insert_sorts env shyps; |
24143
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
988 |
in |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
989 |
Thm (der', {thy_ref = Theory.check_thy thy, tags = [], maxidx = maxidx, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
990 |
shyps = shyps, hyps = hyps, tpairs = tpairs', prop = prop'}) |
24143
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
991 |
end) |
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
992 |
end; |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
993 |
|
0 | 994 |
|
19910 | 995 |
(*Generalization of fixed variables |
996 |
A |
|
997 |
-------------------- |
|
998 |
A[?'a/'a, ?x/x, ...] |
|
999 |
*) |
|
1000 |
||
1001 |
fun generalize ([], []) _ th = th |
|
1002 |
| generalize (tfrees, frees) idx th = |
|
1003 |
let |
|
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1004 |
val Thm (der, {thy_ref, maxidx, shyps, hyps, tpairs, prop, ...}) = th; |
19910 | 1005 |
val _ = idx <= maxidx andalso raise THM ("generalize: bad index", idx, [th]); |
1006 |
||
1007 |
val bad_type = if null tfrees then K false else |
|
1008 |
Term.exists_subtype (fn TFree (a, _) => member (op =) tfrees a | _ => false); |
|
1009 |
fun bad_term (Free (x, T)) = bad_type T orelse member (op =) frees x |
|
1010 |
| bad_term (Var (_, T)) = bad_type T |
|
1011 |
| bad_term (Const (_, T)) = bad_type T |
|
1012 |
| bad_term (Abs (_, T, t)) = bad_type T orelse bad_term t |
|
1013 |
| bad_term (t $ u) = bad_term t orelse bad_term u |
|
1014 |
| bad_term (Bound _) = false; |
|
1015 |
val _ = exists bad_term hyps andalso |
|
1016 |
raise THM ("generalize: variable free in assumptions", 0, [th]); |
|
1017 |
||
20512 | 1018 |
val gen = TermSubst.generalize (tfrees, frees) idx; |
19910 | 1019 |
val prop' = gen prop; |
1020 |
val tpairs' = map (pairself gen) tpairs; |
|
1021 |
val maxidx' = maxidx_tpairs tpairs' (maxidx_of_term prop'); |
|
1022 |
in |
|
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1023 |
Thm (deriv_rule1 (Pt.generalize (tfrees, frees) idx) der, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1024 |
{thy_ref = thy_ref, |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
1025 |
tags = [], |
19910 | 1026 |
maxidx = maxidx', |
1027 |
shyps = shyps, |
|
1028 |
hyps = hyps, |
|
1029 |
tpairs = tpairs', |
|
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1030 |
prop = prop'}) |
19910 | 1031 |
end; |
1032 |
||
1033 |
||
22584 | 1034 |
(*Instantiation of schematic variables |
16656 | 1035 |
A |
1036 |
-------------------- |
|
1037 |
A[t1/v1, ..., tn/vn] |
|
1220 | 1038 |
*) |
0 | 1039 |
|
6928 | 1040 |
local |
1041 |
||
26939
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
wenzelm
parents:
26832
diff
changeset
|
1042 |
fun pretty_typing thy t T = Pretty.block |
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
wenzelm
parents:
26832
diff
changeset
|
1043 |
[Syntax.pretty_term_global thy t, Pretty.str " ::", Pretty.brk 1, Syntax.pretty_typ_global thy T]; |
15797 | 1044 |
|
16884
1678a796b6b2
tuned instantiate (avoid subst_atomic, subst_atomic_types);
wenzelm
parents:
16847
diff
changeset
|
1045 |
fun add_inst (ct, cu) (thy_ref, sorts) = |
6928 | 1046 |
let |
26939
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
wenzelm
parents:
26832
diff
changeset
|
1047 |
val Cterm {t = t, T = T, ...} = ct; |
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
wenzelm
parents:
26832
diff
changeset
|
1048 |
val Cterm {t = u, T = U, sorts = sorts_u, maxidx = maxidx_u, ...} = cu; |
16884
1678a796b6b2
tuned instantiate (avoid subst_atomic, subst_atomic_types);
wenzelm
parents:
16847
diff
changeset
|
1049 |
val thy_ref' = Theory.merge_refs (thy_ref, merge_thys0 ct cu); |
1678a796b6b2
tuned instantiate (avoid subst_atomic, subst_atomic_types);
wenzelm
parents:
16847
diff
changeset
|
1050 |
val sorts' = Sorts.union sorts_u sorts; |
3967
edd5ff9371f8
sg_ref: automatic adjustment of thms of draft theories;
wenzelm
parents:
3895
diff
changeset
|
1051 |
in |
16884
1678a796b6b2
tuned instantiate (avoid subst_atomic, subst_atomic_types);
wenzelm
parents:
16847
diff
changeset
|
1052 |
(case t of Var v => |
20512 | 1053 |
if T = U then ((v, (u, maxidx_u)), (thy_ref', sorts')) |
16884
1678a796b6b2
tuned instantiate (avoid subst_atomic, subst_atomic_types);
wenzelm
parents:
16847
diff
changeset
|
1054 |
else raise TYPE (Pretty.string_of (Pretty.block |
1678a796b6b2
tuned instantiate (avoid subst_atomic, subst_atomic_types);
wenzelm
parents:
16847
diff
changeset
|
1055 |
[Pretty.str "instantiate: type conflict", |
1678a796b6b2
tuned instantiate (avoid subst_atomic, subst_atomic_types);
wenzelm
parents:
16847
diff
changeset
|
1056 |
Pretty.fbrk, pretty_typing (Theory.deref thy_ref') t T, |
1678a796b6b2
tuned instantiate (avoid subst_atomic, subst_atomic_types);
wenzelm
parents:
16847
diff
changeset
|
1057 |
Pretty.fbrk, pretty_typing (Theory.deref thy_ref') u U]), [T, U], [t, u]) |
1678a796b6b2
tuned instantiate (avoid subst_atomic, subst_atomic_types);
wenzelm
parents:
16847
diff
changeset
|
1058 |
| _ => raise TYPE (Pretty.string_of (Pretty.block |
1678a796b6b2
tuned instantiate (avoid subst_atomic, subst_atomic_types);
wenzelm
parents:
16847
diff
changeset
|
1059 |
[Pretty.str "instantiate: not a variable", |
26939
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
wenzelm
parents:
26832
diff
changeset
|
1060 |
Pretty.fbrk, Syntax.pretty_term_global (Theory.deref thy_ref') t]), [], [t])) |
0 | 1061 |
end; |
1062 |
||
16884
1678a796b6b2
tuned instantiate (avoid subst_atomic, subst_atomic_types);
wenzelm
parents:
16847
diff
changeset
|
1063 |
fun add_instT (cT, cU) (thy_ref, sorts) = |
16656 | 1064 |
let |
16884
1678a796b6b2
tuned instantiate (avoid subst_atomic, subst_atomic_types);
wenzelm
parents:
16847
diff
changeset
|
1065 |
val Ctyp {T, thy_ref = thy_ref1, ...} = cT |
20512 | 1066 |
and Ctyp {T = U, thy_ref = thy_ref2, sorts = sorts_U, maxidx = maxidx_U, ...} = cU; |
24143
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
1067 |
val thy' = Theory.deref (Theory.merge_refs (thy_ref, Theory.merge_refs (thy_ref1, thy_ref2))); |
16884
1678a796b6b2
tuned instantiate (avoid subst_atomic, subst_atomic_types);
wenzelm
parents:
16847
diff
changeset
|
1068 |
val sorts' = Sorts.union sorts_U sorts; |
16656 | 1069 |
in |
16884
1678a796b6b2
tuned instantiate (avoid subst_atomic, subst_atomic_types);
wenzelm
parents:
16847
diff
changeset
|
1070 |
(case T of TVar (v as (_, S)) => |
24143
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
1071 |
if Sign.of_sort thy' (U, S) then ((v, (U, maxidx_U)), (Theory.check_thy thy', sorts')) |
26939
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
wenzelm
parents:
26832
diff
changeset
|
1072 |
else raise TYPE ("Type not of sort " ^ Syntax.string_of_sort_global thy' S, [U], []) |
16656 | 1073 |
| _ => raise TYPE (Pretty.string_of (Pretty.block |
15797 | 1074 |
[Pretty.str "instantiate: not a type variable", |
26939
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
wenzelm
parents:
26832
diff
changeset
|
1075 |
Pretty.fbrk, Syntax.pretty_typ_global thy' T]), [T], [])) |
16656 | 1076 |
end; |
0 | 1077 |
|
6928 | 1078 |
in |
1079 |
||
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1080 |
(*Left-to-right replacements: ctpairs = [..., (vi, ti), ...]. |
0 | 1081 |
Instantiates distinct Vars by terms of same type. |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1082 |
Does NOT normalize the resulting theorem!*) |
1529 | 1083 |
fun instantiate ([], []) th = th |
16884
1678a796b6b2
tuned instantiate (avoid subst_atomic, subst_atomic_types);
wenzelm
parents:
16847
diff
changeset
|
1084 |
| instantiate (instT, inst) th = |
16656 | 1085 |
let |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1086 |
val Thm (der, {thy_ref, hyps, shyps, tpairs, prop, ...}) = th; |
16884
1678a796b6b2
tuned instantiate (avoid subst_atomic, subst_atomic_types);
wenzelm
parents:
16847
diff
changeset
|
1087 |
val (inst', (instT', (thy_ref', shyps'))) = |
1678a796b6b2
tuned instantiate (avoid subst_atomic, subst_atomic_types);
wenzelm
parents:
16847
diff
changeset
|
1088 |
(thy_ref, shyps) |> fold_map add_inst inst ||> fold_map add_instT instT; |
20512 | 1089 |
val subst = TermSubst.instantiate_maxidx (instT', inst'); |
1090 |
val (prop', maxidx1) = subst prop ~1; |
|
1091 |
val (tpairs', maxidx') = |
|
1092 |
fold_map (fn (t, u) => fn i => subst t i ||>> subst u) tpairs maxidx1; |
|
16656 | 1093 |
in |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1094 |
Thm (deriv_rule1 (fn d => Pt.instantiate (map (apsnd #1) instT', map (apsnd #1) inst') d) der, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1095 |
{thy_ref = thy_ref', |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
1096 |
tags = [], |
20545
4c1068697159
instantiate: omit has_duplicates check, which is irrelevant for soundness;
wenzelm
parents:
20512
diff
changeset
|
1097 |
maxidx = maxidx', |
4c1068697159
instantiate: omit has_duplicates check, which is irrelevant for soundness;
wenzelm
parents:
20512
diff
changeset
|
1098 |
shyps = shyps', |
4c1068697159
instantiate: omit has_duplicates check, which is irrelevant for soundness;
wenzelm
parents:
20512
diff
changeset
|
1099 |
hyps = hyps, |
4c1068697159
instantiate: omit has_duplicates check, which is irrelevant for soundness;
wenzelm
parents:
20512
diff
changeset
|
1100 |
tpairs = tpairs', |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1101 |
prop = prop'}) |
16656 | 1102 |
end |
1103 |
handle TYPE (msg, _, _) => raise THM (msg, 0, [th]); |
|
6928 | 1104 |
|
22584 | 1105 |
fun instantiate_cterm ([], []) ct = ct |
1106 |
| instantiate_cterm (instT, inst) ct = |
|
1107 |
let |
|
1108 |
val Cterm {thy_ref, t, T, sorts, ...} = ct; |
|
1109 |
val (inst', (instT', (thy_ref', sorts'))) = |
|
1110 |
(thy_ref, sorts) |> fold_map add_inst inst ||> fold_map add_instT instT; |
|
1111 |
val subst = TermSubst.instantiate_maxidx (instT', inst'); |
|
1112 |
val substT = TermSubst.instantiateT_maxidx instT'; |
|
1113 |
val (t', maxidx1) = subst t ~1; |
|
1114 |
val (T', maxidx') = substT T maxidx1; |
|
1115 |
in Cterm {thy_ref = thy_ref', t = t', T = T', sorts = sorts', maxidx = maxidx'} end |
|
1116 |
handle TYPE (msg, _, _) => raise CTERM (msg, [ct]); |
|
1117 |
||
6928 | 1118 |
end; |
1119 |
||
0 | 1120 |
|
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1121 |
(*The trivial implication A ==> A, justified by assume and forall rules. |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1122 |
A can contain Vars, not so for assume!*) |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1123 |
fun trivial (Cterm {thy_ref, t =A, T, maxidx, sorts}) = |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1124 |
if T <> propT then |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1125 |
raise THM ("trivial: the term must have type prop", 0, []) |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1126 |
else |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1127 |
Thm (deriv_rule0 (Pt.AbsP ("H", NONE, Pt.PBound 0)), |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1128 |
{thy_ref = thy_ref, |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
1129 |
tags = [], |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1130 |
maxidx = maxidx, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1131 |
shyps = sorts, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1132 |
hyps = [], |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1133 |
tpairs = [], |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1134 |
prop = Logic.mk_implies (A, A)}); |
0 | 1135 |
|
1503 | 1136 |
(*Axiom-scheme reflecting signature contents: "OFCLASS(?'a::c, c_class)" *) |
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
1137 |
fun class_triv thy c = |
24143
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
1138 |
let |
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
1139 |
val Cterm {t, maxidx, sorts, ...} = |
24848 | 1140 |
cterm_of thy (Logic.mk_inclass (TVar ((Name.aT, 0), [c]), Sign.certify_class thy c)) |
24143
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
1141 |
handle TERM (msg, _) => raise THM ("class_triv: " ^ msg, 0, []); |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1142 |
val der = deriv_rule0 (Pt.PAxm ("Pure.class_triv:" ^ c, t, SOME [])); |
399
86cc2b98f9e0
added class_triv: theory -> class -> thm (for axclasses);
wenzelm
parents:
387
diff
changeset
|
1143 |
in |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1144 |
Thm (der, {thy_ref = Theory.check_thy thy, tags = [], maxidx = maxidx, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1145 |
shyps = sorts, hyps = [], tpairs = [], prop = t}) |
399
86cc2b98f9e0
added class_triv: theory -> class -> thm (for axclasses);
wenzelm
parents:
387
diff
changeset
|
1146 |
end; |
86cc2b98f9e0
added class_triv: theory -> class -> thm (for axclasses);
wenzelm
parents:
387
diff
changeset
|
1147 |
|
19505 | 1148 |
(*Internalize sort constraints of type variable*) |
1149 |
fun unconstrainT |
|
1150 |
(Ctyp {thy_ref = thy_ref1, T, ...}) |
|
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1151 |
(th as Thm (_, {thy_ref = thy_ref2, maxidx, shyps, hyps, tpairs, prop, ...})) = |
19505 | 1152 |
let |
1153 |
val ((x, i), S) = Term.dest_TVar T handle TYPE _ => |
|
1154 |
raise THM ("unconstrainT: not a type variable", 0, [th]); |
|
1155 |
val T' = TVar ((x, i), []); |
|
20548
8ef25fe585a8
renamed Term.map_term_types to Term.map_types (cf. Term.fold_types);
wenzelm
parents:
20545
diff
changeset
|
1156 |
val unconstrain = Term.map_types (Term.map_atyps (fn U => if U = T then T' else U)); |
19505 | 1157 |
val constraints = map (curry Logic.mk_inclass T') S; |
1158 |
in |
|
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1159 |
Thm (deriv_rule0 (Pt.PAxm ("Pure.unconstrainT", prop, SOME [])), |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1160 |
{thy_ref = Theory.merge_refs (thy_ref1, thy_ref2), |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
1161 |
tags = [], |
19505 | 1162 |
maxidx = Int.max (maxidx, i), |
1163 |
shyps = Sorts.remove_sort S shyps, |
|
1164 |
hyps = hyps, |
|
1165 |
tpairs = map (pairself unconstrain) tpairs, |
|
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1166 |
prop = Logic.list_implies (constraints, unconstrain prop)}) |
19505 | 1167 |
end; |
399
86cc2b98f9e0
added class_triv: theory -> class -> thm (for axclasses);
wenzelm
parents:
387
diff
changeset
|
1168 |
|
6786 | 1169 |
(* Replace all TFrees not fixed or in the hyps by new TVars *) |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1170 |
fun varifyT' fixed (Thm (der, {thy_ref, maxidx, shyps, hyps, tpairs, prop, ...})) = |
12500 | 1171 |
let |
23178 | 1172 |
val tfrees = List.foldr add_term_tfrees fixed hyps; |
13658
c9ad3e64ddcf
Changed handling of flex-flex constraints: now stored in separate
berghofe
parents:
13642
diff
changeset
|
1173 |
val prop1 = attach_tpairs tpairs prop; |
21116 | 1174 |
val (al, prop2) = Type.varify tfrees prop1; |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1175 |
val (ts, prop3) = Logic.strip_prems (length tpairs, [], prop2); |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1176 |
in |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1177 |
(al, Thm (deriv_rule1 (Pt.varify_proof prop tfrees) der, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1178 |
{thy_ref = thy_ref, |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
1179 |
tags = [], |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1180 |
maxidx = Int.max (0, maxidx), |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1181 |
shyps = shyps, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1182 |
hyps = hyps, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1183 |
tpairs = rev (map Logic.dest_equals ts), |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1184 |
prop = prop3})) |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1185 |
end; |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1186 |
|
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1187 |
val varifyT = #2 o varifyT' []; |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1188 |
|
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1189 |
(* Replace all TVars by new TFrees *) |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1190 |
fun freezeT (Thm (der, {thy_ref, maxidx, shyps, hyps, tpairs, prop, ...})) = |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1191 |
let |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1192 |
val prop1 = attach_tpairs tpairs prop; |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1193 |
val prop2 = Type.freeze prop1; |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1194 |
val (ts, prop3) = Logic.strip_prems (length tpairs, [], prop2); |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1195 |
in |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1196 |
Thm (deriv_rule1 (Pt.freezeT prop1) der, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1197 |
{thy_ref = thy_ref, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1198 |
tags = [], |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1199 |
maxidx = maxidx_of_term prop2, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1200 |
shyps = shyps, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1201 |
hyps = hyps, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1202 |
tpairs = rev (map Logic.dest_equals ts), |
18127 | 1203 |
prop = prop3}) |
0 | 1204 |
end; |
1205 |
||
1206 |
||
1207 |
(*** Inference rules for tactics ***) |
|
1208 |
||
1209 |
(*Destruct proof state into constraints, other goals, goal(i), rest *) |
|
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1210 |
fun dest_state (state as Thm (_, {prop,tpairs,...}), i) = |
13658
c9ad3e64ddcf
Changed handling of flex-flex constraints: now stored in separate
berghofe
parents:
13642
diff
changeset
|
1211 |
(case Logic.strip_prems(i, [], prop) of |
c9ad3e64ddcf
Changed handling of flex-flex constraints: now stored in separate
berghofe
parents:
13642
diff
changeset
|
1212 |
(B::rBs, C) => (tpairs, rev rBs, B, C) |
c9ad3e64ddcf
Changed handling of flex-flex constraints: now stored in separate
berghofe
parents:
13642
diff
changeset
|
1213 |
| _ => raise THM("dest_state", i, [state])) |
0 | 1214 |
handle TERM _ => raise THM("dest_state", i, [state]); |
1215 |
||
309 | 1216 |
(*Increment variables and parameters of orule as required for |
18035 | 1217 |
resolution with a goal.*) |
1218 |
fun lift_rule goal orule = |
|
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1219 |
let |
18035 | 1220 |
val Cterm {t = gprop, T, maxidx = gmax, sorts, ...} = goal; |
1221 |
val inc = gmax + 1; |
|
1222 |
val lift_abs = Logic.lift_abs inc gprop; |
|
1223 |
val lift_all = Logic.lift_all inc gprop; |
|
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1224 |
val Thm (der, {maxidx, shyps, hyps, tpairs, prop, ...}) = orule; |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1225 |
val (As, B) = Logic.strip_horn prop; |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1226 |
in |
18035 | 1227 |
if T <> propT then raise THM ("lift_rule: the term must have type prop", 0, []) |
1228 |
else |
|
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1229 |
Thm (deriv_rule1 (Pt.lift_proof gprop inc prop) der, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1230 |
{thy_ref = merge_thys1 goal orule, |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
1231 |
tags = [], |
18035 | 1232 |
maxidx = maxidx + inc, |
1233 |
shyps = Sorts.union shyps sorts, (*sic!*) |
|
1234 |
hyps = hyps, |
|
1235 |
tpairs = map (pairself lift_abs) tpairs, |
|
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1236 |
prop = Logic.list_implies (map lift_all As, lift_all B)}) |
0 | 1237 |
end; |
1238 |
||
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1239 |
fun incr_indexes i (thm as Thm (der, {thy_ref, maxidx, shyps, hyps, tpairs, prop, ...})) = |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1240 |
if i < 0 then raise THM ("negative increment", 0, [thm]) |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1241 |
else if i = 0 then thm |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1242 |
else |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1243 |
Thm (deriv_rule1 (Pt.map_proof_terms (Logic.incr_indexes ([], i)) (Logic.incr_tvar i)) der, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1244 |
{thy_ref = thy_ref, |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
1245 |
tags = [], |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1246 |
maxidx = maxidx + i, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1247 |
shyps = shyps, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1248 |
hyps = hyps, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1249 |
tpairs = map (pairself (Logic.incr_indexes ([], i))) tpairs, |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1250 |
prop = Logic.incr_indexes ([], i) prop}); |
10416
5b33e732e459
- Moved rewriting functions to meta_simplifier.ML
berghofe
parents:
10348
diff
changeset
|
1251 |
|
0 | 1252 |
(*Solve subgoal Bi of proof state B1...Bn/C by assumption. *) |
1253 |
fun assumption i state = |
|
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1254 |
let |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1255 |
val Thm (der, {thy_ref, maxidx, shyps, hyps, prop, ...}) = state; |
16656 | 1256 |
val thy = Theory.deref thy_ref; |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1257 |
val (tpairs, Bs, Bi, C) = dest_state (state, i); |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1258 |
fun newth n (env as Envir.Envir {maxidx, ...}, tpairs) = |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1259 |
Thm (deriv_rule1 |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1260 |
((if Envir.is_empty env then I else (Pt.norm_proof' env)) o |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1261 |
Pt.assumption_proof Bs Bi n) der, |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1262 |
{tags = [], |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1263 |
maxidx = maxidx, |
26640
92e6d3ec91bd
simplified handling of sorts, removed unnecessary universal witness;
wenzelm
parents:
26631
diff
changeset
|
1264 |
shyps = Envir.insert_sorts env shyps, |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1265 |
hyps = hyps, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1266 |
tpairs = |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1267 |
if Envir.is_empty env then tpairs |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1268 |
else map (pairself (Envir.norm_term env)) tpairs, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1269 |
prop = |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1270 |
if Envir.is_empty env then (*avoid wasted normalizations*) |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1271 |
Logic.list_implies (Bs, C) |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1272 |
else (*normalize the new rule fully*) |
24143
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
1273 |
Envir.norm_term env (Logic.list_implies (Bs, C)), |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1274 |
thy_ref = Theory.check_thy thy}); |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1275 |
fun addprfs [] _ = Seq.empty |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1276 |
| addprfs ((t, u) :: apairs) n = Seq.make (fn () => Seq.pull |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1277 |
(Seq.mapp (newth n) |
16656 | 1278 |
(Unify.unifiers (thy, Envir.empty maxidx, (t, u) :: tpairs)) |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1279 |
(addprfs apairs (n + 1)))) |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1280 |
in addprfs (Logic.assum_pairs (~1, Bi)) 1 end; |
0 | 1281 |
|
250 | 1282 |
(*Solve subgoal Bi of proof state B1...Bn/C by assumption. |
0 | 1283 |
Checks if Bi's conclusion is alpha-convertible to one of its assumptions*) |
1284 |
fun eq_assumption i state = |
|
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1285 |
let |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1286 |
val Thm (der, {thy_ref, maxidx, shyps, hyps, prop, ...}) = state; |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1287 |
val (tpairs, Bs, Bi, C) = dest_state (state, i); |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1288 |
in |
26832 | 1289 |
(case find_index Pattern.aeconv (Logic.assum_pairs (~1, Bi)) of |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1290 |
~1 => raise THM ("eq_assumption", 0, [state]) |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1291 |
| n => |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1292 |
Thm (deriv_rule1 (Pt.assumption_proof Bs Bi (n + 1)) der, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1293 |
{thy_ref = thy_ref, |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
1294 |
tags = [], |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1295 |
maxidx = maxidx, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1296 |
shyps = shyps, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1297 |
hyps = hyps, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1298 |
tpairs = tpairs, |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1299 |
prop = Logic.list_implies (Bs, C)})) |
0 | 1300 |
end; |
1301 |
||
1302 |
||
2671 | 1303 |
(*For rotate_tac: fast rotation of assumptions of subgoal i*) |
1304 |
fun rotate_rule k i state = |
|
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1305 |
let |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1306 |
val Thm (der, {thy_ref, maxidx, shyps, hyps, prop, ...}) = state; |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1307 |
val (tpairs, Bs, Bi, C) = dest_state (state, i); |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1308 |
val params = Term.strip_all_vars Bi |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1309 |
and rest = Term.strip_all_body Bi; |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1310 |
val asms = Logic.strip_imp_prems rest |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1311 |
and concl = Logic.strip_imp_concl rest; |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1312 |
val n = length asms; |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1313 |
val m = if k < 0 then n + k else k; |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1314 |
val Bi' = |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1315 |
if 0 = m orelse m = n then Bi |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1316 |
else if 0 < m andalso m < n then |
19012 | 1317 |
let val (ps, qs) = chop m asms |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1318 |
in list_all (params, Logic.list_implies (qs @ ps, concl)) end |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1319 |
else raise THM ("rotate_rule", k, [state]); |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1320 |
in |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1321 |
Thm (deriv_rule1 (Pt.rotate_proof Bs Bi m) der, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1322 |
{thy_ref = thy_ref, |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
1323 |
tags = [], |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1324 |
maxidx = maxidx, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1325 |
shyps = shyps, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1326 |
hyps = hyps, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1327 |
tpairs = tpairs, |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1328 |
prop = Logic.list_implies (Bs @ [Bi'], C)}) |
2671 | 1329 |
end; |
1330 |
||
1331 |
||
7248
322151fe6f02
new primitive rule permute_prems to underlie defer_tac and rotate_prems
paulson
parents:
7070
diff
changeset
|
1332 |
(*Rotates a rule's premises to the left by k, leaving the first j premises |
322151fe6f02
new primitive rule permute_prems to underlie defer_tac and rotate_prems
paulson
parents:
7070
diff
changeset
|
1333 |
unchanged. Does nothing if k=0 or if k equals n-j, where n is the |
16656 | 1334 |
number of premises. Useful with etac and underlies defer_tac*) |
7248
322151fe6f02
new primitive rule permute_prems to underlie defer_tac and rotate_prems
paulson
parents:
7070
diff
changeset
|
1335 |
fun permute_prems j k rl = |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1336 |
let |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1337 |
val Thm (der, {thy_ref, maxidx, shyps, hyps, tpairs, prop, ...}) = rl; |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1338 |
val prems = Logic.strip_imp_prems prop |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1339 |
and concl = Logic.strip_imp_concl prop; |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1340 |
val moved_prems = List.drop (prems, j) |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1341 |
and fixed_prems = List.take (prems, j) |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1342 |
handle Subscript => raise THM ("permute_prems: j", j, [rl]); |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1343 |
val n_j = length moved_prems; |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1344 |
val m = if k < 0 then n_j + k else k; |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1345 |
val prop' = |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1346 |
if 0 = m orelse m = n_j then prop |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1347 |
else if 0 < m andalso m < n_j then |
19012 | 1348 |
let val (ps, qs) = chop m moved_prems |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1349 |
in Logic.list_implies (fixed_prems @ qs @ ps, concl) end |
16725 | 1350 |
else raise THM ("permute_prems: k", k, [rl]); |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1351 |
in |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1352 |
Thm (deriv_rule1 (Pt.permute_prems_prf prems j m) der, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1353 |
{thy_ref = thy_ref, |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
1354 |
tags = [], |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1355 |
maxidx = maxidx, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1356 |
shyps = shyps, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1357 |
hyps = hyps, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1358 |
tpairs = tpairs, |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1359 |
prop = prop'}) |
7248
322151fe6f02
new primitive rule permute_prems to underlie defer_tac and rotate_prems
paulson
parents:
7070
diff
changeset
|
1360 |
end; |
322151fe6f02
new primitive rule permute_prems to underlie defer_tac and rotate_prems
paulson
parents:
7070
diff
changeset
|
1361 |
|
322151fe6f02
new primitive rule permute_prems to underlie defer_tac and rotate_prems
paulson
parents:
7070
diff
changeset
|
1362 |
|
0 | 1363 |
(** User renaming of parameters in a subgoal **) |
1364 |
||
1365 |
(*Calls error rather than raising an exception because it is intended |
|
1366 |
for top-level use -- exception handling would not make sense here. |
|
1367 |
The names in cs, if distinct, are used for the innermost parameters; |
|
17868 | 1368 |
preceding parameters may be renamed to make all params distinct.*) |
0 | 1369 |
fun rename_params_rule (cs, i) state = |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1370 |
let |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1371 |
val Thm (der, {thy_ref, tags, maxidx, shyps, hyps, ...}) = state; |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1372 |
val (tpairs, Bs, Bi, C) = dest_state (state, i); |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1373 |
val iparams = map #1 (Logic.strip_params Bi); |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1374 |
val short = length iparams - length cs; |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1375 |
val newnames = |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1376 |
if short < 0 then error "More names than abstractions!" |
20071
8f3e1ddb50e6
replaced Term.variant(list) by Name.variant(_list);
wenzelm
parents:
20057
diff
changeset
|
1377 |
else Name.variant_list cs (Library.take (short, iparams)) @ cs; |
20330 | 1378 |
val freenames = Term.fold_aterms (fn Free (x, _) => insert (op =) x | _ => I) Bi []; |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1379 |
val newBi = Logic.list_rename_params (newnames, Bi); |
250 | 1380 |
in |
21182 | 1381 |
(case duplicates (op =) cs of |
1382 |
a :: _ => (warning ("Can't rename. Bound variables not distinct: " ^ a); state) |
|
1383 |
| [] => |
|
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1384 |
(case cs inter_string freenames of |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1385 |
a :: _ => (warning ("Can't rename. Bound/Free variable clash: " ^ a); state) |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1386 |
| [] => |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1387 |
Thm (der, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1388 |
{thy_ref = thy_ref, |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
1389 |
tags = tags, |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1390 |
maxidx = maxidx, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1391 |
shyps = shyps, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1392 |
hyps = hyps, |
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1393 |
tpairs = tpairs, |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1394 |
prop = Logic.list_implies (Bs @ [newBi], C)}))) |
0 | 1395 |
end; |
1396 |
||
12982 | 1397 |
|
0 | 1398 |
(*** Preservation of bound variable names ***) |
1399 |
||
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1400 |
fun rename_boundvars pat obj (thm as Thm (der, {thy_ref, tags, maxidx, shyps, hyps, tpairs, prop})) = |
12982 | 1401 |
(case Term.rename_abs pat obj prop of |
15531 | 1402 |
NONE => thm |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1403 |
| SOME prop' => Thm (der, |
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
1404 |
{thy_ref = thy_ref, |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
21576
diff
changeset
|
1405 |
tags = tags, |
12982 | 1406 |
maxidx = maxidx, |
1407 |
hyps = hyps, |
|
1408 |
shyps = shyps, |
|
13658
c9ad3e64ddcf
Changed handling of flex-flex constraints: now stored in separate
berghofe
parents:
13642
diff
changeset
|
1409 |
tpairs = tpairs, |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1410 |
prop = prop'})); |
10416
5b33e732e459
- Moved rewriting functions to meta_simplifier.ML
berghofe
parents:
10348
diff
changeset
|
1411 |
|
0 | 1412 |
|
16656 | 1413 |
(* strip_apply f (A, B) strips off all assumptions/parameters from A |
0 | 1414 |
introduced by lifting over B, and applies f to remaining part of A*) |
1415 |
fun strip_apply f = |
|
1416 |
let fun strip(Const("==>",_)$ A1 $ B1, |
|
27336 | 1417 |
Const("==>",_)$ _ $ B2) = Logic.mk_implies (A1, strip(B1,B2)) |
250 | 1418 |
| strip((c as Const("all",_)) $ Abs(a,T,t1), |
1419 |
Const("all",_) $ Abs(_,_,t2)) = c$Abs(a,T,strip(t1,t2)) |
|
1420 |
| strip(A,_) = f A |
|
0 | 1421 |
in strip end; |
1422 |
||
1423 |
(*Use the alist to rename all bound variables and some unknowns in a term |
|
1424 |
dpairs = current disagreement pairs; tpairs = permanent ones (flexflex); |
|
1425 |
Preserves unknowns in tpairs and on lhs of dpairs. *) |
|
1426 |
fun rename_bvs([],_,_,_) = I |
|
1427 |
| rename_bvs(al,dpairs,tpairs,B) = |
|
20330 | 1428 |
let |
1429 |
val add_var = fold_aterms (fn Var ((x, _), _) => insert (op =) x | _ => I); |
|
1430 |
val vids = [] |
|
1431 |
|> fold (add_var o fst) dpairs |
|
1432 |
|> fold (add_var o fst) tpairs |
|
1433 |
|> fold (add_var o snd) tpairs; |
|
250 | 1434 |
(*unknowns appearing elsewhere be preserved!*) |
1435 |
fun rename(t as Var((x,i),T)) = |
|
20330 | 1436 |
(case AList.lookup (op =) al x of |
1437 |
SOME y => |
|
1438 |
if member (op =) vids x orelse member (op =) vids y then t |
|
1439 |
else Var((y,i),T) |
|
1440 |
| NONE=> t) |
|
0 | 1441 |
| rename(Abs(x,T,t)) = |
18944 | 1442 |
Abs (the_default x (AList.lookup (op =) al x), T, rename t) |
0 | 1443 |
| rename(f$t) = rename f $ rename t |
1444 |
| rename(t) = t; |
|
250 | 1445 |
fun strip_ren Ai = strip_apply rename (Ai,B) |
20330 | 1446 |
in strip_ren end; |
0 | 1447 |
|
1448 |
(*Function to rename bounds/unknowns in the argument, lifted over B*) |
|
1449 |
fun rename_bvars(dpairs, tpairs, B) = |
|
23178 | 1450 |
rename_bvs(List.foldr Term.match_bvars [] dpairs, dpairs, tpairs, B); |
0 | 1451 |
|
1452 |
||
1453 |
(*** RESOLUTION ***) |
|
1454 |
||
721
479832ff2d29
Pure/thm/norm_term_skip: new, for skipping normalization of the context
lcp
parents:
678
diff
changeset
|
1455 |
(** Lifting optimizations **) |
479832ff2d29
Pure/thm/norm_term_skip: new, for skipping normalization of the context
lcp
parents:
678
diff
changeset
|
1456 |
|
0 | 1457 |
(*strip off pairs of assumptions/parameters in parallel -- they are |
1458 |
identical because of lifting*) |
|
250 | 1459 |
fun strip_assums2 (Const("==>", _) $ _ $ B1, |
1460 |
Const("==>", _) $ _ $ B2) = strip_assums2 (B1,B2) |
|
0 | 1461 |
| strip_assums2 (Const("all",_)$Abs(a,T,t1), |
250 | 1462 |
Const("all",_)$Abs(_,_,t2)) = |
0 | 1463 |
let val (B1,B2) = strip_assums2 (t1,t2) |
1464 |
in (Abs(a,T,B1), Abs(a,T,B2)) end |
|
1465 |
| strip_assums2 BB = BB; |
|
1466 |
||
1467 |
||
721
479832ff2d29
Pure/thm/norm_term_skip: new, for skipping normalization of the context
lcp
parents:
678
diff
changeset
|
1468 |
(*Faster normalization: skip assumptions that were lifted over*) |
479832ff2d29
Pure/thm/norm_term_skip: new, for skipping normalization of the context
lcp
parents:
678
diff
changeset
|
1469 |
fun norm_term_skip env 0 t = Envir.norm_term env t |
479832ff2d29
Pure/thm/norm_term_skip: new, for skipping normalization of the context
lcp
parents:
678
diff
changeset
|
1470 |
| norm_term_skip env n (Const("all",_)$Abs(a,T,t)) = |
479832ff2d29
Pure/thm/norm_term_skip: new, for skipping normalization of the context
lcp
parents:
678
diff
changeset
|
1471 |
let val Envir.Envir{iTs, ...} = env |
15797 | 1472 |
val T' = Envir.typ_subst_TVars iTs T |
1238 | 1473 |
(*Must instantiate types of parameters because they are flattened; |
721
479832ff2d29
Pure/thm/norm_term_skip: new, for skipping normalization of the context
lcp
parents:
678
diff
changeset
|
1474 |
this could be a NEW parameter*) |
27336 | 1475 |
in Term.all T' $ Abs(a, T', norm_term_skip env n t) end |
721
479832ff2d29
Pure/thm/norm_term_skip: new, for skipping normalization of the context
lcp
parents:
678
diff
changeset
|
1476 |
| norm_term_skip env n (Const("==>", _) $ A $ B) = |
27336 | 1477 |
Logic.mk_implies (A, norm_term_skip env (n-1) B) |
721
479832ff2d29
Pure/thm/norm_term_skip: new, for skipping normalization of the context
lcp
parents:
678
diff
changeset
|
1478 |
| norm_term_skip env n t = error"norm_term_skip: too few assumptions??"; |
479832ff2d29
Pure/thm/norm_term_skip: new, for skipping normalization of the context
lcp
parents:
678
diff
changeset
|
1479 |
|
479832ff2d29
Pure/thm/norm_term_skip: new, for skipping normalization of the context
lcp
parents:
678
diff
changeset
|
1480 |
|
0 | 1481 |
(*Composition of object rule r=(A1...Am/B) with proof state s=(B1...Bn/C) |
250 | 1482 |
Unifies B with Bi, replacing subgoal i (1 <= i <= n) |
0 | 1483 |
If match then forbid instantiations in proof state |
1484 |
If lifted then shorten the dpair using strip_assums2. |
|
1485 |
If eres_flg then simultaneously proves A1 by assumption. |
|
250 | 1486 |
nsubgoal is the number of new subgoals (written m above). |
0 | 1487 |
Curried so that resolution calls dest_state only once. |
1488 |
*) |
|
4270 | 1489 |
local exception COMPOSE |
0 | 1490 |
in |
18486 | 1491 |
fun bicompose_aux flatten match (state, (stpairs, Bs, Bi, C), lifted) |
0 | 1492 |
(eres_flg, orule, nsubgoal) = |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1493 |
let val Thm (sder, {maxidx=smax, shyps=sshyps, hyps=shyps, ...}) = state |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1494 |
and Thm (rder, {maxidx=rmax, shyps=rshyps, hyps=rhyps, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1495 |
tpairs=rtpairs, prop=rprop,...}) = orule |
1529 | 1496 |
(*How many hyps to skip over during normalization*) |
21576 | 1497 |
and nlift = Logic.count_prems (strip_all_body Bi) + (if eres_flg then ~1 else 0) |
24143
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
1498 |
val thy = Theory.deref (merge_thys2 state orule); |
0 | 1499 |
(** Add new theorem with prop = '[| Bs; As |] ==> C' to thq **) |
11518 | 1500 |
fun addth A (As, oldAs, rder', n) ((env as Envir.Envir {maxidx, ...}, tpairs), thq) = |
250 | 1501 |
let val normt = Envir.norm_term env; |
1502 |
(*perform minimal copying here by examining env*) |
|
13658
c9ad3e64ddcf
Changed handling of flex-flex constraints: now stored in separate
berghofe
parents:
13642
diff
changeset
|
1503 |
val (ntpairs, normp) = |
c9ad3e64ddcf
Changed handling of flex-flex constraints: now stored in separate
berghofe
parents:
13642
diff
changeset
|
1504 |
if Envir.is_empty env then (tpairs, (Bs @ As, C)) |
250 | 1505 |
else |
1506 |
let val ntps = map (pairself normt) tpairs |
|
19861 | 1507 |
in if Envir.above env smax then |
1238 | 1508 |
(*no assignments in state; normalize the rule only*) |
1509 |
if lifted |
|
13658
c9ad3e64ddcf
Changed handling of flex-flex constraints: now stored in separate
berghofe
parents:
13642
diff
changeset
|
1510 |
then (ntps, (Bs @ map (norm_term_skip env nlift) As, C)) |
c9ad3e64ddcf
Changed handling of flex-flex constraints: now stored in separate
berghofe
parents:
13642
diff
changeset
|
1511 |
else (ntps, (Bs @ map normt As, C)) |
1529 | 1512 |
else if match then raise COMPOSE |
250 | 1513 |
else (*normalize the new rule fully*) |
13658
c9ad3e64ddcf
Changed handling of flex-flex constraints: now stored in separate
berghofe
parents:
13642
diff
changeset
|
1514 |
(ntps, (map normt (Bs @ As), normt C)) |
250 | 1515 |
end |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1516 |
val th = |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1517 |
Thm (deriv_rule2 |
11518 | 1518 |
((if Envir.is_empty env then I |
19861 | 1519 |
else if Envir.above env smax then |
11518 | 1520 |
(fn f => fn der => f (Pt.norm_proof' env der)) |
1521 |
else |
|
1522 |
curry op oo (Pt.norm_proof' env)) |
|
23296
25f28f9c28a3
Adapted Proofterm.bicompose_proof to Larry's changes in
berghofe
parents:
23178
diff
changeset
|
1523 |
(Pt.bicompose_proof flatten Bs oldAs As A n (nlift+1))) rder' sder, |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1524 |
{tags = [], |
2386 | 1525 |
maxidx = maxidx, |
26640
92e6d3ec91bd
simplified handling of sorts, removed unnecessary universal witness;
wenzelm
parents:
26631
diff
changeset
|
1526 |
shyps = Envir.insert_sorts env (Sorts.union rshyps sshyps), |
16601
ee8eefade568
more efficient treatment of shyps and hyps (use ordered lists);
wenzelm
parents:
16425
diff
changeset
|
1527 |
hyps = union_hyps rhyps shyps, |
13658
c9ad3e64ddcf
Changed handling of flex-flex constraints: now stored in separate
berghofe
parents:
13642
diff
changeset
|
1528 |
tpairs = ntpairs, |
24143
90a9a6fe0d01
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23781
diff
changeset
|
1529 |
prop = Logic.list_implies normp, |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1530 |
thy_ref = Theory.check_thy thy}) |
19475 | 1531 |
in Seq.cons th thq end handle COMPOSE => thq; |
13658
c9ad3e64ddcf
Changed handling of flex-flex constraints: now stored in separate
berghofe
parents:
13642
diff
changeset
|
1532 |
val (rAs,B) = Logic.strip_prems(nsubgoal, [], rprop) |
0 | 1533 |
handle TERM _ => raise THM("bicompose: rule", 0, [orule,state]); |
1534 |
(*Modify assumptions, deleting n-th if n>0 for e-resolution*) |
|
1535 |
fun newAs(As0, n, dpairs, tpairs) = |
|
11518 | 1536 |
let val (As1, rder') = |
25939 | 1537 |
if not lifted then (As0, rder) |
11518 | 1538 |
else (map (rename_bvars(dpairs,tpairs,B)) As0, |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1539 |
deriv_rule1 (Pt.map_proof_terms |
11518 | 1540 |
(rename_bvars (dpairs, tpairs, Bound 0)) I) rder); |
18486 | 1541 |
in (map (if flatten then (Logic.flatten_params n) else I) As1, As1, rder', n) |
250 | 1542 |
handle TERM _ => |
1543 |
raise THM("bicompose: 1st premise", 0, [orule]) |
|
0 | 1544 |
end; |
2147 | 1545 |
val env = Envir.empty(Int.max(rmax,smax)); |
0 | 1546 |
val BBi = if lifted then strip_assums2(B,Bi) else (B,Bi); |
1547 |
val dpairs = BBi :: (rtpairs@stpairs); |
|
1548 |
(*elim-resolution: try each assumption in turn. Initially n=1*) |
|
11518 | 1549 |
fun tryasms (_, _, _, []) = Seq.empty |
1550 |
| tryasms (A, As, n, (t,u)::apairs) = |
|
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
1551 |
(case Seq.pull(Unify.unifiers(thy, env, (t,u)::dpairs)) of |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
1552 |
NONE => tryasms (A, As, n+1, apairs) |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
1553 |
| cell as SOME((_,tpairs),_) => |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
1554 |
Seq.it_right (addth A (newAs(As, n, [BBi,(u,t)], tpairs))) |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
1555 |
(Seq.make(fn()=> cell), |
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
1556 |
Seq.make(fn()=> Seq.pull (tryasms(A, As, n+1, apairs))))) |
0 | 1557 |
fun eres [] = raise THM("bicompose: no premises", 0, [orule,state]) |
15531 | 1558 |
| eres (A1::As) = tryasms(SOME A1, As, 1, Logic.assum_pairs(nlift+1,A1)) |
0 | 1559 |
(*ordinary resolution*) |
15531 | 1560 |
fun res(NONE) = Seq.empty |
1561 |
| res(cell as SOME((_,tpairs),_)) = |
|
1562 |
Seq.it_right (addth NONE (newAs(rev rAs, 0, [BBi], tpairs))) |
|
4270 | 1563 |
(Seq.make (fn()=> cell), Seq.empty) |
0 | 1564 |
in if eres_flg then eres(rev rAs) |
16425
2427be27cc60
accomodate identification of type Sign.sg and theory;
wenzelm
parents:
16352
diff
changeset
|
1565 |
else res(Seq.pull(Unify.unifiers(thy, env, dpairs))) |
0 | 1566 |
end; |
7528 | 1567 |
end; |
0 | 1568 |
|
18501
915105af2e80
turned bicompose_no_flatten into compose_no_flatten, without elimination;
wenzelm
parents:
18486
diff
changeset
|
1569 |
fun compose_no_flatten match (orule, nsubgoal) i state = |
915105af2e80
turned bicompose_no_flatten into compose_no_flatten, without elimination;
wenzelm
parents:
18486
diff
changeset
|
1570 |
bicompose_aux false match (state, dest_state (state, i), false) (false, orule, nsubgoal); |
0 | 1571 |
|
18501
915105af2e80
turned bicompose_no_flatten into compose_no_flatten, without elimination;
wenzelm
parents:
18486
diff
changeset
|
1572 |
fun bicompose match arg i state = |
915105af2e80
turned bicompose_no_flatten into compose_no_flatten, without elimination;
wenzelm
parents:
18486
diff
changeset
|
1573 |
bicompose_aux true match (state, dest_state (state,i), false) arg; |
0 | 1574 |
|
1575 |
(*Quick test whether rule is resolvable with the subgoal with hyps Hs |
|
1576 |
and conclusion B. If eres_flg then checks 1st premise of rule also*) |
|
1577 |
fun could_bires (Hs, B, eres_flg, rule) = |
|
16847
8fc160b12e73
invoke_oracle: do not keep theory value, but theory_ref;
wenzelm
parents:
16725
diff
changeset
|
1578 |
let fun could_reshyp (A1::_) = exists (fn H => could_unify (A1, H)) Hs |
250 | 1579 |
| could_reshyp [] = false; (*no premise -- illegal*) |
1580 |
in could_unify(concl_of rule, B) andalso |
|
1581 |
(not eres_flg orelse could_reshyp (prems_of rule)) |
|
0 | 1582 |
end; |
1583 |
||
1584 |
(*Bi-resolution of a state with a list of (flag,rule) pairs. |
|
1585 |
Puts the rule above: rule/state. Renames vars in the rules. *) |
|
250 | 1586 |
fun biresolution match brules i state = |
18035 | 1587 |
let val (stpairs, Bs, Bi, C) = dest_state(state,i); |
18145 | 1588 |
val lift = lift_rule (cprem_of state i); |
250 | 1589 |
val B = Logic.strip_assums_concl Bi; |
1590 |
val Hs = Logic.strip_assums_hyp Bi; |
|
22573 | 1591 |
val compose = bicompose_aux true match (state, (stpairs, Bs, Bi, C), true); |
4270 | 1592 |
fun res [] = Seq.empty |
250 | 1593 |
| res ((eres_flg, rule)::brules) = |
13642
a3d97348ceb6
added failure trace information to pattern unification
nipkow
parents:
13629
diff
changeset
|
1594 |
if !Pattern.trace_unify_fail orelse |
a3d97348ceb6
added failure trace information to pattern unification
nipkow
parents:
13629
diff
changeset
|
1595 |
could_bires (Hs, B, eres_flg, rule) |
4270 | 1596 |
then Seq.make (*delay processing remainder till needed*) |
22573 | 1597 |
(fn()=> SOME(compose (eres_flg, lift rule, nprems_of rule), |
250 | 1598 |
res brules)) |
1599 |
else res brules |
|
4270 | 1600 |
in Seq.flat (res brules) end; |
0 | 1601 |
|
1602 |
||
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1603 |
|
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1604 |
(*** Promises ***) |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1605 |
|
28330 | 1606 |
(* promise *) |
1607 |
||
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1608 |
fun promise future ct = |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1609 |
let |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1610 |
val {thy_ref = thy_ref, t = prop, T, maxidx, sorts} = rep_cterm ct; |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1611 |
val thy = Context.reject_draft (Theory.deref thy_ref); |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1612 |
val _ = T <> propT andalso raise CTERM ("promise: prop expected", [ct]); |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1613 |
val i = serial (); |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1614 |
in |
28330 | 1615 |
Thm (make_deriv false [(i, Promise (future, thy, sorts, prop))] (Pt.promise_proof i prop), |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1616 |
{thy_ref = thy_ref, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1617 |
tags = [], |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1618 |
maxidx = maxidx, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1619 |
shyps = sorts, |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1620 |
hyps = [], |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1621 |
tpairs = [], |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1622 |
prop = prop}) |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1623 |
end; |
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1624 |
|
28330 | 1625 |
fun check_promise (i, Promise (future, thy1, shyps1, prop1)) = |
1626 |
let |
|
1627 |
val thm = transfer thy1 (Future.join future); |
|
1628 |
val _ = Theory.check_thy thy1; |
|
1629 |
fun err msg = raise THM ("check_promise: " ^ msg, 0, [thm]); |
|
1630 |
||
1631 |
val Thm (Deriv {oracle, proof, promises}, {shyps, hyps, tpairs, prop, ...}) = thm; |
|
1632 |
val _ = null promises orelse err "illegal nested promises"; |
|
1633 |
val _ = shyps = shyps1 orelse err "bad shyps"; |
|
1634 |
val _ = null hyps orelse err "bad hyps"; |
|
1635 |
val _ = null tpairs orelse err "bad tpairs"; |
|
1636 |
val _ = prop aconv prop1 orelse err "bad prop"; |
|
1637 |
in (oracle, (i, proof)) end; |
|
1638 |
||
1639 |
||
1640 |
(* fulfill *) |
|
1641 |
||
1642 |
fun fulfill (thm as Thm (Deriv {oracle, proof, promises}, args)) = |
|
1643 |
let |
|
1644 |
val _ = Future.join_results (map (fn (_, Promise (future, _, _, _)) => future) promises); |
|
1645 |
val results = map check_promise promises; |
|
1646 |
||
1647 |
val ora = oracle orelse exists #1 results; |
|
1648 |
val prf = Pt.fulfill (fold (Inttab.update o #2) results Inttab.empty) proof; |
|
1649 |
in Thm (make_deriv ora [] prf, args) end; |
|
1650 |
||
1651 |
val proof_of = fulfill #> (fn Thm (Deriv {proof, ...}, _) => proof); |
|
1652 |
||
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1653 |
|
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1654 |
|
2509 | 1655 |
(*** Oracles ***) |
1656 |
||
28290 | 1657 |
(* oracle rule *) |
1658 |
||
1659 |
fun invoke_oracle thy_ref1 name oracle arg = |
|
1660 |
let val {thy_ref = thy_ref2, t = prop, T, maxidx, sorts} = rep_cterm (oracle arg) in |
|
1661 |
if T <> propT then |
|
1662 |
raise THM ("Oracle's result must have type prop: " ^ name, 0, []) |
|
1663 |
else |
|
28330 | 1664 |
Thm (make_deriv true [] (Pt.oracle_proof name prop), |
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1665 |
{thy_ref = Theory.merge_refs (thy_ref1, thy_ref2), |
28290 | 1666 |
tags = [], |
1667 |
maxidx = maxidx, |
|
1668 |
shyps = sorts, |
|
1669 |
hyps = [], |
|
1670 |
tpairs = [], |
|
28321
9f4499bf9384
type thm: fully internal derivation, no longer exported;
wenzelm
parents:
28290
diff
changeset
|
1671 |
prop = prop}) |
3812 | 1672 |
end; |
1673 |
||
22237
bb9b1c8a8a95
old-fashioned abstype ctyp/cterm/thm prevents accidental equality tests;
wenzelm
parents:
21975
diff
changeset
|
1674 |
end; |
bb9b1c8a8a95
old-fashioned abstype ctyp/cterm/thm prevents accidental equality tests;
wenzelm
parents:
21975
diff
changeset
|
1675 |
end; |
bb9b1c8a8a95
old-fashioned abstype ctyp/cterm/thm prevents accidental equality tests;
wenzelm
parents:
21975
diff
changeset
|
1676 |
end; |
28290 | 1677 |
|
1678 |
||
1679 |
(* authentic derivation names *) |
|
1680 |
||
1681 |
fun err_dup_ora dup = error ("Duplicate oracle: " ^ quote dup); |
|
1682 |
||
1683 |
structure Oracles = TheoryDataFun |
|
1684 |
( |
|
1685 |
type T = stamp NameSpace.table; |
|
1686 |
val empty = NameSpace.empty_table; |
|
1687 |
val copy = I; |
|
1688 |
val extend = I; |
|
1689 |
fun merge _ oracles = NameSpace.merge_tables (op =) oracles |
|
1690 |
handle Symtab.DUP dup => err_dup_ora dup; |
|
1691 |
); |
|
1692 |
||
1693 |
val extern_oracles = map #1 o NameSpace.extern_table o Oracles.get; |
|
1694 |
||
1695 |
fun add_oracle (bname, oracle) thy = |
|
1696 |
let |
|
1697 |
val naming = Sign.naming_of thy; |
|
1698 |
val name = NameSpace.full naming bname; |
|
1699 |
val thy' = thy |> Oracles.map (fn (space, tab) => |
|
1700 |
(NameSpace.declare naming name space, |
|
1701 |
Symtab.update_new (name, stamp ()) tab handle Symtab.DUP dup => err_dup_ora dup)); |
|
1702 |
in ((name, invoke_oracle (Theory.check_thy thy') name oracle), thy') end; |
|
1703 |
||
0 | 1704 |
end; |
1503 | 1705 |
|
6089 | 1706 |
structure BasicThm: BASIC_THM = Thm; |
1707 |
open BasicThm; |