Skip to content

Commit 806e47d

Browse files
Rafael-SOWNetclaude
andcommitted
Take an arccotangent at its jump from the side its argument arrives from
The library's arccotangent is arctan(1/t), with range (-pi/2, pi/2]: arccot(-0.001) = -1.5698, arccot(0) = pi/2, arccot(0.001) = 1.5698. It jumps at 0, and a limit read the value there, so arccot(x) at 0 was pi/2 from the left, where it is -pi/2, and pi/2 two-sided, where no limit exists. A quotient over it inherited the wrong sign: arccot(x)/x from the left was -oo, where it is +oo. Where the argument arrives at 0, the arccotangent is now answered from the sign its argument arrives with: pi/2 from above, -pi/2 from below, and nothing two-sided unless both sides arrive with the same sign. Substitution and the factor-taking-out paths no longer read the value at the jump, and SitsOnAJump names the arccotangent's jump alongside sgn's. (arccot(x) - pi/2)/x at 0 two-sided was pinned as -1 in LimitTest, which holds for the (0, pi) convention only; under this library's range its left side is +oo. The case moves to the new test as one-sided rows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 6d5f175 commit 806e47d

6 files changed

Lines changed: 106 additions & 7 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,26 @@ A bare `floor(x)` or `sgn(x)` was already declined there. Away from a jump, noth
116116
| `"limit(floor(x) + x, x, 1)".ToEntity().Simplify()` | `2` | `limit(floor(x) + x, x, 1)` |
117117
| `"limitleft(-sgn(x), x, 0)".ToEntity().Simplify()` | `0` | `limitleft(-sgn(x), x, 0)` |
118118

119+
### An arccotangent whose argument arrives at 0 is answered from the side it arrives from
120+
121+
**Silent: a limit through `arccot(u)` where `u` tends to 0 takes `pi/2` where `u` arrives from above and `-pi/2` where
122+
it arrives from below.** This library's arccotangent is `arctan(1/u)`, with range `(-pi/2, pi/2]`, so it jumps at 0:
123+
`arccot(-0.001)` is `-1.5698` and `arccot(0)` is `pi/2`. Limits put 0 in and answered `pi/2` from either side, so a
124+
two-sided limit across the jump had a value, and a quotient over a divisor vanishing from below had the wrong sign.
125+
Found by limitcheck; no issue was filed.
126+
127+
| Input | Was (2.6.0) | Now |
128+
|---|---|---|
129+
| `"arccot(x)".ToEntity().Limit("x", 0, ApproachFrom.Left)` | `pi / 2` | `-pi / 2` |
130+
| `"arccot(x)".ToEntity().Limit("x", 0)` | `pi / 2` | `NaN` |
131+
| `"arccot(-x^2)".ToEntity().Limit("x", 0)` | `pi / 2` | `-pi / 2` |
132+
| `"arccot(x) + arctan(x)".ToEntity().Limit("x", 0)` | `pi / 2` | `NaN` |
133+
| `"arccot(x) / x".ToEntity().Limit("x", 0, ApproachFrom.Left)` | `-oo` | `+oo` |
134+
| `"arccot(x) / x".ToEntity().Limit("x", 0)` | `NaN` | `+oo` |
135+
| `"x * arccot(x) / sin(x)^2".ToEntity().Limit("x", 0)` | `NaN` | `+oo` |
136+
| `"(arccot(x) - pi/2) / x".ToEntity().Limit("x", 0)` | `-1` | `NaN` |
137+
| `"(arccot(x) + pi/2) / x".ToEntity().Limit("x", 0, ApproachFrom.Left)` | `-oo` | `-1` |
138+
119139
### A step function arriving at 0 is answered from the side its argument arrives from
120140

121141
**Silent: a limit of `floor` or `ceil` whose argument tends to 0 is answered where the argument keeps one sign on the

