Skip to content

Commit 4283f8b

Browse files
A complex constant does not make the two sides of a limit differ (#2376)
Where the descent cannot compare the two sides of a limit, each side is asked through the whole of the machinery, but only of an expression that IsRealOnBothSides passes, and that check required every constant to be real. pi^2 / log(x, -2) is pi^2 ln(x) / ln(-2), 0 from each side of 1, and its two-sided limit was NaN. A constant is the same number on both sides, so a complex one cannot make them differ; it is now accepted, and what depends on x is read as before. x^x, x ln(x), x^i, i sgn(x) and (2 + i)/x at 0 stay NaN. limitcheck at DEPTH=3 over 39 seeds: eight two-sided NaNs answered (0, -oo, pi/2 among them), no other move. tanh(log(x, -1) - tan(x)) at 1 is still NaN; asking both sides now takes 14 s where it took 3 s, since each one-sided limit of it takes 4-6 s on master already. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 60e6638 commit 4283f8b

3 files changed

Lines changed: 63 additions & 3 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,20 @@ root near 23.
9393
| `"x^7 - 5x^6 + 1 = 0".Solve("x")` | six roots, none of them near 5 | seven roots |
9494
| `"x^4 - 3*x^(5/2) + 2 = 0".Solve("x")` | `{ 1, 4.8870…^(2/5) }` | four roots: `1`, `1.3734…^2`, and two off the real line |
9595

96+
### A complex constant does not make the two sides of a limit differ
97+
98+
**A two-sided limit with a complex constant in it is answered where each side is, where it was NaN.** Where the
99+
descent cannot compare the two sides, each is asked through the whole of the machinery, but only of an expression
100+
real on both sides, and every constant had to be real. `pi^2 / log(x, -2)` is `pi^2 ln(x) / ln(-2)`, which is 0 from
101+
each side of 1. A constant is the same number on both sides, so a complex one is now allowed; what depends on the
102+
variable is read as before, and `x^x`, `x ln(x)` and `x^i` at 0 are NaN as they were.
103+
104+
| Input | Was (2.6.0) | Now |
105+
|---|---|---|
106+
| `"pi^2 / log(x, -2)".ToEntity().Limit("x", 1)` | `NaN` | `0` |
107+
| `"(log(1/2, 1) + pi^2) / log(x, -2)".ToEntity().Limit("x", 1)` | `NaN` | `0` |
108+
| `"log(x ^ (-1), -1) ^ 2".ToEntity().Limit("x", 1)` | `NaN` | `-oo` |
109+
96110
### A step function reads the side its argument arrives from off the slope
97111

98112
**A one-sided limit of a floor or a ceiling whose argument arrives at a jump like a root is answered, where it was

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ node is Floorf or Ceilf or Roundf or Signumf
202202

203203
/// <summary>
204204
/// Whether <paramref name="expr"/> is real on both sides of a real <paramref name="dest"/>,
205-
/// close enough to it, decided structurally: every power to an exponent that is not whole,
205+
/// close enough to it, but for its constants, decided structurally: every power to an exponent that is not whole,
206206
/// and every logarithm, has a base and an argument positive on both sides, by
207-
/// <see cref="SignNear"/>. Where it is, its one-sided limits are limits of real values from
207+
/// <see cref="SignNear"/>. Where it is, its one-sided limits are limits of values it takes on
208208
/// either side, and their agreeing is the two-sided limit under any codomain. <c>x^x</c>
209209
/// is not, its base being negative on the left, and stays without one; <c>(x^2)^x</c> is,
210210
/// and was NaN at 0 where each side is 1. Anything else unlisted is not real, which costs
@@ -217,8 +217,12 @@ private static bool IsRealOnBothSides(Entity expr, Variable x, Entity dest)
217217
return RealThere(expr);
218218
bool RealThere(Entity node)
219219
{
220+
// A constant is the same number on both sides, so a complex one does not make
221+
// them differ: pi^2 / log(x, -2), which is pi^2 ln(x) / ln(-2), is 0 from each
222+
// side of 1 and was NaN. What a side could differ in is a part that depends on x,
223+
// and those are read below as before.
220224
if (!node.ContainsNode(x))
221-
return node.Evaled is Real { IsFinite: true };
225+
return node.Evaled is Complex { IsFinite: true };
222226
return node switch
223227
{
224228
Variable variable => variable == x,
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 two-sided limit whose sides the descent could not compare asks each side through the whole of the machinery,
15+
/// but only of an expression real on both sides, and a constant was required to be real. <c>pi^2 / log(x, -2)</c> is
16+
/// <c>pi^2 ln(x) / ln(-2)</c>, 0 from each side of 1, and its two-sided limit was NaN. A constant is the same number
17+
/// on both sides, so a complex one does not make them differ. Found by limitcheck at <c>DEPTH=3</c>, <c>SEED=69</c>;
18+
/// no issue was filed.
19+
/// </summary>
20+
[Trait("Area", "Calculus")]
21+
public sealed class AComplexConstantIsTheSameOnBothSidesTest
22+
{
23+
[Theory]
24+
[InlineData("pi^2 / log(x, -2)", "1", "0")]
25+
[InlineData("(log(1/2, 1) + pi^2) / log(x, -2)", "1", "0")]
26+
[InlineData("log(x ^ (-1), -1) ^ 2", "1", "-oo")]
27+
public void IsWhereBothSidesAgree(string input, string destination, string expected)
28+
=> Assert.Equal(MathS.FromString(expected).Simplify(),
29+
MathS.FromString(input).Limit("x", destination).Simplify());
30+
31+
// Where a part that depends on x is not real on one side, or the sides differ, there is still no limit.
32+
[Theory]
33+
[InlineData("i * sgn(x)", "0")]
34+
[InlineData("(2 + i) / x", "0")]
35+
[InlineData("x ^ x", "0")]
36+
[InlineData("x ^ i", "0")]
37+
[InlineData("x * ln(x)", "0")]
38+
[InlineData("ln(-2) / ln(x)", "1")]
39+
public void IsStillNaNWhereTheSidesDiffer(string input, string destination)
40+
=> Assert.Equal(MathS.NaN, MathS.FromString(input).Limit("x", destination));
41+
}
42+
}

0 commit comments

Comments
 (0)