diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 2ed22233c..3842e93ef 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -378,6 +378,30 @@ unchanged ([#2450](https://github.com/asc-community/AngouriMath/issues/2450)). --- +### Two parameters of a system's answer that are independent have two names + +**Silent: a part of the solutions becomes all of them.** Solving a system, each equation's roots bring their own +parameters, and a second equation minted the same name as the first where the two do not reach each other. So +`sin(x) = 1/2` and `sin(y) = 1/2` came back as `(pi/6 + 2 pi n_1, pi/6 + 2 pi n_1)` and its three siblings, which says +`x - y` is a whole number of periods and leaves out `(pi/6, 13 pi/6)`. Each independent parameter now has a name of its +own, and one that reaches a later equation is still shared, as in `tan(x) = 1`, `y = x`. A name also stands for one set +throughout an answer, so the `t` of a `floor` and the `t` of a free unknown are never the same name +([#212](https://github.com/asc-community/AngouriMath/issues/212)). + +| Input | Was (2.7.0) | Now | +|---|---|---| +| `MathS.Equations("sin(x) - 1/2", "sin(y) - 1/2").Solve("x", "y")` | `[[pi / 6 + 2 * pi * n_1, pi / 6 + 2 * pi * n_1], …]`, four rows | `[[pi / 6 + 2 * pi * n_1, pi / 6 + 2 * pi * n_2], …]`, four rows | +| `MathS.Equations("sin(x) - 1/2", "cos(y)").Solve("x", "y")` | `[[pi / 6 + 2 * pi * n_1, pi / 2 + 2 * pi * n_1], …]` | `[[pi / 6 + 2 * pi * n_1, pi / 2 + 2 * pi * n_2], …]` | +| `MathS.Equations("tan(x) - 1", "tan(y) - 1", "tan(z) - 1").Solve("x", "y", "z")` | `[[pi / 4 + pi * n_1, pi / 4 + pi * n_1, pi / 4 + pi * n_1]]` | `[[pi / 4 + pi * n_1, pi / 4 + pi * n_2, pi / 4 + pi * n_3]]` | +| `MathS.Equations("floor(x) - 1", "floor(y) - 2").Solve("x", "y")` | `[[1 + t_1 provided …, 2 + t_1 provided …]]` | `[[1 + t_1 provided …, 2 + t_2 provided …]]` | +| `MathS.Equations("abs(x) - 1", "abs(y) - 2").Solve("x", "y")` | `[[e ^ (i * r_1) provided r_1 in RR, 2 * e ^ (i * r_1) provided r_1 in RR]]` | `[[e ^ (i * r_1) provided r_1 in RR, 2 * e ^ (i * r_2) provided r_2 in RR]]` | +| `MathS.Equations("tan(x) - 1", "y - x").Solve("x", "y")` | `[[pi / 4 + pi * n_1, pi / 4 + pi * n_1]]` | unchanged | + +`EquationSystem.SolveWithParameters` and `MathS.SolveSystemWithParameters` are new, and say what each parameter is: +`(n_1, ZZ)`, `(n_2, ZZ)` for the first row of the table. + +--- + ## 2.7.0 — since 2.6.0 **Read these first: names that read differently.** Each of these was read as something else on 2.6.0. Code that used diff --git a/Sources/.editorconfig b/Sources/.editorconfig index 141699634..706d5cde4 100644 --- a/Sources/.editorconfig +++ b/Sources/.editorconfig @@ -48,6 +48,12 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed [Tests/UnitTests/Common/LogarithmOfAPerfectPowerTest.cs] file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n +[AngouriMath/Functions/Continuous/Solvers/EquationSolver/SolutionParameters.cs] +file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n + +[Tests/UnitTests/Algebra/SolveTest/SystemParametersTest.cs] +file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n + [AngouriMath/Functions/PredicateEntailment.cs] file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n diff --git a/Sources/AngouriMath/Convenience/MathS.cs b/Sources/AngouriMath/Convenience/MathS.cs index d0e16ac17..e05517bcb 100644 --- a/Sources/AngouriMath/Convenience/MathS.cs +++ b/Sources/AngouriMath/Convenience/MathS.cs @@ -394,6 +394,44 @@ public static Integer GreatestCommonDivisor(Integer a, Integer b) public static Matrix? SolveSystem(Entity system, params Variable[] variables) => EquationSystem.EquationsOf(system, out _) is { } equations ? new EquationSystem(equations).Solve(variables) : null; + /// + /// Solves a system of equations written as one statement, as + /// does, and says what each parameter in the + /// answer is and which set it ranges over, as + /// does for a system written + /// as a list. + /// + /// + /// Equations joined by and, as takes them. + /// + /// The unknowns, in the order of the answer's columns. + /// + /// The rows answers and each parameter in + /// them with its set: (t_1, CC) for an unknown nothing constrains, (n_1, ZZ) + /// for a whole number of periods. where + /// is, and where a parameter is one whose + /// set cannot be named. + /// + /// https://github.com/asc-community/AngouriMath/issues/212 + /// + /// As . + /// + /// + /// + /// var solved = MathS.SolveSystemWithParameters("2x - 4y = 12", "x", "y"); + /// Console.WriteLine(solved!.Rows); + /// foreach (var (parameter, domain) in solved.Parameters) + /// Console.WriteLine($"{parameter} in {domain}"); + /// + /// Prints + /// + /// [[6 + 2 * t_1, t_1]] + /// t_1 in CC + /// + /// + public static ParametrizedSolutions? SolveSystemWithParameters(Entity system, params Variable[] variables) + => EquationSystem.EquationsOf(system, out _) is { } equations ? new EquationSystem(equations).SolveWithParameters(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 74167dd3e..3a2ba4a43 100644 --- a/Sources/AngouriMath/Core/EquationSystem.cs +++ b/Sources/AngouriMath/Core/EquationSystem.cs @@ -144,6 +144,85 @@ private static IEnumerable AsExpressionsEqualToZero(Entity equation) /// public Matrix? Solve(params Variable[] vars) => EquationSolver.SolveSystem(equations, vars); + /// + /// Solves the system as does, and says what each parameter + /// in the answer is and which set it ranges over. + /// + /// The unknowns, as takes them. + /// + /// The rows answers, in + /// , and in + /// each symbol of theirs that is neither an + /// unknown nor a symbol of the equations, in the order it first appears, with the set it + /// ranges over: t_1 over CC for an unknown nothing constrains (RR + /// where is ), n_1 + /// over ZZ for a whole number of periods or a branch of the Lambert W function, + /// r_1 over RR for the argument of a number of given modulus, and the + /// t_1 of floor(x) = 1 over [0, 1). The list is empty where the + /// answer has no parameter. where + /// is, and where a parameter is one this cannot name the set of. + /// + /// + /// + /// Each row is a family of solutions, one for each value of the parameters it mentions, + /// taken from their sets; a row need not mention all of them. A name stands for one set + /// throughout the answer, and within a row two parameters are two names: in + /// sin(x) = 1/2, sin(y) = 1/2 the rows read + /// (pi/6 + 2 pi n_1, pi/6 + 2 pi n_2). Rows are separate families, so a + /// name in two rows is chosen independently in each. + /// + /// + /// A row may say where it holds, as 1 + t_1 provided t_1 in RR and t_1 >= 0 and + /// t_1 < 1 does; the set of its parameter is said here either way. + /// + /// https://github.com/asc-community/AngouriMath/issues/212 + /// + /// + /// As . + /// + /// + /// + /// var solved = MathS.Equations("sin(x) - 1/2").SolveWithParameters("x", "y"); + /// Console.WriteLine(solved!.Rows); + /// foreach (var (parameter, domain) in solved.Parameters) + /// Console.WriteLine($"{parameter} in {domain}"); + /// + /// Prints + /// + /// [[pi / 6 + 2 * pi * n_1, t_1], [pi - pi / 6 + 2 * pi * n_1, t_1]] + /// n_1 in ZZ + /// t_1 in CC + /// + /// + public ParametrizedSolutions? SolveWithParameters(params Variable[] vars) + { + var scope = AngouriMath.Functions.Algebra.AnalyticalSolving.SolutionParameters.Open(out var opened); + try + { + if (Solve(vars) is not { } rows) + return null; + var known = new HashSet(equations.SelectMany(equation => equation.Vars)); + known.UnionWith(vars); + var parameters = new List<(Variable Parameter, Set Domain)>(); + for (var row = 0; row < rows.RowCount; row++) + for (var column = 0; column < rows.ColumnCount; column++) + foreach (var symbol in rows[row, column].Vars) + { + if (!known.Add(symbol)) + continue; + if (scope.SetOf(symbol) is not { } domain) + return null; + parameters.Add((symbol, domain)); + } + return new ParametrizedSolutions(rows, parameters); + } + finally + { + if (opened) + scope.Close(); + } + } + /// /// Latexized version of the system. It adds /// zero equality to all the provided expressions @@ -166,4 +245,32 @@ public string Latexize() /// public override string ToString() => string.Join("\n", equations.Select(c => c.Stringize() + " = 0")); } + + /// + /// The solutions of a system as families: the rows + /// answers, and the parameters they are written in, each with the set it ranges over. + /// See . + /// https://github.com/asc-community/AngouriMath/issues/212 + /// + /// + /// A row for each family of solutions and a column for each unknown, as + /// answers them. + /// + /// + /// Each parameter of and the set it ranges over, in the order the + /// parameters first appear: (n_1, ZZ), (t_1, CC). Empty where no row has one. + /// + public sealed record ParametrizedSolutions(Matrix Rows, IReadOnlyList<(Variable Parameter, Set Domain)> Parameters) + { + /// + /// Whether the rows are equal and the parameters are the same, in the same order, with + /// the same sets: compared element by element, where a record compares a list by reference. + /// + public bool Equals(ParametrizedSolutions? other) + => other is not null && Rows == other.Rows && Parameters.SequenceEqual(other.Parameters); + + /// + public override int GetHashCode() + => Parameters.Aggregate(Rows.GetHashCode(), (hash, pair) => unchecked(hash * 31 + pair.GetHashCode())); + } } \ No newline at end of file diff --git a/Sources/AngouriMath/Core/Operations/Catalogue.cs b/Sources/AngouriMath/Core/Operations/Catalogue.cs index d3dc3f373..a5cbcae7a 100644 --- a/Sources/AngouriMath/Core/Operations/Catalogue.cs +++ b/Sources/AngouriMath/Core/Operations/Catalogue.cs @@ -108,6 +108,18 @@ internal static class Catalogue 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, IReadOnlyList, ParametrizedSolutions?>> SolveSystemWithParameters { get; } = new( + "solve_system_with_parameters", "Solves equations jointly for several variables, as solve_system does, and names each parameter of the answer with the set it ranges over.", + static (equations, variables) => MathS.Equations(equations).SolveWithParameters([.. variables]), + new Parameter("variables", "The variables to solve for, in the order of the answer's columns.")); + + /// . + public static Query, ParametrizedSolutions?>> SolveConjunctionWithParameters { get; } = new( + "solve_conjunction_with_parameters", "Solves a conjunction of equations jointly for several variables, as solve_conjunction does, and names each parameter of the answer with the set it ranges over.", + static (system, variables) => MathS.SolveSystemWithParameters(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.", @@ -275,7 +287,7 @@ internal static class Catalogue public static IReadOnlyList All { get; } = [ Simplify, Normalize, Expand, Factorize, Differentiate, Integrate, Limit, Substitute, - Solve, SolveSystem, SolveConjunction, Evaluate, EvaluateNumerically, Variables, Alternatives, Latex, Sympy, Hlsl, Glsl, TruthTable, SatisfyingAssignments, Series, AreEqual, + Solve, SolveSystem, SolveConjunction, SolveSystemWithParameters, SolveConjunctionWithParameters, Evaluate, EvaluateNumerically, Variables, Alternatives, Latex, Sympy, Hlsl, Glsl, TruthTable, SatisfyingAssignments, Series, AreEqual, ToBase, FromBase, Determinant, Inverse, Transpose, Rank, ReducedRowEchelonForm, Trace, TensorProduct, PrimeFactorization, Totient, GreatestCommonDivisor, DivisorCount, IsPrime, diff --git a/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver.cs b/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver.cs index 6dc06fce4..1a1fa4cbe 100644 --- a/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver.cs +++ b/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver.cs @@ -123,6 +123,8 @@ internal static Set Solve(Entity equation, Variable x) // An allowance: a set MathS.Settings.Budget replaces SystemSolveBudget, which is // what the exceptions below mean by "raise MathS.Settings.Budget to allow more". var ledger = BudgetLedger.For("SolveSystem", SystemSolveBudget, BudgetRole.Allowance); + // One name stands for one set in the answer, which the scope keeps while it is open. + var parameters = SolutionParameters.Open(out var opened); try { var variables = new Variable[vars.Length]; @@ -192,6 +194,8 @@ internal static Set Solve(Entity equation, Variable x) } finally { + if (opened) + parameters.Close(); ledger.Report(); } } @@ -449,7 +453,7 @@ private static Entity AtASamplePoint(Entity residual, HashSet own) // https://github.com/asc-community/AngouriMath/issues/550. A free parameter says // what the answer is in the same way the trigonometric solvers say it with n_1. if (solutions == MathS.Sets.C) - return new() { new List { Variable.CreateUnique(nameSource, "t") } }; + return new() { new List { SolutionParameters.Mint(nameSource + equations[0], "t", MathS.Sets.C) } }; // An equation left unsolved has roots that were not found, and no rows here would // say it has none: the rows of the other branches would read as every solution. // y^2 - 2, x^2 + (P - Q y) x - 3, with (1 + sqrt(2))^70 = P + Q sqrt(2), declines @@ -482,14 +486,15 @@ private static Entity AtASamplePoint(Entity residual, HashSet own) foreach (var sol in sols) { - if (InSolveSystem(rest.Select(eq => eq.Substitute(var, sol)).ToList(), remainingVars, nameSource, ledger) is not { } rows) + var below = rest.Select(eq => eq.Substitute(var, sol)).ToList(); + if (InSolveSystem(below, remainingVars, nameSource, ledger) is not { } rows) return null; foreach (var j in rows) { replacements.Clear(); for (int varid = 0; varid < remainingVars.Length; varid++) replacements.Add(remainingVars[varid], j[varid]); - j.Add(sol.Substitute(replacements).InnerSimplified); + j.Add(SolutionParameters.Apart(sol, j, below, nameSource).Substitute(replacements).InnerSimplified); result.Add(j); } } diff --git a/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/InvertNode.Classes.cs b/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/InvertNode.Classes.cs index 6034c3d28..e2f559236 100644 --- a/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/InvertNode.Classes.cs +++ b/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/InvertNode.Classes.cs @@ -7,6 +7,7 @@ using AngouriMath.Core.Exceptions; using AngouriMath.Functions.Algebra; +using AngouriMath.Functions.Algebra.AnalyticalSolving; namespace AngouriMath { @@ -127,7 +128,7 @@ partial record Modf if (!inRange) return Enumerable.Empty(); var step = period.IsNegative ? (-Divisor).InnerSimplified : Divisor; - return Dividend.Invert(value + step * Variable.CreateUnique(this + value, "n"), x); + return Dividend.Invert(value + step * SolutionParameters.Mint(this + value, "n", MathS.Sets.Z), x); } } @@ -266,9 +267,9 @@ partial record Sinf { private protected override IEnumerable? InvertNode(Entity value, Entity x) => // sin(x) = value => x = arcsin(value) + 2pi * n - Argument.Invert(MathS.Arcsin(value) + 2 * MathS.pi * Variable.CreateUnique(this + value, "n"), x) is { } first + Argument.Invert(MathS.Arcsin(value) + 2 * MathS.pi * SolutionParameters.Mint(this + value, "n", MathS.Sets.Z), x) is { } first // sin(x) = value => x = pi - arcsin(value) + 2pi * n - && Argument.Invert(MathS.pi - MathS.Arcsin(value) + 2 * MathS.pi * Variable.CreateUnique(this + value, "n"), x) is { } second + && Argument.Invert(MathS.pi - MathS.Arcsin(value) + 2 * MathS.pi * SolutionParameters.Mint(this + value, "n", MathS.Sets.Z), x) is { } second ? first.Concat(second) : null; } @@ -276,9 +277,9 @@ partial record Cosf { private protected override IEnumerable? InvertNode(Entity value, Entity x) => // cos(x) = value => x = arccos(value) + 2pi * n - Argument.Invert(MathS.Arccos(value) + 2 * MathS.pi * Variable.CreateUnique(this + value, "n"), x) is { } first + Argument.Invert(MathS.Arccos(value) + 2 * MathS.pi * SolutionParameters.Mint(this + value, "n", MathS.Sets.Z), x) is { } first // cos(x) = value => x = -arccos(value) + 2pi * n - && Argument.Invert(-MathS.Arccos(value) + 2 * MathS.pi * Variable.CreateUnique(this + value, "n"), x) is { } second + && Argument.Invert(-MathS.Arccos(value) + 2 * MathS.pi * SolutionParameters.Mint(this + value, "n", MathS.Sets.Z), x) is { } second ? first.Concat(second) : null; } @@ -304,14 +305,14 @@ partial record Tanf { private protected override IEnumerable? InvertNode(Entity value, Entity x) => // tan(x) = value => x = arctan(value) + pi * n - Argument.Invert(MathS.Arctan(value) + MathS.pi * Variable.CreateUnique(this + value, "n"), x); + Argument.Invert(MathS.Arctan(value) + MathS.pi * SolutionParameters.Mint(this + value, "n", MathS.Sets.Z), x); } partial record Cotanf { // cotan(x) = value => x = arccotan(value) + pi * n private protected override IEnumerable? InvertNode(Entity value, Entity x) => - Argument.Invert(MathS.Arccotan(value) + MathS.pi * Variable.CreateUnique(this + value, "n"), x); + Argument.Invert(MathS.Arccotan(value) + MathS.pi * SolutionParameters.Mint(this + value, "n", MathS.Sets.Z), x); } partial record Logf @@ -642,7 +643,7 @@ partial record Signumf // x = f(x).InvertNode(value * pr, x) // TODO: we need to make a piecewise for the case when signum(x) = n and |n| != 1 private protected override IEnumerable? InvertNode(Entity value, Entity x) - => Argument.Invert(value * Variable.CreateUnique(Argument + value, "r"), x); + => Argument.Invert(value * SolutionParameters.Mint(Argument + value, "r", MathS.Sets.Interval(0, false, Real.PositiveInfinity, false)), x); } partial record Absf @@ -658,7 +659,7 @@ partial record Absf // https://github.com/asc-community/AngouriMath/issues/812 private protected override IEnumerable? InvertNode(Entity value, Entity x) { - var @var = Variable.CreateUnique(value + Argument, "r"); + var @var = SolutionParameters.Mint(value + Argument, "r", MathS.Sets.R); return Argument.Invert(value * MathS.e.Pow(MathS.i * @var), x) ?.Select(c => c.Provided(@var.In(MathS.Sets.R) & new GreaterOrEqualf(value, 0))); } @@ -673,7 +674,7 @@ partial record Floorf // their own many-to-one inverses. private protected override IEnumerable? InvertNode(Entity value, Entity x) { - var t = Variable.CreateUnique(value + Argument, "t"); + var t = SolutionParameters.Mint(value + Argument, "t", MathS.Sets.Interval(0, true, 1, false)); return Argument.Invert(value + t, x) ?.Select(c => c.Provided( value.In(MathS.Sets.Z) @@ -690,7 +691,7 @@ partial record Ceilf // is subtracted rather than added. private protected override IEnumerable? InvertNode(Entity value, Entity x) { - var t = Variable.CreateUnique(value + Argument, "t"); + var t = SolutionParameters.Mint(value + Argument, "t", MathS.Sets.Interval(0, true, 1, false)); return Argument.Invert(value - t, x) ?.Select(c => c.Provided( value.In(MathS.Sets.Z) @@ -709,7 +710,7 @@ partial record Roundf // out: every point named is a solution, which is the direction that matters. private protected override IEnumerable? InvertNode(Entity value, Entity x) { - var t = Variable.CreateUnique(value + Argument, "t"); + var t = SolutionParameters.Mint(value + Argument, "t", MathS.Sets.Interval(Rational.Create(-1, 2), false, Rational.Create(1, 2), false)); return Argument.Invert(value + t, x) ?.Select(c => c.Provided( value.In(MathS.Sets.Z) diff --git a/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/LambertWSolver.cs b/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/LambertWSolver.cs index cb2c1ac73..e0aae41ef 100644 --- a/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/LambertWSolver.cs +++ b/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/LambertWSolver.cs @@ -72,7 +72,7 @@ internal static class LambertWSolver Entity Root(Entity branch) => MathS.LambertW(branch, a) / gamma + shift; if (MathS.Settings.Codomain.Value != Core.Domain.Real) - return new FiniteSet(Root(Variable.CreateUnique(expr + a, "n"))); + return new FiniteSet(Root(SolutionParameters.Mint(expr + a, "n", MathS.Sets.Z))); var aboveTheBranchPoint = (a + 1 / MathS.e).InnerSimplified; if (aboveTheBranchPoint.Evaled is Real { EDecimal: var distance } && a.Evaled is Real { EDecimal: var at }) diff --git a/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/LinearSystemSolver.cs b/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/LinearSystemSolver.cs index 92f4c1879..234ddc2fd 100644 --- a/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/LinearSystemSolver.cs +++ b/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/LinearSystemSolver.cs @@ -112,7 +112,7 @@ internal static bool TrySolve( for (var column = 0; column < width; column++) if (!isPivot[column]) { - var parameter = Variable.CreateUnique(nameSource, "t"); + var parameter = SolutionParameters.Mint(nameSource, "t", SolutionParameters.Free); values[column] = parameter; nameSource += parameter; } diff --git a/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/NonSquareSystemSolver.cs b/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/NonSquareSystemSolver.cs index ad8b1c12c..eec2138e5 100644 --- a/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/NonSquareSystemSolver.cs +++ b/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/NonSquareSystemSolver.cs @@ -60,7 +60,7 @@ Variable ParameterFor(int index) { if (parameters[index] is { } minted) return minted; - var parameter = Variable.CreateUnique(nameSource, "t"); + var parameter = SolutionParameters.Mint(nameSource, "t", SolutionParameters.Free); nameSource += parameter; return parameters[index] = parameter; } @@ -79,8 +79,9 @@ Variable ParameterFor(int index) var substituted = equation; for (var index = 0; index < variables.Length; index++) substituted = substituted.Substitute(variables[index], (condition is null ? family : bare)[index]); - // An n_1 a family brings from a periodic root stands for every whole number. - var whole = substituted.Vars.Where(name => !own.Contains(name) && name.Name.StartsWith("n_")).Distinct().ToList(); + // An n_1 a family brings from a periodic root stands for every whole number, + // as it was minted to. + var whole = substituted.Vars.Where(name => !own.Contains(name) && SolutionParameters.Current?.SetOf(name) == MathS.Sets.Z).Distinct().ToList(); if (!Vanishes(substituted, whole) && (condition is null || !VanishesWhere(substituted, condition, whole))) return null; } @@ -176,7 +177,7 @@ Variable ParameterFor(int index) return null; foreach (var family in families) { - var value = root; + var value = SolutionParameters.Apart(root, family, substituted, variable); for (var index = 0; index < count - 1; index++) value = value.Substitute(variables[index], family[index]); family.Add(value.InnerSimplified); diff --git a/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/SolutionParameters.cs b/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/SolutionParameters.cs new file mode 100644 index 000000000..b7d28510b --- /dev/null +++ b/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/SolutionParameters.cs @@ -0,0 +1,130 @@ +// +// Copyright (c) 2019-2026 Angouri. +// AngouriMath is licensed under MIT. +// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. +// Website: https://am.angouri.org. +// + +using System; +using static AngouriMath.Entity; +using static AngouriMath.Entity.Set; + +namespace AngouriMath.Functions.Algebra.AnalyticalSolving +{ + /// + /// The parameters a solve brings into its answer -- n_1 for a whole number of periods, + /// t_1 for an unknown nothing constrains, r_1 for an argument -- each minted here + /// with the set it ranges over, so that the set is said where the parameter is made and not + /// read back from its name. + /// #212 + /// + /// + /// + /// While a system is being solved a scope is open, and within it one name stands for one + /// set: a name already minted for another set is passed over for the next free one, so a + /// t from floor(x) = 1, which ranges over [0, 1), and the t of + /// an unknown left free are never both t_1 in one answer. + /// + /// + /// Outside a scope, as in the solve of one equation, minting is + /// and nothing more. A scope is a thread-static pointer + /// read once per parameter minted; the solve it covers is synchronous. + /// + /// + internal sealed class SolutionParameters + { + [ThreadStatic] private static SolutionParameters? current; + + private readonly Dictionary sets = new(); + + private SolutionParameters() { } + + /// + /// The scope open on this thread, opening one where none is; + /// says whether this call opened it and so is the one to it. + /// + internal static SolutionParameters Open(out bool opened) + { + opened = current is null; + return current ??= new SolutionParameters(); + } + + /// The scope open on this thread, or . + internal static SolutionParameters? Current => current; + + /// Closes the scope this thread has open. + internal void Close() => current = null; + + /// + /// The set was minted for in this scope, or + /// where it was not minted here. + /// + internal Set? SetOf(Variable parameter) => sets.TryGetValue(parameter, out var set) ? set : null; + + /// + /// The set an unknown that nothing constrains ranges over: the reals where the solve + /// is over the reals, and the complex numbers otherwise. + /// + internal static Set Free => MathS.Settings.Codomain.Value == Core.Domain.Real ? MathS.Sets.R : MathS.Sets.C; + + /// + /// A parameter named with an index, not used in + /// , ranging over . + /// + internal static Variable Mint(Entity taken, string prefix, Set over) + { + var parameter = Variable.CreateUnique(taken, prefix); + if (current is not { } scope) + return parameter; + while (scope.sets.TryGetValue(parameter, out var other) && other != over) + { + taken += parameter; + parameter = Variable.CreateUnique(taken, prefix); + } + scope.sets[parameter] = over; + return parameter; + } + + /// + /// , the value one unknown was solved for, with each parameter it + /// brings renamed where , the values solved for after it from + /// , has a parameter of the same name that it minted itself. A + /// new name avoids as well as all of those. + /// + /// + /// A parameter of the root that reaches the equations below is the same parameter in the + /// family, as y = x takes the n_1 of x = pi/4 + pi n_1. One that does + /// not reach them is independent of anything the family says, and a parameter the + /// family minted with its name is a second one: sin(x) = 1/2 and + /// sin(y) = 1/2 each mint an n_1, and the row + /// (pi/6 + 2 pi n_1, pi/6 + 2 pi n_1) left out every solution with + /// x != y. + /// + internal static Entity Apart(Entity root, IReadOnlyList family, IEnumerable below, Entity taken) + { + HashSet? fresh = null; + foreach (var parameter in root.Vars) + { + if (fresh is null) + { + var shared = new HashSet(below.SelectMany(equation => equation.Vars)); + fresh = new HashSet(family.SelectMany(value => value.Vars).Where(name => !shared.Contains(name))); + if (fresh.Count == 0) + return root; + } + if (!fresh.Contains(parameter)) + continue; + taken += root; + foreach (var value in family) + taken += value; + foreach (var equation in below) + taken += equation; + var renamed = Mint(taken, parameter.SplitIndex() is var (prefix, _) ? prefix : parameter.Name, + current?.SetOf(parameter) ?? Free); + root = root.Substitute(parameter, renamed); + fresh.Add(renamed); + } + return root; + } + } +} diff --git a/Sources/MCP/AngouriMath.Mcp/Tools.cs b/Sources/MCP/AngouriMath.Mcp/Tools.cs index 903ac1b95..b376ef79a 100644 --- a/Sources/MCP/AngouriMath.Mcp/Tools.cs +++ b/Sources/MCP/AngouriMath.Mcp/Tools.cs @@ -93,7 +93,8 @@ 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, Catalogue.SolveConjunction], + ["am_solve_system"] = [Catalogue.SolveSystem, Catalogue.SolveConjunction, + Catalogue.SolveSystemWithParameters, Catalogue.SolveConjunctionWithParameters], ["am_represent"] = [Catalogue.ToBase, Catalogue.FromBase], ["am_matrix"] = [Catalogue.Determinant, Catalogue.Inverse, Catalogue.Transpose, Catalogue.Rank, Catalogue.ReducedRowEchelonForm, Catalogue.Trace, Catalogue.TensorProduct], @@ -329,7 +330,8 @@ private static JsonObject[] All() => Tool("am_solve_system", "Solve a system of simultaneous equations for several variables. Returns one row " + - "per solution. Give the system either as a list of equations or as one statement " + + "per solution, and each parameter the rows are written in with the set it ranges " + + "over, e.g. n_1 in ZZ, t_1 in CC. 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 @@ -1433,9 +1435,10 @@ private static JsonObject SolveSystem(JsonObject args) } return FromOutcome(Guard.Run(() => system is not null - ? Catalogue.SolveConjunction.Ask(system, [.. variables.Select(Var)]) - : Catalogue.SolveSystem.Ask(parsed, [.. variables.Select(Var)])), matrix => + ? Catalogue.SolveConjunctionWithParameters.Ask(system, [.. variables.Select(Var)]) + : Catalogue.SolveSystemWithParameters.Ask(parsed, [.. variables.Select(Var)])), solved => { + var matrix = solved?.Rows; var order = new JsonArray(); foreach (var v in variables) order.Add(v); @@ -1447,6 +1450,17 @@ private static JsonObject SolveSystem(JsonObject args) ["solution_count"] = matrix?.RowCount, }; + // A row is a family of solutions, one for each value of its parameters, and a caller + // can only read it as one if it is told what the parameters are and what values they + // take: n_1 is a whole number, t_1 any number. + if (solved is not null) + { + var parameters = new JsonArray(); + foreach (var (parameter, domain) in solved.Parameters) + parameters.Add(new JsonObject { ["parameter"] = parameter.Stringize(), ["set"] = domain.Stringize() }); + response["parameters"] = parameters; + } + if (matrix is null) response["note"] = "No solution was returned. A nonlinear system can come " + "back with nothing even when it has a solution, so absence here is not " + diff --git a/Sources/MCP/README.md b/Sources/MCP/README.md index b3eb960d7..efca06ca3 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`, 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_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. Each parameter of the rows comes back in `parameters` with the set it ranges over, `n_1` in `ZZ`, `t_1` in `CC` | | `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 d2a0e276a..af6866111 100644 --- a/Sources/Terminal/AngouriMath.Terminal.Lib/OneShot.fs +++ b/Sources/Terminal/AngouriMath.Terminal.Lib/OneShot.fs @@ -68,6 +68,7 @@ let ownCommands = /// let notOffered = set [ "expand"; "factorize"; "integrate"; "limit"; "solve_system"; "solve_conjunction"; "evaluate_numerically"; "variables" + "solve_system_with_parameters"; "solve_conjunction_with_parameters" "alternatives"; "sympy"; "hlsl"; "glsl"; "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 b5d6c35bb..72086c9c7 100644 --- a/Sources/Tests/McpUnitTests/ToolsTest.cs +++ b/Sources/Tests/McpUnitTests/ToolsTest.cs @@ -232,6 +232,23 @@ public void ASystemWrittenAsOneConjunctionIsSolved() Assert.Equal("2 1", string.Join(" ", answer.Field("solutions").Split('\n')[1].Split(' ', StringSplitOptions.RemoveEmptyEntries))); } + // https://github.com/asc-community/AngouriMath/issues/212 + [Fact] + public void EachParameterOfASystemsAnswerComesWithItsSet() + { + var answer = Mcp.Call("am_solve_system", """{"equations":["sin(x) = 1/2"],"variables":["x","y"]}"""); + var parameters = answer["parameters"]!.AsArray(); + Assert.Equal(2, parameters.Count); + Assert.Equal("n_1", parameters[0]!["parameter"]!.GetValue()); + Assert.Equal("ZZ", parameters[0]!["set"]!.GetValue()); + Assert.Equal("t_1", parameters[1]!["parameter"]!.GetValue()); + Assert.Equal("CC", parameters[1]!["set"]!.GetValue()); + } + + [Fact] + public void ASystemWithoutParametersListsNone() => + Assert.Empty(Mcp.Call("am_solve_system", """{"statement":"x + y = 3 and x - y = 1","variables":["x","y"]}""")["parameters"]!.AsArray()); + [Fact] public void AConjunctThatIsNotAnEquationIsNamedAndDeclined() { diff --git a/Sources/Tests/UnitTests/Algebra/SolveTest/SystemParametersTest.cs b/Sources/Tests/UnitTests/Algebra/SolveTest/SystemParametersTest.cs new file mode 100644 index 000000000..22d460108 --- /dev/null +++ b/Sources/Tests/UnitTests/Algebra/SolveTest/SystemParametersTest.cs @@ -0,0 +1,231 @@ +// +// Copyright (c) 2019-2026 Angouri. +// AngouriMath is licensed under MIT. +// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. +// Website: https://am.angouri.org. +// + +using System.Collections.Generic; +using System.Linq; +using AngouriMath; +using AngouriMath.Core; +using AngouriMath.Extensions; +using Xunit; +using static AngouriMath.Entity; +using static AngouriMath.Entity.Number; + +namespace AngouriMath.Tests.Algebra +{ + /// + /// : the rows of a system's answer and the + /// parameters they are written in, each with the set it ranges over. + /// #212 + /// + /// + /// Every answer here is checked by giving each parameter values from its set -- whole ones for + /// a parameter over ZZ, which is all an n_1 promises -- and putting each row back + /// into each equation. A set that is wider than the one the family holds over fails that. + /// + [Trait("Area", "Algebra")] + public sealed class SystemParametersTest + { + private static ParametrizedSolutions Solved(string[] equations, params string[] unknowns) + { + var solved = MathS.Equations(equations.Select(equation => equation.ToEntity())) + .SolveWithParameters(unknowns.Select(unknown => (Variable)unknown).ToArray()); + Assert.NotNull(solved); + Assert.Equal(MathS.Equations(equations.Select(equation => equation.ToEntity())) + .Solve(unknowns.Select(unknown => (Variable)unknown).ToArray()), solved!.Rows); + // Solved again, the answer is equal, the list compared by its elements. + Assert.Equal(solved, MathS.Equations(equations.Select(equation => equation.ToEntity())) + .SolveWithParameters(unknowns.Select(unknown => (Variable)unknown).ToArray())); + Holds(solved, equations, unknowns); + return solved; + } + + /// + /// Two values of each parameter from its set, and each row put back into each equation + /// at each pair of choices. + /// + private static void Holds(ParametrizedSolutions solved, string[] equations, string[] unknowns) + { + foreach (var choice in new[] { 0, 1 }) + { + var values = solved.Parameters.Select((pair, index) => (pair.Parameter, Value: SampleOf(pair.Domain, index + choice))).ToList(); + for (var row = 0; row < solved.Rows.RowCount; row++) + { + var point = new Dictionary(); + for (var column = 0; column < unknowns.Length; column++) + { + var entry = solved.Rows[row, column]; + foreach (var (parameter, value) in values) + entry = entry.Substitute(parameter, value); + if (entry is Providedf(var bare, var condition)) + { + Assert.Equal(Boolean.True, condition.Evaled); + entry = bare; + } + point[unknowns[column]] = entry; + } + foreach (var equation in equations) + { + // A symbol of the system's own, as k in 2x - 4y = k, at one value. + var substituted = equation.ToEntity().Substitute(point); + foreach (var symbol in substituted.Vars.ToList()) + substituted = substituted.Substitute(symbol, Rational.Create(3, 7)); + var residual = substituted.EvalNumerical(); + Assert.True(residual.Abs() < 1e-9, $"{equation} at row {row} is {residual}"); + } + } + } + } + + private static Entity SampleOf(Set domain, int index) + { + if (domain == MathS.Sets.Z) + return new[] { 2, -3, 5 }[index % 3]; + if (domain is Set.Interval(var left, _, var right, _)) + return Rational.Create(1 + index % 2, 3) * (right - left) + left; + Assert.True(domain == MathS.Sets.R || domain == MathS.Sets.C, $"no sample of {domain}"); + return new[] { Rational.Create(7, 5), Rational.Create(-13, 10), Rational.Create(9, 4) }[index % 3]; + } + + private static (Variable, Set) In(string parameter, Set domain) => (parameter, domain); + + /// The issue's own example, with its one parameter over every number. + [Fact] + public void TheExampleTheIssueNames() + { + var solved = Solved(new[] { "2x - 4y - 12" }, "x", "y"); + Assert.Equal(MathS.Matrix(new Entity[,] { { "6 + 2 * t_1", "t_1" } }), solved.Rows); + Assert.Equal(new[] { In("t_1", MathS.Sets.C) }, solved.Parameters); + } + + /// + /// A whole-number parameter beside a free one: n_1 is said to be in ZZ, + /// which nothing in the rows themselves says. + /// + [Fact] + public void APeriodicFamilyNamesItsWholeNumberParameter() + { + var solved = Solved(new[] { "sin(x) - 1/2" }, "x", "y"); + Assert.Equal(MathS.Matrix(new Entity[,] + { + { "pi / 6 + 2 * pi * n_1", "t_1" }, + { "pi - pi / 6 + 2 * pi * n_1", "t_1" }, + }), solved.Rows); + Assert.Equal(new[] { In("n_1", MathS.Sets.Z), In("t_1", MathS.Sets.C) }, solved.Parameters); + } + + [Fact] + public void ALinearFreedomAndAPeriodTogether() + { + var solved = Solved(new[] { "x + y - 1", "sin(z)" }, "x", "y", "z"); + Assert.Equal(new[] { In("t_1", MathS.Sets.C), In("n_1", MathS.Sets.Z) }, solved.Parameters); + } + + /// A parameter shared by every column, since each unknown is the one before. + [Fact] + public void APeriodReachingAnotherEquationIsOneParameter() + { + var solved = Solved(new[] { "tan(x) - 1", "y - x" }, "x", "y"); + Assert.Equal(MathS.Matrix(new Entity[,] { { "pi / 4 + pi * n_1", "pi / 4 + pi * n_1" } }), solved.Rows); + Assert.Equal(new[] { In("n_1", MathS.Sets.Z) }, solved.Parameters); + } + + [Fact] + public void AnAnswerWithoutParametersHasNone() + { + var solved = Solved(new[] { "x + y - 3", "x - y - 1" }, "x", "y"); + Assert.Empty(solved.Parameters); + } + + [Fact] + public void ASymbolOfTheSystemIsNotAParameter() + { + var solved = Solved(new[] { "2x - 4y - k" }, "x", "y"); + Assert.Equal(new[] { In("t_1", MathS.Sets.C) }, solved.Parameters); + } + + /// A system with no solutions is , as Solve answers it. + [Fact] + public void ASystemWithoutSolutionsIsNull() + => Assert.Null(MathS.Equations("x + y - 1", "x + y - 2").SolveWithParameters("x", "y")); + + [Fact] + public void ADeclinedSystemIsNull() + => Assert.Null(MathS.Equations("x * e^x - 1").SolveWithParameters("x", "y")); + + /// + /// Two equations that each bring a parameter of their own, and do not reach each other, + /// have two parameters. As one name, (pi/6 + 2 pi n_1, pi/6 + 2 pi n_1), the + /// answer said x - y is a whole number of periods and left out + /// (pi/6, 13 pi/6). + /// + [Fact] + public void IndependentPeriodsAreTwoParameters() + { + var solved = Solved(new[] { "sin(x) - 1/2", "sin(y) - 1/2" }, "x", "y"); + Assert.Equal(4, solved.Rows.RowCount); + Assert.Equal((Entity)"pi / 6 + 2 * pi * n_1", solved.Rows[0, 0]); + Assert.Equal((Entity)"pi / 6 + 2 * pi * n_2", solved.Rows[0, 1]); + Assert.Equal(new[] { In("n_1", MathS.Sets.Z), In("n_2", MathS.Sets.Z) }, solved.Parameters); + } + + [Fact] + public void ThreeIndependentPeriodsAreThreeParameters() + { + var solved = Solved(new[] { "tan(x) - 1", "tan(y) - 1", "tan(z) - 1" }, "x", "y", "z"); + Assert.Equal(MathS.Matrix(new Entity[,] { { "pi / 4 + pi * n_1", "pi / 4 + pi * n_2", "pi / 4 + pi * n_3" } }), solved.Rows); + } + + /// + /// The parameter of floor(x) = 1 ranges over [0, 1), said where it is made, + /// and two floors have one each. + /// + [Fact] + public void AFloorsParameterRangesOverTheUnitInterval() + { + var solved = Solved(new[] { "floor(x) - 1", "floor(y) - 2" }, "x", "y"); + var unit = MathS.Sets.Interval(0, true, 1, false); + Assert.Equal(new[] { In("t_1", unit), In("t_2", unit) }, solved.Parameters); + } + + [Fact] + public void TheArgumentOfAGivenModulusIsReal() + { + var solved = Solved(new[] { "abs(x) - 1", "abs(y) - 2" }, "x", "y"); + Assert.Equal(new[] { In("r_1", MathS.Sets.R), In("r_2", MathS.Sets.R) }, solved.Parameters); + } + + /// + /// Rows are separate families: t_1 is y in the rows where sin(x) is + /// zero and x where cos(y) is, over every number in both. + /// + [Fact] + public void ANameInTwoRowsHasOneSet() + { + var solved = Solved(new[] { "sin(x) * cos(y)" }, "x", "y"); + Assert.Equal(new[] { In("n_1", MathS.Sets.Z), In("t_1", MathS.Sets.C) }, solved.Parameters); + } + + [Fact] + public void OverTheRealsAFreeUnknownIsReal() + { + using var _ = MathS.Settings.Codomain.Set(Domain.Real); + var solved = MathS.Equations("2x - 4y - 12").SolveWithParameters("x", "y"); + Assert.NotNull(solved); + Assert.Equal(new[] { In("t_1", MathS.Sets.R) }, solved!.Parameters); + } + + [Fact] + public void AConjunctionIsSolvedWithItsParameters() + { + var solved = MathS.SolveSystemWithParameters("sin(x) = 1/2 and y - x = 0", "x", "y"); + Assert.NotNull(solved); + Assert.Equal(MathS.SolveSystem("sin(x) = 1/2 and y - x = 0", "x", "y"), solved!.Rows); + Assert.Equal(new[] { In("n_1", MathS.Sets.Z) }, solved.Parameters); + Assert.Null(MathS.SolveSystemWithParameters("x + y = 3 and x > 0", "x", "y")); + } + } +} diff --git a/Sources/Tests/UnitTests/Common/PublicApi.txt b/Sources/Tests/UnitTests/Common/PublicApi.txt index 69721094e..2adde5c9f 100644 --- a/Sources/Tests/UnitTests/Common/PublicApi.txt +++ b/Sources/Tests/UnitTests/Common/PublicApi.txt @@ -191,6 +191,7 @@ AngouriMath.Core.Domain.Real : AngouriMath.Core.Domain AngouriMath.Core.Domain.value__ : System.Int32 AngouriMath.Core.EquationSystem.Latexize() : System.String AngouriMath.Core.EquationSystem.Solve(AngouriMath.Entity+Variable[]) : AngouriMath.Entity+Matrix +AngouriMath.Core.EquationSystem.SolveWithParameters(AngouriMath.Entity+Variable[]) : AngouriMath.Core.ParametrizedSolutions AngouriMath.Core.EquationSystem.ToString() : System.String AngouriMath.Core.EquationSystem.ctor(AngouriMath.Entity[]) AngouriMath.Core.EquationSystem.ctor(System.Collections.Generic.IEnumerable) @@ -226,6 +227,17 @@ AngouriMath.Core.MatrixBuilder.Add(System.Collections.Generic.List>, System.Int32) AngouriMath.Core.MatrixBuilder.ctor(System.Int32) +AngouriMath.Core.ParametrizedSolutions.$() : AngouriMath.Core.ParametrizedSolutions +AngouriMath.Core.ParametrizedSolutions.Deconstruct(AngouriMath.Entity+Matrix&, System.Collections.Generic.IReadOnlyList>&) : System.Void +AngouriMath.Core.ParametrizedSolutions.Equals(AngouriMath.Core.ParametrizedSolutions) : System.Boolean +AngouriMath.Core.ParametrizedSolutions.Equals(System.Object) : System.Boolean +AngouriMath.Core.ParametrizedSolutions.GetHashCode() : System.Int32 +AngouriMath.Core.ParametrizedSolutions.Parameters { } : System.Collections.Generic.IReadOnlyList> +AngouriMath.Core.ParametrizedSolutions.Rows { } : AngouriMath.Entity+Matrix +AngouriMath.Core.ParametrizedSolutions.ToString() : System.String +AngouriMath.Core.ParametrizedSolutions.ctor(AngouriMath.Entity+Matrix, System.Collections.Generic.IReadOnlyList>) +AngouriMath.Core.ParametrizedSolutions.op_Equality(AngouriMath.Core.ParametrizedSolutions, AngouriMath.Core.ParametrizedSolutions) : System.Boolean +AngouriMath.Core.ParametrizedSolutions.op_Inequality(AngouriMath.Core.ParametrizedSolutions, AngouriMath.Core.ParametrizedSolutions) : System.Boolean AngouriMath.Core.ReasonOfFailureWhileParsing+InternalError.$() : AngouriMath.Core.ReasonOfFailureWhileParsing+InternalError AngouriMath.Core.ReasonOfFailureWhileParsing+InternalError.Deconstruct(System.String&) : System.Void AngouriMath.Core.ReasonOfFailureWhileParsing+InternalError.Details { } : System.String @@ -3861,6 +3873,7 @@ AngouriMath.MathS.SolveBooleanTable(AngouriMath.Entity, AngouriMath.Entity+Varia 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.SolveSystemWithParameters(AngouriMath.Entity, AngouriMath.Entity+Variable[]) : AngouriMath.Core.ParametrizedSolutions 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 @@ -3940,6 +3953,7 @@ class AngouriMath.Core.FastExpression class AngouriMath.Core.FiniteSetBuilder class AngouriMath.Core.GeneratedSource class AngouriMath.Core.MatrixBuilder +class AngouriMath.Core.ParametrizedSolutions class AngouriMath.Core.ReasonOfFailureWhileParsing class AngouriMath.Core.ReasonOfFailureWhileParsing+InternalError class AngouriMath.Core.ReasonOfFailureWhileParsing+MissingOperator diff --git a/Sources/Tests/UnitTests/Core/Operations/CatalogueTest.cs b/Sources/Tests/UnitTests/Core/Operations/CatalogueTest.cs index 338ec062a..becd3dfdc 100644 --- a/Sources/Tests/UnitTests/Core/Operations/CatalogueTest.cs +++ b/Sources/Tests/UnitTests/Core/Operations/CatalogueTest.cs @@ -214,6 +214,11 @@ public void EachEntryAnswersAsTheMethodItNames() 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])); + Entity[] periodic = ["sin(x) - 1/2"]; + Assert.Equal(MathS.Equations(periodic).SolveWithParameters(x, y)!.Parameters, Catalogue.SolveSystemWithParameters.Ask(periodic, [x, y])!.Parameters); + Assert.Equal(MathS.Equations(periodic).Solve(x, y), Catalogue.SolveSystemWithParameters.Ask(periodic, [x, y])!.Rows); + Assert.Equal(MathS.SolveSystemWithParameters("sin(x) = 1/2", x, y)!.Parameters, Catalogue.SolveConjunctionWithParameters.Ask("sin(x) = 1/2", [x, y])!.Parameters); + Assert.Null(Catalogue.SolveConjunctionWithParameters.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"));