|
| 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 | + /// The factorial, and the gamma function with it, is defined everywhere but at the negative integers, its poles, where |
| 16 | + /// its condition asked for a real argument as well: <c>i!</c> is <c>0.498 - 0.155i</c>, and <c>x!/x!</c> simplified to |
| 17 | + /// <c>1 provided x in RR</c>, which has no 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 FactorialOffTheRealLineTest |
| 22 | + { |
| 23 | + [Theory] |
| 24 | + [InlineData("x!", "i", true)] |
| 25 | + [InlineData("x!", "1/2 + 6/5 * i", true)] |
| 26 | + [InlineData("x!", "-2 * i", true)] |
| 27 | + [InlineData("x!", "-1/2", true)] |
| 28 | + [InlineData("x!", "0", true)] |
| 29 | + [InlineData("x!", "3", true)] |
| 30 | + [InlineData("x!", "-1", false)] |
| 31 | + [InlineData("x!", "-2", false)] |
| 32 | + [InlineData("gamma(x)", "i", true)] |
| 33 | + [InlineData("gamma(x)", "0", false)] |
| 34 | + [InlineData("gamma(x)", "-3", false)] |
| 35 | + public void ItIsDefinedOffThePoles(string expression, string at, bool defined) |
| 36 | + { |
| 37 | + var condition = expression.ToEntity().DomainCondition.Substitute("x", at.ToEntity()).Evaled; |
| 38 | + Assert.Equal(defined ? Entity.Boolean.True : Entity.Boolean.False, condition); |
| 39 | + Assert.Equal(!defined, expression.ToEntity().Substitute("x", at.ToEntity()).Evaled.IsNaN); |
| 40 | + } |
| 41 | + |
| 42 | + [Theory] |
| 43 | + [InlineData("x! / x!", "i")] |
| 44 | + [InlineData("gamma(x) / gamma(x)", "1/2 + 6/5 * i")] |
| 45 | + public void ASimplificationKeepsItsValueThere(string expression, string at) |
| 46 | + => Assert.Equal(Entity.Number.Integer.One, expression.ToEntity().Simplify().Substitute("x", at.ToEntity()).Evaled); |
| 47 | + } |
| 48 | +} |
0 commit comments