]> www.ginac.de Git - ginac.git/commitdiff
[bugfix] fix elusive bug in quo, rem,...
authorRichard Kreckel <kreckel@ginac.de>
Fri, 5 Feb 2016 23:47:08 +0000 (00:47 +0100)
committerRichard Kreckel <kreckel@ginac.de>
Sat, 6 Feb 2016 00:00:55 +0000 (01:00 +0100)
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

index a8a1e1eb1bd3f7282418eff3160f2ba1a25114e6..a1e2de48c9f598fd09c915dd026e16211d2fde70 100644 (file)
@@ -290,8 +290,13 @@ static ex multiply_lcm(const ex &e, const numeric &lcm)
        } else if (is_exactly_a<power>(e)) {
                if (is_a<symbol>(e.op(0)))
                        return e * lcm;
-               else
-                       return pow(multiply_lcm(e.op(0), lcm.power(ex_to<numeric>(e.op(1)).inverse())), e.op(1));
+               else {
+                       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));
+                       else
+                               return e * lcm;
+               }
        } else
                return e * lcm;
 }