Skip to content

Commit e8b0995

Browse files
Ask the first remarkable limit's parts from the side of the limit (#2403)
Ask the first remarkable limit's parts from the side of the limit The first remarkable limit asks whether a quotient's dividend and divisor both vanish at the point, and whether a sine's argument does, before reading the sine as its argument. It asked from both sides, also inside a one-sided limit, and asked the dividend first. sinh((x - 1)^ln(x)) at 1 from the right is (e^((x - 1)^ln(x)) - e^(-(x - 1)^ln(x))) / 2, and its dividend was taken through the left side as well, where (x - 1)^ln(x) is not real: 5 s, then 3 s more on its respelling, before the divisor 2 said no. Each part is now asked from the side of the limit, and the simpler part first, since one that does not vanish settles the question. The equivalence of a sine and its argument holds on one side of the point as much as on both, so the rule needs its parts to vanish on the side approached only. sinh((x - 1)^ln(x)) at 1 takes 2.1 s from the right, from 9.0 s; 6.8 s from the left, from 14.4 s; and 4.7 s two-sided, from 11.5 s, with the same answers. Asking the divisor first instead would have cost (-1 - x) / (ln(2) / ln(x))^(x - 1) at 1 from the left 2.2 s, its divisor being the expensive part and asked again by the descent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent cc5e13b commit e8b0995

3 files changed

Lines changed: 72 additions & 12 deletions

File tree

