I would indeed expect the detection of common subexpressions to be 
compiler's job. SymPy should not do this by default. But it can do it if 
you explicitly ask: 

cs = sp.cse(dQ_dR)
print "\n".join(sp.fcode(sub[1], sub[0]) for sub in cs[0]) + "\n" + sp.fcode
(cs[1][0], J)


prints

x0 = X_A - X_B
x1 = Y_A - Y_B
x2 = Z_A - Z_B
x3 = 1/sqrt(x0**2 + x1**2 + x2**2)
J(1, 1) = x0*x3
J(1, 2) = x1*x3
J(1, 3) = x2*x3
J(1, 4) = x3*(-X_A + X_B)
J(1, 5) = x3*(-Y_A + Y_B)
J(1, 6) = x3*(-Z_A + Z_B)



-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/48ee8a42-9d61-4aac-91e0-87971b891279%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to