jax
e45ccf46 - Fix precision and premature overflow in jax.scipy.special.log_ndtr and its JVP.

Commit
24 days ago
Fix precision and premature overflow in jax.scipy.special.log_ndtr and its JVP. Previously, `log_ndtr` and its JVP had three issues in the negative tail: 1. For `x <= -20` in `float64`, `_log_ndtr_lower` used a fixed 3-term asymptotic series (`series_order=3`), whose omitted `7!! / x^8` term lost up to ~141,500 ULP near `x = -20`. 2. Below `-10` (`-20` in `float64`), `_log_ndtr_lower` computed `square(x)`, which overflowed early to `+inf` when `|x|` was between `sqrt(fmax)` and `sqrt(2 * fmax)` even though `-0.5 * x^2 >= -fmax` was still finite. 3. `_log_ndtr_jvp` evaluated `exp(_norm_logpdf(x) - log_ndtr(x))`, cancelling `-0.5 * x^2` against `log_ndtr(x)` (up to ~180 ULP error in `float32`), overflowing `square(x)` early above `sqrt(fmax)`, and returning `(-inf) - (-inf) = NaN` once `log_ndtr(x) = -inf`. Move the `log_ndtr` implementation to `jax._src.lax.erf` next to `ndtr`: use `log1p(-ndtr(-x))` for `x > 0`, `log(ndtr(x))` for `-sqrt(2) <= x <= 0`, and `-2 * (0.5 * |x|)^2 + log(0.5 * erfcx_large(|x| / sqrt(2)))` for `x < -sqrt(2)`. Also evaluate `_log_ndtr_jvp` via a closed `@custom_jvp` helper `(r, q) = (log_ndtr'(x), x + log_ndtr'(x))` with `r' = -r * q` and `q' = 1 - r * q` so higher-order derivatives stay accurate in the negative tail without differentiating through minimax polynomials. PiperOrigin-RevId: 1009903930
Author
Parents
Loading