]> www.ginac.de Git - ginac.git/blobdiff - ginac/inifcns.cpp
fixed comments
[ginac.git] / ginac / inifcns.cpp
index fbdceb708c9e7d22795e540051499a6a519ae1f2..1fcba692b5796a46f64992f4871e62e222f9be84 100644 (file)
@@ -29,8 +29,6 @@
 #include "lst.h"
 #include "matrix.h"
 #include "mul.h"
-#include "ncmul.h"
-#include "numeric.h"
 #include "power.h"
 #include "relational.h"
 #include "pseries.h"
@@ -49,13 +47,13 @@ static ex abs_evalf(const ex & arg)
                TYPECHECK(arg,numeric)
        END_TYPECHECK(abs(arg))
        
-       return abs(ex_to_numeric(arg));
+       return abs(ex_to<numeric>(arg));
 }
 
 static ex abs_eval(const ex & arg)
 {
        if (is_ex_exactly_of_type(arg, numeric))
-               return abs(ex_to_numeric(arg));
+               return abs(ex_to<numeric>(arg));
        else
                return abs(arg).hold();
 }
@@ -74,16 +72,17 @@ static ex csgn_evalf(const ex & arg)
                TYPECHECK(arg,numeric)
        END_TYPECHECK(csgn(arg))
        
-       return csgn(ex_to_numeric(arg));
+       return csgn(ex_to<numeric>(arg));
 }
 
 static ex csgn_eval(const ex & arg)
 {
        if (is_ex_exactly_of_type(arg, numeric))
-               return csgn(ex_to_numeric(arg));
+               return csgn(ex_to<numeric>(arg));
        
-       else if (is_ex_exactly_of_type(arg, mul)) {
-               numeric oc = ex_to_numeric(arg.op(arg.nops()-1));
+       else if (is_ex_of_type(arg, mul) &&
+                is_ex_of_type(arg.op(arg.nops()-1),numeric)) {
+               numeric oc = ex_to<numeric>(arg.op(arg.nops()-1));
                if (oc.is_real()) {
                        if (oc > 0)
                                // csgn(42*x) -> csgn(x)
@@ -101,7 +100,7 @@ static ex csgn_eval(const ex & arg)
                                return -csgn(I*arg/oc).hold();
                }
        }
-   
+       
        return csgn(arg).hold();
 }
 
@@ -112,7 +111,7 @@ static ex csgn_series(const ex & arg,
 {
        const ex arg_pt = arg.subs(rel);
        if (arg_pt.info(info_flags::numeric)
-           && ex_to_numeric(arg_pt).real().is_zero()
+           && ex_to<numeric>(arg_pt).real().is_zero()
            && !(options & series_options::suppress_branchcut))
                throw (std::domain_error("csgn_series(): on imaginary axis"));
        
@@ -137,9 +136,9 @@ static ex eta_evalf(const ex & x, const ex & y)
                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));
+       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));
 }
 
@@ -148,9 +147,9 @@ 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));
+               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));
        }
        
