Skip to content

Do not read a power that is not real on the side approached as a real one - #2696

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
fix-2693-left-side-power-limits
Dec 4, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
fix-2693-left-side-power-limits

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Fixes #2693

Cause

x^(x - 1) at 0 from the left: the one-sided descent stops at 0^(-1), and the fallback that moves the point out to +oo hands (-1/x)^(-1/x - 1) to Gruntz's algorithm (traced at the dispatcher). The algorithm's leading term is e^(-(i pi - x) - x) / w, and Gruntz.Sign read every exponential as positive, so it answered +oo. But e^(-i pi) is -1, and the principal value tends to -oo + i pi (-1.0E+20 + 3.1415927i at x = -1e-20, mpmath). An exponential is now positive to the algorithm only where its exponent is real. Otherwise the sign is undecided, and the limit is left unevaluated, as sin(x)^(x - 1) there already was (AnExponentThatOnlyTendsToAWholeNumberIsLeftAloneUnderANegativeBase).

Introduced in #1627 (371b38e), which first let the algorithm answer here. Its parent leaves these limits unevaluated. NuGet 2.5.0 has them unevaluated and 2.6.0 has +oo.

A second fault was found by the sweep. In a two-sided limit, ExpressionNumerical.AreEqual skips any point where either value is NaN, so a side that came back NaN "agreed" with the other side. (x^2 - x)^(x - 1) at 0 is +oo from the left and not real from the right, and it was +oo. A NaN side no longer agrees, so the limit is NaN, as (-x)^x at 0 already is (AComplexSideIsNotRead).

Measured

The sweep covers 432 limits at 0: f^g, f^g * x and f^g / x, each from the left, from the right and two-sided, for f in {x, sin x, e^x - 1, tan x, x^2 - x, x/(1 - x)} and g in {x, x - 1, x - 2, x + 1, 2x - 1, x^2 - 1, 1/2 + x, -x}. Each answer is checked against mpmath's principal value at ∓1e-20, ∓1e-40 and ∓1e-80.

right directed infinity two-sided NaN with a non-real side declined wrong
master 34d4811 306 25 38 32 31
this branch 304 12 40 76 0
  • Of the 31 wrong answers, 28 are now unevaluated and 3 are NaN.
  • The x^(x - 2) family (12 rows) is now unevaluated. On master it was +oo or -oo in the right direction, but the imaginary part also grows without bound. sin(x)^(x - 2) at 0 from the left is already pinned as unevaluated.
  • tan(x)^(±x) * x two-sided went from 0 to NaN, the pinned answer for a two-sided limit with a non-real side.
  • Four two-sided rows went from NaN to unevaluated.
  • x^x, sin(x)^x and x^(x - 1) * x at 0 from the left are still 1.

Suites and harnesses:

  • Unit tests: 22206 passed, 0 failed.
  • F# wrapper: 135 passed.
  • CasBench: 120/121, 0 wrong, the same as master.
  • limitcheck: report identical to master's; about 28 s on each side, run twice, alternating.
  • symlimitcheck: report identical to master's; about 25 s on each side, run twice, alternating.
  • The sweep itself took 24.9 s here against 51.0 s on master.

New test file: ANonRealSideIsNotReadAsRealTest. BREAKING-CHANGES entry: A power that is not real on the side approached is not read as a real one.

🤖 Generated with Claude Code

… one

x^(x - 1) and (e^x - 1)^(x - 1) at 0 from the left were +oo, where the
principal value tends to -oo + i pi (-1.0E+20 + 3.1415927i at x = -1e-20, by
mpmath). Traced at the dispatcher: the one-sided descent stops at 0^(-1), and
the substitution to +oo hands (-1/x)^(-1/x - 1) to Gruntz's algorithm, whose
leading term is e^(-(i pi - x) - x) / w. Sign read every exponential as
positive; e^(-i pi) is -1. An exponential is now positive to it only where
its exponent is real, and the limit is left unevaluated, as sin(x)^(x - 1)
there already was. Introduced in #1627 (371b38e), which made the algorithm
answer at all here; its parent left these unevaluated.

Two-sided, the comparison of the sides took a side that came back NaN to agree
with the other, since ExpressionNumerical.AreEqual passes over a point where
either value is NaN: (x^2 - x)^(x - 1) at 0, +oo from the left and not real
from the right, was +oo. A side that is NaN no longer agrees, and it is NaN, as
(-x)^x at 0 is.

A sweep of f^g, f^g x and f^g / x at 0 from each side and two-sided, f in
{x, sin x, e^x - 1, tan x, x^2 - x, x/(1 - x)} and g in eight exponents, 432
rows against mpmath at 1e-20, 1e-40 and 1e-80: 31 wrong on master, 0 here.

