I'm working with Airy functions. Although sage can evaluate
airy_ai(1.0), it cannot form a symbolic expression like:
A*airy_ai(x)+B*airy_bi, which is what i need.
So I decided to define the symbolic functions:
ai=function('ai',x,latex_name='Ai')
bi=function('bi',x,latex_name='Bi')
this way
f=A*airy_ai(x)+B*airy_bi
f
looks nice, but I also need to use their derivatives,
un fortunately, the diff function returns a rather ugly output:
A1*D[0](ai)(x) + B1*D[0](bi)(x)
I can live with that, but I also need to be able to visualize in
typesetted form some complicated expressions involving the derivatives
of Airy functions, so I would very much prefer if diff(ai) would be
typesetted the same way as
aip=function('aip',x,latex_name='Ai\'')
Can this be done?
Thank you!
Oscar
On Tue, 7 Feb 2012 00:08:04 -0800 (PST)
Oscar Lazo <algebra...@gmail.com> wrote:
> Done:
>
> http://trac.sagemath.org/sage_trac/ticket/12455
Thanks!
> I've added a patch, which should do the job, but it has a few
> shortcomings:
>
> 1.-The resulting symbolic functions seem to remain on hold:
>
> sage: airy_ai(1.0)
> airy_ai(1.00000000000000)
>
> You need to force it to evaluate:
>
> sage: airy_ai(1.0).n()
> 0.135292416313
You need to add an _eval_() function which calls _evalf_() if the
argument is not exact. See this patch for an example:
http://trac.sagemath.org/sage_trac/attachment/ticket/4498/trac_4498-symbolic_arg.cleanup.patch
> 2.- This doesn't work:
>
> sage: airy_ai(2.0).n(digits=100)
> 0.0349241304233
The _evalf_() function in your patch hard codes RDF. You need to do
something like this:
sage: from sage.libs.mpmath import utils as mpmath_utils
sage: import mpmath
sage: mpmath_utils.call(mpmath.airyai, 1, parent=RR)
0.135292416312881
> 3.- There is no evaluation for airy_ai_prime or airy_bi_prime
I don't think we want to have separate functions for the derivatives in
Sage. These might help you get around the printing problem for now, but
they are not useful in general.
BTW, #6244 has a patch that changes the way derivatives are printed:
http://trac.sagemath.org/sage_trac/ticket/6344#comment:2
> 4.- I'm not sure about how should the functions be called, some
> possible schemes are
>
> {ai,bi,aip,bip} {ai,bai,aip,baip}
> {airy_ai,airy_bi,airy_ai_prime,airy_bi_prime}
>
> And also whether the latex representation should be capitalized or
> not. I chose the third scheme, and capitalized typesetting.
I like airy_{a,b}i and capitalized typesetting as well.
Cheers,
Burcin
You're right, I didn't know mpmath supported this. We can have a main
function that takes a single argument and another one with two
arguments to represent the derivatives. This is similar to how maple
implements the airy function:
http://www.maplesoft.com/support/help/Maple/view.aspx?path=Airy
The implementation would be similar to that of the psi function:
http://hg.sagemath.org/sage-main/file/tip/sage/functions/other.py#l810
Note that there are two symbolic functions Function_psi1 and
Function_psi2, with a regular python function names psi() that
wraps these.
You can also put the new functions in a new file sage/functions/airy.py.
Cheers,
Burcin