Give F# a way to solve a system of equations (#562) - #963
Merged
Conversation
The wrapper had `solutions x expr` for one equation and nothing at all for a system,
so the only route was dropping into the C# API.
solveSystem ["x"; "y"] ["x + y - 3"; "x - y - 1"] // [[2, 1]]
That is Version 2 of the two shapes on the issue, chosen because it reads like the
`solutions x expr` already there -- subject first, then the thing -- rather than
introducing an EquationSystem type a caller has to learn before solving anything.
`equationSystem` is exposed as well for anyone who does want to build one and pass it
around, which is Version 1's use without Version 1's cost.
Two decisions the tests pin:
An entry may be written either way. `x + y = 3` and `x + y - 3` mean the same system,
and an equality is moved to one side rather than passed on as a node -- handing an
Equalsf to EquationSystem makes the solver try to invert an equality and throw
NotSufficientlySupportedException, which is what the first version of this did.
No solution answers None rather than a null Matrix, since "there is no solution" and
"the solver gave up" arrive the same way here and neither is a matrix.
@Happypig375 asked on the issue for someone to pick the redesign up. F# wrapper tests
134 passed, 0 failed.
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.
Addresses #562.
Here it is. The wrapper had
solutions x exprfor one equation and nothing for a system, so the only route was dropping into the C# API.Which of the two shapes, and why
The issue offered:
Version 2, because it reads like the
solutions x expralready in the wrapper — subject first, then the thing — and because Version 1 makes a caller learn anEquationSystemtype before they can solve anything.equationSystemis exposed as well, so Version 1's use (build one, pass it around) is available without Version 1 being the only door.Two decisions the tests pin
An entry may be written either way.
x + y = 3andx + y - 3mean the same system. An equality is moved to one side rather than passed on as a node — and that is not cosmetic: handing anEqualsftoEquationSystemmakes the solver try to invert an equality and throwNotSufficientlySupportedException. That is what my first version did, and the tests caught it.No solution answers
None.EquationSystem.Solvereturns a nullMatrix, and in F# a null is worth turning into an option at the boundary. "There is no solution" and "the solver gave up" arrive the same way here, and neither is a matrix.Evidence
vars, the two spellings agreeing, an inconsistent system answeringNone, and building a system to pass aroundBREAKING-CHANGES.mdentryNot included
The issue is one of three
[WIP]F#/plotting redesigns (#575, #558) marked by their author in 2022 and never advanced. This does not speak to those — it takes the one concrete API the thread actually specified.🤖 Generated with Claude Code