`jax.scipy.stats.norm.isf` returns `inf` for finite upper-tail quantiles
Description
jax.scipy.stats.norm.isf(q) loses small tail probabilities because it is
implemented as norm.ppf(1 - q). In float64, 1 - q rounds to 1.0 for
q <= 1e-17, so isf returns inf even though the quantile is finite.
import jax
import jax.numpy as jnp
import jax.scipy.stats as jstats
import scipy.stats as stats
jax.config.update("jax_enable_x64", True)
for q in (1e-16, 1e-17, 1e-20, 1e-100, 1e-300):
q = jnp.float64(q)
print(float(q), float(jstats.norm.isf(q)), stats.norm.isf(float(q)))
Output:
1e-16 8.209536151601387 8.222082216130435
1e-17 inf 8.493793224109599
1e-20 inf 9.262340089798409
1e-100 inf 21.273453560965322
1e-300 inf 37.0470962993612
The current implementation is:
def isf(q, loc=0, scale=1):
return ppf(lax.sub(_lax_const(q, 1), q), loc, scale)
I would expect isf to compute the upper-tail quantile without forming
1 - q, so that finite representable tail probabilities produce finite,
accurate results. This also breaks the inverse relation:
norm.sf(norm.isf(1e-20)) returns 0.0 instead of approximately 1e-20.
The behavior is the same in eager and jitted execution and is present in both JAX 0.10.2 and 0.11.2.
System info (python version, jaxlib version, accelerator, etc.)
jax: 0.11.2
jaxlib: 0.11.2
scipy: 1.18.1
numpy: 2.5.3
python: 3.13.7
platform: macOS 26.6.2 arm64
device: CpuDevice(id=0)
I'd like to work on this.
The issue is that norm.isf(q) is implemented as norm.ppf(1 - q), which loses precision for small tail probabilities. In float64, 1 - q rounds to 1.0 for q <= 1e-17, so isf returns inf.
The fix is to compute the upper-tail quantile without forming 1 - q. This can be done by using norm.ppf with a complement that preserves precision, or by using a dedicated inverse survival function implementation.
I'll add regression tests for small tail probabilities (1e-16, 1e-17, 1e-20, 1e-100, 1e-300).