* Ensure that expand definitions is called on all non-variable expressions. In particular, it is necessary that the sets theory is notified when a set universe term occurs in the input to ensure options are set correctly. The commit moves this check from within check() to expandDefinitions(), and also adds the check for join image which relies on universe set. This fixes a bug reported by Arjun. Add and update regressions.
* Add comments concerning expandDefinitions
* Expand comment, move to .h
if(!childrenPushed) {
Kind k = n.getKind();
- // Apart from apply, we can short circuit leaves
- if(k != kind::APPLY && n.getNumChildren() == 0) {
+ // we can short circuit (variable) leaves
+ if(n.isVar()) {
SmtEngine::DefinedFunctionMap::const_iterator i = d_smt.d_definedFunctions->find(n);
if(i != d_smt.d_definedFunctions->end()) {
// replacement must be closed
node = t->expandDefinition(req, n);
}
- // there should be children here, otherwise we short-circuited a result-push/continue, above
- if (node.getNumChildren() == 0) {
- Debug("expand") << "Unexpectedly no children..." << node << endl;
- }
- // This invariant holds at the moment but it is concievable that a new theory
- // might introduce a kind which can have children before definition expansion but doesn't
- // afterwards. If this happens, remove this assertion.
- Assert(node.getNumChildren() > 0);
-
// the partial functions can fall through, in which case we still
// consider their children
worklist.push(make_triple(Node(n), node, true)); // Original and rewritten result
// Reconstruct the node from it's (now rewritten) children on the stack
Debug("expand") << "cons : " << node << endl;
- //cout << "cons : " << node << endl;
- NodeBuilder<> nb(node.getKind());
- if(node.getMetaKind() == kind::metakind::PARAMETERIZED) {
- Debug("expand") << "op : " << node.getOperator() << endl;
- //cout << "op : " << node.getOperator() << endl;
- nb << node.getOperator();
- }
- for(size_t i = 0; i < node.getNumChildren(); ++i) {
- Assert(!result.empty());
- Node expanded = result.top();
- result.pop();
- //cout << "exchld : " << expanded << endl;
- Debug("expand") << "exchld : " << expanded << endl;
- nb << expanded;
+ if(node.getNumChildren()>0) {
+ //cout << "cons : " << node << endl;
+ NodeBuilder<> nb(node.getKind());
+ if(node.getMetaKind() == kind::metakind::PARAMETERIZED) {
+ Debug("expand") << "op : " << node.getOperator() << endl;
+ //cout << "op : " << node.getOperator() << endl;
+ nb << node.getOperator();
+ }
+ for(size_t i = 0; i < node.getNumChildren(); ++i) {
+ Assert(!result.empty());
+ Node expanded = result.top();
+ result.pop();
+ //cout << "exchld : " << expanded << endl;
+ Debug("expand") << "exchld : " << expanded << endl;
+ nb << expanded;
+ }
+ node = nb;
}
- node = nb;
cache[n] = n == node ? Node::null() : node; // Only cache once all subterms are expanded
result.push(node);
}
d_internal->preRegisterTerm(node);
}
+Node TheorySets::expandDefinition(LogicRequest &logicRequest, Node n) {
+ return d_internal->expandDefinition(logicRequest, n);
+}
+
Theory::PPAssertStatus TheorySets::ppAssert(TNode in, SubstitutionMap& outSubstitutions) {
return d_internal->ppAssert( in, outSubstitutions );
}
void preRegisterTerm(TNode node);
+ Node expandDefinition(LogicRequest &logicRequest, Node n);
+
PPAssertStatus ppAssert(TNode in, SubstitutionMap& outSubstitutions);
void presolve();
}else if( n.getKind()==kind::EMPTYSET ){
d_eqc_emptyset[tnn] = eqc;
}else if( n.getKind()==kind::UNIVERSE_SET ){
- if( options::setsExt() ){
- d_eqc_univset[tnn] = eqc;
- }else{
- std::stringstream ss;
- ss << "Symbols complement and universe set are not supported in default mode, try --sets-ext." << std::endl;
- throw LogicException(ss.str());
- }
+ Assert( options::setsExt() );
+ d_eqc_univset[tnn] = eqc;
}else{
Node r1 = d_equalityEngine.getRepresentative( n[0] );
Node r2 = d_equalityEngine.getRepresentative( n[1] );
}
}
+Node TheorySetsPrivate::expandDefinition(LogicRequest &logicRequest, Node n) {
+ Debug("sets-proc") << "expandDefinition : " << n << std::endl;
+ if( n.getKind()==kind::UNIVERSE_SET || n.getKind()==kind::COMPLEMENT || n.getKind()==kind::JOIN_IMAGE ){
+ if( !options::setsExt() ){
+ std::stringstream ss;
+ ss << "Extended set operators are not supported in default mode, try --sets-ext.";
+ throw LogicException(ss.str());
+ }
+ }
+ return n;
+}
Theory::PPAssertStatus TheorySetsPrivate::ppAssert(TNode in, SubstitutionMap& outSubstitutions) {
+ Debug("sets-proc") << "ppAssert : " << in << std::endl;
Theory::PPAssertStatus status = Theory::PP_ASSERT_STATUS_UNSOLVED;
//TODO: allow variable elimination for sets when setsExt = true
void preRegisterTerm(TNode node);
+ /** expandDefinition
+ * If the sets-ext option is not set and we have an extended operator,
+ * we throw an exception. This function is a no-op otherwise.
+ *
+ * This is related to github issue #1076
+ * TheorySets uses expandDefinition as an entry point to see if the input
+ * contains extended operators.
+ *
+ * We need to be notified when a universe set occurs in our input,
+ * before preprocessing and simplification takes place. Otherwise the models
+ * may be inaccurate when setsExt is false, here is an example:
+ *
+ * x,y : (Set Int)
+ * x = (as univset (Set Int));
+ * 0 in y;
+ * check-sat;
+ *
+ * If setsExt is enabled, the model value of (as univset (Set Int)) is always accurate.
+ *
+ * If setsExt is not enabled, the following can happen for the above example:
+ * x = (as univset (Set Int)) is made into a model substitution during
+ * simplification. This means (as univset (Set Int)) is not a term in any assertion,
+ * and hence we do not throw an exception, nor do we infer that 0 is a member of
+ * (as univset (Set Int)). We instead report a model where x = {}. The correct behavior
+ * is to throw an exception that says universe set is not supported when setsExt disabled.
+ * Hence we check for the existence of universe set before simplification here.
+ *
+ * Another option to fix this is to make TheoryModel::getValue more general
+ * so that it makes theory-specific calls to evaluate interpreted symbols.
+ */
+ Node expandDefinition(LogicRequest &logicRequest, Node n);
+
Theory::PPAssertStatus ppAssert(TNode in, SubstitutionMap& outSubstitutions);
void presolve();
* used, definitions should only be used when rewrites are not
* possible, for example in handling under-specified operations
* using partially defined functions.
+ *
+ * TODO (github issue #1076):
+ * some theories like sets use expandDefinition as a "context
+ * independent preRegisterTerm". This is required for cases where
+ * a theory wants to be notified about a term before preprocessing
+ * and simplification but doesn't necessarily want to rewrite it.
*/
virtual Node expandDefinition(LogicRequest &logicRequest, Node node) {
// by default, do nothing
% EXPECT: sat\r
OPTION "fmf-bound";\r
+OPTION "sets-ext";\r
Atom : TYPE;\r
REAL_UNIVERSE : SET OF [REAL];\r
ATOM_UNIVERSE : SET OF [Atom];\r
% EXPECT: unsat
OPTION "logic" "ALL_SUPPORTED";
+OPTION "sets-ext";
IntPair: TYPE = [INT, INT];
x : SET OF IntPair;
y : SET OF IntPair;
% EXPECT: sat
OPTION "logic" "ALL_SUPPORTED";
+OPTION "sets-ext";
IntPair: TYPE = [INT, INT];
x : SET OF IntPair;
y : SET OF IntPair;
% EXPECT: unsat
OPTION "logic" "ALL_SUPPORTED";
+OPTION "sets-ext";
Atom: TYPE;
x : SET OF [Atom, Atom];
y : SET OF [Atom, Atom];
% EXPECT: sat
OPTION "logic" "ALL_SUPPORTED";
+OPTION "sets-ext";
Atom: TYPE;
x : SET OF [Atom, Atom];
y : SET OF [Atom, Atom];
% EXPECT: unsat
OPTION "logic" "ALL_SUPPORTED";
+OPTION "sets-ext";
Atom: TYPE;
x : SET OF [Atom, Atom];
y : SET OF [Atom, Atom];
% EXPECT: sat
OPTION "logic" "ALL_SUPPORTED";
+OPTION "sets-ext";
Atom: TYPE;
x : SET OF [Atom, Atom];
y : SET OF [Atom, Atom];
ASSERT x = {(f, g), (b, c), (d, e), (c, e)};
ASSERT (NOT(a = b)) OR (NOT(a = f));
-CHECKSAT;
\ No newline at end of file
+CHECKSAT;
sets-poly-nonint.smt2 \
int-real-univ.smt2 \
int-real-univ-unsat.smt2 \
- sets-tuple-poly.cvc
+ sets-tuple-poly.cvc \
+ arjun-set-univ.cvc \
+ univ-set-uf-elim.smt2
EXTRA_DIST = $(TESTS)
--- /dev/null
+% EXPECT: Extended set operators are not supported in default mode, try --sets-ext.
+% EXIT: 1
+OPTION "produce-models" true;
+x,y,z : SET OF BOOLEAN;
+ASSERT x = {TRUE};
+ASSERT y = {FALSE};
+CHECKSAT z = ~ y;
+COUNTERMODEL;
--- /dev/null
+; EXPECT: (error "Extended set operators are not supported in default mode, try --sets-ext.")
+; EXIT: 1
+(set-logic ALL)
+(declare-fun a () Int)
+(declare-fun f ((Set Bool)) Int)
+(declare-fun s () (Set Bool))
+
+(assert (member true s))
+(assert (member false s))
+(assert (= a (f (as univset (Set Bool)))))
+
+(assert (= (f (as emptyset (Set Bool))) 1))
+(assert (= (f (singleton true)) 2))
+(assert (= (f (singleton false)) 3))
+(assert (= (f (union (singleton true) (singleton false))) 4))
+(check-sat)