Skip to content

Commit 2d7d31e

Browse files
Simplify does not add a condition the input does not have (#2171)
PolynomialLongDivision divides by the divisor's leading coefficient. Its first attempt, on the pair as written, declines a symbolic one for the simplifier, since a quotient that loses a value of a parameter is not an equivalence. The second attempt, with the variables replaced by temporaries, had no such guard: it predates it, and #1269 left it as it was. (t x + y)/(1 - y x) divided there 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 1 - x y = 0 and not x = 0. The input is -y + y at x = 0. The replaced attempt now declines too where the coefficient is symbolic and the divisor has more than one term in the variable. A divisor of one term, a x^k, is zero wherever its coefficient is, so dividing by it loses nothing the input had, and is still done. Guarding that case as well changed the limit of (tan(a x) - sin(b x))/(a x) at 0 from (a - b)/a to 1 - b/a, because Simplify does not put 1 - b/a over one denominator (#2137), so it is not guarded. On 2.6.0 and on this branch: -(t*x + y)/(1 - y*x) + (t*x + y)/(1 - y*x) 0 provided not 1 - x * y = 0 and not x = 0 -> 0 provided not 1 - x * y = 0 Unit suite 17,130 passed, 0 failed. SimpSweep 10,463/10,463 agree; CanonCheck matches its baseline; BoundCheck 0 disagreements; CasBench 120/121, unchanged. Part of #2134 Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 689fd01 commit 2d7d31e

3 files changed

Lines changed: 59 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,19 @@ mentions answers it as a parameter, as a short system does, where it was `null`
7575
| `MathS.Equations("x - 1", "x^2 - 1").Solve("x", "y")` | `null` | `[[1, t_1]]` |
7676
| `MathS.Equations("a - 1", "b * 0").Solve("a", "b")` | `null` | `[[1, t_1]]` |
7777

78+
### `Simplify` does not add a condition the input does not have
79+
80+
**Silent: an answer defined at fewer points is defined at all of the input's.** A polynomial division in a
81+
variable divided by the divisor's leading coefficient, and with the variables replaced it did so even where that
82+
coefficient is a symbol and the divisor has another term. `(t x + y)/(1 - y x)` divided in `y` has `1/x` in it,
83+
and `Simplify` passed that on as `not x = 0`, though at `x = 0` the input is `-y + y`. A divisor of one term,
84+
`a x^k`, is still divided, since the input is undefined wherever its coefficient is zero
85+
([#2134](https://github.com/asc-community/AngouriMath/issues/2134)).
86+
87+
| Input | Was (2.6.0) | Now |
88+
|---|---|---|
89+
| `"-(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` |
90+
7891
### A matrix is divided, raised to a power and compared as a matrix
7992

8093
**Silent: wrong answers about matrices become right, or stay written.** Where an operation had no answer of its own

‎Sources/AngouriMath/Functions/TreeAnalyzer/LongDivision.cs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,17 @@ private static (Entity Divided, Entity Remainder)? DivideOnePolynomial(
213213
// https://github.com/asc-community/AngouriMath/issues/180
214214
if (!replaceVars && ((maxvalQ.Vars.Any() && !genericCase) || maxvalQ.Evaled == Integer.Create(0)))
215215
return null;
216+
// **And with the variables replaced, where the divisor has more than one term.** That
217+
// pass divides by a leading coefficient as much as this one does, and it was left
218+
// unguarded only because it predates the guard. `(t x + y)/(1 - y x)` divided in `y`
219+
// is `-1/x + (t x + 1/x)/(1 - x y)`, undefined at `x = 0`, where the divisor is 1; and
220+
// `Simplify` answered `-(t x + y)/(1 - y x) + (t x + y)/(1 - y x)` with
221+
// `0 provided not x = 0`, a condition the input does not have. A divisor of one term,
222+
// `a x^k`, is zero wherever its coefficient is, so dividing by that coefficient loses
223+
// nothing the input had: `(a x - b x)/(a x)` is `(a - b)/a`.
224+
// https://github.com/asc-community/AngouriMath/issues/2134
225+
if (replaceVars && maxvalQ.Vars.Any() && !genericCase && powersOfQ.Count > 1)
226+
return null;
216227

217228
// A leading coefficient with a symbol in it can be zero as a value without being zero
218229
// as written: `(-(a - a u^2) - (u^2 + 1) a)^3` is `-8 a^3`, and expanded it leaves
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// Copyright (c) 2019-2026 Angouri.
3+
// AngouriMath is licensed under MIT.
4+
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
5+
// Website: https://am.angouri.org.
6+
//
7+
8+
using AngouriMath;
9+
using AngouriMath.Extensions;
10+
using Xunit;
11+
using static AngouriMath.Entity.Number;
12+
13+
namespace AngouriMath.Tests.Common
14+
{
15+
/// <summary>
16+
/// <c>Simplify</c> answered <c>-(t x + y)/(1 - y x) + (t x + y)/(1 - y x)</c> with
17+
/// <c>0 provided not 1 - x y = 0 and not x = 0</c>. At <c>x = 0</c> the input is
18+
/// <c>-y + y</c>, which is defined, and the answer was not: a polynomial division in
19+
/// <c>y</c> had divided by the divisor's leading coefficient <c>-x</c>.
20+
/// <a href="https://github.com/asc-community/AngouriMath/issues/2134">#2134</a>
21+
/// </summary>
22+
[Trait("Area", "Common")]
23+
public sealed class SimplifiedConditionNotStricterTest
24+
{
25+
[Theory]
26+
[InlineData("-(t*x + y)/(1 - y*x) + (t*x + y)/(1 - y*x)")]
27+
[InlineData("(t*x + y)/(1 - y*x) - (t*x + y)/(1 - y*x)")]
28+
public void TheAnswerIsDefinedWhereTheInputIs(string input)
29+
{
30+
var simplified = input.Simplify()
31+
.Substitute("x", 0).Substitute("y", 2).Substitute("t", 3);
32+
Assert.Equal(Integer.Zero, simplified.Evaled);
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)