X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Finifcns.cpp;h=c27aa98895697cd62efacf4808a6689f4785adea;hp=4ffbe2540726e1f75a79f719595cc816a5152344;hb=0633ed8082961673eedc092689e06fa39d6bc322;hpb=4ef4fe159e18c9ef8aa2702875caf56c9e22f0c2 diff --git a/ginac/inifcns.cpp b/ginac/inifcns.cpp index 4ffbe254..c27aa988 100644 --- a/ginac/inifcns.cpp +++ b/ginac/inifcns.cpp @@ -3,7 +3,7 @@ * Implementation of GiNaC's initially known functions. */ /* - * GiNaC Copyright (C) 1999-2004 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2005 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 @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include @@ -48,7 +48,7 @@ static ex conjugate_evalf(const ex & arg) if (is_exactly_a(arg)) { return ex_to(arg).conjugate(); } - return conjugate(arg).hold(); + return conjugate_function(arg).hold(); } static ex conjugate_eval(const ex & arg) @@ -66,10 +66,11 @@ 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)); +REGISTER_FUNCTION(conjugate_function, eval_func(conjugate_eval). + evalf_func(conjugate_evalf). + print_func(conjugate_print_latex). + conjugate_func(conjugate_conjugate). + set_name("conjugate","conjugate")); ////////// // absolute value @@ -466,6 +467,17 @@ static ex factorial_eval(const ex & x) return factorial(x).hold(); } +static void factorial_print_dflt_latex(const ex & x, const print_context & c) +{ + if (is_exactly_a(x) || + is_exactly_a(x) || + is_exactly_a(x)) { + x.print(c); c.s << "!"; + } else { + c.s << "("; x.print(c); c.s << ")!"; + } +} + static ex factorial_conjugate(const ex & x) { return factorial(x); @@ -473,6 +485,8 @@ static ex factorial_conjugate(const ex & x) REGISTER_FUNCTION(factorial, eval_func(factorial_eval). evalf_func(factorial_evalf). + print_func(factorial_print_dflt_latex). + print_func(factorial_print_dflt_latex). conjugate_func(factorial_conjugate)); ////////// @@ -484,11 +498,32 @@ static ex binomial_evalf(const ex & x, const ex & y) return binomial(x, y).hold(); } +static ex binomial_sym(const ex & x, const numeric & y) +{ + if (y.is_integer()) { + if (y.is_nonneg_integer()) { + const unsigned N = y.to_int(); + if (N == 0) return _num0; + if (N == 1) return x; + ex t = x.expand(); + for (unsigned i = 2; i <= N; ++i) + t = (t * (x + i - y - 1)).expand() / i; + return t; + } else + return _num0; + } + + return binomial(x, y).hold(); +} + static ex binomial_eval(const ex & x, const ex &y) { - if (is_exactly_a(x) && is_exactly_a(y)) - return binomial(ex_to(x), ex_to(y)); - else + if (is_exactly_a(y)) { + if (is_exactly_a(x) && ex_to(x).is_integer()) + return binomial(ex_to(x), ex_to(y)); + else + return binomial_sym(x, ex_to(y)); + } else return binomial(x, y).hold(); }