]> www.ginac.de Git - ginac.git/blobdiff - ginac/clifford.cpp
clifford and color objects are not contracted if their representation labels
[ginac.git] / ginac / clifford.cpp
index 13bb8b0e7010a30f02d0ee0c777c84ba960017d2..86678ecc6f342e881b3074c524258160287b8917 100644 (file)
@@ -3,7 +3,7 @@
  *  Implementation of GiNaC's clifford algebra (Dirac gamma) objects. */
 
 /*
- *  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,9 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#include <iostream>
+#include <stdexcept>
+
 #include "clifford.h"
 #include "ex.h"
 #include "idx.h"
 #include "mul.h"
 #include "print.h"
 #include "archive.h"
-#include "debugmsg.h"
 #include "utils.h"
 
-#include <stdexcept>
-
 namespace GiNaC {
 
 GINAC_IMPLEMENT_REGISTERED_CLASS(clifford, indexed)
@@ -45,12 +45,11 @@ GINAC_IMPLEMENT_REGISTERED_CLASS(diracgamma, tensor)
 GINAC_IMPLEMENT_REGISTERED_CLASS(diracgamma5, tensor)
 
 //////////
-// default constructor, destructor, copy constructor assignment operator and helpers
+// default ctor, dtor, copy ctor, assignment operator and helpers
 //////////
 
 clifford::clifford() : representation_label(0)
 {
-       debugmsg("clifford default constructor", LOGLEVEL_CONSTRUCT);
        tinfo_key = TINFO_clifford;
 }
 
@@ -74,7 +73,6 @@ DEFAULT_CTORS(diracgamma5)
  *  @see dirac_ONE */
 clifford::clifford(const ex & b, unsigned char rl) : inherited(b), representation_label(rl)
 {
-       debugmsg("clifford constructor from ex", LOGLEVEL_CONSTRUCT);
        tinfo_key = TINFO_clifford;
 }
 
@@ -83,20 +81,17 @@ clifford::clifford(const ex & b, unsigned char rl) : inherited(b), representatio
  *  @see dirac_gamma */
 clifford::clifford(const ex & b, const ex & mu, unsigned char rl) : inherited(b, mu), representation_label(rl)
 {
-       debugmsg("clifford constructor from ex,ex", LOGLEVEL_CONSTRUCT);
        GINAC_ASSERT(is_a<varidx>(mu));
        tinfo_key = TINFO_clifford;
 }
 
 clifford::clifford(unsigned char rl, const exvector & v, bool discardable) : inherited(sy_none(), v, discardable), representation_label(rl)
 {
-       debugmsg("clifford constructor from unsigned char,exvector", LOGLEVEL_CONSTRUCT);
        tinfo_key = TINFO_clifford;
 }
 
 clifford::clifford(unsigned char rl, exvector * vp) : inherited(sy_none(), vp), representation_label(rl)
 {
-       debugmsg("clifford constructor from unsigned char,exvector *", LOGLEVEL_CONSTRUCT);
        tinfo_key = TINFO_clifford;
 }
 
