diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 88426ba3e..66d8750f7 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -623,13 +623,15 @@ It is the forward difference with a step of 1, as Mathematica's `DifferenceDelta **Not silent: what threw is a number.** `binomial(n, k)` with a whole `n` and a `k` that is not whole was left as written, so `EvalNumerical` threw `CannotEvalException`. It is the gamma ratio `Γ(n + 1)/(Γ(k + 1) Γ(n - k + 1))`, as -for any other `n`, and for a negative whole `n` it has no value: `Γ(n + 1)` has a pole there -([#1411](https://github.com/asc-community/AngouriMath/issues/1411)). +for any other `n`, and for a negative whole `n` it has no value: `Γ(n + 1)` has a pole there. Where `n - k` is a +negative whole number, a pole of `Γ(n - k + 1)` in the denominator, it is `0`, the reciprocal gamma vanishing there; +it was left as written ([#1411](https://github.com/asc-community/AngouriMath/issues/1411)). | Input | Was (2.6.0) | Now | |---|---|---| | `"binomial(3, 1/2)".ToEntity().EvalNumerical()` | `CannotEvalException` | `2.0371832715762602978…`, `32/(5 pi)` | | `"binomial(-3, 1/2)".ToEntity().EvalNumerical()` | `CannotEvalException` | `NaN` | +| `"binomial(1/2, 3/2)".ToEntity().Simplify()` | `binomial(1/2, 3/2)` | `0` | ### The harmonic numbers diff --git a/Sources/AngouriMath/Functions/Evaluation/Evaluation.Continuous/Evaluation.Continuous.Arithmetics.Classes.cs b/Sources/AngouriMath/Functions/Evaluation/Evaluation.Continuous/Evaluation.Continuous.Arithmetics.Classes.cs index 6f2a617db..4168f7f50 100644 --- a/Sources/AngouriMath/Functions/Evaluation/Evaluation.Continuous/Evaluation.Continuous.Arithmetics.Classes.cs +++ b/Sources/AngouriMath/Functions/Evaluation/Evaluation.Continuous/Evaluation.Continuous.Arithmetics.Classes.cs @@ -568,6 +568,9 @@ protected override Entity InnerSimplify(bool isExact) => (_, Integer { IsZero: true }) => Integer.Create(1), // A k that is not whole has no value with a negative whole n, a pole of Γ(n + 1). (Integer { EInteger.Sign: < 0 }, Complex bottom) when bottom is not Integer => MathS.NaN, + // And is 0 where n - k is a negative whole number, a pole of Γ(n - k + 1), where the + // reciprocal gamma is 0: binomial(1/2, 3/2) is 0. + (Number top, Number bottom) when bottom is not Integer && (top - bottom).Evaled is Integer { EInteger.Sign: < 0 } => Integer.Zero, // Through the gamma function only numerically: there is no exact form. A whole n // takes it too: binomial(3, 1/2) is 32/(5 pi). (Complex top, Complex bottom) when !isExact diff --git a/Sources/Tests/UnitTests/Convenience/BinomialTest.cs b/Sources/Tests/UnitTests/Convenience/BinomialTest.cs index 1269ac20f..78b5e67c7 100644 --- a/Sources/Tests/UnitTests/Convenience/BinomialTest.cs +++ b/Sources/Tests/UnitTests/Convenience/BinomialTest.cs @@ -83,6 +83,22 @@ public void AWholeUpperArgumentWithAFractionalLowerOneEvaluatesThroughTheGammaFu Assert.True(value.EDecimal.Subtract(PeterO.Numbers.EDecimal.FromString(expected)).Abs().CompareTo(PeterO.Numbers.EDecimal.FromString("1e-25")) < 0, $"{input} evaluated to {value}"); } + /// + /// Where n - k is a negative whole number, Γ(n - k + 1) in the denominator has a pole + /// and the binomial is 0, as mpmath has it: the reciprocal gamma vanishes there. It was left + /// unevaluated. + /// + [Theory] + [InlineData("binomial(1/2, 3/2)")] + [InlineData("binomial(5/2, 7/2)")] + [InlineData("binomial(1/2, 5/2)")] + [InlineData("binomial(3/2 + i, 5/2 + i)")] + public void AtAPoleOfTheDenominatorItIsZero(string input) + { + Assert.Equal(Entity.Number.Integer.Zero, input.ToEntity().InnerSimplified); + Assert.Equal(Entity.Number.Integer.Zero, input.ToEntity().EvalNumerical()); + } + [Fact] public void ANegativeWholeUpperArgumentWithAFractionalLowerOneHasNoValue() => Assert.Equal(MathS.NaN, "binomial(-3, 1/2)".ToEntity().EvalNumerical());