#include "ginac/ginac.h" using namespace std; // declare and register (non-commutative) two-argument function TA(...) DECLARE_FUNCTION_2P(TA) static GiNaC::ex TA_eval(const GiNaC::ex& p, const GiNaC::ex& d) { return dirac_slash(p, d); } GiNaC::return_type_t my_type = GiNaC::make_return_type_t (); REGISTER_FUNCTION(TA, eval_func(TA_eval).set_return_type(GiNaC::return_types::noncommutative, &my_type)) // declare and register one argument function OA(...) DECLARE_FUNCTION_1P(OA) REGISTER_FUNCTION(OA, dummy()) // declare and register zero argument function ZA() (this should probably no be done) class ZA_SERIAL { public: static unsigned serial; }; const unsigned ZA_NPARAMS = 0; template const GiNaC::function ZA() { return GiNaC::function(ZA_SERIAL::serial); } static GiNaC::ex ZA_eval(const GiNaC::ex& dummy = 0) { // empty argument not accepted return 1; } unsigned ZA_SERIAL::serial = GiNaC::function::register_new( GiNaC::function_options("ZA", ZA_NPARAMS).eval_func(ZA_eval)); int main() { using namespace GiNaC; symbol p1("p1"), p2("p2"), d("d"); // bug: parsed product does not respect non-commutativity ex dirac1("TA(p1,d) * TA(p2,d)", lst(p1,p2,d)); ex dirac2("TA(p2,d) * TA(p1,d)", lst(p1,p2,d)); cout << dirac1 << endl; cout << dirac2 << endl; cout << dirac1 - dirac2 << endl << endl; // bug: parser accepts zero and one argument ex z0("ZA()", lst()); cout << "ZA(): " << z0 << endl; ex z1("ZA(2)", lst()); cout << "ZA(2): " << z1 << endl << endl; // bug: parser accepts zero arguments ex a("OA()", lst()); cout << "OA(): " << a << endl; return 0; }