Skip to content

Commit fe19c27

Browse files
Take an arccotangent at its jump from the side its argument arrives from (#2420)
* Take an arccotangent at its jump from the side its argument arrives from Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent bbf56b5 commit fe19c27

6 files changed

Lines changed: 129 additions & 8 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,33 @@ 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. The
125+
sign of an expression vanishing at the point was read from its derivative there, and where that derivative holds
126+
`arccot(x)` the sign came out wrong from the left: `x * arccot(x)` is positive on both sides of 0.
127+
Found by limitcheck; no issue was filed.
128+
129+
| Input | Was (2.6.0) | Now |
130+
|---|---|---|
131+
| `"arccot(x)".ToEntity().Limit("x", 0, ApproachFrom.Left)` | `pi / 2` | `-pi / 2` |
132+
| `"arccot(x)".ToEntity().Limit("x", 0)` | `pi / 2` | `NaN` |
133+
| `"arccot(-x^2)".ToEntity().Limit("x", 0)` | `pi / 2` | `-pi / 2` |
134+
| `"arccot(x) + arctan(x)".ToEntity().Limit("x", 0)` | `pi / 2` | `NaN` |
135+
| `"arccot(x) / x".ToEntity().Limit("x", 0, ApproachFrom.Left)` | `-oo` | `+oo` |
136+
| `"arccot(x) / x".ToEntity().Limit("x", 0)` | `NaN` | `+oo` |
137+
| `"x * arccot(x) / sin(x)^2".ToEntity().Limit("x", 0)` | `NaN` | `+oo` |
138+
| `"(arccot(x) - pi/2) / x".ToEntity().Limit("x", 0)` | `-1` | `NaN` |
139+
| `"(arccot(x) + pi/2) / x".ToEntity().Limit("x", 0, ApproachFrom.Left)` | `-oo` | `-1` |
140+
| `"1 / (x * arccot(x))".ToEntity().Limit("x", 0, ApproachFrom.Left)` | `-oo` | `limitleft(1 / (x * arccotan(x)), x, 0)` |
141+
| `"sgn(x * arccot(x))".ToEntity().Limit("x", 0, ApproachFrom.Left)` | `limitleft(sgn(x * arccotan(x)), x, 0)` | `1` |
142+
| `"sgn(x * arccot(x))".ToEntity().Limit("x", 0)` | `limit(sgn(x * arccotan(x)), x, 0)` | `1` |
143+
| `"floor(x * arccot(x))".ToEntity().Limit("x", 0, ApproachFrom.Left)` | `limitleft(floor(x * arccotan(x)), x, 0)` | `0` |
144+
| `"arccot(x * sin(1/x))".ToEntity().Limit("x", 0)` | `pi / 2` | `limit(arccotan(x * sin(1 / x)), x, 0)` |
145+
119146
### A step function arriving at 0 is answered from the side its argument arrives from
120147

121148
**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: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -766,11 +766,31 @@ 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+
// An argument that is 0 everywhere has no side to arrive from, and the
788+
// arccotangent of it is the constant pi/2: (x^2 - 1) - (x - 1)(x + 1).
789+
_ => Argument.Simplify().Evaled is Number simplified && simplified == 0 ? MathS.pi / 2 : null
790+
};
791+
}
771792
return ComputeLimitImpl(this, x, dist, side) is { } lim ? lim
772-
: ComputeLimitImpl(New(
773-
Argument.ComputeLimitDivideEtImpera(x, dist, side) is { IsFinite: true } lim1 ? lim1 : Argument),
793+
: ComputeLimitImpl(New(argumentLimit is { IsFinite: true } lim1 ? lim1 : Argument),
774794
x, dist, side);
775795
}
776796
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ private static bool IsComplexJustShortOfInfinity(Entity argument, Variable x)
9696
&& LimitFunctional.AtALargeDecimal(argument, x) is Complex and not Real;
9797

