]> www.ginac.de Git - ginac.git/blobdiff - ginac/inifcns.cpp
binomial(n,k) evaluates for non-integer n [Ralph Stephan]
[ginac.git] / ginac / inifcns.cpp
index 4ffbe2540726e1f75a79f719595cc816a5152344..decef1a8806abd633420ecf5798b46ff7f2bc135 100644 (file)
@@ -48,7 +48,7 @@ static ex conjugate_evalf(const ex & arg)
        if (is_exactly_a<numeric>(arg)) {
                return ex_to<numeric>(arg).conjugate();
        }
-       return conjugate(arg).hold();
+       return conjugate_function(arg).hold();
 }
 
 static ex conjugate_eval(const ex & arg)
@@ -66,10 +66,11 @@ static ex conjugate_conjugate(const ex & arg)
        return arg;
 }
 
-REGISTER_FUNCTION(conjugate, eval_func(conjugate_eval).
+REGISTER_FUNCTION(conjugate_function, eval_func(conjugate_eval).
                        evalf_func(conjugate_evalf).
                        print_func<print_latex>(conjugate_print_latex).
-                       conjugate_func(conjugate_conjugate));
+                       conjugate_func(conjugate_conjugate).
+                       set_name("conjugate","conjugate"));
 
 //////////
 // absolute value
@@ -484,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();
 }