Fix reciprocal power simplification loop - #3701
Open
belomaxorka wants to merge 1 commit into
Open
belomaxorka wants to merge 1 commit into
belomaxorka wants to merge 1 commit into
Conversation
`n/n1 -> n*n1^-1` rewrites `1/X` as `1 * X^-1`, and distributing a power over that product creates a `1^n` factor. Nothing eliminates it, so every pass merges a freshly created `1^n` into the accumulated one through `n^n1 * n^n2 -> n^(n1+n2)`. The exponent keeps growing, the expression string never repeats, and `_simplify` never reaches its fixed point. Add `1^n -> 1` after the power distribution rules, so the unit factor is removed where it appears. Expressions that already converged keep their results, except that stray `1^...` factors are no longer left behind in the output. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
belomaxorka
force-pushed
the
fix/simplify-reciprocal-power-loop
branch
from
September 22, 2026 04:34
747b5b6 to
78c9f28
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3693.
simplifynever terminates on(1/(x*(y-1)))^(1/(y-1)), and on symbolic powers of any reciprocal product.Cause
n/n1 -> n*n1^-1rewrites1/Xas1 * X^-1. Distributing a power over that product leaves a1^nfactor, and nothing in the rule set removes it. Each pass creates a fresh one and merges it into the accumulated factor throughn^n1 * n^n2 -> n^(n1+n2), so the exponent keeps growing and the expression string never repeats:_simplifystops when it revisits a string, so it loops forever.simplifyCorealready foldsn^0andn^1, but not1^n.Change
One rule,
1^n -> 1, placed after the power distribution rules so the unit factor is removed where it is created.Effect on existing results
Checked 1766 expressions against the current
develop:developoutput contained a stray1 ^ ...factor that is now gone, for example1 ^ z * (x + 1) ^ z / 2 ^ zbecomes(x + 1) ^ z / 2 ^ z.All 338 changed outputs were compared numerically against the
developoutput at 20 points each with complex-aware comparison: no differences. The 143 newly converging results were compared against their original expressions the same way: no differences.The output form of expressions that already worked is otherwise untouched —
1/x^2stays1 / x ^ 2andx^(-2)staysx ^ (-2).Tests
should terminate when simplifying symbolic powers of reciprocalscovers five looping expressions with a pass counter that fails instead of hanging the runner, asserts the simplified form and checks it numerically against the original.should remove unit factors raised to a powercovers the rule itself. Both fail ondevelopand pass here. One case was added to the non-commutative-multiplication block.npm run test:allpasses on Node 26: 6654 source, 36 generated and 295 node tests, plustscand the TypeScript tests.eslint --max-warnings 0is clean.