From c40d8767f7a64431c69f1f987faf489d84650e18 Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Mon, 9 Nov 2026 15:53:44 +0000 Subject: [PATCH] Ask the parts of a one-sided limit's sum for their limits from its side The trivial transformations a limit makes before its descent replace a sum, a difference or a product by the limits of its parts where both are finite. They asked each part from both sides, also for a one-sided limit. x^pi / log(x, 2) - 2 at 0 from the right took its quotient through l'Hopital's rule from the left as well, where x^pi is not real, and on to +oo by the substitution that side asks for: 10 s, where the quotient alone takes 0.2 s. Each part is now asked from the side the limit is. Finite one-sided limits of the parts are the one-sided limit of their sum, difference or product, so the rewrite says nothing it could not say before; the two-sided case is as it was. The limit takes 0.19 s from the right and 0.85 s from the left, with the same answers. A part with a finite limit from the side approached and none from the other no longer keeps the whole unevaluated: x^x at 0 from the left goes to 1, so log(x, 1) - x^x + 1 is 0 there, where 2.6.0 and master leave it unevaluated. The limitcheck A/B against master answers eight such rows and loses none. Co-Authored-By: Claude Opus 5.5 --- BREAKING-CHANGES.md | 16 ++++++ .../Limits/Solvers/Solvers.Definition.cs | 2 +- .../Continuous/Limits/Transformations.cs | 15 ++++-- .../ATermIsAskedFromTheSideOfItsLimitTest.cs | 54 +++++++++++++++++++ 4 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 Sources/Tests/UnitTests/Calculus/ATermIsAskedFromTheSideOfItsLimitTest.cs diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 325aca1bf..1bae30766 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -107,6 +107,22 @@ filed. | `"floor(log(x - 1, x))".ToEntity().Limit("x", 1, ApproachFrom.Right)` | `limitright(floor(log(x - 1, x)), x, 1)` | `-1` | | `"floor(x / log(x, x))".ToEntity().Limit("x", 0, ApproachFrom.Left)` | `limitleft(floor(x / log(x, x)), x, 0)` | `-1` | +### A one-sided limit asks the parts of a sum or product from its side + +**Silent: before searching, a one-sided limit replaces a sum, difference or product whose parts have finite limits by +those limits, and asks each part from the side of the limit rather than from both.** A part with a finite limit from +the side approached and none from the other, such as `x ^ x` at 0 from the left, no longer keeps the whole +unevaluated; and a part reaching the same value from both sides is no longer worked through l'Hopital's rule on the +side that is not approached, so `x ^ pi / log(x, 2) - 2` at 0 from the right takes 0.2 s rather than 10 s. Found by +limitcheck; no issue was filed. + +| Input | Was (2.6.0) | Now | +|---|---|---| +| `"log(x, 1) - x ^ x + 1".ToEntity().Limit("x", 0, ApproachFrom.Left)` | `limitleft(log(x, 1) - x ^ x + 1, x, 0)` | `0` | +| `"-tan(x) ^ abs(x)".ToEntity().Limit("x", 0, ApproachFrom.Left)` | `limitleft(-tan(x) ^ abs(x), x, 0)` | `-1` | +| `"1/2 * x ^ abs(x)".ToEntity().Limit("x", 0, ApproachFrom.Left)` | `limitleft(1/2 * x ^ abs(x), x, 0)` | `1/2` | +| `"(pi / x) ^ erf(x) * e ^ log(x, x)".ToEntity().Limit("x", 0, ApproachFrom.Left)` | `limitleft((pi / x) ^ erf(x) * e ^ log(x, x), x, 0)` | `e` | + ### A grown derivatives' quotient is read by its terms in a limit **Silent: where l'Hopital's rule turns away a derivatives' quotient for growing too much, a one-sided limit at a finite diff --git a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs index e6c3f743a..2279192a8 100644 --- a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs +++ b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs @@ -521,7 +521,7 @@ node is Derivativef(var expression, Variable variable, var iterations) && iterat // second remarkable limit the descent reads it as 1^(+oo) and is definite about // it, where the same expression approached from both sides gives e. expr = expr.Replace(a => TrivialTrigonometricReplacement(a, x)); - expr = ApplyTrivialTransformations(expr, x, dest, (_, exprLim) => exprLim); + expr = ApplyTrivialTransformations(expr, x, dest, side, (_, exprLim) => exprLim); expr = ApplyFirstRemarkableOverFactors(expr, x, dest); expr = expr.Replace(c => ApplySecondRemarkable(c, x, dest)); // A tangent is a quotient as much as a cosecant is a reciprocal, and leaving it diff --git a/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs index fe4e71925..193f26807 100644 --- a/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs +++ b/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs @@ -2347,19 +2347,26 @@ private static bool ContainsRadical(Entity expr, Variable x) => expr.Nodes.Any(node => node is Powf(var @base, Number.Rational and not Number.Integer) && @base.ContainsNode(x)); - private static Entity ApplyTrivialTransformations(Entity expr, Variable x, Entity dest, Func transformation) + /// + /// Each part is asked from the side the limit is, not from both: finite one-sided limits of the parts are the + /// one-sided limit of their sum, difference or product. Asked from both sides, x^pi / log(x, 2) - 2 at 0 from + /// the right had its quotient taken through l'Hopital's rule from the left as well, where x^pi is not real, + /// and at +oo after the substitution that side asks for, and took 10 seconds where the quotient alone takes a + /// fifth of one. + /// + private static Entity ApplyTrivialTransformations(Entity expr, Variable x, Entity dest, ApproachFrom side, Func transformation) => expr switch { Sumf(var a, var b) - when ComputeLimit(a, x, dest) is { } aLim && ComputeLimit(b, x, dest) is { } bLim && + when ComputeLimit(a, x, dest, side) is { } aLim && ComputeLimit(b, x, dest, side) is { } bLim && IsFiniteNode(aLim.Evaled) && IsFiniteNode(bLim.Evaled) => transformation(a, aLim) + transformation(b, bLim), Minusf(var a, var b) - when ComputeLimit(a, x, dest) is { } aLim && ComputeLimit(b, x, dest) is { } bLim && + when ComputeLimit(a, x, dest, side) is { } aLim && ComputeLimit(b, x, dest, side) is { } bLim && IsFiniteNode(aLim.Evaled) && IsFiniteNode(bLim.Evaled) => transformation(a, aLim) - transformation(b, bLim), Mulf(var a, var b) - when ComputeLimit(a, x, dest) is { } aLim && ComputeLimit(b, x, dest) is { } bLim && + when ComputeLimit(a, x, dest, side) is { } aLim && ComputeLimit(b, x, dest, side) is { } bLim && IsFiniteNode(aLim.Evaled) && IsFiniteNode(bLim.Evaled) => transformation(a, aLim) * transformation(b, bLim), _ => expr diff --git a/Sources/Tests/UnitTests/Calculus/ATermIsAskedFromTheSideOfItsLimitTest.cs b/Sources/Tests/UnitTests/Calculus/ATermIsAskedFromTheSideOfItsLimitTest.cs new file mode 100644 index 000000000..5af1d1807 --- /dev/null +++ b/Sources/Tests/UnitTests/Calculus/ATermIsAskedFromTheSideOfItsLimitTest.cs @@ -0,0 +1,54 @@ +// +// 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; +using System.Threading.Tasks; +using AngouriMath.Core; +using AngouriMath.Extensions; +using Xunit; + +namespace AngouriMath.Tests.Calculus +{ + /// + /// A one-sided limit of a sum, a difference or a product asked each of its parts for its limit from both sides. + /// x^pi / log(x, 2) - 2 at 0 from the right took its quotient through l'Hopital's rule from the left as well, where + /// x^pi is not real, and took 10 seconds where the quotient alone takes a fifth of one. Found by limitcheck; no + /// issue was filed. + /// + [Trait("Area", "Calculus")] + public sealed class ATermIsAskedFromTheSideOfItsLimitTest + { + [Theory] + [InlineData("x^pi / log(x, 2) - 2", ApproachFrom.Right, "-2")] + [InlineData("x^pi / log(x, 2) + 2", ApproachFrom.Right, "2")] + [InlineData("x^e / log(x, 2) - 2", ApproachFrom.Right, "-2")] + [InlineData("x^pi / log(x, 2) - 2", ApproachFrom.Left, "-2")] + public void ADifferenceAtZeroFinishes(string input, ApproachFrom side, string expected) + { + Entity? limit = null; + var task = Task.Factory.StartNew(() => limit = input.ToEntity().Limit("x", 0, side), TaskCreationOptions.LongRunning); + Assert.True(task.Wait(TimeSpan.FromMinutes(1)), "the limit did not finish in a minute"); + Assert.Equal(expected.ToEntity(), limit); + } + + // A part with a limit from the side approached and none from the other no longer keeps the whole unevaluated: + // x^x at 0 from the left is |x|^x e^(i pi x), which goes to 1. + [Theory] + [InlineData("log(x, 1) - x ^ x + 1", "0")] + [InlineData("-tan(x) ^ abs(x)", "-1")] + [InlineData("1/2 * x ^ abs(x)", "1/2")] + public void APartIsReadFromTheLeft(string input, string expected) + => Assert.Equal(expected.ToEntity(), input.ToEntity().Limit("x", 0, ApproachFrom.Left)); + + // Each side is still its own: a step whose sides differ is read from the side asked. + [Theory] + [InlineData(ApproachFrom.Right, "1")] + [InlineData(ApproachFrom.Left, "-1")] + public void AStepIsReadFromItsSide(ApproachFrom side, string expected) + => Assert.Equal(expected.ToEntity(), "sqrt(x) + abs(x) / x".ToEntity().Limit("x", 0, side)); + } +}