X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Finifcns.cpp;h=33582acb1f3c2672371cdba1742d5dfb19161559;hp=e211442406f30989197cf322a37ed6282c5866f8;hb=8dc09f48182574d792a2ed7c37b66831d9267a6c;hpb=27d6204effdef95a00af461fff98024e290dbaa7;ds=sidebyside diff --git a/ginac/inifcns.cpp b/ginac/inifcns.cpp index e2114424..33582acb 100644 --- a/ginac/inifcns.cpp +++ b/ginac/inifcns.cpp @@ -3,7 +3,7 @@ * Implementation of GiNaC's initially known functions. */ /* - * GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2004 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 @@ -30,6 +30,7 @@ #include "matrix.h" #include "mul.h" #include "power.h" +#include "operators.h" #include "relational.h" #include "pseries.h" #include "symbol.h" @@ -38,6 +39,38 @@ namespace GiNaC { +////////// +// complex conjugate +////////// + +static ex conjugate_evalf(const ex & arg) +{ + if (is_exactly_a(arg)) { + return ex_to(arg).conjugate(); + } + return conjugate(arg).hold(); +} + +static ex conjugate_eval(const ex & arg) +{ + return arg.conjugate(); +} + +static void conjugate_print_latex(const ex & arg, const print_context & c) +{ + c.s << "\bar{"; arg.print(c); c.s << "}"; +} + +static ex conjugate_conjugate(const ex & arg) +{ + return arg; +} + +REGISTER_FUNCTION(conjugate, eval_func(conjugate_eval). + evalf_func(conjugate_evalf). + print_func(conjugate_print_latex). + conjugate_func(conjugate_conjugate)); + ////////// // absolute value ////////// @@ -52,14 +85,33 @@ static ex abs_evalf(const ex & arg) static ex abs_eval(const ex & arg) { - if (is_ex_exactly_of_type(arg, numeric)) + if (is_exactly_a(arg)) return abs(ex_to(arg)); else return abs(arg).hold(); } +static void abs_print_latex(const ex & arg, const print_context & c) +{ + c.s << "{|"; arg.print(c); c.s << "|}"; +} + +static void abs_print_csrc_float(const ex & arg, const print_context & c) +{ + c.s << "fabs("; arg.print(c); c.s << ")"; +} + +static ex abs_conjugate(const ex & arg) +{ + return abs(arg); +} + REGISTER_FUNCTION(abs, eval_func(abs_eval). - evalf_func(abs_evalf)); + evalf_func(abs_evalf). + print_func(abs_print_latex). + print_func(abs_print_csrc_float). + print_func(abs_print_csrc_float). + conjugate_func(abs_conjugate)); ////////// @@ -76,11 +128,11 @@ static ex csgn_evalf(const ex & arg) static ex csgn_eval(const ex & arg) { - if (is_ex_exactly_of_type(arg, numeric)) + if (is_exactly_a(arg)) return csgn(ex_to(arg)); - else if (is_ex_of_type(arg, mul) && - is_ex_of_type(arg.op(arg.nops()-1),numeric)) { + else if (is_exactly_a(arg) && + is_exactly_a(arg.op(arg.nops()-1))) { numeric oc = ex_to(arg.op(arg.nops()-1)); if (oc.is_real()) { if (oc > 0) @@ -108,7 +160,7 @@ static ex csgn_series(const ex & arg, int order, unsigned options) { - const ex arg_pt = arg.subs(rel); + const ex arg_pt = arg.subs(rel, subs_options::no_pattern); if (arg_pt.info(info_flags::numeric) && ex_to(arg_pt).real().is_zero() && !(options & series_options::suppress_branchcut)) @@ -119,9 +171,15 @@ static ex csgn_series(const ex & arg, return pseries(rel,seq); } +static ex csgn_conjugate(const ex& arg) +{ + return csgn(arg); +} + REGISTER_FUNCTION(csgn, eval_func(csgn_eval). evalf_func(csgn_evalf). - series_func(csgn_series)); + series_func(csgn_series). + conjugate_func(csgn_conjugate)); ////////// @@ -185,8 +243,8 @@ static ex eta_series(const ex & x, const ex & y, int order, unsigned options) { - const ex x_pt = x.subs(rel); - const ex y_pt = y.subs(rel); + const ex x_pt = x.subs(rel, subs_options::no_pattern); + const ex y_pt = y.subs(rel, subs_options::no_pattern); if ((x_pt.info(info_flags::numeric) && x_pt.info(info_flags::negative)) || (y_pt.info(info_flags::numeric) && y_pt.info(info_flags::negative)) || ((x_pt*y_pt).info(info_flags::numeric) && (x_pt*y_pt).info(info_flags::negative))) @@ -196,11 +254,17 @@ static ex eta_series(const ex & x, const ex & y, return pseries(rel,seq); } +static ex eta_conjugate(const ex & x, const ex & y) +{ + return -eta(x,y); +} + REGISTER_FUNCTION(eta, eval_func(eta_eval). evalf_func(eta_evalf). series_func(eta_series). latex_name("\\eta"). - set_symmetry(sy_symm(0, 1))); + set_symmetry(sy_symm(0, 1)). + conjugate_func(eta_conjugate)); ////////// @@ -254,7 +318,7 @@ static ex Li2_deriv(const ex & x, unsigned deriv_param) static ex Li2_series(const ex &x, const relational &rel, int order, unsigned options) { - const ex x_pt = x.subs(rel); + const ex x_pt = x.subs(rel, subs_options::no_pattern); if (x_pt.info(info_flags::numeric)) { // First special case: x==0 (derivatives have poles) if (x_pt.is_zero()) { @@ -276,7 +340,7 @@ static ex Li2_series(const ex &x, const relational &rel, int order, unsigned opt for (int i=1; i zeta(x) + if (n.is_zero()) + return zeta(x); + } + + return zetaderiv(n, x).hold(); +} + +static ex zetaderiv_deriv(const ex & n, const ex & x, unsigned deriv_param) +{ + GINAC_ASSERT(deriv_param<2); + + if (deriv_param==0) { + // d/dn zeta(n,x) + throw(std::logic_error("cannot diff zetaderiv(n,x) with respect to n")); + } + // d/dx psi(n,x) + return zetaderiv(n+1,x); +} + +REGISTER_FUNCTION(zetaderiv, eval_func(zetaderiv_eval). + derivative_func(zetaderiv_deriv). + latex_name("\\zeta^\\prime")); + ////////// // factorial ////////// @@ -365,14 +460,20 @@ static ex factorial_evalf(const ex & x) static ex factorial_eval(const ex & x) { - if (is_ex_exactly_of_type(x, numeric)) + if (is_exactly_a(x)) return factorial(ex_to(x)); else return factorial(x).hold(); } +static ex factorial_conjugate(const ex & x) +{ + return factorial(x); +} + REGISTER_FUNCTION(factorial, eval_func(factorial_eval). - evalf_func(factorial_evalf)); + evalf_func(factorial_evalf). + conjugate_func(factorial_conjugate)); ////////// // binomial @@ -385,14 +486,23 @@ 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)) + if (is_exactly_a(x) && is_exactly_a(y)) return binomial(ex_to(x), ex_to(y)); else return binomial(x, y).hold(); } +// At the moment the numeric evaluation of a binomail function always +// gives a real number, but if this would be implemented using the gamma +// function, also complex conjugation should be changed (or rather, deleted). +static ex binomial_conjugate(const ex & x, const ex & y) +{ + return binomial(x,y); +} + REGISTER_FUNCTION(binomial, eval_func(binomial_eval). - evalf_func(binomial_evalf)); + evalf_func(binomial_evalf). + conjugate_func(binomial_conjugate)); ////////// // Order term function (for truncated power series) @@ -400,16 +510,16 @@ REGISTER_FUNCTION(binomial, eval_func(binomial_eval). static ex Order_eval(const ex & x) { - if (is_ex_exactly_of_type(x, numeric)) { + if (is_exactly_a(x)) { // O(c) -> O(1) or 0 if (!x.is_zero()) return Order(_ex1).hold(); else return _ex0; - } else if (is_ex_exactly_of_type(x, mul)) { + } else if (is_exactly_a(x)) { const mul &m = ex_to(x); // O(c*expr) -> O(expr) - if (is_ex_exactly_of_type(m.op(m.nops() - 1), numeric)) + if (is_exactly_a(m.op(m.nops() - 1))) return Order(x / m.op(m.nops() - 1)).hold(); } return Order(x).hold(); @@ -419,17 +529,23 @@ static ex Order_series(const ex & x, const relational & r, int order, unsigned o { // Just wrap the function into a pseries object epvector new_seq; - GINAC_ASSERT(is_exactly_a(r.lhs())); + GINAC_ASSERT(is_a(r.lhs())); const symbol &s = ex_to(r.lhs()); new_seq.push_back(expair(Order(_ex1), numeric(std::min(x.ldegree(s), order)))); return pseries(r, new_seq); } +static ex Order_conjugate(const ex & x) +{ + return Order(x); +} + // Differentiation is handled in function::derivative because of its special requirements REGISTER_FUNCTION(Order, eval_func(Order_eval). series_func(Order_series). - latex_name("\\mathcal{O}")); + latex_name("\\mathcal{O}"). + conjugate_func(Order_conjugate)); ////////// // Solve linear system @@ -453,7 +569,7 @@ ex lsolve(const ex &eqns, const ex &symbols, unsigned options) if (!eqns.info(info_flags::list)) { throw(std::invalid_argument("lsolve(): 1st argument must be a list")); } - for (unsigned i=0; i(symbols.op(c)),1); linpart -= co*symbols.op(c); sys(r,c) = co; @@ -485,7 +601,7 @@ ex lsolve(const ex &eqns, const ex &symbols, unsigned options) } // test if system is linear and fill vars matrix - for (unsigned i=0; i