9898
/// <summary>
99-
/// 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
99+
/// Whether <paramref name="node"/> is a step function, or an arccotangent, 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> 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: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,11 @@ internal static bool IsDeterminate(Entity combined, Variable x)
11861186
{
11871187
MultithreadingFunctional.ExitIfCancelled();
11881188
derivative = derivative.Differentiate(x).Simplify();
1189+
// A derivative with an arccotangent at its jump in it has no single value at the point:
1190+
// x arccot(x) differentiates to arccot(x) - x / (1 + x^2), pi/2 there by putting 0 in
1191+
// and -pi/2 from the left, so its sign from the left came out -1 where it is +1.
1192+
if (HasAnArccotangentAtItsJump(derivative, x, dest))
1193+
return null;
11891194
var atThePoint = EvalAssumingContinuous(derivative.Substitute(x, dest).InnerSimplified);
11901195
if (atThePoint is not Real { IsFinite: true } value)
11911196
return null;
@@ -1494,13 +1499,23 @@ internal static bool VanishesNear(Entity difference, Variable x, Entity dest, Ap
14941499
private static bool AlreadyBeingDifferentiated(Entity quotient)
14951500
=> (lHopitalChain ??= new()).Contains(quotient);
14961501

1502+
/// <summary>
1503+
/// Whether <paramref name="expr"/> holds an arccotangent whose argument is 0 at <paramref name="dest"/>, where it
1504+
/// 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
1505+
/// there is not its limit from below, as a step function's value at a jump is not.
1506+
/// </summary>
1507+
private static bool HasAnArccotangentAtItsJump(Entity expr, Variable x, Entity dest)
1508+
=> expr.Nodes.Any(node => node is Arccotanf(var argument) && argument.ContainsNode(x)
1509+
&& argument.Substitute(x, dest).Evaled is Complex { IsZero: true });
1510+
14971511
/// <summary>
14981512
/// The value of <paramref name="expr"/> at a finite <paramref name="dest"/>, where it is a finite real number and
14991513
/// nothing in it jumps, which is its limit there; otherwise <see langword="null"/>.
15001514
/// </summary>
15011515
private static Entity? ItsValueAt(Entity expr, Variable x, Entity dest)
15021516
{
1503-
if (!dest.IsFinite || expr.Nodes.Any(static node => node is Floorf or Ceilf or Roundf or Signumf or Piecewise))
1517+
if (!dest.IsFinite || expr.Nodes.Any(static node => node is Floorf or Ceilf or Roundf or Signumf or Piecewise)
1518+
|| HasAnArccotangentAtItsJump(expr, x, dest))
15041519
return null;
15051520
var there = expr.Substitute(x, dest);
15061521
return there.Evaled is Real { IsFinite: true, IsNaN: false } ? there.InnerSimplified : null;
@@ -1523,7 +1538,8 @@ private static bool AlreadyBeingDifferentiated(Entity quotient)
15231538
private static Entity? ItsValueOrPoleAt(Entity applied, Variable x, Entity dest, ApproachFrom side)
15241539
{
15251540
if (!dest.IsFinite || side is ApproachFrom.BothSides
1526-
|| applied.Nodes.Any(static node => node is Floorf or Ceilf or Roundf or Signumf or Piecewise))
1541+
|| applied.Nodes.Any(static node => node is Floorf or Ceilf or Roundf or Signumf or Piecewise)
1542+
|| HasAnArccotangentAtItsJump(applied, x, dest))
15271543
return null;
15281544
var distance = dest is Integer { IsZero: true } ? (Entity)x : x - dest;
15291545
Entity finite = Integer.Zero;
@@ -2041,6 +2057,7 @@ bool TakeOut(Entity factor)
20412057
{
20422058
if (factor.ContainsNode(x)
20432059
&& !factor.Nodes.Any(static node => node is Floorf or Ceilf or Roundf or Signumf or Piecewise)
2060+
&& !(dest.IsFinite && HasAnArccotangentAtItsJump(factor, x, dest))
20442061
&& TreeAnalyzer.IsRealValued(factor, x)
20452062
&& (dest.IsFinite ? factor.Substitute(x, dest) : IsAPolynomialPower(factor, x) ? MathS.NaN : ComputeLimit(factor, x, dest, side) ?? MathS.NaN) is var there
20462063
&& there.Evaled is Real { IsFinite: true, IsNaN: false, IsZero: false })
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
// x arccot(x) is positive on both sides of 0: its derivative there holds arccot(x) itself,
36+
// whose value at 0 is not its limit from the left, so it does not give the sign.
37+
[InlineData("arccot(x * arccot(x))", ApproachFrom.Left, "pi / 2")]
38+
[InlineData("arccot(x * arccot(x))", ApproachFrom.BothSides, "pi / 2")]
39+
[InlineData("sgn(x * arccot(x))", ApproachFrom.Left, "1")]
40+
[InlineData("1 / (x * arccot(x))", ApproachFrom.Left, "+oo")]
41+
// An argument that is 0 everywhere: the arccotangent of it is the constant pi/2.
42+
[InlineData("arccot((x^2 - 1) - (x - 1) * (x + 1))", ApproachFrom.BothSides, "pi / 2")]
43+
public void IsTakenFromTheSide(string input, ApproachFrom side, string expected)
44+
=> Assert.Equal(expected.Simplify(), input.ToEntity().Limit("x", 0, side).Simplify());
45+
46+
// Where the two sides arrive on different sides of the jump, there is no two-sided limit.
47+
[Theory]
48+
[InlineData("arccot(x)")]
49+
[InlineData("arccot(sin(x))")]
50+
[InlineData("arccot(x) + arctan(x)")]
51+
[InlineData("(arccot(x) - pi / 2) / x")]
52+
public void HasNoTwoSidedLimitAcrossTheJump(string input)
53+
=> Assert.Equal(MathS.NaN, input.ToEntity().Limit("x", 0));
54+
}
55+
}

‎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)