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
13 changes: 13 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// </summary>
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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// 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.
/// </summary>
[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<Entity.Limitf>(MathS.FromString("sin(x)^(x - 2)").Limit("x", 0, ApproachFrom.Right));
}
}
Loading