‎Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -766,11 +766,29 @@ partial record Arccotanf
766766
{
767767
// A diverging argument first, as for the arcsecant: substituting it leaves the
768768
// function of an infinity rather than the angle it tends to.
769-
if (InverseTrigonometryAtInfinity(this, Argument.ComputeLimitDivideEtImpera(x, dist, side)) is { } atInfinity)
769+
var argumentLimit = Argument.ComputeLimitDivideEtImpera(x, dist, side);
770+
if (InverseTrigonometryAtInfinity(this, argumentLimit) is { } atInfinity)
770771
return atInfinity;
772+
// At 0 the arccotangent jumps: it is arctan(1/t), with range (-pi/2, pi/2], so
773+
// arccot(0.001) = 1.5698, arccot(-0.001) = -1.5698 and arccot(0) = pi/2. A
774+
// one-sided limit there is taken from the side the argument arrives from, as for
775+
// the sign, and nothing is answered where that side cannot be read. Putting 0 in
776+
// gave pi/2 for arccot(x) at 0 from the left, and for the two-sided limit, which
777+
// is answered here only where both sides arrive from the same side of 0.
778+
if (argumentLimit?.Evaled is Number argumentValue && argumentValue == 0)
779+
{
780+
var arrivesFrom = side is ApproachFrom.BothSides
781+
? SignNear(Argument, x, dist, ApproachFrom.Left) is { } left && SignNear(Argument, x, dist, ApproachFrom.Right) == left ? left : null
782+
: SignNear(Argument, x, dist, side);
783+
return arrivesFrom switch
784+
{
785+
1 => MathS.pi / 2,
786+
-1 => -MathS.pi / 2,
787+
_ => null
788+
};
789+
}
771790
return ComputeLimitImpl(this, x, dist, side) is { } lim ? lim
772-
: ComputeLimitImpl(New(
773-
Argument.ComputeLimitDivideEtImpera(x, dist, side) is { IsFinite: true } lim1 ? lim1 : Argument),
791+
: ComputeLimitImpl(New(argumentLimit is { IsFinite: true } lim1 ? lim1 : Argument),
774792
x, dist, side);
775793
}
776794
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private static bool IsComplexJustShortOfInfinity(Entity argument, Variable x)
9797

9898
/// <summary>
9999
/// Whether <paramref name="node"/> is a step function whose argument evaluates to one of its jumps: an integer for
100-
/// <c>floor</c> and <c>ceil</c>, a half-integer for <c>round</c>, 0 for <c>sgn</c>. Taken on the real part, and on the
100+
/// <c>floor</c> and <c>ceil</c>, a half-integer for <c>round</c>, 0 for <c>sgn</c> and <c>arccot</c>. Taken on the real part, and on the
101101
/// imaginary part of a value that is not real, as LimitOfAStepFunction takes it.
102102
/// </summary>
103103
private static bool SitsOnAJump(Entity node)
@@ -112,6 +112,9 @@ static bool OnAJump(Entity argument, System.Func<Real, bool> jump)
112112
Ceilf(var argument) => OnAJump(argument, Whole),
113113
Roundf(var argument) => OnAJump(argument, part => Whole((Real)(part + Rational.Create(1, 2)).Evaled)),
114114
Signumf(var argument) => argument.Evaled is Complex { IsZero: true },
115+
// The arccotangent is arctan(1/t), with range (-pi/2, pi/2], and jumps at 0 from -pi/2 to pi/2:
116+
// arccot(-0.001) = -1.5698, arccot(0) = pi/2. Its override answers it from the side.
117+
Arccotanf(var argument) => argument.Evaled is Complex { IsZero: true },
115118
_ => false,
116119
};
117120
}

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,13 +1494,23 @@ internal static bool VanishesNear(Entity difference, Variable x, Entity dest, Ap
14941494
private static bool AlreadyBeingDifferentiated(Entity quotient)
14951495
=> (lHopitalChain ??= new()).Contains(quotient);
14961496

1497+
/// <summary>
1498+
/// Whether <paramref name="expr"/> holds an arccotangent whose argument is 0 at <paramref name="dest"/>, where it
1499+
/// jumps: it is arctan(1/t), with range (-pi/2, pi/2], so arccot(-0.001) = -1.5698 and arccot(0) = pi/2. Its value
1500+
/// there is not its limit from below, as a step function's value at a jump is not.
1501+
/// </summary>
1502+
private static bool HasAnArccotangentAtItsJump(Entity expr, Variable x, Entity dest)
1503+
=> expr.Nodes.Any(node => node is Arccotanf(var argument) && argument.ContainsNode(x)
1504+
&& argument.Substitute(x, dest).Evaled is Complex { IsZero: true });
1505+
14971506
/// <summary>
14981507
/// The value of <paramref name="expr"/> at a finite <paramref name="dest"/>, where it is a finite real number and
14991508
/// nothing in it jumps, which is its limit there; otherwise <see langword="null"/>.
15001509
/// </summary>
15011510
private static Entity? ItsValueAt(Entity expr, Variable x, Entity dest)
15021511
{
1503-
if (!dest.IsFinite || expr.Nodes.Any(static node => node is Floorf or Ceilf or Roundf or Signumf or Piecewise))
1512+
if (!dest.IsFinite || expr.Nodes.Any(static node => node is Floorf or Ceilf or Roundf or Signumf or Piecewise)
1513+
|| HasAnArccotangentAtItsJump(expr, x, dest))
15041514
return null;
15051515
var there = expr.Substitute(x, dest);
15061516
return there.Evaled is Real { IsFinite: true, IsNaN: false } ? there.InnerSimplified : null;
@@ -1523,7 +1533,8 @@ private static bool AlreadyBeingDifferentiated(Entity quotient)
15231533
private static Entity? ItsValueOrPoleAt(Entity applied, Variable x, Entity dest, ApproachFrom side)
15241534
{
15251535
if (!dest.IsFinite || side is ApproachFrom.BothSides
1526-
|| applied.Nodes.Any(static node => node is Floorf or Ceilf or Roundf or Signumf or Piecewise))
1536+
|| applied.Nodes.Any(static node => node is Floorf or Ceilf or Roundf or Signumf or Piecewise)
1537+
|| HasAnArccotangentAtItsJump(applied, x, dest))
15271538
return null;
15281539
var distance = dest is Integer { IsZero: true } ? (Entity)x : x - dest;
15291540
Entity finite = Integer.Zero;
@@ -2041,6 +2052,7 @@ bool TakeOut(Entity factor)
20412052
{
20422053
if (factor.ContainsNode(x)
20432054
&& !factor.Nodes.Any(static node => node is Floorf or Ceilf or Roundf or Signumf or Piecewise)
2055+
&& !(dest.IsFinite && HasAnArccotangentAtItsJump(factor, x, dest))
20442056
&& TreeAnalyzer.IsRealValued(factor, x)
20452057
&& (dest.IsFinite ? factor.Substitute(x, dest) : IsAPolynomialPower(factor, x) ? MathS.NaN : ComputeLimit(factor, x, dest, side) ?? MathS.NaN) is var there
20462058
&& there.Evaled is Real { IsFinite: true, IsNaN: false, IsZero: false })
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 AngouriMath.Core;
9+
using AngouriMath.Extensions;
10+
using Xunit;
11+
12+
namespace AngouriMath.Tests.Calculus
13+
{
14+
/// <summary>
15+
/// The arccotangent here is arctan(1/u), with range (-pi/2, pi/2]: arccot(-0.001) = -1.5698, arccot(0) = pi/2,
16+
/// arccot(0.001) = 1.5698. It jumps at 0, and limits put 0 in and answered pi/2 from either side, so arccot(x) at 0
17+
/// had a two-sided limit and arccot(x) / x from the left was -oo where it is +oo. Found by limitcheck; no issue was
18+
/// filed.
19+
/// </summary>
20+
[Trait("Area", "Calculus")]
21+
public sealed class AnArccotangentAtItsJumpTest
22+
{
23+
[Theory]
24+
[InlineData("arccot(x)", ApproachFrom.Left, "-pi / 2")]
25+
[InlineData("arccot(x)", ApproachFrom.Right, "pi / 2")]
26+
[InlineData("arccot(sin(x))", ApproachFrom.Left, "-pi / 2")]
27+
[InlineData("arccot(-x^2)", ApproachFrom.BothSides, "-pi / 2")]
28+
[InlineData("arccot(x^2)", ApproachFrom.BothSides, "pi / 2")]
29+
[InlineData("arccot(x) / x", ApproachFrom.Left, "+oo")]
30+
[InlineData("arccot(x) / x", ApproachFrom.BothSides, "+oo")]
31+
[InlineData("x * arccot(x) / sin(x)^2", ApproachFrom.BothSides, "+oo")]
32+
[InlineData("(arccot(x) - pi / 2) / x", ApproachFrom.Right, "-1")]
33+
[InlineData("(arccot(x) - pi / 2) / x", ApproachFrom.Left, "+oo")]
34+
[InlineData("(arccot(x) + pi / 2) / x", ApproachFrom.Left, "-1")]
35+
public void IsTakenFromTheSide(string input, ApproachFrom side, string expected)
36+
=> Assert.Equal(expected.Simplify(), input.ToEntity().Limit("x", 0, side).Simplify());
37+
38+
// Where the two sides arrive on different sides of the jump, there is no two-sided limit.
39+
[Theory]
40+
[InlineData("arccot(x)")]
41+
[InlineData("arccot(sin(x))")]
42+
[InlineData("arccot(x) + arctan(x)")]
43+
[InlineData("(arccot(x) - pi / 2) / x")]
44+
public void HasNoTwoSidedLimitAcrossTheJump(string input)
45+
=> Assert.Equal(MathS.NaN, input.ToEntity().Limit("x", 0));
46+
}
47+
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ public void TestGeneral(string exprRaw, string destRaw, string expectedRaw, Appr
9292
[InlineData("sec(x)", "1")]
9393
// [InlineData("a x * csc(b x)", "a / b", Skip = "Equivalence table needs improvement")]
9494
[InlineData("(arccos(x) - pi / 2) / x", "-1")]
95-
[InlineData("(arccotan(x) - pi / 2) / x", "-1")]
9695
[InlineData("arccsc(1 / x)", "0")]
9796
[InlineData("arcsec(1 / x) - pi / 2", "0")]
9897
public void TestEquivalenceTableTo0(string input, string expected)

0 commit comments

Comments
 (0)