diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/theory/arith/arith_rewriter.cpp | 35 | ||||
-rw-r--r-- | src/util/integer.h | 2 | ||||
-rw-r--r-- | src/util/rational.h | 18 |
3 files changed, 42 insertions, 13 deletions
diff --git a/src/theory/arith/arith_rewriter.cpp b/src/theory/arith/arith_rewriter.cpp index 6f1df5958..9ec5c9499 100644 --- a/src/theory/arith/arith_rewriter.cpp +++ b/src/theory/arith/arith_rewriter.cpp @@ -265,8 +265,11 @@ Node ArithRewriter::rewritePlus(TNode t){ 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; @@ -279,6 +282,7 @@ Node ArithRewriter::rewritePlus(TNode t){ 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; } @@ -312,22 +316,31 @@ Node ArithRewriter::rewriteMult(TNode t){ 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); diff --git a/src/util/integer.h b/src/util/integer.h index c019144a9..41582d8db 100644 --- a/src/util/integer.h +++ b/src/util/integer.h @@ -56,7 +56,7 @@ public: * 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) {} diff --git a/src/util/rational.h b/src/util/rational.h index 53a7e9060..8218984a7 100644 --- a/src/util/rational.h +++ b/src/util/rational.h @@ -75,7 +75,7 @@ public: * 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) { @@ -90,6 +90,22 @@ public: } /** + * 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. */ Rational(signed int n, signed int d) : d_value(n,d) { |