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