Skip to content

Give F# a way to solve a system of equations (#562) - #963

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
feat/fsharp-solve-system
Aug 16, 2026
Merged

Give F# a way to solve a system of equations (#562)#963
Rafael-SOWNet merged 1 commit into
masterfrom
feat/fsharp-solve-system

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Collaborator

Addresses #562.

You can be the one to pick up this redesign; keeping open until a redesign arrives.

Here it is. The wrapper had solutions x expr for one equation and nothing for a system, so the only route was dropping into the C# API.

solveSystem ["x"; "y"] ["x + y - 3"; "x - y - 1"]   // [[2, 1]]

Which of the two shapes, and why

The issue offered:

// Version 1
val system : list 'a -> EquationSystem
val solveSystem : EquationSystem -> Matrix

// Version 2
val solveSystem : list Variable -> list 'a -> Matrix

Version 2, because it reads like the solutions x expr already in the wrapper — subject first, then the thing — and because Version 1 makes a caller learn an EquationSystem type before they can solve anything. equationSystem is 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 = 3 and x + y - 3 mean the same system. An equality is moved to one side rather than passed on as a node — and that is not cosmetic: handing an Equalsf to EquationSystem makes the solver try to invert an equality and throw NotSufficientlySupportedException. That is what my first version did, and the tests caught it.

No solution answers None. EquationSystem.Solve returns a null Matrix, 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

  • F# wrapper tests 134 passed, 0 failed (130 existing + 4 new)
  • the tests cover: a solved linear system with columns following the order of vars, the two spellings agreeing, an inconsistent system answering None, and building a system to pass around
  • purely additive — no existing function changes, so no BREAKING-CHANGES.md entry

Not 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

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.
@Rafael-SOWNet
Rafael-SOWNet merged commit 4a5c593 into master Aug 16, 2026
24 checks passed
@Rafael-SOWNet
Rafael-SOWNet deleted the feat/fsharp-solve-system branch August 16, 2026 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant