Skip to content

Commit 50e9403

Browse files
Read an indeterminate power under a function through its exponent (#2381)
x^x at 0+ is 1, and sin(x^x) there was unevaluated. The rule that reads 0^0 and oo^0 through the exponent, e^(g ln f), was asked only of a whole expression at the top level; the descent substituted the parts' limits, met 0^0, evaluated it to NaN, and the function above it had nothing. The power's descent now asks the same rule of the power, one-sided or at an infinity as the top level asks it, and only where the base is positive on the side approached, so the power is real there. x^x on the left of 0 is complex, and the two-sided limits there stay as they were. Where the rule settles nothing, the pair is substituted as before. sqrt(x) / x^pi + x^x at 0+ is answered +oo by it, which its test said was not answered yet; the row moves to an assertion of the value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 42d1fe9 commit 50e9403

6 files changed

Lines changed: 137 additions & 10 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,22 @@ 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+
### An indeterminate power under a function is read through its exponent
127+
128+
**A limit of a function of an indeterminate power, such as `0^0` or `oo^0`, is answered where the power alone
129+
is.** `x^x` at 0 from the right is 1, and `sin(x^x)` there was NaN or unevaluated, because the rule that reads
130+
a power through its exponent was asked only of a whole expression. It is asked of a power wherever it sits,
131+
one-sided or at an infinity, where the base is positive on the side approached. Two-sided limits with a
132+
complex side, as `x^x` has on the left of 0, are left as they were.
133+
134+
| Input | Was (2.6.0) | Now |
135+
|---|---|---|
136+
| `"sin(x^x)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | `NaN` | `sin(1)` |
137+
| `"cos(x^x)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | `NaN` | `cos(1)` |
138+
| `"sin((x - 1)^ln(x))".ToEntity().Limit("x", 1, ApproachFrom.Right)` | `NaN` | `sin(1)` |
139+
| `"sin(x^(1/x))".ToEntity().Limit("x", "+oo")` | unevaluated | `sin(1)` |
140+
| `"sqrt(x) / x^pi + x^x".ToEntity().Limit("x", 0, ApproachFrom.Right)` | `NaN` | `+oo` |
141+
126142
### A vanishing base to a negative whole power tends to an infinity
127143

128144
**A real base tending to 0 with a sign, to a negative whole power, is +oo or -oo, where it was NaN.** For an

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,24 @@ partial record Powf
405405
&& (Exponent.ContainsNode(x) ? Exponent.Simplify() : Exponent).Evaled is Integer { IsNegative: true } wholeExponent
406406
&& SignOfAVanishingBase(wholeExponent.EInteger.IsEven) is { } sign)
407407
return sign > 0 ? Real.PositiveInfinity : Real.NegativeInfinity;
408+
// An indeterminate pair, 0^0 among them, is read through the exponent, by the rule
409+
// the top level asks of a whole expression and asked of the power here, so that a
410+
// power under a function is read too: x^x at 0+ is 1, and sin(x^x) there was
411+
// unevaluated. One-sided, or at an infinity, as the top level asks it, and only where
412+
// the base is positive on the side approached, so that the power is real there: x^x on
413+
// the left of 0 is complex, and the two-sided limit there stays NaN. Where it settles
414+
// nothing, the pair is substituted as before, and 0^0 stays NaN. Not in the descents
415+
// a two-sided limit compares, where it would settle (-x)^x at 0 and leave x^x NaN, and
416+
// not for the whole of the question, which the path above asks once the descent is done.
417+
if (baseLimit is { } pairBase && exponentLimit is { } pairExponent
418+
&& (side is not ApproachFrom.BothSides || !dist.IsFinite)
419+
&& MayReadAPowerThroughItsExponent(this)
420+
&& (EvalAssumingContinuous(pairBase) == 0 && EvalAssumingContinuous(pairExponent) == 0
421+
|| IsIndeterminatePowerForm(pairBase, pairExponent))
422+
&& (side is ApproachFrom.BothSides ? ApproachFrom.Left : side) is var pairSide
423+
&& SignNear(Base, x, dist, pairSide) is 1
424+
&& SolveAsIndeterminatePower(this, x, dist, pairSide) is { } byExponent)
425+
return byExponent;
408426
var substituted =
409427
(baseLimit, exponentLimit)
410428
switch {

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

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,29 @@ bool PositiveOnBothSides(Entity node)
275275

276276
[System.ThreadStatic] private static int bothSidesDepth;
277277

278+
/// <summary>
279+
/// Whether the descent under way is one of the two a two-sided limit at a finite point
280+
/// compares. A power under it reads 0^0 through its exponent only one-sidedly, and two
281+
/// sides compared that way make (-x)^x at 0 answer 1 where x^x, its mirror, is NaN: the
282+
/// branch each side of the point takes is not this reading's to settle.
283+
/// Cleared for each limit asked inside the descent, which is a question of its own.
284+
/// </summary>
285+
[System.ThreadStatic] private static bool comparingSides;
286+
287+
/// <summary>
288+
/// The expression whose one-sided descent is under way. The one-sided path reads it
289+
/// through its exponent itself once the descent has nothing to say, so the descent does
290+
/// not ask the same question of it first.
291+
/// </summary>
292+
[System.ThreadStatic] private static Entity? descentRoot;
293+
294+
/// <summary>
295+
/// Whether a power met in the descent may read itself through its exponent: neither in
296+
/// a two-sided comparison nor as the whole of a one-sided question.
297+
/// </summary>
298+
internal static bool MayReadAPowerThroughItsExponent(Entity power)
299+
=> !comparingSides && !ReferenceEquals(power, descentRoot);
300+
278301
/// <summary>
279302
/// A logarithm to a base other than e as a quotient of natural logarithms.
280303
/// </summary>
@@ -342,8 +365,14 @@ internal static T WithinABudget<T>(int limits, System.Func<T> compute)
342365
// the work -- which is not a wrong answer but is a slower one, since what it declines
343366
// to collapse the search then has to explore.
344367
var enclosingApproach = EnterApproach(x, dest);
368+
var (outerComparing, outerRoot) = (comparingSides, descentRoot);
369+
(comparingSides, descentRoot) = (false, null);
345370
try { return ComputeLimitWithinApproach(expr, x, dest, side, acceptNaN); }
346-
finally { LeaveApproach(enclosingApproach); }
371+
finally
372+
{
373+
(comparingSides, descentRoot) = (outerComparing, outerRoot);
374+
LeaveApproach(enclosingApproach);
375+
}
347376
}
348377

