/** @file function.h * * Interface to class of symbolic functions. */ /* * This file was generated automatically from function.hppy. * Please do not modify it directly, edit function.hppy instead! * * GiNaC Copyright (C) 1999-2010 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_FUNCTION_H #define GINAC_FUNCTION_H #include "exprseq.h" // CINT needs to work properly with #include #include #include +++ for N in range(1, maxargs + 1): #define DECLARE_FUNCTION_@N@P(NAME) \ class NAME##_SERIAL { public: static unsigned serial; }; \ const unsigned NAME##_NPARAMS = @N@; \ template< @seq('typename T%(n)d', N)@ > const GiNaC::function NAME( @seq('const T%(n)d & p%(n)d', N)@ ) { \ return GiNaC::function(NAME##_SERIAL::serial, @seq('GiNaC::ex(p%(n)d)', N)@ ); \ } --- // end of generated lines #define REGISTER_FUNCTION(NAME,OPT) \ unsigned NAME##_SERIAL::serial = \ GiNaC::function::register_new(GiNaC::function_options(#NAME, NAME##_NPARAMS).OPT); namespace GiNaC { class function; class symmetry; typedef ex (* eval_funcp)(); typedef ex (* evalf_funcp)(); typedef ex (* conjugate_funcp)(); typedef ex (* real_part_funcp)(); typedef ex (* imag_part_funcp)(); typedef ex (* expand_funcp)(); typedef ex (* derivative_funcp)(); typedef ex (* power_funcp)(); typedef ex (* series_funcp)(); typedef void (* print_funcp)(); typedef bool (* info_funcp)(); // the following lines have been generated for max. @maxargs@ parameters +++ for N, args in [ ( N, seq('const ex &', N) ) for N in range(1, maxargs + 1) ]: typedef ex (* eval_funcp_@N@)( @args@ ); typedef ex (* evalf_funcp_@N@)( @args@ ); typedef ex (* conjugate_funcp_@N@)( @args@ ); typedef ex (* real_part_funcp_@N@)( @args@ ); typedef ex (* imag_part_funcp_@N@)( @args@ ); typedef ex (* expand_funcp_@N@)( @args@, unsigned ); typedef ex (* derivative_funcp_@N@)( @args@, unsigned ); typedef ex (* power_funcp_@N@)( @args@, const ex & ); typedef ex (* series_funcp_@N@)( @args@, const relational &, int, unsigned ); typedef void (* print_funcp_@N@)( @args@, const print_context & ); typedef bool (* info_funcp_@N@)( @args@, unsigned ); --- // end of generated lines // Alternatively, an exvector may be passed into the static function, instead // of individual ex objects. Then, the number of arguments is not limited. +++ for fp in "eval evalf conjugate real_part imag_part".split(): typedef ex (* @fp@_funcp_exvector)(const exvector &); --- typedef ex (* expand_funcp_exvector)(const exvector &, unsigned); typedef ex (* derivative_funcp_exvector)(const exvector &, unsigned); typedef ex (* power_funcp_exvector)(const exvector &, const ex &); typedef ex (* series_funcp_exvector)(const exvector &, const relational &, int, unsigned); typedef void (* print_funcp_exvector)(const exvector &, const print_context &); typedef bool (* info_funcp_exvector)(const exvector &, unsigned); class function_options { friend class function; friend class fderivative; public: function_options(); function_options(std::string const & n, std::string const & tn=std::string()); function_options(std::string const & n, unsigned np); ~function_options(); void initialize(); function_options & dummy() { return *this; } function_options & set_name(std::string const & n, std::string const & tn=std::string()); function_options & latex_name(std::string const & tn); // following lines have been generated for max. @maxargs@ parameters +++ for f, N in [ (f, N) for f in methods[0:-1] for N in range(1, maxargs + 1) ]: function_options & @f@_func(@f@_funcp_@N@ e); --- +++ for f in methods[0:-1]: function_options & @f@_func(@f@_funcp_exvector e); --- +++ for N in range(1, N + 1): template function_options & print_func(print_funcp_@N@ p) { test_and_set_nparams(@N@); set_print_func(Ctx::get_class_info_static().options.get_id(), print_funcp(p)); return *this; } --- // end of generated lines template function_options & print_func(print_funcp_exvector p) { print_use_exvector_args = true; set_print_func(Ctx::get_class_info_static().options.get_id(), print_funcp(p)); return *this; } function_options & set_return_type(unsigned rt, const return_type_t* rtt = 0); function_options & do_not_evalf_params(); function_options & remember(unsigned size, unsigned assoc_size=0, unsigned strategy=remember_strategies::delete_never); function_options & overloaded(unsigned o); function_options & set_symmetry(const symmetry & s); std::string get_name() const { return name; } unsigned get_nparams() const { return nparams; } protected: bool has_derivative() const { return derivative_f != NULL; } bool has_power() const { return power_f != NULL; } void test_and_set_nparams(unsigned n); void set_print_func(unsigned id, print_funcp f); std::string name; std::string TeX_name; unsigned nparams; eval_funcp eval_f; evalf_funcp evalf_f; conjugate_funcp conjugate_f; real_part_funcp real_part_f; imag_part_funcp imag_part_f; expand_funcp expand_f; derivative_funcp derivative_f; power_funcp power_f; series_funcp series_f; std::vector print_dispatch_table; info_funcp info_f; bool evalf_params_first; bool use_return_type; unsigned return_type; return_type_t return_type_tinfo; bool use_remember; unsigned remember_size; unsigned remember_assoc_size; unsigned remember_strategy; bool eval_use_exvector_args; bool evalf_use_exvector_args; bool conjugate_use_exvector_args; bool real_part_use_exvector_args; bool imag_part_use_exvector_args; bool expand_use_exvector_args; bool derivative_use_exvector_args; bool power_use_exvector_args; bool series_use_exvector_args; bool print_use_exvector_args; bool info_use_exvector_args; unsigned functions_with_same_name; ex symtree; }; /** Exception class thrown by classes which provide their own series expansion * to signal that ordinary Taylor expansion is safe. */ class do_taylor {}; /** The class function is used to implement builtin functions like sin, cos... and user defined functions */ class function : public exprseq { GINAC_DECLARE_REGISTERED_CLASS(function, exprseq) friend class remember_table_entry; // member functions // other constructors public: function(unsigned ser); // the following lines have been generated for max. @maxargs@ parameters +++ for N in range(1, maxargs + 1): function(unsigned ser, @seq('const ex & param%(n)d', N)@); --- // end of generated lines function(unsigned ser, const exprseq & es); function(unsigned ser, const exvector & v, bool discardable = false); function(unsigned ser, std::auto_ptr vp); // functions overriding virtual functions from base classes public: void print(const print_context & c, unsigned level = 0) const; unsigned precedence() const {return 70;} ex expand(unsigned options=0) const; ex eval(int level=0) const; ex evalf(int level=0) const; ex eval_ncmul(const exvector & v) const; unsigned calchash() const; ex series(const relational & r, int order, unsigned options = 0) const; ex thiscontainer(const exvector & v) const; ex thiscontainer(std::auto_ptr vp) const; ex conjugate() const; ex real_part() const; ex imag_part() const; void archive(archive_node& n) const; void read_archive(const archive_node& n, lst& syms); bool info(unsigned inf) const; protected: ex derivative(const symbol & s) const; bool is_equal_same_type(const basic & other) const; bool match_same_type(const basic & other) const; unsigned return_type() const; return_type_t return_type_tinfo() const; // new virtual functions which can be overridden by derived classes // none // non-virtual functions in this class protected: ex pderivative(unsigned diff_param) const; // partial differentiation static std::vector & registered_functions(); bool lookup_remember_table(ex & result) const; void store_remember_table(ex const & result) const; public: ex power(const ex & exp) const; static unsigned register_new(function_options const & opt); static unsigned current_serial; static unsigned find_function(const std::string &name, unsigned nparams); static std::vector get_registered_functions() { return registered_functions(); }; unsigned get_serial() const {return serial;} std::string get_name() const; // member variables protected: unsigned serial; }; GINAC_DECLARE_UNARCHIVER(function); // utility functions/macros template inline bool is_the_function(const ex & x) { return is_exactly_a(x) && ex_to(x).get_serial() == T::serial; } // Check whether OBJ is the specified symbolic function. #define is_ex_the_function(OBJ, FUNCNAME) (GiNaC::is_the_function(OBJ)) } // namespace GiNaC #endif // ndef GINAC_FUNCTION_H