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
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,16 @@ private static bool IsZeroTimesAnInfinity(Entity first, Entity second)
if (Functions.Algebra.LimitFunctional.IsTheWholeQuestion(quotient))
return null;
quotientsAskedWhole ??= new();
if (quotientsAskedWhole.Count > 0 || !quotientsAskedWhole.Add(quotient))
if (quotientsAskedWhole.Count > 0)
return null;
// The expression whose two sides a two-sided limit is comparing, asked whole from one side, is that side's
// own question rather than one asked inside another, and does not use the one level up. Counted, it left
// that side nothing to ask of its own regrouping: x^pi / log(x, 2) at 0 from the right reads as
// x^pi * ln(x), asked whole, in a fifth of a second alone, and from inside the comparison it was refused
// and the side spent ten seconds on other readings that did not answer.
if (Functions.Algebra.LimitFunctional.IsTheComparedQuestion(quotient))
return Functions.Algebra.LimitFunctional.ComputeLimit(quotient, x, dist, side);
if (!quotientsAskedWhole.Add(quotient))
return null;
try { return Functions.Algebra.LimitFunctional.ComputeLimit(quotient, x, dist, side); }
finally { quotientsAskedWhole.Remove(quotient); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,18 @@ internal static bool MayReadAPowerThroughItsExponent(Entity power)
/// </summary>
internal static bool IsTheWholeQuestion(Entity expr) => ReferenceEquals(expr, descentRoot);

/// <summary>
/// The expression whose sides a two-sided limit is comparing. Its whole limit asked from
/// one side inside that comparison is the question of that side, not one asked inside another.
/// </summary>
[System.ThreadStatic] private static Entity? comparedRoot;

/// <summary>
/// Whether <paramref name="expr"/> is the expression whose two sides are being compared, so
/// that its whole limit from one side is that side's own question.
/// </summary>
internal static bool IsTheComparedQuestion(Entity expr) => ReferenceEquals(expr, comparedRoot);

/// <summary>
/// A logarithm of a power to a constant real exponent, log(f^c), as c log(f), or as
/// c log(-f) + log((-1)^c) where f is negative near the point.
Expand Down Expand Up @@ -431,12 +443,12 @@ internal static T WithinABudget<T>(int limits, System.Func<T> compute)
if (expr.Nodes.Any(static node => node is Derivativef))
expr = WithTheDerivativesTaken(expr, x, dest, side);
var enclosingApproach = EnterApproach(x, dest);
var (outerComparing, outerRoot) = (comparingSides, descentRoot);
(comparingSides, descentRoot) = (false, null);
var (outerComparing, outerRoot, outerCompared) = (comparingSides, descentRoot, comparedRoot);
(comparingSides, descentRoot, comparedRoot) = (false, null, null);
try { return ComputeLimitWithinApproach(expr, x, dest, side, acceptNaN); }
finally
{
(comparingSides, descentRoot) = (outerComparing, outerRoot);
(comparingSides, descentRoot, comparedRoot) = (outerComparing, outerRoot, outerCompared);
LeaveApproach(enclosingApproach);
}
}
Expand Down Expand Up @@ -692,9 +704,9 @@ node is Derivativef(var expression, Variable variable, var iterations) && iterat
Entity? DescendComparingSides(ApproachFrom oneSide)
{
var stepped = WithStepsAtTheirLimits(expr, x, dest, oneSide);
comparingSides = true;
(comparingSides, comparedRoot) = (true, stepped);
try { return stepped.ComputeLimitDivideEtImpera(x, dest, oneSide); }
finally { comparingSides = false; }
finally { (comparingSides, comparedRoot) = (false, null); }
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// 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 System;
using System.Threading.Tasks;
using AngouriMath.Extensions;
using Xunit;

namespace AngouriMath.Tests.Calculus
{
/// <summary>
/// A two-sided limit compares its sides by descending into each, and the descent asks the whole expression's limit
/// from that side. That ask used the one level of whole limits a descent may ask, so the side could not ask the
/// regrouping that answers it: x^pi / log(x, 2) at 0 took ten seconds two-sided, against a fifth of one from the
/// right alone. Found by limitcheck; no issue was filed.
/// </summary>
[Trait("Area", "Calculus")]
public sealed class AComparedSideIsItsOwnQuestionTest
{
[Theory]
[InlineData("x^pi / log(x, 2)", "0")]
[InlineData("x^pi / log(x, 2) - 2", "-2")]
[InlineData("x^e / log(x, 2)", "0")]
public void ATwoSidedLimitAtZeroFinishes(string input, string expected)
{
Entity? limit = null;
var task = Task.Factory.StartNew(() => limit = input.ToEntity().Limit("x", 0), TaskCreationOptions.LongRunning);
Assert.True(task.Wait(TimeSpan.FromSeconds(30)), "the limit did not finish in 30 seconds");
Assert.Equal(expected.ToEntity(), limit);
}
}
}
Loading