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 @@ -276,6 +276,21 @@ equation `abs(x - 1) = 2` is solved over `CC` as before
| `abs(1/x) > 1` | throws | `(0; 1) \/ (-1; 0)` |
| `abs(sqrt(x)) > 1` | throws | unchanged |

### A limit under a condition that holds near the point is the expression's limit

**An answer where there was none.** The limit of an expression under a condition, `f provided c`, was not asked of
`f`: a condition is not a continuous node, and the limit was left unevaluated. The antiderivative of
`ln(1 + 2x)/(1 + x)^2` carries `2x + 1 != 0`, so its integral over `[0, +oo)` was left unevaluated. Where the condition
holds near the point, on each side the limit approaches from, the limit is now the limit of `f`. Where it does not,
nothing is claimed ([#2652](https://github.com/asc-community/AngouriMath/issues/2652)).

| | Was (2.10.0) | Now |
|---|---|---|
| `integral(ln(1 + 2x)/(1 + x)^2, x, 0, +oo)`, simplified | unevaluated | `2 * ln(2)` |
| `limit(sin(x)/x provided not x = 0, x, 0)` | unevaluated | `1` |
| `limit(1 provided x > 0, x, 0+)` | unevaluated | `1` |
| `limit(1 provided x > 0, x, 0-)` | unevaluated | unchanged |

### A limit at infinity comparing 2^x with 3^x is answered

**Not silent: a limit that was left unevaluated has a value.** Gruntz's algorithm writes each fastest-growing exponential
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,14 @@ partial record Providedf
{
internal override Entity? ComputeLimitDivideEtImpera(Variable x, Entity dist, ApproachFrom side)
{
// Where the condition holds near the point, the limit is the expression's, asked whole: the descent
// alone reads a sum term by term, and the antiderivative of ln(1 + 2x)/(1 + x)^2, which holds the
// condition 2x + 1 != 0, met +oo - +oo at +oo and was left unevaluated, where without the condition its
// logarithms are gathered and the limit is 2 ln(2). A smaller question than this one: the condition is
// gone. https://github.com/asc-community/AngouriMath/issues/2652
if (Sides(dist, side).All(oneSide => HoldsNear(Predicate, x, dist, oneSide) is true)
&& ComputeLimit(Expression, x, dist, side) is { } whole)
return whole;
var lim = Expression.ComputeLimitDivideEtImpera(x, dist, side);
if (lim is null)
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,13 @@ node is Derivativef(var expression, Variable variable, var iterations) && iterat

private static Entity? ComputeLimitWithinApproach(Entity expr, Variable x, Entity dest, ApproachFrom side, bool acceptNaN)
{
// An expression under a condition that holds near the point has the expression's limit there, which was not
// asked: a condition is no continuous node, and the antiderivative of ln(1 + 2x)/(1 + x)^2, which holds
// 2x + 1 != 0, was left without a limit at +oo, where it is 2 ln(2).
// https://github.com/asc-community/AngouriMath/issues/2652
if (expr is Providedf(var underTheCondition, var condition)
&& Sides(dest, side).All(oneSide => HoldsNear(condition, x, dest, oneSide) is true))
return ComputeLimit(underTheCondition, x, dest, side, acceptNaN);
// A piecewise is not continuous and is still something a limit can be taken of: it
// agrees with one of its cases on the whole of the way in, and that case is
// continuous. Without it here the descent's reading of one was never reached --
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,7 @@ private static bool IsRealNear(Entity expr, Variable x, Entity dest, ApproachFro

// The sides a limit approaches from: both at a finite point asked two-sidedly, and one otherwise,
// since an infinity is approached from one side whichever is asked.
private static ApproachFrom[] Sides(Entity dest, ApproachFrom side)
internal static ApproachFrom[] Sides(Entity dest, ApproachFrom side)
=> side is ApproachFrom.BothSides && dest.IsFinite
? new[] { ApproachFrom.Left, ApproachFrom.Right }
: new[] { side is ApproachFrom.BothSides ? ApproachFrom.Left : side };
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// 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 AngouriMath.Extensions;
using Xunit;
using static AngouriMath.Entity;

namespace AngouriMath.Tests.Calculus
{
/// <summary>
/// The antiderivative of <c>ln(1 + 2x)/(1 + x)^2</c> carries the condition <c>2x + 1 != 0</c>, and the limit of an
/// expression under a condition was not asked of the expression: at <c>+oo</c> it was left unevaluated, where it is
/// <c>2 ln(2)</c>, so the integral over <c>[0, +oo)</c> was too. Where the condition holds near the point, the limit
/// is the expression's; where it does not, nothing is claimed.
/// https://github.com/asc-community/AngouriMath/issues/2652
/// </summary>
[Trait("Area", "Calculus")]
public sealed class ALimitUnderAConditionThatHoldsIsTakenWholeTest
{
/// <summary>Values from mpmath's quadrature at 30 digits.</summary>
[Theory]
[InlineData("ln(1 + 2x)/(1 + x)^2", "1.38629436111989061883446424292")]
[InlineData("ln(1 + 3x)/(1 + x)^2", "1.64791843300216453709286785538")]
public void TheIntegralUpToInfinityIsAnswered(string integrand, string expected)
{
var integral = integrand.ToEntity().Integrate("x", 0, "+oo".ToEntity()).Simplify();
Assert.DoesNotContain(integral.Nodes, node => node is Integralf);
Assert.True((integral - expected.ToEntity()).EvalNumerical().Abs() < 1e-12, $"{integrand} was {integral}");
}

[Theory]
[InlineData("(ln(1 + 2x) (2 - 1/(1 + x)) - 2 ln(x + 1) provided not 2x + 1 = 0)", "+oo", ApproachFrom.BothSides, "2 ln(2)")]
[InlineData("(sin(x)/x provided not x = 0)", "0", ApproachFrom.BothSides, "1")]
[InlineData("(1 provided x > 0)", "0", ApproachFrom.Right, "1")]
public void TheLimitIsTheExpressions(string expression, string to, ApproachFrom side, string expected)
=> Assert.Equal(expected.ToEntity().Evaled, expression.ToEntity().Limit("x", to.ToEntity(), side).Evaled);

/// <summary>Where the condition fails on a side, that side's limit is not answered from the expression.</summary>
[Theory]
[InlineData("(1 provided x > 0)", ApproachFrom.Left)]
[InlineData("(1 provided x > 0)", ApproachFrom.BothSides)]
public void AConditionThatFailsAnswersNothing(string expression, ApproachFrom side)
=> Assert.Contains(expression.ToEntity().Limit("x", 0, side).Nodes, node => node is Limitf);
}
}
Loading