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
22 changes: 22 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 54 additions & 0 deletions Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -2110,6 +2114,56 @@ Entity RewriteRoot(Entity node)
}
}

/// <summary>
/// The expression with every factor <c>g^a</c> of it -- a factor of the product or the quotient it is -- to a
/// constant exponent that is not an integer, of a <c>g</c> tending to 0 or an infinity, replaced by
/// <c>x^(k a)</c>, and the product of the limits <c>L^a</c> of what was taken out; or <see langword="null"/> if
/// there is no such factor. <c>k</c> is the limit of <c>x g' / g</c>, the power of x that <c>g</c> behaves like,
/// taken where it is rational, and <c>L</c> is the limit of <c>g / x^k</c>, taken where it is a positive number.
/// <c>sin(x)^pi ln(x)</c> at 0 from the right is <c>sin(1/x)^pi ln(1/x)</c> here, and nothing read a power of
/// <c>sin(1/x)</c> alongside a logarithm, while it is <c>(x sin(1/x))^pi</c>, which tends to 1, times
/// <c>x^(-pi) ln(1/x)</c>, which tends to 0.
/// </summary>
/// <remarks>
/// A factor tending to a positive number can be taken out of a limit, and <c>(uv)^a = u^a v^a</c> needs <c>u</c>
/// positive, which <c>x^k</c> is on the way to +oo, the only direction this is used in. Only a factor: inside a
/// sum, <c>sin(x)^pi - x^pi</c>, the part taken out is the whole of the answer.
/// </remarks>
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;
}
}
}

/// <summary>
/// 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
Expand Down
61 changes: 61 additions & 0 deletions Sources/Tests/UnitTests/Calculus/APowerIsReadByItsOrderTest.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// 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.
/// </summary>
[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<Entity.Limitf>(input.ToEntity().Limit("x", 1, ApproachFrom.Left));
}
}
Loading