From cbb06437d6cb1d46705d6adbb191b544c4090aed Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Sat, 7 Nov 2026 03:56:00 +0000 Subject: [PATCH] Give no limit to a quotient whose divisor is 0 near the point abs(x) - x is 0 for every positive x, so (abs(x) - x) / (abs(x) - x) has no value anywhere near 1, and l'Hopital's rule, whose premise is a divisor that is not 0 near the point, read it as 1. A divisor holding an abs or a sign is checked first: with each abs and sign read by the sign its argument keeps near the destination, does it simplify to 0? Nothing is sampled, since a sample can land on a zero. Where it does, the limit is NaN; two-sided, only where it does on both sides, since one side alone still approaches the point. Co-Authored-By: Claude Opus 5.5 --- BREAKING-CHANGES.md | 12 ++++++ .../Limits/Solvers/Solvers.Definition.cs | 11 ++++++ .../Continuous/Limits/Transformations.cs | 22 +++++++++++ .../ADivisorThatIsZeroNearThePointTest.cs | 38 +++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 Sources/Tests/UnitTests/Calculus/ADivisorThatIsZeroNearThePointTest.cs diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index ca43f9bdc..4e4139896 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -123,6 +123,18 @@ four parts it is built from. | `"ln(arctan(x) + x) / ln(x)".ToEntity().Limit("x", "+oo")` | unevaluated | `1` | | `"tanh(x) * x / (x + tanh(x))".ToEntity().Limit("x", "-oo")` | did not finish in 30 s | `-1` | +### A quotient whose divisor is 0 near the point has no limit there + +**A limit of a quotient whose divisor is 0 all the way in is NaN, where it was a number.** `abs(x) - x` is +0 for every positive `x`, so `(abs(x) - x) / (abs(x) - x)` has no value anywhere near 1, and l'Hopital's +rule, whose premise is a divisor that is not 0 near the point, read it as 1. A two-sided limit is NaN only +where the divisor is 0 on both sides, since one side alone still approaches the point. + +| Input | Was (2.6.0) | Now | +|---|---|---| +| `"(abs(x) - x) / (abs(x) - x)".ToEntity().Limit("x", 1)` | `1` | `NaN` | +| `"(abs(x) - x) * x / ((abs(x) - x) * sin(x))".ToEntity().Limit("x", 0, ApproachFrom.Right)` | `1` | `NaN` | + ### 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 diff --git a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs index 15282cee5..768487a25 100644 --- a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs +++ b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs @@ -377,6 +377,17 @@ internal static T WithinABudget(int limits, System.Func compute) : RealCodomainWithdraws(expr, x, dest, side)) return null; + // A quotient whose divisor is 0 all the way in has no value there, and has no limit: + // (abs(x) - x) / (abs(x) - x) at 1 was 1, from l'Hopital's rule, whose premise is a + // divisor that is not 0 near the point. Two-sided, only where it has no value on + // either side, since one side alone still approaches the point. + if (dest.IsFinite && expr is Divf(_, var divisor) + && divisor.ContainsNode(x) && divisor.Nodes.Any(static node => node is Absf or Signumf) + && (side is ApproachFrom.BothSides + ? VanishesNear(divisor, x, dest, ApproachFrom.Left) && VanishesNear(divisor, x, dest, ApproachFrom.Right) + : VanishesNear(divisor, x, dest, side))) + return MathS.NaN; + expr = expr.Replace(ExpandLogarithm); // In front of both paths, not only the two-sided one. Each of these is guarded on diff --git a/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs index f24e2fc6c..542eb99f1 100644 --- a/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs +++ b/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs @@ -1290,6 +1290,28 @@ internal static Entity AtALargeDecimal(Entity expr, Variable x) } } + /// + /// Whether is 0 throughout a punctured one-sided + /// neighbourhood of the destination: with every abs and sign in it whose argument keeps a + /// sign there replaced by that argument or its negative, and by that sign, it simplifies to + /// 0. Nothing is sampled, since a sample can land on a zero: sin(pi / x) is 0 at every + /// power of ten. + /// + internal static bool VanishesNear(Entity difference, Variable x, Entity dest, ApproachFrom side) + { + var read = difference.Replace(node => node switch + { + Absf(var argument) when argument.ContainsNode(x) && SignNear(argument, x, dest, side) is { } sign + => sign > 0 ? argument : -argument, + Signumf(var argument) when argument.ContainsNode(x) && SignNear(argument, x, dest, side) is { } sign + => Integer.Create(sign), + _ => node + }); + var simplified = read.Simplify(); + while (simplified is Providedf(var body, _)) simplified = body; + return simplified == Integer.Zero; + } + /// /// How deep the rule may be applied to one limit. Differentiating both parts does not /// always make the quotient simpler -- x / sqrt(x^2 + 1) turns into sqrt(x^2 + 1) / x, diff --git a/Sources/Tests/UnitTests/Calculus/ADivisorThatIsZeroNearThePointTest.cs b/Sources/Tests/UnitTests/Calculus/ADivisorThatIsZeroNearThePointTest.cs new file mode 100644 index 000000000..97df0193d --- /dev/null +++ b/Sources/Tests/UnitTests/Calculus/ADivisorThatIsZeroNearThePointTest.cs @@ -0,0 +1,38 @@ +// +// 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 quotient whose divisor is 0 throughout the approach has no value there and no limit. + /// abs(x) - x is 0 for every positive x, and l'Hopital's rule, whose premise is a divisor that + /// is not 0 near the point, read (abs(x) - x) / (abs(x) - x) at 1 as 1. Found while probing a + /// cancellation in l'Hopital's rule; no issue was filed. + /// + [Trait("Area", "Calculus")] + public sealed class ADivisorThatIsZeroNearThePointTest + { + [Theory] + [InlineData("(abs(x) - x) / (abs(x) - x)", "1", ApproachFrom.BothSides)] + [InlineData("(abs(x) - x) / (abs(x) - x)", "1", ApproachFrom.Left)] + [InlineData("(abs(x) - x) * x / ((abs(x) - x) * sin(x))", "0", ApproachFrom.Right)] + public void HasNoLimit(string input, string destination, ApproachFrom side) + => Assert.Equal(MathS.NaN, MathS.FromString(input).Limit("x", destination, side)); + + // Where the divisor is not 0, or is 0 on one side only of a two-sided limit, the limit stands. + [Theory] + [InlineData("(abs(x) - x) / (abs(x) - x)", "-1", ApproachFrom.BothSides, "1")] + [InlineData("(abs(x) - x) * x / ((abs(x) - x) * sin(x))", "0", ApproachFrom.Left, "1")] + [InlineData("(abs(x) - x) * x / ((abs(x) - x) * sin(x))", "0", ApproachFrom.BothSides, "1")] + [InlineData("x / (abs(x) - x)", "0", ApproachFrom.Left, "-1/2")] + public void Stands(string input, string destination, ApproachFrom side, string expected) + => Assert.Equal(MathS.FromString(expected), MathS.FromString(input).Limit("x", destination, side)); + } +}