]> www.ginac.de Git - ginac.git/blobdiff - ginac/inifcns_trans.cpp
#ifndef around namespace GiNaC { }
[ginac.git] / ginac / inifcns_trans.cpp
index c67d8330758aa3ca78e59ece6deda3bbcc9d2630..01711a7fa3c9aae70cc9afc536ab651a157d2d34 100644 (file)
@@ -3,16 +3,42 @@
  *  Implementation of transcendental (and trigonometric and hyperbolic)
  *  functions. */
 
+/*
+ *  GiNaC Copyright (C) 1999 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
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
 #include <vector>
 #include <stdexcept>
 
-#include "ginac.h"
+#include "inifcns.h"
+#include "ex.h"
+#include "constant.h"
+#include "numeric.h"
+#include "power.h"
+
+#ifndef NO_GINAC_NAMESPACE
+namespace GiNaC {
+#endif // ndef NO_GINAC_NAMESPACE
 
 //////////
 // exponential function
 //////////
 
-ex exp_evalf(ex const & x)
+static ex exp_evalf(ex const & x)
 {
     BEGIN_TYPECHECK
         TYPECHECK(x,numeric)
@@ -21,7 +47,7 @@ ex exp_evalf(ex const & x)
     return exp(ex_to_numeric(x)); // -> numeric exp(numeric)
 }
 
-ex exp_eval(ex const & x)
+static ex exp_eval(ex const & x)
 {
     // exp(0) -> 1
     if (x.is_zero()) {
@@ -51,9 +77,9 @@ ex exp_eval(ex const & x)
     return exp(x).hold();
 }    
 
-ex exp_diff(ex const & x, unsigned diff_param)
+static ex exp_diff(ex const & x, unsigned diff_param)
 {
-    ASSERT(diff_param==0);
+    GINAC_ASSERT(diff_param==0);
 
     return exp(x);
 }
@@ -64,7 +90,7 @@ REGISTER_FUNCTION(exp, exp_eval, exp_evalf, exp_diff, NULL);
 // natural logarithm
 //////////
 
-ex log_evalf(ex const & x)
+static ex log_evalf(ex const & x)
 {
     BEGIN_TYPECHECK
         TYPECHECK(x,numeric)
@@ -73,7 +99,7 @@ ex log_evalf(ex const & x)
     return log(ex_to_numeric(x)); // -> numeric log(numeric)
 }
 
-ex log_eval(ex const & x)
+static ex log_eval(ex const & x)
 {
     if (x.info(info_flags::numeric)) {
         // log(1) -> 0
@@ -99,9 +125,9 @@ ex log_eval(ex const & x)
     return log(x).hold();
 }    
 
-ex log_diff(ex const & x, unsigned diff_param)
+static ex log_diff(ex const & x, unsigned diff_param)
 {
-    ASSERT(diff_param==0);
+    GINAC_ASSERT(diff_param==0);
 
     return power(x, -1);
 }
@@ -112,7 +138,7 @@ REGISTER_FUNCTION(log, log_eval, log_evalf, log_diff, NULL);
 // sine (trigonometric function)
 //////////
 
-ex sin_evalf(ex const & x)
+static ex sin_evalf(ex const & x)
 {
     BEGIN_TYPECHECK
        TYPECHECK(x,numeric)
@@ -121,7 +147,7 @@ ex sin_evalf(ex const & x)
     return sin(ex_to_numeric(x)); // -> numeric sin(numeric)
 }
 
-ex sin_eval(ex const & x)
+static ex sin_eval(ex const & x)
 {
     // sin(n*Pi) -> 0
     ex xOverPi=x/Pi;
@@ -155,9 +181,9 @@ ex sin_eval(ex const & x)
     return sin(x).hold();
 }
 
-ex sin_diff(ex const & x, unsigned diff_param)
+static ex sin_diff(ex const & x, unsigned diff_param)
 {
-    ASSERT(diff_param==0);
+    GINAC_ASSERT(diff_param==0);
     
     return cos(x);
 }
@@ -168,7 +194,7 @@ REGISTER_FUNCTION(sin, sin_eval, sin_evalf, sin_diff, NULL);
 // cosine (trigonometric function)
 //////////
 
-ex cos_evalf(ex const & x)
+static ex cos_evalf(ex const & x)
 {
     BEGIN_TYPECHECK
         TYPECHECK(x,numeric)
@@ -177,7 +203,7 @@ ex cos_evalf(ex const & x)
     return cos(ex_to_numeric(x)); // -> numeric cos(numeric)
 }
 
-ex cos_eval(ex const & x)
+static ex cos_eval(ex const & x)
 {
     // cos(n*Pi) -> {+|-}1
     ex xOverPi=x/Pi;
@@ -211,9 +237,9 @@ ex cos_eval(ex const & x)
     return cos(x).hold();
 }
 
-ex cos_diff(ex const & x, unsigned diff_param)
+static ex cos_diff(ex const & x, unsigned diff_param)
 {
-    ASSERT(diff_param==0);
+    GINAC_ASSERT(diff_param==0);
 
     return numMINUSONE()*sin(x);
 }
@@ -224,7 +250,7 @@ REGISTER_FUNCTION(cos, cos_eval, cos_evalf, cos_diff, NULL);
 // tangent (trigonometric function)
 //////////
 
-ex tan_evalf(ex const & x)
+static ex tan_evalf(ex const & x)
 {
     BEGIN_TYPECHECK
        TYPECHECK(x,numeric)
@@ -233,7 +259,7 @@ ex tan_evalf(ex const & x)
     return tan(ex_to_numeric(x));
 }
 
-ex tan_eval(ex const & x)
+static ex tan_eval(ex const & x)
 {
     // tan(n*Pi/3) -> {0|3^(1/2)|-(3^(1/2))}
     ex ThreeExOverPi=numTHREE()*x/Pi;
@@ -273,9 +299,9 @@ ex tan_eval(ex const & x)
     return tan(x).hold();
 }
 
-ex tan_diff(ex const & x, unsigned diff_param)
+static ex tan_diff(ex const & x, unsigned diff_param)
 {
-    ASSERT(diff_param==0);
+    GINAC_ASSERT(diff_param==0);
     
     return (1+power(tan(x),exTWO()));
 }
@@ -286,7 +312,7 @@ REGISTER_FUNCTION(tan, tan_eval, tan_evalf, tan_diff, NULL);
 // inverse sine (arc sine)
 //////////
 
-ex asin_evalf(ex const & x)
+static ex asin_evalf(ex const & x)
 {
     BEGIN_TYPECHECK
        TYPECHECK(x,numeric)
@@ -295,7 +321,7 @@ ex asin_evalf(ex const & x)
     return asin(ex_to_numeric(x)); // -> numeric asin(numeric)
 }
 
-ex asin_eval(ex const & x)
+static ex asin_eval(ex const & x)
 {
     if (x.info(info_flags::numeric)) {
         // asin(0) -> 0
@@ -321,9 +347,9 @@ ex asin_eval(ex const & x)
     return asin(x).hold();
 }
 
-ex asin_diff(ex const & x, unsigned diff_param)
+static ex asin_diff(ex const & x, unsigned diff_param)
 {
-    ASSERT(diff_param==0);
+    GINAC_ASSERT(diff_param==0);
     
     return power(1-power(x,exTWO()),exMINUSHALF());
 }
@@ -334,7 +360,7 @@ REGISTER_FUNCTION(asin, asin_eval, asin_evalf, asin_diff, NULL);
 // inverse cosine (arc cosine)
 //////////
 
-ex acos_evalf(ex const & x)
+static ex acos_evalf(ex const & x)
 {
     BEGIN_TYPECHECK
        TYPECHECK(x,numeric)
@@ -343,7 +369,7 @@ ex acos_evalf(ex const & x)
     return acos(ex_to_numeric(x)); // -> numeric acos(numeric)
 }
 
-ex acos_eval(ex const & x)
+static ex acos_eval(ex const & x)
 {
     if (x.info(info_flags::numeric)) {
         // acos(1) -> 0
@@ -369,9 +395,9 @@ ex acos_eval(ex const & x)
     return acos(x).hold();
 }
 
-ex acos_diff(ex const & x, unsigned diff_param)
+static ex acos_diff(ex const & x, unsigned diff_param)
 {
-    ASSERT(diff_param==0);
+    GINAC_ASSERT(diff_param==0);
     
     return numMINUSONE()*power(1-power(x,exTWO()),exMINUSHALF());
 }
@@ -382,7 +408,7 @@ REGISTER_FUNCTION(acos, acos_eval, acos_evalf, acos_diff, NULL);
 // inverse tangent (arc tangent)
 //////////
 
-ex atan_evalf(ex const & x)
+static ex atan_evalf(ex const & x)
 {
     BEGIN_TYPECHECK
         TYPECHECK(x,numeric)
@@ -391,7 +417,7 @@ ex atan_evalf(ex const & x)
     return atan(ex_to_numeric(x)); // -> numeric atan(numeric)
 }
 
-ex atan_eval(ex const & x)
+static ex atan_eval(ex const & x)
 {
     if (x.info(info_flags::numeric)) {
         // atan(0) -> 0
@@ -405,9 +431,9 @@ ex atan_eval(ex const & x)
     return atan(x).hold();
 }    
 
-ex atan_diff(ex const & x, unsigned diff_param)
+static ex atan_diff(ex const & x, unsigned diff_param)
 {
-    ASSERT(diff_param==0);
+    GINAC_ASSERT(diff_param==0);
 
     return power(1+x*x, -1);
 }
@@ -418,7 +444,7 @@ REGISTER_FUNCTION(atan, atan_eval, atan_evalf, atan_diff, NULL);
 // inverse tangent (atan2(y,x))
 //////////
 
-ex atan2_evalf(ex const & y, ex const & x)
+static ex atan2_evalf(ex const & y, ex const & x)
 {
     BEGIN_TYPECHECK
         TYPECHECK(y,numeric)
@@ -428,7 +454,7 @@ ex atan2_evalf(ex const & y, ex const & x)
     return atan(ex_to_numeric(y),ex_to_numeric(x)); // -> numeric atan(numeric)
 }
 
-ex atan2_eval(ex const & y, ex const & x)
+static ex atan2_eval(ex const & y, ex const & x)
 {
     if (y.info(info_flags::numeric) && !y.info(info_flags::rational) &&
         x.info(info_flags::numeric) && !x.info(info_flags::rational)) {
@@ -438,16 +464,16 @@ ex atan2_eval(ex const & y, ex const & x)
     return atan2(y,x).hold();
 }    
 
-ex atan2_diff(ex const & y, ex const & x, unsigned diff_param)
+static ex atan2_diff(ex const & y, ex const & x, unsigned diff_param)
 {
-    ASSERT(diff_param<2);
-
+    GINAC_ASSERT(diff_param<2);
+    
     if (diff_param==0) {
         // d/dy atan(y,x)
-        return power(x*(1+y*y/(x*x)),-1);
+        return x*pow(pow(x,2)+pow(y,2),-1);
     }
     // d/dx atan(y,x)
-    return -y*power(x*x+y*y,-1);
+    return -y*pow(pow(x,2)+pow(y,2),-1);
 }
 
 REGISTER_FUNCTION(atan2, atan2_eval, atan2_evalf, atan2_diff, NULL);
@@ -456,7 +482,7 @@ REGISTER_FUNCTION(atan2, atan2_eval, atan2_evalf, atan2_diff, NULL);
 // hyperbolic sine (trigonometric function)
 //////////
 
-ex sinh_evalf(ex const & x)
+static ex sinh_evalf(ex const & x)
 {
     BEGIN_TYPECHECK
        TYPECHECK(x,numeric)
@@ -465,7 +491,7 @@ ex sinh_evalf(ex const & x)
     return sinh(ex_to_numeric(x)); // -> numeric sinh(numeric)
 }
 
-ex sinh_eval(ex const & x)
+static ex sinh_eval(ex const & x)
 {
     if (x.info(info_flags::numeric)) {
         // sinh(0) -> 0
@@ -492,9 +518,9 @@ ex sinh_eval(ex const & x)
     return sinh(x).hold();
 }
 
-ex sinh_diff(ex const & x, unsigned diff_param)
+static ex sinh_diff(ex const & x, unsigned diff_param)
 {
-    ASSERT(diff_param==0);
+    GINAC_ASSERT(diff_param==0);
     
     return cosh(x);
 }
@@ -505,7 +531,7 @@ REGISTER_FUNCTION(sinh, sinh_eval, sinh_evalf, sinh_diff, NULL);
 // hyperbolic cosine (trigonometric function)
 //////////
 
-ex cosh_evalf(ex const & x)
+static ex cosh_evalf(ex const & x)
 {
     BEGIN_TYPECHECK
        TYPECHECK(x,numeric)
@@ -514,7 +540,7 @@ ex cosh_evalf(ex const & x)
     return cosh(ex_to_numeric(x)); // -> numeric cosh(numeric)
 }
 
-ex cosh_eval(ex const & x)
+static ex cosh_eval(ex const & x)
 {
     if (x.info(info_flags::numeric)) {
         // cosh(0) -> 1
@@ -541,9 +567,9 @@ ex cosh_eval(ex const & x)
     return cosh(x).hold();
 }
 
-ex cosh_diff(ex const & x, unsigned diff_param)
+static ex cosh_diff(ex const & x, unsigned diff_param)
 {
-    ASSERT(diff_param==0);
+    GINAC_ASSERT(diff_param==0);
     
     return sinh(x);
 }
@@ -554,7 +580,7 @@ REGISTER_FUNCTION(cosh, cosh_eval, cosh_evalf, cosh_diff, NULL);
 // hyperbolic tangent (trigonometric function)
 //////////
 
-ex tanh_evalf(ex const & x)
+static ex tanh_evalf(ex const & x)
 {
     BEGIN_TYPECHECK
        TYPECHECK(x,numeric)
@@ -563,7 +589,7 @@ ex tanh_evalf(ex const & x)
     return tanh(ex_to_numeric(x)); // -> numeric tanh(numeric)
 }
 
-ex tanh_eval(ex const & x)
+static ex tanh_eval(ex const & x)
 {
     if (x.info(info_flags::numeric)) {
         // tanh(0) -> 0
@@ -590,9 +616,9 @@ ex tanh_eval(ex const & x)
     return tanh(x).hold();
 }
 
-ex tanh_diff(ex const & x, unsigned diff_param)
+static ex tanh_diff(ex const & x, unsigned diff_param)
 {
-    ASSERT(diff_param==0);
+    GINAC_ASSERT(diff_param==0);
     
     return exONE()-power(tanh(x),exTWO());
 }
@@ -603,7 +629,7 @@ REGISTER_FUNCTION(tanh, tanh_eval, tanh_evalf, tanh_diff, NULL);
 // inverse hyperbolic sine (trigonometric function)
 //////////
 
-ex asinh_evalf(ex const & x)
+static ex asinh_evalf(ex const & x)
 {
     BEGIN_TYPECHECK
        TYPECHECK(x,numeric)
@@ -612,7 +638,7 @@ ex asinh_evalf(ex const & x)
     return asinh(ex_to_numeric(x)); // -> numeric asinh(numeric)
 }
 
-ex asinh_eval(ex const & x)
+static ex asinh_eval(ex const & x)
 {
     if (x.info(info_flags::numeric)) {
         // asinh(0) -> 0
@@ -626,9 +652,9 @@ ex asinh_eval(ex const & x)
     return asinh(x).hold();
 }
 
-ex asinh_diff(ex const & x, unsigned diff_param)
+static ex asinh_diff(ex const & x, unsigned diff_param)
 {
-    ASSERT(diff_param==0);
+    GINAC_ASSERT(diff_param==0);
     
     return power(1+power(x,exTWO()),exMINUSHALF());
 }
@@ -639,7 +665,7 @@ REGISTER_FUNCTION(asinh, asinh_eval, asinh_evalf, asinh_diff, NULL);
 // inverse hyperbolic cosine (trigonometric function)
 //////////
 
-ex acosh_evalf(ex const & x)
+static ex acosh_evalf(ex const & x)
 {
     BEGIN_TYPECHECK
        TYPECHECK(x,numeric)
@@ -648,7 +674,7 @@ ex acosh_evalf(ex const & x)
     return acosh(ex_to_numeric(x)); // -> numeric acosh(numeric)
 }
 
-ex acosh_eval(ex const & x)
+static ex acosh_eval(ex const & x)
 {
     if (x.info(info_flags::numeric)) {
         // acosh(0) -> Pi*I/2
@@ -668,9 +694,9 @@ ex acosh_eval(ex const & x)
     return acosh(x).hold();
 }
 
-ex acosh_diff(ex const & x, unsigned diff_param)
+static ex acosh_diff(ex const & x, unsigned diff_param)
 {
-    ASSERT(diff_param==0);
+    GINAC_ASSERT(diff_param==0);
     
     return power(x-1,exMINUSHALF())*power(x+1,exMINUSHALF());
 }
@@ -681,7 +707,7 @@ REGISTER_FUNCTION(acosh, acosh_eval, acosh_evalf, acosh_diff, NULL);
 // inverse hyperbolic tangent (trigonometric function)
 //////////
 
-ex atanh_evalf(ex const & x)
+static ex atanh_evalf(ex const & x)
 {
     BEGIN_TYPECHECK
        TYPECHECK(x,numeric)
@@ -690,7 +716,7 @@ ex atanh_evalf(ex const & x)
     return atanh(ex_to_numeric(x)); // -> numeric atanh(numeric)
 }
 
-ex atanh_eval(ex const & x)
+static ex atanh_eval(ex const & x)
 {
     if (x.info(info_flags::numeric)) {
         // atanh(0) -> 0
@@ -707,11 +733,15 @@ ex atanh_eval(ex const & x)
     return atanh(x).hold();
 }
 
-ex atanh_diff(ex const & x, unsigned diff_param)
+static ex atanh_diff(ex const & x, unsigned diff_param)
 {
-    ASSERT(diff_param==0);
+    GINAC_ASSERT(diff_param==0);
     
     return power(exONE()-power(x,exTWO()),exMINUSONE());
 }
 
 REGISTER_FUNCTION(atanh, atanh_eval, atanh_evalf, atanh_diff, NULL);
+
+#ifndef NO_GINAC_NAMESPACE
+} // namespace GiNaC
+#endif // ndef NO_GINAC_NAMESPACE