# HG changeset patch
# User Stepan Roucka <[EMAIL PROTECTED]>
# Date 1223756894 -7200
# Node ID 8b4b931bb77dee53e3d235592a7aa7c8c8ff96a6
# Parent  7f83ede93315ccf9c350629753d51ade7b960798
Implement simplification of reciprocal of power

In the rules for simplifying exponentiation implemented recently, I forgot
to implement one important relation for complex x and y:
1/x**y = x**(-y)
This patch adds this functionality. As a side effect it also fixes the problem
with failing heurisch test in issue 1130 so the xfail is removed.

One test in test_ccode is changed because of this simplification and unneeded
assumptions from docstrings are removed.

diff --git a/sympy/core/evalf.py b/sympy/core/evalf.py
--- a/sympy/core/evalf.py
+++ b/sympy/core/evalf.py
@@ -1003,7 +1003,7 @@ def N(x, n=15, **options):
 
     Example:
     >>> from sympy import Sum, Symbol, oo
-    >>> k = Symbol("k", integer=True)
+    >>> k = Symbol("k")
     >>> Sum(1/k**k, (k, 1, oo))
     Sum(k**(-k), (k, 1, oo))
     >>> N(Sum(1/k**k, (k, 1, oo)), 4)
diff --git a/sympy/core/power.py b/sympy/core/power.py
--- a/sympy/core/power.py
+++ b/sympy/core/power.py
@@ -81,6 +81,8 @@ class Pow(Basic):
         return self._args[1]
 
     def _eval_power(self, other):
+        if other == S.NegativeOne:
+            return Pow(self.base, self.exp * other)
         if self.exp.is_integer and other.is_integer:
             return Pow(self.base, self.exp * other)
         if self.base.is_nonnegative and self.exp.is_real and other.is_real:
diff --git a/sympy/core/tests/test_eval_power.py 
b/sympy/core/tests/test_eval_power.py
--- a/sympy/core/tests/test_eval_power.py
+++ b/sympy/core/tests/test_eval_power.py
@@ -55,3 +55,8 @@ def test_issue350():
 
 def test_issue767():
     assert --sqrt(sqrt(5)-1)==sqrt(sqrt(5)-1)
+
+def test_negative_one():
+    x = Symbol('x', complex=True)
+    y = Symbol('y', complex=True)
+    assert 1/x**y == x**(-y)
diff --git a/sympy/integrals/tests/test_risch.py 
b/sympy/integrals/tests/test_risch.py
--- a/sympy/integrals/tests/test_risch.py
+++ b/sympy/integrals/tests/test_risch.py
@@ -106,7 +106,6 @@ def test_heurisch_symbolic_coeffs():
     assert heurisch(1/(x+sqrt(2)), x)   == log(x+sqrt(2))
     assert trim(diff(heurisch(log(x+y+z), y), y)) == log(x+y+z)
 
[EMAIL PROTECTED]
 def test_heurisch_symbolic_coeffs_1130():
     assert heurisch(1/(x**2+y), x)      == I*y**(-S.Half)*log(x + 
(-y)**S.Half)/2 - \
                                            I*y**(-S.Half)*log(x - 
(-y)**S.Half)/2
diff --git a/sympy/printing/tests/test_ccode.py 
b/sympy/printing/tests/test_ccode.py
--- a/sympy/printing/tests/test_ccode.py
+++ b/sympy/printing/tests/test_ccode.py
@@ -10,7 +10,7 @@ def test_Pow():
     assert ccode(x**3) == "pow(x,3)"
     assert ccode(x**(y**3)) == "pow(x,(pow(y,3)))"
     assert ccode(1/(g(x)*3.5)**(x - y**x)/(x**2 + y)) == \
-        "1/(pow((3.50000000000000*g(x)),(x - pow(y,x)))*(y + pow(x,2)))"
+        "1/(y + pow(x,2))*pow((3.50000000000000*g(x)),(-x + pow(y,x)))"
 
 def test_Exp1():
     assert ccode(exp(1)) == "exp(1)"
diff --git a/sympy/simplify/simplify.py b/sympy/simplify/simplify.py
--- a/sympy/simplify/simplify.py
+++ b/sympy/simplify/simplify.py
@@ -220,8 +220,6 @@ def together(expr, deep=False):
        It also perfect possible to work with symbolic powers or
        exponential functions or combinations of both:
 
-       >>> x = Symbol('x', positive=True)
-       >>> y = Symbol('y', real=True)
        >>> together(1/x**y + 1/x**(y-1))
        x**(-y)*(1 + x)
 
diff --git a/sympy/simplify/tests/test_simplify.py 
b/sympy/simplify/tests/test_simplify.py
--- a/sympy/simplify/tests/test_simplify.py
+++ b/sympy/simplify/tests/test_simplify.py
@@ -165,6 +165,8 @@ def test_together():
 
     assert together(Rational(1,2) + x/2) == (x+1)/2
 
+    assert together(1/x**y + 1/x**(y-1)) == x**(-y)*(1 + x)
+
 def test_separate():
     x, y, z = map(Symbol, 'xyz')
 

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sympy-patches" group.
To post to this group, send email to sympy-patches@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sympy-patches?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to