Skip to content

Commit f73ac9a

Browse files
Take no undecided limit for an infinite one in l'Hôpital's rule (#2360)
Whether a limit diverges was read off whether an infinity occurs in it, and an unevaluated limit(sin(u), x, +oo) holds one, as its destination. So l'Hopital's rule took sin(u) / cos(u), with neither part's limit taken, for oo/oo and differentiated it: tan(x^2 + x - 1) from the left at 0 answered -cos(-1) / sin(-1), 0.642, where the limit is tan(-1), -1.557. The same on 2.6.0. The rule, and the two places that build its quotients, now ask DivergesDecidedly, which turns an undecided limit away. The rewrites that ask IsInfiniteNode only whether they are worth trying keep it: f^g as e^(g ln f) is an equality whatever f does. Two answers had been reached through the mistake. The Stirling limits read -x + ln(2 pi x)/2 at +oo, asked from the left, unevaluated, as infinite -- which it is. An infinity has only one side and the one-sided path lacks the machinery the two-sided one has there, so a side asked for at a real infinity is now the two-sided limit; that also answers x - sqrt(x^2 + x) at +oo, -1/2, and e^x x at -oo, 0, both unevaluated before. And log(x, tanh(x))^(x^(pi + x)) at 0+ was 1 only because its base came back undecided; decided, it tends to 1 and the exponent to 0. A power whose base tends to a number other than 0 and whose exponent tends to 0 now answers 1. limitcheck, DEPTH=3, seeds 14, 16, 19, 23, 26 against master 37f7377: the limit is another value 11 -> 6, each of the five now unevaluated, and one limit more answered. Found at SEED=26; no issue was filed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 37f7377 commit f73ac9a

4 files changed

Lines changed: 138 additions & 4 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,31 @@ and some are left unevaluated ([#2267](https://github.com/asc-community/AngouriM
133133
| `"limitright(ln(sin(x)) / ln(cos(x)), x, 0)".ToEntity().Simplify()` | `-oo` | `+oo` |
134134
| `"limit(ln(x^2) / ln(cos(x)), x, 0)".ToEntity().Simplify()` | `-oo` | `+oo`, by [#2274](https://github.com/asc-community/AngouriMath/issues/2274) |
135135

136+
### A limit nobody could take is not read as infinite, and an infinity has one side
137+
138+
**Silent: a quotient whose parts' limits were both left unevaluated is no longer answered by l'Hopital's rule, which
139+
gave it a wrong value.** Whether a part diverges was read off whether an infinity occurs in its limit, and an unevaluated
140+
`limit(sin(u), x, +oo)` holds one, as its destination. So `sin(u) / cos(u)`, with neither limit taken, was taken for
141+
`oo / oo` and its derivatives' ratio answered `-cos(-1) / sin(-1)` for `tan(x^2 + x - 1)` from the left at 0, which is
142+
0.642, where the limit is `tan(-1)`, -1.557. An unevaluated limit is now neither infinite nor finite. Some of these
143+
limits are answered rightly, and some are left unevaluated. And a side asked for at `+oo` or `-oo`, which has only one,
144+
is the limit there: it was taken by a path without the machinery for an infinity, and left unevaluated what it is. A
145+
power whose base tends to a number other than 0 and whose exponent tends to 0 tends to 1, which is now answered
146+
wherever the base's limit is found. One right answer of 2.6.0 is among those left unevaluated: `log(x^x, 3/2) - 1` from
147+
the left at -1, which is `-1 - 0.129 i`, and which 2.7.0's previous changes had already turned into the wrong `-1`.
148+
149+
| Input | Was (2.6.0) | Now |
150+
|---|---|---|
151+
| `"tan(x^2 + x - 1)".ToEntity().Limit("x", 0, ApproachFrom.Left)` | `-cos(-1) / sin(-1)` | `tan(-1)` |
152+
| `"sin(x^2 + x - 1) / cos(x^2 + x - 1)".ToEntity().Limit("x", 0, ApproachFrom.Left)` | `-cos(-1) / sin(-1)` | `tan(-1)` |
153+
| `"tan(x^2 - x - 1)".ToEntity().Limit("x", 0, ApproachFrom.Left)` | `-cos(-1) / sin(-1)` | `limitleft(tan(x ^ 2 - x - 1), x, 0)` |
154+
| `"-x + ln(2*pi*x)/2".ToEntity().Limit("x", "+oo", ApproachFrom.Left)` | `limitleft(-x + ln(2 * pi * x) / 2, x, +oo)` | `-oo` |
155+
| `"x - sqrt(x^2 + x)".ToEntity().Limit("x", "+oo", ApproachFrom.Left)` | `limitleft(x - sqrt(x ^ 2 + x), x, +oo)` | `-1/2` |
156+
| `"e^x * x".ToEntity().Limit("x", "-oo", ApproachFrom.Right)` | `limitright(e ^ x * x, x, -oo)` | `0` |
157+
| `"log(x, tanh(x)) ^ (x ^ (pi + x))".ToEntity().Limit("x", 0, ApproachFrom.Left)` | `NaN`, in 10.7 s | `1` |
158+
| `"tanh(log(x / (-1), 1/x))".ToEntity().Limit("x", -1, ApproachFrom.Right)` | `1` | unevaluated; the limit is -1.313 |
159+
| `"log(x^x, 3/2) - 1".ToEntity().Limit("x", -1, ApproachFrom.Left)` | `ln(3/2) / ln(-1) - 1` | `limitleft(log(x ^ x, 3/2) - 1, x, -1)` |
160+
136161
### A value put in for a derivative's variable is where it is evaluated
137162

138163
**Silent: substituting for the variable of a derivative or an indefinite integral evaluates it there, where the value was

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,13 @@ internal static T WithinABudget<T>(int limits, System.Func<T> compute)
271271
return null;
272272
remainingLimits = remaining - 1;
273273
}
274+
// An infinity is approached from one side only, so a side asked for there is the
275+
// limit itself -- and the two-sided path is where the machinery for an infinite
276+
// destination lives. Taken one-sidedly, -x + ln(2 * pi * x) / 2 at +oo was left
277+
// unevaluated where the limit is -oo. A complex infinity is not a real one and is
278+
// turned away below as before.
279+
if (side is not ApproachFrom.BothSides && dest is Real { IsFinite: false, IsNaN: false })
280+
side = ApproachFrom.BothSides;
274281
// The approach is stated for the whole computation, not only where the destination
275282
// has been normalised to +oo. Everything below simplifies as it goes, and a rule that
276283
// may only fire while the approach is in scope is otherwise declining through most of

‎Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs‎

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,15 @@ private static bool IsRealAlong(Entity expr, Variable x)
517517
if (byStirling is null)
518518
{
519519
var baseLimit = EvalAssumingContinuous(@base.Limit(x, dest, side));
520+
// A base tending to a number other than 0 is not an indeterminate form, and
521+
// its limit is the limit's power: g * ln(f) tends to 0 whatever the branch of
522+
// ln(f), which stays bounded on the cut too, so f^g tends to 1. Answered here
523+
// rather than left to the descent, which asks the base's limit by its own
524+
// reading and can decline what this one has just taken:
525+
// lim x->0+ log(x, tanh(x))^(x^(pi + x)) is 1, and was answered only while
526+
// an undecided base was taken for an infinite one.
527+
if (IsFiniteNode(baseLimit) && baseLimit.Evaled is Complex { IsZero: false } finite && finite.IsFinite)
528+
return Integer.One;
520529
if (baseLimit != 0 && !IsInfiniteNode(baseLimit))
521530
return null;
522531
// Every route out of ln(f) runs through differentiating f, so a base this
@@ -789,6 +798,28 @@ private static bool IsInfiniteNode(Entity expr)
789798
=> expr.ContainsNode("+oo") || expr.ContainsNode("-oo")
790799
|| expr.Nodes.Any(node => node is Complex { IsFinite: false, IsNaN: false });
791800

801+
/// <summary>
802+
/// Whether a limit's value is infinite and was decided to be: <see cref="IsInfiniteNode"/>,
803+
/// but never for a value still holding a limit nobody could take.
804+
/// </summary>
805+
/// <remarks>
806+
/// That limit is a question rather than a value, and the destination it carries is not
807+
/// what it tends to: <c>limit(sin(u), x, +oo)</c> holds a <c>+oo</c> and says nothing
808+
/// about diverging. l'Hopital's rule read sin(u) / cos(u) with both limits undecided as
809+
/// oo/oo, differentiated it, and answered lim x->0- tan(x^2 + x - 1) with
810+
/// -cos(-1) / sin(-1), 0.642, where it is tan(-1), -1.557. The rule is only true of the
811+
/// forms it names, so it asks this.
812+
/// <para/>
813+
/// <see cref="IsInfiniteNode"/> is kept as it was for the rewrites that ask it whether
814+
/// they are worth trying, which are equalities wherever they apply: f^g as e^(g ln f)
815+
/// holds whatever f tends to, and an undecided base is exactly where it is worth asking.
816+
/// </remarks>
817+
private static bool DivergesDecidedly(Entity expr)
818+
=> !HoldsAnUndecidedLimit(expr) && IsInfiniteNode(expr);
819+
820+
private static bool HoldsAnUndecidedLimit(Entity expr)
821+
=> expr.Nodes.Any(node => node is Limitf);
822+
792823
/// <summary>
793824
/// Whether what the machinery handed back is an indeterminate form rather than a value:
794825
/// <c>0 / abs(0)</c>, <c>(+oo * 0)^2</c> -- a shape assembled out of the parts' limits
@@ -960,7 +991,7 @@ private static bool DivergesInMagnitude(Entity power, Variable x, Entity dest)
960991
}
961992

962993
private static bool IsFiniteNode(Entity expr)
963-
=> !IsInfiniteNode(expr) && expr != MathS.NaN;
994+
=> !HoldsAnUndecidedLimit(expr) && !IsInfiniteNode(expr) && expr != MathS.NaN;
964995

965996
/// <summary>
966997
/// What an inverse trigonometric function tends to where its argument grows without
@@ -1400,7 +1431,7 @@ private static bool IsIndeterminateQuotient(Entity numerator, Entity denominator
14001431
{
14011432
var above = EvalAssumingContinuous(numerator.Limit(x, dest, side));
14021433
var below = EvalAssumingContinuous(denominator.Limit(x, dest, side));
1403-
return above == 0 && below == 0 || IsInfiniteNode(above) && IsInfiniteNode(below);
1434+
return above == 0 && below == 0 || DivergesDecidedly(above) && DivergesDecidedly(below);
14041435
}
14051436

14061437
/// <summary>
@@ -1433,7 +1464,7 @@ private static bool IsIndeterminateQuotient(Entity numerator, Entity denominator
14331464
var limit = EvalAssumingContinuous(factor.Limit(x, dest, side));
14341465
if (vanishing is null && limit == 0)
14351466
vanishing = factor;
1436-
else if (diverging is null && IsInfiniteNode(limit))
1467+
else if (diverging is null && DivergesDecidedly(limit))
14371468
diverging = factor;
14381469
else
14391470
rest *= factor;
@@ -1511,7 +1542,7 @@ bool DoesNotSettle(Entity argument) => argument.ContainsNode(x)
15111542
if (expr is Divf(var num, var den))
15121543
if (EvalAssumingContinuous(num.Limit(x, dest, side)) is var numLimit && EvalAssumingContinuous(den.Limit(x, dest, side)) is var denLimit)
15131544
if (numLimit == 0 && denLimit == 0 ||
1514-
IsInfiniteNode(numLimit) && IsInfiniteNode(denLimit))
1545+
DivergesDecidedly(numLimit) && DivergesDecidedly(denLimit))
15151546
if (num is not Number && den is not Number)
15161547
if (num.ContainsNode(x) && den.ContainsNode(x)
15171548
&& !HasAStepThatJumpsNear(expr, x, dest, side))
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
using static AngouriMath.Entity.Number;
12+
13+
namespace AngouriMath.Tests.Calculus
14+
{
15+
/// <summary>
16+
/// l'Hopital's rule read a part whose limit nobody could take as infinite, because the unevaluated
17+
/// <c>limit(sin(u), x, +oo)</c> holds a <c>+oo</c> -- its destination. <c>sin(u) / cos(u)</c> with both limits
18+
/// undecided was taken for oo/oo and differentiated, and <c>tan(x^2 + x - 1)</c> at 0 from the left answered
19+
/// <c>-cos(-1) / sin(-1)</c>, which is -cot(-1) = 0.642, where the limit is tan(-1) = -1.557. The same on 2.6.0.
20+
/// Found by limitcheck at <c>DEPTH=3</c>, <c>SEED=26</c>; no issue was filed. And a side asked for at an infinity
21+
/// is now the limit there, which the Stirling limits were reading through the same mistake.
22+
/// </summary>
23+
[Trait("Area", "Calculus")]
24+
public sealed class AnUndecidedLimitIsNotInfiniteTest
25+
{
26+
[Theory]
27+
[InlineData("tan(x^2 + x - 1)", ApproachFrom.Left)]
28+
[InlineData("sin(x^2 + x - 1) / cos(x^2 + x - 1)", ApproachFrom.Left)]
29+
[InlineData("tan(x^2 + x - 1)", ApproachFrom.Right)]
30+
public void IsTheTangent(string input, ApproachFrom side)
31+
{
32+
var limit = MathS.FromString(input).Limit("x", 0, side);
33+
Assert.False(limit is Limitf, $"lim {side} x->0 {input} was left unevaluated");
34+
AssertIsTheTangent(input, side, limit);
35+
}
36+
37+
// These come back unevaluated: the parts' own limits from the left are not taken, and that is a decline, not a
38+
// wrong answer. What they must not be is the quotient of the derivatives, as the first was before.
39+
[Theory]
40+
[InlineData("tan(x^2 - x - 1)", ApproachFrom.Left)]
41+
[InlineData("tan(x^2 + x - 1)", ApproachFrom.BothSides)]
42+
public void IsTheTangentOrUnevaluated(string input, ApproachFrom side)
43+
{
44+
var limit = MathS.FromString(input).Limit("x", 0, side);
45+
if (limit is not Limitf)
46+
AssertIsTheTangent(input, side, limit);
47+
}
48+
49+
// An infinity has one side, and asking for it one-sidedly was left unevaluated where the limit is a value. The
50+
// Stirling limits relied on reading the first of these, unevaluated, as infinite: it is -oo, by luck. The last
51+
// two are a power whose base tends to a number and whose exponent tends to 0.
52+
[Theory]
53+
[InlineData("-x + ln(2*pi*x)/2", "+oo", ApproachFrom.Left, "-oo")]
54+
[InlineData("e^x * x", "-oo", ApproachFrom.Right, "0")]
55+
[InlineData("x - sqrt(x^2 + x)", "+oo", ApproachFrom.Left, "-1/2")]
56+
[InlineData("x - sqrt(x^2 + x)", "+oo", ApproachFrom.Right, "-1/2")]
57+
// Answered only while its base, asked at +oo from the left, came back undecided and was taken for infinite.
58+
// Decided, the base tends to 1 and the power to 0, which is 1 and not an indeterminate form.
59+
[InlineData("log(x, tanh(x)) ^ (x ^ (pi + x))", "0", ApproachFrom.Right, "1")]
60+
[InlineData("(x - 3) ^ x", "0", ApproachFrom.Left, "1")]
61+
public void IsTheLimit(string input, string destination, ApproachFrom side, string expected)
62+
=> Assert.Equal(MathS.FromString(expected), MathS.FromString(input).Limit("x", destination, side));
63+
64+
private static void AssertIsTheTangent(string input, ApproachFrom side, Entity limit)
65+
{
66+
var difference = (limit - MathS.Tan(-1)).EvalNumerical();
67+
Assert.True(difference is Complex value && Complex.Abs(value) is Real abs && abs < 1e-10,
68+
$"lim {side} x->0 {input} = {limit}, which is not tan(-1)");
69+
}
70+
}
71+
}

0 commit comments

Comments
 (0)