From bf5717dc5cace3234f91dc3f085e4386ba115dab Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Wed, 11 Nov 2026 17:47:20 +0000 Subject: [PATCH] Read a power of a positive limit to a constant exponent by continuity in a limit A base tending to a positive number or to +oo, to a constant real exponent that is not 0, is continuous there, so the power's limit is the base's limit to that exponent. The descent asked the whole power first, which simplifies it, and Simplify expands the power: (x + 1 + i / ln(x))^(-16) at +oo took 7.8 s and ^(-24) more than 30 s, for 0. Both now take about 0.16 s. Co-Authored-By: Claude Opus 5.5 --- .../Limits/Solvers/Limit.Classes.cs | 10 +++++ .../APowerOfAPositiveLimitIsContinuousTest.cs | 43 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 Sources/Tests/UnitTests/Calculus/APowerOfAPositiveLimitIsContinuousTest.cs diff --git a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs index 6179c9e30..f1a6149a8 100644 --- a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs +++ b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs @@ -462,6 +462,16 @@ partial record Powf { internal override Entity? ComputeLimitDivideEtImpera(Variable x, Entity dist, ApproachFrom side) { + // A base tending to a positive number or to +oo, to a constant real exponent that is + // not 0, is continuous there: the power tends to the base's limit to that exponent, + // and nothing about the whole has to be read. Asking the whole first simplifies it, + // and Simplify expands the power: (x + 1 + i / ln(x))^(-16) at +oo, which is 0, took + // 7.8 s for it. + if (!Exponent.ContainsNode(x) && Exponent.Evaled is Real { IsFinite: true, IsZero: false } + && Base.ComputeLimitDivideEtImpera(x, dist, side) is { } positiveBaseLimit + && positiveBaseLimit.Evaled is Real { IsPositive: true } positiveBase + && (positiveBase.IsFinite || positiveBase == Real.PositiveInfinity)) + return ComputeLimitImpl(New(positiveBaseLimit, Exponent), x, dist, side); if (ComputeLimitImpl(this, x, dist, side) is { } lim) return lim; var baseLimit = Base.ComputeLimitDivideEtImpera(x, dist, side); diff --git a/Sources/Tests/UnitTests/Calculus/APowerOfAPositiveLimitIsContinuousTest.cs b/Sources/Tests/UnitTests/Calculus/APowerOfAPositiveLimitIsContinuousTest.cs new file mode 100644 index 000000000..1b58c9ee5 --- /dev/null +++ b/Sources/Tests/UnitTests/Calculus/APowerOfAPositiveLimitIsContinuousTest.cs @@ -0,0 +1,43 @@ +// +// 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 +{ + /// + /// A base tending to a positive number or to +oo, to a constant real exponent, is continuous, and the power's + /// limit is read from the base's. The whole power was simplified first, and Simplify expands it: + /// (x + 1 + i / ln(x))^(-16) at +oo took 7.8 s, and to the power -24 more than 30 s, for 0. + /// Found by limitcheck; no issue was filed. + /// + [Trait("Area", "Calculus")] + public sealed class APowerOfAPositiveLimitIsContinuousTest + { + [Theory] + [InlineData("(x + 1 + i / ln(x)) ^ (-32)", "0")] + [InlineData("(x + 1 + i / ln(x)) ^ 32", "+oo")] + [InlineData("((x + 1) - log(x, -1)) ^ (2 ^ 3 * (-1 + -1))", "0")] + public void TheLimitAtInfinityIsAnswered(string input, string expected) + { + var limit = Task.Run(() => input.ToEntity().Limit("x", "+oo", ApproachFrom.BothSides)); + Assert.True(limit.Wait(TimeSpan.FromSeconds(30)), $"{input} at +oo did not finish in 30 seconds"); + Assert.Equal(expected.ToEntity().Evaled, limit.Result.Evaled); + } + + [Theory] + [InlineData("(2 + 1 / x) ^ (-3)", "1/8")] + [InlineData("(4 + i / ln(x)) ^ (1/2)", "2")] + [InlineData("(x + 1 + i / ln(x)) ^ (-1/2)", "0")] + public void APositiveOrInfiniteBaseLimitIsRaisedToTheExponent(string input, string expected) + => Assert.Equal(expected.ToEntity().Evaled, input.ToEntity().Limit("x", "+oo", ApproachFrom.BothSides).Evaled); + } +}