Skip to content

A compiled odd root of a negative real is real - #2318

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
a-compiled-odd-root-of-a-negative-real-is-real
Nov 1, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
a-compiled-odd-root-of-a-negative-real-is-real

Conversation

@Rafael-SOWNet

@Rafael-SOWNet Rafael-SOWNet commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Evaluation takes a negative real to a rational power with an odd denominator below ten as the real root to the numerator: Number.Pow's search for a good root finds it, so (-8)^(1/3) is -2 and (-8)^(2/3) is 4. Both compilers took the principal power instead, and Compile<double, double> took Math.Pow, which is NaN there. Whether the exponent is such a rational is known only where the power is written, so each compiler now makes that choice as it compiles a power: RealProducts.RealRootPower takes the real root to the numerator for a negative real base, and the power as before for any other.

at x = -8 evaluated compiled, 2.6.0 and master now
x^(1/3) -2 <1; 1.73>; NaN over double -2
x^(2/3) 4 <-2; 3.46> 4
x^(-1/3) -1/2 <0.25; -0.43> -1/2
  • Newton's method, which Solve falls back to, runs on the compiled function, so roots that need the real root weren't found. Each of these is now:
    • (3 - 4x)^(1/3) + sqrt(4 + 4x) = 3 was missing 8.379;
    • (1 + x)^(1/3) + sqrt(-1 - 2x) = 4 + 2x was missing -1.672;
    • (-4x)^(1/3) + sqrt(2 + 2x) = 3 was missing 30.81.
  • Unchanged, as in evaluation: a base off the real line, a positive base, an even denominator (sqrt(-4) is still 2i), and a denominator of ten or more ((-1)^(1/11) is principal).
  • Found by a cross-check of equations in roots. I first put the 8.379 miss down to Newton's search grid. Compiling the equation showed the real cause.
  • Seven of the new cases fail on master, and the four principal-power controls pass on both. The suite, the trio, F#, AOT and the eight harnesses pass. BREAKING-CHANGES.md has an entry.

No issue was filed.

🤖 Generated with Claude Code

Evaluation takes a negative real to a rational power whose denominator is odd and below ten
as the real root to the numerator, Number.Pow's search for a good root finding it:
(-8)^(1/3) is -2 and (-8)^(2/3) is 4. Both compilers took the principal power, 1 + 1.73i
and -2 + 3.46i, and Compile<double, double> took Math.Pow, which is NaN there. Whether the
exponent is such a rational is known only where the power is written, so each compiler now
chooses, as it compiles a power to one, RealProducts.RealRootPower: the real root to the
numerator for a negative real base, the power as before for any other.

Newton's method, which Solve falls back to, runs on the compiled function, so the roots that
need the real root were not found: (3 - 4x)^(1/3) + sqrt(4 + 4x) = 3 was answered without
8.379, (1 + x)^(1/3) + sqrt(-1 - 2x) = 4 + 2x without -1.672, and
(-4x)^(1/3) + sqrt(2 + 2x) = 3 without 30.81. Each is found now.

Found by a cross-check of equations in square and cube roots against a Newton search.

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

codecov Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.15385% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 86.78%. Comparing base (b20a516) to head (44cb586).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
.../AngouriMath/Functions/Compilation/RealProducts.cs 87.50% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2318   +/-   ##
=======================================
  Coverage   86.77%   86.78%           
=======================================
  Files         311      311           
  Lines       68216    68241   +25     
  Branches    19827    19833    +6     
=======================================
+ Hits        59197    59220   +23     
  Misses       4878     4878           
- Partials     4141     4143    +2     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.32% <96.15%> (+<0.01%) ⬆️
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 Δ
...gouriMath/Functions/Compilation/IntoFE/Compiler.cs 85.71% <100.00%> (+0.37%) ⬆️
...ath/Functions/Compilation/IntoFE/FastExpression.cs 96.80% <100.00%> (+0.03%) ⬆️
...ctions/Compilation/IntoLinq/CompilationProtocol.cs 93.70% <100.00%> (+0.18%) ⬆️
.../AngouriMath/Functions/Compilation/RealProducts.cs 90.90% <87.50%> (-0.76%) ⬇️

... 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
Rafael-SOWNet merged commit a290f93 into master Nov 1, 2026
36 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in AngouriMath Nov 1, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the a-compiled-odd-root-of-a-negative-real-is-real branch November 1, 2026 19:02
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.

1 participant