Repository navigation
Verify an exact root far below 1 exactly, not through flushed decimals - #2669
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
Evaluation's decimals stop at about 10^-100 and flush anything smaller to 0. Four places read that flushed value as exact, so an equation of x with roots near 10^-30 stayed unsolved where the same equation in 10^30 x was solved: - ExpandOnTwoArguments took an exact Evaled for the node's value. A product, quotient or power of exact rationals that flushed counted, so sqrt(5/10^200 - 4/10^200) became 0, and the quartic formula's -Q/2 + sqrt(Q^2/4 + P^3/27) became -Q/2. CannotBeZero and SignOfANonzero read rationals through the 1e-16 IsZero. A rational now counts as zero only when it is 0, a sum or product of rationals whose parts do not decide its sign takes it from its exact value, and the shortcut, through an allocation-free walk, declines when a part made only of exact numbers cannot be 0 but evaluated to 0. A part with a decimal in it, such as a Newton root, folds as before. - The cubic and quartic formulas chose a branch by Evaled == 0, which uses a 1e-6 tolerance. They now compare the part with the terms it is made of: exactly when the part is rational, and otherwise relative to those terms. Where Q is exactly 0, the quartic takes t = 0 as its root of the resolvent t^3 + P t + Q, instead of U - P/(3U), which is 0 too but divides by a U that evaluates to 0 near 10^-60. - StatementSolver.Weigh, Groebner Satisfies and ModulusSolver's residual evaluated with the floor, so a true root's residual came out as 0.087 at any precision. They now evaluate without the exponent floor: Weigh and the as-written check only where the floored reading is against the root, since setting a setting starts a new cache state and doing it on every call was a third more bytes on solving x^2 + x + 1; Satisfies on every candidate, as a flushed residual also passes a wrong row. So do the decimal entries of a Groebner solution, which were evaluated back outside it to a row that was no solution. A residual not shown to be zero still declines the candidate. Satisfies measured a decimal residual against max(1, largest term), which is absolute below 1, and now measures it against the largest term alone. The check that judges a decimal root against the terms as written evaluates without the floor where its floored reading drops the root. - ModulusSolver.IsClearOfZero measured an imaginary part against max(1, |re|), which is absolute below 1. TryReadReal now measures it against the size of the number. #2650 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 #2669 +/- ##
=======================================
Coverage 86.70% 86.70%
=======================================
Files 346 346
Lines 75724 75712 -12
Branches 22145 22140 -5
=======================================
- Hits 65654 65644 -10
+ Misses 5431 5430 -1
+ Partials 4639 4638 -1
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.
Closes #2650
An equation that is solved with its roots near 1 was declined once x was written as 10^30 x. Evaluation's decimals stop at about
10^-100and flush anything smaller to 0, and several places read that flushed value as exact:ExpandOnTwoArguments(Evaluation.Classes.cs) took an exactEvaledfor the node's value. A root, power or quotient of exact rationals that had flushed counted as well, sosqrt(5/10^200 - 4/10^200)became0, and the quartic formula's-Q/2 + sqrt(Q^2/4 + P^3/27)became-Q/2.CannotBeZeroandSignOfANonzeroread rationals through the 1e-16IsZero.PolynomialSolver.cs) chose a branch byEvaled == 0, which is within10^-6. They now compare the part with the terms it is made of: exactly when it is rational, and otherwise relative to those terms. Where Q is exactly 0, the quartic takest = 0as its root of the resolvent, instead ofU - P/(3U), which divides by a U near10^-60.StatementSolver.Weigh, and Judge a decimal root against the terms of the equation as written (#2645) #2649's check against the terms as written: only where the floored reading is against the root.Satisfies: on every candidate, because a flushed residual also passes a row that is no solution.ModulusSolver's reading of the rows.ModulusSolver.IsClearOfZeromeasured againstmax(1, |re|), and GroebnerIsNegligibleagainstmax(1, largest term). Both now measure against the value's own size.A residual that is not shown to be zero still declines the candidate. No tolerance was loosened.
Rebased on f8a822d, so on top of #2644 and #2649.
Answers
scalecheck.pywithx:Kon the 200 cxcheck equations and the radcheck and logcheck corpora. Each cell counts the equations whose scaled answer differs from the unscaled one, master f8a822d against this branch:3e-98, with the scaled variable of order 1.EvalNumerical()in the default context, which flushes the parts of an exact root near10^-20and reports right answers as wrong roots. For example,(-2i + 3y) + (-2 + 3y) abs(-3y) = 0aty = 10^20 xis answered with the root mpmath puts at0.393078192784 + 0.273588473883i(residual2e-299). Read throughEvalNumerical, it comes out as0.262657 + 0.404009i. That is An exact expression whose parts are below 10^-100 evaluates to wrong digits: sqrt(1/10^200 + 1/10^210) * 10^100 is 0 #2668, which is on master and 2.10.0 alike:sqrt(1/10^200 + 1/10^210) * 10^100evaluates to0.Performance
The Kernel benchmark,
CommonFunctionsInterVersion, on one machine and in one session. The arms alternate: master, this branch, master, this branch.The first version of this branch set the unbounded context on every
Weighcall. Setting a setting starts a new cache state, so SolveEasy allocated 33% more (556,893 B) and ran 30% slower. The tree walk allocated a stack on every exact shortcut.Weighnow evaluates without the floor only after the floored reading goes against the root, and the walk is recursive and allocates nothing.The suite passes: 21872, 0 failed. The library builds for every target framework.
Two related findings are filed separately and not fixed here:
{ }.EvalNumericalflush above.🤖 Generated with Claude Code