On Thu, Nov 10, 2011 at 8:58 AM, [email protected]
<[email protected]> wrote:
> Hi,
>
> I hope Aaron could comment as this concerns the plotting problem he was
> working on (pull request 696).
>
> So for the last day or so I was trying to understand lambdify. According to
> the docstring it's used for numeric calculations - that's the whole idea
> behind translating sympy functions to mpmath, numpy, etc.
>
> Also according to the docstring lambdify is used for _fast_ calculations.
> That's why it's not simply a shortcut for .subs(vars).evalf() which is so
> much simpler but calls subs on every evaluation. (The guy that has created
> the plotting module few years ago has some benchmarks on his blog)
>
> And it seems that the original idea behind lambdify was to be used in the
> plotting framework (see the author of the first commit in git log), giving
> numerical values for the coordinates to be plotted. If I'm incorrect here
> please correct me.
>
> But all this falls apart when I look at the tests:
>
> - the most hard for me to understand are the following:
>  256     f = lambdify(x, x * y)
>  257     assert f(z) == z * y
> and
>  250     f = Lambda(x, exp(-x**2))
>  251     l = lambdify(x, Integral(f(x), (x, -oo, oo)), modules="sympy")
>  252     assert l(x) == Integral(exp(-x**2), (x, -oo, oo))
>
> Why would anyone ever want to do this instead of using a simple python
> lambda? There is no translation to numpy or other modules. The only thing
> that can happen is to mix numpy functions with sympy expressions, but why
> would someone want to do this?
>
> An enormous amount of the tests for lambdify show behaviour that _should_ be
> implemented with python lambda. And that makes lambdify that much harder to
> implement. Why should lambdify care about lists, tuples, dictionaries and
> whatnot when even in the docstring it's said that it's used for numeric
> computation?
>
>
> Or probably I'm simply missing the point of lambdify. Could some one explain
> it to me?

If you look at the implementation of lambdify, and LambdaPrinter, it
is just a wrapper around Python lambda that does some intelligent
translation when going to other modules (like numpy).  Actually, it's
particularly nice for using numpy or some other module because
lambdify([x], sin(x), "numpy")(1) will use numpy's sin() function to
evaluate sin(1), not mpmath.

But in general, I think the reason to use it instead of a straight
Python lambda is because it will be cleaner, and also because for
those cases where those translations matter, you don't have to worry
about them.

And by the way, I'm not the best person to ask about lambdify(), as
I've only used it a little; and similarly with the plotting: I only
have used it a little (for the plotting, it's mostly because it
usually doesn't work on Mac OS X, so I don't bother.  I definitely
would use it more if it worked).  That pull request was fixing someone
else's problem from IRC, for which I was immediately able to see the
problem.

Aaron Meurer

>
>
> notes:
> the integral tests comes from this commit:
> commit 558c862ac98e58a1d27bdc57a777d355cabee28d
> Author: Ondrej Certik <[email protected]>
> Date:   Sun Mar 29 17:49:24 2009 -0700
>     Make lambdify() work with Integral
> but it does not address Sums, Products, any single one quantum expression,
> etc. Why is integral so special (obviously those were not needed until know,
> but the proposed solution does not scale at all)
>
> --
> 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.
>

-- 
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.

Reply via email to