Skip to content

Commit c920408

Browse files
arctan and arccot are undefined at their poles (#2304)
arctan(z) is (i/2)(ln(1 - iz) - ln(1 + iz)), with poles where 1 + z^2 = 0, at i and -i, where it evaluates to an infinity as ln(0) does. arccot(z) is arctan(1/z) and has the same two. Both conditions said True, so arctan(x) - arctan(x) simplified to 0, which has a value at i. They are now not 1 + x^2 = 0, as the tangent's excludes its own poles. The linear-over-quadratic integral wrote its arctangent part even when the numerator was a multiple of the denominator's derivative and left no constant for it, 0 * arctan(2x/2). With the poles in arctan's condition that zero kept them, and x/(x^2 + 1) was answered with provided not 1 + (2x/2)^2 = 0 beside a logarithm that has no value there either: ten tests, through the substitution u = tan(c + dx) as well. It now leaves the part out, as the higher powers of the quadratic already did. An antiderivative that keeps an arctangent can list its poles among the points it has no value at. They say nothing new, and the redundant-condition step cannot see that, since Simplify spells the condition and the arctangent's argument differently. x^2 coth(a + 2 ln(x))^2 is the one test that notices: 1,128 characters of raw answer went to 1,382, against a bound of 1,300 meant to catch the 3,577 of a split on a symbol's sign, so the bound is 1,400. ArctangentPolesTest checks the condition at both poles and off them, and that the two differences have no value at i. The suite, the trio, F#, AOT and the eight harnesses pass. Fixes #2256. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent a435926 commit c920408

6 files changed

Lines changed: 94 additions & 5 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,22 @@ conjugate as `0 - 1i`, in decimals, on the one instance that every `i` is, in ev
974974
|---|---|---|
975975
| `Complex.ImaginaryOne.Conjugate`, after `(1 / Complex.ImaginaryOne).Evaled` with `DowncastingEnabled` off | `0 - 1i` | `-i` |
976976

977+
### `arctan` and `arccot` are undefined at their poles
978+
979+
**Silent: a simplification that cancels an `arctan` or an `arccot` carries `not 1 + x ^ 2 = 0`, where it carried
980+
nothing.** Both have poles at `i` and `-i`, where they evaluate to an infinity, as `ln(0)` does, and the tangent's
981+
condition excludes its own poles the same way. Their condition said they were defined everywhere, so
982+
`arctan(x) - arctan(x)` simplified to `0`, which has a value at `i`. An antiderivative that keeps an `arctan` can now
983+
list its poles beside the other points it has no value at, which says nothing new
984+
([#2256](https://github.com/asc-community/AngouriMath/issues/2256)).
985+
986+
| Input | Was (2.6.0) | Now |
987+
|---|---|---|
988+
| `"arctan(x) - arctan(x)".ToEntity().Simplify()` | `0` | `0 provided not 1 + x ^ 2 = 0` |
989+
| `"arccot(x) - arccot(x)".ToEntity().Simplify()` | `0` | `0 provided not 1 + x ^ 2 = 0` |
990+
| `"arctan(x)".ToEntity().DomainCondition` | `True` | `not 1 + x ^ 2 = 0` |
991+
| `"x^2*coth(a + 2*ln(x))^2".ToEntity().Integrate("x").Simplify()` | `… + C + x ^ 3 / 3` | `… + C + x ^ 3 / 3 provided not x ^ 2 / e ^ (-a) + 1 = 0 and not x ^ 2 / (-e ^ (-a)) + 1 = 0` |
992+
977993
### `max` and `min` are defined where their arguments are real
978994

979995
**Silent: `max(x, x)` and `min(x, x)` simplify to `x provided x in RR`, where they were `x`.** The complex numbers are

‎Sources/.editorconfig‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
235235
[AngouriMath/Core/Budgets/*.cs]
236236
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n
237237

238+
[Tests/UnitTests/Convenience/ArctangentPolesTest.cs]
239+
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n
240+
238241
[Tests/UnitTests/Algebra/SolveTest/ModulusEquationTest.cs]
239242
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n
240243

‎Sources/AngouriMath/Functions/Continuous/Integration/IntegralPatterns.cs‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1479,16 +1479,26 @@ private static bool IsAnEvenRootOfASymbol(Entity expr)
14791479
/// and the second is the constant-numerator case above.
14801480
/// </summary>
14811481
/// <remarks>
1482+
/// <para>
14821483
/// With <c>a</c> a symbol the constant-numerator case is a piecewise with an arm for
14831484
/// <c>a = 0</c>, and on that arm the multiple of the derivative, which divided by
14841485
/// <c>a</c>, is not the integrand's: there it is <c>(px + q)/(bx + c)</c>, which is
14851486
/// <c>px/b + (q - pc/b) ln(bx + c)/b</c>. Timofeev's <c>(b1 + c1 x)/(a + 2b x + c x^2)</c>
14861487
/// had no antiderivative, with the arm declined for the symbol in front.
1488+
/// </para>
1489+
/// <para>
1490+
/// A numerator that is a multiple of the derivative leaves no constant part, and the
1491+
/// arctangent it would have is left out rather than multiplied by zero, as the higher
1492+
/// powers leave it out: <c>0 * arctan(2x/2)</c> is <c>0</c> only where the arctangent has
1493+
/// a value, so <c>x/(x^2 + 1)</c> was answered with <c>provided not 1 + (2x/2)^2 = 0</c>
1494+
/// once the arctangent's poles were in its condition, beside a logarithm that has none
1495+
/// there either. https://github.com/asc-community/AngouriMath/issues/2256
1496+
/// </para>
14871497
/// </remarks>
14881498
private static Entity IntegrateLinearOverQuadratic(
14891499
Entity p, Entity q, Entity a, Entity b, Entity c, Entity denominator, Entity.Variable x)
14901500
=> WithTheArmForAZeroLeadingCoefficient(
1491-
IntegrateRationalQuadratic(q - p * b / (2 * a), a, b, c, x),
1501+
TreeAnalyzer.IsZero(q - p * b / (2 * a)) ? Entity.Number.Integer.Zero : IntegrateRationalQuadratic(q - p * b / (2 * a), a, b, c, x),
14921502
a,
14931503
p / (2 * a) * AntiderivativeLog(denominator),
14941504
LinearOverPowerOfLinear(p, q, b, c, 1, x));

‎Sources/AngouriMath/Functions/Evaluation/Evaluation.Continuous/Evaluation.Continuous.Trigonometry.Classes.cs‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,11 @@ Set.Interval interval when IntervalArithmetic.MonotoneOn(interval, -1, 1, increa
228228

229229
public partial record Arctanf
230230
{
231-
private protected override Entity IntrinsicCondition => Boolean.True;
231+
// arctan(z) = (i/2)(ln(1 - iz) - ln(1 + iz)) has poles where 1 + z^2 = 0, at z = i and z = -i, where it
232+
// evaluates to an infinity, as ln(0) does: undefined there, as the tangent is where its cosine is 0.
233+
// The condition said True, and arctan(x) - arctan(x) simplified to 0, which has a value at i.
234+
// https://github.com/asc-community/AngouriMath/issues/2256
235+
private protected override Entity IntrinsicCondition => !(1 + Argument.Pow(2)).EqualTo(0);
232236

233237
/// <inheritdoc/>
234238
protected override Entity InnerSimplify(bool isExact) =>
@@ -254,7 +258,9 @@ Set.Interval interval when IntervalArithmetic.Monotone(interval, increasing: tru
254258

255259
public partial record Arccotanf
256260
{
257-
private protected override Entity IntrinsicCondition => Boolean.True;
261+
// arccot(z) = arctan(1/z), so its poles are arctan's, z = i and z = -i. At 0 it is pi/2.
262+
// https://github.com/asc-community/AngouriMath/issues/2256
263+
private protected override Entity IntrinsicCondition => !(1 + Argument.Pow(2)).EqualTo(0);
258264

259265
/// <inheritdoc/>
260266
protected override Entity InnerSimplify(bool isExact) =>

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,17 @@ private static void DifferentiatesBack(string integrand, int longest)
7474
/// <summary>
7575
/// An even power of <c>x</c>, where the factorisation reads a symbol and splits the
7676
/// biquadratic over it into arms on its sign -- <c>coth(a + 2 ln(x))/x^2</c> is 3,577
77-
/// characters in the symbol and 413 as the exponential, which is kept.
77+
/// characters in the symbol and 413 as the exponential, which is kept. The bound was 1,300
78+
/// until the arctangent's poles joined the points the answer lists as having no value:
79+
/// <c>x^2 coth(a + 2 ln(x))^2</c> keeps two arctangents and went from 1,128 characters to
80+
/// 1,382 with their two conditions. https://github.com/asc-community/AngouriMath/issues/2256
7881
/// </summary>
7982
[Theory]
8083
[InlineData("coth(a + 2*ln(x))/x^2")]
8184
[InlineData("coth(a + 2*ln(x))^2/x^2")]
8285
[InlineData("coth(a + 2*ln(x))^2")]
8386
[InlineData("x^2*coth(a + 2*ln(x))^2")]
8487
[InlineData("tanh(a + 2*ln(x))^2")]
85-
public void AnEvenPowerOfX(string integrand) => DifferentiatesBack(integrand, 1300);
88+
public void AnEvenPowerOfX(string integrand) => DifferentiatesBack(integrand, 1400);
8689
}
8790
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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;
9+
using AngouriMath.Extensions;
10+
using Xunit;
11+
12+
namespace AngouriMath.Tests.Convenience
13+
{
14+
/// <summary>
15+
/// <c>arctan</c> and <c>arccot</c> are undefined at their poles, <c>i</c> and <c>-i</c>, where they evaluate to an
16+
/// infinity, as <c>ln(0)</c> does and as the tangent is where its cosine is 0. Their condition said <c>True</c>, and
17+
/// <c>arctan(x) - arctan(x)</c> simplified to <c>0</c>, which has a value at <c>i</c>.
18+
/// <a href="https://github.com/asc-community/AngouriMath/issues/2256">#2256</a>
19+
/// </summary>
20+
[Trait("Area", "Convenience")]
21+
public sealed class ArctangentPolesTest
22+
{
23+
[Theory]
24+
[InlineData("arctan(x)", "i", false)]
25+
[InlineData("arctan(x)", "-i", false)]
26+
[InlineData("arctan(x)", "2", true)]
27+
[InlineData("arctan(x)", "0", true)]
28+
[InlineData("arctan(x)", "1/2 + 6/5 * i", true)]
29+
[InlineData("arccot(x)", "i", false)]
30+
[InlineData("arccot(x)", "-i", false)]
31+
[InlineData("arccot(x)", "0", true)]
32+
[InlineData("arccot(x)", "-3", true)]
33+
public void ItIsDefinedOffItsPoles(string expression, string at, bool defined)
34+
{
35+
var condition = expression.ToEntity().DomainCondition.Substitute("x", at.ToEntity()).Evaled;
36+
Assert.Equal(defined ? Entity.Boolean.True : Entity.Boolean.False, condition);
37+
var value = expression.ToEntity().Substitute("x", at.ToEntity()).Evaled;
38+
Assert.Equal(defined, value is Entity.Number number && number.IsFinite);
39+
}
40+
41+
[Theory]
42+
[InlineData("arctan(x) - arctan(x)")]
43+
[InlineData("arccot(x) - arccot(x)")]
44+
public void ASimplificationHasNoValueAtAPole(string expression)
45+
{
46+
var simplified = expression.ToEntity().Simplify();
47+
Assert.True(simplified.Substitute("x", "i".ToEntity()).Evaled.IsNaN, $"{simplified} at i");
48+
Assert.Equal(Entity.Number.Integer.Zero, simplified.Substitute("x", 2).Evaled);
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)