Repository navigation
Answer a polynomial with its roots, not with one per starting point - #686
Merged
Happypig375 merged 1 commit intoAug 4, 2026
Merged
Conversation
…#unreported) x^5 + 3x + 1 came back with 28 roots and x^6 + x + 1 with 23. The numeric search starts from a grid, and the same root reached from different starting points comes back agreeing to about sixteen significant digits and differing after that, so each starting point contributed an answer of its own. Four of the 28 were -0.83907243306660750, -0.83907243306660761, -0.83907243306660773 and -0.83907243306660784. Candidates closer together than the iteration can tell apart are now one root, and the one kept from each group is whichever leaves the equation closest to zero. The room between the two cases is wide: candidates for one root lie within 1e-15 of each other relative to their size, while the nearest two distinct roots over the twelve polynomials tried are 0.42 apart. The threshold is 1e-13, a hundred times above the noise and twelve orders below the closest two roots that were ever told apart. Each of those twelve now comes back with exactly as many roots as its degree, and every one of them satisfies its equation. TestFormula8 asserted which of the two roots of x^2+1 a HashSet hands back first. That was never the solver's to decide and it changed here, because the candidates are now ordered before being collapsed so that which one is compared against which does not depend on the order the grid produced them in. The test now asks for both roots, which is what it was checking. 19 tests, 9 of which fail without the change. 4015 in all, 127 F#, corpus 101/117 with nothing wrong, and 1320 property checks.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #686 +/- ##
==========================================
- Coverage 80.99% 80.41% -0.59%
==========================================
Files 155 156 +1
Lines 13687 12923 -764
Branches 1957 2123 +166
==========================================
- Hits 11086 10392 -694
+ Misses 1990 1923 -67
+ Partials 611 608 -3 ☔ View full report in Codecov by Harness. 🚀 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.
Four of those 28:
They are one root. The numeric search starts from a grid and iterates in double precision, so the same root reached from different starting points comes back agreeing to about sixteen significant digits and differing after that — and each starting point contributed an answer of its own. The rounding that was already there only zeroes components near zero, so it collapses a stray
1e-19imaginary part but has nothing to say about these.What it does now
Candidates closer together than the iteration can tell apart are one root, and the one kept from each group is whichever leaves the equation closest to zero.
The threshold is measured. Candidates for a single root lie within
1e-15of each other relative to their size; the nearest two genuinely distinct roots over the twelve polynomials I tried are0.42apart. The threshold is1e-13— a hundred times above the noise, and twelve orders below the closest two roots that were ever told apart.x^5 + 3x + 1x^6 + x + 1x^9 - x - 1x^5 - 5x + 2Every one of the twelve now comes back with exactly as many roots as its degree, and every root satisfies its equation. The polynomials solved exactly, by radicals rather than by iteration —
x^5 - 1,x^8 - 1,x^7 - 2— never had the problem and are untouched.One existing test changed
FromStringTest.TestFormula8asserted which of the two roots ofx^2 + 1aHashSethands back first. That was never the solver's to decide, and it changed here: the candidates are now ordered before being collapsed, so that which one is compared against which does not depend on the order the grid produced them in. The test now asks for both roots, which is what it was checking.Verification
19 new tests, 9 of which fail without the change. 4015 unit tests and 127 F# tests on both target frameworks, none failing. 117-problem self-verifying corpus at 101/117 with nothing wrong, in error or timing out; 1320 property checks over 151 expressions, none failing.
No issue is filed for this — I found it while checking the answers of #685.