{"record":{"id":"f61d6f392ab18eef","repo":"jax-ml/jax","slug":"series-order-must-be-30","errorCode":null,"errorMessage":"series_order must be <= 30.","messagePattern":"series_order must be <= 30\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/scipy/special.py","lineNumber":1670,"sourceCode":"  Args:\n    x: an array of type `float32`, `float64`.\n    series_order: Positive Python integer. Maximum depth to\n      evaluate the asymptotic expansion. This is the `N` above.\n\n  Returns:\n    an array with `dtype=x.dtype`.\n\n  Raises:\n    TypeError: if `x.dtype` is not handled.\n    TypeError: if `series_order` is a not Python `integer.`\n    ValueError:  if `series_order` is not in `[0, 30]`.\n  \"\"\"\n  if not isinstance(series_order, int):\n    raise TypeError(\"series_order must be a Python integer.\")\n  if series_order < 0:\n    raise ValueError(\"series_order must be non-negative.\")\n  if series_order > 30:\n    raise ValueError(\"series_order must be <= 30.\")\n\n  x_arr = jnp.asarray(x)\n  dtype = lax.dtype(x_arr)\n\n  if dtype == np.float64:\n    lower_segment: np.ndarray = _LOGNDTR_FLOAT64_LOWER\n    upper_segment: np.ndarray = _LOGNDTR_FLOAT64_UPPER\n  elif dtype == np.float32:\n    lower_segment = _LOGNDTR_FLOAT32_LOWER\n    upper_segment = _LOGNDTR_FLOAT32_UPPER\n  else:\n    raise TypeError(f\"x.dtype={np.dtype(dtype)} is not supported.\")\n\n  # The basic idea here was ported from:\n  #   https://root.cern.ch/doc/v608/SpecFuncCephesInv_8cxx_source.html\n  # We copy the main idea, with a few changes\n  # * For x >> 1, and X ~ Normal(0, 1),\n  #     Log[P[X < x]] = Log[1 - P[X < -x]] approx -P[X < -x],","sourceCodeStart":1652,"sourceCodeEnd":1688,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/scipy/special.py#L1652-L1688","documentation":"log_ndtr's series_order is capped at 30 because the precomputed coefficient tables and the asymptotic expansion only cover 30 terms; more terms bring no accuracy benefit and would need larger tables. Values above 30 raise ValueError.","triggerScenarios":"Calling log_ndtr(x, series_order=31) or higher, often from a sweep or an accuracy-tuning loop that assumes more is better.","commonSituations":"Accuracy tuning where users crank the order; copying order values from other libraries' settings; automated hyperparameter search exceeding the bound.","solutions":["Clamp to 30: series_order = min(30, int(order)) — the default of 3 is usually already sufficient for float32/64 accuracy","Read the docstring's documented [0, 30] range and pick a modest value (3–18)","If more tail accuracy is truly needed, use log_ndtr(x.astype(jnp.float64), order) instead of raising order"],"exampleFix":"// before\njax.scipy.special.log_ndtr(x, series_order=50)\n// after\njax.scipy.special.log_ndtr(x, series_order=min(30, 50))","handlingStrategy":"validation","validationCode":"series_order = min(30, max(0, int(series_order)))","typeGuard":"def order_in_range(o):\n    return isinstance(o, int) and 0 <= o <= 30","tryCatchPattern":null,"preventionTips":["Prefer float64 inputs over huge orders for tail accuracy","Document the [0,30] contract wherever log_ndtr is exposed"],"tags":["jax","scipy-special","log-ndtr","argument-validation"],"backgroundTag":"out-of-range-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}