From: Richard Kreckel Date: Wed, 22 Dec 1999 17:51:32 +0000 (+0000) Subject: - polygamma functions (psi functions) know about half-integer arguments X-Git-Tag: release_0-5-0~80 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=fe065a48f215ef391284f3448ba2e7f81e6c0596 - polygamma functions (psi functions) know about half-integer arguments now, which is more than Mathematica's PolyGamma[n,x] provides. :-) --- diff --git a/ginac/inifcns_gamma.cpp b/ginac/inifcns_gamma.cpp index dbe8840a..bcf2539f 100644 --- a/ginac/inifcns_gamma.cpp +++ b/ginac/inifcns_gamma.cpp @@ -86,7 +86,9 @@ static ex gamma_eval(const ex & x) return coefficient*power(Pi,_ex1_2()); } } + // gamma_evalf should be called here once it becomes available } + return gamma(x).hold(); } @@ -204,13 +206,7 @@ static ex beta_series(const ex & x, const ex & y, const symbol & s, const ex & p (!ypoint.info(info_flags::integer) || ypoint.info(info_flags::positive))) throw do_taylor(); // caught by function::series() // if we got here we have to care for a simple pole at -m: - throw (std::domain_error("beta_series(): please code me")); - /*numeric m = -ex_to_numeric(xpoint); - *ex ser_numer = gamma(x+m+_ex1()); - *ex ser_denom = _ex1(); - *for (numeric p; p<=m; ++p) - * ser_denom *= x+p; - *return (ser_numer/ser_denom).series(s, point, order+1);*/ + throw (std::domain_error("beta_series(): Mama, please code me!")); } REGISTER_FUNCTION(beta, beta_eval, beta_evalf, beta_diff, beta_series); @@ -233,28 +229,43 @@ static ex psi1_evalf(const ex & x) static ex psi1_eval(const ex & x) { if (x.info(info_flags::numeric)) { - if (x.info(info_flags::integer) && !x.info(info_flags::positive)) - throw (std::domain_error("psi_eval(): simple pole")); - if (x.info(info_flags::positive)) { - // psi(n) -> 1 + 1/2 +...+ 1/(n-1) - EulerGamma - if (x.info(info_flags::integer)) { + numeric nx = ex_to_numeric(x); + if (nx.is_integer()) { + // integer case + if (nx.is_positive()) { + // psi(n) -> 1 + 1/2 +...+ 1/(n-1) - EulerGamma numeric rat(0); - for (numeric i(ex_to_numeric(x)-_num1()); i.is_positive(); --i) + for (numeric i(nx+_num_1()); i.is_positive(); --i) rat += i.inverse(); return rat-EulerGamma; + } else { + // for non-positive integers there is a pole: + throw (std::domain_error("psi_eval(): simple pole")); } - // psi((2m+1)/2) -> 2/(2m+1) + 2/2m +...+ 2/1 - EulerGamma - 2log(2) - if ((_ex2()*x).info(info_flags::integer)) { + } + if ((_num2()*nx).is_integer()) { + // half integer case + if (nx.is_positive()) { + // psi((2m+1)/2) -> 2/(2m+1) + 2/2m +...+ 2/1 - EulerGamma - 2log(2) numeric rat(0); - for (numeric i((ex_to_numeric(x)-_num1())*_num2()); i.is_positive(); i-=_num2()) - rat += _num2()*i.inverse(); - return rat-EulerGamma-_ex2()*log(_ex2()); - } - if (x.compare(_ex1())==1) { - // should call numeric, since >1 + for (numeric i((nx+_num_1())*_num2()); i.is_positive(); i-=_num2()) + rat += _num2()*i.inverse(); + return rat-EulerGamma-_ex2()*log(_ex2()); + } else { + // use the recurrence relation + // psi(-m-1/2) == psi(-m-1/2+1) - 1 / (-m-1/2) + // to relate psi(-m-1/2) to psi(1/2): + // psi(-m-1/2) == psi(1/2) + r + // where r == ((-1/2)^(-1) + ... + (-m-1/2)^(-1)) + numeric recur(0); + for (numeric p(nx); p<0; ++p) + recur -= pow(p, _num_1()); + return recur+psi(_ex1_2()); } } + // psi1_evalf should be called here once it becomes available } + return psi(x).hold(); } @@ -318,24 +329,53 @@ static ex psi2_eval(const ex & n, const ex & x) numeric nn = ex_to_numeric(n); numeric nx = ex_to_numeric(x); if (nx.is_integer()) { + // integer case if (nx.is_equal(_num1())) - return pow(_num_1(), nn+_num1())*factorial(nn)*zeta(ex(nn+_num1())); + // use psi(n,1) == (-)^(n+1) * n! * zeta(n+1) + return pow(_num_1(),nn+_num1())*factorial(nn)*zeta(ex(nn+_num1())); if (nx.is_positive()) { // use the recurrence relation // psi(n,m) == psi(n,m+1) - (-)^n * n! / m^(n+1) // to relate psi(n,m) to psi(n,1): // psi(n,m) == psi(n,1) + r // where r == (-)^n * n! * (1^(-n-1) + ... + (m-1)^(-n-1)) - numeric recur; + numeric recur(0); for (numeric p(1); p