Skip to content

merge_add (add+add) lacks the review-fix hygiene: missed cancellations and associativity-dependent forms #411

Description

@petlenz

Summary

Deferred finding from the adversarial review of PR #386/#387 (value-correct, so not blocking): merge_add — the add+add merge in include/numsim_cas/functions.h — applies find_like per child but has none of the hygiene the dispatcher paths gained in the review fixes:

  • no reverse-direction probe (stored bare x, incoming child 2*x from the other add): (2*x+y) + (z + (-2*x))2*x+y+z-2*x — the cancellation is missed;
  • no zero filter / degenerate collapse after combining;
  • consequence: (a+b)+c vs a+(b+c) can produce structurally different, ==-unequal results even though both evaluate identically.

How to fix

Route merge_add's per-child insertion through the same helper the dispatchers use (merge_and_finish-style: probe both directions, filter zero_type, collapse empty/single-child, invalidate_hash). The helper currently lives on add_dispatch; hoist it to a free function next to merge_add so both share one implementation.

Tests

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions