Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions Sources/Tests/UnitTests/Convenience/BinomialTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}

/// <summary>
/// Where <c>n - k</c> is a negative whole number, <c>Γ(n - k + 1)</c> in the denominator has a pole
/// and the binomial is 0, as mpmath has it: the reciprocal gamma vanishes there. It was left
/// unevaluated.
/// </summary>
[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());
Expand Down
Loading