]> 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 7ab2ef91cde6f0472b680426eca8fcfa616adde2..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>
 
@@ -509,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
@@ -565,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);
 }
@@ -573,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);
 }