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