]> www.ginac.de Git - ginac.git/blobdiff - ginac/inifcns_zeta.cpp
#ifndef around namespace GiNaC { }
[ginac.git] / ginac / inifcns_zeta.cpp
index d4890f2863c28205e64931f50e7f2b5074f8239d..c2a298a9aaf1661dedf2ce2245677e4982574d4e 100644 (file)
@@ -30,7 +30,9 @@
 #include "power.h"
 #include "symbol.h"
 
+#ifndef NO_GINAC_NAMESPACE
 namespace GiNaC {
+#endif // ndef NO_GINAC_NAMESPACE
 
 //////////
 // Riemann's Zeta-function
@@ -39,18 +41,29 @@ namespace GiNaC {
 static ex zeta_eval(ex const & x)
 {
     if (x.info(info_flags::numeric)) {
+        numeric y = ex_to_numeric(x);
         // trap integer arguments:
-        if ( x.info(info_flags::integer) ) {
-            if ( x.info(info_flags::posint) ) {
-                return numZERO();  // FIXME
+        if (y.is_integer()) {
+            if (y.is_zero())
+                return -exHALF();
+            if (x.is_equal(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 abs(bernoulli(y))*pow(Pi,x)*numTWO().power(y-numONE())/factorial(y);
             } else {
-                return numZERO();  // FIXME
+                if (x.info(info_flags::odd))
+                    return -bernoulli(numONE()-y)/(numONE()-y);
+                else
+                    return numZERO();
             }
         }
     }
     return zeta(x).hold();
-}    
-    
+}
+
 static ex zeta_evalf(ex const & x)
 {
     BEGIN_TYPECHECK
@@ -62,7 +75,7 @@ static ex zeta_evalf(ex const & x)
 
 static ex zeta_diff(ex const & x, unsigned diff_param)
 {
-    ASSERT(diff_param==0);
+    GINAC_ASSERT(diff_param==0);
     
     return exZERO();  // should return zeta(numONE(),x);
 }
@@ -74,4 +87,6 @@ static ex zeta_series(ex const & x, symbol const & s, ex const & point, int orde
 
 REGISTER_FUNCTION(zeta, zeta_eval, zeta_evalf, zeta_diff, zeta_series);
 
+#ifndef NO_GINAC_NAMESPACE
 } // namespace GiNaC
+#endif // ndef NO_GINAC_NAMESPACE