X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Ffunction.pl;h=7a2f6a9d779b9e323052d601e9caffeb95fb3ac2;hp=102e324e51ed567d7e41ce419f09a1bb3a31adff;hb=f4f72212e7428c848c1a1771864c2f1b09f8962f;hpb=e57b40dfa44dd3fe56bb06090332b2f9bb7e2dc6 diff --git a/ginac/function.pl b/ginac/function.pl index 102e324e..7a2f6a9d 100755 --- a/ginac/function.pl +++ b/ginac/function.pl @@ -1,3 +1,23 @@ +# This perl script automatically generates function.h and function.cpp + +# function.pl options: \$maxargs=${maxargs} +# +# GiNaC Copyright (C) 1999-2005 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + $maxargs=14; sub generate_seq { @@ -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=< print_dispatch_table; @@ -319,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; @@ -372,6 +423,7 @@ public: ex series(const relational & r, int order, unsigned options = 0) const; ex thiscontainer(const exvector & v) const; ex thiscontainer(std::auto_ptr vp) const; + ex conjugate() const; protected: ex derivative(const symbol & s) const; bool is_equal_same_type(const basic & other) const; @@ -435,7 +487,7 @@ $implementation=< @@ -487,6 +539,13 @@ function_options::function_options(std::string const & n, std::string const & 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() { // nothing to clean up at the moment @@ -496,11 +555,12 @@ void function_options::initialize() { 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; @@ -529,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 @@ -545,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; @@ -926,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