Skip to content

Commit a1c0034

Browse files
Read the logarithm of a power through the logarithm of its base in a limit (#2385)
Nothing in a limit read ln(f^c), for a constant real c, as a multiple of ln(f). log(x, arcsin(x)^tan(1/2)) at 0, which is tan(1/2) from each side, was left unevaluated after 3.1 s from the right, 2.2 s from the left and 4.2 s two-sided, where log(x, arcsin(x)) was 1 at once. For f positive near the point, ln(f^c) is c ln(f). For f negative, f^c is (-f)^c (-1)^c on the principal branch, a positive number times one of modulus 1, so ln(f^c) is c ln(-f) + ln((-1)^c), which is c ln(f) only for c in (-1, 1]. In that range the first form holds wherever f is real, so a two-sided limit whose sides differ in sign is asked through it too. The rewrite runs beside the one that turns log(b, f) into ln(f) / ln(b). Measured, master against this branch, each alone: log(x, arcsin(x)^tan(1/2)) at 0+ unevaluated 3.1 s -> tan(1/2) 0.29 s the same two-sided unevaluated 4.2 s -> tan(1/2) 0.44 s ln(arcsin(x)^pi) / ln(x) at 0 unevaluated 2.7 s -> pi 1.1 s ln(sin(x)^(1/3)) / ln(x) at 0 1/3 2.4 s -> 1/3 0.23 s Found by limitcheck at DEPTH=3, SEED=65; no issue was filed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 9d499b8 commit a1c0034

4 files changed

Lines changed: 134 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,32 @@ A bare `floor(x)` or `sgn(x)` was already declined there. Away from a jump, noth
7272
| `"limit(floor(x) + x, x, 1)".ToEntity().Simplify()` | `2` | `limit(floor(x) + x, x, 1)` |
7373
| `"limitleft(-sgn(x), x, 0)".ToEntity().Simplify()` | `0` | `limitleft(-sgn(x), x, 0)` |
7474

75+
### A logarithm of a power is read through the logarithm of its base in a limit
76+
77+
**Silent: in a limit, the logarithm of a power to a constant real exponent, `log(f^c)`, is read as `c log(f)`, or as
78+
`c log(-f) + log((-1)^c)` where `f` is negative near the point.** Nothing read it through `log(f)`, so a logarithm to
79+
the base `x` of `arcsin(x)^tan(1/2)` was left unevaluated where that of `arcsin(x)` was 1 at once. Where `f` is negative
80+
the second form keeps the principal branch, and an answer that was a decimal is now exact. A left-sided limit at -1 that
81+
was a wrong finite value is now 0, and where a left side now agrees with the right, the two-sided limit that was NaN
82+
is that value. Found by limitcheck; no
83+
issue was filed.
84+
85+
| Input | Was (2.6.0) | Now |
86+
|---|---|---|
87+
| `"log(x, arcsin(x)^tan(1/2))".ToEntity().Limit("x", 0, ApproachFrom.Right)` | `limitright(log(x, arcsin(x) ^ tan(1/2)), x, 0)` | `sin(1/2) / cos(1/2)` |
88+
| `"log(x, arcsin(x)^tan(1/2))".ToEntity().Limit("x", 0, ApproachFrom.Left)` | `limitleft(log(x, arcsin(x) ^ tan(1/2)), x, 0)` | `sin(1/2) / cos(1/2)` |
89+
| `"log(x, arcsin(x)^tan(1/2))".ToEntity().Limit("x", 0)` | `limit(log(x, arcsin(x) ^ tan(1/2)), x, 0)` | `sin(1/2) / cos(1/2)` |
90+
| `"ln(arcsin(x)^pi) / ln(x)".ToEntity().Limit("x", 0)` | `limit(ln(arcsin(x) ^ pi) / ln(x), x, 0)` | `pi` |
91+
| `"ln((-x)^pi) / ln(x)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | `1 + 2.14159265358979323846…`, the decimal of pi | `pi` |
92+
| `"e^(1/2)^x / log(x^2, arctan(x))".ToEntity().Limit("x", -1, ApproachFrom.Left)` | `e ^ 2 / (1/2 * 1 / (-pi / 4 * (-2)))`, wrong: the values tend to 0 | `0` |
93+
| `"e^(1/2)^x / log(x^2, arctan(x))".ToEntity().Limit("x", -1)` | `NaN` | `0` |
94+
| `"log(log(x - 1, 1/2), log(abs(x), x^2))".ToEntity().Limit("x", -1, ApproachFrom.Left)` | `NaN` | `-0.19160486490703… - 0.22317814847246…i`, as from the right |
95+
| `"log(log(x - 1, 1/2), log(abs(x), x^2))".ToEntity().Limit("x", -1)` | `NaN` | `-0.19160486490703… - 0.22317814847246…i` |
96+
| `"sqrt(x / 2)^(x^pi * x)".ToEntity().Limit("x", 0, ApproachFrom.Right)`, and from the left | `limitright(sqrt(x / 2) ^ (x ^ pi * x), x, 0)` | `1` |
97+
| `"log(x^pi, sgn(-1))^2".ToEntity().Limit("x", 1, ApproachFrom.Right)`, and from the left | `limitright(log(x ^ pi, sgn(-1)) ^ 2, x, 1)` | `-oo` |
98+
| `"log(x^pi, sgn(-1))^2".ToEntity().Limit("x", 1)` | `NaN` | `-oo` |
99+
| `"(tanh(x)^erf(2))^sin(x^3)".ToEntity().Limit("x", 0, ApproachFrom.Right)`, and from the left | `limitright((((e ^ (2 * x) - 1) / (e ^ (2 * x) + 1)) ^ erf(2)) ^ sin(x ^ 3), x, 0)` | `1` |
100+
75101
### An equation through a negative whole power is not answered with no roots
76102

77103
**Silent: an empty answer becomes the roots.** Inverting `x^n = v` for a negative whole `n` multiplied by the roots

‎Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,36 @@ internal static bool MayReadAPowerThroughItsExponent(Entity power)
312312
/// </summary>
313313
internal static bool IsTheWholeQuestion(Entity expr) => ReferenceEquals(expr, descentRoot);
314314

315+
/// <summary>
316+
/// A logarithm of a power to a constant real exponent, log(f^c), as c log(f), or as
317+
/// c log(-f) + log((-1)^c) where f is negative near the point.
318+
/// </summary>
319+
/// <remarks>
320+
/// For f positive and c real, f^c is positive and ln(f^c) is c ln(f). For f negative, f^c is
321+
/// (-f)^c (-1)^c on the principal branch, a positive number times one of modulus 1, so
322+
/// ln(f^c) is c ln(-f) + ln((-1)^c), which is c ln(f) only for c in (-1, 1]. In that range the
323+
/// first form holds wherever f is real, whatever its sign, so a two-sided limit whose sides
324+
/// differ in sign can still be asked through it. Nothing read ln(f^c) through ln(f):
325+
/// log(x, arcsin(x)^tan(1/2)) at 0, which is tan(1/2) from each side, was left unevaluated
326+
/// after three seconds from the right and four two-sided, where log(x, arcsin(x)) was 1 at
327+
/// once. Found by limitcheck at <c>DEPTH=3</c>, <c>SEED=65</c>; no issue was filed.
328+
/// </remarks>
329+
private static Entity LogarithmOfAPower(Entity node, Variable x, Entity dest, ApproachFrom side)
330+
{
331+
if (node is not Logf(var @base, Powf(var power, var exponent))
332+
|| exponent.ContainsNode(x) || exponent.Evaled is not Real { IsFinite: true } c
333+
|| !power.ContainsNode(x))
334+
return node;
335+
if (c > -1 && c <= 1 && IsRealOnEachSide(power, x, dest, side))
336+
return exponent * new Logf(@base, power);
337+
return SignOnEachSide(power, x, dest, side) switch
338+
{
339+
1 => exponent * new Logf(@base, power),
340+
-1 => exponent * new Logf(@base, -power) + new Logf(@base, MathS.Pow(-1, exponent)),
341+
_ => node
342+
};
343+
}
344+
315345
/// <summary>
316346
/// A logarithm to a base other than e as a quotient of natural logarithms.
317347
/// </summary>
@@ -432,6 +462,7 @@ internal static T WithinABudget<T>(int limits, System.Func<T> compute)
432462
return MathS.NaN;
433463

434464
expr = expr.Replace(ExpandLogarithm);
465+
expr = expr.Replace(node => LogarithmOfAPower(node, x, dest, side));
435466

436467
// In front of both paths, not only the two-sided one. Each of these is guarded on
437468
// a two-sided limit, and a two-sided limit that exists is also the limit from

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,40 @@ internal static Entity AtALargeDecimal(Entity expr, Variable x)
11801180
=> MathS.Settings.DowncastingEnabled.As(false,
11811181
() => expr.Substitute(x, Real.Create(PeterO.Numbers.EDecimal.FromString("1E6"))).Evaled);
11821182

1183+
/// <summary>
1184+
/// The sign <paramref name="expr"/> keeps near the destination on each side approached, where it
1185+
/// is real there and the sides agree, or <see langword="null"/>.
1186+
/// </summary>
1187+
internal static int? SignOnEachSide(Entity expr, Variable x, Entity dest, ApproachFrom side)
1188+
{
1189+
int? sign = null;
1190+
foreach (var oneSide in Sides(dest, side))
1191+
{
1192+
if (!IsRealNear(expr, x, dest, oneSide)
1193+
|| SignNear(expr, x, dest, oneSide) is not { } here || sign is { } earlier && earlier != here)
1194+
return null;
1195+
sign = here;
1196+
}
1197+
return sign;
1198+
}
1199+
1200+
/// <summary>Whether <paramref name="expr"/> is real near the destination on each side approached.</summary>
1201+
internal static bool IsRealOnEachSide(Entity expr, Variable x, Entity dest, ApproachFrom side)
1202+
=> Sides(dest, side).All(oneSide => IsRealNear(expr, x, dest, oneSide));
1203+
1204+
// Where the real region is not known, as arcsin's is not, the form can still say it is real there.
1205+
private static bool IsRealNear(Entity expr, Variable x, Entity dest, ApproachFrom oneSide)
1206+
=> Functions.TreeAnalyzer.IsRealValued(expr, x)
1207+
|| Functions.TreeAnalyzer.WhereRealValued(expr, x) is { } whereReal && HoldsNear(whereReal, x, dest, oneSide) is true
1208+
|| IsRealOnBothSides(expr, x, dest);
1209+
1210+
// The sides a limit approaches from: both at a finite point asked two-sidedly, and one otherwise,
1211+
// since an infinity is approached from one side whichever is asked.
1212+
private static ApproachFrom[] Sides(Entity dest, ApproachFrom side)
1213+
=> side is ApproachFrom.BothSides && dest.IsFinite
1214+
? new[] { ApproachFrom.Left, ApproachFrom.Right }
1215+
: new[] { side is ApproachFrom.BothSides ? ApproachFrom.Left : side };
1216+
11831217
/// <summary>
11841218
/// The sign an expression keeps throughout a punctured one-sided neighbourhood of the
11851219
/// destination, or <see langword="null"/> where it cannot be read off.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 Xunit;
10+
11+
namespace AngouriMath.Tests.Calculus
12+
{
13+
/// <summary>
14+
/// A limit read log(f^c), for a constant real c, as nothing but a logarithm of a power, never as
15+
/// c log(f). <c>log(x, arcsin(x)^tan(1/2))</c> at 0, which is tan(1/2) from each side, was left
16+
/// unevaluated after three seconds from the right and four two-sided, where <c>log(x, arcsin(x))</c>
17+
/// was 1 at once. It is c log(f) where f is positive near the point, and for c in (-1, 1] wherever
18+
/// f is real; where f is negative, it is c log(-f) + log((-1)^c). Found by limitcheck at <c>DEPTH=3</c>,
19+
/// <c>SEED=65</c>; no issue was filed.
20+
/// </summary>
21+
[Trait("Area", "Calculus")]
22+
public sealed class ALogarithmOfAPowerTest
23+
{
24+
[Theory]
25+
// arcsin(x) is negative on the left of 0, and tan(1/2) is in (-1, 1].
26+
[InlineData("log(x, arcsin(x)^tan(1/2))", ApproachFrom.Right, "tan(1/2)")]
27+
[InlineData("log(x, arcsin(x)^tan(1/2))", ApproachFrom.Left, "tan(1/2)")]
28+
[InlineData("log(x, arcsin(x)^tan(1/2))", ApproachFrom.BothSides, "tan(1/2)")]
29+
[InlineData("ln(sin(x)^(1/3)) / ln(x)", ApproachFrom.BothSides, "1/3")]
30+
// Positive on the right, so any exponent; on the left, ln(f^pi) is pi ln(-f) + ln((-1)^pi).
31+
[InlineData("ln(arcsin(x)^pi) / ln(x)", ApproachFrom.Right, "pi")]
32+
[InlineData("ln(arcsin(x)^pi) / ln(x)", ApproachFrom.Left, "pi")]
33+
[InlineData("ln(arcsin(x)^pi) / ln(x)", ApproachFrom.BothSides, "pi")]
34+
public void IsTheExponentTimesTheLimit(string input, ApproachFrom side, string expected)
35+
{
36+
var limit = MathS.FromString(input).Limit("x", 0, side);
37+
// Simplifying a limit left unevaluated simplifies what is under it and asks again, which
38+
// answers some of these, so that it was answered is asserted first.
39+
Assert.DoesNotContain(limit.Nodes, node => node is Entity.Limitf);
40+
Assert.Equal(Entity.Number.Integer.Zero, (limit - MathS.FromString(expected)).Simplify());
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)