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
26 changes: 26 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,32 @@ since past about 10^100 an integer times a radical is folded into a rounded deci
| `32768 * 2^(-29/2)` | `32768 * 2 ^ (-29/2)` | `sqrt(2)` |
| `2 / (2^(-29/2) * 32768)` | `1/16384 / 2 ^ (-29/2)` | `sqrt(2)` |

### A power that is not real on the side approached is not read as a real one

**Silent: a wrong infinity becomes an unevaluated limit.** A power of a base that is negative on the side approached,
to an exponent that is not whole there, is not real on that side. Moved out to `+oo`, `x^(x - 1)` at 0 from the left
is `(-1/x)^(-1/x - 1)`, and Gruntz's algorithm found it growing like `e^(-i pi)` times `x` and read the exponential
as positive, answering `+oo`, where the principal value tends to `-oo + i pi` (`-1.0E+20 + 3.1415927i` at
`x = -1e-20`, by mpmath). An exponential is now positive to the algorithm only where its exponent is real, and the
limit is left unevaluated, as `sin(x)^(x - 1)` there already was. So is `x^(x - 2)` there, which was `+oo` and whose
principal value grows in the direction of `+oo` with an imaginary part that grows too, as `sin(x)^(x - 2)` there
already was. `x^x`, `sin(x)^x` and `x^(x - 1) * x` at 0 from the left are still `1`.

