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); + } +}