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/-/FTpd6jnPuDUJ. 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.