X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fmul.cpp;h=16bbc5b229ac9f21c26bcadbfacb1a26c5b6790f;hp=9843e616dfa4c369d9b59fa313b330da23986fa2;hb=ec64e556734484ca3c518e6de95b26be61bedee7;hpb=47ecb72dce5ea9c917d1e1e77863c45a8b2b1bba diff --git a/ginac/mul.cpp b/ginac/mul.cpp index 9843e616..16bbc5b2 100644 --- a/ginac/mul.cpp +++ b/ginac/mul.cpp @@ -3,7 +3,7 @@ * Implementation of GiNaC's products of expressions. */ /* - * GiNaC Copyright (C) 1999-2016 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2019 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 @@ -574,22 +574,14 @@ ex mul::eval() const return this->hold(); } -ex mul::evalf(int level) const +ex mul::evalf() const { - if (level==1) - return mul(seq, overall_coeff); - - if (level==-max_recursion_level) - throw(std::runtime_error("max recursion level reached")); - epvector s; s.reserve(seq.size()); - --level; - for (auto & it : seq) { - s.push_back(expair(it.rest.evalf(level), it.coeff)); - } - return dynallocate(std::move(s), overall_coeff.evalf(level)); + for (auto & it : seq) + s.push_back(expair(it.rest.evalf(), it.coeff)); + return dynallocate(std::move(s), overall_coeff.evalf()); } void mul::find_real_imag(ex & rp, ex & ip) const @@ -970,13 +962,14 @@ expair mul::combine_ex_with_coeff_to_pair(const ex & e, if (is_exactly_a(e)) return expair(e, c); + // trivial case: exponent 1 + if (c.is_equal(_ex1)) + return split_ex_to_pair(e); + // to avoid duplication of power simplification rules, // we create a temporary power object // otherwise it would be hard to correctly evaluate // expression like (4^(1/3))^(3/2) - if (c.is_equal(_ex1)) - return split_ex_to_pair(e); - return split_ex_to_pair(pow(e,c)); } @@ -986,19 +979,26 @@ expair mul::combine_pair_with_coeff_to_pair(const expair & p, GINAC_ASSERT(is_exactly_a(p.coeff)); GINAC_ASSERT(is_exactly_a(c)); + // First, try a common shortcut: + if (is_exactly_a(p.rest)) + return expair(p.rest, p.coeff * c); + + // trivial case: exponent 1 + if (c.is_equal(_ex1)) + return p; + if (p.coeff.is_equal(_ex1)) + return expair(p.rest, c); + // to avoid duplication of power simplification rules, // we create a temporary power object // otherwise it would be hard to correctly evaluate // expression like (4^(1/3))^(3/2) - if (c.is_equal(_ex1)) - return p; - return split_ex_to_pair(pow(recombine_pair_to_ex(p),c)); } ex mul::recombine_pair_to_ex(const expair & p) const { - if (ex_to(p.coeff).is_equal(*_num1_p)) + if (p.coeff.is_equal(_ex1)) return p.rest; else return dynallocate(p.rest, p.coeff);