Skip to content

Commit 2c9dceb

Browse files
A limit on a logarithm's cut is not read off the principal value (#2294)
limitright(ln(x^x), x, -1) was ln(-1), which is i pi, where it is -i pi: x^x comes to -1 from below as x comes down to -1, and the principal logarithm is continuous on its cut from above only. The value on the cut is the limit along the real line and from above, so it was given as the limit from either side. ArrivesOnTheCutOffTheRealLine asks whether a logarithm's argument, or the base of a power to an exponent that is not whole, tends to a negative real and is not known to be real on the approach; a power's base and a logarithm's argument count as positive where their values at the destination are. Which side such an argument comes from is not decided, so a limit there is declined: by substitution, by the logarithm's and the power's descent, by SolveAsLogarithm, by the quotient of logarithms, and by Gruntz, whose series took the principal logarithm of a negative coefficient. A limit from above, whose answer was right, is declined too. LimitOnABranchCutTest takes eight limits from below the cut, three two-sided ones that do not exist, and nine along the real line, which are answered as before; eleven fail on master. The suite, the trio, F#, AOT and the eight harnesses pass. Composed with #2268, #2275 and #2276, work/limitcheck finds none of the 56 limits it found answered with another value on master, of 600 expressions. Part of #2266. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 0f3df21 commit 2c9dceb

7 files changed

Lines changed: 190 additions & 3 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,24 @@ mentions answers it as a parameter, as a short system does, where it was `null`
254254
| `MathS.Equations("x - 1", "x^2 - 1").Solve("x", "y")` | `null` | `[[1, t_1]]` |
255255
| `MathS.Equations("a - 1", "b * 0").Solve("a", "b")` | `null` | `[[1, t_1]]` |
256256

