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
369 /** Specialization of is_exactly_a<function>(obj) for objects of type function. */
370 template<> inline bool is_exactly_a<function>(const basic & obj)
372 return obj.tinfo()==TINFO_function;
375 #define is_ex_the_function(OBJ, FUNCNAME) \\
376 (is_exactly_a<GiNaC::function>(OBJ) && ex_to<GiNaC::function>(OBJ).get_serial() == function_index_##FUNCNAME)
380 #endif // ndef __GINAC_FUNCTION_H__
384 $implementation=<<END_OF_IMPLEMENTATION;
385 /** \@file function.cpp
387 * Implementation of class of symbolic functions. */
390 * This file was generated automatically by function.pl.
391 * Please do not modify it directly, edit the perl script instead!
392 * function.pl options: \$maxargs=${maxargs}
394 * GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
396 * This program is free software; you can redistribute it and/or modify
397 * it under the terms of the GNU General Public License as published by
398 * the Free Software Foundation; either version 2 of the License, or
399 * (at your option) any later version.
401 * This program is distributed in the hope that it will be useful,
402 * but WITHOUT ANY WARRANTY; without even the implied warranty of
403 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
404 * GNU General Public License for more details.
406 * You should have received a copy of the GNU General Public License
407 * along with this program; if not, write to the Free Software
408 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
415 #include "function.h"
416 #include "fderivative.h"
419 #include "symmetry.h"
423 #include "tostring.h"
425 #include "debugmsg.h"
426 #include "remember.h"
431 // helper class function_options
434 function_options::function_options()
439 function_options::function_options(std::string const & n, std::string const & tn)
445 function_options::~function_options()
447 // nothing to clean up at the moment
450 void function_options::initialize(void)
452 set_name("unnamed_function","\\\\mbox{unnamed}");
454 eval_f = evalf_f = derivative_f = series_f = 0;
455 evalf_params_first = true;
456 use_return_type = false;
457 use_remember = false;
458 functions_with_same_name = 1;
462 function_options & function_options::set_name(std::string const & n,
463 std::string const & tn)
466 if (tn==std::string())
467 TeX_name = "\\\\mbox{"+name+"}";
473 function_options & function_options::latex_name(std::string const & tn)
479 // the following lines have been generated for max. ${maxargs} parameters
480 $eval_func_implementation
481 $evalf_func_implementation
482 $derivative_func_implementation
483 $series_func_implementation
484 // end of generated lines
486 function_options & function_options::set_return_type(unsigned rt, unsigned rtt)
488 use_return_type = true;
490 return_type_tinfo = rtt;
494 function_options & function_options::do_not_evalf_params(void)
496 evalf_params_first = false;
500 function_options & function_options::remember(unsigned size,
505 remember_size = size;
506 remember_assoc_size = assoc_size;
507 remember_strategy = strategy;
511 function_options & function_options::overloaded(unsigned o)
513 functions_with_same_name = o;
517 function_options & function_options::set_symmetry(const symmetry & s)
523 void function_options::test_and_set_nparams(unsigned n)
527 } else if (nparams!=n) {
528 // we do not throw an exception here because this code is
529 // usually executed before main(), so the exception could not
531 std::cerr << "WARNING: number of parameters ("
532 << n << ") differs from number set before ("
533 << nparams << ")" << std::endl;
537 GINAC_IMPLEMENT_REGISTERED_CLASS(function, exprseq)
540 // default ctor, dtor, copy ctor assignment operator and helpers
545 function::function() : serial(0)
547 debugmsg("function default ctor",LOGLEVEL_CONSTRUCT);
548 tinfo_key = TINFO_function;
553 void function::copy(const function & other)
555 inherited::copy(other);
556 serial = other.serial;
559 void function::destroy(bool call_parent)
562 inherited::destroy(call_parent);
571 function::function(unsigned ser) : serial(ser)
573 debugmsg("function ctor from unsigned",LOGLEVEL_CONSTRUCT);
574 tinfo_key = TINFO_function;
577 // the following lines have been generated for max. ${maxargs} parameters
578 $constructors_implementation
579 // end of generated lines
581 function::function(unsigned ser, const exprseq & es) : exprseq(es), serial(ser)
583 debugmsg("function ctor from unsigned,exprseq",LOGLEVEL_CONSTRUCT);
584 tinfo_key = TINFO_function;
587 function::function(unsigned ser, const exvector & v, bool discardable)
588 : exprseq(v,discardable), serial(ser)
590 debugmsg("function ctor from string,exvector,bool",LOGLEVEL_CONSTRUCT);
591 tinfo_key = TINFO_function;
594 function::function(unsigned ser, exvector * vp)
595 : exprseq(vp), serial(ser)
597 debugmsg("function ctor from unsigned,exvector *",LOGLEVEL_CONSTRUCT);
598 tinfo_key = TINFO_function;
605 /** Construct object from archive_node. */
606 function::function(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
608 debugmsg("function ctor from archive_node", LOGLEVEL_CONSTRUCT);
610 // Find serial number by function name
612 if (n.find_string("name", s)) {
613 unsigned int ser = 0;
614 std::vector<function_options>::const_iterator i = registered_functions().begin(), iend = registered_functions().end();
622 throw (std::runtime_error("unknown function '" + s + "' in archive"));
624 throw (std::runtime_error("unnamed function in archive"));
627 /** Unarchive the object. */
628 ex function::unarchive(const archive_node &n, const lst &sym_lst)
630 return (new function(n, sym_lst))->setflag(status_flags::dynallocated);
633 /** Archive the object. */
634 void function::archive(archive_node &n) const
636 inherited::archive(n);
637 GINAC_ASSERT(serial < registered_functions().size());
638 n.add_string("name", registered_functions()[serial].name);
642 // functions overriding virtual functions from base classes
647 void function::print(const print_context & c, unsigned level) const
649 debugmsg("function print", LOGLEVEL_PRINT);
651 GINAC_ASSERT(serial<registered_functions().size());
653 if (is_of_type(c, print_tree)) {
655 c.s << std::string(level, ' ') << class_name() << " "
656 << registered_functions()[serial].name
657 << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
658 << ", nops=" << nops()
660 unsigned delta_indent = static_cast<const print_tree &>(c).delta_indent;
661 for (unsigned i=0; i<seq.size(); ++i)
662 seq[i].print(c, level + delta_indent);
663 c.s << std::string(level + delta_indent, ' ') << "=====" << std::endl;
665 } else if (is_of_type(c, print_csrc)) {
667 // Print function name in lowercase
668 std::string lname = registered_functions()[serial].name;
669 unsigned num = lname.size();
670 for (unsigned i=0; i<num; i++)
671 lname[i] = tolower(lname[i]);
674 // Print arguments, separated by commas
675 exvector::const_iterator it = seq.begin(), itend = seq.end();
676 while (it != itend) {
684 } else if (is_of_type(c, print_latex)) {
685 c.s << registered_functions()[serial].TeX_name;
686 printseq(c, '(', ',', ')', exprseq::precedence(), function::precedence());
688 c.s << registered_functions()[serial].name;
689 printseq(c, '(', ',', ')', exprseq::precedence(), function::precedence());
693 ex function::expand(unsigned options) const
695 // Only expand arguments when asked to do so
696 if (options & expand_options::expand_function_args)
697 return inherited::expand(options);
699 return (options == 0) ? setflag(status_flags::expanded) : *this;
702 int function::degree(const ex & s) const
704 return is_equal(ex_to<basic>(s)) ? 1 : 0;
707 int function::ldegree(const ex & s) const
709 return is_equal(ex_to<basic>(s)) ? 1 : 0;
712 ex function::coeff(const ex & s, int n) const
714 if (is_equal(ex_to<basic>(s)))
715 return n==1 ? _ex1() : _ex0();
717 return n==0 ? ex(*this) : _ex0();
720 ex function::eval(int level) const
722 GINAC_ASSERT(serial<registered_functions().size());
725 // first evaluate children, then we will end up here again
726 return function(serial,evalchildren(level));
729 const function_options &opt = registered_functions()[serial];
731 // Canonicalize argument order according to the symmetry properties
732 if (seq.size() > 1 && !(opt.symtree.is_zero())) {
734 GINAC_ASSERT(is_a<symmetry>(opt.symtree));
735 int sig = canonicalize(v.begin(), ex_to<symmetry>(opt.symtree));
736 if (sig != INT_MAX) {
737 // Something has changed while sorting arguments, more evaluations later
740 return ex(sig) * thisexprseq(v);
748 bool use_remember = opt.use_remember;
750 if (use_remember && lookup_remember_table(eval_result)) {
754 switch (opt.nparams) {
755 // the following lines have been generated for max. ${maxargs} parameters
756 ${eval_switch_statement}
757 // end of generated lines
759 throw(std::logic_error("function::eval(): invalid nparams"));
762 store_remember_table(eval_result);
767 ex function::evalf(int level) const
769 GINAC_ASSERT(serial<registered_functions().size());
771 // Evaluate children first
775 else if (level == -max_recursion_level)
776 throw(std::runtime_error("max recursion level reached"));
778 eseq.reserve(seq.size());
780 exvector::const_iterator it = seq.begin(), itend = seq.end();
781 while (it != itend) {
782 eseq.push_back(it->evalf(level));
786 if (registered_functions()[serial].evalf_f==0) {
787 return function(serial,eseq).hold();
789 switch (registered_functions()[serial].nparams) {
790 // the following lines have been generated for max. ${maxargs} parameters
791 ${evalf_switch_statement}
792 // end of generated lines
794 throw(std::logic_error("function::evalf(): invalid nparams"));
797 unsigned function::calchash(void) const
799 unsigned v = golden_ratio_hash(golden_ratio_hash(tinfo()) ^ serial);
800 for (unsigned i=0; i<nops(); i++) {
801 v = rotate_left_31(v);
802 v ^= this->op(i).gethash();
805 if (flags & status_flags::evaluated) {
806 setflag(status_flags::hash_calculated);
812 ex function::thisexprseq(const exvector & v) const
814 return function(serial,v);
817 ex function::thisexprseq(exvector * vp) const
819 return function(serial,vp);
822 /** Implementation of ex::series for functions.
823 * \@see ex::series */
824 ex function::series(const relational & r, int order, unsigned options) const
826 GINAC_ASSERT(serial<registered_functions().size());
828 if (registered_functions()[serial].series_f==0) {
829 return basic::series(r, order);
832 switch (registered_functions()[serial].nparams) {
833 // the following lines have been generated for max. ${maxargs} parameters
834 ${series_switch_statement}
835 // end of generated lines
837 throw(std::logic_error("function::series(): invalid nparams"));
842 /** Implementation of ex::diff() for functions. It applies the chain rule,
843 * except for the Order term function.
845 ex function::derivative(const symbol & s) const
849 if (serial == function_index_Order) {
850 // Order Term function only differentiates the argument
851 return Order(seq[0].diff(s));
855 unsigned num = seq.size();
856 for (unsigned i=0; i<num; i++) {
857 arg_diff = seq[i].diff(s);
858 // We apply the chain rule only when it makes sense. This is not
859 // just for performance reasons but also to allow functions to
860 // throw when differentiated with respect to one of its arguments
861 // without running into trouble with our automatic full
863 if (!arg_diff.is_zero())
864 result += pderivative(i)*arg_diff;
870 int function::compare_same_type(const basic & other) const
872 GINAC_ASSERT(is_of_type(other, function));
873 const function & o = static_cast<const function &>(other);
875 if (serial != o.serial)
876 return serial < o.serial ? -1 : 1;
878 return exprseq::compare_same_type(o);
881 bool function::is_equal_same_type(const basic & other) const
883 GINAC_ASSERT(is_of_type(other, function));
884 const function & o = static_cast<const function &>(other);
886 if (serial != o.serial)
889 return exprseq::is_equal_same_type(o);
892 bool function::match_same_type(const basic & other) const
894 GINAC_ASSERT(is_of_type(other, function));
895 const function & o = static_cast<const function &>(other);
897 return serial == o.serial;
900 unsigned function::return_type(void) const
903 return return_types::commutative;
905 return seq.begin()->return_type();
908 unsigned function::return_type_tinfo(void) const
913 return seq.begin()->return_type_tinfo();
917 // new virtual functions which can be overridden by derived classes
923 // non-virtual functions in this class
928 ex function::pderivative(unsigned diff_param) const // partial differentiation
930 GINAC_ASSERT(serial<registered_functions().size());
932 // No derivative defined? Then return abstract derivative object
933 if (registered_functions()[serial].derivative_f == NULL)
934 return fderivative(serial, diff_param, seq);
936 switch (registered_functions()[serial].nparams) {
937 // the following lines have been generated for max. ${maxargs} parameters
938 ${diff_switch_statement}
939 // end of generated lines
941 throw(std::logic_error("function::pderivative(): no diff function defined"));
944 std::vector<function_options> & function::registered_functions(void)
946 static std::vector<function_options> * rf = new std::vector<function_options>;
950 bool function::lookup_remember_table(ex & result) const
952 return remember_table::remember_tables()[serial].lookup_entry(*this,result);
955 void function::store_remember_table(ex const & result) const
957 remember_table::remember_tables()[serial].add_entry(*this,result);
962 unsigned function::register_new(function_options const & opt)
964 unsigned same_name = 0;
965 for (unsigned i=0; i<registered_functions().size(); ++i) {
966 if (registered_functions()[i].name==opt.name) {
970 if (same_name>=opt.functions_with_same_name) {
971 // we do not throw an exception here because this code is
972 // usually executed before main(), so the exception could not
974 std::cerr << "WARNING: function name " << opt.name
975 << " already in use!" << std::endl;
977 registered_functions().push_back(opt);
978 if (opt.use_remember) {
979 remember_table::remember_tables().
980 push_back(remember_table(opt.remember_size,
981 opt.remember_assoc_size,
982 opt.remember_strategy));
984 remember_table::remember_tables().push_back(remember_table());
986 return registered_functions().size()-1;
989 /** Find serial number of function by name and number of parameters.
990 * Throws exception if function was not found. */
991 unsigned function::find_function(const std::string &name, unsigned nparams)
993 std::vector<function_options>::const_iterator i = function::registered_functions().begin(), end = function::registered_functions().end();
996 if (i->get_name() == name && i->get_nparams() == nparams)
1001 throw (std::runtime_error("no function '" + name + "' with " + ToString(nparams) + " parameters defined"));
1004 /** Return the print name of the function. */
1005 std::string function::get_name(void) const
1007 GINAC_ASSERT(serial<registered_functions().size());
1008 return registered_functions()[serial].name;
1011 } // namespace GiNaC
1013 END_OF_IMPLEMENTATION
1015 print "Creating interface file function.h...";
1016 open OUT,">function.h" or die "cannot open function.h";
1017 print OUT $interface;
1021 print "Creating implementation file function.cpp...";
1022 open OUT,">function.cpp" or die "cannot open function.cpp";
1023 print OUT $implementation;