return find != d_nodeToLiteralMap.end();
}
-void CnfStream::ensureLiteral(TNode n, bool noPreregistration)
+void CnfStream::ensureMappingForLiteral(TNode n)
{
- // These are not removable and have no proof ID
- d_removable = false;
-
- Trace("cnf") << "ensureLiteral(" << n << ")\n";
- if(hasLiteral(n)) {
- SatLiteral lit = getLiteral(n);
- if(!d_literalToNodeMap.contains(lit)){
- // Store backward-mappings
- d_literalToNodeMap.insert(lit, n);
- d_literalToNodeMap.insert(~lit, n.notNode());
- }
- return;
+ SatLiteral lit = getLiteral(n);
+ if (!d_literalToNodeMap.contains(lit))
+ {
+ // Store backward-mappings
+ d_literalToNodeMap.insert(lit, n);
+ d_literalToNodeMap.insert(~lit, n.notNode());
}
+}
+void CnfStream::ensureLiteral(TNode n)
+{
AlwaysAssertArgument(
- n.getType().isBoolean(),
+ hasLiteral(n) || n.getType().isBoolean(),
n,
- "CnfStream::ensureLiteral() requires a node of Boolean type.\n"
+ "ProofCnfStream::ensureLiteral() requires a node of Boolean type.\n"
"got node: %s\n"
"its type: %s\n",
n.toString().c_str(),
n.getType().toString().c_str());
-
- bool negated CVC4_UNUSED = false;
- SatLiteral lit;
-
- if(n.getKind() == kind::NOT) {
- negated = true;
- n = n[0];
+ Trace("cnf") << "ensureLiteral(" << n << ")\n";
+ if (hasLiteral(n))
+ {
+ ensureMappingForLiteral(n);
+ return;
}
-
- if( theory::Theory::theoryOf(n) == theory::THEORY_BOOL &&
- !n.isVar() ) {
+ // remove top level negation
+ n = n.getKind() == kind::NOT ? n[0] : n;
+ if (theory::Theory::theoryOf(n) == theory::THEORY_BOOL && !n.isVar())
+ {
// If we were called with something other than a theory atom (or
// Boolean variable), we get a SatLiteral that is definitionally
// equal to it.
{
d_cnfProof->pushCurrentAssertion(Node::null());
}
+ // These are not removable and have no proof ID
+ d_removable = false;
- lit = toCNF(n, false);
+ SatLiteral lit = toCNF(n, false);
if (d_cnfProof)
{
// These may already exist
d_literalToNodeMap.insert_safe(lit, n);
d_literalToNodeMap.insert_safe(~lit, n.notNode());
- } else {
+ }
+ else
+ {
// We have a theory atom or variable.
- lit = convertAtom(n, noPreregistration);
+ convertAtom(n);
}
-
- Assert(hasLiteral(n) && getNode(lit) == n);
- Debug("ensureLiteral") << "CnfStream::ensureLiteral(): out lit is " << lit << std::endl;
}
SatLiteral CnfStream::newLiteral(TNode node, bool isTheoryAtom, bool preRegister, bool canEliminate) {
d_cnfProof = proof;
}
-SatLiteral CnfStream::convertAtom(TNode node, bool noPreregistration) {
+SatLiteral CnfStream::convertAtom(TNode node)
+{
Trace("cnf") << "convertAtom(" << node << ")\n";
Assert(!hasLiteral(node)) << "atom already mapped!";
{
theoryLiteral = true;
canEliminate = false;
- preRegister = !noPreregistration;
+ preRegister = true;
}
// Make a new literal (variables are not considered theory literals)
break;
}
// Return the (maybe negated) literal
+ Trace("cnf") << "toCNF(): resulting literal: "
+ << (!negated ? nodeLit : ~nodeLit) << "\n";
return !negated ? nodeLit : ~nodeLit;
}
* can be queried via getSatValue(). Essentially, this is like a "convert-but-
* don't-assert" version of convertAndAssert().
*/
- void ensureLiteral(TNode n, bool noPreregistration = false);
+ void ensureLiteral(TNode n);
/**
* Returns the literal that represents the given node in the SAT CNF
SatLiteral handleAnd(TNode node);
SatLiteral handleOr(TNode node);
+ /** Stores the literal of the given node in d_literalToNodeMap.
+ *
+ * Note that n must already have a literal associated to it in
+ * d_nodeToLiteralMap.
+ */
+ void ensureMappingForLiteral(TNode n);
+
/** The SAT solver we will be using */
SatSolver* d_satSolver;
* structure in this expression. Assumed to not be in the
* translation cache.
*/
- SatLiteral convertAtom(TNode node, bool noPreprocessing = false);
+ SatLiteral convertAtom(TNode node);
/** Pointer to resource manager for associated SmtEngine */
ResourceManager* d_resourceManager;
d_psb.clear();
}
+void ProofCnfStream::ensureLiteral(TNode n)
+{
+ Trace("cnf") << "ProofCnfStream::ensureLiteral(" << n << ")\n";
+ if (d_cnfStream.hasLiteral(n))
+ {
+ d_cnfStream.ensureMappingForLiteral(n);
+ return;
+ }
+ // remove top level negation. We don't need to track this because it's a
+ // literal.
+ n = n.getKind() == kind::NOT ? n[0] : n;
+ if (theory::Theory::theoryOf(n) == theory::THEORY_BOOL && !n.isVar())
+ {
+ SatLiteral lit = toCNF(n, false);
+ // Store backward-mappings
+ // These may already exist
+ d_cnfStream.d_literalToNodeMap.insert_safe(lit, n);
+ d_cnfStream.d_literalToNodeMap.insert_safe(~lit, n.notNode());
+ }
+ else
+ {
+ d_cnfStream.convertAtom(n);
+ }
+}
+
SatLiteral ProofCnfStream::toCNF(TNode node, bool negated)
{
Trace("cnf") << "toCNF(" << node