FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaRes/src/atp/SimpleProofState.java at master · eprover/JavaRes · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
eprover
/
JavaRes
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaRes
/
src
/
atp
/
SimpleProofState.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
158 lines (128 loc) · 5.82 KB
Breadcrumbs
JavaRes
/
src
/
atp
/
SimpleProofState.java
Copy path
File metadata and controls
158 lines (128 loc) · 5.82 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
* Minimal implementation of the given-clause algorithm for
saturation of clause sets under the rules of the resolution calculus.
Copyright 2010-2011 Adam Pease, apease@articulatesoftware.com
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
*/
package
atp
;
import
java
.
io
.*;
/** ***************************************************************
* Top-level data structure for the prover. The complete knowledge
* base is split into two sets, processed clauses and unprocessed
* clauses. These are represented here as individual clause sets. The
* main algorithm "processes" clauses and moves them from the
* unprocessed into the processed set. Processing typically generates
* several new clauses, which are direct consequences of the given
* clause and the processed clauses. These new clauses are added to
* the set of unprocessed clauses.
*/
public
class
SimpleProofState
{
ClauseSet
unprocessed
=
new
ClauseSet
();
ClauseSet
processed
=
new
ClauseSet
();
/** ***************************************************************
* Initialize the proof state with a set of clauses.
*/
public
SimpleProofState
(
ClauseSet
clauses
) {
unprocessed
.
addAll
(
clauses
);
}
/** ***************************************************************
* Pick a clause from unprocessed and process it. If the empty
* clause is found, return it. Otherwise return None.
*/
public
Clause
processClause
() {
Clause
given_clause
=
unprocessed
.
extractFirst
();
given_clause
=
given_clause
.
freshVarCopy
();
System
.
out
.
println
(
"#"
+
given_clause
.
toStringJustify
());
if
(
given_clause
.
isEmpty
())
// We have found an explicit contradiction
return
given_clause
;
ClauseSet
newClauses
=
new
ClauseSet
();
ClauseSet
factors
=
ResControl
.
computeAllFactors
(
given_clause
);
//System.out.println("INFO in SimpleProofState.processClause(): factors: " + factors);
newClauses
.
addAll
(
factors
);
ClauseSet
resolvents
=
ResControl
.
computeAllResolvents
(
given_clause
,
processed
);
//System.out.println("INFO in SimpleProofState.processClause(): resolvents: " + resolvents);
newClauses
.
addAll
(
resolvents
);
processed
.
add
(
given_clause
);
//System.out.println("INFO in SimpleProofState.processClause(): processed clauses: " + processed);
for
(
int
i
=
0
;
i
<
newClauses
.
length
();
i
++) {
Clause
c
=
newClauses
.
get
(
i
);
unprocessed
.
add
(
c
);
}
return
null
;
}
/** ***************************************************************
* Main proof procedure. If the clause set is found
* unsatisfiable, return the empty clause as a witness. Otherwise
* return None.
*/
public
Clause
saturate
() {
while
(
unprocessed
.
length
() !=
0
) {
//System.out.println("INFO in SimpleProofState.saturate(): unprocessed clauses: " + unprocessed);
Clause
res
=
processClause
();
if
(
res
!=
null
)
return
res
;
//else
//return null;
}
return
null
;
}
/** ***************************************************************
* ************ UNIT TESTS *****************
*/
public
static
String
spec1
=
"cnf(axiom, a_is_true, a).
\n
"
+
"cnf(negated_conjecture, is_a_true, ~a)."
;
public
static
String
spec2
=
"cnf(axiom1, humans_are_mortal, mortal(X)|~human(X)).
\n
"
+
"cnf(axiom2, socrates_is_human, human(socrates)).
\n
"
+
"cnf(negated_conjecture, is_socrates_mortal, ~mortal(socrates)).
\n
"
;
public
static
String
spec3
=
"cnf(p_or_q, axiom, p(a)).
\n
"
+
"cnf(taut, axiom, q(a)).
\n
"
+
"cnf(not_p, axiom, p(b)).
\n
"
;
/** ***************************************************************
* Evaluate the result of a saturation compared to the expected result.
*/
public
static
void
evalSatResult
(
String
spec
,
boolean
provable
) {
Lexer
lex
=
new
Lexer
(
spec
);
ClauseSet
problem
=
new
ClauseSet
();
problem
.
parse
(
lex
);
//System.out.println("SimpleProofState.evalSatResult(): problem: " + problem);
SimpleProofState
prover
=
new
SimpleProofState
(
problem
);
Clause
res
=
prover
.
saturate
();
if
(
provable
) {
if
(
res
==
null
)
System
.
out
.
println
(
"# Failure: Should have found a proof!"
);
else
System
.
out
.
println
(
"# Success: Proof found"
);
}
else
{
if
(
res
!=
null
)
System
.
out
.
println
(
"# Failure: Should not have found a proof!"
);
else
System
.
out
.
println
(
"# Success: No proof found"
);
}
}
/** ***************************************************************
* Test that saturation works.
*/
public
static
void
testSaturation
() {
evalSatResult
(
spec1
,
true
);
evalSatResult
(
spec2
,
true
);
evalSatResult
(
spec3
,
false
);
}
/** ***************************************************************
* Test method for this class.
*/
public
static
void
main
(
String
[]
args
) {
testSaturation
();
}
}
Back
|
FazBrowse Home
|
New Git URL