{"record":{"id":"260f21d7d710acbb","repo":"jax-ml/jax","slug":"order-of-derivative-must-be-positive","errorCode":null,"errorMessage":"Order of derivative must be positive","messagePattern":"Order of derivative must be positive","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/polynomial.py","lineNumber":623,"sourceCode":"\n    The first order derivative of the polynomial :math:`2 x^3 - 5 x^2 + 3 x - 1`\n    is :math:`6 x^2 - 10 x +3`:\n\n    >>> p = jnp.array([2, -5, 3, -1])\n    >>> jnp.polyder(p)\n    Array([  6., -10.,   3.], dtype=float32)\n\n    and its second order derivative is :math:`12 x - 10`:\n\n    >>> jnp.polyder(p, m=2)\n    Array([ 12., -10.], dtype=float32)\n  \"\"\"\n  p = ensure_arraylike(\"polyder\", p)\n  m = core.concrete_or_error(operator.index, m, \"'m' argument of jnp.polyder\")\n  p_arr, = promote_dtypes_inexact(p)\n  del p\n  if m < 0:\n    raise ValueError(\"Order of derivative must be positive\")\n  if m == 0:\n    return p_arr\n  coeff = (arange(m, len(p_arr), dtype=p_arr.dtype)[np.newaxis]\n          - arange(m, dtype=p_arr.dtype)[:, np.newaxis]).prod(0)\n  return p_arr[:-m] * coeff[::-1]\n\n\n@export\ndef polymul(a1: ArrayLike, a2: ArrayLike, *, trim_leading_zeros: bool = False) -> Array:\n  r\"\"\"Returns the product of two polynomials.\n\n  JAX implementation of :func:`numpy.polymul`.\n\n  Args:\n    a1: 1D array of polynomial coefficients.\n    a2: 1D array of polynomial coefficients.\n    trim_leading_zeros: Default is ``False``. If ``True`` removes the leading\n      zeros in the return value to match the result of numpy. But prevents the","sourceCodeStart":605,"sourceCodeEnd":641,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/polynomial.py#L605-L641","documentation":"jnp.polyder requires the derivative order m to be a non-negative integer; negative orders are rejected because integration (polyint) is a separate API.","triggerScenarios":"Calling jnp.polyder(p, m=-1) or any negative integer order.","commonSituations":"Loop variables for differentiation order going negative; mixing up polyint/polyder sign conventions; user-supplied order parameter not validated.","solutions":["Use jnp.polyder only with m >= 0","Use jnp.polyint for negative-order intent","Clamp or validate m at the call site"],"exampleFix":"// before\njnp.polyder(p, m=-1)\n// after\njnp.polyint(p, m=1)","handlingStrategy":"validation","validationCode":"m = int(m)\nassert m >= 0, 'polyder order must be >= 0'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Guard order parameters in loops that decrement m","Use polyint for integration semantics"],"tags":["jax","polyder","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}