3 * Interface to GiNaC's clifford algebra (Dirac gamma) objects. */
6 * GiNaC Copyright (C) 1999-2021 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
35 /** This class holds an object representing an element of the Clifford
36 * algebra (the Dirac gamma matrices). These objects only carry Lorentz
37 * indices. Spinor indices are hidden. A representation label (an unsigned
38 * 8-bit integer) is used to distinguish elements from different Clifford
39 * algebras (objects with different labels commutate). */
40 class clifford : public indexed
42 GINAC_DECLARE_REGISTERED_CLASS(clifford, indexed)
45 clifford(const ex & b, unsigned char rl = 0);
46 clifford(const ex & b, const ex & mu, const ex & metr, unsigned char rl = 0, int comm_sign = -1);
48 // internal constructors
49 clifford(unsigned char rl, const ex & metr, int comm_sign, const exvector & v);
50 clifford(unsigned char rl, const ex & metr, int comm_sign, exvector && v);
52 // functions overriding virtual functions from base classes
54 unsigned precedence() const override { return 65; }
55 void archive(archive_node& n) const override;
56 void read_archive(const archive_node& n, lst& sym_lst) override;
58 ex eval_ncmul(const exvector & v) const override;
59 bool match_same_type(const basic & other) const override;
60 ex thiscontainer(const exvector & v) const override;
61 ex thiscontainer(exvector && v) const override;
62 unsigned return_type() const override { return return_types::noncommutative; }
63 return_type_t return_type_tinfo() const override;
64 // non-virtual functions in this class
66 unsigned char get_representation_label() const { return representation_label; }
67 ex get_metric() const { return metric; }
68 virtual ex get_metric(const ex & i, const ex & j, bool symmetrised = false) const;
69 bool same_metric(const ex & other) const;
70 int get_commutator_sign() const { return commutator_sign; } //**< See the member variable commutator_sign */
72 inline size_t nops() const override {return inherited::nops() + 1; }
73 ex op(size_t i) const override;
74 ex & let_op(size_t i) override;
75 ex subs(const exmap & m, unsigned options = 0) const override;
78 void do_print_dflt(const print_dflt & c, unsigned level) const;
79 void do_print_latex(const print_latex & c, unsigned level) const;
80 void do_print_tree(const print_tree & 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 override;
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;
117 GINAC_DECLARE_UNARCHIVER(cliffordunit);
120 /** This class represents the Dirac gamma Lorentz vector. */
121 class diracgamma : public cliffordunit
123 GINAC_DECLARE_REGISTERED_CLASS(diracgamma, cliffordunit)
125 // functions overriding virtual functions from base classes
127 bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const override;
129 // non-virtual functions in this class
131 void do_print(const print_context & c, unsigned level) const;
132 void do_print_latex(const print_latex & c, unsigned level) const;
134 GINAC_DECLARE_UNARCHIVER(diracgamma);
137 /** This class represents the Dirac gamma5 object which anticommutates with
138 * all other gammas. */
139 class diracgamma5 : public tensor
141 GINAC_DECLARE_REGISTERED_CLASS(diracgamma5, tensor)
143 // functions overriding virtual functions from base classes
144 ex conjugate() const override;
146 // non-virtual functions in this class
148 void do_print(const print_context & c, unsigned level) const;
149 void do_print_latex(const print_latex & c, unsigned level) const;
151 GINAC_DECLARE_UNARCHIVER(diracgamma5);
154 /** This class represents the Dirac gammaL object which behaves like
156 class diracgammaL : public tensor
158 GINAC_DECLARE_REGISTERED_CLASS(diracgammaL, tensor)
160 // functions overriding virtual functions from base classes
161 ex conjugate() const override;
163 // non-virtual functions in this class
165 void do_print(const print_context & c, unsigned level) const;
166 void do_print_latex(const print_latex & c, unsigned level) const;
168 GINAC_DECLARE_UNARCHIVER(diracgammaL);
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 override;
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;
185 GINAC_DECLARE_UNARCHIVER(diracgammaR);
190 /** Check whether a given return_type_t object (as returned by return_type_tinfo()
191 * is that of a clifford object (with an arbitrary representation label).
193 * @param ti tinfo key */
194 inline bool is_clifford_tinfo(const return_type_t& ti)
196 return *(ti.tinfo) == typeid(clifford);
199 /** Create a Clifford unity object.
201 * @param rl Representation label
202 * @return newly constructed object */
203 ex dirac_ONE(unsigned char rl = 0);
205 /** Create a Clifford unit object.
207 * @param mu Index (must be of class varidx or a derived class)
208 * @param metr Metric (should be indexed, tensmetric or a derived class, or a matrix)
209 * @param rl Representation label
210 * @return newly constructed Clifford unit object */
211 ex clifford_unit(const ex & mu, const ex & metr, unsigned char rl = 0);
213 /** Create a Dirac gamma object.
215 * @param mu Index (must be of class varidx or a derived class)
216 * @param rl Representation label
217 * @return newly constructed gamma object */
218 ex dirac_gamma(const ex & mu, unsigned char rl = 0);
220 /** Create a Dirac gamma5 object.
222 * @param rl Representation label
223 * @return newly constructed object */
224 ex dirac_gamma5(unsigned char rl = 0);
226 /** Create a Dirac gammaL object.
228 * @param rl Representation label
229 * @return newly constructed object */
230 ex dirac_gammaL(unsigned char rl = 0);
232 /** Create a Dirac gammaR object.
234 * @param rl Representation label
235 * @return newly constructed object */
236 ex dirac_gammaR(unsigned char rl = 0);
238 /** Create a term of the form e_mu * gamma~mu with a unique index mu.
240 * @param e Original expression
241 * @param dim Dimension of index
242 * @param rl Representation label */
243 ex dirac_slash(const ex & e, const ex & dim, unsigned char rl = 0);
245 /** Calculate dirac traces over the specified set of representation labels.
246 * The computed trace is a linear functional that is equal to the usual
247 * trace only in D = 4 dimensions. In particular, the functional is not
248 * always cyclic in D != 4 dimensions when gamma5 is involved.
250 * @param e Expression to take the trace of
251 * @param rls Set of representation labels
252 * @param trONE Expression to be returned as the trace of the unit matrix */
253 ex dirac_trace(const ex & e, const std::set<unsigned char> & rls, const ex & trONE = 4);
255 /** Calculate dirac traces over the specified list of representation labels.
256 * The computed trace is a linear functional that is equal to the usual
257 * trace only in D = 4 dimensions. In particular, the functional is not
258 * always cyclic in D != 4 dimensions when gamma5 is involved.
260 * @param e Expression to take the trace of
261 * @param rll List of representation labels
262 * @param trONE Expression to be returned as the trace of the unit matrix */
263 ex dirac_trace(const ex & e, const lst & rll, const ex & trONE = 4);
265 /** Calculate the trace of an expression containing gamma objects with
266 * a specified representation label. The computed trace is a linear
267 * functional that is equal to the usual trace only in D = 4 dimensions.
268 * In particular, the functional is not always cyclic in D != 4 dimensions
269 * when gamma5 is involved.
271 * @param e Expression to take the trace of
272 * @param rl Representation label
273 * @param trONE Expression to be returned as the trace of the unit matrix */
274 ex dirac_trace(const ex & e, unsigned char rl = 0, const ex & trONE = 4);
276 /** Bring all products of clifford objects in an expression into a canonical
277 * order. This is not necessarily the most simple form but it will allow
278 * to check two expressions for equality. */
279 ex canonicalize_clifford(const ex & e);
281 /** Automorphism of the Clifford algebra, simply changes signs of all
283 ex clifford_prime(const ex & e);
285 /** An auxillary function performing clifford_star() and clifford_bar().*/
286 ex clifford_star_bar(const ex & e, bool do_bar, unsigned options);
288 /** Main anti-automorphism of the Clifford algebra: makes reversion
289 * and changes signs of all clifford units. */
290 inline ex clifford_bar(const ex & e) { return clifford_star_bar(e, true, 0); }
292 /** Reversion of the Clifford algebra, reverse the order of all clifford units
294 inline ex clifford_star(const ex & e) { return clifford_star_bar(e, false, 0); }
296 /** Replaces dirac_ONE's (with a representation_label no less than rl) in e with 1.
297 * For the default value rl = 0 remove all of them. Aborts if e contains any
298 * clifford_unit with representation_label to be removed.
300 * @param e Expression to be processed
301 * @param rl Value of representation label
302 * @param options Defines some internal use */
303 ex remove_dirac_ONE(const ex & e, unsigned char rl = 0, unsigned options = 0);
305 /** Returns the maximal representation label of a clifford object
306 * if e contains at least one, otherwise returns -1
308 * @param e Expression to be processed
309 * @ignore_ONE defines if clifford_ONE should be ignored in the search*/
310 int clifford_max_label(const ex & e, bool ignore_ONE = false);
312 /** Calculation of the norm in the Clifford algebra. */
313 ex clifford_norm(const ex & e);
315 /** Calculation of the inverse in the Clifford algebra. */
316 ex clifford_inverse(const ex & e);
318 /** List or vector conversion into the Clifford vector.
320 * @param v List or vector of coordinates
321 * @param mu Index (must be of class varidx or a derived class)
322 * @param metr Metric (should be indexed, tensmetric or a derived class, or a matrix)
323 * @param rl Representation label
324 * @param e Clifford unit object
325 * @return Clifford vector with given components */
326 ex lst_to_clifford(const ex & v, const ex & mu, const ex & metr, unsigned char rl = 0);
327 ex lst_to_clifford(const ex & v, const ex & e);
329 /** An inverse function to lst_to_clifford(). For given Clifford vector extracts
330 * its components with respect to given Clifford unit. Obtained components may
331 * contain Clifford units with a different metric. Extraction is based on
332 * the algebraic formula (e * c.i + c.i * e)/ pow(e.i, 2) for non-degenerate cases
333 * (i.e. neither pow(e.i, 2) = 0).
335 * @param e Clifford expression to be decomposed into components
336 * @param c Clifford unit defining the metric for splitting (should have numeric dimension of indices)
337 * @param algebraic Use algebraic or symbolic algorithm for extractions
338 * @return List of components of a Clifford vector*/
339 lst clifford_to_lst(const ex & e, const ex & c, bool algebraic=true);
341 /** Calculations of Moebius transformations (conformal map) defined by a 2x2 Clifford matrix
342 * (a b\\c d) in linear spaces with arbitrary signature. The expression is
343 * (a * x + b)/(c * x + d), where x is a vector build from list v with metric G.
344 * (see Jan Cnops. An introduction to {D}irac operators on manifolds, v.24 of
345 * Progress in Mathematical Physics. Birkhauser Boston Inc., Boston, MA, 2002.)
347 * @param a (1,1) entry of the defining matrix
348 * @param b (1,2) entry of the defining matrix
349 * @param c (2,1) entry of the defining matrix
350 * @param d (2,2) entry of the defining matrix
351 * @param v Vector to be transformed
352 * @param G Metric of the surrounding space, may be a Clifford unit then the next parameter is ignored
353 * @param rl Representation label
354 * @return List of components of the transformed vector*/
355 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);
357 /** The second form of Moebius transformations defined by a 2x2 Clifford matrix M
358 * This function takes the transformation matrix M as a single entity.
360 * @param M the defining matrix
361 * @param v Vector to be transformed
362 * @param G Metric of the surrounding space, may be a Clifford unit then the next parameter is ignored
363 * @param rl Representation label
364 * @return List of components of the transformed vector*/
365 ex clifford_moebius_map(const ex & M, const ex & v, const ex & G, unsigned char rl = 0);
369 #endif // ndef GINAC_CLIFFORD_H