]> www.ginac.de Git - ginac.git/blobdiff - ginac/expairseq.cpp
Fixed bug in ::match.
[ginac.git] / ginac / expairseq.cpp
index bd1604e1f4e94a5277d39eff4a32dc121af02295..9d72a7873c45ee23a4a4ceb0236a62571dfafe09 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "expairseq.h"
 #include "lst.h"
+#include "add.h"
 #include "mul.h"
 #include "power.h"
 #include "relational.h"
@@ -347,6 +348,17 @@ ex expairseq::conjugate() const
        return result;
 }
 
+bool expairseq::is_polynomial(const ex & var) const
+{
+       if (!is_exactly_a<add>(*this) && !is_exactly_a<mul>(*this))
+               return basic::is_polynomial(var);
+       for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i) {
+               if (!(i->rest).is_polynomial(var))
+                       return false;
+       }
+       return true;
+}
+
 bool expairseq::match(const ex & pattern, lst & repl_lst) const
 {
        // This differs from basic::match() because we want "a+b+c+d" to
@@ -383,10 +395,20 @@ bool expairseq::match(const ex & pattern, lst & repl_lst) const
                                continue;
                        exvector::iterator it = ops.begin(), itend = ops.end();
                        while (it != itend) {
+                               lst::const_iterator last_el = repl_lst.end();
+                               --last_el;
                                if (it->match(p, repl_lst)) {
                                        ops.erase(it);
                                        goto found;
                                }
+                               while(true) {
+                                       lst::const_iterator next_el = last_el;
+                                       ++next_el;
+                                       if(next_el == repl_lst.end())
+                                               break;
+                                       else
+                                               repl_lst.remove_last();
+                               }
                                ++it;
                        }
                        return false; // no match found
@@ -571,7 +593,7 @@ unsigned expairseq::return_type() const
 
 unsigned expairseq::calchash() const
 {
-       unsigned v = golden_ratio_hash((unsigned)this->tinfo());
+       unsigned v = golden_ratio_hash((p_int)this->tinfo());
        epvector::const_iterator i = seq.begin();
        const epvector::const_iterator end = seq.end();
        while (i != end) {