author | wenzelm |
Sat, 17 Dec 2016 14:13:15 +0100 | |
changeset 64581 | ee4b9cea7fb5 |
parent 63063 | c9605a284fba |
child 67721 | 5348bea4accd |
permissions | -rw-r--r-- |
9460 | 1 |
(* Title: Pure/logic.ML |
2 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
29276 | 3 |
Author: Makarius |
0 | 4 |
|
9460 | 5 |
Abstract syntax operations of the Pure meta-logic. |
0 | 6 |
*) |
7 |
||
9460 | 8 |
signature LOGIC = |
4345 | 9 |
sig |
46217
7b19666f0e3d
renamed Term.all to Logic.all_const, in accordance to HOLogic.all_const;
wenzelm
parents:
46215
diff
changeset
|
10 |
val all_const: typ -> term |
27334 | 11 |
val all: term -> term -> term |
61655
f217bbe4e93e
avoid vacuous quantification, as usual for shared variable scope;
wenzelm
parents:
61654
diff
changeset
|
12 |
val dependent_all_name: string * term -> term -> term |
27334 | 13 |
val is_all: term -> bool |
14 |
val dest_all: term -> (string * typ) * term |
|
46218
ecf6375e2abb
renamed Term.list_all to Logic.list_all, in accordance to HOLogic.list_all;
wenzelm
parents:
46217
diff
changeset
|
15 |
val list_all: (string * typ) list * term -> term |
60454
a4c6b278f3a7
eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents:
59787
diff
changeset
|
16 |
val all_constraint: (string -> typ option) -> string * string -> term -> term |
a4c6b278f3a7
eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents:
59787
diff
changeset
|
17 |
val dependent_all_constraint: (string -> typ option) -> string * string -> term -> term |
18181 | 18 |
val mk_equals: term * term -> term |
19 |
val dest_equals: term -> term * term |
|
27334 | 20 |
val implies: term |
18181 | 21 |
val mk_implies: term * term -> term |
22 |
val dest_implies: term -> term * term |
|
23 |
val list_implies: term list * term -> term |
|
24 |
val strip_imp_prems: term -> term list |
|
25 |
val strip_imp_concl: term -> term |
|
26 |
val strip_prems: int * term list * term -> term list * term |
|
21576 | 27 |
val count_prems: term -> int |
18181 | 28 |
val nth_prem: int * term -> term |
63056
9b95ae9ec671
defs are closed, which leads to proper auto_bind_facts;
wenzelm
parents:
61655
diff
changeset
|
29 |
val close_term: (string * term) list -> term -> term |
9b95ae9ec671
defs are closed, which leads to proper auto_bind_facts;
wenzelm
parents:
61655
diff
changeset
|
30 |
val close_prop: (string * term) list -> term list -> term -> term |
63063 | 31 |
val close_prop_constraint: (string -> typ option) -> |
32 |
(string * string) list -> term list -> term -> term |
|
23418 | 33 |
val true_prop: term |
19125
59b26248547b
simplified Pure conjunction, based on actual const;
wenzelm
parents:
19103
diff
changeset
|
34 |
val conjunction: term |
18181 | 35 |
val mk_conjunction: term * term -> term |
12757 | 36 |
val mk_conjunction_list: term list -> term |
23418 | 37 |
val mk_conjunction_balanced: term list -> term |
18469 | 38 |
val dest_conjunction: term -> term * term |
19425 | 39 |
val dest_conjunction_list: term -> term list |
23418 | 40 |
val dest_conjunction_balanced: int -> term -> term list |
18469 | 41 |
val dest_conjunctions: term -> term list |
18181 | 42 |
val strip_horn: term -> term list * term |
21520 | 43 |
val mk_type: typ -> term |
18938 | 44 |
val dest_type: term -> typ |
21520 | 45 |
val type_map: (term -> term) -> typ -> typ |
18938 | 46 |
val const_of_class: class -> string |
47 |
val class_of_const: string -> class |
|
31943
5e960a0780a2
renamed inclass/Inclass to of_class/OfClass, in accordance to of_sort;
wenzelm
parents:
30554
diff
changeset
|
48 |
val mk_of_class: typ * class -> term |
5e960a0780a2
renamed inclass/Inclass to of_class/OfClass, in accordance to of_sort;
wenzelm
parents:
30554
diff
changeset
|
49 |
val dest_of_class: term -> typ * class |
35854 | 50 |
val mk_of_sort: typ * sort -> term list |
20630 | 51 |
val name_classrel: string * string -> string |
19406
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
52 |
val mk_classrel: class * class -> term |
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
53 |
val dest_classrel: term -> class * class |
20630 | 54 |
val name_arities: arity -> string list |
55 |
val name_arity: string * sort list * class -> string |
|
56 |
val mk_arities: arity -> term list |
|
19406
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
57 |
val dest_arity: term -> string * sort list * class |
45328 | 58 |
val unconstrainT: sort list -> term -> |
37230
7b548f137276
outer_constraints with original variable names, to ensure that argsP is consistent with args
berghofe
parents:
36768
diff
changeset
|
59 |
((typ -> typ) * ((typ * class) * term) list * (typ * class) list) * term |
18181 | 60 |
val protectC: term |
61 |
val protect: term -> term |
|
62 |
val unprotect: term -> term |
|
19775 | 63 |
val mk_term: term -> term |
64 |
val dest_term: term -> term |
|
18181 | 65 |
val occs: term * term -> bool |
66 |
val close_form: term -> term |
|
18938 | 67 |
val combound: term * int * int -> term |
68 |
val rlist_abs: (string * typ) list * term -> term |
|
32023 | 69 |
val incr_tvar_same: int -> typ Same.operation |
70 |
val incr_tvar: int -> typ -> typ |
|
59787 | 71 |
val incr_indexes_same: string list * typ list * int -> term Same.operation |
72 |
val incr_indexes: string list * typ list * int -> term -> term |
|
18181 | 73 |
val lift_abs: int -> term -> term -> term |
74 |
val lift_all: int -> term -> term -> term |
|
75 |
val strip_assums_hyp: term -> term list |
|
9460 | 76 |
val strip_assums_concl: term -> term |
18181 | 77 |
val strip_params: term -> (string * typ) list |
23597 | 78 |
val has_meta_prems: term -> bool |
18181 | 79 |
val flatten_params: int -> term -> term |
45328 | 80 |
val list_rename_params: string list -> term -> term |
81 |
val assum_pairs: int * term -> (term * term) list |
|
30554
73f8bd5f0af8
substantial speedup of assumption and elim-resolution: Logic.assum_problems refrains from eager application of parameters, discriminate via Term.could_unify before invoking full unification (assumes terms in beta-normal form, as do higher term net operations anyway);
wenzelm
parents:
30364
diff
changeset
|
82 |
val assum_problems: int * term -> (term -> term) * term list * term |
35845
e5980f0ad025
renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
wenzelm
parents:
32784
diff
changeset
|
83 |
val varifyT_global: typ -> typ |
e5980f0ad025
renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
wenzelm
parents:
32784
diff
changeset
|
84 |
val unvarifyT_global: typ -> typ |
45344
e209da839ff4
added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
wenzelm
parents:
45328
diff
changeset
|
85 |
val varify_types_global: term -> term |
e209da839ff4
added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
wenzelm
parents:
45328
diff
changeset
|
86 |
val unvarify_types_global: term -> term |
35845
e5980f0ad025
renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
wenzelm
parents:
32784
diff
changeset
|
87 |
val varify_global: term -> term |
e5980f0ad025
renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
wenzelm
parents:
32784
diff
changeset
|
88 |
val unvarify_global: term -> term |
18181 | 89 |
val get_goal: term -> int -> term |
90 |
val goal_params: term -> int -> term * term list |
|
91 |
val prems_of_goal: term -> int -> term list |
|
92 |
val concl_of_goal: term -> int -> term |
|
4345 | 93 |
end; |
0 | 94 |
|
1500 | 95 |
structure Logic : LOGIC = |
0 | 96 |
struct |
398
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
97 |
|
4345 | 98 |
|
0 | 99 |
(*** Abstract syntax operations on the meta-connectives ***) |
100 |
||
23238 | 101 |
(** all **) |
5041
a1d0a6d555cd
Goals may now contain assumptions, which are not returned.
nipkow
parents:
4822
diff
changeset
|
102 |
|
56245 | 103 |
fun all_const T = Const ("Pure.all", (T --> propT) --> propT); |
46217
7b19666f0e3d
renamed Term.all to Logic.all_const, in accordance to HOLogic.all_const;
wenzelm
parents:
46215
diff
changeset
|
104 |
|
7b19666f0e3d
renamed Term.all to Logic.all_const, in accordance to HOLogic.all_const;
wenzelm
parents:
46215
diff
changeset
|
105 |
fun all v t = all_const (Term.fastype_of v) $ lambda v t; |
61655
f217bbe4e93e
avoid vacuous quantification, as usual for shared variable scope;
wenzelm
parents:
61654
diff
changeset
|
106 |
|
f217bbe4e93e
avoid vacuous quantification, as usual for shared variable scope;
wenzelm
parents:
61654
diff
changeset
|
107 |
fun dependent_all_name (x, v) t = |
f217bbe4e93e
avoid vacuous quantification, as usual for shared variable scope;
wenzelm
parents:
61654
diff
changeset
|
108 |
let |
f217bbe4e93e
avoid vacuous quantification, as usual for shared variable scope;
wenzelm
parents:
61654
diff
changeset
|
109 |
val x' = if x = "" then Term.term_name v else x; |
f217bbe4e93e
avoid vacuous quantification, as usual for shared variable scope;
wenzelm
parents:
61654
diff
changeset
|
110 |
val T = Term.fastype_of v; |
f217bbe4e93e
avoid vacuous quantification, as usual for shared variable scope;
wenzelm
parents:
61654
diff
changeset
|
111 |
val t' = Term.abstract_over (v, t); |
f217bbe4e93e
avoid vacuous quantification, as usual for shared variable scope;
wenzelm
parents:
61654
diff
changeset
|
112 |
in if Term.is_dependent t' then all_const T $ Abs (x', T, t') else t end; |
27334 | 113 |
|
56245 | 114 |
fun is_all (Const ("Pure.all", _) $ Abs _) = true |
27334 | 115 |
| is_all _ = false; |
116 |
||
56245 | 117 |
fun dest_all (Const ("Pure.all", _) $ Abs (abs as (_, T, _))) = |
27334 | 118 |
let val (x, b) = Term.dest_abs abs (*potentially slow*) |
119 |
in ((x, T), b) end |
|
18762 | 120 |
| dest_all t = raise TERM ("dest_all", [t]); |
121 |
||
46218
ecf6375e2abb
renamed Term.list_all to Logic.list_all, in accordance to HOLogic.list_all;
wenzelm
parents:
46217
diff
changeset
|
122 |
fun list_all ([], t) = t |
ecf6375e2abb
renamed Term.list_all to Logic.list_all, in accordance to HOLogic.list_all;
wenzelm
parents:
46217
diff
changeset
|
123 |
| list_all ((a, T) :: vars, t) = all_const T $ Abs (a, T, list_all (vars, t)); |
ecf6375e2abb
renamed Term.list_all to Logic.list_all, in accordance to HOLogic.list_all;
wenzelm
parents:
46217
diff
changeset
|
124 |
|
18762 | 125 |
|
60454
a4c6b278f3a7
eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents:
59787
diff
changeset
|
126 |
(* operations before type-inference *) |
a4c6b278f3a7
eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents:
59787
diff
changeset
|
127 |
|
a4c6b278f3a7
eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents:
59787
diff
changeset
|
128 |
local |
a4c6b278f3a7
eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents:
59787
diff
changeset
|
129 |
|
a4c6b278f3a7
eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents:
59787
diff
changeset
|
130 |
fun abs_body default_type z tm = |
a4c6b278f3a7
eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents:
59787
diff
changeset
|
131 |
let |
a4c6b278f3a7
eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents:
59787
diff
changeset
|
132 |
fun abs lev (Abs (x, T, b)) = Abs (x, T, abs (lev + 1) b) |
a4c6b278f3a7
eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents:
59787
diff
changeset
|
133 |
| abs lev (t $ u) = abs lev t $ abs lev u |
a4c6b278f3a7
eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents:
59787
diff
changeset
|
134 |
| abs lev (a as Free (x, T)) = |
a4c6b278f3a7
eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents:
59787
diff
changeset
|
135 |
if x = z then |
a4c6b278f3a7
eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents:
59787
diff
changeset
|
136 |
Type.constraint (the_default dummyT (default_type x)) |
a4c6b278f3a7
eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents:
59787
diff
changeset
|
137 |
(Type.constraint T (Bound lev)) |
a4c6b278f3a7
eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents:
59787
diff
changeset
|
138 |
else a |
a4c6b278f3a7
eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents:
59787
diff
changeset
|
139 |
| abs _ a = a; |
a4c6b278f3a7
eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents:
59787
diff
changeset
|
140 |
in abs 0 (Term.incr_boundvars 1 tm) end; |
a4c6b278f3a7
eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents:
59787
diff
changeset
|
141 |
|
a4c6b278f3a7
eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents:
59787
diff
changeset
|
142 |
in |
a4c6b278f3a7
eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents:
59787
diff
changeset
|
143 |
|
a4c6b278f3a7
eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents:
59787
diff
changeset
|
144 |
fun all_constraint default_type (y, z) t = |
a4c6b278f3a7
eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents:
59787
diff
changeset
|
145 |
all_const dummyT $ Abs (y, dummyT, abs_body default_type z t); |
a4c6b278f3a7
eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents:
59787
diff
changeset
|
146 |
|
a4c6b278f3a7
eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents:
59787
diff
changeset
|
147 |
fun dependent_all_constraint default_type (y, z) t = |
a4c6b278f3a7
eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents:
59787
diff
changeset
|
148 |
let val t' = abs_body default_type z t |
a4c6b278f3a7
eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents:
59787
diff
changeset
|
149 |
in if Term.is_dependent t' then all_const dummyT $ Abs (y, dummyT, t') else t end; |
a4c6b278f3a7
eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents:
59787
diff
changeset
|
150 |
|
a4c6b278f3a7
eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents:
59787
diff
changeset
|
151 |
end; |
a4c6b278f3a7
eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents:
59787
diff
changeset
|
152 |
|
a4c6b278f3a7
eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents:
59787
diff
changeset
|
153 |
|
0 | 154 |
(** equality **) |
155 |
||
27334 | 156 |
fun mk_equals (t, u) = |
157 |
let val T = Term.fastype_of t |
|
56245 | 158 |
in Const ("Pure.eq", T --> T --> propT) $ t $ u end; |
0 | 159 |
|
56245 | 160 |
fun dest_equals (Const ("Pure.eq", _) $ t $ u) = (t, u) |
20883 | 161 |
| dest_equals t = raise TERM ("dest_equals", [t]); |
637 | 162 |
|
163 |
||
0 | 164 |
(** implies **) |
165 |
||
56245 | 166 |
val implies = Const ("Pure.imp", propT --> propT --> propT); |
27334 | 167 |
|
20883 | 168 |
fun mk_implies (A, B) = implies $ A $ B; |
0 | 169 |
|
56245 | 170 |
fun dest_implies (Const ("Pure.imp", _) $ A $ B) = (A, B) |
20883 | 171 |
| dest_implies A = raise TERM ("dest_implies", [A]); |
5041
a1d0a6d555cd
Goals may now contain assumptions, which are not returned.
nipkow
parents:
4822
diff
changeset
|
172 |
|
4822 | 173 |
|
0 | 174 |
(** nested implications **) |
175 |
||
176 |
(* [A1,...,An], B goes to A1==>...An==>B *) |
|
18181 | 177 |
fun list_implies ([], B) = B |
178 |
| list_implies (A::As, B) = implies $ A $ list_implies(As,B); |
|
0 | 179 |
|
180 |
(* A1==>...An==>B goes to [A1,...,An], where B is not an implication *) |
|
56245 | 181 |
fun strip_imp_prems (Const("Pure.imp", _) $ A $ B) = A :: strip_imp_prems B |
0 | 182 |
| strip_imp_prems _ = []; |
183 |
||
184 |
(* A1==>...An==>B goes to B, where B is not an implication *) |
|
56245 | 185 |
fun strip_imp_concl (Const("Pure.imp", _) $ A $ B) = strip_imp_concl B |
0 | 186 |
| strip_imp_concl A = A : term; |
187 |
||
188 |
(*Strip and return premises: (i, [], A1==>...Ai==>B) |
|
9460 | 189 |
goes to ([Ai, A(i-1),...,A1] , B) (REVERSED) |
0 | 190 |
if i<0 or else i too big then raises TERM*) |
9460 | 191 |
fun strip_prems (0, As, B) = (As, B) |
56245 | 192 |
| strip_prems (i, As, Const("Pure.imp", _) $ A $ B) = |
9460 | 193 |
strip_prems (i-1, A::As, B) |
0 | 194 |
| strip_prems (_, As, A) = raise TERM("strip_prems", A::As); |
195 |
||
16130 | 196 |
(*Count premises -- quicker than (length o strip_prems) *) |
56245 | 197 |
fun count_prems (Const ("Pure.imp", _) $ _ $ B) = 1 + count_prems B |
21576 | 198 |
| count_prems _ = 0; |
0 | 199 |
|
16130 | 200 |
(*Select Ai from A1 ==>...Ai==>B*) |
56245 | 201 |
fun nth_prem (1, Const ("Pure.imp", _) $ A $ _) = A |
202 |
| nth_prem (i, Const ("Pure.imp", _) $ _ $ B) = nth_prem (i - 1, B) |
|
16130 | 203 |
| nth_prem (_, A) = raise TERM ("nth_prem", [A]); |
204 |
||
13659
3cf622f6b0b2
Removed obsolete functions dealing with flex-flex constraints.
berghofe
parents:
12902
diff
changeset
|
205 |
(*strip a proof state (Horn clause): |
3cf622f6b0b2
Removed obsolete functions dealing with flex-flex constraints.
berghofe
parents:
12902
diff
changeset
|
206 |
B1 ==> ... Bn ==> C goes to ([B1, ..., Bn], C) *) |
3cf622f6b0b2
Removed obsolete functions dealing with flex-flex constraints.
berghofe
parents:
12902
diff
changeset
|
207 |
fun strip_horn A = (strip_imp_prems A, strip_imp_concl A); |
3cf622f6b0b2
Removed obsolete functions dealing with flex-flex constraints.
berghofe
parents:
12902
diff
changeset
|
208 |
|
4822 | 209 |
|
63063 | 210 |
(* close -- omit vacuous quantifiers *) |
63056
9b95ae9ec671
defs are closed, which leads to proper auto_bind_facts;
wenzelm
parents:
61655
diff
changeset
|
211 |
|
9b95ae9ec671
defs are closed, which leads to proper auto_bind_facts;
wenzelm
parents:
61655
diff
changeset
|
212 |
val close_term = fold_rev Term.dependent_lambda_name; |
63063 | 213 |
|
214 |
fun close_prop xs As B = |
|
215 |
fold_rev dependent_all_name xs (list_implies (As, B)); |
|
216 |
||
217 |
fun close_prop_constraint default_type xs As B = |
|
218 |
fold_rev (dependent_all_constraint default_type) xs (list_implies (As, B)); |
|
63056
9b95ae9ec671
defs are closed, which leads to proper auto_bind_facts;
wenzelm
parents:
61655
diff
changeset
|
219 |
|
23418 | 220 |
|
12137 | 221 |
(** conjunction **) |
222 |
||
46217
7b19666f0e3d
renamed Term.all to Logic.all_const, in accordance to HOLogic.all_const;
wenzelm
parents:
46215
diff
changeset
|
223 |
val true_prop = all_const propT $ Abs ("dummy", propT, mk_implies (Bound 0, Bound 0)); |
26424 | 224 |
val conjunction = Const ("Pure.conjunction", propT --> propT --> propT); |
19125
59b26248547b
simplified Pure conjunction, based on actual const;
wenzelm
parents:
19103
diff
changeset
|
225 |
|
23418 | 226 |
|
28856
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
wenzelm
parents:
28448
diff
changeset
|
227 |
(*A &&& B*) |
19125
59b26248547b
simplified Pure conjunction, based on actual const;
wenzelm
parents:
19103
diff
changeset
|
228 |
fun mk_conjunction (A, B) = conjunction $ A $ B; |
12137 | 229 |
|
28856
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
wenzelm
parents:
28448
diff
changeset
|
230 |
(*A &&& B &&& C -- improper*) |
23418 | 231 |
fun mk_conjunction_list [] = true_prop |
12757 | 232 |
| mk_conjunction_list ts = foldr1 mk_conjunction ts; |
12137 | 233 |
|
28856
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
wenzelm
parents:
28448
diff
changeset
|
234 |
(*(A &&& B) &&& (C &&& D) -- balanced*) |
23418 | 235 |
fun mk_conjunction_balanced [] = true_prop |
32765 | 236 |
| mk_conjunction_balanced ts = Balanced_Tree.make mk_conjunction ts; |
23418 | 237 |
|
18499 | 238 |
|
28856
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
wenzelm
parents:
28448
diff
changeset
|
239 |
(*A &&& B*) |
26424 | 240 |
fun dest_conjunction (Const ("Pure.conjunction", _) $ A $ B) = (A, B) |
18469 | 241 |
| dest_conjunction t = raise TERM ("dest_conjunction", [t]); |
242 |
||
28856
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
wenzelm
parents:
28448
diff
changeset
|
243 |
(*A &&& B &&& C -- improper*) |
19425 | 244 |
fun dest_conjunction_list t = |
245 |
(case try dest_conjunction t of |
|
246 |
NONE => [t] |
|
247 |
| SOME (A, B) => A :: dest_conjunction_list B); |
|
248 |
||
28856
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
wenzelm
parents:
28448
diff
changeset
|
249 |
(*(A &&& B) &&& (C &&& D) -- balanced*) |
23418 | 250 |
fun dest_conjunction_balanced 0 _ = [] |
32765 | 251 |
| dest_conjunction_balanced n t = Balanced_Tree.dest dest_conjunction n t; |
23418 | 252 |
|
28856
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
wenzelm
parents:
28448
diff
changeset
|
253 |
(*((A &&& B) &&& C) &&& D &&& E -- flat*) |
18469 | 254 |
fun dest_conjunctions t = |
255 |
(case try dest_conjunction t of |
|
256 |
NONE => [t] |
|
257 |
| SOME (A, B) => dest_conjunctions A @ dest_conjunctions B); |
|
258 |
||
259 |
||
12137 | 260 |
|
398
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
261 |
(** types as terms **) |
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
262 |
|
56243 | 263 |
fun mk_type ty = Const ("Pure.type", Term.itselfT ty); |
398
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
264 |
|
56243 | 265 |
fun dest_type (Const ("Pure.type", Type ("itself", [ty]))) = ty |
398
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
266 |
| dest_type t = raise TERM ("dest_type", [t]); |
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
267 |
|
21520 | 268 |
fun type_map f = dest_type o f o mk_type; |
269 |
||
4822 | 270 |
|
19406
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
271 |
|
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
272 |
(** type classes **) |
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
273 |
|
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
274 |
(* const names *) |
398
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
275 |
|
18938 | 276 |
val classN = "_class"; |
277 |
||
278 |
val const_of_class = suffix classN; |
|
19406
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
279 |
|
18938 | 280 |
fun class_of_const c = unsuffix classN c |
281 |
handle Fail _ => raise TERM ("class_of_const: bad name " ^ quote c, []); |
|
282 |
||
19406
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
283 |
|
35854 | 284 |
(* class/sort membership *) |
19406
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
285 |
|
31943
5e960a0780a2
renamed inclass/Inclass to of_class/OfClass, in accordance to of_sort;
wenzelm
parents:
30554
diff
changeset
|
286 |
fun mk_of_class (ty, c) = |
19391 | 287 |
Const (const_of_class c, Term.itselfT ty --> propT) $ mk_type ty; |
398
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
288 |
|
32784 | 289 |
fun dest_of_class (Const (c_class, _) $ ty) = (dest_type ty, class_of_const c_class) |
31943
5e960a0780a2
renamed inclass/Inclass to of_class/OfClass, in accordance to of_sort;
wenzelm
parents:
30554
diff
changeset
|
290 |
| dest_of_class t = raise TERM ("dest_of_class", [t]); |
398
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
291 |
|
35854 | 292 |
fun mk_of_sort (ty, S) = map (fn c => mk_of_class (ty, c)) S; |
293 |
||
0 | 294 |
|
19406
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
295 |
(* class relations *) |
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
296 |
|
20630 | 297 |
fun name_classrel (c1, c2) = |
30364
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
30280
diff
changeset
|
298 |
Long_Name.base_name c1 ^ "_" ^ Long_Name.base_name c2; |
20630 | 299 |
|
31943
5e960a0780a2
renamed inclass/Inclass to of_class/OfClass, in accordance to of_sort;
wenzelm
parents:
30554
diff
changeset
|
300 |
fun mk_classrel (c1, c2) = mk_of_class (Term.aT [c1], c2); |
19406
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
301 |
|
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
302 |
fun dest_classrel tm = |
31943
5e960a0780a2
renamed inclass/Inclass to of_class/OfClass, in accordance to of_sort;
wenzelm
parents:
30554
diff
changeset
|
303 |
(case dest_of_class tm of |
19406
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
304 |
(TVar (_, [c1]), c2) => (c1, c2) |
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
305 |
| _ => raise TERM ("dest_classrel", [tm])); |
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
306 |
|
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
307 |
|
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
308 |
(* type arities *) |
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
309 |
|
20630 | 310 |
fun name_arities (t, _, S) = |
30364
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
30280
diff
changeset
|
311 |
let val b = Long_Name.base_name t |
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
30280
diff
changeset
|
312 |
in S |> map (fn c => Long_Name.base_name c ^ "_" ^ b) end; |
20630 | 313 |
|
314 |
fun name_arity (t, dom, c) = hd (name_arities (t, dom, [c])); |
|
315 |
||
19406
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
316 |
fun mk_arities (t, Ss, S) = |
43329
84472e198515
tuned signature: Name.invent and Name.invent_names;
wenzelm
parents:
37230
diff
changeset
|
317 |
let val T = Type (t, ListPair.map TFree (Name.invent Name.context Name.aT (length Ss), Ss)) |
31943
5e960a0780a2
renamed inclass/Inclass to of_class/OfClass, in accordance to of_sort;
wenzelm
parents:
30554
diff
changeset
|
318 |
in map (fn c => mk_of_class (T, c)) S end; |
19406
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
319 |
|
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
320 |
fun dest_arity tm = |
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
321 |
let |
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
322 |
fun err () = raise TERM ("dest_arity", [tm]); |
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
323 |
|
31943
5e960a0780a2
renamed inclass/Inclass to of_class/OfClass, in accordance to of_sort;
wenzelm
parents:
30554
diff
changeset
|
324 |
val (ty, c) = dest_of_class tm; |
19406
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
325 |
val (t, tvars) = |
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
326 |
(case ty of |
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
327 |
Type (t, tys) => (t, map dest_TVar tys handle TYPE _ => err ()) |
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
328 |
| _ => err ()); |
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
329 |
val Ss = |
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
330 |
if has_duplicates (eq_fst (op =)) tvars then err () |
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
331 |
else map snd tvars; |
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
332 |
in (t, Ss, c) end; |
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
333 |
|
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents:
19391
diff
changeset
|
334 |
|
36767
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
335 |
(* internalized sort constraints *) |
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
336 |
|
36768
46be86127972
just one version of Thm.unconstrainT, which affects all variables;
wenzelm
parents:
36767
diff
changeset
|
337 |
fun unconstrainT shyps prop = |
36767
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
338 |
let |
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
339 |
val present = rev ((fold_types o fold_atyps_sorts) (insert (eq_fst op =)) prop []); |
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
340 |
val extra = fold (Sorts.remove_sort o #2) present shyps; |
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
341 |
|
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
342 |
val n = length present; |
43329
84472e198515
tuned signature: Name.invent and Name.invent_names;
wenzelm
parents:
37230
diff
changeset
|
343 |
val (names1, names2) = Name.invent Name.context Name.aT (n + length extra) |> chop n; |
36767
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
344 |
|
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
345 |
val present_map = |
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
346 |
map2 (fn (T, S) => fn a => (T, TVar ((a, 0), S))) present names1; |
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
347 |
val constraints_map = |
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
348 |
map2 (fn (_, S) => fn a => (S, TVar ((a, 0), S))) present names1 @ |
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
349 |
map2 (fn S => fn a => (S, TVar ((a, 0), S))) extra names2; |
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
350 |
|
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
351 |
fun atyp_map T = |
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
352 |
(case AList.lookup (op =) present_map T of |
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
353 |
SOME U => U |
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
354 |
| NONE => |
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
355 |
(case AList.lookup (op =) constraints_map (Type.sort_of_atyp T) of |
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
356 |
SOME U => U |
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
357 |
| NONE => raise TYPE ("Dangling type variable", [T], []))); |
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
358 |
|
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
359 |
val constraints = |
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
360 |
maps (fn (_, T as TVar (ai, S)) => |
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
361 |
map (fn c => ((T, c), mk_of_class (TVar (ai, []), c))) S) |
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
362 |
constraints_map; |
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
363 |
|
37230
7b548f137276
outer_constraints with original variable names, to ensure that argsP is consistent with args
berghofe
parents:
36768
diff
changeset
|
364 |
val outer_constraints = |
7b548f137276
outer_constraints with original variable names, to ensure that argsP is consistent with args
berghofe
parents:
36768
diff
changeset
|
365 |
maps (fn (T, S) => map (pair T) S) |
7b548f137276
outer_constraints with original variable names, to ensure that argsP is consistent with args
berghofe
parents:
36768
diff
changeset
|
366 |
(present @ map (fn S => (TFree ("'dummy", S), S)) extra); |
7b548f137276
outer_constraints with original variable names, to ensure that argsP is consistent with args
berghofe
parents:
36768
diff
changeset
|
367 |
|
36767
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
368 |
val prop' = |
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
369 |
prop |
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
370 |
|> (Term.map_types o Term.map_atyps) (Type.strip_sorts o atyp_map) |
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
371 |
|> curry list_implies (map snd constraints); |
37230
7b548f137276
outer_constraints with original variable names, to ensure that argsP is consistent with args
berghofe
parents:
36768
diff
changeset
|
372 |
in ((atyp_map, constraints, outer_constraints), prop') end; |
36767
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
373 |
|
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents:
35854
diff
changeset
|
374 |
|
18938 | 375 |
|
28448 | 376 |
(** protected propositions and embedded terms **) |
9460 | 377 |
|
56244 | 378 |
val protectC = Const ("Pure.prop", propT --> propT); |
18029
19f1ad18bece
renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents:
17120
diff
changeset
|
379 |
fun protect t = protectC $ t; |
9460 | 380 |
|
56244 | 381 |
fun unprotect (Const ("Pure.prop", _) $ t) = t |
18029
19f1ad18bece
renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents:
17120
diff
changeset
|
382 |
| unprotect t = raise TERM ("unprotect", [t]); |
9460 | 383 |
|
384 |
||
26424 | 385 |
fun mk_term t = Const ("Pure.term", Term.fastype_of t --> propT) $ t; |
19775 | 386 |
|
26424 | 387 |
fun dest_term (Const ("Pure.term", _) $ t) = t |
19775 | 388 |
| dest_term t = raise TERM ("dest_term", [t]); |
389 |
||
390 |
||
18181 | 391 |
|
0 | 392 |
(*** Low-level term operations ***) |
393 |
||
394 |
(*Does t occur in u? Or is alpha-convertible to u? |
|
395 |
The term t must contain no loose bound variables*) |
|
16846 | 396 |
fun occs (t, u) = exists_subterm (fn s => t aconv s) u; |
0 | 397 |
|
398 |
(*Close up a formula over all free variables by quantification*) |
|
46215
0da9433f959e
discontinued old-style Term.list_all_free in favour of plain Logic.all;
wenzelm
parents:
45344
diff
changeset
|
399 |
fun close_form A = fold (all o Free) (Term.add_frees A []) A; |
0 | 400 |
|
401 |
||
18938 | 402 |
|
0 | 403 |
(*** Specialized operations for resolution... ***) |
404 |
||
18938 | 405 |
(*computes t(Bound(n+k-1),...,Bound(n)) *) |
406 |
fun combound (t, n, k) = |
|
407 |
if k>0 then combound (t,n+1,k-1) $ (Bound n) else t; |
|
408 |
||
409 |
(* ([xn,...,x1], t) ======> (x1,...,xn)t *) |
|
410 |
fun rlist_abs ([], body) = body |
|
411 |
| rlist_abs ((a,T)::pairs, body) = rlist_abs(pairs, Abs(a, T, body)); |
|
412 |
||
32026 | 413 |
fun incr_tvar_same 0 = Same.same |
414 |
| incr_tvar_same k = Term_Subst.map_atypsT_same |
|
415 |
(fn TVar ((a, i), S) => TVar ((a, i + k), S) |
|
416 |
| _ => raise Same.SAME); |
|
16879
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
417 |
|
32026 | 418 |
fun incr_tvar k T = incr_tvar_same k T handle Same.SAME => T; |
32023 | 419 |
|
0 | 420 |
(*For all variables in the term, increment indexnames and lift over the Us |
421 |
result is ?Gidx(B.(lev+n-1),...,B.lev) where lev is abstraction level *) |
|
59787 | 422 |
fun incr_indexes_same ([], [], 0) = Same.same |
423 |
| incr_indexes_same (fixed, Ts, k) = |
|
32020 | 424 |
let |
425 |
val n = length Ts; |
|
32026 | 426 |
val incrT = incr_tvar_same k; |
16879
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
427 |
|
32020 | 428 |
fun incr lev (Var ((x, i), T)) = |
429 |
combound (Var ((x, i + k), Ts ---> Same.commit incrT T), lev, n) |
|
59787 | 430 |
| incr lev (Free (x, T)) = |
431 |
if member (op =) fixed x then |
|
432 |
combound (Free (x, Ts ---> Same.commit incrT T), lev, n) |
|
433 |
else Free (x, incrT T) |
|
32020 | 434 |
| incr lev (Abs (x, T, body)) = |
435 |
(Abs (x, incrT T, incr (lev + 1) body handle Same.SAME => body) |
|
436 |
handle Same.SAME => Abs (x, T, incr (lev + 1) body)) |
|
437 |
| incr lev (t $ u) = |
|
438 |
(incr lev t $ (incr lev u handle Same.SAME => u) |
|
439 |
handle Same.SAME => t $ incr lev u) |
|
440 |
| incr _ (Const (c, T)) = Const (c, incrT T) |
|
32026 | 441 |
| incr _ (Bound _) = raise Same.SAME; |
442 |
in incr 0 end; |
|
443 |
||
444 |
fun incr_indexes arg t = incr_indexes_same arg t handle Same.SAME => t; |
|
16879
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
445 |
|
0 | 446 |
|
18248 | 447 |
(* Lifting functions from subgoal and increment: |
18029
19f1ad18bece
renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents:
17120
diff
changeset
|
448 |
lift_abs operates on terms |
19f1ad18bece
renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents:
17120
diff
changeset
|
449 |
lift_all operates on propositions *) |
19f1ad18bece
renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents:
17120
diff
changeset
|
450 |
|
19f1ad18bece
renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents:
17120
diff
changeset
|
451 |
fun lift_abs inc = |
19f1ad18bece
renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents:
17120
diff
changeset
|
452 |
let |
56245 | 453 |
fun lift Ts (Const ("Pure.imp", _) $ _ $ B) t = lift Ts B t |
454 |
| lift Ts (Const ("Pure.all", _) $ Abs (a, T, B)) t = Abs (a, T, lift (T :: Ts) B t) |
|
59787 | 455 |
| lift Ts _ t = incr_indexes ([], rev Ts, inc) t; |
18029
19f1ad18bece
renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents:
17120
diff
changeset
|
456 |
in lift [] end; |
19f1ad18bece
renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents:
17120
diff
changeset
|
457 |
|
19f1ad18bece
renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents:
17120
diff
changeset
|
458 |
fun lift_all inc = |
19f1ad18bece
renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents:
17120
diff
changeset
|
459 |
let |
56245 | 460 |
fun lift Ts ((c as Const ("Pure.imp", _)) $ A $ B) t = c $ A $ lift Ts B t |
461 |
| lift Ts ((c as Const ("Pure.all", _)) $ Abs (a, T, B)) t = c $ Abs (a, T, lift (T :: Ts) B t) |
|
59787 | 462 |
| lift Ts _ t = incr_indexes ([], rev Ts, inc) t; |
18029
19f1ad18bece
renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents:
17120
diff
changeset
|
463 |
in lift [] end; |
0 | 464 |
|
465 |
(*Strips assumptions in goal, yielding list of hypotheses. *) |
|
21016
430b35c9cd27
Repaired strip_assums_hyp (now also works for goals not
berghofe
parents:
20883
diff
changeset
|
466 |
fun strip_assums_hyp B = |
430b35c9cd27
Repaired strip_assums_hyp (now also works for goals not
berghofe
parents:
20883
diff
changeset
|
467 |
let |
56245 | 468 |
fun strip Hs (Const ("Pure.imp", _) $ H $ B) = strip (H :: Hs) B |
469 |
| strip Hs (Const ("Pure.all", _) $ Abs (a, T, t)) = |
|
21016
430b35c9cd27
Repaired strip_assums_hyp (now also works for goals not
berghofe
parents:
20883
diff
changeset
|
470 |
strip (map (incr_boundvars 1) Hs) t |
430b35c9cd27
Repaired strip_assums_hyp (now also works for goals not
berghofe
parents:
20883
diff
changeset
|
471 |
| strip Hs B = rev Hs |
430b35c9cd27
Repaired strip_assums_hyp (now also works for goals not
berghofe
parents:
20883
diff
changeset
|
472 |
in strip [] B end; |
0 | 473 |
|
474 |
(*Strips assumptions in goal, yielding conclusion. *) |
|
56245 | 475 |
fun strip_assums_concl (Const("Pure.imp", _) $ H $ B) = strip_assums_concl B |
60705 | 476 |
| strip_assums_concl (Const("Pure.all", _) $ Abs (a, T, t)) = strip_assums_concl t |
0 | 477 |
| strip_assums_concl B = B; |
478 |
||
479 |
(*Make a list of all the parameters in a subgoal, even if nested*) |
|
56245 | 480 |
fun strip_params (Const("Pure.imp", _) $ H $ B) = strip_params B |
60705 | 481 |
| strip_params (Const("Pure.all", _) $ Abs (a, T, t)) = (a, T) :: strip_params t |
0 | 482 |
| strip_params B = []; |
483 |
||
23597 | 484 |
(*test for nested meta connectives in prems*) |
485 |
val has_meta_prems = |
|
9667 | 486 |
let |
56245 | 487 |
fun is_meta (Const ("Pure.eq", _) $ _ $ _) = true |
488 |
| is_meta (Const ("Pure.imp", _) $ _ $ _) = true |
|
489 |
| is_meta (Const ("Pure.all", _) $ _) = true |
|
9667 | 490 |
| is_meta _ = false; |
56245 | 491 |
fun ex_meta (Const ("Pure.imp", _) $ A $ B) = is_meta A orelse ex_meta B |
492 |
| ex_meta (Const ("Pure.all", _) $ Abs (_, _, B)) = ex_meta B |
|
23597 | 493 |
| ex_meta _ = false; |
494 |
in ex_meta end; |
|
9483 | 495 |
|
0 | 496 |
(*Removes the parameters from a subgoal and renumber bvars in hypotheses, |
9460 | 497 |
where j is the total number of parameters (precomputed) |
0 | 498 |
If n>0 then deletes assumption n. *) |
9460 | 499 |
fun remove_params j n A = |
0 | 500 |
if j=0 andalso n<=0 then A (*nothing left to do...*) |
501 |
else case A of |
|
56245 | 502 |
Const("Pure.imp", _) $ H $ B => |
9460 | 503 |
if n=1 then (remove_params j (n-1) B) |
504 |
else implies $ (incr_boundvars j H) $ (remove_params j (n-1) B) |
|
56245 | 505 |
| Const("Pure.all",_)$Abs(a,T,t) => remove_params (j-1) n t |
0 | 506 |
| _ => if n>0 then raise TERM("remove_params", [A]) |
507 |
else A; |
|
508 |
||
509 |
(*Move all parameters to the front of the subgoal, renaming them apart; |
|
510 |
if n>0 then deletes assumption n. *) |
|
511 |
fun flatten_params n A = |
|
512 |
let val params = strip_params A; |
|
25939 | 513 |
val vars = ListPair.zip (Name.variant_list [] (map #1 params), |
514 |
map #2 params) |
|
46218
ecf6375e2abb
renamed Term.list_all to Logic.list_all, in accordance to HOLogic.list_all;
wenzelm
parents:
46217
diff
changeset
|
515 |
in list_all (vars, remove_params (length vars) n A) end; |
0 | 516 |
|
517 |
(*Makes parameters in a goal have the names supplied by the list cs.*) |
|
56245 | 518 |
fun list_rename_params cs (Const ("Pure.imp", _) $ A $ B) = |
45328 | 519 |
implies $ A $ list_rename_params cs B |
56245 | 520 |
| list_rename_params (c :: cs) ((a as Const ("Pure.all", _)) $ Abs (_, T, t)) = |
45328 | 521 |
a $ Abs (c, T, list_rename_params cs t) |
522 |
| list_rename_params cs B = B; |
|
0 | 523 |
|
32008 | 524 |
|
525 |
||
19806 | 526 |
(*** Treatment of "assume", "erule", etc. ***) |
0 | 527 |
|
16879
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
528 |
(*Strips assumptions in goal yielding |
15451
c6c8786b9921
fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents:
14137
diff
changeset
|
529 |
HS = [Hn,...,H1], params = [xm,...,x1], and B, |
16879
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
530 |
where x1...xm are the parameters. This version (21.1.2005) REQUIRES |
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
531 |
the the parameters to be flattened, but it allows erule to work on |
15451
c6c8786b9921
fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents:
14137
diff
changeset
|
532 |
assumptions of the form !!x. phi. Any !! after the outermost string |
c6c8786b9921
fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents:
14137
diff
changeset
|
533 |
will be regarded as belonging to the conclusion, and left untouched. |
15454 | 534 |
Used ONLY by assum_pairs. |
535 |
Unless nasms<0, it can terminate the recursion early; that allows |
|
536 |
erule to work on assumptions of the form P==>Q.*) |
|
537 |
fun strip_assums_imp (0, Hs, B) = (Hs, B) (*recursion terminated by nasms*) |
|
56245 | 538 |
| strip_assums_imp (nasms, Hs, Const("Pure.imp", _) $ H $ B) = |
15454 | 539 |
strip_assums_imp (nasms-1, H::Hs, B) |
540 |
| strip_assums_imp (_, Hs, B) = (Hs, B); (*recursion terminated by B*) |
|
541 |
||
32008 | 542 |
(*Strips OUTER parameters only.*) |
56245 | 543 |
fun strip_assums_all (params, Const("Pure.all",_)$Abs(a,T,t)) = |
15451
c6c8786b9921
fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents:
14137
diff
changeset
|
544 |
strip_assums_all ((a,T)::params, t) |
c6c8786b9921
fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents:
14137
diff
changeset
|
545 |
| strip_assums_all (params, B) = (params, B); |
0 | 546 |
|
547 |
(*Produces disagreement pairs, one for each assumption proof, in order. |
|
548 |
A is the first premise of the lifted rule, and thus has the form |
|
15454 | 549 |
H1 ==> ... Hk ==> B and the pairs are (H1,B),...,(Hk,B). |
550 |
nasms is the number of assumptions in the original subgoal, needed when B |
|
551 |
has the form B1 ==> B2: it stops B1 from being taken as an assumption. *) |
|
552 |
fun assum_pairs(nasms,A) = |
|
15451
c6c8786b9921
fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents:
14137
diff
changeset
|
553 |
let val (params, A') = strip_assums_all ([],A) |
15454 | 554 |
val (Hs,B) = strip_assums_imp (nasms,[],A') |
18938 | 555 |
fun abspar t = rlist_abs(params, t) |
15451
c6c8786b9921
fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents:
14137
diff
changeset
|
556 |
val D = abspar B |
c6c8786b9921
fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents:
14137
diff
changeset
|
557 |
fun pairrev ([], pairs) = pairs |
c6c8786b9921
fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents:
14137
diff
changeset
|
558 |
| pairrev (H::Hs, pairs) = pairrev(Hs, (abspar H, D) :: pairs) |
c6c8786b9921
fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents:
14137
diff
changeset
|
559 |
in pairrev (Hs,[]) |
0 | 560 |
end; |
561 |
||
30554
73f8bd5f0af8
substantial speedup of assumption and elim-resolution: Logic.assum_problems refrains from eager application of parameters, discriminate via Term.could_unify before invoking full unification (assumes terms in beta-normal form, as do higher term net operations anyway);
wenzelm
parents:
30364
diff
changeset
|
562 |
fun assum_problems (nasms, A) = |
73f8bd5f0af8
substantial speedup of assumption and elim-resolution: Logic.assum_problems refrains from eager application of parameters, discriminate via Term.could_unify before invoking full unification (assumes terms in beta-normal form, as do higher term net operations anyway);
wenzelm
parents:
30364
diff
changeset
|
563 |
let |
73f8bd5f0af8
substantial speedup of assumption and elim-resolution: Logic.assum_problems refrains from eager application of parameters, discriminate via Term.could_unify before invoking full unification (assumes terms in beta-normal form, as do higher term net operations anyway);
wenzelm
parents:
30364
diff
changeset
|
564 |
val (params, A') = strip_assums_all ([], A) |
73f8bd5f0af8
substantial speedup of assumption and elim-resolution: Logic.assum_problems refrains from eager application of parameters, discriminate via Term.could_unify before invoking full unification (assumes terms in beta-normal form, as do higher term net operations anyway);
wenzelm
parents:
30364
diff
changeset
|
565 |
val (Hs, B) = strip_assums_imp (nasms, [], A') |
73f8bd5f0af8
substantial speedup of assumption and elim-resolution: Logic.assum_problems refrains from eager application of parameters, discriminate via Term.could_unify before invoking full unification (assumes terms in beta-normal form, as do higher term net operations anyway);
wenzelm
parents:
30364
diff
changeset
|
566 |
fun abspar t = rlist_abs (params, t) |
73f8bd5f0af8
substantial speedup of assumption and elim-resolution: Logic.assum_problems refrains from eager application of parameters, discriminate via Term.could_unify before invoking full unification (assumes terms in beta-normal form, as do higher term net operations anyway);
wenzelm
parents:
30364
diff
changeset
|
567 |
in (abspar, rev Hs, B) end; |
73f8bd5f0af8
substantial speedup of assumption and elim-resolution: Logic.assum_problems refrains from eager application of parameters, discriminate via Term.could_unify before invoking full unification (assumes terms in beta-normal form, as do higher term net operations anyway);
wenzelm
parents:
30364
diff
changeset
|
568 |
|
19806 | 569 |
|
570 |
(* global schematic variables *) |
|
571 |
||
572 |
fun bad_schematic xi = "Illegal schematic variable: " ^ quote (Term.string_of_vname xi); |
|
573 |
fun bad_fixed x = "Illegal fixed variable: " ^ quote x; |
|
574 |
||
35845
e5980f0ad025
renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
wenzelm
parents:
32784
diff
changeset
|
575 |
fun varifyT_global_same ty = ty |
32020 | 576 |
|> Term_Subst.map_atypsT_same |
577 |
(fn TFree (a, S) => TVar ((a, 0), S) |
|
31981
9c59cbb9c5a2
tuned varify/unvarify: use Term_Subst.map_XXX combinators;
wenzelm
parents:
31943
diff
changeset
|
578 |
| TVar (ai, _) => raise TYPE (bad_schematic ai, [ty], [])); |
19806 | 579 |
|
35845
e5980f0ad025
renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
wenzelm
parents:
32784
diff
changeset
|
580 |
fun unvarifyT_global_same ty = ty |
32020 | 581 |
|> Term_Subst.map_atypsT_same |
582 |
(fn TVar ((a, 0), S) => TFree (a, S) |
|
31981
9c59cbb9c5a2
tuned varify/unvarify: use Term_Subst.map_XXX combinators;
wenzelm
parents:
31943
diff
changeset
|
583 |
| TVar (ai, _) => raise TYPE (bad_schematic ai, [ty], []) |
9c59cbb9c5a2
tuned varify/unvarify: use Term_Subst.map_XXX combinators;
wenzelm
parents:
31943
diff
changeset
|
584 |
| TFree (a, _) => raise TYPE (bad_fixed a, [ty], [])); |
0 | 585 |
|
35845
e5980f0ad025
renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
wenzelm
parents:
32784
diff
changeset
|
586 |
val varifyT_global = Same.commit varifyT_global_same; |
e5980f0ad025
renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
wenzelm
parents:
32784
diff
changeset
|
587 |
val unvarifyT_global = Same.commit unvarifyT_global_same; |
31981
9c59cbb9c5a2
tuned varify/unvarify: use Term_Subst.map_XXX combinators;
wenzelm
parents:
31943
diff
changeset
|
588 |
|
45344
e209da839ff4
added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
wenzelm
parents:
45328
diff
changeset
|
589 |
fun varify_types_global tm = tm |
e209da839ff4
added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
wenzelm
parents:
45328
diff
changeset
|
590 |
|> Same.commit (Term_Subst.map_types_same varifyT_global_same) |
e209da839ff4
added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
wenzelm
parents:
45328
diff
changeset
|
591 |
handle TYPE (msg, _, _) => raise TERM (msg, [tm]); |
e209da839ff4
added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
wenzelm
parents:
45328
diff
changeset
|
592 |
|
e209da839ff4
added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
wenzelm
parents:
45328
diff
changeset
|
593 |
fun unvarify_types_global tm = tm |
e209da839ff4
added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
wenzelm
parents:
45328
diff
changeset
|
594 |
|> Same.commit (Term_Subst.map_types_same unvarifyT_global_same) |
e209da839ff4
added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
wenzelm
parents:
45328
diff
changeset
|
595 |
handle TYPE (msg, _, _) => raise TERM (msg, [tm]); |
e209da839ff4
added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
wenzelm
parents:
45328
diff
changeset
|
596 |
|
35845
e5980f0ad025
renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
wenzelm
parents:
32784
diff
changeset
|
597 |
fun varify_global tm = tm |
32020 | 598 |
|> Same.commit (Term_Subst.map_aterms_same |
599 |
(fn Free (x, T) => Var ((x, 0), T) |
|
19806 | 600 |
| Var (xi, _) => raise TERM (bad_schematic xi, [tm]) |
32020 | 601 |
| _ => raise Same.SAME)) |
45344
e209da839ff4
added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
wenzelm
parents:
45328
diff
changeset
|
602 |
|> varify_types_global; |
19806 | 603 |
|
35845
e5980f0ad025
renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
wenzelm
parents:
32784
diff
changeset
|
604 |
fun unvarify_global tm = tm |
32020 | 605 |
|> Same.commit (Term_Subst.map_aterms_same |
606 |
(fn Var ((x, 0), T) => Free (x, T) |
|
19806 | 607 |
| Var (xi, _) => raise TERM (bad_schematic xi, [tm]) |
608 |
| Free (x, _) => raise TERM (bad_fixed x, [tm]) |
|
32020 | 609 |
| _ => raise Same.SAME)) |
45344
e209da839ff4
added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
wenzelm
parents:
45328
diff
changeset
|
610 |
|> unvarify_types_global; |
19806 | 611 |
|
13799
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
612 |
|
16862 | 613 |
(* goal states *) |
614 |
||
49865 | 615 |
fun get_goal st i = |
616 |
nth_prem (i, st) handle TERM _ => |
|
617 |
error ("Subgoal number " ^ string_of_int i ^ " out of range (a total of " ^ |
|
618 |
string_of_int (count_prems st) ^ " subgoals)"); |
|
13799
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
619 |
|
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
620 |
(*reverses parameters for substitution*) |
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
621 |
fun goal_params st i = |
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
622 |
let val gi = get_goal st i |
29276 | 623 |
val rfrees = map Free (Term.rename_wrt_term gi (strip_params gi)) |
13799
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
624 |
in (gi, rfrees) end; |
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
625 |
|
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
626 |
fun concl_of_goal st i = |
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
627 |
let val (gi, rfrees) = goal_params st i |
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
628 |
val B = strip_assums_concl gi |
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
629 |
in subst_bounds (rfrees, B) end; |
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
630 |
|
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
631 |
fun prems_of_goal st i = |
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
632 |
let val (gi, rfrees) = goal_params st i |
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
633 |
val As = strip_assums_hyp gi |
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
634 |
in map (fn A => subst_bounds (rfrees, A)) As end; |
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
635 |
|
0 | 636 |
end; |