[PATCH] Fix bug in evaluation of real and imaginary parts of powers.
authorVladimir V. Kisil <kisilv@maths.leeds.ac.uk>
Mon, 11 Sep 2017 21:12:36 +0000 (23:12 +0200)
committerRichard Kreckel <kreckel@ginac.de>
Mon, 11 Sep 2017 21:12:36 +0000 (23:12 +0200)
Be more careful when simplifying Re(a^c) -> a^c and Im(a^c) -> 0.

Thanks to Jan Rheinländer for reporting this.

ginac/power.cpp

index 2619492..a45e1fa 100644 (file)
@@ -669,7 +669,8 @@ ex power::real_part() const
        // basis == a+I*b, exponent == c+I*d
        const ex a = basis.real_part();
        const ex c = exponent.real_part();
-       if (basis.is_equal(a) && exponent.is_equal(c)) {
+       if (basis.is_equal(a) && exponent.is_equal(c) &&
+           (a.info(info_flags::nonnegative) || c.info(info_flags::integer))) {
                // Re(a^c)
                return *this;
        }
@@ -704,7 +705,8 @@ ex power::imag_part() const
        // basis == a+I*b, exponent == c+I*d
        const ex a = basis.real_part();
        const ex c = exponent.real_part();
-       if (basis.is_equal(a) && exponent.is_equal(c)) {
+       if (basis.is_equal(a) && exponent.is_equal(c) &&
+           (a.info(info_flags::nonnegative) || c.info(info_flags::integer))) {
                // Im(a^c)
                return 0;
        }