Skip to content

Commit 6d5f175

Browse files
Leave a two-sided limit unevaluated where a side stops at an indeterminate form (#2419)
* Leave a two-sided limit unevaluated where a side stops at an indeterminate form Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 15070c6 commit 6d5f175

3 files changed

Lines changed: 91 additions & 9 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,20 @@ rational exponent is still written as its value. Found by limitcheck; no issue w
8787
| `"x^(abs(x)^arctan(2))".ToEntity().Limit("x", 0, ApproachFrom.Left)` | unevaluated | `1` |
8888
| `"x^(abs(x)^arctan(2))".ToEntity().Limit("x", 0, ApproachFrom.Right)` | unevaluated | `1` |
8989

90+
### A two-sided limit whose sides are undecided is left unevaluated
91+
92+
**Silent: a two-sided limit is left unevaluated, rather than `NaN`, where a side's limit stops at an indeterminate form
93+
with an infinity in it**, such as `0 * floor(-oo)`. That form is a side whose parts were never compared, not a side
94+
without a limit, and `NaN` says the limit does not exist. Each limit below exists, and they are 2, 1, 1
95+
and 1 in order. 2.6.0 answered the third with a wrong `0`. Found by limitcheck; no issue was filed.
96+
97+
| Input | Was (2.6.0) | Now |
98+
|---|---|---|
99+
| `"x * floor(2/x)".ToEntity().Limit("x", 0)` | `NaN` | `limit(x * floor(2 / x), x, 0)` |
100+
| `"floor(1/x) * sin(x)".ToEntity().Limit("x", 0)` | `NaN` | `limit(floor(1 / x) * sin(x), x, 0)` |
101+
| `"x^2 * floor(1/x^2)".ToEntity().Limit("x", 0)` | `0` | `limit(x ^ 2 * floor(1 / x ^ 2), x, 0)` |
102+
| `"x * ceil(1/x)".ToEntity().Limit("x", 0)` | `NaN` | `limit(x * ceil(1 / x), x, 0)` |
103+
90104
### A limit at the jump of a step function is not answered by substitution
91105

92106
**Silent: a limit of an expression built on `floor`, `ceil`, `round` or `sgn`, where the step's argument arrives on one

‎Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs‎

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,24 +180,48 @@ node is Floorf or Ceilf or Roundf or Signumf
180180
/// <a href="https://github.com/asc-community/AngouriMath/issues/719">#719</a>,
181181
/// <a href="https://github.com/asc-community/AngouriMath/issues/596">#596</a>
182182
/// </remarks>
183-
private static Entity? WhereBothSidesAgree(Entity expr, Variable x, Entity dest)
183+
private static Entity? WhereBothSidesAgree(Entity expr, Variable x, Entity dest, out bool aSideIsUndecided)
184184
{
185+
// Set where no answer came because a side has none yet, rather than because a side
186+
// does not exist or the two differ. Neither side is then known to be NaN, so neither
187+
// is the limit: x floor(2/x) at 0 is 2 from each side, the one-sided paths do not
188+
// decide it, and the two-sided one answered NaN.
189+
aSideIsUndecided = false;
185190
if (bothSidesDepth >= MaxBothSidesDepth
186191
|| MathS.Settings.Codomain.Value is not AngouriMath.Core.Domain.Real && !IsRealOnBothSides(expr, x, dest))
187192
return null;
188193
bothSidesDepth++;
189194
try
190195
{
191-
if (ComputeLimit(expr, x, dest, ApproachFrom.Left) is not { } fromLeft
192-
|| fromLeft.Evaled == MathS.NaN)
196+
var fromLeft = Decided(ComputeLimit(expr, x, dest, ApproachFrom.Left));
197+
if (fromLeft?.Evaled == MathS.NaN)
193198
return null;
194-
if (ComputeLimit(expr, x, dest, ApproachFrom.Right) is not { } fromRight
195-
|| fromRight.Evaled == MathS.NaN)
199+
// A side that does not exist settles the question whatever the other side does,
200+
// so the right is still asked when the left is undecided.
201+
var fromRight = Decided(ComputeLimit(expr, x, dest, ApproachFrom.Right));
202+
if (fromRight?.Evaled == MathS.NaN)
196203
return null;
204+
if (fromLeft is null || fromRight is null)
205+
{
206+
aSideIsUndecided = true;
207+
return null;
208+
}
197209
return fromLeft == fromRight || ExpressionNumerical.AreEqual(fromLeft, fromRight)
198210
? fromLeft : null;
199211
}
200212
finally { bothSidesDepth--; }
213+
214+
// An indeterminate form a side's own limit could not read is NaN inside the machinery,
215+
// where it stops the search, and withheld at the outermost call, where it is not an
216+
// answer. One with an infinity in it, 0 * floor(-oo) for x floor(2/x), is a product or
217+
// a quotient of parts whose rates were never compared, so that side is undecided rather
218+
// than absent. One of finite parts only stays a side without a limit, as before: 0 / 0
219+
// for (x - x) / (x - x), which has no value anywhere, and ln(-2) / 0 for ln(-2) / ln(x)
220+
// at 1, whose sides are infinities in different directions.
221+
static Entity? Decided(Entity? limit)
222+
=> limit is { } && IsAnIndeterminateForm(limit)
223+
&& limit.Nodes.Any(static node => node is Real { IsFinite: false })
224+
? null : limit;
201225
}
202226

203227
/// <summary>
@@ -719,9 +743,13 @@ node is Derivativef(var expression, Variable variable, var iterations) && iterat
719743
// again: tan(x/2) at pi, +oo and -oo, asked both sides through the whole of the
720744
// machinery each time, and a definite integral over [0, pi] spent its budget of
721745
// limits on that.
722-
if ((fromLeft.Evaled == MathS.NaN || fromRight.Evaled == MathS.NaN)
723-
&& WhereBothSidesAgree(expr, x, dest) is { } agreed)
724-
return agreed;
746+
if (fromLeft.Evaled == MathS.NaN || fromRight.Evaled == MathS.NaN)
747+
{
748+
if (WhereBothSidesAgree(expr, x, dest, out var aSideIsUndecided) is { } agreed)
749+
return agreed;
750+
if (aSideIsUndecided)
751+
return null;
752+
}
725753
return MathS.NaN; // A two-sided limit cannot exist if the limit from left and right don't match.
726754
}
727755
else
@@ -734,7 +762,7 @@ node is Derivativef(var expression, Variable variable, var iterations) && iterat
734762
// something that disagrees -- which is most of what the one-sided
735763
// fallbacks are for, so it is where the promotion is worth the most.
736764
// https://github.com/asc-community/AngouriMath/issues/719
737-
return WhereBothSidesAgree(expr, x, dest);
765+
return WhereBothSidesAgree(expr, x, dest, out _);
738766
}
739767
}
740768
throw new AngouriBugException($"Unresolved enum parameter {side}");
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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.Extensions;
9+
using Xunit;
10+
11+
namespace AngouriMath.Tests.Calculus
12+
{
13+
/// <summary>
14+
/// A two-sided limit whose sides stopped at an indeterminate form with an infinity in it, 0 * floor(-oo) for
15+
/// x floor(2/x) at 0, answered NaN, which says there is no limit, where each side is 2. Such a side is undecided,
16+
/// so the limit is left unevaluated. Found by limitcheck; no issue was filed.
17+
/// </summary>
18+
[Trait("Area", "Calculus")]
19+
public sealed class AnUndecidedSideLeavesTheLimitUnevaluatedTest
20+
{
21+
[Theory]
22+
[InlineData("x * floor(2/x)")]
23+
[InlineData("floor(1/x) * sin(x)")]
24+
[InlineData("x^2 * floor(1/x^2)")]
25+
[InlineData("x * ceil(1/x)")]
26+
public void IsNotNaN(string input)
27+
=> Assert.IsType<Entity.Limitf>(input.ToEntity().Limit("x", 0));
28+
29+
// A side that has no limit, or two sides that differ, still mean there is none: 0 / 0 everywhere, infinities
30+
// in different directions, an oscillation, a jump.
31+
[Theory]
32+
[InlineData("(x - x) * sin(x) / ((x - x) * x)", "0")]
33+
[InlineData("ln(-2) / ln(x)", "1")]
34+
[InlineData("sin(1/x)", "0")]
35+
[InlineData("floor(2/x)", "0")]
36+
[InlineData("floor(x)", "0")]
37+
public void IsStillNaN(string input, string destination)
38+
=> Assert.Equal(MathS.NaN, input.ToEntity().Limit("x", destination));
39+
}
40+
}

0 commit comments

Comments
 (0)