Skip to content

Commit 2eea2e9

Browse files
Leave a two-sided limit undecided where a side stops at a finite form beside real values (#2426)
* Leave a two-sided limit undecided where a side stops at a finite form beside real values Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent fe19c27 commit 2eea2e9

3 files changed

Lines changed: 51 additions & 8 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,19 @@ and 1 in order. 2.6.0 answered the third with a wrong `0`. Found by limitcheck;
101101
| `"x^2 * floor(1/x^2)".ToEntity().Limit("x", 0)` | `0` | `limit(x ^ 2 * floor(1 / x ^ 2), x, 0)` |
102102
| `"x * ceil(1/x)".ToEntity().Limit("x", 0)` | `NaN` | `limit(x * ceil(1 / x), x, 0)` |
103103

104+
### A two-sided limit whose side stops at a finite indeterminate form is left unevaluated
105+
106+
**Silent: a two-sided limit is left unevaluated, rather than answered, where a side's limit stops at an indeterminate
107+
form of finite parts, such as `c / 0`, and the expression is real just beside the point.** That form is a side whose
108+
parts were never compared, not a side without a limit. `1 / log(x^2, cos(x))` is `+oo` from each side of 0, and 2.6.0
109+
answered `-oo`; `1 / (x * arccot(x))` is `+oo` from each side, and 2.6.0 answered `NaN`. Where the expression has no real value beside the point, as `(x - x) / (x - x)` has none anywhere, the
110+
limit is still `NaN`. Found by limitcheck; no issue was filed.
111+
112+
| Input | Was (2.6.0) | Now |
113+
|---|---|---|
114+
| `"1 / log(x^2, cos(x))".ToEntity().Limit("x", 0)` | `-oo` | `limit(1 / log(x ^ 2, cos(x)), x, 0)` |
115+
| `"1 / (x * arccot(x))".ToEntity().Limit("x", 0)` | `NaN` | `limit(1 / (x * arccotan(x)), x, 0)` |
116+
104117
### A limit at the jump of a step function is not answered by substitution
105118

106119
**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: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,12 @@ node is Floorf or Ceilf or Roundf or Signumf
193193
bothSidesDepth++;
194194
try
195195
{
196-
var fromLeft = Decided(ComputeLimit(expr, x, dest, ApproachFrom.Left));
196+
var fromLeft = Decided(ComputeLimit(expr, x, dest, ApproachFrom.Left), ApproachFrom.Left);
197197
if (fromLeft?.Evaled == MathS.NaN)
198198
return null;
199199
// A side that does not exist settles the question whatever the other side does,
200200
// so the right is still asked when the left is undecided.
201-
var fromRight = Decided(ComputeLimit(expr, x, dest, ApproachFrom.Right));
201+
var fromRight = Decided(ComputeLimit(expr, x, dest, ApproachFrom.Right), ApproachFrom.Right);
202202
if (fromRight?.Evaled == MathS.NaN)
203203
return null;
204204
if (fromLeft is null || fromRight is null)
@@ -215,15 +215,35 @@ node is Floorf or Ceilf or Roundf or Signumf
215215
// where it stops the search, and withheld at the outermost call, where it is not an
216216
// answer. One with an infinity in it, 0 * floor(-oo) for x floor(2/x), is a product or
217217
// 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)
218+
// than absent. So is one of finite parts where the expression takes real values on that
219+
// side: erf(abs(x)) / x^4 at 0 stops at 0 / 0 from each side, is +oo from each, and was
220+
// NaN. One of finite parts stays a side without a limit where the expression has no real
221+
// value beside the point: 0 / 0 for (x - x) / (x - x), which has no value anywhere, and
222+
// ln(-2) / 0 for ln(-2) / ln(x) at 1, whose values there are not real and whose sides
223+
// are infinities in different directions.
224+
Entity? Decided(Entity? limit, ApproachFrom side)
222225
=> limit is { } && IsAnIndeterminateForm(limit)
223-
&& limit.Nodes.Any(static node => node is Real { IsFinite: false })
226+
&& (limit.Nodes.Any(static node => node is Real { IsFinite: false })
227+
|| IsRealBeside(expr, x, dest, side))
224228
? null : limit;
225229
}
226230

231+
/// <summary>
232+
/// Whether <paramref name="expr"/> has a finite real value at two points on
233+
/// <paramref name="side"/> of a finite real <paramref name="dest"/>, 10^-6 and 10^-9 away.
234+
/// A witness that the expression is defined and real there, not a proof of it near
235+
/// every point; a side it finds real is only ever left undecided, never answered.
236+
/// </summary>
237+
private static bool IsRealBeside(Entity expr, Variable x, Entity dest, ApproachFrom side)
238+
{
239+
if (dest.Evaled is not Real { IsFinite: true } at || side is ApproachFrom.BothSides)
240+
return false;
241+
var sign = side is ApproachFrom.Left ? -1 : 1;
242+
return RealAt(Rational.Create(sign, 1_000_000)) && RealAt(Rational.Create(sign, 1_000_000_000));
243+
bool RealAt(Rational offset)
244+
=> expr.Substitute(x, at + offset).Evaled is Real { IsFinite: true };
245+
}
246+
227247
/// <summary>
228248
/// Whether <paramref name="expr"/> is real on both sides of a real <paramref name="dest"/>,
229249
/// close enough to it, but for its constants, decided structurally: every power to an exponent that is not whole,

‎Sources/Tests/UnitTests/Calculus/AnUndecidedSideLeavesTheLimitUnevaluatedTest.cs‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ namespace AngouriMath.Tests.Calculus
1313
/// <summary>
1414
/// A two-sided limit whose sides stopped at an indeterminate form with an infinity in it, 0 * floor(-oo) for
1515
/// 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.
16+
/// so the limit is left unevaluated. So is a side that stops at a form of finite parts, 0 / 0 for erf(abs(x)) / x^4,
17+
/// where the expression is real beside the point. Found by limitcheck; no issue was filed.
1718
/// </summary>
1819
[Trait("Area", "Calculus")]
1920
public sealed class AnUndecidedSideLeavesTheLimitUnevaluatedTest
@@ -23,13 +24,22 @@ public sealed class AnUndecidedSideLeavesTheLimitUnevaluatedTest
2324
[InlineData("floor(1/x) * sin(x)")]
2425
[InlineData("x^2 * floor(1/x^2)")]
2526
[InlineData("x * ceil(1/x)")]
27+
// A side that stops at 0 / 0, or at c / 0, of an expression real beside the point is undecided too:
28+
// erf(abs(x)) / x^4 is +oo from each side, 1 / log(x^2, cos(x)) is +oo, abs(x)^erf(x) is 1.
29+
[InlineData("erf(abs(x)) / x^4")]
30+
[InlineData("erf(abs(x)) / (x^3 * sinh(x))")]
31+
[InlineData("1 / log(x^2, cos(x))")]
32+
[InlineData("abs(x)^erf(x)")]
33+
[InlineData("tan(1/2 + x) + abs(x)^erf(x)")]
34+
[InlineData("1 / (x * arccot(x))")]
2635
public void IsNotNaN(string input)
2736
=> Assert.IsType<Entity.Limitf>(input.ToEntity().Limit("x", 0));
2837

2938
// A side that has no limit, or two sides that differ, still mean there is none: 0 / 0 everywhere, infinities
3039
// in different directions, an oscillation, a jump.
3140
[Theory]
3241
[InlineData("(x - x) * sin(x) / ((x - x) * x)", "0")]
42+
[InlineData("(x - x) / (x - x)", "0")]
3343
[InlineData("ln(-2) / ln(x)", "1")]
3444
[InlineData("sin(1/x)", "0")]
3545
[InlineData("floor(2/x)", "0")]

0 commit comments

Comments
 (0)