# How to make special functions/orthogonal polynomials as callable symbolic expression.

Hello,

I'd like to make some special functions/orthogonal polynomials as callable symbolic expression. However, those functions always remind me the argument is not an integer.

var('n a x')
f(x) = gen_laguerre(n,a,x)

TypeError: unable to convert x (=n) to an integer


, and

var('n x')
g(x) = spherical_bessel_J(n, x)

TypeError: unable to convert x (=n) to an integer


Even if I tried the "domain" keyword, there's still the same problem:

var('n', domain=ZZ)
var('a x')
f(x) = gen_laguerre(n,a,x)

TypeError: unable to convert x (=n) to an integer


How do I reassure those functions that I will give integers to n later in each calculation?

edit retag close merge delete

Sort by » oldest newest most voted

gen_laguerre wraps maxima's function with the same name. In maxima, if you enter gen_laguerre(5,6,x), for example, you get a polynomial in x, and this is what the sage function is intended for.

If you enter in maxima gen_laguerre(n,a,x) it will accept it and spit gen_laguerre(n,a,x) back at you, and will later know how to differentiate it with respect to x, for example, but this capability is currently not wrapped in sage. You can work directly with maxima objects:

sage: f = maxima('gen_laguerre(n,a,x)')
sage: f.diff(x)
(n*gen_laguerre(n,a,x)-(n+a)*gen_laguerre(n-1,a,x)*unit_step(n))/x


but if you only intend to evaluate your function later, and not use symbolic manipulations (such as diff), you can create a python function instead of a symbolic object:

sage: f = lambda n,a,x:gen_laguerre(n,a,x)
sage: f(3,4,5)
-10/3


BTW, this is the code of gen_laguerre:

sage_eval(maxima.eval('gen_laguerre(%s,%s,x)'%(ZZ(n),a)), locals={'x':x})


so you see that n is evaluated to an integer. If you do

maxima.eval('gen_laguerre(n,a,x)')


instead you will just get a string saying gen_laguerre(n,a,x) which is not very useful.

more

Another thing you can do is to initialize a symbolic function with its derivative etc. See Ticket #11143 for a lot of discussion of how to do this. Of course, we'd love to have you contribute that to Sage in that case so that others can use it!

more

There is a patch attached to #9706 which fixes this. It's quite old, so it might need some manual care. It would be great if someone started working on that ticket again. I don't think Stefan has time any more.

more