author | wenzelm |
Tue, 16 Aug 2005 13:42:40 +0200 | |
changeset 17069 | ee08b2466a09 |
parent 16879 | b81d3f2ee565 |
child 17120 | 4ddeef83bd66 |
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 |
||
9460 | 9 |
signature LOGIC = |
4345 | 10 |
sig |
5041
a1d0a6d555cd
Goals may now contain assumptions, which are not returned.
nipkow
parents:
4822
diff
changeset
|
11 |
val is_all : term -> bool |
9460 | 12 |
val mk_equals : term * term -> term |
13 |
val dest_equals : term -> term * term |
|
3963
29c5ec9ecbaa
Corrected alphabetical order of entries in signature.
nipkow
parents:
3915
diff
changeset
|
14 |
val is_equals : term -> bool |
9460 | 15 |
val mk_implies : term * term -> term |
16 |
val dest_implies : term -> term * term |
|
5041
a1d0a6d555cd
Goals may now contain assumptions, which are not returned.
nipkow
parents:
4822
diff
changeset
|
17 |
val is_implies : term -> bool |
9460 | 18 |
val list_implies : term list * term -> term |
19 |
val strip_imp_prems : term -> term list |
|
20 |
val strip_imp_concl : term -> term |
|
21 |
val strip_prems : int * term list * term -> term list * term |
|
22 |
val count_prems : term * int -> int |
|
16879
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
23 |
val nth_prem : int * term -> term |
12137 | 24 |
val mk_conjunction : term * term -> term |
12757 | 25 |
val mk_conjunction_list: term list -> term |
13659
3cf622f6b0b2
Removed obsolete functions dealing with flex-flex constraints.
berghofe
parents:
12902
diff
changeset
|
26 |
val strip_horn : term -> term list * term |
9460 | 27 |
val mk_cond_defpair : term list -> term * term -> string * term |
28 |
val mk_defpair : term * term -> string * term |
|
29 |
val mk_type : typ -> term |
|
30 |
val dest_type : term -> typ |
|
31 |
val mk_inclass : typ * class -> term |
|
32 |
val dest_inclass : term -> typ * class |
|
33 |
val goal_const : term |
|
34 |
val mk_goal : term -> term |
|
35 |
val dest_goal : term -> term |
|
36 |
val occs : term * term -> bool |
|
37 |
val close_form : term -> term |
|
38 |
val incr_indexes : typ list * int -> term -> term |
|
16879
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
39 |
val incr_tvar : int -> typ -> typ |
9460 | 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 |
15454 | 49 |
val assum_pairs : int * term -> (term*term)list |
9460 | 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 |
14107 | 53 |
val goal_params : term -> int -> term * term list |
13799
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
54 |
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
|
55 |
val concl_of_goal : term -> int -> 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 |
||
16130 | 115 |
(*Count premises -- quicker than (length o strip_prems) *) |
0 | 116 |
fun count_prems (Const("==>", _) $ A $ B, n) = count_prems (B,n+1) |
117 |
| count_prems (_,n) = n; |
|
118 |
||
16130 | 119 |
(*Select Ai from A1 ==>...Ai==>B*) |
120 |
fun nth_prem (1, Const ("==>", _) $ A $ _) = A |
|
121 |
| nth_prem (i, Const ("==>", _) $ _ $ B) = nth_prem (i - 1, B) |
|
122 |
| nth_prem (_, A) = raise TERM ("nth_prem", [A]); |
|
123 |
||
13659
3cf622f6b0b2
Removed obsolete functions dealing with flex-flex constraints.
berghofe
parents:
12902
diff
changeset
|
124 |
(*strip a proof state (Horn clause): |
3cf622f6b0b2
Removed obsolete functions dealing with flex-flex constraints.
berghofe
parents:
12902
diff
changeset
|
125 |
B1 ==> ... Bn ==> C goes to ([B1, ..., Bn], C) *) |
3cf622f6b0b2
Removed obsolete functions dealing with flex-flex constraints.
berghofe
parents:
12902
diff
changeset
|
126 |
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
|
127 |
|
4822 | 128 |
|
12137 | 129 |
(** conjunction **) |
130 |
||
131 |
fun mk_conjunction (t, u) = |
|
132 |
Term.list_all ([("C", propT)], mk_implies (list_implies ([t, u], Bound 0), Bound 0)); |
|
133 |
||
12757 | 134 |
fun mk_conjunction_list [] = Term.all propT $ Abs ("dummy", propT, mk_implies (Bound 0, Bound 0)) |
135 |
| mk_conjunction_list ts = foldr1 mk_conjunction ts; |
|
12137 | 136 |
|
137 |
||
4822 | 138 |
(** definitions **) |
139 |
||
140 |
fun mk_cond_defpair As (lhs, rhs) = |
|
141 |
(case Term.head_of lhs of |
|
142 |
Const (name, _) => |
|
143 |
(Sign.base_name name ^ "_def", list_implies (As, mk_equals (lhs, rhs))) |
|
144 |
| _ => raise TERM ("Malformed definition: head of lhs not a constant", [lhs, rhs])); |
|
145 |
||
146 |
fun mk_defpair lhs_rhs = mk_cond_defpair [] lhs_rhs; |
|
147 |
||
148 |
||
398
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
149 |
(** types as terms **) |
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
150 |
|
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
151 |
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
|
152 |
|
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
153 |
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
|
154 |
| 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
|
155 |
|
4822 | 156 |
|
447 | 157 |
(** class constraints **) |
398
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
158 |
|
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
159 |
fun mk_inclass (ty, c) = |
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
160 |
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
|
161 |
|
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
162 |
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
|
163 |
((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
|
164 |
handle TERM _ => raise TERM ("dest_inclass", [t])) |
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents:
210
diff
changeset
|
165 |
| 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
|
166 |
|
0 | 167 |
|
9460 | 168 |
(** atomic goals **) |
169 |
||
170 |
val goal_const = Const ("Goal", propT --> propT); |
|
171 |
fun mk_goal t = goal_const $ t; |
|
172 |
||
173 |
fun dest_goal (Const ("Goal", _) $ t) = t |
|
174 |
| dest_goal t = raise TERM ("dest_goal", [t]); |
|
175 |
||
176 |
||
0 | 177 |
(*** Low-level term operations ***) |
178 |
||
179 |
(*Does t occur in u? Or is alpha-convertible to u? |
|
180 |
The term t must contain no loose bound variables*) |
|
16846 | 181 |
fun occs (t, u) = exists_subterm (fn s => t aconv s) u; |
0 | 182 |
|
183 |
(*Close up a formula over all free variables by quantification*) |
|
184 |
fun close_form A = |
|
4443 | 185 |
list_all_free (sort_wrt fst (map dest_Free (term_frees A)), A); |
0 | 186 |
|
187 |
||
188 |
(*** Specialized operations for resolution... ***) |
|
189 |
||
16879
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
190 |
local exception SAME in |
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
191 |
|
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
192 |
fun incrT k = |
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
193 |
let |
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
194 |
fun incr (TVar ((a, i), S)) = TVar ((a, i + k), S) |
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
195 |
| incr (Type (a, Ts)) = Type (a, incrs Ts) |
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
196 |
| incr _ = raise SAME |
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
197 |
and incrs (T :: Ts) = |
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
198 |
(incr T :: (incrs Ts handle SAME => Ts) |
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
199 |
handle SAME => T :: incrs Ts) |
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
200 |
| incrs [] = raise SAME; |
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
201 |
in incr end; |
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
202 |
|
0 | 203 |
(*For all variables in the term, increment indexnames and lift over the Us |
204 |
result is ?Gidx(B.(lev+n-1),...,B.lev) where lev is abstraction level *) |
|
16879
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
205 |
fun incr_indexes (Us, k) t = |
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
206 |
let |
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
207 |
val n = length Us; |
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
208 |
val incrT = if k = 0 then I else incrT k; |
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
209 |
|
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
210 |
fun incr lev (Var ((x, i), T)) = |
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
211 |
Unify.combound (Var ((x, i + k), Us ---> (incrT T handle SAME => T)), lev, n) |
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
212 |
| incr lev (Abs (x, T, body)) = |
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
213 |
(Abs (x, incrT T, incr (lev + 1) body handle SAME => body) |
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
214 |
handle SAME => Abs (x, T, incr (lev + 1) body)) |
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
215 |
| incr lev (t $ u) = |
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
216 |
(incr lev t $ (incr lev u handle SAME => u) |
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
217 |
handle SAME => t $ incr lev u) |
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
218 |
| incr _ (Const (c, T)) = Const (c, incrT T) |
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
219 |
| incr _ (Free (x, T)) = Free (x, incrT T) |
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
220 |
| incr _ (t as Bound _) = t; |
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
221 |
in incr 0 t handle SAME => t end; |
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
222 |
|
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
223 |
fun incr_tvar 0 T = T |
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
224 |
| incr_tvar k T = incrT k T handle SAME => T; |
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
225 |
|
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
226 |
end; |
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
227 |
|
0 | 228 |
|
229 |
(*Make lifting functions from subgoal and increment. |
|
230 |
lift_abs operates on tpairs (unification constraints) |
|
231 |
lift_all operates on propositions *) |
|
232 |
fun lift_fns (B,inc) = |
|
233 |
let fun lift_abs (Us, Const("==>", _) $ _ $ B) u = lift_abs (Us,B) u |
|
9460 | 234 |
| lift_abs (Us, Const("all",_)$Abs(a,T,t)) u = |
235 |
Abs(a, T, lift_abs (T::Us, t) u) |
|
236 |
| lift_abs (Us, _) u = incr_indexes(rev Us, inc) u |
|
0 | 237 |
fun lift_all (Us, Const("==>", _) $ A $ B) u = |
9460 | 238 |
implies $ A $ lift_all (Us,B) u |
239 |
| lift_all (Us, Const("all",_)$Abs(a,T,t)) u = |
|
240 |
all T $ Abs(a, T, lift_all (T::Us,t) u) |
|
241 |
| lift_all (Us, _) u = incr_indexes(rev Us, inc) u; |
|
0 | 242 |
in (lift_abs([],B), lift_all([],B)) end; |
243 |
||
244 |
(*Strips assumptions in goal, yielding list of hypotheses. *) |
|
245 |
fun strip_assums_hyp (Const("==>", _) $ H $ B) = H :: strip_assums_hyp B |
|
246 |
| strip_assums_hyp (Const("all",_)$Abs(a,T,t)) = strip_assums_hyp t |
|
247 |
| strip_assums_hyp B = []; |
|
248 |
||
249 |
(*Strips assumptions in goal, yielding conclusion. *) |
|
250 |
fun strip_assums_concl (Const("==>", _) $ H $ B) = strip_assums_concl B |
|
251 |
| strip_assums_concl (Const("all",_)$Abs(a,T,t)) = strip_assums_concl t |
|
252 |
| strip_assums_concl B = B; |
|
253 |
||
254 |
(*Make a list of all the parameters in a subgoal, even if nested*) |
|
255 |
fun strip_params (Const("==>", _) $ H $ B) = strip_params B |
|
256 |
| strip_params (Const("all",_)$Abs(a,T,t)) = (a,T) :: strip_params t |
|
257 |
| strip_params B = []; |
|
258 |
||
9667 | 259 |
(*test for meta connectives in prems of a 'subgoal'*) |
260 |
fun has_meta_prems prop i = |
|
261 |
let |
|
262 |
fun is_meta (Const ("==>", _) $ _ $ _) = true |
|
10442 | 263 |
| is_meta (Const ("==", _) $ _ $ _) = true |
9667 | 264 |
| is_meta (Const ("all", _) $ _) = true |
265 |
| is_meta _ = false; |
|
266 |
in |
|
13659
3cf622f6b0b2
Removed obsolete functions dealing with flex-flex constraints.
berghofe
parents:
12902
diff
changeset
|
267 |
(case strip_prems (i, [], prop) of |
9667 | 268 |
(B :: _, _) => exists is_meta (strip_assums_hyp B) |
269 |
| _ => false) handle TERM _ => false |
|
270 |
end; |
|
9483 | 271 |
|
0 | 272 |
(*Removes the parameters from a subgoal and renumber bvars in hypotheses, |
9460 | 273 |
where j is the total number of parameters (precomputed) |
0 | 274 |
If n>0 then deletes assumption n. *) |
9460 | 275 |
fun remove_params j n A = |
0 | 276 |
if j=0 andalso n<=0 then A (*nothing left to do...*) |
277 |
else case A of |
|
9460 | 278 |
Const("==>", _) $ H $ B => |
279 |
if n=1 then (remove_params j (n-1) B) |
|
280 |
else implies $ (incr_boundvars j H) $ (remove_params j (n-1) B) |
|
0 | 281 |
| Const("all",_)$Abs(a,T,t) => remove_params (j-1) n t |
282 |
| _ => if n>0 then raise TERM("remove_params", [A]) |
|
283 |
else A; |
|
284 |
||
285 |
(** Auto-renaming of parameters in subgoals **) |
|
286 |
||
287 |
val auto_rename = ref false |
|
288 |
and rename_prefix = ref "ka"; |
|
289 |
||
290 |
(*rename_prefix is not exported; it is set by this function.*) |
|
291 |
fun set_rename_prefix a = |
|
4693 | 292 |
if a<>"" andalso forall Symbol.is_letter (Symbol.explode a) |
0 | 293 |
then (rename_prefix := a; auto_rename := true) |
294 |
else error"rename prefix must be nonempty and consist of letters"; |
|
295 |
||
296 |
(*Makes parameters in a goal have distinctive names (not guaranteed unique!) |
|
297 |
A name clash could cause the printer to rename bound vars; |
|
298 |
then res_inst_tac would not work properly.*) |
|
299 |
fun rename_vars (a, []) = [] |
|
300 |
| rename_vars (a, (_,T)::vars) = |
|
12902 | 301 |
(a,T) :: rename_vars (Symbol.bump_string a, vars); |
0 | 302 |
|
303 |
(*Move all parameters to the front of the subgoal, renaming them apart; |
|
304 |
if n>0 then deletes assumption n. *) |
|
305 |
fun flatten_params n A = |
|
306 |
let val params = strip_params A; |
|
9460 | 307 |
val vars = if !auto_rename |
308 |
then rename_vars (!rename_prefix, params) |
|
309 |
else ListPair.zip (variantlist(map #1 params,[]), |
|
310 |
map #2 params) |
|
0 | 311 |
in list_all (vars, remove_params (length vars) n A) |
312 |
end; |
|
313 |
||
314 |
(*Makes parameters in a goal have the names supplied by the list cs.*) |
|
315 |
fun list_rename_params (cs, Const("==>", _) $ A $ B) = |
|
316 |
implies $ A $ list_rename_params (cs, B) |
|
9460 | 317 |
| list_rename_params (c::cs, Const("all",_)$Abs(_,T,t)) = |
0 | 318 |
all T $ Abs(c, T, list_rename_params (cs, t)) |
319 |
| list_rename_params (cs, B) = B; |
|
320 |
||
15451
c6c8786b9921
fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents:
14137
diff
changeset
|
321 |
(*** Treatmsent of "assume", "erule", etc. ***) |
0 | 322 |
|
16879
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
323 |
(*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
|
324 |
HS = [Hn,...,H1], params = [xm,...,x1], and B, |
16879
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
325 |
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
|
326 |
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
|
327 |
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
|
328 |
will be regarded as belonging to the conclusion, and left untouched. |
15454 | 329 |
Used ONLY by assum_pairs. |
330 |
Unless nasms<0, it can terminate the recursion early; that allows |
|
331 |
erule to work on assumptions of the form P==>Q.*) |
|
332 |
fun strip_assums_imp (0, Hs, B) = (Hs, B) (*recursion terminated by nasms*) |
|
16879
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents:
16862
diff
changeset
|
333 |
| strip_assums_imp (nasms, Hs, Const("==>", _) $ H $ B) = |
15454 | 334 |
strip_assums_imp (nasms-1, H::Hs, B) |
335 |
| strip_assums_imp (_, Hs, B) = (Hs, B); (*recursion terminated by B*) |
|
336 |
||
0 | 337 |
|
15451
c6c8786b9921
fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents:
14137
diff
changeset
|
338 |
(*Strips OUTER parameters only, unlike similar legacy versions.*) |
c6c8786b9921
fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents:
14137
diff
changeset
|
339 |
fun strip_assums_all (params, Const("all",_)$Abs(a,T,t)) = |
c6c8786b9921
fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents:
14137
diff
changeset
|
340 |
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
|
341 |
| strip_assums_all (params, B) = (params, B); |
0 | 342 |
|
343 |
(*Produces disagreement pairs, one for each assumption proof, in order. |
|
344 |
A is the first premise of the lifted rule, and thus has the form |
|
15454 | 345 |
H1 ==> ... Hk ==> B and the pairs are (H1,B),...,(Hk,B). |
346 |
nasms is the number of assumptions in the original subgoal, needed when B |
|
347 |
has the form B1 ==> B2: it stops B1 from being taken as an assumption. *) |
|
348 |
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
|
349 |
let val (params, A') = strip_assums_all ([],A) |
15454 | 350 |
val (Hs,B) = strip_assums_imp (nasms,[],A') |
15451
c6c8786b9921
fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents:
14137
diff
changeset
|
351 |
fun abspar t = Unify.rlist_abs(params, t) |
c6c8786b9921
fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents:
14137
diff
changeset
|
352 |
val D = abspar B |
c6c8786b9921
fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents:
14137
diff
changeset
|
353 |
fun pairrev ([], pairs) = pairs |
c6c8786b9921
fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents:
14137
diff
changeset
|
354 |
| 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
|
355 |
in pairrev (Hs,[]) |
0 | 356 |
end; |
357 |
||
358 |
(*Converts Frees to Vars and TFrees to TVars so that axioms can be written |
|
359 |
without (?) everywhere*) |
|
16862 | 360 |
fun varify (Const(a, T)) = Const (a, Type.varifyT T) |
361 |
| varify (Free (a, T)) = Var ((a, 0), Type.varifyT T) |
|
362 |
| varify (Var (ixn, T)) = Var (ixn, Type.varifyT T) |
|
363 |
| varify (t as Bound _) = t |
|
364 |
| varify (Abs (a, T, body)) = Abs (a, Type.varifyT T, varify body) |
|
365 |
| varify (f $ t) = varify f $ varify t; |
|
0 | 366 |
|
546 | 367 |
(*Inverse of varify. Converts axioms back to their original form.*) |
16862 | 368 |
fun unvarify (Const (a, T)) = Const (a, Type.unvarifyT T) |
369 |
| unvarify (Free (a, T)) = Free (a, Type.unvarifyT T) |
|
370 |
| unvarify (Var ((a, 0), T)) = Free (a, Type.unvarifyT T) |
|
371 |
| unvarify (Var (ixn, T)) = Var (ixn, Type.unvarifyT T) (*non-0 index!*) |
|
372 |
| unvarify (t as Bound _) = t |
|
373 |
| unvarify (Abs (a, T, body)) = Abs (a, Type.unvarifyT T, unvarify body) |
|
374 |
| unvarify (f $ t) = unvarify f $ unvarify t; |
|
546 | 375 |
|
13799
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
376 |
|
16862 | 377 |
(* goal states *) |
378 |
||
379 |
fun get_goal st i = nth_prem (i, st) |
|
380 |
handle TERM _ => error "Goal number out of range"; |
|
13799
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
381 |
|
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
382 |
(*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
|
383 |
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
|
384 |
let val gi = get_goal st i |
14137
c57ec95e7763
Removed extraneous rev in function goal_params (the list of parameters
berghofe
parents:
14107
diff
changeset
|
385 |
val rfrees = map Free (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
|
386 |
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
|
387 |
|
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
388 |
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
|
389 |
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
|
390 |
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
|
391 |
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
|
392 |
|
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents:
13659
diff
changeset
|
393 |
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
|
394 |
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
|
395 |
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
|
396 |
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
|
397 |
|
0 | 398 |
end; |