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
35 GINAC_IMPLEMENT_REGISTERED_CLASS(clifford, indexed)
36 GINAC_IMPLEMENT_REGISTERED_CLASS(diracone, tensor)
37 GINAC_IMPLEMENT_REGISTERED_CLASS(diracgamma, tensor)
40 // default constructor, destructor, copy constructor assignment operator and helpers
45 debugmsg("clifford default constructor", LOGLEVEL_CONSTRUCT);
46 tinfo_key = TINFO_clifford;
49 DEFAULT_COPY(clifford)
50 DEFAULT_DESTROY(clifford)
51 DEFAULT_CTORS(diracone)
52 DEFAULT_CTORS(diracgamma)
58 /** Construct object with one Lorentz index. This constructor is for internal
59 * use only. Use the dirac_gamma() function instead.
61 clifford::clifford(const ex & b, const ex & mu) : inherited(b, mu)
63 debugmsg("clifford constructor from ex,ex", LOGLEVEL_CONSTRUCT);
64 GINAC_ASSERT(is_ex_of_type(mu, varidx));
65 tinfo_key = TINFO_clifford;
68 /** Construct object without any indices. This constructor is for internal
69 * use only. Use the dirac_one() function instead.
71 clifford::clifford(const ex & b) : inherited(b)
73 debugmsg("clifford constructor from ex", LOGLEVEL_CONSTRUCT);
74 tinfo_key = TINFO_clifford;
77 clifford::clifford(const exvector & v, bool discardable) : inherited(indexed::unknown, v, discardable)
79 debugmsg("clifford constructor from exvector", LOGLEVEL_CONSTRUCT);
80 tinfo_key = TINFO_clifford;
83 clifford::clifford(exvector * vp) : inherited(indexed::unknown, vp)
85 debugmsg("clifford constructor from exvector *", LOGLEVEL_CONSTRUCT);
86 tinfo_key = TINFO_clifford;
93 DEFAULT_ARCHIVING(clifford)
94 DEFAULT_ARCHIVING(diracone)
95 DEFAULT_ARCHIVING(diracgamma)
98 // functions overriding virtual functions from bases classes
101 int clifford::compare_same_type(const basic & other) const
103 return inherited::compare_same_type(other);
106 DEFAULT_COMPARE(diracone)
107 DEFAULT_COMPARE(diracgamma)
108 DEFAULT_PRINT(diracone, "ONE")
109 DEFAULT_PRINT(diracgamma, "gamma")
111 /** Contraction of a gamma matrix with something else. */
112 bool diracgamma::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const
114 GINAC_ASSERT(is_ex_of_type(*self, indexed));
115 GINAC_ASSERT(is_ex_of_type(*other, indexed));
116 GINAC_ASSERT(is_ex_of_type(self->op(0), diracgamma));
118 if (is_ex_of_type(other->op(0), diracgamma)) {
120 // gamma~mu*gamma.mu = dim*ONE
121 if (other - self == 1) {
122 *self = ex_to_idx(self->op(1)).get_dim();
123 *other = dirac_one();
126 // gamma~mu*gamma~alpha*gamma.mu = (2-dim)*gamma~alpha
127 } else if (other - self == 2) {
128 *self = 2 - ex_to_idx(self->op(1)).get_dim();
137 /** Perform automatic simplification on noncommutative product of clifford
138 * objects. This removes superfluous ONEs. */
139 ex clifford::simplify_ncmul(const exvector & v) const
144 exvector::const_iterator it = v.begin(), itend = v.end();
145 while (it != itend) {
146 if (!is_ex_of_type(it->op(0), diracone))
152 return clifford(diracone());
153 else if (s.size() == v.size())
154 return simplified_ncmul(v);
156 return simplified_ncmul(s);
159 ex clifford::thisexprseq(const exvector & v) const
164 ex clifford::thisexprseq(exvector * vp) const
175 return clifford(diracone());
178 ex dirac_gamma(const ex & mu)
180 if (!is_ex_of_type(mu, varidx))
181 throw(std::invalid_argument("index of Dirac gamma must be of type varidx"));
183 return clifford(diracgamma(), mu);