From ea8b6162525d343d05921433c2681e8960d7e678 Mon Sep 17 00:00:00 2001 From: Christian Bauer Date: Mon, 8 Jul 2002 21:07:33 +0000 Subject: [PATCH] moved even more duplicated code to the 'tensor' class --- ginac/tensor.cpp | 128 ++++++++++------------------------------------- ginac/tensor.h | 7 +++ 2 files changed, 34 insertions(+), 101 deletions(-) diff --git a/ginac/tensor.cpp b/ginac/tensor.cpp index b71f6b03..a4ae63e0 100644 --- a/ginac/tensor.cpp +++ b/ginac/tensor.cpp @@ -443,15 +443,9 @@ ex tensepsilon::eval_indexed(const basic & i) const return i.hold(); } -/** Contraction of an indexed delta tensor with something else. */ -bool tensdelta::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const +bool tensor::replace_contr_index(exvector::iterator self, exvector::iterator other) const { - GINAC_ASSERT(is_a(*self)); - GINAC_ASSERT(is_a(*other)); - GINAC_ASSERT(self->nops() == 3); - GINAC_ASSERT(is_a(self->op(0))); - - // Try to contract first index + // Try to contract the first index const idx *self_idx = &ex_to(self->op(1)); const idx *free_idx = &ex_to(self->op(2)); bool first_index_tried = false; @@ -462,8 +456,8 @@ again: const idx &other_idx = ex_to(other->op(i)); if (is_dummy_pair(*self_idx, other_idx)) { - // Contraction found, remove delta tensor and substitute - // index in second object + // Contraction found, remove this tensor and substitute the + // index in the second object *self = _ex1; *other = other->subs(other_idx == *free_idx); return true; @@ -473,7 +467,7 @@ again: if (!first_index_tried) { - // No contraction with first index found, try second index + // No contraction with the first index found, try the second index self_idx = &ex_to(self->op(2)); free_idx = &ex_to(self->op(1)); first_index_tried = true; @@ -483,6 +477,19 @@ again: return false; } +/** Contraction of an indexed delta tensor with something else. */ +bool tensdelta::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const +{ + GINAC_ASSERT(is_a(*self)); + GINAC_ASSERT(is_a(*other)); + GINAC_ASSERT(self->nops() == 3); + GINAC_ASSERT(is_a(self->op(0))); + + // Replace the dummy index with this tensor's other index and remove + // the tensor (this is valid for contractions with all other tensors) + return replace_contr_index(self, other); +} + /** Contraction of an indexed 4-dimensional delta tensor with something else. */ bool tens4delta::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const { @@ -495,36 +502,9 @@ bool tens4delta::contract_with(exvector::iterator self, exvector::iterator other if (!(is_a(other->op(0)) || is_a(other->op(0)) || is_a(other->op(0)))) return false; - // Try to contract first index - const idx *self_idx = &ex_to(self->op(1)); - const idx *free_idx = &ex_to(self->op(2)); - bool first_index_tried = false; - -again: - if (self_idx->is_symbolic()) { - for (unsigned i=1; inops(); i++) { - const idx &other_idx = ex_to(other->op(i)); - if (is_dummy_pair(*self_idx, other_idx)) { - - // Contraction found, remove delta tensor and substitute - // index in second object - *self = _ex1; - *other = other->subs(other_idx == *free_idx); - return true; - } - } - } - - if (!first_index_tried) { - - // No contraction with first index found, try second index - self_idx = &ex_to(self->op(2)); - free_idx = &ex_to(self->op(1)); - first_index_tried = true; - goto again; - } - - return false; + // Replace the dummy index with this tensor's other index and remove + // the tensor + return replace_contr_index(self, other); } /** Contraction of an indexed metric tensor with something else. */ @@ -540,36 +520,9 @@ bool tensmetric::contract_with(exvector::iterator self, exvector::iterator other if (is_a(other->op(0))) return false; - // Try to contract first index - const idx *self_idx = &ex_to(self->op(1)); - const idx *free_idx = &ex_to(self->op(2)); - bool first_index_tried = false; - -again: - if (self_idx->is_symbolic()) { - for (unsigned i=1; inops(); i++) { - const idx &other_idx = ex_to(other->op(i)); - if (is_dummy_pair(*self_idx, other_idx)) { - - // Contraction found, remove metric tensor and substitute - // index in second object - *self = _ex1; - *other = other->subs(other_idx == *free_idx); - return true; - } - } - } - - if (!first_index_tried) { - - // No contraction with first index found, try second index - self_idx = &ex_to(self->op(2)); - free_idx = &ex_to(self->op(1)); - first_index_tried = true; - goto again; - } - - return false; + // Replace the dummy index with this tensor's other index and remove + // the tensor + return replace_contr_index(self, other); } /** Contraction of an indexed 4-dimensional Lorentz metric tensor with something else. */ @@ -584,36 +537,9 @@ bool mink4metric::contract_with(exvector::iterator self, exvector::iterator othe if (!(is_a(other->op(0)) || is_a(other->op(0)))) return false; - // Try to contract first index - const idx *self_idx = &ex_to(self->op(1)); - const idx *free_idx = &ex_to(self->op(2)); - bool first_index_tried = false; - -again: - if (self_idx->is_symbolic()) { - for (unsigned i=1; inops(); i++) { - const idx &other_idx = ex_to(other->op(i)); - if (is_dummy_pair(*self_idx, other_idx)) { - - // Contraction found, remove metric tensor and substitute - // index in second object - *self = _ex1; - *other = other->subs(other_idx == *free_idx); - return true; - } - } - } - - if (!first_index_tried) { - - // No contraction with first index found, try second index - self_idx = &ex_to(self->op(2)); - free_idx = &ex_to(self->op(1)); - first_index_tried = true; - goto again; - } - - return false; + // Replace the dummy index with this tensor's other index and remove + // the tensor + return replace_contr_index(self, other); } diff --git a/ginac/tensor.h b/ginac/tensor.h index d3b3a136..2fa8e661 100644 --- a/ginac/tensor.h +++ b/ginac/tensor.h @@ -42,6 +42,13 @@ protected: // functions overriding virtual functions from base classes protected: unsigned return_type(void) const { return return_types::noncommutative_composite; } + + // non-virtual functions in this class +public: + /** Replace dummy index in contracted-with object by the contracting + * object's second index (used internally for delta and metric tensor + * contractions. */ + bool replace_contr_index(exvector::iterator self, exvector::iterator other) const; }; -- 2.49.0