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

> The equations I am dealing with can be several thousand lines long at
> times, so things get extremely messy.  However, within these
> equations, many of the same quantities are used repeatedly, just like
> in your example -- sin(theta) and cos(theta).

I don't understand which criteria you use to substitute the
subexpressions --- the most frequent subexpression?

>
> There is a program I use called Autolev, written by some people from
> Stanford, and it does this introduction of intermediate variables very
> effectively.  Unfortunately, Autolev isn't open source.  I am very
> interested in writing an open source variant of Autolev, but this part
> of the program is something that I know little about and am not sure
> yet how to approach.

Could you post here the input and output of autolev so that we can see
some examples? (if it is legal of course)
If you cannot, at least if you could describe your specific problem
you want to solve, i.e. the exact form
of the equations etc.

>
> Thanks for the response and if you have any other ideas or references,
> I'd love to hear them!  I'm guessing I'm going to need to study up on
> searching, sorting, and regular expressions.

I am interested in what you want to do, especially if you want to
solve something in physics.

Your usage could improve sympy tree traversal
functionality/subsitution. SymPy's expression is basically a tree,
each element has .args property, that is basically a list. See
Basic.atoms()'s implementation, as you can see, it's just 9 lines of
code. So you'd just traverse it and compare/substitute stuff. Let us
know how the current interface feel and if you find some ways to
improve it or make it more intuitive, please write us too.

Ondrej

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

Reply via email to