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
15 changes: 15 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,21 @@ did, and `ln(x + 2) / ln(x + 3)` at 0 was `ln(2) / ln(3)`. With symbols it was n
| `"limit(ln(a + 1/x) / ln(b + 1/x), x, +oo)".ToEntity().Simplify()` | `a / b` | `ln(a) / ln(b)` |
| `"limit(ln(1 + x) / ln(y + x), x, 0)".ToEntity().Simplify()` | `1 / y` | `0 provided not ln(y) = 0` |

### A difference of logarithms of one base is read as one logarithm in a limit

**Silent: a limit of a difference of two logarithms of one base, each tending to an infinity, is answered, where it
was left unevaluated.** `ln(f) - ln(g)` is `ln(f / g)` wherever `f` and `g` are both positive, and the quotient often
has a limit where neither logarithm has. The two are gathered only where both arguments are checked to be positive
near the point, so a side on which either is negative is left as it was.

| Input | Was (2.6.0) | Now |
|---|---|---|
| `"ln(sin(x)) - ln(x)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | unevaluated | `0` |
| `"(ln(sin(x)) - ln(x)) / x^2".ToEntity().Limit("x", 0, ApproachFrom.Right)` | unevaluated | `-1/6` |
| `"(ln(sin(x)) - ln(x)) / x".ToEntity().Limit("x", 0, ApproachFrom.Right)` | unevaluated | `0` |
| `"log(2, sin(x)) - log(2, x)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | unevaluated | `0` |
| `"2 ln(sin(x)) - ln(x^2)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | unevaluated | `0` |

### A limit over a vanishing absolute value is not claimed not to exist

**Silent: `1/abs(x)` at 0 is `+oo`, where it was `NaN`, the claim that the limit does not exist.** The sign a
Expand Down
56 changes: 56 additions & 0 deletions Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2436,6 +2436,18 @@ private static int InfiniteSign(Entity? limit)
/// </summary>
private static Entity? SolveAsDifferenceOfInfinities(Entity expr, Variable x)
{
// A constant factor or divisor is taken out, and the difference read inside it: simplifying
// log(2, sin(1/x)) - log(2, 1/x) puts it over ln(2) as one quotient. A real, nonzero constant
// times an infinity, or a finite limit, is the limit times it.
var (scaled, scale) = expr switch
{
Mulf(var factor, var rest) when IsNonzeroRealConstant(factor) => (rest, factor),
Mulf(var rest, var factor) when IsNonzeroRealConstant(factor) => (rest, factor),
Divf(var rest, var divisor) when IsNonzeroRealConstant(divisor) => (rest, 1 / divisor),
_ => ((Entity?)null, (Entity?)null)
};
if (scaled is { } && scale is { })
return SolveAsDifferenceOfInfinities(scaled, x) is { } inside ? (scale * inside).InnerSimplified : null;
if (differenceDepth >= MaxDifferenceDepth || expr is not (Sumf or Minusf))
return null;
var terms = Sumf.LinearChildren(expr).ToArray();
Expand All @@ -2455,6 +2467,23 @@ private static int InfiniteSign(Entity? limit)
? (terms[0], -terms[1])
: (terms[1], -terms[0]);

// Two logarithms to one base are one logarithm: c log(a) + d log(b) = log(a^c b^d),
// exactly, for a and b positive on the way and c and d real. The difference is then a
// limit of one function, which ln(sin(1/x)) - ln(1/x), ln(sin(x)) - ln(x) at 0 from the
// right, has: it is ln(x sin(1/x)), and tends to 0. The ratio of the two tends to 1 and
// the conjugate needs a root, so nothing below had a reading of it.
// Each antilogarithm's sign is asked, not inferred from its logarithm tending to a real
// infinity: ln(-x) at 0 from the right is read as -oo, and ln(x) - ln(-x), which is
// -pi i there, gathered into ln(-1), which is pi i.
if (AsMultipleOfALogarithm(terms[0], x) is var (firstBase, firstArgument, firstMultiple)
&& AsMultipleOfALogarithm(terms[1], x) is var (secondBase, secondArgument, secondMultiple)
&& firstBase == secondBase
&& IsPositiveOnTheWay(firstArgument) && IsPositiveOnTheWay(secondArgument))
return ComputeLimit(
MathS.Log(firstBase,
(MathS.Pow(firstArgument, firstMultiple) * MathS.Pow(secondArgument, secondMultiple)).InnerSimplified),
x, dest);

// The faster growing part decides the answer whenever there is one, which is
// what the ratio of the two says: lim x -> +oo e^x - x is +oo because x / e^x
// tends to 0, and -oo the other way round. This settles nothing when the two
Expand Down Expand Up @@ -2486,8 +2515,35 @@ private static int InfiniteSign(Entity? limit)
finally { suppresslHopital = false; }
}
finally { differenceDepth--; }

bool IsPositiveOnTheWay(Entity argument)
=> ComputeLimit(MathS.Signum(argument), x, Real.PositiveInfinity)?.Evaled is Integer one && one == 1;
}

/// <summary>
/// <paramref name="term"/> as <c>c log(a)</c>, a logarithm to a base free of <paramref name="x"/> times a
/// nonzero real constant or over one, or <see langword="null"/> if it is not one. Over one is how a logarithm to
/// a base other than e comes out of simplifying: log(2, x) is ln(x) / ln(2).
/// </summary>
private static (Entity Base, Entity Argument, Entity Multiple)? AsMultipleOfALogarithm(Entity term, Variable x)
{
var read = Read(term);
return read is var (_, _, multiple) && IsNonzeroRealConstant(multiple) ? read : null;

(Entity Base, Entity Argument, Entity Multiple)? Read(Entity node) => node switch
{
Logf(var @base, var argument) when !@base.ContainsNode(x) => (@base, argument, Integer.One),
Mulf(var constant, var rest) when !constant.ContainsNode(x) && Read(rest) is var (b, a, m) => (b, a, constant * m),
Mulf(var rest, var constant) when !constant.ContainsNode(x) && Read(rest) is var (b, a, m) => (b, a, m * constant),
Divf(var rest, var constant) when !constant.ContainsNode(x) && Read(rest) is var (b, a, m) => (b, a, m / constant),
_ => null
};
}

/// <summary>Whether <paramref name="entity"/> is a finite real number other than 0, which a limit may be scaled by.</summary>
private static bool IsNonzeroRealConstant(Entity entity)
=> entity.Evaled is Real { IsFinite: true } real && !real.IsZero;

private static bool ContainsRadical(Entity expr, Variable x)
=> expr.Nodes.Any(node =>
node is Powf(var @base, Number.Rational and not Number.Integer) && @base.ContainsNode(x));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// 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>
/// Two logarithms to one base tending to opposite infinities are one logarithm, where both antilogarithms are
/// positive on the way: ln(sin(x)) - ln(x) at 0 from the right is ln(sin(x) / x), and tends to 0. The ratio of the
/// two tends to 1, which settles nothing, so it was left unevaluated. An antilogarithm that is negative is not
/// gathered: ln(x) - ln(-x) is -pi i there, and gathered it would be ln(-1), pi i. Found by limitcheck; no issue was
/// filed.
/// </summary>
[Trait("Area", "Calculus")]
public sealed class ADifferenceOfLogarithmsIsGatheredTest
{
[Theory]
[InlineData("ln(sin(x)) - ln(x)", "0")]
[InlineData("(ln(sin(x)) - ln(x)) / x^2", "-1/6")]
[InlineData("(ln(sin(x)) - ln(x)) / x", "0")]
[InlineData("log(2, sin(x)) - log(2, x)", "0")]
[InlineData("2 * ln(sin(x)) - ln(x^2)", "0")]
[InlineData("ln(x) - ln(-x)", "-pi * i")]
public void TheLimitFromTheRightIsAnswered(string input, string expected)
=> Assert.Equal(expected.ToEntity().Evaled, input.ToEntity().Limit("x", 0, ApproachFrom.Right).Evaled);
}
}
Loading