From e8199a7b09917859c22b5b9b3c0db2cede8117a9 Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Fri, 30 Oct 2026 19:11:03 +0000 Subject: [PATCH] A limit at the jump of a step function is not answered by substitution floor, ceil and sgn each decline a limit whose argument arrives on one of their jumps, since the value differs on the two sides. But where the node declined, the dispatcher answered the whole expression by substitution, which evaluates through the jump. floor(x) - 1 from the left of 0 is floor(-1/t) - 1 at t = +oo there, and -1/oo evaluates to 0, so the limit came back -1 where it is -2, and the two-sided limit, which does not exist, came back -1 too. SolveBySubstitution now declines when a floor, ceil or round, or a sgn, has an argument that lands on one of its jumps at the destination: an integer, a half-integer, and 0. LimitAtAJumpTest takes seven one-sided limits at a jump, which must be the limit or nothing, four two-sided ones, which must have no value, and four away from a jump, which keep their values. Nine fail on master. A limit on a branch cut answered by substitution, limitright(ln(x^x), x, -1), is left for #2266. Found by work/limitcheck. Part of #2266. Co-Authored-By: Claude Opus 5.5 (1M context) --- BREAKING-CHANGES.md | 15 +++++ Sources/.editorconfig | 3 + .../Limits/Solvers/Limit.Solvers.cs | 29 ++++++++++ .../UnitTests/Calculus/LimitAtAJumpTest.cs | 58 +++++++++++++++++++ 4 files changed, 105 insertions(+) create mode 100644 Sources/Tests/UnitTests/Calculus/LimitAtAJumpTest.cs diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index e2d1048ee..c377f503a 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -42,6 +42,21 @@ A not-equal written `<>` is read as `not (a = b)`, and printed that way. ## Unreleased — since 2.6.0 +### A limit at the jump of a step function is not answered by substitution + +**Silent: a limit of an expression built on `floor`, `ceil`, `round` or `sgn`, where the step's argument arrives on one +of its jumps, is left unevaluated, where it was answered by substituting the destination.** That value is the limit only +where the expression is continuous, and at a jump the value differs on the two sides. `floor(x) - 1` is -2 all the way in +from the left of 0, but substitution answered -1, and it answered the two-sided limit, which does not exist, with -1 too. +A bare `floor(x)` or `sgn(x)` was already declined there. Away from a jump, nothing changes +([#2266](https://github.com/asc-community/AngouriMath/issues/2266)). + +| Input | Was (2.6.0) | Now | +|---|---|---| +| `"limitleft(floor(x) - 1, x, 0)".ToEntity().Simplify()` | `-1` | `limitleft(floor(x) - 1, x, 0)` | +| `"limit(floor(x) + x, x, 1)".ToEntity().Simplify()` | `2` | `limit(floor(x) + x, x, 1)` | +| `"limitleft(-sgn(x), x, 0)".ToEntity().Simplify()` | `0` | `limitleft(-sgn(x), x, 0)` | + ### An equation through a negative whole power is not answered with no roots **Silent: an empty answer becomes the roots.** Inverting `x^n = v` for a negative whole `n` multiplied by the roots diff --git a/Sources/.editorconfig b/Sources/.editorconfig index 6cd877dc9..956681b59 100644 --- a/Sources/.editorconfig +++ b/Sources/.editorconfig @@ -75,6 +75,9 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed [Tests/UnitTests/Calculus/ModulusPhaseTest.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/LimitAtAJumpTest.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/Core/DomainConditionInAReadingTest.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/Limit.Solvers.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Solvers.cs index 06a5ab1db..088f31ca9 100644 --- a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Solvers.cs +++ b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Solvers.cs @@ -42,6 +42,14 @@ internal static class LimitSolvers internal static Entity? SolveBySubstitution(Entity expr, Variable x) { var res = expr.Substitute(x, Infinity); + // Reading the value at the destination is the limit only where the expression is continuous there, and a step + // function whose argument arrives on one of its jumps is not: floor(x) - 1 from the left of 0 is floor(-1/t) - 1 + // at t = +oo here, whose -1/oo evaluates to 0, and the floor of that is 0 where it is -1 all the way in. The + // nodes decline a jump themselves (LimitOfAStepFunction, Signumf's override), and this is where the declined + // node was answered anyway, as part of the expression it is in. + // https://github.com/asc-community/AngouriMath/issues/2266 + if (res.Nodes.Any(SitsOnAJump)) + return null; if (res.Evaled is Complex limit) { MultithreadingFunctional.ExitIfCancelled(); @@ -65,6 +73,27 @@ internal static class LimitSolvers return null; } + /// + /// Whether is a step function whose argument evaluates to one of its jumps: an integer for + /// floor and ceil, a half-integer for round, 0 for sgn. Taken on the real part, and on the + /// imaginary part of a value that is not real, as LimitOfAStepFunction takes it. + /// + private static bool SitsOnAJump(Entity node) + { + static bool Whole(Real part) => part is Integer || part.EDecimal.IsFinite && part.EDecimal.CompareTo(part.EDecimal.Floor()) == 0; + static bool OnAJump(Entity argument, System.Func jump) + => argument.Evaled is Complex { RealPart: var real, ImaginaryPart: var imaginary } value + && (jump(real) || value is not Real && jump(imaginary)); + return node switch + { + Floorf(var argument) => OnAJump(argument, Whole), + Ceilf(var argument) => OnAJump(argument, Whole), + Roundf(var argument) => OnAJump(argument, part => Whole((Real)(part + Rational.Create(1, 2)).Evaled)), + Signumf(var argument) => argument.Evaled is Complex { IsZero: true }, + _ => false, + }; + } + internal static Entity? SolveAsPolynomial(Entity expr, Variable x) { if (ParseAsPolynomial(expr, x) is { } mono) diff --git a/Sources/Tests/UnitTests/Calculus/LimitAtAJumpTest.cs b/Sources/Tests/UnitTests/Calculus/LimitAtAJumpTest.cs new file mode 100644 index 000000000..105e2fda0 --- /dev/null +++ b/Sources/Tests/UnitTests/Calculus/LimitAtAJumpTest.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 AngouriMath; +using AngouriMath.Extensions; +using Xunit; + +namespace AngouriMath.Tests.Calculus +{ + /// + /// A limit of an expression built on a step function is not answered by substituting the destination where the + /// step's argument arrives on a jump: limitleft(floor(x) - 1, x, 0) was -1, where it is -2, and the + /// two-sided limit, which does not exist, was -1 too. Declining is an honest answer there; a value is a wrong one + /// unless it is the limit. + /// #2266 + /// + [Trait("Area", "Calculus")] + public sealed class LimitAtAJumpTest + { + [Theory] + [InlineData("limitleft(floor(x) - 1, x, 0)", "-2")] + [InlineData("limitright(floor(x) - 1, x, 0)", "-1")] + [InlineData("limitleft(floor(x)^2, x, 0)", "1")] + [InlineData("limitleft(arcsin(floor(x)), x, 0)", "-pi / 2")] + [InlineData("limitleft(-sgn(x), x, 0)", "1")] + [InlineData("limitright(-sgn(x), x, 0)", "-1")] + [InlineData("limitleft(ceil(x) + 1, x, 1)", "2")] + public void AOneSidedLimitAtAJumpIsTheLimitOrNothing(string limit, string value) + { + var answer = limit.ToEntity().Simplify(); + Assert.True(answer is not Entity.Number || answer == value.ToEntity().Simplify(), $"{limit} is {answer}, where it is {value}"); + } + + [Theory] + [InlineData("limit(floor(x) - 1, x, 0)")] + [InlineData("limit(floor(x) + x, x, 1)")] + [InlineData("limit(-sgn(x), x, 0)")] + [InlineData("limit(round(x) + x, x, 1/2)")] + public void ATwoSidedLimitAtAJumpHasNoValue(string limit) + { + var answer = limit.ToEntity().Simplify(); + Assert.True(answer is not Entity.Number || answer.IsNaN, $"{limit} is {answer}, where the two sides differ"); + } + + /// Away from a jump the step is constant, and the limit is its value. + [Theory] + [InlineData("limit(floor(x) - 1, x, 1/2)", "-1")] + [InlineData("limit(sgn(x) + x, x, 2)", "3")] + [InlineData("limitleft(ceil(x) + 1, x, 1/2)", "2")] + [InlineData("limit(round(x) + x, x, 1/4)", "1/4")] + public void AwayFromAJumpTheLimitIsTheValue(string limit, string value) + => Assert.Equal(value.ToEntity().Simplify(), limit.ToEntity().Simplify()); + } +}