25#include "ProofChecker.hpp"
28ProofChecker::ProofChecker(
Matrix& m,
49 return (i >= 0 && i <
C.
size());
53 return (i >= 0 && i <
P.size());
57 return (i >= 0 && i <
Lem.size());
63 s +=
C.
to_string(
true) +=
" substituted.\n\nP = { ";
65 s += l.to_string() +=
" ";
68 s += l.to_string(
true) +=
" ";
69 s +=
" } substituted.\n\nL = { ";
71 s += l.to_string() +=
" ";
74 s += l.to_string(
true) +=
" ";
75 s +=
" } substituted.\n\n";
83 for (
size_t i = 0; i <
proof.size(); i++) {
84 out_string +=
"** Proof step: ";
85 out_string += std::to_string(i) +=
" *************************************************\n";
87 ProofLine line =
proof[i];
89 if (line.first ==
"start") {
90 out_string +=
"Found a Start step with C = ";
91 size_t C_i = line.second[0];
92 out_string += std::to_string(C_i) +=
".\n";
94 out_string +=
"Error: you can only use the Start rule as step 1 of a proof.\n";
99 out_string +=
"Error: the start clause index is out of range.\n";
104 out_string +=
"C = ";
107 out_string +=
"Starting from state (with new variables):\n";
110 else if (line.first ==
"left_branch") {
111 size_t Lit_i = line.second[0];
112 size_t newC_i = line.second[1];
113 size_t newLit_i = line.second[2];
114 size_t d = line.second[3];
115 out_string +=
"Found an Extension step (left) with: L = ";
116 out_string += std::to_string(Lit_i) +=
", C' = ";
117 out_string += std::to_string(newC_i) +=
", L' = ";
118 out_string += std::to_string(newLit_i) +=
", depth = ";
119 out_string += std::to_string(d) +=
".\n";
121 out_string +=
"Error: the clause literal index is out of range.\n";
126 out_string +=
"L = ";
127 out_string += Lit.
to_string() +=
"\nL = ";
128 out_string += Lit.
to_string(
true) +=
" substituted.\n";
130 out_string +=
"Error: the new clause index is out of range.\n";
135 out_string +=
"C' = ";
138 out_string +=
"C' = ";
139 out_string += newCcopy.
to_string() +=
" with new variables.\n";
140 if (newLit_i < 0 || newLit_i >= newC.
size()) {
141 out_string +=
"Error: the new literal index is out of range.\n";
145 Literal newLit = newCcopy[newLit_i];
146 Literal newLitinv = newCcopy[newLit_i];
148 out_string +=
"~L' = ";
149 out_string += newLitinv.
to_string() +=
" and has new variables.\n";
150 UnificationOutcome out =
u(Lit, newLitinv);
151 if (out != UnificationOutcome::Succeed) {
152 out_string +=
"Error: these literals can not be unified.\n";
157 out_string +=
"Literals L and ~L' are unified by: ";
161 vector<Literal> rightP(
P);
162 vector<Literal> rightLem(
Lem);
163 rightLem.push_back(Lit);
166 RightStackItem r_item;
167 r_item = std::make_tuple(rightC, rightP, rightLem, d);
174 out_string +=
"Continuing with:\n";
177 else if (line.first ==
"reduction") {
178 size_t Lit_i = line.second[0];
179 size_t P_i = line.second[1];
180 out_string +=
"Found a Reduction step with L = ";
181 out_string += std::to_string(Lit_i) +=
" and L' = ";
182 out_string += std::to_string(P_i) +=
".\n";
184 out_string +=
"Error: the clause literal index is out of range.\n";
189 out_string +=
"Error: the path literal index is out of range.\n";
193 out_string +=
"L = ";
195 out_string += l1.
to_string() +=
"\nL = ";
196 out_string += l1.
to_string(
true) +=
" substituted.\n";
197 out_string +=
"~L' = ";
201 out_string += l2inv.
to_string() +=
"\n~L' = ";
202 out_string += l2inv.
to_string(
true) +=
" substituted.\n";
203 UnificationOutcome out =
u(l1, l2inv);
204 if (out != UnificationOutcome::Succeed) {
205 out_string +=
"Error: these literals can not be unified.\n";
210 out_string +=
"Literals L and ~L' are unified by: ";
214 out_string +=
"Continuing with:\n";
217 else if (line.first ==
"lemmata") {
218 size_t Lit_i = line.second[0];
219 size_t Lem_i = line.second[1];
220 out_string +=
"Found a Lemma step with L = ";
221 out_string += std::to_string(Lit_i) +=
" and L' = ";
222 out_string += std::to_string(Lem_i) +=
".\n";
224 out_string +=
"Error: the clause literal index is out of range.\n";
229 out_string +=
"Error: the lemma literal index is out of range.\n";
233 out_string +=
"L = ";
235 out_string += l1.
to_string() +=
"\nL = ";
236 out_string += l1.
to_string(
true) +=
" substituted.\n";
237 out_string +=
"L' = ";
239 out_string += l2.
to_string() +=
"\nL' = ";
240 out_string += l2.
to_string(
true) +=
" substituted.\n";
242 out_string +=
"Error: these literals are not equal with the current substitution.\n";
246 out_string +=
"Literals L and L' are equal with the current substitution.\n";
248 out_string +=
"Continuing with:\n";
251 else if (line.first ==
"right_branch") {
252 size_t new_d = line.second[0];
253 out_string +=
"Found a right branch step with depth ";
254 out_string += std::to_string(new_d) +=
".\n";
256 out_string +=
"Error: the right stack is empty.\n";
261 out_string +=
"Error: this should be an axiom but C is not empty.\n";
265 out_string +=
"We have an Axiom!\n";
266 RightStackItem r_item(
r_stack.back());
270 Lem = get<2>(r_item);
271 size_t d = get<3>(r_item);
273 out_string +=
"Error: the depths don't match.\n";
277 out_string +=
"Continuing with:\n";
281 out_string +=
"The proof is badly-formed.\n";
287 out_string +=
"Error: you haven't ended with an Axiom.\n";
291 out_string +=
"SUCCESS! The proof is good.\n";
293 for (
size_t i = 0; i <
num_subs; i++) {
296 return pair<bool, string>(result, out_string);
302 for (
size_t i = 0; i <
proof.size(); i++) {
304 ProofLine line =
proof[i];
306 if (line.first ==
"start") {
307 size_t C_i = line.second[0];
319 else if (line.first ==
"left_branch") {
320 size_t Lit_i = line.second[0];
321 size_t newC_i = line.second[1];
322 size_t newLit_i = line.second[2];
323 size_t d = line.second[3];
335 if (newLit_i < 0 || newLit_i >= newC.
size()) {
339 Literal newLit = newCcopy[newLit_i];
340 Literal newLitinv = newCcopy[newLit_i];
342 UnificationOutcome out =
u(Lit, newLitinv);
343 if (out != UnificationOutcome::Succeed) {
350 vector<Literal> rightP(
P);
351 vector<Literal> rightLem(
Lem);
352 rightLem.push_back(Lit);
355 RightStackItem r_item;
356 r_item = std::make_tuple(rightC, rightP, rightLem, d);
364 else if (line.first ==
"reduction") {
365 size_t Lit_i = line.second[0];
366 size_t P_i = line.second[1];
379 UnificationOutcome out =
u(l1, l2inv);
380 if (out != UnificationOutcome::Succeed) {
388 else if (line.first ==
"lemmata") {
389 size_t Lit_i = line.second[0];
390 size_t Lem_i = line.second[1];
407 else if (line.first ==
"right_branch") {
408 size_t new_d = line.second[0];
417 RightStackItem r_item(
r_stack.back());
421 Lem = get<2>(r_item);
422 size_t d = get<3>(r_item);
436 for (
size_t i = 0; i <
num_subs; i++) {
Representation of clauses.
bool empty() const
Straightforward get method.
Clause make_copy_with_new_vars(VariableIndex &, TermIndex &) const
Make a copy of an entire clause, introducing new variables.
size_t size() const
Straightforward get method.
string to_string(bool=false) const
Convert to a string.
void drop_literal(LitNum)
Get rid of the specified Literal.
Basic representation of literals, bundling together (pointers to) a Predicate, a collection of argume...
string to_string(bool=false) const
Full conversion of Literal to string.
bool subbed_equal(Literal *) const
Equality, taking account of substitutions.
void invert()
Basic manipulation - entirely self-explanatory.
Representation of the Matrix within a proof.
ClauseNum get_num_clauses() const
Straightforward get method.
ProofType proof
Straightforward internal representation of the proof.
VariableIndex * vi
Needed as we need to generate things with new variables.
bool P_i_ok(size_t) const
Check index. Self-explanatory!
bool check_proof()
Check the proof quietly.
bool C_i_ok(size_t) const
Check index. Self-explanatory!
bool Lem_i_ok(size_t) const
Check index. Self-explanatory!
vector< Literal > P
Part of the representation of the current state of the proof.
TermIndex * ti
Needed as we need to generate things with new variables.
vector< Literal > Lem
Part of the representation of the current state of the proof.
Unifier u
Needed to check some proof steps.
Matrix & matrix
Reference to the problem matrix.
Clause C
Part of the representation of the current state of the proof.
vector< RightStackItem > r_stack
Collection of right-hand branches to complete.
size_t num_subs
Use this to undo the substitutions when you've finished.
pair< bool, string > check_proof_verbose()
Check the proof and produce a string with a detailed description.
bool Lit_i_ok(size_t) const
Check index. Self-explanatory!
string state_to_string() const
Make a string containing the current state.
Look after terms, using hash consing to avoid storing copies of terms.
void backtrack()
Apply the backtracking process to the substitution that has been constructed.
string to_string(bool subbed=false) const
Make a nice string representation.
Storage of named variables, and management of new, anonymous and unique variables.