diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md
index 36f63e4fd..3fd80e96f 100644
--- a/BREAKING-CHANGES.md
+++ b/BREAKING-CHANGES.md
@@ -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
diff --git a/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs
index e98d9ecb7..5c2ac288d 100644
--- a/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs
+++ b/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs
@@ -2436,6 +2436,18 @@ private static int InfiniteSign(Entity? limit)
///
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();
@@ -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
@@ -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;
+ }
+
+ ///
+ /// as c log(a), a logarithm to a base free of times a
+ /// nonzero real constant or over one, or 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).
+ ///
+ 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
+ };
}
+ /// Whether is a finite real number other than 0, which a limit may be scaled by.
+ 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));
diff --git a/Sources/Tests/UnitTests/Calculus/ADifferenceOfLogarithmsIsGatheredTest.cs b/Sources/Tests/UnitTests/Calculus/ADifferenceOfLogarithmsIsGatheredTest.cs
new file mode 100644
index 000000000..ee23e726a
--- /dev/null
+++ b/Sources/Tests/UnitTests/Calculus/ADifferenceOfLogarithmsIsGatheredTest.cs
@@ -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
+{
+ ///
+ /// 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.
+ ///
+ [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);
+ }
+}