Skip to content

Fix #422: tensor sub simplifier round-7 parity (0 - (-A) built nested negative) - #423

Open
petlenz wants to merge 1 commit into
mainfrom
fix-422-tensor-sub-round7-parity
Open

Fix #422: tensor sub simplifier round-7 parity (0 - (-A) built nested negative)#423
petlenz wants to merge 1 commit into
mainfrom
fix-422-tensor-sub-round7-parity

Conversation

@petlenz

@petlenz petlenz commented Aug 2, 2026

Copy link
Copy Markdown
Member

Closes #422.

Round-7 (001164d) routed sub_base::dispatch(zero) and dispatch(negative) through operator- in the scalar and t2s domains; the tensor domain was missed and still built raw negative nodes:

  • dispatch(tensor_zero): 0 - (-A) produced negative(negative(A)) instead of A.
  • dispatch(tensor_negative): a sum that itself normalizes to a negative re-wrapped into a nested negative (the scalar R7-1 shape).

Both now route through operator- (whose tag_invoke(neg_fn, ...) already folds -0 → 0 and -(-x) → x). Behavior preserved: the 0 - 0 special case flows through the operator's zero branch; the tensor-specific is_valid guard on the negative-lhs path (tensor add can yield an invalid holder on full cancellation) stays.

Found downstream: numsim-codegen's emitters received the nested-negative node and produced invalid C++ (--A) until they grew a defensive paren guard (numsim-codegen#136 / PR numsim-codegen#147, which keeps its guard as defense-in-depth).

Test: RoundSevenReview.TensorSubNormalizesLikeScalarAndT2s0-(-A) → A, 0-0 → 0, (-A)-(-A) → 0 (not negative(zero)), (-A)-B → -(A+B) unchanged. Full suite: 2311/2311 green locally (gcc-14 Debug).

…/dispatch(negative) through operator-

Signed-off-by: petlenz <peterlenz89.pl@gmail.com>
@petlenz
petlenz force-pushed the fix-422-tensor-sub-round7-parity branch from 68cfaa4 to 3eab126 Compare August 2, 2026 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tensor sub simplifier missed the round-7 normalization: 0 - (-A) builds negative(negative(A))

1 participant