Skip to content

Commit 2e2bf9d

Browse files
Ask a quotient factor whole before l'Hopital's rule splits it (#2382)
l'Hopital's rule takes out of each side a factor that tends to a finite number other than 0, since the product rule only carries it along. The factors were read after flattening the product, which takes a quotient apart: tanh(x) written through exponentials is (e^(2x) - 1) / (e^(2x) + 1), which tends to 1 at +oo, while its parts tend to +oo and to 0 and neither was taken out. tanh(x) * x / (x + tanh(x)) at +oo then differentiated the whole of tanh and did not finish. A quotient is now asked whole first, and taken apart only where it does not settle at such a number. tanh(x) * x / (x + tanh(x)) at +oo: did not finish in 60 s -> 1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 50e9403 commit 2e2bf9d

3 files changed

Lines changed: 32 additions & 5 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,14 @@ analytic where they are defined and is plainly not 0 at a point.
112112
**Limits whose derivatives grew without bound under l'Hopital's rule are answered, where they did not
113113
finish or were left unevaluated.** The rule differentiates the whole of each side, and the product rule
114114
carries every factor beside the one it differentiates. Now a factor that tends to a finite number other
115-
than 0 at an infinity is replaced by that number, as one continuous at a finite point already was, and a
115+
than 0 at an infinity is replaced by that number, a quotient such as tanh(x) written through exponentials
116+
being asked whole before its parts, as one continuous at a finite point already was, and a
116117
polynomial written on both sides is divided out. The quotient of two logarithms does the same with the
117118
four parts it is built from.
118119

119120
| Input | Was (2.6.0) | Now |
120121
|---|---|---|
122+
| `"tanh(x) * x / (x + tanh(x))".ToEntity().Limit("x", "+oo")` | did not finish in 60 s | `1` |
121123
| `"ln(tanh(x) + x) / ln((x - pi)^2)".ToEntity().Limit("x", "+oo")` | did not finish in 30 s | `1/2` |
122124
| `"ln(tanh(x) + x) / ln(x - pi)".ToEntity().Limit("x", "+oo")` | did not finish in 30 s | `1` |
123125
| `"ln(arctan(x) + x) / ln(x)".ToEntity().Limit("x", "+oo")` | unevaluated | `1` |

‎Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs‎

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,7 +1655,32 @@ private static (Entity Value, Entity Others) TakeOutContinuousFactors(Entity exp
16551655
return (Integer.One, expr);
16561656
Entity value = Integer.One, rest = Integer.One;
16571657
var any = false;
1658-
foreach (var factor in Mulf.LinearChildren(expr))
1658+
Gather(expr);
1659+
return any && rest.ContainsNode(x) ? (value.InnerSimplified, rest.InnerSimplified) : (Integer.One, expr);
1660+
1661+
// A quotient is asked whole before it is taken apart. tanh(x) written through exponentials
1662+
// is (e^(2x) - 1) / (e^(2x) + 1), which tends to 1 at +oo, while its two parts tend to +oo
1663+
// and to 0 and neither is taken out.
1664+
void Gather(Entity node)
1665+
{
1666+
if (node is Mulf(var left, var right))
1667+
{
1668+
Gather(left);
1669+
Gather(right);
1670+
}
1671+
else if (TakeOut(node))
1672+
return;
1673+
else if (node is Divf)
1674+
foreach (var factor in Mulf.LinearChildren(node))
1675+
{
1676+
if (!TakeOut(factor))
1677+
rest *= factor;
1678+
}
1679+
else
1680+
rest *= node;
1681+
}
1682+
1683+
bool TakeOut(Entity factor)
16591684
{
16601685
if (factor.ContainsNode(x)
16611686
&& !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
16651690
{
16661691
value *= there;
16671692
any = true;
1693+
return true;
16681694
}
1669-
else
1670-
rest *= factor;
1695+
return false;
16711696
}
1672-
return any && rest.ContainsNode(x) ? (value.InnerSimplified, rest.InnerSimplified) : (Integer.One, expr);
16731697
}
16741698

16751699
/// <summary>Whether <paramref name="node"/> is built from <paramref name="x"/> and real constants by sums, differences, products and positive whole powers.</summary>

‎Sources/Tests/UnitTests/Calculus/LhopitalKeepsTheDerivativesSmallTest.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public sealed class LhopitalKeepsTheDerivativesSmallTest
2929
[InlineData("ln(tanh(x) + x) / ln(x)", "+oo", "1")]
3030
[InlineData("ln(arctan(x) + x) / ln(x)", "+oo", "1")]
3131
[InlineData("tanh(x) * x / (x + tanh(x))", "-oo", "-1")]
32+
[InlineData("tanh(x) * x / (x + tanh(x))", "+oo", "1")]
3233
[InlineData("(x - pi)^2 / ((x + tanh(x)) * (x - pi))", "+oo", "1")]
3334
[InlineData("arctan(x) * x / (x + 1)", "+oo", "pi / 2")]
3435
[InlineData("(x - 1)^2 * sin(x - 1) / ((x - 1)^3 * cos(x))", "1", "sec(1)")]

0 commit comments

Comments
 (0)