Skip to content

Commit e59e609

Browse files
A binomial at a pole of its denominator is zero (#2212)
binomial(n, k) with a k that is not whole, where n - k is a negative whole number, was left as written: Γ(n - k + 1) in the denominator has a pole there, and the evaluation gave up on the NaN it computed. The reciprocal gamma is 0 at a pole, so the binomial is 0, as mpmath has it: binomial(1/2, 3/2), binomial(5/2, 7/2) and binomial(3/2 + i, 5/2 + i) are 0. A whole k is not taken here, where binomial(-3, k) is not 0. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
1 parent f3272dc commit e59e609

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,13 +623,15 @@ It is the forward difference with a step of 1, as Mathematica's `DifferenceDelta
623623

624624
**Not silent: what threw is a number.** `binomial(n, k)` with a whole `n` and a `k` that is not whole was left as
625625
written, so `EvalNumerical` threw `CannotEvalException`. It is the gamma ratio `Γ(n + 1)/(Γ(k + 1) Γ(n - k + 1))`, as
626-
for any other `n`, and for a negative whole `n` it has no value: `Γ(n + 1)` has a pole there
627-
([#1411](https://github.com/asc-community/AngouriMath/issues/1411)).
626+
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
627+
negative whole number, a pole of `Γ(n - k + 1)` in the denominator, it is `0`, the reciprocal gamma vanishing there;
628+
it was left as written ([#1411](https://github.com/asc-community/AngouriMath/issues/1411)).
628629

629630
| Input | Was (2.6.0) | Now |
630631
|---|---|---|
631632
| `"binomial(3, 1/2)".ToEntity().EvalNumerical()` | `CannotEvalException` | `2.0371832715762602978…`, `32/(5 pi)` |
632633
| `"binomial(-3, 1/2)".ToEntity().EvalNumerical()` | `CannotEvalException` | `NaN` |
634+
| `"binomial(1/2, 3/2)".ToEntity().Simplify()` | `binomial(1/2, 3/2)` | `0` |
633635

634636
### The harmonic numbers
635637

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,9 @@ protected override Entity InnerSimplify(bool isExact) =>
568568
(_, Integer { IsZero: true }) => Integer.Create(1),
569569
// A k that is not whole has no value with a negative whole n, a pole of Γ(n + 1).
570570
(Integer { EInteger.Sign: < 0 }, Complex bottom) when bottom is not Integer => MathS.NaN,
571+
// And is 0 where n - k is a negative whole number, a pole of Γ(n - k + 1), where the
572+
// reciprocal gamma is 0: binomial(1/2, 3/2) is 0.
573+
(Number top, Number bottom) when bottom is not Integer && (top - bottom).Evaled is Integer { EInteger.Sign: < 0 } => Integer.Zero,
571574
// Through the gamma function only numerically: there is no exact form. A whole n
572575
// takes it too: binomial(3, 1/2) is 32/(5 pi).
573576
(Complex top, Complex bottom) when !isExact

‎Sources/Tests/UnitTests/Convenience/BinomialTest.cs‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,22 @@ public void AWholeUpperArgumentWithAFractionalLowerOneEvaluatesThroughTheGammaFu
8383
Assert.True(value.EDecimal.Subtract(PeterO.Numbers.EDecimal.FromString(expected)).Abs().CompareTo(PeterO.Numbers.EDecimal.FromString("1e-25")) < 0, $"{input} evaluated to {value}");
8484
}
8585

86+
/// <summary>
87+
/// Where <c>n - k</c> is a negative whole number, <c>Γ(n - k + 1)</c> in the denominator has a pole
88+
/// and the binomial is 0, as mpmath has it: the reciprocal gamma vanishes there. It was left
89+
/// unevaluated.
90+
/// </summary>
91+
[Theory]
92+
[InlineData("binomial(1/2, 3/2)")]
93+
[InlineData("binomial(5/2, 7/2)")]
94+
[InlineData("binomial(1/2, 5/2)")]
95+
[InlineData("binomial(3/2 + i, 5/2 + i)")]
96+
public void AtAPoleOfTheDenominatorItIsZero(string input)
97+
{
98+
Assert.Equal(Entity.Number.Integer.Zero, input.ToEntity().InnerSimplified);
99+
Assert.Equal(Entity.Number.Integer.Zero, input.ToEntity().EvalNumerical());
100+
}
101+
86102
[Fact]
87103
public void ANegativeWholeUpperArgumentWithAFractionalLowerOneHasNoValue()
88104
=> Assert.Equal(MathS.NaN, "binomial(-3, 1/2)".ToEntity().EvalNumerical());

0 commit comments

Comments
 (0)