-$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)=@_;
<<'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}); \\
}
'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 &','','');
$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",'','','');
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}:
}
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)
* 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
#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 {
typedef ex (* eval_funcp)();
typedef ex (* evalf_funcp)();
+typedef ex (* conjugate_funcp)();
typedef ex (* derivative_funcp)();
typedef ex (* series_funcp)();
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
// 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 &);
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);
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;
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;
ex series(const relational & r, int order, unsigned options = 0) const;
ex thiscontainer(const exvector & v) 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;
* 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
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()
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;
// 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
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;
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,