Skip to content

A compiled power of real numbers is the real power, at an infinity and at zero - #2231

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
a-real-power-is-real
Oct 30, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
a-real-power-is-real

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Fixes #2225.

In FastExpression and in the LINQ compiler over Complex, a power was Complex.Pow, which takes e^(b ln a). At an infinite base that brings in ∞ · 0, so x^2, x^3, sqrt(x) and exp(-x) at an infinity were (NaN, NaN), where evaluation gives +oo, -oo or 0. It also gave 0 for 0^(-1) and 1 for 0^0, where evaluation has no value for either.

RealProducts.Power is now the power in both compilers, through FastExpression's CALL_POW and MathAllMethods.Pow over Complex:

  • A real power where there is one, a positive base or a negative one to a whole power, comes from Math.Pow, or from Math.Sqrt for an exponent of 1/2.
  • A zero base: 0 to a positive power is 0, and 0 to any other power has no value.
  • NaN on either side gives NaN.
  • Anything else is Complex.Pow, as before. That includes a negative base to a power that is not whole. Its principal value differs from evaluation's real root for an odd denominator, which a double exponent cannot show.
2.6.0 and master now
"x^2".ToEntity().Compile("x").Call(double.PositiveInfinity) (NaN, NaN) (Infinity, 0)
"x^(-1)".ToEntity().Compile("x").Call(0) (0, 0) (NaN, 0)
"x^0".ToEntity().Compile("x").Call(0) (1, 0) (NaN, 0)

At finite positive points nothing moves. Complex.Pow already equals Math.Pow at all 100,000 random points of (0, 100) × (-5, 5) measured, so the accuracy question raised on #2225 does not arise.

Tests: RealPowerCompilationTest compares both compilers with evaluation over 10 real bases by 11 exponents, among them 0, the infinities and fractions. It also covers six expressions at an infinity and three complex powers that stay principal. 7 of its 10 cases fail on master. Full suite 18070/0, interactive trio, AOT smoke 73/0, all frameworks build.

🤖 Generated with Claude Code

…d at zero

In FastExpression and in the LINQ compiler over Complex, a power was
Complex.Pow, which takes e^(b ln a). At an infinite base that brings in
inf * 0, so x^2, x^3, sqrt(x) and exp(-x) at an infinity were (NaN, NaN),
where evaluation gives +oo, -oo or 0. And it gave 0 for 0^(-1) and 1 for
0^0, where evaluation has no value for either.

RealProducts.Power is now the power in both compilers, through
FastExpression's CALL_POW and MathAllMethods.Pow over Complex:
- a real power where there is one, a positive base or a negative one to
  a whole power, by Math.Pow, and by Math.Sqrt for an exponent of 1/2;
- 0 to a positive power is 0, and 0 to any other power has no value;
- NaN where either side is NaN;
- Complex.Pow for anything else, as before. That includes a negative base
  to a power that is not whole, whose principal value differs from
  evaluation's real root for an odd denominator. A double exponent cannot
  show that denominator.

At finite positive points nothing moves. Complex.Pow already equals
Math.Pow at all 100000 random points of (0, 100) x (-5, 5) measured.

RealPowerCompilationTest compares both compilers with evaluation over
10 real bases by 11 exponents, among them 0, the infinities and fractions.
It also covers six expressions at an infinity and three complex powers
that stay principal. 7 of its 10 cases fail on master.

Fixes #2225.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@Rafael-SOWNet Rafael-SOWNet moved this from Todo to In review in AngouriMath Oct 30, 2026
@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.66%. Comparing base (1c9dbce) to head (29addf0).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2231      +/-   ##
==========================================
- Coverage   86.68%   86.66%   -0.02%     
==========================================
  Files         310      310              
  Lines       67679    67691      +12     
  Branches    19627    19634       +7     
==========================================
- Hits        58668    58665       -3     
- Misses       4894     4908      +14     
- Partials     4117     4118       +1     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.21% <100.00%> (-0.03%) ⬇️
fsharp 32.97% <ø> (ø)
interactive 40.72% <ø> (ø)

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

Files with missing lines Coverage Δ
...ath/Functions/Compilation/IntoFE/FastExpression.cs 96.72% <100.00%> (ø)
...h/Functions/Compilation/IntoLinq/MathAllMethods.cs 73.72% <100.00%> (ø)
.../AngouriMath/Functions/Compilation/RealProducts.cs 100.00% <100.00%> (ø)

... and 9 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
Rafael-SOWNet merged commit a4b7b74 into master Oct 30, 2026
36 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in AngouriMath Oct 30, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the a-real-power-is-real branch October 30, 2026 08:10
Rafael-SOWNet added a commit that referenced this pull request Nov 2, 2026
m_1 sqrt(A) + m_2 sqrt(B) + P = 0 with two different square roots was
not raised at all, and went to Newton's method, which cannot reach a root
where a radicand is 0. sqrt(-4 - 4x) + sqrt(2 + x) = -3 - 4x was answered
without its root -1. 2.6.0 found that root only because a compiled
0^(-1/2) was 0, so Newton's step from -1 was 0; since #2231 made it NaN,
the root has been missed, and sqrt(2x + 3) - sqrt(x + 1) = 1 lost its
root -1 with it.

It is now squared twice, 4 P^2 m_2^2 B = (m_1^2 A - P^2 - m_2^2 B)^2,
which keeps every root, and each root of that polynomial is put back into
the equation as for one radical. Only for an equation in x alone: with a
parameter left in, a root put back cannot be decided, and
sqrt(x + 1) + sqrt(x + 2) + a + x = 0 kept all four roots of its square.

radcheck, random radical equations, unsolved on master and here:
seed 61, 26 and 5 of 400; seed 51, 31 and 7; seed 22, 24 and 3; seed 62
(pow), 0 and 0 of 600. No root is unsound and none missed but one that
is not a root.

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.

A compiled power at a real infinity has no value: x^2 at +oo is (NaN, NaN)

1 participant