Fixes #2693

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Rafael-SOWNet Rafael-SOWNet added this to the 2.11 milestone Dec 3, 2026
@codecov

codecov Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.61%. Comparing base (52a6530) to head (28b1e9c).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2696      +/-   ##
==========================================
- Coverage   86.62%   86.61%   -0.01%     
==========================================
  Files         346      346              
  Lines       76734    76754      +20     
  Branches    22546    22554       +8     
==========================================
+ Hits        66470    66482      +12     
- Misses       5537     5546       +9     
+ Partials     4727     4726       -1     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.10% <100.00%> (-0.01%) ⬇️
fsharp 32.79% <ø> (ø)
interactive 40.09% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...iMath/Functions/Continuous/Limits/Gruntz/Gruntz.cs 76.44% <100.00%> (+0.10%) ⬆️
...ns/Continuous/Limits/Solvers/Solvers.Definition.cs 90.32% <100.00%> (+0.83%) ⬆️

... and 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Rafael-SOWNet

Copy link
Copy Markdown
Member Author

This declines the limits #2693 lists rather than answering them. Answering them with a directed infinity where the phase settles (x^(x - 1) at 0- is -oo) is #2697, which follows this PR.

@Rafael-SOWNet
Rafael-SOWNet merged commit 82eb869 into master Dec 4, 2026
35 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in AngouriMath Dec 4, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the fix-2693-left-side-power-limits branch December 4, 2026 01:05
Rafael-SOWNet added a commit that referenced this pull request Dec 4, 2026
…tion settles in (#2702)

x^(x - 1) at 0 from the left, left unevaluated by #2696, is -1.0E+20 + 3.1i at
x = -1e-20 (mpmath): its modulus grows and its argument settles at pi, so it is
-oo, as ln(x) there already is. Gruntz's algorithm now reads the direction of a
leading coefficient that has no real sign, where it settles on an axis: +oo,
-oo, +ooi or -ooi. Off the axes (x^(x - 1/3), at -pi/3) it declines. A term is
read as growing only when w is real: x^(1/x) at 0 from the left, whose phase
pi/x keeps turning, was +oo and now declines, as do six more wrong +oo rows.

A root of an argument tending to -oo off the real line takes its direction from
the side of the cut, and is declined in the algorithm and in the descent:
sqrt((-x)^(x - 1)) at 0 from the right tends to -ooi. The logarithm of an
infinity in any direction is +oo, where ln(sqrt(x) / x) at 0 from the left was
ln(-ooi). Two sides agreeing on an infinity, where one is not real through a
power to a moving exponent, stay NaN, as (-x)^x at 0 is.

AnExponentThatOnlyTendsToAWholeNumberIsLeftAloneUnderANegativeBase pinned
sin(x)^(x - 2) and sin(x)^(x - 1) at 0 from the left as unevaluated; they are
+oo and -oo. FromTheLeftNothingChanges pinned (sqrt(x) - erf(x)) / x there as
unevaluated; it is -ooi, as sqrt(x) / x is. #2693's left-side rows now expect
their directions.

A sweep of 1024 rows (the #2693 432, exponents tending to non-integers or not
settling, products with ln, sqrt and constant powers, and rows at +-oo) against
mpmath at 1e-10, 1e-20 and 1e-40: 7 wrong on master (and two more at the
infinities), 0 here.

Fixes #2697

The rule is a theorem about real functions; its proof is Cauchy's mean value
theorem, which fails for a complex-valued denominator: x / (x + x^2 e^(i/x^2))
at 0 from the right tends to 1 (1.0 - 7.8E-9i at x = 1e-8, by mpmath), while the
quotient of the derivatives tends to 0. It holds where the denominator's
derivative is c h' with h' real, the quotient then being the real rule's over h,
part by part; ln(x) at 0 from the left, ln(abs(x)) + i pi, qualifies. A
derivative seen to turn beside the destination declines the rule, after the
quotient is tried upside down: x^pi / log(x, 2) at 0 keeps its 0 that way.

A power of a negative base to a moving exponent declines it too, for its cost:
directed sub-limits let the rule differentiate such powers chain after chain,
and x^(x - 1) * x at 0 from the left took 5 s to reach 1, (-x)^(x - 1) sqrt(x)
at 0 from the right 8 s. Both are under 0.3 s now, and the 1038-row sweep runs
in 32 s against master's 50 s with the same answers as before this commit; the
complex-denominator rows are declined, as on master.

Part of #2697


Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

The limits of x^(x - 1) and (e^x - 1)^(x - 1) at 0- are +oo; the principal value tends to -oo + pi i

1 participant