Skip to content

Commit e994ffd

Browse files
Gather a difference of logarithms into one in a limit (#2409)
Record the differences of logarithms now answered in a limit Gather a difference of logarithms into one at an infinity ln(sin(x)) - ln(x) at 0 from the right is ln(sin(x) / x), which tends to 0, and was left unevaluated. At +oo, where the limit is taken, it is ln(sin(1/x)) - ln(1/x), a difference of two infinities whose ratio tends to 1, which settles nothing, and with no root for the conjugate. Two logarithms to one base, each a real constant times a logarithm, are now gathered into one where both antilogarithms are positive on the way: c log(a) + d log(b) = log(a^c b^d) holds exactly there. The sign is asked of each, and not inferred from the logarithm tending to a real infinity: ln(-x) at 0 from the right is read as -oo, and ln(x) - ln(-x) would have gathered into ln(-1) where it is -pi i. A constant factor or divisor is taken out of the difference first, since simplifying puts log(2, sin(1/x)) - log(2, 1/x) over ln(2). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent cb49a8c commit e994ffd

3 files changed

Lines changed: 105 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,21 @@ did, and `ln(x + 2) / ln(x + 3)` at 0 was `ln(2) / ln(3)`. With symbols it was n
618618
| `"limit(ln(a + 1/x) / ln(b + 1/x), x, +oo)".ToEntity().Simplify()` | `a / b` | `ln(a) / ln(b)` |
619619
| `"limit(ln(1 + x) / ln(y + x), x, 0)".ToEntity().Simplify()` | `1 / y` | `0 provided not ln(y) = 0` |
620620

621+
### A difference of logarithms of one base is read as one logarithm in a limit
622+
623+
**Silent: a limit of a difference of two logarithms of one base, each tending to an infinity, is answered, where it
624+
was left unevaluated.** `ln(f) - ln(g)` is `ln(f / g)` wherever `f` and `g` are both positive, and the quotient often
625+
has a limit where neither logarithm has. The two are gathered only where both arguments are checked to be positive
626+
near the point, so a side on which either is negative is left as it was.
627+
628+
| Input | Was (2.6.0) | Now |
629+
|---|---|---|
630+
| `"ln(sin(x)) - ln(x)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | unevaluated | `0` |
631+
| `"(ln(sin(x)) - ln(x)) / x^2".ToEntity().Limit("x", 0, ApproachFrom.Right)` | unevaluated | `-1/6` |
632+
| `"(ln(sin(x)) - ln(x)) / x".ToEntity().Limit("x", 0, ApproachFrom.Right)` | unevaluated | `0` |
633+
| `"log(2, sin(x)) - log(2, x)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | unevaluated | `0` |
634+
| `"2 ln(sin(x)) - ln(x^2)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | unevaluated | `0` |
635+
621636
### A limit over a vanishing absolute value is not claimed not to exist
622637

623638
**Silent: `1/abs(x)` at 0 is `+oo`, where it was `NaN`, the claim that the limit does not exist.** The sign a

‎Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2436,6 +2436,18 @@ private static int InfiniteSign(Entity? limit)
24362436
/// </summary>
24372437
private static Entity? SolveAsDifferenceOfInfinities(Entity expr, Variable x)
24382438
{
2439+
// A constant factor or divisor is taken out, and the difference read inside it: simplifying
2440+
// log(2, sin(1/x)) - log(2, 1/x) puts it over ln(2) as one quotient. A real, nonzero constant
2441+
// times an infinity, or a finite limit, is the limit times it.
2442+
var (scaled, scale) = expr switch
2443+
{
2444+
Mulf(var factor, var rest) when IsNonzeroRealConstant(factor) => (rest, factor),
2445+
Mulf(var rest, var factor) when IsNonzeroRealConstant(factor) => (rest, factor),
2446+
Divf(var rest, var divisor) when IsNonzeroRealConstant(divisor) => (rest, 1 / divisor),
2447+
_ => ((Entity?)null, (Entity?)null)
2448+
};
2449+
if (scaled is { } && scale is { })
2450+
return SolveAsDifferenceOfInfinities(scaled, x) is { } inside ? (scale * inside).InnerSimplified : null;
24392451
if (differenceDepth >= MaxDifferenceDepth || expr is not (Sumf or Minusf))
24402452
return null;
24412453
var terms = Sumf.LinearChildren(expr).ToArray();
@@ -2455,6 +2467,23 @@ private static int InfiniteSign(Entity? limit)
24552467
? (terms[0], -terms[1])
24562468
: (terms[1], -terms[0]);
24572469

2470+
// Two logarithms to one base are one logarithm: c log(a) + d log(b) = log(a^c b^d),
2471+
// exactly, for a and b positive on the way and c and d real. The difference is then a
2472+
// limit of one function, which ln(sin(1/x)) - ln(1/x), ln(sin(x)) - ln(x) at 0 from the
2473+
// right, has: it is ln(x sin(1/x)), and tends to 0. The ratio of the two tends to 1 and
2474+
// the conjugate needs a root, so nothing below had a reading of it.
2475+
// Each antilogarithm's sign is asked, not inferred from its logarithm tending to a real
2476+
// infinity: ln(-x) at 0 from the right is read as -oo, and ln(x) - ln(-x), which is
2477+
// -pi i there, gathered into ln(-1), which is pi i.
2478+
if (AsMultipleOfALogarithm(terms[0], x) is var (firstBase, firstArgument, firstMultiple)
2479+
&& AsMultipleOfALogarithm(terms[1], x) is var (secondBase, secondArgument, secondMultiple)
2480+
&& firstBase == secondBase
2481+
&& IsPositiveOnTheWay(firstArgument) && IsPositiveOnTheWay(secondArgument))
2482+
return ComputeLimit(
2483+
MathS.Log(firstBase,
2484+
(MathS.Pow(firstArgument, firstMultiple) * MathS.Pow(secondArgument, secondMultiple)).InnerSimplified),
2485+
x, dest);
2486+
24582487
// The faster growing part decides the answer whenever there is one, which is
24592488
// what the ratio of the two says: lim x -> +oo e^x - x is +oo because x / e^x
24602489
// 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)
24862515
finally { suppresslHopital = false; }
24872516
}
24882517
finally { differenceDepth--; }
2518+
2519+
bool IsPositiveOnTheWay(Entity argument)
2520+
=> ComputeLimit(MathS.Signum(argument), x, Real.PositiveInfinity)?.Evaled is Integer one && one == 1;
2521+
}
2522+
2523+
/// <summary>
2524+
/// <paramref name="term"/> as <c>c log(a)</c>, a logarithm to a base free of <paramref name="x"/> times a
2525+
/// nonzero real constant or over one, or <see langword="null"/> if it is not one. Over one is how a logarithm to
2526+
/// a base other than e comes out of simplifying: log(2, x) is ln(x) / ln(2).
2527+
/// </summary>
2528+
private static (Entity Base, Entity Argument, Entity Multiple)? AsMultipleOfALogarithm(Entity term, Variable x)
2529+
{
2530+
var read = Read(term);
2531+
return read is var (_, _, multiple) && IsNonzeroRealConstant(multiple) ? read : null;
2532+
2533+
(Entity Base, Entity Argument, Entity Multiple)? Read(Entity node) => node switch
2534+
{
2535+
Logf(var @base, var argument) when !@base.ContainsNode(x) => (@base, argument, Integer.One),
2536+
Mulf(var constant, var rest) when !constant.ContainsNode(x) && Read(rest) is var (b, a, m) => (b, a, constant * m),
2537+
Mulf(var rest, var constant) when !constant.ContainsNode(x) && Read(rest) is var (b, a, m) => (b, a, m * constant),
2538+
Divf(var rest, var constant) when !constant.ContainsNode(x) && Read(rest) is var (b, a, m) => (b, a, m / constant),
2539+
_ => null
2540+
};
24892541
}
24902542

2543+
/// <summary>Whether <paramref name="entity"/> is a finite real number other than 0, which a limit may be scaled by.</summary>
2544+
private static bool IsNonzeroRealConstant(Entity entity)
2545+
=> entity.Evaled is Real { IsFinite: true } real && !real.IsZero;
2546+
24912547
private static bool ContainsRadical(Entity expr, Variable x)
24922548
=> expr.Nodes.Any(node =>
24932549
node is Powf(var @base, Number.Rational and not Number.Integer) && @base.ContainsNode(x));
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// Copyright (c) 2019-2026 Angouri.
3+
// AngouriMath is licensed under MIT.
4+
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
5+
// Website: https://am.angouri.org.
6+
//
7+
8+
using AngouriMath.Core;
9+
using AngouriMath.Extensions;
10+
using Xunit;
11+
12+
namespace AngouriMath.Tests.Calculus
13+
{
14+
/// <summary>
15+
/// Two logarithms to one base tending to opposite infinities are one logarithm, where both antilogarithms are
16+
/// 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
17+
/// two tends to 1, which settles nothing, so it was left unevaluated. An antilogarithm that is negative is not
18+
/// gathered: ln(x) - ln(-x) is -pi i there, and gathered it would be ln(-1), pi i. Found by limitcheck; no issue was
19+
/// filed.
20+
/// </summary>
21+
[Trait("Area", "Calculus")]
22+
public sealed class ADifferenceOfLogarithmsIsGatheredTest
23+
{
24+
[Theory]
25+
[InlineData("ln(sin(x)) - ln(x)", "0")]
26+
[InlineData("(ln(sin(x)) - ln(x)) / x^2", "-1/6")]
27+
[InlineData("(ln(sin(x)) - ln(x)) / x", "0")]
28+
[InlineData("log(2, sin(x)) - log(2, x)", "0")]
29+
[InlineData("2 * ln(sin(x)) - ln(x^2)", "0")]
30+
[InlineData("ln(x) - ln(-x)", "-pi * i")]
31+
public void TheLimitFromTheRightIsAnswered(string input, string expected)
32+
=> Assert.Equal(expected.ToEntity().Evaled, input.ToEntity().Limit("x", 0, ApproachFrom.Right).Evaled);
33+
}
34+
}

0 commit comments

Comments
 (0)