]> www.ginac.de Git - ginac.git/blobdiff - ginac/inifcns_gamma.cpp
- changed function::diff() to be more tolerant by checking first if the
[ginac.git] / ginac / inifcns_gamma.cpp
index bb3a74e0c0a24566bf52fe1ee88d5687bd2f11f7..a208592f82eab47de23bcfde1d83aeaea4095297 100644 (file)
@@ -46,19 +46,19 @@ static ex gamma_eval(ex const & x)
 {
     if (x.info(info_flags::numeric)) {
         // trap integer arguments:
-        if ( x.info(info_flags::integer) ) {
+        if (x.info(info_flags::integer)) {
             // gamma(n+1) -> n! for postitive n
-            if ( x.info(info_flags::posint) ) {
+            if (x.info(info_flags::posint)) {
                 return factorial(ex_to_numeric(x).sub(numONE()));
             } else {
                 return numZERO();  // Infinity. Throw? What?
             }
         }
         // trap half integer arguments:
-        if ( (x*2).info(info_flags::integer) ) {
+        if ((x*2).info(info_flags::integer)) {
             // trap positive x=(n+1/2)
             // gamma(n+1/2) -> Pi^(1/2)*(1*3*..*(2*n-1))/(2^n)
-            if ( (x*2).info(info_flags::posint) ) {
+            if ((x*2).info(info_flags::posint)) {
                 numeric n = ex_to_numeric(x).sub(numHALF());
                 numeric coefficient = doublefactorial(n.mul(numTWO()).sub(numONE()));
                 coefficient = coefficient.div(numTWO().power(n));
@@ -75,7 +75,7 @@ static ex gamma_eval(ex const & x)
     }
     return gamma(x).hold();
 }    
-    
+
 static ex gamma_evalf(ex const & x)
 {
     BEGIN_TYPECHECK
@@ -89,7 +89,7 @@ static ex gamma_diff(ex const & x, unsigned diff_param)
 {
     GINAC_ASSERT(diff_param==0);
     
-    return psi(exZERO(),x)*gamma(x);  // diff(log(gamma(x)),x)==psi(0,x)
+    return psi(x)*gamma(x);  // diff(log(gamma(x)),x)==psi(x)
 }
 
 static ex gamma_series(ex const & x, symbol const & s, ex const & point, int order)
@@ -108,17 +108,57 @@ REGISTER_FUNCTION(gamma, gamma_eval, gamma_evalf, gamma_diff, gamma_series);
 // Psi-function (aka polygamma-function)
 //////////
 
+/** Evaluation of polygamma-function psi(x). 
+ *  Somebody ought to provide some good numerical evaluation some day... */
+static ex psi1_eval(ex const & x)
+{
+    if (x.info(info_flags::numeric)) {
+        // do some stuff...
+    }
+    return psi(x).hold();
+}    
+
+static ex psi1_evalf(ex const & x)
+{
+    BEGIN_TYPECHECK
+        TYPECHECK(x,numeric)
+    END_TYPECHECK(psi(x))
+    
+    return psi(ex_to_numeric(x));
+}
+
+static ex psi1_diff(ex const & x, unsigned diff_param)
+{
+    GINAC_ASSERT(diff_param==0);
+    
+    return psi(exONE(), x);
+}
+
+static ex psi1_series(ex const & x, symbol const & s, ex const & point, int order)
+{
+    throw(std::logic_error("Nobody told me how to series expand the psi function. :-("));
+}
+
+unsigned function_index_psi1 = function::register_new("psi", psi1_eval, psi1_evalf, psi1_diff, psi1_series);
+
+//////////
+// Psi-functions (aka polygamma-functions)  psi(0,x)==psi(x)
+//////////
+
 /** Evaluation of polygamma-function psi(n,x). 
  *  Somebody ought to provide some good numerical evaluation some day... */
-static ex psi_eval(ex const & n, ex const & x)
+static ex psi2_eval(ex const & n, ex const & x)
 {
+    // psi(0,x) -> psi(x)
+    if (n.is_zero())
+        return psi(x).hold();
     if (n.info(info_flags::numeric) && x.info(info_flags::numeric)) {
         // do some stuff...
     }
     return psi(n, x).hold();
 }    
-    
-static ex psi_evalf(ex const & n, ex const & x)
+
+static ex psi2_evalf(ex const & n, ex const & x)
 {
     BEGIN_TYPECHECK
         TYPECHECK(n,numeric)
@@ -128,18 +168,23 @@ static ex psi_evalf(ex const & n, ex const & x)
     return psi(ex_to_numeric(n), ex_to_numeric(x));
 }
 
-static ex psi_diff(ex const & n, ex const & x, unsigned diff_param)
+static ex psi2_diff(ex const & n, ex const & x, unsigned diff_param)
 {
-    GINAC_ASSERT(diff_param==0);
+    GINAC_ASSERT(diff_param<2);
     
+    if (diff_param==0) {
+        // d/dn psi(n,x)
+        throw(std::logic_error("cannot diff psi(n,x) with respect to n"));
+    }
+    // d/dx psi(n,x)
     return psi(n+1, x);
 }
 
-static ex psi_series(ex const & n, ex const & x, symbol const & s, ex const & point, int order)
+static ex psi2_series(ex const & n, ex const & x, symbol const & s, ex const & point, int order)
 {
-    throw(std::logic_error("Nobody told me how to series expand the psi function. :-("));
+    throw(std::logic_error("Nobody told me how to series expand the psi functions. :-("));
 }
 
-REGISTER_FUNCTION(psi, psi_eval, psi_evalf, psi_diff, psi_series);
+unsigned function_index_psi2 = function::register_new("psi", psi2_eval, psi2_evalf, psi2_diff, psi2_series);
 
 } // namespace GiNaC