1 /** @file inifcns_zeta.cpp
3 * Implementation of the Zeta-function and some related stuff. */
6 * GiNaC Copyright (C) 1999-2002 Johannes Gutenberg University Mainz, Germany
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36 // Riemann's Zeta-function
39 static ex zeta1_evalf(const ex & x)
41 if (is_exactly_a<numeric>(x)) {
43 return zeta(ex_to<numeric>(x));
44 } catch (const dunno &e) { }
47 return zeta(x).hold();
50 static ex zeta1_eval(const ex & x)
52 if (x.info(info_flags::numeric)) {
53 const numeric &y = ex_to<numeric>(x);
54 // trap integer arguments:
58 if (y.is_equal(_num1))
59 throw(std::domain_error("zeta(1): infinity"));
60 if (y.info(info_flags::posint)) {
61 if (y.info(info_flags::odd))
62 return zeta(x).hold();
64 return abs(bernoulli(y))*pow(Pi,y)*pow(_num2,y-_num1)/factorial(y);
66 if (y.info(info_flags::odd))
67 return -bernoulli(_num1-y)/(_num1-y);
73 if (y.info(info_flags::numeric) && !y.info(info_flags::crational))
74 return zeta1_evalf(x);
76 return zeta(x).hold();
79 static ex zeta1_deriv(const ex & x, unsigned deriv_param)
81 GINAC_ASSERT(deriv_param==0);
86 const unsigned function_index_zeta1 =
87 function::register_new(function_options("zeta").
88 eval_func(zeta1_eval).
89 evalf_func(zeta1_evalf).
90 derivative_func(zeta1_deriv).
95 // Derivatives of Riemann's Zeta-function zeta(0,x)==zeta(x)
98 static ex zeta2_eval(const ex & n, const ex & x)
100 if (n.info(info_flags::numeric)) {
101 // zeta(0,x) -> zeta(x)
106 return zeta(n, x).hold();
109 static ex zeta2_deriv(const ex & n, const ex & x, unsigned deriv_param)
111 GINAC_ASSERT(deriv_param<2);
113 if (deriv_param==0) {
115 throw(std::logic_error("cannot diff zeta(n,x) with respect to n"));
121 const unsigned function_index_zeta2 =
122 function::register_new(function_options("zeta").
123 eval_func(zeta2_eval).
124 derivative_func(zeta2_deriv).
125 latex_name("\\zeta").