Skip to content

Commit a9c0191

Browse files
Invert a power of the variable in a product l'Hopital's rule reads at infinity (#2404)
Invert a power of the variable in a product l'Hopital's rule reads at infinity A product of something vanishing and something diverging is written as a quotient before l'Hopital's rule reads it, the diverging factor on top and the reciprocal of the vanishing one underneath. Where the diverging factor is a power of the variable, that arrangement grows on every step: the reciprocal of the vanishing factor squares it under differentiation, so x^2 * ln(1 - 1 / x) at +oo went to x^3 * ln(1 - 1 / x)^2, then x^4 * ln(1 - 1 / x)^3, for three seconds before answering -oo. The power is inverted instead at an infinity, where its reciprocal is another power that differentiating lowers. A vanishing factor that leaves the reals on the approach keeps the old arrangement. (sqrt(x) - erf(x)) / x at 0 from the left reaches here at +oo with sqrt(-1 / x) in it, and over the power came out a directed complex infinity where it is left unevaluated. Faster, with the same answers: x^2 * ln(1 - 1 / x) at +oo 3.1 s to 0.19 s; (-1 - x) / log(x, 2)^(x - 1) at 1 from the left 6.0 s to 1.6 s, which is 2.6.0's time again; sinh((x - 1)^ln(x)) at 1 from the right 2.0 s to 0.6 s; ln(1 + 1 / x) * ln(1 / x) at +oo 2.1 s to 0.5 s. And some that were declined are answered, because the inverted quotient differentiates to something the rule can read: x^2 * (1 - cos(1 / x)) at +oo is 1/2, x * abs(2 / x) at +oo and -oo is 2 and -2, log(x, x^3 / abs(x)) at 0 from the right is 2, and log(2 * (-1)^x, arcsin(x) / (2 * x)) at 0 is -1, where master said NaN. 2.6.0 answers none of them. tanh(log(arcsin(x), x)) at 0 from the left is slower, 2.8 s to 6.7 s, same answer (2.6.0 declines it after 11 s): x^3 * arccsc(-x) inside it is now differentiated, and the caller declines the result. Only inverting where the old arrangement would differentiate too gave that time back, and lost x^2 * (1 - cos(1 / x)). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent e8b0995 commit a9c0191

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,7 +1780,19 @@ private static bool IsIndeterminateQuotient(Entity numerator, Entity denominator
17801780
// input. Into the denominator it gives ln(x) / (cos(x) / sin(x)), which is oo/oo
17811781
// and which the rule settles at 0.
17821782
var (restNumerator, restDenominator) = SplitProduct(rest);
1783+
// At an infinity a power of the variable is the one exception, and it is inverted instead: its
1784+
// reciprocal is another power, which differentiating lowers, where the reciprocal of the vanishing
1785+
// factor squares it on every step. x^2 * ln(1 - 1 / x) at +oo went to x^3 * ln(1 - 1 / x)^2, then
1786+
// x^4 * ln(1 - 1 / x)^3, for three seconds; written ln(1 - 1 / x) / x^(-2) it is settled in one. A
1787+
// vanishing factor that leaves the reals keeps the old arrangement: over the power,
1788+
// (sqrt(x) - erf(x)) / x at 0 from the left, which reaches here at +oo with sqrt(-1 / x) in it, came
1789+
// out a directed complex infinity rather than unevaluated.
1790+
if (!dest.IsFinite && IsAPowerOfTheVariable(infinity, x) && !LeavesTheRealsOnTheApproach(zero, x, dest, side))
1791+
return restNumerator * zero / (restDenominator * (1 / infinity)).InnerSimplified;
17831792
return restNumerator * infinity / (restDenominator * (1 / zero)).InnerSimplified;
1793+
1794+
static bool IsAPowerOfTheVariable(Entity factor, Variable x)
1795+
=> factor == x || factor is Powf(var @base, Number) && @base == x;
17841796
}
17851797

17861798
/// <remarks>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 AngouriMath.Extensions;
12+
using Xunit;
13+
14+
namespace AngouriMath.Tests.Calculus
15+
{
16+
/// <summary>
17+
/// l'Hopital's rule read a product of a power of the variable and a vanishing factor as the power over the
18+
/// reciprocal of that factor, which differentiating makes worse on every step: x^2 * ln(1 - 1 / x) at +oo went to
19+
/// x^3 * ln(1 - 1 / x)^2, then x^4 * ln(1 - 1 / x)^3, for three seconds, and (-1 - x) / log(x, 2)^(x - 1) at 1
20+
/// from the left reaches it and took six. Found by limitcheck; no issue was filed.
21+
/// </summary>
22+
[Trait("Area", "Calculus")]
23+
public sealed class APowerOfTheVariableIsInvertedTest
24+
{
25+
[Theory]
26+
[InlineData("x^2 * ln(1 - 1 / x)", "+oo", ApproachFrom.BothSides, "-oo")]
27+
[InlineData("ln(1 + 1 / x) * ln(1 / x)", "+oo", ApproachFrom.BothSides, "0")]
28+
[InlineData("(x - 1) * ln(ln(2) / ln(x))", "1", ApproachFrom.Left, "0")]
29+
[InlineData("(ln(2) / ln(x))^(x - 1)", "1", ApproachFrom.Left, "1")]
30+
public void TheProductFinishes(string input, string at, ApproachFrom side, string expected)
31+
{
32+
Entity? limit = null;
33+
var task = Task.Factory.StartNew(() => limit = input.ToEntity().Limit("x", at, side), TaskCreationOptions.LongRunning);
34+
Assert.True(task.Wait(TimeSpan.FromSeconds(30)), "the limit did not finish in 30 seconds");
35+
Assert.Equal(expected.ToEntity(), limit);
36+
}
37+
38+
// Products of a power and a vanishing factor, at a finite point and at infinity, and the remarkable limits.
39+
[Theory]
40+
[InlineData("x * ln(1 + 1 / x)", "+oo", "1")]
41+
[InlineData("x * log(2, 1 + 1 / x)", "+oo", "1 / ln(2)")]
42+
[InlineData("x^2 * (1 - cos(1 / x))", "+oo", "1/2")]
43+
[InlineData("x^4 * e^(-x)", "+oo", "0")]
44+
[InlineData("x^(-2) * (1 - cos(x))", "0", "1/2")]
45+
[InlineData("ln(1 + x) / x", "0", "1")]
46+
[InlineData("ln(x) / (x - 1)", "1", "1")]
47+
public void TheLimitStillHolds(string input, string at, string expected)
48+
=> Assert.Equal(expected.ToEntity().Simplify(), input.ToEntity().Limit("x", at).Simplify());
49+
}
50+
}

0 commit comments

Comments
 (0)