diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index b5ebaaacb..a832e432d 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -135,6 +135,21 @@ answers the same rows as before, except the three below that did not finish. | `"((x + 1) - log(x, -1)) ^ (-16)".ToEntity().Limit("x", 1, ApproachFrom.Right)` | did not finish in 30 s | `0` | | `"((x + 1) - log(x, -1)) ^ (-16)".ToEntity().Limit("x", 1, ApproachFrom.BothSides)` | did not finish in 30 s | `0` | +### A step function of a quotient tending to a constant is answered from the quotient's parts in a limit + +**Silent: the side a quotient `a / b` arrives at a constant `c` from is read as the sign of `a - c b` times that of +`b`**, so a step function of it is answered. `log(x / 2, tan(x))` at 0 from the right is `ln(tan(x)) / ln(x / 2)`, +which tends to 1. `ln(tan(x)) - ln(x / 2)` tends to `ln(2)` and `ln(x / 2)` to -oo, so the quotient arrives from below, +and its floor is 0. Since 2.6.0 these were also declined only after 10 to 19 s, spent in l'Hôpital's rule on the slope. +Found by limitcheck; no issue was filed. + +| Input | Was (2.6.0) | Now | +|---|---|---| +| `"floor(log(x / 2, tan(x)))".ToEntity().Limit("x", 0, ApproachFrom.Right)` | unevaluated | `0` | +| `"floor(log(pi / x, tan(x)))".ToEntity().Limit("x", 0, ApproachFrom.Right)` | unevaluated | `-1` | +| `"floor(tanh(1 / x))".ToEntity().Limit("x", 0, ApproachFrom.Right)` | unevaluated | `0` | +| `"floor(tanh(1 / x))".ToEntity().Limit("x", 0)` | unevaluated | `NaN`: the left side is `-1` | + ### A logarithm of a part tending to 1 is read as the part less 1 in a limit **Silent: a factor `ln(u)` whose antilogarithm tends to 1 is read as `u - 1`, as `sin(f)` is read as `f` where `f` diff --git a/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs index 3da7303c6..72be07dd3 100644 --- a/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs +++ b/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs @@ -1273,10 +1273,25 @@ private static ApproachFrom[] Sides(Entity dest, ApproachFrom side) // the smaller question. sgn((x * x)^arctan(1/2)) at 0 from the left asked for the slope of the power, which // l'Hopital's rule took 6.6 s over, for the sign x * x has as a product. return SignFromVanishingOrder(expr, x, dest, side) - ?? (expr is Powf ? SignOfTheFactors(expr, x, dest, side) : null) ?? SignFromTheSlope(expr, x, dest, side) + ?? (expr is Powf ? SignOfTheFactors(expr, x, dest, side) : null) ?? SignOfAQuotientLessAConstant(expr, x, dest, side) + ?? SignFromTheSlope(expr, x, dest, side) ?? SignOfTheFactors(expr, x, dest, side) ?? SignThroughAChangeOfVariable(expr, x, dest, side); } + // A quotient less a constant, a / b - c, is the one quotient (a - c b) / b, and has the sign of a - c b times that + // of b, which are two smaller questions than its slope. floor(log(x / 2, tan(x))) at 0 from the right is the + // floor of ln(tan(x)) / ln(x / 2), which tends to 1, and asks the sign of that less 1: a - b tends to ln(2) and + // b to -oo, so it is negative, and the floor is 0. Read through the slope, l'Hopital's rule spent 20 s and + // declined, and the limit was left unevaluated. + private static int? SignOfAQuotientLessAConstant(Entity expr, Variable x, Entity dest, ApproachFrom side) + => expr switch + { + Minusf(Divf(var dividend, var divisor), var constant) when !constant.ContainsNode(x) + => SignNear(dividend - constant * divisor, x, dest, side) is { } top && SignNear(divisor, x, dest, side) is { } bottom + ? top * bottom : null, + _ => null + }; + // Where the variable is only ever inside one part u, the expression is h(u), and near the destination it has the // sign h(t) has as t tends to the limit of u, from the side u arrives from. sinh(e^x) at -oo is (e^t - e^-t) / 2 // at 0 from the right, which has a slope; read at -oo itself, through 1/x, it is flat, every derivative of diff --git a/Sources/Tests/UnitTests/Calculus/AQuotientArrivesByItsPartsTest.cs b/Sources/Tests/UnitTests/Calculus/AQuotientArrivesByItsPartsTest.cs new file mode 100644 index 000000000..32bdd7c9c --- /dev/null +++ b/Sources/Tests/UnitTests/Calculus/AQuotientArrivesByItsPartsTest.cs @@ -0,0 +1,41 @@ +// +// 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; + +namespace AngouriMath.Tests.Calculus +{ + /// + /// The side a quotient a / b arrives at a constant c from is the sign of a - c b times that of b. floor(log(x / 2, tan(x))) + /// at 0 from the right is the floor of ln(tan(x)) / ln(x / 2), which tends to 1 from below, since ln(tan(x)) - ln(x / 2) + /// tends to ln(2) and ln(x / 2) to -oo. It was left unevaluated after 20 s in l'Hopital's rule on the slope. + /// Found by limitcheck; no issue was filed. + /// + [Trait("Area", "Calculus")] + public sealed class AQuotientArrivesByItsPartsTest + { + [Theory] + [InlineData("floor(log(x / 2, tan(x)))", "0")] + [InlineData("floor(log(pi / x, tan(x)))", "-1")] + [InlineData("floor(ln(tan(x)) / ln(x / 2))", "0")] + [InlineData("ceil(ln(tan(x)) / ln(x / 2))", "1")] + [InlineData("floor(tanh(1 / x))", "0")] + public void TheLimitFromTheRightIsAnswered(string input, string expected) + => Assert.Equal(expected.ToEntity().Evaled, input.ToEntity().Limit("x", 0, ApproachFrom.Right).Evaled); + + // tanh(1 / x) is (e^(2 / x) - 1) / (e^(2 / x) + 1), which arrives at 1 from below on the right and at -1 from above on + // the left, so its floor is 0 on one side and -1 on the other, and the two-sided limit does not exist. + [Fact] + public void TheSidesOfAQuotientCanDisagree() + { + Assert.Equal(MathS.FromString("-1"), MathS.FromString("floor(tanh(1 / x))").Limit("x", 0, ApproachFrom.Left).Evaled); + Assert.Equal(MathS.NaN, MathS.FromString("floor(tanh(1 / x))").Limit("x", 0)); + } + } +}