‎Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ node is Derivativef(var expression, Variable variable, var iterations) && iterat
534534
// it, where the same expression approached from both sides gives e.
535535
expr = expr.Replace(a => TrivialTrigonometricReplacement(a, x));
536536
expr = ApplyTrivialTransformations(expr, x, dest, side, (_, exprLim) => exprLim);
537-
expr = ApplyFirstRemarkableOverFactors(expr, x, dest);
537+
expr = ApplyFirstRemarkableOverFactors(expr, x, dest, side);
538538
expr = expr.Replace(c => ApplySecondRemarkable(c, x, dest));
539539
// A tangent is a quotient as much as a cosecant is a reciprocal, and leaving it
540540
// written as one function makes it opaque to everything that reads quotients --

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

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ partial class LimitFunctional
2828
/// to pi - x -- so rewriting it as x turned <c>lim x-&gt;pi sin(x) / (x - pi)</c>, which
2929
/// is -1, into pi / 0.
3030
/// </remarks>
31-
private static Entity EquivalenceRules(Entity expr, Variable x, Entity dest)
31+
private static Entity EquivalenceRules(Entity expr, Variable x, Entity dest, ApproachFrom side)
3232
=> expr is (Sinf or Tanf or Arcsinf or Arctanf)
33-
&& EvalAssumingContinuous(expr.DirectChildren[0].Limit(x, dest)) == 0
33+
&& EvalAssumingContinuous(expr.DirectChildren[0].Limit(x, dest, side)) == 0
3434
? expr.DirectChildren[0]
3535
: expr;
3636
internal static Entity EvalAssumingContinuous(Entity expr) =>
@@ -118,27 +118,40 @@ internal static bool RealCodomainWithdraws(Entity expr, Variable x, Entity dest,
118118
=> MathS.Settings.Codomain.Value is AngouriMath.Core.Domain.Real
119119
&& LeavesTheRealsOnTheApproach(expr, x, dest, side);
120120

121-
private static Entity ApplyFirstRemarkable(Entity expr, Variable x, Entity dest)
121+
/// <remarks>
122+
/// Each part is asked from the side of the limit. The equivalence of a sine and its argument holds on one side
123+
/// of the point as much as on both, so a one-sided limit needs its parts to vanish on its side alone; asked
124+
/// from both, (e^((x - 1)^ln(x)) - e^(-(x - 1)^ln(x))) / 2 at 1 from the right spent eight seconds on the left
125+
/// of its dividend, where (x - 1)^ln(x) is not real. The simpler part is asked first, since a part that does
126+
/// not vanish settles the question and a simple one is the cheaper to ask: the divisor of that quotient, a
127+
/// constant, but the dividend of (-1 - x) / (ln(2) / ln(x))^(x - 1) at 1 from the left, whose divisor takes
128+
/// seconds and is asked again by the descent.
129+
/// </remarks>
130+
private static Entity ApplyFirstRemarkable(Entity expr, Variable x, Entity dest, ApproachFrom side)
122131
=> expr switch
123132
{
124133
Divf(var a, var b) div
125-
when EvalAssumingContinuous(a.Limit(x, dest)) == 0 && EvalAssumingContinuous(b.Limit(x, dest)) == 0
126-
=> div.New(EquivalenceRules(a, x, dest), EquivalenceRules(b, x, dest)),
134+
when BothVanish(a.Complexity <= b.Complexity ? (a, b) : (b, a), x, dest, side)
135+
=> div.New(EquivalenceRules(a, x, dest, side), EquivalenceRules(b, x, dest, side)),
127136

128137
// A product takes the substitution as much as a quotient does -- it is the ratio
129138
// of the two forms tending to 1 that licenses it, and that says nothing about
130139
// which of them the rest of the expression is written over. Only the quotient
131140
// had it, so lim x->0+ tan(x) * ln(x) went the long way round through l'Hopital's
132141
// rule and came back NaN, where the same limit written sin(x) * ln(x) is 0.
133142
Mulf(var a, var b)
134-
when EquivalenceRules(a, x, dest) is var equivalentA
135-
&& EquivalenceRules(b, x, dest) is var equivalentB
143+
when EquivalenceRules(a, x, dest, side) is var equivalentA
144+
&& EquivalenceRules(b, x, dest, side) is var equivalentB
136145
&& (!ReferenceEquals(equivalentA, a) || !ReferenceEquals(equivalentB, b))
137146
=> equivalentA * equivalentB,
138147

139148
_ => expr
140149
};
141150

151+
private static bool BothVanish((Entity First, Entity Second) parts, Variable x, Entity dest, ApproachFrom side)
152+
=> EvalAssumingContinuous(parts.First.Limit(x, dest, side)) == 0
153+
&& EvalAssumingContinuous(parts.Second.Limit(x, dest, side)) == 0;
154+
142155
/// <summary>
143156
/// <see cref="ApplyFirstRemarkable"/> applied down the product-and-quotient spine
144157
/// rather than at the root alone.
@@ -161,13 +174,13 @@ when EquivalenceRules(a, x, dest) is var equivalentA
161174
/// factor of the whole.
162175
/// <a href="https://github.com/asc-community/AngouriMath/issues/749">#749</a>
163176
/// </remarks>
164-
private static Entity ApplyFirstRemarkableOverFactors(Entity expr, Variable x, Entity dest)
177+
private static Entity ApplyFirstRemarkableOverFactors(Entity expr, Variable x, Entity dest, ApproachFrom side)
165178
{
166-
var applied = ApplyFirstRemarkable(expr, x, dest);
179+
var applied = ApplyFirstRemarkable(expr, x, dest, side);
167180
if (applied is not (Mulf or Divf))
168181
return applied;
169-
var left = ApplyFirstRemarkableOverFactors(applied.DirectChildren[0], x, dest);
170-
var right = ApplyFirstRemarkableOverFactors(applied.DirectChildren[1], x, dest);
182+
var left = ApplyFirstRemarkableOverFactors(applied.DirectChildren[0], x, dest, side);
183+
var right = ApplyFirstRemarkableOverFactors(applied.DirectChildren[1], x, dest, side);
171184
// Rebuilt only where a factor actually changed, so an expression the rule has
172185
// nothing to say about comes back as the very node it went in as, keeping whatever
173186
// the rest of the machinery has already cached against it.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//
2+
// Copyright (c) 2019-2026 Angouri.
3+
// AngouriMath is licensed under MIT.
4+
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
5+
// Website: https://am.angouri.org.
6+
//
7+
8+
using System;
9+
using System.Threading.Tasks;
10+
using AngouriMath.Core;
11+
using AngouriMath.Extensions;
12+
using Xunit;
13+
14+
namespace AngouriMath.Tests.Calculus
15+
{
16+
/// <summary>
17+
/// The first remarkable limit asked whether a quotient's parts vanish from both sides of the point, also inside a
18+
/// one-sided limit, and asked the dividend first. sinh((x - 1)^ln(x)) at 1 from the right is a quotient over 2, and
19+
/// its dividend was taken through the left side, where (x - 1)^ln(x) is not real, for eight seconds. Found by
20+
/// limitcheck; no issue was filed.
21+
/// </summary>
22+
[Trait("Area", "Calculus")]
23+
public sealed class ARemarkableLimitIsAskedFromItsSideTest
24+
{
25+
[Theory]
26+
[InlineData("sinh((x - 1)^ln(x))", 1, ApproachFrom.Right, "sinh(1)")]
27+
[InlineData("cosh((x - 1)^ln(x))", 1, ApproachFrom.Right, "cosh(1)")]
28+
public void AFunctionOfAPowerFinishes(string input, int at, ApproachFrom side, string expected)
29+
{
30+
Entity? limit = null;
31+
var task = Task.Factory.StartNew(() => limit = input.ToEntity().Limit("x", at, side), TaskCreationOptions.LongRunning);
32+
Assert.True(task.Wait(TimeSpan.FromSeconds(30)), "the limit did not finish in 30 seconds");
33+
Assert.NotNull(limit);
34+
Assert.Equal(expected.ToEntity().EvalNumerical(), limit!.EvalNumerical());
35+
}
36+
37+
// The remarkable limits themselves, from either side and both.
38+
[Theory]
39+
[InlineData("sin(x) / x", ApproachFrom.BothSides, "1")]
40+
[InlineData("sin(x) / x", ApproachFrom.Left, "1")]
41+
[InlineData("tan(2 * x) / sin(x)", ApproachFrom.Right, "2")]
42+
[InlineData("tan(x) * ln(x)", ApproachFrom.Right, "0")]
43+
[InlineData("(sin(x) / x - 1) / x^2", ApproachFrom.BothSides, "-1/6")]
44+
public void TheRemarkableLimitStillHolds(string input, ApproachFrom side, string expected)
45+
=> Assert.Equal(expected.ToEntity(), input.ToEntity().Limit("x", 0, side));
46+
}
47+
}

0 commit comments

Comments
 (0)