diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 1a1ab7b56..d4430ed95 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -75,6 +75,19 @@ mentions answers it as a parameter, as a short system does, where it was `null` | `MathS.Equations("x - 1", "x^2 - 1").Solve("x", "y")` | `null` | `[[1, t_1]]` | | `MathS.Equations("a - 1", "b * 0").Solve("a", "b")` | `null` | `[[1, t_1]]` | +### `Simplify` does not add a condition the input does not have + +**Silent: an answer defined at fewer points is defined at all of the input's.** A polynomial division in a +variable divided by the divisor's leading coefficient, and with the variables replaced it did so even where that +coefficient is a symbol and the divisor has another term. `(t x + y)/(1 - y x)` divided in `y` has `1/x` in it, +and `Simplify` passed that on as `not x = 0`, though at `x = 0` the input is `-y + y`. A divisor of one term, +`a x^k`, is still divided, since the input is undefined wherever its coefficient is zero +([#2134](https://github.com/asc-community/AngouriMath/issues/2134)). + +| Input | Was (2.6.0) | Now | +|---|---|---| +| `"-(t*x + y)/(1 - y*x) + (t*x + y)/(1 - y*x)".Simplify()` | `0 provided not 1 - x * y = 0 and not x = 0` | `0 provided not 1 - x * y = 0` | + ### A matrix is divided, raised to a power and compared as a matrix **Silent: wrong answers about matrices become right, or stay written.** Where an operation had no answer of its own diff --git a/Sources/AngouriMath/Functions/TreeAnalyzer/LongDivision.cs b/Sources/AngouriMath/Functions/TreeAnalyzer/LongDivision.cs index 92b61c348..1e9b1d6b0 100644 --- a/Sources/AngouriMath/Functions/TreeAnalyzer/LongDivision.cs +++ b/Sources/AngouriMath/Functions/TreeAnalyzer/LongDivision.cs @@ -213,6 +213,17 @@ private static (Entity Divided, Entity Remainder)? DivideOnePolynomial( // https://github.com/asc-community/AngouriMath/issues/180 if (!replaceVars && ((maxvalQ.Vars.Any() && !genericCase) || maxvalQ.Evaled == Integer.Create(0))) return null; + // **And with the variables replaced, where the divisor has more than one term.** That + // pass divides by a leading coefficient as much as this one does, and it was left + // unguarded only because it predates the guard. `(t x + y)/(1 - y x)` divided in `y` + // is `-1/x + (t x + 1/x)/(1 - x y)`, undefined at `x = 0`, where the divisor is 1; and + // `Simplify` answered `-(t x + y)/(1 - y x) + (t x + y)/(1 - y x)` with + // `0 provided not x = 0`, a condition the input does not have. A divisor of one term, + // `a x^k`, is zero wherever its coefficient is, so dividing by that coefficient loses + // nothing the input had: `(a x - b x)/(a x)` is `(a - b)/a`. + // https://github.com/asc-community/AngouriMath/issues/2134 + if (replaceVars && maxvalQ.Vars.Any() && !genericCase && powersOfQ.Count > 1) + return null; // A leading coefficient with a symbol in it can be zero as a value without being zero // as written: `(-(a - a u^2) - (u^2 + 1) a)^3` is `-8 a^3`, and expanded it leaves diff --git a/Sources/Tests/UnitTests/Common/SimplifiedConditionNotStricterTest.cs b/Sources/Tests/UnitTests/Common/SimplifiedConditionNotStricterTest.cs new file mode 100644 index 000000000..502e03bf4 --- /dev/null +++ b/Sources/Tests/UnitTests/Common/SimplifiedConditionNotStricterTest.cs @@ -0,0 +1,35 @@ +// +// 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; +using AngouriMath.Extensions; +using Xunit; +using static AngouriMath.Entity.Number; + +namespace AngouriMath.Tests.Common +{ + /// + /// Simplify answered -(t x + y)/(1 - y x) + (t x + y)/(1 - y x) with + /// 0 provided not 1 - x y = 0 and not x = 0. At x = 0 the input is + /// -y + y, which is defined, and the answer was not: a polynomial division in + /// y had divided by the divisor's leading coefficient -x. + /// #2134 + /// + [Trait("Area", "Common")] + public sealed class SimplifiedConditionNotStricterTest + { + [Theory] + [InlineData("-(t*x + y)/(1 - y*x) + (t*x + y)/(1 - y*x)")] + [InlineData("(t*x + y)/(1 - y*x) - (t*x + y)/(1 - y*x)")] + public void TheAnswerIsDefinedWhereTheInputIs(string input) + { + var simplified = input.Simplify() + .Substitute("x", 0).Substitute("y", 2).Substitute("t", 3); + Assert.Equal(Integer.Zero, simplified.Evaled); + } + } +}