From: Christian Bauer Date: Wed, 6 Oct 2004 15:38:02 +0000 (+0000) Subject: synced to HEAD (binomial()) X-Git-Tag: release_1-2-4~5 X-Git-Url: https://www.ginac.de/ginac.git/static/git-favicon.png/ginac.git?a=commitdiff_plain;h=0c0833bb36921d6546ce87c6bef959330b561a9e;p=ginac.git synced to HEAD (binomial()) --- diff --git a/NEWS b/NEWS index a188df7f..37b6c5fc 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,8 @@ This file records noteworthy changes. +1.2.4 () +* binomial(n, k) evaluates for non-integer arguments n. + 1.2.3 (13 August 2004) * Added variants of dirac_trace() and color_trace() that take the trace over more than one representation label by specifying a set or list of labels. diff --git a/ginac/inifcns.cpp b/ginac/inifcns.cpp index fa5e9a20..decef1a8 100644 --- a/ginac/inifcns.cpp +++ b/ginac/inifcns.cpp @@ -485,11 +485,32 @@ static ex binomial_evalf(const ex & x, const ex & y) return binomial(x, y).hold(); } +static ex binomial_sym(const ex & x, const numeric & y) +{ + if (y.is_integer()) { + if (y.is_nonneg_integer()) { + const unsigned N = y.to_int(); + if (N == 0) return _num0; + if (N == 1) return x; + ex t = x.expand(); + for (unsigned i = 2; i <= N; ++i) + t = (t * (x + i - y - 1)).expand() / i; + return t; + } else + return _num0; + } + + return binomial(x, y).hold(); +} + static ex binomial_eval(const ex & x, const ex &y) { - if (is_exactly_a(x) && is_exactly_a(y)) - return binomial(ex_to(x), ex_to(y)); - else + if (is_exactly_a(y)) { + if (is_exactly_a(x) && ex_to(x).is_integer()) + return binomial(ex_to(x), ex_to(y)); + else + return binomial_sym(x, ex_to(y)); + } else return binomial(x, y).hold(); } diff --git a/ginac/numeric.cpp b/ginac/numeric.cpp index b6c95e01..3130e272 100644 --- a/ginac/numeric.cpp +++ b/ginac/numeric.cpp @@ -1629,7 +1629,7 @@ const numeric binomial(const numeric &n, const numeric &k) } // should really be gamma(n+1)/gamma(k+1)/gamma(n-k+1) or a suitable limit - throw std::range_error("numeric::binomial(): don“t know how to evaluate that."); + throw std::range_error("numeric::binomial(): don't know how to evaluate that."); }