3 * Implementation of GiNaC's clifford algebra (Dirac gamma) objects. */
6 * GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
37 GINAC_IMPLEMENT_REGISTERED_CLASS(clifford, indexed)
38 GINAC_IMPLEMENT_REGISTERED_CLASS(diracone, tensor)
39 GINAC_IMPLEMENT_REGISTERED_CLASS(diracgamma, tensor)
40 GINAC_IMPLEMENT_REGISTERED_CLASS(diracgamma5, tensor)
43 // default constructor, destructor, copy constructor assignment operator and helpers
46 clifford::clifford() : representation_label(0)
48 debugmsg("clifford default constructor", LOGLEVEL_CONSTRUCT);
49 tinfo_key = TINFO_clifford;
52 void clifford::copy(const clifford & other)
54 inherited::copy(other);
55 representation_label = other.representation_label;
58 DEFAULT_DESTROY(clifford)
59 DEFAULT_CTORS(diracone)
60 DEFAULT_CTORS(diracgamma)
61 DEFAULT_CTORS(diracgamma5)
67 /** Construct object without any indices. This constructor is for internal
68 * use only. Use the dirac_ONE() function instead.
70 clifford::clifford(const ex & b, unsigned char rl) : inherited(b), representation_label(rl)
72 debugmsg("clifford constructor from ex", LOGLEVEL_CONSTRUCT);
73 tinfo_key = TINFO_clifford;
76 /** Construct object with one Lorentz index. This constructor is for internal
77 * use only. Use the dirac_gamma() function instead.
79 clifford::clifford(const ex & b, const ex & mu, unsigned char rl) : inherited(b, mu), representation_label(rl)
81 debugmsg("clifford constructor from ex,ex", LOGLEVEL_CONSTRUCT);
82 GINAC_ASSERT(is_ex_of_type(mu, varidx));
83 tinfo_key = TINFO_clifford;
86 clifford::clifford(unsigned char rl, const exvector & v, bool discardable) : inherited(indexed::unknown, v, discardable), representation_label(rl)
88 debugmsg("clifford constructor from unsigned char,exvector", LOGLEVEL_CONSTRUCT);
89 tinfo_key = TINFO_clifford;
92 clifford::clifford(unsigned char rl, exvector * vp) : inherited(indexed::unknown, vp), representation_label(rl)
94 debugmsg("clifford constructor from unsigned char,exvector *", LOGLEVEL_CONSTRUCT);
95 tinfo_key = TINFO_clifford;
102 clifford::clifford(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
104 debugmsg("clifford constructor from archive_node", LOGLEVEL_CONSTRUCT);
106 n.find_unsigned("label", rl);
107 representation_label = rl;
110 void clifford::archive(archive_node &n) const
112 inherited::archive(n);
113 n.add_unsigned("label", representation_label);
116 DEFAULT_UNARCHIVE(clifford)
117 DEFAULT_ARCHIVING(diracone)
118 DEFAULT_ARCHIVING(diracgamma)
119 DEFAULT_ARCHIVING(diracgamma5)
122 // functions overriding virtual functions from bases classes
125 int clifford::compare_same_type(const basic & other) const
127 GINAC_ASSERT(other.tinfo() == TINFO_clifford);
128 const clifford &o = static_cast<const clifford &>(other);
130 if (representation_label != o.representation_label) {
131 // different representation label
132 return representation_label < o.representation_label ? -1 : 1;
135 return inherited::compare_same_type(other);
138 DEFAULT_COMPARE(diracone)
139 DEFAULT_COMPARE(diracgamma)
140 DEFAULT_COMPARE(diracgamma5)
142 DEFAULT_PRINT_LATEX(diracone, "ONE", "\\mathbb{1}")
143 DEFAULT_PRINT_LATEX(diracgamma, "gamma", "\\gamma")
144 DEFAULT_PRINT_LATEX(diracgamma5, "gamma5", "{\\gamma^5}")
146 /** Contraction of a gamma matrix with something else. */
147 bool diracgamma::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const
149 GINAC_ASSERT(is_ex_of_type(*self, clifford));
150 GINAC_ASSERT(is_ex_of_type(*other, indexed));
151 GINAC_ASSERT(is_ex_of_type(self->op(0), diracgamma));
152 unsigned char rl = ex_to_clifford(*self).get_representation_label();
154 if (is_ex_of_type(*other, clifford)) {
156 ex dim = ex_to_idx(self->op(1)).get_dim();
158 // gamma~mu gamma.mu = dim ONE
159 if (other - self == 1) {
161 *other = dirac_ONE(rl);
164 // gamma~mu gamma~alpha gamma.mu = (2-dim) gamma~alpha
165 } else if (other - self == 2
166 && is_ex_of_type(self[1], clifford)) {
171 // gamma~mu gamma~alpha gamma~beta gamma.mu = 4 g~alpha~beta + (dim-4) gamam~alpha gamma~beta
172 } else if (other - self == 3
173 && is_ex_of_type(self[1], clifford)
174 && is_ex_of_type(self[2], clifford)) {
175 *self = 4 * lorentz_g(self[1].op(1), self[2].op(1)) * dirac_ONE(rl) + (dim - 4) * self[1] * self[2];
181 // gamma~mu S gamma~alpha gamma.mu = 2 gamma~alpha S - gamma~mu S gamma.mu gamma~alpha
182 // (commutate contracted indices towards each other, simplify_indexed()
183 // will re-expand and re-run the simplification)
185 exvector::iterator it = self + 1, next_to_last = other - 1;
186 while (it != other) {
187 if (!is_ex_of_type(*it, clifford))
194 while (it != next_to_last) {
199 *self = 2 * (*next_to_last) * S - (*self) * S * (*other) * (*next_to_last);
200 *next_to_last = _ex1();
209 /** Perform automatic simplification on noncommutative product of clifford
210 * objects. This removes superfluous ONEs, permutes gamma5's to the front
211 * and removes squares of gamma objects. */
212 ex clifford::simplify_ncmul(const exvector & v) const
216 unsigned rl = ex_to_clifford(v[0]).get_representation_label();
218 // Remove superfluous ONEs
219 exvector::const_iterator cit = v.begin(), citend = v.end();
220 while (cit != citend) {
221 if (!is_ex_of_type(cit->op(0), diracone))
226 bool something_changed = false;
229 // Anticommute gamma5's to the front
231 exvector::iterator first = s.begin(), next_to_last = s.end() - 2;
233 exvector::iterator it = next_to_last;
235 exvector::iterator it2 = it + 1;
236 if (!is_ex_of_type(it->op(0), diracgamma5) && is_ex_of_type(it2->op(0), diracgamma5)) {
239 something_changed = true;
245 if (next_to_last == first)
251 // Remove squares of gamma5
252 while (s.size() >= 2 && is_ex_of_type(s[0].op(0), diracgamma5) && is_ex_of_type(s[1].op(0), diracgamma5)) {
253 s.erase(s.begin(), s.begin() + 2);
254 something_changed = true;
257 // Remove equal adjacent gammas
259 exvector::iterator it = s.begin(), itend = s.end() - 1;
260 while (it != itend) {
263 if (is_ex_of_type(a.op(0), diracgamma) && is_ex_of_type(b.op(0), diracgamma)) {
264 const ex & ia = a.op(1);
265 const ex & ib = b.op(1);
266 if (ia.is_equal(ib)) {
267 a = lorentz_g(ia, ib);
269 something_changed = true;
277 return clifford(diracone(), rl) * sign;
278 if (something_changed)
279 return nonsimplified_ncmul(s) * sign;
281 return simplified_ncmul(s) * sign;
284 ex clifford::thisexprseq(const exvector & v) const
286 return clifford(representation_label, v);
289 ex clifford::thisexprseq(exvector * vp) const
291 return clifford(representation_label, vp);
298 ex dirac_ONE(unsigned char rl)
300 return clifford(diracone(), rl);
303 ex dirac_gamma(const ex & mu, unsigned char rl)
305 if (!is_ex_of_type(mu, varidx))
306 throw(std::invalid_argument("index of Dirac gamma must be of type varidx"));
308 return clifford(diracgamma(), mu, rl);
311 ex dirac_gamma5(unsigned char rl)
313 return clifford(diracgamma5(), rl);
316 ex dirac_gamma6(unsigned char rl)
318 return clifford(diracone(), rl) + clifford(diracgamma5(), rl);
321 ex dirac_gamma7(unsigned char rl)
323 return clifford(diracone(), rl) - clifford(diracgamma5(), rl);
326 ex dirac_slash(const ex & e, const ex & dim, unsigned char rl)
328 varidx mu((new symbol)->setflag(status_flags::dynallocated), dim);
329 return indexed(e, mu.toggle_variance()) * dirac_gamma(mu, rl);
332 /** Check whether a given tinfo key (as returned by return_type_tinfo()
333 * is that of a clifford object with the specified representation label. */
334 static bool is_clifford_tinfo(unsigned ti, unsigned char rl)
336 return ti == (TINFO_clifford + rl);
339 ex dirac_trace(const ex & e, unsigned char rl)
341 if (is_ex_of_type(e, clifford)) {
343 if (ex_to_clifford(e).get_representation_label() == rl
344 && is_ex_of_type(e.op(0), diracone))
349 } else if (is_ex_exactly_of_type(e, add)) {
351 // Trace of sum = sum of traces
353 for (unsigned i=0; i<e.nops(); i++)
354 sum += dirac_trace(e.op(i), rl);
357 } else if (is_ex_exactly_of_type(e, mul)) {
359 // Trace of product: pull out non-clifford factors
361 for (unsigned i=0; i<e.nops(); i++) {
362 const ex &o = e.op(i);
363 unsigned ti = o.return_type_tinfo();
364 if (is_clifford_tinfo(o.return_type_tinfo(), rl))
365 prod *= dirac_trace(o, rl);
371 } else if (is_ex_exactly_of_type(e, ncmul)) {
373 if (!is_clifford_tinfo(e.return_type_tinfo(), rl))
376 // Expand product, if necessary
377 ex e_expanded = e.expand();
378 if (!is_ex_of_type(e_expanded, ncmul))
379 return dirac_trace(e_expanded, rl);
381 // gamma5 gets moved to the front so this check is enough
382 bool has_gamma5 = is_ex_of_type(e.op(0).op(0), diracgamma5);
383 unsigned num = e.nops();
387 // Trace of gamma5 * odd number of gammas and trace of
388 // gamma5 * gamma.mu * gamma.nu are zero
389 if ((num & 1) == 0 || num == 3)
393 // epsilon0123.mu1.mu2.mu3.mu4 * Tr gamma.mu1 gamma.mu2 gamma.mu3 gamma.mu4 S_2k
394 ex dim = ex_to_idx(e.op(1).op(1)).get_dim();
395 varidx mu1((new symbol)->setflag(status_flags::dynallocated), dim),
396 mu2((new symbol)->setflag(status_flags::dynallocated), dim),
397 mu3((new symbol)->setflag(status_flags::dynallocated), dim),
398 mu4((new symbol)->setflag(status_flags::dynallocated), dim);
401 v.push_back(dirac_gamma(mu1, rl));
402 v.push_back(dirac_gamma(mu2, rl));
403 v.push_back(dirac_gamma(mu3, rl));
404 v.push_back(dirac_gamma(mu4, rl));
405 for (int i=1; i<num; i++)
406 v.push_back(e.op(i));
408 return (eps0123(mu1.toggle_variance(), mu2.toggle_variance(), mu3.toggle_variance(), mu4.toggle_variance()) *
409 dirac_trace(ncmul(v), rl)).simplify_indexed() / 24;
411 } else { // no gamma5
413 // Trace of odd number of gammas is zero
417 // Tr gamma.mu gamma.nu = 4 g.mu.nu
419 return 4 * lorentz_g(e.op(0).op(1), e.op(1).op(1));
421 // Traces of 4 or more gammas are computed recursively:
422 // Tr gamma.mu1 gamma.mu2 ... gamma.mun =
423 // + g.mu1.mu2 * Tr gamma.mu3 ... gamma.mun
424 // - g.mu1.mu3 * Tr gamma.mu2 gamma.mu4 ... gamma.mun
425 // + g.mu1.mu4 * Tr gamma.mu3 gamma.mu3 gamma.mu5 ... gamma.mun
427 // + g.mu1.mun * Tr gamma.mu2 ... gamma.mu(n-1)
430 const ex &ix1 = e.op(0).op(1);
432 for (int i=1; i<num; i++) {
433 for (int n=1, j=0; n<num; n++) {
438 result += sign * lorentz_g(ix1, e.op(i).op(1)) * dirac_trace(ncmul(v), rl);