diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 1fed46ffa..ce3ac9c1c 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -429,6 +429,17 @@ real radical form still takes it ([#2143](https://github.com/asc-community/Angou | `"sin(pi/18)".ToEntity().Simplify()` | `sqrt((1 - 1/4 * ((4 + 4 * sqrt(-3)) ^ (1/3) + (4 - 4 * sqrt(-3)) ^ (1/3))) / 2)` | `sin(pi / 18)` | | `"sin(pi/5)".ToEntity().Simplify()` | `1/4 * sqrt(10 - 2 * sqrt(5))` | `1/4 * sqrt(10 - 2 * sqrt(5))` | +### A quotient is zero where its numerator is and its denominator is not + +**Silent: `N/D = 0` is solved as `N = 0` less the zeros of `D`, where it was left to the spellings.** One of those took +`t = x^2` into half-integer powers of `t` and handed it to Newton's method, which answered near-copies of a root and left +out others. A non-strict inequality takes the roots of its equation, so its answer was wrong with it. + +| Input | Was (2.6.0) | Now | +|---|---|---| +| `"(18x^2 - 3x^3 - 4x^4 + x^5)/(9x^2 - 6x^4 + x^6) = 0".ToEntity().Solve("x")` | `{ 3 }` | `{ -2, 3 }` | +| `"(108x^2 - 18x^3 - 24x^4 + 6x^5)/(27x^2 - 18x^4 + 3x^6) >= 0".ToEntity().Solve("x")` | `{ -sqrt(9.000000…), …, -3, … } \/ (-2; -sqrt(3)) \/ …`, with `-3`, where the quotient is negative, and without `-2` | `[-2; -sqrt(3)) \/ (-sqrt(3); 0) \/ (0; sqrt(3)) \/ (sqrt(3); +oo)` | + ### A step function at a jump takes the side its argument arrives from **Silent: a limit of `floor`, `ceil` or `sgn` whose argument arrives on a jump is answered, where it was left diff --git a/Sources/.editorconfig b/Sources/.editorconfig index 6ef48f91f..edc3d32b1 100644 --- a/Sources/.editorconfig +++ b/Sources/.editorconfig @@ -63,6 +63,9 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed [Tests/UnitTests/Convenience/RoundIsExactTest.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/AQuotientIsZeroWhereItsNumeratorIsTest.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/Core/FactorialCacheIsThreadSafeTest.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/AnalyticalEquationSolver.cs b/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/AnalyticalEquationSolver.cs index 8dcbc9707..2ceb20437 100644 --- a/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/AnalyticalEquationSolver.cs +++ b/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/AnalyticalEquationSolver.cs @@ -224,6 +224,19 @@ when @base.ContainsNode(x) && !power.ContainsNode(x) return TreeAnalyzer.Assuming(predicate, () => Solve(expression, x, compensateSolving)).Filter(predicate, x); case Piecewise p: return EquationSolver.SolvePiecewise(p, x, (e, x) => Solve(e, x, compensateSolving)); + // A quotient is zero exactly where its numerator is and its denominator is not + // zero: (x^2 - x)/(x^2 + x) = 0 is x = 1, x = 0 being a zero of both. Left to the + // spellings below, (18x^2 - 3x^3 - 4x^4 + x^5)/(9x^2 - 6x^4 + x^6) = 0 was taken + // by a substitution t = x^2 into powers t^(3/2) and t^(5/2) and given to Newton's + // method, which answered three near-copies of 3 beside it and left out -2. Only + // where the numerator's roots are finitely many numbers, each of which can be put + // into the denominator; anything else is left to the routes below. + case Divf(var numerator, var denominator) + when numerator.ContainsNode(x) && denominator.ContainsNode(x) + && Solve(numerator, x, compensateSolving) is FiniteSet zeros + && zeros.All(root => !root.Vars.Any()): + return zeros.Where(root => denominator.Substitute(x, root).Evaled is not Complex value + || value.IsFinite && !(value is Rational rational ? rational.IsZero : IsZero(value))).ToSet(); // A product is zero exactly where one of its factors is. Without this the // factors are expanded back into a polynomial and the equation is answered // by the general formula for whatever degree that turns out to be, so diff --git a/Sources/Tests/UnitTests/Algebra/SolveTest/AQuotientIsZeroWhereItsNumeratorIsTest.cs b/Sources/Tests/UnitTests/Algebra/SolveTest/AQuotientIsZeroWhereItsNumeratorIsTest.cs new file mode 100644 index 000000000..e6b024729 --- /dev/null +++ b/Sources/Tests/UnitTests/Algebra/SolveTest/AQuotientIsZeroWhereItsNumeratorIsTest.cs @@ -0,0 +1,46 @@ +// +// 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; +using static AngouriMath.Entity.Set; + +namespace AngouriMath.Tests.Algebra +{ + /// + /// A quotient is zero exactly where its numerator is and its denominator is not. Left to the + /// spellings, (18x^2 - 3x^3 - 4x^4 + x^5)/(9x^2 - 6x^4 + x^6) = 0 was taken by a + /// substitution t = x^2 into half-integer powers of t and given to Newton's method, + /// which answered three near-copies of 3 beside it and left out -2; and the inequality with it + /// for its = 0 part lost -2 as well. Found by a cross-check of rational inequalities + /// against their exact values; no issue was filed. + /// + [Trait("Area", "Algebra")] + public sealed class AQuotientIsZeroWhereItsNumeratorIsTest + { + [Theory] + [InlineData("(18x^2 - 3x^3 - 4x^4 + x^5)/(9x^2 - 6x^4 + x^6) = 0", "{ -2, 3 }")] + [InlineData("(108x^2 - 18x^3 - 24x^4 + 6x^5)/(27x^2 - 18x^4 + 3x^6) = 0", "{ -2, 3 }")] + // Zeros of the numerator that the denominator shares are not roots: 0/0 has no value. + [InlineData("(x^2 - 1)/(x - 1) = 0", "{ -1 }")] + [InlineData("(x^4 - 9x^2)/(x^6 - 3x^4) = 0", "{ 3, -3 }")] + public void TheRootsAreTheNumeratorsTheDenominatorDoesNotShare(string equation, string expected) + => Assert.Equal(expected.ToEntity(), equation.ToEntity().Solve("x")); + + [Fact] + public void TheNonStrictInequalityKeepsTheRootsOfItsEquation() + { + var answer = (Set)"(108x^2 - 18x^3 - 24x^4 + 6x^5)/(27x^2 - 18x^4 + 3x^6) >= 0".ToEntity().Solve("x"); + foreach (var (at, inside) in new[] { ("-2", true), ("3", true), ("1", true), ("-3", false), ("0", false), ("sqrt(3)", false) }) + { + Assert.True(answer.TryContains(at.ToEntity(), out var contains), $"{at} undecided in {answer}"); + Assert.Equal(inside, contains); + } + } + } +}