Skip to content

Commit

Permalink
Trying a simple fix for issue-619. During debugging, I found that Ana…
Browse files Browse the repository at this point in the history
…lyticalEquationSolver.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. (#622)
  • Loading branch information
adk7507 authored Jan 19, 2024
1 parent 79490e3 commit 1ae631f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ internal static List<List<Entity>> InSolveSystem(List<Entity> 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<Entity> { sol }).ToList()
: new();
var result = new List<List<Entity>>();
Expand Down
19 changes: 19 additions & 0 deletions Sources/Tests/UnitTests/Algebra/SolveTest/SolveSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 1ae631f

Please sign in to comment.