So I think the problem with using atoms is that the atoms change as
the expression is replaced.  xreplace is capable of doing this
tranformation.  For example, using Transform in sympy.core.rules

In [7]: a = sin(sin(x) + y) + sin(z)

In [8]: from sympy.core.rules import Transform

In [11]: a.xreplace(Transform(lambda x: cos(x.args[0]), lambda x:
isinstance(x, sin)))
Out[11]: cos(z) + cos(y + cos(x))

This works because unlike atoms, which creates a static transformation
dictionary on all the sin's in the untransformed expression, Transform
checks for sin's as it goes.  This is also more efficient (atoms +
xreplace has to go through an expression tree twice).

So I like Transform, except I don't like the interface. Any interface
that uses lambdas 90% of the time can be improved, IMHO. Any thoughts?

Aaron Meurer

On Sat, May 25, 2013 at 10:10 PM, Chris Smith <[email protected]> wrote:
>
>
>
> On Sun, May 26, 2013 at 8:19 AM, Aaron Meurer <[email protected]> wrote:
>>
>> This has come up before actually. It would be useful to have a general
>> function that can topologically sort a list of expressions.
>>
>
> see reps_toposort in cse_main.
>
>>
>> What would be the best way to have an ordered dict to use for xreplace
>> (given that OrderedDict is Python 2.7+ only)?
>>
>
>
>
> --
> 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 http://groups.google.com/group/sympy?hl=en-US.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

-- 
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 http://groups.google.com/group/sympy?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to