details:   http://hg.sympy.org/sympy/rev/876257540928
changeset: 1831:876257540928
user:      Fredrik Johansson <[EMAIL PROTECTED]>
date:      Mon Oct 20 16:48:16 2008 +0200
description:
Fix substitution of 0 in evalf of powers

diffs (51 lines):

diff -r 9292ed4fdd71 -r 876257540928 sympy/core/evalf.py
--- a/sympy/core/evalf.py       Sun Oct 19 22:24:48 2008 +0200
+++ b/sympy/core/evalf.py       Mon Oct 20 16:48:16 2008 +0200
@@ -419,6 +419,9 @@
             if case == 1: return None, z, None, target_prec
             if case == 2: return mpf_neg(z), None, target_prec, None
             if case == 3: return None, mpf_neg(z), None, target_prec
+        # Zero raised to an integer power
+        if not re:
+            return None, None, None, None
         # General complex number to arbitrary integer power
         re, im = libmpc.mpc_pow_int((re, im), p, prec)
         # Assumes full accuracy in input
@@ -443,6 +446,10 @@
     # This determines the working precision that must be used
     prec += 10
     yre, yim, yre_acc, yim_acc = evalf(exp, prec, options)
+    # Special cases: x**0
+    if not (yre or yim):
+        return fone, None, prec, None
+
     ysize = fastlog(yre)
     # Restart if too big
     # XXX: prec + ysize might exceed maxprec
@@ -458,6 +465,9 @@
         return mpf_exp(yre, target_prec), None, target_prec, None
 
     xre, xim, xre_acc, yim_acc = evalf(base, prec+5, options)
+    # 0**y
+    if not (xre or xim):
+        return None, None, None, None
 
     # (real ** complex) or (complex ** complex)
     if yim:
diff -r 9292ed4fdd71 -r 876257540928 sympy/core/tests/test_evalf.py
--- a/sympy/core/tests/test_evalf.py    Sun Oct 19 22:24:48 2008 +0200
+++ b/sympy/core/tests/test_evalf.py    Mon Oct 20 16:48:16 2008 +0200
@@ -179,3 +179,13 @@
     assert abs(complex(pi+E*I) - (3.1415926535897931+2.7182818284590451j)) < 
1e-10
     raises(ValueError, "float(pi+x)")
     raises(ValueError, "complex(pi+x)")
+
+def test_evalf_power_subs_bugs():
+    assert (x**2).evalf(subs={x:0}) == 0
+    assert sqrt(x).evalf(subs={x:0}) == 0
+    assert (x**Rational(2,3)).evalf(subs={x:0}) == 0
+    assert (x**x).evalf(subs={x:0}) == 1
+    assert (3**x).evalf(subs={x:0}) == 1
+    assert exp(x).evalf(subs={x:0}) == 1
+    assert ((2+I)**x).evalf(subs={x:0}) == 1
+    assert (0**x).evalf(subs={x:0}) == 1

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to