diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 8257994bf..6a6271474 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -112,12 +112,14 @@ analytic where they are defined and is plainly not 0 at a point. **Limits whose derivatives grew without bound under l'Hopital's rule are answered, where they did not finish or were left unevaluated.** The rule differentiates the whole of each side, and the product rule carries every factor beside the one it differentiates. Now a factor that tends to a finite number other -than 0 at an infinity is replaced by that number, as one continuous at a finite point already was, and a +than 0 at an infinity is replaced by that number, a quotient such as tanh(x) written through exponentials +being asked whole before its parts, as one continuous at a finite point already was, and a polynomial written on both sides is divided out. The quotient of two logarithms does the same with the four parts it is built from. | Input | Was (2.6.0) | Now | |---|---|---| +| `"tanh(x) * x / (x + tanh(x))".ToEntity().Limit("x", "+oo")` | did not finish in 60 s | `1` | | `"ln(tanh(x) + x) / ln((x - pi)^2)".ToEntity().Limit("x", "+oo")` | did not finish in 30 s | `1/2` | | `"ln(tanh(x) + x) / ln(x - pi)".ToEntity().Limit("x", "+oo")` | did not finish in 30 s | `1` | | `"ln(arctan(x) + x) / ln(x)".ToEntity().Limit("x", "+oo")` | unevaluated | `1` | diff --git a/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs index b3ef2cd08..e34b0b0b7 100644 --- a/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs +++ b/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs @@ -1655,7 +1655,32 @@ private static (Entity Value, Entity Others) TakeOutContinuousFactors(Entity exp return (Integer.One, expr); Entity value = Integer.One, rest = Integer.One; var any = false; - foreach (var factor in Mulf.LinearChildren(expr)) + Gather(expr); + return any && rest.ContainsNode(x) ? (value.InnerSimplified, rest.InnerSimplified) : (Integer.One, expr); + + // A quotient is asked whole before it is taken apart. tanh(x) written through exponentials + // is (e^(2x) - 1) / (e^(2x) + 1), which tends to 1 at +oo, while its two parts tend to +oo + // and to 0 and neither is taken out. + void Gather(Entity node) + { + if (node is Mulf(var left, var right)) + { + Gather(left); + Gather(right); + } + else if (TakeOut(node)) + return; + else if (node is Divf) + foreach (var factor in Mulf.LinearChildren(node)) + { + if (!TakeOut(factor)) + rest *= factor; + } + else + rest *= node; + } + + bool TakeOut(Entity factor) { if (factor.ContainsNode(x) && !factor.Nodes.Any(static node => node is Floorf or Ceilf or Roundf or Signumf or Piecewise) @@ -1665,11 +1690,10 @@ private static (Entity Value, Entity Others) TakeOutContinuousFactors(Entity exp { value *= there; any = true; + return true; } - else - rest *= factor; + return false; } - return any && rest.ContainsNode(x) ? (value.InnerSimplified, rest.InnerSimplified) : (Integer.One, expr); } /// Whether is built from and real constants by sums, differences, products and positive whole powers. diff --git a/Sources/Tests/UnitTests/Calculus/LhopitalKeepsTheDerivativesSmallTest.cs b/Sources/Tests/UnitTests/Calculus/LhopitalKeepsTheDerivativesSmallTest.cs index f509b1b68..82a0fe90c 100644 --- a/Sources/Tests/UnitTests/Calculus/LhopitalKeepsTheDerivativesSmallTest.cs +++ b/Sources/Tests/UnitTests/Calculus/LhopitalKeepsTheDerivativesSmallTest.cs @@ -29,6 +29,7 @@ public sealed class LhopitalKeepsTheDerivativesSmallTest [InlineData("ln(tanh(x) + x) / ln(x)", "+oo", "1")] [InlineData("ln(arctan(x) + x) / ln(x)", "+oo", "1")] [InlineData("tanh(x) * x / (x + tanh(x))", "-oo", "-1")] + [InlineData("tanh(x) * x / (x + tanh(x))", "+oo", "1")] [InlineData("(x - pi)^2 / ((x + tanh(x)) * (x - pi))", "+oo", "1")] [InlineData("arctan(x) * x / (x + 1)", "+oo", "pi / 2")] [InlineData("(x - 1)^2 * sin(x - 1) / ((x - 1)^3 * cos(x))", "1", "sec(1)")]