What I'm proposing is something that takes a complete Function, not a
callable.  If an interface requires the use of lambda to work, it's
probably not a good one, especially in SymPy, where we have symbolic
expressions.

I want something like

eq = 1 - cos(x) + cos(2*x)
eq.funcreplace(cos(x), 1 - x**2/2)

to work as you describe. But

eq.funcreplace(cos(y), 1 - y**2/2)

would also return exactly the same thing.  (I'm using the name
"funcreplace" because I'm thinking this maybe shouldn't go in subs,
but we can worry about the name later).  The point is that the
function variables should be treated as bound.  Something like

eq = cos(x) + cos(y)
eq.funcreplace(cos(t), 1 - x**2/2)

should return

2 - x**2/2 - y**2/2

If the first argument of funcreplace is not a Function with arguments
that are either Symbols or also Functions, it should probably raise a
ValueError, though we could also try to make it smart and do a
recursive subs.

Aaron Meurer

On Mon, Apr 30, 2012 at 1:48 AM, Chris Smith <smi...@gmail.com> wrote:
> On Mon, Apr 30, 2012 at 12:51 PM, Aaron Meurer <asmeu...@gmail.com> wrote:
>> I just mean it doesn't have to be subs that does this.  It could be
>> some other method, like replace, or something new.  I'm not sure if
>> such functionality belongs as a hint to subs or as a different method.
>>
>
> Not sure, but we have subs, replace, xreplace and transform that all
> handle different situations involving substitution. I think that
> things could get a little confusing if this were all wrapped into
> subs.
>
> Maybe this case isn't too bad, however. It represents old/new being
> callable/callable if this is detected it could just be passed off to
> replace. So `(1 - cos(x) + cos(2*x)).subs(cos, lambda x: 1 - x**2/2)`
> -> `-3*x**2/2 + 1`.
>
> --
> 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 
> sympy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sympy?hl=en.
>

-- 
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 
sympy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to