From 5493dde3b736e08bde6093748ebe3d6d33b146a7 Mon Sep 17 00:00:00 2001 From: adk7507 Date: Thu, 4 Jan 2024 11:39:17 -0700 Subject: [PATCH] Trying a simple fix for issue-619. During debugging, I found that AnalyticalEquationSolver.Solve( "{-(x + -1000) / (-1)}", "{x}" ) was returning "{{ } \/ { 1000 } \ { }}". That wasn't being interpreted as a FiniteSet. Getting InnerSimplified results in "{1000}", and that fits the FiniteSet type. --- .../Continuous/Solvers/EquationSolver.cs | 2 +- .../Algebra/SolveTest/SolveSystem.cs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Sources/AngouriMath/AngouriMath/Functions/Continuous/Solvers/EquationSolver.cs b/Sources/AngouriMath/AngouriMath/Functions/Continuous/Solvers/EquationSolver.cs index a1cc1d053..230a2bbde 100644 --- a/Sources/AngouriMath/AngouriMath/Functions/Continuous/Solvers/EquationSolver.cs +++ b/Sources/AngouriMath/AngouriMath/Functions/Continuous/Solvers/EquationSolver.cs @@ -77,7 +77,7 @@ internal static List> InSolveSystem(List equations, ReadOnl { var var = vars[^1]; if (equations.Count == 1) - return equations[0].InnerSimplified.SolveEquation(var) is FiniteSet els + return equations[0].InnerSimplified.SolveEquation(var).InnerSimplified is FiniteSet els ? els.Select(sol => new List { sol }).ToList() : new(); var result = new List>(); diff --git a/Sources/Tests/UnitTests/Algebra/SolveTest/SolveSystem.cs b/Sources/Tests/UnitTests/Algebra/SolveTest/SolveSystem.cs index cee23809f..29c806654 100644 --- a/Sources/Tests/UnitTests/Algebra/SolveTest/SolveSystem.cs +++ b/Sources/Tests/UnitTests/Algebra/SolveTest/SolveSystem.cs @@ -102,5 +102,24 @@ public void EquationWithDivisionIsSolved() => AssertSystemSolvable(new Entity[] "x2 + y", "y - x - 3" }, new Entity.Variable[] { "x", "y" }, 2); + + + [Fact] + public void SystemWithZero() => AssertSystemSolvable(new Entity[] { + "x - y - 1000", + "y - 0" + }, new Entity.Variable[] { "x", "y" }, 1); + + [Fact] + public void SystemWithZero2() => AssertSystemSolvable(new Entity[] { + "y - 0", + "x - y - 1000" + }, new Entity.Variable[] { "x", "y" }, 1); + + [Fact] + public void SystemWithZero3() => AssertSystemSolvable(new Entity[] { + "y - 0", + "x - y" + }, new Entity.Variable[] { "x", "y" }, 1); } }