From: Christian Bauer Date: Tue, 21 Jan 2003 23:06:28 +0000 (+0000) Subject: added missing minimal_dim() from 1.1 branch X-Git-Tag: release_1-0-13~5 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=dc9588b89a3f53b0d63b0a80ee7d67a98580c067;hp=dbd9c306a74f1cb258c0d15a346b973b39deaad2;ds=sidebyside added missing minimal_dim() from 1.1 branch --- diff --git a/ginac/clifford.cpp b/ginac/clifford.cpp index b12e385c..352ee194 100644 --- a/ginac/clifford.cpp +++ b/ginac/clifford.cpp @@ -208,10 +208,11 @@ bool diracgamma::contract_with(exvector::iterator self, exvector::iterator other GINAC_ASSERT(is_a(*other)); GINAC_ASSERT(is_a(self->op(0))); unsigned char rl = ex_to(*self).get_representation_label(); + ex dim = ex_to(self->op(1)).get_dim(); + if (other->nops() > 1) + dim = minimal_dim(dim, ex_to(self->op(1)).get_dim()); - if (other->nops() > 1) - dim = minimal_dim(dim, ex_to(self->op(1)).get_dim()); if (is_a(*other)) { // Contraction only makes sense if the represenation labels are equal diff --git a/ginac/idx.cpp b/ginac/idx.cpp index 503a74ac..82052d88 100644 --- a/ginac/idx.cpp +++ b/ginac/idx.cpp @@ -449,12 +449,7 @@ ex idx::replace_dim(const ex & new_dim) const ex idx::minimal_dim(const idx & other) const { - if (dim.is_equal(other.dim) || dim < other.dim || (is_exactly_a(dim) && is_a(other.dim))) - return dim; - else if (dim > other.dim || (is_a(dim) && is_exactly_a(other.dim))) - return other.dim; - else - throw (std::runtime_error("idx::minimal_dim: index dimensions cannot be ordered")); + return GiNaC::minimal_dim(dim, other.dim); } ex varidx::toggle_variance(void) const @@ -545,4 +540,14 @@ void find_free_and_dummy(exvector::const_iterator it, exvector::const_iterator i out_free.push_back(*last); } +ex minimal_dim(const ex & dim1, const ex & dim2) +{ + if (dim1.is_equal(dim2) || dim1 < dim2 || (is_exactly_a(dim1) && is_a(dim2))) + return dim1; + else if (dim1 > dim2 || (is_a(dim1) && is_exactly_a(dim2))) + return dim2; + else + throw (std::runtime_error("minimal_dim(): index dimensions cannot be ordered")); +} + } // namespace GiNaC diff --git a/ginac/idx.h b/ginac/idx.h index ecc6f468..3811a4ef 100644 --- a/ginac/idx.h +++ b/ginac/idx.h @@ -263,6 +263,11 @@ inline unsigned count_free_indices(const exvector & v) return free_indices.size(); } +/** Return the minimum of two index dimensions. If this is undecidable, + * throw an exception. Numeric dimensions are always considered "smaller" + * than symbolic dimensions. */ +ex minimal_dim(const ex & dim1, const ex & dim2); + } // namespace GiNaC #endif // ndef __GINAC_IDX_H__