349378
private static Entity? ComputeLimitWithinApproach(Entity expr, Variable x, Entity dest, ApproachFrom side, bool acceptNaN)
@@ -419,7 +448,10 @@ internal static T WithinABudget<T>(int limits, System.Func<T> compute)
419448
if (side is ApproachFrom.Left or ApproachFrom.Right)
420449
{
421450
expr = WithStepsAtTheirLimits(expr, x, dest, side);
422-
var oneSided = expr.ComputeLimitDivideEtImpera(x, dest, side);
451+
descentRoot = expr;
452+
Entity? oneSided;
453+
try { oneSided = expr.ComputeLimitDivideEtImpera(x, dest, side); }
454+
finally { descentRoot = null; }
423455
if (oneSided is { } found && (acceptNaN || found.Evaled != MathS.NaN))
424456
return oneSided;
425457
// The same rule the two-sided path falls through to, asked with the side it was
@@ -462,7 +494,10 @@ internal static T WithinABudget<T>(int limits, System.Func<T> compute)
462494
{
463495
// just compute limit with no check for left/right equality
464496
// here approach left will be ignored anyways, as dest is infinite number
465-
var atInfinity = expr.ComputeLimitDivideEtImpera(x, dest, ApproachFrom.Left);
497+
descentRoot = expr;
498+
Entity? atInfinity;
499+
try { atInfinity = expr.ComputeLimitDivideEtImpera(x, dest, ApproachFrom.Left); }
500+
finally { descentRoot = null; }
466501
if (atInfinity is { } found && found.Evaled != MathS.NaN)
467502
return found;
468503
// l'Hopital's rule was only ever reached for a finite destination, so the
@@ -520,8 +555,8 @@ internal static T WithinABudget<T>(int limits, System.Func<T> compute)
520555
}
521556
// Each side with its own steps put in: floor(x) ^ x at 0 is 1 from the left and 0
522557
// from the right, and read bare both sides were 1.
523-
else if (WithStepsAtTheirLimits(expr, x, dest, ApproachFrom.Left).ComputeLimitDivideEtImpera(x, dest, ApproachFrom.Left) is { } fromLeft
524-
&& WithStepsAtTheirLimits(expr, x, dest, ApproachFrom.Right).ComputeLimitDivideEtImpera(x, dest, ApproachFrom.Right) is { } fromRight)
558+
else if (DescendComparingSides(ApproachFrom.Left) is { } fromLeft
559+
&& DescendComparingSides(ApproachFrom.Right) is { } fromRight)
525560
{
526561
if (fromLeft == fromRight && (acceptNaN || fromLeft.Evaled != MathS.NaN))
527562
return fromLeft;
@@ -558,6 +593,14 @@ internal static T WithinABudget<T>(int limits, System.Func<T> compute)
558593
}
559594
}
560595
throw new AngouriBugException($"Unresolved enum parameter {side}");
596+
597+
Entity? DescendComparingSides(ApproachFrom oneSide)
598+
{
599+
var stepped = WithStepsAtTheirLimits(expr, x, dest, oneSide);
600+
comparingSides = true;
601+
try { return stepped.ComputeLimitDivideEtImpera(x, dest, oneSide); }
602+
finally { comparingSides = false; }
603+
}
561604
}
562605

563606
internal static Entity? ComputeLimitImpl(Entity expr, Variable x, Entity dist, ApproachFrom side) => dist switch

