#include "context/cdo.h"
#include "preprocessing/assertion_pipeline.h"
#include "preprocessing/preprocessing_pass_context.h"
-#include "theory/rewriter.h"
+#include "smt/env.h"
#include "theory/substitutions.h"
namespace cvc5 {
<< std::endl;
d_preprocContext->spendResource(Resource::PreprocessStep);
assertionsToPreprocess->replaceTrusted(
- i, tlsm.applyTrusted((*assertionsToPreprocess)[i]));
+ i,
+ tlsm.applyTrusted((*assertionsToPreprocess)[i], d_env.getRewriter()));
Trace("apply-substs") << " got " << (*assertionsToPreprocess)[i]
<< std::endl;
}
<< " learned literals." << std::endl;
// No conflict, go through the literals and solve them
context::Context* u = userContext();
+ Rewriter* rw = d_env.getRewriter();
TrustSubstitutionMap& ttls = d_preprocContext->getTopLevelSubstitutions();
CVC5_UNUSED SubstitutionMap& top_level_substs = ttls.get();
// constant propagations
c = learnedLiteral[1];
}
Assert(!t.isConst());
- Assert(cps.apply(t, true) == t);
+ Assert(rewrite(cps.apply(t)) == t);
Assert(top_level_substs.apply(t) == t);
Assert(nss.apply(t) == t);
// also add to learned literal
for (size_t i = 0, size = assertionsToPreprocess->size(); i < size; ++i)
{
Node assertion = (*assertionsToPreprocess)[i];
- TrustNode assertionNew = newSubstitutions->applyTrusted(assertion);
+ TrustNode assertionNew = newSubstitutions->applyTrusted(assertion, rw);
Trace("non-clausal-simplify") << "assertion = " << assertion << std::endl;
if (!assertionNew.isNull())
{
}
for (;;)
{
- assertionNew = constantPropagations->applyTrusted(assertion);
+ assertionNew = constantPropagations->applyTrusted(assertion, rw);
if (assertionNew.isNull())
{
break;
if (d_preprocContext->getSymsInAssertions().contains(lhs))
{
// if it has, the substitution becomes an assertion
- TrustNode trhs = newSubstitutions->applyTrusted(lhs);
+ TrustNode trhs = newSubstitutions->applyTrusted(lhs, rw);
Assert(!trhs.isNull());
Trace("non-clausal-simplify")
<< "substitute: will notify SAT layer of substitution: "
theory::TrustSubstitutionMap* subs,
theory::TrustSubstitutionMap* cp)
{
+ Rewriter* rw = d_env.getRewriter();
TrustNode tlit;
if (subs != nullptr)
{
- tlit = subs->applyTrusted(lit);
+ tlit = subs->applyTrusted(lit, rw);
if (!tlit.isNull())
{
lit = processRewrittenLearnedLit(tlit);
{
for (;;)
{
- tlit = cp->applyTrusted(lit);
+ tlit = cp->applyTrusted(lit, rw);
if (tlit.isNull())
{
break;
std::vector<Node> asserts(axioms.begin(), axioms.end());
// must expand definitions
Node conjn = d_env.getTopLevelSubstitutions().apply(goal);
+ conjn = rewrite(conjn);
// now negate
conjn = conjn.negate();
d_abdConj = conjn;
// evaluate e.g. divide-by-zero. This is intentional since the evaluation
// is not trustworthy, since the UF introduced by expanding definitions may
// not be properly constrained.
- Node n = sm.apply(assertion, false);
+ Node n = sm.apply(assertion);
verbose(1) << "SolverEngine::checkModel(): -- substitutes to " << n
<< std::endl;
<< std::endl;
// must expand definitions
Node conjn = d_env.getTopLevelSubstitutions().apply(conj);
+ conjn = rewrite(conjn);
std::string name("__internal_interpol");
quantifiers::SygusInterpol interpolSolver(d_env);
// Ensure node is type-checked at this point.
n.getType(true);
}
- // we apply substitutions here, before expanding definitions
- n = d_env.getTopLevelSubstitutions().apply(n, false);
+ // apply substitutions here (without rewriting), before expanding definitions
+ n = d_env.getTopLevelSubstitutions().apply(n);
// now call expand definitions
n = d_exDefs.expandDefinitions(n, cache);
return n;
theory::TrustSubstitutionMap& tls = d_env->getTopLevelSubstitutions();
for (UnsatCore::iterator i = core.begin(); i != core.end(); ++i)
{
- Node assertionAfterExpansion = tls.apply(*i, false);
+ Node assertionAfterExpansion = tls.apply(*i);
d_env->verbose(1) << "SolverEngine::checkUnsatCore(): pushing core member "
<< *i << ", expanded to " << assertionAfterExpansion
<< std::endl;
d_cbqi_set_quant_inactive(false),
d_incomplete_check(false),
d_added_cbqi_lemma(userContext()),
- d_vtsCache(new VtsTermCache(qim)),
+ d_vtsCache(new VtsTermCache(env, qim)),
d_bv_invert(nullptr),
d_small_const_multiplier(NodeManager::currentNM()->mkConst(
CONST_RATIONAL, Rational(1) / Rational(1000000))),
namespace theory {
namespace quantifiers {
-VtsTermCache::VtsTermCache(QuantifiersInferenceManager& qim) : d_qim(qim)
+VtsTermCache::VtsTermCache(Env& env, QuantifiersInferenceManager& qim)
+ : EnvObj(env), d_qim(qim)
{
d_zero = NodeManager::currentNM()->mkConst(CONST_RATIONAL, Rational(0));
}
subs_lhs.end(),
subs_rhs.begin(),
subs_rhs.end());
- n = Rewriter::rewrite(n);
+ n = rewrite(n);
// may have cancelled
if (!expr::hasSubterm(n, rew_vts_inf))
{
#define CVC5__THEORY__QUANTIFIERS__CEGQI__VTS_TERM_CACHE_H
#include <map>
+
#include "expr/attribute.h"
#include "expr/node.h"
+#include "smt/env_obj.h"
namespace cvc5 {
namespace theory {
* that combine instantiating quantified formulas with nested quantifiers
* with terms containing virtual terms.
*/
-class VtsTermCache
+class VtsTermCache : protected EnvObj
{
public:
- VtsTermCache(QuantifiersInferenceManager& qim);
+ VtsTermCache(Env& env, QuantifiersInferenceManager& qim);
~VtsTermCache() {}
/**
* Get vts delta. The argument isFree indicates if we are getting the
{
Node r = computeProcessTerms2(fbody, cache, new_vars, new_conds);
Assert(new_vars.size() == h.getNumChildren());
- return Rewriter::rewrite(NodeManager::currentNM()->mkNode(EQUAL, h, r));
+ return NodeManager::currentNM()->mkNode(EQUAL, h, r);
}
// It can happen that we can't infer the shape of the function definition,
// for example: forall xy. f( x, y ) = 1 + f( x, y ), this is rewritten to
std::vector<Node>& subs) const
{
Kind nk = n.getKind();
- if (nk == NOT)
+ while (nk == NOT)
{
n = n[0];
pol = !pol;
nk = n.getKind();
- Assert(nk != NOT);
}
if ((nk == AND && pol) || (nk == OR && !pol))
{
// remake with eliminated nodes
body =
body.substitute(vars.begin(), vars.end(), subs.begin(), subs.end());
- body = Rewriter::rewrite(body);
if (!qa.d_ipl.isNull())
{
qa.d_ipl = qa.d_ipl.substitute(
#include "expr/node_algorithm.h"
#include "expr/skolem_manager.h"
#include "theory/quantifiers/term_util.h"
-#include "theory/rewriter.h"
using namespace cvc5;
using namespace cvc5::kind;
cr = cr.substitute(
termsNs.begin(), termsNs.end(), subsNs.begin(), subsNs.end());
}
- cr = Rewriter::rewrite(cr);
Trace("si-prt") << ".....got si=" << singleInvocation
<< ", result : " << cr << std::endl;
d_conjuncts[2].push_back(cr);
Assert(si_terms.size() == si_subs.size());
cr = cr.substitute(
si_terms.begin(), si_terms.end(), si_subs.begin(), si_subs.end());
- cr = Rewriter::rewrite(cr);
Trace("si-prt") << ".....si version=" << cr << std::endl;
d_conjuncts[0].push_back(cr);
}
{
Node bvl = nm->mkNode(BOUND_VAR_LIST, rem_ind_vars);
nret = nm->mkNode(FORALL, bvl, nret);
- nret = Rewriter::rewrite(nret);
sub = nret;
sub_vars.insert(
sub_vars.end(), ind_var_indicies.begin() + 1, ind_var_indicies.end());
#include "theory/quantifiers/sygus/sygus_grammar_cons.h"
#include "theory/quantifiers/sygus/sygus_utils.h"
#include "theory/quantifiers/term_util.h"
-#include "theory/rewriter.h"
using namespace std;
using namespace cvc5::kind;
res = SygusUtils::mkSygusConjecture({abd}, res, {instAttr});
Trace("sygus-abduct-debug") << "...finish" << std::endl;
- res = theory::Rewriter::rewrite(res);
-
Trace("sygus-abduct") << "Generate: " << res << std::endl;
return res;
}
}
-Node SubstitutionMap::apply(TNode t, bool doRewrite) {
-
+Node SubstitutionMap::apply(TNode t, Rewriter* r)
+{
Debug("substitution") << "SubstitutionMap::apply(" << t << ")" << endl;
// Setup the cache
Node result = internalSubstitute(t, d_substitutionCache);
Debug("substitution") << "SubstitutionMap::apply(" << t << ") => " << result << endl;
- if (doRewrite)
+ if (r != nullptr)
{
- result = Rewriter::rewrite(result);
+ result = r->rewrite(result);
}
return result;
namespace cvc5 {
namespace theory {
+class Rewriter;
+
/**
* The type for the Substitutions mapping output by
* Theory::simplify(), TheoryEngine::simplify(), and
}
/**
- * Apply the substitutions to the node.
+ * Apply the substitutions to the node, optionally rewrite if a non-null
+ * Rewriter pointer is passed.
*/
- Node apply(TNode t, bool doRewrite = false);
+ Node apply(TNode t, Rewriter* r = nullptr);
/**
* Apply the substitutions to the node.
*/
- Node apply(TNode t, bool doRewrite = false) const
+ Node apply(TNode t, Rewriter* r = nullptr) const
{
- return const_cast<SubstitutionMap*>(this)->apply(t, doRewrite);
+ return const_cast<SubstitutionMap*>(this)->apply(t, r);
}
iterator begin() { return d_substitutions.begin(); }
{
//apply substitutions
Node nn = d_env.getTopLevelSubstitutions().apply(n);
+ nn = rewrite(nn);
Debug("model-getvalue-debug") << "[model-getvalue] getValue : substitute " << n << " to " << nn << std::endl;
//get value in model
nn = getModelValue(nn);
}
}
-TrustNode TrustSubstitutionMap::applyTrusted(Node n, bool doRewrite)
+TrustNode TrustSubstitutionMap::applyTrusted(Node n, Rewriter* r)
{
Trace("trust-subs") << "TrustSubstitutionMap::addSubstitution: apply " << n
<< std::endl;
- Node ns = d_subs.apply(n, doRewrite);
+ Node ns = d_subs.apply(n, r);
Trace("trust-subs") << "...subs " << ns << std::endl;
if (n == ns)
{
return TrustNode::mkTrustRewrite(n, ns, this);
}
-Node TrustSubstitutionMap::apply(Node n, bool doRewrite)
+Node TrustSubstitutionMap::apply(Node n, Rewriter* r)
{
- return d_subs.apply(n, doRewrite);
+ return d_subs.apply(n, r);
}
std::shared_ptr<ProofNode> TrustSubstitutionMap::getProofFor(Node eq)
/**
* Apply substitutions in this class to node n. Returns a trust node
* proving n = n*sigma, where the proof generator is provided by this class
- * (when proofs are enabled).
+ * (when proofs are enabled). If a non-null rewriter is provided, the result
+ * of the substitution is rewritten.
*/
- TrustNode applyTrusted(Node n, bool doRewrite = true);
+ TrustNode applyTrusted(Node n, Rewriter* r = nullptr);
/** Same as above, without proofs */
- Node apply(Node n, bool doRewrite = true);
+ Node apply(Node n, Rewriter* r = nullptr);
/** Get the proof for formula f */
std::shared_ptr<ProofNode> getProofFor(Node f) override;