Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix powsimp issues #9183, #10095, and KeyError #13131

Merged
merged 6 commits into from Sep 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions sympy/core/power.py
Expand Up @@ -1174,6 +1174,11 @@ def as_numer_denom(self):
if neg_exp:
n, d = d, n
exp = -exp
if exp.is_infinite:
if n is S.One and d is not S.One:
return n, self.func(d, exp)
if n is not S.One and d is S.One:
return self.func(n, exp), d
return self.func(n, exp), self.func(d, exp)

def matches(self, expr, repl_dict={}, old=False):
Expand Down
4 changes: 2 additions & 2 deletions sympy/simplify/powsimp.py
Expand Up @@ -163,7 +163,7 @@ def recurse(arg, **kwargs):
# allow 2**x/4 -> 2**(x - 2); don't do this when b and e are
# Numbers since autoevaluation will undo it, e.g.
# 2**(1/3)/4 -> 2**(1/3 - 2) -> 2**(1/3)/4
if (b and b.is_Number and not all(ei.is_Number for ei in e) and \
if (b and b.is_Rational and not all(ei.is_Number for ei in e) and \
coeff is not S.One and
b not in (S.One, S.NegativeOne)):
m = multiplicity(abs(b), abs(coeff))
Expand Down Expand Up @@ -276,7 +276,7 @@ def update(b):
bases = []
for b, e in c_powers:
b, e = bkey(b, e)
if b in common_b.keys():
if b in common_b:
common_b[b] = common_b[b] + e
else:
common_b[b] = e
Expand Down
12 changes: 11 additions & 1 deletion sympy/simplify/tests/test_powsimp.py
@@ -1,7 +1,7 @@
from sympy import (
symbols, powsimp, symbols, MatrixSymbol, sqrt, pi, Mul, gamma, Function,
S, I, exp, simplify, sin, E, log, hyper, Symbol, Dummy, powdenest, root,
Rational)
Rational, oo)

from sympy.abc import x, y, z, t, a, b, c, d, e, f, g, h, i, k

Expand Down Expand Up @@ -98,6 +98,16 @@ def test_powsimp():
# issue 8836
assert str( powsimp(exp(I*pi/3)*root(-1,3)) ) == '(-1)**(2/3)'

# issue 9183
assert powsimp(-0.1**x) == -0.1**x

# issue 10095
assert powsimp((1/(2*E))**oo) == (exp(-1)/2)**oo

# PR 13131
eq = sin(2*x)**2*sin(2.0*x)**2
assert powsimp(eq) == eq


def test_powsimp_negated_base():
assert powsimp((-x + y)/sqrt(x - y)) == -sqrt(x - y)
Expand Down