3 * Interface to GiNaC's clifford algebra (Dirac gamma) objects. */
6 * GiNaC Copyright (C) 1999-2008 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)
46 clifford(const ex & b, unsigned char rl = 0);
47 clifford(const ex & b, const ex & mu, const ex & metr, unsigned char rl = 0, int comm_sign = -1);
49 // internal constructors
50 clifford(unsigned char rl, const ex & metr, int comm_sign, const exvector & v, bool discardable = false);
51 clifford(unsigned char rl, const ex & metr, int comm_sign, std::auto_ptr<exvector> vp);
53 // functions overriding virtual functions from base classes
55 unsigned precedence() const { return 65; }
56 void archive(archive_node& n) const;
57 void read_archive(const archive_node& n, lst& sym_lst);
59 ex eval_ncmul(const exvector & v) const;
60 bool match_same_type(const basic & other) const;
61 ex thiscontainer(const exvector & v) const;
62 ex thiscontainer(std::auto_ptr<exvector> vp) const;
63 unsigned return_type() const { return return_types::noncommutative; }
64 return_type_t return_type_tinfo() const;
65 // non-virtual functions in this class
67 unsigned char get_representation_label() const { return representation_label; }
68 ex get_metric() const { return metric; }
69 virtual ex get_metric(const ex & i, const ex & j, bool symmetrised = false) const;
70 bool same_metric(const ex & other) const;
71 int get_commutator_sign() const { return commutator_sign; } //**< See the member variable commutator_sign */
73 inline size_t nops() const {return inherited::nops() + 1; }
74 ex op(size_t i) const;
75 ex & let_op(size_t i);
76 ex subs(const exmap & m, unsigned options = 0) const;
79 void do_print_dflt(const print_dflt & c, unsigned level) const;
80 void do_print_latex(const print_latex & c, unsigned level) const;
84 unsigned char representation_label; /**< Representation label to distinguish independent spin lines */
85 ex metric; /**< Metric of the space, all constructors make it an indexed object */
86 int commutator_sign; /**< It is the sign in the definition e~i e~j +/- e~j e~i = B(i, j) + B(j, i)*/
88 GINAC_DECLARE_UNARCHIVER(clifford);
90 /** This class represents the Clifford algebra unity element. */
91 class diracone : public tensor
93 GINAC_DECLARE_REGISTERED_CLASS(diracone, tensor)
95 // non-virtual functions in this class
97 void do_print(const print_context & c, unsigned level) const;
98 void do_print_latex(const print_latex & c, unsigned level) const;
100 GINAC_DECLARE_UNARCHIVER(diracone);
103 /** This class represents the Clifford algebra generators (units). */
104 class cliffordunit : public tensor
106 GINAC_DECLARE_REGISTERED_CLASS(cliffordunit, tensor)
108 // functions overriding virtual functions from base classes
110 bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
112 // non-virtual functions in this class
114 void do_print(const print_context & c, unsigned level) const;
115 void do_print_latex(const print_latex & c, unsigned level) const;
119 /** This class represents the Dirac gamma Lorentz vector. */
120 class diracgamma : public cliffordunit
122 GINAC_DECLARE_REGISTERED_CLASS(diracgamma, cliffordunit)
124 // functions overriding virtual functions from base classes
126 bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
128 // non-virtual functions in this class
130 void do_print(const print_context & c, unsigned level) const;
131 void do_print_latex(const print_latex & c, unsigned level) const;
133 GINAC_DECLARE_UNARCHIVER(diracgamma);
136 /** This class represents the Dirac gamma5 object which anticommutates with
137 * all other gammas. */
138 class diracgamma5 : public tensor
140 GINAC_DECLARE_REGISTERED_CLASS(diracgamma5, tensor)
142 // functions overriding virtual functions from base classes
143 ex conjugate() const;
145 // non-virtual functions in this class
147 void do_print(const print_context & c, unsigned level) const;
148 void do_print_latex(const print_latex & c, unsigned level) const;
150 GINAC_DECLARE_UNARCHIVER(diracgamma5);
153 /** This class represents the Dirac gammaL object which behaves like
155 class diracgammaL : public tensor
157 GINAC_DECLARE_REGISTERED_CLASS(diracgammaL, tensor)
159 // functions overriding virtual functions from base classes
160 ex conjugate() const;
162 // non-virtual functions in this class
164 void do_print(const print_context & c, unsigned level) const;
165 void do_print_latex(const print_latex & c, unsigned level) const;
167 GINAC_DECLARE_UNARCHIVER(diracgammaL);
170 /** This class represents the Dirac gammaL object which behaves like
172 class diracgammaR : public tensor
174 GINAC_DECLARE_REGISTERED_CLASS(diracgammaR, tensor)
176 // functions overriding virtual functions from base classes
177 ex conjugate() const;
179 // non-virtual functions in this class
181 void do_print(const print_context & c, unsigned level) const;
182 void do_print_latex(const print_latex & c, unsigned level) const;
184 GINAC_DECLARE_UNARCHIVER(diracgammaR);
189 /** Check whether a given return_type_t object (as returned by return_type_tinfo()
190 * is that of a clifford object (with an arbitrary representation label).
192 * @param ti tinfo key */
193 inline bool is_clifford_tinfo(const return_type_t& ti)
195 return *(ti.tinfo) == typeid(clifford);
198 /** Create a Clifford unity object.
200 * @param rl Representation label
201 * @return newly constructed object */
202 ex dirac_ONE(unsigned char rl = 0);
204 /** Create a Clifford unit object.
206 * @param mu Index (must be of class varidx or a derived class)
207 * @param metr Metric (should be indexed, tensmetric or a derived class, or a matrix)
208 * @param rl Representation label
209 * @return newly constructed Clifford unit object */
210 ex clifford_unit(const ex & mu, const ex & metr, unsigned char rl = 0);
212 /** Create a Dirac gamma object.
214 * @param mu Index (must be of class varidx or a derived class)
215 * @param rl Representation label
216 * @return newly constructed gamma object */
217 ex dirac_gamma(const ex & mu, unsigned char rl = 0);
219 /** Create a Dirac gamma5 object.
221 * @param rl Representation label
222 * @return newly constructed object */
223 ex dirac_gamma5(unsigned char rl = 0);
225 /** Create a Dirac gammaL object.
227 * @param rl Representation label
228 * @return newly constructed object */
229 ex dirac_gammaL(unsigned char rl = 0);
231 /** Create a Dirac gammaR object.
233 * @param rl Representation label
234 * @return newly constructed object */
235 ex dirac_gammaR(unsigned char rl = 0);
237 /** Create a term of the form e_mu * gamma~mu with a unique index mu.
239 * @param e Original expression
240 * @param dim Dimension of index
241 * @param rl Representation label */
242 ex dirac_slash(const ex & e, const ex & dim, unsigned char rl = 0);
244 /** Calculate dirac traces over the specified set of representation labels.
245 * The computed trace is a linear functional that is equal to the usual
246 * trace only in D = 4 dimensions. In particular, the functional is not
247 * always cyclic in D != 4 dimensions when gamma5 is involved.
249 * @param e Expression to take the trace of
250 * @param rls Set of representation labels
251 * @param trONE Expression to be returned as the trace of the unit matrix */
252 ex dirac_trace(const ex & e, const std::set<unsigned char> & rls, const ex & trONE = 4);
254 /** Calculate dirac traces over the specified list of representation labels.
255 * The computed trace is a linear functional that is equal to the usual
256 * trace only in D = 4 dimensions. In particular, the functional is not
257 * always cyclic in D != 4 dimensions when gamma5 is involved.
259 * @param e Expression to take the trace of
260 * @param rll List of representation labels
261 * @param trONE Expression to be returned as the trace of the unit matrix */
262 ex dirac_trace(const ex & e, const lst & rll, const ex & trONE = 4);
264 /** Calculate the trace of an expression containing gamma objects with
265 * a specified representation label. The computed trace is a linear
266 * functional that is equal to the usual trace only in D = 4 dimensions.
267 * In particular, the functional is not always cyclic in D != 4 dimensions
268 * when gamma5 is involved.
270 * @param e Expression to take the trace of
271 * @param rl Representation label
272 * @param trONE Expression to be returned as the trace of the unit matrix */
273 ex dirac_trace(const ex & e, unsigned char rl = 0, const ex & trONE = 4);
275 /** Bring all products of clifford objects in an expression into a canonical
276 * order. This is not necessarily the most simple form but it will allow
277 * to check two expressions for equality. */
278 ex canonicalize_clifford(const ex & e);
280 /** Automorphism of the Clifford algebra, simply changes signs of all
282 ex clifford_prime(const ex & e);
284 /** Main anti-automorphism of the Clifford algebra: makes reversion
285 * and changes signs of all clifford units. */
286 inline ex clifford_bar(const ex & e) { return clifford_prime(e.conjugate()); }
288 /** Reversion of the Clifford algebra, coincides with the conjugate(). */
289 inline ex clifford_star(const ex & e) { return e.conjugate(); }
291 /** Replaces dirac_ONE's (with a representation_label no less than rl) in e with 1.
292 * For the default value rl = 0 remove all of them. Aborts if e contains any
293 * clifford_unit with representation_label to be removed.
295 * @param e Expression to be processed
296 * @param rl Value of representation label
297 * @param options Defines some internal use */
298 ex remove_dirac_ONE(const ex & e, unsigned char rl = 0, unsigned options = 0);
300 /** Returns the maximal representation label of a clifford object
301 * if e contains at least one, otherwise returns -1
303 * @param e Expression to be processed
304 * @ignore_ONE defines if clifford_ONE should be ignored in the search*/
305 char clifford_max_label(const ex & e, bool ignore_ONE = false);
307 /** Calculation of the norm in the Clifford algebra. */
308 ex clifford_norm(const ex & e);
310 /** Calculation of the inverse in the Clifford algebra. */
311 ex clifford_inverse(const ex & e);
313 /** List or vector conversion into the Clifford vector.
315 * @param v List or vector of coordinates
316 * @param mu Index (must be of class varidx or a derived class)
317 * @param metr Metric (should be indexed, tensmetric or a derived class, or a matrix)
318 * @param rl Representation label
319 * @param e Clifford unit object
320 * @return Clifford vector with given components */
321 ex lst_to_clifford(const ex & v, const ex & mu, const ex & metr, unsigned char rl = 0);
322 ex lst_to_clifford(const ex & v, const ex & e);
324 /** An inverse function to lst_to_clifford(). For given Clifford vector extracts
325 * its components with respect to given Clifford unit. Obtained components may
326 * contain Clifford units with a different metric. Extraction is based on
327 * the algebraic formula (e * c.i + c.i * e)/ pow(e.i, 2) for non-degenerate cases
328 * (i.e. neither pow(e.i, 2) = 0).
330 * @param e Clifford expression to be decomposed into components
331 * @param c Clifford unit defining the metric for splitting (should have numeric dimension of indices)
332 * @param algebraic Use algebraic or symbolic algorithm for extractions
333 * @return List of components of a Clifford vector*/
334 lst clifford_to_lst(const ex & e, const ex & c, bool algebraic=true);
336 /** Calculations of Moebius transformations (conformal map) defined by a 2x2 Clifford matrix
337 * (a b\\c d) in linear spaces with arbitrary signature. The expression is
338 * (a * x + b)/(c * x + d), where x is a vector build from list v with metric G.
339 * (see Jan Cnops. An introduction to {D}irac operators on manifolds, v.24 of
340 * Progress in Mathematical Physics. Birkhauser Boston Inc., Boston, MA, 2002.)
342 * @param a (1,1) entry of the defining matrix
343 * @param b (1,2) entry of the defining matrix
344 * @param c (2,1) entry of the defining matrix
345 * @param d (2,2) entry of the defining matrix
346 * @param v Vector to be transformed
347 * @param G Metric of the surrounding space, may be a Clifford unit then the next parameter is ignored
348 * @param rl Representation label
349 * @return List of components of the transformed vector*/
350 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);
352 /** The second form of Moebius transformations defined by a 2x2 Clifford matrix M
353 * This function takes the transformation matrix M as a single entity.
355 * @param M the defining matrix
356 * @param v Vector to be transformed
357 * @param G Metric of the surrounding space, may be a Clifford unit then the next parameter is ignored
358 * @param rl Representation label
359 * @return List of components of the transformed vector*/
360 ex clifford_moebius_map(const ex & M, const ex & v, const ex & G, unsigned char rl = 0);
364 #endif // ndef __GINAC_CLIFFORD_H__