On Thu, Mar 26, 2009 at 6:45 PM, Gael Varoquaux <[email protected]> wrote: > > Hey guys, > > We are sitting at a sprint, trying to use sympy to implement a clean way > of generation of numpy vectors. > > What we want is to specify formulas for these vectors, and at the end of > the day, we sample these formulas on a given set of values. It is > important for us to seprate the specification from the sampling. All the > rest (incuding the fact the sympy is able to compute closed form > formulas or not) does not matters, as long as we can get numerical > values.
Yes. > > Where this fails is when we try to do some convolutions: I can't figure > out a way of using lambdify with none evaluated integrals. I don't see > why sympy shouldn't be abe to cal scipy.integrate to get numerical values > for these integrals. We don't actually need to use lambdify: we are going > to evaluate these functions on vector of length < 1000. Let me play, I think we haven't yet tested lambdify with unevaluated integrals. I don't see a reason why it couldn't work, let me check. In [9]: l = lambdify(x, Integral(f(x), (x, -oo, oo))) In [10]: l Out[10]: <function <lambda> at 0x310c7d0> In [11]: l(3) --------------------------------------------------------------------------- NameError Traceback (most recent call last) /home/ondrej/repos/sympy/<ipython console> in <module>() /home/ondrej/repos/sympy/<string> in <lambda>(x) NameError: global name 'Integral' is not defined Ok, it's a bug: http://code.google.com/p/sympy/issues/detail?id=1352 I think it's easy to fix, I'll look into it. But even when this is fixed --- it will still be a sympy integral. So what do you want lambdify to do with it? keep it as a sympy integral and you will then call .evalf() yourself on it, or make it somehow call scipy.integrate? I believe the best option is to patch sympy to create an option in .evalf(use_scipy=True), that would lambdify the argument and then call scipy integrate on the argument. But try sympy's integration, if it's <1000, it *may* be fast enough. If it's not, let's implement use_scipy, so that it can use scipy automatically. Btw, I am myself surprised, that we can do this integral already: In [16]: i Out[16]: ∞ ⌠ ⎮ 2 ⎮ -x ⎮ ℯ dx ⌡ -∞ In [17]: i.doit() Out[17]: ⎽⎽⎽ ╲╱ π In [18]: i.evalf() Out[18]: 1.77245385090552 In [19]: i.doit().evalf() Out[19]: 1.77245385090552 > > What is the right strategy here? (I guess my e-mail is unclear, if I need > to ask the question like this). > > A side question: subs is not working the way I thought it would on > 'Integral' objects: > > In [1]: f = Lambda(x, exp(-x**2)) > > In [2]: conv = Integral(f(x-y)*f(y), (y, -oo, oo)) > > In [3]: conv > Out[3]: > ∞ > ⌠ > ⎮ 2 2 > ⎮ - y - (x - y) > ⎮ ℯ dy > ⌡ > -∞ > > In [4]: conv.subs({x:0}) > Out[4]: > ∞ > ⌠ > ⎮ 2 2 > ⎮ - y - (x - y) > ⎮ ℯ dy > ⌡ > -∞ > > I would like 'Out[4]' to have x substituted :). I can see why it is hard > (sympy is probably not tracking that the integration variable does not > depend on x), but I'd still like it :). Yes, sure. I think it doesn't work yet, I found some related issues: http://code.google.com/p/sympy/issues/detail?id=951 http://code.google.com/p/sympy/issues/detail?id=987 anyway, I made a new one set to fix in the next release, as this is a high priority and I think it's easy to fix: http://code.google.com/p/sympy/issues/detail?id=1351 Let's make a deal --- I'll fix this for you and you'll review my patches that are holding off the sympy release: http://code.google.com/p/sympy/issues/list?q=label:NeedsReview :) Then we can release sympy *and* have it fixed. Ondrej --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
