]> www.ginac.de Git - ginac.git/blob - ginac/inifcns_zeta.cpp
- Run automake again on squark, as we had agreed earlier.
[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 #ifndef NO_GINAC_NAMESPACE
34 namespace GiNaC {
35 #endif // ndef NO_GINAC_NAMESPACE
36
37 //////////
38 // Riemann's Zeta-function
39 //////////
40
41 static ex zeta1_evalf(ex const & x)
42 {
43     BEGIN_TYPECHECK
44         TYPECHECK(x,numeric)
45     END_TYPECHECK(zeta(x))
46         
47     return zeta(ex_to_numeric(x));
48 }
49
50 static ex zeta1_eval(ex const & x)
51 {
52     if (x.info(info_flags::numeric)) {
53         numeric y = ex_to_numeric(x);
54         // trap integer arguments:
55         if (y.is_integer()) {
56             if (y.is_zero())
57                 return -exHALF();
58             if (x.is_equal(exONE()))
59                 throw(std::domain_error("zeta(1): infinity"));
60             if (x.info(info_flags::posint)) {
61                 if (x.info(info_flags::odd))
62                     return zeta(x).hold();
63                 else
64                     return abs(bernoulli(y))*pow(Pi,x)*numTWO().power(y-numONE())/factorial(y);
65             } else {
66                 if (x.info(info_flags::odd))
67                     return -bernoulli(numONE()-y)/(numONE()-y);
68                 else
69                     return numZERO();
70             }
71         }
72     }
73     return zeta(x).hold();
74 }
75
76 static ex zeta1_diff(ex const & x, unsigned diff_param)
77 {
78     GINAC_ASSERT(diff_param==0);
79     
80     return zeta(exONE(), x);
81 }
82
83 const unsigned function_index_zeta1 = function::register_new("zeta", zeta1_eval, zeta1_evalf, zeta1_diff, NULL);
84
85 //////////
86 // Derivatives of Riemann's Zeta-function  zeta(0,x)==zeta(x)
87 //////////
88
89 static ex zeta2_eval(ex const & n, ex const & x)
90 {
91     if (n.info(info_flags::numeric)) {
92         // zeta(0,x) -> zeta(x)
93         if (n.is_zero())
94             return zeta(x);
95     }
96     
97     return zeta(n, x).hold();
98 }
99
100 static ex zeta2_diff(ex const & n, ex const & x, unsigned diff_param)
101 {
102     GINAC_ASSERT(diff_param<2);
103     
104     if (diff_param==0) {
105         // d/dn zeta(n,x)
106         throw(std::logic_error("cannot diff zeta(n,x) with respect to n"));
107     }
108     // d/dx psi(n,x)
109     return zeta(n+1,x);
110 }
111
112 const unsigned function_index_zeta2 = function::register_new("zeta", zeta2_eval, NULL, zeta2_diff, NULL);
113
114 #ifndef NO_GINAC_NAMESPACE
115 } // namespace GiNaC
116 #endif // ndef NO_GINAC_NAMESPACE