]> www.ginac.de Git - ginac.git/blobdiff - ginac/inifcns_nstdsums.cpp
S(0,p,x) now evaluates numerically
[ginac.git] / ginac / inifcns_nstdsums.cpp
index 4fe91ad391eeb7f41e40362c7fa67223339da3a6..ec9586ed9367160fcd3b5a97fb5a3dda4db84ebf 100644 (file)
@@ -46,7 +46,7 @@
  */
 
 /*
- *  GiNaC Copyright (C) 1999-2003 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2004 Johannes Gutenberg University Mainz, Germany
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -939,9 +939,8 @@ numeric S_num(int n, int p, const numeric& x)
        else if (!x.imag().is_rational())
                prec = cln::float_format(cln::the<cln::cl_F>(cln::imagpart(value)));
 
-
        // [Kol] (5.3)
-       if (cln::realpart(value) < -0.5) {
+       if ((cln::realpart(value) < -0.5) || (n == 0)) {
 
                cln::cl_N result = cln::expt(cln::cl_I(-1),p) * cln::expt(cln::log(value),n)
                                   * cln::expt(cln::log(1-value),p) / cln::factorial(n) / cln::factorial(p);
@@ -1029,6 +1028,10 @@ static ex S_eval(const ex& n, const ex& p, const ex& x)
                        return S_num(ex_to<numeric>(n).to_int(), ex_to<numeric>(p).to_int(), ex_to<numeric>(x));
                }
        }
+       if (n.is_zero()) {
+               // [Kol] (5.3)
+               return pow(-log(1-x), p) / factorial(p);
+       }
        return S(n, p, x).hold();
 }
 
@@ -1088,6 +1091,10 @@ REGISTER_FUNCTION(S,
 // anonymous namespace for helper functions
 namespace {
 
+       
+// regulates the pole (used by 1/x-transformation)
+symbol H_polesign("IMSIGN");
+
 
 // convert parameters from H to Li representation
 // parameters are expected to be in expanded form, i.e. only 0, 1 and -1
@@ -1601,7 +1608,7 @@ struct map_trafo_H_1overx : public map_function
                                        }
                                        if (allthesame) {
                                                map_trafo_H_mult unify;
-                                               return unify((pow(H(lst(1),1/arg).hold() + H(lst(0),1/arg).hold() - I*Pi, parameter.nops())
+                                               return unify((pow(H(lst(1),1/arg).hold() + H(lst(0),1/arg).hold() + H_polesign, parameter.nops())
                                                       / factorial(parameter.nops())).expand());
                                        }
                                }
@@ -1928,6 +1935,11 @@ static ex H_evalf(const ex& x1, const ex& x2)
                        // x -> 1/x
                        map_trafo_H_1overx trafo;
                        res *= trafo(H(m, xtemp));
+                       if (cln::imagpart(x) <= 0) {
+                               res = res.subs(H_polesign == -I*Pi);
+                       } else {
+                               res = res.subs(H_polesign == I*Pi);
+                       }
                }
 
                // simplify result
@@ -2033,25 +2045,25 @@ static ex H_eval(const ex& m_, const ex& x)
        if ((x == _ex1) && (*(--m.end()) != _ex0)) {
                return convert_H_to_zeta(m);
        }
-//     if (step == 0) {
-//             if (pos1 == _ex0) {
-//                     // all zero
-//                     if (x == _ex0) {
-//                             return H(m_, x).hold();
-//                     }
-//                     return pow(log(x), m.nops()) / factorial(m.nops());
-//             } else {
-//                     // all (minus) one
-//                     return pow(-pos1*log(1-pos1*x), m.nops()) / factorial(m.nops());
-//             }
-//     } else if ((step == 1) && (pos1 == _ex0)){
-//             // convertible to S
-//             if (pos2 == _ex1) {
-//                     return S(n, p, x);
-//             } else {
-//                     return pow(-1, p) * S(n, p, -x);
-//             }
-//     }
+       if (step == 0) {
+               if (pos1 == _ex0) {
+                       // all zero
+                       if (x == _ex0) {
+                               return H(m_, x).hold();
+                       }
+                       return pow(log(x), m.nops()) / factorial(m.nops());
+               } else {
+                       // all (minus) one
+                       return pow(-pos1*log(1-pos1*x), m.nops()) / factorial(m.nops());
+               }
+       } else if ((step == 1) && (pos1 == _ex0)){
+               // convertible to S
+               if (pos2 == _ex1) {
+                       return S(n, p, x);
+               } else {
+                       return pow(-1, p) * S(n, p, -x);
+               }
+       }
        if (x == _ex0) {
                return _ex0;
        }