An equation in a remainder is solved to its whole family - #1630
Merged
Merged
Conversation
f mod a = r has one solution per period. It is now inverted the way the
trigonometric functions are, with a whole parameter: f = r + |a| n where r is
a value the floored remainder takes -- [0, a) for a positive a, (a, 0] for a
negative one -- and no solution where it is not. (x mod 4) + 1 = 3 is
{ 2 + 4 n_1 }, where 2.5.0 answered { }; (2x + 1) mod 4 = 3 is every odd
number, where 2.5.0 listed six of them. A divisor or value that is not a
number is left unsolved.
Closes #1629.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
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.
(x mod 4) + 1 = 3holds for everyx = 2 + 4n. On 2.5.0 it was{ }, which claims there is no solution. Where the numeric fallback reached one of these equations, it listed the solutions it found in its window:(2x + 1) mod 4 = 3was{ -5, -3, -1, 1, 3, 5 }, and 7 is a solution too.The remainder is now inverted the way the trigonometric functions are, with a whole parameter.
modis the floored remainder and takes the sign of the divisor:-1 mod 4 = 3,5 mod (-4) = -3,5/2 mod 2 = 1/2. So modulo a positiveait takes each value in[0, a)once per period, and modulo a negativeaeach value in(a, 0].f mod a = ris thereforef = r + |a| nwhenrlies in that range, and has no solution when it does not. A divisor containingx, or a divisor or value that is not a number, is left unsolved.Solve("x")of(x mod 4) + 1 = 3{ }{ 2 + 4 * n_1 }(2x + 1) mod 4 = 3{ -5, -3, -1, 1, 3, 5 }{ (3 + 4 * n_1 - 1) / 2 }x mod (-4) = -1{ }{ -1 + 4 * n_1 }x mod 4 = 5{ }{ }x mod a = 1{ }{ x : x mod a = 1 }RemainderEquationTestchecks four things:nfrom -2 to 2;Two tests pinned the old answer so that this change would be seen.
ModulusTest.SolvingIsNotClaimedis nowSolvingGivesEverySolution. Thex mod 3 = 1row ofAnUnwrittenInverseIsNotTheEmptySetTestmoved toRemainderEquationTestand is checked at values ofn, because a membership test cannot range over a parameter.Suite on net10.0, at
78c07506on master371b38e1: 14164 passed and 1 failed, the pinnedModulusTest.SolvingIsNotClaimedabove. The head,8963256a, differs from78c07506only in that test. At the head the 428 solver, remainder, modulus and residue tests pass, the rewritten one among them. Every target framework builds.Gate: allocation matches the baseline on all 19 gated benchmarks.
BREAKING-CHANGES.mdgains a new entry. The earlier entry for equations the solver cannot invert now listsmodonly for a divisor that is not a number, and itsx mod 3 = 1row is nowx mod a = 1.Closes #1629.
Part of #180.
🤖 Generated with Claude Code
https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura