{"record":{"id":"ad06dfa8cc1035ca","repo":"jax-ml/jax","slug":"found-multiple-equality-constraints-with-the-same","errorCode":null,"errorMessage":"Found multiple equality constraints with the same left-hand-side: {before}","messagePattern":"Found multiple equality constraints with the same left-hand-side: (.+?)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"jax/_src/export/shape_poly.py","lineNumber":1085,"sourceCode":"  def _process_explicit_constraint(self, constr: _SymbolicConstraint):\n    if (diff_const := _DimExpr._to_constant(constr.diff)) is not None:\n      if ((constr.cmp == Comparator.EQ and diff_const != 0) or\n          (constr.cmp == Comparator.GEQ and diff_const < 0)):\n        raise ValueError(f\"Unsatisfiable explicit constraint: {constr.debug_str}\")\n      return\n\n    if constr.cmp == Comparator.EQ:\n      if not isinstance(constr.e1, _DimExpr):\n        raise ValueError(\"Invalid equality constraint: {e1} == {e2}. \"\n                         \"The left-hand-side must be of the form `term * coefficient`.\")\n      (before, before_k), *rest = constr.e1._sorted_terms\n      if rest:\n        raise ValueError(\"Invalid equality constraint: {e1} == {e2}. \"\n                         \"The left-hand-side must be of the form `term * coefficient`.\")\n\n      after = _ensure_poly(constr.e2, \"parse_constraint\", constr.e1.scope)\n      if before in self._normalization_rules:\n        raise NotImplementedError(\n            f\"Found multiple equality constraints with the same left-hand-side: {before}\")\n      self._normalization_rules[before] = (after, before_k)\n      # Look for constraints of the form mod(before_e1, before_k2) * 1 == 0\n      if (before_k == 1 and\n          isinstance(constr.e2, int) and constr.e2 == 0 and\n          (before_f := before.to_factor()) and\n          before_f.operation == _DimFactor.MOD and\n          (before_k2 := _DimExpr._to_constant(before_f.operands[1])) is not None):\n        # Add before_k2*floordiv(before_e1, before_k2) == before_e1\n        k_times_floordiv = _DimExpr._from_term(\n            _DimTerm.from_operation(\n                _DimFactor.FLOORDIV, *before_f.operands, scope=constr.e1.scope),\n            before_k2, scope=constr.e1.scope)\n        before_e1 = before_f.operands[0]\n        self._process_explicit_constraint(\n            _SymbolicConstraint(cmp=Comparator.EQ,\n                                e1=k_times_floordiv, e2=before_e1,\n                                diff=k_times_floordiv - before_e1,","sourceCodeStart":1067,"sourceCodeEnd":1103,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/export/shape_poly.py#L1067-L1103","documentation":"Equality constraints act as normalization rules keyed by their left-hand-side term. Two constraints with the same LHS term (e.g. 'a == b' and 'a == c') would give contradictory definitions, which is not yet supported, hence NotImplementedError.","triggerScenarios":"Adding constraints 'a*2 == b' and 'a*2 == c' (same normalized LHS term) to one SymbolicScope, including when the second is added later via scope.add_constraint.","commonSituations":"Dynamically accumulated constraints from multiple modules colliding on the same variable; refactoring that duplicates an existing equality.","solutions":["Express one variable in terms of the other instead of repeating the LHS: keep 'a == b' and write 'b == c' (or substitute)","Remove the duplicate equality","Restructure so each symbolic variable is defined by exactly one equality constraint"],"exampleFix":"# before\nconstraints = ('a == b', 'a == c')\n# after\nconstraints = ('a == b', 'b == c')","handlingStrategy":"validation","validationCode":"lhs_terms = [normalized_lhs(c) for c in eq_constraints]\nassert len(lhs_terms) == len(set(lhs_terms)), 'duplicate LHS in equality constraints'","typeGuard":null,"tryCatchPattern":"try:\n    scope.add_constraint(c)\nexcept NotImplementedError as e:\n    if 'same left-hand-side' in str(e): rewrite_via_chain(c)","preventionTips":["Define each variable exactly once via equality","Chain definitions (a==b, b==c) instead of repeating an LHS"],"tags":["jax","shape-polymorphism","constraints","duplicate-key"],"backgroundTag":"duplicate-constraint-definition","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}