]> www.ginac.de Git - ginac.git/blobdiff - ginac/pseries.cpp
sums of indexed matrices are now possible
[ginac.git] / ginac / pseries.cpp
index fbb7583b3bc1b0b10e7c16eacff1b86f5049fc24..3b2ac7010e051a5d2b49fb2dd90e65aab7c24b82 100644 (file)
@@ -175,7 +175,7 @@ void pseries::print(std::ostream &os, unsigned upper_precedence) const
 void pseries::printraw(std::ostream &os) const
 {
        debugmsg("pseries printraw", LOGLEVEL_PRINT);
-       os << "pseries(" << var << ";" << point << ";";
+       os << class_name() << "(" << var << ";" << point << ";";
        for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i)
                os << "(" << (*i).rest << "," << (*i).coeff << "),";
        os << ")";
@@ -185,7 +185,7 @@ void pseries::printraw(std::ostream &os) const
 void pseries::printtree(std::ostream & os, unsigned indent) const
 {
        debugmsg("pseries printtree",LOGLEVEL_PRINT);
-       os << std::string(indent,' ') << "pseries " 
+       os << std::string(indent,' ') << class_name()
           << ", hash=" << hashvalue
           << " (0x" << std::hex << hashvalue << std::dec << ")"
           << ", flags=" << flags << std::endl;
@@ -203,24 +203,32 @@ int pseries::compare_same_type(const basic & other) const
 {
        GINAC_ASSERT(is_of_type(other, pseries));
        const pseries &o = static_cast<const pseries &>(other);
-
+       
+       // first compare the lengths of the series...
+       if (seq.size()>o.seq.size())
+               return 1;
+       if (seq.size()<o.seq.size())
+               return -1;
+       
+       // ...then the expansion point...
        int cmpval = var.compare(o.var);
        if (cmpval)
                return cmpval;
        cmpval = point.compare(o.point);
        if (cmpval)
                return cmpval;
-
-       epvector::const_iterator it1 = seq.begin(), it2 = o.seq.begin(), it1end = seq.end(), it2end = o.seq.end();
-       while ((it1 != it1end) && (it2 != it2end)) {
-               cmpval = it1->compare(*it2);
+       
+       // ...and if that failed the individual elements
+       epvector::const_iterator it = seq.begin(), o_it = o.seq.begin();
+       while (it!=seq.end() && o_it!=o.seq.end()) {
+               cmpval = it->compare(*o_it);
                if (cmpval)
                        return cmpval;
-               it1++; it2++;
+               ++it;
+               ++o_it;
        }
-       if (it1 == it1end)
-               return it2 == it2end ? 0 : -1;
 
+       // so they are equal.
        return 0;
 }