NodeBuilder<> nb(kind::PLUS);
nb << mkRationalNode(accumulator);
+ Debug("arithrewrite") << mkRationalNode(accumulator) << std::endl;
for(vector<Node>::iterator i = pnfs.begin(); i != pnfs.end(); ++i){
nb << *i;
+ Debug("arithrewrite") << (*i) << std::endl;
+
}
Node normalForm = nb;
Node toPnf(Rational& c, std::set<Node>& variables){
NodeBuilder<> nb(kind::MULT);
nb << mkRationalNode(c);
+
for(std::set<Node>::iterator i = variables.begin(); i != variables.end(); ++i){
nb << *i;
}
Rational accumulator(1,1);
set<Node> variables;
vector<Node> sums;
- stack<pair<TNode, TNode::iterator> > mult_iterators;
- mult_iterators.push(make_pair(t, t.begin()));
- while(!mult_iterators.empty()){
- pair<TNode, TNode::iterator> p = mult_iterators.top();
- mult_iterators.pop();
+ //These stacks need to be kept in lock step
+ stack<TNode> mult_iterators_nodes;
+ stack<unsigned> mult_iterators_iters;
+
+ mult_iterators_nodes.push(t);
+ mult_iterators_iters.push(0);
- TNode mult = p.first;
- TNode::iterator i = p.second;
+ while(!mult_iterators_nodes.empty()){
+ TNode mult = mult_iterators_nodes.top();
+ unsigned i = mult_iterators_iters.top();
- for(; i!= mult.end(); ++i){
- TNode child = *i;
+ mult_iterators_nodes.pop();
+ mult_iterators_iters.pop();
+
+
+ for(; i < mult.getNumChildren(); ++i){
+ TNode child = mult[i];
if(child.getKind() == kind::MULT){ //TODO add not rewritten already checks
++i;
- mult_iterators.push(make_pair(mult,i));
- mult_iterators.push(make_pair(child,child.begin()));
+ mult_iterators_nodes.push(mult);
+ mult_iterators_iters.push(i);
+
+ mult_iterators_nodes.push(child);
+ mult_iterators_iters.push(0);
break;
}
Node rewrittenChild = rewrite(child);
* For more information about what is a valid rational string,
* see GMP's documentation for mpq_set_str().
*/
- Integer(const char * s, int base = 10): d_value(s,base) {}
+ explicit Integer(const char * s, int base = 10): d_value(s,base) {}
Integer(const std::string& s, unsigned base = 10) : d_value(s, base) {}
Integer(const Integer& q) : d_value(q.d_value) {}
* For more information about what is a valid rational string,
* see GMP's documentation for mpq_set_str().
*/
- Rational(const char * s, int base = 10): d_value(s,base) {
+ explicit Rational(const char * s, int base = 10): d_value(s,base) {
d_value.canonicalize();
}
Rational(const std::string& s, unsigned base = 10) : d_value(s, base) {
d_value.canonicalize();
}
+ /**
+ * Constructs a canonical Rational from a numerator.
+ */
+ Rational(signed int n) : d_value(n,1) {
+ d_value.canonicalize();
+ }
+ Rational(unsigned int n) : d_value(n,1) {
+ d_value.canonicalize();
+ }
+ Rational(signed long int n) : d_value(n,1) {
+ d_value.canonicalize();
+ }
+ Rational(unsigned long int n) : d_value(n,1) {
+ d_value.canonicalize();
+ }
+
/**
* Constructs a canonical Rational from a numerator and denominator.
*/
void testMkConstInt() {
- Integer i = "3";
+ Integer i("3");
Node n = d_nodeManager->mkConst(i);
TS_ASSERT_EQUALS(n.getConst<Integer>(),i);
}
void testMkConstRat() {
- Rational r = "3/2";
+ Rational r("3/2");
Node n = d_nodeManager->mkConst(r);
TS_ASSERT_EQUALS(n.getConst<Rational>(),r);
}
}
void testMkConstInt() {
- Integer i = "3";
+ Integer i("3");
Node n = d_nm->mkConst(i);
Node m = d_nm->mkConst(i);
TS_ASSERT_EQUALS(n.getId(), m.getId());
TS_ASSERT_EQUALS(z7.getUnsignedLong(), 1536729ul);
}
+ void testCompareAgainstZero(){
+ Integer z(0);
+ TS_ASSERT_THROWS_NOTHING(z == 0;);
+ TS_ASSERT_EQUALS(z,0);
+ }
+
void testOperatorAssign(){
Integer x(0);
Integer y(79);
TS_ASSERT_THROWS_NOTHING( delete q );
}
+ void testCompareAgainstZero(){
+ Rational q(0);
+ TS_ASSERT_THROWS_NOTHING(q == 0;);
+ TS_ASSERT_EQUALS(q,0);
+ }
+
void testConstructors(){
Rational zero; //Default constructor
TS_ASSERT_EQUALS(0L, zero.getNumerator().getLong());