diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 23f7e89fd..bc011742b 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -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 diff --git a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs index 135097319..3cd2fc606 100644 --- a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs +++ b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs @@ -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; diff --git a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs index 49d953778..4946a3115 100644 --- a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs +++ b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs @@ -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 -- diff --git a/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs index 45dfff058..7ec2f5fd6 100644 --- a/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs +++ b/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs @@ -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 }; diff --git a/Sources/Tests/UnitTests/Calculus/ALimitUnderAConditionThatHoldsIsTakenWholeTest.cs b/Sources/Tests/UnitTests/Calculus/ALimitUnderAConditionThatHoldsIsTakenWholeTest.cs new file mode 100644 index 000000000..0d3e44950 --- /dev/null +++ b/Sources/Tests/UnitTests/Calculus/ALimitUnderAConditionThatHoldsIsTakenWholeTest.cs @@ -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 +{ + /// + /// The antiderivative of ln(1 + 2x)/(1 + x)^2 carries the condition 2x + 1 != 0, and the limit of an + /// expression under a condition was not asked of the expression: at +oo it was left unevaluated, where it is + /// 2 ln(2), so the integral over [0, +oo) 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 + /// + [Trait("Area", "Calculus")] + public sealed class ALimitUnderAConditionThatHoldsIsTakenWholeTest + { + /// Values from mpmath's quadrature at 30 digits. + [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); + + /// Where the condition fails on a side, that side's limit is not answered from the expression. + [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); + } +}