X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fpower.cpp;h=b12ff8a44299351bf082e8be20782059fcecc014;hp=b2622d60e932410997b625bc8ac79e5be4e6541b;hb=85f46b3d72dbafb6fe1fbb9bca32ec612cf8b480;hpb=cc308418b3e239e05a7f1f0f6cfc5919672fccfd diff --git a/ginac/power.cpp b/ginac/power.cpp index b2622d60..b12ff8a4 100644 --- a/ginac/power.cpp +++ b/ginac/power.cpp @@ -571,7 +571,7 @@ ex power::eval(int level) const if (num_exponent->is_pos_integer() && ebasis.return_type() != return_types::commutative && !is_a(ebasis)) { - return ncmul(exvector(num_exponent->to_int(), ebasis), true); + return ncmul(exvector(num_exponent->to_int(), ebasis)); } } @@ -1091,7 +1091,7 @@ public: * where n = p1+p2+...+pk, i.e. p is a partition of n. */ const numeric -multinomial_coefficient(const std::vector p) +multinomial_coefficient(const std::vector & p) { numeric n = 0, d = 1; for (auto & it : p) { @@ -1207,7 +1207,6 @@ ex power::expand_add(const add & a, int n, unsigned options) const numeric factor = coeff; for (unsigned i = 0; i < exponent.size(); ++i) { const ex & r = a.seq[i].rest; - const ex & c = a.seq[i].coeff; GINAC_ASSERT(!is_exactly_a(r)); GINAC_ASSERT(!is_exactly_a(r) || !is_exactly_a(ex_to(r).exponent) || @@ -1215,15 +1214,19 @@ ex power::expand_add(const add & a, int n, unsigned options) const !is_exactly_a(ex_to(r).basis) || !is_exactly_a(ex_to(r).basis) || !is_exactly_a(ex_to(r).basis)); + GINAC_ASSERT(is_exactly_a(a.seq[i].coeff)); + const numeric & c = ex_to(a.seq[i].coeff); if (exponent[i] == 0) { // optimize away } else if (exponent[i] == 1) { // optimized term.push_back(r); - factor = factor.mul(ex_to(c)); + if (c != *_num1_p) + factor = factor.mul(c); } else { // general case exponent[i] > 1 term.push_back((new power(r, exponent[i]))->setflag(status_flags::dynallocated)); - factor = factor.mul(ex_to(c).power(exponent[i])); + if (c != *_num1_p) + factor = factor.mul(c.power(exponent[i])); } } result.push_back(a.combine_ex_with_coeff_to_pair(mul(term).expand(options), factor));