| author | paulson |
| Tue, 16 Aug 2005 15:36:28 +0200 | |
| changeset 17084 | fb0a80aef0be |
| parent 16515 | 7896ea4f3a87 |
| child 17312 | 159783c74f75 |
| permissions | -rw-r--r-- |
|
15789
4cb16144c81b
added hearder lines and deleted some redundant material
paulson
parents:
15774
diff
changeset
|
1 |
(* ID: $Id$ |
|
4cb16144c81b
added hearder lines and deleted some redundant material
paulson
parents:
15774
diff
changeset
|
2 |
Author: Claire Quigley |
|
4cb16144c81b
added hearder lines and deleted some redundant material
paulson
parents:
15774
diff
changeset
|
3 |
Copyright 2004 University of Cambridge |
|
4cb16144c81b
added hearder lines and deleted some redundant material
paulson
parents:
15774
diff
changeset
|
4 |
*) |
|
4cb16144c81b
added hearder lines and deleted some redundant material
paulson
parents:
15774
diff
changeset
|
5 |
|
| 16061 | 6 |
structure ReconOrderClauses = |
7 |
struct |
|
8 |
||
| 15642 | 9 |
(*----------------------------------------------*) |
10 |
(* Reorder clauses for use in binary resolution *) |
|
11 |
(*----------------------------------------------*) |
|
12 |
||
13 |
fun remove_nth n [] = [] |
|
| 15697 | 14 |
| remove_nth n xs = (List.take (xs, n-1)) @ (List.drop (xs, n)) |
| 15642 | 15 |
|
| 15774 | 16 |
(*Differs from List.nth: it counts from 1 rather than from 0*) |
17 |
fun get_nth n (x::xs) = hd (Library.drop (n-1, x::xs)) |
|
| 15642 | 18 |
|
19 |
||
20 |
exception Not_in_list; |
|
21 |
||
22 |
||
23 |
fun numlist 0 = [] |
|
24 |
| numlist n = (numlist (n - 1))@[n] |
|
25 |
||
26 |
||
27 |
fun last(x::xs) = if xs=[] then x else last xs |
|
28 |
fun butlast []= [] |
|
29 |
| butlast(x::xs) = if xs=[] then [] else (x::(butlast xs)) |
|
30 |
||
31 |
||
32 |
fun minus a b = b - a; |
|
33 |
||
34 |
||
35 |
(* code to rearrange clauses so that they're the same as the parsed in SPASS version *) |
|
36 |
||
37 |
fun takeUntil ch [] res = (res, []) |
|
38 |
| takeUntil ch (x::xs) res = if x = ch |
|
39 |
then |
|
40 |
(res, xs) |
|
41 |
else |
|
| 16061 | 42 |
takeUntil ch xs (res@[x]); |
43 |
||
| 16157 | 44 |
fun contains_eq str = "=" mem str |
| 15642 | 45 |
|
46 |
fun eq_not_neq str = let val uptoeq = fst(takeUntil "=" str []) |
|
| 16061 | 47 |
in (last uptoeq) <> "~" end |
| 15642 | 48 |
|
49 |
fun get_eq_strs str = if eq_not_neq str (*not an inequality *) |
|
50 |
then |
|
51 |
let val (left, right) = takeUntil "=" str [] |
|
52 |
in |
|
| 15774 | 53 |
(butlast left, tl right) |
| 15642 | 54 |
end |
55 |
else (* is an inequality *) |
|
56 |
let val (left, right) = takeUntil "~" str [] |
|
57 |
in |
|
| 15774 | 58 |
(butlast left, tl (tl right)) |
| 15642 | 59 |
end |
60 |
||
61 |
||
62 |
||
63 |
fun switch_equal a x = let val (a_lhs, a_rhs) = get_eq_strs a |
|
64 |
val (x_lhs, x_rhs) = get_eq_strs x |
|
65 |
in |
|
66 |
(a_lhs = x_rhs) andalso (a_rhs = x_lhs) |
|
67 |
end |
|
68 |
||
69 |
fun is_var_pair (a,b) vars = (a mem vars) andalso (b mem vars) |
|
70 |
||
|
16515
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
16157
diff
changeset
|
71 |
fun var_equiv vars (a,b) = a=b orelse (is_var_pair (a,b) vars) |
| 15642 | 72 |
|
73 |
fun all_true [] = false |
|
74 |
| all_true xs = let val falselist = List.filter (equal false ) xs |
|
75 |
in |
|
76 |
falselist = [] |
|
77 |
end |
|
78 |
||
79 |
||
80 |
||
| 16061 | 81 |
fun var_pos_eq vars x y = |
82 |
String.size x = String.size y andalso |
|
83 |
let val xs = explode x |
|
84 |
val ys = explode y |
|
85 |
val xsys = ListPair.zip (xs,ys) |
|
86 |
val are_var_pairs = map (var_equiv vars) xsys |
|
87 |
in |
|
88 |
all_true are_var_pairs |
|
89 |
end; |
|
90 |
||
91 |
fun pos_in_list a [] allvars (pos_num, symlist, nsymlist) = raise Not_in_list |
|
92 |
| pos_in_list a (x::[]) allvars (pos_num , symlist, nsymlist) = |
|
93 |
let val y = explode x |
|
94 |
val b = explode a |
|
95 |
in |
|
96 |
if b = y |
|
97 |
then |
|
98 |
(pos_num, symlist, nsymlist) |
|
99 |
else |
|
100 |
if (var_pos_eq allvars a x) |
|
101 |
then (* Equal apart from meta-vars having different names *) |
|
102 |
(pos_num, symlist, nsymlist) |
|
103 |
else |
|
104 |
if (contains_eq b) andalso (contains_eq y) |
|
105 |
then |
|
106 |
if (eq_not_neq b) andalso (eq_not_neq y) andalso (switch_equal b y ) |
|
107 |
then (* both are equalities and equal under sym*) |
|
108 |
(pos_num, (pos_num::symlist), nsymlist) (* add pos to symlist *) |
|
109 |
else |
|
110 |
if not(eq_not_neq b) andalso not(eq_not_neq y) andalso (switch_equal b y) |
|
111 |
then (* if they're equal under not_sym *) |
|
112 |
(pos_num, (symlist), (pos_num::nsymlist))(* add pos to nsymlist *) |
|
113 |
else |
|
114 |
raise Not_in_list |
|
115 |
else |
|
116 |
raise Not_in_list |
|
117 |
end |
|
118 |
| pos_in_list a (x::xs) allvars (pos_num, symlist, nsymlist) = |
|
119 |
let val y = explode x |
|
120 |
val b = explode a |
|
121 |
in |
|
122 |
if b = y |
|
123 |
then |
|
124 |
(pos_num, symlist, nsymlist) |
|
125 |
||
126 |
else |
|
127 |
if (var_pos_eq allvars a x) (* Equal apart from meta-vars having different names *) |
|
128 |
then |
|
129 |
(pos_num, symlist, nsymlist) |
|
130 |
else |
|
131 |
if (contains_eq b) andalso (contains_eq y) |
|
132 |
then |
|
133 |
if (eq_not_neq b) andalso (eq_not_neq y) andalso (switch_equal b y ) (* both are equalities and equal under sym*) |
|
134 |
then |
|
135 |
(pos_num, (pos_num::symlist), nsymlist) (* add pos to symlist *) else |
|
136 |
if not(eq_not_neq b) andalso not(eq_not_neq y) andalso (switch_equal b y ) (* if they're equal under not_sym *) |
|
137 |
then |
|
138 |
(pos_num, (symlist), (pos_num::nsymlist))(* add pos to nsymlist *) |
|
139 |
else |
|
140 |
pos_in_list a xs allvars((pos_num + 1), symlist, nsymlist) |
|
141 |
else |
|
142 |
pos_in_list a xs allvars((pos_num + 1), symlist, nsymlist) |
|
143 |
||
144 |
end; |
|
| 15642 | 145 |
|
146 |
||
| 16061 | 147 |
(* in |
148 |
if b = y |
|
149 |
then |
|
150 |
(pos_num, symlist, nsymlist) |
|
151 |
else if (contains_eq b) andalso (contains_eq y) |
|
152 |
then if (eq_not_neq b) andalso (eq_not_neq y) (* both are equalities*) |
|
153 |
then if (switch_equal b y ) (* if they're equal under sym *) |
|
154 |
then |
|
155 |
(pos_num, (pos_num::symlist), nsymlist) (* add pos to symlist *) |
|
156 |
else |
|
157 |
pos_in_list a xs ((pos_num + 1), symlist, nsymlist) |
|
158 |
else if not(eq_not_neq b) andalso not(eq_not_neq y) (* both are inequalities *) |
|
159 |
then if (switch_equal b y ) (* if they're equal under not_sym *) |
|
160 |
then |
|
161 |
(pos_num, (symlist), (pos_num::nsymlist))(* add pos to nsymlist *) |
|
162 |
else |
|
163 |
pos_in_list a xs ((pos_num + 1), symlist, nsymlist) |
|
164 |
else |
|
165 |
pos_in_list a xs ((pos_num + 1), symlist, nsymlist) |
|
166 |
else |
|
167 |
pos_in_list a xs ((pos_num + 1), symlist, nsymlist) |
|
168 |
else |
|
169 |
pos_in_list a xs ((pos_num + 1), symlist, nsymlist) |
|
170 |
end |
|
| 15642 | 171 |
|
| 16061 | 172 |
*) |
| 15642 | 173 |
|
174 |
||
175 |
(* checkorder Spass Isabelle [] *) |
|
176 |
||
| 16061 | 177 |
fun checkorder [] strlist allvars (numlist, symlist, not_symlist) = |
178 |
(numlist,symlist, not_symlist) |
|
| 15642 | 179 |
| checkorder (x::xs) strlist allvars (numlist, symlist, not_symlist) = |
| 16061 | 180 |
let val (posnum, symlist', not_symlist') = |
181 |
pos_in_list x strlist allvars (0, symlist, not_symlist) |
|
| 15642 | 182 |
in |
183 |
checkorder xs strlist allvars ((numlist@[posnum]), symlist', not_symlist') |
|
184 |
end |
|
185 |
||
186 |
fun is_digit ch = |
|
187 |
( ch >= "0" andalso ch <= "9") |
|
188 |
||
189 |
||
190 |
fun is_alpha ch = |
|
191 |
(ch >= "A" andalso ch <= "Z") orelse |
|
192 |
(ch >= "a" andalso ch <= "z") |
|
193 |
||
194 |
||
| 16061 | 195 |
fun is_alpha_space_or_neg_or_eq ch = |
196 |
(ch = "~") orelse (is_alpha ch) orelse ( ch = " ")orelse ( ch = "=") |
|
| 15642 | 197 |
|
|
15739
bb2acfed8212
yet more tidying up: removal of some references to Main
paulson
parents:
15702
diff
changeset
|
198 |
fun lit_string sg t = |
| 16061 | 199 |
let val termstr = Sign.string_of_term sg t |
200 |
val exp_term = explode termstr |
|
201 |
in |
|
202 |
implode(List.filter is_alpha_space_or_neg_or_eq exp_term) |
|
203 |
end |
|
| 15642 | 204 |
|
|
15739
bb2acfed8212
yet more tidying up: removal of some references to Main
paulson
parents:
15702
diff
changeset
|
205 |
fun get_meta_lits thm = map (lit_string (sign_of_thm thm)) (prems_of thm) |
| 15642 | 206 |
|
207 |
||
| 16061 | 208 |
fun is_alpha_space_or_neg_or_eq_or_bracket ch = |
209 |
is_alpha_space_or_neg_or_eq ch orelse (ch= "(") orelse (ch = ")")
|
|
| 15642 | 210 |
|
|
15739
bb2acfed8212
yet more tidying up: removal of some references to Main
paulson
parents:
15702
diff
changeset
|
211 |
fun lit_string_bracket sg t = |
| 16061 | 212 |
let val termstr = Sign.string_of_term sg t |
213 |
val exp_term = explode termstr |
|
214 |
in |
|
215 |
implode(List.filter is_alpha_space_or_neg_or_eq_or_bracket exp_term) |
|
216 |
end; |
|
| 15642 | 217 |
|
|
15739
bb2acfed8212
yet more tidying up: removal of some references to Main
paulson
parents:
15702
diff
changeset
|
218 |
fun get_meta_lits_bracket thm = |
|
bb2acfed8212
yet more tidying up: removal of some references to Main
paulson
parents:
15702
diff
changeset
|
219 |
map (lit_string_bracket (sign_of_thm thm)) (prems_of thm) |
| 15642 | 220 |
|
221 |
||
222 |
fun apply_rule rule [] thm = thm |
|
223 |
| apply_rule rule (x::xs) thm = let val thm' = rule RSN ((x+1),thm) |
|
224 |
in |
|
225 |
apply_rule rule xs thm' |
|
226 |
end |
|
227 |
||
228 |
||
229 |
||
| 16061 | 230 |
(* resulting thm, clause-strs in spass order, vars *) |
| 15642 | 231 |
|
232 |
fun rearrange_clause thm res_strlist allvars = |
|
| 16061 | 233 |
let val isa_strlist = get_meta_lits thm |
234 |
(* change this to use Jia's code to get same looking thing as isastrlist? *) |
|
235 |
val (posns, symlist, not_symlist) = checkorder res_strlist isa_strlist allvars([],[],[]) |
|
236 |
val symmed = apply_rule sym symlist thm |
|
237 |
val not_symmed = apply_rule not_sym not_symlist symmed |
|
238 |
in |
|
239 |
((rearrange_prems posns not_symmed), posns, symlist,not_symlist) |
|
240 |
end |
|
241 |
||
242 |
end; |
|
243 |