#include "relational.h"
#include "lst.h"
#include "numeric.h"
+#include "matrix.h"
#include "print.h"
#include "archive.h"
#include "utils.h"
}
//////////
-// functions overriding virtual functions from bases classes
+// functions overriding virtual functions from base classes
//////////
DEFAULT_COMPARE(tensor)
again:
if (self_idx->is_symbolic()) {
- for (int i=1; i<other->nops(); i++) {
+ for (unsigned i=1; i<other->nops(); i++) {
const idx &other_idx = ex_to<idx>(other->op(i));
if (is_dummy_pair(*self_idx, other_idx)) {
again:
if (self_idx->is_symbolic()) {
- for (int i=1; i<other->nops(); i++) {
+ for (unsigned i=1; i<other->nops(); i++) {
const idx &other_idx = ex_to<idx>(other->op(i));
if (is_dummy_pair(*self_idx, other_idx)) {
again:
if (self_idx->is_symbolic()) {
- for (int i=1; i<other->nops(); i++) {
+ for (unsigned i=1; i<other->nops(); i++) {
const idx &other_idx = ex_to<idx>(other->op(i));
if (is_dummy_pair(*self_idx, other_idx)) {
return false;
}
+/** Contraction of epsilon tensor with something else. */
+bool tensepsilon::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const
+{
+ GINAC_ASSERT(is_ex_of_type(*self, indexed));
+ GINAC_ASSERT(is_ex_of_type(*other, indexed));
+ GINAC_ASSERT(is_ex_of_type(self->op(0), tensepsilon));
+ unsigned num = self->nops() - 1;
+
+ if (is_ex_exactly_of_type(other->op(0), tensepsilon) && num+1 == other->nops()) {
+
+ // Contraction of two epsilon tensors is a determinant
+ ex dim = ex_to<idx>(self->op(1)).get_dim();
+ matrix M(num, num);
+ for (int i=0; i<num; i++) {
+ for (int j=0; j<num; j++) {
+ if (minkowski)
+ M(i, j) = lorentz_g(self->op(i+1), other->op(j+1), pos_sig);
+ else
+ M(i, j) = metric_tensor(self->op(i+1), other->op(j+1));
+ }
+ }
+ int sign = minkowski ? -1 : 1;
+ *self = sign * M.determinant().simplify_indexed();
+ *other = _ex1();
+ return true;
+
+ } 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...
+ exvector c;
+
+ // Handle all indices of the epsilon tensor
+ for (int i=0; i<num; i++) {
+ ex idx = self->op(i+1);
+
+ // Look whether there's a contraction with this index
+ exvector::const_iterator ait, aitend = v.end();
+ for (ait = v.begin(); ait != aitend; ait++) {
+ if (ait == self)
+ continue;
+ if (is_a<indexed>(*ait) && ait->return_type() == return_types::commutative && ex_to<indexed>(*ait).has_dummy_index_for(idx) && ait->nops() == 2) {
+
+ // Yes, did we already have another contraction with the same base expression?
+ ex base = ait->op(0);
+ if (std::find_if(c.begin(), c.end(), bind2nd(ex_is_equal(), base)) == c.end()) {
+
+ // No, add the base expression to the list
+ c.push_back(base);
+
+ } else {
+
+ // Yes, the contraction is zero
+ *self = _ex0();
+ *other = _ex0();
+ return true;
+ }
+ }
+ }
+ }
+#endif
+ }
+
+ return false;
+}
+
//////////
// global functions
//////////