I'm working on some code that symbolically generates equations of motion for mechanical systems. I would like the equations to be computationally efficient in that they don't repeatedly calculate quantities that have previously been calculated -- i.e. if cos(theta)*sin(alpha)*L is a subexpression that occurs in multiple places in an equation, it would be identified and computed once and stored in an intermediate variable that then replaces the subexpression everywhere it occurs in the equation. Does anybody know a good algorithm for searching equations and building up a list of subexpressions? There could be many levels of subexpressions -- in the example above, cos(theta) and sin(theta) themselves would like be used in other subexpressions, so they could be considered subexpressions themselves.
I have used a symbolic manipulator that has this feature but it is a small closed source project and I don't know how they did it. It is very valuable though -- the difference in the file size for the right hand sides of the differential equations for the system we are studying is several orders of magnitude -- this makes integration times *much* faster when this common subexpression replacement method is used. Any ideas or references on this subject? Thanks, ~Luke --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sympy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sympy?hl=en -~----------~----~----~----~------~----~------~--~---