This adds functionality to CNF stream to allow e.g. TheoryProxy to be notified when a formula is asserted (not just literals).
This will be required for SAT relevancy.
No behavior changes in this PR.
context::Context* context,
OutputManager* outMgr,
ResourceManager* rm,
- bool fullLitToNodeMap,
+ FormulaLitPolicy flpol,
std::string name)
: d_satSolver(satSolver),
d_outMgr(outMgr),
d_booleanVariables(context),
+ d_notifyFormulas(context),
d_nodeToLiteralMap(context),
d_literalToNodeMap(context),
- d_fullLitToNodeMap(fullLitToNodeMap),
+ d_flitPolicy(flpol),
d_registrar(registrar),
d_name(name),
d_cnfProof(nullptr),
<< push;
Assert(node.getKind() != kind::NOT);
+ // if we are tracking formulas, everything is a theory atom
+ if (!isTheoryAtom && d_flitPolicy == FormulaLitPolicy::TRACK_AND_NOTIFY)
+ {
+ isTheoryAtom = true;
+ d_notifyFormulas.insert(node);
+ }
+
// Get the literal for this node
SatLiteral lit;
if (!hasLiteral(node)) {
}
// If it's a theory literal, need to store it for back queries
- if ( isTheoryAtom || d_fullLitToNodeMap || (Dump.isOn("clauses")) ) {
+ if (isTheoryAtom || d_flitPolicy == FormulaLitPolicy::TRACK
+ || (Dump.isOn("clauses")))
+ {
d_literalToNodeMap.insert_safe(lit, node);
d_literalToNodeMap.insert_safe(~lit, node.notNode());
}
}
}
+bool CnfStream::isNotifyFormula(TNode node) const
+{
+ return d_notifyFormulas.find(node) != d_notifyFormulas.end();
+}
+
void CnfStream::setProof(CnfProof* proof) {
Assert(d_cnfProof == NULL);
d_cnfProof = proof;
#ifndef CVC4__PROP__CNF_STREAM_H
#define CVC4__PROP__CNF_STREAM_H
+#include "context/cdhashset.h"
#include "context/cdinsert_hashmap.h"
#include "context/cdlist.h"
#include "expr/node.h"
class ProofCnfStream;
+/** A policy for how literals for formulas are handled in cnf_stream */
+enum class FormulaLitPolicy : uint32_t
+{
+ // literals for formulas are notified
+ TRACK_AND_NOTIFY,
+ // literals for formulas are added to node map
+ TRACK,
+ // literals for formulas are kept internal (default)
+ INTERNAL,
+};
+
/**
* Implements the following recursive algorithm
* http://people.inf.ethz.ch/daniekro/classes/251-0247-00/f2007/readings/Tseitin70.pdf
* @param outMgr Reference to the output manager of the smt engine. Assertions
* will not be dumped if outMgr == nullptr.
* @param rm the resource manager of the CNF stream
- * @param fullLitToNodeMap maintain a full SAT-literal-to-Node mapping.
+ * @param flpol policy for literals corresponding to formulas (those that are
+ * not-theory literals).
* @param name string identifier to distinguish between different instances
* even for non-theory literals.
*/
context::Context* context,
OutputManager* outMgr,
ResourceManager* rm,
- bool fullLitToNodeMap = false,
+ FormulaLitPolicy flpol = FormulaLitPolicy::INTERNAL,
std::string name = "");
/**
* Convert a given formula to CNF and assert it to the SAT solver.
*/
void getBooleanVariables(std::vector<TNode>& outputVariables) const;
+ /**
+ * For SAT/theory relevancy. Returns true if node is a "notify formula".
+ * Returns true if node is formula that we are being notified about that
+ * is not a theory atom.
+ *
+ * Note this is only ever true when the policy passed to this class is
+ * FormulaLitPolicy::TRACK_AND_NOTIFY.
+ */
+ bool isNotifyFormula(TNode node) const;
+
/** Retrieves map from nodes to literals. */
const CnfStream::NodeToLiteralMap& getTranslationCache() const;
/** Boolean variables that we translated */
context::CDList<TNode> d_booleanVariables;
+ /** Formulas that we translated that we are notifying */
+ context::CDHashSet<Node, NodeHashFunction> d_notifyFormulas;
+
/** Map from nodes to literals */
NodeToLiteralMap d_nodeToLiteralMap;
* theory lits. This is true if e.g. replay logging is on, which
* dumps the Nodes corresponding to decision literals.
*/
- const bool d_fullLitToNodeMap;
+ const FormulaLitPolicy d_flitPolicy;
/** The "registrar" for pre-registration of terms */
Registrar* d_registrar;
polarity .push(sign);
decision .push();
trail .capacity(v+1);
- theory .push(isTheoryAtom);
+ // push whether it corresponds to a theory atom
+ theory.push(isTheoryAtom);
setDecisionVar(v, dvar);
polarity.shrink(shrinkSize);
decision.shrink(shrinkSize);
theory.shrink(shrinkSize);
-
}
if (Debug.isOn("minisat::pop")) {
ClauseAllocator ca;
// CVC4 Stuff
- vec<bool> theory; // Is the variable representing a theory atom
+ /**
+ * A vector determining whether each variable represents a theory atom.
+ * More generally, this value is true for any literal that the theory proxy
+ * should be notified about when asserted.
+ */
+ vec<bool> theory;
enum TheoryCheckType {
// Quick check, but don't perform theory reasoning
d_registrar = new theory::TheoryRegistrar(d_theoryEngine);
d_cnfStream = new CVC4::prop::CnfStream(
- d_satSolver, d_registrar, userContext, &d_outMgr, rm, true);
+ d_satSolver, d_registrar, userContext, &d_outMgr, rm, FormulaLitPolicy::TRACK);
d_theoryProxy = new TheoryProxy(this,
d_theoryEngine,
#include "cvc4_private.h"
#include "options/bv_options.h"
+#include "options/smt_options.h"
#include "prop/cnf_stream.h"
#include "prop/sat_solver_factory.h"
#include "smt/smt_engine.h"
d_nullContext.get(),
nullptr,
rm,
- false,
+ prop::FormulaLitPolicy::INTERNAL,
"EagerBitblaster"));
}
d_nullContext.get(),
nullptr,
rm,
- false,
+ prop::FormulaLitPolicy::INTERNAL,
"LazyBitblaster"));
d_satSolverNotify.reset(
#include "theory/bv/bv_eager_solver.h"
#include "options/bv_options.h"
+#include "options/smt_options.h"
#include "theory/bv/bitblast/aig_bitblaster.h"
#include "theory/bv/bitblast/eager_bitblaster.h"
#include "theory/bv/theory_bv.h"
#include "options/bv_options.h"
+#include "options/smt_options.h"
#include "theory/bv/bv_solver_lazy.h"
#include "theory/bv/bv_solver_simple.h"
#include "theory/bv/theory_bv_utils.h"
case kind::BITVECTOR_UREM:
{
NodeManager* nm = NodeManager::currentNM();
- unsigned width = node.getType().getBitVectorSize();
Kind kind = node.getKind() == kind::BITVECTOR_UDIV
? kind::BITVECTOR_UDIV_TOTAL