]> www.ginac.de Git - ginac.git/blob - ginac/inifcns_zeta.cpp
- One more hyperclever example and two more fixed from Alex' list.
[ginac.git] / ginac / inifcns_zeta.cpp
1 /** @file inifcns_zeta.cpp
2  *
3  *  Implementation of the Zeta-function and some related stuff. */
4
5 /*
6  *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
7  *
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.
12  *
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.
17  *
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
21  */
22
23 #include <vector>
24 #include <stdexcept>
25
26 #include "inifcns.h"
27 #include "ex.h"
28 #include "constant.h"
29 #include "numeric.h"
30 #include "power.h"
31 #include "symbol.h"
32
33 namespace GiNaC {
34
35 //////////
36 // Riemann's Zeta-function
37 //////////
38
39 static ex zeta_eval(ex const & x)
40 {
41     if (x.info(info_flags::numeric)) {
42         // trap integer arguments:
43         if (x.info(info_flags::integer)) {
44             if (x.is_zero())
45                 return -exHALF();
46             if (!x.compare(exONE()))
47                 throw(std::domain_error("zeta(1): infinity"));
48             if (x.info(info_flags::posint)) {
49                 if (x.info(info_flags::odd))
50                     return zeta(x).hold();
51                 else
52                     // return bernoulli(ex_to_numeric(x))*pow(Pi,x)*numTWO().power(ex_to_numeric(x))/factorial(x);
53                     throw (std::domain_error("you found a missing feature"));
54             } else {
55                 if (x.info(info_flags::odd))
56                     // return -bernoulli(1-ex_to_numeric(x))/(1-ex_to_numeric(x))
57                     throw (std::domain_error("you found a missing feature"));
58                 else 
59                     return numZERO();
60             }
61         }
62     }
63     return zeta(x).hold();
64 }
65     
66 static ex zeta_evalf(ex const & x)
67 {
68     BEGIN_TYPECHECK
69         TYPECHECK(x,numeric)
70     END_TYPECHECK(zeta(x))
71     
72     return zeta(ex_to_numeric(x));
73 }
74
75 static ex zeta_diff(ex const & x, unsigned diff_param)
76 {
77     ASSERT(diff_param==0);
78     
79     return exZERO();  // should return zeta(numONE(),x);
80 }
81
82 static ex zeta_series(ex const & x, symbol const & s, ex const & point, int order)
83 {
84     throw(std::logic_error("don't know the series expansion of the zeta function"));
85 }
86
87 REGISTER_FUNCTION(zeta, zeta_eval, zeta_evalf, zeta_diff, zeta_series);
88
89 } // namespace GiNaC