Repository: sympy/sympy

Issue:
limit(x**n, x, -oo) is sometimes wrong
For example,

``` python
>>> n = Symbol('n', integer=True, positive=True)  # could be 3
>>> limit(x**n, x, -oo)
oo
```

while

``` python
>>> limit(x**3, x, -oo)
-oo
```

It looks like it assumes `n` is even, because stating `odd=True` for `n` seems to solve this issue.


Discussion:

Patch:
diff --git a/sympy/series/limits.py b/sympy/series/limits.py
index d2d746d976..174ce38967 100644
--- a/sympy/series/limits.py
+++ b/sympy/series/limits.py
@@ -353,20 +353,12 @@ def set_signs(expr):
                 elif ex == 0:
                     return coeff
                 elif ex.is_negative:
-                    if ex.is_integer:
-                        if cdir == 1 or ex.is_even:
-                            return S.Infinity*sign(coeff)
-                        elif cdir == -1:
-                            return S.NegativeInfinity*sign(coeff)
-                        else:
-                            return S.ComplexInfinity
+                    if cdir == 1:
+                        return S.Infinity*sign(coeff)
+                    elif cdir == -1:
+                        return S.NegativeInfinity*sign(coeff)*S.NegativeOne**(S.One + ex)
                     else:
-                        if cdir == 1:
-                            return S.Infinity*sign(coeff)
-                        elif cdir == -1:
-                            return S.Infinity*sign(coeff)*S.NegativeOne**ex
-                        else:
-                            return S.ComplexInfinity
+                        return S.ComplexInfinity
                 else:
                     raise NotImplementedError("Not sure of sign of %s" % ex)
 


Test patch:
diff --git a/sympy/series/tests/test_limits.py b/sympy/series/tests/test_limits.py
index 4648931550..12829faef0 100644
--- a/sympy/series/tests/test_limits.py
+++ b/sympy/series/tests/test_limits.py
@@ -93,7 +93,7 @@ def test_basic1():
     assert limit(1/sqrt(x), x, 0, dir='-') == (-oo)*I
     assert limit(x**2, x, 0, dir='-') == 0
     assert limit(sqrt(x), x, 0, dir='-') == 0
-    assert limit(x**-pi, x, 0, dir='-') == oo/(-1)**pi
+    assert limit(x**-pi, x, 0, dir='-') == -oo*(-1)**(1 - pi)
     assert limit((1 + cos(x))**oo, x, 0) == Limit((cos(x) + 1)**oo, x, 0)
 
     # test pull request 22491
@@ -714,6 +714,12 @@ def test_issue_8462():
     assert limit(binomial(n, n/2) * 3 ** (-n), n, oo) == 0
 
 
+def test_issue_8634():
+    n = Symbol('n', integer=True, positive=True)
+    x = Symbol('x')
+    assert limit(x**n, x, -oo) == oo*sign((-1)**n)
+
+
 def test_issue_8635_18176():
     x = Symbol('x', real=True)
     k = Symbol('k', positive=True)