jax-ml/jax · error · ValueError

Order of derivative must be positive

Error message

Order of derivative must be positive

What it means

jnp.polyder requires the derivative order m to be a non-negative integer; negative orders are rejected because integration (polyint) is a separate API.

Source

Thrown at jax/_src/numpy/polynomial.py:623

    The first order derivative of the polynomial :math:`2 x^3 - 5 x^2 + 3 x - 1`
    is :math:`6 x^2 - 10 x +3`:

    >>> p = jnp.array([2, -5, 3, -1])
    >>> jnp.polyder(p)
    Array([  6., -10.,   3.], dtype=float32)

    and its second order derivative is :math:`12 x - 10`:

    >>> jnp.polyder(p, m=2)
    Array([ 12., -10.], dtype=float32)
  """
  p = ensure_arraylike("polyder", p)
  m = core.concrete_or_error(operator.index, m, "'m' argument of jnp.polyder")
  p_arr, = promote_dtypes_inexact(p)
  del p
  if m < 0:
    raise ValueError("Order of derivative must be positive")
  if m == 0:
    return p_arr
  coeff = (arange(m, len(p_arr), dtype=p_arr.dtype)[np.newaxis]
          - arange(m, dtype=p_arr.dtype)[:, np.newaxis]).prod(0)
  return p_arr[:-m] * coeff[::-1]


@export
def polymul(a1: ArrayLike, a2: ArrayLike, *, trim_leading_zeros: bool = False) -> Array:
  r"""Returns the product of two polynomials.

  JAX implementation of :func:`numpy.polymul`.

  Args:
    a1: 1D array of polynomial coefficients.
    a2: 1D array of polynomial coefficients.
    trim_leading_zeros: Default is ``False``. If ``True`` removes the leading
      zeros in the return value to match the result of numpy. But prevents the

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Use jnp.polyder only with m >= 0
  2. Use jnp.polyint for negative-order intent
  3. Clamp or validate m at the call site

Example fix

// before
jnp.polyder(p, m=-1)
// after
jnp.polyint(p, m=1)
Defensive patterns

Strategy: validation

Validate before calling

m = int(m)
assert m >= 0, 'polyder order must be >= 0'

Prevention

When it happens

Trigger: Calling jnp.polyder(p, m=-1) or any negative integer order.

Common situations: Loop variables for differentiation order going negative; mixing up polyint/polyder sign conventions; user-supplied order parameter not validated.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27). Data as JSON: /api/errors/260f21d7d710acbb. Report an issue: GitHub.