Repository: sympy/sympy

Issue:
Simple limit crashes
Tried versions: 1.7, 1.8. 1.9rc1

```python
from sympy import *

expression = sympify("(-1)**n * 2**(-n)")
print(limit(expression, Symbol("n"), oo))
```

The limit of `(-1)**n * 2**(-n)` as `n` to `oo` is obviously `0`, but sympy crashes. 


Discussion:
sympy-bot: 

Hi, I am the [SymPy bot](https://github.com/sympy/sympy-bot) (v161). I'm here to help you write a release notes entry. Please read the [guide on how to write release notes](https://github.com/sympy/sympy/wiki/Writing-Release-Notes).

:x: There was an issue with the release notes. **Please do not close this pull request;** instead edit the description after reading the [guide on how to write release notes](https://github.com/sympy/sympy/wiki/Writing-Release-Notes).

* No subheader found. Please add a header for the module, for example,

  ```
  * solvers
    * improve solving of trig equations
  ```

  A list of valid headers can be found at https://github.com/sympy/sympy-bot/blob/master/sympy_bot/submodules.txt.

<details><summary>Click here to see the pull request description that was parsed.</summary>

    <!-- Your title above should be a short description of what
    was changed. Do not include the issue number in the title. -->

    #### References to other Issues or PRs
    <!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
    format, e.g. "Fixes #1234" (see
    https://tinyurl.com/auto-closing for more information). Also, please
    write a comment on that issue linking back to this pull request once it is
    open. -->
    Fixes #22181 

    #### Brief description of what is fixed or changed
    Previously, `(-1)**(1/n)` (1/n as sympy substitutes to bring n->0) is rewritten as `exp(I*pi/n)` and `2**(1/n)` is rewritten as `exp(log(2)/n)` which leads to the `NotImplementedError` with `(-log(2) + I*pi)`.
    Now the expression is first `powsimp`lified in case it is a `Mul` with `z0` as infinite.

    #### Release Notes

    <!-- Write the release notes for this release below between the BEGIN and END
    statements. The basic format is a bulleted list with the name of the subpackage
    and the release note for this PR. For example:

    * solvers
      * Added a new solver for logarithmic equations.

    * functions
      * Fixed a bug with log of integers.

    or if no release note(s) should be included use:

    NO ENTRY

    See https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more
    information on how to write release notes. The bot will check your release
    notes automatically to see if they are formatted correctly. -->

    <!-- BEGIN RELEASE NOTES -->
     * series
       * Fixed a bug due to insufficient power simplification in limits
    <!-- END RELEASE NOTES -->


</details><p>

github-actions[bot]: Benchmark results from GitHub Actions

Lower numbers are good, higher numbers are bad. A ratio less than 1
means a speed up and greater than 1 means a slowdown. Green lines
beginning with `+` are slowdowns (the PR is slower then master or
master is slower than the previous release). Red lines beginning
with `-` are speedups.

Significantly changed benchmark results (PR vs master)
```diff

```
Significantly changed benchmark results (master vs previous release)
```diff

```
Full benchmark results can be found as artifacts in GitHub Actions
(click on checks at the top of the PR).

Patch:
diff --git a/sympy/series/limits.py b/sympy/series/limits.py
index 5b5b83d107..a085ddcd37 100644
--- a/sympy/series/limits.py
+++ b/sympy/series/limits.py
@@ -175,20 +175,20 @@ def free_symbols(self):
         return isyms
 
 
-    def pow_heuristics(self):
+    def pow_heuristics(self, e):
         from sympy import exp, log
-        expr, z, z0, _ = self.args
-        b, e = expr.base, expr.exp
-        if not b.has(z):
-            res = limit(e*log(b), z, z0)
+        _, z, z0, _ = self.args
+        b1, e1 = e.base, e.exp
+        if not b1.has(z):
+            res = limit(e1*log(b1), z, z0)
             return exp(res)
 
-        ex_lim = limit(e, z, z0)
-        base_lim = limit(b, z, z0)
+        ex_lim = limit(e1, z, z0)
+        base_lim = limit(b1, z, z0)
 
         if base_lim is S.One:
             if ex_lim in (S.Infinity, S.NegativeInfinity):
-                res = limit(e*(b - 1), z, z0)
+                res = limit(e1*(b1 - 1), z, z0)
                 return exp(res)
         if base_lim is S.NegativeInfinity and ex_lim is S.Infinity:
             return S.ComplexInfinity
@@ -207,7 +207,7 @@ def doit(self, **hints):
         hints : optional keyword arguments
             To be passed to ``doit`` methods; only used if deep is True.
         """
-        from sympy import Abs, sign
+        from sympy import Abs, powsimp, sign
 
         e, z, z0, dir = self.args
 
@@ -295,8 +295,9 @@ def set_signs(expr):
             coeff, ex = newe.leadterm(z, cdir=cdir)
         except (ValueError, NotImplementedError, PoleError):
             # The NotImplementedError catching is for custom functions
+            e = powsimp(e)
             if e.is_Pow:
-                r = self.pow_heuristics()
+                r = self.pow_heuristics(e)
                 if r is not None:
                     return r
         else:


Test patch:
diff --git a/sympy/series/tests/test_limits.py b/sympy/series/tests/test_limits.py
index 9ac7a02619..6c324df14c 100644
--- a/sympy/series/tests/test_limits.py
+++ b/sympy/series/tests/test_limits.py
@@ -1010,3 +1010,7 @@ def test_issue_21756():
 def test_issue_21785():
     a = Symbol('a')
     assert sqrt((-a**2 + x**2)/(1 - x**2)).limit(a, 1, '-') == I
+
+
+def test_issue_22181():
+    assert limit((-1)**x * 2**(-x), x, oo) == 0