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
16 changes: 16 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Entity, Entity, Entity> transformation)
/// <remarks>
/// 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.
/// </remarks>
private static Entity ApplyTrivialTransformations(Entity expr, Variable x, Entity dest, ApproachFrom side, Func<Entity, Entity, Entity> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// 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.
/// </summary>
[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));
}
}
Loading