3 * Interface to GiNaC's clifford algebra (Dirac gamma) objects. */
6 * GiNaC Copyright (C) 1999-2007 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #ifndef __GINAC_CLIFFORD_H__
24 #define __GINAC_CLIFFORD_H__
36 /** This class holds an object representing an element of the Clifford
37 * algebra (the Dirac gamma matrices). These objects only carry Lorentz
38 * indices. Spinor indices are hidden. A representation label (an unsigned
39 * 8-bit integer) is used to distinguish elements from different Clifford
40 * algebras (objects with different labels commutate). */
41 class clifford : public indexed
43 GINAC_DECLARE_REGISTERED_CLASS(clifford, indexed)
45 static const tinfo_static_t return_type_tinfo_static[256];
49 clifford(const ex & b, unsigned char rl = 0);
50 clifford(const ex & b, const ex & mu, const ex & metr, unsigned char rl = 0, int comm_sign = -1);
52 // internal constructors
53 clifford(unsigned char rl, const ex & metr, int comm_sign, const exvector & v, bool discardable = false);
54 clifford(unsigned char rl, const ex & metr, int comm_sign, std::auto_ptr<exvector> vp);
56 // functions overriding virtual functions from base classes
58 unsigned precedence() const { return 65; }
60 ex eval_ncmul(const exvector & v) const;
61 bool match_same_type(const basic & other) const;
62 ex thiscontainer(const exvector & v) const;
63 ex thiscontainer(std::auto_ptr<exvector> vp) const;
64 unsigned return_type() const { return return_types::noncommutative; }
65 tinfo_t return_type_tinfo() const { return clifford::return_type_tinfo_static+representation_label; }
67 // non-virtual functions in this class
69 unsigned char get_representation_label() const { return representation_label; }
70 ex get_metric() const { return metric; }
71 virtual ex get_metric(const ex & i, const ex & j, bool symmetrised = false) const;
72 bool same_metric(const ex & other) const;
73 int get_commutator_sign() const { return commutator_sign; } //**< See the member variable commutator_sign */
75 inline size_t nops() const {return inherited::nops() + 1; }
76 ex op(size_t i) const;
77 ex & let_op(size_t i);
78 ex subs(const exmap & m, unsigned options = 0) const;
81 void do_print_dflt(const print_dflt & c, unsigned level) const;
82 void do_print_latex(const print_latex & c, unsigned level) const;
86 unsigned char representation_label; /**< Representation label to distinguish independent spin lines */
87 ex metric; /**< Metric of the space, all constructors make it an indexed object */
88 int commutator_sign; /**< It is the sign in the definition e~i e~j +/- e~j e~i = B(i, j) + B(j, i)*/
91 /** This class represents the Clifford algebra unity element. */
92 class diracone : public tensor
94 GINAC_DECLARE_REGISTERED_CLASS(diracone, tensor)
96 // non-virtual functions in this class
98 void do_print(const print_context & c, unsigned level) const;
99 void do_print_latex(const print_latex & c, unsigned level) const;
103 /** This class represents the Clifford algebra generators (units). */
104 class cliffordunit : public tensor
106 GINAC_DECLARE_REGISTERED_CLASS(cliffordunit, tensor)
108 // other constructors
110 cliffordunit(tinfo_t ti) : inherited(ti) {}
112 // functions overriding virtual functions from base classes
114 bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
116 // non-virtual functions in this class
118 void do_print(const print_context & c, unsigned level) const;
119 void do_print_latex(const print_latex & c, unsigned level) const;
123 /** This class represents the Dirac gamma Lorentz vector. */
124 class diracgamma : public cliffordunit
126 GINAC_DECLARE_REGISTERED_CLASS(diracgamma, cliffordunit)
128 // functions overriding virtual functions from base classes
130 bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
132 // non-virtual functions in this class
134 void do_print(const print_context & c, unsigned level) const;
135 void do_print_latex(const print_latex & c, unsigned level) const;
139 /** This class represents the Dirac gamma5 object which anticommutates with
140 * all other gammas. */
141 class diracgamma5 : public tensor
143 GINAC_DECLARE_REGISTERED_CLASS(diracgamma5, tensor)
145 // functions overriding virtual functions from base classes
146 ex conjugate() const;
148 // non-virtual functions in this class
150 void do_print(const print_context & c, unsigned level) const;
151 void do_print_latex(const print_latex & c, unsigned level) const;
155 /** This class represents the Dirac gammaL object which behaves like
157 class diracgammaL : public tensor
159 GINAC_DECLARE_REGISTERED_CLASS(diracgammaL, tensor)
161 // functions overriding virtual functions from base classes
162 ex conjugate() const;
164 // non-virtual functions in this class
166 void do_print(const print_context & c, unsigned level) const;
167 void do_print_latex(const print_latex & c, unsigned level) const;
171 /** This class represents the Dirac gammaL object which behaves like
173 class diracgammaR : public tensor
175 GINAC_DECLARE_REGISTERED_CLASS(diracgammaR, tensor)
177 // functions overriding virtual functions from base classes
178 ex conjugate() const;
180 // non-virtual functions in this class
182 void do_print(const print_context & c, unsigned level) const;
183 void do_print_latex(const print_latex & c, unsigned level) const;
189 /** Check whether a given tinfo key (as returned by return_type_tinfo()
190 * is that of a clifford object (with an arbitrary representation label).
192 * @param ti tinfo key */
193 bool is_clifford_tinfo(tinfo_t ti);
195 /** Create a Clifford unity object.
197 * @param rl Representation label
198 * @return newly constructed object */
199 ex dirac_ONE(unsigned char rl = 0);
201 /** Create a Clifford unit object.
203 * @param mu Index (must be of class varidx or a derived class)
204 * @param metr Metric (should be indexed, tensmetric or a derived class, or a matrix)
205 * @param rl Representation label
206 * @return newly constructed Clifford unit object */
207 ex clifford_unit(const ex & mu, const ex & metr, unsigned char rl = 0);
209 /** Create a Dirac gamma object.
211 * @param mu Index (must be of class varidx or a derived class)
212 * @param rl Representation label
213 * @return newly constructed gamma object */
214 ex dirac_gamma(const ex & mu, unsigned char rl = 0);
216 /** Create a Dirac gamma5 object.
218 * @param rl Representation label
219 * @return newly constructed object */
220 ex dirac_gamma5(unsigned char rl = 0);
222 /** Create a Dirac gammaL object.
224 * @param rl Representation label
225 * @return newly constructed object */
226 ex dirac_gammaL(unsigned char rl = 0);
228 /** Create a Dirac gammaR object.
230 * @param rl Representation label
231 * @return newly constructed object */
232 ex dirac_gammaR(unsigned char rl = 0);
234 /** Create a term of the form e_mu * gamma~mu with a unique index mu.
236 * @param e Original expression
237 * @param dim Dimension of index
238 * @param rl Representation label */
239 ex dirac_slash(const ex & e, const ex & dim, unsigned char rl = 0);
241 /** Calculate dirac traces over the specified set of representation labels.
242 * The computed trace is a linear functional that is equal to the usual
243 * trace only in D = 4 dimensions. In particular, the functional is not
244 * always cyclic in D != 4 dimensions when gamma5 is involved.
246 * @param e Expression to take the trace of
247 * @param rls Set of representation labels
248 * @param trONE Expression to be returned as the trace of the unit matrix */
249 ex dirac_trace(const ex & e, const std::set<unsigned char> & rls, const ex & trONE = 4);
251 /** Calculate dirac traces over the specified list of representation labels.
252 * The computed trace is a linear functional that is equal to the usual
253 * trace only in D = 4 dimensions. In particular, the functional is not
254 * always cyclic in D != 4 dimensions when gamma5 is involved.
256 * @param e Expression to take the trace of
257 * @param rll List of representation labels
258 * @param trONE Expression to be returned as the trace of the unit matrix */
259 ex dirac_trace(const ex & e, const lst & rll, const ex & trONE = 4);
261 /** Calculate the trace of an expression containing gamma objects with
262 * a specified representation label. The computed trace is a linear
263 * functional that is equal to the usual trace only in D = 4 dimensions.
264 * In particular, the functional is not always cyclic in D != 4 dimensions
265 * when gamma5 is involved.
267 * @param e Expression to take the trace of
268 * @param rl Representation label
269 * @param trONE Expression to be returned as the trace of the unit matrix */
270 ex dirac_trace(const ex & e, unsigned char rl = 0, const ex & trONE = 4);
272 /** Bring all products of clifford objects in an expression into a canonical
273 * order. This is not necessarily the most simple form but it will allow
274 * to check two expressions for equality. */
275 ex canonicalize_clifford(const ex & e);
277 /** Automorphism of the Clifford algebra, simply changes signs of all
279 ex clifford_prime(const ex & e);
281 /** Main anti-automorphism of the Clifford algebra: makes reversion
282 * and changes signs of all clifford units. */
283 inline ex clifford_bar(const ex & e) { return clifford_prime(e.conjugate()); }
285 /** Reversion of the Clifford algebra, coincides with the conjugate(). */
286 inline ex clifford_star(const ex & e) { return e.conjugate(); }
288 /** Replaces dirac_ONE's (with a representation_label no less than rl) in e with 1.
289 * For the default value rl = 0 remove all of them. Aborts if e contains any
290 * clifford_unit with representation_label to be removed.
292 * @param e Expression to be processed
293 * @param rl Value of representation label
294 * @param options Defines some internal use */
295 ex remove_dirac_ONE(const ex & e, unsigned char rl = 0, unsigned options = 0);
297 /** Returns the maximal representation label of a clifford object
298 * if e contains at least one, otherwise returns -1
300 * @param e Expression to be processed
301 * @ignore_ONE defines if clifford_ONE should be ignored in the search*/
302 char clifford_max_label(const ex & e, bool ignore_ONE = false);
304 /** Calculation of the norm in the Clifford algebra. */
305 ex clifford_norm(const ex & e);
307 /** Calculation of the inverse in the Clifford algebra. */
308 ex clifford_inverse(const ex & e);
310 /** List or vector conversion into the Clifford vector.
312 * @param v List or vector of coordinates
313 * @param mu Index (must be of class varidx or a derived class)
314 * @param metr Metric (should be indexed, tensmetric or a derived class, or a matrix)
315 * @param rl Representation label
316 * @param e Clifford unit object
317 * @return Clifford vector with given components */
318 ex lst_to_clifford(const ex & v, const ex & mu, const ex & metr, unsigned char rl = 0);
319 ex lst_to_clifford(const ex & v, const ex & e);
321 /** An inverse function to lst_to_clifford(). For given Clifford vector extracts
322 * its components with respect to given Clifford unit. Obtained components may
323 * contain Clifford units with a different metric. Extraction is based on
324 * the algebraic formula (e * c.i + c.i * e)/ pow(e.i, 2) for non-degenerate cases
325 * (i.e. neither pow(e.i, 2) = 0).
327 * @param e Clifford expression to be decomposed into components
328 * @param c Clifford unit defining the metric for splitting (should have numeric dimension of indices)
329 * @param algebraic Use algebraic or symbolic algorithm for extractions
330 * @return List of components of a Clifford vector*/
331 lst clifford_to_lst(const ex & e, const ex & c, bool algebraic=true);
333 /** Calculations of Moebius transformations (conformal map) defined by a 2x2 Clifford matrix
334 * (a b\\c d) in linear spaces with arbitrary signature. The expression is
335 * (a * x + b)/(c * x + d), where x is a vector build from list v with metric G.
336 * (see Jan Cnops. An introduction to {D}irac operators on manifolds, v.24 of
337 * Progress in Mathematical Physics. Birkhauser Boston Inc., Boston, MA, 2002.)
339 * @param a (1,1) entry of the defining matrix
340 * @param b (1,2) entry of the defining matrix
341 * @param c (2,1) entry of the defining matrix
342 * @param d (2,2) entry of the defining matrix
343 * @param v Vector to be transformed
344 * @param G Metric of the surrounding space, may be a Clifford unit then the next parameter is ignored
345 * @param rl Representation label
346 * @return List of components of the transformed vector*/
347 ex clifford_moebius_map(const ex & a, const ex & b, const ex & c, const ex & d, const ex & v, const ex & G, unsigned char rl = 0);
349 /** The second form of Moebius transformations defined by a 2x2 Clifford matrix M
350 * This function takes the transformation matrix M as a single entity.
352 * @param M the defining matrix
353 * @param v Vector to be transformed
354 * @param G Metric of the surrounding space, may be a Clifford unit then the next parameter is ignored
355 * @param rl Representation label
356 * @return List of components of the transformed vector*/
357 ex clifford_moebius_map(const ex & M, const ex & v, const ex & G, unsigned char rl = 0);
361 #endif // ndef __GINAC_CLIFFORD_H__