4 my ($seq_template,$n)=@_;
8 for ($N=1; $N<=$n; $N++) {
9 $res .= eval('"' . $seq_template . '"');
17 sub generate_from_to {
18 my ($template,$seq_template1,$seq_template2,$seq_template3,$from,$to)=@_;
22 for ($N=$from; $N<=$to; $N++) {
23 $SEQ1=generate_seq($seq_template1,$N);
24 $SEQ2=generate_seq($seq_template2,$N);
25 $SEQ3=generate_seq($seq_template3,$N);
26 $res .= eval('"' . $template . '"');
27 $SEQ1=''; # to avoid main::SEQ1 used only once warning
28 $SEQ2=''; # same as above
29 $SEQ3=''; # same as above
35 my ($template,$seq_template1,$seq_template2,$seq_template3)=@_;
36 return generate_from_to($template,$seq_template1,$seq_template2,$seq_template3,1,$maxargs);
39 $declare_function_macro = generate(
40 <<'END_OF_DECLARE_FUNCTION_MACRO','typename T${N}','const T${N} & p${N}','GiNaC::ex(p${N})');
41 #define DECLARE_FUNCTION_${N}P(NAME) \\
42 extern const unsigned function_index_##NAME; \\
44 inline const GiNaC::function NAME(${SEQ2}) { \\
45 return GiNaC::function(function_index_##NAME, ${SEQ3}); \\
48 END_OF_DECLARE_FUNCTION_MACRO
50 $typedef_eval_funcp=generate(
51 'typedef ex (* eval_funcp_${N})(${SEQ1});'."\n",
54 $typedef_evalf_funcp=generate(
55 'typedef ex (* evalf_funcp_${N})(${SEQ1});'."\n",
58 $typedef_derivative_funcp=generate(
59 'typedef ex (* derivative_funcp_${N})(${SEQ1}, unsigned);'."\n",
62 $typedef_series_funcp=generate(
63 'typedef ex (* series_funcp_${N})(${SEQ1}, const relational &, int, unsigned);'."\n",
66 $eval_func_interface=generate(' function_options & eval_func(eval_funcp_${N} e);'."\n",'','','');
68 $evalf_func_interface=generate(' function_options & evalf_func(evalf_funcp_${N} ef);'."\n",'','','');
70 $derivative_func_interface=generate(' function_options & derivative_func(derivative_funcp_${N} d);'."\n",'','','');
72 $series_func_interface=generate(' function_options & series_func(series_funcp_${N} s);'."\n",'','','');
74 $constructors_interface=generate(
75 ' function(unsigned ser, ${SEQ1});'."\n",
76 'const ex & param${N}','','');
78 $constructors_implementation=generate(
79 <<'END_OF_CONSTRUCTORS_IMPLEMENTATION','const ex & param${N}','param${N}','');
80 function::function(unsigned ser, ${SEQ1})
81 : exprseq(${SEQ2}), serial(ser)
83 debugmsg(\"function ctor from unsigned,${N}*ex\",LOGLEVEL_CONSTRUCT);
84 tinfo_key = TINFO_function;
86 END_OF_CONSTRUCTORS_IMPLEMENTATION
88 $eval_switch_statement=generate(
89 <<'END_OF_EVAL_SWITCH_STATEMENT','seq[${N}-1]','','');
91 eval_result = ((eval_funcp_${N})(registered_functions()[serial].eval_f))(${SEQ1});
93 END_OF_EVAL_SWITCH_STATEMENT
95 $evalf_switch_statement=generate(
96 <<'END_OF_EVALF_SWITCH_STATEMENT','eseq[${N}-1]','','');
98 return ((evalf_funcp_${N})(registered_functions()[serial].evalf_f))(${SEQ1});
99 END_OF_EVALF_SWITCH_STATEMENT
101 $diff_switch_statement=generate(
102 <<'END_OF_DIFF_SWITCH_STATEMENT','seq[${N}-1]','','');
104 return ((derivative_funcp_${N})(registered_functions()[serial].derivative_f))(${SEQ1},diff_param);
105 END_OF_DIFF_SWITCH_STATEMENT
107 $series_switch_statement=generate(
108 <<'END_OF_SERIES_SWITCH_STATEMENT','seq[${N}-1]','','');
111 res = ((series_funcp_${N})(registered_functions()[serial].series_f))(${SEQ1},r,order,options);
112 } catch (do_taylor) {
113 res = basic::series(r, order, options);
116 END_OF_SERIES_SWITCH_STATEMENT
118 $eval_func_implementation=generate(
119 <<'END_OF_EVAL_FUNC_IMPLEMENTATION','','','');
120 function_options & function_options::eval_func(eval_funcp_${N} e)
122 test_and_set_nparams(${N});
123 eval_f = eval_funcp(e);
126 END_OF_EVAL_FUNC_IMPLEMENTATION
128 $evalf_func_implementation=generate(
129 <<'END_OF_EVALF_FUNC_IMPLEMENTATION','','','');
130 function_options & function_options::evalf_func(evalf_funcp_${N} ef)
132 test_and_set_nparams(${N});
133 evalf_f = evalf_funcp(ef);
136 END_OF_EVALF_FUNC_IMPLEMENTATION
138 $derivative_func_implementation=generate(
139 <<'END_OF_DERIVATIVE_FUNC_IMPLEMENTATION','','','');
140 function_options & function_options::derivative_func(derivative_funcp_${N} d)
142 test_and_set_nparams(${N});
143 derivative_f = derivative_funcp(d);
146 END_OF_DERIVATIVE_FUNC_IMPLEMENTATION
148 $series_func_implementation=generate(
149 <<'END_OF_SERIES_FUNC_IMPLEMENTATION','','','');
150 function_options & function_options::series_func(series_funcp_${N} s)
152 test_and_set_nparams(${N});
153 series_f = series_funcp(s);
156 END_OF_SERIES_FUNC_IMPLEMENTATION
158 $interface=<<END_OF_INTERFACE;
159 /** \@file function.h
161 * Interface to class of symbolic functions. */
164 * This file was generated automatically by function.pl.
165 * Please do not modify it directly, edit the perl script instead!
166 * function.pl options: \$maxargs=${maxargs}
168 * GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
170 * This program is free software; you can redistribute it and/or modify
171 * it under the terms of the GNU General Public License as published by
172 * the Free Software Foundation; either version 2 of the License, or
173 * (at your option) any later version.
175 * This program is distributed in the hope that it will be useful,
176 * but WITHOUT ANY WARRANTY; without even the implied warranty of
177 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
178 * GNU General Public License for more details.
180 * You should have received a copy of the GNU General Public License
181 * along with this program; if not, write to the Free Software
182 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
185 #ifndef __GINAC_FUNCTION_H__
186 #define __GINAC_FUNCTION_H__
191 // CINT needs <algorithm> to work properly with <vector>
196 // the following lines have been generated for max. ${maxargs} parameters
197 $declare_function_macro
198 // end of generated lines
200 #define REGISTER_FUNCTION(NAME,OPT) \\
201 const unsigned function_index_##NAME= \\
202 GiNaC::function::register_new(GiNaC::function_options(#NAME).OPT);
204 // The TYPECHECK-macros were used inside the _evalf() functions. They are
205 // considered obsolete now: (FIXME: remove them)
207 #define BEGIN_TYPECHECK \\
208 bool automatic_typecheck=true;
210 #define TYPECHECK(VAR,TYPE) \\
211 if (!is_exactly_a<TYPE>(VAR)) { \\
212 automatic_typecheck=false; \\
215 #define TYPECHECK_INTEGER(VAR) \\
216 if (!(VAR).info(GiNaC::info_flags::integer)) { \\
217 automatic_typecheck=false; \\
220 #define END_TYPECHECK(RV) \\
222 if (!automatic_typecheck) { \\
231 typedef ex (* eval_funcp)();
232 typedef ex (* evalf_funcp)();
233 typedef ex (* derivative_funcp)();
234 typedef ex (* series_funcp)();
236 // the following lines have been generated for max. ${maxargs} parameters
239 $typedef_derivative_funcp
240 $typedef_series_funcp
241 // end of generated lines
243 class function_options
245 friend class function;
246 friend class fderivative;
249 function_options(std::string const & n, std::string const & tn=std::string());
251 void initialize(void);
252 function_options & set_name(std::string const & n, std::string const & tn=std::string());
253 function_options & latex_name(std::string const & tn);
254 // the following lines have been generated for max. ${maxargs} parameters
256 $evalf_func_interface
257 $derivative_func_interface
258 $series_func_interface
259 // end of generated lines
260 function_options & set_return_type(unsigned rt, unsigned rtt=0);
261 function_options & do_not_evalf_params(void);
262 function_options & remember(unsigned size, unsigned assoc_size=0,
263 unsigned strategy=remember_strategies::delete_never);
264 function_options & overloaded(unsigned o);
265 function_options & set_symmetry(const symmetry & s);
266 void test_and_set_nparams(unsigned n);
267 std::string get_name(void) const { return name; }
268 unsigned get_nparams(void) const { return nparams; }
269 bool has_derivative(void) const { return derivative_f != NULL; }
273 std::string TeX_name;
279 derivative_funcp derivative_f;
280 series_funcp series_f;
282 bool evalf_params_first;
284 bool use_return_type;
285 unsigned return_type;
286 unsigned return_type_tinfo;
289 unsigned remember_size;
290 unsigned remember_assoc_size;
291 unsigned remember_strategy;
293 unsigned functions_with_same_name;
298 /** The class function is used to implement builtin functions like sin, cos...
299 and user defined functions */
300 class function : public exprseq
302 GINAC_DECLARE_REGISTERED_CLASS(function, exprseq)
304 // CINT has a linking problem
306 friend void ginsh_get_ginac_functions(void);
307 #endif // def __MAKECINT__
309 friend class remember_table_entry;
310 // friend class remember_table_list;
311 // friend class remember_table;
317 function(unsigned ser);
318 // the following lines have been generated for max. ${maxargs} parameters
319 $constructors_interface
320 // end of generated lines
321 function(unsigned ser, const exprseq & es);
322 function(unsigned ser, const exvector & v, bool discardable = false);
323 function(unsigned ser, exvector * vp); // vp will be deleted
325 // functions overriding virtual functions from base classes
327 void print(const print_context & c, unsigned level = 0) const;
328 unsigned precedence(void) const {return 70;}
329 int degree(const ex & s) const;
330 int ldegree(const ex & s) const;
331 ex coeff(const ex & s, int n = 1) const;
332 ex expand(unsigned options=0) const;
333 ex eval(int level=0) const;
334 ex evalf(int level=0) const;
335 unsigned calchash(void) const;
336 ex series(const relational & r, int order, unsigned options = 0) const;
337 ex thisexprseq(const exvector & v) const;
338 ex thisexprseq(exvector * vp) const;
340 ex derivative(const symbol & s) const;
341 bool is_equal_same_type(const basic & other) const;
342 bool match_same_type(const basic & other) const;
343 unsigned return_type(void) const;
344 unsigned return_type_tinfo(void) const;
346 // new virtual functions which can be overridden by derived classes
349 // non-virtual functions in this class
351 ex pderivative(unsigned diff_param) const; // partial differentiation
352 static std::vector<function_options> & registered_functions(void);
353 bool lookup_remember_table(ex & result) const;
354 void store_remember_table(ex const & result) const;
356 static unsigned register_new(function_options const & opt);
357 static unsigned find_function(const std::string &name, unsigned nparams);
358 unsigned get_serial(void) const {return serial;}
359 std::string get_name(void) const;
367 // utility functions/macros
368 /** Return the object of type function handled by an ex.
369 * This is unsafe: you need to check the type first. */
370 inline const function &ex_to_function(const ex &e)
372 return static_cast<const function &>(*e.bp);
375 /** Specialization of is_exactly_a<function>(obj) for objects of type function. */
376 template<> inline bool is_exactly_a<function>(const basic & obj)
378 return obj.tinfo()==TINFO_function;
381 #define is_ex_the_function(OBJ, FUNCNAME) \\
382 (is_exactly_a<function>(OBJ) && static_cast<GiNaC::function *>(OBJ.bp)->get_serial() == function_index_##FUNCNAME)
386 #endif // ndef __GINAC_FUNCTION_H__
390 $implementation=<<END_OF_IMPLEMENTATION;
391 /** \@file function.cpp
393 * Implementation of class of symbolic functions. */
396 * This file was generated automatically by function.pl.
397 * Please do not modify it directly, edit the perl script instead!
398 * function.pl options: \$maxargs=${maxargs}
400 * GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
402 * This program is free software; you can redistribute it and/or modify
403 * it under the terms of the GNU General Public License as published by
404 * the Free Software Foundation; either version 2 of the License, or
405 * (at your option) any later version.
407 * This program is distributed in the hope that it will be useful,
408 * but WITHOUT ANY WARRANTY; without even the implied warranty of
409 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
410 * GNU General Public License for more details.
412 * You should have received a copy of the GNU General Public License
413 * along with this program; if not, write to the Free Software
414 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
421 #include "function.h"
422 #include "fderivative.h"
425 #include "symmetry.h"
429 #include "tostring.h"
431 #include "debugmsg.h"
432 #include "remember.h"
437 // helper class function_options
440 function_options::function_options()
445 function_options::function_options(std::string const & n, std::string const & tn)
451 function_options::~function_options()
453 // nothing to clean up at the moment
456 void function_options::initialize(void)
458 set_name("unnamed_function","\\\\mbox{unnamed}");
460 eval_f = evalf_f = derivative_f = series_f = 0;
461 evalf_params_first = true;
462 use_return_type = false;
463 use_remember = false;
464 functions_with_same_name = 1;
468 function_options & function_options::set_name(std::string const & n,
469 std::string const & tn)
472 if (tn==std::string())
473 TeX_name = "\\\\mbox{"+name+"}";
479 function_options & function_options::latex_name(std::string const & tn)
485 // the following lines have been generated for max. ${maxargs} parameters
486 $eval_func_implementation
487 $evalf_func_implementation
488 $derivative_func_implementation
489 $series_func_implementation
490 // end of generated lines
492 function_options & function_options::set_return_type(unsigned rt, unsigned rtt)
494 use_return_type = true;
496 return_type_tinfo = rtt;
500 function_options & function_options::do_not_evalf_params(void)
502 evalf_params_first = false;
506 function_options & function_options::remember(unsigned size,
511 remember_size = size;
512 remember_assoc_size = assoc_size;
513 remember_strategy = strategy;
517 function_options & function_options::overloaded(unsigned o)
519 functions_with_same_name = o;
523 function_options & function_options::set_symmetry(const symmetry & s)
529 void function_options::test_and_set_nparams(unsigned n)
533 } else if (nparams!=n) {
534 // we do not throw an exception here because this code is
535 // usually executed before main(), so the exception could not
537 std::cerr << "WARNING: number of parameters ("
538 << n << ") differs from number set before ("
539 << nparams << ")" << std::endl;
543 GINAC_IMPLEMENT_REGISTERED_CLASS(function, exprseq)
546 // default ctor, dtor, copy ctor assignment operator and helpers
551 function::function() : serial(0)
553 debugmsg("function default ctor",LOGLEVEL_CONSTRUCT);
554 tinfo_key = TINFO_function;
559 void function::copy(const function & other)
561 inherited::copy(other);
562 serial = other.serial;
565 void function::destroy(bool call_parent)
568 inherited::destroy(call_parent);
577 function::function(unsigned ser) : serial(ser)
579 debugmsg("function ctor from unsigned",LOGLEVEL_CONSTRUCT);
580 tinfo_key = TINFO_function;
583 // the following lines have been generated for max. ${maxargs} parameters
584 $constructors_implementation
585 // end of generated lines
587 function::function(unsigned ser, const exprseq & es) : exprseq(es), serial(ser)
589 debugmsg("function ctor from unsigned,exprseq",LOGLEVEL_CONSTRUCT);
590 tinfo_key = TINFO_function;
593 function::function(unsigned ser, const exvector & v, bool discardable)
594 : exprseq(v,discardable), serial(ser)
596 debugmsg("function ctor from string,exvector,bool",LOGLEVEL_CONSTRUCT);
597 tinfo_key = TINFO_function;
600 function::function(unsigned ser, exvector * vp)
601 : exprseq(vp), serial(ser)
603 debugmsg("function ctor from unsigned,exvector *",LOGLEVEL_CONSTRUCT);
604 tinfo_key = TINFO_function;
611 /** Construct object from archive_node. */
612 function::function(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
614 debugmsg("function ctor from archive_node", LOGLEVEL_CONSTRUCT);
616 // Find serial number by function name
618 if (n.find_string("name", s)) {
619 unsigned int ser = 0;
620 std::vector<function_options>::const_iterator i = registered_functions().begin(), iend = registered_functions().end();
628 throw (std::runtime_error("unknown function '" + s + "' in archive"));
630 throw (std::runtime_error("unnamed function in archive"));
633 /** Unarchive the object. */
634 ex function::unarchive(const archive_node &n, const lst &sym_lst)
636 return (new function(n, sym_lst))->setflag(status_flags::dynallocated);
639 /** Archive the object. */
640 void function::archive(archive_node &n) const
642 inherited::archive(n);
643 GINAC_ASSERT(serial < registered_functions().size());
644 n.add_string("name", registered_functions()[serial].name);
648 // functions overriding virtual functions from base classes
653 void function::print(const print_context & c, unsigned level) const
655 debugmsg("function print", LOGLEVEL_PRINT);
657 GINAC_ASSERT(serial<registered_functions().size());
659 if (is_of_type(c, print_tree)) {
661 c.s << std::string(level, ' ') << class_name() << " "
662 << registered_functions()[serial].name
663 << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
664 << ", nops=" << nops()
666 unsigned delta_indent = static_cast<const print_tree &>(c).delta_indent;
667 for (unsigned i=0; i<seq.size(); ++i)
668 seq[i].print(c, level + delta_indent);
669 c.s << std::string(level + delta_indent, ' ') << "=====" << std::endl;
671 } else if (is_of_type(c, print_csrc)) {
673 // Print function name in lowercase
674 std::string lname = registered_functions()[serial].name;
675 unsigned num = lname.size();
676 for (unsigned i=0; i<num; i++)
677 lname[i] = tolower(lname[i]);
680 // Print arguments, separated by commas
681 exvector::const_iterator it = seq.begin(), itend = seq.end();
682 while (it != itend) {
690 } else if (is_of_type(c, print_latex)) {
691 c.s << registered_functions()[serial].TeX_name;
692 printseq(c, '(', ',', ')', exprseq::precedence(), function::precedence());
694 c.s << registered_functions()[serial].name;
695 printseq(c, '(', ',', ')', exprseq::precedence(), function::precedence());
699 ex function::expand(unsigned options) const
701 // Only expand arguments when asked to do so
702 if (options & expand_options::expand_function_args)
703 return inherited::expand(options);
705 return (options == 0) ? setflag(status_flags::expanded) : *this;
708 int function::degree(const ex & s) const
710 return is_equal(*s.bp) ? 1 : 0;
713 int function::ldegree(const ex & s) const
715 return is_equal(*s.bp) ? 1 : 0;
718 ex function::coeff(const ex & s, int n) const
721 return n==1 ? _ex1() : _ex0();
723 return n==0 ? ex(*this) : _ex0();
726 ex function::eval(int level) const
728 GINAC_ASSERT(serial<registered_functions().size());
731 // first evaluate children, then we will end up here again
732 return function(serial,evalchildren(level));
735 const function_options &opt = registered_functions()[serial];
737 // Canonicalize argument order according to the symmetry properties
738 if (seq.size() > 1 && !(opt.symtree.is_zero())) {
740 GINAC_ASSERT(is_a<symmetry>(opt.symtree));
741 int sig = canonicalize(v.begin(), ex_to<symmetry>(opt.symtree));
742 if (sig != INT_MAX) {
743 // Something has changed while sorting arguments, more evaluations later
746 return ex(sig) * thisexprseq(v);
754 bool use_remember = opt.use_remember;
756 if (use_remember && lookup_remember_table(eval_result)) {
760 switch (opt.nparams) {
761 // the following lines have been generated for max. ${maxargs} parameters
762 ${eval_switch_statement}
763 // end of generated lines
765 throw(std::logic_error("function::eval(): invalid nparams"));
768 store_remember_table(eval_result);
773 ex function::evalf(int level) const
775 GINAC_ASSERT(serial<registered_functions().size());
777 // Evaluate children first
781 else if (level == -max_recursion_level)
782 throw(std::runtime_error("max recursion level reached"));
784 eseq.reserve(seq.size());
786 exvector::const_iterator it = seq.begin(), itend = seq.end();
787 while (it != itend) {
788 eseq.push_back(it->evalf(level));
792 if (registered_functions()[serial].evalf_f==0) {
793 return function(serial,eseq).hold();
795 switch (registered_functions()[serial].nparams) {
796 // the following lines have been generated for max. ${maxargs} parameters
797 ${evalf_switch_statement}
798 // end of generated lines
800 throw(std::logic_error("function::evalf(): invalid nparams"));
803 unsigned function::calchash(void) const
805 unsigned v = golden_ratio_hash(golden_ratio_hash(tinfo()) ^ serial);
806 for (unsigned i=0; i<nops(); i++) {
807 v = rotate_left_31(v);
808 v ^= this->op(i).gethash();
811 if (flags & status_flags::evaluated) {
812 setflag(status_flags::hash_calculated);
818 ex function::thisexprseq(const exvector & v) const
820 return function(serial,v);
823 ex function::thisexprseq(exvector * vp) const
825 return function(serial,vp);
828 /** Implementation of ex::series for functions.
829 * \@see ex::series */
830 ex function::series(const relational & r, int order, unsigned options) const
832 GINAC_ASSERT(serial<registered_functions().size());
834 if (registered_functions()[serial].series_f==0) {
835 return basic::series(r, order);
838 switch (registered_functions()[serial].nparams) {
839 // the following lines have been generated for max. ${maxargs} parameters
840 ${series_switch_statement}
841 // end of generated lines
843 throw(std::logic_error("function::series(): invalid nparams"));
848 /** Implementation of ex::diff() for functions. It applies the chain rule,
849 * except for the Order term function.
851 ex function::derivative(const symbol & s) const
855 if (serial == function_index_Order) {
856 // Order Term function only differentiates the argument
857 return Order(seq[0].diff(s));
861 unsigned num = seq.size();
862 for (unsigned i=0; i<num; i++) {
863 arg_diff = seq[i].diff(s);
864 // We apply the chain rule only when it makes sense. This is not
865 // just for performance reasons but also to allow functions to
866 // throw when differentiated with respect to one of its arguments
867 // without running into trouble with our automatic full
869 if (!arg_diff.is_zero())
870 result += pderivative(i)*arg_diff;
876 int function::compare_same_type(const basic & other) const
878 GINAC_ASSERT(is_of_type(other, function));
879 const function & o = static_cast<const function &>(other);
881 if (serial != o.serial)
882 return serial < o.serial ? -1 : 1;
884 return exprseq::compare_same_type(o);
887 bool function::is_equal_same_type(const basic & other) const
889 GINAC_ASSERT(is_of_type(other, function));
890 const function & o = static_cast<const function &>(other);
892 if (serial != o.serial)
895 return exprseq::is_equal_same_type(o);
898 bool function::match_same_type(const basic & other) const
900 GINAC_ASSERT(is_of_type(other, function));
901 const function & o = static_cast<const function &>(other);
903 return serial == o.serial;
906 unsigned function::return_type(void) const
909 return return_types::commutative;
911 return seq.begin()->return_type();
914 unsigned function::return_type_tinfo(void) const
919 return seq.begin()->return_type_tinfo();
923 // new virtual functions which can be overridden by derived classes
929 // non-virtual functions in this class
934 ex function::pderivative(unsigned diff_param) const // partial differentiation
936 GINAC_ASSERT(serial<registered_functions().size());
938 // No derivative defined? Then return abstract derivative object
939 if (registered_functions()[serial].derivative_f == NULL)
940 return fderivative(serial, diff_param, seq);
942 switch (registered_functions()[serial].nparams) {
943 // the following lines have been generated for max. ${maxargs} parameters
944 ${diff_switch_statement}
945 // end of generated lines
947 throw(std::logic_error("function::pderivative(): no diff function defined"));
950 std::vector<function_options> & function::registered_functions(void)
952 static std::vector<function_options> * rf = new std::vector<function_options>;
956 bool function::lookup_remember_table(ex & result) const
958 return remember_table::remember_tables()[serial].lookup_entry(*this,result);
961 void function::store_remember_table(ex const & result) const
963 remember_table::remember_tables()[serial].add_entry(*this,result);
968 unsigned function::register_new(function_options const & opt)
970 unsigned same_name = 0;
971 for (unsigned i=0; i<registered_functions().size(); ++i) {
972 if (registered_functions()[i].name==opt.name) {
976 if (same_name>=opt.functions_with_same_name) {
977 // we do not throw an exception here because this code is
978 // usually executed before main(), so the exception could not
980 std::cerr << "WARNING: function name " << opt.name
981 << " already in use!" << std::endl;
983 registered_functions().push_back(opt);
984 if (opt.use_remember) {
985 remember_table::remember_tables().
986 push_back(remember_table(opt.remember_size,
987 opt.remember_assoc_size,
988 opt.remember_strategy));
990 remember_table::remember_tables().push_back(remember_table());
992 return registered_functions().size()-1;
995 /** Find serial number of function by name and number of parameters.
996 * Throws exception if function was not found. */
997 unsigned function::find_function(const std::string &name, unsigned nparams)
999 std::vector<function_options>::const_iterator i = function::registered_functions().begin(), end = function::registered_functions().end();
1000 unsigned serial = 0;
1002 if (i->get_name() == name && i->get_nparams() == nparams)
1007 throw (std::runtime_error("no function '" + name + "' with " + ToString(nparams) + " parameters defined"));
1010 /** Return the print name of the function. */
1011 std::string function::get_name(void) const
1013 GINAC_ASSERT(serial<registered_functions().size());
1014 return registered_functions()[serial].name;
1017 } // namespace GiNaC
1019 END_OF_IMPLEMENTATION
1021 print "Creating interface file function.h...";
1022 open OUT,">function.h" or die "cannot open function.h";
1023 print OUT $interface;
1027 print "Creating implementation file function.cpp...";
1028 open OUT,">function.cpp" or die "cannot open function.cpp";
1029 print OUT $implementation;