]> www.ginac.de Git - ginac.git/blobdiff - ginac/function.pl
Synced to HEAD
[ginac.git] / ginac / function.pl
index 7e5d0dac0307ca6db6dbe4427a0461bc9bfb5871..318e46c19bda4143f4f77908f19928de6cbdf203 100755 (executable)
@@ -1,4 +1,24 @@
-$maxargs=13;
+#  This perl script automatically generates function.h and function.cpp
+
+#  function.pl options: \$maxargs=${maxargs}
+# 
+#  GiNaC Copyright (C) 1999-2004 Johannes Gutenberg University Mainz, Germany
+# 
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+# 
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+# 
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+$maxargs=14;
 
 sub generate_seq {
        my ($seq_template,$n)=@_;
@@ -40,6 +60,7 @@ $declare_function_macro = generate(
        <<'END_OF_DECLARE_FUNCTION_MACRO','typename T${N}','const T${N} & p${N}','GiNaC::ex(p${N})');
 #define DECLARE_FUNCTION_${N}P(NAME) \\
 class NAME##_SERIAL { public: static unsigned serial; }; \\
+const unsigned NAME##_NPARAMS = ${N}; \\
 template<${SEQ1}> const GiNaC::function NAME(${SEQ2}) { \\
        return GiNaC::function(NAME##_SERIAL::serial, ${SEQ3}); \\
 }
@@ -54,6 +75,10 @@ $typedef_evalf_funcp=generate(
 'typedef ex (* evalf_funcp_${N})(${SEQ1});'."\n",
 'const ex &','','');
 
+$typedef_conjugate_funcp=generate(
+'typedef ex (* conjugate_funcp_${N})(${SEQ1});'."\n",
+'const ex &','','');
+
 $typedef_derivative_funcp=generate(
 'typedef ex (* derivative_funcp_${N})(${SEQ1}, unsigned);'."\n",
 'const ex &','','');
@@ -70,6 +95,8 @@ $eval_func_interface=generate('    function_options & eval_func(eval_funcp_${N}
 
 $evalf_func_interface=generate('    function_options & evalf_func(evalf_funcp_${N} ef);'."\n",'','','');
 
+$conjugate_func_interface=generate('    function_options & conjugate_func(conjugate_funcp_${N} d);'."\n",'','','');
+
 $derivative_func_interface=generate('    function_options & derivative_func(derivative_funcp_${N} d);'."\n",'','','');
 
 $series_func_interface=generate('    function_options & series_func(series_funcp_${N} s);'."\n",'','','');
@@ -110,6 +137,12 @@ $evalf_switch_statement=generate(
                return ((evalf_funcp_${N})(opt.evalf_f))(${SEQ1});
 END_OF_EVALF_SWITCH_STATEMENT
 
+$conjugate_switch_statement=generate(
+       <<'END_OF_DIFF_SWITCH_STATEMENT','seq[${N}-1]','','');
+       case ${N}:
+               return ((conjugate_funcp_${N})(opt.conjugate_f))(${SEQ1});
+END_OF_DIFF_SWITCH_STATEMENT
+
 $diff_switch_statement=generate(
        <<'END_OF_DIFF_SWITCH_STATEMENT','seq[${N}-1]','','');
        case ${N}:
@@ -154,6 +187,16 @@ function_options & function_options::evalf_func(evalf_funcp_${N} ef)
 }
 END_OF_EVALF_FUNC_IMPLEMENTATION
 
+$conjugate_func_implementation=generate(
+       <<'END_OF_CONJUGATE_FUNC_IMPLEMENTATION','','','');
+function_options & function_options::conjugate_func(conjugate_funcp_${N} c)
+{
+       test_and_set_nparams(${N});
+       conjugate_f = conjugate_funcp(c);
+       return *this;
+}
+END_OF_CONJUGATE_FUNC_IMPLEMENTATION
+
 $derivative_func_implementation=generate(
        <<'END_OF_DERIVATIVE_FUNC_IMPLEMENTATION','','','');
 function_options & function_options::derivative_func(derivative_funcp_${N} d)
@@ -184,7 +227,7 @@ $interface=<<END_OF_INTERFACE;
  *  Please do not modify it directly, edit the perl script instead!
  *  function.pl options: \$maxargs=${maxargs}
  *
- *  GiNaC Copyright (C) 1999-2003 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2004 Johannes Gutenberg University Mainz, Germany
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -218,7 +261,7 @@ $declare_function_macro
 
 #define REGISTER_FUNCTION(NAME,OPT) \\
 unsigned NAME##_SERIAL::serial = \\
-       GiNaC::function::register_new(GiNaC::function_options(#NAME).OPT);
+       GiNaC::function::register_new(GiNaC::function_options(#NAME, NAME##_NPARAMS).OPT);
 
 namespace GiNaC {
 
@@ -227,6 +270,7 @@ class symmetry;
 
 typedef ex (* eval_funcp)();
 typedef ex (* evalf_funcp)();
+typedef ex (* conjugate_funcp)();
 typedef ex (* derivative_funcp)();
 typedef ex (* series_funcp)();
 typedef void (* print_funcp)();
@@ -234,6 +278,7 @@ typedef void (* print_funcp)();
 // the following lines have been generated for max. ${maxargs} parameters
 $typedef_eval_funcp
 $typedef_evalf_funcp
+$typedef_conjugate_funcp
 $typedef_derivative_funcp
 $typedef_series_funcp
 $typedef_print_funcp
@@ -243,6 +288,7 @@ $typedef_print_funcp
 // of individual ex objects.  Then, the number of arguments is not limited.
 typedef ex (* eval_funcp_exvector)(const exvector &);
 typedef ex (* evalf_funcp_exvector)(const exvector &);
+typedef ex (* conjugate_funcp_exvector)(const exvector &);
 typedef ex (* derivative_funcp_exvector)(const exvector &, unsigned);
 typedef ex (* series_funcp_exvector)(const exvector &, const relational &, int, unsigned);
 typedef void (* print_funcp_exvector)(const exvector &, const print_context &);
@@ -255,19 +301,24 @@ class function_options
 public:
        function_options();
        function_options(std::string const & n, std::string const & tn=std::string());
+       function_options(std::string const & n, unsigned np);
        ~function_options();
        void initialize();
+
+       function_options & dummy() { return *this; }
        function_options & set_name(std::string const & n, std::string const & tn=std::string());
        function_options & latex_name(std::string const & tn);
 // the following lines have been generated for max. ${maxargs} parameters
 $eval_func_interface
 $evalf_func_interface
+$conjugate_func_interface
 $derivative_func_interface
 $series_func_interface
 $print_func_interface
 // end of generated lines
        function_options & eval_func(eval_funcp_exvector e);
        function_options & evalf_func(evalf_funcp_exvector ef);
+       function_options & conjugate_func(conjugate_funcp_exvector d);
        function_options & derivative_func(derivative_funcp_exvector d);
        function_options & series_func(series_funcp_exvector s);
 
@@ -300,6 +351,7 @@ protected:
 
        eval_funcp eval_f;
        evalf_funcp evalf_f;
+       conjugate_funcp conjugate_f;
        derivative_funcp derivative_f;
        series_funcp series_f;
        std::vector<print_funcp> print_dispatch_table;
@@ -317,6 +369,7 @@ protected:
 
        bool eval_use_exvector_args;
        bool evalf_use_exvector_args;
+       bool conjugate_use_exvector_args;
        bool derivative_use_exvector_args;
        bool series_use_exvector_args;
        bool print_use_exvector_args;
@@ -357,7 +410,7 @@ $constructors_interface
        // end of generated lines
        function(unsigned ser, const exprseq & es);
        function(unsigned ser, const exvector & v, bool discardable = false);
-       function(unsigned ser, exvector * vp); // vp will be deleted
+       function(unsigned ser, std::auto_ptr<exvector> vp);
 
        // functions overriding virtual functions from base classes
 public:
@@ -369,7 +422,8 @@ public:
        unsigned calchash() const;
        ex series(const relational & r, int order, unsigned options = 0) const;
        ex thiscontainer(const exvector & v) const;
-       ex thiscontainer(exvector * vp) const;
+       ex thiscontainer(std::auto_ptr<exvector> vp) const;
+       ex conjugate() const;
 protected:
        ex derivative(const symbol & s) const;
        bool is_equal_same_type(const basic & other) const;
@@ -433,7 +487,7 @@ $implementation=<<END_OF_IMPLEMENTATION;
  *  Please do not modify it directly, edit the perl script instead!
  *  function.pl options: \$maxargs=${maxargs}
  *
- *  GiNaC Copyright (C) 1999-2003 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2004 Johannes Gutenberg University Mainz, Germany
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -482,7 +536,14 @@ function_options::function_options()
 function_options::function_options(std::string const & n, std::string const & tn)
 {
        initialize();
-       set_name(n,tn);
+       set_name(n, tn);
+}
+
+function_options::function_options(std::string const & n, unsigned np)
+{
+       initialize();
+       set_name(n, std::string());
+       nparams = np;
 }
 
 function_options::~function_options()
@@ -492,13 +553,14 @@ function_options::~function_options()
 
 void function_options::initialize()
 {
-       set_name("unnamed_function","\\\\mbox{unnamed}");
+       set_name("unnamed_function", "\\\\mbox{unnamed}");
        nparams = 0;
-       eval_f = evalf_f = derivative_f = series_f = 0;
+       eval_f = evalf_f = conjugate_f = derivative_f = series_f = 0;
        evalf_params_first = true;
        use_return_type = false;
        eval_use_exvector_args = false;
        evalf_use_exvector_args = false;
+       conjugate_use_exvector_args = false;
        derivative_use_exvector_args = false;
        series_use_exvector_args = false;
        print_use_exvector_args = false;
@@ -527,6 +589,7 @@ function_options & function_options::latex_name(std::string const & tn)
 // the following lines have been generated for max. ${maxargs} parameters
 $eval_func_implementation
 $evalf_func_implementation
+$conjugate_func_implementation
 $derivative_func_implementation
 $series_func_implementation
 // end of generated lines
@@ -543,6 +606,12 @@ function_options& function_options::evalf_func(evalf_funcp_exvector ef)
        evalf_f = evalf_funcp(ef);
        return *this;
 }
+function_options& function_options::conjugate_func(conjugate_funcp_exvector c)
+{
+       conjugate_use_exvector_args = true;
+       conjugate_f = conjugate_funcp(c);
+       return *this;
+}
 function_options& function_options::derivative_func(derivative_funcp_exvector d)
 {
        derivative_use_exvector_args = true;
@@ -661,7 +730,7 @@ function::function(unsigned ser, const exvector & v, bool discardable)
        tinfo_key = TINFO_function;
 }
 
-function::function(unsigned ser, exvector * vp) 
+function::function(unsigned ser, std::auto_ptr<exvector> vp) 
   : exprseq(vp), serial(ser)
 {
        tinfo_key = TINFO_function;
@@ -888,12 +957,12 @@ unsigned function::calchash() const
 
 ex function::thiscontainer(const exvector & v) const
 {
-       return function(serial,v);
+       return function(serial, v);
 }
 
-ex function::thiscontainer(exvector * vp) const
+ex function::thiscontainer(std::auto_ptr<exvector> vp) const
 {
-       return function(serial,vp);
+       return function(serial, vp);
 }
 
 /** Implementation of ex::series for functions.
@@ -924,6 +993,28 @@ ${series_switch_statement}
        throw(std::logic_error("function::series(): invalid nparams"));
 }
 
+/** Implementation of ex::conjugate for functions. */
+ex function::conjugate() const
+{
+       GINAC_ASSERT(serial<registered_functions().size());
+       const function_options & opt = registered_functions()[serial];
+
+       if (opt.conjugate_f==0) {
+               return exprseq::conjugate();
+       }
+
+       if (opt.conjugate_use_exvector_args) {
+               return ((conjugate_funcp_exvector)(opt.conjugate_f))(seq);
+       }
+
+       switch (opt.nparams) {
+               // the following lines have been generated for max. ${maxargs} parameters
+${conjugate_switch_statement}
+               // end of generated lines
+       }
+       throw(std::logic_error("function::conjugate(): invalid nparams"));
+}
+
 // protected
 
 /** Implementation of ex::diff() for functions. It applies the chain rule,