]> www.ginac.de Git - ginac.git/commitdiff
synced to HEAD (binomial())
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Wed, 6 Oct 2004 15:38:02 +0000 (15:38 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Wed, 6 Oct 2004 15:38:02 +0000 (15:38 +0000)
NEWS
ginac/inifcns.cpp
ginac/numeric.cpp

diff --git a/NEWS b/NEWS
index a188df7f2ac95f295cd1f9d883d2bc3986e86b1c..37b6c5fc465ef2b40f3957f12a4efe433cf30ccc 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,8 @@
 This file records noteworthy changes.
 
+1.2.4 (<date>)
+* 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.
index fa5e9a20fb4e2f0aff9fea5d09663bf38d709f2a..decef1a8806abd633420ecf5798b46ff7f2bc135 100644 (file)
@@ -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<numeric>(x) && is_exactly_a<numeric>(y))
-               return binomial(ex_to<numeric>(x), ex_to<numeric>(y));
-       else
+       if (is_exactly_a<numeric>(y)) {
+               if (is_exactly_a<numeric>(x) && ex_to<numeric>(x).is_integer())
+                       return binomial(ex_to<numeric>(x), ex_to<numeric>(y));
+               else
+                       return binomial_sym(x, ex_to<numeric>(y));
+       } else
                return binomial(x, y).hold();
 }
 
index b6c95e01e0c9854ee3e2ab7f97156b6966afc573..3130e272ac17e3afb2e549d8f9ae75437569c1d2 100644 (file)
@@ -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.");
 }