Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 2414 by five...@gmail.com: [Feature request] Deferred expressions
http://code.google.com/p/sympy/issues/detail?id=2414

I'm concerned about improving the performance of differentiation and subsequent code generation. It would be handy to mark certain intermediate expressions such that they would not be expanded directly in symbolic manipulation. Here is a simple example of the idea.

from sympy import *
def grad(f,x):
    return Matrix([f]).jacobian(Matrix([x]))
def div(q,X):
    return sum(diff(*t) for t in zip(q,X))
x,y = symbols('x y')
X = Matrix([x,y])
u = sin(x+y)*cos(x*y**3)
du = grad(u,X)
def q(u,du):
    return (u**2 + du.dot(du))*du # This might be quite complicated
f = div(q(u,du),X)
print len(ccode(f)) # 2066

# Use intermediate symbols
U = Symbol('U')
dU = Matrix(symbols('Ux Uy')).reshape(1,2)
ddU = Matrix(symbols('Uxx Uxy Uyx Uyy')).reshape(2,2)
Q = q(U,dU)
f2 = (grad(Q[0],U) * dU[0] + grad(Q[0],dU) * ddU[:,0] +
      grad(Q[1],U) * dU[1] + grad(Q[1],dU) * ddU[:,1])[0]
print sum(map(len,map(ccode,[u] + list(du) + list(grad(du,X)) + [f2]))) # 982

# Proposed alternative
f3 = div(deferred(u),deferred(du))
ccode(f3) # Would produce code similar to f2

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