[sympy] Re: Problem with user-defined functions

2011-06-02 Thread luke
Oh, thanks a lot. Now it's working fine. Now the only problem is that the code is evaluated when calling sympify, and not when calling evalf. Could I ask you what is the way to keep the function lazy? I explain myself better. Since the function SUM has to operate on a database if I have something l

[sympy] Re: Problem with user-defined functions

2011-06-02 Thread luke
Yes, that worked. But I had to restructure the code class SUM(Function): nargs = 2 @classmethod def eval(cls, arg): cls.arg=arg @classmethod def _eval_evalf(cls, arg): map = Code("""function () { emit("sum",{%(field)s:this.%(field)s});

[sympy] Re: Problem with user-defined functions

2011-06-02 Thread luke
Actually you're wrong. Every instance of a class in python has its own attributes and editing the attributes of one instance of a class wont modify the attributes of the other classes. Try: class MyClass: def __init__(self,var): self.var=var then execute: >>> a = MyClass(10) >>> pri

[sympy] Re: Problem with user-defined functions

2011-06-02 Thread luke
WAIT, I didn't see that you use self.arg[0]!! that's why my code was giving me 57, I just need to call cls.arg[0], great now I can remove the eval ;)! thanks again On Jun 2, 9:30 pm, luke wrote: > Actually you're wrong. Every instance of a class in python has its own > attributes and editing the

[sympy] Re: Problem with user-defined functions

2011-06-02 Thread luke
Nope in spite of my enthusiasm cls.args wont work properly as it will give me a and not a :) I'll put back my eval since it worked. Hope that was of any help! On Jun 2, 9:32 pm, luke wrote: > WAIT, I didn't see that you use > self.arg[0]!! that's why my code was giving me 57, I just need to ca

[sympy] Re: Problem with user-defined functions

2011-06-02 Thread luke
My bad, sorry for my inexperience with sympy, final code: (this is really working!) class SUM(Function): nargs = 1 def _eval_evalf(cls, prec): print cls.args map = Code("""function () { emit("sum",{%(field)s:this.%(field)s}); }"""

Re: [sympy] Re: Problem with user-defined functions

2011-06-02 Thread Ronan Lamy
Le jeudi 02 juin 2011 à 08:03 -0700, luke a écrit : > Oh, thanks a lot. Now it's working fine. > Now the only problem is that the code is evaluated when calling > sympify, and not when calling evalf. > Could I ask you what is the way to keep the function lazy? I explain > myself better. Since the f

Re: [sympy] Re: Problem with user-defined functions

2011-06-02 Thread Ronan Lamy
Le jeudi 02 juin 2011 à 09:35 -0700, luke a écrit : > Yes, that worked. But I had to restructure the code > > class SUM(Function): > nargs = 2 > @classmethod > def eval(cls, arg): > cls.arg=arg > @classmethod > def _eval_evalf(cls, arg): > map = Code("""function

Re: [sympy] Re: Problem with user-defined functions

2011-06-02 Thread Aaron S. Meurer
This is indeed a very interesting application of SymPy. Here we see one example of the power of symbolic computer algebra systems, which is that symbolic preprocessing, even very simple preprocessing like what we have here, can greatly optimize arbitrary code execution. If your expressions a

Re: [sympy] Re: Problem with user-defined functions

2011-06-02 Thread Aaron S. Meurer
Is there a specific reason why you want to use evalf() to do your lookups, or is it just because you want something that will recurse down the expression tree? Aaron Meurer On Jun 2, 2011, at 2:10 PM, luke wrote: > My bad, sorry for my inexperience with sympy, final code: (this is > really w