- non-integer powers are treated as 0 by (l)degree() and coeff()
[ginac.git] / ginac / mul.cpp
index b9bae4456a638c0c8f165ba772c7dcd789e4317c..ad7aa13e3d5e5568241398f18ab55788241e94ad 100644 (file)
@@ -310,7 +310,8 @@ int mul::degree(const symbol & s) const
 {
        int deg_sum = 0;
        for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
-               deg_sum+=(*cit).rest.degree(s) * ex_to_numeric((*cit).coeff).to_int();
+               if (ex_to_numeric(cit->coeff).is_integer())
+                       deg_sum+=cit->rest.degree(s) * ex_to_numeric(cit->coeff).to_int();
        }
        return deg_sum;
 }
@@ -319,7 +320,8 @@ int mul::ldegree(const symbol & s) const
 {
        int deg_sum = 0;
        for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
-               deg_sum+=(*cit).rest.ldegree(s) * ex_to_numeric((*cit).coeff).to_int();
+               if (ex_to_numeric(cit->coeff).is_integer())
+                       deg_sum+=cit->rest.ldegree(s) * ex_to_numeric(cit->coeff).to_int();
        }
        return deg_sum;
 }
@@ -412,21 +414,19 @@ ex mul::eval(int level) const
                // *(x;1) -> x
                return recombine_pair_to_ex(*(seq.begin()));
        } else if ((seq_size==1) &&
-                          is_ex_exactly_of_type((*seq.begin()).rest,add) &&
-                          ex_to_numeric((*seq.begin()).coeff).is_equal(_num1())) {
+                  is_ex_exactly_of_type((*seq.begin()).rest,add) &&
+                  ex_to_numeric((*seq.begin()).coeff).is_equal(_num1())) {
                // *(+(x,y,...);c) -> +(*(x,c),*(y,c),...) (c numeric(), no powers of +())
                const add & addref=ex_to_add((*seq.begin()).rest);
                epvector distrseq;
                distrseq.reserve(addref.seq.size());
                for (epvector::const_iterator cit=addref.seq.begin(); cit!=addref.seq.end(); ++cit) {
-                       distrseq.push_back(addref.combine_pair_with_coeff_to_pair(*cit,
-                                                                  overall_coeff));
+                       distrseq.push_back(addref.combine_pair_with_coeff_to_pair(*cit, overall_coeff));
                }
                return (new add(distrseq,
-                                               ex_to_numeric(addref.overall_coeff).
-                                               mul_dyn(ex_to_numeric(overall_coeff))))
-                       ->setflag(status_flags::dynallocated |
-                                         status_flags::evaluated);
+                               ex_to_numeric(addref.overall_coeff).
+                               mul_dyn(ex_to_numeric(overall_coeff))))
+                     ->setflag(status_flags::dynallocated | status_flags::evaluated);
        }
        return this->hold();
 }
@@ -445,7 +445,7 @@ ex mul::evalf(int level) const
        --level;
        for (epvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
                s.push_back(combine_ex_with_coeff_to_pair((*it).rest.evalf(level),
-                                                                                                 (*it).coeff));
+                                                         (*it).coeff));
        }
        return mul(s,overall_coeff.evalf(level));
 }
@@ -481,8 +481,8 @@ ex mul::derivative(const symbol & s) const
        // D(a*b*c) = D(a)*b*c + a*D(b)*c + a*b*D(c)
        for (unsigned i=0; i!=seq.size(); ++i) {
                epvector mulseq = seq;
-               mulseq[i] = split_ex_to_pair(power(seq[i].rest,seq[i].coeff - _ex1())*
-                                                                        seq[i].rest.diff(s));
+               mulseq[i] = split_ex_to_pair(power(seq[i].rest,seq[i].coeff - _ex1()) *
+                                            seq[i].rest.diff(s));
                addseq.push_back((new mul(mulseq,overall_coeff*seq[i].coeff))->setflag(status_flags::dynallocated));
        }
        return (new add(addseq))->setflag(status_flags::dynallocated);
@@ -567,7 +567,7 @@ expair mul::split_ex_to_pair(const ex & e) const
 }
        
 expair mul::combine_ex_with_coeff_to_pair(const ex & e,
-                                                                                 const ex & c) const
+                                          const ex & c) const
 {
        // to avoid duplication of power simplification rules,
        // we create a temporary power object
@@ -580,7 +580,7 @@ expair mul::combine_ex_with_coeff_to_pair(const ex & e,
 }
        
 expair mul::combine_pair_with_coeff_to_pair(const expair & p,
-                                                                                       const ex & c) const
+                                            const ex & c) const
 {
        // to avoid duplication of power simplification rules,
        // we create a temporary power object
@@ -640,8 +640,7 @@ void mul::combine_overall_coeff(const ex & c1, const ex & c2)
        GINAC_ASSERT(is_ex_exactly_of_type(overall_coeff,numeric));
        GINAC_ASSERT(is_ex_exactly_of_type(c1,numeric));
        GINAC_ASSERT(is_ex_exactly_of_type(c2,numeric));
-       overall_coeff = ex_to_numeric(overall_coeff).
-                                               mul_dyn(ex_to_numeric(c1).power(ex_to_numeric(c2)));
+       overall_coeff = ex_to_numeric(overall_coeff).mul_dyn(ex_to_numeric(c1).power(ex_to_numeric(c2)));
 }
 
 bool mul::can_make_flat(const expair & p) const
@@ -692,8 +691,7 @@ ex mul::expand(unsigned options) const
                        return this->setflag(status_flags::expanded);
                else
                        return ((new mul(expanded_seqp,overall_coeff))->
-                                       setflag(status_flags::dynallocated |
-                                                       status_flags::expanded));
+                              setflag(status_flags::dynallocated | status_flags::expanded));
        }
        
        exvector distrseq;
@@ -711,8 +709,7 @@ ex mul::expand(unsigned options) const
                        term[positions_of_adds[l]]=split_ex_to_pair(addref.op(k[l]));
                }
                distrseq.push_back((new mul(term,overall_coeff))->
-                                                  setflag(status_flags::dynallocated |
-                                                                  status_flags::expanded));
+                                   setflag(status_flags::dynallocated | status_flags::expanded));
                
                // increment k[]
                int l = number_of_adds-1;
@@ -789,7 +786,7 @@ unsigned mul::precedence = 50;
 //////////
 
 const mul some_mul;
-const type_info & typeid_mul = typeid(some_mul);
+const std::type_info & typeid_mul = typeid(some_mul);
 
 #ifndef NO_NAMESPACE_GINAC
 } // namespace GiNaC