Ask Your Question
1

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

asked 2011-11-06 03:18:21 +0100

minihair gravatar image

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 flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
2

answered 2011-11-06 13:48:05 +0100

parzan gravatar image

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.

edit flag offensive delete link more
1

answered 2011-11-07 10:49:09 +0100

kcrisman gravatar image

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!

edit flag offensive delete link more
0

answered 2011-11-10 08:16:59 +0100

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-11-06 03:18:21 +0100

Seen: 987 times

Last updated: Nov 10 '11