‎Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ private static Entity EquivalenceRules(Entity expr, Variable x, Entity dest)
3333
&& EvalAssumingContinuous(expr.DirectChildren[0].Limit(x, dest)) == 0
3434
? expr.DirectChildren[0]
3535
: expr;
36-
private static Entity EvalAssumingContinuous(Entity expr) =>
36+
internal static Entity EvalAssumingContinuous(Entity expr) =>
3737
expr.Evaled switch
3838
{
3939
Providedf(var inner, _) => inner,
@@ -498,7 +498,7 @@ private static bool IsRealAlong(Entity expr, Variable x)
498498
/// 1^oo is left to <see cref="ApplySecondRemarkable"/>, which answers it more directly,
499499
/// and 0^oo and oo^oo are not indeterminate at all.
500500
/// </remarks>
501-
private static Entity? SolveAsIndeterminatePower(Entity expr, Variable x, Entity dest, ApproachFrom side)
501+
internal static Entity? SolveAsIndeterminatePower(Entity expr, Variable x, Entity dest, ApproachFrom side)
502502
{
503503
if (expr is not Powf(var @base, var power)
504504
|| !@base.ContainsNode(x) || !power.ContainsNode(x)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
/// An indeterminate power under a function is read through its exponent, as one standing alone is.
15+
/// x^x at 0+ is 1, and sin(x^x) there was unevaluated, because the rule that reads a power through
16+
/// its exponent was asked only of a whole expression. Found by limitcheck at SEED=84; no issue was
17+
/// filed.
18+
/// </summary>
19+
[Trait("Area", "Calculus")]
20+
public sealed class AnIndeterminatePowerUnderAFunctionTest
21+
{
22+
[Theory]
23+
[InlineData("sin(x^x)", "0", ApproachFrom.Right, "sin(1)")]
24+
[InlineData("cos(x^x)", "0", ApproachFrom.Right, "cos(1)")]
25+
[InlineData("sin(x^x + 1)", "0", ApproachFrom.Right, "sin(2)")]
26+
[InlineData("sin(sin(x)^x)", "0", ApproachFrom.Right, "sin(1)")]
27+
[InlineData("sin((x - 1)^ln(x))", "1", ApproachFrom.Right, "sin(1)")]
28+
[InlineData("sin(x^(1/x))", "+oo", ApproachFrom.BothSides, "sin(1)")]
29+
public void IsReadThroughItsExponent(string input, string destination, ApproachFrom side, string expected)
30+
=> Assert.Equal(MathS.FromString(expected), MathS.FromString(input).Limit("x", destination, side));
31+
32+
// The base of x^x is negative on the left of 0, where the power is complex, and the two-sided
33+
// limit there is left as it was.
34+
[Fact]
35+
public void AComplexSideIsNotRead()
36+
{
37+
Assert.Equal(MathS.NaN, MathS.FromString("sin(x^x)").Limit("x", 0, ApproachFrom.BothSides));
38+
Assert.IsType<Entity.Limitf>(MathS.FromString("sin(x^x)").Limit("x", 0, ApproachFrom.Left));
39+
// Its mirror as well: two sides each read through the exponent would settle (-x)^x at 0
40+
// and leave x^x NaN.
41+
Assert.Equal(MathS.NaN, MathS.FromString("(-x)^x").Limit("x", 0, ApproachFrom.BothSides));
42+
Assert.Equal(MathS.NaN, MathS.FromString("arctan((-x)^(2x))").Limit("x", 0, ApproachFrom.BothSides));
43+
}
44+
}
45+
}

‎Sources/Tests/UnitTests/Calculus/AnInfinityIsNotACoefficientTest.cs‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,17 @@ public void LeavesEverythingElseAsItWas()
4646
Assert.Equal(MathS.FromString("+oo"), MathS.FromString("+oo * x").Limit("x", "+oo"));
4747
}
4848

49-
// The values are 1 near 1/2, and +oo near 0 from the right; a coefficient evaluated to NaN answered NaN for
50-
// both. Neither is answered yet, and a declined limit keeps its node.
49+
// The values are 1 near 1/2; a coefficient evaluated to NaN answered NaN. It is not answered yet, and a
50+
// declined limit keeps its node.
5151
[Theory]
5252
[InlineData("1 ^ log(1 - x, x - x)", "1/2", ApproachFrom.BothSides)]
53-
[InlineData("sqrt(x) / x ^ pi + x ^ x", "0", ApproachFrom.Right)]
5453
public void ANaNCoefficientIsNotAnAnswer(string input, string destination, ApproachFrom side)
5554
=> Assert.IsType<Entity.Limitf>(MathS.FromString(input).Limit("x", destination, side));
55+
56+
// The values are +oo near 0 from the right, where a coefficient evaluated to NaN answered NaN too. It is
57+
// answered since x ^ x, an indeterminate power in a sum, is read through its exponent.
58+
[Fact]
59+
public void ANaNCoefficientInASumWithAnIndeterminatePower()
60+
=> Assert.Equal(MathS.FromString("+oo"), MathS.FromString("sqrt(x) / x ^ pi + x ^ x").Limit("x", 0, ApproachFrom.Right));
5661
}
5762
}

0 commit comments

Comments
 (0)