* @param lcm LCM to multiply in */
static ex multiply_lcm(const ex &e, const numeric &lcm)
{
* @param lcm LCM to multiply in */
static ex multiply_lcm(const ex &e, const numeric &lcm)
{
numeric lcm_accum = *_num1_p;
for (size_t i=0; i<num; i++) {
numeric op_lcm = lcmcoeff(e.op(i), *_num1_p);
numeric lcm_accum = *_num1_p;
for (size_t i=0; i<num; i++) {
numeric op_lcm = lcmcoeff(e.op(i), *_num1_p);
v.push_back(lcm / lcm_accum);
return dynallocate<mul>(v);
} else if (is_exactly_a<add>(e)) {
v.push_back(lcm / lcm_accum);
return dynallocate<mul>(v);
} else if (is_exactly_a<add>(e)) {
for (size_t i=0; i<num; i++)
v.push_back(multiply_lcm(e.op(i), lcm));
return dynallocate<add>(v);
} else if (is_exactly_a<power>(e)) {
for (size_t i=0; i<num; i++)
v.push_back(multiply_lcm(e.op(i), lcm));
return dynallocate<add>(v);
} else if (is_exactly_a<power>(e)) {
- if (is_a<symbol>(e.op(0)))
- return e * lcm;
- else {
+ if (!is_a<symbol>(e.op(0))) {
+ // (b^e)*lcm -> (b*lcm^(1/e))^e if lcm^(1/e) ∈ ℝ (i.e. not a float)
+ // but not for symbolic b, as evaluation would undo this again
numeric root_of_lcm = lcm.power(ex_to<numeric>(e.op(1)).inverse());
if (root_of_lcm.is_rational())
return pow(multiply_lcm(e.op(0), root_of_lcm), e.op(1));
numeric root_of_lcm = lcm.power(ex_to<numeric>(e.op(1)).inverse());
if (root_of_lcm.is_rational())
return pow(multiply_lcm(e.op(0), root_of_lcm), e.op(1));