details: http://hg.sympy.org/sympy/rev/8b4b931bb77d changeset: 1792:8b4b931bb77d user: Stepan Roucka <[EMAIL PROTECTED]> date: Sat Oct 11 22:28:14 2008 +0200 description: 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. diffs (83 lines): diff -r 7f83ede93315 -r 8b4b931bb77d sympy/core/evalf.py --- a/sympy/core/evalf.py Fri Oct 10 19:37:43 2008 +0200 +++ b/sympy/core/evalf.py Sat Oct 11 22:28:14 2008 +0200 @@ -1003,7 +1003,7 @@ 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 -r 7f83ede93315 -r 8b4b931bb77d sympy/core/power.py --- a/sympy/core/power.py Fri Oct 10 19:37:43 2008 +0200 +++ b/sympy/core/power.py Sat Oct 11 22:28:14 2008 +0200 @@ -81,6 +81,8 @@ 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 -r 7f83ede93315 -r 8b4b931bb77d sympy/core/tests/test_eval_power.py --- a/sympy/core/tests/test_eval_power.py Fri Oct 10 19:37:43 2008 +0200 +++ b/sympy/core/tests/test_eval_power.py Sat Oct 11 22:28:14 2008 +0200 @@ -55,3 +55,8 @@ 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 -r 7f83ede93315 -r 8b4b931bb77d sympy/integrals/tests/test_risch.py --- a/sympy/integrals/tests/test_risch.py Fri Oct 10 19:37:43 2008 +0200 +++ b/sympy/integrals/tests/test_risch.py Sat Oct 11 22:28:14 2008 +0200 @@ -106,7 +106,6 @@ 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 -r 7f83ede93315 -r 8b4b931bb77d sympy/printing/tests/test_ccode.py --- a/sympy/printing/tests/test_ccode.py Fri Oct 10 19:37:43 2008 +0200 +++ b/sympy/printing/tests/test_ccode.py Sat Oct 11 22:28:14 2008 +0200 @@ -10,7 +10,7 @@ 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 -r 7f83ede93315 -r 8b4b931bb77d sympy/simplify/simplify.py --- a/sympy/simplify/simplify.py Fri Oct 10 19:37:43 2008 +0200 +++ b/sympy/simplify/simplify.py Sat Oct 11 22:28:14 2008 +0200 @@ -220,8 +220,6 @@ 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 -r 7f83ede93315 -r 8b4b931bb77d sympy/simplify/tests/test_simplify.py --- a/sympy/simplify/tests/test_simplify.py Fri Oct 10 19:37:43 2008 +0200 +++ b/sympy/simplify/tests/test_simplify.py Sat Oct 11 22:28:14 2008 +0200 @@ -165,6 +165,8 @@ 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-commits" group. To post to this group, send email to sympy-commits@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-commits?hl=en -~----------~----~----~----~------~----~------~--~---