]> www.ginac.de Git - ginac.git/blob - ginac/function.hppy
fa178135451cb951d9c48bc958a67b7286260ed9
[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-2010 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
66 // the following lines have been generated for max. @maxargs@ parameters
67 +++ for N, args in [ ( N, seq('const ex &', N) ) for N in range(1, maxargs + 1) ]:
68 typedef ex (* eval_funcp_@N@)( @args@ );
69 typedef ex (* evalf_funcp_@N@)( @args@ );
70 typedef ex (* conjugate_funcp_@N@)( @args@ );
71 typedef ex (* real_part_funcp_@N@)( @args@ );
72 typedef ex (* imag_part_funcp_@N@)( @args@ );
73 typedef ex (* expand_funcp_@N@)( @args@, unsigned );
74 typedef ex (* derivative_funcp_@N@)( @args@, unsigned );
75 typedef ex (* power_funcp_@N@)( @args@, const ex & );
76 typedef ex (* series_funcp_@N@)( @args@, const relational &, int, unsigned );
77 typedef void (* print_funcp_@N@)( @args@, const print_context & );
78 ---
79 // end of generated lines
80
81 // Alternatively, an exvector may be passed into the static function, instead
82 // of individual ex objects.  Then, the number of arguments is not limited.
83 +++ for fp in "eval evalf conjugate real_part imag_part".split():
84 typedef ex (* @fp@_funcp_exvector)(const exvector &);
85 ---
86 typedef ex (* expand_funcp_exvector)(const exvector &, unsigned);
87 typedef ex (* derivative_funcp_exvector)(const exvector &, unsigned);
88 typedef ex (* power_funcp_exvector)(const exvector &, const ex &);
89 typedef ex (* series_funcp_exvector)(const exvector &, const relational &, int, unsigned);
90 typedef void (* print_funcp_exvector)(const exvector &, const print_context &);
91
92
93 class function_options
94 {
95         friend class function;
96         friend class fderivative;
97 public:
98         function_options();
99         function_options(std::string const & n, std::string const & tn=std::string());
100         function_options(std::string const & n, unsigned np);
101         ~function_options();
102         void initialize();
103
104         function_options & dummy() { return *this; }
105         function_options & set_name(std::string const & n, std::string const & tn=std::string());
106         function_options & latex_name(std::string const & tn);
107         // following lines have been generated for max. @maxargs@ parameters
108 +++ for f, N in [ (f, N) for f in methods[0:-1] for N in range(1, maxargs + 1) ]:
109         function_options & @f@_func(@f@_funcp_@N@ e);
110 ---
111 +++ for f in methods[0:-1]:
112         function_options & @f@_func(@f@_funcp_exvector e);
113 ---
114 +++ for N in range(1, N + 1):
115         template <class Ctx> function_options & print_func(print_funcp_@N@ p)
116         {
117                 test_and_set_nparams(@N@);
118                 set_print_func(Ctx::get_class_info_static().options.get_id(), print_funcp(p));
119                 return *this;
120         }
121 ---
122         // end of generated lines
123
124         template <class Ctx> function_options & print_func(print_funcp_exvector p)
125         {
126                 print_use_exvector_args = true;
127                 set_print_func(Ctx::get_class_info_static().options.get_id(), print_funcp(p));
128                 return *this;
129         }
130
131         function_options & set_return_type(unsigned rt, const return_type_t* rtt = 0);
132         function_options & do_not_evalf_params();
133         function_options & remember(unsigned size, unsigned assoc_size=0,
134                                     unsigned strategy=remember_strategies::delete_never);
135         function_options & overloaded(unsigned o);
136         function_options & set_symmetry(const symmetry & s);
137
138         std::string get_name() const { return name; }
139         unsigned get_nparams() const { return nparams; }
140
141 protected:
142         bool has_derivative() const { return derivative_f != NULL; }
143         bool has_power() const { return power_f != NULL; }
144         void test_and_set_nparams(unsigned n);
145         void set_print_func(unsigned id, print_funcp f);
146
147         std::string name;
148         std::string TeX_name;
149
150         unsigned nparams;
151
152         eval_funcp eval_f;
153         evalf_funcp evalf_f;
154         conjugate_funcp conjugate_f;
155         real_part_funcp real_part_f;
156         imag_part_funcp imag_part_f;
157         expand_funcp expand_f;
158         derivative_funcp derivative_f;
159         power_funcp power_f;
160         series_funcp series_f;
161         std::vector<print_funcp> print_dispatch_table;
162
163         bool evalf_params_first;
164
165         bool use_return_type;
166         unsigned return_type;
167         return_type_t return_type_tinfo;
168
169         bool use_remember;
170         unsigned remember_size;
171         unsigned remember_assoc_size;
172         unsigned remember_strategy;
173
174         bool eval_use_exvector_args;
175         bool evalf_use_exvector_args;
176         bool conjugate_use_exvector_args;
177         bool real_part_use_exvector_args;
178         bool imag_part_use_exvector_args;
179         bool expand_use_exvector_args;
180         bool derivative_use_exvector_args;
181         bool power_use_exvector_args;
182         bool series_use_exvector_args;
183         bool print_use_exvector_args;
184
185         unsigned functions_with_same_name;
186
187         ex symtree;
188 };
189
190
191 /** Exception class thrown by classes which provide their own series expansion
192  *  to signal that ordinary Taylor expansion is safe. */
193 class do_taylor {};
194
195
196 /** The class function is used to implement builtin functions like sin, cos...
197         and user defined functions */
198 class function : public exprseq
199 {
200         GINAC_DECLARE_REGISTERED_CLASS(function, exprseq)
201
202         friend class remember_table_entry;
203
204 // member functions
205
206         // other constructors
207 public:
208         function(unsigned ser);
209         // the following lines have been generated for max. @maxargs@ parameters
210 +++ for N in range(1, maxargs + 1):
211         function(unsigned ser, @seq('const ex & param%(n)d', N)@);
212 ---
213         // end of generated lines
214         function(unsigned ser, const exprseq & es);
215         function(unsigned ser, const exvector & v, bool discardable = false);
216         function(unsigned ser, std::auto_ptr<exvector> vp);
217         
218         // functions overriding virtual functions from base classes
219 public:
220         void print(const print_context & c, unsigned level = 0) const;
221         unsigned precedence() const {return 70;}
222         ex expand(unsigned options=0) const;
223         ex eval(int level=0) const;
224         ex evalf(int level=0) const;
225         ex eval_ncmul(const exvector & v) const;
226         unsigned calchash() const;
227         ex series(const relational & r, int order, unsigned options = 0) const;
228         ex thiscontainer(const exvector & v) const;
229         ex thiscontainer(std::auto_ptr<exvector> vp) const;
230         ex conjugate() const;
231         ex real_part() const;
232         ex imag_part() const;
233         void archive(archive_node& n) const;
234         void read_archive(const archive_node& n, lst& syms);
235 protected:
236         ex derivative(const symbol & s) const;
237         bool is_equal_same_type(const basic & other) const;
238         bool match_same_type(const basic & other) const;
239         unsigned return_type() const;
240         return_type_t return_type_tinfo() const;
241         
242         // new virtual functions which can be overridden by derived classes
243         // none
244         
245         // non-virtual functions in this class
246 protected:
247         ex pderivative(unsigned diff_param) const; // partial differentiation
248         static std::vector<function_options> & registered_functions();
249         bool lookup_remember_table(ex & result) const;
250         void store_remember_table(ex const & result) const;
251 public:
252         ex power(const ex & exp) const;
253         static unsigned register_new(function_options const & opt);
254         static unsigned current_serial;
255         static unsigned find_function(const std::string &name, unsigned nparams);
256         static std::vector<function_options> get_registered_functions() { return registered_functions(); };
257         unsigned get_serial() const {return serial;}
258         std::string get_name() const;
259
260 // member variables
261
262 protected:
263         unsigned serial;
264 };
265 GINAC_DECLARE_UNARCHIVER(function);
266
267 // utility functions/macros
268
269 template <typename T>
270 inline bool is_the_function(const ex & x)
271 {
272         return is_exactly_a<function>(x)
273             && ex_to<function>(x).get_serial() == T::serial;
274 }
275
276 // Check whether OBJ is the specified symbolic function.
277 #define is_ex_the_function(OBJ, FUNCNAME) (GiNaC::is_the_function<FUNCNAME##_SERIAL>(OBJ))
278
279 } // namespace GiNaC
280
281 #endif // ndef GINAC_FUNCTION_H
282