{
if (bv != bvr)
{
- Trace("sygus-rr-verify")
- << "Testing rewrite rule " << bv << " ---> " << bvr << std::endl;
// add to the sampler database object
std::map<TypeNode, quantifiers::SygusSampler>::iterator its =
d_sampler[a].find(tn);
d_tds, nv, options::sygusSamples(), false);
its = d_sampler[a].find(tn);
}
- // see if they evaluate to same thing on all sample points
- bool ptDisequal = false;
- unsigned pt_index = 0;
- Node bve, bvre;
- for (unsigned i = 0, npoints = its->second.getNumSamplePoints();
- i < npoints;
- i++)
- {
- bve = its->second.evaluate(bv, i);
- bvre = its->second.evaluate(bvr, i);
- if (bve != bvre)
- {
- ptDisequal = true;
- pt_index = i;
- break;
- }
- }
- // bv and bvr should be equivalent under examples
- if (ptDisequal)
- {
- // we have detected unsoundness in the rewriter
- Options& nodeManagerOptions =
- NodeManager::currentNM()->getOptions();
- std::ostream* out = nodeManagerOptions.getOut();
- (*out) << "(unsound-rewrite " << bv << " " << bvr << ")"
- << std::endl;
- // debugging information
- (*out) << "; unsound: are not equivalent for : " << std::endl;
- std::vector<Node> vars;
- its->second.getVariables(vars);
- std::vector<Node> pt;
- its->second.getSamplePoint(pt_index, pt);
- Assert(vars.size() == pt.size());
- for (unsigned i = 0, size = pt.size(); i < size; i++)
- {
- (*out) << "; unsound: " << vars[i] << " -> " << pt[i]
- << std::endl;
- }
- Assert(bve != bvre);
- (*out) << "; unsound: where they evaluate to " << bve << " and "
- << bvre << std::endl;
-
- if (options::sygusRewVerifyAbort())
- {
- AlwaysAssert(
- false,
- "--sygus-rr-verify detected unsoundness in the rewriter!");
- }
- }
+ // check equivalent
+ its->second.checkEquivalent(bv, bvr);
}
}
d_isSygusType(false),
d_numConClasses(0),
d_sizeEnum(0),
- d_isComplete(false)
+ d_isComplete(false),
+ d_sampleRrVInit(false)
{
}
void SygusEnumerator::TermCache::initialize(Node e,
{
Node bn = d_tds->sygusToBuiltin(n);
Node bnr = d_tds->getExtRewriter()->extendedRewrite(bn);
+ if (options::sygusRewVerify())
+ {
+ if (bn != bnr)
+ {
+ if (!d_sampleRrVInit)
+ {
+ d_sampleRrVInit = true;
+ d_samplerRrV.initializeSygus(
+ d_tds, d_enum, options::sygusSamples(), false);
+ }
+ d_samplerRrV.checkEquivalent(bn, bnr);
+ }
+ }
// must be unique up to rewriting
if (d_bterms.find(bnr) != d_bterms.end())
{
unsigned d_sizeEnum;
/** whether this term cache is complete */
bool d_isComplete;
+ /** sampler (for --sygus-rr-verify) */
+ quantifiers::SygusSampler d_samplerRrV;
+ /** is the above sampler initialized? */
+ bool d_sampleRrVInit;
};
/** above cache for each sygus type */
std::map<TypeNode, TermCache> d_tcache;
}
}
+void SygusSampler::checkEquivalent(Node bv, Node bvr)
+{
+ Trace("sygus-rr-verify") << "Testing rewrite rule " << bv << " ---> " << bvr
+ << std::endl;
+
+ // see if they evaluate to same thing on all sample points
+ bool ptDisequal = false;
+ unsigned pt_index = 0;
+ Node bve, bvre;
+ for (unsigned i = 0, npoints = getNumSamplePoints(); i < npoints; i++)
+ {
+ bve = evaluate(bv, i);
+ bvre = evaluate(bvr, i);
+ if (bve != bvre)
+ {
+ ptDisequal = true;
+ pt_index = i;
+ break;
+ }
+ }
+ // bv and bvr should be equivalent under examples
+ if (ptDisequal)
+ {
+ // we have detected unsoundness in the rewriter
+ Options& nodeManagerOptions = NodeManager::currentNM()->getOptions();
+ std::ostream* out = nodeManagerOptions.getOut();
+ (*out) << "(unsound-rewrite " << bv << " " << bvr << ")" << std::endl;
+ // debugging information
+ (*out) << "; unsound: are not equivalent for : " << std::endl;
+ std::vector<Node> vars;
+ getVariables(vars);
+ std::vector<Node> pt;
+ getSamplePoint(pt_index, pt);
+ Assert(vars.size() == pt.size());
+ for (unsigned i = 0, size = pt.size(); i < size; i++)
+ {
+ (*out) << "; unsound: " << vars[i] << " -> " << pt[i] << std::endl;
+ }
+ Assert(bve != bvre);
+ (*out) << "; unsound: where they evaluate to " << bve << " and " << bvre
+ << std::endl;
+
+ if (options::sygusRewVerifyAbort())
+ {
+ AlwaysAssert(false,
+ "--sygus-rr-verify detected unsoundness in the rewriter!");
+ }
+ }
+}
+
} /* CVC4::theory::quantifiers namespace */
} /* CVC4::theory namespace */
} /* CVC4 namespace */
*/
bool containsFreeVariables(Node a, Node b, bool strict = false);
//--------------------------end queries about terms
+ /** check equivalent
+ *
+ * Check whether bv and bvr are equivalent on all sample points, print
+ * an error if not. Used with --sygus-rr-verify.
+ */
+ void checkEquivalent(Node bv, Node bvr);
protected:
/** sygus term database of d_qe */