A two-sided limit took a side that came back `NaN` to agree with the other side, since the numerical comparison of the two
passes over a point where either is `NaN`. `(x^2 - x)^(x - 1)` at 0 is `+oo` from the left and not real from the right,
and it was `+oo`. It is `NaN`, as `(-x)^x` at 0 is. Measured on master `34d481139` and on this branch
([#2693](https://github.com/asc-community/AngouriMath/issues/2693)).

| `.Limit(x, ...)` | Was (`34d481139`) | Now |
|---|---|---|
| `x^(x - 1)` at 0 from the left | `+oo` | `limitleft(x ^ (x - 1), x, 0)` |
| `(e^x - 1)^(x - 1)` at 0 from the left | `+oo` | unevaluated |
| `x^(x - 2)` at 0 from the left | `+oo` | unevaluated |
| `(x^2 - x)^(x - 1)` at 0 | `+oo` | `NaN` |
| `tan(x)^x * x` at 0 | `0` | `NaN` |
| `x^(1/2 + x) / x` at 0 | `NaN` | unevaluated |
| `x^(x - 1)` at 0 from the right; `x^x`, `x^(x - 1) * x` at 0 from the left | `+oo`; `1`, `1` | unchanged |

### A two-sided limit is NaN only where its sides say so

**Not silent: a wrong answer becomes an unevaluated limit.** A two-sided limit came back `NaN`, the claim that it does
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,13 @@ private static bool IsRealOnTheWay(Entity e, Variable x)
};
if (e == x)
return 1;
if (IsExponential(e, out _))
return 1; // an exponential is positive wherever defined
// An exponential is positive where its exponent is real, and only there: e^(-i pi) is -1. Rewritten in
// the mrv set, x^(x - 1) at 0 from the left, which is (-1/x)^(-1/x - 1) at +oo, leads with
// e^(-(i pi - x) - x) times 1/w, and read as positive it was +oo, where the principal value tends to
// -oo + i pi. https://github.com/asc-community/AngouriMath/issues/2693
if (IsExponential(e, out var exponent))
return IsRealOnTheWay(exponent, x) && !exponent.Nodes.Any(static node => node is Complex and not Real)
? 1 : null;
switch (e)
{
case Mulf(var multiplier, var multiplicand):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,12 @@ node is Derivativef(var expression, Variable variable, var iterations) && iterat

if (fromLeft == fromRight && (acceptNaN || fromLeft.Evaled != MathS.NaN))
return fromLeft;
if (ExpressionNumerical.AreEqual(fromLeft, fromRight) && (acceptNaN || fromLeft.Evaled != MathS.NaN))
// The numerical comparison passes over a point where either side is NaN, so a side that is NaN
// agrees with anything there: (x^2 - x)^(x - 1) at 0 was +oo from the left and 0^(-1) from the
// right, where the base is negative and the power not real, and the two "agreed" on +oo.
// https://github.com/asc-community/AngouriMath/issues/2693
if (fromLeft.Evaled != MathS.NaN && fromRight.Evaled != MathS.NaN
&& ExpressionNumerical.AreEqual(fromLeft, fromRight))
return fromLeft;
if (ApplylHopitalRule(expr, x, dest) is { } lhopital
&& ComputeLimit(lhopital, x, dest, acceptNaN: true) is { } byRule
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// 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 power of a base that is negative on the side approached, to an exponent that is not whole there, is not
/// real on that side, and its limit is not read as though it were. x^(x - 1) at 0 from the left was +oo, where
/// its principal value tends to -oo + i pi (-1.0E+20 + 3.1415927i at x = -1e-20, by mpmath). Moved out to +oo
/// it is (-1/x)^(-1/x - 1), and Gruntz's algorithm found its leading term e^(-(i pi - x) - x) / w and took the
/// exponential for positive, which it is only for a real exponent: e^(-i pi) is -1. It is left unevaluated, as
/// sin(x)^(x - 1) there already is.
/// <para/>
/// Two-sided, the comparison of the sides took a side that was NaN to agree with the other, so the same powers
/// of a base negative on the right of 0 were the left side's +oo.
/// https://github.com/asc-community/AngouriMath/issues/2693
/// </summary>
[Trait("Area", "Calculus")]
public sealed class ANonRealSideIsNotReadAsRealTest
{
[Theory]
[InlineData("x^(x - 1)")]
[InlineData("(e^x - 1)^(x - 1)")]
[InlineData("x^(x - 2)")]
[InlineData("x^(2x - 1)")]
[InlineData("tan(x)^(x - 1)")]
public void Issue2693_IsLeftUnevaluatedFromTheLeft(string input)
=> Assert.IsType<Entity.Limitf>(MathS.FromString(input).Limit("x", 0, ApproachFrom.Left));

// The same powers from the right, where the base is positive and the power real, are +oo as before.
[Theory]
[InlineData("x^(x - 1)")]
[InlineData("(e^x - 1)^(x - 1)")]
[InlineData("x^(x - 2)")]
public void Issue2693_IsPositiveInfinityFromTheRight(string input)
=> Assert.Equal(Entity.Number.Real.PositiveInfinity, MathS.FromString(input).Limit("x", 0, ApproachFrom.Right));

// Two-sided, a side that came back NaN was taken to agree with the other: the numerical comparison of the
// sides passes over a point where either is NaN. (x^2 - x)^(x - 1) at 0 is +oo from the left and not real
// from the right, where the base is negative, and it was +oo; it is NaN, as (-x)^x at 0 is.
[Theory]
[InlineData("(x^2 - x)^(x - 1)")]
[InlineData("(x^2 - x)^(2x - 1)")]
[InlineData("(x^2 - x)^(x - 2) / x")]
public void Issue2693_ASideThatIsNaNDoesNotAgreeWithTheOther(string input)
=> Assert.Equal(MathS.NaN, MathS.FromString(input).Limit("x", 0, ApproachFrom.BothSides));

// A power whose principal value tends to 1 from the left still is 1 there: 1.0 - 3.1415927E-20i at
// x = -1e-20 for x^x, by mpmath. x^(x - 1) * x is the same function, and Gruntz's algorithm answers it.
[Theory]
[InlineData("x^x")]
[InlineData("sin(x)^x")]
[InlineData("x^(-x)")]
[InlineData("x^(x - 1) * x")]
public void Issue2693_AnIndeterminatePowerIsStillReadFromTheLeft(string input)
=> Assert.Equal(Entity.Number.Integer.One, MathS.FromString(input).Limit("x", 0, ApproachFrom.Left));
}
}
Loading