X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Finifcns.cpp;h=f64597e5c3cb50031b57e577b7c221f060d4d999;hp=d5e9275b54ee1f482745fdfc1d8f06e9656d0995;hb=818a7af0fe95c6d6c27910bb0ded22d80d795a10;hpb=703c6cebb5d3d395437e73e6935f3691aed68e0a diff --git a/ginac/inifcns.cpp b/ginac/inifcns.cpp index d5e9275b..f64597e5 100644 --- a/ginac/inifcns.cpp +++ b/ginac/inifcns.cpp @@ -3,7 +3,7 @@ * Implementation of GiNaC's initially known functions. */ /* - * GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2001 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 @@ -29,17 +29,13 @@ #include "lst.h" #include "matrix.h" #include "mul.h" -#include "ncmul.h" -#include "numeric.h" #include "power.h" #include "relational.h" #include "pseries.h" #include "symbol.h" #include "utils.h" -#ifndef NO_NAMESPACE_GINAC namespace GiNaC { -#endif // ndef NO_NAMESPACE_GINAC ////////// // absolute value @@ -51,19 +47,19 @@ static ex abs_evalf(const ex & arg) TYPECHECK(arg,numeric) END_TYPECHECK(abs(arg)) - return abs(ex_to_numeric(arg)); + return abs(ex_to(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(arg)); else return abs(arg).hold(); } REGISTER_FUNCTION(abs, eval_func(abs_eval). - evalf_func(abs_evalf)); + evalf_func(abs_evalf)); ////////// @@ -76,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(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(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(arg.op(arg.nops()-1)); if (oc.is_real()) { if (oc > 0) // csgn(42*x) -> csgn(x) @@ -103,18 +100,19 @@ static ex csgn_eval(const ex & arg) return -csgn(I*arg/oc).hold(); } } - + return csgn(arg).hold(); } static ex csgn_series(const ex & arg, - const relational & rel, - int order, - unsigned options) + const relational & rel, + int order, + unsigned options) { const ex arg_pt = arg.subs(rel); - if (arg_pt.info(info_flags::numeric) && - ex_to_numeric(arg_pt).real().is_zero()) + if (arg_pt.info(info_flags::numeric) + && ex_to(arg_pt).real().is_zero() + && !(options & series_options::suppress_branchcut)) throw (std::domain_error("csgn_series(): on imaginary axis")); epvector seq; @@ -123,8 +121,8 @@ static ex csgn_series(const ex & arg, } REGISTER_FUNCTION(csgn, eval_func(csgn_eval). - evalf_func(csgn_evalf). - series_func(csgn_series)); + evalf_func(csgn_evalf). + series_func(csgn_series)); ////////// @@ -138,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(x)); + numeric yim = imag(ex_to(y)); + numeric xyim = imag(ex_to(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)); } @@ -149,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(x)); + numeric yim = imag(ex_to(y)); + numeric xyim = imag(ex_to(x*y)); return (I/4)*Pi*((csgn(-xim)+1)*(csgn(-yim)+1)*(csgn(xyim)+1)-(csgn(xim)+1)*(csgn(yim)+1)*(csgn(-xyim)+1)); } @@ -159,16 +157,16 @@ static ex eta_eval(const ex & x, const ex & y) } static ex eta_series(const ex & arg1, - const ex & arg2, - const relational & rel, - int order, - unsigned options) + 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()) { + if (ex_to(arg1_pt).imag().is_zero() || + ex_to(arg2_pt).imag().is_zero() || + ex_to(arg1_pt*arg2_pt).imag().is_zero()) { throw (std::domain_error("eta_series(): on discontinuity")); } epvector seq; @@ -177,8 +175,9 @@ static ex eta_series(const ex & arg1, } REGISTER_FUNCTION(eta, eval_func(eta_eval). - evalf_func(eta_evalf). - series_func(eta_series)); + evalf_func(eta_evalf). + series_func(eta_series). + latex_name("\\eta")); ////////// @@ -191,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(x)); // -> numeric Li2(numeric) } static ex Li2_eval(const ex & x) @@ -275,7 +274,7 @@ static ex Li2_series(const ex &x, const relational &rel, int order, unsigned opt // method: // construct series manually in a dummy symbol s const symbol s; - ex ser = zeta(2); + ex ser = zeta(_ex2()); // manually construct the primitive expansion for (int i=1; i=1 (branch cut) if (!(options & series_options::suppress_branchcut) && - ex_to_numeric(x_pt).is_real() && ex_to_numeric(x_pt)>1) { + ex_to(x_pt).is_real() && ex_to(x_pt)>1) { // method: // This is the branch cut: assemble the primitive series manually // and then add the corresponding complex step function. @@ -314,9 +313,10 @@ 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)); + evalf_func(Li2_evalf). + derivative_func(Li2_deriv). + series_func(Li2_series). + latex_name("\\mbox{Li}_2")); ////////// // trilogarithm @@ -329,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 @@ -343,13 +344,13 @@ 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(x)); else return factorial(x).hold(); } REGISTER_FUNCTION(factorial, eval_func(factorial_eval). - evalf_func(factorial_evalf)); + evalf_func(factorial_evalf)); ////////// // binomial @@ -363,13 +364,13 @@ 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(x), ex_to(y)); else return binomial(x, y).hold(); } REGISTER_FUNCTION(binomial, eval_func(binomial_eval). - evalf_func(binomial_evalf)); + evalf_func(binomial_evalf)); ////////// // Order term function (for truncated power series) @@ -405,24 +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)); - -////////// -// Inert partial differentiation operator -////////// - -static ex Derivative_eval(const ex & f, const ex & l) -{ - if (!is_ex_exactly_of_type(f, function)) { - throw(std::invalid_argument("Derivative(): 1st argument must be a function")); - } - if (!is_ex_exactly_of_type(l, lst)) { - throw(std::invalid_argument("Derivative(): 2nd argument must be a list")); - } - return Derivative(f, l).hold(); -} - -REGISTER_FUNCTION(Derivative, eval_func(Derivative_eval)); + series_func(Order_series). + latex_name("\\mathcal{O}")); ////////// // Solve linear system @@ -469,17 +454,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.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