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-2014 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 (* expand_funcp)();
61 typedef ex (* derivative_funcp)();
62 typedef ex (* power_funcp)();
63 typedef ex (* series_funcp)();
64 typedef void (* print_funcp)();
65 typedef bool (* info_funcp)();
67 // the following lines have been generated for max. @maxargs@ parameters
68 +++ for N, args in [ ( N, seq('const ex &', N) ) for N in range(1, maxargs + 1) ]:
69 typedef ex (* eval_funcp_@N@)( @args@ );
70 typedef ex (* evalf_funcp_@N@)( @args@ );
71 typedef ex (* conjugate_funcp_@N@)( @args@ );
72 typedef ex (* real_part_funcp_@N@)( @args@ );
73 typedef ex (* imag_part_funcp_@N@)( @args@ );
74 typedef ex (* expand_funcp_@N@)( @args@, unsigned );
75 typedef ex (* derivative_funcp_@N@)( @args@, unsigned );
76 typedef ex (* power_funcp_@N@)( @args@, const ex & );
77 typedef ex (* series_funcp_@N@)( @args@, const relational &, int, unsigned );
78 typedef void (* print_funcp_@N@)( @args@, const print_context & );
79 typedef bool (* info_funcp_@N@)( @args@, unsigned );
81 // end of generated lines
83 // Alternatively, an exvector may be passed into the static function, instead
84 // of individual ex objects. Then, the number of arguments is not limited.
85 +++ for fp in "eval evalf conjugate real_part imag_part".split():
86 typedef ex (* @fp@_funcp_exvector)(const exvector &);
88 typedef ex (* expand_funcp_exvector)(const exvector &, unsigned);
89 typedef ex (* derivative_funcp_exvector)(const exvector &, unsigned);
90 typedef ex (* power_funcp_exvector)(const exvector &, const ex &);
91 typedef ex (* series_funcp_exvector)(const exvector &, const relational &, int, unsigned);
92 typedef void (* print_funcp_exvector)(const exvector &, const print_context &);
93 typedef bool (* info_funcp_exvector)(const exvector &, unsigned);
96 class function_options
98 friend class function;
99 friend class fderivative;
102 function_options(std::string const & n, std::string const & tn=std::string());
103 function_options(std::string const & n, unsigned np);
107 function_options & dummy() { return *this; }
108 function_options & set_name(std::string const & n, std::string const & tn=std::string());
109 function_options & latex_name(std::string const & tn);
110 // following lines have been generated for max. @maxargs@ parameters
111 +++ for f, N in [ (f, N) for f in methods[0:-1] for N in range(1, maxargs + 1) ]:
112 function_options & @f@_func(@f@_funcp_@N@ e);
114 +++ for f in methods[0:-1]:
115 function_options & @f@_func(@f@_funcp_exvector e);
117 +++ for N in range(1, N + 1):
118 template <class Ctx> function_options & print_func(print_funcp_@N@ p)
120 test_and_set_nparams(@N@);
121 set_print_func(Ctx::get_class_info_static().options.get_id(), print_funcp(p));
125 // end of generated lines
127 template <class Ctx> function_options & print_func(print_funcp_exvector p)
129 print_use_exvector_args = true;
130 set_print_func(Ctx::get_class_info_static().options.get_id(), print_funcp(p));
134 function_options & set_return_type(unsigned rt, const return_type_t* rtt = 0);
135 function_options & do_not_evalf_params();
136 function_options & remember(unsigned size, unsigned assoc_size=0,
137 unsigned strategy=remember_strategies::delete_never);
138 function_options & overloaded(unsigned o);
139 function_options & set_symmetry(const symmetry & s);
141 std::string get_name() const { return name; }
142 unsigned get_nparams() const { return nparams; }
145 bool has_derivative() const { return derivative_f != NULL; }
146 bool has_power() const { return power_f != NULL; }
147 void test_and_set_nparams(unsigned n);
148 void set_print_func(unsigned id, print_funcp f);
151 std::string TeX_name;
157 conjugate_funcp conjugate_f;
158 real_part_funcp real_part_f;
159 imag_part_funcp imag_part_f;
160 expand_funcp expand_f;
161 derivative_funcp derivative_f;
163 series_funcp series_f;
164 std::vector<print_funcp> print_dispatch_table;
167 bool evalf_params_first;
169 bool use_return_type;
170 unsigned return_type;
171 return_type_t return_type_tinfo;
174 unsigned remember_size;
175 unsigned remember_assoc_size;
176 unsigned remember_strategy;
178 bool eval_use_exvector_args;
179 bool evalf_use_exvector_args;
180 bool conjugate_use_exvector_args;
181 bool real_part_use_exvector_args;
182 bool imag_part_use_exvector_args;
183 bool expand_use_exvector_args;
184 bool derivative_use_exvector_args;
185 bool power_use_exvector_args;
186 bool series_use_exvector_args;
187 bool print_use_exvector_args;
188 bool info_use_exvector_args;
190 unsigned functions_with_same_name;
196 /** Exception class thrown by classes which provide their own series expansion
197 * to signal that ordinary Taylor expansion is safe. */
201 /** The class function is used to implement builtin functions like sin, cos...
202 and user defined functions */
203 class function : public exprseq
205 GINAC_DECLARE_REGISTERED_CLASS(function, exprseq)
207 friend class remember_table_entry;
211 // other constructors
213 function(unsigned ser);
214 // the following lines have been generated for max. @maxargs@ parameters
215 +++ for N in range(1, maxargs + 1):
216 function(unsigned ser, @seq('const ex & param%(n)d', N)@);
218 // end of generated lines
219 function(unsigned ser, const exprseq & es);
220 function(unsigned ser, const exvector & v, bool discardable = false);
221 function(unsigned ser, std::auto_ptr<exvector> vp);
223 // functions overriding virtual functions from base classes
225 void print(const print_context & c, unsigned level = 0) const;
226 unsigned precedence() const {return 70;}
227 ex expand(unsigned options=0) const;
228 ex eval(int level=0) const;
229 ex evalf(int level=0) const;
230 ex eval_ncmul(const exvector & v) const;
231 unsigned calchash() const;
232 ex series(const relational & r, int order, unsigned options = 0) const;
233 ex thiscontainer(const exvector & v) const;
234 ex thiscontainer(std::auto_ptr<exvector> vp) const;
235 ex conjugate() const;
236 ex real_part() const;
237 ex imag_part() const;
238 void archive(archive_node& n) const;
239 void read_archive(const archive_node& n, lst& syms);
240 bool info(unsigned inf) const;
242 ex derivative(const symbol & s) const;
243 bool is_equal_same_type(const basic & other) const;
244 bool match_same_type(const basic & other) const;
245 unsigned return_type() const;
246 return_type_t return_type_tinfo() const;
248 // new virtual functions which can be overridden by derived classes
251 // non-virtual functions in this class
253 ex pderivative(unsigned diff_param) const; // partial differentiation
254 static std::vector<function_options> & registered_functions();
255 bool lookup_remember_table(ex & result) const;
256 void store_remember_table(ex const & result) const;
258 ex power(const ex & exp) const;
259 static unsigned register_new(function_options const & opt);
260 static unsigned current_serial;
261 static unsigned find_function(const std::string &name, unsigned nparams);
262 static std::vector<function_options> get_registered_functions() { return registered_functions(); };
263 unsigned get_serial() const {return serial;}
264 std::string get_name() const;
271 GINAC_DECLARE_UNARCHIVER(function);
273 // utility functions/macros
275 template <typename T>
276 inline bool is_the_function(const ex & x)
278 return is_exactly_a<function>(x)
279 && ex_to<function>(x).get_serial() == T::serial;
282 // Check whether OBJ is the specified symbolic function.
283 #define is_ex_the_function(OBJ, FUNCNAME) (GiNaC::is_the_function<FUNCNAME##_SERIAL>(OBJ))
287 #endif // ndef GINAC_FUNCTION_H