3 * Implementation of class function.
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
9 * GiNaC Copyright (C) 1999 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 // default constructor, destructor, copy constructor assignment operator and helpers
37 function::function() : serial(0)
39 debugmsg("function default constructor",LOGLEVEL_CONSTRUCT);
40 tinfo_key = TINFO_FUNCTION;
45 debugmsg("function destructor",LOGLEVEL_DESTRUCT);
49 function::function(function const & other)
51 debugmsg("function copy constructor",LOGLEVEL_CONSTRUCT);
55 function const & function::operator=(function const & other)
57 debugmsg("function operator=",LOGLEVEL_ASSIGNMENT);
67 void function::copy(function const & other)
73 void function::destroy(bool call_parent)
75 if (call_parent) exprseq::destroy(call_parent);
84 function::function(unsigned ser) : serial(ser)
86 debugmsg("function constructor from unsigned",LOGLEVEL_CONSTRUCT);
87 tinfo_key = TINFO_FUNCTION;
90 // the following lines have been generated for max. 10 parameters
91 function::function(unsigned ser, ex const & param1)
92 : exprseq(param1), serial(ser)
94 debugmsg("function constructor from unsigned,1*ex",LOGLEVEL_CONSTRUCT);
95 tinfo_key = TINFO_FUNCTION;
97 function::function(unsigned ser, ex const & param1, ex const & param2)
98 : exprseq(param1, param2), serial(ser)
100 debugmsg("function constructor from unsigned,2*ex",LOGLEVEL_CONSTRUCT);
101 tinfo_key = TINFO_FUNCTION;
103 function::function(unsigned ser, ex const & param1, ex const & param2, ex const & param3)
104 : exprseq(param1, param2, param3), serial(ser)
106 debugmsg("function constructor from unsigned,3*ex",LOGLEVEL_CONSTRUCT);
107 tinfo_key = TINFO_FUNCTION;
109 function::function(unsigned ser, ex const & param1, ex const & param2, ex const & param3, ex const & param4)
110 : exprseq(param1, param2, param3, param4), serial(ser)
112 debugmsg("function constructor from unsigned,4*ex",LOGLEVEL_CONSTRUCT);
113 tinfo_key = TINFO_FUNCTION;
115 function::function(unsigned ser, ex const & param1, ex const & param2, ex const & param3, ex const & param4, ex const & param5)
116 : exprseq(param1, param2, param3, param4, param5), serial(ser)
118 debugmsg("function constructor from unsigned,5*ex",LOGLEVEL_CONSTRUCT);
119 tinfo_key = TINFO_FUNCTION;
121 function::function(unsigned ser, ex const & param1, ex const & param2, ex const & param3, ex const & param4, ex const & param5, ex const & param6)
122 : exprseq(param1, param2, param3, param4, param5, param6), serial(ser)
124 debugmsg("function constructor from unsigned,6*ex",LOGLEVEL_CONSTRUCT);
125 tinfo_key = TINFO_FUNCTION;
127 function::function(unsigned ser, ex const & param1, ex const & param2, ex const & param3, ex const & param4, ex const & param5, ex const & param6, ex const & param7)
128 : exprseq(param1, param2, param3, param4, param5, param6, param7), serial(ser)
130 debugmsg("function constructor from unsigned,7*ex",LOGLEVEL_CONSTRUCT);
131 tinfo_key = TINFO_FUNCTION;
133 function::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)
134 : exprseq(param1, param2, param3, param4, param5, param6, param7, param8), serial(ser)
136 debugmsg("function constructor from unsigned,8*ex",LOGLEVEL_CONSTRUCT);
137 tinfo_key = TINFO_FUNCTION;
139 function::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)
140 : exprseq(param1, param2, param3, param4, param5, param6, param7, param8, param9), serial(ser)
142 debugmsg("function constructor from unsigned,9*ex",LOGLEVEL_CONSTRUCT);
143 tinfo_key = TINFO_FUNCTION;
145 function::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)
146 : exprseq(param1, param2, param3, param4, param5, param6, param7, param8, param9, param10), serial(ser)
148 debugmsg("function constructor from unsigned,10*ex",LOGLEVEL_CONSTRUCT);
149 tinfo_key = TINFO_FUNCTION;
152 // end of generated lines
154 function::function(unsigned ser, exprseq const & es) : exprseq(es), serial(ser)
156 debugmsg("function constructor from unsigned,exprseq",LOGLEVEL_CONSTRUCT);
157 tinfo_key = TINFO_FUNCTION;
160 function::function(unsigned ser, exvector const & v, bool discardable)
161 : exprseq(v,discardable), serial(ser)
163 debugmsg("function constructor from string,exvector,bool",LOGLEVEL_CONSTRUCT);
164 tinfo_key = TINFO_FUNCTION;
167 function::function(unsigned ser, exvector * vp)
168 : exprseq(vp), serial(ser)
170 debugmsg("function constructor from unsigned,exvector *",LOGLEVEL_CONSTRUCT);
171 tinfo_key = TINFO_FUNCTION;
175 // functions overriding virtual functions from bases classes
180 basic * function::duplicate() const
182 debugmsg("function duplicate",LOGLEVEL_DUPLICATE);
183 return new function(*this);
186 void function::printraw(ostream & os) const
188 debugmsg("function printraw",LOGLEVEL_PRINT);
190 ASSERT(serial<registered_functions().size());
192 os << "function(name=" << registered_functions()[serial].name;
193 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
200 void function::print(ostream & os, unsigned upper_precedence) const
202 debugmsg("function print",LOGLEVEL_PRINT);
204 ASSERT(serial<registered_functions().size());
206 os << registered_functions()[serial].name;
207 printseq(os,'(',',',')',exprseq::precedence,function::precedence);
210 void function::printtree(ostream & os, unsigned indent) const
212 debugmsg("function printtree",LOGLEVEL_PRINT);
214 ASSERT(serial<registered_functions().size());
216 os << string(indent,' ') << "function "
217 << registered_functions()[serial].name
218 << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
219 << ", flags=" << flags
220 << ", nops=" << nops() << endl;
221 for (int i=0; i<nops(); ++i) {
222 seq[i].printtree(os,indent+delta_indent);
224 os << string(indent+delta_indent,' ') << "=====" << endl;
227 void function::printcsrc(ostream & os, unsigned type, unsigned upper_precedence) const
229 debugmsg("function print csrc",LOGLEVEL_PRINT);
231 ASSERT(serial<registered_functions().size());
233 // Print function name in lowercase
235 lname=registered_functions()[serial].name;
236 for (unsigned i=0; i<lname.size(); i++)
237 lname[i] = tolower(lname[i]);
240 // Print arguments, separated by commas
241 exvector::const_iterator it = seq.begin();
242 exvector::const_iterator itend = seq.end();
243 while (it != itend) {
244 it->bp->printcsrc(os, type, 0);
252 ex function::expand(unsigned options) const
254 return this->setflag(status_flags::expanded);
257 ex function::eval(int level) const
259 ASSERT(serial<registered_functions().size());
261 exvector eseq=evalchildren(level);
263 if (registered_functions()[serial].e==0) {
264 return function(serial,eseq).hold();
266 switch (registered_functions()[serial].nparams) {
267 // the following lines have been generated for max. 10 parameters
269 return ((eval_funcp_1)(registered_functions()[serial].e))(eseq[1-1]);
272 return ((eval_funcp_2)(registered_functions()[serial].e))(eseq[1-1], eseq[2-1]);
275 return ((eval_funcp_3)(registered_functions()[serial].e))(eseq[1-1], eseq[2-1], eseq[3-1]);
278 return ((eval_funcp_4)(registered_functions()[serial].e))(eseq[1-1], eseq[2-1], eseq[3-1], eseq[4-1]);
281 return ((eval_funcp_5)(registered_functions()[serial].e))(eseq[1-1], eseq[2-1], eseq[3-1], eseq[4-1], eseq[5-1]);
284 return ((eval_funcp_6)(registered_functions()[serial].e))(eseq[1-1], eseq[2-1], eseq[3-1], eseq[4-1], eseq[5-1], eseq[6-1]);
287 return ((eval_funcp_7)(registered_functions()[serial].e))(eseq[1-1], eseq[2-1], eseq[3-1], eseq[4-1], eseq[5-1], eseq[6-1], eseq[7-1]);
290 return ((eval_funcp_8)(registered_functions()[serial].e))(eseq[1-1], eseq[2-1], eseq[3-1], eseq[4-1], eseq[5-1], eseq[6-1], eseq[7-1], eseq[8-1]);
293 return ((eval_funcp_9)(registered_functions()[serial].e))(eseq[1-1], eseq[2-1], eseq[3-1], eseq[4-1], eseq[5-1], eseq[6-1], eseq[7-1], eseq[8-1], eseq[9-1]);
296 return ((eval_funcp_10)(registered_functions()[serial].e))(eseq[1-1], eseq[2-1], eseq[3-1], eseq[4-1], eseq[5-1], eseq[6-1], eseq[7-1], eseq[8-1], eseq[9-1], eseq[10-1]);
299 // end of generated lines
301 throw(std::logic_error("function::eval(): invalid nparams"));
304 ex function::evalf(int level) const
306 ASSERT(serial<registered_functions().size());
308 exvector eseq=evalfchildren(level);
310 if (registered_functions()[serial].ef==0) {
311 return function(serial,eseq).hold();
313 switch (registered_functions()[serial].nparams) {
314 // the following lines have been generated for max. 10 parameters
316 return ((evalf_funcp_1)(registered_functions()[serial].ef))(eseq[1-1]);
319 return ((evalf_funcp_2)(registered_functions()[serial].ef))(eseq[1-1], eseq[2-1]);
322 return ((evalf_funcp_3)(registered_functions()[serial].ef))(eseq[1-1], eseq[2-1], eseq[3-1]);
325 return ((evalf_funcp_4)(registered_functions()[serial].ef))(eseq[1-1], eseq[2-1], eseq[3-1], eseq[4-1]);
328 return ((evalf_funcp_5)(registered_functions()[serial].ef))(eseq[1-1], eseq[2-1], eseq[3-1], eseq[4-1], eseq[5-1]);
331 return ((evalf_funcp_6)(registered_functions()[serial].ef))(eseq[1-1], eseq[2-1], eseq[3-1], eseq[4-1], eseq[5-1], eseq[6-1]);
334 return ((evalf_funcp_7)(registered_functions()[serial].ef))(eseq[1-1], eseq[2-1], eseq[3-1], eseq[4-1], eseq[5-1], eseq[6-1], eseq[7-1]);
337 return ((evalf_funcp_8)(registered_functions()[serial].ef))(eseq[1-1], eseq[2-1], eseq[3-1], eseq[4-1], eseq[5-1], eseq[6-1], eseq[7-1], eseq[8-1]);
340 return ((evalf_funcp_9)(registered_functions()[serial].ef))(eseq[1-1], eseq[2-1], eseq[3-1], eseq[4-1], eseq[5-1], eseq[6-1], eseq[7-1], eseq[8-1], eseq[9-1]);
343 return ((evalf_funcp_10)(registered_functions()[serial].ef))(eseq[1-1], eseq[2-1], eseq[3-1], eseq[4-1], eseq[5-1], eseq[6-1], eseq[7-1], eseq[8-1], eseq[9-1], eseq[10-1]);
346 // end of generated lines
348 throw(std::logic_error("function::evalf(): invalid nparams"));
351 ex function::thisexprseq(exvector const & v) const
353 return function(serial,v);
356 ex function::thisexprseq(exvector * vp) const
358 return function(serial,vp);
361 /** Implementation of ex::series for functions.
363 ex function::series(symbol const & s, ex const & point, int order) const
365 ASSERT(serial<registered_functions().size());
367 if (registered_functions()[serial].s==0) {
368 return basic::series(s, point, order);
370 switch (registered_functions()[serial].nparams) {
371 // the following lines have been generated for max. 10 parameters
373 return ((series_funcp_1)(registered_functions()[serial].s))(seq[1-1],s,point,order);
376 return ((series_funcp_2)(registered_functions()[serial].s))(seq[1-1], seq[2-1],s,point,order);
379 return ((series_funcp_3)(registered_functions()[serial].s))(seq[1-1], seq[2-1], seq[3-1],s,point,order);
382 return ((series_funcp_4)(registered_functions()[serial].s))(seq[1-1], seq[2-1], seq[3-1], seq[4-1],s,point,order);
385 return ((series_funcp_5)(registered_functions()[serial].s))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1],s,point,order);
388 return ((series_funcp_6)(registered_functions()[serial].s))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1],s,point,order);
391 return ((series_funcp_7)(registered_functions()[serial].s))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1],s,point,order);
394 return ((series_funcp_8)(registered_functions()[serial].s))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1], seq[8-1],s,point,order);
397 return ((series_funcp_9)(registered_functions()[serial].s))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1], seq[8-1], seq[9-1],s,point,order);
400 return ((series_funcp_10)(registered_functions()[serial].s))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1], seq[8-1], seq[9-1], seq[10-1],s,point,order);
403 // end of generated lines
405 throw(std::logic_error("function::series(): invalid nparams"));
410 int function::compare_same_type(basic const & other) const
412 ASSERT(is_of_type(other, function));
413 function const & o=static_cast<function &>(const_cast<basic &>(other));
415 if (serial!=o.serial) {
416 return serial < o.serial ? -1 : 1;
418 return exprseq::compare_same_type(o);
421 bool function::is_equal_same_type(basic const & other) const
423 ASSERT(is_of_type(other, function));
424 function const & o=static_cast<function &>(const_cast<basic &>(other));
426 if (serial!=o.serial) return false;
427 return exprseq::is_equal_same_type(o);
430 unsigned function::return_type(void) const
433 return return_types::commutative;
435 return (*seq.begin()).return_type();
438 unsigned function::return_type_tinfo(void) const
443 return (*seq.begin()).return_type_tinfo();
447 // new virtual functions which can be overridden by derived classes
453 // non-virtual functions in this class
458 ex function::pdiff(unsigned diff_param) const // partial differentiation
460 ASSERT(serial<registered_functions().size());
462 if (registered_functions()[serial].d==0) {
463 throw(std::logic_error(string("function::pdiff(") + registered_functions()[serial].name + "): no diff function defined"));
465 switch (registered_functions()[serial].nparams) {
466 // the following lines have been generated for max. 10 parameters
468 return ((diff_funcp_1)(registered_functions()[serial].d))(seq[1-1],diff_param);
471 return ((diff_funcp_2)(registered_functions()[serial].d))(seq[1-1], seq[2-1],diff_param);
474 return ((diff_funcp_3)(registered_functions()[serial].d))(seq[1-1], seq[2-1], seq[3-1],diff_param);
477 return ((diff_funcp_4)(registered_functions()[serial].d))(seq[1-1], seq[2-1], seq[3-1], seq[4-1],diff_param);
480 return ((diff_funcp_5)(registered_functions()[serial].d))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1],diff_param);
483 return ((diff_funcp_6)(registered_functions()[serial].d))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1],diff_param);
486 return ((diff_funcp_7)(registered_functions()[serial].d))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1],diff_param);
489 return ((diff_funcp_8)(registered_functions()[serial].d))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1], seq[8-1],diff_param);
492 return ((diff_funcp_9)(registered_functions()[serial].d))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1], seq[8-1], seq[9-1],diff_param);
495 return ((diff_funcp_10)(registered_functions()[serial].d))(seq[1-1], seq[2-1], seq[3-1], seq[4-1], seq[5-1], seq[6-1], seq[7-1], seq[8-1], seq[9-1], seq[10-1],diff_param);
498 // end of generated lines
500 throw(std::logic_error("function::pdiff(): no diff function defined"));
503 vector<registered_function_info> & function::registered_functions(void)
505 static vector<registered_function_info> * rf=new vector<registered_function_info>;
511 // the following lines have been generated for max. 10 parameters
512 unsigned function::register_new(char const * nm, eval_funcp_1 e,
513 evalf_funcp_1 ef, diff_funcp_1 d, series_funcp_1 s)
515 registered_function_info rfi={nm,1,0,eval_funcp(e),
516 evalf_funcp(ef),diff_funcp(d),series_funcp(s)};
517 registered_functions().push_back(rfi);
518 return registered_functions().size()-1;
520 unsigned function::register_new(char const * nm, eval_funcp_2 e,
521 evalf_funcp_2 ef, diff_funcp_2 d, series_funcp_2 s)
523 registered_function_info rfi={nm,2,0,eval_funcp(e),
524 evalf_funcp(ef),diff_funcp(d),series_funcp(s)};
525 registered_functions().push_back(rfi);
526 return registered_functions().size()-1;
528 unsigned function::register_new(char const * nm, eval_funcp_3 e,
529 evalf_funcp_3 ef, diff_funcp_3 d, series_funcp_3 s)
531 registered_function_info rfi={nm,3,0,eval_funcp(e),
532 evalf_funcp(ef),diff_funcp(d),series_funcp(s)};
533 registered_functions().push_back(rfi);
534 return registered_functions().size()-1;
536 unsigned function::register_new(char const * nm, eval_funcp_4 e,
537 evalf_funcp_4 ef, diff_funcp_4 d, series_funcp_4 s)
539 registered_function_info rfi={nm,4,0,eval_funcp(e),
540 evalf_funcp(ef),diff_funcp(d),series_funcp(s)};
541 registered_functions().push_back(rfi);
542 return registered_functions().size()-1;
544 unsigned function::register_new(char const * nm, eval_funcp_5 e,
545 evalf_funcp_5 ef, diff_funcp_5 d, series_funcp_5 s)
547 registered_function_info rfi={nm,5,0,eval_funcp(e),
548 evalf_funcp(ef),diff_funcp(d),series_funcp(s)};
549 registered_functions().push_back(rfi);
550 return registered_functions().size()-1;
552 unsigned function::register_new(char const * nm, eval_funcp_6 e,
553 evalf_funcp_6 ef, diff_funcp_6 d, series_funcp_6 s)
555 registered_function_info rfi={nm,6,0,eval_funcp(e),
556 evalf_funcp(ef),diff_funcp(d),series_funcp(s)};
557 registered_functions().push_back(rfi);
558 return registered_functions().size()-1;
560 unsigned function::register_new(char const * nm, eval_funcp_7 e,
561 evalf_funcp_7 ef, diff_funcp_7 d, series_funcp_7 s)
563 registered_function_info rfi={nm,7,0,eval_funcp(e),
564 evalf_funcp(ef),diff_funcp(d),series_funcp(s)};
565 registered_functions().push_back(rfi);
566 return registered_functions().size()-1;
568 unsigned function::register_new(char const * nm, eval_funcp_8 e,
569 evalf_funcp_8 ef, diff_funcp_8 d, series_funcp_8 s)
571 registered_function_info rfi={nm,8,0,eval_funcp(e),
572 evalf_funcp(ef),diff_funcp(d),series_funcp(s)};
573 registered_functions().push_back(rfi);
574 return registered_functions().size()-1;
576 unsigned function::register_new(char const * nm, eval_funcp_9 e,
577 evalf_funcp_9 ef, diff_funcp_9 d, series_funcp_9 s)
579 registered_function_info rfi={nm,9,0,eval_funcp(e),
580 evalf_funcp(ef),diff_funcp(d),series_funcp(s)};
581 registered_functions().push_back(rfi);
582 return registered_functions().size()-1;
584 unsigned function::register_new(char const * nm, eval_funcp_10 e,
585 evalf_funcp_10 ef, diff_funcp_10 d, series_funcp_10 s)
587 registered_function_info rfi={nm,10,0,eval_funcp(e),
588 evalf_funcp(ef),diff_funcp(d),series_funcp(s)};
589 registered_functions().push_back(rfi);
590 return registered_functions().size()-1;
593 // end of generated lines
596 // static member variables
605 const function some_function;
606 type_info const & typeid_function=typeid(some_function);