From bfe7fffdef899feec8832becc22dbba7feb1e7ce Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Fri, 6 Nov 2026 01:23:07 +0000 Subject: [PATCH] A complex constant does not make the two sides of a limit differ 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 --- BREAKING-CHANGES.md | 14 +++++++ .../Limits/Solvers/Solvers.Definition.cs | 10 +++-- ...ComplexConstantIsTheSameOnBothSidesTest.cs | 42 +++++++++++++++++++ 3 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 Sources/Tests/UnitTests/Calculus/AComplexConstantIsTheSameOnBothSidesTest.cs diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 40d064d4a..bbf7f4a34 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -93,6 +93,20 @@ root near 23. | `"x^7 - 5x^6 + 1 = 0".Solve("x")` | six roots, none of them near 5 | seven roots | | `"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 | +### A complex constant does not make the two sides of a limit differ + +**A two-sided limit with a complex constant in it is answered where each side is, where it was NaN.** Where the +descent cannot compare the two sides, each is asked through the whole of the machinery, but only of an expression +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 +each side of 1. A constant is the same number on both sides, so a complex one is now allowed; what depends on the +variable is read as before, and `x^x`, `x ln(x)` and `x^i` at 0 are NaN as they were. + +| Input | Was (2.6.0) | Now | +|---|---|---| +| `"pi^2 / log(x, -2)".ToEntity().Limit("x", 1)` | `NaN` | `0` | +| `"(log(1/2, 1) + pi^2) / log(x, -2)".ToEntity().Limit("x", 1)` | `NaN` | `0` | +| `"log(x ^ (-1), -1) ^ 2".ToEntity().Limit("x", 1)` | `NaN` | `-oo` | + ### A step function reads the side its argument arrives from off the slope **A one-sided limit of a floor or a ceiling whose argument arrives at a jump like a root is answered, where it was diff --git a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs index 3c14c6e5b..15282cee5 100644 --- a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs +++ b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs @@ -202,9 +202,9 @@ node is Floorf or Ceilf or Roundf or Signumf /// /// Whether is real on both sides of a real , - /// close enough to it, decided structurally: every power to an exponent that is not whole, + /// close enough to it, but for its constants, decided structurally: every power to an exponent that is not whole, /// and every logarithm, has a base and an argument positive on both sides, by - /// . Where it is, its one-sided limits are limits of real values from + /// . Where it is, its one-sided limits are limits of values it takes on /// either side, and their agreeing is the two-sided limit under any codomain. x^x /// is not, its base being negative on the left, and stays without one; (x^2)^x is, /// 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) return RealThere(expr); bool RealThere(Entity node) { + // A constant is the same number on both sides, so a complex one does not make + // them differ: pi^2 / log(x, -2), which is pi^2 ln(x) / ln(-2), is 0 from each + // side of 1 and was NaN. What a side could differ in is a part that depends on x, + // and those are read below as before. if (!node.ContainsNode(x)) - return node.Evaled is Real { IsFinite: true }; + return node.Evaled is Complex { IsFinite: true }; return node switch { Variable variable => variable == x, diff --git a/Sources/Tests/UnitTests/Calculus/AComplexConstantIsTheSameOnBothSidesTest.cs b/Sources/Tests/UnitTests/Calculus/AComplexConstantIsTheSameOnBothSidesTest.cs new file mode 100644 index 000000000..4b096718b --- /dev/null +++ b/Sources/Tests/UnitTests/Calculus/AComplexConstantIsTheSameOnBothSidesTest.cs @@ -0,0 +1,42 @@ +// +// 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 Xunit; + +namespace AngouriMath.Tests.Calculus +{ + /// + /// A two-sided limit whose sides the descent could not compare asks each side through the whole of the machinery, + /// but only of an expression real on both sides, and a constant was required 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 does not make them differ. Found by limitcheck at DEPTH=3, SEED=69; + /// no issue was filed. + /// + [Trait("Area", "Calculus")] + public sealed class AComplexConstantIsTheSameOnBothSidesTest + { + [Theory] + [InlineData("pi^2 / log(x, -2)", "1", "0")] + [InlineData("(log(1/2, 1) + pi^2) / log(x, -2)", "1", "0")] + [InlineData("log(x ^ (-1), -1) ^ 2", "1", "-oo")] + public void IsWhereBothSidesAgree(string input, string destination, string expected) + => Assert.Equal(MathS.FromString(expected).Simplify(), + MathS.FromString(input).Limit("x", destination).Simplify()); + + // Where a part that depends on x is not real on one side, or the sides differ, there is still no limit. + [Theory] + [InlineData("i * sgn(x)", "0")] + [InlineData("(2 + i) / x", "0")] + [InlineData("x ^ x", "0")] + [InlineData("x ^ i", "0")] + [InlineData("x * ln(x)", "0")] + [InlineData("ln(-2) / ln(x)", "1")] + public void IsStillNaNWhereTheSidesDiffer(string input, string destination) + => Assert.Equal(MathS.NaN, MathS.FromString(input).Limit("x", destination)); + } +}