These will be necessary for upcoming changes to the SAT proof manager and Proof Cnf Stream to handle incremental proofs when optimizing the level of SAT clauses.
#include "theory/builtin/proof_checker.h"
#include "util/rational.h"
-using namespace cvc5::kind;
-
namespace cvc5 {
namespace prop {
std::string ProofCnfStream::identify() const { return "ProofCnfStream"; }
-void ProofCnfStream::normalizeAndRegister(TNode clauseNode)
+Node ProofCnfStream::normalizeAndRegister(TNode clauseNode)
{
Node normClauseNode = d_psb.factorReorderElimDoubleNeg(clauseNode);
if (Trace.isOn("cnf") && normClauseNode != clauseNode)
<< pop;
}
d_satPM->registerSatAssumptions({normClauseNode});
+ return normClauseNode;
}
void ProofCnfStream::convertAndAssert(TNode node,
void ProofCnfStream::convertAndAssert(TNode node, bool negated)
{
Trace("cnf") << "ProofCnfStream::convertAndAssert(" << node
- << ", negated = " << (negated ? "true" : "false") << ")\n";
+ << ", negated = " << (negated ? "true" : "false") << ")\n"
+ << push;
switch (node.getKind())
{
case kind::AND: convertAndAssertAnd(node, negated); break;
}
}
}
+ Trace("cnf") << pop;
}
void ProofCnfStream::convertAndAssertAnd(TNode node, bool negated)
{
Trace("cnf") << "ProofCnfStream::convertAndAssertAnd(" << node
- << ", negated = " << (negated ? "true" : "false") << ")\n";
+ << ", negated = " << (negated ? "true" : "false") << ")\n"
+ << push;
Assert(node.getKind() == kind::AND);
if (!negated)
{
normalizeAndRegister(clauseNode);
}
}
+ Trace("cnf") << pop;
}
void ProofCnfStream::convertAndAssertOr(TNode node, bool negated)
{
Trace("cnf") << "ProofCnfStream::convertAndAssertOr(" << node
- << ", negated = " << (negated ? "true" : "false") << ")\n";
+ << ", negated = " << (negated ? "true" : "false") << ")\n"
+ << push;
Assert(node.getKind() == kind::OR);
if (!negated)
{
convertAndAssert(node[i], true);
}
}
+ Trace("cnf") << pop;
}
void ProofCnfStream::convertAndAssertXor(TNode node, bool negated)
{
Trace("cnf") << "ProofCnfStream::convertAndAssertXor(" << node
- << ", negated = " << (negated ? "true" : "false") << ")\n";
+ << ", negated = " << (negated ? "true" : "false") << ")\n"
+ << push;
if (!negated)
{
// p XOR q
normalizeAndRegister(clauseNode);
}
}
+ Trace("cnf") << pop;
}
void ProofCnfStream::convertAndAssertIff(TNode node, bool negated)
{
Trace("cnf") << "ProofCnfStream::convertAndAssertIff(" << node
- << ", negated = " << (negated ? "true" : "false") << ")\n";
+ << ", negated = " << (negated ? "true" : "false") << ")\n"
+ << push;
if (!negated)
{
// p <=> q
normalizeAndRegister(clauseNode);
}
}
+ Trace("cnf") << pop;
}
void ProofCnfStream::convertAndAssertImplies(TNode node, bool negated)
{
Trace("cnf") << "ProofCnfStream::convertAndAssertImplies(" << node
- << ", negated = " << (negated ? "true" : "false") << ")\n";
+ << ", negated = " << (negated ? "true" : "false") << ")\n"
+ << push;
if (!negated)
{
// ~p v q
<< "ProofCnfStream::convertAndAssertImplies: NOT_IMPLIES_ELIM2 added "
<< node[1].notNode() << "\n";
}
+ Trace("cnf") << pop;
}
void ProofCnfStream::convertAndAssertIte(TNode node, bool negated)
{
Trace("cnf") << "ProofCnfStream::convertAndAssertIte(" << node
- << ", negated = " << (negated ? "true" : "false") << ")\n";
+ << ", negated = " << (negated ? "true" : "false") << ")\n"
+ << push;
// ITE(p, q, r)
SatLiteral p = toCNF(node[0], false);
SatLiteral q = toCNF(node[1], negated);
normalizeAndRegister(clauseNode);
}
}
+ Trace("cnf") << pop;
}
void ProofCnfStream::convertPropagation(TrustNode trn)
}
}
+
+Node ProofCnfStream::getClauseNode(const SatClause& clause)
+{
+ std::vector<Node> clauseNodes;
+ for (size_t i = 0, size = clause.size(); i < size; ++i)
+ {
+ SatLiteral satLit = clause[i];
+ clauseNodes.push_back(d_cnfStream.getNode(satLit));
+ }
+ // order children by node id
+ std::sort(clauseNodes.begin(), clauseNodes.end());
+ return NodeManager::currentNM()->mkNode(kind::OR, clauseNodes);
+}
+
void ProofCnfStream::ensureLiteral(TNode n)
{
Trace("cnf") << "ProofCnfStream::ensureLiteral(" << n << ")\n";
* resulting clauses of the clausification process are synchronized with the
* clauses used in the underlying SAT solver, which automatically performs the
* above normalizations on all added clauses.
+ *
+ * @param clauseNode The clause node to be normalized.
+ * @return The normalized clause node.
+ */
+ Node normalizeAndRegister(TNode clauseNode);
+
+ /** Gets node equivalent to SAT clause.
+ *
+ * To avoid generating different nodes for the same clause, modulo ordering,
+ * an invariant assumed throughout this class, the OR node generated by this
+ * method always has its children ordered.
*/
- void normalizeAndRegister(TNode clauseNode);
+ Node getClauseNode(const SatClause& clause);
/** Reference to the underlying cnf stream. */
CnfStream& d_cnfStream;
void SatProofManager::printClause(const Minisat::Clause& clause)
{
- for (unsigned i = 0, size = clause.size(); i < size; ++i)
+ for (size_t i = 0, size = clause.size(); i < size; ++i)
{
SatLiteral satLit = MinisatSatSolver::toSatLiteral(clause[i]);
Trace("sat-proof") << satLit << " ";
}
}
-Node SatProofManager::getClauseNode(SatLiteral satLit)
-{
- Assert(d_cnfStream->getNodeCache().find(satLit)
- != d_cnfStream->getNodeCache().end())
- << "SatProofManager::getClauseNode: literal " << satLit
- << " undefined.\n";
- return d_cnfStream->getNodeCache()[satLit];
-}
-
Node SatProofManager::getClauseNode(const Minisat::Clause& clause)
{
std::vector<Node> clauseNodes;
- for (unsigned i = 0, size = clause.size(); i < size; ++i)
+ for (size_t i = 0, size = clause.size(); i < size; ++i)
{
SatLiteral satLit = MinisatSatSolver::toSatLiteral(clause[i]);
- Assert(d_cnfStream->getNodeCache().find(satLit)
- != d_cnfStream->getNodeCache().end())
- << "SatProofManager::getClauseNode: literal " << satLit
- << " undefined\n";
- clauseNodes.push_back(d_cnfStream->getNodeCache()[satLit]);
+ clauseNodes.push_back(d_cnfStream->getNode(satLit));
}
// order children by node id
std::sort(clauseNodes.begin(), clauseNodes.end());
SatLiteral satLit = MinisatSatSolver::toSatLiteral(lit);
Trace("sat-proof") << "SatProofManager::endResChain: chain_res for "
<< satLit;
- endResChain(getClauseNode(satLit), {satLit});
+ endResChain(d_cnfStream->getNode(satLit), {satLit});
}
void SatProofManager::endResChain(const Minisat::Clause& clause)
std::unordered_set<TNode>& premises)
{
Trace("sat-proof") << push << "SatProofManager::explainLit: Lit: " << lit;
- Node litNode = getClauseNode(lit);
+ Node litNode = d_cnfStream->getNode(lit);
Trace("sat-proof") << " [" << litNode << "]\n";
// We don't need to explain nodes who are inputs. Note that it's *necessary*
// to avoid attempting such explanations because they can introduce cycles at
Trace("sat-proof")
<< "SatProofManager::finalizeProof: conflicting (lazy) satLit: "
<< d_conflictLit << "\n";
- finalizeProof(getClauseNode(d_conflictLit), {d_conflictLit});
+ finalizeProof(d_cnfStream->getNode(d_conflictLit), {d_conflictLit});
// reset since if in incremental mode this may be used again
d_conflictLit = undefSatVariable;
}
SatLiteral satLit = MinisatSatSolver::toSatLiteral(inConflict);
Trace("sat-proof") << "SatProofManager::finalizeProof: conflicting satLit: "
<< satLit << "\n";
- Node clauseNode = getClauseNode(satLit);
+ Node clauseNode = d_cnfStream->getNode(satLit);
if (adding)
{
registerSatAssumptions({clauseNode});
void SatProofManager::registerSatLitAssumption(Minisat::Lit lit)
{
Trace("sat-proof") << "SatProofManager::registerSatLitAssumption: - "
- << getClauseNode(MinisatSatSolver::toSatLiteral(lit))
+ << d_cnfStream->getNode(
+ MinisatSatSolver::toSatLiteral(lit))
<< "\n";
- d_assumptions.insert(getClauseNode(MinisatSatSolver::toSatLiteral(lit)));
+ d_assumptions.insert(
+ d_cnfStream->getNode(MinisatSatSolver::toSatLiteral(lit)));
}
void SatProofManager::registerSatAssumptions(const std::vector<Node>& assumps)
/** All clauses added to the SAT solver, kept in a context-dependent manner.
*/
context::CDHashSet<Node> d_assumptions;
-
/**
* A placeholder that may be used to store the literal with the final
* conflict.
*/
SatLiteral d_conflictLit;
- /** Gets node equivalent to literal */
- Node getClauseNode(SatLiteral satLit);
/** Gets node equivalent to clause.
*
* To avoid generating different nodes for the same clause, modulo ordering,