From 7a2515e58294acd668f41a9cbc2176e8bfdbbe5b Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Sat, 5 Dec 2026 19:57:04 +0000 Subject: [PATCH] Leave a limit whose phase keeps turning unevaluated: exp of an exponent off the real line, and gamma along a path off it A constant to a power whose exponent grows was read through the exponent's limit, and an infinite one gave an infinity: ln(x)^2 at -oo is +oo, rightly, and exp(ln(x)^2) there was +oo where its argument 2 pi ln|x| keeps turning. The modulus of b^g is e^Re(g ln b) and its argument Im(g ln b), so the exponent's limit says nothing about the direction. Powf's descent now keeps an infinity for a positive constant base only where the argument settles on an axis: the exponent is real near the point, or what is left once its addends real there are taken out has a finite limit, as pi i in exp(x + pi i), which is -oo. Otherwise it declines, and the routes after it answer where they can: exp((x - 1) ln(x)) at 0 from the left is now -oo, and exp(-ln(x)/2) there -ooi, both +oo before. The gamma function along a path off the real line turns as Im(z) ln|z| by Stirling's formula, so the factorial's descent keeps an infinity only for an argument real near the point, and the Stirling route that answers e^(lim ln H) keeps an infinite one only where the logarithm is real: gamma(x + i) at +oo and gamma(ln(x)) at -oo were +oo. Realness near the point is decided structurally by a new IsRealNear: a power or a logarithm of a base positive there by SignNear, which keeps exp(x^x) and gamma(x^(x/3)) at +oo answered. Of the 6314 limits of the sweep that found this, 18 answers changed: 14 wrong +oo are unevaluated, and so are three two-sided NaN with one turning side and x tanh(ln((1 + 1/x)^x)) at -1, which needed only the modulus. Fixes https://github.com/asc-community/AngouriMath/issues/2708 Co-Authored-By: Claude Opus 5.5 --- BREAKING-CHANGES.md | 32 +++++++ .../Limits/Solvers/Limit.Classes.cs | 92 +++++++++++++++++++ .../Continuous/Limits/Transformations.cs | 8 +- ...haseThatKeepsTurningIsNotADirectionTest.cs | 79 ++++++++++++++++ 4 files changed, 210 insertions(+), 1 deletion(-) create mode 100644 Sources/Tests/UnitTests/Calculus/APhaseThatKeepsTurningIsNotADirectionTest.cs diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index fad9d71b9..af54b96f4 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -757,6 +757,38 @@ and it was `+oo`. It is `NaN`, as `(-x)^x` at 0 is. Measured on master `34d48113 | `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 constant to a power, or a gamma function, whose argument keeps turning has no limit + +**Silent: a wrong `+oo` becomes an unevaluated limit.** The limit of an exponent says how the modulus of `e^g` +grows and nothing about its argument, which is the imaginary part of `g`: `ln(x)^2` at `-oo` is `+oo`, rightly, and +`exp(ln(x)^2)` there was `+oo` where its argument `2 pi ln|x|` keeps turning (arg/pi 0.05, 0.66, -0.74 at +`x = -1e10, -1e11, -1e12`, by mpmath). A constant to a power whose exponent grows now keeps an infinity only where the +argument settles on an axis: the exponent is real near the point, or what is left of it once the addends real there +are taken out has a finite limit, as `pi i` for `exp(x + pi i)`, which is `-oo`. The gamma function along a path off +the real line turns as `Im(z) ln|z|`, and keeps an infinity only for an argument real near the point; +`gamma(x + i/x)` at `+oo`, whose argument does settle, is now left unevaluated with the rest. So are two limits that +need only the modulus: a two-sided limit with one such side, `NaN` before where the other side is `+oo` or `0` and +unevaluated now, as `x^(1/x)` at 0 already was, and `x tanh(ln((1 + 1/x)^x))` at -1, whose tangent tends to 1 for +any argument. Of the 6314 limits of the sweep that found this, 18 answers changed: 14 wrong `+oo` are unevaluated, +and so are the four above, the `NaN`s and the `-1`. Measured on master `409d68805` +and on this branch ([#2708](https://github.com/asc-community/AngouriMath/issues/2708)). + +| `.Limit(x, ...)` | Was (`409d68805`) | Now | +|---|---|---| +| `exp((1 + i) x)`, `exp(x + i)`, `exp(x + i ln(x))`, `2^(x + i)`, `gamma(x + i)` at `+oo` | `+oo` | unevaluated | +| `exp(x + 2 i)` at `+oo` | `-oo` | unevaluated | +| `exp(ln(x)^2)`, `exp(-x ln(x))`, `gamma(ln(x))` at `-oo` | `+oo` | unevaluated | +| `exp(ln(x) / x)`, `exp(ln(x)^2)`, `gamma(-ln(x))` at 0 from the left | `+oo` | unevaluated | +| `gamma(ln(ln(x)))`, `exp(1/x + i)` at 0 from the right | `+oo` | unevaluated | +| `exp((x - 1) ln(x))` at 0 from the left | `+oo` | `-oo` | +| `exp(-ln(x) / 2)` at 0 from the left | `+oo` | `-ooi` | +| `2^(x + pi i / ln(2))` at `+oo` | `+oo` | `-oo` | +| `exp((1 + i) x) / x` at `+oo` | `+oo + +ooi` | unevaluated | +| `gamma(x + i/x)` at `+oo` | `+oo` | unevaluated | +| `exp(ln(x) / x)`, `exp(ln(2 x) / (2 x))`, `exp(ln(sqrt(x)) ln(x))` at 0 | `NaN` | unevaluated | +| `x tanh(ln((1 + 1/x)^x))` at -1 | `-1` | unevaluated | +| `exp(x + pi i)`, `exp(x + i/x)`, `gamma(x)` at `+oo`; `exp(-ln(x))`, `x^(x - 1)` at 0 from the left | `-oo`, `+oo`, `+oo`; `-oo`, `-oo` | unchanged | + ### A limit on a side that is not real is the infinity its direction settles in **Not silent: an unevaluated limit becomes a directed infinity, and a wrong `+oo` becomes an unevaluated limit.** Where diff --git a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs index ed08bf760..04a6f41fb 100644 --- a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs +++ b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs @@ -14,6 +14,45 @@ namespace AngouriMath using static Functions.Algebra.LimitFunctional; partial record Entity { + /// + /// Whether is real near on each side approached, decided + /// structurally: a power to an exponent that is not whole, and a logarithm, of a base and an argument real and + /// positive there, by , a factorial of a real argument, and otherwise + /// or 's + /// condition holding near the point. Not , which counts a constant that is not + /// real as the same on each side, and so reads i ln(x) as real. Unlisted is not real, which costs + /// coverage and never correctness. https://github.com/asc-community/AngouriMath/issues/2708 + /// + internal static bool IsRealNear(Entity expr, Variable x, Entity dist, ApproachFrom side) + { + if (!expr.ContainsNode(x)) + return expr.Evaled is Real { IsNaN: false }; + if (Functions.TreeAnalyzer.IsRealValued(expr, x) + || Functions.TreeAnalyzer.WhereRealValued(expr, x) is { } whereReal + && Sides(dist, side).All(oneSide => HoldsNear(whereReal, x, dist, oneSide) is true)) + return true; + return expr switch + { + Variable => true, + Sumf(var augend, var addend) => Near(augend) && Near(addend), + Minusf(var minuend, var subtrahend) => Near(minuend) && Near(subtrahend), + Mulf(var multiplier, var multiplicand) => Near(multiplier) && Near(multiplicand), + Divf(var dividend, var divisor) => Near(dividend) && Near(divisor), + Powf(var @base, Integer) => Near(@base), + Powf(var @base, var exponent) => Near(@base) && Near(exponent) && Positive(@base), + Logf(var @base, var antilogarithm) => Near(@base) && Near(antilogarithm) && Positive(@base) && Positive(antilogarithm), + Factorialf(var argument) => Near(argument), + Sinf or Cosf or Tanf or Cotanf or Secantf or Cosecantf or Arctanf or Arccotanf or Erff or Erfcf or Erfif + or Sif or Shif => Near(expr.DirectChildren[0]), + Absf => true, + _ => false + }; + bool Near(Entity part) => IsRealNear(part, x, dist, side); + bool Positive(Entity part) + => !part.ContainsNode(x) ? part.Evaled is Real { IsPositive: true } + : Sides(dist, side).All(oneSide => SignNear(part, x, dist, oneSide) is 1); + } + partial record Number { internal override Entity? ComputeLimitDivideEtImpera(Variable x, Entity dist, ApproachFrom side) => this; @@ -598,6 +637,47 @@ partial record Logf partial record Powf { internal override Entity? ComputeLimitDivideEtImpera(Variable x, Entity dist, ApproachFrom side) + => ComputeLimitDivideEtImperaCore(x, dist, side) is var limit + && !Base.ContainsNode(x) && Exponent.ContainsNode(x) + && limit is { Evaled: Complex { IsFinite: false, IsNaN: false } } + ? WhereThePhaseSettles(limit, x, dist, side) + : limit; + + /// + /// An infinity found for a constant to a power that grows, kept only where the argument of the power settles. + /// + /// + /// The modulus of b^g is e^Re(g ln b) and its argument Im(g ln b), so a limit of the exponent + /// in a direction says how the modulus grows and nothing about the argument: ln(x)^2 at -oo is + /// +oo, rightly, and exp(ln(x)^2) was +oo where its argument 2 pi ln|x| keeps turning + /// (arg/pi 0.05, 0.66, -0.74 at x = -1e10, -1e11, -1e12, by mpmath). For a positive base the argument is that of + /// b^v, where v is what is left of the exponent once the addends real near the point are taken out, + /// and it settles where v has a finite limit: exp(x + pi i) at +oo is -oo and + /// exp(x + i/x) is +oo, while exp(x + i) settles off the axes and exp((1 + i) x) turns, + /// and both are left unevaluated. + /// https://github.com/asc-community/AngouriMath/issues/2708 + /// + private Entity? WhereThePhaseSettles(Entity infinity, Variable x, Entity dist, ApproachFrom side) + { + if (Base.Evaled is not Real { IsPositive: true, IsFinite: true }) + return null; + Entity? turning = null; + foreach (var addend in Sumf.LinearChildren(Exponent)) + if (!IsRealNear(addend, x, dist, side)) + turning = turning is null ? addend : turning + addend; + if (turning is null) + return infinity; + if (turning.ComputeLimitDivideEtImpera(x, dist, side) is not { IsFinite: true } settled + || New(Base, settled).Evaled is not Complex { IsFinite: true, IsNaN: false, IsZero: false } direction) + return null; + if (direction.ImaginaryPart.IsZero) + return direction.RealPart.IsNegative ? Real.NegativeInfinity : Real.PositiveInfinity; + if (direction.RealPart.IsZero) + return Complex.Create(Integer.Zero, direction.ImaginaryPart.IsNegative ? Real.NegativeInfinity : Real.PositiveInfinity); + return null; + } + + private Entity? ComputeLimitDivideEtImperaCore(Variable x, Entity dist, ApproachFrom side) { // A base tending to a positive number or to +oo, to a constant real exponent that is // not 0, is continuous there: the power tends to the base's limit to that exponent, @@ -946,6 +1026,18 @@ partial record Factorialf // to an infinity there whose sign depends on the side, so putting the argument's limit in // would only write the pole down. x! at -1 came back (-1)! once that limit arrived as -1. internal override Entity? ComputeLimitDivideEtImpera(Variable x, Entity dist, ApproachFrom side) + => ComputeLimitDivideEtImperaCore(x, dist, side) is var limit + && limit is { Evaled: Complex { IsFinite: false, IsNaN: false } } + && !IsRealNear(Argument, x, dist, side) + ? null + : limit; + + // An infinity is kept only for an argument real near the point. Along a path off the real line the argument of + // z! keeps turning, by Stirling's formula as about Im(z) ln|z|: gamma(x + i) at +oo was +oo where its argument + // is ln(x) (arg/pi 0.72, -0.54, 0.20, 0.40 at x = 10, 100, 1e3, 1e6, by mpmath), and gamma(ln(x)) at -oo, whose + // argument tends to +oo with the imaginary part pi, was +oo too. + // https://github.com/asc-community/AngouriMath/issues/2708 + private Entity? ComputeLimitDivideEtImperaCore(Variable x, Entity dist, ApproachFrom side) { if (ComputeLimitImpl(this, x, dist, side) is { } lim) return lim; diff --git a/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs index 1b10ceae0..d15714581 100644 --- a/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs +++ b/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs @@ -2487,7 +2487,13 @@ static Entity Times(Entity taken, Entity limit) substitutingFactorial = true; try { - if (Settled(ComputeLimit(logarithm, x, toInfinity)) is { } exponent) + // e to an infinite limit of the logarithm is a direction only where the logarithm's + // imaginary part, the argument, settles, which it does where it is real: ln((x + i - 1)!) is + // +oo, and gamma(x + i) was +oo where its argument keeps turning as ln(x). + // https://github.com/asc-community/AngouriMath/issues/2708 + if (Settled(ComputeLimit(logarithm, x, toInfinity)) is { } exponent + && (exponent.Evaled is not Complex { IsFinite: false } + || Entity.IsRealNear(logarithm, x, toInfinity, ApproachFrom.Left))) return MathS.e.Pow(exponent).InnerSimplified; } finally { substitutingFactorial = false; } diff --git a/Sources/Tests/UnitTests/Calculus/APhaseThatKeepsTurningIsNotADirectionTest.cs b/Sources/Tests/UnitTests/Calculus/APhaseThatKeepsTurningIsNotADirectionTest.cs new file mode 100644 index 000000000..6bbbd032a --- /dev/null +++ b/Sources/Tests/UnitTests/Calculus/APhaseThatKeepsTurningIsNotADirectionTest.cs @@ -0,0 +1,79 @@ +// +// 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; +using static AngouriMath.Entity.Number; + +namespace AngouriMath.Tests.Calculus +{ + /// + /// A constant to a power, or a gamma function, whose modulus grows without bound while its argument keeps turning + /// has no direction, and the limit is left unevaluated. The exponent's own limit says how the modulus grows and + /// nothing about the argument: ln(x)^2 at -oo is +oo, and the argument of exp(ln(x)^2) is 2 pi ln|x|. Values by mpmath. + /// https://github.com/asc-community/AngouriMath/issues/2708 + /// + [Trait("Area", "Calculus")] + public sealed class APhaseThatKeepsTurningIsNotADirectionTest + { + // arg/pi of exp((1 + i) x) is x/pi; of exp(x + i ln(x)) ln(x)/pi; of gamma(x + i) 0.72, -0.54, 0.20, 0.40 + // at x = 10, 100, 1e3, 1e6. exp(x + i) settles at 1, off the axes. + [Theory] + [InlineData("exp((1 + i) * x)")] + [InlineData("exp(x + i * ln(x))")] + [InlineData("exp(x + i)")] + [InlineData("2^((1 + i) * x)")] + [InlineData("gamma(x + i)")] + [InlineData("gamma(x + i * ln(x))")] + public void Issue2708_AtPositiveInfinity(string input) + => Assert.IsType(MathS.FromString(input).Limit("x", Real.PositiveInfinity)); + + // arg/pi of exp(ln(x)^2) is 0.05, 0.66, -0.74 at x = -1e10, -1e11, -1e12, and of gamma(ln(x)) -0.88, -0.56, + // -0.26, 0.04 at x = -1e10 ... -1e10000. x^ln(x), the first spelled otherwise, was already left unevaluated. + [Theory] + [InlineData("exp(ln(x)^2)")] + [InlineData("x^ln(x)")] + [InlineData("gamma(ln(x))")] + public void Issue2708_AtNegativeInfinity(string input) + => Assert.IsType(MathS.FromString(input).Limit("x", Real.NegativeInfinity)); + + // arg/pi of exp(ln(x)/x) is 0, 0.91, 0.67, 0.77 at x = -1e-3 ... -1.3e-3; x^(1/x) was already unevaluated. + [Theory] + [InlineData("exp(ln(x) / x)", ApproachFrom.Left)] + [InlineData("x^(1/x)", ApproachFrom.Left)] + [InlineData("exp(ln(x)^2)", ApproachFrom.Left)] + [InlineData("gamma(-ln(x))", ApproachFrom.Left)] + [InlineData("gamma(ln(ln(x)))", ApproachFrom.Right)] + [InlineData("exp(1/x + i/x)", ApproachFrom.Right)] + public void Issue2708_AtZero(string input, ApproachFrom side) + => Assert.IsType(MathS.FromString(input).Limit("x", 0, side)); + + // Where the argument settles on an axis the infinity stays: exp(x + pi i) is -e^x, and exp(x + i/x) has the + // argument 1/x. A gamma function of an argument real on the way is real. + [Theory] + [InlineData("exp(x + pi * i)", "-oo")] + [InlineData("exp(x + i / x)", "+oo")] + [InlineData("gamma(x)", "+oo")] + [InlineData("x!", "+oo")] + public void Issue2708_ASettledDirectionStays(string input, string expected) + => Assert.Equal(MathS.FromString(expected), MathS.FromString(input).Limit("x", Real.PositiveInfinity)); + + [Fact] + public void Issue2708_ASettledImaginaryDirectionStays() + => Assert.Equal(Complex.Create(Integer.Zero, Real.PositiveInfinity), + MathS.FromString("exp(x + pi / 2 * i)").Limit("x", Real.PositiveInfinity)); + + [Theory] + [InlineData("exp(-ln(x))", "-oo")] + [InlineData("exp(-2 * ln(x))", "+oo")] + [InlineData("ln(x)", "-oo")] + [InlineData("x^(x - 1)", "-oo")] + [InlineData("x^(x - 2)", "+oo")] + public void Issue2708_OnTheLeftOfZeroADirectionStays(string input, string expected) + => Assert.Equal(MathS.FromString(expected), MathS.FromString(input).Limit("x", 0, ApproachFrom.Left)); + } +}