{"record":{"id":"fd33cb61839a6dec","repo":"jax-ml/jax","slug":"cannot-divide-self-by-divisor","errorCode":null,"errorMessage":"Cannot divide {self} by {divisor}.","messagePattern":"Cannot divide (.+?) by (.+?)\\.","errorType":"exception","errorClass":"InconclusiveDimensionOperation","httpStatus":null,"severity":"error","filePath":"jax/_src/export/shape_poly.py","lineNumber":380,"sourceCode":"\n  def mul(self, other: _DimTerm) -> _DimTerm:\n    \"\"\"\n    Returns the product with another term. Example: (n^2*m) * n == n^3 * m.\n    \"\"\"\n    return _DimTerm(_DimExpr._linear_combination_sorted_pairs(self._factors, 0, 1,\n                                                              other._factors, 0, 1))\n\n  def divide(self, divisor: _DimTerm) -> _DimTerm:\n    \"\"\"\n    Divides by another term. Raises a InconclusiveDimensionOperation\n    if the result is not a term.\n    For example, (n^3 * m) // n == n^2*m, but n // m fails.\n    \"\"\"\n    new_factors = _DimExpr._linear_combination_sorted_pairs(self._factors, 0, 1,\n                                                            divisor._factors, 0, -1)\n    for _, f_exp in new_factors:\n      if f_exp <= 0:\n        raise InconclusiveDimensionOperation(f\"Cannot divide {self} by {divisor}.\")\n    return _DimTerm(new_factors)\n\n  def evaluate(self, env: DimVarEnv, scope: SymbolicScope):\n    prod = lambda xs: functools.reduce(_evaluate_multiply, xs) if xs else core.dim_constant(1)\n    def pow_opt(v, p: int):\n      return v if p == 1 else prod([v] * p)\n    return prod([pow_opt(f.evaluate(env, scope), exp) for f, exp in self._factors])\n\n  def __deepcopy__(self, memo):\n    return _DimTerm(copy.deepcopy(self._factors, memo))\n\n# The constant 1, as a term.\n_DimTerm_one = _DimTerm(())\n\n\nclass _DimExpr:\n  \"\"\"Symbolic expressions using dimension variables.\n","sourceCodeStart":362,"sourceCodeEnd":398,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/export/shape_poly.py#L362-L398","documentation":"JAX's symbolic dimension algebra can only divide (floordiv) a polynomial term by another when every factor of the divisor cancels to a positive exponent, e.g. (n^3*m)//n == n^2*m. If any factor would end with exponent <= 0 (or the divisor has factors absent from the dividend), the operation is inconclusive.","triggerScenarios":"Calling // or divmod on symbolic dims like n // m, (2*n) // n**2, or reshape logic that divides unrelated dim vars during polymorphic export.","commonSituations":"Reshapes or poolings with symbolic batch dims where JAX must divide symbolic dims that don't divide evenly; using x.reshape(-1, m) with two independent symbolic variables.","solutions":["Rewrite the computation so the division is by a factor that provably divides the dividend (express dims as n, n*2, etc.)","Use explicit dimension variables tied by constraints (SymbolicScope equality constraints) so normalization can cancel","Pass concrete shapes (drop polymorphism) for that part of the model"],"exampleFix":"# before\ny = x.reshape(n, -1)  # divides n*m by n symbolically ok, but x.reshape(-1, m) with unknowns fails\n# after\n# make total size a known multiple: parameterize shape as (n, m) and reshape to (n*m,) explicitly\ny = x.reshape(n * m)","handlingStrategy":"try-catch","validationCode":"# before exporting, dry-run reshape arithmetic on a sample symbolic scope\nscope = jax.export.shape_poly.SymbolicScope(())\nn, m = jax.export.shape_poly.make_symbolic_scope_vars  # or construct dims via parsing\n# simply: verify divisor factors subset of dividend factors","typeGuard":null,"tryCatchPattern":"from jax._src.export import shape_poly\ntry:\n    y = x.reshape(-1, m)\nexcept shape_poly.InconclusiveDimensionOperation:\n    y = x.reshape(n * m)  # explicit total","preventionTips":["Avoid reshape(-1, k) with multiple independent symbolic dims","Tie variables together with equality constraints so division cancels"],"tags":["jax","shape-polymorphism","floor-division","export"],"backgroundTag":"symbolic-dimension-inconclusive-operation","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}