]> www.ginac.de Git - ginac.git/commitdiff
Redone the way in which function serial numbers are stored. This allows for
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Wed, 16 Oct 2002 20:44:08 +0000 (20:44 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Wed, 16 Oct 2002 20:44:08 +0000 (20:44 +0000)
using namespace qualifiers in the is_ex_the_function() macro like this

  is_ex_the_function(e, GiNaC::sin);

and it also works with the (overloaded) zeta() and psi() functions.
Unfortunately, it's not possible to

  using GiNaC::sin;
  is_ex_the_function(e, sin);

and the is_the_function<> template is not useful outside the is_ex_the_function()
macro. Even renaming the 'sin_SERIAL' class to 'sin' (which doesn't seem to
work with gcc3) you would still have to write 'is_the_function<class sin>(e)'
instead of 'is_the_function<sin>(e)'. I currently see no better solution,
though...

ginac/function.pl
ginac/inifcns.cpp
ginac/inifcns.h
ginac/inifcns_gamma.cpp
ginac/inifcns_zeta.cpp

index 394f22345beef07a738e0fa7ef6363ca8a4f52af..76af1dc9cd045046fa574f0112e71d0d03edf7b5 100755 (executable)
@@ -39,10 +39,9 @@ sub generate {
 $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) \\
-extern const unsigned function_index_##NAME; \\
-template<${SEQ1}> \\
-inline const GiNaC::function NAME(${SEQ2}) { \\
-       return GiNaC::function(function_index_##NAME, ${SEQ3}); \\
+class NAME##_SERIAL { public: static unsigned serial; }; \\
+template<${SEQ1}> const GiNaC::function NAME(${SEQ2}) { \\
+       return GiNaC::function(NAME##_SERIAL::serial, ${SEQ3}); \\
 }
 
 END_OF_DECLARE_FUNCTION_MACRO
@@ -197,7 +196,7 @@ $declare_function_macro
 // end of generated lines
 
 #define REGISTER_FUNCTION(NAME,OPT) \\
-const unsigned function_index_##NAME= \\
+unsigned NAME##_SERIAL::serial = \\
        GiNaC::function::register_new(GiNaC::function_options(#NAME).OPT);
 
 namespace GiNaC {
@@ -364,8 +363,15 @@ template<> inline bool is_exactly_a<function>(const basic & obj)
        return obj.tinfo()==TINFO_function;
 }
 
-#define is_ex_the_function(OBJ, FUNCNAME) \\
-       (GiNaC::is_exactly_a<GiNaC::function>(OBJ) && GiNaC::ex_to<GiNaC::function>(OBJ).get_serial() == GiNaC::function_index_##FUNCNAME)
+template <typename T>
+inline bool is_the_function(const ex & x)
+{
+       return is_exactly_a<function>(x)
+           && ex_to<function>(x).get_serial() == T::serial;
+}
+
+// Check whether OBJ is the specified symbolic function.
+#define is_ex_the_function(OBJ, FUNCNAME) (GiNaC::is_the_function<FUNCNAME##_SERIAL>(OBJ))
 
 } // namespace GiNaC
 
@@ -861,7 +867,7 @@ ex function::derivative(const symbol & s) const
 {
        ex result;
 
-       if (serial == function_index_Order) {
+       if (serial == Order_SERIAL::serial) {
                // Order Term function only differentiates the argument
                return Order(seq[0].diff(s));
        } else {
index 761a9eac21660d80b0103aad4b31d67a7e08a62a..9739b286c33f4923fbb3619e7aad4063b18abe22 100644 (file)
@@ -515,7 +515,7 @@ ex lsolve(const ex &eqns, const ex &symbols, unsigned options)
 
 /* Force inclusion of functions from inifcns_gamma and inifcns_zeta
  * for static lib (so ginsh will see them). */
-unsigned force_include_tgamma = function_index_tgamma;
-unsigned force_include_zeta1 = function_index_zeta1;
+unsigned force_include_tgamma = tgamma_SERIAL::serial;
+unsigned force_include_zeta1 = zeta1_SERIAL::serial;
 
 } // namespace GiNaC
index 58b5fa9f5ded1f891150520ae405d4c0b924ff4f..accc7c70dc7d1f6c5ce3f81dd7f87e479fc1a449 100644 (file)
@@ -90,16 +90,21 @@ DECLARE_FUNCTION_1P(Li3)
 
 // overloading at work: we cannot use the macros here
 /** Riemann's Zeta-function. */
-extern const unsigned function_index_zeta1;
+class zeta1_SERIAL { public: static unsigned serial; };
 template<typename T1>
 inline function zeta(const T1 & p1) {
-       return function(function_index_zeta1, ex(p1));
+       return function(zeta1_SERIAL::serial, ex(p1));
 }
 /** Derivatives of Riemann's Zeta-function. */
-extern const unsigned function_index_zeta2;
+class zeta2_SERIAL { public: static unsigned serial; };
 template<typename T1, typename T2>
 inline function zeta(const T1 & p1, const T2 & p2) {
-       return function(function_index_zeta2, ex(p1), ex(p2));
+       return function(zeta2_SERIAL::serial, ex(p1), ex(p2));
+}
+class zeta_SERIAL;
+template<> inline bool is_the_function<class zeta_SERIAL>(const ex & x)
+{
+       return is_the_function<zeta1_SERIAL>(x) || is_the_function<zeta2_SERIAL>(x);
 }
 
 /** Gamma-function. */
@@ -111,16 +116,21 @@ DECLARE_FUNCTION_2P(beta)
 
 // overloading at work: we cannot use the macros here
 /** Psi-function (aka digamma-function). */
-extern const unsigned function_index_psi1;
+class psi1_SERIAL { public: static unsigned serial; };
 template<typename T1>
 inline function psi(const T1 & p1) {
-       return function(function_index_psi1, ex(p1));
+       return function(psi1_SERIAL::serial, ex(p1));
 }
 /** Derivatives of Psi-function (aka polygamma-functions). */
-extern const unsigned function_index_psi2;
+class psi2_SERIAL { public: static unsigned serial; };
 template<typename T1, typename T2>
 inline function psi(const T1 & p1, const T2 & p2) {
-       return function(function_index_psi2, ex(p1), ex(p2));
+       return function(psi2_SERIAL::serial, ex(p1), ex(p2));
+}
+class psi_SERIAL;
+template<> inline bool is_the_function<class psi_SERIAL>(const ex & x)
+{
+       return is_the_function<psi1_SERIAL>(x) || is_the_function<psi2_SERIAL>(x);
 }
        
 /** Factorial function. */
index d2e9a6b779917f24a287041433af3218d97329b6..14b9ae87b6ab67025bbae77d179305b6d4970fdc 100644 (file)
@@ -422,7 +422,7 @@ static ex psi1_series(const ex & arg,
        return (psi(arg+m+_ex1)-recur).series(rel, order, options);
 }
 
-const unsigned function_index_psi1 =
+unsigned psi1_SERIAL::serial =
        function::register_new(function_options("psi").
                               eval_func(psi1_eval).
                               evalf_func(psi1_evalf).
@@ -550,7 +550,7 @@ static ex psi2_series(const ex & n,
        return (psi(n, arg+m+_ex1)-recur).series(rel, order, options);
 }
 
-const unsigned function_index_psi2 =
+unsigned psi2_SERIAL::serial =
        function::register_new(function_options("psi").
                               eval_func(psi2_eval).
                               evalf_func(psi2_evalf).
index 45ab0c954591da48c995dc7b61b933f96edd374e..57b94127e8eab730b7140baed2005248db302814 100644 (file)
@@ -84,7 +84,7 @@ static ex zeta1_deriv(const ex & x, unsigned deriv_param)
        return zeta(_ex1, x);
 }
 
-const unsigned function_index_zeta1 =
+unsigned zeta1_SERIAL::serial =
        function::register_new(function_options("zeta").
                               eval_func(zeta1_eval).
                               evalf_func(zeta1_evalf).
@@ -119,7 +119,7 @@ static ex zeta2_deriv(const ex & n, const ex & x, unsigned deriv_param)
        return zeta(n+1,x);
 }
 
-const unsigned function_index_zeta2 =
+unsigned zeta2_SERIAL::serial =
        function::register_new(function_options("zeta").
                               eval_func(zeta2_eval).
                               derivative_func(zeta2_deriv).