author | kleing |
Sun, 06 Apr 2003 21:16:50 +0200 | |
changeset 13901 | af38553e61ee |
parent 13799 | 77614fe09362 |
child 14107 | 215585ac94e2 |
permissions | -rw-r--r-- |
9460 | 1 |
(* Title: Pure/logic.ML |
0 | 2 |
ID: $Id$ |
9460 | 3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
0 | 4 |
Copyright Cambridge University 1992 |
5 |
||
9460 | 6 |
Abstract syntax operations of the Pure meta-logic. |
0 | 7 |
*) |
8 |
||
9 |
infix occs; |
|
10 |
||
9460 | 11 |
signature LOGIC = |
4345 | 12 |
sig |
5041
a1d0a6d555cd
Goals may now contain assumptions, which are not returned.
nipkow
parents:
4822
diff
changeset
|
13 |
val is_all : term -> bool |
9460 | 14 |
val mk_equals : term * term -> term |
15 |
val dest_equals : term -> term * term |
|
3963
29c5ec9ecbaa
Corrected alphabetical order of entries in signature.
nipkow
parents:
3915
diff
changeset
|
16 |
val is_equals : term -> bool |
9460 | 17 |
val mk_implies : term * term -> term |
18 |
val dest_implies : term -> term * term |
|
5041
a1d0a6d555cd
Goals may now contain assumptions, which are not returned.
nipkow
parents:
4822
diff
changeset
|
19 |
val is_implies : term -> bool |
9460 | 20 |
val list_implies : term list * term -> term |
21 |
val strip_imp_prems : term -> term list |
|
22 |
val strip_imp_concl : term -> term |
|
23 |
val strip_prems : int * term list * term -> term list * term |
|
24 |
val count_prems : term * int -> int |
|
12137 | 25 |
val mk_conjunction : term * term -> term |
12757 | 26 |
val mk_conjunction_list: term list -> term |
13659
3cf622f6b0b2
Removed obsolete functions dealing with flex-flex constraints.
berghofe
parents:
12902
diff
changeset
|
27 |
val strip_horn : term -> term list * term |
9460 | 28 |
val mk_cond_defpair : term list -> term * term -> string * term |
29 |
val mk_defpair : term * term -> string * term |
|
30 |
val mk_type : typ -> term |
|
31 |
val dest_type : term -> typ |
|
32 |
val mk_inclass : typ * class -> term |
|
33 |
val dest_inclass : term -> typ * class |
|
34 |
val goal_const : term |
|
35 |
val mk_goal : term -> term |
|
36 |
val dest_goal : term -> term |
|
37 |
val occs : term * term -> bool |
|
38 |
val close_form : term -> term |
|
39 |
val incr_indexes : typ list * int -> term -> term |
|
40 |
val lift_fns : term * int -> (term -> term) * (term -> term) |
|
41 |
val strip_assums_hyp : term -> term list |
|
42 |
val strip_assums_concl: term -> term |
|
43 |
val strip_params : term -> (string * typ) list |
|
9667 | 44 |
val has_meta_prems : term -> int -> bool |
9460 | 45 |
val flatten_params : int -> term -> term |
46 |
val auto_rename : bool ref |
|
47 |
val set_rename_prefix : string -> unit |
|
0 | 48 |
val list_rename_params: string list * term -> term |
9460 | 49 |
val assum_pairs : term -> (term*term)list |
50 |
val varify : term -> term |
|
51 |
val unvarify : term -> term |
|
13799
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
52 |
val get_goal : term -> int -> term |
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
53 |
val prems_of_goal : term -> int -> term list |
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
54 |
val concl_of_goal : term -> int -> term |
4345 | 55 |
end; |
0 | 56 |
|
1500 | 57 |
structure Logic : LOGIC = |
0 | 58 |
struct |
398
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
59 |
|
4345 | 60 |
|
0 | 61 |
(*** Abstract syntax operations on the meta-connectives ***) |
62 |
||
5041
a1d0a6d555cd
Goals may now contain assumptions, which are not returned.
nipkow
parents:
4822
diff
changeset
|
63 |
(** all **) |
a1d0a6d555cd
Goals may now contain assumptions, which are not returned.
nipkow
parents:
4822
diff
changeset
|
64 |
|
a1d0a6d555cd
Goals may now contain assumptions, which are not returned.
nipkow
parents:
4822
diff
changeset
|
65 |
fun is_all (Const ("all", _) $ _) = true |
a1d0a6d555cd
Goals may now contain assumptions, which are not returned.
nipkow
parents:
4822
diff
changeset
|
66 |
| is_all _ = false; |
a1d0a6d555cd
Goals may now contain assumptions, which are not returned.
nipkow
parents:
4822
diff
changeset
|
67 |
|
a1d0a6d555cd
Goals may now contain assumptions, which are not returned.
nipkow
parents:
4822
diff
changeset
|
68 |
|
0 | 69 |
(** equality **) |
70 |
||
1835 | 71 |
(*Make an equality. DOES NOT CHECK TYPE OF u*) |
64
0bbe5d86cb38
logic/mk_equals,mk_flexpair: now calls fastype_of instead of type_of.
lcp
parents:
0
diff
changeset
|
72 |
fun mk_equals(t,u) = equals(fastype_of t) $ t $ u; |
0 | 73 |
|
74 |
fun dest_equals (Const("==",_) $ t $ u) = (t,u) |
|
75 |
| dest_equals t = raise TERM("dest_equals", [t]); |
|
76 |
||
637 | 77 |
fun is_equals (Const ("==", _) $ _ $ _) = true |
78 |
| is_equals _ = false; |
|
79 |
||
80 |
||
0 | 81 |
(** implies **) |
82 |
||
83 |
fun mk_implies(A,B) = implies $ A $ B; |
|
84 |
||
85 |
fun dest_implies (Const("==>",_) $ A $ B) = (A,B) |
|
86 |
| dest_implies A = raise TERM("dest_implies", [A]); |
|
87 |
||
5041
a1d0a6d555cd
Goals may now contain assumptions, which are not returned.
nipkow
parents:
4822
diff
changeset
|
88 |
fun is_implies (Const ("==>", _) $ _ $ _) = true |
a1d0a6d555cd
Goals may now contain assumptions, which are not returned.
nipkow
parents:
4822
diff
changeset
|
89 |
| is_implies _ = false; |
a1d0a6d555cd
Goals may now contain assumptions, which are not returned.
nipkow
parents:
4822
diff
changeset
|
90 |
|
4822 | 91 |
|
0 | 92 |
(** nested implications **) |
93 |
||
94 |
(* [A1,...,An], B goes to A1==>...An==>B *) |
|
95 |
fun list_implies ([], B) = B : term |
|
96 |
| list_implies (A::AS, B) = implies $ A $ list_implies(AS,B); |
|
97 |
||
98 |
(* A1==>...An==>B goes to [A1,...,An], where B is not an implication *) |
|
99 |
fun strip_imp_prems (Const("==>", _) $ A $ B) = A :: strip_imp_prems B |
|
100 |
| strip_imp_prems _ = []; |
|
101 |
||
102 |
(* A1==>...An==>B goes to B, where B is not an implication *) |
|
103 |
fun strip_imp_concl (Const("==>", _) $ A $ B) = strip_imp_concl B |
|
104 |
| strip_imp_concl A = A : term; |
|
105 |
||
106 |
(*Strip and return premises: (i, [], A1==>...Ai==>B) |
|
9460 | 107 |
goes to ([Ai, A(i-1),...,A1] , B) (REVERSED) |
0 | 108 |
if i<0 or else i too big then raises TERM*) |
9460 | 109 |
fun strip_prems (0, As, B) = (As, B) |
110 |
| strip_prems (i, As, Const("==>", _) $ A $ B) = |
|
111 |
strip_prems (i-1, A::As, B) |
|
0 | 112 |
| strip_prems (_, As, A) = raise TERM("strip_prems", A::As); |
113 |
||
114 |
(*Count premises -- quicker than (length ostrip_prems) *) |
|
115 |
fun count_prems (Const("==>", _) $ A $ B, n) = count_prems (B,n+1) |
|
116 |
| count_prems (_,n) = n; |
|
117 |
||
13659
3cf622f6b0b2
Removed obsolete functions dealing with flex-flex constraints.
berghofe
parents:
12902
diff
changeset
|
118 |
(*strip a proof state (Horn clause): |
3cf622f6b0b2
Removed obsolete functions dealing with flex-flex constraints.
berghofe
parents:
12902
diff
changeset
|
119 |
B1 ==> ... Bn ==> C goes to ([B1, ..., Bn], C) *) |
3cf622f6b0b2
Removed obsolete functions dealing with flex-flex constraints.
berghofe
parents:
12902
diff
changeset
|
120 |
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
|
121 |
|
4822 | 122 |
|
12137 | 123 |
(** conjunction **) |
124 |
||
125 |
fun mk_conjunction (t, u) = |
|
126 |
Term.list_all ([("C", propT)], mk_implies (list_implies ([t, u], Bound 0), Bound 0)); |
|
127 |
||
12757 | 128 |
fun mk_conjunction_list [] = Term.all propT $ Abs ("dummy", propT, mk_implies (Bound 0, Bound 0)) |
129 |
| mk_conjunction_list ts = foldr1 mk_conjunction ts; |
|
12137 | 130 |
|
131 |
||
4822 | 132 |
(** definitions **) |
133 |
||
134 |
fun mk_cond_defpair As (lhs, rhs) = |
|
135 |
(case Term.head_of lhs of |
|
136 |
Const (name, _) => |
|
137 |
(Sign.base_name name ^ "_def", list_implies (As, mk_equals (lhs, rhs))) |
|
138 |
| _ => raise TERM ("Malformed definition: head of lhs not a constant", [lhs, rhs])); |
|
139 |
||
140 |
fun mk_defpair lhs_rhs = mk_cond_defpair [] lhs_rhs; |
|
141 |
||
142 |
||
398
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
143 |
(** types as terms **) |
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
144 |
|
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
145 |
fun mk_type ty = Const ("TYPE", itselfT ty); |
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
146 |
|
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
147 |
fun dest_type (Const ("TYPE", Type ("itself", [ty]))) = ty |
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
148 |
| 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
|
149 |
|
4822 | 150 |
|
447 | 151 |
(** class constraints **) |
398
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
152 |
|
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
153 |
fun mk_inclass (ty, c) = |
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
154 |
Const (Sign.const_of_class c, itselfT ty --> propT) $ mk_type ty; |
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
155 |
|
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
156 |
fun dest_inclass (t as Const (c_class, _) $ ty) = |
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
157 |
((dest_type ty, Sign.class_of_const c_class) |
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
158 |
handle TERM _ => raise TERM ("dest_inclass", [t])) |
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
159 |
| dest_inclass t = raise TERM ("dest_inclass", [t]); |
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
160 |
|
0 | 161 |
|
9460 | 162 |
(** atomic goals **) |
163 |
||
164 |
val goal_const = Const ("Goal", propT --> propT); |
|
165 |
fun mk_goal t = goal_const $ t; |
|
166 |
||
167 |
fun dest_goal (Const ("Goal", _) $ t) = t |
|
168 |
| dest_goal t = raise TERM ("dest_goal", [t]); |
|
169 |
||
170 |
||
0 | 171 |
(*** Low-level term operations ***) |
172 |
||
173 |
(*Does t occur in u? Or is alpha-convertible to u? |
|
174 |
The term t must contain no loose bound variables*) |
|
4631 | 175 |
fun t occs u = exists_subterm (fn s => t aconv s) u; |
0 | 176 |
|
177 |
(*Close up a formula over all free variables by quantification*) |
|
178 |
fun close_form A = |
|
4443 | 179 |
list_all_free (sort_wrt fst (map dest_Free (term_frees A)), A); |
0 | 180 |
|
181 |
||
182 |
(*** Specialized operations for resolution... ***) |
|
183 |
||
184 |
(*For all variables in the term, increment indexnames and lift over the Us |
|
185 |
result is ?Gidx(B.(lev+n-1),...,B.lev) where lev is abstraction level *) |
|
9460 | 186 |
fun incr_indexes (Us: typ list, inc:int) t = |
187 |
let fun incr (Var ((a,i), T), lev) = |
|
188 |
Unify.combound (Var((a, i+inc), Us---> incr_tvar inc T), |
|
189 |
lev, length Us) |
|
190 |
| incr (Abs (a,T,body), lev) = |
|
191 |
Abs (a, incr_tvar inc T, incr(body,lev+1)) |
|
192 |
| incr (Const(a,T),_) = Const(a, incr_tvar inc T) |
|
193 |
| incr (Free(a,T),_) = Free(a, incr_tvar inc T) |
|
194 |
| incr (f$t, lev) = incr(f,lev) $ incr(t,lev) |
|
195 |
| incr (t,lev) = t |
|
0 | 196 |
in incr(t,0) end; |
197 |
||
198 |
(*Make lifting functions from subgoal and increment. |
|
199 |
lift_abs operates on tpairs (unification constraints) |
|
200 |
lift_all operates on propositions *) |
|
201 |
fun lift_fns (B,inc) = |
|
202 |
let fun lift_abs (Us, Const("==>", _) $ _ $ B) u = lift_abs (Us,B) u |
|
9460 | 203 |
| lift_abs (Us, Const("all",_)$Abs(a,T,t)) u = |
204 |
Abs(a, T, lift_abs (T::Us, t) u) |
|
205 |
| lift_abs (Us, _) u = incr_indexes(rev Us, inc) u |
|
0 | 206 |
fun lift_all (Us, Const("==>", _) $ A $ B) u = |
9460 | 207 |
implies $ A $ lift_all (Us,B) u |
208 |
| lift_all (Us, Const("all",_)$Abs(a,T,t)) u = |
|
209 |
all T $ Abs(a, T, lift_all (T::Us,t) u) |
|
210 |
| lift_all (Us, _) u = incr_indexes(rev Us, inc) u; |
|
0 | 211 |
in (lift_abs([],B), lift_all([],B)) end; |
212 |
||
213 |
(*Strips assumptions in goal, yielding list of hypotheses. *) |
|
214 |
fun strip_assums_hyp (Const("==>", _) $ H $ B) = H :: strip_assums_hyp B |
|
215 |
| strip_assums_hyp (Const("all",_)$Abs(a,T,t)) = strip_assums_hyp t |
|
216 |
| strip_assums_hyp B = []; |
|
217 |
||
218 |
(*Strips assumptions in goal, yielding conclusion. *) |
|
219 |
fun strip_assums_concl (Const("==>", _) $ H $ B) = strip_assums_concl B |
|
220 |
| strip_assums_concl (Const("all",_)$Abs(a,T,t)) = strip_assums_concl t |
|
221 |
| strip_assums_concl B = B; |
|
222 |
||
223 |
(*Make a list of all the parameters in a subgoal, even if nested*) |
|
224 |
fun strip_params (Const("==>", _) $ H $ B) = strip_params B |
|
225 |
| strip_params (Const("all",_)$Abs(a,T,t)) = (a,T) :: strip_params t |
|
226 |
| strip_params B = []; |
|
227 |
||
9667 | 228 |
(*test for meta connectives in prems of a 'subgoal'*) |
229 |
fun has_meta_prems prop i = |
|
230 |
let |
|
231 |
fun is_meta (Const ("==>", _) $ _ $ _) = true |
|
10442 | 232 |
| is_meta (Const ("==", _) $ _ $ _) = true |
9667 | 233 |
| is_meta (Const ("all", _) $ _) = true |
234 |
| is_meta _ = false; |
|
235 |
in |
|
13659
3cf622f6b0b2
Removed obsolete functions dealing with flex-flex constraints.
berghofe
parents:
12902
diff
changeset
|
236 |
(case strip_prems (i, [], prop) of |
9667 | 237 |
(B :: _, _) => exists is_meta (strip_assums_hyp B) |
238 |
| _ => false) handle TERM _ => false |
|
239 |
end; |
|
9483 | 240 |
|
0 | 241 |
(*Removes the parameters from a subgoal and renumber bvars in hypotheses, |
9460 | 242 |
where j is the total number of parameters (precomputed) |
0 | 243 |
If n>0 then deletes assumption n. *) |
9460 | 244 |
fun remove_params j n A = |
0 | 245 |
if j=0 andalso n<=0 then A (*nothing left to do...*) |
246 |
else case A of |
|
9460 | 247 |
Const("==>", _) $ H $ B => |
248 |
if n=1 then (remove_params j (n-1) B) |
|
249 |
else implies $ (incr_boundvars j H) $ (remove_params j (n-1) B) |
|
0 | 250 |
| Const("all",_)$Abs(a,T,t) => remove_params (j-1) n t |
251 |
| _ => if n>0 then raise TERM("remove_params", [A]) |
|
252 |
else A; |
|
253 |
||
254 |
(** Auto-renaming of parameters in subgoals **) |
|
255 |
||
256 |
val auto_rename = ref false |
|
257 |
and rename_prefix = ref "ka"; |
|
258 |
||
259 |
(*rename_prefix is not exported; it is set by this function.*) |
|
260 |
fun set_rename_prefix a = |
|
4693 | 261 |
if a<>"" andalso forall Symbol.is_letter (Symbol.explode a) |
0 | 262 |
then (rename_prefix := a; auto_rename := true) |
263 |
else error"rename prefix must be nonempty and consist of letters"; |
|
264 |
||
265 |
(*Makes parameters in a goal have distinctive names (not guaranteed unique!) |
|
266 |
A name clash could cause the printer to rename bound vars; |
|
267 |
then res_inst_tac would not work properly.*) |
|
268 |
fun rename_vars (a, []) = [] |
|
269 |
| rename_vars (a, (_,T)::vars) = |
|
12902 | 270 |
(a,T) :: rename_vars (Symbol.bump_string a, vars); |
0 | 271 |
|
272 |
(*Move all parameters to the front of the subgoal, renaming them apart; |
|
273 |
if n>0 then deletes assumption n. *) |
|
274 |
fun flatten_params n A = |
|
275 |
let val params = strip_params A; |
|
9460 | 276 |
val vars = if !auto_rename |
277 |
then rename_vars (!rename_prefix, params) |
|
278 |
else ListPair.zip (variantlist(map #1 params,[]), |
|
279 |
map #2 params) |
|
0 | 280 |
in list_all (vars, remove_params (length vars) n A) |
281 |
end; |
|
282 |
||
283 |
(*Makes parameters in a goal have the names supplied by the list cs.*) |
|
284 |
fun list_rename_params (cs, Const("==>", _) $ A $ B) = |
|
285 |
implies $ A $ list_rename_params (cs, B) |
|
9460 | 286 |
| list_rename_params (c::cs, Const("all",_)$Abs(_,T,t)) = |
0 | 287 |
all T $ Abs(c, T, list_rename_params (cs, t)) |
288 |
| list_rename_params (cs, B) = B; |
|
289 |
||
9684
6b7d7635a062
fixed strip_assums and assum_pairs, restoring them (essentially) to their
paulson
parents:
9667
diff
changeset
|
290 |
(*Strips assumptions in goal yielding ( [HPn,...,HP1], [xm,...,x1], B ). |
6b7d7635a062
fixed strip_assums and assum_pairs, restoring them (essentially) to their
paulson
parents:
9667
diff
changeset
|
291 |
Where HPi has the form (Hi,nparams_i) and x1...xm are the parameters. |
6b7d7635a062
fixed strip_assums and assum_pairs, restoring them (essentially) to their
paulson
parents:
9667
diff
changeset
|
292 |
We need nparams_i only when the parameters aren't flattened; then we |
6b7d7635a062
fixed strip_assums and assum_pairs, restoring them (essentially) to their
paulson
parents:
9667
diff
changeset
|
293 |
must call incr_boundvars to make up the difference. See assum_pairs. |
6b7d7635a062
fixed strip_assums and assum_pairs, restoring them (essentially) to their
paulson
parents:
9667
diff
changeset
|
294 |
Without this refinement we can get the wrong answer, e.g. by |
10816 | 295 |
Goal "!!f. EX B. Q(f,B) ==> (!!y. P(f,y))"; |
296 |
by (etac exE 1); |
|
9684
6b7d7635a062
fixed strip_assums and assum_pairs, restoring them (essentially) to their
paulson
parents:
9667
diff
changeset
|
297 |
*) |
6b7d7635a062
fixed strip_assums and assum_pairs, restoring them (essentially) to their
paulson
parents:
9667
diff
changeset
|
298 |
fun strip_assums_aux (HPs, params, Const("==>", _) $ H $ B) = |
6b7d7635a062
fixed strip_assums and assum_pairs, restoring them (essentially) to their
paulson
parents:
9667
diff
changeset
|
299 |
strip_assums_aux ((H,length params)::HPs, params, B) |
6b7d7635a062
fixed strip_assums and assum_pairs, restoring them (essentially) to their
paulson
parents:
9667
diff
changeset
|
300 |
| strip_assums_aux (HPs, params, Const("all",_)$Abs(a,T,t)) = |
6b7d7635a062
fixed strip_assums and assum_pairs, restoring them (essentially) to their
paulson
parents:
9667
diff
changeset
|
301 |
strip_assums_aux (HPs, (a,T)::params, t) |
6b7d7635a062
fixed strip_assums and assum_pairs, restoring them (essentially) to their
paulson
parents:
9667
diff
changeset
|
302 |
| strip_assums_aux (HPs, params, B) = (HPs, params, B); |
0 | 303 |
|
304 |
fun strip_assums A = strip_assums_aux ([],[],A); |
|
305 |
||
306 |
||
307 |
(*Produces disagreement pairs, one for each assumption proof, in order. |
|
308 |
A is the first premise of the lifted rule, and thus has the form |
|
309 |
H1 ==> ... Hk ==> B and the pairs are (H1,B),...,(Hk,B) *) |
|
310 |
fun assum_pairs A = |
|
9684
6b7d7635a062
fixed strip_assums and assum_pairs, restoring them (essentially) to their
paulson
parents:
9667
diff
changeset
|
311 |
let val (HPs, params, B) = strip_assums A |
6b7d7635a062
fixed strip_assums and assum_pairs, restoring them (essentially) to their
paulson
parents:
9667
diff
changeset
|
312 |
val nparams = length params |
0 | 313 |
val D = Unify.rlist_abs(params, B) |
10816 | 314 |
fun incr_hyp(H,np) = |
315 |
Unify.rlist_abs(params, incr_boundvars (nparams-np) H) |
|
9460 | 316 |
fun pairrev ([],pairs) = pairs |
9684
6b7d7635a062
fixed strip_assums and assum_pairs, restoring them (essentially) to their
paulson
parents:
9667
diff
changeset
|
317 |
| pairrev ((H,np)::HPs, pairs) = |
6b7d7635a062
fixed strip_assums and assum_pairs, restoring them (essentially) to their
paulson
parents:
9667
diff
changeset
|
318 |
pairrev(HPs, (incr_hyp(H,np),D) :: pairs) |
10816 | 319 |
in pairrev (HPs,[]) |
0 | 320 |
end; |
321 |
||
322 |
(*Converts Frees to Vars and TFrees to TVars so that axioms can be written |
|
323 |
without (?) everywhere*) |
|
324 |
fun varify (Const(a,T)) = Const(a, Type.varifyT T) |
|
325 |
| varify (Free(a,T)) = Var((a,0), Type.varifyT T) |
|
326 |
| varify (Var(ixn,T)) = Var(ixn, Type.varifyT T) |
|
327 |
| varify (Abs (a,T,body)) = Abs (a, Type.varifyT T, varify body) |
|
328 |
| varify (f$t) = varify f $ varify t |
|
329 |
| varify t = t; |
|
330 |
||
546 | 331 |
(*Inverse of varify. Converts axioms back to their original form.*) |
585 | 332 |
fun unvarify (Const(a,T)) = Const(a, Type.unvarifyT T) |
333 |
| unvarify (Var((a,0), T)) = Free(a, Type.unvarifyT T) |
|
334 |
| unvarify (Var(ixn,T)) = Var(ixn, Type.unvarifyT T) (*non-0 index!*) |
|
335 |
| unvarify (Abs (a,T,body)) = Abs (a, Type.unvarifyT T, unvarify body) |
|
546 | 336 |
| unvarify (f$t) = unvarify f $ unvarify t |
337 |
| unvarify t = t; |
|
338 |
||
13799
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
339 |
|
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
340 |
(*Get subgoal i*) |
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
341 |
fun get_goal st i = List.nth (strip_imp_prems st, i-1) |
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
342 |
handle Subscript => error "get_goal: Goal number out of range"; |
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
343 |
|
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
344 |
(*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
|
345 |
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
|
346 |
let val gi = get_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
|
347 |
val rfrees = rev (map Free (rename_wrt_term gi (strip_params gi))) |
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
348 |
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
|
349 |
|
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
350 |
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
|
351 |
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
|
352 |
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
|
353 |
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
|
354 |
|
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
355 |
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
|
356 |
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
|
357 |
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
|
358 |
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
|
359 |
|
0 | 360 |
end; |