Skip to content

Commit f86d0a2

Browse files
Turn l'Hôpital away from a quotient whose whole powers grow (#2357)
GrewTooMuch turned the rule away where a quotient grew in nodes, and a chain whose divisor is a reciprocal power, x^n / (1 / g^k), grows in its exponents instead: the derivative of 1/g^k is over g^(2k), so k doubled at each step with the node count flat, and the inner limits expanded the powers. The limit of (-ln(2)/ln(x))^(e^x - 1) at 0 from the right went 6, 12, 24, ... and did not finish in ten minutes; it is 1, which 2.6.0 answered and #2306 stopped answering (bisected: #2306's factor taken out of a sum changed the route into this chain). The spelling with log(x, 1/2) and sgn(x) was 0 in 2.6.0 and hung on master. The sum of the whole exponents is measured as the nodes are, with the same room, the larger of eight more and three fifths again: a chain that is getting somewhere lowers its degrees. Both limits are 1, in 6 s and 3.4 s. limitcheck at SEED=16, and at DEPTH=3 on SEED=19 and 23, changes only the limit that did not finish; 752 limit tests pass. Give the l'Hopital chain test five minutes, far from the runner and the hang The 0^0 limit takes about 6 s here and past a minute on CI's Windows runner, whose suite took 19 m 54 s against 7 m; a minute's cap measured the runner. Before the fix it did not finish in ten minutes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 195da7f commit f86d0a2

3 files changed

Lines changed: 77 additions & 1 deletion

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,20 @@ positive on both sides. `x^x` is still `NaN` at 0.
351351
| `"(x^2)^x".ToEntity().Limit("x", 0)` | `NaN` | `1` |
352352
| `"(x*x)^(x - 1)".ToEntity().Limit("x", 0)` | `NaN` | `+oo` |
353353

354+
### A 0^0 limit whose l'Hopital chain doubles its powers has its value
355+
356+
**Silent: a different answer.** l'Hopital's rule was turned away where a
357+
quotient grew in nodes, and a chain whose divisor is a reciprocal power, `x^n / (1 / g^k)`, grows in its exponents
358+
instead: the derivative of `1/g^k` is over `g^(2k)`, so k doubled at each step and the chain never ended. The whole
359+
exponents are measured as the nodes are now, with the same room, and the limits below have their value. No issue was
360+
filed; a check of limits against values near the destination found it.
361+
362+
| Input | Was (2.6.0) | Now |
363+
|---|---|---|
364+
| `limitright((log(x, 1/2))^(exp(x) - sgn(x)), x, 0)` | `0` | `1` |
365+
366+
The same spelled `(-ln(2)/ln(x))^(exp(x) - 1)` was `1` in 2.6.0 and did not return after it; it is `1` again.
367+
354368
### A limit of a logarithm that is not decided is left unevaluated
355369

356370
**Not silent: what overflowed the stack now returns.** A limit of a logarithm whose argument has no limit, as

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,23 @@ private static bool AlreadyBeingDifferentiated(Entity quotient)
12641264
/// unchanged at 112/117 and, in total time, within noise of where it was.
12651265
/// </remarks>
12661266
private static bool GrewTooMuch(Entity quotient, Entity applied)
1267-
=> applied.Nodes.Count() > Math.Max(quotient.Nodes.Count() + 8, quotient.Nodes.Count() * 8 / 5);
1267+
=> applied.Nodes.Count() > Math.Max(quotient.Nodes.Count() + 8, quotient.Nodes.Count() * 8 / 5)
1268+
|| WholePowers(applied) > Math.Max(WholePowers(quotient) + 8, WholePowers(quotient) * 8 / 5);
1269+
1270+
/// <summary>
1271+
/// The whole exponents of <paramref name="expr"/>'s powers, added up: the growth a node count does not see.
1272+
/// </summary>
1273+
/// <remarks>
1274+
/// <c>(e^(-1/x) - 1)^12</c> and <c>(e^(-1/x) - 1)^24</c> have the same nodes, and a chain whose divisor is
1275+
/// a reciprocal power, <c>x^n / (1 / g^k)</c>, doubles k at every step, since the derivative of
1276+
/// <c>1/g^k</c> is over <c>g^(2k)</c>: the limit of <c>(-ln(2)/ln(x))^(e^x - 1)</c> at 0 from the right
1277+
/// went 6, 12, 24, ... and did not finish in ten minutes, the inner limits expanding the powers. A
1278+
/// derivative lowers the degrees of a chain that is getting somewhere; so the same room as for the
1279+
/// nodes, the larger of eight more and three fifths again.
1280+
/// </remarks>
1281+
private static int WholePowers(Entity expr)
1282+
=> expr.Nodes.Sum(static node => node is Powf(_, Integer { EInteger: var exponent }) && exponent.CanFitInInt32()
1283+
? Math.Abs(exponent.ToInt32Unchecked()) : 0);
12681284

12691285
[ThreadStatic] private static bool suppresslHopital;
12701286

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 System;
9+
using System.Threading.Tasks;
10+
using AngouriMath.Core;
11+
using Xunit;
12+
using static AngouriMath.Entity;
13+
14+
namespace AngouriMath.Tests.Calculus
15+
{
16+
/// <summary>
17+
/// l'Hopital's rule was turned away where a quotient grew in nodes, and a chain whose divisor is a reciprocal power,
18+
/// <c>x^n / (1 / g^k)</c>, grows in its exponents instead: the derivative of <c>1/g^k</c> is over <c>g^(2k)</c>, so k
19+
/// went 6, 12, 24, ..., and the limit of <c>(-ln(2)/ln(x))^(e^x - 1)</c> at 0 from the right did not finish in ten
20+
/// minutes. It is 1, as 2.6.0 answered; the spelling with <c>log(x, 1/2)</c> and <c>sgn(x)</c>, 2.6.0 answered 0. Found by
21+
/// limitcheck at <c>DEPTH=3</c>, <c>SEED=23</c>; no issue was filed.
22+
/// </summary>
23+
[Trait("Area", "Calculus")]
24+
public sealed class AQuotientWhosePowersGrowIsNotDifferentiatedTest
25+
{
26+
[Theory]
27+
[InlineData("(-ln(2)/ln(x))^(exp(x) - 1)")]
28+
[InlineData("(log(x, 1/2))^(exp(x) - sgn(x))")]
29+
public void IsOneAtZeroFromTheRight(string input)
30+
{
31+
var task = Task.Factory.StartNew(() => MathS.FromString(input).Limit("x", 0, ApproachFrom.Right),
32+
TaskCreationOptions.LongRunning);
33+
// Far from both: the limit takes about 6 s here and past a minute on CI's Windows runner, whose suite runs
34+
// three times as long, and before the fix it did not finish in ten minutes.
35+
Assert.True(task.Wait(TimeSpan.FromMinutes(5)), $"the limit of {input} at 0 from the right did not finish in five minutes");
36+
Assert.Equal(Number.Integer.One, task.Result);
37+
}
38+
39+
[Theory]
40+
[InlineData("1/x^2 - 1/sin(x)^2", "-1/3")]
41+
[InlineData("(1 - cos(x)) / x^2", "1/2")]
42+
[InlineData("x^3 / (x - sin(x))", "6")]
43+
public void AChainThatGetsSomewhereIsAsBefore(string input, string expected)
44+
=> Assert.Equal(MathS.FromString(expected), MathS.FromString(input).Limit("x", 0));
45+
}
46+
}

0 commit comments

Comments
 (0)