Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Sources/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1055,5 +1055,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
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,40 @@ internal static Set UnsolvedWhereIndependenceIsDenied(Set roots, Entity conditio
/// </remarks>
[ConstantField] private static readonly EDecimal RelativeResidualTolerance = EDecimal.FromString("0.01");

/// <summary>
/// <paramref name="answer"/> without the real points at which <paramref name="expr"/>, as
/// written, has no value because a denominator in it is zero; <paramref name="answer"/> as
/// it is where a denominator's zeros are not found as finitely many numbers.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
private static Set? WithoutPoles(Set? answer, Entity expr, Variable x)
{
if (answer is null)
return null;
var poles = new List<Entity>();
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;
}

/// <summary>
/// Whether a root demonstrably fails the equation. Anything that cannot be
/// evaluated to a number -- a root still carrying a parameter, say
Expand Down Expand Up @@ -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),

Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// 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: <c>(4x - x^3)/x &gt; 0</c> was
/// <c>(-2; 2)</c>, with 0 in it, and <c>x/x &gt; 0</c> was <c>RR</c>. Found by a cross-check of
/// rational inequalities against their exact values; no issue was filed.
/// </summary>
[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);
}
}
}
Loading