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
12 changes: 12 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,17 @@ internal static T WithinABudget<T>(int limits, System.Func<T> 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
Expand Down
22 changes: 22 additions & 0 deletions Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,28 @@ internal static Entity AtALargeDecimal(Entity expr, Variable x)
}
}

/// <summary>
/// Whether <paramref name="difference"/> 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.
/// </summary>
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;
}

/// <summary>
/// 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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// 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.
/// </summary>
[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));
}
}
Loading