Thanks for the temporary fix to ndiv. However even with this fix cse in bleeding edge sympy gives:
[pg01**2/pg00**2, 1.0 - 2*pg01/pg00, pg01*(1.0 - pg01/pg00)] [(x0, -pg01/pg00)] [pg01**2/pg00**2, 1.0 - 2*pg01/pg00, pg01*(x0 + 1.0)] whereas cse in sympy 7.1 gives: [pg01**2/pg00**2, 1.0 - 2*pg01/pg00, pg01*(1.0 - pg01/pg00)] [(x0, 1/pg00), (x1, pg01*x0)] [x1**2, -2*x1 + 1.0, pg01*(-x1 + 1.0)] I think sympy 7.1 result is better. Larry Wigton On Thursday, September 6, 2012 12:55:44 PM UTC-7, Larry Wigton wrote: > > Python code using cse from sympy: > > from sympy import * > x=Symbol('x') > y=Symbol('y') > eq1 = 5*x**3*y**2 + y**3 > eq2 = 4*x**2*y**3 + y**2 > eq = [eq1,eq2] > print eq > (red,rep) = cse(eq) > print red > print rep > eq = [eq2,eq1] > print eq > (red,rep) = cse(eq) > print red > print rep > > *********************************************** > > Output from the code: > > [5*x**3*y**2 + y**3, 4*x**2*y**3 + y**2] > [(x0, y**3), (x1, x0**(2/3))] > [5*x**3*x1 + x0, 4*x**2*x0 + x1] > > [4*x**2*y**3 + y**2, 5*x**3*y**2 + y**3] > [(x0, y**2), (x1, x0**(3/2))] > [4*x**2*x1 + x0, 5*x**3*x0 + x1] > > ********************************************** > > The introduction of the powers 2/3 and 3/2 is not acceptable. > > For one thing in Fortran 2/3 will beocme 0 and 3/2 will become 1. > > Even if we make 2 and 3 floating point numbers this is not efficient. > > Also if we take x0=y**2 and then try to compute y**3 using x0**(1.5) > we get the wrong answer in the case y is negative. > > ************************************************************ > > Is there some way to run cse to avoid this undesirable behavior? > > Can cse be modified to avoid this undesirable behavior? > > -- You received this message because you are subscribed to the Google Groups "sympy" group. To view this discussion on the web visit https://groups.google.com/d/msg/sympy/-/sJo-8F7Kdl0J. To post to this group, send email to sympy@googlegroups.com. To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.