Repository navigation
A system with more or fewer equations than unknowns is solved or declined - #2124
Merged
Merged
Conversation
…ined EquationSystem.Solve threw WrongNumberOfArgumentsException for a non-square system unless the triangularisation took it (polynomial over Q, rational solutions) or it was short and linear with rational coefficients. The exception says the call was wrong, and it was not: x^2 + y^2 = 1 for x and y has a family of solutions, and sin(x) = 0 with x = 0 has one. Happypig375 agreed on #212 that accepting new forms and not throwing is fine. Such a system now goes to NonSquareSystemSolver. It eliminates the last unknown from the equation with the fewest occurrences of it, recurses on each root, and makes an unknown that nothing is left to constrain a parameter, t_1, as the linear path does. With no unknown left, an equation that is a number away from zero drops its branch; one that cannot be decided, like (a + b)/2 - c, makes that equation's roots no answer, and the next equation is tried. Every family is substituted back into every equation and kept only where each one vanishes, and a system with one that does not is declined as null, which Solve documents as no solution found. Two cases need that check: - sqrt(y) = x is solved for y as x^2, which is no solution for a negative x; sqrt(t^2) - t does not simplify to 0, so the system is declined rather than answered (t, t^2). - A coefficient that is zero without being written so: t^2 - c (t^2/c) simplifies to 0 provided not c = 0 for c = (a + 1)^2 - a^2 - 2a - 1. A provided condition counts only where it holds with the symbols pinned, so that family is declined too. A square system does not reach this, so no square answer changes. Measured, each non-square shape probed on 2.6.0 and on this branch: x^2 + y^2 - 1 in x, y exception -> [[t_1, sqrt(-(t_1 ^ 2 + -1))], [t_1, -sqrt(-(t_1 ^ 2 + -1))]] a*x + y - 1 in x, y exception -> [[t_1, -(a * t_1 + -1)]] sin(x); x in x exception -> [0] sin(x) - y; cos(x) - y; x - pi/4 exception -> [[pi / 4, 1/2 * sqrt(2)]] sqrt(y) - x in x, y exception -> null x + y - a; x - y - b; x - c in x, y exception -> null Part of #212 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.
EquationSystem.SolvethrewWrongNumberOfArgumentsExceptionfor a system with more or fewer equations than unknowns, unless the triangularisation took it or it was short and linear with rational coefficients. The exception says the call was wrong, and it was not. On #212, @Happypig375 said accepting new forms and not throwing is fine, which answers the question my earlier comment there left open.Such a system is now eliminated one unknown at a time:
t_1, as in the linear case.(a + b)/2 - c, means that equation gives no answer, and the next equation is tried.null, whichSolvedocuments as no solution found.A square system does not reach this path, so no square answer changes.
x^2 + y^2 - 1inx, yWrongNumberOfArgumentsException[[t_1, sqrt(-(t_1 ^ 2 + -1))], [t_1, -sqrt(-(t_1 ^ 2 + -1))]]a*x + y - 1inx, yWrongNumberOfArgumentsException[[t_1, -(a * t_1 + -1)]]sin(x),xinxWrongNumberOfArgumentsException[0]sin(x) - y,cos(x) - y,x - pi/4inx, yWrongNumberOfArgumentsException[[pi / 4, 1/2 * sqrt(2)]]sqrt(y) - xinx, yWrongNumberOfArgumentsExceptionnullx + y - a,x - y - b,x - cinx, yWrongNumberOfArgumentsExceptionnullWhy the substitution back is needed. Two of the declines would otherwise be wrong answers:
sqrt(y) = xis solved foryasx^2, which is no solution for a negativex.sqrt(t^2) - tdoes not simplify to 0, so the family(t, t^2)is not returned.x^2 - c ywithc = (a + 1)^2 - a^2 - 2a - 1, the elimination divides byc, andSimplifycalls the residual0 provided not c = 0. Aprovidedcondition counts only where it holds with the symbols pinned, so that family is declined too.NonSquareSystemTestchecks the families numerically at negative and positive values of their parameters, instead of the way the solver checks them. It also checks the overdetermined answers exactly, and the three declines.ParametricSystemTest.WhatIsNotLinearInTheUnknownsIsRefusedpinned the exception for four of these shapes and is removed. Entry inBREAKING-CHANGES.md;Exceptions.mdand theSolvedoc comment no longer say the counts must match.Not in this PR:
sqrt(y) - x,x + 1inx, ygives[[-1, 1]], whilesqrt(1) - (-1)is 2. That is a changed answer for square systems, so it goes in its own PR, for A system of equations is answered with rows that do not satisfy it #2123.sin(x) - 1/2inx, ygivesnull, becausesin(pi/6 + 2 pi n_1) - 1/2does not simplify to 0 without knowing thatn_1is an integer.Part of #212
🤖 Generated with Claude Code
https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura