]> www.ginac.de Git - ginac.git/blob - ginac/function.pl
Fixed bug in the Q matrix calculation and the univariate factorization function.
[ginac.git] / ginac / function.pl
1 #  This perl script automatically generates function.h and function.cpp
2
3 #  function.pl options: \$maxargs=${maxargs}
4
5 #  GiNaC Copyright (C) 1999-2008 Johannes Gutenberg University Mainz, Germany
6
7 #  This program is free software; you can redistribute it and/or modify
8 #  it under the terms of the GNU General Public License as published by
9 #  the Free Software Foundation; either version 2 of the License, or
10 #  (at your option) any later version.
11
12 #  This program is distributed in the hope that it will be useful,
13 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #  GNU General Public License for more details.
16
17 #  You should have received a copy of the GNU General Public License
18 #  along with this program; if not, write to the Free Software
19 #  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
20
21 $maxargs=14;
22
23 sub generate_seq {
24         my ($seq_template,$n)=@_;
25         my ($res,$N);
26         
27         $res='';
28         for ($N=1; $N<=$n; $N++) {
29                 $res .= eval('"' . $seq_template . '"');
30                 if ($N!=$n) {
31                         $res .= ', ';
32                 }
33         }
34         return $res;
35 }
36
37 sub generate_from_to {
38         my ($template,$seq_template1,$seq_template2,$seq_template3,$from,$to)=@_;
39         my ($res,$N,$SEQ);
40
41         $res='';
42         for ($N=$from; $N<=$to; $N++) {
43                 $SEQ1=generate_seq($seq_template1,$N);
44                 $SEQ2=generate_seq($seq_template2,$N);
45                 $SEQ3=generate_seq($seq_template3,$N);
46                 $res .= eval('"' . $template . '"');
47                 $SEQ1=''; # to avoid main::SEQ1 used only once warning
48                 $SEQ2=''; # same as above
49                 $SEQ3=''; # same as above
50         }
51         return $res;
52 }
53
54 sub generate {
55         my ($template,$seq_template1,$seq_template2,$seq_template3)=@_;
56         return generate_from_to($template,$seq_template1,$seq_template2,$seq_template3,1,$maxargs);
57 }
58
59 $declare_function_macro = generate(
60         <<'END_OF_DECLARE_FUNCTION_MACRO','typename T${N}','const T${N} & p${N}','GiNaC::ex(p${N})');
61 #define DECLARE_FUNCTION_${N}P(NAME) \\
62 class NAME##_SERIAL { public: static unsigned serial; }; \\
63 const unsigned NAME##_NPARAMS = ${N}; \\
64 template<${SEQ1}> const GiNaC::function NAME(${SEQ2}) { \\
65         return GiNaC::function(NAME##_SERIAL::serial, ${SEQ3}); \\
66 }
67
68 END_OF_DECLARE_FUNCTION_MACRO
69
70 $typedef_eval_funcp=generate(
71 'typedef ex (* eval_funcp_${N})(${SEQ1});'."\n",
72 'const ex &','','');
73
74 $typedef_evalf_funcp=generate(
75 'typedef ex (* evalf_funcp_${N})(${SEQ1});'."\n",
76 'const ex &','','');
77
78 $typedef_conjugate_funcp=generate(
79 'typedef ex (* conjugate_funcp_${N})(${SEQ1});'."\n",
80 'const ex &','','');
81
82 $typedef_real_part_funcp=generate(
83 'typedef ex (* real_part_funcp_${N})(${SEQ1});'."\n",
84 'const ex &','','');
85
86 $typedef_imag_part_funcp=generate(
87 'typedef ex (* imag_part_funcp_${N})(${SEQ1});'."\n",
88 'const ex &','','');
89
90 $typedef_derivative_funcp=generate(
91 'typedef ex (* derivative_funcp_${N})(${SEQ1}, unsigned);'."\n",
92 'const ex &','','');
93
94 $typedef_power_funcp=generate(
95 'typedef ex (* power_funcp_${N})(${SEQ1}, const ex &);'."\n",
96 'const ex &','','');
97
98 $typedef_series_funcp=generate(
99 'typedef ex (* series_funcp_${N})(${SEQ1}, const relational &, int, unsigned);'."\n",
100 'const ex &','','');
101
102 $typedef_print_funcp=generate(
103 'typedef void (* print_funcp_${N})(${SEQ1}, const print_context &);'."\n",
104 'const ex &','','');
105
106 $eval_func_interface=generate('    function_options & eval_func(eval_funcp_${N} e);'."\n",'','','');
107
108 $evalf_func_interface=generate('    function_options & evalf_func(evalf_funcp_${N} ef);'."\n",'','','');
109
110 $conjugate_func_interface=generate('    function_options & conjugate_func(conjugate_funcp_${N} d);'."\n",'','','');
111
112 $real_part_func_interface=generate('    function_options & real_part_func(real_part_funcp_${N} d);'."\n",'','','');
113
114 $imag_part_func_interface=generate('    function_options & imag_part_func(imag_part_funcp_${N} d);'."\n",'','','');
115
116 $derivative_func_interface=generate('    function_options & derivative_func(derivative_funcp_${N} d);'."\n",'','','');
117
118 $power_func_interface=generate('    function_options & power_func(power_funcp_${N} d);'."\n",'','','');
119
120 $series_func_interface=generate('    function_options & series_func(series_funcp_${N} s);'."\n",'','','');
121
122 $print_func_interface=generate(
123         <<'END_OF_PRINT_FUNC_INTERFACE','','','');
124     template <class Ctx> function_options & print_func(print_funcp_${N} p)
125     {
126         test_and_set_nparams(${N});
127         set_print_func(Ctx::get_class_info_static().options.get_id(), print_funcp(p));
128         return *this;
129     }
130 END_OF_PRINT_FUNC_INTERFACE
131
132 $constructors_interface=generate(
133 '    function(unsigned ser, ${SEQ1});'."\n",
134 'const ex & param${N}','','');
135
136 $constructors_implementation=generate(
137         <<'END_OF_CONSTRUCTORS_IMPLEMENTATION','const ex & param${N}','param${N}','');
138 function::function(unsigned ser, ${SEQ1})
139         : exprseq(${SEQ2}), serial(ser)
140 {
141         tinfo_key = &function::tinfo_static;
142 }
143 END_OF_CONSTRUCTORS_IMPLEMENTATION
144
145 $eval_switch_statement=generate(
146         <<'END_OF_EVAL_SWITCH_STATEMENT','seq[${N}-1]','','');
147         case ${N}:
148                 eval_result = ((eval_funcp_${N})(opt.eval_f))(${SEQ1});
149                 break;
150 END_OF_EVAL_SWITCH_STATEMENT
151
152 $evalf_switch_statement=generate(
153         <<'END_OF_EVALF_SWITCH_STATEMENT','eseq[${N}-1]','','');
154         case ${N}:
155                 return ((evalf_funcp_${N})(opt.evalf_f))(${SEQ1});
156 END_OF_EVALF_SWITCH_STATEMENT
157
158 $conjugate_switch_statement=generate(
159         <<'END_OF_DIFF_SWITCH_STATEMENT','seq[${N}-1]','','');
160         case ${N}:
161                 return ((conjugate_funcp_${N})(opt.conjugate_f))(${SEQ1});
162 END_OF_DIFF_SWITCH_STATEMENT
163
164 $real_part_switch_statement=generate(
165         <<'END_OF_DIFF_SWITCH_STATEMENT','seq[${N}-1]','','');
166         case ${N}:
167                 return ((real_part_funcp_${N})(opt.real_part_f))(${SEQ1});
168 END_OF_DIFF_SWITCH_STATEMENT
169
170 $imag_part_switch_statement=generate(
171         <<'END_OF_DIFF_SWITCH_STATEMENT','seq[${N}-1]','','');
172         case ${N}:
173                 return ((imag_part_funcp_${N})(opt.imag_part_f))(${SEQ1});
174 END_OF_DIFF_SWITCH_STATEMENT
175
176 $diff_switch_statement=generate(
177         <<'END_OF_DIFF_SWITCH_STATEMENT','seq[${N}-1]','','');
178         case ${N}:
179                 return ((derivative_funcp_${N})(opt.derivative_f))(${SEQ1},diff_param);
180 END_OF_DIFF_SWITCH_STATEMENT
181
182 $power_switch_statement=generate(
183         <<'END_OF_POWER_SWITCH_STATEMENT','seq[${N}-1]','','');
184         case ${N}:
185                 return ((power_funcp_${N})(opt.power_f))(${SEQ1},power_param);
186 END_OF_POWER_SWITCH_STATEMENT
187
188 $series_switch_statement=generate(
189         <<'END_OF_SERIES_SWITCH_STATEMENT','seq[${N}-1]','','');
190         case ${N}:
191                 try {
192                         res = ((series_funcp_${N})(opt.series_f))(${SEQ1},r,order,options);
193                 } catch (do_taylor) {
194                         res = basic::series(r, order, options);
195                 }
196                 return res;
197 END_OF_SERIES_SWITCH_STATEMENT
198
199 $print_switch_statement=generate(
200         <<'END_OF_PRINT_SWITCH_STATEMENT','seq[${N}-1]','','');
201                 case ${N}:
202                         ((print_funcp_${N})(pdt[id]))(${SEQ1}, c);
203                         break;
204 END_OF_PRINT_SWITCH_STATEMENT
205
206 $eval_func_implementation=generate(
207         <<'END_OF_EVAL_FUNC_IMPLEMENTATION','','','');
208 function_options & function_options::eval_func(eval_funcp_${N} e)
209 {
210         test_and_set_nparams(${N});
211         eval_f = eval_funcp(e);
212         return *this;
213 }
214 END_OF_EVAL_FUNC_IMPLEMENTATION
215
216 $evalf_func_implementation=generate(
217         <<'END_OF_EVALF_FUNC_IMPLEMENTATION','','','');
218 function_options & function_options::evalf_func(evalf_funcp_${N} ef)
219 {
220         test_and_set_nparams(${N});
221         evalf_f = evalf_funcp(ef);
222         return *this;
223 }
224 END_OF_EVALF_FUNC_IMPLEMENTATION
225
226 $conjugate_func_implementation=generate(
227         <<'END_OF_CONJUGATE_FUNC_IMPLEMENTATION','','','');
228 function_options & function_options::conjugate_func(conjugate_funcp_${N} c)
229 {
230         test_and_set_nparams(${N});
231         conjugate_f = conjugate_funcp(c);
232         return *this;
233 }
234 END_OF_CONJUGATE_FUNC_IMPLEMENTATION
235
236 $real_part_func_implementation=generate(
237         <<'END_OF_REAL_PART_FUNC_IMPLEMENTATION','','','');
238 function_options & function_options::real_part_func(real_part_funcp_${N} c)
239 {
240         test_and_set_nparams(${N});
241         real_part_f = real_part_funcp(c);
242         return *this;
243 }
244 END_OF_REAL_PART_FUNC_IMPLEMENTATION
245
246 $imag_part_func_implementation=generate(
247         <<'END_OF_IMAG_PART_FUNC_IMPLEMENTATION','','','');
248 function_options & function_options::imag_part_func(imag_part_funcp_${N} c)
249 {
250         test_and_set_nparams(${N});
251         imag_part_f = imag_part_funcp(c);
252         return *this;
253 }
254 END_OF_IMAG_PART_FUNC_IMPLEMENTATION
255
256 $derivative_func_implementation=generate(
257         <<'END_OF_DERIVATIVE_FUNC_IMPLEMENTATION','','','');
258 function_options & function_options::derivative_func(derivative_funcp_${N} d)
259 {
260         test_and_set_nparams(${N});
261         derivative_f = derivative_funcp(d);
262         return *this;
263 }
264 END_OF_DERIVATIVE_FUNC_IMPLEMENTATION
265
266 $power_func_implementation=generate(
267         <<'END_OF_POWER_FUNC_IMPLEMENTATION','','','');
268 function_options & function_options::power_func(power_funcp_${N} d)
269 {
270         test_and_set_nparams(${N});
271         power_f = power_funcp(d);
272         return *this;
273 }
274 END_OF_POWER_FUNC_IMPLEMENTATION
275
276 $series_func_implementation=generate(
277         <<'END_OF_SERIES_FUNC_IMPLEMENTATION','','','');
278 function_options & function_options::series_func(series_funcp_${N} s)
279 {
280         test_and_set_nparams(${N});
281         series_f = series_funcp(s);
282         return *this;
283 }
284 END_OF_SERIES_FUNC_IMPLEMENTATION
285
286 $interface=<<END_OF_INTERFACE;
287 /** \@file function.h
288  *
289  *  Interface to class of symbolic functions. */
290
291 /*
292  *  This file was generated automatically by function.pl.
293  *  Please do not modify it directly, edit the perl script instead!
294  *  function.pl options: \$maxargs=${maxargs}
295  *
296  *  GiNaC Copyright (C) 1999-2008 Johannes Gutenberg University Mainz, Germany
297  *
298  *  This program is free software; you can redistribute it and/or modify
299  *  it under the terms of the GNU General Public License as published by
300  *  the Free Software Foundation; either version 2 of the License, or
301  *  (at your option) any later version.
302  *
303  *  This program is distributed in the hope that it will be useful,
304  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
305  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
306  *  GNU General Public License for more details.
307  *
308  *  You should have received a copy of the GNU General Public License
309  *  along with this program; if not, write to the Free Software
310  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
311  */
312
313 #ifndef __GINAC_FUNCTION_H__
314 #define __GINAC_FUNCTION_H__
315
316 #include <string>
317 #include <vector>
318
319 // CINT needs <algorithm> to work properly with <vector>
320 #include <algorithm>
321
322 #include "exprseq.h"
323
324 // the following lines have been generated for max. ${maxargs} parameters
325 $declare_function_macro
326 // end of generated lines
327
328 #define REGISTER_FUNCTION(NAME,OPT) \\
329 unsigned NAME##_SERIAL::serial = \\
330         GiNaC::function::register_new(GiNaC::function_options(#NAME, NAME##_NPARAMS).OPT);
331
332 namespace GiNaC {
333
334 class function;
335 class symmetry;
336
337 typedef ex (* eval_funcp)();
338 typedef ex (* evalf_funcp)();
339 typedef ex (* conjugate_funcp)();
340 typedef ex (* real_part_funcp)();
341 typedef ex (* imag_part_funcp)();
342 typedef ex (* derivative_funcp)();
343 typedef ex (* power_funcp)();
344 typedef ex (* series_funcp)();
345 typedef void (* print_funcp)();
346
347 // the following lines have been generated for max. ${maxargs} parameters
348 $typedef_eval_funcp
349 $typedef_evalf_funcp
350 $typedef_conjugate_funcp
351 $typedef_real_part_funcp
352 $typedef_imag_part_funcp
353 $typedef_derivative_funcp
354 $typedef_power_funcp
355 $typedef_series_funcp
356 $typedef_print_funcp
357 // end of generated lines
358
359 // Alternatively, an exvector may be passed into the static function, instead
360 // of individual ex objects.  Then, the number of arguments is not limited.
361 typedef ex (* eval_funcp_exvector)(const exvector &);
362 typedef ex (* evalf_funcp_exvector)(const exvector &);
363 typedef ex (* conjugate_funcp_exvector)(const exvector &);
364 typedef ex (* real_part_funcp_exvector)(const exvector &);
365 typedef ex (* imag_part_funcp_exvector)(const exvector &);
366 typedef ex (* derivative_funcp_exvector)(const exvector &, unsigned);
367 typedef ex (* power_funcp_exvector)(const exvector &, const ex &);
368 typedef ex (* series_funcp_exvector)(const exvector &, const relational &, int, unsigned);
369 typedef void (* print_funcp_exvector)(const exvector &, const print_context &);
370
371
372 class function_options
373 {
374         friend class function;
375         friend class fderivative;
376 public:
377         function_options();
378         function_options(std::string const & n, std::string const & tn=std::string());
379         function_options(std::string const & n, unsigned np);
380         ~function_options();
381         void initialize();
382
383         function_options & dummy() { return *this; }
384         function_options & set_name(std::string const & n, std::string const & tn=std::string());
385         function_options & latex_name(std::string const & tn);
386 // the following lines have been generated for max. ${maxargs} parameters
387 $eval_func_interface
388 $evalf_func_interface
389 $conjugate_func_interface
390 $real_part_func_interface
391 $imag_part_func_interface
392 $derivative_func_interface
393 $power_func_interface
394 $series_func_interface
395 $print_func_interface
396 // end of generated lines
397         function_options & eval_func(eval_funcp_exvector e);
398         function_options & evalf_func(evalf_funcp_exvector ef);
399         function_options & conjugate_func(conjugate_funcp_exvector d);
400         function_options & real_part_func(real_part_funcp_exvector d);
401         function_options & imag_part_func(imag_part_funcp_exvector d);
402         function_options & derivative_func(derivative_funcp_exvector d);
403         function_options & power_func(power_funcp_exvector d);
404         function_options & series_func(series_funcp_exvector s);
405
406         template <class Ctx> function_options & print_func(print_funcp_exvector p)
407         {
408                 print_use_exvector_args = true;
409                 set_print_func(Ctx::get_class_info_static().options.get_id(), print_funcp(p));
410                 return *this;
411         }
412
413         function_options & set_return_type(unsigned rt, tinfo_t rtt=NULL);
414         function_options & do_not_evalf_params();
415         function_options & remember(unsigned size, unsigned assoc_size=0,
416                                     unsigned strategy=remember_strategies::delete_never);
417         function_options & overloaded(unsigned o);
418         function_options & set_symmetry(const symmetry & s);
419
420         std::string get_name() const { return name; }
421         unsigned get_nparams() const { return nparams; }
422
423 protected:
424         bool has_derivative() const { return derivative_f != NULL; }
425         bool has_power() const { return power_f != NULL; }
426         void test_and_set_nparams(unsigned n);
427         void set_print_func(unsigned id, print_funcp f);
428
429         std::string name;
430         std::string TeX_name;
431
432         unsigned nparams;
433
434         eval_funcp eval_f;
435         evalf_funcp evalf_f;
436         conjugate_funcp conjugate_f;
437         real_part_funcp real_part_f;
438         imag_part_funcp imag_part_f;
439         derivative_funcp derivative_f;
440         power_funcp power_f;
441         series_funcp series_f;
442         std::vector<print_funcp> print_dispatch_table;
443
444         bool evalf_params_first;
445
446         bool use_return_type;
447         unsigned return_type;
448         tinfo_t return_type_tinfo;
449
450         bool use_remember;
451         unsigned remember_size;
452         unsigned remember_assoc_size;
453         unsigned remember_strategy;
454
455         bool eval_use_exvector_args;
456         bool evalf_use_exvector_args;
457         bool conjugate_use_exvector_args;
458         bool real_part_use_exvector_args;
459         bool imag_part_use_exvector_args;
460         bool derivative_use_exvector_args;
461         bool power_use_exvector_args;
462         bool series_use_exvector_args;
463         bool print_use_exvector_args;
464
465         unsigned functions_with_same_name;
466
467         ex symtree;
468 };
469
470
471 /** Exception class thrown by classes which provide their own series expansion
472  *  to signal that ordinary Taylor expansion is safe. */
473 class do_taylor {};
474
475
476 /** The class function is used to implement builtin functions like sin, cos...
477         and user defined functions */
478 class function : public exprseq
479 {
480         GINAC_DECLARE_REGISTERED_CLASS(function, exprseq)
481
482         // CINT has a linking problem
483 #ifndef __MAKECINT__
484         friend void ginsh_get_ginac_functions();
485 #endif // def __MAKECINT__
486
487         friend class remember_table_entry;
488         // friend class remember_table_list;
489         // friend class remember_table;
490
491 // member functions
492
493         // other constructors
494 public:
495         function(unsigned ser);
496         // the following lines have been generated for max. ${maxargs} parameters
497 $constructors_interface
498         // end of generated lines
499         function(unsigned ser, const exprseq & es);
500         function(unsigned ser, const exvector & v, bool discardable = false);
501         function(unsigned ser, std::auto_ptr<exvector> vp);
502
503         // functions overriding virtual functions from base classes
504 public:
505         void print(const print_context & c, unsigned level = 0) const;
506         unsigned precedence() const {return 70;}
507         ex expand(unsigned options=0) const;
508         ex eval(int level=0) const;
509         ex evalf(int level=0) const;
510         ex eval_ncmul(const exvector & v) const;
511         unsigned calchash() const;
512         ex series(const relational & r, int order, unsigned options = 0) const;
513         ex thiscontainer(const exvector & v) const;
514         ex thiscontainer(std::auto_ptr<exvector> vp) const;
515         ex conjugate() const;
516         ex real_part() const;
517         ex imag_part() const;
518 protected:
519         ex derivative(const symbol & s) const;
520         bool is_equal_same_type(const basic & other) const;
521         bool match_same_type(const basic & other) const;
522         unsigned return_type() const;
523         tinfo_t return_type_tinfo() const;
524         
525         // new virtual functions which can be overridden by derived classes
526         // none
527         
528         // non-virtual functions in this class
529 protected:
530         ex pderivative(unsigned diff_param) const; // partial differentiation
531         static std::vector<function_options> & registered_functions();
532         bool lookup_remember_table(ex & result) const;
533         void store_remember_table(ex const & result) const;
534 public:
535         ex power(const ex & exp) const;
536         static unsigned register_new(function_options const & opt);
537         static unsigned current_serial;
538         static unsigned find_function(const std::string &name, unsigned nparams);
539         unsigned get_serial() const {return serial;}
540         std::string get_name() const;
541
542 // member variables
543
544 protected:
545         unsigned serial;
546 };
547
548 // utility functions/macros
549
550 template <typename T>
551 inline bool is_the_function(const ex & x)
552 {
553         return is_exactly_a<function>(x)
554             && ex_to<function>(x).get_serial() == T::serial;
555 }
556
557 // Check whether OBJ is the specified symbolic function.
558 #define is_ex_the_function(OBJ, FUNCNAME) (GiNaC::is_the_function<FUNCNAME##_SERIAL>(OBJ))
559
560 } // namespace GiNaC
561
562 #endif // ndef __GINAC_FUNCTION_H__
563
564 END_OF_INTERFACE
565
566 $implementation=<<END_OF_IMPLEMENTATION;
567 /** \@file function.cpp
568  *
569  *  Implementation of class of symbolic functions. */
570
571 /*
572  *  This file was generated automatically by function.pl.
573  *  Please do not modify it directly, edit the perl script instead!
574  *  function.pl options: \$maxargs=${maxargs}
575  *
576  *  GiNaC Copyright (C) 1999-2008 Johannes Gutenberg University Mainz, Germany
577  *
578  *  This program is free software; you can redistribute it and/or modify
579  *  it under the terms of the GNU General Public License as published by
580  *  the Free Software Foundation; either version 2 of the License, or
581  *  (at your option) any later version.
582  *
583  *  This program is distributed in the hope that it will be useful,
584  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
585  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
586  *  GNU General Public License for more details.
587  *
588  *  You should have received a copy of the GNU General Public License
589  *  along with this program; if not, write to the Free Software
590  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
591  */
592
593 #include <iostream>
594 #include <string>
595 #include <stdexcept>
596 #include <list>
597 #include <limits>
598
599 #include "function.h"
600 #include "operators.h"
601 #include "fderivative.h"
602 #include "ex.h"
603 #include "lst.h"
604 #include "symmetry.h"
605 #include "print.h"
606 #include "power.h"
607 #include "archive.h"
608 #include "inifcns.h"
609 #include "tostring.h"
610 #include "utils.h"
611 #include "remember.h"
612
613 namespace GiNaC {
614
615 //////////
616 // helper class function_options
617 //////////
618
619 function_options::function_options()
620 {
621         initialize();
622 }
623
624 function_options::function_options(std::string const & n, std::string const & tn)
625 {
626         initialize();
627         set_name(n, tn);
628 }
629
630 function_options::function_options(std::string const & n, unsigned np)
631 {
632         initialize();
633         set_name(n, std::string());
634         nparams = np;
635 }
636
637 function_options::~function_options()
638 {
639         // nothing to clean up at the moment
640 }
641
642 void function_options::initialize()
643 {
644         set_name("unnamed_function", "\\\\mbox{unnamed}");
645         nparams = 0;
646         eval_f = evalf_f = real_part_f = imag_part_f = conjugate_f = derivative_f
647                 = power_f = series_f = 0;
648         evalf_params_first = true;
649         use_return_type = false;
650         eval_use_exvector_args = false;
651         evalf_use_exvector_args = false;
652         conjugate_use_exvector_args = false;
653         real_part_use_exvector_args = false;
654         imag_part_use_exvector_args = false;
655         derivative_use_exvector_args = false;
656         power_use_exvector_args = false;
657         series_use_exvector_args = false;
658         print_use_exvector_args = false;
659         use_remember = false;
660         functions_with_same_name = 1;
661         symtree = 0;
662 }
663
664 function_options & function_options::set_name(std::string const & n,
665                                               std::string const & tn)
666 {
667         name = n;
668         if (tn==std::string())
669                 TeX_name = "\\\\mbox{"+name+"}";
670         else
671                 TeX_name = tn;
672         return *this;
673 }
674
675 function_options & function_options::latex_name(std::string const & tn)
676 {
677         TeX_name = tn;
678         return *this;
679 }
680
681 // the following lines have been generated for max. ${maxargs} parameters
682 $eval_func_implementation
683 $evalf_func_implementation
684 $conjugate_func_implementation
685 $real_part_func_implementation
686 $imag_part_func_implementation
687 $derivative_func_implementation
688 $power_func_implementation
689 $series_func_implementation
690 // end of generated lines
691
692 function_options& function_options::eval_func(eval_funcp_exvector e)
693 {
694         eval_use_exvector_args = true;
695         eval_f = eval_funcp(e);
696         return *this;
697 }
698 function_options& function_options::evalf_func(evalf_funcp_exvector ef)
699 {
700         evalf_use_exvector_args = true;
701         evalf_f = evalf_funcp(ef);
702         return *this;
703 }
704 function_options& function_options::conjugate_func(conjugate_funcp_exvector c)
705 {
706         conjugate_use_exvector_args = true;
707         conjugate_f = conjugate_funcp(c);
708         return *this;
709 }
710 function_options& function_options::real_part_func(real_part_funcp_exvector c)
711 {
712         real_part_use_exvector_args = true;
713         real_part_f = real_part_funcp(c);
714         return *this;
715 }
716 function_options& function_options::imag_part_func(imag_part_funcp_exvector c)
717 {
718         imag_part_use_exvector_args = true;
719         imag_part_f = imag_part_funcp(c);
720         return *this;
721 }
722
723 function_options& function_options::derivative_func(derivative_funcp_exvector d)
724 {
725         derivative_use_exvector_args = true;
726         derivative_f = derivative_funcp(d);
727         return *this;
728 }
729 function_options& function_options::power_func(power_funcp_exvector d)
730 {
731         power_use_exvector_args = true;
732         power_f = power_funcp(d);
733         return *this;
734 }
735 function_options& function_options::series_func(series_funcp_exvector s)
736 {
737         series_use_exvector_args = true;
738         series_f = series_funcp(s);
739         return *this;
740 }
741
742 function_options & function_options::set_return_type(unsigned rt, tinfo_t rtt)
743 {
744         use_return_type = true;
745         return_type = rt;
746         return_type_tinfo = rtt;
747         return *this;
748 }
749
750 function_options & function_options::do_not_evalf_params()
751 {
752         evalf_params_first = false;
753         return *this;
754 }
755
756 function_options & function_options::remember(unsigned size,
757                                               unsigned assoc_size,
758                                               unsigned strategy)
759 {
760         use_remember = true;
761         remember_size = size;
762         remember_assoc_size = assoc_size;
763         remember_strategy = strategy;
764         return *this;
765 }
766
767 function_options & function_options::overloaded(unsigned o)
768 {
769         functions_with_same_name = o;
770         return *this;
771 }
772
773 function_options & function_options::set_symmetry(const symmetry & s)
774 {
775         symtree = s;
776         return *this;
777 }
778         
779 void function_options::test_and_set_nparams(unsigned n)
780 {
781         if (nparams==0) {
782                 nparams = n;
783         } else if (nparams!=n) {
784                 // we do not throw an exception here because this code is
785                 // usually executed before main(), so the exception could not
786                 // be caught anyhow
787                 std::cerr << "WARNING: " << name << "(): number of parameters ("
788                           << n << ") differs from number set before (" 
789                           << nparams << ")" << std::endl;
790         }
791 }
792
793 void function_options::set_print_func(unsigned id, print_funcp f)
794 {
795         if (id >= print_dispatch_table.size())
796                 print_dispatch_table.resize(id + 1);
797         print_dispatch_table[id] = f;
798 }
799
800 /** This can be used as a hook for external applications. */
801 unsigned function::current_serial = 0;
802
803
804 GINAC_IMPLEMENT_REGISTERED_CLASS(function, exprseq)
805
806 //////////
807 // default constructor
808 //////////
809
810 // public
811
812 function::function() : serial(0)
813 {
814         tinfo_key = &function::tinfo_static;
815 }
816
817 //////////
818 // other constructors
819 //////////
820
821 // public
822
823 function::function(unsigned ser) : serial(ser)
824 {
825         tinfo_key = &function::tinfo_static;
826 }
827
828 // the following lines have been generated for max. ${maxargs} parameters
829 $constructors_implementation
830 // end of generated lines
831
832 function::function(unsigned ser, const exprseq & es) : exprseq(es), serial(ser)
833 {
834         tinfo_key = &function::tinfo_static;
835
836         // Force re-evaluation even if the exprseq was already evaluated
837         // (the exprseq copy constructor copies the flags)
838         clearflag(status_flags::evaluated);
839 }
840
841 function::function(unsigned ser, const exvector & v, bool discardable) 
842   : exprseq(v,discardable), serial(ser)
843 {
844         tinfo_key = &function::tinfo_static;
845 }
846
847 function::function(unsigned ser, std::auto_ptr<exvector> vp) 
848   : exprseq(vp), serial(ser)
849 {
850         tinfo_key = &function::tinfo_static;
851 }
852
853 //////////
854 // archiving
855 //////////
856
857 /** Construct object from archive_node. */
858 function::function(const archive_node &n, lst &sym_lst) : inherited(n, sym_lst)
859 {
860         // Find serial number by function name
861         std::string s;
862         if (n.find_string("name", s)) {
863                 unsigned int ser = 0;
864                 std::vector<function_options>::const_iterator i = registered_functions().begin(), iend = registered_functions().end();
865                 while (i != iend) {
866                         if (s == i->name) {
867                                 serial = ser;
868                                 return;
869                         }
870                         ++i; ++ser;
871                 }
872                 throw (std::runtime_error("unknown function '" + s + "' in archive"));
873         } else
874                 throw (std::runtime_error("unnamed function in archive"));
875 }
876
877 /** Unarchive the object. */
878 ex function::unarchive(const archive_node &n, lst &sym_lst)
879 {
880         return (new function(n, sym_lst))->setflag(status_flags::dynallocated);
881 }
882
883 /** Archive the object. */
884 void function::archive(archive_node &n) const
885 {
886         inherited::archive(n);
887         GINAC_ASSERT(serial < registered_functions().size());
888         n.add_string("name", registered_functions()[serial].name);
889 }
890
891 //////////
892 // functions overriding virtual functions from base classes
893 //////////
894
895 // public
896
897 void function::print(const print_context & c, unsigned level) const
898 {
899         GINAC_ASSERT(serial<registered_functions().size());
900         const function_options &opt = registered_functions()[serial];
901         const std::vector<print_funcp> &pdt = opt.print_dispatch_table;
902
903         // Dynamically dispatch on print_context type
904         const print_context_class_info *pc_info = &c.get_class_info();
905
906 next_context:
907         unsigned id = pc_info->options.get_id();
908         if (id >= pdt.size() || pdt[id] == NULL) {
909
910                 // Method not found, try parent print_context class
911                 const print_context_class_info *parent_pc_info = pc_info->get_parent();
912                 if (parent_pc_info) {
913                         pc_info = parent_pc_info;
914                         goto next_context;
915                 }
916
917                 // Method still not found, use default output
918                 if (is_a<print_tree>(c)) {
919
920                         c.s << std::string(level, ' ') << class_name() << " "
921                             << opt.name << " @" << this
922                             << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
923                             << ", nops=" << nops()
924                             << std::endl;
925                         unsigned delta_indent = static_cast<const print_tree &>(c).delta_indent;
926                         for (size_t i=0; i<seq.size(); ++i)
927                                 seq[i].print(c, level + delta_indent);
928                         c.s << std::string(level + delta_indent, ' ') << "=====" << std::endl;
929
930                 } else if (is_a<print_csrc>(c)) {
931
932                         // Print function name in lowercase
933                         std::string lname = opt.name;
934                         size_t num = lname.size();
935                         for (size_t i=0; i<num; i++)
936                                 lname[i] = tolower(lname[i]);
937                         c.s << lname;
938                         printseq(c, '(', ',', ')', exprseq::precedence(), function::precedence());
939
940                 } else if (is_a<print_latex>(c)) {
941                         c.s << opt.TeX_name;
942                         printseq(c, '(', ',', ')', exprseq::precedence(), function::precedence());
943                 } else {
944                         c.s << opt.name;
945                         printseq(c, '(', ',', ')', exprseq::precedence(), function::precedence());
946                 }
947
948         } else {
949
950                 // Method found, call it
951                 current_serial = serial;
952                 if (opt.print_use_exvector_args)
953                         ((print_funcp_exvector)pdt[id])(seq, c);
954                 else switch (opt.nparams) {
955                         // the following lines have been generated for max. ${maxargs} parameters
956 ${print_switch_statement}
957                         // end of generated lines
958                 default:
959                         throw(std::logic_error("function::print(): invalid nparams"));
960                 }
961         }
962 }
963
964 ex function::expand(unsigned options) const
965 {
966         // Only expand arguments when asked to do so
967         if (options & expand_options::expand_function_args)
968                 return inherited::expand(options);
969         else
970                 return (options == 0) ? setflag(status_flags::expanded) : *this;
971 }
972
973 ex function::eval(int level) const
974 {
975         if (level>1) {
976                 // first evaluate children, then we will end up here again
977                 return function(serial,evalchildren(level));
978         }
979
980         GINAC_ASSERT(serial<registered_functions().size());
981         const function_options &opt = registered_functions()[serial];
982
983         // Canonicalize argument order according to the symmetry properties
984         if (seq.size() > 1 && !(opt.symtree.is_zero())) {
985                 exvector v = seq;
986                 GINAC_ASSERT(is_a<symmetry>(opt.symtree));
987                 int sig = canonicalize(v.begin(), ex_to<symmetry>(opt.symtree));
988                 if (sig != std::numeric_limits<int>::max()) {
989                         // Something has changed while sorting arguments, more evaluations later
990                         if (sig == 0)
991                                 return _ex0;
992                         return ex(sig) * thiscontainer(v);
993                 }
994         }
995
996         if (opt.eval_f==0) {
997                 return this->hold();
998         }
999
1000         bool use_remember = opt.use_remember;
1001         ex eval_result;
1002         if (use_remember && lookup_remember_table(eval_result)) {
1003                 return eval_result;
1004         }
1005         current_serial = serial;
1006         if (opt.eval_use_exvector_args)
1007                 eval_result = ((eval_funcp_exvector)(opt.eval_f))(seq);
1008         else
1009         switch (opt.nparams) {
1010                 // the following lines have been generated for max. ${maxargs} parameters
1011 ${eval_switch_statement}
1012                 // end of generated lines
1013         default:
1014                 throw(std::logic_error("function::eval(): invalid nparams"));
1015         }
1016         if (use_remember) {
1017                 store_remember_table(eval_result);
1018         }
1019         return eval_result;
1020 }
1021
1022 ex function::evalf(int level) const
1023 {
1024         GINAC_ASSERT(serial<registered_functions().size());
1025         const function_options &opt = registered_functions()[serial];
1026
1027         // Evaluate children first
1028         exvector eseq;
1029         if (level == 1 || !(opt.evalf_params_first))
1030                 eseq = seq;
1031         else if (level == -max_recursion_level)
1032                 throw(std::runtime_error("max recursion level reached"));
1033         else {
1034                 eseq.reserve(seq.size());
1035                 --level;
1036                 exvector::const_iterator it = seq.begin(), itend = seq.end();
1037                 while (it != itend) {
1038                         eseq.push_back(it->evalf(level));
1039                         ++it;
1040                 }
1041         }
1042
1043         if (opt.evalf_f==0) {
1044                 return function(serial,eseq).hold();
1045         }
1046         current_serial = serial;
1047         if (opt.evalf_use_exvector_args)
1048                 return ((evalf_funcp_exvector)(opt.evalf_f))(seq);
1049         switch (opt.nparams) {
1050                 // the following lines have been generated for max. ${maxargs} parameters
1051 ${evalf_switch_statement}
1052                 // end of generated lines
1053         }
1054         throw(std::logic_error("function::evalf(): invalid nparams"));
1055 }
1056
1057 /**
1058  *  This method is defined to be in line with behaviour of function::return_type()
1059  */
1060 ex function::eval_ncmul(const exvector & v) const
1061 {
1062         // If this function is called then the list of arguments is non-empty
1063         // and the first argument is non-commutative, see  function::return_type()
1064         return seq.begin()->eval_ncmul(v);
1065 }
1066
1067 unsigned function::calchash() const
1068 {
1069         unsigned v = golden_ratio_hash(golden_ratio_hash((p_int)tinfo()) ^ serial);
1070         for (size_t i=0; i<nops(); i++) {
1071                 v = rotate_left(v);
1072                 v ^= this->op(i).gethash();
1073         }
1074
1075         if (flags & status_flags::evaluated) {
1076                 setflag(status_flags::hash_calculated);
1077                 hashvalue = v;
1078         }
1079         return v;
1080 }
1081
1082 ex function::thiscontainer(const exvector & v) const
1083 {
1084         return function(serial, v);
1085 }
1086
1087 ex function::thiscontainer(std::auto_ptr<exvector> vp) const
1088 {
1089         return function(serial, vp);
1090 }
1091
1092 /** Implementation of ex::series for functions.
1093  *  \@see ex::series */
1094 ex function::series(const relational & r, int order, unsigned options) const
1095 {
1096         GINAC_ASSERT(serial<registered_functions().size());
1097         const function_options &opt = registered_functions()[serial];
1098
1099         if (opt.series_f==0) {
1100                 return basic::series(r, order);
1101         }
1102         ex res;
1103         current_serial = serial;
1104         if (opt.series_use_exvector_args) {
1105                 try {
1106                         res = ((series_funcp_exvector)(opt.series_f))(seq, r, order, options);
1107                 } catch (do_taylor) {
1108                         res = basic::series(r, order, options);
1109                 }
1110                 return res;
1111         }
1112         switch (opt.nparams) {
1113                 // the following lines have been generated for max. ${maxargs} parameters
1114 ${series_switch_statement}
1115                 // end of generated lines
1116         }
1117         throw(std::logic_error("function::series(): invalid nparams"));
1118 }
1119
1120 /** Implementation of ex::conjugate for functions. */
1121 ex function::conjugate() const
1122 {
1123         GINAC_ASSERT(serial<registered_functions().size());
1124         const function_options & opt = registered_functions()[serial];
1125
1126         if (opt.conjugate_f==0) {
1127                 return exprseq::conjugate();
1128         }
1129
1130         if (opt.conjugate_use_exvector_args) {
1131                 return ((conjugate_funcp_exvector)(opt.conjugate_f))(seq);
1132         }
1133
1134         switch (opt.nparams) {
1135                 // the following lines have been generated for max. ${maxargs} parameters
1136 ${conjugate_switch_statement}
1137                 // end of generated lines
1138         }
1139         throw(std::logic_error("function::conjugate(): invalid nparams"));
1140 }
1141
1142 /** Implementation of ex::real_part for functions. */
1143 ex function::real_part() const
1144 {
1145         GINAC_ASSERT(serial<registered_functions().size());
1146         const function_options & opt = registered_functions()[serial];
1147
1148         if (opt.real_part_f==0)
1149                 return basic::real_part();
1150
1151         if (opt.real_part_use_exvector_args)
1152                 return ((real_part_funcp_exvector)(opt.real_part_f))(seq);
1153
1154         switch (opt.nparams) {
1155                 // the following lines have been generated for max. ${maxargs} parameters
1156 ${real_part_switch_statement}
1157                 // end of generated lines
1158         }
1159         throw(std::logic_error("function::real_part(): invalid nparams"));
1160 }
1161
1162 /** Implementation of ex::imag_part for functions. */
1163 ex function::imag_part() const
1164 {
1165         GINAC_ASSERT(serial<registered_functions().size());
1166         const function_options & opt = registered_functions()[serial];
1167
1168         if (opt.imag_part_f==0)
1169                 return basic::imag_part();
1170
1171         if (opt.imag_part_use_exvector_args)
1172                 return ((imag_part_funcp_exvector)(opt.imag_part_f))(seq);
1173
1174         switch (opt.nparams) {
1175                 // the following lines have been generated for max. ${maxargs} parameters
1176 ${imag_part_switch_statement}
1177                 // end of generated lines
1178         }
1179         throw(std::logic_error("function::imag_part(): invalid nparams"));
1180 }
1181
1182 // protected
1183
1184 /** Implementation of ex::diff() for functions. It applies the chain rule,
1185  *  except for the Order term function.
1186  *  \@see ex::diff */
1187 ex function::derivative(const symbol & s) const
1188 {
1189         ex result;
1190
1191         if (serial == Order_SERIAL::serial) {
1192                 // Order Term function only differentiates the argument
1193                 return Order(seq[0].diff(s));
1194         } else {
1195                 // Chain rule
1196                 ex arg_diff;
1197                 size_t num = seq.size();
1198                 for (size_t i=0; i<num; i++) {
1199                         arg_diff = seq[i].diff(s);
1200                         // We apply the chain rule only when it makes sense.  This is not
1201                         // just for performance reasons but also to allow functions to
1202                         // throw when differentiated with respect to one of its arguments
1203                         // without running into trouble with our automatic full
1204                         // differentiation:
1205                         if (!arg_diff.is_zero())
1206                                 result += pderivative(i)*arg_diff;
1207                 }
1208         }
1209         return result;
1210 }
1211
1212 int function::compare_same_type(const basic & other) const
1213 {
1214         GINAC_ASSERT(is_a<function>(other));
1215         const function & o = static_cast<const function &>(other);
1216
1217         if (serial != o.serial)
1218                 return serial < o.serial ? -1 : 1;
1219         else
1220                 return exprseq::compare_same_type(o);
1221 }
1222
1223 bool function::is_equal_same_type(const basic & other) const
1224 {
1225         GINAC_ASSERT(is_a<function>(other));
1226         const function & o = static_cast<const function &>(other);
1227
1228         if (serial != o.serial)
1229                 return false;
1230         else
1231                 return exprseq::is_equal_same_type(o);
1232 }
1233
1234 bool function::match_same_type(const basic & other) const
1235 {
1236         GINAC_ASSERT(is_a<function>(other));
1237         const function & o = static_cast<const function &>(other);
1238
1239         return serial == o.serial;
1240 }
1241
1242 unsigned function::return_type() const
1243 {
1244         GINAC_ASSERT(serial<registered_functions().size());
1245         const function_options &opt = registered_functions()[serial];
1246
1247         if (opt.use_return_type) {
1248                 // Return type was explicitly specified
1249                 return opt.return_type;
1250         } else {
1251                 // Default behavior is to use the return type of the first
1252                 // argument. Thus, exp() of a matrix behaves like a matrix, etc.
1253                 if (seq.empty())
1254                         return return_types::commutative;
1255                 else
1256                         return seq.begin()->return_type();
1257         }
1258 }
1259
1260 tinfo_t function::return_type_tinfo() const
1261 {
1262         GINAC_ASSERT(serial<registered_functions().size());
1263         const function_options &opt = registered_functions()[serial];
1264
1265         if (opt.use_return_type) {
1266                 // Return type was explicitly specified
1267                 return opt.return_type_tinfo;
1268         } else {
1269                 // Default behavior is to use the return type of the first
1270                 // argument. Thus, exp() of a matrix behaves like a matrix, etc.
1271                 if (seq.empty())
1272                         return this;
1273                 else
1274                         return seq.begin()->return_type_tinfo();
1275         }
1276 }
1277
1278 //////////
1279 // new virtual functions which can be overridden by derived classes
1280 //////////
1281
1282 // none
1283
1284 //////////
1285 // non-virtual functions in this class
1286 //////////
1287
1288 // protected
1289
1290 ex function::pderivative(unsigned diff_param) const // partial differentiation
1291 {
1292         GINAC_ASSERT(serial<registered_functions().size());
1293         const function_options &opt = registered_functions()[serial];
1294         
1295         // No derivative defined? Then return abstract derivative object
1296         if (opt.derivative_f == NULL)
1297                 return fderivative(serial, diff_param, seq);
1298
1299         current_serial = serial;
1300         if (opt.derivative_use_exvector_args)
1301                 return ((derivative_funcp_exvector)(opt.derivative_f))(seq, diff_param);
1302         switch (opt.nparams) {
1303                 // the following lines have been generated for max. ${maxargs} parameters
1304 ${diff_switch_statement}
1305                 // end of generated lines
1306         }
1307         throw(std::logic_error("function::pderivative(): no diff function defined"));
1308 }
1309
1310 ex function::power(const ex & power_param) const // power of function
1311 {
1312         GINAC_ASSERT(serial<registered_functions().size());
1313         const function_options &opt = registered_functions()[serial];
1314         
1315         // No derivative defined? Then return abstract derivative object
1316         if (opt.power_f == NULL)
1317                 return (new power::power(*this, power_param))->setflag(status_flags::dynallocated |
1318                                                        status_flags::evaluated);
1319
1320         current_serial = serial;
1321         if (opt.power_use_exvector_args)
1322                 return ((power_funcp_exvector)(opt.power_f))(seq,  power_param);
1323         switch (opt.nparams) {
1324                 // the following lines have been generated for max. ${maxargs} parameters
1325 ${power_switch_statement}
1326                 // end of generated lines
1327         }
1328         throw(std::logic_error("function::power(): no power function defined"));
1329 }
1330
1331 std::vector<function_options> & function::registered_functions()
1332 {
1333         static std::vector<function_options> * rf = new std::vector<function_options>;
1334         return *rf;
1335 }
1336
1337 bool function::lookup_remember_table(ex & result) const
1338 {
1339         return remember_table::remember_tables()[this->serial].lookup_entry(*this,result);
1340 }
1341
1342 void function::store_remember_table(ex const & result) const
1343 {
1344         remember_table::remember_tables()[this->serial].add_entry(*this,result);
1345 }
1346
1347 // public
1348
1349 unsigned function::register_new(function_options const & opt)
1350 {
1351         size_t same_name = 0;
1352         for (size_t i=0; i<registered_functions().size(); ++i) {
1353                 if (registered_functions()[i].name==opt.name) {
1354                         ++same_name;
1355                 }
1356         }
1357         if (same_name>=opt.functions_with_same_name) {
1358                 // we do not throw an exception here because this code is
1359                 // usually executed before main(), so the exception could not
1360                 // caught anyhow
1361                 std::cerr << "WARNING: function name " << opt.name
1362                           << " already in use!" << std::endl;
1363         }
1364         registered_functions().push_back(opt);
1365         if (opt.use_remember) {
1366                 remember_table::remember_tables().
1367                         push_back(remember_table(opt.remember_size,
1368                                                  opt.remember_assoc_size,
1369                                                  opt.remember_strategy));
1370         } else {
1371                 remember_table::remember_tables().push_back(remember_table());
1372         }
1373         return registered_functions().size()-1;
1374 }
1375
1376 /** Find serial number of function by name and number of parameters.
1377  *  Throws exception if function was not found. */
1378 unsigned function::find_function(const std::string &name, unsigned nparams)
1379 {
1380         std::vector<function_options>::const_iterator i = function::registered_functions().begin(), end = function::registered_functions().end();
1381         unsigned serial = 0;
1382         while (i != end) {
1383                 if (i->get_name() == name && i->get_nparams() == nparams)
1384                         return serial;
1385                 ++i;
1386                 ++serial;
1387         }
1388         throw (std::runtime_error("no function '" + name + "' with " + ToString(nparams) + " parameters defined"));
1389 }
1390
1391 /** Return the print name of the function. */
1392 std::string function::get_name() const
1393 {
1394         GINAC_ASSERT(serial<registered_functions().size());
1395         return registered_functions()[serial].name;
1396 }
1397
1398 } // namespace GiNaC
1399
1400 END_OF_IMPLEMENTATION
1401
1402 print "Creating interface file function.h...";
1403 open OUT,">function.h" or die "cannot open function.h";
1404 print OUT $interface;
1405 close OUT;
1406 print "ok.\n";
1407
1408 print "Creating implementation file function.cpp...";
1409 open OUT,">function.cpp" or die "cannot open function.cpp";
1410 print OUT $implementation;
1411 close OUT;
1412 print "ok.\n";
1413
1414 print "done.\n";