From 5fbf5d7a446e7c8649d06abbf94782099720790c Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Sun, 1 Nov 2026 19:40:36 +0000 Subject: [PATCH] An inequality has no solution where it has no value The inequality solver reads a quotient after a factor its numerator and denominator share has cancelled, so its answer had the points where that factor is zero, at which the quotient is 0/0 and has no value: (4x - x^3)/x > 0 was (-2; 2), with 0 in it, and x/x > 0 was RR. A pole that does not cancel was outside the answer already, a quotient being solved as the product of its numerator and denominator. The real zeros of every denominator in the expression as written are now taken out of the answer, for each of the four inequalities. Where a denominator's zeros are not found as finitely many numbers the answer is left as it was. Found by a cross-check of rational inequalities against their exact values at rational points, on which this leaves no point in an answer where the inequality fails. Co-Authored-By: Claude Opus 5.5 (1M context) --- BREAKING-CHANGES.md | 11 ++++ Sources/.editorconfig | 3 ++ .../Solvers/EquationSolver/SolveStatement.cs | 50 ++++++++++++++++--- ...alityHasNoSolutionWhereItHasNoValueTest.cs | 43 ++++++++++++++++ 4 files changed, 99 insertions(+), 8 deletions(-) create mode 100644 Sources/Tests/UnitTests/Algebra/SolveTest/AnInequalityHasNoSolutionWhereItHasNoValueTest.cs diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 1fed46ffa..2e73cc468 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -383,6 +383,17 @@ except where shown. | `([[1, 2], [2, 4]] ^ (-1)).Evaled` | throws `InvalidDeterminantException` | `[[1, 2], [2, 4]] ^ (-1)` | | `([[1, 2], [2, 4]] ^ (-1)).Simplify()` | throws `InvalidDeterminantException` | `1 / [[1, 2], [2, 4]]` | +### An inequality has no solution where its expression has no value + +**Silent: the answer to an inequality leaves out the real points where a denominator of the expression as written is +zero.** The solver reads a quotient after a factor shared by its numerator and denominator has cancelled, so its answer +had the points where that factor vanishes, at which the quotient is `0/0`. + +| Input | Was (2.6.0) | Now | +|---|---|---| +| `"(4x - x^3)/x > 0".ToEntity().Solve("x")` | `(-2; 2)` | `(-2; 2) \ { 0 }` | +| `"x/x > 0".ToEntity().Solve("x")` | `RR` | `RR \ { 0 }` | + ### A 1x1 matrix has a rank and row echelon forms **Not silent: what threw now answers.** For a 1x1 matrix, `Rank`, `RowEchelonForm` and `ReducedRowEchelonForm` threw diff --git a/Sources/.editorconfig b/Sources/.editorconfig index 6ef48f91f..220fa278c 100644 --- a/Sources/.editorconfig +++ b/Sources/.editorconfig @@ -1052,5 +1052,8 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed [Tests/UnitTests/Common/RefuseNonRealCompilationTest.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/AnInequalityHasNoSolutionWhereItHasNoValueTest.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/Common/BranchCutCompilationTest.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/Functions/Continuous/Solvers/EquationSolver/SolveStatement.cs b/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/SolveStatement.cs index a1fc46f63..d8a13cc30 100644 --- a/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/SolveStatement.cs +++ b/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/SolveStatement.cs @@ -121,6 +121,40 @@ internal static Set UnsolvedWhereIndependenceIsDenied(Set roots, Entity conditio /// [ConstantField] private static readonly EDecimal RelativeResidualTolerance = EDecimal.FromString("0.01"); + /// + /// without the real points at which , as + /// written, has no value because a denominator in it is zero; as + /// it is where a denominator's zeros are not found as finitely many numbers. + /// + /// + /// The inequality solver reads the expression after a factor common to a numerator and a + /// denominator has cancelled, so its answer had the points where that factor is zero, at + /// which the quotient is 0/0 and has no value: (4x - x^3)/x > 0 was (-2; 2), with 0 in it, + /// and x/x > 0 was RR. A pole that has not cancelled is outside the answer already, since a + /// quotient is solved as the product of its numerator and denominator. + /// + private static Set? WithoutPoles(Set? answer, Entity expr, Variable x) + { + if (answer is null) + return null; + var poles = new List(); + foreach (var node in expr.Nodes) + { + var denominator = node switch + { + Divf(_, var divisor) => divisor, + Powf(var @base, Integer { EInteger.Sign: < 0 }) => @base, + _ => null, + }; + if (denominator is null || !denominator.ContainsNode(x)) + continue; + if (AnalyticalEquationSolver.Solve(denominator, x) is not FiniteSet zeros || zeros.Any(zero => zero.Vars.Any())) + return answer; + poles.AddRange(zeros.Where(zero => zero.Evaled is Number.Real)); + } + return poles.Count == 0 ? answer : (Set)MathS.SetSubtraction(answer, new FiniteSet(poles)).InnerSimplified; + } + /// /// Whether a root demonstrably fails the equation. Anything that cannot be /// evaluated to a number -- a root still carrying a parameter, say @@ -411,17 +445,17 @@ private static Entity Equivalent(Entity left, Entity right) Impliesf(var left, var right) => Implication(left, right, x), Notf(var operand) => Negation(expr, operand, x), - Greaterf(var left, var right) => - AnalyticalInequalitySolver.Solve(Minus(left, right), x), + Greaterf(var left, var right) => + WithoutPoles(AnalyticalInequalitySolver.Solve(Minus(left, right), x), Minus(left, right), x), LessOrEqualf(var left, var right) => - AnalyticalInequalitySolver.Solve(Minus(right, left), x) - ?.Unite(AnalyticalEquationSolver.Solve(Minus(left, right), x)), + WithoutPoles(AnalyticalInequalitySolver.Solve(Minus(right, left), x) + ?.Unite(AnalyticalEquationSolver.Solve(Minus(left, right), x)), Minus(left, right), x), GreaterOrEqualf(var left, var right) => - AnalyticalInequalitySolver.Solve(Minus(left, right), x) is { } above - ? (Set)MathS.Union(above, AnalyticalEquationSolver.Solve(Minus(left, right), x)) : null, + WithoutPoles(AnalyticalInequalitySolver.Solve(Minus(left, right), x) is { } above + ? (Set)MathS.Union(above, AnalyticalEquationSolver.Solve(Minus(left, right), x)) : null, Minus(left, right), x), - Lessf(var left, var right) => - AnalyticalInequalitySolver.Solve(Minus(right, left), x), + Lessf(var left, var right) => + WithoutPoles(AnalyticalInequalitySolver.Solve(Minus(right, left), x), Minus(left, right), x), Variable when expr == x => new FiniteSet(true), diff --git a/Sources/Tests/UnitTests/Algebra/SolveTest/AnInequalityHasNoSolutionWhereItHasNoValueTest.cs b/Sources/Tests/UnitTests/Algebra/SolveTest/AnInequalityHasNoSolutionWhereItHasNoValueTest.cs new file mode 100644 index 000000000..d0e6fc5a2 --- /dev/null +++ b/Sources/Tests/UnitTests/Algebra/SolveTest/AnInequalityHasNoSolutionWhereItHasNoValueTest.cs @@ -0,0 +1,43 @@ +// +// 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 AngouriMath.Extensions; +using Xunit; +using static AngouriMath.Entity; + +namespace AngouriMath.Tests.Algebra +{ + /// + /// An inequality holds only where its expression has a value. The solver reads a quotient after + /// a factor its numerator and denominator share has cancelled, so its answer had the points where + /// that factor is zero, at which the quotient is 0/0: (4x - x^3)/x > 0 was + /// (-2; 2), with 0 in it, and x/x > 0 was RR. Found by a cross-check of + /// rational inequalities against their exact values; no issue was filed. + /// + [Trait("Area", "Algebra")] + public sealed class AnInequalityHasNoSolutionWhereItHasNoValueTest + { + [Theory] + [InlineData("(4x - x^3)/x > 0", "1", true)] + [InlineData("(4x - x^3)/x > 0", "0", false)] + [InlineData("x/x > 0", "5", true)] + [InlineData("x/x > 0", "0", false)] + [InlineData("(-x + 2x^2 - x^3)/x <= 0", "-3", true)] + [InlineData("(-x + 2x^2 - x^3)/x <= 0", "0", false)] + [InlineData("(x^2 - 1)/(x - 1) >= 0", "-1", true)] + [InlineData("(x^2 - 1)/(x - 1) >= 0", "1", false)] + [InlineData("(x^2 - 1)/(x^2 - 1) < 2", "1", false)] + [InlineData("(x^2 - 1)/(x^2 - 1) < 2", "-1", false)] + [InlineData("(x^2 - 1)/(x^2 - 1) < 2", "0", true)] + public void APointWithoutAValueIsNotASolution(string inequality, string at, bool solves) + { + var answer = (Set)inequality.ToEntity().Solve("x"); + Assert.True(answer.TryContains(at.ToEntity(), out var contains), $"{at} undecided in {answer}"); + Assert.Equal(solves, contains); + } + } +}