diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 4e4139896..06d2305fe 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -123,6 +123,19 @@ four parts it is built from. | `"ln(arctan(x) + x) / ln(x)".ToEntity().Limit("x", "+oo")` | unevaluated | `1` | | `"tanh(x) * x / (x + tanh(x))".ToEntity().Limit("x", "-oo")` | did not finish in 30 s | `-1` | +### A vanishing base to a negative whole power tends to an infinity + +**A real base tending to 0 with a sign, to a negative whole power, is +oo or -oo, where it was NaN.** For an +even power the limit is +oo; for an odd one it is +oo or -oo by the base's sign, and two-sided it is NaN only +where the two sides disagree. `1/sin(x)^2` already answered +oo; `sin(x)^(-2)` did not. + +| Input | Was (2.6.0) | Now | +|---|---|---| +| `"sin(x)^(-2)".ToEntity().Limit("x", 0)` | `NaN` | `+oo` | +| `"sin(x)^(-2)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | `NaN` | `+oo` | +| `"(arcsin(x)^(-2))^2".ToEntity().Limit("x", 0)` | `NaN` | `+oo` | +| `"sin(x)^(-1)".ToEntity().Limit("x", 0, ApproachFrom.Left)` | `NaN` | `-oo` | + ### A quotient whose divisor is 0 near the point has no limit there **A limit of a quotient whose divisor is 0 all the way in is NaN, where it was a number.** `abs(x) - x` is diff --git a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs index 8f379938b..35ee63d07 100644 --- a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs +++ b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs @@ -393,6 +393,18 @@ partial record Powf if (baseLimit?.Evaled is Real { IsZero: true } && exponentLimit?.Evaled is Real { IsNegative: true, IsFinite: true } && IsNeverNegative(Base, x)) return Real.PositiveInfinity; + // A base that keeps a sign as it vanishes is real and not 0 near the point, so to a + // negative whole power it is 1 over a power tending to 0 from that sign's side: +oo for + // an even power, and +oo or -oo by the sign for an odd one. sin(x)^(-2) at 0 was left + // unevaluated from each side and was NaN two-sided, where 1/sin(x)^2 was +oo. + // The exponent has to be that whole number near the point and not only tend to it, and + // x - 1 - (x + 1) is -2 only once Simplify has cancelled x; it is asked only where the + // exponent's limit already is one. + if (baseLimit?.Evaled is Real { IsZero: true } && exponentLimit?.Evaled is Integer { IsNegative: true } + && dist.IsFinite + && (Exponent.ContainsNode(x) ? Exponent.Simplify() : Exponent).Evaled is Integer { IsNegative: true } wholeExponent + && SignOfAVanishingBase(wholeExponent.EInteger.IsEven) is { } sign) + return sign > 0 ? Real.PositiveInfinity : Real.NegativeInfinity; var substituted = (baseLimit, exponentLimit) switch { @@ -416,6 +428,31 @@ partial record Powf && IsIndeterminatePowerForm(substitutedBase, substitutedExponent)) return null; return ComputeLimitImpl(substituted, x, dist, side); + + // The sign the power keeps near the point, or null where a side's base has no sign + // or, for an odd power, the two sides disagree. + int? SignOfAVanishingBase(bool even) + { + var sides = side is ApproachFrom.BothSides ? new[] { ApproachFrom.Left, ApproachFrom.Right } : new[] { side }; + int? sign = null; + foreach (var oneSide in sides) + { + // A sign is a question about a real value: x^x - 1 on the left of 0 is complex, + // and its reciprocal square goes off the real line. Where the base's real region + // is not known, as arcsin's is not, its form can still say it is real there. + if (!Functions.TreeAnalyzer.IsRealValued(Base, x) + && !(Functions.TreeAnalyzer.WhereRealValued(Base, x) is { } whereReal && HoldsNear(whereReal, x, dist, oneSide) is true) + && !IsRealOnBothSides(Base, x, dist)) + return null; + if (SignNear(Base, x, dist, oneSide) is not { } baseSign) + return null; + var powerSign = even ? 1 : baseSign; + if (sign is { } earlier && earlier != powerSign) + return null; + sign = powerSign; + } + return sign; + } } } diff --git a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs index 768487a25..a0f59dfd6 100644 --- a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs +++ b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs @@ -210,7 +210,7 @@ node is Floorf or Ceilf or Roundf or Signumf /// and was NaN at 0 where each side is 1. Anything else unlisted is not real, which costs /// coverage and never correctness. /// - private static bool IsRealOnBothSides(Entity expr, Variable x, Entity dest) + internal static bool IsRealOnBothSides(Entity expr, Variable x, Entity dest) { if (dest.Evaled is not Real { IsFinite: true }) return false; diff --git a/Sources/Tests/UnitTests/Calculus/AVanishingBaseToANegativeWholePowerTest.cs b/Sources/Tests/UnitTests/Calculus/AVanishingBaseToANegativeWholePowerTest.cs new file mode 100644 index 000000000..7e3577087 --- /dev/null +++ b/Sources/Tests/UnitTests/Calculus/AVanishingBaseToANegativeWholePowerTest.cs @@ -0,0 +1,42 @@ +// +// 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 AngouriMath.Core; +using Xunit; + +namespace AngouriMath.Tests.Calculus +{ + /// + /// A real base tending to 0 with a sign, to a negative whole power, tends to +oo, or for an odd power + /// to +oo or -oo by the base's sign. sin(x)^(-2) at 0 was left unevaluated from each side and was NaN + /// two-sided, where 1/sin(x)^2 was +oo. Found by limitcheck at SEED=80; no issue was filed. + /// + [Trait("Area", "Calculus")] + public sealed class AVanishingBaseToANegativeWholePowerTest + { + [Theory] + [InlineData("sin(x)^(-2)", ApproachFrom.BothSides, "+oo")] + [InlineData("sin(x)^(-2)", ApproachFrom.Left, "+oo")] + [InlineData("sin(x)^(-2)", ApproachFrom.Right, "+oo")] + [InlineData("(arcsin(x)^(-2))^2", ApproachFrom.BothSides, "+oo")] + [InlineData("tan(x/2)^((x - 1) - (x + 1))", ApproachFrom.BothSides, "+oo")] + [InlineData("sin(x)^(-1)", ApproachFrom.Left, "-oo")] + [InlineData("sin(x)^(-3)", ApproachFrom.Right, "+oo")] + public void TendsToAnInfinity(string input, ApproachFrom side, string expected) + => Assert.Equal(MathS.FromString(expected), MathS.FromString(input).Limit("x", 0, side)); + + // The two sides of an odd power disagree, so there is no two-sided limit. + [Fact] + public void AnOddPowerHasNoTwoSidedLimit() + => Assert.Equal(MathS.NaN, MathS.FromString("sin(x)^(-1)").Limit("x", 0, ApproachFrom.BothSides)); + + // An exponent that only tends to a whole number is not one near the point, and is left alone. + [Fact] + public void AnExponentThatOnlyTendsToAWholeNumberIsLeftAlone() + => Assert.IsType(MathS.FromString("sin(x)^(x - 2)").Limit("x", 0, ApproachFrom.Right)); + } +}