257+
### A limit on a logarithm's cut is not read off the principal value
258+
259+
**Silent: a limit of a logarithm, or of a power to an exponent that is not whole, whose argument arrives on the negative
260+
real line other than along it is left unevaluated.** The principal logarithm is continuous on its cut from above only, and
261+
its value there was given as the limit from any side: `x^x` comes to -1 from below as x comes down to -1, so
262+
`limitright(ln(x^x), x, -1)` is `-i pi`, and it was `ln(-1)`, which is `i pi`. Which side an argument off the real line comes
263+
from is not decided, so a limit from above, whose answer was right, is left unevaluated too. Along the real line the value
264+
on the cut is the limit, and `limit(ln(x), x, -1)` is still `ln(-1)`
265+
([#2266](https://github.com/asc-community/AngouriMath/issues/2266)).
266+
267+
| Input | Was (2.6.0) | Now |
268+
|---|---|---|
269+
| `"limitright(ln(x^x), x, -1)".ToEntity().Simplify()` | `ln(-1)`, which is `i pi` | unevaluated; the limit is `-i pi` |
270+
| `"limit(ln(x^x), x, -1)".ToEntity().Simplify()` | `ln(-1)` | unevaluated; there is no limit |
271+
| `"limitleft(ln(-1 + i*x), x, 0)".ToEntity().Simplify()` | `ln(-1)` | unevaluated; the limit is `-i pi` |
272+
| `"limitright(sqrt(x^x), x, -1)".ToEntity().Simplify()` | `i` | unevaluated; the limit is `-i` |
273+
| `"limitleft(ln(x^x), x, -1)".ToEntity().Simplify()` | `ln(-1)`, which is right | unevaluated |
274+
257275
### `Simplify` does not add a condition the input does not have
258276

259277
**Silent: an answer defined at fewer points is defined at all of the input's.** A polynomial division in a

‎Sources/.editorconfig‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
135135
[Tests/UnitTests/Calculus/PowerSubstitutionIntegralTest.cs]
136136
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n
137137

138+
[Tests/UnitTests/Calculus/LimitOnABranchCutTest.cs]
139+
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n
140+
138141
[Tests/UnitTests/Calculus/ProductOfPowersDerivativeTest.cs]
139142
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n
140143

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ private static void Trace(string what, object? value)
7878
{
7979
if (depth > 0)
8080
return null; // already inside; the caller is the entry
81+
// The algorithm is for real functions, and its series takes the logarithm of a
82+
// negative leading coefficient as the principal one, which is the limit from above
83+
// the cut. ln(x^x) at -1 from the right is ln((1/x - 1)^(1/x - 1)) here, whose
84+
// argument comes to -1 from below, and it answered i pi where the limit is -i pi.
85+
// https://github.com/asc-community/AngouriMath/issues/2266
86+
if (expr.Nodes.Any(node => LimitFunctional.TakesItsValueOnACut(node, x, Real.PositiveInfinity)))
87+
return null;
8188
expr = AsExponentials(expr, x);
8289
return LimitInf(expr, x);
8390
}

‎Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,15 @@ partial record Logf
242242
return lim;
243243
else
244244
{
245-
var @base = Base.ComputeLimitDivideEtImpera(x, dist, side) is { IsFinite: true } lim1 && lim1 != 0 ? lim1 : Base;
246-
var power = Antilogarithm.ComputeLimitDivideEtImpera(x, dist, side) is { IsFinite: true } lim2 && lim2 != 0 ? lim2 : Antilogarithm;
245+
var baseLimit = Base.ComputeLimitDivideEtImpera(x, dist, side);
246+
var antilogarithmLimit = Antilogarithm.ComputeLimitDivideEtImpera(x, dist, side);
247+
// The logarithm of a limit on the cut is the limit only from above or along the
248+
// real line. https://github.com/asc-community/AngouriMath/issues/2266
249+
if (ArrivesOnTheCutOffTheRealLine(Base, baseLimit, x, dist)
250+
|| ArrivesOnTheCutOffTheRealLine(Antilogarithm, antilogarithmLimit, x, dist))
251+
return null;
252+
var @base = baseLimit is { IsFinite: true } lim1 && lim1 != 0 ? lim1 : Base;
253+
var power = antilogarithmLimit is { IsFinite: true } lim2 && lim2 != 0 ? lim2 : Antilogarithm;
247254
MultithreadingFunctional.ExitIfCancelled();
248255
return ComputeLimitImpl(New(@base, power), x, dist, side);
249256
}
@@ -256,8 +263,14 @@ partial record Powf
256263
{
257264
if (ComputeLimitImpl(this, x, dist, side) is { } lim)
258265
return lim;
266+
var baseLimit = Base.ComputeLimitDivideEtImpera(x, dist, side);
267+
var exponentLimit = Exponent.ComputeLimitDivideEtImpera(x, dist, side);
268+
// A power to an exponent that is not whole has the logarithm's cut, for the reason
269+
// the logarithm above declines it. https://github.com/asc-community/AngouriMath/issues/2266
270+
if (exponentLimit?.Evaled is not Integer && ArrivesOnTheCutOffTheRealLine(Base, baseLimit, x, dist))
271+
return null;
259272
var substituted =
260-
(Base.ComputeLimitDivideEtImpera(x, dist, side), Exponent.ComputeLimitDivideEtImpera(x, dist, side))
273+
(baseLimit, exponentLimit)
261274
switch {
262275
({ IsFinite: true } lim1, { IsFinite: true } lim2) => New(lim1, lim2),
263276
(_, { } l2) when !Base.ContainsNode(x) => New(Base, l2),

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ internal static class LimitSolvers
5454
{
5555
MultithreadingFunctional.ExitIfCancelled();
5656
if (limit == Real.NaN) return null;
57+
// Nor where a logarithm's argument, or a power's base, arrives on the cut off the
58+
// real line, where the value there is the limit from above and not from below.
59+
// https://github.com/asc-community/AngouriMath/issues/2266
60+
if (expr.Nodes.Any(node => LimitFunctional.TakesItsValueOnACut(node, x, Infinity))) return null;
5761
// Reading the value at the destination is the limit only where the expression
5862
// is continuous there, and an indeterminate form is exactly where it is not.
5963
// Every other one of them already declines on the line above, because this
@@ -160,6 +164,7 @@ static bool OnAJump(Entity argument, System.Func<Real, bool> jump)
160164
MultithreadingFunctional.ExitIfCancelled();
161165
var innerLimit = LimitFunctional.ComputeLimit(logArgument, x, Real.PositiveInfinity);
162166
if (innerLimit is null) return null;
167+
if (LimitFunctional.ArrivesOnTheCutOffTheRealLine(logArgument, innerLimit, x, Real.PositiveInfinity)) return null;
163168
// do same as wolframalpha: https://www.wolframalpha.com/input/?i=ln%28-inf%29
164169
if (innerLimit == Real.NegativeInfinity) return Real.PositiveInfinity;
165170
if (innerLimit == Real.PositiveInfinity) return Real.PositiveInfinity;
@@ -333,6 +338,9 @@ private static bool LogarithmDiverges(Entity argumentLimit)
333338
else
334339

335340
{
341+
if (LimitFunctional.ArrivesOnTheCutOffTheRealLine(upperLogArgument, upperLogLimit, x, Real.PositiveInfinity)
342+
|| LimitFunctional.ArrivesOnTheCutOffTheRealLine(lowerLogArgument, lowerLogLimit, x, Real.PositiveInfinity))
343+
return null;
336344
var div = (MathS.Ln(upperLogLimit) / MathS.Ln(lowerLogLimit));
337345
var divEvaled = div.Evaled;
338346
return divEvaled switch

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

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,76 @@ internal static bool HoldsAnIndeterminatePowerForm(Entity expr)
855855
=> expr.Nodes.Any(node => node is Powf(var @base, var exponent)
856856
&& IsIndeterminatePowerForm(@base, exponent));
857857

858+
/// <summary>
859+
/// Whether <paramref name="argument"/>, a logarithm's or the base of a power, tends to
860+
/// <paramref name="limit"/> on the negative real line, where the logarithm has its cut, and
861+
/// is not known to arrive there along the real line.
862+
/// </summary>
863+
/// <remarks>
864+
/// The principal logarithm is continuous on its cut from above only. Its value there,
865+
/// <c>ln(-1) = i pi</c>, is the limit along the line and from above, and from below the limit
866+
/// is <c>-i pi</c>. So a limit read off a logarithm of an argument's limit is that limit only
867+
/// where the argument does not come from below: <c>x^x</c> tends to -1 from below as x comes
868+
/// down to -1, and <c>limitright(ln(x^x), x, -1)</c> answered <c>i pi</c>. A power to an
869+
/// exponent that is not whole is <c>e^(exponent * ln(base))</c> and has the same cut. Which
870+
/// side an argument off the real line comes from is not decided here, so a limit there is
871+
/// declined, including one from above, whose answer was right.
872+
/// <a href="https://github.com/asc-community/AngouriMath/issues/2266">#2266</a>
873+
/// </remarks>
874+
internal static bool ArrivesOnTheCutOffTheRealLine(Entity argument, Entity? limit, Variable x, Entity dest)
875+
=> argument.ContainsNode(x)
876+
&& limit?.Evaled is Real { IsFinite: true, IsNegative: true }
877+
&& !IsRealOnTheApproach(argument, x, dest);
878+
879+
/// <summary>
880+
/// Whether a node of an expression that is about to be read at <paramref name="dest"/> is a
881+
/// logarithm or a power whose argument arrives on the cut off the real line, by
882+
/// <see cref="ArrivesOnTheCutOffTheRealLine"/>, with the argument's value at the destination
883+
/// as its limit. A power to an exponent whose value there is whole is continuous across the
884+
/// cut, where each of its values is reached from both sides.
885+
/// </summary>
886+
internal static bool TakesItsValueOnACut(Entity node, Variable x, Entity dest)
887+
{
888+
return node switch
889+
{
890+
Logf(var @base, var antilogarithm) => OnTheCut(@base) || OnTheCut(antilogarithm),
891+
Powf(var @base, var exponent) => exponent.Substitute(x, dest).Evaled is not Integer && OnTheCut(@base),
892+
_ => false
893+
};
894+
bool OnTheCut(Entity argument) => ArrivesOnTheCutOffTheRealLine(argument, argument.Substitute(x, dest), x, dest);
895+
}
896+
897+
/// <summary>
898+
/// Whether <paramref name="expr"/> is real as <paramref name="x"/> runs along the real line to
899+
/// <paramref name="dest"/>, decided structurally, as <see cref="IsRealAlong"/> is. A power's
900+
/// base and a logarithm's argument count as positive where their values at the destination
901+
/// are, which they then are near it. Anything else is
902+
/// <see cref="TreeAnalyzer.IsRealValued"/>'s, and unlisted is not real, which costs
903+
/// coverage and never correctness.
904+
/// </summary>
905+
private static bool IsRealOnTheApproach(Entity expr, Variable x, Entity dest)
906+
{
907+
if (dest.Evaled is not Real)
908+
return false;
909+
if (!expr.ContainsNode(x))
910+
return expr.Evaled is Real { IsFinite: true };
911+
return expr switch
912+
{
913+
Variable variable => variable == x,
914+
Sumf(var augend, var addend) => Along(augend) && Along(addend),
915+
Minusf(var minuend, var subtrahend) => Along(minuend) && Along(subtrahend),
916+
Mulf(var multiplier, var multiplicand) => Along(multiplier) && Along(multiplicand),
917+
Divf(var dividend, var divisor) => Along(dividend) && Along(divisor),
918+
Powf(var @base, Integer) => Along(@base),
919+
Powf(var @base, var exponent) => Along(@base) && Along(exponent) && PositiveThere(@base),
920+
Logf(var @base, var antilogarithm) => Along(@base) && Along(antilogarithm)
921+
&& PositiveThere(@base) && PositiveThere(antilogarithm),
922+
_ => TreeAnalyzer.IsRealValued(expr, x)
923+
};
924+
bool Along(Entity part) => IsRealOnTheApproach(part, x, dest);
925+
bool PositiveThere(Entity part) => part.Substitute(x, dest).Evaled is Real { IsPositive: true };
926+
}
927+
858928
/// <summary>
859929
/// Whether the exponent grows without bound, which is all the second remarkable
860930
/// limit needs.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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 System.Linq;
9+
using AngouriMath.Extensions;
10+
using Xunit;
11+
12+
namespace AngouriMath.Tests.Calculus
13+
{
14+
/// <summary>
15+
/// A limit of a logarithm, or of a power to an exponent that is not whole, whose argument arrives on the negative real
16+
/// line other than along it is not read off the principal value there. The principal logarithm is continuous on its cut
17+
/// from above only: x^x comes to -1 from below as x comes down to -1, so limitright(ln(x^x), x, -1) is -i pi, and it
18+
/// answered ln(-1), which is i pi. Each expected value is the expression's near the destination.
19+
/// <a href="https://github.com/asc-community/AngouriMath/issues/2266">#2266</a>
20+
/// </summary>
21+
[Trait("Area", "Calculus")]
22+
public sealed class LimitOnABranchCutTest
23+
{
24+
/// <summary>From below the cut, or from both sides of it, where the principal value is not the limit.</summary>
25+
[Theory]
26+
[InlineData("limitright(ln(x^x), x, -1)", "-i pi")]
27+
[InlineData("limitright(sqrt(x^x), x, -1)", "-i")]
28+
[InlineData("limitright(log(2, x^x), x, -1)", "-i pi / ln(2)")]
29+
[InlineData("limitright(ln(x^x) * x, x, -1)", "i pi")]
30+
[InlineData("limitleft(ln(-1 + i x), x, 0)", "-i pi")]
31+
[InlineData("limitleft(sqrt(-1 + i x), x, 0)", "-i")]
32+
[InlineData("limitleft(ln(-1 - i x^2), x, 0)", "-i pi")]
33+
[InlineData("limitright(ln(-e^(i x)), x, 0)", "-i pi")]
34+
public void ItIsTheLimitOrNothing(string limit, string value)
35+
{
36+
var answer = limit.ToEntity().Simplify();
37+
Assert.True(IsUnevaluated(answer) || answer.Evaled == value.ToEntity().Evaled, $"{limit} is {answer}, where it is {value}");
38+
}
39+
40+
/// <summary>Where the sides disagree there is no limit, and the principal value was given for it.</summary>
41+
[Theory]
42+
[InlineData("limit(ln(x^x), x, -1)")]
43+
[InlineData("limit(ln(-1 + i x), x, 0)")]
44+
[InlineData("limit(ln(e^(i x) - 2), x, pi)")]
45+
public void ThereIsNone(string limit)
46+
{
47+
var answer = limit.ToEntity().Simplify();
48+
Assert.True(IsUnevaluated(answer) || answer == MathS.NaN, $"{limit} is {answer}");
49+
}
50+
51+
/// <summary>A limit left as a limit, where ln(-1) is an answer like any number.</summary>
52+
private static bool IsUnevaluated(Entity answer) => answer.Nodes.Any(node => node is Entity.Limitf);
53+
54+
/// <summary>Along the real line the value on the cut is the limit, and is answered as before.</summary>
55+
[Theory]
56+
[InlineData("limit(ln(x), x, -1)", "i pi")]
57+
[InlineData("limitright(ln(x), x, -1)", "i pi")]
58+
[InlineData("limit(ln(x - 2), x, 0)", "ln(-2)")]
59+
[InlineData("limit(sqrt(x - 2), x, 0)", "sqrt(-2)")]
60+
[InlineData("limit(ln(-1 + x^2), x, 0)", "i pi")]
61+
[InlineData("limit(x^(1/3), x, -8)", "-2")]
62+
[InlineData("limitright(x^x, x, -1)", "-1")]
63+
[InlineData("limitright(ln(x^x), x, -1/2)", "ln((-1/2)^(-1/2))")]
64+
[InlineData("limit(ln(sin(x) - 2), x, 0)", "ln(-2)")]
65+
public void AlongTheRealLineItIsTheValue(string limit, string value)
66+
=> Assert.Equal(value.ToEntity().Evaled, limit.ToEntity().Simplify().Evaled);
67+
}
68+
}

0 commit comments

Comments
 (0)