]> www.ginac.de Git - ginac.git/blobdiff - ginac/pseries.cpp
fixed another power::series() bug [Alexei Sheplyakov]
[ginac.git] / ginac / pseries.cpp
index eaef6388aa1d5143ec9787af3315309272f26bfc..4ec5bcefca4e1f559a7b326f9b9c400fc5f55f4f 100644 (file)
@@ -798,8 +798,7 @@ ex mul::series(const relational & r, int order, unsigned options) const
                int real_ldegree = 0;
                try {
                        real_ldegree = buf.expand().ldegree(sym-r.rhs());
-               }
-               catch (std::runtime_error) {}
+               } catch (std::runtime_error) {}
 
                if (real_ldegree == 0) {
                        int orderloop = 0;
@@ -814,7 +813,7 @@ ex mul::series(const relational & r, int order, unsigned options) const
 
        int degsum = std::accumulate(ldegrees.begin(), ldegrees.end(), 0);
 
-       if (degsum>order) {
+       if (degsum >= order) {
                epvector epv;
                epv.push_back(expair(Order(_ex1), order));
                return (new pseries(r, epv))->setflag(status_flags::dynallocated);
@@ -828,7 +827,7 @@ ex mul::series(const relational & r, int order, unsigned options) const
                ex op = recombine_pair_to_ex(*it).series(r, order-degsum+(*itd), options);
 
                // Series multiplication
-               if (it==itbeg)
+               if (it == itbeg)
                        acc = ex_to<pseries>(op);
                else
                        acc = ex_to<pseries>(acc.mul_series(ex_to<pseries>(op)));
@@ -953,11 +952,13 @@ ex power::series(const relational & r, int order, unsigned options) const
        }
 
        // Is the expression of type something^(-int)?
-       if (!must_expand_basis && !exponent.info(info_flags::negint) && !is_a<add>(basis))
+       if (!must_expand_basis && !exponent.info(info_flags::negint)
+        && (!is_a<add>(basis) || !is_a<numeric>(exponent)))
                return basic::series(r, order, options);
 
        // Is the expression of type 0^something?
-       if (!must_expand_basis && !basis.subs(r, subs_options::no_pattern).is_zero() && !is_a<add>(basis))
+       if (!must_expand_basis && !basis.subs(r, subs_options::no_pattern).is_zero()
+        && (!is_a<add>(basis) || !is_a<numeric>(exponent)))
                return basic::series(r, order, options);
 
        // Singularity encountered, is the basis equal to (var - point)?
@@ -972,7 +973,12 @@ ex power::series(const relational & r, int order, unsigned options) const
 
        // No, expand basis into series
 
-       numeric numexp = ex_to<numeric>(exponent);
+       numeric numexp;
+       if (is_a<numeric>(exponent)) {
+               numexp = ex_to<numeric>(exponent);
+       } else {
+               numexp = 0;
+       }
        const ex& sym = r.lhs();
        // find existing minimal degree
        int real_ldegree = basis.expand().ldegree(sym-r.rhs());