Repository navigation
Expand file tree
/
Copy path__init__.py
More file actions
executable file
·291 lines (252 loc) · 9.31 KB
/
Copy path__init__.py
File metadata and controls
executable file
·291 lines (252 loc) · 9.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#!/usr/bin/env python3
# ----------------------------------
#
# Module pyres-fof.py
"""
Usage: pyres-fof.py [options] <problem_file>
This is a straightforward implementation of a simple resolution-based
prover for full first-order logic. The problem file should be in
TPTP-3 CNF/FOF syntax. Unsupported features include double quoted
strings/distinct objects. Equality is parsed, and will by default be
dealt with by adding equality axioms for all function- and predicate
symbols.
Options:
-h
--help
Print this help.
-s
--silent
Supress output of processed given clauses.
-p
--proof
Construct and print an explicit proof object (or the derivation of
the saturated clause set if no proof can be found).
-i
--index
Use indexing to speed up some operations.
-t
--delete-tautologies
Discard the given clause if it is a tautology.
-f
--forward-subsumption
Discard the given clause if it is subsumed by a processed clause.
-b
--backward-subsumption
Discard processed clauses if they are subsumed by the given clause.
-H <heuristic>
--given-clause-heuristic=<heuristic>
Use the specified heuristic for given-clause selection.
-n
--neg-lit-selection
Use the specified negative literal selection function.
-S
--suppress-eq-axioms
Do not add equality axioms. This makes the prover incomplete for
equality problems.
A reasonable command line to run the prover would be:
./pyres-fof.py -tifb -HPickGiven5 -nlargest EXAMPLES/PUZ001+1.p
Copyright 2011-2023 Stephan Schulz, schulz@eprover.org
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program ; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston,
MA 02111-1307 USA
The original copyright holder can be contacted as
Stephan Schulz
Auf der Altenburg 7
70376 Stuttgart
Germany
Email: schulz@eprover.org
"""
import sys
import time
from resource import RLIMIT_STACK, setrlimit, getrlimit
import getopt
from signal import signal, SIGXCPU
from resource import getrusage, RUSAGE_SELF
from version import version
from lexer import Token, Lexer
from derivations import (
enableDerivationOutput,
disableDerivationOutput,
Derivable,
flatDerivation,
)
from clausesets import ClauseSet
from clauses import firstLit, varSizeLit, eqResVarSizeLit
from fofspec import FOFSpec
from heuristics import GivenClauseHeuristics
from saturation import SearchParams, ProofState
from litselection import LiteralSelectors
from alternatingpath_set import SetRelevanceGraph
suppressEqAxioms = False
silent = False
indexed = False
proofObject = False
def processOptions(opts):
"""
Process the options given
"""
global silent, indexed, suppressEqAxioms, proofObject
params = SearchParams()
for opt, optarg in opts:
if opt == "-h" or opt == "--help":
print("pyres-fof.py " + version)
print(__doc__)
sys.exit()
elif opt == "-s" or opt == "--silent":
silent = True
elif opt == "-V" or opt == "--version":
print("% Version: ", version)
elif opt == "-p" or opt == "--proof":
proofObject = True
elif opt == "-i" or opt == "--index":
indexed = True
elif opt == "-t" or opt == "--delete-tautologies":
params.delete_tautologies = True
elif opt == "-f" or opt == "--forward-subsumption":
params.forward_subsumption = True
elif opt == "-b" or opt == "--backward-subsumption":
params.backward_subsumption = True
elif opt == "-r" or opt == "--relevance-distance":
params.relevance_distance = int(optarg)
params.perform_rel_filter = True
elif opt == "-H" or opt == "--given-clause-heuristic":
try:
params.heuristics = GivenClauseHeuristics[optarg]
except KeyError:
print("Unknown clause evaluation function", optarg)
print("Supported:", GivenClauseHeuristics.keys())
sys.exit(1)
elif opt == "-n" or opt == "--neg-lit-selection":
try:
params.literal_selection = LiteralSelectors[optarg]
except KeyError:
print("Unknown literal selection function", optarg)
print("Supported:", LiteralSelectors.keys())
sys.exit(1)
elif opt == "-S" or opt == "--suppress-eq-axioms":
suppressEqAxioms = True
return params
def timeoutHandler(sign, frame):
"""
This will be called if the process receives a SIGXCPU error. In
that case, we print an informative message before terminating. We
expect this signal from the benchmark environment (typically
StarExec).
"""
print("% Failure: Resource limit exceeded (time)")
print("% SZS status ResourceOut")
sys.exit(0)
def main(from_notebook=False, notebook_opts=[], notebook_args=[]):
# We try to increase stack space, since we use a lot of
# recursion. This works differentially well on different OSes, so
# it is a bit more complex than I would hope for.
try:
soft, hard = getrlimit(RLIMIT_STACK)
soft = 10 * soft
if hard > 0 and soft > hard:
soft = hard
setrlimit(RLIMIT_STACK, (soft, hard))
except ValueError:
# For reasons nobody understands, this seems to fail on
# OS-X. In that case, we just do our best...
pass
signal(SIGXCPU, timeoutHandler)
sys.setrecursionlimit(10000)
if not from_notebook:
try:
opts, args = getopt.gnu_getopt(
sys.argv[1:],
"hsVpitfbH:n:Sr:",
[
"help",
"silent",
"version",
"proof",
"index",
"delete-tautologies",
"forward-subsumption",
"backward-subsumption",
"given-clause-heuristic=",
"neg-lit-selection=",
"supress-eq-axioms",
"relevance-distance=",
],
)
except getopt.GetoptError as err:
print(sys.argv[0], ":", err)
sys.exit(1)
params = processOptions(notebook_opts if from_notebook else opts)
problem = FOFSpec()
for file in notebook_args if from_notebook else args:
problem.parse(file)
if not suppressEqAxioms:
problem.addEqAxioms()
cnf = problem.clausify()
rel_cnf: ClauseSet = ClauseSet()
if params.perform_rel_filter:
print(f"# rel_distance: {params.relevance_distance}")
neg_conjs = cnf.getNegatedConjectures()
start = time.process_time()
rel_graph = SetRelevanceGraph(cnf)
graph_constructed = time.process_time()
rel_cnf = rel_graph.get_rel_neighbourhood(neg_conjs, params.relevance_distance)
neighbourhood_computed = time.process_time()
print(f"# graph_construction_time: {graph_constructed - start}")
print(f"# neighbourhood_computation_time: {neighbourhood_computed - graph_constructed}")
state = ProofState(
params,
rel_cnf if params.perform_rel_filter else cnf,
silent,
indexed,
)
res = state.saturate()
# todo: test alternate path findings properly into statistics and output
if res != None:
if problem.isFof and problem.hasConj:
print("% SZS status Theorem")
else:
print("% SZS status Unsatisfiable")
if proofObject:
proof = res.orderedDerivation()
enableDerivationOutput()
print("% SZS output start CNFRefutation")
for s in proof:
print(s)
print("% SZS output end CNFRefutation")
disableDerivationOutput()
else:
if params.perform_rel_filter and len(rel_cnf) != len(cnf):
print("%\n% SZS status GaveUp")
elif problem.isFof and problem.hasConj:
print("% SZS status CounterSatisfiable")
else:
print("% SZS status Satisfiable")
if proofObject:
dummy = Derivable(
"dummy", flatDerivation("pseudoreference", state.processed.clauses)
)
sat = dummy.orderedDerivation()
enableDerivationOutput()
print("% SZS output start Saturation")
for s in sat[:-1]:
print(s)
print("% SZS output end Saturation")
disableDerivationOutput()
print(state.statisticsStr())
# We use the resources interface to get and print the CPU time
resources = getrusage(RUSAGE_SELF)
print("% -------- CPU Time ---------")
print("%% User time : %.3f s" % (resources.ru_utime,))
print("%% System time : %.3f s" % (resources.ru_stime,))
print("%% Total time : %.3f s" % (resources.ru_utime + resources.ru_stime,))
if __name__ == "__main__":
main()