Repository navigation
Keep evaluation's digits from 1e-100000 to 1e100000 - #2674
Open
Rafael-SOWNet wants to merge 1 commit into
Open
Rafael-SOWNet wants to merge 1 commit into
Rafael-SOWNet wants to merge 1 commit into
Conversation
The default DecimalPrecisionContext had a hundred digits but exponents from -100 to 1000 only. An exact part below 10^-100 became 0 as a decimal and one past 10^1000 became +oo, so every digit built on it was wrong: sqrt(1/10^200 + 1/10^210) * 10^100 was 0, exp(3000) * exp(-3000) was NaN, and the exact roots Solve writes for an equation in 10^20 x evaluated to points with a residual of 1.36. The range is now -100000 to 100000, both ways, so that a number and its reciprocal are both held. With the range open, three precision limits that the flush had hidden showed, and are fixed with it: - the sine, cosine and arctangent ran in fixed point, whose guard digits are absolute, so below 10^-8 (10^-5 for the arctangent) they lost digits and at 10^-200 gave 0; they are now summed as series in floating point there; - the reduction of a sine's argument by 2 pi used pi to the working digits, so from 10^8 up it lost a digit per digit of the argument, and sin(10^500) had none right; it is now reduced with pi to as many more digits as the argument has, and an exact rational argument is written out to that many digits; - the Hermite reduction over two binomials of degree three or four was declined only because its check overflowed. Over the range, its answer to x^7 (a + b x^3)^(1/3)/(c + d x^3) is 23,030 characters, where the cube root's rules give 2,861. It is now declined for that pair, as the split by residues already declines it. Tests changed because their answers got better: the flushed gamma parts are asked for in a context ending at 1e-100, as the default did, with the default's values pinned beside them; catalannumber(2000.5), (1e600 + 1e600 i)^2 and three comparisons were +oo or stayed written, and are now their values, mpmath's. The rows still past the range moved past the new ends. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2674 +/- ##
==========================================
- Coverage 86.73% 86.66% -0.07%
==========================================
Files 346 346
Lines 75913 75966 +53
Branches 22231 22245 +14
==========================================
- Hits 65841 65836 -5
- Misses 5426 5477 +51
- Partials 4646 4653 +7
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
Fixes #2668.
What was wrong
DecimalPrecisionContextdefaulted toEContext(100, HalfUp, -100, 1000, false): a hundred digits, but exponents only from -100 to 1000. An exact part below10^-100became0as a decimal, and one past10^1000became+oo. Every digit built on such a part was wrong:sqrt(1/10^200 + 1/10^210) * 10^100was0, andexp(3000) * exp(-3000)wasNaN. On master the exact rootSolvewrites for((-2i) + 3y) + (-2 + 3y) abs(-3y) = 0withy = 10^20 xevaluated to(0.2627 + 0.4040i)/10^20, with residual 1.36. It now evaluates to(0.3931 + 0.2736i)/10^20, which is mpmath's root, with residual 0.The options, measured
sqrt(1/10^200+1/10^210)*10^100exp(3000)*exp(-3000)2^(-5000)*sqrt(2)*2^50000NaN0+oo+oo11.414…1.0e-200 * sqrt(2)and1/10^200 * sqrt(2)would also disagree. And it needs a per-evaluation decision of what counts as exact, inside[ThreadStatic]settings.NaNand0into+oo, because a saturated large part now meets a tiny part that is no longer 0. That is why the range is symmetric: a number and its reciprocal are both held.What came with it
With the range open, three limits that the flush had hidden showed. They are fixed here, because each would otherwise turn an old
0orNaNinto wrong digits:sin(1/10^200) * 10^200stayed0. Below10^-8(10^-5for the arctangent, whose guard is five digits) they are now summed as series in floating point. The loops compare as numbers: a zero argument's terms are zeros of ever smaller exponent, and a representation comparison ran 100,000 iterations on them. That hungintegral(ln(x) erf(x), x, 0, 1)in the first run of the suite. Its time now equals master's: 15.6 s against 15.9 s.2 pi. Pi was taken to the working digits, so from10^8up one digit was lost per digit of the argument.sin(10^500)was-0.2785, where it is0.3110. This was wrong on master too, and over the new range it would replacecos(10^5000) = NaNwith wrong digits. The argument is now reduced with pi taken to as many more digits as the argument has. Pi is cached per thread in 256-digit buckets, keyed by digit count, not byEContext, so the constant cache is not touched. An exact rational argument past10^8is written out to the same width first.sin(2^1000)was0.2915(master) and is-0.1592, mpmath's value.1e1000. Without the overflow,x^7 (a + b x^3)^(1/3)/(c + d x^3)integrates to a right antiderivative of 23,030 characters withc^50in it. The cube-root rules give 2,861. That pair is now declined explicitly, as the split by residues already declines it.Changed answers
Recorded in
BREAKING-CHANGES.md, measured on v2.10.0 and on this branch. Two rows of the #2664 entry changed:exp(-1000.5) > exp(-3002.5)andexp(-2000) = exp(-2000.5)are now decided (True,False) where they stayed written.Tests changed because the answer got better:
AFlushedPartOfTheGammaFunctionIsZeroTest: these parts no longer flush. The flush is now asked for in a context ending at1e-100, as the default did, and the default's values (mpmath) are pinned beside it.catalannumber(2000.5)is1.6614…E+1199(mpmath), not+oo.(1e600 + 1e600 i)^2is2e1200 i. The overflow rows moved to1e60000.Measurements
C# suite: 21,981 passed, 0 failed, 13 skipped. The F# suite, the harnesses against master, and the performance comparison are in progress, and their numbers will be added here.
🤖 Generated with Claude Code