diff --git a/Sources/AngouriMath/Convenience/MathS.cs b/Sources/AngouriMath/Convenience/MathS.cs
index 37453f767..dad44859b 100644
--- a/Sources/AngouriMath/Convenience/MathS.cs
+++ b/Sources/AngouriMath/Convenience/MathS.cs
@@ -304,6 +304,55 @@ public static Integer GreatestCommonDivisor(Integer a, Integer b)
///
public static Set SolveEquation(Entity equation, Variable var) => EquationSolver.Solve(equation, var);
+ ///
+ /// Solves a system of equations written as one statement, a conjunction of equations,
+ /// jointly for several variables, as solves one written
+ /// as a list.
+ ///
+ ///
+ /// Equations joined by and, nested or not: x + y = 3 and x - y = 1. An
+ /// equation a = b is read as a - b = 0, and a chain a = b = c is the
+ /// conjunction a = b and b = c. One equation is a system of one, and an expression
+ /// that is not a statement is read as equal to zero, as reads one.
+ ///
+ ///
+ /// The unknowns, in the order of the answer's columns, as many as there are equations or
+ /// not, as takes them.
+ ///
+ ///
+ /// What answers for the equations: a matrix
+ /// with a row for each solution and a column for each variable, a variable the system
+ /// leaves free becoming a parameter. where no solution was found,
+ /// which includes a system that has none, as x + y = 1 and x + y = 2, and one the
+ /// solver could not settle. Also where a conjunct is not an
+ /// equation -- an inequality, an in, an or, a not or a boolean --
+ /// since solving the others alone would answer a different question; solve such a
+ /// statement for one variable at a time with .
+ ///
+ ///
+ /// on the same statement solves it for one variable,
+ /// with the others as parameters: x + y = 3 and x - y = 1 for x is
+ /// { 3 - y } ∩ { 1 + y }, the values of x for each y. This is the
+ /// question for all of them at once, and answers the point (2, 1).
+ /// https://github.com/asc-community/AngouriMath/issues/2450
+ ///
+ ///
+ /// As : the work the call may spend ran out
+ /// before the system was solved, which is "not settled", not "no solution".
+ ///
+ ///
+ ///
+ /// var solutions = MathS.SolveSystem("x^2 + y^2 = 25 and x - y = 1", "x", "y");
+ /// Console.WriteLine(solutions);
+ ///
+ /// Prints
+ ///
+ /// [[-3, -4], [4, 3]]
+ ///
+ ///
+ public static Matrix? SolveSystem(Entity system, params Variable[] variables)
+ => EquationSystem.EquationsOf(system, out _) is { } equations ? new EquationSystem(equations).Solve(variables) : null;
+
///
/// Solves a first-order linear ordinary differential equation
/// by its
diff --git a/Sources/AngouriMath/Core/EquationSystem.cs b/Sources/AngouriMath/Core/EquationSystem.cs
index dabfa8ecb..97306175e 100644
--- a/Sources/AngouriMath/Core/EquationSystem.cs
+++ b/Sources/AngouriMath/Core/EquationSystem.cs
@@ -63,6 +63,46 @@ public sealed class EquationSystem : ILatexizeable
private static Entity AsAnExpressionEqualToZero(Entity equation)
=> equation is Equalsf(var left, var right) ? left - right : equation;
+ ///
+ /// The equations of , each an expression equal to zero, where it
+ /// is a conjunction of equations -- nested or not, and one equation is a conjunction of
+ /// one -- or an expression, which is read as equal to zero. , with
+ /// the first conjunct that is not an equation in , where
+ /// any conjunct is something else: an inequality, a membership, a disjunction, a
+ /// negation or a boolean. Leaving one out would answer a different question.
+ ///
+ ///
+ /// An equality whose side is itself a statement, (x = 1) = (y = 2), is an
+ /// equivalence of statements rather than an equation in numbers, and is not one either.
+ /// https://github.com/asc-community/AngouriMath/issues/2450
+ ///
+ internal static List? EquationsOf(Entity system, out Entity? notAnEquation)
+ {
+ notAnEquation = null;
+ if (system is not Statement)
+ return new List { system };
+ var equations = new List();
+ var pending = new Stack();
+ pending.Push(system);
+ while (pending.Count > 0)
+ {
+ switch (pending.Pop())
+ {
+ case Andf(var left, var right):
+ pending.Push(right);
+ pending.Push(left);
+ break;
+ case Equalsf(var left, var right) when left is not Statement && right is not Statement:
+ equations.Add(left - right);
+ break;
+ case var other:
+ notAnEquation = other;
+ return null;
+ }
+ }
+ return equations;
+ }
+
///
/// Solves a system of equations, if possible.
///
diff --git a/Sources/AngouriMath/Core/Operations/Catalogue.cs b/Sources/AngouriMath/Core/Operations/Catalogue.cs
index 19d128a4e..c0d4a06ee 100644
--- a/Sources/AngouriMath/Core/Operations/Catalogue.cs
+++ b/Sources/AngouriMath/Core/Operations/Catalogue.cs
@@ -1,4 +1,4 @@
-//
+//
// Copyright (c) 2019-2026 Angouri.
// AngouriMath is licensed under MIT.
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
@@ -102,6 +102,12 @@ internal static class Catalogue
static (equations, variables) => MathS.Equations(equations).Solve([.. variables]),
new Parameter("variables", "The variables to solve for, in the order of the answer's columns."));
+ /// .
+ public static Query, Matrix?>> SolveConjunction { get; } = new(
+ "solve_conjunction", "Solves a conjunction of equations jointly for several variables, as solve_system solves them listed, and declines one with a conjunct that is not an equation.",
+ static (system, variables) => MathS.SolveSystem(system, [.. variables]),
+ new Parameter("variables", "The variables to solve for, in the order of the answer's columns."));
+
/// .
public static Query> Evaluate { get; } = new(
"evaluate", "Evaluates as far as it goes: to a number, a boolean or a set where it can, and as an expression where it cannot.",
@@ -254,7 +260,7 @@ internal static class Catalogue
public static IReadOnlyList All { get; } =
[
Simplify, Normalize, Expand, Factorize, Differentiate, Integrate, Limit, Substitute,
- Solve, SolveSystem, Evaluate, EvaluateNumerically, Variables, Alternatives, Latex, Sympy, TruthTable, SatisfyingAssignments, Series, AreEqual,
+ Solve, SolveSystem, SolveConjunction, Evaluate, EvaluateNumerically, Variables, Alternatives, Latex, Sympy, TruthTable, SatisfyingAssignments, Series, AreEqual,
ToBase, FromBase,
Determinant, Inverse, Transpose, Rank, ReducedRowEchelonForm, Trace, TensorProduct,
PrimeFactorization, Totient, GreatestCommonDivisor, DivisorCount, IsPrime,
diff --git a/Sources/MCP/AngouriMath.Mcp/Tools.cs b/Sources/MCP/AngouriMath.Mcp/Tools.cs
index eb4d74399..a37ba2aff 100644
--- a/Sources/MCP/AngouriMath.Mcp/Tools.cs
+++ b/Sources/MCP/AngouriMath.Mcp/Tools.cs
@@ -1,4 +1,4 @@
-//
+//
// Copyright (c) 2019-2026 Angouri.
// AngouriMath is licensed under MIT.
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
@@ -93,7 +93,7 @@ private static JsonObject Schema(JsonObject props, params string[] required)
["am_limit"] = [Catalogue.Limit],
["am_evaluate"] = [Catalogue.EvaluateNumerically],
["am_truth_table"] = [Catalogue.TruthTable, Catalogue.SatisfyingAssignments],
- ["am_solve_system"] = [Catalogue.SolveSystem],
+ ["am_solve_system"] = [Catalogue.SolveSystem, Catalogue.SolveConjunction],
["am_represent"] = [Catalogue.ToBase, Catalogue.FromBase],
["am_matrix"] = [Catalogue.Determinant, Catalogue.Inverse, Catalogue.Transpose, Catalogue.Rank,
Catalogue.ReducedRowEchelonForm, Catalogue.Trace, Catalogue.TensorProduct],
@@ -327,7 +327,8 @@ private static JsonObject[] All() =>
Tool("am_solve_system",
"Solve a system of simultaneous equations for several variables. Returns one row " +
- "per solution. Note: nonlinear systems may return no solution even when one " +
+ "per solution. Give the system either as a list of equations or as one statement " +
+ "joining them with 'and'. Note: nonlinear systems may return no solution even when one " +
"exists (a known library limitation).",
Schema(new JsonObject
{
@@ -335,7 +336,13 @@ private static JsonObject[] All() =>
{
["type"] = "array",
["items"] = new JsonObject { ["type"] = "string" },
- ["description"] = "Equations, e.g. ['x + y = 3', 'x - y = 1'].",
+ ["description"] = "Equations, e.g. ['x + y = 3', 'x - y = 1']. Give this or 'statement'.",
+ },
+ ["statement"] = new JsonObject
+ {
+ ["type"] = "string",
+ ["description"] = "The system as one conjunction of equations, e.g. 'x + y = 3 and x - y = 1'. " +
+ "Declined where a conjunct is not an equation (an inequality, 'in', 'or', 'not'). Give this or 'equations'.",
},
["variables"] = new JsonObject
{
@@ -343,7 +350,7 @@ private static JsonObject[] All() =>
["items"] = new JsonObject { ["type"] = "string" },
["description"] = "Variables to solve for, e.g. ['x','y'].",
},
- }, "equations", "variables")),
+ }, "variables")),
Tool("am_check_steps",
"Check a chain of working step by step and report WHICH step broke. Use this to " +
@@ -1386,8 +1393,10 @@ private static JsonObject TruthTable(JsonObject args)
private static JsonObject SolveSystem(JsonObject args)
{
var equations = A(args, "equations");
+ var statement = S(args, "statement");
var variables = A(args, "variables");
- if (equations.Count == 0) return Fail("'equations' must not be empty");
+ if (statement is not null && equations.Count > 0) return Fail("give 'equations' or 'statement', not both");
+ if (statement is null && equations.Count == 0) return Fail("'equations' must not be empty");
if (variables.Count == 0) return Fail("'variables' must not be empty");
var parsed = new List();
@@ -1402,8 +1411,28 @@ private static JsonObject SolveSystem(JsonObject args)
warnings.AddRange(w);
}
- return FromOutcome(Guard.Run(() =>
- Catalogue.SolveSystem.Ask(parsed, [.. variables.Select(Var)])), matrix =>
+ Entity? system = null;
+ if (statement is not null)
+ {
+ if (!TryParse(statement, "statement", false, out var e, out var w, out var error))
+ return error!;
+ // A conjunct that is not an equation is declined by the library as well; naming it
+ // here is what tells the caller why, where the library can only say null.
+ if (EquationSystem.EquationsOf(e, out var notAnEquation) is null)
+ return new JsonObject
+ {
+ ["status"] = "declined",
+ ["note"] = $"'{notAnEquation!.Stringize()}' is not an equation, and solving the other " +
+ "conjuncts without it would answer a different question. Solve the statement for one " +
+ "variable with am_solve instead.",
+ };
+ system = e;
+ warnings.AddRange(w);
+ }
+
+ return FromOutcome(Guard.Run(() => system is not null
+ ? Catalogue.SolveConjunction.Ask(system, [.. variables.Select(Var)])
+ : Catalogue.SolveSystem.Ask(parsed, [.. variables.Select(Var)])), matrix =>
{
var order = new JsonArray();
foreach (var v in variables) order.Add(v);
diff --git a/Sources/MCP/README.md b/Sources/MCP/README.md
index c8c510c2a..b3eb960d7 100644
--- a/Sources/MCP/README.md
+++ b/Sources/MCP/README.md
@@ -62,7 +62,7 @@ echo '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}' | amcli mcp
| `am_are_equal` | `equal` only with a proof, `not_equal` only with a witness point, else `unknown`; never decided by sampling alone. Bounded in steps |
| `am_check_steps` | checks a chain of working and names the step that broke |
| `am_truth_table` | the table and the satisfying assignments |
-| `am_solve_system` | takes `x + y = 3` as well as `x + y - 3` |
+| `am_solve_system` | takes `x + y = 3` as well as `x + y - 3`, and the system as a list or as one statement, `x + y = 3 and x - y = 1`; a conjunct that is not an equation is declined and named |
| `am_domain_check` | domain conditions, structural hazards, and where it stops being real |
| `am_represent` | encodings: bases 2–36, Q-format fixed point, IEEE 754 bits, polar form |
| `am_matrix` | determinant, inverse, transpose, rank, RREF, trace, multiply, tensor product, power |
diff --git a/Sources/Terminal/AngouriMath.Terminal.Lib/OneShot.fs b/Sources/Terminal/AngouriMath.Terminal.Lib/OneShot.fs
index 620cbd9e0..2d4b461b3 100644
--- a/Sources/Terminal/AngouriMath.Terminal.Lib/OneShot.fs
+++ b/Sources/Terminal/AngouriMath.Terminal.Lib/OneShot.fs
@@ -67,7 +67,7 @@ let ownCommands =
/// the question of #1019 item 16; an entry added to the catalogue joins this list or a command.
///
let notOffered =
- set [ "expand"; "factorize"; "integrate"; "limit"; "solve_system"; "evaluate_numerically"; "variables"
+ set [ "expand"; "factorize"; "integrate"; "limit"; "solve_system"; "solve_conjunction"; "evaluate_numerically"; "variables"
"alternatives"; "sympy"; "truth_table"; "satisfying_assignments"; "series"; "to_base"; "from_base"
"determinant"; "inverse"; "transpose"; "rank"; "reduced_row_echelon_form"; "trace"; "tensor_product"
"prime_factorization"; "totient"; "greatest_common_divisor"; "divisor_count"; "is_prime"; "are_equal" ]
diff --git a/Sources/Tests/McpUnitTests/ToolsTest.cs b/Sources/Tests/McpUnitTests/ToolsTest.cs
index 508217fc8..b5d6c35bb 100644
--- a/Sources/Tests/McpUnitTests/ToolsTest.cs
+++ b/Sources/Tests/McpUnitTests/ToolsTest.cs
@@ -1,4 +1,4 @@
-//
+//
// Copyright (c) 2019-2026 Angouri.
// AngouriMath is licensed under MIT.
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
@@ -223,6 +223,28 @@ public void ASystemWrittenAsEqualitiesIsSolved()
Assert.Equal("2 1", string.Join(" ", answer.Field("solutions").Split('\n')[1].Split(' ', StringSplitOptions.RemoveEmptyEntries)));
}
+ // https://github.com/asc-community/AngouriMath/issues/2450
+ [Fact]
+ public void ASystemWrittenAsOneConjunctionIsSolved()
+ {
+ var answer = Mcp.Call("am_solve_system", """{"statement":"x + y = 3 and x - y = 1","variables":["x","y"]}""");
+ Assert.Equal(1, answer["solution_count"]!.GetValue());
+ Assert.Equal("2 1", string.Join(" ", answer.Field("solutions").Split('\n')[1].Split(' ', StringSplitOptions.RemoveEmptyEntries)));
+ }
+
+ [Fact]
+ public void AConjunctThatIsNotAnEquationIsNamedAndDeclined()
+ {
+ var answer = Mcp.Call("am_solve_system", """{"statement":"x + y = 3 and x > 0","variables":["x","y"]}""");
+ Assert.Equal("declined", answer.Field("status"));
+ Assert.Contains("x > 0", answer.Field("note"));
+ }
+
+ [Fact]
+ public void ASystemIsGivenAsAListOrAsAStatementNotBoth() =>
+ Assert.Equal("failed", Mcp.Call("am_solve_system",
+ """{"equations":["x + y = 3"],"statement":"x - y = 1","variables":["x","y"]}""").Field("status"));
+
[Fact]
public void ToSympyWritesAProgram() =>
Assert.Contains("sympy", Mcp.Call("am_to_sympy", """{"expression":"sin(x)/x"}""").Field("sympy"));
diff --git a/Sources/Tests/UnitTests/Common/PublicApi.txt b/Sources/Tests/UnitTests/Common/PublicApi.txt
index db33de691..59f79c929 100644
--- a/Sources/Tests/UnitTests/Common/PublicApi.txt
+++ b/Sources/Tests/UnitTests/Common/PublicApi.txt
@@ -3779,6 +3779,7 @@ AngouriMath.MathS.Sin(AngouriMath.Entity) : AngouriMath.Entity
AngouriMath.MathS.SolveBooleanTable(AngouriMath.Entity, AngouriMath.Entity+Variable[]) : AngouriMath.Entity+Matrix
AngouriMath.MathS.SolveEquation(AngouriMath.Entity, AngouriMath.Entity+Variable) : AngouriMath.Entity+Set
AngouriMath.MathS.SolveOde(AngouriMath.Entity, AngouriMath.Entity+Variable, AngouriMath.Entity+Variable) : AngouriMath.Entity
+AngouriMath.MathS.SolveSystem(AngouriMath.Entity, AngouriMath.Entity+Variable[]) : AngouriMath.Entity+Matrix
AngouriMath.MathS.Sqr(AngouriMath.Entity) : AngouriMath.Entity
AngouriMath.MathS.Sqrt(AngouriMath.Entity) : AngouriMath.Entity
AngouriMath.MathS.Sum(AngouriMath.Entity, AngouriMath.Entity, AngouriMath.Entity) : AngouriMath.Entity
diff --git a/Sources/Tests/UnitTests/Common/SolverRegressionTest.cs b/Sources/Tests/UnitTests/Common/SolverRegressionTest.cs
index 1366bf87b..d894ae036 100644
--- a/Sources/Tests/UnitTests/Common/SolverRegressionTest.cs
+++ b/Sources/Tests/UnitTests/Common/SolverRegressionTest.cs
@@ -1,4 +1,4 @@
-//
+//
// Copyright (c) 2019-2022 Angouri.
// AngouriMath is licensed under MIT.
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
@@ -388,5 +388,75 @@ public void Issue2425_OverTheComplexNumbersTheRootIsKept()
var value = Assert.IsAssignableFrom(root.Evaled);
Assert.Equal(System.Math.PI, value.ImaginaryPart.EDecimal.ToDouble(), 12);
}
+
+ // A statement that is a conjunction of equations is a system, and it is solved for
+ // several variables at once as the same equations listed are: x + y = 3 and x - y = 1
+ // is the point (2, 1). Every row is put back into every conjunct, a parameter left
+ // free included, and the answer is what MathS.Equations answers for the conjuncts.
+ // https://github.com/asc-community/AngouriMath/issues/2450
+ [Theory]
+ [InlineData("x + y = 3 and x - y = 1", "x,y", 1)]
+ [InlineData("x^2 + y^2 = 25 and x - y = 1", "x,y", 2)]
+ [InlineData("x + y + z = 6 and (x - y = 0 and z = 2)", "x,y,z", 1)]
+ [InlineData("(x + y = 3 and x - y = 1) and (x + 2 y = 4)", "x,y", 1)]
+ [InlineData("x = y = 1", "x,y", 1)]
+ [InlineData("x + y = 3 and x - y = 1", "x,y,z", 1)]
+ [InlineData("x + y = 3", "x,y", 1)]
+ [InlineData("x + y - 3", "x,y", 1)]
+ public void Issue2450_AConjunctionOfEquationsIsSolvedAsASystem(string statement, string variables, int rows)
+ {
+ var unknowns = variables.Split(',').Select(name => MathS.Var(name)).ToArray();
+ var solutions = MathS.SolveSystem(statement, unknowns);
+ Assert.NotNull(solutions);
+ Assert.Equal(rows, solutions.RowCount);
+ var equations = AngouriMath.Core.EquationSystem.EquationsOf(statement, out _);
+ Assert.NotNull(equations);
+ Assert.Equal(MathS.Equations(equations).Solve(unknowns), solutions);
+ for (var row = 0; row < solutions.RowCount; row++)
+ foreach (var equation in equations)
+ {
+ var residual = equation;
+ for (var column = 0; column < unknowns.Length; column++)
+ residual = residual.Substitute(unknowns[column], solutions[row, column]);
+ Assert.True(residual.Simplify() == 0, $"row {row} leaves {residual.Simplify()} in {equation} = 0");
+ }
+ }
+
+ // The point the issue asked for.
+ [Fact]
+ public void Issue2450_TheIssuesSystemIsThePointTwoOne()
+ {
+ var solutions = MathS.SolveSystem("x + y = 3 and x - y = 1", "x", "y");
+ Assert.NotNull(solutions);
+ Assert.Equal(1, solutions.RowCount);
+ Assert.True(solutions[0, 0] == 2 && solutions[0, 1] == 1, solutions.ToString());
+ }
+
+ // A conjunct that is not an equation is not dropped: solving the others alone would
+ // answer a different question, so the system is declined.
+ [Theory]
+ [InlineData("x + y = 3 and x > 0")]
+ [InlineData("x + y = 3 and x in RR")]
+ [InlineData("x + y = 3 or x - y = 1")]
+ [InlineData("x + y = 3 and not (x - y = 1)")]
+ [InlineData("x + y = 3 and true")]
+ [InlineData("(x = 1) = (y = 2)")]
+ public void Issue2450_AConjunctThatIsNotAnEquationIsDeclined(string statement)
+ {
+ Assert.Null(AngouriMath.Core.EquationSystem.EquationsOf(statement, out var notAnEquation));
+ Assert.NotNull(notAnEquation);
+ Assert.Null(MathS.SolveSystem(statement, "x", "y"));
+ }
+
+ // A system with no solution is null, as the system solver answers it for the same
+ // equations listed: null is "no solution was found", which a system without one is.
+ [Theory]
+ [InlineData("x + y = 1 and x + y = 2")]
+ [InlineData("x + y = 3 and x - y = 1 and x + 2 y = 5")]
+ public void Issue2450_AnInconsistentSystemIsNull(string statement)
+ {
+ Assert.Null(MathS.SolveSystem(statement, "x", "y"));
+ Assert.Null(MathS.Equations(AngouriMath.Core.EquationSystem.EquationsOf(statement, out _)!).Solve("x", "y"));
+ }
}
}
diff --git a/Sources/Tests/UnitTests/Core/Operations/CatalogueTest.cs b/Sources/Tests/UnitTests/Core/Operations/CatalogueTest.cs
index 292cbe107..f82560fd7 100644
--- a/Sources/Tests/UnitTests/Core/Operations/CatalogueTest.cs
+++ b/Sources/Tests/UnitTests/Core/Operations/CatalogueTest.cs
@@ -1,4 +1,4 @@
-//
+//
// Copyright (c) 2019-2026 Angouri.
// AngouriMath is licensed under MIT.
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
@@ -211,6 +211,9 @@ public void EachEntryAnswersAsTheMethodItNames()
Assert.Equal(MathS.FromString("x^2 = 4").Solve(x), Catalogue.Solve.Ask("x^2 = 4", x));
Entity[] system = ["x + y - 3", "x - y - 1"];
Assert.Equal(MathS.Equations(system).Solve(x, y), Catalogue.SolveSystem.Ask(system, [x, y]));
+ Assert.Equal(MathS.SolveSystem("x + y = 3 and x - y = 1", x, y), Catalogue.SolveConjunction.Ask("x + y = 3 and x - y = 1", [x, y]));
+ Assert.NotNull(Catalogue.SolveConjunction.Ask("x + y = 3 and x - y = 1", [x, y]));
+ Assert.Null(Catalogue.SolveConjunction.Ask("x + y = 3 and x > 0", [x, y]));
Assert.Equal(MathS.FromString("sqrt(2) + 1").Evaled, Catalogue.Evaluate.Ask("sqrt(2) + 1"));
Assert.Equal(MathS.FromString("sqrt(2) + 1").EvalNumerical(), Catalogue.EvaluateNumerically.Ask("sqrt(2) + 1"));
Assert.Equal(MathS.FromString("x + y").Vars, Catalogue.Variables.Ask("x + y"));