Skip to content

Commit 553e68d

Browse files
Ask the whole limit of an indeterminate quotient a function holds (#2358)
A function of a quotient took the quotient's limit from the descent alone, which reads 0/0 or oo/oo off the two parts as NaN -- the claim that there is no limit -- where only the descent cannot tell. sin(x)/x at 0 is 1, which the whole limit reaches through the first remarkable limit; (sin(x)/x)^2, exp(sin(x)/x), sin(sin(x)/x) and exp((cos(x) - 1)/x^2) came out NaN two-sided and unevaluated from either side. 2.6.0 answers the same. Where the descent of a quotient would return NaN for an indeterminate form and nothing else answers, the quotient's whole limit is asked once, and only a value is taken. Three things keep it from costing what it answers: - One level: no whole limit is asked inside another. - Not under a caller's budget of limits, which it would spend. - The form a limit comes back in can hold the infinity it was taken at: -4/9 * 0 * (1 - (1 + (1/+oo)^2)^(1/3)), handed on as written, left a definite integral across 0 unevaluated. It is folded first, which makes it 0 and ln(2) * 2^(1/+oo) ln(2), and taken as its number only where an infinity is still in it. limitcheck on SEED=14 and 16, and at DEPTH=3 on 19 and 23, gains cos(sin(x)/x), (x/arctan(x))^3 and 1/(x/abs(x)) at 0, each agreeing with the values, and no limit of another value. 4180 limit and integration tests pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent f86d0a2 commit 553e68d

4 files changed

Lines changed: 105 additions & 1 deletion

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,21 @@ Two-sided, each side is now taken with its own value, and `floor(x)^x` at 0 is 1
338338
| `"floor(x)^tanh(x)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | unevaluated | `0` |
339339
| `"floor(x)^x".ToEntity().Limit("x", 0)` | unevaluated | `NaN`, the sides differ |
340340

341+
### A function of a quotient tending to 0/0 has the value at the quotient's limit
342+
343+
**Silent: a different answer.** A function of a quotient took the quotient's limit from the descent alone, which reads
344+
0/0 or oo/oo off the two parts as NaN -- the claim that there is no limit -- where only the descent cannot tell. The
345+
quotient's whole limit is asked now, once, through the remarkable limits and l'Hopital's rule, and only a value it
346+
gives is taken. No issue was filed.
347+
348+
| Input | Was (2.6.0) | Now |
349+
|---|---|---|
350+
| `limit((sin(x)/x)^2, x, 0)` | `NaN` | `1` |
351+
| `limit(exp(sin(x)/x), x, 0)` | `NaN` | `e` |
352+
| `limit(sin(sin(x)/x), x, 0)` | `NaN` | `sin(1)` |
353+
| `limit(exp((cos(x) - 1)/x^2), x, 0)` | `NaN` | `e ^ (-1/2)` |
354+
| `limitright(exp(sin(x)/x), x, 0)` | unevaluated | `e` |
355+
341356
### A two-sided limit of an expression real on both sides is where its sides agree
342357

343358
**Silent: a two-sided limit that was `NaN` although both sides agree has their value, where the expression is real on

‎Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs‎

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,55 @@ partial record Divf
118118
// which side the divisor vanishes from, and so comes back NaN. Only where
119119
// nothing above answered, and whatever it did answer is kept if this finds
120120
// nothing better.
121-
return DivergesAtAVanishingDivisor(Dividend, Divisor, x, dist, side) ?? substituted;
121+
if (DivergesAtAVanishingDivisor(Dividend, Divisor, x, dist, side) is { } diverges)
122+
return diverges;
123+
// An indeterminate form, 0/0 or oo/oo, read off the parts is NaN, which says there
124+
// is no limit, where the descent only cannot tell: sin(x)/x at 0 is 1, which the
125+
// whole limit reaches through the first remarkable limit, and a function of it --
126+
// (sin(x)/x)^2, exp(sin(x)/x), exp(ln(cos(x))/x^2) -- came out NaN, its argument
127+
// asked only of the descent. The whole limit of the quotient is asked once, and
128+
// only a value is taken, and as the number where the form it came back in holds the
129+
// infinity it was taken at: -4/9 * 0 * (1 - (1 + (1/+oo)^2)^(1/3)), handed on as
130+
// written, sent a definite integral astray. Folded, it is 0, and ln(2) * 2^(1/+oo) is
131+
// ln(2), not its decimal. Where it has no
132+
// value, what was answered is kept.
133+
if (substituted?.Evaled == MathS.NaN && IsAnIndeterminateQuotient(dividend, divisor)
134+
&& AsTheWholeLimit(this, x, dist, side) is { } whole && whole.Evaled is Number { IsNaN: false } value)
135+
return whole.InnerSimplified is var folded && folded.Nodes.Any(static node => node is Number { IsFinite: false })
136+
? value : folded;
137+
return substituted;
122138
}
123139
}
124140
}
125141

142+
/// <summary>Whether two parts' limits make a quotient 0/0 or oo/oo.</summary>
143+
private static bool IsAnIndeterminateQuotient(Entity dividend, Entity divisor)
144+
=> (dividend.Evaled, divisor.Evaled) switch
145+
{
146+
(Complex { IsZero: true }, Complex { IsZero: true }) => true,
147+
(Number { IsFinite: false, IsNaN: false }, Number { IsFinite: false, IsNaN: false }) => true,
148+
_ => false,
149+
};
150+
151+
/// <summary>The quotient whose whole limit is being asked from inside the descent, so that no other is asked inside it.</summary>
152+
[System.ThreadStatic] private static HashSet<Entity>? quotientsAskedWhole;
153+
154+
private static Entity? AsTheWholeLimit(Entity quotient, Variable x, Entity dist, ApproachFrom side)
155+
{
156+
// One level: a whole limit asked from here descends again, and a retry inside it asked another, so that a
157+
// definite integral's antiderivative at its bounds -- 1/((1 + x^2)^(1/3) (9 + x^2)) across 0 -- went from four
158+
// seconds to past two minutes and was left unevaluated.
159+
// Nor under a caller's budget of limits, which every limit asked here spends: fifty asked on the side of a
160+
// definite integral's bounds left the bounds none, and the integral unevaluated.
161+
if (Functions.Algebra.LimitFunctional.UnderALimitBudget)
162+
return null;
163+
quotientsAskedWhole ??= new();
164+
if (quotientsAskedWhole.Count > 0 || !quotientsAskedWhole.Add(quotient))
165+
return null;
166+
try { return Functions.Algebra.LimitFunctional.ComputeLimit(quotient, x, dist, side); }
167+
finally { quotientsAskedWhole.Remove(quotient); }
168+
}
169+
126170
partial record Modf
127171
{
128172
internal override Entity? ComputeLimitDivideEtImpera(Variable x, Entity dist, ApproachFrom side)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ private static Entity ExpandLogarithm(Entity expr)
242242
/// </summary>
243243
[System.ThreadStatic] private static int? remainingLimits;
244244

245+
/// <summary>Whether a caller has set a budget of limits, which a limit asked on the side would spend.</summary>
246+
internal static bool UnderALimitBudget => remainingLimits is not null;
247+
245248
/// <summary>
246249
/// <paramref name="compute"/> with at most <paramref name="limits"/> limits taken in all, for a caller that has a
247250
/// use only for a limit it can have cheaply, and leaves the question open otherwise.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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.Core;
9+
using Xunit;
10+
using static AngouriMath.Entity;
11+
12+
namespace AngouriMath.Tests.Calculus
13+
{
14+
/// <summary>
15+
/// A function of a quotient that tends to 0/0 took the quotient's limit from the descent alone, which reads 0/0 off
16+
/// the two parts as NaN -- the claim that there is no limit -- where only the descent cannot tell: <c>sin(x)/x</c> at 0
17+
/// is 1, and <c>(sin(x)/x)^2</c> and <c>exp(sin(x)/x)</c> were NaN two-sided and unevaluated from either side. The
18+
/// quotient's whole limit is asked now, once, and only its value is taken. Found while checking a limit
19+
/// limitcheck reported; no issue was filed.
20+
/// </summary>
21+
[Trait("Area", "Calculus")]
22+
public sealed class AFunctionOfAnIndeterminateQuotientTest
23+
{
24+
[Theory]
25+
[InlineData("(sin(x)/x)^2", ApproachFrom.BothSides, "1")]
26+
[InlineData("exp(sin(x)/x)", ApproachFrom.BothSides, "e")]
27+
[InlineData("exp(sin(x)/x)", ApproachFrom.Right, "e")]
28+
[InlineData("sin(sin(x)/x)", ApproachFrom.BothSides, "sin(1)")]
29+
[InlineData("exp((cos(x) - 1)/x^2)", ApproachFrom.BothSides, "e^(-1/2)")]
30+
[InlineData("sqrt(sin(x)/x)", ApproachFrom.Right, "1")]
31+
// As before.
32+
[InlineData("sin(x)/x", ApproachFrom.BothSides, "1")]
33+
[InlineData("exp(x/x)", ApproachFrom.BothSides, "e")]
34+
public void HasTheValueOfTheFunctionAtTheQuotientsLimit(string input, ApproachFrom side, string expected)
35+
{
36+
var limit = MathS.FromString(input).Limit("x", 0, side);
37+
Assert.IsAssignableFrom<Number>(limit.Evaled);
38+
var difference = (limit - MathS.FromString(expected)).EvalNumerical();
39+
Assert.True(difference.Abs() < (Number.Real)1e-30, $"the limit of {input} at 0 is {limit}, where it is {expected}");
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)