From 0c7b386201bff979f58b6e79d4b1e407334659cc Mon Sep 17 00:00:00 2001 From: Richard Kreckel Date: Fri, 29 Apr 2016 07:31:20 +0200 Subject: [PATCH] More shortcuts for trivial cases in mul::combine_*_to_pair(). --- ginac/mul.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/ginac/mul.cpp b/ginac/mul.cpp index 15dee661..9ba3b2c6 100644 --- a/ginac/mul.cpp +++ b/ginac/mul.cpp @@ -962,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)); } @@ -978,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); -- 2.44.0