On 2/11/12 1:07 PM, Oscar Lazo wrote:
Hello, I've been working in implementing Airy functions in sage, and
since mpmath allows calcultating any derivative or integral of Airy
functions I wanted to implement the generalized symbolic case, but I am
very puzzled by this error:
from sage.symbolic.function import BuiltinFunction
class FunctionAiryAiGeneral(BuiltinFunction):
def __init__(self,alpha):
self.alpha=alpha
BuiltinFunction.__init__(self, "airy_ai", nargs=2,
latex_name=r"\operatorname{Ai}")
def _derivative_(self, x):
return airy_ai(self.alpha+1,x)
airy_2=FunctionAiryAiGeneral(-2)
f=airy_2(-2,x)
print f
derivative(f,x)
gets me this output:
airy_ai(-2, x)
Traceback (most recent call last): latex_name=r"\operatorname{Ai}")
File "", line 1, in <module>
File "/tmp/tmpkTtzNc/___code___.py", line 18, in <module>
exec compile(u'derivative(f,x)
File "", line 1, in <module>
File
"/home/oscar/sage/sage-4.7.1/local/lib/python2.6/site-packages/sage/calculus/functional.py",
line 130, in derivative
return f.derivative(*args, **kwds)
File "expression.pyx", line 2699, in
sage.symbolic.expression.Expression.derivative
(sage/symbolic/expression.cpp:12542)
File "derivative.pyx", line 216, in
sage.misc.derivative.multi_derivative (sage/misc/derivative.c:2207)
File "expression.pyx", line 2771, in
sage.symbolic.expression.Expression._derivative
(sage/symbolic/expression.cpp:12918)
TypeError: _derivative_() takes exactly 2 non-keyword arguments (3 given)
I did give derivative exactly 2 non-keyword arguments...
This probably is a problem with the self argument:
sage: class A:
....: def f(self, x):
....: print self, x
....:
sage: myclass=A()
sage: myclass.f('a','b')
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/Users/grout/projects/bencalc3/<ipython console> in <module>()
TypeError: f() takes exactly 2 arguments (3 given)
Notice that the two arguments I gave it ('a' and 'b') are appended to
the self argument to f, so really f is called as f(self, 'a','b').
In your case, the class method only takes one argument, but it should
take more to be in line with the derivative api. Changing your code
slightly illustrates what is going on:
from sage.symbolic.function import BuiltinFunction
class FunctionAiryAiGeneral(BuiltinFunction):
def __init__(self,alpha):
self.alpha=alpha
BuiltinFunction.__init__(self, "airy_ai", nargs=2,
latex_name=r"\operatorname{Ai}")
def _derivative_(self, x, *args, **kwds):
print x, args, kwds
return airy_ai(self.alpha+1,x)
airy_2=FunctionAiryAiGeneral(-2)
f=airy_2(-2,x)
print f
derivative(f,x)
now gives an error, but does helpfully print out that the derivative
function is being called with:
-2 (x,) {'diff_param': 1}
So the first value, x, is really -2, then the variable x is being
passed, and then that last keyword argument is being passed.
Does that help?
Jason
--
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org