]> www.ginac.de Git - ginac.git/blobdiff - ginac/inifcns.cpp
- Made determinant_algo (in flags.h) really work.
[ginac.git] / ginac / inifcns.cpp
index 14e53b5e0c27522767fa4fd23d96aac7522b417e..b560100f2437296cd6f752a372c35aeb7fcb8994 100644 (file)
@@ -45,21 +45,21 @@ namespace GiNaC {
 // absolute value
 //////////
 
-static ex abs_evalf(const ex & x)
+static ex abs_evalf(const ex & arg)
 {
     BEGIN_TYPECHECK
-        TYPECHECK(x,numeric)
-    END_TYPECHECK(abs(x))
+        TYPECHECK(arg,numeric)
+    END_TYPECHECK(abs(arg))
     
-    return abs(ex_to_numeric(x));
+    return abs(ex_to_numeric(arg));
 }
 
-static ex abs_eval(const ex & x)
+static ex abs_eval(const ex & arg)
 {
-    if (is_ex_exactly_of_type(x, numeric))
-        return abs(ex_to_numeric(x));
+    if (is_ex_exactly_of_type(arg, numeric))
+        return abs(ex_to_numeric(arg));
     else
-        return abs(x).hold();
+        return abs(arg).hold();
 }
 
 REGISTER_FUNCTION(abs, eval_func(abs_eval).
@@ -70,56 +70,53 @@ REGISTER_FUNCTION(abs, eval_func(abs_eval).
 // Complex sign
 //////////
 
-static ex csgn_evalf(const ex & x)
+static ex csgn_evalf(const ex & arg)
 {
     BEGIN_TYPECHECK
-        TYPECHECK(x,numeric)
-    END_TYPECHECK(csgn(x))
+        TYPECHECK(arg,numeric)
+    END_TYPECHECK(csgn(arg))
     
-    return csgn(ex_to_numeric(x));
+    return csgn(ex_to_numeric(arg));
 }
 
-static ex csgn_eval(const ex & x)
+static ex csgn_eval(const ex & arg)
 {
-    if (is_ex_exactly_of_type(x, numeric))
-        return csgn(ex_to_numeric(x));
+    if (is_ex_exactly_of_type(arg, numeric))
+        return csgn(ex_to_numeric(arg));
     
-    else if (is_ex_exactly_of_type(x, mul)) {
-        numeric oc = ex_to_numeric(x.op(x.nops()-1));
+    else if (is_ex_exactly_of_type(arg, mul)) {
+        numeric oc = ex_to_numeric(arg.op(arg.nops()-1));
         if (oc.is_real()) {
             if (oc > 0)
                 // csgn(42*x) -> csgn(x)
-                return csgn(x/oc).hold();
+                return csgn(arg/oc).hold();
             else
                 // csgn(-42*x) -> -csgn(x)
-                return -csgn(x/oc).hold();
+                return -csgn(arg/oc).hold();
         }
         if (oc.real().is_zero()) {
             if (oc.imag() > 0)
                 // csgn(42*I*x) -> csgn(I*x)
-                return csgn(I*x/oc).hold();
+                return csgn(I*arg/oc).hold();
             else
                 // csgn(-42*I*x) -> -csgn(I*x)
-                return -csgn(I*x/oc).hold();
+                return -csgn(I*arg/oc).hold();
         }
        }
    
-    return csgn(x).hold();
+    return csgn(arg).hold();
 }
 
 static ex csgn_series(const ex & arg,
                       const relational & rel,
                       int order,
-                      bool branchcut)
+                      unsigned options)
 {
     const ex arg_pt = arg.subs(rel);
-    if (arg_pt.info(info_flags::numeric)) {
-        if (ex_to_numeric(arg_pt).real().is_zero())
-            throw (std::domain_error("csgn_series(): on imaginary axis"));
-        epvector seq;
-        seq.push_back(expair(csgn(arg_pt), _ex0()));
-        return pseries(rel,seq);
-    }
+    if (arg_pt.info(info_flags::numeric) &&
+        ex_to_numeric(arg_pt).real().is_zero())
+        throw (std::domain_error("csgn_series(): on imaginary axis"));
+    
     epvector seq;
     seq.push_back(expair(csgn(arg_pt), _ex0()));
     return pseries(rel,seq);
@@ -129,6 +126,61 @@ REGISTER_FUNCTION(csgn, eval_func(csgn_eval).
                         evalf_func(csgn_evalf).
                         series_func(csgn_series));
 
+
+//////////
+// Eta function: log(x*y) == log(x) + log(y) + eta(x,y).
+//////////
+
+static ex eta_evalf(const ex & x, const ex & y)
+{
+    BEGIN_TYPECHECK
+        TYPECHECK(x,numeric)
+        TYPECHECK(y,numeric)
+    END_TYPECHECK(eta(x,y))
+        
+    numeric xim = imag(ex_to_numeric(x));
+    numeric yim = imag(ex_to_numeric(y));
+    numeric xyim = imag(ex_to_numeric(x*y));
+    return evalf(I/4*Pi)*((csgn(-xim)+1)*(csgn(-yim)+1)*(csgn(xyim)+1)-(csgn(xim)+1)*(csgn(yim)+1)*(csgn(-xyim)+1));
+}
+
+static ex eta_eval(const ex & x, const ex & y)
+{
+    if (is_ex_exactly_of_type(x, numeric) &&
+        is_ex_exactly_of_type(y, numeric)) {
+        // don't call eta_evalf here because it would call Pi.evalf()!
+        numeric xim = imag(ex_to_numeric(x));
+        numeric yim = imag(ex_to_numeric(y));
+        numeric xyim = imag(ex_to_numeric(x*y));
+        return (I/4)*Pi*((csgn(-xim)+1)*(csgn(-yim)+1)*(csgn(xyim)+1)-(csgn(xim)+1)*(csgn(yim)+1)*(csgn(-xyim)+1));
+    }
+    
+    return eta(x,y).hold();
+}
+
+static ex eta_series(const ex & arg1,
+                     const ex & arg2,
+                     const relational & rel,
+                     int order,
+                     unsigned options)
+{
+    const ex arg1_pt = arg1.subs(rel);
+    const ex arg2_pt = arg2.subs(rel);
+    if (ex_to_numeric(arg1_pt).imag().is_zero() ||
+        ex_to_numeric(arg2_pt).imag().is_zero() ||
+        ex_to_numeric(arg1_pt*arg2_pt).imag().is_zero()) {
+        throw (std::domain_error("eta_series(): on discontinuity"));
+    }
+    epvector seq;
+    seq.push_back(expair(eta(arg1_pt,arg2_pt), _ex0()));
+    return pseries(rel,seq);
+}
+
+REGISTER_FUNCTION(eta, eval_func(eta_eval).
+                       evalf_func(eta_evalf).
+                       series_func(eta_series));
+
+
 //////////
 // dilogarithm
 //////////
@@ -179,7 +231,7 @@ static ex Li2_deriv(const ex & x, unsigned deriv_param)
     return -log(1-x)/x;
 }
 
-static ex Li2_series(const ex &x, const relational &rel, int order, bool branchcut)
+static ex Li2_series(const ex &x, const relational &rel, int order, unsigned options)
 {
     const ex x_pt = x.subs(rel);
     if (x_pt.info(info_flags::numeric)) {
@@ -237,7 +289,8 @@ static ex Li2_series(const ex &x, const relational &rel, int order, bool branchc
             return ser.series(rel, order);
         }
         // third special case: x real, >=1 (branch cut)
-        if (ex_to_numeric(x_pt).is_real() && ex_to_numeric(x_pt)>1) {
+        if (!(options & series_options::suppress_branchcut) &&
+            ex_to_numeric(x_pt).is_real() && ex_to_numeric(x_pt)>1) {
             // method:
             // This is the branch cut: assemble the primitive series manually
             // and then add the corresponding complex step function.
@@ -250,7 +303,7 @@ static ex Li2_series(const ex &x, const relational &rel, int order, bool branchc
             // compute the intermediate terms:
             ex replarg = series(Li2(x), *s==foo, order);
             for (unsigned i=1; i<replarg.nops()-1; ++i)
-                seq.push_back(expair((replarg.op(i)/power(*s-foo,i)).series(foo==point,1,branchcut).op(0).subs(foo==*s),i));
+                seq.push_back(expair((replarg.op(i)/power(*s-foo,i)).series(foo==point,1,options).op(0).subs(foo==*s),i));
             // append an order term:
             seq.push_back(expair(Order(_ex1()), replarg.nops()-1));
             return pseries(rel, seq);
@@ -341,7 +394,7 @@ static ex Order_eval(const ex & x)
        return Order(x).hold();
 }
 
-static ex Order_series(const ex & x, const relational & r, int order, bool branchcut)
+static ex Order_series(const ex & x, const relational & r, int order, unsigned options)
 {
        // Just wrap the function into a pseries object
        epvector new_seq;