]> www.ginac.de Git - ginac.git/blob - ginac/function.hppy
Prepare for 1.6.3 release.
[ginac.git] / ginac / function.hppy
1 /** @file function.h
2  *
3  *  Interface to class of symbolic functions. */
4
5 /*
6  *  This file was generated automatically from function.hppy.
7  *  Please do not modify it directly, edit function.hppy instead!
8  *
9  *  GiNaC Copyright (C) 1999-2014 Johannes Gutenberg University Mainz, Germany
10  *
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.
15  *
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.
20  *
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
24  */
25
26 #ifndef GINAC_FUNCTION_H
27 #define GINAC_FUNCTION_H
28
29 #include "exprseq.h"
30
31 // CINT needs <algorithm> to work properly with <vector>
32 #include <algorithm>
33 #include <string>
34 #include <vector>
35
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)@ ); \
42 }
43 ---
44 // end of generated lines
45
46 #define REGISTER_FUNCTION(NAME,OPT) \
47 unsigned NAME##_SERIAL::serial = \
48         GiNaC::function::register_new(GiNaC::function_options(#NAME, NAME##_NPARAMS).OPT);
49
50 namespace GiNaC {
51
52 class function;
53 class symmetry;
54
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)();
66
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 );
80 ---
81 // end of generated lines
82
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 &);
87 ---
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);
94
95
96 class function_options
97 {
98         friend class function;
99         friend class fderivative;
100 public:
101         function_options();
102         function_options(std::string const & n, std::string const & tn=std::string());
103         function_options(std::string const & n, unsigned np);
104         ~function_options();
105         void initialize();
106
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);
113 ---
114 +++ for f in methods[0:-1]:
115         function_options & @f@_func(@f@_funcp_exvector e);
116 ---
117 +++ for N in range(1, N + 1):
118         template <class Ctx> function_options & print_func(print_funcp_@N@ p)
119         {
120                 test_and_set_nparams(@N@);
121                 set_print_func(Ctx::get_class_info_static().options.get_id(), print_funcp(p));
122                 return *this;
123         }
124 ---
125         // end of generated lines
126
127         template <class Ctx> function_options & print_func(print_funcp_exvector p)
128         {
129                 print_use_exvector_args = true;
130                 set_print_func(Ctx::get_class_info_static().options.get_id(), print_funcp(p));
131                 return *this;
132         }
133
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);
140
141         std::string get_name() const { return name; }
142         unsigned get_nparams() const { return nparams; }
143
144 protected:
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);
149
150         std::string name;
151         std::string TeX_name;
152
153         unsigned nparams;
154
155         eval_funcp eval_f;
156         evalf_funcp evalf_f;
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;
162         power_funcp power_f;
163         series_funcp series_f;
164         std::vector<print_funcp> print_dispatch_table;
165         info_funcp info_f;
166
167         bool evalf_params_first;
168
169         bool use_return_type;
170         unsigned return_type;
171         return_type_t return_type_tinfo;
172
173         bool use_remember;
174         unsigned remember_size;
175         unsigned remember_assoc_size;
176         unsigned remember_strategy;
177
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;
189
190         unsigned functions_with_same_name;
191
192         ex symtree;
193 };
194
195
196 /** Exception class thrown by classes which provide their own series expansion
197  *  to signal that ordinary Taylor expansion is safe. */
198 class do_taylor {};
199
200
201 /** The class function is used to implement builtin functions like sin, cos...
202         and user defined functions */
203 class function : public exprseq
204 {
205         GINAC_DECLARE_REGISTERED_CLASS(function, exprseq)
206
207         friend class remember_table_entry;
208
209 // member functions
210
211         // other constructors
212 public:
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)@);
217 ---
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);
222         
223         // functions overriding virtual functions from base classes
224 public:
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;
241 protected:
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;
247         
248         // new virtual functions which can be overridden by derived classes
249         // none
250         
251         // non-virtual functions in this class
252 protected:
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;
257 public:
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;
265
266 // member variables
267
268 protected:
269         unsigned serial;
270 };
271 GINAC_DECLARE_UNARCHIVER(function);
272
273 // utility functions/macros
274
275 template <typename T>
276 inline bool is_the_function(const ex & x)
277 {
278         return is_exactly_a<function>(x)
279             && ex_to<function>(x).get_serial() == T::serial;
280 }
281
282 // Check whether OBJ is the specified symbolic function.
283 #define is_ex_the_function(OBJ, FUNCNAME) (GiNaC::is_the_function<FUNCNAME##_SERIAL>(OBJ))
284
285 } // namespace GiNaC
286
287 #endif // ndef GINAC_FUNCTION_H
288