From 3066da5921407d7c939bb05bf8f6d58afb52b853 Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Mon, 9 Nov 2026 02:55:26 +0000 Subject: [PATCH] Read a real power of a vanishing function in a limit by its order A power g^a to an exponent that is not an integer, of a g tending to 0 or +oo, had no reading against a logarithm unless g was x itself: x^pi ln(x) at 0 from the right was 0, while sin(x)^pi ln(x), and even (2x)^pi ln(x), were left unevaluated, and ln(x) / (2x)^(-pi) took fifteen seconds to be. As a factor of the product or quotient the expression is, g^a is x^(k a) times (g / x^k)^a, where k, the limit of x g' / g, is the power of x that g behaves like. The second part tends to a positive number, which is taken out of the limit, and what is left is a power of x against the rest. Only a factor is rewritten: in a sum, the part taken out is the whole of the answer. A base tending to -oo is not read: its real power is complex, and asking for its order took a decline that master gives in 0.3 s to 17.6 s. Found by limitcheck; no issue was filed. Co-Authored-By: Claude Opus 5.5 --- BREAKING-CHANGES.md | 22 +++++++ .../Continuous/Limits/Transformations.cs | 54 ++++++++++++++++ .../Calculus/APowerIsReadByItsOrderTest.cs | 61 +++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 Sources/Tests/UnitTests/Calculus/APowerIsReadByItsOrderTest.cs diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 8951d8dec..fc7a12241 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -107,6 +107,28 @@ filed. | `"floor(log(x - 1, x))".ToEntity().Limit("x", 1, ApproachFrom.Right)` | `limitright(floor(log(x - 1, x)), x, 1)` | `-1` | | `"floor(x / log(x, x))".ToEntity().Limit("x", 0, ApproachFrom.Left)` | `limitleft(floor(x / log(x, x)), x, 0)` | `-1` | +### A real power in a limit is read by its order + +**Silent: in a limit, a factor `g^a` with `a` a constant that is not an integer, and `g` tending to 0 or to +oo, is read +as `x^(k a)` times `(g / x^k)^a`, where `k` is the power of `x` that `g` behaves like.** The second part tends to a +positive number and is taken out of the limit, so the power left is one of `x` itself, which the other readings already +answer. A non-integer power of anything but `x` was not read at all, so even `(2x)^pi ln(x)` at 0 was left unevaluated, +and `ln(x) / (2x)^(-pi)` took 15 seconds to be. Only a factor of a product or a quotient is read this way, so a power +inside a sum is left alone, and a base tending to -oo, whose real power is complex, is not read either. Found by +limitcheck; no issue was filed. + +| Input | Was (2.6.0) | Now | +|---|---|---| +| `"sin(x)^pi * ln(x)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | `limitright(sin(x) ^ pi * ln(x), x, 0)` | `0` | +| `"(2x)^pi * ln(x)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | `limitright((2 * x) ^ pi * ln(x), x, 0)` | `0` | +| `"sqrt(sin(x)) * ln(x)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | `limitright(sqrt(sin(x)) * ln(x), x, 0)` | `0` | +| `"ln(x) / (2x)^(-pi)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | `limitright(ln(x) / (2 * x) ^ (-pi), x, 0)` | `0` | +| `"sin(sin(x)^pi * ln(x))".ToEntity().Limit("x", 0, ApproachFrom.Right)` | `limitright(sin(sin(x) ^ pi * ln(x)), x, 0)` | `0` | +| `"sin(x)^pi / x^pi".ToEntity().Limit("x", 0, ApproachFrom.Right)` | `limitright(sin(x) ^ pi / x ^ pi, x, 0)` | `1` | +| `"(x^2 + 1)^(1/pi) / x^(2/pi)".ToEntity().Limit("x", "+oo")` | `limit((x ^ 2 + 1) ^ (1 / pi) / x ^ (2 / pi), x, +oo)` | `1` | +| `"sqrt(arctan(1)) / (1/2 / x)^sinh(pi)".ToEntity().Limit("x", "+oo")` | `limit(sqrt(arctan(1)) / (1/2 / x) ^ ((e ^ pi - e ^ (-pi)) / 2), x, +oo)` | `+oo` | +| `"x / (1/2) / (x + 1)^pi".ToEntity().Limit("x", -1, ApproachFrom.Right)` | `limitright(x / (1/2) / (x + 1) ^ pi, x, -1)` | `-oo` | + ### The sign of a limit is read through a change of variable **Silent: in a limit, where the variable is only inside one part `u` of an expression `h(u)`, the expression's sign near diff --git a/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs index f64f938b8..bd871eafb 100644 --- a/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs +++ b/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs @@ -2030,6 +2030,10 @@ static Entity Times(Entity taken, Entity limit) && Settled(extracted.ComputeLimitDivideEtImpera(x, toInfinity, ApproachFrom.Left)) is { } byGrowth) return byGrowth; + if (FactorPowersByTheirOrder(simplified, x) is var (byOrder, coefficient) + && Settled(ComputeLimit(byOrder, x, toInfinity)) is { } byItsOrder) + return (coefficient * byItsOrder).InnerSimplified; + // A factorial's logarithm has no reading anywhere else -- every route out of // ln(f) differentiates f, and a factorial's derivative wants the digamma // function. SolveAsIndeterminatePower reaches the ones sitting under a @@ -2110,6 +2114,56 @@ Entity RewriteRoot(Entity node) } } + /// + /// The expression with every factor g^a of it -- a factor of the product or the quotient it is -- to a + /// constant exponent that is not an integer, of a g tending to 0 or an infinity, replaced by + /// x^(k a), and the product of the limits L^a of what was taken out; or if + /// there is no such factor. k is the limit of x g' / g, the power of x that g behaves like, + /// taken where it is rational, and L is the limit of g / x^k, taken where it is a positive number. + /// sin(x)^pi ln(x) at 0 from the right is sin(1/x)^pi ln(1/x) here, and nothing read a power of + /// sin(1/x) alongside a logarithm, while it is (x sin(1/x))^pi, which tends to 1, times + /// x^(-pi) ln(1/x), which tends to 0. + /// + /// + /// A factor tending to a positive number can be taken out of a limit, and (uv)^a = u^a v^a needs u + /// positive, which x^k is on the way to +oo, the only direction this is used in. Only a factor: inside a + /// sum, sin(x)^pi - x^pi, the part taken out is the whole of the answer. + /// + private static (Entity Rewritten, Entity Coefficient)? FactorPowersByTheirOrder(Entity expr, Variable x) + { + Entity coefficient = Integer.One; + var rewritten = Factor(expr, inDivisor: false); + return rewritten == expr ? null : (rewritten, coefficient); + + Entity Factor(Entity node, bool inDivisor) + { + switch (node) + { + case Mulf(var left, var right): + return Factor(left, inDivisor) * Factor(right, inDivisor); + case Divf(var dividend, var divisor): + return Factor(dividend, inDivisor) / Factor(divisor, !inDivisor); + case Powf(var @base, var exponent) when @base.ContainsNode(x) && @base != x + && !exponent.ContainsNode(x) && exponent.Evaled is Real { IsFinite: true } and not Integer: + var baseLimit = ComputeLimit(@base, x, Real.PositiveInfinity); + // Only a base tending to 0 or to +oo: a real power of a negative base is + // complex, and the limits below are too dear to ask for one. + if (InfiniteSign(baseLimit) != 1 && (baseLimit is null || EvalAssumingContinuous(baseLimit) is not Complex { IsZero: true })) + return node; + if (ComputeLimit(x * @base.Differentiate(x) / @base, x, Real.PositiveInfinity) is not { } orderLimit + || EvalAssumingContinuous(orderLimit) is not Rational order || order == 0) + return node; + if (ComputeLimit(@base / MathS.Pow(x, order), x, Real.PositiveInfinity) is not { } limit + || EvalAssumingContinuous(limit) is not Real { IsFinite: true, IsNegative: false } positive || positive == 0) + return node; + coefficient = inDivisor ? coefficient / MathS.Pow(limit, exponent) : coefficient * MathS.Pow(limit, exponent); + return MathS.Pow(x, order * exponent); + default: + return node; + } + } + } + /// /// How many times a single limit may be broken down as a difference of two divergent /// parts. The conjugate below turns one difference into another, and every part of it diff --git a/Sources/Tests/UnitTests/Calculus/APowerIsReadByItsOrderTest.cs b/Sources/Tests/UnitTests/Calculus/APowerIsReadByItsOrderTest.cs new file mode 100644 index 000000000..968e6abb8 --- /dev/null +++ b/Sources/Tests/UnitTests/Calculus/APowerIsReadByItsOrderTest.cs @@ -0,0 +1,61 @@ +// +// 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 AngouriMath.Extensions; +using Xunit; + +namespace AngouriMath.Tests.Calculus +{ + /// + /// A power g^a to an exponent that is not an integer, of a g tending to 0, had no reading against a logarithm unless + /// g was x itself: x^pi ln(x) at 0 from the right was 0 and sin(x)^pi ln(x), and even (2x)^pi ln(x), were left + /// unevaluated, while ln(x) / (2x)^(-pi) took fifteen seconds to be. As a factor, g^a is x^(k a) times + /// (g / x^k)^a, where k is the power of x that g behaves like, and the second part tends to a positive number that + /// can be taken out of the limit. Found by limitcheck; no issue was filed. + /// + [Trait("Area", "Calculus")] + public sealed class APowerIsReadByItsOrderTest + { + [Theory] + [InlineData("sin(x)^pi * ln(x)", "0")] + [InlineData("(2x)^pi * ln(x)", "0")] + [InlineData("sqrt(sin(x)) * ln(x)", "0")] + [InlineData("tan(x)^pi * ln(x)", "0")] + [InlineData("(1 - cos(x))^pi * ln(x)", "0")] + [InlineData("(x + x^2)^pi * ln(x)", "0")] + [InlineData("ln(x) / (2x)^(-pi)", "0")] + [InlineData("sin(sin(x)^pi * ln(x))", "0")] + [InlineData("sin(x)^pi / x^pi", "1")] + public void AtZeroFromTheRight(string input, string expected) + => Assert.Equal(expected.ToEntity(), input.ToEntity().Limit("x", 0, ApproachFrom.Right)); + + [Fact] + public void AtAnInfinity() + => Assert.Equal("1".ToEntity(), "(x^2 + 1)^(1/pi) / x^(2/pi)".ToEntity().Limit("x", "+oo", ApproachFrom.BothSides)); + + // Only a factor is taken out: in a sum the part taken out is the whole of the answer. + [Fact] + public void APowerInASumIsLeftAlone() + => Assert.Equal("0".ToEntity(), "sin(x)^pi - x^pi".ToEntity().Limit("x", 0, ApproachFrom.Right)); + + [Fact] + public void APowerOfAGrowingBaseIsInTheDivisor() + { + Assert.Equal("+oo".ToEntity(), "sqrt(arctan(1)) / (1/2 / x)^sinh(pi)".ToEntity().Limit("x", "+oo", ApproachFrom.BothSides)); + Assert.Equal("-oo".ToEntity(), "x / (1/2) / (x + 1)^pi".ToEntity().Limit("x", -1, ApproachFrom.Right)); + } + + // A real power of a base tending to -oo is complex and stays unevaluated. It is not read by its order, which + // took 6.8 s to decline the first of these and 17.6 s the second, where master declines both in 0.3 s. + [Theory] + [InlineData("log(x^pi, pi^2)^arctan(tan(2))")] + [InlineData("log(x, 2)^(1 - pi) / (log(1/2, x) - pi)")] + public void APowerOfANegativeBaseIsDeclined(string input) + => Assert.IsType(input.ToEntity().Limit("x", 1, ApproachFrom.Left)); + } +}