X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Finifcns_zeta.cpp;h=287059835180a06dea6a2763b5d77ae11074cda3;hp=8dbe5d2da58da0e7f263859acf3b3e087c3ec0fc;hb=abc868b70eea6e434130c4d8d9916ae8f55db370;hpb=fc86859d22eb864d43e9b2446d7077836acbe6b4 diff --git a/ginac/inifcns_zeta.cpp b/ginac/inifcns_zeta.cpp index 8dbe5d2d..28705983 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-2001 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 @@ -24,11 +24,11 @@ #include #include "inifcns.h" -#include "ex.h" #include "constant.h" #include "numeric.h" #include "power.h" #include "symbol.h" +#include "utils.h" namespace GiNaC { @@ -36,54 +36,93 @@ namespace GiNaC { // Riemann's Zeta-function ////////// -static ex zeta_eval(ex const & x) +static ex zeta1_evalf(const ex & x) { - if (x.info(info_flags::numeric)) { - // trap integer arguments: - if (x.info(info_flags::integer)) { - if (x.is_zero()) - return -exHALF(); - if (!x.compare(exONE())) - 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 bernoulli(ex_to_numeric(x))*pow(Pi,x)*numTWO().power(ex_to_numeric(x))/factorial(x); - throw (std::domain_error("you found a missing feature")); - } else { - if (x.info(info_flags::odd)) - // return -bernoulli(1-ex_to_numeric(x))/(1-ex_to_numeric(x)) - throw (std::domain_error("you found a missing feature")); - else - return numZERO(); - } - } - } - return zeta(x).hold(); + if (is_exactly_a(x)) { + try { + return zeta(ex_to(x)); + } catch (const dunno &e) { } + } + + return zeta(x).hold(); } - -static ex zeta_evalf(ex const & x) + +static ex zeta1_eval(const ex & x) +{ + if (x.info(info_flags::numeric)) { + numeric y = ex_to(x); + // trap integer arguments: + if (y.is_integer()) { + if (y.is_zero()) + return _ex_1_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)*pow(_num2,y-_num1)/factorial(y); + } else { + if (x.info(info_flags::odd)) + return -bernoulli(_num1-y)/(_num1-y); + else + return _num0; + } + } + // zeta(float) + if (x.info(info_flags::numeric) && !x.info(info_flags::crational)) + return zeta1_evalf(x); + } + return zeta(x).hold(); +} + +static ex zeta1_deriv(const ex & x, unsigned deriv_param) { - BEGIN_TYPECHECK - TYPECHECK(x,numeric) - END_TYPECHECK(zeta(x)) - - return zeta(ex_to_numeric(x)); + GINAC_ASSERT(deriv_param==0); + + return zeta(_ex1, x); } -static ex zeta_diff(ex const & x, unsigned diff_param) +const unsigned function_index_zeta1 = + function::register_new(function_options("zeta"). + eval_func(zeta1_eval). + evalf_func(zeta1_evalf). + derivative_func(zeta1_deriv). + latex_name("\\zeta"). + overloaded(2)); + +////////// +// Derivatives of Riemann's Zeta-function zeta(0,x)==zeta(x) +////////// + +static ex zeta2_eval(const ex & n, const ex & x) { - ASSERT(diff_param==0); - - return exZERO(); // should return zeta(numONE(),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 zeta_series(ex const & x, symbol const & s, ex const & point, int order) +static ex zeta2_deriv(const ex & n, const ex & x, unsigned deriv_param) { - throw(std::logic_error("don't know the series expansion of the zeta function")); + GINAC_ASSERT(deriv_param<2); + + if (deriv_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, zeta_diff, zeta_series); +const unsigned function_index_zeta2 = + function::register_new(function_options("zeta"). + eval_func(zeta2_eval). + derivative_func(zeta2_deriv). + latex_name("\\zeta"). + overloaded(2)); } // namespace GiNaC