]> www.ginac.de Git - ginac.git/blobdiff - ginac/inifcns_zeta.cpp
* Oops, forgot to cvs add the two new files in last commit.
[ginac.git] / ginac / inifcns_zeta.cpp
index 0f069089b2785f6890da63113066a11ce53504f6..365f35e22aeb9501541b8fb559a9d44168d171c0 100644 (file)
@@ -3,7 +3,7 @@
  *  Implementation of the Zeta-function and some related stuff. */
 
 /*
- *  GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2003 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
@@ -28,6 +28,7 @@
 #include "numeric.h"
 #include "power.h"
 #include "symbol.h"
+#include "operators.h"
 #include "utils.h"
 
 namespace GiNaC {
@@ -38,35 +39,40 @@ namespace GiNaC {
 
 static ex zeta1_evalf(const ex & x)
 {
-       BEGIN_TYPECHECK
-               TYPECHECK(x,numeric)
-       END_TYPECHECK(zeta(x))
-               
-       return zeta(ex_to_numeric(x));
+       if (is_exactly_a<numeric>(x)) {
+               try {
+                       return zeta(ex_to<numeric>(x));
+               } catch (const dunno &e) { }
+       }
+       
+       return zeta(x).hold();
 }
 
 static ex zeta1_eval(const ex & x)
 {
        if (x.info(info_flags::numeric)) {
-               numeric y = ex_to_numeric(x);
+               const numeric &y = ex_to<numeric>(x);
                // trap integer arguments:
                if (y.is_integer()) {
                        if (y.is_zero())
-                               return -_ex1_2();
-                       if (x.is_equal(_ex1()))
+                               return _ex_1_2;
+                       if (y.is_equal(_num1))
                                throw(std::domain_error("zeta(1): infinity"));
-                       if (x.info(info_flags::posint)) {
-                               if (x.info(info_flags::odd))
+                       if (y.info(info_flags::posint)) {
+                               if (y.info(info_flags::odd))
                                        return zeta(x).hold();
                                else
-                                       return abs(bernoulli(y))*pow(Pi,x)*pow(_num2(),y-_num1())/factorial(y);
+                                       return abs(bernoulli(y))*pow(Pi,y)*pow(_num2,y-_num1)/factorial(y);
                        } else {
-                               if (x.info(info_flags::odd))
-                                       return -bernoulli(_num1()-y)/(_num1()-y);
+                               if (y.info(info_flags::odd))
+                                       return -bernoulli(_num1-y)/(_num1-y);
                                else
-                                       return _num0();
+                                       return _ex0;
                        }
                }
+               // zeta(float)
+               if (y.info(info_flags::numeric) && !y.info(info_flags::crational))
+                       return zeta1_evalf(x);
        }
        return zeta(x).hold();
 }
@@ -75,14 +81,15 @@ static ex zeta1_deriv(const ex & x, unsigned deriv_param)
 {
        GINAC_ASSERT(deriv_param==0);
        
-       return zeta(_ex1(), x);
+       return zeta(_ex1, x);
 }
 
-const unsigned function_index_zeta1 =
+unsigned zeta1_SERIAL::serial =
        function::register_new(function_options("zeta").
                               eval_func(zeta1_eval).
                               evalf_func(zeta1_evalf).
                               derivative_func(zeta1_deriv).
+                              latex_name("\\zeta").
                               overloaded(2));
 
 //////////
@@ -112,10 +119,11 @@ static ex zeta2_deriv(const ex & n, const ex & x, unsigned deriv_param)
        return zeta(n+1,x);
 }
 
-const unsigned function_index_zeta2 =
+unsigned zeta2_SERIAL::serial =
        function::register_new(function_options("zeta").
                               eval_func(zeta2_eval).
                               derivative_func(zeta2_deriv).
+                              latex_name("\\zeta").
                               overloaded(2));
 
 } // namespace GiNaC