Repository navigation
Take the real odd root of a negative number with downcasting off (#2622) - #2629
Merged
Merged
Conversation
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 Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
MathS.Settings.DowncastingEnabledoff, the parser keeps1/3as a quotient of the decimals 1 and 3, which evaluates to0.333….Number.Powtakes the real root only for aRationalpower, 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 rulePreciseEvaluationalready applies throughTheRealRootIsTaken. The hunk is one helper and one guard line inPowf.InnerSimplify. It does not touchReal(ERational)..Evaled, downcasting off(-8)^(1/3)1.000… + 1.732…i-2.000…-2(-8)^(2/3)-2.000… + 3.464…i4.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…i5.522…iChecks:
AnOddRootIsRealWhateverTheDowncastingTest: 11 cases, each run with downcasting on and off, through bothEvaledandEvalNumerical. 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.BREAKING-CHANGES.mdentry.Heads-up: this edits
Evaluation.Continuous.Arithmetics.Classes.cs, as #2620 does. The hunk is small, at thePowfInnerSimplifymember.Closes #2622.
🤖 Generated with Claude Code