summaryrefslogtreecommitdiff
path: root/src/smt/smt_engine.cpp
diff options
context:
space:
mode:
authorJustin Xu <justinx@barrett5.stanford.edu>2017-08-03 15:25:46 -0700
committerJustin Xu <justinx@barrett5.stanford.edu>2017-08-03 15:25:46 -0700
commitd8c47bc5890b77eb2b73af40389dfa8ab678d297 (patch)
tree51759dfb20ea48602f245ac5614db810148ae31f /src/smt/smt_engine.cpp
parent0935dacd76c09c32783c6c8ffa75ddfbef07590d (diff)
cleaned up code in smt_engine.cpp and removed moved timers
Diffstat (limited to 'src/smt/smt_engine.cpp')
-rw-r--r--src/smt/smt_engine.cpp1151
1 files changed, 23 insertions, 1128 deletions
diff --git a/src/smt/smt_engine.cpp b/src/smt/smt_engine.cpp
index fb8c543ae..e4c152b2a 100644
--- a/src/smt/smt_engine.cpp
+++ b/src/smt/smt_engine.cpp
@@ -127,17 +127,6 @@ void DeleteAndClearCommandVector(std::vector<Command*>& commands) {
}
/** Useful for counting the number of recursive calls. */
-/*class ScopeCounter {
-private:
- unsigned& d_depth;
-public:
- ScopeCounter(unsigned& d) : d_depth(d) {
- ++d_depth;
- }
- ~ScopeCounter(){
- --d_depth;
- }
-};*/
/**
* Representation of a defined function. We keep these around in
@@ -146,72 +135,14 @@ public:
* in terms of defined functions, etc.
*/
-/*class DefinedFunction {
- Node d_func;
- vector<Node> d_formals;
- Node d_formula;
-public:
- DefinedFunction() {}
- DefinedFunction(Node func, vector<Node> formals, Node formula) :
- d_func(func),
- d_formals(formals),
- d_formula(formula) {
- }
- Node getFunction() const { return d_func; }
- vector<Node> getFormals() const { return d_formals; }
- Node getFormula() const { return d_formula; }
-};*/
-/* class DefinedFunction */
-
-/*class AssertionPipeline {
- vector<Node> d_nodes;
-
-public:
-
- size_t size() const { return d_nodes.size(); }
-
- void resize(size_t n) { d_nodes.resize(n); }
- void clear() { d_nodes.clear(); }
-
- Node& operator[](size_t i) { return d_nodes[i]; }
- const Node& operator[](size_t i) const { return d_nodes[i]; }
- void push_back(Node n) { d_nodes.push_back(n); }
-
- vector<Node>& ref() { return d_nodes; }
- const vector<Node>& ref() const { return d_nodes; }
-
- void replace(size_t i, Node n) {
- PROOF( ProofManager::currentPM()->addDependence(n, d_nodes[i]); );
- d_nodes[i] = n;
- }
-}; //class AssertionPipeline
+/*
+ * AssertionPipeline, ScopeCounter, and DefinedFunction classes
+ * moved to preprocessing_pass.h
*/
-
+
struct SmtEngineStatistics {
- /** time spent in definition-expansion */
- TimerStat d_definitionExpansionTime;
- /** time spent in non-clausal simplification */
- TimerStat d_nonclausalSimplificationTime;
- /** time spent in miplib pass */
- TimerStat d_miplibPassTime;
- /** number of assertions removed by miplib pass */
- IntStat d_numMiplibAssertionsRemoved;
- /** number of constant propagations found during nonclausal simp */
- IntStat d_numConstantProps;
- /** time spent in static learning */
- TimerStat d_staticLearningTime;
- /** time spent in simplifying ITEs */
- TimerStat d_simpITETime;
- /** time spent in simplifying ITEs */
- TimerStat d_unconstrainedSimpTime;
/** time spent removing ITEs */
TimerStat d_iteRemovalTime;
- /** time spent in theory preprocessing */
- TimerStat d_theoryPreprocessTime;
- /** time spent in theory preprocessing */
- TimerStat d_rewriteApplyToConstTime;
- /** time spent converting to CNF */
- TimerStat d_cnfConversionTime;
/** Num of assertions before ite removal */
IntStat d_numAssertionsPre;
/** Num of assertions after ite removal */
@@ -235,18 +166,7 @@ struct SmtEngineStatistics {
ReferenceStat<uint64_t> d_resourceUnitsUsed;
SmtEngineStatistics() :
- d_definitionExpansionTime("smt::SmtEngine::definitionExpansionTime"),
- d_nonclausalSimplificationTime("smt::SmtEngine::nonclausalSimplificationTime"),
- d_miplibPassTime("smt::SmtEngine::miplibPassTime"),
- d_numMiplibAssertionsRemoved("smt::SmtEngine::numMiplibAssertionsRemoved", 0),
- d_numConstantProps("smt::SmtEngine::numConstantProps", 0),
- d_staticLearningTime("smt::SmtEngine::staticLearningTime"),
- d_simpITETime("smt::SmtEngine::simpITETime"),
- d_unconstrainedSimpTime("smt::SmtEngine::unconstrainedSimpTime"),
d_iteRemovalTime("smt::SmtEngine::iteRemovalTime"),
- d_theoryPreprocessTime("smt::SmtEngine::theoryPreprocessTime"),
- d_rewriteApplyToConstTime("smt::SmtEngine::rewriteApplyToConstTime"),
- d_cnfConversionTime("smt::SmtEngine::cnfConversionTime"),
d_numAssertionsPre("smt::SmtEngine::numAssertionsPreITERemoval", 0),
d_numAssertionsPost("smt::SmtEngine::numAssertionsPostITERemoval", 0),
d_checkModelTime("smt::SmtEngine::checkModelTime"),
@@ -259,18 +179,7 @@ struct SmtEngineStatistics {
d_resourceUnitsUsed("smt::SmtEngine::resourceUnitsUsed")
{
- smtStatisticsRegistry()->registerStat(&d_definitionExpansionTime);
- smtStatisticsRegistry()->registerStat(&d_nonclausalSimplificationTime);
- smtStatisticsRegistry()->registerStat(&d_miplibPassTime);
- smtStatisticsRegistry()->registerStat(&d_numMiplibAssertionsRemoved);
- smtStatisticsRegistry()->registerStat(&d_numConstantProps);
- smtStatisticsRegistry()->registerStat(&d_staticLearningTime);
- smtStatisticsRegistry()->registerStat(&d_simpITETime);
- smtStatisticsRegistry()->registerStat(&d_unconstrainedSimpTime);
smtStatisticsRegistry()->registerStat(&d_iteRemovalTime);
- smtStatisticsRegistry()->registerStat(&d_theoryPreprocessTime);
- smtStatisticsRegistry()->registerStat(&d_rewriteApplyToConstTime);
- smtStatisticsRegistry()->registerStat(&d_cnfConversionTime);
smtStatisticsRegistry()->registerStat(&d_numAssertionsPre);
smtStatisticsRegistry()->registerStat(&d_numAssertionsPost);
smtStatisticsRegistry()->registerStat(&d_checkModelTime);
@@ -284,18 +193,7 @@ struct SmtEngineStatistics {
}
~SmtEngineStatistics() {
- smtStatisticsRegistry()->unregisterStat(&d_definitionExpansionTime);
- smtStatisticsRegistry()->unregisterStat(&d_nonclausalSimplificationTime);
- smtStatisticsRegistry()->unregisterStat(&d_miplibPassTime);
- smtStatisticsRegistry()->unregisterStat(&d_numMiplibAssertionsRemoved);
- smtStatisticsRegistry()->unregisterStat(&d_numConstantProps);
- smtStatisticsRegistry()->unregisterStat(&d_staticLearningTime);
- smtStatisticsRegistry()->unregisterStat(&d_simpITETime);
- smtStatisticsRegistry()->unregisterStat(&d_unconstrainedSimpTime);
smtStatisticsRegistry()->unregisterStat(&d_iteRemovalTime);
- smtStatisticsRegistry()->unregisterStat(&d_theoryPreprocessTime);
- smtStatisticsRegistry()->unregisterStat(&d_rewriteApplyToConstTime);
- smtStatisticsRegistry()->unregisterStat(&d_cnfConversionTime);
smtStatisticsRegistry()->unregisterStat(&d_numAssertionsPre);
smtStatisticsRegistry()->unregisterStat(&d_numAssertionsPost);
smtStatisticsRegistry()->unregisterStat(&d_checkModelTime);
@@ -563,6 +461,7 @@ public:
RemoveTermFormulas d_iteRemover;
private:
+ //boolean to check if classes have been initialized
bool d_initialized;
theory::arith::PseudoBooleanProcessor d_pbsProcessor;
@@ -572,71 +471,14 @@ private:
static const bool d_doConstantProp = true;
- /**
- * Runs the nonclausal solver and tries to solve all the assigned
- * theory literals.
- *
- * Returns false if the formula simplifies to "false"
- */
- bool nonClausalSimplify();
-
- /**
- * Performs static learning on the assertions.
- */
- void staticLearning();
-
- /**
- * Remove ITEs from the assertions.
- */
- void removeITEs();
- Node intToBVMakeBinary(TNode n, NodeToNodeHashMap& cache);
-
- /**
- * Helper function to fix up assertion list to restore invariants needed after
- * ite removal.
- */
- void collectSkolems(TNode n, set<TNode>& skolemSet, NodeToBoolHashMap& cache);
-
- /**
- * Helper function to fix up assertion list to restore invariants needed after
- * ite removal.
- */
- bool checkForBadSkolems(TNode n, TNode skolem, NodeToBoolHashMap& cache);
-
- // Simplify ITE structure
- bool simpITE();
-
- /**
- * Ensures the assertions asserted after before now effectively come before
- *d_realAssertionsEnd.
- */
- void compressBeforeRealAssertions(size_t before);
-
- /**
- * Trace nodes back to their assertions using CircuitPropagator's
- * BackEdgesMap.
- */
- void traceBackToAssertions(const std::vector<Node>& nodes,
- std::vector<TNode>& assertions);
-
- /**
- * Remove conjuncts in toRemove from conjunction n. Return # of removed
- * conjuncts.
- */
- size_t removeFromConjunction(Node& n,
- const std::unordered_set<unsigned long>& toRemove);
-
- /** Scrub miplib encodings. */
- void doMiplibTrick();
-
- /**
+ /**
* Perform non-clausal simplification of a Node. This involves
* Theory implementations, but does NOT involve the SAT solver in
* any way.
*
* Returns false if the formula simplifies to "false"
*/
- bool simplifyAssertions() throw(TypeCheckingException, LogicException,
+ bool simplifyAssertions() throw(TypeCheckingException, LogicException,
UnsafeInterruptException);
public:
@@ -2410,39 +2252,6 @@ Node SmtEnginePrivate::expandDefinitions(TNode n, unordered_map<Node, Node, Node
typedef std::unordered_map<Node, Node, NodeHashFunction> NodeMap;
-void SmtEnginePrivate::removeITEs() {
- d_smt.finalOptionsAreSet();
- spendResource(options::preprocessStep());
- Trace("simplify") << "SmtEnginePrivate::removeITEs()" << endl;
-
- // Remove all of the ITE occurrences and normalize
- d_iteRemover.run(d_assertions.ref(), *d_assertions.getSkolemMap(), true);
- for (unsigned i = 0; i < d_assertions.size(); ++ i) {
- d_assertions.replace(i, Rewriter::rewrite(d_assertions[i]));
- }
-}
-
-void SmtEnginePrivate::staticLearning() {
- d_smt.finalOptionsAreSet();
- spendResource(options::preprocessStep());
-
- TimerStat::CodeTimer staticLearningTimer(d_smt.d_stats->d_staticLearningTime);
-
- Trace("simplify") << "SmtEnginePrivate::staticLearning()" << endl;
-
- for (unsigned i = 0; i < d_assertions.size(); ++ i) {
-
- NodeBuilder<> learned(kind::AND);
- learned << d_assertions[i];
- d_smt.d_theoryEngine->ppStaticLearn(d_assertions[i], learned);
- if(learned.getNumChildren() == 1) {
- learned.clear();
- } else {
- d_assertions.replace(i, learned);
- }
- }
-}
-
// do dumping (before/after any preprocessing pass)
static void dumpAssertions(const char* key, const AssertionPipeline& assertionList) {
if( Dump.isOn("assertions") &&
@@ -2455,769 +2264,6 @@ static void dumpAssertions(const char* key, const AssertionPipeline& assertionLi
}
}
-// returns false if it learns a conflict
-bool SmtEnginePrivate::nonClausalSimplify() {
- spendResource(options::preprocessStep());
- d_smt.finalOptionsAreSet();
-
- if(options::unsatCores() || options::fewerPreprocessingHoles()) {
- return true;
- }
-
- TimerStat::CodeTimer nonclausalTimer(d_smt.d_stats->d_nonclausalSimplificationTime);
-
- Trace("simplify") << "SmtEnginePrivate::nonClausalSimplify()" << endl;
- for (unsigned i = 0; i < d_assertions.size(); ++ i) {
- Trace("simplify") << "Assertion #" << i << " : " << d_assertions[i] << std::endl;
- }
-
- if(d_propagatorNeedsFinish) {
- d_propagator.finish();
- d_propagatorNeedsFinish = false;
- }
- d_propagator.initialize();
-
- // Assert all the assertions to the propagator
- Trace("simplify") << "SmtEnginePrivate::nonClausalSimplify(): "
- << "asserting to propagator" << endl;
- for (unsigned i = 0; i < d_assertions.size(); ++ i) {
- Assert(Rewriter::rewrite(d_assertions[i]) == d_assertions[i]);
- // Don't reprocess substitutions
- if (d_substitutionsIndex > 0 && i == d_substitutionsIndex) {
- continue;
- }
- Trace("simplify") << "SmtEnginePrivate::nonClausalSimplify(): asserting " << d_assertions[i] << endl;
- Debug("cores") << "d_propagator assertTrue: " << d_assertions[i] << std::endl;
- d_propagator.assertTrue(d_assertions[i]);
- }
-
- Trace("simplify") << "SmtEnginePrivate::nonClausalSimplify(): "
- << "propagating" << endl;
- if (d_propagator.propagate()) {
- // If in conflict, just return false
- Trace("simplify") << "SmtEnginePrivate::nonClausalSimplify(): "
- << "conflict in non-clausal propagation" << endl;
- Node falseNode = NodeManager::currentNM()->mkConst<bool>(false);
- Assert(!options::unsatCores() && !options::fewerPreprocessingHoles());
- d_assertions.clear();
- addFormula(falseNode, false, false);
- d_propagatorNeedsFinish = true;
- return false;
- }
-
-
- Trace("simplify") << "Iterate through " << d_nonClausalLearnedLiterals.size() << " learned literals." << std::endl;
- // No conflict, go through the literals and solve them
- SubstitutionMap constantPropagations(d_smt.d_context);
- SubstitutionMap newSubstitutions(d_smt.d_context);
- SubstitutionMap::iterator pos;
- unsigned j = 0;
- for(unsigned i = 0, i_end = d_nonClausalLearnedLiterals.size(); i < i_end; ++ i) {
- // Simplify the literal we learned wrt previous substitutions
- Node learnedLiteral = d_nonClausalLearnedLiterals[i];
- Assert(Rewriter::rewrite(learnedLiteral) == learnedLiteral);
- Assert(d_topLevelSubstitutions.apply(learnedLiteral) == learnedLiteral);
- Trace("simplify") << "Process learnedLiteral : " << learnedLiteral << std::endl;
- Node learnedLiteralNew = newSubstitutions.apply(learnedLiteral);
- if (learnedLiteral != learnedLiteralNew) {
- learnedLiteral = Rewriter::rewrite(learnedLiteralNew);
- }
- Trace("simplify") << "Process learnedLiteral, after newSubs : " << learnedLiteral << std::endl;
- for (;;) {
- learnedLiteralNew = constantPropagations.apply(learnedLiteral);
- if (learnedLiteralNew == learnedLiteral) {
- break;
- }
- ++d_smt.d_stats->d_numConstantProps;
- learnedLiteral = Rewriter::rewrite(learnedLiteralNew);
- }
- Trace("simplify") << "Process learnedLiteral, after constProp : " << learnedLiteral << std::endl;
- // It might just simplify to a constant
- if (learnedLiteral.isConst()) {
- if (learnedLiteral.getConst<bool>()) {
- // If the learned literal simplifies to true, it's redundant
- continue;
- } else {
- // If the learned literal simplifies to false, we're in conflict
- Trace("simplify") << "SmtEnginePrivate::nonClausalSimplify(): "
- << "conflict with "
- << d_nonClausalLearnedLiterals[i] << endl;
- Assert(!options::unsatCores());
- d_assertions.clear();
- addFormula(NodeManager::currentNM()->mkConst<bool>(false), false, false);
- d_propagatorNeedsFinish = true;
- return false;
- }
- }
-
- // Solve it with the corresponding theory, possibly adding new
- // substitutions to newSubstitutions
- Trace("simplify") << "SmtEnginePrivate::nonClausalSimplify(): "
- << "solving " << learnedLiteral << endl;
-
- Theory::PPAssertStatus solveStatus =
- d_smt.d_theoryEngine->solve(learnedLiteral, newSubstitutions);
-
- switch (solveStatus) {
- case Theory::PP_ASSERT_STATUS_SOLVED: {
- // The literal should rewrite to true
- Trace("simplify") << "SmtEnginePrivate::nonClausalSimplify(): "
- << "solved " << learnedLiteral << endl;
- Assert(Rewriter::rewrite(newSubstitutions.apply(learnedLiteral)).isConst());
- // vector<pair<Node, Node> > equations;
- // constantPropagations.simplifyLHS(d_topLevelSubstitutions, equations, true);
- // if (equations.empty()) {
- // break;
- // }
- // Assert(equations[0].first.isConst() && equations[0].second.isConst() && equations[0].first != equations[0].second);
- // else fall through
- break;
- }
- case Theory::PP_ASSERT_STATUS_CONFLICT:
- // If in conflict, we return false
- Trace("simplify") << "SmtEnginePrivate::nonClausalSimplify(): "
- << "conflict while solving "
- << learnedLiteral << endl;
- Assert(!options::unsatCores());
- d_assertions.clear();
- addFormula(NodeManager::currentNM()->mkConst<bool>(false), false, false);
- d_propagatorNeedsFinish = true;
- return false;
- default:
- if (d_doConstantProp && learnedLiteral.getKind() == kind::EQUAL && (learnedLiteral[0].isConst() || learnedLiteral[1].isConst())) {
- // constant propagation
- TNode t;
- TNode c;
- if (learnedLiteral[0].isConst()) {
- t = learnedLiteral[1];
- c = learnedLiteral[0];
- }
- else {
- t = learnedLiteral[0];
- c = learnedLiteral[1];
- }
- Assert(!t.isConst());
- Assert(constantPropagations.apply(t) == t);
- Assert(d_topLevelSubstitutions.apply(t) == t);
- Assert(newSubstitutions.apply(t) == t);
- constantPropagations.addSubstitution(t, c);
- // vector<pair<Node,Node> > equations;
- // constantPropagations.simplifyLHS(t, c, equations, true);
- // if (!equations.empty()) {
- // Assert(equations[0].first.isConst() && equations[0].second.isConst() && equations[0].first != equations[0].second);
- // d_assertions.clear();
- // addFormula(NodeManager::currentNM()->mkConst<bool>(false), false, false);
- // return;
- // }
- // d_topLevelSubstitutions.simplifyRHS(constantPropagations);
- }
- else {
- // Keep the literal
- d_nonClausalLearnedLiterals[j++] = d_nonClausalLearnedLiterals[i];
- }
- break;
- }
- }
-
-#ifdef CVC4_ASSERTIONS
- // NOTE: When debugging this code, consider moving this check inside of the
- // loop over d_nonClausalLearnedLiterals. This check has been moved outside
- // because it is costly for certain inputs (see bug 508).
- //
- // Check data structure invariants:
- // 1. for each lhs of d_topLevelSubstitutions, does not appear anywhere in rhs of d_topLevelSubstitutions or anywhere in constantPropagations
- // 2. each lhs of constantPropagations rewrites to itself
- // 3. if l -> r is a constant propagation and l is a subterm of l' with l' -> r' another constant propagation, then l'[l/r] -> r' should be a
- // constant propagation too
- // 4. each lhs of constantPropagations is different from each rhs
- for (pos = newSubstitutions.begin(); pos != newSubstitutions.end(); ++pos) {
- Assert((*pos).first.isVar());
- Assert(d_topLevelSubstitutions.apply((*pos).first) == (*pos).first);
- Assert(d_topLevelSubstitutions.apply((*pos).second) == (*pos).second);
- Assert(newSubstitutions.apply(newSubstitutions.apply((*pos).second)) == newSubstitutions.apply((*pos).second));
- }
- for (pos = constantPropagations.begin(); pos != constantPropagations.end(); ++pos) {
- Assert((*pos).second.isConst());
- Assert(Rewriter::rewrite((*pos).first) == (*pos).first);
- // Node newLeft = d_topLevelSubstitutions.apply((*pos).first);
- // if (newLeft != (*pos).first) {
- // newLeft = Rewriter::rewrite(newLeft);
- // Assert(newLeft == (*pos).second ||
- // (constantPropagations.hasSubstitution(newLeft) && constantPropagations.apply(newLeft) == (*pos).second));
- // }
- // newLeft = constantPropagations.apply((*pos).first);
- // if (newLeft != (*pos).first) {
- // newLeft = Rewriter::rewrite(newLeft);
- // Assert(newLeft == (*pos).second ||
- // (constantPropagations.hasSubstitution(newLeft) && constantPropagations.apply(newLeft) == (*pos).second));
- // }
- Assert(constantPropagations.apply((*pos).second) == (*pos).second);
- }
-#endif /* CVC4_ASSERTIONS */
-
- // Resize the learnt
- Trace("simplify") << "Resize non-clausal learned literals to " << j << std::endl;
- d_nonClausalLearnedLiterals.resize(j);
-
- unordered_set<TNode, TNodeHashFunction> s;
- Trace("debugging") << "NonClausal simplify pre-preprocess\n";
- for (unsigned i = 0; i < d_assertions.size(); ++ i) {
- Node assertion = d_assertions[i];
- Node assertionNew = newSubstitutions.apply(assertion);
- Trace("debugging") << "assertion = " << assertion << endl;
- Trace("debugging") << "assertionNew = " << assertionNew << endl;
- if (assertion != assertionNew) {
- assertion = Rewriter::rewrite(assertionNew);
- Trace("debugging") << "rewrite(assertion) = " << assertion << endl;
- }
- Assert(Rewriter::rewrite(assertion) == assertion);
- for (;;) {
- assertionNew = constantPropagations.apply(assertion);
- if (assertionNew == assertion) {
- break;
- }
- ++d_smt.d_stats->d_numConstantProps;
- Trace("debugging") << "assertionNew = " << assertionNew << endl;
- assertion = Rewriter::rewrite(assertionNew);
- Trace("debugging") << "assertionNew = " << assertionNew << endl;
- }
- Trace("debugging") << "\n";
- s.insert(assertion);
- d_assertions.replace(i, assertion);
- Trace("simplify") << "SmtEnginePrivate::nonClausalSimplify(): "
- << "non-clausal preprocessed: "
- << assertion << endl;
- }
-
- // If in incremental mode, add substitutions to the list of assertions
- if (d_substitutionsIndex > 0) {
- NodeBuilder<> substitutionsBuilder(kind::AND);
- substitutionsBuilder << d_assertions[d_substitutionsIndex];
- pos = newSubstitutions.begin();
- for (; pos != newSubstitutions.end(); ++pos) {
- // Add back this substitution as an assertion
- TNode lhs = (*pos).first, rhs = newSubstitutions.apply((*pos).second);
- Node n = NodeManager::currentNM()->mkNode(kind::EQUAL, lhs, rhs);
- substitutionsBuilder << n;
- Trace("simplify") << "SmtEnginePrivate::nonClausalSimplify(): will notify SAT layer of substitution: " << n << endl;
- }
- if (substitutionsBuilder.getNumChildren() > 1) {
- d_assertions.replace(d_substitutionsIndex,
- Rewriter::rewrite(Node(substitutionsBuilder)));
- }
- } else {
- // If not in incremental mode, must add substitutions to model
- TheoryModel* m = d_smt.d_theoryEngine->getModel();
- if(m != NULL) {
- for(pos = newSubstitutions.begin(); pos != newSubstitutions.end(); ++pos) {
- Node n = (*pos).first;
- Node v = newSubstitutions.apply((*pos).second);
- Trace("model") << "Add substitution : " << n << " " << v << endl;
- m->addSubstitution( n, v );
- }
- }
- }
-
- NodeBuilder<> learnedBuilder(kind::AND);
- Assert(d_assertions.getRealAssertionsEnd() <= d_assertions.size());
- learnedBuilder << d_assertions[d_assertions.getRealAssertionsEnd() - 1];
-
- for (unsigned i = 0; i < d_nonClausalLearnedLiterals.size(); ++ i) {
- Node learned = d_nonClausalLearnedLiterals[i];
- Assert(d_topLevelSubstitutions.apply(learned) == learned);
- Node learnedNew = newSubstitutions.apply(learned);
- if (learned != learnedNew) {
- learned = Rewriter::rewrite(learnedNew);
- }
- Assert(Rewriter::rewrite(learned) == learned);
- for (;;) {
- learnedNew = constantPropagations.apply(learned);
- if (learnedNew == learned) {
- break;
- }
- ++d_smt.d_stats->d_numConstantProps;
- learned = Rewriter::rewrite(learnedNew);
- }
- if (s.find(learned) != s.end()) {
- continue;
- }
- s.insert(learned);
- learnedBuilder << learned;
- Trace("simplify") << "SmtEnginePrivate::nonClausalSimplify(): "
- << "non-clausal learned : "
- << learned << endl;
- }
- d_nonClausalLearnedLiterals.clear();
-
- for (pos = constantPropagations.begin(); pos != constantPropagations.end(); ++pos) {
- Node cProp = (*pos).first.eqNode((*pos).second);
- Assert(d_topLevelSubstitutions.apply(cProp) == cProp);
- Node cPropNew = newSubstitutions.apply(cProp);
- if (cProp != cPropNew) {
- cProp = Rewriter::rewrite(cPropNew);
- Assert(Rewriter::rewrite(cProp) == cProp);
- }
- if (s.find(cProp) != s.end()) {
- continue;
- }
- s.insert(cProp);
- learnedBuilder << cProp;
- Trace("simplify") << "SmtEnginePrivate::nonClausalSimplify(): "
- << "non-clausal constant propagation : "
- << cProp << endl;
- }
-
- // Add new substitutions to topLevelSubstitutions
- // Note that we don't have to keep rhs's in full solved form
- // because SubstitutionMap::apply does a fixed-point iteration when substituting
- d_topLevelSubstitutions.addSubstitutions(newSubstitutions);
-
- if(learnedBuilder.getNumChildren() > 1) {
- d_assertions.replace(d_assertions.getRealAssertionsEnd() - 1,
- Rewriter::rewrite(Node(learnedBuilder)));
- }
-
- d_propagatorNeedsFinish = true;
- return true;
-}
-
-bool SmtEnginePrivate::simpITE() {
- TimerStat::CodeTimer simpITETimer(d_smt.d_stats->d_simpITETime);
-
- spendResource(options::preprocessStep());
-
- Trace("simplify") << "SmtEnginePrivate::simpITE()" << endl;
-
- unsigned numAssertionOnEntry = d_assertions.size();
- for (unsigned i = 0; i < d_assertions.size(); ++i) {
- spendResource(options::preprocessStep());
- Node result = d_smt.d_theoryEngine->ppSimpITE(d_assertions[i]);
- d_assertions.replace(i, result);
- if(result.isConst() && !result.getConst<bool>()){
- return false;
- }
- }
- bool result = d_smt.d_theoryEngine->donePPSimpITE(d_assertions.ref());
- if(numAssertionOnEntry < d_assertions.size()){
- compressBeforeRealAssertions(numAssertionOnEntry);
- }
- return result;
-}
-
-void SmtEnginePrivate::compressBeforeRealAssertions(size_t before){
- size_t curr = d_assertions.size();
- if(before >= curr ||
- d_assertions.getRealAssertionsEnd() <= 0 ||
- d_assertions.getRealAssertionsEnd() >= curr){
- return;
- }
-
- // assertions
- // original: [0 ... d_realAssertionsEnd)
- // can be modified
- // ites skolems [d_realAssertionsEnd, before)
- // cannot be moved
- // added [before, curr)
- // can be modified
- Assert(0 < d_assertions.getRealAssertionsEnd());
- Assert(d_assertions.getRealAssertionsEnd() <= before);
- Assert(before < curr);
-
- std::vector<Node> intoConjunction;
- for(size_t i = before; i<curr; ++i){
- intoConjunction.push_back(d_assertions[i]);
- }
- d_assertions.resize(before);
- size_t lastBeforeItes = d_assertions.getRealAssertionsEnd() - 1;
- intoConjunction.push_back(d_assertions[lastBeforeItes]);
- Node newLast = util::NaryBuilder::mkAssoc(kind::AND, intoConjunction);
- d_assertions.replace(lastBeforeItes, newLast);
- Assert(d_assertions.size() == before);
-}
-
-void SmtEnginePrivate::traceBackToAssertions(const std::vector<Node>& nodes, std::vector<TNode>& assertions) {
- const booleans::CircuitPropagator::BackEdgesMap& backEdges = d_propagator.getBackEdges();
- for(vector<Node>::const_iterator i = nodes.begin(); i != nodes.end(); ++i) {
- booleans::CircuitPropagator::BackEdgesMap::const_iterator j = backEdges.find(*i);
- // term must appear in map, otherwise how did we get here?!
- Assert(j != backEdges.end());
- // if term maps to empty, that means it's a top-level assertion
- if(!(*j).second.empty()) {
- traceBackToAssertions((*j).second, assertions);
- } else {
- assertions.push_back(*i);
- }
- }
-}
-
-size_t SmtEnginePrivate::removeFromConjunction(Node& n, const std::unordered_set<unsigned long>& toRemove) {
- Assert(n.getKind() == kind::AND);
- size_t removals = 0;
- for(Node::iterator j = n.begin(); j != n.end(); ++j) {
- size_t subremovals = 0;
- Node sub = *j;
- if(toRemove.find(sub.getId()) != toRemove.end() ||
- (sub.getKind() == kind::AND && (subremovals = removeFromConjunction(sub, toRemove)) > 0)) {
- NodeBuilder<> b(kind::AND);
- b.append(n.begin(), j);
- if(subremovals > 0) {
- removals += subremovals;
- b << sub;
- } else {
- ++removals;
- }
- for(++j; j != n.end(); ++j) {
- if(toRemove.find((*j).getId()) != toRemove.end()) {
- ++removals;
- } else if((*j).getKind() == kind::AND) {
- sub = *j;
- if((subremovals = removeFromConjunction(sub, toRemove)) > 0) {
- removals += subremovals;
- b << sub;
- } else {
- b << *j;
- }
- } else {
- b << *j;
- }
- }
- if(b.getNumChildren() == 0) {
- n = d_true;
- b.clear();
- } else if(b.getNumChildren() == 1) {
- n = b[0];
- b.clear();
- } else {
- n = b;
- }
- n = Rewriter::rewrite(n);
- return removals;
- }
- }
-
- Assert(removals == 0);
- return 0;
-}
-
-void SmtEnginePrivate::doMiplibTrick() {
- Assert(d_assertions.getRealAssertionsEnd() == d_assertions.size());
- Assert(!options::incrementalSolving());
-
- const booleans::CircuitPropagator::BackEdgesMap& backEdges = d_propagator.getBackEdges();
- unordered_set<unsigned long> removeAssertions;
-
- NodeManager* nm = NodeManager::currentNM();
- Node zero = nm->mkConst(Rational(0)), one = nm->mkConst(Rational(1));
-
- unordered_map<TNode, Node, TNodeHashFunction> intVars;
- for(vector<Node>::const_iterator i = d_boolVars.begin(); i != d_boolVars.end(); ++i) {
- if(d_propagator.isAssigned(*i)) {
- Debug("miplib") << "ineligible: " << *i << " because assigned " << d_propagator.getAssignment(*i) << endl;
- continue;
- }
-
- vector<TNode> assertions;
- booleans::CircuitPropagator::BackEdgesMap::const_iterator j = backEdges.find(*i);
- // if not in back edges map, the bool var is unconstrained, showing up in no assertions.
- // if maps to an empty vector, that means the bool var was asserted itself.
- if(j != backEdges.end()) {
- if(!(*j).second.empty()) {
- traceBackToAssertions((*j).second, assertions);
- } else {
- assertions.push_back(*i);
- }
- }
- Debug("miplib") << "for " << *i << endl;
- bool eligible = true;
- map<pair<Node, Node>, uint64_t> marks;
- map<pair<Node, Node>, vector<Rational> > coef;
- map<pair<Node, Node>, vector<Rational> > checks;
- map<pair<Node, Node>, vector<TNode> > asserts;
- for(vector<TNode>::const_iterator j = assertions.begin(); j != assertions.end(); ++j) {
- Debug("miplib") << " found: " << *j << endl;
- if((*j).getKind() != kind::IMPLIES) {
- eligible = false;
- Debug("miplib") << " -- INELIGIBLE -- (not =>)" << endl;
- break;
- }
- Node conj = BooleanSimplification::simplify((*j)[0]);
- if(conj.getKind() == kind::AND && conj.getNumChildren() > 6) {
- eligible = false;
- Debug("miplib") << " -- INELIGIBLE -- (N-ary /\\ too big)" << endl;
- break;
- }
- if(conj.getKind() != kind::AND && !conj.isVar() && !(conj.getKind() == kind::NOT && conj[0].isVar())) {
- eligible = false;
- Debug("miplib") << " -- INELIGIBLE -- (not /\\ or literal)" << endl;
- break;
- }
- if((*j)[1].getKind() != kind::EQUAL ||
- !( ( (*j)[1][0].isVar() &&
- (*j)[1][1].getKind() == kind::CONST_RATIONAL ) ||
- ( (*j)[1][0].getKind() == kind::CONST_RATIONAL &&
- (*j)[1][1].isVar() ) )) {
- eligible = false;
- Debug("miplib") << " -- INELIGIBLE -- (=> (and X X) X)" << endl;
- break;
- }
- if(conj.getKind() == kind::AND) {
- vector<Node> posv;
- bool found_x = false;
- map<TNode, bool> neg;
- for(Node::iterator ii = conj.begin(); ii != conj.end(); ++ii) {
- if((*ii).isVar()) {
- posv.push_back(*ii);
- neg[*ii] = false;
- found_x = found_x || *i == *ii;
- } else if((*ii).getKind() == kind::NOT && (*ii)[0].isVar()) {
- posv.push_back((*ii)[0]);
- neg[(*ii)[0]] = true;
- found_x = found_x || *i == (*ii)[0];
- } else {
- eligible = false;
- Debug("miplib") << " -- INELIGIBLE -- (non-var: " << *ii << ")" << endl;
- break;
- }
- if(d_propagator.isAssigned(posv.back())) {
- eligible = false;
- Debug("miplib") << " -- INELIGIBLE -- (" << posv.back() << " asserted)" << endl;
- break;
- }
- }
- if(!eligible) {
- break;
- }
- if(!found_x) {
- eligible = false;
- Debug("miplib") << " --INELIGIBLE -- (couldn't find " << *i << " in conjunction)" << endl;
- break;
- }
- sort(posv.begin(), posv.end());
- const Node pos = NodeManager::currentNM()->mkNode(kind::AND, posv);
- const TNode var = ((*j)[1][0].getKind() == kind::CONST_RATIONAL) ? (*j)[1][1] : (*j)[1][0];
- const pair<Node, Node> pos_var(pos, var);
- const Rational& constant = ((*j)[1][0].getKind() == kind::CONST_RATIONAL) ? (*j)[1][0].getConst<Rational>() : (*j)[1][1].getConst<Rational>();
- uint64_t mark = 0;
- unsigned countneg = 0, thepos = 0;
- for(unsigned ii = 0; ii < pos.getNumChildren(); ++ii) {
- if(neg[pos[ii]]) {
- ++countneg;
- } else {
- thepos = ii;
- mark |= (0x1 << ii);
- }
- }
- if((marks[pos_var] & (1lu << mark)) != 0) {
- eligible = false;
- Debug("miplib") << " -- INELIGIBLE -- (remarked)" << endl;
- break;
- }
- Debug("miplib") << "mark is " << mark << " -- " << (1lu << mark) << endl;
- marks[pos_var] |= (1lu << mark);
- Debug("miplib") << "marks[" << pos << "," << var << "] now " << marks[pos_var] << endl;
- if(countneg == pos.getNumChildren()) {
- if(constant != 0) {
- eligible = false;
- Debug("miplib") << " -- INELIGIBLE -- (nonzero constant)" << endl;
- break;
- }
- } else if(countneg == pos.getNumChildren() - 1) {
- Assert(coef[pos_var].size() <= 6 && thepos < 6);
- if(coef[pos_var].size() <= thepos) {
- coef[pos_var].resize(thepos + 1);
- }
- coef[pos_var][thepos] = constant;
- } else {
- if(checks[pos_var].size() <= mark) {
- checks[pos_var].resize(mark + 1);
- }
- checks[pos_var][mark] = constant;
- }
- asserts[pos_var].push_back(*j);
- } else {
- TNode x = conj;
- if(x != *i && x != (*i).notNode()) {
- eligible = false;
- Debug("miplib") << " -- INELIGIBLE -- (x not present where I expect it)" << endl;
- break;
- }
- const bool xneg = (x.getKind() == kind::NOT);
- x = xneg ? x[0] : x;
- Debug("miplib") << " x:" << x << " " << xneg << endl;
- const TNode var = ((*j)[1][0].getKind() == kind::CONST_RATIONAL) ? (*j)[1][1] : (*j)[1][0];
- const pair<Node, Node> x_var(x, var);
- const Rational& constant = ((*j)[1][0].getKind() == kind::CONST_RATIONAL) ? (*j)[1][0].getConst<Rational>() : (*j)[1][1].getConst<Rational>();
- unsigned mark = (xneg ? 0 : 1);
- if((marks[x_var] & (1u << mark)) != 0) {
- eligible = false;
- Debug("miplib") << " -- INELIGIBLE -- (remarked)" << endl;
- break;
- }
- marks[x_var] |= (1u << mark);
- if(xneg) {
- if(constant != 0) {
- eligible = false;
- Debug("miplib") << " -- INELIGIBLE -- (nonzero constant)" << endl;
- break;
- }
- } else {
- Assert(coef[x_var].size() <= 6);
- coef[x_var].resize(6);
- coef[x_var][0] = constant;
- }
- asserts[x_var].push_back(*j);
- }
- }
- if(eligible) {
- for(map<pair<Node, Node>, uint64_t>::const_iterator j = marks.begin(); j != marks.end(); ++j) {
- const TNode pos = (*j).first.first;
- const TNode var = (*j).first.second;
- const pair<Node, Node>& pos_var = (*j).first;
- const uint64_t mark = (*j).second;
- const unsigned numVars = pos.getKind() == kind::AND ? pos.getNumChildren() : 1;
- uint64_t expected = (uint64_t(1) << (1 << numVars)) - 1;
- expected = (expected == 0) ? -1 : expected; // fix for overflow
- Debug("miplib") << "[" << pos << "] => " << hex << mark << " expect " << expected << dec << endl;
- Assert(pos.getKind() == kind::AND || pos.isVar());
- if(mark != expected) {
- Debug("miplib") << " -- INELIGIBLE " << pos << " -- (insufficiently marked, got " << mark << " for " << numVars << " vars, expected " << expected << endl;
- } else {
- if(mark != 3) { // exclude single-var case; nothing to check there
- uint64_t sz = (uint64_t(1) << checks[pos_var].size()) - 1;
- sz = (sz == 0) ? -1 : sz; // fix for overflow
- Assert(sz == mark, "expected size %u == mark %u", sz, mark);
- for(size_t k = 0; k < checks[pos_var].size(); ++k) {
- if((k & (k - 1)) != 0) {
- Rational sum = 0;
- Debug("miplib") << k << " => " << checks[pos_var][k] << endl;
- for(size_t v = 1, kk = k; kk != 0; ++v, kk >>= 1) {
- if((kk & 0x1) == 1) {
- Assert(pos.getKind() == kind::AND);
- Debug("miplib") << "var " << v << " : " << pos[v - 1] << " coef:" << coef[pos_var][v - 1] << endl;
- sum += coef[pos_var][v - 1];
- }
- }
- Debug("miplib") << "checkSum is " << sum << " input says " << checks[pos_var][k] << endl;
- if(sum != checks[pos_var][k]) {
- eligible = false;
- Debug("miplib") << " -- INELIGIBLE " << pos << " -- (nonlinear combination)" << endl;
- break;
- }
- } else {
- Assert(checks[pos_var][k] == 0, "checks[(%s,%s)][%u] should be 0, but it's %s", pos.toString().c_str(), var.toString().c_str(), k, checks[pos_var][k].toString().c_str()); // we never set for single-positive-var
- }
- }
- }
- if(!eligible) {
- eligible = true; // next is still eligible
- continue;
- }
-
- Debug("miplib") << " -- ELIGIBLE " << *i << " , " << pos << " --" << endl;
- vector<Node> newVars;
- expr::NodeSelfIterator ii, iiend;
- if(pos.getKind() == kind::AND) {
- ii = pos.begin();
- iiend = pos.end();
- } else {
- ii = expr::NodeSelfIterator::self(pos);
- iiend = expr::NodeSelfIterator::selfEnd(pos);
- }
- for(; ii != iiend; ++ii) {
- Node& varRef = intVars[*ii];
- if(varRef.isNull()) {
- stringstream ss;
- ss << "mipvar_" << *ii;
- Node newVar = nm->mkSkolem(ss.str(), nm->integerType(), "a variable introduced due to scrubbing a miplib encoding", NodeManager::SKOLEM_EXACT_NAME);
- Node geq = Rewriter::rewrite(nm->mkNode(kind::GEQ, newVar, zero));
- Node leq = Rewriter::rewrite(nm->mkNode(kind::LEQ, newVar, one));
- addFormula(Rewriter::rewrite(geq.andNode(leq)), false, false);
- SubstitutionMap nullMap(&d_fakeContext);
- Theory::PPAssertStatus status CVC4_UNUSED; // just for assertions
- status = d_smt.d_theoryEngine->solve(geq, nullMap);
- Assert(status == Theory::PP_ASSERT_STATUS_UNSOLVED,
- "unexpected solution from arith's ppAssert()");
- Assert(nullMap.empty(),
- "unexpected substitution from arith's ppAssert()");
- status = d_smt.d_theoryEngine->solve(leq, nullMap);
- Assert(status == Theory::PP_ASSERT_STATUS_UNSOLVED,
- "unexpected solution from arith's ppAssert()");
- Assert(nullMap.empty(),
- "unexpected substitution from arith's ppAssert()");
- d_smt.d_theoryEngine->getModel()->addSubstitution(*ii, newVar.eqNode(one));
- newVars.push_back(newVar);
- varRef = newVar;
- } else {
- newVars.push_back(varRef);
- }
- if(!d_smt.d_logic.areIntegersUsed()) {
- d_smt.d_logic = d_smt.d_logic.getUnlockedCopy();
- d_smt.d_logic.enableIntegers();
- d_smt.d_logic.lock();
- }
- }
- Node sum;
- if(pos.getKind() == kind::AND) {
- NodeBuilder<> sumb(kind::PLUS);
- for(size_t ii = 0; ii < pos.getNumChildren(); ++ii) {
- sumb << nm->mkNode(kind::MULT, nm->mkConst(coef[pos_var][ii]), newVars[ii]);
- }
- sum = sumb;
- } else {
- sum = nm->mkNode(kind::MULT, nm->mkConst(coef[pos_var][0]), newVars[0]);
- }
- Debug("miplib") << "vars[] " << var << endl
- << " eq " << Rewriter::rewrite(sum) << endl;
- Node newAssertion = var.eqNode(Rewriter::rewrite(sum));
- if(d_topLevelSubstitutions.hasSubstitution(newAssertion[0])) {
- //Warning() << "RE-SUBSTITUTION " << newAssertion[0] << endl;
- //Warning() << "REPLACE " << newAssertion[1] << endl;
- //Warning() << "ORIG " << d_topLevelSubstitutions.getSubstitution(newAssertion[0]) << endl;
- Assert(d_topLevelSubstitutions.getSubstitution(newAssertion[0]) == newAssertion[1]);
- } else if(pos.getNumChildren() <= options::arithMLTrickSubstitutions()) {
- d_topLevelSubstitutions.addSubstitution(newAssertion[0], newAssertion[1]);
- Debug("miplib") << "addSubs: " << newAssertion[0] << " to " << newAssertion[1] << endl;
- } else {
- Debug("miplib") << "skipSubs: " << newAssertion[0] << " to " << newAssertion[1] << " (threshold is " << options::arithMLTrickSubstitutions() << ")" << endl;
- }
- newAssertion = Rewriter::rewrite(newAssertion);
- Debug("miplib") << " " << newAssertion << endl;
- addFormula(newAssertion, false, false);
- Debug("miplib") << " assertions to remove: " << endl;
- for(vector<TNode>::const_iterator k = asserts[pos_var].begin(), k_end = asserts[pos_var].end(); k != k_end; ++k) {
- Debug("miplib") << " " << *k << endl;
- removeAssertions.insert((*k).getId());
- }
- }
- }
- }
- }
- if(!removeAssertions.empty()) {
- Debug("miplib") << "SmtEnginePrivate::simplify(): scrubbing miplib encoding..." << endl;
- for(size_t i = 0; i < d_assertions.getRealAssertionsEnd(); ++i) {
- if(removeAssertions.find(d_assertions[i].getId()) != removeAssertions.end()) {
- Debug("miplib") << "SmtEnginePrivate::simplify(): - removing " << d_assertions[i] << endl;
- d_assertions[i] = d_true;
- ++d_smt.d_stats->d_numMiplibAssertionsRemoved;
- } else if(d_assertions[i].getKind() == kind::AND) {
- size_t removals = removeFromConjunction(d_assertions[i], removeAssertions);
- if(removals > 0) {
- Debug("miplib") << "SmtEnginePrivate::simplify(): - reduced " << d_assertions[i] << endl;
- Debug("miplib") << "SmtEnginePrivate::simplify(): - by " << removals << " conjuncts" << endl;
- d_smt.d_stats->d_numMiplibAssertionsRemoved += removals;
- }
- }
- Debug("miplib") << "had: " << d_assertions[i] << endl;
- d_assertions[i] = Rewriter::rewrite(d_topLevelSubstitutions.apply(d_assertions[i]));
- Debug("miplib") << "now: " << d_assertions[i] << endl;
- }
- } else {
- Debug("miplib") << "SmtEnginePrivate::simplify(): miplib pass found nothing." << endl;
- }
- d_assertions.setRealAssertionsEnd(d_assertions.size());
-}
-
-
// returns false if simplification led to "false"
bool SmtEnginePrivate::simplifyAssertions()
throw(TypeCheckingException, LogicException, UnsafeInterruptException) {
@@ -3254,8 +2300,7 @@ bool SmtEnginePrivate::simplifyAssertions()
// restriction only disables miplib processing during
// re-simplification, which we don't expect to be useful anyway)
d_assertions.getRealAssertionsEnd() == d_assertions.size() ) {
-/* preproc::MiplibTrickPass pass;
- pass.apply(&d_assertions);*/
+
PreprocessingPassRegistry::getInstance()->getPass("miplibTrick")->apply(&d_assertions);
} else {
Trace("simplify") << "SmtEnginePrivate::simplify(): "
@@ -3274,10 +2319,8 @@ bool SmtEnginePrivate::simplifyAssertions()
// Theory preprocessing
if (d_smt.d_earlyTheoryPP) {
-/* preproc::EarlyTheoryPass pass;
- pass.apply(&d_assertions);*/
- PreprocessingPassRegistry::getInstance()->getPass("earlyTheory")->apply(&d_assertions);
+ PreprocessingPassRegistry::getInstance()->getPass("earlyTheory")->apply(&d_assertions);
}
dumpAssertions("post-theorypp", d_assertions);
@@ -3288,9 +2331,7 @@ bool SmtEnginePrivate::simplifyAssertions()
if(options::doITESimp() &&
(d_simplifyAssertionsDepth <= 1 || options::doITESimpOnRepeat())) {
Chat() << "...doing ITE simplification..." << endl;
-/* SimpITEPass pass;
- bool noConflict = pass.apply(&d_assertions).d_noConflict;*/
-
+
bool noConflict = (PreprocessingPassRegistry::getInstance()->getPass("simpITE")->apply(&d_assertions)).d_noConflict;
if(!noConflict){
@@ -3306,9 +2347,8 @@ bool SmtEnginePrivate::simplifyAssertions()
// Unconstrained simplification
if(options::unconstrainedSimp()) {
Chat() << "...doing unconstrained simplification..." << endl;
-/* preproc::UnconstrainedSimpPass pass;
- pass.apply(&d_assertons);*/
- PreprocessingPassRegistry::getInstance()->getPass("unconstrainedSimp")->apply(&d_assertions);
+
+ PreprocessingPassRegistry::getInstance()->getPass("unconstrainedSimp")->apply(&d_assertions);
}
@@ -3321,9 +2361,8 @@ bool SmtEnginePrivate::simplifyAssertions()
Trace("simplify") << "SmtEnginePrivate::simplify(): "
<< " doing repeated simplification" << endl;
-/* preproc::NonClausalSimplificationPass pass;
- bool noConflict = pass.apply(&d_assertions).d_noConflict; */
bool noConflict = (PreprocessingPassRegistry::getInstance()->getPass("nlExtPurify")->apply(&d_assertions)).d_noConflict;
+
if(!noConflict) {
return false;
}
@@ -3405,65 +2444,6 @@ Result SmtEngine::quickCheck() {
return Result(Result::VALIDITY_UNKNOWN, Result::REQUIRES_FULL_CHECK, d_filename);
}
-
-void SmtEnginePrivate::collectSkolems(TNode n, set<TNode>& skolemSet, unordered_map<Node, bool, NodeHashFunction>& cache)
-{
- unordered_map<Node, bool, NodeHashFunction>::iterator it;
- it = cache.find(n);
- if (it != cache.end()) {
- return;
- }
-
- size_t sz = n.getNumChildren();
- if (sz == 0) {
- IteSkolemMap::iterator it = d_assertions.getSkolemMap()->find(n);
- if (it != d_assertions.getSkolemMap()->end()) {
- skolemSet.insert(n);
- }
- cache[n] = true;
- return;
- }
-
- size_t k = 0;
- for (; k < sz; ++k) {
- collectSkolems(n[k], skolemSet, cache);
- }
- cache[n] = true;
-}
-
-bool SmtEnginePrivate::checkForBadSkolems(TNode n, TNode skolem, unordered_map<Node, bool, NodeHashFunction>& cache)
-{
- unordered_map<Node, bool, NodeHashFunction>::iterator it;
- it = cache.find(n);
- if (it != cache.end()) {
- return (*it).second;
- }
-
- size_t sz = n.getNumChildren();
- if (sz == 0) {
- IteSkolemMap::iterator it = d_assertions.getSkolemMap()->find(n);
- bool bad = false;
- if (it != d_assertions.getSkolemMap()->end()) {
- if (!((*it).first < n)) {
- bad = true;
- }
- }
- cache[n] = bad;
- return bad;
- }
-
- size_t k = 0;
- for (; k < sz; ++k) {
- if (checkForBadSkolems(n[k], skolem, cache)) {
- cache[n] = true;
- return true;
- }
- }
-
- cache[n] = false;
- return false;
-}
-
void SmtEnginePrivate::processAssertions() {
if(!d_initialized) {
PreprocessingPassRegistry::getInstance()->init(&d_smt, d_smt.d_theoryEngine, &d_topLevelSubstitutions, &d_pbsProcessor, &d_iteRemover, d_smt.d_decisionEngine, d_smt.d_propEngine, &d_propagatorNeedsFinish, &d_propagator, &d_boolVars, &d_substitutionsIndex, &d_nonClausalLearnedLiterals);
@@ -3505,10 +2485,7 @@ void SmtEnginePrivate::processAssertions() {
Trace("smt-proc") << "SmtEnginePrivate::processAssertions() : pre-definition-expansion" << endl;
dumpAssertions("pre-definition-expansion", d_assertions);
{
-/* preroc::ExpandingDefinitionsPass pass;
- pass.apply(&d_assertions);*/
- PreprocessingPassRegistry::getInstance()->getPass("expandingDefinitions")->apply(&d_assertions);
-
+ PreprocessingPassRegistry::getInstance()->getPass("expandingDefinitions")->apply(&d_assertions);
}
Trace("smt-proc") << "SmtEnginePrivate::processAssertions() : post-definition-expansion" << endl;
@@ -3525,35 +2502,21 @@ void SmtEnginePrivate::processAssertions() {
Debug("smt") << " d_assertions : " << d_assertions.size() << endl;
if( options::nlExtPurify() ){
- // preproc::NlExtPurifyPass pass;
- // pass.apply(&d_assertions);
-
- // TODO: With the PreprocessingPassRegistry, it should be possible to do
- // something like this:
- PreprocessingPassRegistry::getInstance()->getPass("nlExtPurify")->apply(&d_assertions);
+ PreprocessingPassRegistry::getInstance()->getPass("nlExtPurify")->apply(&d_assertions);
}
if( options::ceGuidedInst() ){
//register sygus conjecture pre-rewrite (motivated by solution reconstruction)
- /* preproc::CEGuidedInstPass pass;
- pass.apply(&d_assertions);*/
- PreprocessingPassRegistry::getInstance()->getPass("ceGuidedInst")->apply(&d_assertions);
-
+ PreprocessingPassRegistry::getInstance()->getPass("ceGuidedInst")->apply(&d_assertions);
}
if (options::solveRealAsInt()) {
- /* preproc::SolveRealAsIntPass pass;
- pass.apply(&d_assertions); */
-
- PreprocessingPassRegistry::getInstance()->getPass("solveRealAsInt")->apply(&d_assertions);
+ PreprocessingPassRegistry::getInstance()->getPass("solveRealAsInt")->apply(&d_assertions);
}
if (options::solveIntAsBV() > 0) {
-/* preproc::SolveIntAsBVPass pass;
- pass.apply(&d_assertions); */
-
- PreprocessingPassRegistry::getInstance()->getPass("solveIntAsbv")->apply(&d_assertions);
+ PreprocessingPassRegistry::getInstance()->getPass("solveIntAsbv")->apply(&d_assertions);
}
if (options::bitblastMode() == theory::bv::BITBLAST_MODE_EAGER &&
@@ -3566,21 +2529,12 @@ void SmtEnginePrivate::processAssertions() {
}
if (options::bitblastMode() == theory::bv::BITBLAST_MODE_EAGER) {
-/* preproc::BitBlastModePass pass;
- pass.apply(&d_assertions);*/
-
PreprocessingPassRegistry::getInstance()->getPass("bitBlastMode")->apply(&d_assertions);
}
if ( options::bvAbstraction() &&
!options::incrementalSolving()) {
-/* preproc::BVAbstractionPass pass;
- pass.apply(&d_assertions);*/
-
PreprocessingPassRegistry::getInstance()->getPass("bvAbstraction")->apply(&d_assertions);
-/* preproc::RewritePass pass1;
- pass1.apply(&d_assertions);*/
-
PreprocessingPassRegistry::getInstance()->getPass("rewrite")->apply(&d_assertions);
}
@@ -3593,14 +2547,8 @@ void SmtEnginePrivate::processAssertions() {
dumpAssertions("pre-unconstrained-simp", d_assertions);
Chat() << "...doing unconstrained simplification..." << std::endl;
-/* preproc::RewritePass pass;
- pass.apply(&d_assertions); */
-
PreprocessingPassRegistry::getInstance()->getPass("rewrite")->apply(&d_assertions);
-/* preproc::UnconstrainedSimpPass pass1;
- pass1.apply(&d_assertions);*/
-
PreprocessingPassRegistry::getInstance()->getPass("unconstrainedSimp")->apply(&d_assertions);
Trace("smt-proc") << "SmtEnginePrivate::processAssertions() : post-unconstrained-simp" << std::endl;
@@ -3616,16 +2564,10 @@ void SmtEnginePrivate::processAssertions() {
if(options::unsatCores()) {
// special rewriting pass for unsat cores, since many of the passes below are skipped
-/* preproc::RewritePass pass;
- pass.apply(&d_assertions);*/
-
PreprocessingPassRegistry::getInstance()->getPass("rewrite")->apply(&d_assertions);
} else {
// Apply the substitutions we already have, and normalize
//unsatCore check removed for redundancy
-/* preproc::NotUnsatCoresPass pass1;
- pass1.apply(&d_assertions); */
-
PreprocessingPassRegistry::getInstance()->getPass("notUnsatCores")->apply(&d_assertions);
}
@@ -3636,54 +2578,31 @@ void SmtEnginePrivate::processAssertions() {
// Lift bit-vectors of size 1 to bool
if(options::bitvectorToBool()) {
-/* preproc::BVToBoolPass pass;
- pass.apply(&d_assertions);*/
-
PreprocessingPassRegistry::getInstance()->getPass("bvToBool")->apply(&d_assertions);
-/* preproc::RewritePass pass1;
- pass1.apply(&d_assertions);*/
-
PreprocessingPassRegistry::getInstance()->getPass("rewrite")->apply(&d_assertions);
}
// Convert non-top-level Booleans to bit-vectors of size 1
if(options::boolToBitvector()) {
-/* preproc::BoolToBVPass pass;
- pass.apply(&d_assertions);*/
-
PreprocessingPassRegistry::getInstance()->getPass("boolTobv")->apply(&d_assertions);
-/* preproc::RewritePass pass1;
- pass1.apply(&d_assertions);*/
-
PreprocessingPassRegistry::getInstance()->getPass("rewrite")->apply(&d_assertions);
}
if(options::sepPreSkolemEmp()) {
-/* preproc::SepPreSkolemEmpPass pass;
- pass.apply(&d_assertions);*/
-
PreprocessingPassRegistry::getInstance()->getPass("sepPreSkolem")->apply(&d_assertions);
}
if( d_smt.d_logic.isQuantified() ){
-/* preproc::QuantifiedPass pass;
- pass.apply(&d_assertions);*/
-
PreprocessingPassRegistry::getInstance()->getPass("quantified")->apply(&d_assertions);
}
if( options::sortInference() || options::ufssFairnessMonotone() ){
//sort inference technique
-/* preproc::InferenceOrFairnessPass pass;
- pass.apply(&d_assertions); */
- PreprocessingPassRegistry::getInstance()->getPass("inferenceOrFairness")->apply(&d_assertions);
+ PreprocessingPassRegistry::getInstance()->getPass("inferenceOrFairness")->apply(&d_assertions);
}
if( options::pbRewrites() ){
-/* preproc::PBRewritePass pass;
- pass.apply(&d_assertions);*/
-
PreprocessingPassRegistry::getInstance()->getPass("pbRewrite")->apply(&d_assertions);
}
@@ -3699,9 +2618,6 @@ void SmtEnginePrivate::processAssertions() {
dumpAssertions("pre-static-learning", d_assertions);
if(options::doStaticLearning()) {
-/* preproc::DoStaticLearningPass pass;
- pass.apply(&d_assertions);*/
-
PreprocessingPassRegistry::getInstance()->getPass("doStaticLearning")->apply(&d_assertions);
}
@@ -3717,11 +2633,8 @@ void SmtEnginePrivate::processAssertions() {
// Remove ITEs, updating d_iteSkolemMap
d_smt.d_stats->d_numAssertionsPre += d_assertions.size();
-/* preproc::RemoveITEPass pass;
- pass.apply(&d_assertions);*/
-
PreprocessingPassRegistry::getInstance()->getPass("removeITE")->apply(&d_assertions);
-//removeITEs();
+
d_smt.d_stats->d_numAssertionsPost += d_assertions.size();
}
Trace("smt-proc") << "SmtEnginePrivate::processAssertions() : post-ite-removal" << endl;
@@ -3734,16 +2647,10 @@ void SmtEnginePrivate::processAssertions() {
noConflict &= simplifyAssertions();
if (noConflict) {
-/* preproc::RepeatSimpPass pass1;
- pass1.apply(&d_assertions);*/
-
PreprocessingPassRegistry::getInstance()->getPass("repeatSimp")->apply(&d_assertions);
// For some reason this is needed for some benchmarks, such as
// http://cvc4.cs.nyu.edu/benchmarks/smtlib2/QF_AUFBV/dwp_formulas/try5_small_difret_functions_dwp_tac.re_node_set_remove_at.il.dwp.smt2
// Figure it out later
-/* preproc::RemoveITEPass pass2;
- pass2.apply(&d_assertions); */
-
PreprocessingPassRegistry::getInstance()->getPass("removeITE")->apply(&d_assertions);
// Assert(iteRewriteAssertionsEnd == d_assertions.size());
}
@@ -3753,9 +2660,6 @@ void SmtEnginePrivate::processAssertions() {
dumpAssertions("pre-rewrite-apply-to-const", d_assertions);
if(options::rewriteApplyToConst()) {
-/* preproc::RewriteApplyToConstPass pass;
- pass.apply(&d_assertions);*/
-
PreprocessingPassRegistry::getInstance()->getPass("rewriteApplyToConst")->apply(&d_assertions);
}
dumpAssertions("post-rewrite-apply-to-const", d_assertions);
@@ -3774,9 +2678,6 @@ void SmtEnginePrivate::processAssertions() {
Trace("smt-proc") << "SmtEnginePrivate::processAssertions() : pre-theory-preprocessing" << endl;
dumpAssertions("pre-theory-preprocessing", d_assertions);
{
-/* preproc::TheoryPreprocessPass pass;
- pass.apply(&d_assertions);*/
-
PreprocessingPassRegistry::getInstance()->getPass("theoryPreprocess")->apply(&d_assertions);
}
Trace("smt-proc") << "SmtEnginePrivate::processAssertions() : post-theory-preprocessing" << endl;
@@ -3785,9 +2686,7 @@ void SmtEnginePrivate::processAssertions() {
// If we are using eager bit-blasting wrap assertions in fake atom so that
// everything gets bit-blasted to internal SAT solver
if (options::bitblastMode() == theory::bv::BITBLAST_MODE_EAGER) {
-/* preproc::BitBlastModeEagerPass pass;
- pass.apply(&d_assertions);*/
- PreprocessingPassRegistry::getInstance()->getPass("bitBlastModeEager")->apply(&d_assertions);
+ PreprocessingPassRegistry::getInstance()->getPass("bitBlastModeEager")->apply(&d_assertions);
}
//notify theory engine new preprocessed assertions
@@ -3796,9 +2695,7 @@ void SmtEnginePrivate::processAssertions() {
// Push the formula to decision engine
if(noConflict) {
Assert(iteRewriteAssertionsEnd == d_assertions.size());
-/* preproc::NoConflictPass pass;
- pass.apply(&d_assertions); */
- PreprocessingPassRegistry::getInstance()->getPass("noConflict")->apply(&d_assertions);
+ PreprocessingPassRegistry::getInstance()->getPass("noConflict")->apply(&d_assertions);
}
// end: INVARIANT to maintain: no reordering of assertions or
@@ -3809,9 +2706,7 @@ void SmtEnginePrivate::processAssertions() {
// Push the formula to SAT
{
-/* preproc::CNFPass pass;
- pass.apply(&d_assertions);*/
- PreprocessingPassRegistry::getInstance()->getPass("cnf")->apply(&d_assertions);
+ PreprocessingPassRegistry::getInstance()->getPass("cnf")->apply(&d_assertions);
}
d_assertionsProcessed = true;
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback