Skip to content

Combine powers only where both sides read the base alike - #2779

Open
Rafael-SOWNet wants to merge 1 commit into
masterfrom
fix-2735-2736-power-rules-off-real-line
Open

Rafael-SOWNet wants to merge 1 commit into
masterfrom
fix-2735-2736-power-rules-off-real-line

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Fixes #2735, Fixes #2736.

Cause

Two mechanisms, both power-combining rules that hold for the principal power e^(n Log u) and were applied where the two sides are not both that.

What changed

Three predicates in Patterns.Power.cs state the conditions:

  • PowersOfOneBaseCombine(base, a, b, subtract): the exponents a, b and a ± b do not mix a real-root reading with a principal one (whole exponents go with either), or the base is a positive number. A symbolic exponent counts as principal, so x^n * x still combines.
  • ThePowerIsPrincipal(u, k): for e^(k ln u) = u^k, c^(k log(c, u)) = u^k and a^(n / log(c, a)) = c^n.
  • APowerOfAPowerMultiplies(a, n, m): for a whole m, the readings of n and n m agree ((x^(1/6))^2 is not x^(1/3)). For any other m, the base is positive and n is real. "Real" is decided the same way log_b(a^c) already decides it (MayTakeLogOfPower: decidably real, the real codomain setting, or the limit machinery's own reading). A numeric n also qualifies when it lies decidably inside the strip.

Every rule asks the matching predicate, in both spellings (the switch in Patterns.Power.cs and MatchedRules.Power / PowerOfPower). So do CollectLikeTerms in Expand and TreeAnalyzer.DivideOnePolynomial. IsWholeOrAnOddRoot now means a denominator below 10, which is what the power does: (1/x)^(1/11) * x is not x^(10/11).

Before / after (master 8b4f507 vs this branch)

input master branch at
simplify(exp((1/3) * ln(x))) x ^ (1/3) (-2) e ^ (ln(x) / 3) (1 + 1.732i) x = -8
simplify(x^(1/3) * x^(1/2)) x ^ (5/6) x ^ (1/3) * sqrt(x) x = -1
simplify(x^(1/2) / x^(1/3)) x ^ (1/6) provided not x = 0 sqrt(x) / x ^ (1/3) x = -1
simplify((x^(1/6))^2) x ^ (1/3) (x ^ (1/6)) ^ 2 x = -1
simplify((x^(3/5) + 2 x^(3/10) + 1) / (x^(3/10) + 1)) 1 + x ^ (3/10) provided ... unchanged x = -2
simplify(exp(i * x)^(5/3)) e ^ (5/3 * i * x) (e ^ (i * x)) ^ (5/3) x = 4.2
simplify(sqrt(exp(x))) e ^ (x / 2) sqrt(e ^ x) x = 4i
simplify((2^x)^(1/2)) 2 ^ (x / 2) sqrt(2 ^ x) x = 10i
expand(exp(i * x)^(5/3) - x) e ^ (i * x * 5/3) + -x (e ^ (i * x)) ^ (5/3) + -x x = 4.2
derive(exp((1/3) * ln(-2 * x)), x) 1/3 * ((-2) * x) ^ (1/3) / x e ^ (ln((-2) * x) / 3) / (3 * x) x > 0

These rewrites are still made: e^(1/2 ln x) = sqrt(x), x^(1/3) x^(2/3) = x, x^(1/2) x^(1/2) = x, (x^(1/2))^2 = x, (2^(1/2))^(1/3) = 2^(1/6), (x^(2/3) - 1)/(x^(1/3) - 1) = x^(1/3) + 1, and e^(k ln x) = x^k with a symbolic k.

Sweep

The sweep generated 1110 inputs: (b^u)^a, sqrt(exp(u)), (exp(u)^k)^a, exp(a ln u), exp(ln(u)/q), 2^(a log(2,u)), u^a * u^b, u^a / u^b, (u^a)^b, and quotients of fractional powers. Each was run through Simplify and through Expand. Values were taken at 11 points: -8, -2.3, -0.7, 0.35, 1.7, 4.2, 4i, 2.1 - 1.7i, 0.3 + 0.7i, -1.5 + 0.2i and 10i. Each value was compared with mpmath at 40 digits, using the library's real-root convention.

right wrong timeout
master 1185 1035 0
branch 2220 0 0

No row got worse. 11 answers that master simplified are now left as written, for example (2^(x/3))^(3/2) (was 2^(x/2)) and (exp(x^2)^2)^(1/2) (was e^(x^2)). Each of those rewrites is right at the sample points but wrong once the imaginary part is larger: (exp(x^2)^2)^(1/2) at x = 1 + i is the negation of e^(x^2). The sweep's run time was 830 ms on master and 706 ms on the branch, summed over 2220 calls, with no timeouts on either.

Suite, harnesses, allocation

  • Unit suite (net10.0): 22572 passed, 13 skipped, 0 failed. The first run failed only AreaTraitTest, because the new test class lacked its Area trait. The trait was added, and the two tests were re-run green.
  • Harnesses on the branch:
    • CasBench: 120/121 solved, 0 wrong (the one unsolved row, ln(x) + ln(y) - ln(x*y), is unsolved on master too).
    • PropCheck: 0 failures.
    • SimpSweep: 10463/10463 agree.
    • BoundCheck: 0 disagreements.
    • RuleCheck: 0 value changes, 0 never settle.
    • CanonCheck and Confluence: both match their baselines.
  • Library builds for netstandard2.0, net8.0 and net10.0 with 0 warnings.
  • Allocation of the gate inputs, master against branch, interleaved, bytes per call (GC.GetAllocatedBytesForCurrentThread):
    • SimplifyEasy, Derivate, SolveEasy and SolveHard are identical (28882, 24682, 427482, 6240032).
    • SimplifyHard is 135.15 MB against 135.13 MB, then 135.11 MB against 135.16 MB, which is inside its own run-to-run noise.

Not in this PR

The integrator does the same combining on its own (GatherPowersOfOneBase, its Decompose, and arms in IndefiniteIntegralSolver). For example, integrate(x^(1/3) * x^(1/2), x) is x^(11/6)/(11/6), whose derivative is not the integrand at a negative x. That is a separate mechanism with its own sweep, so it is left for its own issue.

🤖 Generated with Claude Code

A negative real base takes the real root under an exact exponent of odd
denominator below 10 ((-8)^(1/3) is -2) and the principal power under any
other. The power rules assumed every power was principal: e^(k ln u) became
u^k, u^a * u^b became u^(a+b), (u^a)^n became u^(a n), and long division in
fractional powers added their exponents. Each changes the value at a
negative u where a real root meets a principal power: exp(1/3 ln(x)) became
x^(1/3), -2 at x = -8 where the input is 1 + 1.732i (#2735). And (b^u)^a
became b^(a u) for any positive b, which also needs Im(u ln b) inside
(-pi, pi]: exp(i x)^(5/3) at x = 4.2 is -0.946 + 0.324i, not
e^(5/3 i x) = 0.754 + 0.657i (#2736).

Three predicates in Patterns.Power state the conditions, and both spellings
of each rule (the switch and MatchedRules), Expand's like-term collection
and the long division ask them: PowersOfOneBaseCombine (no real root beside
a principal power among the exponents, or a positive base),
ThePowerIsPrincipal (for e^(k ln u) = u^k), and APowerOfAPowerMultiplies
(a whole outer exponent with consistent readings, or a positive base and an
inner exponent that is real, as log_b(a^c) already requires, or numeric
inside the strip). IsWholeOrAnOddRoot now means denominators below 10 only,
as the power does: (1/x)^(1/11) * x is not x^(10/11) at x = -1.

Sweep of 1110 generated (b^u)^a, exp(a ln u), u^a u^b, (u^a)^b and
fractional-power quotients, simplify and expand, at 11 points (negative,
positive, imaginary and complex), values against mpmath with the real-root
convention: master 1035 of 2220 wrong, branch 0; none worse; 11 answers no
longer simplified, each a rewrite that is wrong for a larger imaginary part
than the sample points reach.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

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

Labels

None yet

Projects

Status: Todo

1 participant