std::vector<Node> left_tuple;
left_tuple.push_back(Node::fromExpr(tn.getDatatype()[0].getConstructor()));
for(int i = 0; i < left_len; i++) {
- left_tuple.push_back(TheorySetsRels::nthElementOfTuple(*left_it,i));
+ left_tuple.push_back(RelsUtils::nthElementOfTuple(*left_it,i));
}
Elements::const_iterator right_it = right.begin();
int right_len = (*right_it).getType().getTupleLength();
while(right_it != right.end()) {
std::vector<Node> right_tuple;
for(int j = 0; j < right_len; j++) {
- right_tuple.push_back(TheorySetsRels::nthElementOfTuple(*right_it,j));
+ right_tuple.push_back(RelsUtils::nthElementOfTuple(*right_it,j));
}
std::vector<Node> new_tuple;
new_tuple.insert(new_tuple.end(), left_tuple.begin(), left_tuple.end());
std::vector<Node> left_tuple;
left_tuple.push_back(Node::fromExpr(tn.getDatatype()[0].getConstructor()));
for(int i = 0; i < left_len - 1; i++) {
- left_tuple.push_back(TheorySetsRels::nthElementOfTuple(*left_it,i));
+ left_tuple.push_back(RelsUtils::nthElementOfTuple(*left_it,i));
}
Elements::const_iterator right_it = right.begin();
int right_len = (*right_it).getType().getTupleLength();
while(right_it != right.end()) {
- if(TheorySetsRels::nthElementOfTuple(*left_it,left_len-1) == TheorySetsRels::nthElementOfTuple(*right_it,0)) {
+ if(RelsUtils::nthElementOfTuple(*left_it,left_len-1) == RelsUtils::nthElementOfTuple(*right_it,0)) {
std::vector<Node> right_tuple;
for(int j = 1; j < right_len; j++) {
- right_tuple.push_back(TheorySetsRels::nthElementOfTuple(*right_it,j));
+ right_tuple.push_back(RelsUtils::nthElementOfTuple(*right_it,j));
}
std::vector<Node> new_tuple;
new_tuple.insert(new_tuple.end(), left_tuple.begin(), left_tuple.end());
m->assertRepresentative(shape);
}
-#ifdef CVC4_ASSERTIONS
- bool checkPassed = true;
- BOOST_FOREACH(TNode term, terms) {
- if( term.getType().isSet() ) {
- checkPassed &= checkModel(settermElementsMap, term);
- }
- }
- if(Trace.isOn("sets-checkmodel-ignore")) {
- Trace("sets-checkmodel-ignore") << "[sets-checkmodel-ignore] checkPassed value was " << checkPassed << std::endl;
- } else {
- Assert( checkPassed,
- "THEORY_SETS check-model failed. Run with -d sets-model for details." );
- }
-#endif
+// #ifdef CVC4_ASSERTIONS
+// bool checkPassed = true;
+// BOOST_FOREACH(TNode term, terms) {
+// if( term.getType().isSet() ) {
+// checkPassed &= checkModel(settermElementsMap, term);
+// }
+// }
+// if(Trace.isOn("sets-checkmodel-ignore")) {
+// Trace("sets-checkmodel-ignore") << "[sets-checkmodel-ignore] checkPassed value was " << checkPassed << std::endl;
+// } else {
+// Assert( checkPassed,
+// "THEORY_SETS check-model failed. Run with -d sets-model for details." );
+// }
+// #endif
}
Node TheorySetsPrivate::getModelValue(TNode n)
// need to add all tuple elements as shared terms
} else if(n.getType().isTuple() && !n.isConst() && !n.isVar()) {
for(unsigned int i = 0; i < n.getType().getTupleLength(); i++) {
- Node element = nthElementOfTuple(n, i);
+ Node element = RelsUtils::nthElementOfTuple(n, i);
if(!element.isConst()) {
makeSharedTerm(element);
}
if(mem_it != d_membership_db.end()) {
for(std::vector<Node>::iterator pair_it = mem_it->second.begin();
pair_it != mem_it->second.end(); pair_it++) {
- TC_PAIR_IT pair_set_it = tc_graph.find(nthElementOfTuple(*pair_it, 0));
+ TC_PAIR_IT pair_set_it = tc_graph.find(RelsUtils::nthElementOfTuple(*pair_it, 0));
if( pair_set_it != tc_graph.end() ) {
- pair_set_it->second.insert(nthElementOfTuple(*pair_it, 1));
+ pair_set_it->second.insert(RelsUtils::nthElementOfTuple(*pair_it, 1));
} else {
std::hash_set< Node, NodeHashFunction > snd_pair_set;
- snd_pair_set.insert(nthElementOfTuple(*pair_it, 1));
- tc_graph[nthElementOfTuple(*pair_it, 0)] = snd_pair_set;
+ snd_pair_set.insert(RelsUtils::nthElementOfTuple(*pair_it, 1));
+ tc_graph[RelsUtils::nthElementOfTuple(*pair_it, 0)] = snd_pair_set;
}
}
}
TC_IT tc_graph_it = d_membership_tc_cache.find(tc_rep);
if(polarity) {
if(tc_graph_it != d_membership_tc_cache.end()) {
- TC_PAIR_IT pair_set_it = tc_graph_it->second.find(nthElementOfTuple(atom[0], 0));
+ TC_PAIR_IT pair_set_it = tc_graph_it->second.find(RelsUtils::nthElementOfTuple(atom[0], 0));
if(pair_set_it != tc_graph_it->second.end()) {
- pair_set_it->second.insert(nthElementOfTuple(atom[0], 1));
+ pair_set_it->second.insert(RelsUtils::nthElementOfTuple(atom[0], 1));
} else {
std::hash_set< Node, NodeHashFunction > pair_set;
- pair_set.insert(nthElementOfTuple(atom[0], 1));
- tc_graph_it->second[nthElementOfTuple(atom[0], 0)] = pair_set;
+ pair_set.insert(RelsUtils::nthElementOfTuple(atom[0], 1));
+ tc_graph_it->second[RelsUtils::nthElementOfTuple(atom[0], 0)] = pair_set;
}
Node reason = getReason(tc_rep, tc_term, tc_r_rep, tc_term[0]);
std::map< Node, Node >::iterator exp_it = d_membership_tc_exp_cache.find(tc_rep);
} else {
std::map< Node, std::hash_set< Node, NodeHashFunction > > pair_set;
std::hash_set< Node, NodeHashFunction > set;
- set.insert(nthElementOfTuple(atom[0], 1));
- pair_set[nthElementOfTuple(atom[0], 0)] = set;
+ set.insert(RelsUtils::nthElementOfTuple(atom[0], 1));
+ pair_set[RelsUtils::nthElementOfTuple(atom[0], 0)] = set;
d_membership_tc_cache[tc_rep] = pair_set;
Node reason = getReason(tc_rep, tc_term, tc_r_rep, tc_term[0]);
if(!reason.isNull()) {
// check if atom[0] already exists in TC graph for conflict
} else {
if(tc_graph_it != d_membership_tc_cache.end()) {
- checkTCGraphForConflict(atom, tc_rep, d_trueNode, nthElementOfTuple(atom[0], 0),
- nthElementOfTuple(atom[0], 1), tc_graph_it->second);
+ checkTCGraphForConflict(atom, tc_rep, d_trueNode, RelsUtils::nthElementOfTuple(atom[0], 0),
+ RelsUtils::nthElementOfTuple(atom[0], 1), tc_graph_it->second);
}
}
}
r1_element.push_back(Node::fromExpr(dt[0].getConstructor()));
for(; i < s1_len; ++i) {
- r1_element.push_back(nthElementOfTuple(atom[0], i));
+ r1_element.push_back(RelsUtils::nthElementOfTuple(atom[0], i));
}
dt = r2_rep.getType().getSetElementType().getDatatype();
r2_element.push_back(Node::fromExpr(dt[0].getConstructor()));
for(; i < tup_len; ++i) {
- r2_element.push_back(nthElementOfTuple(atom[0], i));
+ r2_element.push_back(RelsUtils::nthElementOfTuple(atom[0], i));
}
Node fact_1;
r1_element.push_back(Node::fromExpr(dt[0].getConstructor()));
for(; i < s1_len-1; ++i) {
- r1_element.push_back(nthElementOfTuple(atom[0], i));
+ r1_element.push_back(RelsUtils::nthElementOfTuple(atom[0], i));
}
r1_element.push_back(shared_x);
r2_element.push_back(Node::fromExpr(dt[0].getConstructor()));
r2_element.push_back(shared_x);
for(; i < tup_len; ++i) {
- r2_element.push_back(nthElementOfTuple(atom[0], i));
+ r2_element.push_back(RelsUtils::nthElementOfTuple(atom[0], i));
}
Node t1 = nm->mkNode(kind::APPLY_CONSTRUCTOR, r1_element);
Trace("rels-debug") << "\n[sets-rels] *********** Applying TRANSPOSE rule " << std::endl;
bool polarity = exp.getKind() != kind::NOT;
Node atom = polarity ? exp : exp[0];
- Node reversedTuple = getRepresentative(reverseTuple(atom[0]));
+ Node reversedTuple = getRepresentative(RelsUtils::reverseTuple(atom[0]));
if(tp_occur) {
Trace("rels-debug") << "\n[sets-rels] Apply TRANSPOSE-OCCUR rule on term: " << tp_term
Assert(tuples.size() == exps.size());
for(unsigned int i = 0; i < tuples.size(); i++) {
Node reason = exps[i][1] == n0_rep ? exps[i] : AND(exps[i], EQUAL(exps[i][1], n0_rep));
- Node rev_tup = getRepresentative(reverseTuple(tuples[i]));
+ Node rev_tup = getRepresentative(RelsUtils::reverseTuple(tuples[i]));
Node fact = MEMBER(rev_tup, n_rep);
if(holds(fact)) {
Trace("rels-debug") << "[sets-rels] New fact: " << fact << " already holds! Skip..." << std::endl;
for(unsigned int j = 0; j < r2_elements.size(); j++) {
std::vector<Node> composed_tuple;
TypeNode tn = n.getType().getSetElementType();
- Node r2_lmost = nthElementOfTuple(r2_elements[j], 0);
- Node r1_rmost = nthElementOfTuple(r1_elements[i], t1_len-1);
+ Node r2_lmost = RelsUtils::nthElementOfTuple(r2_elements[j], 0);
+ Node r1_rmost = RelsUtils::nthElementOfTuple(r1_elements[i], t1_len-1);
composed_tuple.push_back(Node::fromExpr(tn.getDatatype()[0].getConstructor()));
if((areEqual(r1_rmost, r2_lmost) && n.getKind() == kind::JOIN) ||
unsigned int k = 0;
unsigned int l = 1;
for(; k < t1_len - 1; ++k) {
- composed_tuple.push_back(nthElementOfTuple(r1_elements[i], k));
+ composed_tuple.push_back(RelsUtils::nthElementOfTuple(r1_elements[i], k));
}
if(isProduct) {
- composed_tuple.push_back(nthElementOfTuple(r1_elements[i], k));
- composed_tuple.push_back(nthElementOfTuple(r2_elements[j], 0));
+ composed_tuple.push_back(RelsUtils::nthElementOfTuple(r1_elements[i], k));
+ composed_tuple.push_back(RelsUtils::nthElementOfTuple(r2_elements[j], 0));
}
for(; l < t2_len; ++l) {
- composed_tuple.push_back(nthElementOfTuple(r2_elements[j], l));
+ composed_tuple.push_back(RelsUtils::nthElementOfTuple(r2_elements[j], l));
}
Node composed_tuple_rep = getRepresentative(nm->mkNode(kind::APPLY_CONSTRUCTOR, composed_tuple));
Node fact = MEMBER(composed_tuple_rep, new_rel_rep);
d_pending_split_facts.clear();
}
- Node TheorySetsRels::reverseTuple( Node tuple ) {
- Assert( tuple.getType().isTuple() );
- std::vector<Node> elements;
- std::vector<TypeNode> tuple_types = tuple.getType().getTupleTypes();
- std::reverse( tuple_types.begin(), tuple_types.end() );
- TypeNode tn = NodeManager::currentNM()->mkTupleType( tuple_types );
- Datatype dt = tn.getDatatype();
- elements.push_back( Node::fromExpr(dt[0].getConstructor() ) );
- for(int i = tuple_types.size() - 1; i >= 0; --i) {
- elements.push_back( nthElementOfTuple(tuple, i) );
- }
- return NodeManager::currentNM()->mkNode( kind::APPLY_CONSTRUCTOR, elements );
- }
-
void TheorySetsRels::assertMembership( Node fact, Node reason, bool polarity ) {
d_eqEngine->assertPredicate( fact, polarity, reason );
}
} else if(a.getType().isTuple()) {
bool equal = true;
for(unsigned int i = 0; i < a.getType().getTupleLength(); i++) {
- equal = equal && areEqual(nthElementOfTuple(a, i), nthElementOfTuple(b, i));
+ equal = equal && areEqual(RelsUtils::nthElementOfTuple(a, i), RelsUtils::nthElementOfTuple(b, i));
}
return equal;
} else if(!a.getType().isBoolean()){
exp = AND(exp, explain(EQUAL(tc_rep, tc_term)));
}
if(tc_r_mems->second[i] != tuple) {
- if(nthElementOfTuple(tc_r_mems->second[i], 0) != nthElementOfTuple(tuple, 0)) {
- exp = AND(exp, explain(EQUAL(nthElementOfTuple(tc_r_mems->second[i], 0), nthElementOfTuple(tuple, 0))));
+ if(RelsUtils::nthElementOfTuple(tc_r_mems->second[i], 0) != RelsUtils::nthElementOfTuple(tuple, 0)) {
+ exp = AND(exp, explain(EQUAL(RelsUtils::nthElementOfTuple(tc_r_mems->second[i], 0), RelsUtils::nthElementOfTuple(tuple, 0))));
}
- if(nthElementOfTuple(tc_r_mems->second[i], 1) != nthElementOfTuple(tuple, 1)) {
- exp = AND(exp, explain(EQUAL(nthElementOfTuple(tc_r_mems->second[i], 1), nthElementOfTuple(tuple, 1))));
+ if(RelsUtils::nthElementOfTuple(tc_r_mems->second[i], 1) != RelsUtils::nthElementOfTuple(tuple, 1)) {
+ exp = AND(exp, explain(EQUAL(RelsUtils::nthElementOfTuple(tc_r_mems->second[i], 1), RelsUtils::nthElementOfTuple(tuple, 1))));
}
exp = AND(exp, EQUAL(tc_r_mems->second[i], tuple));
}
exp = AND(exp, explain(EQUAL(tc_term_rep, tc_terms[i])));
}
if(tc_t_mems->second[j] != tuple) {
- if(nthElementOfTuple(tc_t_mems->second[j], 0) != nthElementOfTuple(tuple, 0)) {
- exp = AND(exp, explain(EQUAL(nthElementOfTuple(tc_t_mems->second[j], 0), nthElementOfTuple(tuple, 0))));
+ if(RelsUtils::nthElementOfTuple(tc_t_mems->second[j], 0) != RelsUtils::nthElementOfTuple(tuple, 0)) {
+ exp = AND(exp, explain(EQUAL(RelsUtils::nthElementOfTuple(tc_t_mems->second[j], 0), RelsUtils::nthElementOfTuple(tuple, 0))));
}
- if(nthElementOfTuple(tc_t_mems->second[j], 1) != nthElementOfTuple(tuple, 1)) {
- exp = AND(exp, explain(EQUAL(nthElementOfTuple(tc_t_mems->second[j], 1), nthElementOfTuple(tuple, 1))));
+ if(RelsUtils::nthElementOfTuple(tc_t_mems->second[j], 1) != RelsUtils::nthElementOfTuple(tuple, 1)) {
+ exp = AND(exp, explain(EQUAL(RelsUtils::nthElementOfTuple(tc_t_mems->second[j], 1), RelsUtils::nthElementOfTuple(tuple, 1))));
}
exp = AND(exp, EQUAL(tc_t_mems->second[j], tuple));
}
return Node::null();
}
- Node TheorySetsRels::nthElementOfTuple( Node tuple, int n_th ) {
- if(tuple.isConst() || (!tuple.isVar() && !tuple.isConst()))
- return tuple[n_th];
- Datatype dt = tuple.getType().getDatatype();
- return NodeManager::currentNM()->mkNode(kind::APPLY_SELECTOR_TOTAL, dt[0][n_th].getSelector(), tuple);
- }
-
void TheorySetsRels::addSharedTerm( TNode n ) {
Trace("rels-debug") << "[sets-rels] Add a shared term: " << n << std::endl;
d_sets_theory.addSharedTerm(n);
void TheorySetsRels::computeTupleReps( Node n ) {
if( d_tuple_reps.find( n ) == d_tuple_reps.end() ){
for( unsigned i = 0; i < n.getType().getTupleLength(); i++ ){
- d_tuple_reps[n].push_back( getRepresentative( nthElementOfTuple(n, i) ) );
+ d_tuple_reps[n].push_back( getRepresentative( RelsUtils::nthElementOfTuple(n, i) ) );
}
}
}
std::vector<Node> tuple_elements;
tuple_elements.push_back(Node::fromExpr((n[0].getType().getDatatype())[0].getConstructor()));
for(unsigned int i = 0; i < n[0].getType().getTupleLength(); i++) {
- Node element = nthElementOfTuple(n[0], i);
+ Node element = RelsUtils::nthElementOfTuple(n[0], i);
makeSharedTerm(element);
tuple_elements.push_back(element);
}
Node n1;
if(reverseOnly) {
if(polarity) {
- n1 = NodeManager::currentNM()->mkNode( kind::IMPLIES, exp, MEMBER(reverseTuple(t1), t2[0]) );
+ n1 = NodeManager::currentNM()->mkNode( kind::IMPLIES, exp, MEMBER(RelsUtils::reverseTuple(t1), t2[0]) );
} else {
- n1 = NodeManager::currentNM()->mkNode( kind::IMPLIES, exp, MEMBER(reverseTuple(t1), t2[0]).negate() );
+ n1 = NodeManager::currentNM()->mkNode( kind::IMPLIES, exp, MEMBER(RelsUtils::reverseTuple(t1), t2[0]).negate() );
}
} else {
Node n2;
if(polarity) {
n1 = NodeManager::currentNM()->mkNode( kind::IMPLIES, exp, MEMBER(t1, t2) );
- n2 = NodeManager::currentNM()->mkNode( kind::IMPLIES, exp, MEMBER(reverseTuple(t1), t2[0]) );
+ n2 = NodeManager::currentNM()->mkNode( kind::IMPLIES, exp, MEMBER(RelsUtils::reverseTuple(t1), t2[0]) );
} else {
n1 = NodeManager::currentNM()->mkNode( kind::IMPLIES, exp, MEMBER(t1, t2).negate() );
- n2 = NodeManager::currentNM()->mkNode( kind::IMPLIES, exp, MEMBER(reverseTuple(t1), t2[0]).negate() );
+ n2 = NodeManager::currentNM()->mkNode( kind::IMPLIES, exp, MEMBER(RelsUtils::reverseTuple(t1), t2[0]).negate() );
}
Trace("rels-std") << "[sets-rels-lemma] Generate a lemma by applying transpose rule: "
<< n2 << std::endl;
r1_element.push_back(Node::fromExpr(dt[0].getConstructor()));
for(; i < s1_len; ++i) {
- r1_element.push_back(nthElementOfTuple(t1, i));
+ r1_element.push_back(RelsUtils::nthElementOfTuple(t1, i));
}
dt = r2.getType().getSetElementType().getDatatype();
r2_element.push_back(Node::fromExpr(dt[0].getConstructor()));
for(; i < tup_len; ++i) {
- r2_element.push_back(nthElementOfTuple(t1, i));
+ r2_element.push_back(RelsUtils::nthElementOfTuple(t1, i));
}
Node tuple_1 = getRepresentative(nm->mkNode(kind::APPLY_CONSTRUCTOR, r1_element));
Node tuple_2 = getRepresentative(nm->mkNode(kind::APPLY_CONSTRUCTOR, r2_element));
return conjunction;
}/* mkAnd() */
+
}
}
#include "theory/sets/theory_sets_rewriter.h"
#include "theory/sets/normal_form.h"
#include "theory/sets/theory_sets_rels.h"
+#include "theory/sets/rels_utils.h"
namespace CVC4 {
namespace theory {
std::set<Node>::iterator tuple_it = tuple_set.begin();
while(tuple_it != tuple_set.end()) {
- new_tuple_set.insert(TheorySetsRels::reverseTuple(*tuple_it));
+ new_tuple_set.insert(RelsUtils::reverseTuple(*tuple_it));
tuple_it++;
}
Node new_node = NormalForm::elementsToSet(new_tuple_set, node.getType());
std::vector<Node> left_tuple;
left_tuple.push_back(Node::fromExpr(tn.getDatatype()[0].getConstructor()));
for(int i = 0; i < left_len; i++) {
- left_tuple.push_back(TheorySetsRels::nthElementOfTuple(*left_it,i));
+ left_tuple.push_back(RelsUtils::nthElementOfTuple(*left_it,i));
}
std::set<Node>::iterator right_it = right.begin();
int right_len = (*right_it).getType().getTupleLength();
Trace("rels-debug") << "Sets::postRewrite processing left_it = " << *right_it << std::endl;
std::vector<Node> right_tuple;
for(int j = 0; j < right_len; j++) {
- right_tuple.push_back(TheorySetsRels::nthElementOfTuple(*right_it,j));
+ right_tuple.push_back(RelsUtils::nthElementOfTuple(*right_it,j));
}
std::vector<Node> new_tuple;
new_tuple.insert(new_tuple.end(), left_tuple.begin(), left_tuple.end());
std::vector<Node> left_tuple;
left_tuple.push_back(Node::fromExpr(tn.getDatatype()[0].getConstructor()));
for(int i = 0; i < left_len - 1; i++) {
- left_tuple.push_back(TheorySetsRels::nthElementOfTuple(*left_it,i));
+ left_tuple.push_back(RelsUtils::nthElementOfTuple(*left_it,i));
}
std::set<Node>::iterator right_it = right.begin();
int right_len = (*right_it).getType().getTupleLength();
while(right_it != right.end()) {
- if(TheorySetsRels::nthElementOfTuple(*left_it,left_len-1) == TheorySetsRels::nthElementOfTuple(*right_it,0)) {
+ if(RelsUtils::nthElementOfTuple(*left_it,left_len-1) == RelsUtils::nthElementOfTuple(*right_it,0)) {
std::vector<Node> right_tuple;
for(int j = 1; j < right_len; j++) {
- right_tuple.push_back(TheorySetsRels::nthElementOfTuple(*right_it,j));
+ right_tuple.push_back(RelsUtils::nthElementOfTuple(*right_it,j));
}
std::vector<Node> new_tuple;
new_tuple.insert(new_tuple.end(), left_tuple.begin(), left_tuple.end());
if(node[0].getKind() == kind::EMPTYSET) {
return RewriteResponse(REWRITE_DONE, nm->mkConst(EmptySet(nm->toType(node.getType()))));
} else if (node[0].isConst()) {
-
+ std::set<Node> rel_mems = NormalForm::getElementsFromNormalConstant(node[0]);
+ std::set<Node> tc_rel_mems = RelsUtils::computeTC(rel_mems, node);
+ Node new_node = NormalForm::elementsToSet(tc_rel_mems, node.getType());
+ Assert(new_node.isConst());
+ Trace("sets-postrewrite") << "Sets::postRewrite returning " << new_node << std::endl;
+ return RewriteResponse(REWRITE_DONE, new_node);
+
} else if(node[0].getKind() == kind::TCLOSURE) {
return RewriteResponse(REWRITE_AGAIN, node[0]);
} else if(node[0].getKind() != kind::TCLOSURE) {