ginac-1.6.2.orig/0000755000000000000000000000000011655511062010430 5ustar ginac-1.6.2.orig/ginac/0000755000000000000000000000000011655511063011512 5ustar ginac-1.6.2.orig/ginac/expair.cpp0000644000000000000000000000262111562317235013511 0ustar /** @file expair.cpp * * Implementation of expression pairs (building blocks of expairseq). */ /* * GiNaC Copyright (C) 1999-2011 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "expair.h" #include "operators.h" #include namespace GiNaC { void expair::print(std::ostream & os) const { os << "expair:"; print_tree c(os); rest.print(c, c.delta_indent); coeff.print(c, c.delta_indent); } const expair expair::conjugate() const { ex newrest = rest.conjugate(); ex newcoeff = coeff.conjugate(); if (are_ex_trivially_equal(newrest,rest) && are_ex_trivially_equal(newcoeff,coeff)) { return *this; } return expair(newrest, newcoeff); } } // namespace GiNaC ginac-1.6.2.orig/ginac/pseries.h0000644000000000000000000001146611562317236013350 0ustar /** @file pseries.h * * Interface to class for extended truncated power series. */ /* * GiNaC Copyright (C) 1999-2011 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef GINAC_SERIES_H #define GINAC_SERIES_H #include "basic.h" #include "expairseq.h" namespace GiNaC { /** This class holds a extended truncated power series (positive and negative * integer powers). It consists of expression coefficients (only non-zero * coefficients are stored), an expansion variable and an expansion point. * Other classes must provide members to convert into this type. */ class pseries : public basic { GINAC_DECLARE_REGISTERED_CLASS(pseries, basic) // other constructors public: pseries(const ex &rel_, const epvector &ops_); // functions overriding virtual functions from base classes public: unsigned precedence() const {return 38;} // for clarity just below add::precedence size_t nops() const; ex op(size_t i) const; int degree(const ex &s) const; int ldegree(const ex &s) const; ex coeff(const ex &s, int n = 1) const; ex collect(const ex &s, bool distributed = false) const; ex eval(int level=0) const; ex evalf(int level=0) const; ex series(const relational & r, int order, unsigned options = 0) const; ex subs(const exmap & m, unsigned options = 0) const; ex normal(exmap & repl, exmap & rev_lookup, int level = 0) const; ex expand(unsigned options = 0) const; ex conjugate() const; ex real_part() const; ex imag_part() const; ex eval_integ() const; ex evalm() const; /** Save (a.k.a. serialize) object into archive. */ void archive(archive_node& n) const; /** Read (a.k.a. deserialize) object from archive. */ void read_archive(const archive_node& n, lst& syms); protected: ex derivative(const symbol & s) const; // non-virtual functions in this class public: /** Get the expansion variable. */ ex get_var() const {return var;} /** Get the expansion point. */ ex get_point() const {return point;} /** Convert the pseries object to an ordinary polynomial. * * @param no_order flag: discard higher order terms */ ex convert_to_poly(bool no_order = false) const; /** Check whether series is compatible to another series (expansion * variable and point are the same. */ bool is_compatible_to(const pseries &other) const {return var.is_equal(other.var) && point.is_equal(other.point);} /** Check whether series has the value zero. */ bool is_zero() const {return seq.size() == 0;} /** Returns true if there is no order term, i.e. the series terminates and * false otherwise. */ bool is_terminating() const; /** Get coefficients and exponents. */ ex coeffop(size_t i) const; ex exponop(size_t i) const; ex add_series(const pseries &other) const; ex mul_const(const numeric &other) const; ex mul_series(const pseries &other) const; ex power_const(const numeric &p, int deg) const; pseries shift_exponents(int deg) const; protected: void print_series(const print_context & c, const char *openbrace, const char *closebrace, const char *mul_sym, const char *pow_sym, unsigned level) const; void do_print(const print_context & c, unsigned level) const; void do_print_latex(const print_latex & c, unsigned level) const; void do_print_tree(const print_tree & c, unsigned level) const; void do_print_python(const print_python & c, unsigned level) const; void do_print_python_repr(const print_python_repr & c, unsigned level) const; protected: /** Vector of {coefficient, power} pairs */ epvector seq; /** Series variable (holds a symbol) */ ex var; /** Expansion point */ ex point; }; GINAC_DECLARE_UNARCHIVER(pseries); // utility functions /** Convert the pseries object embedded in an expression to an ordinary * polynomial in the expansion variable. The result is undefined if the * expression does not contain a pseries object at its top level. * * @param e expression * @return polynomial expression * @see is_a<> * @see pseries::convert_to_poly */ inline ex series_to_poly(const ex &e) { return (ex_to(e).convert_to_poly(true)); } inline bool is_terminating(const pseries & s) { return s.is_terminating(); } } // namespace GiNaC #endif // ndef GINAC_SERIES_H ginac-1.6.2.orig/ginac/function.cpp0000644000000000000000000016713311600170637014054 0ustar /** @file function.cpp * * Implementation of class of symbolic functions. */ /* * This file was generated automatically by function.pl. * Please do not modify it directly, edit the perl script instead! * function.pl options: $maxargs=14 * * GiNaC Copyright (C) 1999-2011 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "function.h" #include "operators.h" #include "fderivative.h" #include "ex.h" #include "lst.h" #include "symmetry.h" #include "print.h" #include "power.h" #include "archive.h" #include "inifcns.h" #include "tostring.h" #include "utils.h" #include "hash_seed.h" #include "remember.h" #include #include #include #include #include namespace GiNaC { ////////// // helper class function_options ////////// function_options::function_options() { initialize(); } function_options::function_options(std::string const & n, std::string const & tn) { initialize(); set_name(n, tn); } function_options::function_options(std::string const & n, unsigned np) { initialize(); set_name(n, std::string()); nparams = np; } function_options::~function_options() { // nothing to clean up at the moment } void function_options::initialize() { set_name("unnamed_function", "\\mbox{unnamed}"); nparams = 0; eval_f = evalf_f = real_part_f = imag_part_f = conjugate_f = derivative_f = power_f = series_f = 0; evalf_params_first = true; use_return_type = false; eval_use_exvector_args = false; evalf_use_exvector_args = false; conjugate_use_exvector_args = false; real_part_use_exvector_args = false; imag_part_use_exvector_args = false; derivative_use_exvector_args = false; power_use_exvector_args = false; series_use_exvector_args = false; print_use_exvector_args = false; use_remember = false; functions_with_same_name = 1; symtree = 0; } function_options & function_options::set_name(std::string const & n, std::string const & tn) { name = n; if (tn==std::string()) TeX_name = "\\mbox{"+name+"}"; else TeX_name = tn; return *this; } function_options & function_options::latex_name(std::string const & tn) { TeX_name = tn; return *this; } // the following lines have been generated for max. 14 parameters function_options & function_options::eval_func(eval_funcp_1 e) { test_and_set_nparams(1); eval_f = eval_funcp(e); return *this; } function_options & function_options::eval_func(eval_funcp_2 e) { test_and_set_nparams(2); eval_f = eval_funcp(e); return *this; } function_options & function_options::eval_func(eval_funcp_3 e) { test_and_set_nparams(3); eval_f = eval_funcp(e); return *this; } function_options & function_options::eval_func(eval_funcp_4 e) { test_and_set_nparams(4); eval_f = eval_funcp(e); return *this; } function_options & function_options::eval_func(eval_funcp_5 e) { test_and_set_nparams(5); eval_f = eval_funcp(e); return *this; } function_options & function_options::eval_func(eval_funcp_6 e) { test_and_set_nparams(6); eval_f = eval_funcp(e); return *this; } function_options & function_options::eval_func(eval_funcp_7 e) { test_and_set_nparams(7); eval_f = eval_funcp(e); return *this; } function_options & function_options::eval_func(eval_funcp_8 e) { test_and_set_nparams(8); eval_f = eval_funcp(e); return *this; } function_options & function_options::eval_func(eval_funcp_9 e) { test_and_set_nparams(9); eval_f = eval_funcp(e); return *this; } function_options & function_options::eval_func(eval_funcp_10 e) { test_and_set_nparams(10); eval_f = eval_funcp(e); return *this; } function_options & function_options::eval_func(eval_funcp_11 e) { test_and_set_nparams(11); eval_f = eval_funcp(e); return *this; } function_options & function_options::eval_func(eval_funcp_12 e) { test_and_set_nparams(12); eval_f = eval_funcp(e); return *this; } function_options & function_options::eval_func(eval_funcp_13 e) { test_and_set_nparams(13); eval_f = eval_funcp(e); return *this; } function_options & function_options::eval_func(eval_funcp_14 e) { test_and_set_nparams(14); eval_f = eval_funcp(e); return *this; } function_options & function_options::evalf_func(evalf_funcp_1 ef) { test_and_set_nparams(1); evalf_f = evalf_funcp(ef); return *this; } function_options & function_options::evalf_func(evalf_funcp_2 ef) { test_and_set_nparams(2); evalf_f = evalf_funcp(ef); return *this; } function_options & function_options::evalf_func(evalf_funcp_3 ef) { test_and_set_nparams(3); evalf_f = evalf_funcp(ef); return *this; } function_options & function_options::evalf_func(evalf_funcp_4 ef) { test_and_set_nparams(4); evalf_f = evalf_funcp(ef); return *this; } function_options & function_options::evalf_func(evalf_funcp_5 ef) { test_and_set_nparams(5); evalf_f = evalf_funcp(ef); return *this; } function_options & function_options::evalf_func(evalf_funcp_6 ef) { test_and_set_nparams(6); evalf_f = evalf_funcp(ef); return *this; } function_options & function_options::evalf_func(evalf_funcp_7 ef) { test_and_set_nparams(7); evalf_f = evalf_funcp(ef); return *this; } function_options & function_options::evalf_func(evalf_funcp_8 ef) { test_and_set_nparams(8); evalf_f = evalf_funcp(ef); return *this; } function_options & function_options::evalf_func(evalf_funcp_9 ef) { test_and_set_nparams(9); evalf_f = evalf_funcp(ef); return *this; } function_options & function_options::evalf_func(evalf_funcp_10 ef) { test_and_set_nparams(10); evalf_f = evalf_funcp(ef); return *this; } function_options & function_options::evalf_func(evalf_funcp_11 ef) { test_and_set_nparams(11); evalf_f = evalf_funcp(ef); return *this; } function_options & function_options::evalf_func(evalf_funcp_12 ef) { test_and_set_nparams(12); evalf_f = evalf_funcp(ef); return *this; } function_options & function_options::evalf_func(evalf_funcp_13 ef) { test_and_set_nparams(13); evalf_f = evalf_funcp(ef); return *this; } function_options & function_options::evalf_func(evalf_funcp_14 ef) { test_and_set_nparams(14); evalf_f = evalf_funcp(ef); return *this; } function_options & function_options::conjugate_func(conjugate_funcp_1 c) { test_and_set_nparams(1); conjugate_f = conjugate_funcp(c); return *this; } function_options & function_options::conjugate_func(conjugate_funcp_2 c) { test_and_set_nparams(2); conjugate_f = conjugate_funcp(c); return *this; } function_options & function_options::conjugate_func(conjugate_funcp_3 c) { test_and_set_nparams(3); conjugate_f = conjugate_funcp(c); return *this; } function_options & function_options::conjugate_func(conjugate_funcp_4 c) { test_and_set_nparams(4); conjugate_f = conjugate_funcp(c); return *this; } function_options & function_options::conjugate_func(conjugate_funcp_5 c) { test_and_set_nparams(5); conjugate_f = conjugate_funcp(c); return *this; } function_options & function_options::conjugate_func(conjugate_funcp_6 c) { test_and_set_nparams(6); conjugate_f = conjugate_funcp(c); return *this; } function_options & function_options::conjugate_func(conjugate_funcp_7 c) { test_and_set_nparams(7); conjugate_f = conjugate_funcp(c); return *this; } function_options & function_options::conjugate_func(conjugate_funcp_8 c) { test_and_set_nparams(8); conjugate_f = conjugate_funcp(c); return *this; } function_options & function_options::conjugate_func(conjugate_funcp_9 c) { test_and_set_nparams(9); conjugate_f = conjugate_funcp(c); return *this; } function_options & function_options::conjugate_func(conjugate_funcp_10 c) { test_and_set_nparams(10); conjugate_f = conjugate_funcp(c); return *this; } function_options & function_options::conjugate_func(conjugate_funcp_11 c) { test_and_set_nparams(11); conjugate_f = conjugate_funcp(c); return *this; } function_options & function_options::conjugate_func(conjugate_funcp_12 c) { test_and_set_nparams(12); conjugate_f = conjugate_funcp(c); return *this; } function_options & function_options::conjugate_func(conjugate_funcp_13 c) { test_and_set_nparams(13); conjugate_f = conjugate_funcp(c); return *this; } function_options & function_options::conjugate_func(conjugate_funcp_14 c) { test_and_set_nparams(14); conjugate_f = conjugate_funcp(c); return *this; } function_options & function_options::real_part_func(real_part_funcp_1 c) { test_and_set_nparams(1); real_part_f = real_part_funcp(c); return *this; } function_options & function_options::real_part_func(real_part_funcp_2 c) { test_and_set_nparams(2); real_part_f = real_part_funcp(c); return *this; } function_options & function_options::real_part_func(real_part_funcp_3 c) { test_and_set_nparams(3); real_part_f = real_part_funcp(c); return *this; } function_options & function_options::real_part_func(real_part_funcp_4 c) { test_and_set_nparams(4); real_part_f = real_part_funcp(c); return *this; } function_options & function_options::real_part_func(real_part_funcp_5 c) { test_and_set_nparams(5); real_part_f = real_part_funcp(c); return *this; } function_options & function_options::real_part_func(real_part_funcp_6 c) { test_and_set_nparams(6); real_part_f = real_part_funcp(c); return *this; } function_options & function_options::real_part_func(real_part_funcp_7 c) { test_and_set_nparams(7); real_part_f = real_part_funcp(c); return *this; } function_options & function_options::real_part_func(real_part_funcp_8 c) { test_and_set_nparams(8); real_part_f = real_part_funcp(c); return *this; } function_options & function_options::real_part_func(real_part_funcp_9 c) { test_and_set_nparams(9); real_part_f = real_part_funcp(c); return *this; } function_options & function_options::real_part_func(real_part_funcp_10 c) { test_and_set_nparams(10); real_part_f = real_part_funcp(c); return *this; } function_options & function_options::real_part_func(real_part_funcp_11 c) { test_and_set_nparams(11); real_part_f = real_part_funcp(c); return *this; } function_options & function_options::real_part_func(real_part_funcp_12 c) { test_and_set_nparams(12); real_part_f = real_part_funcp(c); return *this; } function_options & function_options::real_part_func(real_part_funcp_13 c) { test_and_set_nparams(13); real_part_f = real_part_funcp(c); return *this; } function_options & function_options::real_part_func(real_part_funcp_14 c) { test_and_set_nparams(14); real_part_f = real_part_funcp(c); return *this; } function_options & function_options::imag_part_func(imag_part_funcp_1 c) { test_and_set_nparams(1); imag_part_f = imag_part_funcp(c); return *this; } function_options & function_options::imag_part_func(imag_part_funcp_2 c) { test_and_set_nparams(2); imag_part_f = imag_part_funcp(c); return *this; } function_options & function_options::imag_part_func(imag_part_funcp_3 c) { test_and_set_nparams(3); imag_part_f = imag_part_funcp(c); return *this; } function_options & function_options::imag_part_func(imag_part_funcp_4 c) { test_and_set_nparams(4); imag_part_f = imag_part_funcp(c); return *this; } function_options & function_options::imag_part_func(imag_part_funcp_5 c) { test_and_set_nparams(5); imag_part_f = imag_part_funcp(c); return *this; } function_options & function_options::imag_part_func(imag_part_funcp_6 c) { test_and_set_nparams(6); imag_part_f = imag_part_funcp(c); return *this; } function_options & function_options::imag_part_func(imag_part_funcp_7 c) { test_and_set_nparams(7); imag_part_f = imag_part_funcp(c); return *this; } function_options & function_options::imag_part_func(imag_part_funcp_8 c) { test_and_set_nparams(8); imag_part_f = imag_part_funcp(c); return *this; } function_options & function_options::imag_part_func(imag_part_funcp_9 c) { test_and_set_nparams(9); imag_part_f = imag_part_funcp(c); return *this; } function_options & function_options::imag_part_func(imag_part_funcp_10 c) { test_and_set_nparams(10); imag_part_f = imag_part_funcp(c); return *this; } function_options & function_options::imag_part_func(imag_part_funcp_11 c) { test_and_set_nparams(11); imag_part_f = imag_part_funcp(c); return *this; } function_options & function_options::imag_part_func(imag_part_funcp_12 c) { test_and_set_nparams(12); imag_part_f = imag_part_funcp(c); return *this; } function_options & function_options::imag_part_func(imag_part_funcp_13 c) { test_and_set_nparams(13); imag_part_f = imag_part_funcp(c); return *this; } function_options & function_options::imag_part_func(imag_part_funcp_14 c) { test_and_set_nparams(14); imag_part_f = imag_part_funcp(c); return *this; } function_options & function_options::derivative_func(derivative_funcp_1 d) { test_and_set_nparams(1); derivative_f = derivative_funcp(d); return *this; } function_options & function_options::derivative_func(derivative_funcp_2 d) { test_and_set_nparams(2); derivative_f = derivative_funcp(d); return *this; } function_options & function_options::derivative_func(derivative_funcp_3 d) { test_and_set_nparams(3); derivative_f = derivative_funcp(d); return *this; } function_options & function_options::derivative_func(derivative_funcp_4 d) { test_and_set_nparams(4); derivative_f = derivative_funcp(d); return *this; } function_options & function_options::derivative_func(derivative_funcp_5 d) { test_and_set_nparams(5); derivative_f = derivative_funcp(d); return *this; } function_options & function_options::derivative_func(derivative_funcp_6 d) { test_and_set_nparams(6); derivative_f = derivative_funcp(d); return *this; } function_options & function_options::derivative_func(derivative_funcp_7 d) { test_and_set_nparams(7); derivative_f = derivative_funcp(d); return *this; } function_options & function_options::derivative_func(derivative_funcp_8 d) { test_and_set_nparams(8); derivative_f = derivative_funcp(d); return *this; } function_options & function_options::derivative_func(derivative_funcp_9 d) { test_and_set_nparams(9); derivative_f = derivative_funcp(d); return *this; } function_options & function_options::derivative_func(derivative_funcp_10 d) { test_and_set_nparams(10); derivative_f = derivative_funcp(d); return *this; } function_options & function_options::derivative_func(derivative_funcp_11 d) { test_and_set_nparams(11); derivative_f = derivative_funcp(d); return *this; } function_options & function_options::derivative_func(derivative_funcp_12 d) { test_and_set_nparams(12); derivative_f = derivative_funcp(d); return *this; } function_options & function_options::derivative_func(derivative_funcp_13 d) { test_and_set_nparams(13); derivative_f = derivative_funcp(d); return *this; } function_options & function_options::derivative_func(derivative_funcp_14 d) { test_and_set_nparams(14); derivative_f = derivative_funcp(d); return *this; } function_options & function_options::power_func(power_funcp_1 d) { test_and_set_nparams(1); power_f = power_funcp(d); return *this; } function_options & function_options::power_func(power_funcp_2 d) { test_and_set_nparams(2); power_f = power_funcp(d); return *this; } function_options & function_options::power_func(power_funcp_3 d) { test_and_set_nparams(3); power_f = power_funcp(d); return *this; } function_options & function_options::power_func(power_funcp_4 d) { test_and_set_nparams(4); power_f = power_funcp(d); return *this; } function_options & function_options::power_func(power_funcp_5 d) { test_and_set_nparams(5); power_f = power_funcp(d); return *this; } function_options & function_options::power_func(power_funcp_6 d) { test_and_set_nparams(6); power_f = power_funcp(d); return *this; } function_options & function_options::power_func(power_funcp_7 d) { test_and_set_nparams(7); power_f = power_funcp(d); return *this; } function_options & function_options::power_func(power_funcp_8 d) { test_and_set_nparams(8); power_f = power_funcp(d); return *this; } function_options & function_options::power_func(power_funcp_9 d) { test_and_set_nparams(9); power_f = power_funcp(d); return *this; } function_options & function_options::power_func(power_funcp_10 d) { test_and_set_nparams(10); power_f = power_funcp(d); return *this; } function_options & function_options::power_func(power_funcp_11 d) { test_and_set_nparams(11); power_f = power_funcp(d); return *this; } function_options & function_options::power_func(power_funcp_12 d) { test_and_set_nparams(12); power_f = power_funcp(d); return *this; } function_options & function_options::power_func(power_funcp_13 d) { test_and_set_nparams(13); power_f = power_funcp(d); return *this; } function_options & function_options::power_func(power_funcp_14 d) { test_and_set_nparams(14); power_f = power_funcp(d); return *this; } function_options & function_options::series_func(series_funcp_1 s) { test_and_set_nparams(1); series_f = series_funcp(s); return *this; } function_options & function_options::series_func(series_funcp_2 s) { test_and_set_nparams(2); series_f = series_funcp(s); return *this; } function_options & function_options::series_func(series_funcp_3 s) { test_and_set_nparams(3); series_f = series_funcp(s); return *this; } function_options & function_options::series_func(series_funcp_4 s) { test_and_set_nparams(4); series_f = series_funcp(s); return *this; } function_options & function_options::series_func(series_funcp_5 s) { test_and_set_nparams(5); series_f = series_funcp(s); return *this; } function_options & function_options::series_func(series_funcp_6 s) { test_and_set_nparams(6); series_f = series_funcp(s); return *this; } function_options & function_options::series_func(series_funcp_7 s) { test_and_set_nparams(7); series_f = series_funcp(s); return *this; } function_options & function_options::series_func(series_funcp_8 s) { test_and_set_nparams(8); series_f = series_funcp(s); return *this; } function_options & function_options::series_func(series_funcp_9 s) { test_and_set_nparams(9); series_f = series_funcp(s); return *this; } function_options & function_options::series_func(series_funcp_10 s) { test_and_set_nparams(10); series_f = series_funcp(s); return *this; } function_options & function_options::series_func(series_funcp_11 s) { test_and_set_nparams(11); series_f = series_funcp(s); return *this; } function_options & function_options::series_func(series_funcp_12 s) { test_and_set_nparams(12); series_f = series_funcp(s); return *this; } function_options & function_options::series_func(series_funcp_13 s) { test_and_set_nparams(13); series_f = series_funcp(s); return *this; } function_options & function_options::series_func(series_funcp_14 s) { test_and_set_nparams(14); series_f = series_funcp(s); return *this; } // end of generated lines function_options& function_options::eval_func(eval_funcp_exvector e) { eval_use_exvector_args = true; eval_f = eval_funcp(e); return *this; } function_options& function_options::evalf_func(evalf_funcp_exvector ef) { evalf_use_exvector_args = true; evalf_f = evalf_funcp(ef); return *this; } function_options& function_options::conjugate_func(conjugate_funcp_exvector c) { conjugate_use_exvector_args = true; conjugate_f = conjugate_funcp(c); return *this; } function_options& function_options::real_part_func(real_part_funcp_exvector c) { real_part_use_exvector_args = true; real_part_f = real_part_funcp(c); return *this; } function_options& function_options::imag_part_func(imag_part_funcp_exvector c) { imag_part_use_exvector_args = true; imag_part_f = imag_part_funcp(c); return *this; } function_options& function_options::derivative_func(derivative_funcp_exvector d) { derivative_use_exvector_args = true; derivative_f = derivative_funcp(d); return *this; } function_options& function_options::power_func(power_funcp_exvector d) { power_use_exvector_args = true; power_f = power_funcp(d); return *this; } function_options& function_options::series_func(series_funcp_exvector s) { series_use_exvector_args = true; series_f = series_funcp(s); return *this; } function_options & function_options::set_return_type(unsigned rt, const return_type_t* rtt) { use_return_type = true; return_type = rt; if (rtt != 0) return_type_tinfo = *rtt; else return_type_tinfo = make_return_type_t(); return *this; } function_options & function_options::do_not_evalf_params() { evalf_params_first = false; return *this; } function_options & function_options::remember(unsigned size, unsigned assoc_size, unsigned strategy) { use_remember = true; remember_size = size; remember_assoc_size = assoc_size; remember_strategy = strategy; return *this; } function_options & function_options::overloaded(unsigned o) { functions_with_same_name = o; return *this; } function_options & function_options::set_symmetry(const symmetry & s) { symtree = s; return *this; } void function_options::test_and_set_nparams(unsigned n) { if (nparams==0) { nparams = n; } else if (nparams!=n) { // we do not throw an exception here because this code is // usually executed before main(), so the exception could not // be caught anyhow std::cerr << "WARNING: " << name << "(): number of parameters (" << n << ") differs from number set before (" << nparams << ")" << std::endl; } } void function_options::set_print_func(unsigned id, print_funcp f) { if (id >= print_dispatch_table.size()) print_dispatch_table.resize(id + 1); print_dispatch_table[id] = f; } /** This can be used as a hook for external applications. */ unsigned function::current_serial = 0; GINAC_IMPLEMENT_REGISTERED_CLASS(function, exprseq) ////////// // default constructor ////////// // public function::function() : serial(0) { } ////////// // other constructors ////////// // public function::function(unsigned ser) : serial(ser) { } // the following lines have been generated for max. 14 parameters function::function(unsigned ser, const ex & param1) : exprseq(param1), serial(ser) { } function::function(unsigned ser, const ex & param1, const ex & param2) : exprseq(param1, param2), serial(ser) { } function::function(unsigned ser, const ex & param1, const ex & param2, const ex & param3) : exprseq(param1, param2, param3), serial(ser) { } function::function(unsigned ser, const ex & param1, const ex & param2, const ex & param3, const ex & param4) : exprseq(param1, param2, param3, param4), serial(ser) { } function::function(unsigned ser, const ex & param1, const ex & param2, const ex & param3, const ex & param4, const ex & param5) : exprseq(param1, param2, param3, param4, param5), serial(ser) { } function::function(unsigned ser, const ex & param1, const ex & param2, const ex & param3, const ex & param4, const ex & param5, const ex & param6) : exprseq(param1, param2, param3, param4, param5, param6), serial(ser) { } function::function(unsigned ser, const ex & param1, const ex & param2, const ex & param3, const ex & param4, const ex & param5, const ex & param6, const ex & param7) : exprseq(param1, param2, param3, param4, param5, param6, param7), serial(ser) { } function::function(unsigned ser, const ex & param1, const ex & param2, const ex & param3, const ex & param4, const ex & param5, const ex & param6, const ex & param7, const ex & param8) : exprseq(param1, param2, param3, param4, param5, param6, param7, param8), serial(ser) { } function::function(unsigned ser, const ex & param1, const ex & param2, const ex & param3, const ex & param4, const ex & param5, const ex & param6, const ex & param7, const ex & param8, const ex & param9) : exprseq(param1, param2, param3, param4, param5, param6, param7, param8, param9), serial(ser) { } function::function(unsigned ser, const ex & param1, const ex & param2, const ex & param3, const ex & param4, const ex & param5, const ex & param6, const ex & param7, const ex & param8, const ex & param9, const ex & param10) : exprseq(param1, param2, param3, param4, param5, param6, param7, param8, param9, param10), serial(ser) { } function::function(unsigned ser, const ex & param1, const ex & param2, const ex & param3, const ex & param4, const ex & param5, const ex & param6, const ex & param7, const ex & param8, const ex & param9, const ex & param10, const ex & param11) : exprseq(param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11), serial(ser) { } function::function(unsigned ser, const ex & param1, const ex & param2, const ex & param3, const ex & param4, const ex & param5, const ex & param6, const ex & param7, const ex & param8, const ex & param9, const ex & param10, const ex & param11, const ex & param12) : exprseq(param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12), serial(ser) { } function::function(unsigned ser, const ex & param1, const ex & param2, const ex & param3, const ex & param4, const ex & param5, const ex & param6, const ex & param7, const ex & param8, const ex & param9, const ex & param10, const ex & param11, const ex & param12, const ex & param13) : exprseq(param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13), serial(ser) { } function::function(unsigned ser, const ex & param1, const ex & param2, const ex & param3, const ex & param4, const ex & param5, const ex & param6, const ex & param7, const ex & param8, const ex & param9, const ex & param10, const ex & param11, const ex & param12, const ex & param13, const ex & param14) : exprseq(param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14), serial(ser) { } // end of generated lines function::function(unsigned ser, const exprseq & es) : exprseq(es), serial(ser) { // Force re-evaluation even if the exprseq was already evaluated // (the exprseq copy constructor copies the flags) clearflag(status_flags::evaluated); } function::function(unsigned ser, const exvector & v, bool discardable) : exprseq(v,discardable), serial(ser) { if ( ser >= registered_functions().size() ) { throw std::runtime_error("function does not exist"); } } function::function(unsigned ser, std::auto_ptr vp) : exprseq(vp), serial(ser) { } ////////// // archiving ////////// /** Construct object from archive_node. */ void function::read_archive(const archive_node& n, lst& sym_lst) { inherited::read_archive(n, sym_lst); // Find serial number by function name std::string s; if (n.find_string("name", s)) { unsigned int ser = 0; std::vector::const_iterator i = registered_functions().begin(), iend = registered_functions().end(); while (i != iend) { if (s == i->name) { serial = ser; return; } ++i; ++ser; } throw (std::runtime_error("unknown function '" + s + "' in archive")); } else throw (std::runtime_error("unnamed function in archive")); } /** Archive the object. */ void function::archive(archive_node &n) const { inherited::archive(n); GINAC_ASSERT(serial < registered_functions().size()); n.add_string("name", registered_functions()[serial].name); } GINAC_BIND_UNARCHIVER(function); ////////// // functions overriding virtual functions from base classes ////////// // public void function::print(const print_context & c, unsigned level) const { GINAC_ASSERT(serial &pdt = opt.print_dispatch_table; // Dynamically dispatch on print_context type const print_context_class_info *pc_info = &c.get_class_info(); next_context: unsigned id = pc_info->options.get_id(); if (id >= pdt.size() || pdt[id] == NULL) { // Method not found, try parent print_context class const print_context_class_info *parent_pc_info = pc_info->get_parent(); if (parent_pc_info) { pc_info = parent_pc_info; goto next_context; } // Method still not found, use default output if (is_a(c)) { c.s << std::string(level, ' ') << class_name() << " " << opt.name << " @" << this << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec << ", nops=" << nops() << std::endl; unsigned delta_indent = static_cast(c).delta_indent; for (size_t i=0; i(c)) { // Print function name in lowercase std::string lname = opt.name; size_t num = lname.size(); for (size_t i=0; i(c)) { c.s << opt.TeX_name; printseq(c, '(', ',', ')', exprseq::precedence(), function::precedence()); } else { c.s << opt.name; printseq(c, '(', ',', ')', exprseq::precedence(), function::precedence()); } } else { // Method found, call it current_serial = serial; if (opt.print_use_exvector_args) ((print_funcp_exvector)pdt[id])(seq, c); else switch (opt.nparams) { // the following lines have been generated for max. 14 parameters case 1: ((print_funcp_1)(pdt[id]))(seq[1-1], c); break; case 2: ((print_funcp_2)(pdt[id]))(seq[1-1], seq[2-1], c); break; case 3: ((print_funcp_3)(pdt[id]))(seq[1-1], seq[2-1], seq[3-1], c); break; case 4: ((print_funcp_4)(pdt[id]))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], c); break; case 5: ((print_funcp_5)(pdt[id]))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], c); break; case 6: ((print_funcp_6)(pdt[id]))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], c); break; case 7: ((print_funcp_7)(pdt[id]))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1], c); break; case 8: ((print_funcp_8)(pdt[id]))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1], seq[8-1], c); break; case 9: ((print_funcp_9)(pdt[id]))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1], seq[8-1], seq[9-1], c); break; case 10: ((print_funcp_10)(pdt[id]))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1], seq[8-1], seq[9-1], seq[10-1], c); break; case 11: ((print_funcp_11)(pdt[id]))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1], seq[8-1], seq[9-1], seq[10-1], seq[11-1], c); break; case 12: ((print_funcp_12)(pdt[id]))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1], seq[8-1], seq[9-1], seq[10-1], seq[11-1], seq[12-1], c); break; case 13: ((print_funcp_13)(pdt[id]))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1], seq[8-1], seq[9-1], seq[10-1], seq[11-1], seq[12-1], seq[13-1], c); break; case 14: ((print_funcp_14)(pdt[id]))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1], seq[8-1], seq[9-1], seq[10-1], seq[11-1], seq[12-1], seq[13-1], seq[14-1], c); break; // end of generated lines default: throw(std::logic_error("function::print(): invalid nparams")); } } } ex function::expand(unsigned options) const { // Only expand arguments when asked to do so if (options & expand_options::expand_function_args) return inherited::expand(options); else return (options == 0) ? setflag(status_flags::expanded) : *this; } ex function::eval(int level) const { if (level>1) { // first evaluate children, then we will end up here again return function(serial,evalchildren(level)); } GINAC_ASSERT(serial 1 && !(opt.symtree.is_zero())) { exvector v = seq; GINAC_ASSERT(is_a(opt.symtree)); int sig = canonicalize(v.begin(), ex_to(opt.symtree)); if (sig != std::numeric_limits::max()) { // Something has changed while sorting arguments, more evaluations later if (sig == 0) return _ex0; return ex(sig) * thiscontainer(v); } } if (opt.eval_f==0) { return this->hold(); } bool use_remember = opt.use_remember; ex eval_result; if (use_remember && lookup_remember_table(eval_result)) { return eval_result; } current_serial = serial; if (opt.eval_use_exvector_args) eval_result = ((eval_funcp_exvector)(opt.eval_f))(seq); else switch (opt.nparams) { // the following lines have been generated for max. 14 parameters case 1: eval_result = ((eval_funcp_1)(opt.eval_f))(seq[1-1]); break; case 2: eval_result = ((eval_funcp_2)(opt.eval_f))(seq[1-1], seq[2-1]); break; case 3: eval_result = ((eval_funcp_3)(opt.eval_f))(seq[1-1], seq[2-1], seq[3-1]); break; case 4: eval_result = ((eval_funcp_4)(opt.eval_f))(seq[1-1], seq[2-1], seq[3-1], seq[4-1]); break; case 5: eval_result = ((eval_funcp_5)(opt.eval_f))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1]); break; case 6: eval_result = ((eval_funcp_6)(opt.eval_f))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1]); break; case 7: eval_result = ((eval_funcp_7)(opt.eval_f))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1]); break; case 8: eval_result = ((eval_funcp_8)(opt.eval_f))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1], seq[8-1]); break; case 9: eval_result = ((eval_funcp_9)(opt.eval_f))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1], seq[8-1], seq[9-1]); break; case 10: eval_result = ((eval_funcp_10)(opt.eval_f))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1], seq[8-1], seq[9-1], seq[10-1]); break; case 11: eval_result = ((eval_funcp_11)(opt.eval_f))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1], seq[8-1], seq[9-1], seq[10-1], seq[11-1]); break; case 12: eval_result = ((eval_funcp_12)(opt.eval_f))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1], seq[8-1], seq[9-1], seq[10-1], seq[11-1], seq[12-1]); break; case 13: eval_result = ((eval_funcp_13)(opt.eval_f))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1], seq[8-1], seq[9-1], seq[10-1], seq[11-1], seq[12-1], seq[13-1]); break; case 14: eval_result = ((eval_funcp_14)(opt.eval_f))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1], seq[8-1], seq[9-1], seq[10-1], seq[11-1], seq[12-1], seq[13-1], seq[14-1]); break; // end of generated lines default: throw(std::logic_error("function::eval(): invalid nparams")); } if (use_remember) { store_remember_table(eval_result); } return eval_result; } ex function::evalf(int level) const { GINAC_ASSERT(serialevalf(level)); ++it; } } if (opt.evalf_f==0) { return function(serial,eseq).hold(); } current_serial = serial; if (opt.evalf_use_exvector_args) return ((evalf_funcp_exvector)(opt.evalf_f))(seq); switch (opt.nparams) { // the following lines have been generated for max. 14 parameters case 1: return ((evalf_funcp_1)(opt.evalf_f))(eseq[1-1]); case 2: return ((evalf_funcp_2)(opt.evalf_f))(eseq[1-1], eseq[2-1]); case 3: return ((evalf_funcp_3)(opt.evalf_f))(eseq[1-1], eseq[2-1], eseq[3-1]); case 4: return ((evalf_funcp_4)(opt.evalf_f))(eseq[1-1], eseq[2-1], eseq[3-1], eseq[4-1]); case 5: return ((evalf_funcp_5)(opt.evalf_f))(eseq[1-1], eseq[2-1], eseq[3-1], eseq[4-1], eseq[5-1]); case 6: return ((evalf_funcp_6)(opt.evalf_f))(eseq[1-1], eseq[2-1], eseq[3-1], eseq[4-1], eseq[5-1], eseq[6-1]); case 7: return ((evalf_funcp_7)(opt.evalf_f))(eseq[1-1], eseq[2-1], eseq[3-1], eseq[4-1], eseq[5-1], eseq[6-1], eseq[7-1]); case 8: return ((evalf_funcp_8)(opt.evalf_f))(eseq[1-1], eseq[2-1], eseq[3-1], eseq[4-1], eseq[5-1], eseq[6-1], eseq[7-1], eseq[8-1]); case 9: return ((evalf_funcp_9)(opt.evalf_f))(eseq[1-1], eseq[2-1], eseq[3-1], eseq[4-1], eseq[5-1], eseq[6-1], eseq[7-1], eseq[8-1], eseq[9-1]); case 10: return ((evalf_funcp_10)(opt.evalf_f))(eseq[1-1], eseq[2-1], eseq[3-1], eseq[4-1], eseq[5-1], eseq[6-1], eseq[7-1], eseq[8-1], eseq[9-1], eseq[10-1]); case 11: return ((evalf_funcp_11)(opt.evalf_f))(eseq[1-1], eseq[2-1], eseq[3-1], eseq[4-1], eseq[5-1], eseq[6-1], eseq[7-1], eseq[8-1], eseq[9-1], eseq[10-1], eseq[11-1]); case 12: return ((evalf_funcp_12)(opt.evalf_f))(eseq[1-1], eseq[2-1], eseq[3-1], eseq[4-1], eseq[5-1], eseq[6-1], eseq[7-1], eseq[8-1], eseq[9-1], eseq[10-1], eseq[11-1], eseq[12-1]); case 13: return ((evalf_funcp_13)(opt.evalf_f))(eseq[1-1], eseq[2-1], eseq[3-1], eseq[4-1], eseq[5-1], eseq[6-1], eseq[7-1], eseq[8-1], eseq[9-1], eseq[10-1], eseq[11-1], eseq[12-1], eseq[13-1]); case 14: return ((evalf_funcp_14)(opt.evalf_f))(eseq[1-1], eseq[2-1], eseq[3-1], eseq[4-1], eseq[5-1], eseq[6-1], eseq[7-1], eseq[8-1], eseq[9-1], eseq[10-1], eseq[11-1], eseq[12-1], eseq[13-1], eseq[14-1]); // end of generated lines } throw(std::logic_error("function::evalf(): invalid nparams")); } /** * This method is defined to be in line with behaviour of function::return_type() */ ex function::eval_ncmul(const exvector & v) const { // If this function is called then the list of arguments is non-empty // and the first argument is non-commutative, see function::return_type() return seq.begin()->eval_ncmul(v); } unsigned function::calchash() const { unsigned v = golden_ratio_hash(make_hash_seed(typeid(*this)) ^ serial); for (size_t i=0; iop(i).gethash(); } if (flags & status_flags::evaluated) { setflag(status_flags::hash_calculated); hashvalue = v; } return v; } ex function::thiscontainer(const exvector & v) const { return function(serial, v); } ex function::thiscontainer(std::auto_ptr vp) const { return function(serial, vp); } /** Implementation of ex::series for functions. * @see ex::series */ ex function::series(const relational & r, int order, unsigned options) const { GINAC_ASSERT(serial(other)); const function & o = static_cast(other); if (serial != o.serial) return serial < o.serial ? -1 : 1; else return exprseq::compare_same_type(o); } bool function::is_equal_same_type(const basic & other) const { GINAC_ASSERT(is_a(other)); const function & o = static_cast(other); if (serial != o.serial) return false; else return exprseq::is_equal_same_type(o); } bool function::match_same_type(const basic & other) const { GINAC_ASSERT(is_a(other)); const function & o = static_cast(other); return serial == o.serial; } unsigned function::return_type() const { GINAC_ASSERT(serialreturn_type(); } } return_type_t function::return_type_tinfo() const { GINAC_ASSERT(serial(); else return seq.begin()->return_type_tinfo(); } } ////////// // new virtual functions which can be overridden by derived classes ////////// // none ////////// // non-virtual functions in this class ////////// // protected ex function::pderivative(unsigned diff_param) const // partial differentiation { GINAC_ASSERT(serialsetflag(status_flags::dynallocated | status_flags::evaluated); current_serial = serial; if (opt.power_use_exvector_args) return ((power_funcp_exvector)(opt.power_f))(seq, power_param); switch (opt.nparams) { // the following lines have been generated for max. 14 parameters case 1: return ((power_funcp_1)(opt.power_f))(seq[1-1],power_param); case 2: return ((power_funcp_2)(opt.power_f))(seq[1-1], seq[2-1],power_param); case 3: return ((power_funcp_3)(opt.power_f))(seq[1-1], seq[2-1], seq[3-1],power_param); case 4: return ((power_funcp_4)(opt.power_f))(seq[1-1], seq[2-1], seq[3-1], seq[4-1],power_param); case 5: return ((power_funcp_5)(opt.power_f))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1],power_param); case 6: return ((power_funcp_6)(opt.power_f))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1],power_param); case 7: return ((power_funcp_7)(opt.power_f))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1],power_param); case 8: return ((power_funcp_8)(opt.power_f))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1], seq[8-1],power_param); case 9: return ((power_funcp_9)(opt.power_f))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1], seq[8-1], seq[9-1],power_param); case 10: return ((power_funcp_10)(opt.power_f))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1], seq[8-1], seq[9-1], seq[10-1],power_param); case 11: return ((power_funcp_11)(opt.power_f))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1], seq[8-1], seq[9-1], seq[10-1], seq[11-1],power_param); case 12: return ((power_funcp_12)(opt.power_f))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1], seq[8-1], seq[9-1], seq[10-1], seq[11-1], seq[12-1],power_param); case 13: return ((power_funcp_13)(opt.power_f))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1], seq[8-1], seq[9-1], seq[10-1], seq[11-1], seq[12-1], seq[13-1],power_param); case 14: return ((power_funcp_14)(opt.power_f))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1], seq[8-1], seq[9-1], seq[10-1], seq[11-1], seq[12-1], seq[13-1], seq[14-1],power_param); // end of generated lines } throw(std::logic_error("function::power(): no power function defined")); } std::vector & function::registered_functions() { static std::vector rf = std::vector(); return rf; } bool function::lookup_remember_table(ex & result) const { return remember_table::remember_tables()[this->serial].lookup_entry(*this,result); } void function::store_remember_table(ex const & result) const { remember_table::remember_tables()[this->serial].add_entry(*this,result); } // public unsigned function::register_new(function_options const & opt) { size_t same_name = 0; for (size_t i=0; i=opt.functions_with_same_name) { // we do not throw an exception here because this code is // usually executed before main(), so the exception could not // caught anyhow std::cerr << "WARNING: function name " << opt.name << " already in use!" << std::endl; } registered_functions().push_back(opt); if (opt.use_remember) { remember_table::remember_tables(). push_back(remember_table(opt.remember_size, opt.remember_assoc_size, opt.remember_strategy)); } else { remember_table::remember_tables().push_back(remember_table()); } return registered_functions().size()-1; } /** Find serial number of function by name and number of parameters. * Throws exception if function was not found. */ unsigned function::find_function(const std::string &name, unsigned nparams) { std::vector::const_iterator i = function::registered_functions().begin(), end = function::registered_functions().end(); unsigned serial = 0; while (i != end) { if (i->get_name() == name && i->get_nparams() == nparams) return serial; ++i; ++serial; } throw (std::runtime_error("no function '" + name + "' with " + ToString(nparams) + " parameters defined")); } /** Return the print name of the function. */ std::string function::get_name() const { if ( serial >= registered_functions().size() ) { throw std::runtime_error("unknown function"); } return registered_functions()[serial].name; } } // namespace GiNaC ginac-1.6.2.orig/ginac/integral.cpp0000644000000000000000000002670411562317235014036 0ustar /** @file integral.cpp * * Implementation of GiNaC's symbolic integral. */ /* * GiNaC Copyright (C) 1999-2011 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "integral.h" #include "numeric.h" #include "symbol.h" #include "add.h" #include "mul.h" #include "power.h" #include "inifcns.h" #include "wildcard.h" #include "archive.h" #include "registrar.h" #include "utils.h" #include "operators.h" #include "relational.h" using namespace std; namespace GiNaC { GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(integral, basic, print_func(&integral::do_print). print_func(&integral::do_print_latex)) ////////// // default constructor ////////// integral::integral() : x((new symbol())->setflag(status_flags::dynallocated)) {} ////////// // other constructors ////////// // public integral::integral(const ex & x_, const ex & a_, const ex & b_, const ex & f_) : x(x_), a(a_), b(b_), f(f_) { if (!is_a(x)) { throw(std::invalid_argument("first argument of integral must be of type symbol")); } } ////////// // archiving ////////// void integral::read_archive(const archive_node& n, lst& sym_lst) { inherited::read_archive(n, sym_lst); n.find_ex("x", x, sym_lst); n.find_ex("a", a, sym_lst); n.find_ex("b", b, sym_lst); n.find_ex("f", f, sym_lst); } void integral::archive(archive_node & n) const { inherited::archive(n); n.add_ex("x", x); n.add_ex("a", a); n.add_ex("b", b); n.add_ex("f", f); } ////////// // functions overriding virtual functions from base classes ////////// void integral::do_print(const print_context & c, unsigned level) const { c.s << "integral("; x.print(c); c.s << ","; a.print(c); c.s << ","; b.print(c); c.s << ","; f.print(c); c.s << ")"; } void integral::do_print_latex(const print_latex & c, unsigned level) const { string varname = ex_to(x).get_name(); if (level > precedence()) c.s << "\\left("; c.s << "\\int_{"; a.print(c); c.s << "}^{"; b.print(c); c.s << "} d"; if (varname.size() > 1) c.s << "\\," << varname << "\\:"; else c.s << varname << "\\,"; f.print(c,precedence()); if (level > precedence()) c.s << "\\right)"; } int integral::compare_same_type(const basic & other) const { GINAC_ASSERT(is_exactly_a(other)); const integral &o = static_cast(other); int cmpval = x.compare(o.x); if (cmpval) return cmpval; cmpval = a.compare(o.a); if (cmpval) return cmpval; cmpval = b.compare(o.b); if (cmpval) return cmpval; return f.compare(o.f); } ex integral::eval(int level) const { if ((level==1) && (flags & status_flags::evaluated)) return *this; if (level == -max_recursion_level) throw(std::runtime_error("max recursion level reached")); ex eintvar = (level==1) ? x : x.eval(level-1); ex ea = (level==1) ? a : a.eval(level-1); ex eb = (level==1) ? b : b.eval(level-1); ex ef = (level==1) ? f : f.eval(level-1); if (!ef.has(eintvar) && !haswild(ef)) return eb*ef-ea*ef; if (ea==eb) return _ex0; if (are_ex_trivially_equal(eintvar,x) && are_ex_trivially_equal(ea,a) && are_ex_trivially_equal(eb,b) && are_ex_trivially_equal(ef,f)) return this->hold(); return (new integral(eintvar, ea, eb, ef)) ->setflag(status_flags::dynallocated | status_flags::evaluated); } ex integral::evalf(int level) const { ex ea; ex eb; ex ef; if (level==1) { ea = a; eb = b; ef = f; } else if (level == -max_recursion_level) { throw(runtime_error("max recursion level reached")); } else { ea = a.evalf(level-1); eb = b.evalf(level-1); ef = f.evalf(level-1); } // 12.34 is just an arbitrary number used to check whether a number // results after subsituting a number for the integration variable. if (is_exactly_a(ea) && is_exactly_a(eb) && is_exactly_a(ef.subs(x==12.34).evalf())) { return adaptivesimpson(x, ea, eb, ef); } if (are_ex_trivially_equal(a, ea) && are_ex_trivially_equal(b, eb) && are_ex_trivially_equal(f, ef)) return *this; else return (new integral(x, ea, eb, ef)) ->setflag(status_flags::dynallocated); } int integral::max_integration_level = 15; ex integral::relative_integration_error = 1e-8; ex subsvalue(const ex & var, const ex & value, const ex & fun) { ex result = fun.subs(var==value).evalf(); if (is_a(result)) return result; throw logic_error("integrand does not evaluate to numeric"); } struct error_and_integral { error_and_integral(const ex &err, const ex &integ) :error(err), integral(integ){} ex error; ex integral; }; struct error_and_integral_is_less { bool operator()(const error_and_integral &e1,const error_and_integral &e2) const { int c = e1.integral.compare(e2.integral); if(c < 0) return true; if(c > 0) return false; return ex_is_less()(e1.error, e2.error); } }; typedef map lookup_map; /** Numeric integration routine based upon the "Adaptive Quadrature" one * in "Numerical Analysis" by Burden and Faires. Parameters are integration * variable, left boundary, right boundary, function to be integrated and * the relative integration error. The function should evalf into a number * after substituting the integration variable by a number. Another thing * to note is that this implementation is no good at integrating functions * with discontinuities. */ ex adaptivesimpson(const ex & x, const ex & a_in, const ex & b_in, const ex & f, const ex & error) { // Check whether boundaries and error are numbers. ex a = is_exactly_a(a_in) ? a_in : a_in.evalf(); ex b = is_exactly_a(b_in) ? b_in : b_in.evalf(); if(!is_exactly_a(a) || !is_exactly_a(b)) throw std::runtime_error("For numerical integration the boundaries of the integral should evalf into numbers."); if(!is_exactly_a(error)) throw std::runtime_error("For numerical integration the error should be a number."); // Use lookup table to be potentially much faster. static lookup_map lookup; static symbol ivar("ivar"); ex lookupex = integral(ivar,a,b,f.subs(x==ivar)); lookup_map::iterator emi = lookup.find(error_and_integral(error, lookupex)); if (emi!=lookup.end()) return emi->second; ex app = 0; int i = 1; exvector avec(integral::max_integration_level+1); exvector hvec(integral::max_integration_level+1); exvector favec(integral::max_integration_level+1); exvector fbvec(integral::max_integration_level+1); exvector fcvec(integral::max_integration_level+1); exvector svec(integral::max_integration_level+1); exvector errorvec(integral::max_integration_level+1); vector lvec(integral::max_integration_level+1); avec[i] = a; hvec[i] = (b-a)/2; favec[i] = subsvalue(x, a, f); fcvec[i] = subsvalue(x, a+hvec[i], f); fbvec[i] = subsvalue(x, b, f); svec[i] = hvec[i]*(favec[i]+4*fcvec[i]+fbvec[i])/3; lvec[i] = 1; errorvec[i] = error*abs(svec[i]); while (i>0) { ex fd = subsvalue(x, avec[i]+hvec[i]/2, f); ex fe = subsvalue(x, avec[i]+3*hvec[i]/2, f); ex s1 = hvec[i]*(favec[i]+4*fd+fcvec[i])/6; ex s2 = hvec[i]*(fcvec[i]+4*fe+fbvec[i])/6; ex nu1 = avec[i]; ex nu2 = favec[i]; ex nu3 = fcvec[i]; ex nu4 = fbvec[i]; ex nu5 = hvec[i]; // hopefully prevents a crash if the function is zero sometimes. ex nu6 = max(errorvec[i], abs(s1+s2)*error); ex nu7 = svec[i]; int nu8 = lvec[i]; --i; if (abs(ex_to(s1+s2-nu7)) <= nu6) app+=(s1+s2); else { if (nu8>=integral::max_integration_level) throw runtime_error("max integration level reached"); ++i; avec[i] = nu1+nu5; favec[i] = nu3; fcvec[i] = fe; fbvec[i] = nu4; hvec[i] = nu5/2; errorvec[i]=nu6/2; svec[i] = s2; lvec[i] = nu8+1; ++i; avec[i] = nu1; favec[i] = nu2; fcvec[i] = fd; fbvec[i] = nu3; hvec[i] = hvec[i-1]; errorvec[i]=errorvec[i-1]; svec[i] = s1; lvec[i] = lvec[i-1]; } } lookup[error_and_integral(error, lookupex)]=app; return app; } int integral::degree(const ex & s) const { return ((b-a)*f).degree(s); } int integral::ldegree(const ex & s) const { return ((b-a)*f).ldegree(s); } ex integral::eval_ncmul(const exvector & v) const { return f.eval_ncmul(v); } size_t integral::nops() const { return 4; } ex integral::op(size_t i) const { GINAC_ASSERT(i<4); switch (i) { case 0: return x; case 1: return a; case 2: return b; case 3: return f; default: throw (std::out_of_range("integral::op() out of range")); } } ex & integral::let_op(size_t i) { ensure_if_modifiable(); switch (i) { case 0: return x; case 1: return a; case 2: return b; case 3: return f; default: throw (std::out_of_range("integral::let_op() out of range")); } } ex integral::expand(unsigned options) const { if (options==0 && (flags & status_flags::expanded)) return *this; ex newa = a.expand(options); ex newb = b.expand(options); ex newf = f.expand(options); if (is_a(newf)) { exvector v; v.reserve(newf.nops()); for (size_t i=0; i(newf)) { ex prefactor = 1; ex rest = 1; for (size_t i=0; isetflag(status_flags::expanded); return *this; } const basic & newint = (new integral(x, newa, newb, newf)) ->setflag(status_flags::dynallocated); if (options == 0) newint.setflag(status_flags::expanded); return newint; } ex integral::derivative(const symbol & s) const { if (s==x) throw(logic_error("differentiation with respect to dummy variable")); return b.diff(s)*f.subs(x==b)-a.diff(s)*f.subs(x==a)+integral(x, a, b, f.diff(s)); } unsigned integral::return_type() const { return f.return_type(); } return_type_t integral::return_type_tinfo() const { return f.return_type_tinfo(); } ex integral::conjugate() const { ex conja = a.conjugate(); ex conjb = b.conjugate(); ex conjf = f.conjugate().subs(x.conjugate()==x); if (are_ex_trivially_equal(a, conja) && are_ex_trivially_equal(b, conjb) && are_ex_trivially_equal(f, conjf)) return *this; return (new integral(x, conja, conjb, conjf)) ->setflag(status_flags::dynallocated); } ex integral::eval_integ() const { if (!(flags & status_flags::expanded)) return this->expand().eval_integ(); if (f==x) return b*b/2-a*a/2; if (is_a(f) && f.op(0)==x) { if (f.op(1)==-1) return log(b/a); if (!f.op(1).has(x)) { ex primit = power(x,f.op(1)+1)/(f.op(1)+1); return primit.subs(x==b)-primit.subs(x==a); } } return *this; } GINAC_BIND_UNARCHIVER(integral); } // namespace GiNaC ginac-1.6.2.orig/ginac/normal.h0000644000000000000000000000761011562317235013161 0ustar /** @file normal.h * * This file defines several functions that work on univariate and * multivariate polynomials and rational functions. * These functions include polynomial quotient and remainder, GCD and LCM * computation, square-free factorization and rational function normalization. */ /* * GiNaC Copyright (C) 1999-2011 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef GINAC_NORMAL_H #define GINAC_NORMAL_H #include "lst.h" namespace GiNaC { /** * Flags to control the behaviour of gcd() and friends */ struct gcd_options { enum { /** * Usually GiNaC tries heuristic GCD first, because typically * it's much faster than anything else. Even if heuristic * algorithm fails, the overhead is negligible w.r.t. cost * of computing the GCD by some other method. However, some * people dislike it, so here's a flag which tells GiNaC * to NOT use the heuristic algorithm. */ no_heur_gcd = 2, /** * GiNaC tries to avoid expanding expressions when computing * GCDs. This is a good idea, but some people dislike it. * Hence the flag to disable special handling of partially * factored polynomials. DON'T SET THIS unless you *really* * know what are you doing! */ no_part_factored = 4, /** * By default GiNaC uses modular GCD algorithm. Typically * it's much faster than PRS (pseudo remainder sequence) * algorithm. This flag forces GiNaC to use PRS algorithm */ use_sr_gcd = 8 }; }; class ex; class symbol; // Quotient q(x) of polynomials a(x) and b(x) in Q[x], so that a(x)=b(x)*q(x)+r(x) extern ex quo(const ex &a, const ex &b, const ex &x, bool check_args = true); // Remainder r(x) of polynomials a(x) and b(x) in Q[x], so that a(x)=b(x)*q(x)+r(x) extern ex rem(const ex &a, const ex &b, const ex &x, bool check_args = true); // Decompose rational function a(x)=N(x)/D(x) into Q(x)+R(x)/D(x) with degree(R, x) < degree(D, x) extern ex decomp_rational(const ex &a, const ex &x); // Pseudo-remainder of polynomials a(x) and b(x) in Q[x] extern ex prem(const ex &a, const ex &b, const ex &x, bool check_args = true); // Pseudo-remainder of polynomials a(x) and b(x) in Q[x] extern ex sprem(const ex &a, const ex &b, const ex &x, bool check_args = true); // Exact polynomial division of a(X) by b(X) in Q[X] (quotient returned in q), returns false when exact division fails extern bool divide(const ex &a, const ex &b, ex &q, bool check_args = true); // Polynomial GCD in Z[X], cofactors are returned in ca and cb, if desired extern ex gcd(const ex &a, const ex &b, ex *ca = NULL, ex *cb = NULL, bool check_args = true, unsigned options = 0); // Polynomial LCM in Z[X] extern ex lcm(const ex &a, const ex &b, bool check_args = true); // Square-free factorization of a polynomial a(x) extern ex sqrfree(const ex &a, const lst &l = lst()); // Square-free partial fraction decomposition of a rational function a(x) extern ex sqrfree_parfrac(const ex & a, const symbol & x); // Collect common factors in sums. extern ex collect_common_factors(const ex & e); // Resultant of two polynomials e1,e2 with respect to symbol s. extern ex resultant(const ex & e1, const ex & e2, const ex & s); } // namespace GiNaC #endif // ndef GINAC_NORMAL_H ginac-1.6.2.orig/ginac/ncmul.cpp0000644000000000000000000004103711562317235013343 0ustar /** @file ncmul.cpp * * Implementation of GiNaC's non-commutative products of expressions. */ /* * GiNaC Copyright (C) 1999-2011 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "ncmul.h" #include "ex.h" #include "add.h" #include "mul.h" #include "clifford.h" #include "matrix.h" #include "archive.h" #include "indexed.h" #include "utils.h" #include #include #include namespace GiNaC { GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(ncmul, exprseq, print_func(&ncmul::do_print). print_func(&ncmul::do_print_tree). print_func(&ncmul::do_print_csrc). print_func(&ncmul::do_print_csrc)) ////////// // default constructor ////////// ncmul::ncmul() { } ////////// // other constructors ////////// // public ncmul::ncmul(const ex & lh, const ex & rh) : inherited(lh,rh) { } ncmul::ncmul(const ex & f1, const ex & f2, const ex & f3) : inherited(f1,f2,f3) { } ncmul::ncmul(const ex & f1, const ex & f2, const ex & f3, const ex & f4) : inherited(f1,f2,f3,f4) { } ncmul::ncmul(const ex & f1, const ex & f2, const ex & f3, const ex & f4, const ex & f5) : inherited(f1,f2,f3,f4,f5) { } ncmul::ncmul(const ex & f1, const ex & f2, const ex & f3, const ex & f4, const ex & f5, const ex & f6) : inherited(f1,f2,f3,f4,f5,f6) { } ncmul::ncmul(const exvector & v, bool discardable) : inherited(v,discardable) { } ncmul::ncmul(std::auto_ptr vp) : inherited(vp) { } ////////// // archiving ////////// ////////// // functions overriding virtual functions from base classes ////////// // public void ncmul::do_print(const print_context & c, unsigned level) const { printseq(c, '(', '*', ')', precedence(), level); } void ncmul::do_print_csrc(const print_context & c, unsigned level) const { c.s << class_name(); printseq(c, '(', ',', ')', precedence(), precedence()); } bool ncmul::info(unsigned inf) const { return inherited::info(inf); } typedef std::vector uintvector; ex ncmul::expand(unsigned options) const { // First, expand the children std::auto_ptr vp = expandchildren(options); const exvector &expanded_seq = vp.get() ? *vp : this->seq; // Now, look for all the factors that are sums and remember their // position and number of terms. uintvector positions_of_adds(expanded_seq.size()); uintvector number_of_add_operands(expanded_seq.size()); size_t number_of_adds = 0; size_t number_of_expanded_terms = 1; size_t current_position = 0; exvector::const_iterator last = expanded_seq.end(); for (exvector::const_iterator cit=expanded_seq.begin(); cit!=last; ++cit) { if (is_exactly_a(*cit)) { positions_of_adds[number_of_adds] = current_position; size_t num_ops = cit->nops(); number_of_add_operands[number_of_adds] = num_ops; number_of_expanded_terms *= num_ops; number_of_adds++; } ++current_position; } // If there are no sums, we are done if (number_of_adds == 0) { if (vp.get()) return (new ncmul(vp))-> setflag(status_flags::dynallocated | (options == 0 ? status_flags::expanded : 0)); else return *this; } // Now, form all possible products of the terms of the sums with the // remaining factors, and add them together exvector distrseq; distrseq.reserve(number_of_expanded_terms); uintvector k(number_of_adds); /* Rename indices in the static members of the product */ exvector expanded_seq_mod; size_t j = 0; exvector va; for (size_t i=0; i setflag(status_flags::dynallocated | (options == 0 ? status_flags::expanded : 0))); // increment k[] int l = number_of_adds-1; while ((l>=0) && ((++k[l]) >= number_of_add_operands[l])) { k[l] = 0; l--; } if (l<0) break; } return (new add(distrseq))-> setflag(status_flags::dynallocated | (options == 0 ? status_flags::expanded : 0)); } int ncmul::degree(const ex & s) const { if (is_equal(ex_to(s))) return 1; // Sum up degrees of factors int deg_sum = 0; exvector::const_iterator i = seq.begin(), end = seq.end(); while (i != end) { deg_sum += i->degree(s); ++i; } return deg_sum; } int ncmul::ldegree(const ex & s) const { if (is_equal(ex_to(s))) return 1; // Sum up degrees of factors int deg_sum = 0; exvector::const_iterator i = seq.begin(), end = seq.end(); while (i != end) { deg_sum += i->degree(s); ++i; } return deg_sum; } ex ncmul::coeff(const ex & s, int n) const { if (is_equal(ex_to(s))) return n==1 ? _ex1 : _ex0; exvector coeffseq; coeffseq.reserve(seq.size()); if (n == 0) { // product of individual coeffs // if a non-zero power of s is found, the resulting product will be 0 exvector::const_iterator it=seq.begin(); while (it!=seq.end()) { coeffseq.push_back((*it).coeff(s,n)); ++it; } return (new ncmul(coeffseq,1))->setflag(status_flags::dynallocated); } exvector::const_iterator i = seq.begin(), end = seq.end(); bool coeff_found = false; while (i != end) { ex c = i->coeff(s,n); if (c.is_zero()) { coeffseq.push_back(*i); } else { coeffseq.push_back(c); coeff_found = true; } ++i; } if (coeff_found) return (new ncmul(coeffseq,1))->setflag(status_flags::dynallocated); return _ex0; } size_t ncmul::count_factors(const ex & e) const { if ((is_exactly_a(e)&&(e.return_type()!=return_types::commutative))|| (is_exactly_a(e))) { size_t factors=0; for (size_t i=0; i(e)&&(e.return_type()!=return_types::commutative))|| (is_exactly_a(e))) { for (size_t i=0; i unsignedvector; typedef std::vector exvectorvector; /** Perform automatic term rewriting rules in this class. In the following * x, x1, x2,... stand for a symbolic variables of type ex and c, c1, c2... * stand for such expressions that contain a plain number. * - ncmul(...,*(x1,x2),...,ncmul(x3,x4),...) -> ncmul(...,x1,x2,...,x3,x4,...) (associativity) * - ncmul(x) -> x * - ncmul() -> 1 * - ncmul(...,c1,...,c2,...) -> *(c1,c2,ncmul(...)) (pull out commutative elements) * - ncmul(x1,y1,x2,y2) -> *(ncmul(x1,x2),ncmul(y1,y2)) (collect elements of same type) * - ncmul(x1,x2,x3,...) -> x::eval_ncmul(x1,x2,x3,...) * * @param level cut-off in recursive evaluation */ ex ncmul::eval(int level) const { // The following additional rule would be nice, but produces a recursion, // which must be trapped by introducing a flag that the sub-ncmuls() // are already evaluated (maybe later...) // ncmul(x1,x2,...,X,y1,y2,...) -> // ncmul(ncmul(x1,x2,...),X,ncmul(y1,y2,...) // (X noncommutative_composite) if ((level==1) && (flags & status_flags::evaluated)) { return *this; } exvector evaledseq=evalchildren(level); // ncmul(...,*(x1,x2),...,ncmul(x3,x4),...) -> // ncmul(...,x1,x2,...,x3,x4,...) (associativity) size_t factors = 0; exvector::const_iterator cit = evaledseq.begin(), citend = evaledseq.end(); while (cit != citend) factors += count_factors(*cit++); exvector assocseq; assocseq.reserve(factors); cit = evaledseq.begin(); make_flat_inserter mf(evaledseq, true); while (cit != citend) { ex factor = mf.handle_factor(*(cit++), 1); append_factors(assocseq, factor); } // ncmul(x) -> x if (assocseq.size()==1) return *(seq.begin()); // ncmul() -> 1 if (assocseq.empty()) return _ex1; // determine return types unsignedvector rettypes(assocseq.size()); size_t i = 0; size_t count_commutative=0; size_t count_noncommutative=0; size_t count_noncommutative_composite=0; cit = assocseq.begin(); citend = assocseq.end(); while (cit != citend) { rettypes[i] = cit->return_type(); switch (rettypes[i]) { case return_types::commutative: count_commutative++; break; case return_types::noncommutative: count_noncommutative++; break; case return_types::noncommutative_composite: count_noncommutative_composite++; break; default: throw(std::logic_error("ncmul::eval(): invalid return type")); } ++i; ++cit; } GINAC_ASSERT(count_commutative+count_noncommutative+count_noncommutative_composite==assocseq.size()); // ncmul(...,c1,...,c2,...) -> // *(c1,c2,ncmul(...)) (pull out commutative elements) if (count_commutative!=0) { exvector commutativeseq; commutativeseq.reserve(count_commutative+1); exvector noncommutativeseq; noncommutativeseq.reserve(assocseq.size()-count_commutative); size_t num = assocseq.size(); for (size_t i=0; isetflag(status_flags::dynallocated)); return (new mul(commutativeseq))->setflag(status_flags::dynallocated); } // ncmul(x1,y1,x2,y2) -> *(ncmul(x1,x2),ncmul(y1,y2)) // (collect elements of same type) if (count_noncommutative_composite==0) { // there are neither commutative nor noncommutative_composite // elements in assocseq GINAC_ASSERT(count_commutative==0); size_t assoc_num = assocseq.size(); exvectorvector evv; std::vector rttinfos; evv.reserve(assoc_num); rttinfos.reserve(assoc_num); cit = assocseq.begin(), citend = assocseq.end(); while (cit != citend) { return_type_t ti = cit->return_type_tinfo(); size_t rtt_num = rttinfos.size(); // search type in vector of known types for (i=0; i= rtt_num) { // new type rttinfos.push_back(ti); evv.push_back(exvector()); (evv.end()-1)->reserve(assoc_num); (evv.end()-1)->push_back(*cit); } ++cit; } size_t evv_num = evv.size(); #ifdef DO_GINAC_ASSERT GINAC_ASSERT(evv_num == rttinfos.size()); GINAC_ASSERT(evv_num > 0); size_t s=0; for (i=0; isetflag(status_flags::dynallocated)); return (new mul(splitseq))->setflag(status_flags::dynallocated); } return (new ncmul(assocseq))->setflag(status_flags::dynallocated | status_flags::evaluated); } ex ncmul::evalm() const { // Evaluate children first std::auto_ptr s(new exvector); s->reserve(seq.size()); exvector::const_iterator it = seq.begin(), itend = seq.end(); while (it != itend) { s->push_back(it->evalm()); it++; } // If there are only matrices, simply multiply them it = s->begin(); itend = s->end(); if (is_a(*it)) { matrix prod(ex_to(*it)); it++; while (it != itend) { if (!is_a(*it)) goto no_matrix; prod = prod.mul(ex_to(*it)); it++; } return prod; } no_matrix: return (new ncmul(s))->setflag(status_flags::dynallocated); } ex ncmul::thiscontainer(const exvector & v) const { return (new ncmul(v))->setflag(status_flags::dynallocated); } ex ncmul::thiscontainer(std::auto_ptr vp) const { return (new ncmul(vp))->setflag(status_flags::dynallocated); } ex ncmul::conjugate() const { if (return_type() != return_types::noncommutative) { return exprseq::conjugate(); } if (!is_clifford_tinfo(return_type_tinfo())) { return exprseq::conjugate(); } exvector ev; ev.reserve(nops()); for (const_iterator i=end(); i!=begin();) { --i; ev.push_back(i->conjugate()); } return (new ncmul(ev, true))->setflag(status_flags::dynallocated).eval(); } ex ncmul::real_part() const { return basic::real_part(); } ex ncmul::imag_part() const { return basic::imag_part(); } // protected /** Implementation of ex::diff() for a non-commutative product. It applies * the product rule. * @see ex::diff */ ex ncmul::derivative(const symbol & s) const { size_t num = seq.size(); exvector addseq; addseq.reserve(num); // D(a*b*c) = D(a)*b*c + a*D(b)*c + a*b*D(c) exvector ncmulseq = seq; for (size_t i=0; isetflag(status_flags::dynallocated)); e.swap(ncmulseq[i]); } return (new add(addseq))->setflag(status_flags::dynallocated); } int ncmul::compare_same_type(const basic & other) const { return inherited::compare_same_type(other); } unsigned ncmul::return_type() const { if (seq.empty()) return return_types::commutative; bool all_commutative = true; exvector::const_iterator noncommutative_element; // point to first found nc element exvector::const_iterator i = seq.begin(), end = seq.end(); while (i != end) { unsigned rt = i->return_type(); if (rt == return_types::noncommutative_composite) return rt; // one ncc -> mul also ncc if ((rt == return_types::noncommutative) && (all_commutative)) { // first nc element found, remember position noncommutative_element = i; all_commutative = false; } if ((rt == return_types::noncommutative) && (!all_commutative)) { // another nc element found, compare type_infos if(noncommutative_element->return_type_tinfo() != i->return_type_tinfo()) return return_types::noncommutative_composite; } ++i; } // all factors checked GINAC_ASSERT(!all_commutative); // not all factors should commutate, because this is a ncmul(); return all_commutative ? return_types::commutative : return_types::noncommutative; } return_type_t ncmul::return_type_tinfo() const { if (seq.empty()) return make_return_type_t(); // return type_info of first noncommutative element exvector::const_iterator i = seq.begin(), end = seq.end(); while (i != end) { if (i->return_type() == return_types::noncommutative) return i->return_type_tinfo(); ++i; } // no noncommutative element found, should not happen return make_return_type_t(); } ////////// // new virtual functions which can be overridden by derived classes ////////// // none ////////// // non-virtual functions in this class ////////// std::auto_ptr ncmul::expandchildren(unsigned options) const { const_iterator cit = this->seq.begin(), end = this->seq.end(); while (cit != end) { const ex & expanded_ex = cit->expand(options); if (!are_ex_trivially_equal(*cit, expanded_ex)) { // copy first part of seq which hasn't changed std::auto_ptr s(new exvector(this->seq.begin(), cit)); reserve(*s, this->seq.size()); // insert changed element s->push_back(expanded_ex); ++cit; // copy rest while (cit != end) { s->push_back(cit->expand(options)); ++cit; } return s; } ++cit; } return std::auto_ptr(0); // nothing has changed } const exvector & ncmul::get_factors() const { return seq; } ////////// // friend functions ////////// ex reeval_ncmul(const exvector & v) { return (new ncmul(v))->setflag(status_flags::dynallocated); } ex hold_ncmul(const exvector & v) { if (v.empty()) return _ex1; else if (v.size() == 1) return v[0]; else return (new ncmul(v))->setflag(status_flags::dynallocated | status_flags::evaluated); } GINAC_BIND_UNARCHIVER(ncmul); } // namespace GiNaC ginac-1.6.2.orig/ginac/numeric.h0000644000000000000000000002574211562317235013341 0ustar /** @file numeric.h * * Makes the interface to the underlying bignum package available. */ /* * GiNaC Copyright (C) 1999-2011 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef GINAC_NUMERIC_H #define GINAC_NUMERIC_H #include "basic.h" #include "ex.h" #include "archive.h" #include #if defined(G__CINTVERSION) && !defined(__MAKECINT__) // Cint @$#$! doesn't like forward declaring classes used for casting operators // so we have to include the definition of cln::cl_N here, but it is enough to // do so for the compiler, hence the !defined(__MAKECINT__). #include #endif #include #include namespace GiNaC { /** Function pointer to implement callbacks in the case 'Digits' gets changed. * Main purpose of such callbacks is to adjust look-up tables of certain * functions to the new precision. Parameter contains the signed difference * between new Digits and old Digits. */ typedef void (* digits_changed_callback)(long); /** This class is used to instantiate a global singleton object Digits * which behaves just like Maple's Digits. We need an object rather * than a dumber basic type since as a side-effect we let it change * cl_default_float_format when it gets changed. The only other * meaningful thing to do with it is converting it to an unsigned, * for temprary storing its value e.g. The user must not create an * own working object of this class! Since C++ forces us to make the * class definition visible in order to use an object we put in a * flag which prevents other objects of that class to be created. */ class _numeric_digits { // member functions public: _numeric_digits(); _numeric_digits& operator=(long prec); operator long(); void print(std::ostream& os) const; void add_callback(digits_changed_callback callback); // member variables private: long digits; ///< Number of decimal digits static bool too_late; ///< Already one object present // Holds a list of functions that get called when digits is changed. std::vector callbacklist; }; /** Exception class thrown when a singularity is encountered. */ class pole_error : public std::domain_error { public: explicit pole_error(const std::string& what_arg, int degree); int degree() const; private: int deg; }; /** This class is a wrapper around CLN-numbers within the GiNaC class * hierarchy. Objects of this type may directly be created by the user.*/ class numeric : public basic { GINAC_DECLARE_REGISTERED_CLASS(numeric, basic) // member functions // other constructors public: numeric(int i); numeric(unsigned int i); numeric(long i); numeric(unsigned long i); numeric(long numer, long denom); numeric(double d); numeric(const char *); // functions overriding virtual functions from base classes public: unsigned precedence() const {return 30;} bool info(unsigned inf) const; bool is_polynomial(const ex & var) const; int degree(const ex & s) const; int ldegree(const ex & s) const; ex coeff(const ex & s, int n = 1) const; bool has(const ex &other, unsigned options = 0) const; ex eval(int level = 0) const; ex evalf(int level = 0) const; ex subs(const exmap & m, unsigned options = 0) const { return subs_one_level(m, options); } // overwrites basic::subs() for performance reasons ex normal(exmap & repl, exmap & rev_lookup, int level = 0) const; ex to_rational(exmap & repl) const; ex to_polynomial(exmap & repl) const; numeric integer_content() const; ex smod(const numeric &xi) const; numeric max_coefficient() const; ex conjugate() const; ex real_part() const; ex imag_part() const; /** Save (a.k.a. serialize) object into archive. */ void archive(archive_node& n) const; /** Read (a.k.a. deserialize) object from archive. */ void read_archive(const archive_node& n, lst& syms); protected: /** Implementation of ex::diff for a numeric always returns 0. * @see ex::diff */ ex derivative(const symbol &s) const { return 0; } bool is_equal_same_type(const basic &other) const; unsigned calchash() const; // new virtual functions which can be overridden by derived classes // (none) // non-virtual functions in this class public: const numeric add(const numeric &other) const; const numeric sub(const numeric &other) const; const numeric mul(const numeric &other) const; const numeric div(const numeric &other) const; const numeric power(const numeric &other) const; const numeric & add_dyn(const numeric &other) const; const numeric & sub_dyn(const numeric &other) const; const numeric & mul_dyn(const numeric &other) const; const numeric & div_dyn(const numeric &other) const; const numeric & power_dyn(const numeric &other) const; const numeric & operator=(int i); const numeric & operator=(unsigned int i); const numeric & operator=(long i); const numeric & operator=(unsigned long i); const numeric & operator=(double d); const numeric & operator=(const char *s); const numeric inverse() const; numeric step() const; int csgn() const; int compare(const numeric &other) const; bool is_equal(const numeric &other) const; bool is_zero() const; bool is_positive() const; bool is_negative() const; bool is_integer() const; bool is_pos_integer() const; bool is_nonneg_integer() const; bool is_even() const; bool is_odd() const; bool is_prime() const; bool is_rational() const; bool is_real() const; bool is_cinteger() const; bool is_crational() const; bool operator==(const numeric &other) const; bool operator!=(const numeric &other) const; bool operator<(const numeric &other) const; bool operator<=(const numeric &other) const; bool operator>(const numeric &other) const; bool operator>=(const numeric &other) const; int to_int() const; long to_long() const; double to_double() const; cln::cl_N to_cl_N() const; const numeric real() const; const numeric imag() const; const numeric numer() const; const numeric denom() const; int int_length() const; // converting routines for interfacing with CLN: explicit numeric(const cln::cl_N &z); protected: void print_numeric(const print_context & c, const char *par_open, const char *par_close, const char *imag_sym, const char *mul_sym, unsigned level) const; void do_print(const print_context & c, unsigned level) const; void do_print_latex(const print_latex & c, unsigned level) const; void do_print_csrc(const print_csrc & c, unsigned level) const; void do_print_csrc_cl_N(const print_csrc_cl_N & c, unsigned level) const; void do_print_tree(const print_tree & c, unsigned level) const; void do_print_python_repr(const print_python_repr & c, unsigned level) const; // member variables protected: cln::cl_N value; }; GINAC_DECLARE_UNARCHIVER(numeric); // global constants extern const numeric I; extern _numeric_digits Digits; // global functions const numeric exp(const numeric &x); const numeric log(const numeric &x); const numeric sin(const numeric &x); const numeric cos(const numeric &x); const numeric tan(const numeric &x); const numeric asin(const numeric &x); const numeric acos(const numeric &x); const numeric atan(const numeric &x); const numeric atan(const numeric &y, const numeric &x); const numeric sinh(const numeric &x); const numeric cosh(const numeric &x); const numeric tanh(const numeric &x); const numeric asinh(const numeric &x); const numeric acosh(const numeric &x); const numeric atanh(const numeric &x); const numeric Li2(const numeric &x); const numeric zeta(const numeric &x); const numeric lgamma(const numeric &x); const numeric tgamma(const numeric &x); const numeric psi(const numeric &x); const numeric psi(const numeric &n, const numeric &x); const numeric factorial(const numeric &n); const numeric doublefactorial(const numeric &n); const numeric binomial(const numeric &n, const numeric &k); const numeric bernoulli(const numeric &n); const numeric fibonacci(const numeric &n); const numeric isqrt(const numeric &x); const numeric sqrt(const numeric &x); const numeric abs(const numeric &x); const numeric mod(const numeric &a, const numeric &b); const numeric smod(const numeric &a, const numeric &b); const numeric irem(const numeric &a, const numeric &b); const numeric irem(const numeric &a, const numeric &b, numeric &q); const numeric iquo(const numeric &a, const numeric &b); const numeric iquo(const numeric &a, const numeric &b, numeric &r); const numeric gcd(const numeric &a, const numeric &b); const numeric lcm(const numeric &a, const numeric &b); // wrapper functions around member functions inline const numeric pow(const numeric &x, const numeric &y) { return x.power(y); } inline const numeric inverse(const numeric &x) { return x.inverse(); } inline numeric step(const numeric &x) { return x.step(); } inline int csgn(const numeric &x) { return x.csgn(); } inline bool is_zero(const numeric &x) { return x.is_zero(); } inline bool is_positive(const numeric &x) { return x.is_positive(); } inline bool is_negative(const numeric &x) { return x.is_negative(); } inline bool is_integer(const numeric &x) { return x.is_integer(); } inline bool is_pos_integer(const numeric &x) { return x.is_pos_integer(); } inline bool is_nonneg_integer(const numeric &x) { return x.is_nonneg_integer(); } inline bool is_even(const numeric &x) { return x.is_even(); } inline bool is_odd(const numeric &x) { return x.is_odd(); } inline bool is_prime(const numeric &x) { return x.is_prime(); } inline bool is_rational(const numeric &x) { return x.is_rational(); } inline bool is_real(const numeric &x) { return x.is_real(); } inline bool is_cinteger(const numeric &x) { return x.is_cinteger(); } inline bool is_crational(const numeric &x) { return x.is_crational(); } inline int to_int(const numeric &x) { return x.to_int(); } inline long to_long(const numeric &x) { return x.to_long(); } inline double to_double(const numeric &x) { return x.to_double(); } inline const numeric real(const numeric &x) { return x.real(); } inline const numeric imag(const numeric &x) { return x.imag(); } inline const numeric numer(const numeric &x) { return x.numer(); } inline const numeric denom(const numeric &x) { return x.denom(); } // numeric evaluation functions for class constant objects: ex PiEvalf(); ex EulerEvalf(); ex CatalanEvalf(); } // namespace GiNaC #ifdef __MAKECINT__ #pragma link off defined_in cln/number.h; #pragma link off defined_in cln/complex_class.h; #endif #endif // ndef GINAC_NUMERIC_H ginac-1.6.2.orig/ginac/relational.h0000644000000000000000000000635011562317236014024 0ustar /** @file relational.h * * Interface to relations between expressions. */ /* * GiNaC Copyright (C) 1999-2011 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef GINAC_RELATIONAL_H #define GINAC_RELATIONAL_H #include "basic.h" #include "ex.h" #include "archive.h" namespace GiNaC { /** This class holds a relation consisting of two expressions and a logical * relation between them. */ class relational : public basic { GINAC_DECLARE_REGISTERED_CLASS(relational, basic) // types public: enum operators { equal, not_equal, less, less_or_equal, greater, greater_or_equal }; // other constructors public: relational(const ex & lhs, const ex & rhs, operators oper=equal); // functions overriding virtual functions from base classes public: unsigned precedence() const {return 20;} bool info(unsigned inf) const; size_t nops() const; ex op(size_t i) const; ex map(map_function & f) const; ex subs(const exmap & m, unsigned options = 0) const; ex eval(int level=0) const; /** Save (a.k.a. serialize) object into archive. */ void archive(archive_node& n) const; /** Read (a.k.a. deserialize) object from archive. */ void read_archive(const archive_node& n, lst& syms); protected: ex eval_ncmul(const exvector & v) const; bool match_same_type(const basic & other) const; unsigned return_type() const; return_type_t return_type_tinfo() const; unsigned calchash() const; // new virtual functions which can be overridden by derived classes protected: void do_print(const print_context & c, unsigned level) const; void do_print_python_repr(const print_python_repr & c, unsigned level) const; public: virtual ex lhs() const; virtual ex rhs() const; // non-virtual functions in this class private: // For conversions to boolean, as would be used in an if conditional, // implicit conversions from bool to int have a large number of // undesirable side effects. The following safe_bool type enables // use of relational objects in conditionals without those side effects struct safe_bool_helper { void nonnull() {}; }; typedef void (safe_bool_helper::*safe_bool)(); safe_bool make_safe_bool(bool) const; public: operator safe_bool() const; safe_bool operator!() const; // member variables protected: ex lh; ex rh; operators o; }; GINAC_DECLARE_UNARCHIVER(relational); // utility functions // inlined functions for efficiency inline relational::safe_bool relational::operator!() const { return make_safe_bool(!static_cast(*this)); } } // namespace GiNaC #endif // ndef GINAC_RELATIONAL_H ginac-1.6.2.orig/ginac/version.h0000644000000000000000000000253311655511060013350 0ustar /* ginac/version.h. Generated from version.h.in by configure. */ /** @file version.h * * GiNaC library version information. */ /* * GiNaC Copyright (C) 1999-2008 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef __GINAC_VERSION_H__ #define __GINAC_VERSION_H__ /* Major version of GiNaC */ #define GINACLIB_MAJOR_VERSION 1 /* Minor version of GiNaC */ #define GINACLIB_MINOR_VERSION 6 /* Micro version of GiNaC */ #define GINACLIB_MICRO_VERSION 2 namespace GiNaC { extern const int version_major; extern const int version_minor; extern const int version_micro; } // namespace GiNaC #endif // ndef __GINAC_VERSION_H__ ginac-1.6.2.orig/ginac/wildcard.cpp0000644000000000000000000000672111562317236014020 0ustar /** @file wildcard.cpp * * Implementation of GiNaC's wildcard objects. */ /* * GiNaC Copyright (C) 1999-2011 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "wildcard.h" #include "archive.h" #include "utils.h" #include "hash_seed.h" #include namespace GiNaC { GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(wildcard, basic, print_func(&wildcard::do_print). print_func(&wildcard::do_print_tree). print_func(&wildcard::do_print_python_repr)) ////////// // default constructor ////////// wildcard::wildcard() : label(0) { setflag(status_flags::evaluated | status_flags::expanded); } ////////// // other constructors ////////// wildcard::wildcard(unsigned l) : label(l) { setflag(status_flags::evaluated | status_flags::expanded); } ////////// // archiving ////////// void wildcard::read_archive(const archive_node& n, lst& sym_lst) { inherited::read_archive(n, sym_lst); n.find_unsigned("label", label); setflag(status_flags::evaluated | status_flags::expanded); } GINAC_BIND_UNARCHIVER(wildcard); void wildcard::archive(archive_node &n) const { inherited::archive(n); n.add_unsigned("label", label); } ////////// // functions overriding virtual functions from base classes ////////// int wildcard::compare_same_type(const basic & other) const { GINAC_ASSERT(is_a(other)); const wildcard &o = static_cast(other); if (label == o.label) return 0; else return label < o.label ? -1 : 1; } void wildcard::do_print(const print_context & c, unsigned level) const { c.s << "$" << label; } void wildcard::do_print_tree(const print_tree & c, unsigned level) const { c.s << std::string(level, ' ') << class_name() << "(" << label << ")" << " @" << this << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec << std::endl; } void wildcard::do_print_python_repr(const print_python_repr & c, unsigned level) const { c.s << class_name() << '(' << label << ')'; } unsigned wildcard::calchash() const { // this is where the schoolbook method // (golden_ratio_hash(typeid(*this).name()) ^ label) // is not good enough yet... unsigned seed = make_hash_seed(typeid(*this)); hashvalue = golden_ratio_hash(seed ^ label); setflag(status_flags::hash_calculated); return hashvalue; } bool wildcard::match(const ex & pattern, exmap& repl_lst) const { // Wildcards must match each other exactly (this is required for // subs() to work properly because in the final step it substitutes // all wildcards by their matching expressions) return is_equal(ex_to(pattern)); } bool haswild(const ex & x) { if (is_a(x)) return true; for (size_t i=0; i namespace GiNaC { /** This class holds an object representing an element of the Clifford * algebra (the Dirac gamma matrices). These objects only carry Lorentz * indices. Spinor indices are hidden. A representation label (an unsigned * 8-bit integer) is used to distinguish elements from different Clifford * algebras (objects with different labels commutate). */ class clifford : public indexed { GINAC_DECLARE_REGISTERED_CLASS(clifford, indexed) // other constructors public: clifford(const ex & b, unsigned char rl = 0); clifford(const ex & b, const ex & mu, const ex & metr, unsigned char rl = 0, int comm_sign = -1); // internal constructors clifford(unsigned char rl, const ex & metr, int comm_sign, const exvector & v, bool discardable = false); clifford(unsigned char rl, const ex & metr, int comm_sign, std::auto_ptr vp); // functions overriding virtual functions from base classes public: unsigned precedence() const { return 65; } void archive(archive_node& n) const; void read_archive(const archive_node& n, lst& sym_lst); protected: ex eval_ncmul(const exvector & v) const; bool match_same_type(const basic & other) const; ex thiscontainer(const exvector & v) const; ex thiscontainer(std::auto_ptr vp) const; unsigned return_type() const { return return_types::noncommutative; } return_type_t return_type_tinfo() const; // non-virtual functions in this class public: unsigned char get_representation_label() const { return representation_label; } ex get_metric() const { return metric; } virtual ex get_metric(const ex & i, const ex & j, bool symmetrised = false) const; bool same_metric(const ex & other) const; int get_commutator_sign() const { return commutator_sign; } //**< See the member variable commutator_sign */ inline size_t nops() const {return inherited::nops() + 1; } ex op(size_t i) const; ex & let_op(size_t i); ex subs(const exmap & m, unsigned options = 0) const; protected: void do_print_dflt(const print_dflt & c, unsigned level) const; void do_print_latex(const print_latex & c, unsigned level) const; // member variables protected: unsigned char representation_label; /**< Representation label to distinguish independent spin lines */ ex metric; /**< Metric of the space, all constructors make it an indexed object */ int commutator_sign; /**< It is the sign in the definition e~i e~j +/- e~j e~i = B(i, j) + B(j, i)*/ }; GINAC_DECLARE_UNARCHIVER(clifford); /** This class represents the Clifford algebra unity element. */ class diracone : public tensor { GINAC_DECLARE_REGISTERED_CLASS(diracone, tensor) // non-virtual functions in this class protected: void do_print(const print_context & c, unsigned level) const; void do_print_latex(const print_latex & c, unsigned level) const; }; GINAC_DECLARE_UNARCHIVER(diracone); /** This class represents the Clifford algebra generators (units). */ class cliffordunit : public tensor { GINAC_DECLARE_REGISTERED_CLASS(cliffordunit, tensor) // functions overriding virtual functions from base classes public: bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const; // non-virtual functions in this class protected: void do_print(const print_context & c, unsigned level) const; void do_print_latex(const print_latex & c, unsigned level) const; }; /** This class represents the Dirac gamma Lorentz vector. */ class diracgamma : public cliffordunit { GINAC_DECLARE_REGISTERED_CLASS(diracgamma, cliffordunit) // functions overriding virtual functions from base classes public: bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const; // non-virtual functions in this class protected: void do_print(const print_context & c, unsigned level) const; void do_print_latex(const print_latex & c, unsigned level) const; }; GINAC_DECLARE_UNARCHIVER(diracgamma); /** This class represents the Dirac gamma5 object which anticommutates with * all other gammas. */ class diracgamma5 : public tensor { GINAC_DECLARE_REGISTERED_CLASS(diracgamma5, tensor) // functions overriding virtual functions from base classes ex conjugate() const; // non-virtual functions in this class protected: void do_print(const print_context & c, unsigned level) const; void do_print_latex(const print_latex & c, unsigned level) const; }; GINAC_DECLARE_UNARCHIVER(diracgamma5); /** This class represents the Dirac gammaL object which behaves like * 1/2 (1-gamma5). */ class diracgammaL : public tensor { GINAC_DECLARE_REGISTERED_CLASS(diracgammaL, tensor) // functions overriding virtual functions from base classes ex conjugate() const; // non-virtual functions in this class protected: void do_print(const print_context & c, unsigned level) const; void do_print_latex(const print_latex & c, unsigned level) const; }; GINAC_DECLARE_UNARCHIVER(diracgammaL); /** This class represents the Dirac gammaL object which behaves like * 1/2 (1+gamma5). */ class diracgammaR : public tensor { GINAC_DECLARE_REGISTERED_CLASS(diracgammaR, tensor) // functions overriding virtual functions from base classes ex conjugate() const; // non-virtual functions in this class protected: void do_print(const print_context & c, unsigned level) const; void do_print_latex(const print_latex & c, unsigned level) const; }; GINAC_DECLARE_UNARCHIVER(diracgammaR); // global functions /** Check whether a given return_type_t object (as returned by return_type_tinfo() * is that of a clifford object (with an arbitrary representation label). * * @param ti tinfo key */ inline bool is_clifford_tinfo(const return_type_t& ti) { return *(ti.tinfo) == typeid(clifford); } /** Create a Clifford unity object. * * @param rl Representation label * @return newly constructed object */ ex dirac_ONE(unsigned char rl = 0); /** Create a Clifford unit object. * * @param mu Index (must be of class varidx or a derived class) * @param metr Metric (should be indexed, tensmetric or a derived class, or a matrix) * @param rl Representation label * @return newly constructed Clifford unit object */ ex clifford_unit(const ex & mu, const ex & metr, unsigned char rl = 0); /** Create a Dirac gamma object. * * @param mu Index (must be of class varidx or a derived class) * @param rl Representation label * @return newly constructed gamma object */ ex dirac_gamma(const ex & mu, unsigned char rl = 0); /** Create a Dirac gamma5 object. * * @param rl Representation label * @return newly constructed object */ ex dirac_gamma5(unsigned char rl = 0); /** Create a Dirac gammaL object. * * @param rl Representation label * @return newly constructed object */ ex dirac_gammaL(unsigned char rl = 0); /** Create a Dirac gammaR object. * * @param rl Representation label * @return newly constructed object */ ex dirac_gammaR(unsigned char rl = 0); /** Create a term of the form e_mu * gamma~mu with a unique index mu. * * @param e Original expression * @param dim Dimension of index * @param rl Representation label */ ex dirac_slash(const ex & e, const ex & dim, unsigned char rl = 0); /** Calculate dirac traces over the specified set of representation labels. * The computed trace is a linear functional that is equal to the usual * trace only in D = 4 dimensions. In particular, the functional is not * always cyclic in D != 4 dimensions when gamma5 is involved. * * @param e Expression to take the trace of * @param rls Set of representation labels * @param trONE Expression to be returned as the trace of the unit matrix */ ex dirac_trace(const ex & e, const std::set & rls, const ex & trONE = 4); /** Calculate dirac traces over the specified list of representation labels. * The computed trace is a linear functional that is equal to the usual * trace only in D = 4 dimensions. In particular, the functional is not * always cyclic in D != 4 dimensions when gamma5 is involved. * * @param e Expression to take the trace of * @param rll List of representation labels * @param trONE Expression to be returned as the trace of the unit matrix */ ex dirac_trace(const ex & e, const lst & rll, const ex & trONE = 4); /** Calculate the trace of an expression containing gamma objects with * a specified representation label. The computed trace is a linear * functional that is equal to the usual trace only in D = 4 dimensions. * In particular, the functional is not always cyclic in D != 4 dimensions * when gamma5 is involved. * * @param e Expression to take the trace of * @param rl Representation label * @param trONE Expression to be returned as the trace of the unit matrix */ ex dirac_trace(const ex & e, unsigned char rl = 0, const ex & trONE = 4); /** Bring all products of clifford objects in an expression into a canonical * order. This is not necessarily the most simple form but it will allow * to check two expressions for equality. */ ex canonicalize_clifford(const ex & e); /** Automorphism of the Clifford algebra, simply changes signs of all * clifford units. */ ex clifford_prime(const ex & e); /** Main anti-automorphism of the Clifford algebra: makes reversion * and changes signs of all clifford units. */ inline ex clifford_bar(const ex & e) { return clifford_prime(e.conjugate()); } /** Reversion of the Clifford algebra, coincides with the conjugate(). */ inline ex clifford_star(const ex & e) { return e.conjugate(); } /** Replaces dirac_ONE's (with a representation_label no less than rl) in e with 1. * For the default value rl = 0 remove all of them. Aborts if e contains any * clifford_unit with representation_label to be removed. * * @param e Expression to be processed * @param rl Value of representation label * @param options Defines some internal use */ ex remove_dirac_ONE(const ex & e, unsigned char rl = 0, unsigned options = 0); /** Returns the maximal representation label of a clifford object * if e contains at least one, otherwise returns -1 * * @param e Expression to be processed * @ignore_ONE defines if clifford_ONE should be ignored in the search*/ int clifford_max_label(const ex & e, bool ignore_ONE = false); /** Calculation of the norm in the Clifford algebra. */ ex clifford_norm(const ex & e); /** Calculation of the inverse in the Clifford algebra. */ ex clifford_inverse(const ex & e); /** List or vector conversion into the Clifford vector. * * @param v List or vector of coordinates * @param mu Index (must be of class varidx or a derived class) * @param metr Metric (should be indexed, tensmetric or a derived class, or a matrix) * @param rl Representation label * @param e Clifford unit object * @return Clifford vector with given components */ ex lst_to_clifford(const ex & v, const ex & mu, const ex & metr, unsigned char rl = 0); ex lst_to_clifford(const ex & v, const ex & e); /** An inverse function to lst_to_clifford(). For given Clifford vector extracts * its components with respect to given Clifford unit. Obtained components may * contain Clifford units with a different metric. Extraction is based on * the algebraic formula (e * c.i + c.i * e)/ pow(e.i, 2) for non-degenerate cases * (i.e. neither pow(e.i, 2) = 0). * * @param e Clifford expression to be decomposed into components * @param c Clifford unit defining the metric for splitting (should have numeric dimension of indices) * @param algebraic Use algebraic or symbolic algorithm for extractions * @return List of components of a Clifford vector*/ lst clifford_to_lst(const ex & e, const ex & c, bool algebraic=true); /** Calculations of Moebius transformations (conformal map) defined by a 2x2 Clifford matrix * (a b\\c d) in linear spaces with arbitrary signature. The expression is * (a * x + b)/(c * x + d), where x is a vector build from list v with metric G. * (see Jan Cnops. An introduction to {D}irac operators on manifolds, v.24 of * Progress in Mathematical Physics. Birkhauser Boston Inc., Boston, MA, 2002.) * * @param a (1,1) entry of the defining matrix * @param b (1,2) entry of the defining matrix * @param c (2,1) entry of the defining matrix * @param d (2,2) entry of the defining matrix * @param v Vector to be transformed * @param G Metric of the surrounding space, may be a Clifford unit then the next parameter is ignored * @param rl Representation label * @return List of components of the transformed vector*/ ex clifford_moebius_map(const ex & a, const ex & b, const ex & c, const ex & d, const ex & v, const ex & G, unsigned char rl = 0); /** The second form of Moebius transformations defined by a 2x2 Clifford matrix M * This function takes the transformation matrix M as a single entity. * * @param M the defining matrix * @param v Vector to be transformed * @param G Metric of the surrounding space, may be a Clifford unit then the next parameter is ignored * @param rl Representation label * @return List of components of the transformed vector*/ ex clifford_moebius_map(const ex & M, const ex & v, const ex & G, unsigned char rl = 0); } // namespace GiNaC #endif // ndef GINAC_CLIFFORD_H ginac-1.6.2.orig/ginac/container.h0000644000000000000000000005627211562317235013663 0ustar /** @file container.h * * Wrapper template for making GiNaC classes out of STL containers. */ /* * GiNaC Copyright (C) 1999-2011 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef GINAC_CONTAINER_H #define GINAC_CONTAINER_H #include "ex.h" #include "print.h" #include "archive.h" #include "assertion.h" #include #include #include #include #include #include namespace GiNaC { /** Helper template for encapsulating the reserve() mechanics of STL containers. */ template