@@ -106,7 +101,6 @@ clifford::clifford(unsigned char rl, exvector * vp) : inherited(sy_none(), vp),
 
 clifford::clifford(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
 {
-       debugmsg("clifford constructor from archive_node", LOGLEVEL_CONSTRUCT);
        unsigned rl;
        n.find_unsigned("label", rl);
        representation_label = rl;
@@ -129,7 +123,7 @@ DEFAULT_ARCHIVING(diracgamma5)
 
 int clifford::compare_same_type(const basic & other) const
 {
-       GINAC_ASSERT(is_of_type(other, clifford));
+       GINAC_ASSERT(is_a<clifford>(other));
        const clifford &o = static_cast<const clifford &>(other);
 
        if (representation_label != o.representation_label) {
@@ -142,13 +136,13 @@ int clifford::compare_same_type(const basic & other) const
 
 bool clifford::match_same_type(const basic & other) const
 {
-       GINAC_ASSERT(is_of_type(other, clifford));
+       GINAC_ASSERT(is_a<clifford>(other));
        const clifford &o = static_cast<const clifford &>(other);
 
        return representation_label == o.representation_label;
 }
 
-void clifford::print(const print_context & c, unsigned level = 0) const
+void clifford::print(const print_context & c, unsigned level) const
 {
        if (!is_a<diracgamma5>(seq[0]) && !is_a<diracgamma>(seq[0]) && !is_a<diracone>(seq[0])) {
 
@@ -184,7 +178,10 @@ static void base_and_index(const ex & c, ex & b, ex & i)
 
        if (is_a<diracgamma>(c.op(0))) { // proper dirac gamma object
                i = c.op(1);
-               b = _ex1();
+               b = _ex1;
+       } else if (is_a<diracgamma5>(c.op(0))) { // gamma5
+               i = _ex0;
+               b = _ex1;
        } else { // slash object, generate new dummy index
                varidx ix((new symbol)->setflag(status_flags::dynallocated), ex_to<idx>(c.op(1)).get_dim());
                b = indexed(c.op(0), ix.toggle_variance());
@@ -202,6 +199,10 @@ bool diracgamma::contract_with(exvector::iterator self, exvector::iterator other
 
        if (is_a<clifford>(*other)) {
 
+               // Contraction only makes sense if the represenation labels are equal
+               if (ex_to<clifford>(*other).get_representation_label() != rl)
+                       return false;
+
                ex dim = ex_to<idx>(self->op(1)).get_dim();
 
                // gamma~mu gamma.mu = dim ONE
@@ -214,7 +215,7 @@ bool diracgamma::contract_with(exvector::iterator self, exvector::iterator other
                } else if (other - self == 2
                        && is_a<clifford>(self[1])) {
                        *self = 2 - dim;
-                       *other = _ex1();
+                       *other = _ex1;
                        return true;
 
                // gamma~mu gamma~alpha gamma~beta gamma.mu = 4 g~alpha~beta + (dim-4) gamam~alpha gamma~beta
@@ -225,9 +226,9 @@ bool diracgamma::contract_with(exvector::iterator self, exvector::iterator other
                        base_and_index(self[1], b1, i1);
                        base_and_index(self[2], b2, i2);
                        *self = 4 * lorentz_g(i1, i2) * b1 * b2 * dirac_ONE(rl) + (dim - 4) * self[1] * self[2];
-                       self[1] = _ex1();
-                       self[2] = _ex1();
-                       *other = _ex1();
+                       self[1] = _ex1;
+                       self[2] = _ex1;
+                       *other = _ex1;
                        return true;
 
                // gamma~mu gamma~alpha gamma~beta gamma~delta gamma.mu = -2 gamma~delta gamma~beta gamma~alpha - (dim-4) gamam~alpha gamma~beta gamma~delta
@@ -236,10 +237,10 @@ bool diracgamma::contract_with(exvector::iterator self, exvector::iterator other
                        && is_a<clifford>(self[2])
                        && is_a<clifford>(self[3])) {
                        *self = -2 * self[3] * self[2] * self[1] - (dim - 4) * self[1] * self[2] * self[3];
-                       self[1] = _ex1();
-                       self[2] = _ex1();
-                       self[3] = _ex1();
-                       *other = _ex1();
+                       self[1] = _ex1;
+                       self[2] = _ex1;
+                       self[3] = _ex1;
+                       *other = _ex1;
                        return true;
 
                // gamma~mu S gamma~alpha gamma.mu = 2 gamma~alpha S - gamma~mu S gamma.mu gamma~alpha
@@ -254,15 +255,15 @@ bool diracgamma::contract_with(exvector::iterator self, exvector::iterator other
                        }
 
                        it = self + 1;
-                       ex S = _ex1();
+                       ex S = _ex1;
                        while (it != next_to_last) {
                                S *= *it;
-                               *it++ = _ex1();
+                               *it++ = _ex1;
                        }
 
                        *self = 2 * (*next_to_last) * S - (*self) * S * (*other) * (*next_to_last);
-                       *next_to_last = _ex1();
-                       *other = _ex1();
+                       *next_to_last = _ex1;
+                       *other = _ex1;
                        return true;
                }
        }
@@ -311,12 +312,6 @@ ex clifford::simplify_ncmul(const exvector & v) const
                }
        }
 
-       // Remove squares of gamma5
-       while (s.size() >= 2 && is_a<clifford>(s[0]) && is_a<clifford>(s[1]) && is_a<diracgamma5>(s[0].op(0)) && is_a<diracgamma5>(s[1].op(0))) {
-               s.erase(s.begin(), s.begin() + 2);
-               something_changed = true;
-       }
-
        // Remove equal adjacent gammas
        if (s.size() >= 2) {
                exvector::iterator it, itend = s.end() - 1;
@@ -325,7 +320,9 @@ ex clifford::simplify_ncmul(const exvector & v) const
                        ex & b = it[1];
                        if (!is_a<clifford>(a) || !is_a<clifford>(b))
                                continue;
-                       if (is_a<diracgamma>(a.op(0)) && is_a<diracgamma>(b.op(0))) {
+                       bool a_is_diracgamma = is_a<diracgamma>(a.op(0));
+                       bool b_is_diracgamma = is_a<diracgamma>(b.op(0));
+                       if (a_is_diracgamma && b_is_diracgamma) {
                                const ex & ia = a.op(1);
                                const ex & ib = b.op(1);
                                if (ia.is_equal(ib)) { // gamma~alpha gamma~alpha -> g~alpha~alpha
@@ -333,7 +330,12 @@ ex clifford::simplify_ncmul(const exvector & v) const
                                        b = dirac_ONE(representation_label);
                                        something_changed = true;
                                }
-                       } else if (!is_a<diracgamma>(a.op(0)) && !is_a<diracgamma>(b.op(0))) {
+                       } else if (is_a<diracgamma5>(a.op(0)) && is_a<diracgamma5>(b.op(0))) {
+                               // Remove squares of gamma5
+                               a = dirac_ONE(representation_label);
+                               b = dirac_ONE(representation_label);
+                               something_changed = true;
+                       } else if (!a_is_diracgamma && !b_is_diracgamma) {
                                const ex & ba = a.op(0);
                                const ex & bb = b.op(0);
                                if (ba.is_equal(bb)) { // a\ a\ -> a^2
@@ -462,12 +464,12 @@ ex dirac_trace(const ex & e, unsigned char rl, const ex & trONE)
                 && is_a<diracone>(e.op(0)))
                        return trONE;
                else
-                       return _ex0();
+                       return _ex0;
 
        } else if (is_ex_exactly_of_type(e, mul)) {
 
                // Trace of product: pull out non-clifford factors
-               ex prod = _ex1();
+               ex prod = _ex1;
                for (unsigned i=0; i<e.nops(); i++) {
                        const ex &o = e.op(i);
                        if (is_clifford_tinfo(o.return_type_tinfo(), rl))
@@ -480,7 +482,7 @@ ex dirac_trace(const ex & e, unsigned char rl, const ex & trONE)
        } else if (is_ex_exactly_of_type(e, ncmul)) {
 
                if (!is_clifford_tinfo(e.return_type_tinfo(), rl))
-                       return _ex0();
+                       return _ex0;
 
                // Expand product, if necessary
                ex e_expanded = e.expand();
@@ -496,7 +498,7 @@ ex dirac_trace(const ex & e, unsigned char rl, const ex & trONE)
                        // Trace of gamma5 * odd number of gammas and trace of
                        // gamma5 * gamma.mu * gamma.nu are zero
                        if ((num & 1) == 0 || num == 3)
-                               return _ex0();
+                               return _ex0;
 
                        // Tr gamma5 gamma.mu gamma.nu gamma.rho gamma.sigma = 4I * epsilon(mu, nu, rho, sigma)
                        if (num == 5) {
@@ -547,7 +549,7 @@ ex dirac_trace(const ex & e, unsigned char rl, const ex & trONE)
 
                        // Trace of odd number of gammas is zero
                        if ((num & 1) == 1)
-                               return _ex0();
+                               return _ex0;
 
                        // Tr gamma.mu gamma.nu = 4 g.mu.nu
                        if (num == 2) {
@@ -571,7 +573,7 @@ ex dirac_trace(const ex & e, unsigned char rl, const ex & trONE)
                return e.map(fcn);
 
        } else
-               return _ex0();
+               return _ex0;
 }
 
 ex canonicalize_clifford(const ex & e)
@@ -613,7 +615,7 @@ ex canonicalize_clifford(const ex & e)
                                        base_and_index(it[0], b1, i1);
                                        base_and_index(it[1], b2, i2);
                                        it[0] = (lorentz_g(i1, i2) * b1 * b2).simplify_indexed();
-                                       it[1] = _ex2();
+                                       it[1] = _ex2;
                                        ex sum = ncmul(v);
                                        it[0] = save1;
                                        it[1] = save0;