Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Sources/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -65,6 +73,27 @@ internal static class LimitSolvers
return null;
}

/// <summary>
/// Whether <paramref name="node"/> is a step function whose argument evaluates to one of its jumps: an integer for
/// <c>floor</c> and <c>ceil</c>, a half-integer for <c>round</c>, 0 for <c>sgn</c>. Taken on the real part, and on the
/// imaginary part of a value that is not real, as LimitOfAStepFunction takes it.
/// </summary>
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<Real, bool> 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)
Expand Down
58 changes: 58 additions & 0 deletions Sources/Tests/UnitTests/Calculus/LimitAtAJumpTest.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// 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: <c>limitleft(floor(x) - 1, x, 0)</c> was <c>-1</c>, where it is <c>-2</c>, and the
/// two-sided limit, which does not exist, was <c>-1</c> too. Declining is an honest answer there; a value is a wrong one
/// unless it is the limit.
/// <a href="https://github.com/asc-community/AngouriMath/issues/2266">#2266</a>
/// </summary>
[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");
}

/// <summary>Away from a jump the step is constant, and the limit is its value.</summary>
[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());
}
}
Loading