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