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.)
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.
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.
return -(bessel_K(n - 1, x) + bessel_K(n + 1, x)) / Integer(2) |
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!