]> www.ginac.de Git - ginac.git/blobdiff - ginac/tensor.cpp
reactivated an epsilon-tensor simplification hack because of a user request
[ginac.git] / ginac / tensor.cpp
index f6379bd0b7d95bc3ce24ced1d525f7f42f512f19..fb2e596e60bfc38f0d1641d40b76faf71df10652 100644 (file)
@@ -3,7 +3,7 @@
  *  Implementation of GiNaC's special tensors. */
 
 /*
- *  GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2002 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
@@ -20,6 +20,7 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#include <iostream>
 #include <stdexcept>
 #include <vector>
 
@@ -34,7 +35,6 @@
 #include "print.h"
 #include "archive.h"
 #include "utils.h"
-#include "debugmsg.h"
 
 namespace GiNaC {
 
@@ -46,14 +46,9 @@ GINAC_IMPLEMENT_REGISTERED_CLASS(spinmetric, tensmetric)
 GINAC_IMPLEMENT_REGISTERED_CLASS(tensepsilon, tensor)
 
 //////////
-// default constructor, destructor, copy constructor assignment operator and helpers
+// default ctor, dtor, copy ctor, assignment operator and helpers
 //////////
 
-tensor::tensor(unsigned ti) : inherited(ti)
-{
-       debugmsg("tensor constructor from unsigned", LOGLEVEL_CONSTRUCT); \
-}
-
 DEFAULT_CTORS(tensor)
 DEFAULT_CTORS(tensdelta)
 DEFAULT_CTORS(tensmetric)
@@ -64,19 +59,16 @@ DEFAULT_DESTROY(tensepsilon)
 
 minkmetric::minkmetric() : pos_sig(false)
 {
-       debugmsg("minkmetric default constructor", LOGLEVEL_CONSTRUCT);
        tinfo_key = TINFO_minkmetric;
 }
 
 spinmetric::spinmetric()
 {
-       debugmsg("spinmetric default constructor", LOGLEVEL_CONSTRUCT);
        tinfo_key = TINFO_spinmetric;
 }
 
 minkmetric::minkmetric(bool ps) : pos_sig(ps)
 {
-       debugmsg("minkmetric constructor from bool", LOGLEVEL_CONSTRUCT);
        tinfo_key = TINFO_minkmetric;
 }
 
@@ -88,13 +80,11 @@ void minkmetric::copy(const minkmetric & other)
 
 tensepsilon::tensepsilon() : minkowski(false), pos_sig(false)
 {
-       debugmsg("tensepsilon default constructor", LOGLEVEL_CONSTRUCT);
        tinfo_key = TINFO_tensepsilon;
 }
 
 tensepsilon::tensepsilon(bool mink, bool ps) : minkowski(mink), pos_sig(ps)
 {
-       debugmsg("tensepsilon constructor from bool,bool", LOGLEVEL_CONSTRUCT);
        tinfo_key = TINFO_tensepsilon;
 }
 
@@ -118,7 +108,6 @@ DEFAULT_UNARCHIVE(tensepsilon)
 
 minkmetric::minkmetric(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
 {
-       debugmsg("minkmetric constructor from archive_node", LOGLEVEL_CONSTRUCT);
        n.find_bool("pos_sig", pos_sig);
 }
 
@@ -130,7 +119,6 @@ void minkmetric::archive(archive_node &n) const
 
 tensepsilon::tensepsilon(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
 {
-       debugmsg("tensepsilon constructor from archive_node", LOGLEVEL_CONSTRUCT);
        n.find_bool("minkowski", minkowski);
        n.find_bool("pos_sig", pos_sig);
 }
@@ -522,10 +510,14 @@ bool tensepsilon::contract_with(exvector::iterator self, exvector::iterator othe
 
        } else if (other->return_type() == return_types::commutative) {
 
-#if 0
-               // This handles eps.i.j.k * p.j * p.k = 0
-               // Maybe something like this should go to simplify_indexed() because
-               // such relations are true for any antisymmetric tensors...
+#if 1
+               // This handles eps.i.j.k * p.j * p.k = 0 and related cases.
+               // Actually, simplify_indexed() can handle most of them on its own
+               // but one specific case that is not covered there is
+               //   eps~mu.nu~i~j * p.mu * p~nu
+               // because of the difference in variance in the dummy indices mu
+               // and nu. Eventually, simplify_indexed() should be extended to
+               // handle this case, and this hack removed.
                exvector c;
 
                // Handle all indices of the epsilon tensor
@@ -578,6 +570,9 @@ ex metric_tensor(const ex & i1, const ex & i2)
 {
        if (!is_ex_of_type(i1, varidx) || !is_ex_of_type(i2, varidx))
                throw(std::invalid_argument("indices of metric tensor must be of type varidx"));
+       ex dim = ex_to<idx>(i1).get_dim();
+       if (!dim.is_equal(ex_to<idx>(i2).get_dim()))
+               throw(std::invalid_argument("all indices of metric tensor must have the same dimension"));
 
        return indexed(tensmetric(), sy_symm(), i1, i2);
 }
@@ -586,6 +581,9 @@ ex lorentz_g(const ex & i1, const ex & i2, bool pos_sig)
 {
        if (!is_ex_of_type(i1, varidx) || !is_ex_of_type(i2, varidx))
                throw(std::invalid_argument("indices of metric tensor must be of type varidx"));
+       ex dim = ex_to<idx>(i1).get_dim();
+       if (!dim.is_equal(ex_to<idx>(i2).get_dim()))
+               throw(std::invalid_argument("all indices of metric tensor must have the same dimension"));
 
        return indexed(minkmetric(pos_sig), sy_symm(), i1, i2);
 }