Skip to content

Fix #344: remove division-style rules from the pow simplifier - #388

Merged
petlenz merged 3 commits into
mainfrom
fix-344-pow-division-rules
Jul 28, 2026
Merged

Fix #344: remove division-style rules from the pow simplifier#388
petlenz merged 3 commits into
mainfrom
fix-344-pow-division-rules

Conversation

@petlenz

@petlenz petlenz commented Jul 24, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #344. Stacked on #387.

The negative-exponent branches of the shared pow simplifier treated pow(a,−b) as the division a/b. Probe-confirmed wrong results fixed (scalar and t2s share the generic dispatch):

Before After
pow(-x, 2)-pow(x,2) (evaluated −9) pow(x,2) → +9
pow(-trace(A), 2)−36 +36
pow(x, -x)1 stays x^(−x) (6⁻⁶ ≈ 2.14e−5)
pow(x*y, -x)y stays structural
pow(x, -y) * yx stays y·x^(−y)
pow(-x, y)-pow(x,y) stays pow(-x,y)

Design

Tests

POW_Simplification / TensorToScalar_PowSimplification explicitly pinned the deleted rules ('division cancellation', 'mul factor cancel'); their expectations update to the corrected contract. Two new evaluation-verified lock-in tests. Full suite: 2426/2426 pass.

@petlenz
petlenz force-pushed the fix-340-hash-identity-sweep branch from 89658e1 to 349c423 Compare July 24, 2026 19:26
@petlenz
petlenz force-pushed the fix-344-pow-division-rules branch from d3e4962 to 951d0e8 Compare July 24, 2026 19:26
@petlenz
petlenz force-pushed the fix-340-hash-identity-sweep branch from 349c423 to 9590ea4 Compare July 25, 2026 11:56
@petlenz
petlenz force-pushed the fix-344-pow-division-rules branch from 951d0e8 to 8f5ef67 Compare July 25, 2026 12:06
@petlenz
petlenz force-pushed the fix-340-hash-identity-sweep branch from 9590ea4 to f2a2102 Compare July 25, 2026 13:25
@petlenz
petlenz force-pushed the fix-344-pow-division-rules branch 7 times, most recently from cb35152 to 444bca1 Compare July 26, 2026 18:40
petlenz added 3 commits July 26, 2026 20:58
The negative-exponent branches treated pow(a, -b) as the division a/b:
pow(x, -x) -> 1, pow(x*y, -x) -> y, pow(x, -y)*y -> x, and pow(-e, p)
-> -pow(e, p) for every exponent (so pow(-x, 2) evaluated to -9 where
+9 is correct; same for pow(-trace(A), 2) -> -36 in the t2s domain,
which shares the generic dispatch). Real division composes as
mul x pow(rhs, -1) with a constant exponent, so these branches never
fired on legitimate divisions - only on wrong inputs.

- Deleted: the expr/expr->1 and erase-matching-factor branches in
  pow_dispatch::get_default, the x*y*z/x branch in
  mul_pow_dispatch::dispatch(negative_type) and its scalar copy, and
  the pow(expr,-p)*p -> expr branch in scalar_pow_mul.
- pow(-e, p) sign pull-out is now gated on a provably integer
  exponent: even folds to pow(e, p), odd to -pow(e, p), anything else
  stays structural. x^(-1)*x -> 1 keeps working via exponent addition.
- POW_Simplification / TensorToScalar_PowSimplification pinned the
  deleted rules ('division cancellation', 'mul factor cancel',
  unconditional negative-base extraction); their expectations update
  to the corrected contract per #344.
- New evaluation-verified lock-in tests in CoreBugFixTest.h.

Signed-off-by: petlenz <peterlenz89.pl@gmail.com>
…ric bases

The even/odd fold built a raw pow node, so nested bases stopped
canonicalizing: pow(-pow(x,2), 2) stayed pow(pow(x,2),2) and never
cancelled against pow(x,4). Recursing through pow() restores the
nested folds; numeric bases stay structural so pow(2,-1) keeps
printing as a division instead of folding to the rational 1/2
(PRINT_DivisionFormat contract). Regression test included.

Signed-off-by: petlenz <peterlenz89.pl@gmail.com>
The division-style fold in scalar_pow_mul::dispatch(scalar) was removed
with the other unsound rules, leaving its 'power' alias unused
(gcc -Wunused-variable).

Signed-off-by: petlenz <peterlenz89.pl@gmail.com>
@petlenz
petlenz force-pushed the fix-344-pow-division-rules branch from 444bca1 to 44b9918 Compare July 26, 2026 19:03
@petlenz
petlenz changed the base branch from fix-340-hash-identity-sweep to main July 28, 2026 18:40
@petlenz
petlenz merged commit 80bf145 into main Jul 28, 2026
39 checks passed
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.

pow simplifier applies division-style rules: pow(-x,2)→-pow(x,2) (evaluates −9 for +9), pow(x,-x)→1, pow(x,-y)*y→x

1 participant