On Sun, Jun 15, 2008 at 16:11, Ondrej Certik <[EMAIL PROTECTED]> wrote: > > Hi Luke, > > On Sun, Jun 15, 2008 at 9:00 PM, Luke <[EMAIL PROTECTED]> wrote: >> >> Ondrej, >> I know that Sympy has the capability to do symbolic replacement like >> you described. I guess what I'm looking for is more an algorithm to >> help identify and automatically collect common subexpressions so that >> repeated quantities are only calculated once. For each repeated >> subexpression in an equation, an intermediate variable would be >> introduced and assigned the value of the subexpression, and then all >> occurrences of the repeated subexpression in the equation would be >> replaced with the intermediate variable. By generating symbolic > > Does it also go in several layers, e.g > > sin(x) -> A > sqrt(A**2) -> B > > etc.? > >> equations this way, when it comes time to actually use them with >> numerical values (numerical integration of equations of motion, for >> example), one avoids the repetitive computation of the same >> quantity. >> >> In regards to providing an example -- writing an algorithm to automate >> the example you did by hand would be exactly what I am looking to do. > > How should sympy know that you want to substitute for sin(x) and not > sqrt(sin(x)) ?
Actually, that example is not relevant since there is no repeated subexpression. The idea is to reduce the amount of unnecessarily repeated computation (usually numerical) when there are subexpressions that pop up several times in the complete expression. For example, Mathematica has an example of its common subexpression elimination: http://www.wolfram.com/technology/guide/subexpressiondetection.html -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to [email protected] 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 -~----------~----~----~----~------~----~------~--~---
