Updates:
Cc: [email protected]
Blockedon: -sympy:1688 -sympy:1927 sympy:1688 sympy:1927
Comment #5 on issue 2006 by [email protected]: Make all expressions
recursively callable
http://code.google.com/p/sympy/issues/detail?id=2006
I'm beginning to think this was a bad idea (and I'm ready for the "I told
you so"s). Right now we have
a = x + 1
a(3)
x + 1
which is very confusing. The expression is completely left alone, but a
lot of new users think that it should somehow automatically apply on the
free variable, x, and give 3 + 1 == 4.
I think what we should do instead is make this not default, but think about
how we can make this formalism useful in terms of Lambda. Lambda(x, a) is
the actual expression that does what you would expect for the above. The
issues with it are:
1. It requires you to create a free variable, even if you don't naturally
have one. Technically, this is not really an issue, because we have Dummy,
but it can be more notationally convenient to write something like cos +
sin instead of Lambda(x, cos(x) + sin(x)).
2. Lambdas do not combine. Currently, everything works because Expr is
recursively callable, but if we remove this, then (Lambda(x, cos(x)) +
Lambda(x, sin(x))(pi) will no longer work. Making it "just work" is
apparently a bad idea, since it means that all ordinary expressions
also "just work", which is the confusing behavior I noted above. Since
expressions are by far more common than actual functions, this is I think a
good argument to require a little more work to make the functions work.
For point 1, it already doesn't work. This gets into the design of
functions as objects (issue 1688). If we ever fix that, we will need to
think if it makes sense to allow expressions like sin + cos.
For point 2, perhaps we should have a simple function that automatically
combines Lambdas, like lambdasimp(Lambda(x, cos(x)) + Lambda(x, sin(x)) =>
Lambda(x, cos(x) + sin(x)). We could also play with having this happen
automatically (but that would really require issue 1941).
Another thought is to make Expr not callable by default, but only work if
it actually contains a callable. But this could end up being an annoyance,
because you would have
a = Lambda(x, cos(x)) -> callable
b = Lambda(x, cos(x)) + 1 -> callable
b - a -> not callable
but
a = Lambda(x, cos(x)) -> callable
b = Lambda(x, cos(x) + 1) -> callable
b - a -> callable
and note that the b's in both cases are essentially equivalent, as
functions.
To summarize: Recursively callable Expr, as it currently exists, is a bad
idea. We should undo this and think about it more before enabling it
again. I'll play with removing it and seeing what breaks (I guess some
stuff from diffgeom relies on this).
--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings
--
You received this message because you are subscribed to the Google Groups
"sympy-issues" 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-issues?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.