1
$\begingroup$

I like to use the (common) representations of the binomials for integer arguments, such that eg Binomial[1/2,1] evaluates to 0 rand not to 1/2. Is there a simple generic way to do this?

This is relevant since there are quite some standard expressions and equations which are based on that, e.g. definition of Fibonacci Polynomials, ...

$\endgroup$
3
  • $\begingroup$ In version 11.3., Binomial[1/2, 1] does evaluate to 1/2. If your version does not support this, you might define binomial[n_, m_] := Gamma[n + 1]/(Gamma[m + 1] Gamma[n - m + 1]). $\endgroup$ Commented Apr 12, 2018 at 11:42
  • $\begingroup$ @HenrikSchumacher: I also get 1/2 but I need a simple way to get to 0. $\endgroup$ Commented Apr 12, 2018 at 11:44
  • 1
    $\begingroup$ Ah, now I got it (hopefully...) $\endgroup$ Commented Apr 12, 2018 at 11:46

1 Answer 1

1
$\begingroup$

Try this:

ClearAll[binomial]
binomial[
   n_?(Statistics`Library`RealIntegerQ[#] && Positive[#] &),
   m_?(Statistics`Library`RealIntegerQ[#] && Positive[#] &)
  ] := Binomial[Round[n], Round[m]];
binomial[n_, m_] := 0;

Older, less robust version

ClearAll[binomial]
binomial[
   n_Integer?Positive,
   m_Integer?Positive
  ] := Binomial[n,m];
binomial[n_, m_] := 0;
$\endgroup$
3
  • $\begingroup$ Perfect! Thanks a lot!! $\endgroup$ Commented Apr 12, 2018 at 11:49
  • 1
    $\begingroup$ See also last edit. The old version did not behave as desired for negative arguments and for integers in disguise (such as binomial[2.,1] also returned 0). Just tell me if you happen to observe bugs. $\endgroup$ Commented Apr 12, 2018 at 11:57
  • $\begingroup$ Well, actually what I was looking for was anyway the version for natural numbers, and it was easy to understand. Thus, would it be possible that you still give the old answer as an alternative? $\endgroup$ Commented Apr 12, 2018 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.