X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?a=blobdiff_plain;f=ginac%2Finifcns_zeta.cpp;h=4be6f0226cae4f35f983c89f071a8f5afd1414a9;hb=d11acf2982b74cca5c0f4dc58c72832530957cd9;hp=e343b6fbe2692dc6c2eb92953309b65c0e2ec081;hpb=d8148ca72f0e9c5f39b7142a87f004a7a5840d69;p=ginac.git diff --git a/ginac/inifcns_zeta.cpp b/ginac/inifcns_zeta.cpp index e343b6fb..4be6f022 100644 --- a/ginac/inifcns_zeta.cpp +++ b/ginac/inifcns_zeta.cpp @@ -3,7 +3,7 @@ * Implementation of the Zeta-function and some related stuff. */ /* - * GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2000 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 @@ -29,6 +29,7 @@ #include "numeric.h" #include "power.h" #include "symbol.h" +#include "utils.h" #ifndef NO_GINAC_NAMESPACE namespace GiNaC { @@ -38,42 +39,78 @@ namespace GiNaC { // Riemann's Zeta-function ////////// -static ex zeta_eval(ex const & x) +static ex zeta1_evalf(const ex & x) +{ + BEGIN_TYPECHECK + TYPECHECK(x,numeric) + END_TYPECHECK(zeta(x)) + + return zeta(ex_to_numeric(x)); +} + +static ex zeta1_eval(const ex & x) { if (x.info(info_flags::numeric)) { numeric y = ex_to_numeric(x); // trap integer arguments: if (y.is_integer()) { if (y.is_zero()) - return -exHALF(); - if (x.is_equal(exONE())) + return -_ex1_2(); + if (x.is_equal(_ex1())) throw(std::domain_error("zeta(1): infinity")); if (x.info(info_flags::posint)) { if (x.info(info_flags::odd)) return zeta(x).hold(); else - return abs(bernoulli(y))*pow(Pi,x)*numTWO().power(y-numONE())/factorial(y); + return abs(bernoulli(y))*pow(Pi,x)*pow(_num2(),y-_num1())/factorial(y); } else { if (x.info(info_flags::odd)) - return -bernoulli(numONE()-y)/(numONE()-y); + return -bernoulli(_num1()-y)/(_num1()-y); else - return numZERO(); + return _num0(); } } } return zeta(x).hold(); } -static ex zeta_evalf(ex const & x) +static ex zeta1_diff(const ex & x, unsigned diff_param) { - BEGIN_TYPECHECK - TYPECHECK(x,numeric) - END_TYPECHECK(zeta(x)) + GINAC_ASSERT(diff_param==0); - return zeta(ex_to_numeric(x)); + return zeta(_ex1(), x); +} + +const unsigned function_index_zeta1 = function::register_new("zeta", zeta1_eval, zeta1_evalf, zeta1_diff, NULL); + +////////// +// Derivatives of Riemann's Zeta-function zeta(0,x)==zeta(x) +////////// + +static ex zeta2_eval(const ex & n, const ex & x) +{ + if (n.info(info_flags::numeric)) { + // zeta(0,x) -> zeta(x) + if (n.is_zero()) + return zeta(x); + } + + return zeta(n, x).hold(); +} + +static ex zeta2_diff(const ex & n, const ex & x, unsigned diff_param) +{ + GINAC_ASSERT(diff_param<2); + + if (diff_param==0) { + // d/dn zeta(n,x) + throw(std::logic_error("cannot diff zeta(n,x) with respect to n")); + } + // d/dx psi(n,x) + return zeta(n+1,x); } -REGISTER_FUNCTION(zeta, zeta_eval, zeta_evalf, NULL, NULL); +const unsigned function_index_zeta2 = function::register_new("zeta", zeta2_eval, NULL, zeta2_diff, NULL); #ifndef NO_GINAC_NAMESPACE } // namespace GiNaC