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