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
19 changes: 15 additions & 4 deletions Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1970,11 +1970,14 @@ private static bool IsAPolynomialPower(Entity factor, Variable x)
}
if (!cancelledAny)
return null;
// Only where what is left is still a quotient of two functions of x: 3x^2 / (x^3 * f(x))
// at 0 became 3 / (x * f(x)), which is no longer a question for this rule, and the
// limits machinery took more than twenty seconds over it where differentiating took one.
// Only where what is left above is still a function of x: 3x^2 / (x^3 * f(x)) at 0
// became 3 / (x * f(x)), which is no longer a question for this rule, and the limits
// machinery took more than twenty seconds over it where differentiating took one. What
// is left below may be a constant, and then the quotient is a product whose limit is
// asked as one: x^3 * arccsc(-x) * sqrt(1 - 1 / x^2) / x^2 at +oo is -1, and
// differentiated instead it grew past the rule's bound and was left unevaluated.
var (top, bottom) = (Rebuild(above), Rebuild(below));
return top.ContainsNode(x) && bottom.ContainsNode(x) ? top / bottom : null;
return top.ContainsNode(x) ? top / bottom : null;

static Dictionary<Entity, int> Powers(Entity side)
{
Expand Down Expand Up @@ -2043,6 +2046,14 @@ bool VanishesIdentically(Entity polynomial)
// unread. Limits already treat the expression as continuous, as
// SimplifyAndComputeLimitToInfinity does with the same shape.
while (applied is Providedf(var body, _)) applied = body;
// And a factor written on both sides of it is divided out, as it is from the quotient
// above, since simplification leaves a power of the variable on both sides beside a root
// of something in it: arccsc(-x) / (1 / x^3) at +oo differentiates into
// -1/3 * x^6 / (x^4 * sqrt(1 - 1 / x^2)), whose powers count as growth, and
// x^3 * arccsc(-x), which is -oo there, was left unevaluated.
var (appliedAbove, appliedBelow) = SplitProduct(applied);
if (WithTheFactorsOnBothSidesCancelled(appliedAbove.InnerSimplified, appliedBelow.InnerSimplified, x) is { } appliedCancelled)
applied = appliedCancelled;
// A derivative the library cannot compute comes back unevaluated
// (https://github.com/asc-community/AngouriMath/issues/958), and
// differentiating *that* again only raises its Iterations -- so
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// 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
{
/// <summary>
/// l'Hopital's rule divides a factor written on both sides out of the quotient it differentiates, and now also out of
/// the quotient it gets, where simplification leaves a power of the variable on both sides beside a root:
/// arccsc(-x) / (1 / x^3) at +oo differentiated into -1/3 * x^6 / (x^4 * sqrt(1 - 1 / x^2)), which counted as growth.
/// And a quotient whose denominator cancels to a constant is asked as the product it is. Found by limitcheck; no issue
/// was filed.
/// </summary>
[Trait("Area", "Calculus")]
public sealed class APowerOnBothSidesIsCancelledTest
{
[Theory]
[InlineData("x^3 * arccsc(-x)", "-oo")]
[InlineData("x^3 * arccsc(x)", "+oo")]
[InlineData("x^3 * arccsc(-x) * sqrt(1 - 1 / x^2) / x^2", "-1")]
[InlineData("x * arccsc(-x)", "-1")]
public void TheLimitIsAnswered(string input, string expected)
=> Assert.Equal(expected.ToEntity().Evaled, input.ToEntity().Limit("x", "+oo", ApproachFrom.BothSides).Evaled);

[Theory]
[InlineData("1 / x^2 - 1 / sin(x)^2", "0", "-1/3")]
[InlineData("ln(sin(x)) / ln(sinh(x))", "0", "1")]
[InlineData("(1 - cos(x)) / x^2", "0", "1/2")]
[InlineData("x^2 * ln(1 - 1 / x)", "+oo", "-oo")]
public void TheLimitStillHolds(string input, string at, string expected)
=> Assert.Equal(expected.ToEntity().Evaled, input.ToEntity().Limit("x", at, ApproachFrom.Right).Evaled);
}
}
Loading