Le mardi 15 mai 2012 à 23:05 +0200, [email protected] a écrit :
> In another discussion on the mailing list Ronan mentioned that Lambda
> should not subclass Expr. Here I was proposing just the opposite: have
> Function subclass Expr in order to have callable Expr.
>
> (1+f)(x) returning 1+f(x)
> and
> (1+Lambda(a, 2*a))(x) returning 1+2*a
>
> Any thoughts? For precedent check "Functional Differential Geometry".
I don't think it's a good idea.
* This logically implies 1(x) == 1, which is surprising, to say the
least.
* Consequently, this gives most objects a dual role as themselves and
as a constant function returning themselves, in clear contradiction
with the single responsibility principle.
* It makes it impossible to distinguish between callables and
non-callables.
* Why is this new behaviour limited to Expr? Callability and
existence of arithmetic operations are orthogonal concepts.
* What about function arity? If f = Lambda(x, x) and
g = Lambda((x, y), x+y), what is 1 + f + g?
* 1 + Function('f') can't work anyway, because Function('f') is a
class, not a sympy object.
> On 12 May 2012 22:23, [email protected]
> <[email protected]> wrote:
> > I would like to be able to do the following:
> >
> >>>> f = Function('f')
> >>>> expr = 2+f
> >>>> expr(x)
> > 2+f(x)
> >
> > It would be extremely useful for the vector analysis stuff on which I
> > am working for gsoc. `f` is a `Field` and `x` is a `Point`.
> >
> > I will try to implement it. Please raise any objections if you have.
>
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected].
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.