Repository: sympy/sympy

Issue:
simplify throws unexpected ValueError
The following error was unexpected for me and I could not find anything about it in the docs so I thought I'd report it. Hope it helps.

kind regards,
Jesse

this works fine:

> > > a=sympy.sympify('0.12**d+43') - sympy.sympify('0.12*d+43')
> > > a.simplify()
> > > 0.12**d - 0.12*d

however, the reverse throws an exception:

> > > a=sympy.sympify('0.12_d+43') - sympy.sympify('0.12__d+43')
> > > a
> > > -0.12__d + 0.12_d
> > > a.simplify()
> > > Traceback (most recent call last):
> > >   File "<interactive input>", line 1, in <module>
> > >   File "C:\Python34\lib\site-packages\sympy\core\expr.py", line 2922, in simplify
> > >     return simplify(self, ratio, measure)
> > >   File "C:\Python34\lib\site-packages\sympy\simplify\simplify.py", line 3684, in simplify
> > >     expr = Mul(_powsimp(expr).as_content_primitive())
> > >   File "C:\Python34\lib\site-packages\sympy\simplify\simplify.py", line 2549, in powsimp
> > >     expr = expr.func(_[recurse(w) for w in expr.args])
> > >   File "C:\Python34\lib\site-packages\sympy\simplify\simplify.py", line 2549, in <listcomp>
> > >     expr = expr.func(*[recurse(w) for w in expr.args])
> > >   File "C:\Python34\lib\site-packages\sympy\simplify\simplify.py", line 2540, in recurse
> > >     return powsimp(arg, _deep, _combine, _force, _measure)
> > >   File "C:\Python34\lib\site-packages\sympy\simplify\simplify.py", line 2597, in powsimp
> > >     m = multiplicity(abs(b), abs(coeff))
> > >   File "C:\Python34\lib\site-packages\sympy\ntheory\factor_.py", line 230, in multiplicity
> > >     raise ValueError('expecting ints or fractions, got %s and %s' % (p, n))
> > > ValueError: expecting ints or fractions, got 0.120000000000000 and 1


Discussion:

Patch:
diff --git a/sympy/core/power.py b/sympy/core/power.py
index 82bc545f33..2c31134dc4 100644
--- a/sympy/core/power.py
+++ b/sympy/core/power.py
@@ -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):
diff --git a/sympy/simplify/powsimp.py b/sympy/simplify/powsimp.py
index 3cf646ca4d..045c04760d 100644
--- a/sympy/simplify/powsimp.py
+++ b/sympy/simplify/powsimp.py
@@ -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))
@@ -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


Test patch:
diff --git a/sympy/simplify/tests/test_powsimp.py b/sympy/simplify/tests/test_powsimp.py
index 8c80867ddf..6a41c23637 100644
--- a/sympy/simplify/tests/test_powsimp.py
+++ b/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
 
@@ -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)