Repository navigation
Hold a constant near a rational to an enclosure before taking it for one - #2776
Open
Rafael-SOWNet wants to merge 3 commits into
Open
Rafael-SOWNet wants to merge 3 commits into
Rafael-SOWNet wants to merge 3 commits into
Conversation
A constant past the decimals' exponent range evaluates to +oo or flushes to 0, and the exact shortcuts took that value as the node's: e^400000 / e^399999 was NaN (+oo / +oo), exp(400000) * exp(-399999) was 0, 1 / e^400000 was 0. The two-argument shortcut asked whether a zero or an infinity was rounding's, but a quotient by such a part, a NaN, and every one-argument function asked nothing, so abs(e^(-400000)) and sin(e^(-400000)) were 0, sin(e^400000) NaN and e^(-400000) = 0 True. A part now counts as finite when it is written with exact numbers and constants using sums, products, quotients by parts that cannot be 0, powers, the factorial off its poles, sine, cosine and erf. Every exact shortcut, of one, two and three arguments, refuses a value resting on such a part flushed or saturated. The trigonometric table lookups and equality of constants ask the same. The half-integer factorial closed form is capped at 2n = 50000, since past the range it was never built and building it took over 20 s. A quotient of factorials of rationals a whole number apart is the product of the terms that do not cancel, so gamma(300000.5) / gamma(299999.5) is 599999/2. sgn reads the sign of a constant from its parts. Measured on 624 generated inputs against mpmath: master 281 right, 273 wrong, 70 declined; this branch 432 right, 29 wrong, 163 declined. The 29 are equally wrong on master (tiny angles read as 0 by the trig tables, and trig of a large finite argument), a separate class. 16 rows went from answered to written: 12 cos/sec/arccos of a flushed argument whose answer 1 or pi/2 was not exact, and floor(e^(-a)) = 0, which was right by luck. Fixes #2753 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… bound The first commit left floor(e^(-400000)) written, where 0 had been right only because the value flushed to 0. Its parts prove it in (0, 1): a base above 1 to a negative exponent, or a bounded constant over a power large enough, by a rational below the base raised to the exponent's whole part. floor, ceil and round take the sign and the bound, never the decimal, so floor(-e^(-400000)) is -1 and ceil(e^(-400000)) 1, where both were 0. x mod 1 of such an x is x, or x + 1 below 0, and a zero rounding made of it is refused: e^(-1000) mod 1 was 0. Sweep of 624 inputs: 436 right, 29 wrong, 159 declined against master's 281/273/70; no row got worse once master's twelve cos/sec/arccos answers of 1 and pi/2, which are not the exact values, count as wrong. 210 more floor, ceil, round, mod 1 and sgn rows: master 164 right and 46 wrong, now 210 right. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Evaluation rounds a value within 1e-50 of a small rational onto it, so that a cancellation such as cosh(1)^2 - sinh(1)^2 comes out as 1. The exact shortcuts took that rational for the value of any constant only near one: 1 - e^(-200), sinh(60)/cosh(60) and sqrt(10^120 + 1)/10^60 were 1. The trig tables read an angle within the working digits of a table angle as it, so sin(1/10^99) and arctan(1/10^150) were 0. tan, cot, sec and csc of e^1000, whose period the hundred digits cannot place, were NaN. Comparisons, floor, ceil, round and mod read the same rounded values. A value the evaluation rounded onto a rational is now taken only where an interval enclosure of the node, in twice the working digits plus twice the largest decimal exponent of a part, holds it. Rational terms of a sum are moved across first, so 1 + e^(-1000) is decided by the enclosure of e^(-1000). A table hit off a rational multiple of pi is checked the same way. A rational argument of an inverse table must equal its entry exactly. A NaN from a trigonometric part whose argument's sine is NaN is not taken. Equalities and orders of such sides, and floor, ceil, round and mod at their boundary, are decided from the enclosures or left written. Sweep of 547 inputs (near-rationals at 1e-10..1e-120 both sides, true rationals written irrationally, tiny and huge trig arguments, comparisons, floor/ceil/round/mod), judged against mpmath at 700 digits: master 254 wrong, branch 0. No row got worse. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 #2775.
Built on #2774. This branch contains #2774's two commits (
50ab0c9a6,0479f80bf) and one more,8b3c18c4f. Review that last commit only. Merge #2774 first; this PR's diff then shrinks to its own commit. Both PRs edit the same guard (IsAValueOnlyRoundingMadeand the shortcuts that call it). This PR adds its checks inside that predicate, so the two do not conflict.Cause
Evaluation rounds a value within
DowncastingTolerance(1e-50 at 100 digits) of a small rational onto it. The exact shortcuts took that rational as the node's value, so1 - e^(-200),sinh(60)/cosh(60)andsqrt(10^120 + 1)/10^60became 1. The same class shows up in four more places:AgreesToTheWorkingDigits), sosin(1/10^99),sin(pi + 1/10^150)andarctan(1/10^150)became 0.tan,cot,secandcscofe^1000wereNaN: the argument's sine isNaNbecause 100 digits cannot placee^1000within its period. AProvidedfwhose condition wasNaNfor the same reason becameNaN.1 - e^(-200) = 1wasTrueandcos(1/10^30) < 1wasFalse.floor(1 - e^(-200))was 1 and(-e^(-1000)) mod 1was 1.Change
IsARationalOnlyRoundingMade: an exact value of a node that is not rational arithmetic is taken only where an interval enclosure (PreciseEvaluation) holds it. The enclosure is worked out in twice the working digits plus twice the largest decimal exponent of a part, rounded up to a hundred and capped at 2000. Rational terms of a sum are moved to the other side first, so1 + e^(-1000)is decided by the enclosure ofe^(-1000). An enclosure that holds the value decides nothing, and the value is taken as before. That is howcosh(1)^2 - sinh(1)^2,sqrt(2)^2,sin(pi)and Cardano residuals keep their integers.TableValueHolds,InverseTableValueHolds). The check is skipped for an argument written as a rational multiple of pi. A rational argument of an inverse table must equal its rational entry exactly.IsANaNOnlyLostDigitsMade: aNaNthat comes from a trig part whose argument's sine isNaNis not taken, and aProvidedfdoes not read such aNaNas false.IntegerPartByEnclosure). Otherwise they are left written.ModulusSolver: two accepted roots that evaluate alike but are not shown to be one number now decline. AFiniteSetkeyed both by their evaluations would otherwise hold only one of them. Without this,x^4 - 10 x^2 - |x| + 10^-70lost its root near +1e-71 once the roots stayed written.Before / after (measured on master
a3f3b9ed1and on this branch).Simplify()1 - e^(-200)11 - 1 / e ^ 200sinh(60)/cosh(60)1(e ^ 60 + (-1) / e ^ 60) / (e ^ 60 + 1 / e ^ 60)sqrt(10^120 + 1) / 10^601sin(1/10^99)0arctan(1/10^150)0sin(pi + 1/10^150)0sin(1/10…0 + pi)tan(e^1000)NaNtan(e ^ 1000)csc(e^1000)^2 - cot(e^1000)^2NaN11 - e^(-200) = 1TrueFalsecos(1/10^30) < 1FalseTruefloor(1 - e^(-200))10(-e^(-1000)) mod 111 + (-1) / e ^ 1000(7/2 - e^(-200)) mod 11/21/2 + (-1) / e ^ 200cosh(200)^2 - sinh(200)^201Sweep
I generated 547 inputs and judged each against mpmath at 700 digits:
e^300ande^1000sqrt(10^120)/10^60,cosh(k)^2 - sinh(k)^2,e^(ln n), table values)No row got worse. *The one row is a judge artifact:
floor(cosh(3)^2 - sinh(3)^2)is 1, as the branch answers, but mpmath's own cancellation gives 0.999….Suite and harnesses
Issue2659_AnUndecidedRootOfAPieceDeclines(10^-70), which led to theModulusSolverchange above. After that change,SolverRegressionTest, the new tests, Keep a value past the exponent range out of Simplify's exact shortcuts #2774's tests and the modulus and abs tests pass: 734 passed.ln(x) + ln(y) - ln(x y), is symbolic and unrelated to this change.Timing
24 ordinary inputs (radicals, trig table values, solves, integrals, limits), summed per process, three runs each:
arcsin(sqrt(2)/2) + arctan(sqrt(3))).Left open
Separately from this change,
x^4 - 10 x^2 - abs(x) + 10^(-70) = 0solved over the reals drops both roots near ±1e-71, on master and here. I have an issue draft for it; it is not filed.🤖 Generated with Claude Code