Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1780,7 +1780,19 @@ private static bool IsIndeterminateQuotient(Entity numerator, Entity denominator
// input. Into the denominator it gives ln(x) / (cos(x) / sin(x)), which is oo/oo
// and which the rule settles at 0.
var (restNumerator, restDenominator) = SplitProduct(rest);
// At an infinity a power of the variable is the one exception, and it is inverted instead: its
// reciprocal is another power, which differentiating lowers, where the reciprocal of the vanishing
// factor squares it on every step. 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; written ln(1 - 1 / x) / x^(-2) it is settled in one. A
// vanishing factor that leaves the reals keeps the old arrangement: over the power,
// (sqrt(x) - erf(x)) / x at 0 from the left, which reaches here at +oo with sqrt(-1 / x) in it, came
// out a directed complex infinity rather than unevaluated.
if (!dest.IsFinite && IsAPowerOfTheVariable(infinity, x) && !LeavesTheRealsOnTheApproach(zero, x, dest, side))
return restNumerator * zero / (restDenominator * (1 / infinity)).InnerSimplified;
return restNumerator * infinity / (restDenominator * (1 / zero)).InnerSimplified;

static bool IsAPowerOfTheVariable(Entity factor, Variable x)
=> factor == x || factor is Powf(var @base, Number) && @base == x;
}

/// <remarks>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// Copyright (c) 2019-2026 Angouri.
// AngouriMath is licensed under MIT.
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
// Website: https://am.angouri.org.
//

using System;
using System.Threading.Tasks;
using AngouriMath.Core;
using AngouriMath.Extensions;
using Xunit;

namespace AngouriMath.Tests.Calculus
{
/// <summary>
/// l'Hopital's rule read a product of a power of the variable and a vanishing factor as the power over the
/// reciprocal of that factor, which differentiating makes worse on every step: 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, and (-1 - x) / log(x, 2)^(x - 1) at 1
/// from the left reaches it and took six. Found by limitcheck; no issue was filed.
/// </summary>
[Trait("Area", "Calculus")]
public sealed class APowerOfTheVariableIsInvertedTest
{
[Theory]
[InlineData("x^2 * ln(1 - 1 / x)", "+oo", ApproachFrom.BothSides, "-oo")]
[InlineData("ln(1 + 1 / x) * ln(1 / x)", "+oo", ApproachFrom.BothSides, "0")]
[InlineData("(x - 1) * ln(ln(2) / ln(x))", "1", ApproachFrom.Left, "0")]
[InlineData("(ln(2) / ln(x))^(x - 1)", "1", ApproachFrom.Left, "1")]
public void TheProductFinishes(string input, string at, ApproachFrom side, string expected)
{
Entity? limit = null;
var task = Task.Factory.StartNew(() => limit = input.ToEntity().Limit("x", at, side), TaskCreationOptions.LongRunning);
Assert.True(task.Wait(TimeSpan.FromSeconds(30)), "the limit did not finish in 30 seconds");
Assert.Equal(expected.ToEntity(), limit);
}

// Products of a power and a vanishing factor, at a finite point and at infinity, and the remarkable limits.
[Theory]
[InlineData("x * ln(1 + 1 / x)", "+oo", "1")]
[InlineData("x * log(2, 1 + 1 / x)", "+oo", "1 / ln(2)")]
[InlineData("x^2 * (1 - cos(1 / x))", "+oo", "1/2")]
[InlineData("x^4 * e^(-x)", "+oo", "0")]
[InlineData("x^(-2) * (1 - cos(x))", "0", "1/2")]
[InlineData("ln(1 + x) / x", "0", "1")]
[InlineData("ln(x) / (x - 1)", "1", "1")]
public void TheLimitStillHolds(string input, string at, string expected)
=> Assert.Equal(expected.ToEntity().Simplify(), input.ToEntity().Limit("x", at).Simplify());
}
}
Loading