X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Ftensor.cpp;h=c14b50d74499642752135ee25a602616284ff8dd;hp=0e6b116250e69281283c012650dc674253c2ff97;hb=d9927cf4bc27d542d5f6487d31f5d43dc2e39af7;hpb=fd097c33e414f72c77376ae7ad4fbd630b3ccce6 diff --git a/ginac/tensor.cpp b/ginac/tensor.cpp index 0e6b1162..c14b50d7 100644 --- a/ginac/tensor.cpp +++ b/ginac/tensor.cpp @@ -27,7 +27,9 @@ #include "idx.h" #include "indexed.h" #include "relational.h" +#include "lst.h" #include "numeric.h" +#include "print.h" #include "archive.h" #include "utils.h" #include "debugmsg.h" @@ -44,24 +46,6 @@ GINAC_IMPLEMENT_REGISTERED_CLASS(tensepsilon, tensor) // default constructor, destructor, copy constructor assignment operator and helpers ////////// -#define DEFAULT_DESTROY(classname) \ -void classname::destroy(bool call_parent) \ -{ \ - if (call_parent) \ - inherited::destroy(call_parent); \ -} - -#define DEFAULT_CTORS(classname) \ -classname::classname() : inherited(TINFO_##classname) \ -{ \ - debugmsg(#classname " default constructor", LOGLEVEL_CONSTRUCT); \ -} \ -void classname::copy(const classname & other) \ -{ \ - inherited::copy(other); \ -} \ -DEFAULT_DESTROY(classname) - tensor::tensor(unsigned ti) : inherited(ti) { debugmsg("tensor constructor from unsigned", LOGLEVEL_CONSTRUCT); \ @@ -114,23 +98,6 @@ void tensepsilon::copy(const tensepsilon & other) // archiving ////////// -#define DEFAULT_UNARCHIVE(classname) \ -ex classname::unarchive(const archive_node &n, const lst &sym_lst) \ -{ \ - return (new classname(n, sym_lst))->setflag(status_flags::dynallocated); \ -} - -#define DEFAULT_ARCHIVING(classname) \ -classname::classname(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst) \ -{ \ - debugmsg(#classname " constructor from archive_node", LOGLEVEL_CONSTRUCT); \ -} \ -DEFAULT_UNARCHIVE(classname) \ -void classname::archive(archive_node &n) const \ -{ \ - inherited::archive(n); \ -} - DEFAULT_ARCHIVING(tensor) DEFAULT_ARCHIVING(tensdelta) DEFAULT_ARCHIVING(tensmetric) @@ -167,13 +134,6 @@ void tensepsilon::archive(archive_node &n) const // functions overriding virtual functions from bases classes ////////// -#define DEFAULT_COMPARE(classname) \ -int classname::compare_same_type(const basic & other) const \ -{ \ - /* by default, two tensors of the same class are always identical */ \ - return 0; \ -} - DEFAULT_COMPARE(tensor) DEFAULT_COMPARE(tensdelta) DEFAULT_COMPARE(tensmetric) @@ -202,29 +162,10 @@ int tensepsilon::compare_same_type(const basic & other) const return inherited::compare_same_type(other); } -void tensdelta::print(std::ostream & os, unsigned upper_precedence) const -{ - debugmsg("tensdelta print",LOGLEVEL_PRINT); - os << "delta"; -} - -void tensmetric::print(std::ostream & os, unsigned upper_precedence) const -{ - debugmsg("tensmetric print",LOGLEVEL_PRINT); - os << "g"; -} - -void minkmetric::print(std::ostream & os, unsigned upper_precedence) const -{ - debugmsg("minkmetric print",LOGLEVEL_PRINT); - os << "eta"; -} - -void tensepsilon::print(std::ostream & os, unsigned upper_precedence) const -{ - debugmsg("tensepsilon print",LOGLEVEL_PRINT); - os << "eps"; -} +DEFAULT_PRINT(tensdelta, "delta") +DEFAULT_PRINT(tensmetric, "g") +DEFAULT_PRINT(minkmetric, "eta") +DEFAULT_PRINT(tensepsilon, "eps") /** Automatic symbolic evaluation of an indexed delta tensor. */ ex tensdelta::eval_indexed(const basic & i) const @@ -240,6 +181,15 @@ ex tensdelta::eval_indexed(const basic & i) const if (is_dummy_pair(i1, i2)) return i1.get_dim(); + // Numeric evaluation + if (static_cast(i).all_index_values_are(info_flags::integer)) { + int n1 = ex_to_numeric(i1.get_value()).to_int(), n2 = ex_to_numeric(i2.get_value()).to_int(); + if (n1 == n2) + return _ex1(); + else + return _ex0(); + } + // No further simplifications return i.hold(); } @@ -385,7 +335,7 @@ bool tensmetric::contract_with(exvector::iterator self, exvector::iterator other // If contracting with the delta tensor, let the delta do it // (don't raise/lower delta indices) - if (is_ex_exactly_of_type(other->op(0), tensdelta)) + if (is_ex_of_type(other->op(0), tensdelta)) return false; // Try to contract first index