Repository navigation
Order exact numbers exactly, and leave a comparison the decimals cannot decide (#2664) - #2665
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
…ot decide (#2664) The ordering arms of Greaterf, Lessf, GreaterOrEqualf and LessOrEqualf compared two evaluated numbers through their hundred-digit decimals. 10^(-200) < 2 * 10^(-200) was False, because both sides fall below the decimals' least exponent. 10^2360 > 10^1175 was False, because both overflow. -10^400 > -10^400 - 1 and 1000! * 2 < 1001! were False, because each pair rounds to one decimal. Equality answered exp(-2000) = exp(-2000.5) with True, both sides flushed to 0, and sqrt(5)^1000 = 5^500 with False, the decimal differing from the exact integer in its last digits. Two rationals are now ordered exactly. A decimal decides an order only where the two sides differ by more than the downcasting tolerance relative to the larger, and an equality is declined, not answered False, where they differ by less. A side written as a product, quotient or power of nonzero finite constants that evaluates to 0 or to an infinity was flushed or saturated, and decides nothing. In each of these cases the comparison stays written. This is checked in the comparison code itself, before the exact 0 a flushed value is downcast to is read, so it does not depend on how Evaluation.Classes reads such a value. Two decimals that agree are still equal (#1376). This is a temporary reading before v3, which decides exact comparisons exactly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2665 +/- ##
=======================================
Coverage 86.70% 86.70%
=======================================
Files 346 346
Lines 75739 75785 +46
Branches 22152 22176 +24
=======================================
+ Hits 65671 65713 +42
Misses 5431 5431
- Partials 4637 4641 +4
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.
Comparisons of evaluated numbers went through their hundred-digit decimals, so they gave wrong
True/Falseanswers at extreme magnitudes and for close values.Fix, inside the comparison code (
Evaluation.Discrete.Classes.cs):False.In each undecided case the comparison stays written. This is a temporary reading before v3, linked to #1019 §10.
.Evaled10^(-200) < 2 * 10^(-200)FalseTrue10^(-300) > 0FalseTrue10^(2360) > 10^(1175)FalseTrue-10^(400) > -10^(400) - 1FalseTrue1000! * 2 < 1001!FalseTrue10^(590) >= 10^(590) + 10^(440)TrueFalseexp(-1000.5) > exp(-3002.5)Falseexp(6000) >= exp(6100)Trueexp(-2000) = exp(-2000.5)Truesqrt(5)^1000 = 5^500Falsesqrt(2) < sqrt(2) + 10^(-150)FalseSweep. Two runs of 260 comparisons (
<,>,<=,>=,=) between exact values from1e-3000to1e3000, including pairs that differ by a tiny relative amount. Truth comes from exact rational arithmetic, or from mpmath at 400 digits forexpandsqrt.The one remaining wrong answer in each run is
sqrt(2) = sqrt(2) + 10^(-99)→True. That is a residual that cannot be told apart from a difference, and it is #1376's agreed v3 question, so this PR does not touch it.Relation to #2650. This does not depend on #2650 (
exact-verify-2650). The flush check is structural and runs in the comparison code before the exact 0 a flushed value is downcast to is read. It does not touchExpandOnTwoArguments,CannotBeZeroorSignOfANonzero.Checks.
Closes #2664.
🤖 Generated with Claude Code