Skip to content

Take the real odd root of a negative number with downcasting off (#2622) - #2629

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
odd-root-downcasting-2622
Nov 28, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
odd-root-downcasting-2622

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

With MathS.Settings.DowncastingEnabled off, the parser keeps 1/3 as a quotient of the decimals 1 and 3, which evaluates to 0.333…. Number.Pow takes the real root only for a Rational power, so an odd root of a negative number came back as the principal root.

Now, when a power's exponent is written as an exact fraction with an odd denominator below 10 (a Rational, or a quotient of two whole numbers) and that exponent evaluates to a decimal, a negative base takes the real root. This is the rule PreciseEvaluation already applies through TheRealRootIsTaken. The hunk is one helper and one guard line in Powf.InnerSimplify. It does not touch Real(ERational).

.Evaled, downcasting off master / 2.10.0 this PR downcasting on
(-8)^(1/3) 1.000… + 1.732…i -2.000… -2
(-8)^(2/3) -2.000… + 3.464…i 4.000… 4
(-32)^(1/5) 1.618… + 1.175…i -2.000… -2
(-30.5)^(1/3) 1.562… + 2.705…i -3.124… -3.124…
(-30.5)^(1/2) 5.522…i unchanged 5.522…i

Checks:

  • AnOddRootIsRealWhateverTheDowncastingTest: 11 cases, each run with downcasting on and off, through both Evaled and EvalNumerical. The cases cover negative bases with odd denominators and negative exponents; halves, a positive base and an even denominator are controls. 7 fail on master.
  • The 96-row exactcheck gives output identical to master's.
  • Full UnitTests suite (net10.0): 21750 passed, 0 failed, 13 skipped.
  • The library builds with 0 errors for every target framework.
  • There is a BREAKING-CHANGES.md entry.

Heads-up: this edits Evaluation.Continuous.Arithmetics.Classes.cs, as #2620 does. The hunk is small, at the Powf InnerSimplify member.

Closes #2622.

🤖 Generated with Claude Code

An odd root of a negative number is the real one: (-8)^(1/3) is -2. With
downcasting off, the parser keeps 1/3 as a quotient of the decimals 1 and
3, which evaluates to 0.333.... Number.Pow takes the real root only for a
Rational power, so the principal root came back: 1 + 1.732i, and
(-8)^(2/3) was -2 + 3.464i where it is 4. A value depended on a setting
where the mathematics does not, and code that turns downcasting off
followed the principal branch without saying so: the Newton refinement of
#2618 went to another root that way.

Evaluating a power now reads the exponent as written. Where it is an
exact fraction with an odd denominator below 10, as a Rational or as a
quotient of two whole numbers, and it evaluates to a decimal, a negative
base takes the real root: the root of the modulus, signed by the
numerator's parity. This is the rule PreciseEvaluation already applies,
through TheRealRootIsTaken. With downcasting on the exponent evaluates to
a Rational and nothing changes. Halves and even denominators are
unchanged. The 96-row exactcheck gives the same output as on master.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@codecov

codecov Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.72%. Comparing base (00813f6) to head (0706c2b).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2629   +/-   ##
=======================================
  Coverage   86.72%   86.72%           
=======================================
  Files         345      345           
  Lines       75318    75378   +60     
  Branches    22014    22030   +16     
=======================================
+ Hits        65318    65372   +54     
- Misses       5396     5399    +3     
- Partials     4604     4607    +3     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.22% <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 Δ
...nuous/Evaluation.Continuous.Arithmetics.Classes.cs 89.07% <100.00%> (+0.12%) ⬆️

... and 7 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 d0489be into master Nov 28, 2026
35 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in AngouriMath Nov 28, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the odd-root-downcasting-2622 branch November 28, 2026 21:00
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.

An odd root of a negative number is the principal root with downcasting off: (-8)^(1/3) is 1 + 1.732i, and -2 with it on

1 participant