Open kcrisman opened 15 years ago
Sure, it probably shouldn't work:
sage: f=x^2
sage: a=lambda x: f
sage: a(2)
x^2
plot expects that when it feeds "a" a number (like a(2)), a number should be returned. Instead, a function is returned.
Replying to @jasongrout:
Sure, it probably shouldn't work: plot expects that when it feeds "a" a number (like a(2)), a number should be returned. Instead, a function is returned.
I guess my point was that I think one can catch this and use it. Unless for some reason this is not desired, like some MS Word "guesses" at fixing mistakes, it is the sort of thing that one can do
sage: f=x^2
sage: a=lambda x: f
sage: a(2)
x^2
sage: a=a(x)
sage: a(2)
4
so that in principle upon a TypeError, one could try letting func=func(x) and then do float(func(point)).
But I don't have time to try that for a few more days. And maybe there is some internal reason not to do this... but I don't think so, because the result of plotting these is the empty plot otherwise, and one would reraise the exception if this still caused a TypeError. Can you think of anything where this would not raise an exception but still lead to bad behavior? I've seen weirder things...
I think this is enough of a change in design that the issue ought to be raised on sage-devel to get more input. Would you like to post a message?
Replying to @jasongrout:
I think this is enough of a change in design that the issue ought to be raised on sage-devel to get more input. Would you like to post a message?
This was done, but the issue generated no interest on sage-devel, so I will go ahead and try to implement and document this as detailed above.
This works:
But this doesn't:
The behavior is the same for f(x)=x^2.
This is because in the second example "evaluating" the lambda function yields a SymbolicCallableExpression, which needs to be called again to actually yield a numerical value.
Component: graphics
Issue created by migration from https://trac.sagemath.org/ticket/4677