diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md
index 4a85794fe..9c7580899 100644
--- a/BREAKING-CHANGES.md
+++ b/BREAKING-CHANGES.md
@@ -152,6 +152,22 @@ since past about 10^100 an integer times a radical is folded into a rounded deci
| `32768 * 2^(-29/2)` | `32768 * 2 ^ (-29/2)` | `sqrt(2)` |
| `2 / (2^(-29/2) * 32768)` | `1/16384 / 2 ^ (-29/2)` | `sqrt(2)` |
+### A two-sided limit is NaN only where its sides say so
+
+**Not silent: a wrong answer becomes an unevaluated limit.** A two-sided limit came back `NaN`, the claim that it does
+not exist, from an indeterminate form the machinery could not read. The difference quotient of `abs` at a symbolic
+point is `sgn(a)` for every real `a` other than 0, and each side alone was left unevaluated, while the two-sided limit
+was `NaN`. A side that stops at `0 / 0` where the expression has a value beside the point, its other symbols read as
+a number, is now undecided for an expression that may take complex values too, as it already was for a real one, and
+the limit is left unevaluated. `(x - x) / (x - x)`, which has no value anywhere, is still `NaN`
+([#2667](https://github.com/asc-community/AngouriMath/issues/2667)).
+
+| `.Limit(x, ...)` | Was (2.10.0) | Now |
+|---|---|---|
+| `(abs(a + x) - abs(a)) / x` at 0 | `NaN` | `limit((abs(a + x) - abs(a)) / x, x, 0)` |
+| `(abs(x) - abs(a)) / (x - a)` at `a` | `NaN` | unevaluated |
+| `abs(x) / x`, `1 / x`, `sin(1 / x)` at 0 | `NaN` | unchanged |
+
### A real integral through ln of a negative number is real
**Not silent: a divergent integral had an imaginary part, and a finite one was written through `ln` of a negative
diff --git a/Sources/.editorconfig b/Sources/.editorconfig
index cf33fc601..d627a2c3f 100644
--- a/Sources/.editorconfig
+++ b/Sources/.editorconfig
@@ -45,6 +45,9 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
[AngouriMath/Functions/TreeAnalyzer/PerfectPower.cs]
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
+[Tests/UnitTests/Calculus/AnUndecidedSideIsNotADisagreementTest.cs]
+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
+
[Tests/UnitTests/Common/TheWholePartOfALargeRationalPowerTest.cs]
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
diff --git a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs
index be062dcd7..4031c189f 100644
--- a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs
+++ b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs
@@ -196,9 +196,15 @@ node is Floorf or Ceilf or Roundf or Signumf
// is the limit: floor(1/x) / floor(2/x) at 0 is 1/2 from each side, the one-sided
// paths do not decide it, and a NaN here would say there is no limit.
aSideIsUndecided = false;
- if (bothSidesDepth >= MaxBothSidesDepth
- || MathS.Settings.Codomain.Value is not AngouriMath.Core.Domain.Real && !IsRealOnBothSides(expr, x, dest))
+ if (bothSidesDepth >= MaxBothSidesDepth)
return null;
+ // Agreement is promoted to the limit only for real-valued functions. Off them the sides
+ // are still asked, but only for whether one of them is undecided: a NaN is no answer where
+ // a side has none yet. (abs(a + x) - abs(a)) / x at 0, with a free to be complex, stops at
+ // 0 / 0 from each side, has a value beside the point, and was NaN where it is sgn(a) for
+ // every real a other than 0.
+ // https://github.com/asc-community/AngouriMath/issues/2667
+ var promoting = MathS.Settings.Codomain.Value is AngouriMath.Core.Domain.Real || IsRealOnBothSides(expr, x, dest);
bothSidesDepth++;
try
{
@@ -215,7 +221,7 @@ node is Floorf or Ceilf or Roundf or Signumf
aSideIsUndecided = true;
return null;
}
- return fromLeft == fromRight || ExpressionNumerical.AreEqual(fromLeft, fromRight)
+ return promoting && (fromLeft == fromRight || ExpressionNumerical.AreEqual(fromLeft, fromRight))
? fromLeft : null;
}
finally { bothSidesDepth--; }
@@ -230,13 +236,45 @@ node is Floorf or Ceilf or Roundf or Signumf
// value beside the point: 0 / 0 for (x - x) / (x - x), which has no value anywhere, and
// ln(-2) / 0 for ln(-2) / ln(x) at 1, whose values there are not real and whose sides
// are infinities in different directions.
+ // Off the real functions a form with an infinity in it is undecided as it is on them, and of the forms of
+ // finite parts only 0 / 0 itself, where the expression has a value beside the point with its other symbols
+ // read as a number: (x - x) / (x - x) has none, and its NaN stands.
Entity? Decided(Entity? limit, ApproachFrom side)
=> limit is { } && IsAnIndeterminateForm(limit)
&& (limit.Nodes.Any(static node => node is Real { IsFinite: false })
- || IsRealBeside(expr, x, dest, side))
+ || (promoting
+ ? IsRealBeside(expr, x, dest, side)
+ : limit is Divf(var above, var below) && above.Evaled is Complex { IsZero: true } && below.Evaled is Complex { IsZero: true }
+ && HasAValueBeside(expr, x, dest, side)))
? null : limit;
}
+ ///
+ /// Whether has a finite value, real or not, at two points on
+ /// of a finite , 10^-6 and 10^-9 away, with every other symbol read as one generic
+ /// number. A witness only: a side it finds a value on is left undecided, never answered.
+ /// https://github.com/asc-community/AngouriMath/issues/2667
+ ///
+ private static bool HasAValueBeside(Entity expr, Variable x, Entity dest, ApproachFrom side)
+ {
+ if (side is ApproachFrom.BothSides || dest.Evaled is Number { IsFinite: false })
+ return false;
+ var generic = Rational.Create(3719, 10000);
+ var reading = expr;
+ var at = dest;
+ foreach (var other in expr.Vars.Concat(dest.Vars).Where(v => v != x).Distinct().ToList())
+ {
+ reading = reading.Substitute(other, generic);
+ at = at.Substitute(other, generic);
+ }
+ if (at.Evaled is not Complex { IsFinite: true } point)
+ return false;
+ var sign = side is ApproachFrom.Left ? -1 : 1;
+ return ValueAt(Rational.Create(sign, 1_000_000)) && ValueAt(Rational.Create(sign, 1_000_000_000));
+ bool ValueAt(Rational offset)
+ => reading.Substitute(x, point + offset).Evaled is Complex { IsFinite: true, IsNaN: false };
+ }
+
///
/// Whether has a finite real value at two points on
/// of a finite real , 10^-6 and 10^-9 away.
diff --git a/Sources/Tests/UnitTests/Calculus/AnUndecidedSideIsNotADisagreementTest.cs b/Sources/Tests/UnitTests/Calculus/AnUndecidedSideIsNotADisagreementTest.cs
new file mode 100644
index 000000000..014a82031
--- /dev/null
+++ b/Sources/Tests/UnitTests/Calculus/AnUndecidedSideIsNotADisagreementTest.cs
@@ -0,0 +1,58 @@
+//
+// 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 System.Linq;
+using AngouriMath.Extensions;
+using Xunit;
+
+namespace AngouriMath.Tests.Calculus
+{
+ ///
+ /// A two-sided limit is NaN only where its sides disagree or one of them has no limit. Where a
+ /// side is undecided, the NaN of an indeterminate form the machinery could not read is not that
+ /// claim, and the limit is left unevaluated: the difference quotient of abs at a symbolic point
+ /// is sgn(a) for every real a other than 0, and was answered NaN.
+ /// https://github.com/asc-community/AngouriMath/issues/2667
+ ///
+ [Trait("Area", "Calculus")]
+ public sealed class AnUndecidedSideIsNotADisagreementTest
+ {
+ [Theory]
+ [InlineData("(abs(a + x) - abs(a)) / x", "0")]
+ [InlineData("(abs(x) - abs(a)) / (x - a)", "a")]
+ [InlineData("(abs(a + x) - abs(a)) * x^(-1)", "0")]
+ public void IsLeftUnevaluated(string expression, string destination)
+ {
+ // Through every entry point: the two-sided overload, the one naming the side, and Simplify of the node.
+ foreach (var limit in new[] {
+ expression.ToEntity().Limit("x", destination.ToEntity()),
+ expression.ToEntity().Limit("x", destination.ToEntity(), AngouriMath.Core.ApproachFrom.BothSides),
+ MathS.Limit(expression.ToEntity(), "x", destination.ToEntity()).Simplify() })
+ {
+ Assert.NotEqual(MathS.NaN, limit.Evaled);
+ Assert.Contains(limit.Nodes, node => node is Entity.Limitf);
+ }
+ }
+
+ /// Where the sides do disagree, or one has no limit, NaN stands.
+ [Theory]
+ [InlineData("abs(x) / x", "0")]
+ [InlineData("1 / x", "0")]
+ [InlineData("sin(1 / x)", "0")]
+ [InlineData("e^(1 / x)", "0")]
+ [InlineData("tan(x)", "pi / 2")]
+ [InlineData("1 / (x - a)", "a")]
+ [InlineData("abs(x + a) / x", "0")]
+ public void ADisagreementIsStillNaN(string expression, string destination)
+ => Assert.Equal(MathS.NaN, expression.ToEntity().Limit("x", destination.ToEntity()).Evaled);
+
+ /// And a limit that exists is answered as before.
+ [Fact]
+ public void ANumericPointIsAnswered()
+ => Assert.Equal(Entity.Number.Integer.One, "(abs(2 + x) - 2) / x".ToEntity().Limit("x", 0).Evaled);
+ }
+}