-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathpyres-cnf.py
More file actions
executable file
·143 lines (118 loc) · 4.25 KB
/
pyres-cnf.py
File metadata and controls
executable file
·143 lines (118 loc) · 4.25 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
#!/usr/bin/env python3
# ----------------------------------
#
# Module pyres-cnf.py
"""
Usage: pyres-cnf.py [options] <problem_file>
This is a straightforward implementation of a simple resolution-based
prover for first-order clausal logic. Problem file should be in
(restricted) TPTP-3 CNF syntax. Unsupported features include double
quoted strings and include files. Equality is parsed, but not
interpreted so far.
Options:
-h
--help
Print this help.
-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.
Copyright 2011-2019 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 getopt
from version import version
from lexer import Token,Lexer
from derivations import enableDerivationOutput,disableDerivationOutput
from clausesets import ClauseSet
from heuristics import GivenClauseHeuristics
from saturation import SearchParams,ProofState
from litselection import LiteralSelectors
def processOptions(opts):
"""
Process the options given
"""
params = SearchParams()
for opt, optarg in opts:
if opt == "-h" or opt == "--help":
print("pyres-cnf.py "+version)
print(__doc__)
sys.exit()
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=="-H" or opt == "--given-clause-heuristic":
try:
params.heuristics = GivenClauseHeuristics[optarg]
except KeyError:
print("Unknown clause evaluation function", optarg)
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)
sys.exit(1)
return params
if __name__ == '__main__':
try:
opts, args = getopt.gnu_getopt(sys.argv[1:],
"htfbH:n:",
["help",
"delete-tautologies",
"forward-subsumption",
"backward-subsumption"
"given-clause-heuristic=",
"neg-lit-selection="])
except getopt.GetoptError as err:
print(sys.argv[0],":", err)
sys.exit(1)
params = processOptions(opts)
problem = ClauseSet()
for file in args:
fp = open(file, "r")
input = fp.read()
fp.close()
lex = Lexer(input)
problem.parse(lex)
state = ProofState(params, problem)
res = state.saturate()
print(state.statisticsStr())
if res != None:
print("% SZS status Unsatisfiable")
proof = res.orderedDerivation()
enableDerivationOutput()
for s in proof:
print(s)
disableDerivationOutput()
else:
print("% SZS status Satisfiable")