method needs a home

8 views
Skip to first unread message

smichr

unread,
May 23, 2012, 4:45:06 AM5/23/12
to sy...@googlegroups.com
Pull request 1272 is languishing for lack of an agreeable location for this functionality:

`f(x, y).foo(f(a, b), a +b) -> x + y`

Making this part of subs, rewrite, and replace has been voted down. If it is to be a stand-alone method, are there suggestions for the name you would expect to use in place of foo above? I suggested `explicate` which is not that much more complicated than enumerate. It could be `define`, too.

/c

Sergiu Ivanov

unread,
May 23, 2012, 9:46:50 AM5/23/12
to sy...@googlegroups.com
Hello,
This looks a lot like inlining functions. Maybe "inline"?

Sergiu

Ronan Lamy

unread,
May 23, 2012, 11:12:50 AM5/23/12
to sy...@googlegroups.com
If you could define precisely what your method should do, and explain
how it relates to existing methods, it would be easier to answer.


Chris Smith

unread,
May 23, 2012, 11:35:05 AM5/23/12
to sy...@googlegroups.com
>> `f(x, y).foo(f(a, b), a +b) -> x + y`

It replaces a generic function with an expression. So f(x,y) in the
above is replaced with the sum of its arguments, regardless of what
the arguments are. f(1,2) would be replaced with 3 and f(1, -x - y)
would be replaced with 1 - x - y. (It does a little more than this as
the discussion in the pull request records, but this is the main
idea.)

krastano...@gmail.com

unread,
May 23, 2012, 11:41:14 AM5/23/12
to sy...@googlegroups.com
I am sorry for not participating in the pull request discussions.
Maybe this was discussed, but why would you prefer this method instead
of:

In [3]: (f(x,y)+1).subs(f, Lambda([x, y], x+y))
Out[3]: x + y + 1

It seems that this does the same thing with a slightly different syntax.

Otherwise the `inline` proposal for a name sounds ok. It is just that
this is a special case of function that is already implemented (or am
I wrong?).

Chris Smith

unread,
May 23, 2012, 12:47:43 PM5/23/12
to sy...@googlegroups.com
On Wed, May 23, 2012 at 9:26 PM, krastano...@gmail.com
<krastano...@gmail.com> wrote:
> I am sorry for not participating in the pull request discussions.
> Maybe this was discussed, but why would you prefer this method instead
> of:
>
> In [3]: (f(x,y)+1).subs(f, Lambda([x, y], x+y))
> Out[3]: x + y + 1
>
> It seems that this does the same thing with a slightly different syntax.


At the suggestion of Aaron, the method also handles linear transforms
(which I am not sure the lambda handles):

```
assert (f(x, y) + f(x + 1, y)).rewrite(f(a - c, b), a**b) == \
(c + x)**y + (c + x + 1)**y
assert (f(x, y) + f(x + 1, y)).rewrite(f(1/a - c, b), a**b) == \
(1/(c + x))**y + (1/(c + x + 1))**y
```

Aaron Meurer

unread,
May 26, 2012, 1:39:25 AM5/26/12
to sy...@googlegroups.com
You can do it with subs or replace, but the proposed way is a little
cleaner. It fits nicely with the concept of replacing a
(mathematical) function with it's value. See the other discussion on
this list about it.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To post to this group, send email to sy...@googlegroups.com.
> To unsubscribe from this group, send email to sympy+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
>
Reply all
Reply to author
Forward
0 new messages