]> www.ginac.de Git - ginac.git/blob - ginac/function.h
- modified GiNaC headers to Alexander's liking
[ginac.git] / ginac / function.h
1 /** @file function.h
2  *
3  *  Interface to abstract class function (new function concept).
4  *
5  *  This file was generated automatically by function.pl.
6  *  Please do not modify it directly, edit the perl script instead!
7  *  function.pl options: $maxargs=10
8  *
9  *  GiNaC Copyright (C) 1999 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24  */
25
26 #ifndef __GINAC_FUNCTION_H__
27 #define __GINAC_FUNCTION_H__
28
29 #include <string>
30 #include <vector>
31 #include <ginac/exprseq.h>
32
33 class function;
34
35 // the following lines have been generated for max. 10 parameters
36 #define DECLARE_FUNCTION_1P(NAME) \
37 extern unsigned function_index_##NAME; \
38 inline function NAME(ex const & p1) { \
39     return function(function_index_##NAME, p1); \
40 }
41
42 #define DECLARE_FUNCTION_2P(NAME) \
43 extern unsigned function_index_##NAME; \
44 inline function NAME(ex const & p1, ex const & p2) { \
45     return function(function_index_##NAME, p1, p2); \
46 }
47
48 #define DECLARE_FUNCTION_3P(NAME) \
49 extern unsigned function_index_##NAME; \
50 inline function NAME(ex const & p1, ex const & p2, ex const & p3) { \
51     return function(function_index_##NAME, p1, p2, p3); \
52 }
53
54 #define DECLARE_FUNCTION_4P(NAME) \
55 extern unsigned function_index_##NAME; \
56 inline function NAME(ex const & p1, ex const & p2, ex const & p3, ex const & p4) { \
57     return function(function_index_##NAME, p1, p2, p3, p4); \
58 }
59
60 #define DECLARE_FUNCTION_5P(NAME) \
61 extern unsigned function_index_##NAME; \
62 inline function NAME(ex const & p1, ex const & p2, ex const & p3, ex const & p4, ex const & p5) { \
63     return function(function_index_##NAME, p1, p2, p3, p4, p5); \
64 }
65
66 #define DECLARE_FUNCTION_6P(NAME) \
67 extern unsigned function_index_##NAME; \
68 inline function NAME(ex const & p1, ex const & p2, ex const & p3, ex const & p4, ex const & p5, ex const & p6) { \
69     return function(function_index_##NAME, p1, p2, p3, p4, p5, p6); \
70 }
71
72 #define DECLARE_FUNCTION_7P(NAME) \
73 extern unsigned function_index_##NAME; \
74 inline function NAME(ex const & p1, ex const & p2, ex const & p3, ex const & p4, ex const & p5, ex const & p6, ex const & p7) { \
75     return function(function_index_##NAME, p1, p2, p3, p4, p5, p6, p7); \
76 }
77
78 #define DECLARE_FUNCTION_8P(NAME) \
79 extern unsigned function_index_##NAME; \
80 inline function NAME(ex const & p1, ex const & p2, ex const & p3, ex const & p4, ex const & p5, ex const & p6, ex const & p7, ex const & p8) { \
81     return function(function_index_##NAME, p1, p2, p3, p4, p5, p6, p7, p8); \
82 }
83
84 #define DECLARE_FUNCTION_9P(NAME) \
85 extern unsigned function_index_##NAME; \
86 inline function NAME(ex const & p1, ex const & p2, ex const & p3, ex const & p4, ex const & p5, ex const & p6, ex const & p7, ex const & p8, ex const & p9) { \
87     return function(function_index_##NAME, p1, p2, p3, p4, p5, p6, p7, p8, p9); \
88 }
89
90 #define DECLARE_FUNCTION_10P(NAME) \
91 extern unsigned function_index_##NAME; \
92 inline function NAME(ex const & p1, ex const & p2, ex const & p3, ex const & p4, ex const & p5, ex const & p6, ex const & p7, ex const & p8, ex const & p9, ex const & p10) { \
93     return function(function_index_##NAME, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10); \
94 }
95
96
97 // end of generated lines
98
99 #define REGISTER_FUNCTION(NAME,E,EF,D,S) \
100 unsigned function_index_##NAME=function::register_new(#NAME,E,EF,D,S);
101
102 #define BEGIN_TYPECHECK \
103 bool automatic_typecheck=true;
104
105 #define TYPECHECK(VAR,TYPE) \
106 if (!is_ex_exactly_of_type(VAR,TYPE)) { \
107     automatic_typecheck=false; \
108 } else
109
110 #define TYPECHECK_INTEGER(VAR) \
111 if (!(VAR).info(info_flags::integer)) { \
112     automatic_typecheck=false; \
113 } else
114
115 #define END_TYPECHECK(RV) \
116 {} \
117 if (!automatic_typecheck) { \
118     return RV.hold(); \
119 }
120
121 typedef ex (* eval_funcp)();
122 typedef ex (* evalf_funcp)();
123 typedef ex (* diff_funcp)();
124 typedef ex (* series_funcp)();
125
126 // the following lines have been generated for max. 10 parameters
127 typedef ex (* eval_funcp_1)(ex const &);
128 typedef ex (* eval_funcp_2)(ex const &, ex const &);
129 typedef ex (* eval_funcp_3)(ex const &, ex const &, ex const &);
130 typedef ex (* eval_funcp_4)(ex const &, ex const &, ex const &, ex const &);
131 typedef ex (* eval_funcp_5)(ex const &, ex const &, ex const &, ex const &, ex const &);
132 typedef ex (* eval_funcp_6)(ex const &, ex const &, ex const &, ex const &, ex const &, ex const &);
133 typedef ex (* eval_funcp_7)(ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &);
134 typedef ex (* eval_funcp_8)(ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &);
135 typedef ex (* eval_funcp_9)(ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &);
136 typedef ex (* eval_funcp_10)(ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &);
137
138 typedef ex (* evalf_funcp_1)(ex const &);
139 typedef ex (* evalf_funcp_2)(ex const &, ex const &);
140 typedef ex (* evalf_funcp_3)(ex const &, ex const &, ex const &);
141 typedef ex (* evalf_funcp_4)(ex const &, ex const &, ex const &, ex const &);
142 typedef ex (* evalf_funcp_5)(ex const &, ex const &, ex const &, ex const &, ex const &);
143 typedef ex (* evalf_funcp_6)(ex const &, ex const &, ex const &, ex const &, ex const &, ex const &);
144 typedef ex (* evalf_funcp_7)(ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &);
145 typedef ex (* evalf_funcp_8)(ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &);
146 typedef ex (* evalf_funcp_9)(ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &);
147 typedef ex (* evalf_funcp_10)(ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &);
148
149 typedef ex (* diff_funcp_1)(ex const &, unsigned);
150 typedef ex (* diff_funcp_2)(ex const &, ex const &, unsigned);
151 typedef ex (* diff_funcp_3)(ex const &, ex const &, ex const &, unsigned);
152 typedef ex (* diff_funcp_4)(ex const &, ex const &, ex const &, ex const &, unsigned);
153 typedef ex (* diff_funcp_5)(ex const &, ex const &, ex const &, ex const &, ex const &, unsigned);
154 typedef ex (* diff_funcp_6)(ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, unsigned);
155 typedef ex (* diff_funcp_7)(ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, unsigned);
156 typedef ex (* diff_funcp_8)(ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, unsigned);
157 typedef ex (* diff_funcp_9)(ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, unsigned);
158 typedef ex (* diff_funcp_10)(ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, unsigned);
159
160 typedef ex (* series_funcp_1)(ex const &, symbol const &, ex const &, int);
161 typedef ex (* series_funcp_2)(ex const &, ex const &, symbol const &, ex const &, int);
162 typedef ex (* series_funcp_3)(ex const &, ex const &, ex const &, symbol const &, ex const &, int);
163 typedef ex (* series_funcp_4)(ex const &, ex const &, ex const &, ex const &, symbol const &, ex const &, int);
164 typedef ex (* series_funcp_5)(ex const &, ex const &, ex const &, ex const &, ex const &, symbol const &, ex const &, int);
165 typedef ex (* series_funcp_6)(ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, symbol const &, ex const &, int);
166 typedef ex (* series_funcp_7)(ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, symbol const &, ex const &, int);
167 typedef ex (* series_funcp_8)(ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, symbol const &, ex const &, int);
168 typedef ex (* series_funcp_9)(ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, symbol const &, ex const &, int);
169 typedef ex (* series_funcp_10)(ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, ex const &, symbol const &, ex const &, int);
170
171 // end of generated lines
172
173 struct registered_function_info {
174     char const * name;
175     unsigned nparams;
176     unsigned options;
177     eval_funcp e;
178     evalf_funcp ef;
179     diff_funcp d;
180     series_funcp s;
181 };
182
183 /** The class function is used to implement builtin functions like sin, cos...
184     and user defined functions */
185 class function : public exprseq
186 {
187     friend void ginsh_get_ginac_functions(void);
188
189 // member functions
190
191     // default constructor, destructor, copy constructor assignment operator and helpers
192 public:
193     function();
194     ~function();
195     function(function const & other);
196     function const & operator=(function const & other);
197 protected:
198     void copy(function const & other);
199     void destroy(bool call_parent);
200
201     // other constructors
202 public:
203     function(unsigned ser);
204     // the following lines have been generated for max. 10 parameters
205     function(unsigned ser, ex const & param1);
206     function(unsigned ser, ex const & param1, ex const & param2);
207     function(unsigned ser, ex const & param1, ex const & param2, ex const & param3);
208     function(unsigned ser, ex const & param1, ex const & param2, ex const & param3, ex const & param4);
209     function(unsigned ser, ex const & param1, ex const & param2, ex const & param3, ex const & param4, ex const & param5);
210     function(unsigned ser, ex const & param1, ex const & param2, ex const & param3, ex const & param4, ex const & param5, ex const & param6);
211     function(unsigned ser, ex const & param1, ex const & param2, ex const & param3, ex const & param4, ex const & param5, ex const & param6, ex const & param7);
212     function(unsigned ser, ex const & param1, ex const & param2, ex const & param3, ex const & param4, ex const & param5, ex const & param6, ex const & param7, ex const & param8);
213     function(unsigned ser, ex const & param1, ex const & param2, ex const & param3, ex const & param4, ex const & param5, ex const & param6, ex const & param7, ex const & param8, ex const & param9);
214     function(unsigned ser, ex const & param1, ex const & param2, ex const & param3, ex const & param4, ex const & param5, ex const & param6, ex const & param7, ex const & param8, ex const & param9, ex const & param10);
215
216     // end of generated lines
217     function(unsigned ser, exprseq const & es);
218     function(unsigned ser, exvector const & v, bool discardable=0);
219     function(unsigned ser, exvector * vp); // vp will be deleted
220
221     // functions overriding virtual functions from bases classes
222 public:
223     basic * duplicate() const;
224     void printraw(ostream & os) const; 
225     void print(ostream & os, unsigned upper_precedence=0) const;
226     void printtree(ostream & os, unsigned indent) const;
227     void printcsrc(ostream & os, unsigned type, unsigned upper_precedence=0) const;
228     ex expand(unsigned options=0) const;
229     ex eval(int level=0) const;
230     ex evalf(int level=0) const;
231     ex diff(symbol const & s) const;
232     ex series(symbol const & s, ex const & point, int order) const;
233     ex thisexprseq(exvector const & v) const;
234     ex thisexprseq(exvector * vp) const;
235 protected:
236     int compare_same_type(basic const & other) const;
237     bool is_equal_same_type(basic const & other) const;
238     unsigned return_type(void) const;
239     unsigned return_type_tinfo(void) const;
240     
241     // new virtual functions which can be overridden by derived classes
242     // none
243     
244     // non-virtual functions in this class
245 protected:
246     ex pdiff(unsigned diff_param) const; // partial differentiation
247     static vector<registered_function_info> & registered_functions(void);
248 public:
249     // the following lines have been generated for max. 10 parameters
250     static unsigned register_new(char const * nm, eval_funcp_1 e,
251                                  evalf_funcp_1 ef=0, diff_funcp_1 d=0, series_funcp_1 s=0);
252     static unsigned register_new(char const * nm, eval_funcp_2 e,
253                                  evalf_funcp_2 ef=0, diff_funcp_2 d=0, series_funcp_2 s=0);
254     static unsigned register_new(char const * nm, eval_funcp_3 e,
255                                  evalf_funcp_3 ef=0, diff_funcp_3 d=0, series_funcp_3 s=0);
256     static unsigned register_new(char const * nm, eval_funcp_4 e,
257                                  evalf_funcp_4 ef=0, diff_funcp_4 d=0, series_funcp_4 s=0);
258     static unsigned register_new(char const * nm, eval_funcp_5 e,
259                                  evalf_funcp_5 ef=0, diff_funcp_5 d=0, series_funcp_5 s=0);
260     static unsigned register_new(char const * nm, eval_funcp_6 e,
261                                  evalf_funcp_6 ef=0, diff_funcp_6 d=0, series_funcp_6 s=0);
262     static unsigned register_new(char const * nm, eval_funcp_7 e,
263                                  evalf_funcp_7 ef=0, diff_funcp_7 d=0, series_funcp_7 s=0);
264     static unsigned register_new(char const * nm, eval_funcp_8 e,
265                                  evalf_funcp_8 ef=0, diff_funcp_8 d=0, series_funcp_8 s=0);
266     static unsigned register_new(char const * nm, eval_funcp_9 e,
267                                  evalf_funcp_9 ef=0, diff_funcp_9 d=0, series_funcp_9 s=0);
268     static unsigned register_new(char const * nm, eval_funcp_10 e,
269                                  evalf_funcp_10 ef=0, diff_funcp_10 d=0, series_funcp_10 s=0);
270
271     // end of generated lines
272     unsigned getserial(void) const {return serial;}
273     
274 // member variables
275
276 protected:
277     unsigned serial;
278 };
279
280 // utility macros
281
282 #define is_ex_the_function(OBJ, FUNCNAME) \
283     (is_ex_exactly_of_type(OBJ, function) && static_cast<function *>(OBJ.bp)->getserial() == function_index_##FUNCNAME)
284
285 // global constants
286
287 extern const function some_function;
288 extern type_info const & typeid_function;
289
290 #endif // ndef __GINAC_FUNCTION_H__