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 #define BEGIN_TYPECHECK \\
205 bool automatic_typecheck=true;
207 #define TYPECHECK(VAR,TYPE) \\
208 if (!is_exactly_a<TYPE>(VAR)) { \\
209 automatic_typecheck=false; \\
212 #define TYPECHECK_INTEGER(VAR) \\
213 if (!(VAR).info(GiNaC::info_flags::integer)) { \\
214 automatic_typecheck=false; \\
217 #define END_TYPECHECK(RV) \\
219 if (!automatic_typecheck) { \\
228 typedef ex (* eval_funcp)();
229 typedef ex (* evalf_funcp)();
230 typedef ex (* derivative_funcp)();
231 typedef ex (* series_funcp)();
233 // the following lines have been generated for max. ${maxargs} parameters
236 $typedef_derivative_funcp
237 $typedef_series_funcp
238 // end of generated lines
240 class function_options
242 friend class function;
243 friend class fderivative;
246 function_options(std::string const & n, std::string const & tn=std::string());
248 void initialize(void);
249 function_options & set_name(std::string const & n, std::string const & tn=std::string());
250 function_options & latex_name(std::string const & tn);
251 // the following lines have been generated for max. ${maxargs} parameters
253 $evalf_func_interface
254 $derivative_func_interface
255 $series_func_interface
256 // end of generated lines
257 function_options & set_return_type(unsigned rt, unsigned rtt=0);
258 function_options & do_not_evalf_params(void);
259 function_options & remember(unsigned size, unsigned assoc_size=0,
260 unsigned strategy=remember_strategies::delete_never);
261 function_options & overloaded(unsigned o);
262 function_options & set_symmetry(const symmetry & s);
263 void test_and_set_nparams(unsigned n);
264 std::string get_name(void) const { return name; }
265 unsigned get_nparams(void) const { return nparams; }
266 bool has_derivative(void) const { return derivative_f != NULL; }
270 std::string TeX_name;
276 derivative_funcp derivative_f;
277 series_funcp series_f;
279 bool evalf_params_first;
281 bool use_return_type;
282 unsigned return_type;
283 unsigned return_type_tinfo;
286 unsigned remember_size;
287 unsigned remember_assoc_size;
288 unsigned remember_strategy;
290 unsigned functions_with_same_name;
295 /** The class function is used to implement builtin functions like sin, cos...
296 and user defined functions */
297 class function : public exprseq
299 GINAC_DECLARE_REGISTERED_CLASS(function, exprseq)
301 // CINT has a linking problem
303 friend void ginsh_get_ginac_functions(void);
304 #endif // def __MAKECINT__
306 friend class remember_table_entry;
307 // friend class remember_table_list;
308 // friend class remember_table;
314 function(unsigned ser);
315 // the following lines have been generated for max. ${maxargs} parameters
316 $constructors_interface
317 // end of generated lines
318 function(unsigned ser, const exprseq & es);
319 function(unsigned ser, const exvector & v, bool discardable = false);
320 function(unsigned ser, exvector * vp); // vp will be deleted
322 // functions overriding virtual functions from base classes
324 void print(const print_context & c, unsigned level = 0) const;
325 unsigned precedence(void) const {return 70;}
326 int degree(const ex & s) const;
327 int ldegree(const ex & s) const;
328 ex coeff(const ex & s, int n = 1) const;
329 ex expand(unsigned options=0) const;
330 ex eval(int level=0) const;
331 ex evalf(int level=0) const;
332 unsigned calchash(void) const;
333 ex series(const relational & r, int order, unsigned options = 0) const;
334 ex thisexprseq(const exvector & v) const;
335 ex thisexprseq(exvector * vp) const;
337 ex derivative(const symbol & s) const;
338 bool is_equal_same_type(const basic & other) const;
339 bool match_same_type(const basic & other) const;
340 unsigned return_type(void) const;
341 unsigned return_type_tinfo(void) const;
343 // new virtual functions which can be overridden by derived classes
346 // non-virtual functions in this class
348 ex pderivative(unsigned diff_param) const; // partial differentiation
349 static std::vector<function_options> & registered_functions(void);
350 bool lookup_remember_table(ex & result) const;
351 void store_remember_table(ex const & result) const;
353 static unsigned register_new(function_options const & opt);
354 static unsigned find_function(const std::string &name, unsigned nparams);
355 unsigned get_serial(void) const {return serial;}
356 std::string get_name(void) const;
364 // utility functions/macros
365 /** Return the object of type function handled by an ex.
366 * This is unsafe: you need to check the type first. */
367 inline const function &ex_to_function(const ex &e)
369 return static_cast<const function &>(*e.bp);
372 /** Specialization of is_exactly_a<function>(obj) for objects of type function. */
373 template<> inline bool is_exactly_a<function>(const basic & obj)
375 return obj.tinfo()==TINFO_function;
378 #define is_ex_the_function(OBJ, FUNCNAME) \\
379 (is_ex_exactly_of_type(OBJ, function) && static_cast<GiNaC::function *>(OBJ.bp)->get_serial() == function_index_##FUNCNAME)
383 #endif // ndef __GINAC_FUNCTION_H__
387 $implementation=<<END_OF_IMPLEMENTATION;
388 /** \@file function.cpp
390 * Implementation of class of symbolic functions. */
393 * This file was generated automatically by function.pl.
394 * Please do not modify it directly, edit the perl script instead!
395 * function.pl options: \$maxargs=${maxargs}
397 * GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
399 * This program is free software; you can redistribute it and/or modify
400 * it under the terms of the GNU General Public License as published by
401 * the Free Software Foundation; either version 2 of the License, or
402 * (at your option) any later version.
404 * This program is distributed in the hope that it will be useful,
405 * but WITHOUT ANY WARRANTY; without even the implied warranty of
406 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
407 * GNU General Public License for more details.
409 * You should have received a copy of the GNU General Public License
410 * along with this program; if not, write to the Free Software
411 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
418 #include "function.h"
419 #include "fderivative.h"
422 #include "symmetry.h"
426 #include "tostring.h"
428 #include "debugmsg.h"
429 #include "remember.h"
434 // helper class function_options
437 function_options::function_options()
442 function_options::function_options(std::string const & n, std::string const & tn)
448 function_options::~function_options()
450 // nothing to clean up at the moment
453 void function_options::initialize(void)
455 set_name("unnamed_function","\\\\mbox{unnamed}");
457 eval_f = evalf_f = derivative_f = series_f = 0;
458 evalf_params_first = true;
459 use_return_type = false;
460 use_remember = false;
461 functions_with_same_name = 1;
465 function_options & function_options::set_name(std::string const & n,
466 std::string const & tn)
469 if (tn==std::string())
470 TeX_name = "\\\\mbox{"+name+"}";
476 function_options & function_options::latex_name(std::string const & tn)
482 // the following lines have been generated for max. ${maxargs} parameters
483 $eval_func_implementation
484 $evalf_func_implementation
485 $derivative_func_implementation
486 $series_func_implementation
487 // end of generated lines
489 function_options & function_options::set_return_type(unsigned rt, unsigned rtt)
491 use_return_type = true;
493 return_type_tinfo = rtt;
497 function_options & function_options::do_not_evalf_params(void)
499 evalf_params_first = false;
503 function_options & function_options::remember(unsigned size,
508 remember_size = size;
509 remember_assoc_size = assoc_size;
510 remember_strategy = strategy;
514 function_options & function_options::overloaded(unsigned o)
516 functions_with_same_name = o;
520 function_options & function_options::set_symmetry(const symmetry & s)
526 void function_options::test_and_set_nparams(unsigned n)
530 } else if (nparams!=n) {
531 // we do not throw an exception here because this code is
532 // usually executed before main(), so the exception could not
534 std::cerr << "WARNING: number of parameters ("
535 << n << ") differs from number set before ("
536 << nparams << ")" << std::endl;
540 GINAC_IMPLEMENT_REGISTERED_CLASS(function, exprseq)
543 // default ctor, dtor, copy ctor assignment operator and helpers
548 function::function() : serial(0)
550 debugmsg("function default ctor",LOGLEVEL_CONSTRUCT);
551 tinfo_key = TINFO_function;
556 void function::copy(const function & other)
558 inherited::copy(other);
559 serial = other.serial;
562 void function::destroy(bool call_parent)
565 inherited::destroy(call_parent);
574 function::function(unsigned ser) : serial(ser)
576 debugmsg("function ctor from unsigned",LOGLEVEL_CONSTRUCT);
577 tinfo_key = TINFO_function;
580 // the following lines have been generated for max. ${maxargs} parameters
581 $constructors_implementation
582 // end of generated lines
584 function::function(unsigned ser, const exprseq & es) : exprseq(es), serial(ser)
586 debugmsg("function ctor from unsigned,exprseq",LOGLEVEL_CONSTRUCT);
587 tinfo_key = TINFO_function;
590 function::function(unsigned ser, const exvector & v, bool discardable)
591 : exprseq(v,discardable), serial(ser)
593 debugmsg("function ctor from string,exvector,bool",LOGLEVEL_CONSTRUCT);
594 tinfo_key = TINFO_function;
597 function::function(unsigned ser, exvector * vp)
598 : exprseq(vp), serial(ser)
600 debugmsg("function ctor from unsigned,exvector *",LOGLEVEL_CONSTRUCT);
601 tinfo_key = TINFO_function;
608 /** Construct object from archive_node. */
609 function::function(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
611 debugmsg("function ctor from archive_node", LOGLEVEL_CONSTRUCT);
613 // Find serial number by function name
615 if (n.find_string("name", s)) {
616 unsigned int ser = 0;
617 std::vector<function_options>::const_iterator i = registered_functions().begin(), iend = registered_functions().end();
625 throw (std::runtime_error("unknown function '" + s + "' in archive"));
627 throw (std::runtime_error("unnamed function in archive"));
630 /** Unarchive the object. */
631 ex function::unarchive(const archive_node &n, const lst &sym_lst)
633 return (new function(n, sym_lst))->setflag(status_flags::dynallocated);
636 /** Archive the object. */
637 void function::archive(archive_node &n) const
639 inherited::archive(n);
640 GINAC_ASSERT(serial < registered_functions().size());
641 n.add_string("name", registered_functions()[serial].name);
645 // functions overriding virtual functions from base classes
650 void function::print(const print_context & c, unsigned level) const
652 debugmsg("function print", LOGLEVEL_PRINT);
654 GINAC_ASSERT(serial<registered_functions().size());
656 if (is_of_type(c, print_tree)) {
658 c.s << std::string(level, ' ') << class_name() << " "
659 << registered_functions()[serial].name
660 << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
661 << ", nops=" << nops()
663 unsigned delta_indent = static_cast<const print_tree &>(c).delta_indent;
664 for (unsigned i=0; i<seq.size(); ++i)
665 seq[i].print(c, level + delta_indent);
666 c.s << std::string(level + delta_indent, ' ') << "=====" << std::endl;
668 } else if (is_of_type(c, print_csrc)) {
670 // Print function name in lowercase
671 std::string lname = registered_functions()[serial].name;
672 unsigned num = lname.size();
673 for (unsigned i=0; i<num; i++)
674 lname[i] = tolower(lname[i]);
677 // Print arguments, separated by commas
678 exvector::const_iterator it = seq.begin(), itend = seq.end();
679 while (it != itend) {
687 } else if (is_of_type(c, print_latex)) {
688 c.s << registered_functions()[serial].TeX_name;
689 printseq(c, '(', ',', ')', exprseq::precedence(), function::precedence());
691 c.s << registered_functions()[serial].name;
692 printseq(c, '(', ',', ')', exprseq::precedence(), function::precedence());
696 ex function::expand(unsigned options) const
698 // Only expand arguments when asked to do so
699 if (options & expand_options::expand_function_args)
700 return inherited::expand(options);
702 return (options == 0) ? setflag(status_flags::expanded) : *this;
705 int function::degree(const ex & s) const
707 return is_equal(*s.bp) ? 1 : 0;
710 int function::ldegree(const ex & s) const
712 return is_equal(*s.bp) ? 1 : 0;
715 ex function::coeff(const ex & s, int n) const
718 return n==1 ? _ex1() : _ex0();
720 return n==0 ? ex(*this) : _ex0();
723 ex function::eval(int level) const
725 GINAC_ASSERT(serial<registered_functions().size());
728 // first evaluate children, then we will end up here again
729 return function(serial,evalchildren(level));
732 const function_options &opt = registered_functions()[serial];
734 // Canonicalize argument order according to the symmetry properties
735 if (seq.size() > 1 && !(opt.symtree.is_zero())) {
737 GINAC_ASSERT(is_of_type<symmetry>(opt.symtree));
738 int sig = canonicalize(v.begin(), ex_to<symmetry>(opt.symtree));
739 if (sig != INT_MAX) {
740 // Something has changed while sorting arguments, more evaluations later
743 return ex(sig) * thisexprseq(v);
751 bool use_remember = opt.use_remember;
753 if (use_remember && lookup_remember_table(eval_result)) {
757 switch (opt.nparams) {
758 // the following lines have been generated for max. ${maxargs} parameters
759 ${eval_switch_statement}
760 // end of generated lines
762 throw(std::logic_error("function::eval(): invalid nparams"));
765 store_remember_table(eval_result);
770 ex function::evalf(int level) const
772 GINAC_ASSERT(serial<registered_functions().size());
774 // Evaluate children first
778 else if (level == -max_recursion_level)
779 throw(std::runtime_error("max recursion level reached"));
781 eseq.reserve(seq.size());
783 exvector::const_iterator it = seq.begin(), itend = seq.end();
784 while (it != itend) {
785 eseq.push_back(it->evalf(level));
789 if (registered_functions()[serial].evalf_f==0) {
790 return function(serial,eseq).hold();
792 switch (registered_functions()[serial].nparams) {
793 // the following lines have been generated for max. ${maxargs} parameters
794 ${evalf_switch_statement}
795 // end of generated lines
797 throw(std::logic_error("function::evalf(): invalid nparams"));
800 unsigned function::calchash(void) const
802 unsigned v = golden_ratio_hash(golden_ratio_hash(tinfo()) ^ serial);
803 for (unsigned i=0; i<nops(); i++) {
804 v = rotate_left_31(v);
805 v ^= this->op(i).gethash();
808 if (flags & status_flags::evaluated) {
809 setflag(status_flags::hash_calculated);
815 ex function::thisexprseq(const exvector & v) const
817 return function(serial,v);
820 ex function::thisexprseq(exvector * vp) const
822 return function(serial,vp);
825 /** Implementation of ex::series for functions.
826 * \@see ex::series */
827 ex function::series(const relational & r, int order, unsigned options) const
829 GINAC_ASSERT(serial<registered_functions().size());
831 if (registered_functions()[serial].series_f==0) {
832 return basic::series(r, order);
835 switch (registered_functions()[serial].nparams) {
836 // the following lines have been generated for max. ${maxargs} parameters
837 ${series_switch_statement}
838 // end of generated lines
840 throw(std::logic_error("function::series(): invalid nparams"));
845 /** Implementation of ex::diff() for functions. It applies the chain rule,
846 * except for the Order term function.
848 ex function::derivative(const symbol & s) const
852 if (serial == function_index_Order) {
853 // Order Term function only differentiates the argument
854 return Order(seq[0].diff(s));
858 unsigned num = seq.size();
859 for (unsigned i=0; i<num; i++) {
860 arg_diff = seq[i].diff(s);
861 // We apply the chain rule only when it makes sense. This is not
862 // just for performance reasons but also to allow functions to
863 // throw when differentiated with respect to one of its arguments
864 // without running into trouble with our automatic full
866 if (!arg_diff.is_zero())
867 result += pderivative(i)*arg_diff;
873 int function::compare_same_type(const basic & other) const
875 GINAC_ASSERT(is_of_type(other, function));
876 const function & o = static_cast<const function &>(other);
878 if (serial != o.serial)
879 return serial < o.serial ? -1 : 1;
881 return exprseq::compare_same_type(o);
884 bool function::is_equal_same_type(const basic & other) const
886 GINAC_ASSERT(is_of_type(other, function));
887 const function & o = static_cast<const function &>(other);
889 if (serial != o.serial)
892 return exprseq::is_equal_same_type(o);
895 bool function::match_same_type(const basic & other) const
897 GINAC_ASSERT(is_of_type(other, function));
898 const function & o = static_cast<const function &>(other);
900 return serial == o.serial;
903 unsigned function::return_type(void) const
906 return return_types::commutative;
908 return seq.begin()->return_type();
911 unsigned function::return_type_tinfo(void) const
916 return seq.begin()->return_type_tinfo();
920 // new virtual functions which can be overridden by derived classes
926 // non-virtual functions in this class
931 ex function::pderivative(unsigned diff_param) const // partial differentiation
933 GINAC_ASSERT(serial<registered_functions().size());
935 // No derivative defined? Then return abstract derivative object
936 if (registered_functions()[serial].derivative_f == NULL)
937 return fderivative(serial, diff_param, seq);
939 switch (registered_functions()[serial].nparams) {
940 // the following lines have been generated for max. ${maxargs} parameters
941 ${diff_switch_statement}
942 // end of generated lines
944 throw(std::logic_error("function::pderivative(): no diff function defined"));
947 std::vector<function_options> & function::registered_functions(void)
949 static std::vector<function_options> * rf = new std::vector<function_options>;
953 bool function::lookup_remember_table(ex & result) const
955 return remember_table::remember_tables()[serial].lookup_entry(*this,result);
958 void function::store_remember_table(ex const & result) const
960 remember_table::remember_tables()[serial].add_entry(*this,result);
965 unsigned function::register_new(function_options const & opt)
967 unsigned same_name = 0;
968 for (unsigned i=0; i<registered_functions().size(); ++i) {
969 if (registered_functions()[i].name==opt.name) {
973 if (same_name>=opt.functions_with_same_name) {
974 // we do not throw an exception here because this code is
975 // usually executed before main(), so the exception could not
977 std::cerr << "WARNING: function name " << opt.name
978 << " already in use!" << std::endl;
980 registered_functions().push_back(opt);
981 if (opt.use_remember) {
982 remember_table::remember_tables().
983 push_back(remember_table(opt.remember_size,
984 opt.remember_assoc_size,
985 opt.remember_strategy));
987 remember_table::remember_tables().push_back(remember_table());
989 return registered_functions().size()-1;
992 /** Find serial number of function by name and number of parameters.
993 * Throws exception if function was not found. */
994 unsigned function::find_function(const std::string &name, unsigned nparams)
996 std::vector<function_options>::const_iterator i = function::registered_functions().begin(), end = function::registered_functions().end();
999 if (i->get_name() == name && i->get_nparams() == nparams)
1004 throw (std::runtime_error("no function '" + name + "' with " + ToString(nparams) + " parameters defined"));
1007 /** Return the print name of the function. */
1008 std::string function::get_name(void) const
1010 GINAC_ASSERT(serial<registered_functions().size());
1011 return registered_functions()[serial].name;
1014 } // namespace GiNaC
1016 END_OF_IMPLEMENTATION
1018 print "Creating interface file function.h...";
1019 open OUT,">function.h" or die "cannot open function.h";
1020 print OUT $interface;
1024 print "Creating implementation file function.cpp...";
1025 open OUT,">function.cpp" or die "cannot open function.cpp";
1026 print OUT $implementation;