Skip to content

Commit 42d1fe9

Browse files
Give a vanishing base to a negative whole power its infinity (#2380)
sin(x)^(-2) at 0 was left unevaluated from each side and was NaN two-sided, where 1/sin(x)^2 was +oo. The power's own rule for a vanishing base took only one that is never negative by its form. A base tending to 0 that is real near the point and keeps a sign there is not 0 near it, 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, +oo or -oo by the sign for an odd one, and two-sided only where both sides agree. The exponent has to be that whole number near the point, not only tend to it, so it is read through Simplify, which is asked only once its limit already is one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent c41c8c5 commit 42d1fe9

4 files changed

Lines changed: 93 additions & 1 deletion

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,19 @@ four parts it is built from.
123123
| `"ln(arctan(x) + x) / ln(x)".ToEntity().Limit("x", "+oo")` | unevaluated | `1` |
124124
| `"tanh(x) * x / (x + tanh(x))".ToEntity().Limit("x", "-oo")` | did not finish in 30 s | `-1` |
125125

126+
### A vanishing base to a negative whole power tends to an infinity
127+
128+
**A real base tending to 0 with a sign, to a negative whole power, is +oo or -oo, where it was NaN.** For an
129+
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
130+
where the two sides disagree. `1/sin(x)^2` already answered +oo; `sin(x)^(-2)` did not.
131+
132+
| Input | Was (2.6.0) | Now |
133+
|---|---|---|
134+
| `"sin(x)^(-2)".ToEntity().Limit("x", 0)` | `NaN` | `+oo` |
135+
| `"sin(x)^(-2)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | `NaN` | `+oo` |
136+
| `"(arcsin(x)^(-2))^2".ToEntity().Limit("x", 0)` | `NaN` | `+oo` |
137+
| `"sin(x)^(-1)".ToEntity().Limit("x", 0, ApproachFrom.Left)` | `NaN` | `-oo` |
138+
126139
### A quotient whose divisor is 0 near the point has no limit there
127140

128141
**A limit of a quotient whose divisor is 0 all the way in is NaN, where it was a number.** `abs(x) - x` is

‎Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,18 @@ partial record Powf
393393
if (baseLimit?.Evaled is Real { IsZero: true } && exponentLimit?.Evaled is Real { IsNegative: true, IsFinite: true }
394394
&& IsNeverNegative(Base, x))
395395
return Real.PositiveInfinity;
396+
// A base that keeps a sign as it vanishes is real and not 0 near the point, so to a
397+
// negative whole power it is 1 over a power tending to 0 from that sign's side: +oo for
398+
// an even power, and +oo or -oo by the sign for an odd one. sin(x)^(-2) at 0 was left
399+
// unevaluated from each side and was NaN two-sided, where 1/sin(x)^2 was +oo.
400+
// The exponent has to be that whole number near the point and not only tend to it, and
401+
// x - 1 - (x + 1) is -2 only once Simplify has cancelled x; it is asked only where the
402+
// exponent's limit already is one.
403+
if (baseLimit?.Evaled is Real { IsZero: true } && exponentLimit?.Evaled is Integer { IsNegative: true }
404+
&& dist.IsFinite
405+
&& (Exponent.ContainsNode(x) ? Exponent.Simplify() : Exponent).Evaled is Integer { IsNegative: true } wholeExponent
406+
&& SignOfAVanishingBase(wholeExponent.EInteger.IsEven) is { } sign)
407+
return sign > 0 ? Real.PositiveInfinity : Real.NegativeInfinity;
396408
var substituted =
397409
(baseLimit, exponentLimit)
398410
switch {
@@ -416,6 +428,31 @@ partial record Powf
416428
&& IsIndeterminatePowerForm(substitutedBase, substitutedExponent))
417429
return null;
418430
return ComputeLimitImpl(substituted, x, dist, side);
431+
432+
// The sign the power keeps near the point, or null where a side's base has no sign
433+
// or, for an odd power, the two sides disagree.
434+
int? SignOfAVanishingBase(bool even)
435+
{
436+
var sides = side is ApproachFrom.BothSides ? new[] { ApproachFrom.Left, ApproachFrom.Right } : new[] { side };
437+
int? sign = null;
438+
foreach (var oneSide in sides)
439+
{
440+
// A sign is a question about a real value: x^x - 1 on the left of 0 is complex,
441+
// and its reciprocal square goes off the real line. Where the base's real region
442+
// is not known, as arcsin's is not, its form can still say it is real there.
443+
if (!Functions.TreeAnalyzer.IsRealValued(Base, x)
444+
&& !(Functions.TreeAnalyzer.WhereRealValued(Base, x) is { } whereReal && HoldsNear(whereReal, x, dist, oneSide) is true)
445+
&& !IsRealOnBothSides(Base, x, dist))
446+
return null;
447+
if (SignNear(Base, x, dist, oneSide) is not { } baseSign)
448+
return null;
449+
var powerSign = even ? 1 : baseSign;
450+
if (sign is { } earlier && earlier != powerSign)
451+
return null;
452+
sign = powerSign;
453+
}
454+
return sign;
455+
}
419456
}
420457
}
421458

‎Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ node is Floorf or Ceilf or Roundf or Signumf
210210
/// and was NaN at 0 where each side is 1. Anything else unlisted is not real, which costs
211211
/// coverage and never correctness.
212212
/// </summary>
213-
private static bool IsRealOnBothSides(Entity expr, Variable x, Entity dest)
213+
internal static bool IsRealOnBothSides(Entity expr, Variable x, Entity dest)
214214
{
215215
if (dest.Evaled is not Real { IsFinite: true })
216216
return false;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// Copyright (c) 2019-2026 Angouri.
3+
// AngouriMath is licensed under MIT.
4+
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
5+
// Website: https://am.angouri.org.
6+
//
7+
8+
using AngouriMath.Core;
9+
using Xunit;
10+
11+
namespace AngouriMath.Tests.Calculus
12+
{
13+
/// <summary>
14+
/// A real base tending to 0 with a sign, to a negative whole power, tends to +oo, or for an odd power
15+
/// to +oo or -oo by the base's sign. sin(x)^(-2) at 0 was left unevaluated from each side and was NaN
16+
/// two-sided, where 1/sin(x)^2 was +oo. Found by limitcheck at SEED=80; no issue was filed.
17+
/// </summary>
18+
[Trait("Area", "Calculus")]
19+
public sealed class AVanishingBaseToANegativeWholePowerTest
20+
{
21+
[Theory]
22+
[InlineData("sin(x)^(-2)", ApproachFrom.BothSides, "+oo")]
23+
[InlineData("sin(x)^(-2)", ApproachFrom.Left, "+oo")]
24+
[InlineData("sin(x)^(-2)", ApproachFrom.Right, "+oo")]
25+
[InlineData("(arcsin(x)^(-2))^2", ApproachFrom.BothSides, "+oo")]
26+
[InlineData("tan(x/2)^((x - 1) - (x + 1))", ApproachFrom.BothSides, "+oo")]
27+
[InlineData("sin(x)^(-1)", ApproachFrom.Left, "-oo")]
28+
[InlineData("sin(x)^(-3)", ApproachFrom.Right, "+oo")]
29+
public void TendsToAnInfinity(string input, ApproachFrom side, string expected)
30+
=> Assert.Equal(MathS.FromString(expected), MathS.FromString(input).Limit("x", 0, side));
31+
32+
// The two sides of an odd power disagree, so there is no two-sided limit.
33+
[Fact]
34+
public void AnOddPowerHasNoTwoSidedLimit()
35+
=> Assert.Equal(MathS.NaN, MathS.FromString("sin(x)^(-1)").Limit("x", 0, ApproachFrom.BothSides));
36+
37+
// An exponent that only tends to a whole number is not one near the point, and is left alone.
38+
[Fact]
39+
public void AnExponentThatOnlyTendsToAWholeNumberIsLeftAlone()
40+
=> Assert.IsType<Entity.Limitf>(MathS.FromString("sin(x)^(x - 2)").Limit("x", 0, ApproachFrom.Right));
41+
}
42+
}

0 commit comments

Comments
 (0)