@@ -165,9 +164,9 @@ static ex eta_series(const ex & arg1,
 {
        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()) {
+       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;
@@ -177,7 +176,8 @@ static ex eta_series(const ex & arg1,
 
 REGISTER_FUNCTION(eta, eval_func(eta_eval).
                        evalf_func(eta_evalf).
-                       series_func(eta_series));
+                       series_func(eta_series).
+                       latex_name("\\eta"));
 
 
 //////////
@@ -190,7 +190,7 @@ static ex Li2_evalf(const ex & x)
                TYPECHECK(x,numeric)
        END_TYPECHECK(Li2(x))
        
-       return Li2(ex_to_numeric(x));  // -> numeric Li2(numeric)
+       return Li2(ex_to<numeric>(x));  // -> numeric Li2(numeric)
 }
 
 static ex Li2_eval(const ex & x)
@@ -289,7 +289,7 @@ static ex Li2_series(const ex &x, const relational &rel, int order, unsigned opt
                }
                // third special case: x real, >=1 (branch cut)
                if (!(options & series_options::suppress_branchcut) &&
-                       ex_to_numeric(x_pt).is_real() && ex_to_numeric(x_pt)>1) {
+                       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.
@@ -315,7 +315,8 @@ static ex Li2_series(const ex &x, const relational &rel, int order, unsigned opt
 REGISTER_FUNCTION(Li2, eval_func(Li2_eval).
                        evalf_func(Li2_evalf).
                        derivative_func(Li2_deriv).
-                       series_func(Li2_series));
+                       series_func(Li2_series).
+                       latex_name("\\mbox{Li}_2"));
 
 //////////
 // trilogarithm
@@ -328,7 +329,8 @@ static ex Li3_eval(const ex & x)
        return Li3(x).hold();
 }
 
-REGISTER_FUNCTION(Li3, eval_func(Li3_eval));
+REGISTER_FUNCTION(Li3, eval_func(Li3_eval).
+                       latex_name("\\mbox{Li}_3"));
 
 //////////
 // factorial
@@ -342,7 +344,7 @@ static ex factorial_evalf(const ex & x)
 static ex factorial_eval(const ex & x)
 {
        if (is_ex_exactly_of_type(x, numeric))
-               return factorial(ex_to_numeric(x));
+               return factorial(ex_to<numeric>(x));
        else
                return factorial(x).hold();
 }
@@ -362,7 +364,7 @@ static ex binomial_evalf(const ex & x, const ex & y)
 static ex binomial_eval(const ex & x, const ex &y)
 {
        if (is_ex_exactly_of_type(x, numeric) && is_ex_exactly_of_type(y, numeric))
-               return binomial(ex_to_numeric(x), ex_to_numeric(y));
+               return binomial(ex_to<numeric>(x), ex_to<numeric>(y));
        else
                return binomial(x, y).hold();
 }
@@ -404,7 +406,8 @@ static ex Order_series(const ex & x, const relational & r, int order, unsigned o
 // Differentiation is handled in function::derivative because of its special requirements
 
 REGISTER_FUNCTION(Order, eval_func(Order_eval).
-                         series_func(Order_series));
+                         series_func(Order_series).
+                         latex_name("\\mathcal{O}"));
 
 //////////
 // Inert partial differentiation operator
@@ -468,17 +471,17 @@ ex lsolve(const ex &eqns, const ex &symbols)
                ex eq = eqns.op(r).op(0)-eqns.op(r).op(1); // lhs-rhs==0
                ex linpart = eq;
                for (unsigned c=0; c<symbols.nops(); c++) {
-                       ex co = eq.coeff(ex_to_symbol(symbols.op(c)),1);
+                       ex co = eq.coeff(ex_to<symbol>(symbols.op(c)),1);
                        linpart -= co*symbols.op(c);
-                       sys.set(r,c,co);
+                       sys(r,c) = co;
                }
                linpart = linpart.expand();
-               rhs.set(r,0,-linpart);
+               rhs(r,0) = -linpart;
        }
        
        // test if system is linear and fill vars matrix
        for (unsigned i=0; i<symbols.nops(); i++) {
-               vars.set(i,0,symbols.op(i));
+               vars(i,0) = symbols.op(i);
                if (sys.has(symbols.op(i)))
                        throw(std::logic_error("lsolve: system is not linear"));
                if (rhs.has(symbols.op(i)))
@@ -504,24 +507,8 @@ ex lsolve(const ex &eqns, const ex &symbols)
        return sollist;
 }
 
-/** non-commutative power. */
-ex ncpower(const ex &basis, unsigned exponent)
-{
-       if (exponent==0) {
-               return _ex1();
-       }
-
-       exvector v;
-       v.reserve(exponent);
-       for (unsigned i=0; i<exponent; ++i) {
-               v.push_back(basis);
-       }
-
-       return ncmul(v,1);
-}
-
-/** Force inclusion of functions from initcns_gamma and inifcns_zeta
- *  for static lib (so ginsh will see them). */
+/* Force inclusion of functions from inifcns_gamma and inifcns_zeta
+ * for static lib (so ginsh will see them). */
 unsigned force_include_tgamma = function_index_tgamma;
 unsigned force_include_zeta1 = function_index_zeta1;