From 054495cd8a0bb3f71e898a290bfdc026fc0fc5bb Mon Sep 17 00:00:00 2001 From: Richard Kreckel Date: Sat, 6 Feb 2016 00:47:08 +0100 Subject: [PATCH 1/1] [bugfix] fix elusive bug in quo, rem,... The power of two rational numeric objects needs not be rational. As a result, some care is required when transforming (b^e)*l -> (b*l^(1/e))^e for some rational e and l. This is a common transformation in order to convert a polynomial over Q into a polynomial over Z when computing their quotient, remainder, etc. Failure to be careful can potentially introduce spurious non-rational numbers into rational polynomials and make those operations fail. This patch avoids this transformation when l^(1/e) is not a rational number. --- ginac/normal.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ginac/normal.cpp b/ginac/normal.cpp index a8a1e1eb..a1e2de48 100644 --- a/ginac/normal.cpp +++ b/ginac/normal.cpp @@ -290,8 +290,13 @@ static ex multiply_lcm(const ex &e, const numeric &lcm) } else if (is_exactly_a(e)) { if (is_a(e.op(0))) return e * lcm; - else - return pow(multiply_lcm(e.op(0), lcm.power(ex_to(e.op(1)).inverse())), e.op(1)); + else { + numeric root_of_lcm = lcm.power(ex_to(e.op(1)).inverse()); + if (root_of_lcm.is_rational()) + return pow(multiply_lcm(e.op(0), root_of_lcm), e.op(1)); + else + return e * lcm; + } } else return e * lcm; } -- 2.44.0