]> www.ginac.de Git - ginac.git/blobdiff - ginac/mul.cpp
Happy new year!
[ginac.git] / ginac / mul.cpp
index b7e0e827bb040189d8915987f3162437d245cbd5..dce2a8e600682ddca03be727fa2da8c508511fc2 100644 (file)
@@ -3,7 +3,7 @@
  *  Implementation of GiNaC's products of expressions. */
 
 /*
- *  GiNaC Copyright (C) 1999-2007 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2008 Johannes Gutenberg University Mainz, Germany
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -317,7 +317,7 @@ int mul::degree(const ex & s) const
        epvector::const_iterator i = seq.begin(), end = seq.end();
        while (i != end) {
                if (ex_to<numeric>(i->coeff).is_integer())
-                       deg_sum += i->rest.degree(s) * ex_to<numeric>(i->coeff).to_int();
+                       deg_sum += recombine_pair_to_ex(*i).degree(s);
                ++i;
        }
        return deg_sum;
@@ -330,7 +330,7 @@ int mul::ldegree(const ex & s) const
        epvector::const_iterator i = seq.begin(), end = seq.end();
        while (i != end) {
                if (ex_to<numeric>(i->coeff).is_integer())
-                       deg_sum += i->rest.ldegree(s) * ex_to<numeric>(i->coeff).to_int();
+                       deg_sum += recombine_pair_to_ex(*i).ldegree(s);
                ++i;
        }
        return deg_sum;
@@ -461,8 +461,8 @@ ex mul::eval(int level) const
 
                        // XXX: What is the best way to check if the polynomial is a primitive? 
                        numeric c = i->rest.integer_content();
-                       const numeric& lead_coeff =
-                               ex_to<numeric>(ex_to<add>(i->rest).seq.begin()->coeff).div_dyn(c);
+                       const numeric lead_coeff =
+                               ex_to<numeric>(ex_to<add>(i->rest).seq.begin()->coeff).div(c);
                        const bool canonicalizable = lead_coeff.is_integer();
 
                        // XXX: The main variable is chosen in a random way, so this code 
@@ -942,12 +942,14 @@ bool mul::can_be_further_expanded(const ex & e)
 ex mul::expand(unsigned options) const
 {
        {
-       // trivial case: expanding the monomial (~ 30% of all calls)
+       // trivial case: expanding the monomial (~ 30% of all calls)
                epvector::const_iterator i = seq.begin(), seq_end = seq.end();
                while ((i != seq.end()) &&  is_a<symbol>(i->rest) && i->coeff.info(info_flags::integer))
                        ++i;
-               if (i == seq_end)
-                       return (new mul(*this))->setflag(status_flags::dynallocated | status_flags::expanded);
+               if (i == seq_end) {
+                       setflag(status_flags::expanded);
+                       return *this;
+               }
        }
 
        // do not rename indices if the object has no indices at all