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-2015 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 (* expl_derivative_funcp)();
63 typedef ex (* power_funcp)();
64 typedef ex (* series_funcp)();
65 typedef void (* print_funcp)();
66 typedef bool (* info_funcp)();
68 // the following lines have been generated for max. @maxargs@ parameters
69 +++ for N, args in [ ( N, seq('const ex &', N) ) for N in range(1, maxargs + 1) ]:
70 typedef ex (* eval_funcp_@N@)( @args@ );
71 typedef ex (* evalf_funcp_@N@)( @args@ );
72 typedef ex (* conjugate_funcp_@N@)( @args@ );
73 typedef ex (* real_part_funcp_@N@)( @args@ );
74 typedef ex (* imag_part_funcp_@N@)( @args@ );
75 typedef ex (* expand_funcp_@N@)( @args@, unsigned );
76 typedef ex (* derivative_funcp_@N@)( @args@, unsigned );
77 typedef ex (* expl_derivative_funcp_@N@)( @args@, const symbol & );
78 typedef ex (* power_funcp_@N@)( @args@, const ex & );
79 typedef ex (* series_funcp_@N@)( @args@, const relational &, int, unsigned );
80 typedef void (* print_funcp_@N@)( @args@, const print_context & );
81 typedef bool (* info_funcp_@N@)( @args@, unsigned );
83 // end of generated lines
85 // Alternatively, an exvector may be passed into the static function, instead
86 // of individual ex objects. Then, the number of arguments is not limited.
87 +++ for fp in "eval evalf conjugate real_part imag_part".split():
88 typedef ex (* @fp@_funcp_exvector)(const exvector &);
90 typedef ex (* expand_funcp_exvector)(const exvector &, unsigned);
91 typedef ex (* derivative_funcp_exvector)(const exvector &, unsigned);
92 typedef ex (* expl_derivative_funcp_exvector)(const exvector &, const symbol &);
93 typedef ex (* power_funcp_exvector)(const exvector &, const ex &);
94 typedef ex (* series_funcp_exvector)(const exvector &, const relational &, int, unsigned);
95 typedef void (* print_funcp_exvector)(const exvector &, const print_context &);
96 typedef bool (* info_funcp_exvector)(const exvector &, unsigned);
99 class function_options
101 friend class function;
102 friend class fderivative;
105 function_options(std::string const & n, std::string const & tn=std::string());
106 function_options(std::string const & n, unsigned np);
110 function_options & dummy() { return *this; }
111 function_options & set_name(std::string const & n, std::string const & tn=std::string());
112 function_options & latex_name(std::string const & tn);
113 // following lines have been generated for max. @maxargs@ parameters
114 +++ for f, N in [ (f, N) for f in methods[0:-1] for N in range(1, maxargs + 1) ]:
115 function_options & @f@_func(@f@_funcp_@N@ e);
117 +++ for f in methods[0:-1]:
118 function_options & @f@_func(@f@_funcp_exvector e);
120 +++ for N in range(1, N + 1):
121 template <class Ctx> function_options & print_func(print_funcp_@N@ p)
123 test_and_set_nparams(@N@);
124 set_print_func(Ctx::get_class_info_static().options.get_id(), print_funcp(p));
128 // end of generated lines
130 template <class Ctx> function_options & print_func(print_funcp_exvector p)
132 print_use_exvector_args = true;
133 set_print_func(Ctx::get_class_info_static().options.get_id(), print_funcp(p));
137 function_options & set_return_type(unsigned rt, const return_type_t* rtt = 0);
138 function_options & do_not_evalf_params();
139 function_options & remember(unsigned size, unsigned assoc_size=0,
140 unsigned strategy=remember_strategies::delete_never);
141 function_options & overloaded(unsigned o);
142 function_options & set_symmetry(const symmetry & s);
144 std::string get_name() const { return name; }
145 unsigned get_nparams() const { return nparams; }
148 bool has_derivative() const { return derivative_f != nullptr; }
149 bool has_power() const { return power_f != nullptr; }
150 void test_and_set_nparams(unsigned n);
151 void set_print_func(unsigned id, print_funcp f);
154 std::string TeX_name;
160 conjugate_funcp conjugate_f;
161 real_part_funcp real_part_f;
162 imag_part_funcp imag_part_f;
163 expand_funcp expand_f;
164 derivative_funcp derivative_f;
165 expl_derivative_funcp expl_derivative_f;
167 series_funcp series_f;
168 std::vector<print_funcp> print_dispatch_table;
171 bool evalf_params_first;
173 bool use_return_type;
174 unsigned return_type;
175 return_type_t return_type_tinfo;
178 unsigned remember_size;
179 unsigned remember_assoc_size;
180 unsigned remember_strategy;
182 bool eval_use_exvector_args;
183 bool evalf_use_exvector_args;
184 bool conjugate_use_exvector_args;
185 bool real_part_use_exvector_args;
186 bool imag_part_use_exvector_args;
187 bool expand_use_exvector_args;
188 bool derivative_use_exvector_args;
189 bool expl_derivative_use_exvector_args;
190 bool power_use_exvector_args;
191 bool series_use_exvector_args;
192 bool print_use_exvector_args;
193 bool info_use_exvector_args;
195 unsigned functions_with_same_name;
201 /** Exception class thrown by classes which provide their own series expansion
202 * to signal that ordinary Taylor expansion is safe. */
206 /** The class function is used to implement builtin functions like sin, cos...
207 and user defined functions */
208 class function : public exprseq
210 GINAC_DECLARE_REGISTERED_CLASS(function, exprseq)
212 friend class remember_table_entry;
216 // other constructors
218 function(unsigned ser);
219 // the following lines have been generated for max. @maxargs@ parameters
220 +++ for N in range(1, maxargs + 1):
221 function(unsigned ser, @seq('const ex & param%(n)d', N)@);
223 // end of generated lines
224 function(unsigned ser, const exprseq & es);
225 function(unsigned ser, const exvector & v);
226 function(unsigned ser, exvector && v);
228 // functions overriding virtual functions from base classes
230 void print(const print_context & c, unsigned level = 0) const;
231 unsigned precedence() const {return 70;}
232 ex expand(unsigned options=0) const;
233 ex eval(int level=0) const;
234 ex evalf(int level=0) const;
235 ex eval_ncmul(const exvector & v) const;
236 unsigned calchash() const;
237 ex series(const relational & r, int order, unsigned options = 0) const;
238 ex thiscontainer(const exvector & v) const;
239 ex thiscontainer(exvector && v) const;
240 ex conjugate() const;
241 ex real_part() const;
242 ex imag_part() const;
243 void archive(archive_node& n) const;
244 void read_archive(const archive_node& n, lst& syms);
245 bool info(unsigned inf) const;
247 ex derivative(const symbol & s) const;
248 bool is_equal_same_type(const basic & other) const;
249 bool match_same_type(const basic & other) const;
250 unsigned return_type() const;
251 return_type_t return_type_tinfo() const;
253 // new virtual functions which can be overridden by derived classes
256 // non-virtual functions in this class
258 ex pderivative(unsigned diff_param) const; // partial differentiation
259 ex expl_derivative(const symbol & s) const; // partial differentiation
260 static std::vector<function_options> & registered_functions();
261 bool lookup_remember_table(ex & result) const;
262 void store_remember_table(ex const & result) const;
264 ex power(const ex & exp) const;
265 static unsigned register_new(function_options const & opt);
266 static unsigned current_serial;
267 static unsigned find_function(const std::string &name, unsigned nparams);
268 static std::vector<function_options> get_registered_functions() { return registered_functions(); };
269 unsigned get_serial() const {return serial;}
270 std::string get_name() const;
277 GINAC_DECLARE_UNARCHIVER(function);
279 // utility functions/macros
281 template <typename T>
282 inline bool is_the_function(const ex & x)
284 return is_exactly_a<function>(x)
285 && ex_to<function>(x).get_serial() == T::serial;
288 // Check whether OBJ is the specified symbolic function.
289 #define is_ex_the_function(OBJ, FUNCNAME) (GiNaC::is_the_function<FUNCNAME##_SERIAL>(OBJ))
293 #endif // ndef GINAC_FUNCTION_H