Possible problem with custom derivative of jnp.sinc. at x=0 #23990
-
Hello, Lines 2940 to 2953 in 15024ba But looking at the successive derivative at x=0 sincp = grad(jnp.sinc)
sincp2 = grad(sincp)
sincp3 = grad(sincp2)
sincp4 = grad(sincp3)
sincp(0.),sincp2(0.),sincp3(0.),sincp4(0.) gives
But clearly in Mathematica
which will gives for the sincp2(0.), sincp4(0.).
And if one instead uses
then one recovers the current JAX sinc behavior as
So I wander if someones forget to use the factorial "(p+1)!" (ie. Gamma[p+2]) and use simply ("p+1"). If I am true this is a bug in the current version. and I propse @partial(custom_jvp, nondiff_argnums=(0,))
def _sinc_maclaurin(k, x):
# compute the kth derivative of x -> sin(x)/x evaluated at zero (since we
# compute the monomial term in the jvp rule)
# TODO(mattjj): see https://github.com/jax-ml/jax/issues/10750
if k % 2:
return x * 0
else:
return x * 0 + _lax_const(x, (-1) ** (k // 2) / jax.numpy.exp(jax.lax.lgamma(k+2.)) If not then there is some I do not undersrtand. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
I don't understand the mathematica result you quote: it just seems wrong. For example, here is a table of sinc derivatives at >>> np.pi ** 2 * (-1 / 3)
-3.289868133696453
>>> np.pi ** 4 * (1 / 5)
19.481818206800483 Checking another source, wolfram alpha returns values that match this table, and thus agrees with JAX: https://www.wolframalpha.com/input?i=table+d%5En%2Fdx%5En+sinc%28x%29+for+n+%3D+1+...+4 |
Beta Was this translation helpful? Give feedback.
-
Well in Mathematuca
and
While
gives
|
Beta Was this translation helpful? Give feedback.
I don't understand the mathematica result you quote: it just seems wrong.
For example, here is a table of sinc derivatives at$\sin(x)/x$ , while JAX uses the convention $\sin(\pi x)/(\pi x)$ so you need to multiply the values in the table by a factor of $\pi^k$ :
x = 0
that agrees with the formula and output values used in JAX, and disagrees with the formula and values you mention from mathematica: https://calculus.subwiki.org/wiki/Sinc_function#Higher_derivatives_at_zero Note that this table is forChecking another source, wolfram alpha returns values that match this table, and thus agrees with JAX: h…