diff --git a/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs index e45c169eb..3da7303c6 100644 --- a/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs +++ b/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs @@ -1269,7 +1269,11 @@ private static ApproachFrom[] Sides(Entity dest, ApproachFrom side) if (dest.Evaled is Real { IsFinite: false, IsNaN: false } infinity) return SignFromVanishingOrder(expr.Substitute(x, infinity.IsNegative ? -1 / x : 1 / x), x, Integer.Zero, ApproachFrom.Right) ?? SignOfTheFactors(expr, x, dest, side) ?? SignThroughAChangeOfVariable(expr, x, dest, side); - return SignFromVanishingOrder(expr, x, dest, side) ?? SignFromTheSlope(expr, x, dest, side) + // A power is read by its base before its slope: a positive base to a real power is positive, and the base is + // the smaller question. sgn((x * x)^arctan(1/2)) at 0 from the left asked for the slope of the power, which + // l'Hopital's rule took 6.6 s over, for the sign x * x has as a product. + return SignFromVanishingOrder(expr, x, dest, side) + ?? (expr is Powf ? SignOfTheFactors(expr, x, dest, side) : null) ?? SignFromTheSlope(expr, x, dest, side) ?? SignOfTheFactors(expr, x, dest, side) ?? SignThroughAChangeOfVariable(expr, x, dest, side); } diff --git a/Sources/Tests/UnitTests/Calculus/APowerHasTheSignOfItsBaseTest.cs b/Sources/Tests/UnitTests/Calculus/APowerHasTheSignOfItsBaseTest.cs new file mode 100644 index 000000000..9f932ec72 --- /dev/null +++ b/Sources/Tests/UnitTests/Calculus/APowerHasTheSignOfItsBaseTest.cs @@ -0,0 +1,40 @@ +// +// 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 +{ + /// + /// The sign a power keeps near a point is read from its base before its slope: a positive base to a real power is + /// positive. sgn((x * x)^arctan(1/2)) at 0 from the left asked for the slope of the power first, which l'Hopital's + /// rule took 6.6 s over, for 1. Found by limitcheck; no issue was filed. + /// + [Trait("Area", "Calculus")] + public sealed class APowerHasTheSignOfItsBaseTest + { + [Theory] + [InlineData("sgn((x * x) ^ arctan(1/2))", ApproachFrom.Left, "1")] + [InlineData("sgn((x * x) ^ arctan(1/2))", ApproachFrom.BothSides, "1")] + [InlineData("floor((x * x) ^ pi)", ApproachFrom.Left, "0")] + public void TheLimitAtZeroIsAnswered(string input, ApproachFrom side, string expected) + { + var limit = Task.Run(() => input.ToEntity().Limit("x", 0, side)); + Assert.True(limit.Wait(TimeSpan.FromSeconds(30)), $"{input} at 0 from {side} did not finish in 30 seconds"); + Assert.Equal(expected.ToEntity().Evaled, limit.Result.Evaled); + } + + // A negative base to a power that is not whole is complex on that side, and has no sign. + [Fact] + public void AComplexPowerHasNoSign() + => Assert.IsType("sgn((x * x * x) ^ pi)".ToEntity().Limit("x", 0, ApproachFrom.Left)); + } +}