Derivatives of bessel_K have the wrong sign

75 views
Skip to first unread message

roman...@googlemail.com

unread,
Sep 19, 2014, 10:23:09 AM9/19/14
to sage-s...@googlegroups.com
Hello,
it seems that the derivatives of bessel_K have the wrong sign:

sage: [Bessel(i, 'K')(x).diff(x) for i in range(5)]
[1/2*bessel_K(1, x) + 1/2*bessel_K(-1, x), 1/2*bessel_K(2, x) + 1/2*bessel_K(0, x), 1/2*bessel_K(3, x) + 1/2*bessel_K(1, x), 1/2*bessel_K(4, x) + 1/2*bessel_K(2, x), 1/2*bessel_K(5, x) + 1/2*bessel_K(3, x)]

on:
Sage Version 6.1.1, Release Date: 2014-02-04
CPU: AMD Athlon(tm) 64 X2 Dual Core Processor 4200+
OS: Ubuntu 12.04.5 LTS

For type J, Y and I Bessel functions the derivatives appear to be right.

Best regards,
Roman.

roman...@googlemail.com

unread,
Sep 19, 2014, 9:19:08 PM9/19/14
to sage-s...@googlegroups.com
Ok, convert to maxima, derive, convert back to sage works fine.
At first a little bit confusing for the unprepared mind though.

kcrisman

unread,
Sep 22, 2014, 8:31:58 AM9/22/14
to sage-s...@googlegroups.com


Ok, convert to maxima, derive, convert back to sage works fine.

Good workaround!  But I assume this is still incorrect in Sage proper, though?  (The derivative is done by Pynac/Ginac, not Maxima.)

Nils Bruin

unread,
Sep 22, 2014, 12:16:08 PM9/22/14
to sage-s...@googlegroups.com
On Monday, September 22, 2014 5:31:58 AM UTC-7, kcrisman wrote:
Good workaround!  But I assume this is still incorrect in Sage proper, though?  (The derivative is done by Pynac/Ginac, not Maxima.)

It would seem so:

sage: bessel_K(3,x).diff(x)
1/2*bessel_K(4, x) + 1/2*bessel_K(2, x)
sage: SR(maxima_calculus(bessel_K(3,x)).diff(x))
-1/2*bessel_K(4, x) - 1/2*bessel_K(2, x)

Given that bessel_K(3,x) is not a constant function, at least one of those answers must be wrong.

Nils Bruin

unread,
Sep 22, 2014, 12:27:06 PM9/22/14
to sage-s...@googlegroups.com


On Monday, September 22, 2014 9:16:08 AM UTC-7, Nils Bruin wrote:

sage: bessel_K(3,x).diff(x)
1/2*bessel_K(4, x) + 1/2*bessel_K(2, x)
sage: SR(maxima_calculus(bessel_K(3,x)).diff(x))
-1/2*bessel_K(4, x) - 1/2*bessel_K(2, x)

Given that bessel_K(3,x) is not a constant function, at least one of those answers must be wrong.

The formula is hard-coded in sage.functions.bessel.py  as Function_Bessel_K._derivative_ (line 843). Fixing should be a one character edit.

slelievre

unread,
Sep 22, 2014, 1:00:48 PM9/22/14
to sage-s...@googlegroups.com

kcrisman

unread,
Sep 23, 2014, 9:04:30 AM9/23/14
to sage-s...@googlegroups.com, Benjamin Jones
sage: bessel_K(3,x).diff(x)
1/2*bessel_K(4, x) + 1/2*bessel_K(2, x)
sage: SR(maxima_calculus(bessel_K(3,x)).diff(x))
-1/2*bessel_K(4, x) - 1/2*bessel_K(2, x)

Given that bessel_K(3,x) is not a constant function, at least one of those answers must be wrong.

The formula is hard-coded in sage.functions.bessel.py  as Function_Bessel_K._derivative_ (line 843). Fixing should be a one character edit.

I.e. 

return -(bessel_K(n - 1, x) + bessel_K(n + 1, x)) / Integer(2)
 
instead of 

return (bessel_K(n - 1, x) + bessel_K(n + 1, x)) / Integer(2)
It looks like this may have just been copied from bessel_I in the original place, most likely..  Wolfram functions also says this is a correct change, so go for it!

Nils Bruin

unread,
Sep 23, 2014, 1:48:41 PM9/23/14
to sage-s...@googlegroups.com, benjami...@gmail.com
On Tuesday, September 23, 2014 6:04:30 AM UTC-7, kcrisman wrote:

It looks like this may have just been copied from bessel_I in the original place, most likely..  Wolfram functions also says this is a correct change, so go for it!
 
OK, this seemed like the perfect change to try to make with github. Indeed, a pull request there gets translated into a trac ticket:

 http://trac.sagemath.org/ticket/17031

but no branch gets created! That's pretty useless.
Reply all
Reply to author
Forward
0 new messages