Skip to content

Compiled arithmetic of a complex number is evaluation's at a whole power and at an infinity - #2249

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
complex-arithmetic-at-an-infinity
Oct 30, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
complex-arithmetic-at-an-infinity

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Compiled arithmetic of numbers that are not real now gives evaluation's value at a whole power and at an infinity, in FastExpression and in Compile<Complex, Complex> alike.

  • A whole power of a number that is not real is a product of its factors, by squaring, as evaluation's BinaryIntPow takes it. Complex.Pow's e^(n ln z) left a rounded part, so i^2 was not real, and iverson((x i)^2 < 0) at 3 was NaN.
  • A product takes a zero part times an infinite part as 0, and a whole zero times an infinity as NaN, as Number.OpMul does (limit answers 1 for z/abs(z) whatever the phase of z #1186). Complex took 0 · ∞ as NaN in every part.
  • A quotient by a real number other than 0 is taken part by part.
  • sgn of a real infinity is its sign, where z / |z| was ∞ / ∞.
2.6.0 master this branch, and evaluation
x^2 at i (-1, 1.2246467991473532E-16) same (-1, 0)
x^3 at 1 + i (-2.0000000000000004, 2.0000000000000004) same (-2, 2)
iverson((x * i)^2 < 0) at 3 refused (NaN, 0) (1, 0)
i * x at +oo (NaN, Infinity) same (0, Infinity)
(x + i) * 2 at -oo (-Infinity, NaN) same (-Infinity, 2)
ln(x) / 2 at -oo (NaN, NaN) same (Infinity, 1.5707963267948966)
ln(ln(x)) at 0 (NaN, NaN) (Infinity, NaN) (Infinity, 3.141592653589793)
sgn(x) at +oo (NaN, NaN) same (1, 0)

ComplexArithmeticCompilationTest checks 22 values under both compilers against evaluation. 19 of them fail on master. The other 3 pin what did not change: x * (2 + 3i) at -oo, and a zero times an infinity, which has no value. Found by work/compilesweep.

CompilationIntoLinqTest.TestUpcastDowncast5 pinned Complex.Pow's (7.000000000000001, 24) for (4 + 3i)^2, which is 7 + 24i exactly, and now expects that. Suite 18189 passed. The F# wrapper suite, the Mcp, Terminal and InteractiveWrapper suites and the AOT smoke test pass.

Fixes #2247.

🤖 Generated with Claude Code

…wer and at an infinity

A compiled whole power of a number that is not real went through
Complex.Pow, which takes e^(n ln z) and leaves a rounded part: i^2 was
(-1, 1.2e-16), which is not real, so iverson((x i)^2 < 0) at 3 was NaN
where it is 1. RealProducts.Power now takes such a power as a product
of its factors, by squaring, as evaluation's BinaryIntPow does. Past
2^62 it is left to Complex.Pow.

System.Numerics.Complex's product takes 0 * oo as NaN in every part, so
i * x at +oo was (NaN, oo) and (x + i) * 2 at -oo was (-oo, NaN).
Number.OpMul takes a zero part times an infinite part as 0, and a whole
zero times an infinity as NaN (#1186), and RealProducts.Product now
does the same. A quotient by a real number other than 0 is taken part
by part, where Complex multiplied each part by the divisor's imaginary
0: ln(x) / 2 at -oo was (NaN, NaN), and ln(ln(x)) at 0 was (oo, NaN),
through ComplexBranches.Log's quotient by ln(e).

The compiled sgn was z / |z|, which is oo / oo at an infinity. A real
number's is now its sign, as evaluation's is.

ComplexArithmeticCompilationTest compares 22 values under both
compilers with evaluation, and 19 fail on master. The other three pin
what has not changed: x * (2 + 3i) at -oo, and a zero times an
infinity, which has no value.

CompilationIntoLinqTest.TestUpcastDowncast5 compared (4 + 3i)^2 with
Complex.Pow's (7.000000000000001, 24). It is 16 - 9 + 24i exactly, as
evaluation has it, and the compiled power is that now.

Found by work/compilesweep.

Fixes #2247.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@Rafael-SOWNet Rafael-SOWNet added this to the 2.7.0 milestone Oct 30, 2026
@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

❌ Patch coverage is 89.28571% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.71%. Comparing base (bd750c4) to head (a283e74).

Files with missing lines Patch % Lines
.../AngouriMath/Functions/Compilation/RealProducts.cs 88.00% 1 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2249      +/-   ##
==========================================
- Coverage   86.71%   86.71%   -0.01%     
==========================================
  Files         310      310              
  Lines       67785    67809      +24     
  Branches    19664    19674      +10     
==========================================
+ Hits        58781    58799      +18     
- Misses       4892     4896       +4     
- Partials     4112     4114       +2     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.26% <89.28%> (-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 Δ
...rces/AngouriMath/Functions/InternalAMExtensions.cs 86.06% <100.00%> (+0.05%) ⬆️
.../AngouriMath/Functions/Compilation/RealProducts.cs 91.66% <88.00%> (-8.34%) ⬇️

... 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 3d21a61 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 complex-arithmetic-at-an-infinity branch October 30, 2026 16:41
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 whole power of a complex number, and complex arithmetic at an infinity, are not evaluation's

1 participant