]> www.ginac.de Git - ginac.git/blobdiff - ginac/inifcns_trans.cpp
- expairseq.cpp: moved expairseq::to_rational to...
[ginac.git] / ginac / inifcns_trans.cpp
index 14921f46cccd3eec28084c7d3c82b6f413ca521c..81f92a93aca908aa6f698e79dd1a4380d5998d61 100644 (file)
@@ -31,6 +31,7 @@
 #include "power.h"
 #include "relational.h"
 #include "symbol.h"
 #include "power.h"
 #include "relational.h"
 #include "symbol.h"
+#include "pseries.h"
 #include "utils.h"
 
 #ifndef NO_NAMESPACE_GINAC
 #include "utils.h"
 
 #ifndef NO_NAMESPACE_GINAC
@@ -108,16 +109,16 @@ static ex log_evalf(const ex & x)
 static ex log_eval(const ex & x)
 {
     if (x.info(info_flags::numeric)) {
 static ex log_eval(const ex & x)
 {
     if (x.info(info_flags::numeric)) {
+        if (x.is_equal(_ex0()))  // log(0) -> infinity
+            throw(std::domain_error("log_eval(): log(0)"));
+        if (x.info(info_flags::real) && x.info(info_flags::negative))
+            return (log(-x)+I*Pi);
         if (x.is_equal(_ex1()))  // log(1) -> 0
             return _ex0();
         if (x.is_equal(_ex1()))  // log(1) -> 0
             return _ex0();
-        if (x.is_equal(_ex_1())) // log(-1) -> I*Pi
-            return (I*Pi);        
         if (x.is_equal(I))       // log(I) -> Pi*I/2
             return (Pi*I*_num1_2());
         if (x.is_equal(-I))      // log(-I) -> -Pi*I/2
             return (Pi*I*_num_1_2());
         if (x.is_equal(I))       // log(I) -> Pi*I/2
             return (Pi*I*_num1_2());
         if (x.is_equal(-I))      // log(-I) -> -Pi*I/2
             return (Pi*I*_num_1_2());
-        if (x.is_equal(_ex0()))  // log(0) -> infinity
-            throw(std::domain_error("log_eval(): log(0)"));
         // log(float)
         if (!x.info(info_flags::crational))
             return log_evalf(x);
         // log(float)
         if (!x.info(info_flags::crational))
             return log_evalf(x);
@@ -138,14 +139,37 @@ static ex log_eval(const ex & x)
 static ex log_deriv(const ex & x, unsigned deriv_param)
 {
     GINAC_ASSERT(deriv_param==0);
 static ex log_deriv(const ex & x, unsigned deriv_param)
 {
     GINAC_ASSERT(deriv_param==0);
-
+    
     // d/dx log(x) -> 1/x
     return power(x, _ex_1());
 }
 
     // d/dx log(x) -> 1/x
     return power(x, _ex_1());
 }
 
+static ex log_series(const ex &x, const relational &rel, int order)
+{
+    const ex x_pt = x.subs(rel);
+    if (!x_pt.info(info_flags::negative) && !x_pt.is_zero())
+        throw do_taylor();  // caught by function::series()
+    // now we either have to care for the branch cut or the branch point:
+    if (x_pt.is_zero()) {  // branch point: return a plain log(x).
+        epvector seq;
+        seq.push_back(expair(log(x), _ex0()));
+        return pseries(rel, seq);
+    } // on the branch cut:
+    const ex point = rel.rhs();
+    const symbol *s = static_cast<symbol *>(rel.lhs().bp);
+    const symbol foo;
+    // compute the formal series:
+    ex replx = series(log(x),*s==foo,order).subs(foo==point);
+    epvector seq;
+    seq.push_back(expair(-I*csgn(x*I)*Pi,_ex0()));
+    seq.push_back(expair(Order(_ex1()),order));
+    return series(replx - I*Pi + pseries(rel, seq),rel,order);
+}
+
 REGISTER_FUNCTION(log, eval_func(log_eval).
                        evalf_func(log_evalf).
 REGISTER_FUNCTION(log, eval_func(log_eval).
                        evalf_func(log_evalf).
-                       derivative_func(log_deriv));
+                       derivative_func(log_deriv).
+                       series_func(log_series));
 
 //////////
 // sine (trigonometric function)
 
 //////////
 // sine (trigonometric function)
@@ -351,7 +375,7 @@ static ex tan_eval(const ex & x)
         if (z.is_equal(_num25())) // tan(5/12*Pi) -> 2+sqrt(3)
             return sign*(power(_ex3(),_ex1_2())+_ex2());
         if (z.is_equal(_num30())) // tan(Pi/2)    -> infinity
         if (z.is_equal(_num25())) // tan(5/12*Pi) -> 2+sqrt(3)
             return sign*(power(_ex3(),_ex1_2())+_ex2());
         if (z.is_equal(_num30())) // tan(Pi/2)    -> infinity
-            throw (std::domain_error("tan_eval(): infinity"));
+            throw (std::domain_error("tan_eval(): simple pole"));
     }
     
     if (is_ex_exactly_of_type(x, function)) {
     }
     
     if (is_ex_exactly_of_type(x, function)) {
@@ -383,16 +407,16 @@ static ex tan_deriv(const ex & x, unsigned deriv_param)
     return (_ex1()+power(tan(x),_ex2()));
 }
 
     return (_ex1()+power(tan(x),_ex2()));
 }
 
-static ex tan_series(const ex & x, const symbol & s, const ex & pt, int order)
+static ex tan_series(const ex &x, const relational &rel, int order)
 {
     // method:
     // Taylor series where there is no pole falls back to tan_deriv.
     // On a pole simply expand sin(x)/cos(x).
 {
     // method:
     // Taylor series where there is no pole falls back to tan_deriv.
     // On a pole simply expand sin(x)/cos(x).
-    const ex x_pt = x.subs(s==pt);
+    const ex x_pt = x.subs(rel);
     if (!(2*x_pt/Pi).info(info_flags::odd))
         throw do_taylor();  // caught by function::series()
     // if we got here we have to care for a simple pole
     if (!(2*x_pt/Pi).info(info_flags::odd))
         throw do_taylor();  // caught by function::series()
     // if we got here we have to care for a simple pole
-    return (sin(x)/cos(x)).series(s, pt, order+2);
+    return (sin(x)/cos(x)).series(rel, order+2);
 }
 
 REGISTER_FUNCTION(tan, eval_func(tan_eval).
 }
 
 REGISTER_FUNCTION(tan, eval_func(tan_eval).
@@ -740,16 +764,16 @@ static ex tanh_deriv(const ex & x, unsigned deriv_param)
     return _ex1()-power(tanh(x),_ex2());
 }
 
     return _ex1()-power(tanh(x),_ex2());
 }
 
-static ex tanh_series(const ex & x, const symbol & s, const ex & pt, int order)
+static ex tanh_series(const ex &x, const relational &rel, int order)
 {
     // method:
     // Taylor series where there is no pole falls back to tanh_deriv.
     // On a pole simply expand sinh(x)/cosh(x).
 {
     // method:
     // Taylor series where there is no pole falls back to tanh_deriv.
     // On a pole simply expand sinh(x)/cosh(x).
-    const ex x_pt = x.subs(s==pt);
+    const ex x_pt = x.subs(rel);
     if (!(2*I*x_pt/Pi).info(info_flags::odd))
         throw do_taylor();  // caught by function::series()
     // if we got here we have to care for a simple pole
     if (!(2*I*x_pt/Pi).info(info_flags::odd))
         throw do_taylor();  // caught by function::series()
     // if we got here we have to care for a simple pole
-    return (sinh(x)/cosh(x)).series(s, pt, order+2);
+    return (sinh(x)/cosh(x)).series(rel, order+2);
 }
 
 REGISTER_FUNCTION(tanh, eval_func(tanh_eval).
 }
 
 REGISTER_FUNCTION(tanh, eval_func(tanh_eval).
@@ -861,8 +885,8 @@ static ex atanh_eval(const ex & x)
         if (x.is_zero())
             return _ex0();
         // atanh({+|-}1) -> throw
         if (x.is_zero())
             return _ex0();
         // atanh({+|-}1) -> throw
-        if (x.is_equal(_ex1()) || x.is_equal(_ex1()))
-            throw (std::domain_error("atanh_eval(): infinity"));
+        if (x.is_equal(_ex1()) || x.is_equal(_ex_1()))
+            throw (std::domain_error("atanh_eval(): logarithmic pole"));
         // atanh(float) -> float
         if (!x.info(info_flags::crational))
             return atanh_evalf(x);
         // atanh(float) -> float
         if (!x.info(info_flags::crational))
             return atanh_evalf(x);