3 * Interface to class of symbolic functions. */
6 * This file was generated automatically from function.hppy.
7 * Please do not modify it directly, edit function.hppy instead!
9 * GiNaC Copyright (C) 1999-2010 Johannes Gutenberg University Mainz, Germany
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #ifndef GINAC_FUNCTION_H
27 #define GINAC_FUNCTION_H
31 // CINT needs <algorithm> to work properly with <vector>
36 +++ for N in range(1, maxargs + 1):
37 #define DECLARE_FUNCTION_@N@P(NAME) \
38 class NAME##_SERIAL { public: static unsigned serial; }; \
39 const unsigned NAME##_NPARAMS = @N@; \
40 template< @seq('typename T%(n)d', N)@ > const GiNaC::function NAME( @seq('const T%(n)d & p%(n)d', N)@ ) { \
41 return GiNaC::function(NAME##_SERIAL::serial, @seq('GiNaC::ex(p%(n)d)', N)@ ); \
44 // end of generated lines
46 #define REGISTER_FUNCTION(NAME,OPT) \
47 unsigned NAME##_SERIAL::serial = \
48 GiNaC::function::register_new(GiNaC::function_options(#NAME, NAME##_NPARAMS).OPT);
55 typedef ex (* eval_funcp)();
56 typedef ex (* evalf_funcp)();
57 typedef ex (* conjugate_funcp)();
58 typedef ex (* real_part_funcp)();
59 typedef ex (* imag_part_funcp)();
60 typedef ex (* derivative_funcp)();
61 typedef ex (* power_funcp)();
62 typedef ex (* series_funcp)();
63 typedef void (* print_funcp)();
65 // the following lines have been generated for max. @maxargs@ parameters
66 +++ for N, args in [ ( N, seq('const ex &', N) ) for N in range(1, maxargs + 1) ]:
67 typedef ex (* eval_funcp_@N@)( @args@ );
68 typedef ex (* evalf_funcp_@N@)( @args@ );
69 typedef ex (* conjugate_funcp_@N@)( @args@ );
70 typedef ex (* real_part_funcp_@N@)( @args@ );
71 typedef ex (* imag_part_funcp_@N@)( @args@ );
72 typedef ex (* derivative_funcp_@N@)( @args@, unsigned );
73 typedef ex (* power_funcp_@N@)( @args@, const ex & );
74 typedef ex (* series_funcp_@N@)( @args@, const relational &, int, unsigned );
75 typedef void (* print_funcp_@N@)( @args@, const print_context & );
77 // end of generated lines
79 // Alternatively, an exvector may be passed into the static function, instead
80 // of individual ex objects. Then, the number of arguments is not limited.
81 +++ for fp in "eval evalf conjugate real_part imag_part".split():
82 typedef ex (* @fp@_funcp_exvector)(const exvector &);
84 typedef ex (* derivative_funcp_exvector)(const exvector &, unsigned);
85 typedef ex (* power_funcp_exvector)(const exvector &, const ex &);
86 typedef ex (* series_funcp_exvector)(const exvector &, const relational &, int, unsigned);
87 typedef void (* print_funcp_exvector)(const exvector &, const print_context &);
90 class function_options
92 friend class function;
93 friend class fderivative;
96 function_options(std::string const & n, std::string const & tn=std::string());
97 function_options(std::string const & n, unsigned np);
101 function_options & dummy() { return *this; }
102 function_options & set_name(std::string const & n, std::string const & tn=std::string());
103 function_options & latex_name(std::string const & tn);
104 // following lines have been generated for max. @maxargs@ parameters
105 +++ for f, N in [ (f, N) for f in methods[0:-1] for N in range(1, maxargs + 1) ]:
106 function_options & @f@_func(@f@_funcp_@N@ e);
108 +++ for f in methods[0:-1]:
109 function_options & @f@_func(@f@_funcp_exvector e);
111 +++ for N in range(1, N + 1):
112 template <class Ctx> function_options & print_func(print_funcp_@N@ p)
114 test_and_set_nparams(@N@);
115 set_print_func(Ctx::get_class_info_static().options.get_id(), print_funcp(p));
119 // end of generated lines
121 template <class Ctx> function_options & print_func(print_funcp_exvector p)
123 print_use_exvector_args = true;
124 set_print_func(Ctx::get_class_info_static().options.get_id(), print_funcp(p));
128 function_options & set_return_type(unsigned rt, const return_type_t* rtt = 0);
129 function_options & do_not_evalf_params();
130 function_options & remember(unsigned size, unsigned assoc_size=0,
131 unsigned strategy=remember_strategies::delete_never);
132 function_options & overloaded(unsigned o);
133 function_options & set_symmetry(const symmetry & s);
135 std::string get_name() const { return name; }
136 unsigned get_nparams() const { return nparams; }
139 bool has_derivative() const { return derivative_f != NULL; }
140 bool has_power() const { return power_f != NULL; }
141 void test_and_set_nparams(unsigned n);
142 void set_print_func(unsigned id, print_funcp f);
145 std::string TeX_name;
151 conjugate_funcp conjugate_f;
152 real_part_funcp real_part_f;
153 imag_part_funcp imag_part_f;
154 derivative_funcp derivative_f;
156 series_funcp series_f;
157 std::vector<print_funcp> print_dispatch_table;
159 bool evalf_params_first;
161 bool use_return_type;
162 unsigned return_type;
163 return_type_t return_type_tinfo;
166 unsigned remember_size;
167 unsigned remember_assoc_size;
168 unsigned remember_strategy;
170 bool eval_use_exvector_args;
171 bool evalf_use_exvector_args;
172 bool conjugate_use_exvector_args;
173 bool real_part_use_exvector_args;
174 bool imag_part_use_exvector_args;
175 bool derivative_use_exvector_args;
176 bool power_use_exvector_args;
177 bool series_use_exvector_args;
178 bool print_use_exvector_args;
180 unsigned functions_with_same_name;
186 /** Exception class thrown by classes which provide their own series expansion
187 * to signal that ordinary Taylor expansion is safe. */
191 /** The class function is used to implement builtin functions like sin, cos...
192 and user defined functions */
193 class function : public exprseq
195 GINAC_DECLARE_REGISTERED_CLASS(function, exprseq)
197 friend class remember_table_entry;
201 // other constructors
203 function(unsigned ser);
204 // the following lines have been generated for max. @maxargs@ parameters
205 +++ for N in range(1, maxargs + 1):
206 function(unsigned ser, @seq('const ex & param%(n)d', N)@);
208 // end of generated lines
209 function(unsigned ser, const exprseq & es);
210 function(unsigned ser, const exvector & v, bool discardable = false);
211 function(unsigned ser, std::auto_ptr<exvector> vp);
213 // functions overriding virtual functions from base classes
215 void print(const print_context & c, unsigned level = 0) const;
216 unsigned precedence() const {return 70;}
217 ex expand(unsigned options=0) const;
218 ex eval(int level=0) const;
219 ex evalf(int level=0) const;
220 ex eval_ncmul(const exvector & v) const;
221 unsigned calchash() const;
222 ex series(const relational & r, int order, unsigned options = 0) const;
223 ex thiscontainer(const exvector & v) const;
224 ex thiscontainer(std::auto_ptr<exvector> vp) const;
225 ex conjugate() const;
226 ex real_part() const;
227 ex imag_part() const;
228 void archive(archive_node& n) const;
229 void read_archive(const archive_node& n, lst& syms);
231 ex derivative(const symbol & s) const;
232 bool is_equal_same_type(const basic & other) const;
233 bool match_same_type(const basic & other) const;
234 unsigned return_type() const;
235 return_type_t return_type_tinfo() const;
237 // new virtual functions which can be overridden by derived classes
240 // non-virtual functions in this class
242 ex pderivative(unsigned diff_param) const; // partial differentiation
243 static std::vector<function_options> & registered_functions();
244 bool lookup_remember_table(ex & result) const;
245 void store_remember_table(ex const & result) const;
247 ex power(const ex & exp) const;
248 static unsigned register_new(function_options const & opt);
249 static unsigned current_serial;
250 static unsigned find_function(const std::string &name, unsigned nparams);
251 static std::vector<function_options> get_registered_functions() { return registered_functions(); };
252 unsigned get_serial() const {return serial;}
253 std::string get_name() const;
260 GINAC_DECLARE_UNARCHIVER(function);
262 // utility functions/macros
264 template <typename T>
265 inline bool is_the_function(const ex & x)
267 return is_exactly_a<function>(x)
268 && ex_to<function>(x).get_serial() == T::serial;
271 // Check whether OBJ is the specified symbolic function.
272 #define is_ex_the_function(OBJ, FUNCNAME) (GiNaC::is_the_function<FUNCNAME##_SERIAL>(OBJ))
276 #endif // ndef GINAC_FUNCTION_H