Updates:
        Status: Started

Comment #1 on issue 1434 by ondrej.certik: substitution doesn't work for  
sqrt()
http://code.google.com/p/sympy/issues/detail?id=1434

Here is a fix for the sqrt(x*y) problem:

diff --git a/sympy/core/mul.py b/sympy/core/mul.py
index 795b293..f63f805 100644
--- a/sympy/core/mul.py
+++ b/sympy/core/mul.py
@@ -290,7 +290,15 @@ class Mul(AssocOp):
                      elif coeff < 0:
                          return (-coeff)**e * Mul(*((S.NegativeOne,)  
+rest))**e
                      else:
-                        return coeff**e * Mul(*[s**e for s in rest])
+                        # we distribute things if all things are positive:
+                        if coeff.is_positive:
+                            pos = True
+                            for s in rest:
+                                if not s.is_positive:
+                                    pos = False
+                                    break
+                            if pos:
+                                return coeff**e * Mul(*[s**e for s in  
rest])


                  coeff, rest = b.as_coeff_terms()



Before:

In [1]: sqrt(x*y)
Out[1]:
   ⎽⎽⎽   ⎽⎽⎽
╲╱ x ⋅╲╱ y

In [2]: x, y = symbols("x y", positive=True)

In [3]: sqrt(x*y)
Out[3]:
   ⎽⎽⎽   ⎽⎽⎽
╲╱ x ⋅╲╱ y


After:

In [1]: sqrt(x*y)
Out[1]:
   ⎽⎽⎽⎽⎽
╲╱ x⋅y

In [2]: x, y = symbols("x y", positive=True)

In [3]: sqrt(x*y)
Out[3]:
   ⎽⎽⎽   ⎽⎽⎽
╲╱ x ⋅╲╱ y



All tests pass, except:

_______________ sympy/series/tests/test_limits.py:test_heuristic  
_______________
   File "/home/ondrej/repos/sympy/sympy/series/tests/test_limits.py", line  
119, in
test_heuristic
     assert limit(log(2+sqrt(atan(x)*sin(1/x))), x, 0) == log(2)
   File "/home/ondrej/repos/sympy/sympy/series/limits.py", line 79, in limit
     r = heuristics(e, z, z0, dir)
   File "/home/ondrej/repos/sympy/sympy/series/limits.py", line 98, in  
heuristics
     return e.subs(e.args[0], heuristics(e.args[0], z, z0, dir))
   File "/home/ondrej/repos/sympy/sympy/series/limits.py", line 95, in  
heuristics
     r.append(a.limit(z, z0, dir))
   File "/home/ondrej/repos/sympy/sympy/core/basic.py", line 2139, in limit
     return limit(self, x, xlim, direction)
   File "/home/ondrej/repos/sympy/sympy/series/limits.py", line 79, in limit
     r = heuristics(e, z, z0, dir)
   File "/home/ondrej/repos/sympy/sympy/series/limits.py", line 100, in  
heuristics
     raise PoleError(msg % (e, z, z0, dir))
PoleError: Don't know how to calculate the limit((atan(x)*sin(1/x))**(1/2),  
x, 0,
dir=+), sorry.

  tests finished: 1438 passed, 4 skipped, 28 xfailed, 1 xpassed, 1  
exceptions in 99.56
seconds
DO *NOT* COMMIT!


which is just some small problem in limits, which I'll debug later. This  
however
still doesn't fix the subs issue above.

--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings

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

Reply via email to