+static ex psi2_series(ex const & n, ex const & x, symbol const & s, ex const & point, int order)
+{
+ // method:
+ // Taylor series where there is no pole falls back to polygamma function
+ // evaluation.
+ // On a pole at -m use the recurrence relation
+ // psi(n,x) == psi(n,x+1) - (-)^n * n! / z^(n+1)
+ // from which follows
+ // series(psi(x),x,-m,order) ==
+ // series(psi(x+m+1) - (-1)^n * n!
+ // * ((x)^(-n-1) + (x+1)^(-n-1) + (x+m)^(-n-1))),x,-m,order);
+ ex xpoint = x.subs(s==point);
+ if (!xpoint.info(info_flags::integer) || xpoint.info(info_flags::positive))
+ throw do_taylor(); // caught by function::series()
+ // if we got here we have to care for a pole of order n+1 at -m:
+ numeric m = -ex_to_numeric(xpoint);
+ ex recur;
+ for (numeric p; p<=m; ++p)
+ recur += power(x+p,-n+_ex_1());
+ recur *= factorial(n)*power(_ex_1(),n);
+ return (psi(n, x+m+_ex1())-recur).series(s, point, order);
+}
+
+const unsigned function_index_psi2 = function::register_new("psi", psi2_eval, psi2_evalf, psi2_diff, psi2_series);