]> www.ginac.de Git - ginac.git/blob - ginac/clifford.h
A better return_type_tinfo() mechanism.
[ginac.git] / ginac / clifford.h
1 /** @file clifford.h
2  *
3  *  Interface to GiNaC's clifford algebra (Dirac gamma) objects. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2008 Johannes Gutenberg University Mainz, Germany
7  *
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.
12  *
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.
17  *
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
21  */
22
23 #ifndef __GINAC_CLIFFORD_H__
24 #define __GINAC_CLIFFORD_H__
25
26 #include "indexed.h"
27 #include "tensor.h"
28 #include "symbol.h"
29 #include "idx.h"
30
31 #include <set>
32
33 namespace GiNaC {
34
35
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
42 {
43         GINAC_DECLARE_REGISTERED_CLASS(clifford, indexed)
44         // other constructors
45 public:
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);
48
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);
52
53         // functions overriding virtual functions from base classes
54 public:
55         unsigned precedence() const { return 65; }
56 protected:
57         ex eval_ncmul(const exvector & v) const;
58         bool match_same_type(const basic & other) const;
59         ex thiscontainer(const exvector & v) const;
60         ex thiscontainer(std::auto_ptr<exvector> vp) const;
61         unsigned return_type() const { return return_types::noncommutative; }
62         return_type_t return_type_tinfo() const;
63         // non-virtual functions in this class
64 public:
65         unsigned char get_representation_label() const { return representation_label; }
66         ex get_metric() const { return metric; }
67         virtual ex get_metric(const ex & i, const ex & j, bool symmetrised = false) const;
68         bool same_metric(const ex & other) const;
69         int get_commutator_sign() const { return commutator_sign; } //**< See the member variable commutator_sign */
70
71         inline size_t nops() const {return inherited::nops() + 1; }
72         ex op(size_t i) const;
73         ex & let_op(size_t i);
74         ex subs(const exmap & m, unsigned options = 0) const;
75
76 protected:
77         void do_print_dflt(const print_dflt & c, unsigned level) const;
78         void do_print_latex(const print_latex & c, unsigned level) const;
79
80         // member variables
81 protected:
82         unsigned char representation_label; /**< Representation label to distinguish independent spin lines */
83         ex metric; /**< Metric of the space, all constructors make it an indexed object */
84         int commutator_sign; /**< It is the sign in the definition e~i e~j +/- e~j e~i = B(i, j) + B(j, i)*/
85 };
86
87 /** This class represents the Clifford algebra unity element. */
88 class diracone : public tensor
89 {
90         GINAC_DECLARE_REGISTERED_CLASS(diracone, tensor)
91
92         // non-virtual functions in this class
93 protected:
94         void do_print(const print_context & c, unsigned level) const;
95         void do_print_latex(const print_latex & c, unsigned level) const;
96 };
97
98
99 /** This class represents the Clifford algebra generators (units). */
100 class cliffordunit : public tensor
101 {
102         GINAC_DECLARE_REGISTERED_CLASS(cliffordunit, tensor)
103
104         // other constructors
105 protected:
106         cliffordunit(tinfo_t ti) : inherited(ti) {}
107                                                                                                     
108         // functions overriding virtual functions from base classes
109 public:
110         bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
111
112         // non-virtual functions in this class
113 protected:
114         void do_print(const print_context & c, unsigned level) const;
115         void do_print_latex(const print_latex & c, unsigned level) const;
116 };
117
118
119 /** This class represents the Dirac gamma Lorentz vector. */
120 class diracgamma : public cliffordunit
121 {
122         GINAC_DECLARE_REGISTERED_CLASS(diracgamma, cliffordunit)
123
124         // functions overriding virtual functions from base classes
125 public:
126         bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
127
128         // non-virtual functions in this class
129 protected:
130         void do_print(const print_context & c, unsigned level) const;
131         void do_print_latex(const print_latex & c, unsigned level) const;
132 };
133
134
135 /** This class represents the Dirac gamma5 object which anticommutates with
136  *  all other gammas. */
137 class diracgamma5 : public tensor
138 {
139         GINAC_DECLARE_REGISTERED_CLASS(diracgamma5, tensor)
140
141         // functions overriding virtual functions from base classes
142         ex conjugate() const;
143
144         // non-virtual functions in this class
145 protected:
146         void do_print(const print_context & c, unsigned level) const;
147         void do_print_latex(const print_latex & c, unsigned level) const;
148 };
149
150
151 /** This class represents the Dirac gammaL object which behaves like
152  *  1/2 (1-gamma5). */
153 class diracgammaL : public tensor
154 {
155         GINAC_DECLARE_REGISTERED_CLASS(diracgammaL, tensor)
156
157         // functions overriding virtual functions from base classes
158         ex conjugate() const;
159
160         // non-virtual functions in this class
161 protected:
162         void do_print(const print_context & c, unsigned level) const;
163         void do_print_latex(const print_latex & c, unsigned level) const;
164 };
165
166
167 /** This class represents the Dirac gammaL object which behaves like
168  *  1/2 (1+gamma5). */
169 class diracgammaR : public tensor
170 {
171         GINAC_DECLARE_REGISTERED_CLASS(diracgammaR, tensor)
172
173         // functions overriding virtual functions from base classes
174         ex conjugate() const;
175
176         // non-virtual functions in this class
177 protected:
178         void do_print(const print_context & c, unsigned level) const;
179         void do_print_latex(const print_latex & c, unsigned level) const;
180 };
181
182
183 // global functions
184
185 /** Check whether a given return_type_t object (as returned by return_type_tinfo()
186   * is that of a clifford object (with an arbitrary representation label).
187   *
188   * @param ti tinfo key */
189 inline bool is_clifford_tinfo(const return_type_t& ti)
190 {
191         return *(ti.tinfo) == typeid(clifford);
192 }
193
194 /** Create a Clifford unity object.
195  *
196  *  @param rl Representation label
197  *  @return newly constructed object */
198 ex dirac_ONE(unsigned char rl = 0);
199
200 /** Create a Clifford unit object.
201  *
202  *  @param mu Index (must be of class varidx or a derived class)
203  *  @param metr Metric (should be indexed, tensmetric or a derived class, or a matrix)
204  *  @param rl Representation label
205  *  @return newly constructed Clifford unit object */
206 ex clifford_unit(const ex & mu, const ex & metr, unsigned char rl = 0);
207
208 /** Create a Dirac gamma object.
209  *
210  *  @param mu Index (must be of class varidx or a derived class)
211  *  @param rl Representation label
212  *  @return newly constructed gamma object */
213 ex dirac_gamma(const ex & mu, unsigned char rl = 0);
214
215 /** Create a Dirac gamma5 object.
216  *
217  *  @param rl Representation label
218  *  @return newly constructed object */
219 ex dirac_gamma5(unsigned char rl = 0);
220
221 /** Create a Dirac gammaL object.
222  *
223  *  @param rl Representation label
224  *  @return newly constructed object */
225 ex dirac_gammaL(unsigned char rl = 0);
226
227 /** Create a Dirac gammaR object.
228  *
229  *  @param rl Representation label
230  *  @return newly constructed object */
231 ex dirac_gammaR(unsigned char rl = 0);
232
233 /** Create a term of the form e_mu * gamma~mu with a unique index mu.
234  *
235  *  @param e Original expression
236  *  @param dim Dimension of index
237  *  @param rl Representation label */
238 ex dirac_slash(const ex & e, const ex & dim, unsigned char rl = 0);
239
240 /** Calculate dirac traces over the specified set of representation labels.
241  *  The computed trace is a linear functional that is equal to the usual
242  *  trace only in D = 4 dimensions. In particular, the functional is not
243  *  always cyclic in D != 4 dimensions when gamma5 is involved.
244  *
245  *  @param e Expression to take the trace of
246  *  @param rls Set of representation labels
247  *  @param trONE Expression to be returned as the trace of the unit matrix */
248 ex dirac_trace(const ex & e, const std::set<unsigned char> & rls, const ex & trONE = 4);
249
250 /** Calculate dirac traces over the specified list of representation labels.
251  *  The computed trace is a linear functional that is equal to the usual
252  *  trace only in D = 4 dimensions. In particular, the functional is not
253  *  always cyclic in D != 4 dimensions when gamma5 is involved.
254  *
255  *  @param e Expression to take the trace of
256  *  @param rll List of representation labels
257  *  @param trONE Expression to be returned as the trace of the unit matrix */
258 ex dirac_trace(const ex & e, const lst & rll, const ex & trONE = 4);
259
260 /** Calculate the trace of an expression containing gamma objects with
261  *  a specified representation label. The computed trace is a linear
262  *  functional that is equal to the usual trace only in D = 4 dimensions.
263  *  In particular, the functional is not always cyclic in D != 4 dimensions
264  *  when gamma5 is involved.
265  *
266  *  @param e Expression to take the trace of
267  *  @param rl Representation label
268  *  @param trONE Expression to be returned as the trace of the unit matrix */
269 ex dirac_trace(const ex & e, unsigned char rl = 0, const ex & trONE = 4);
270
271 /** Bring all products of clifford objects in an expression into a canonical
272  *  order. This is not necessarily the most simple form but it will allow
273  *  to check two expressions for equality. */
274 ex canonicalize_clifford(const ex & e);
275
276 /** Automorphism of the Clifford algebra, simply changes signs of all
277  *  clifford units. */
278 ex clifford_prime(const ex & e);
279
280 /** Main anti-automorphism of the Clifford algebra: makes reversion
281  *  and changes signs of all clifford units. */
282 inline ex clifford_bar(const ex & e) { return clifford_prime(e.conjugate()); }
283
284 /** Reversion of the Clifford algebra, coincides with the conjugate(). */
285 inline ex clifford_star(const ex & e) { return e.conjugate(); }
286
287 /** Replaces dirac_ONE's (with a representation_label no less than rl) in e with 1.
288  *  For the default value rl = 0 remove all of them. Aborts if e contains any 
289  *  clifford_unit with representation_label to be removed.
290  *
291  *  @param e Expression to be processed
292  *  @param rl Value of representation label 
293  *  @param options Defines some internal use */
294 ex remove_dirac_ONE(const ex & e, unsigned char rl = 0, unsigned options = 0);
295
296 /** Returns the maximal representation label of a clifford object 
297  *  if e contains at least one, otherwise returns -1 
298  *
299  *  @param e Expression to be processed
300  *  @ignore_ONE defines if clifford_ONE should be ignored in the search*/
301 char clifford_max_label(const ex & e, bool ignore_ONE = false);
302
303 /** Calculation of the norm in the Clifford algebra. */
304 ex clifford_norm(const ex & e);
305
306 /** Calculation of the inverse in the Clifford algebra. */
307 ex clifford_inverse(const ex & e);
308
309 /** List or vector conversion into the Clifford vector.
310  *
311  *  @param v List or vector of coordinates
312  *  @param mu Index (must be of class varidx or a derived class)
313  *  @param metr Metric (should be indexed, tensmetric or a derived class, or a matrix)
314  *  @param rl Representation label
315  *  @param e Clifford unit object
316  *  @return Clifford vector with given components */
317 ex lst_to_clifford(const ex & v, const ex & mu,  const ex & metr, unsigned char rl = 0);
318 ex lst_to_clifford(const ex & v, const ex & e);
319
320 /** An inverse function to lst_to_clifford(). For given Clifford vector extracts
321  *  its components with respect to given Clifford unit. Obtained components may 
322  *  contain Clifford units with a different metric. Extraction is based on 
323  *  the algebraic formula (e * c.i + c.i * e)/ pow(e.i, 2) for non-degenerate cases
324  *  (i.e. neither pow(e.i, 2) = 0).
325  *  
326  *  @param e Clifford expression to be decomposed into components
327  *  @param c Clifford unit defining the metric for splitting (should have numeric dimension of indices)
328  *  @param algebraic Use algebraic or symbolic algorithm for extractions 
329  *  @return List of components of a Clifford vector*/
330 lst clifford_to_lst(const ex & e, const ex & c, bool algebraic=true);
331
332 /** Calculations of Moebius transformations (conformal map) defined by a 2x2 Clifford matrix
333  *  (a b\\c d) in linear spaces with arbitrary signature. The expression is 
334  *  (a * x + b)/(c * x + d), where x is a vector build from list v with metric G.
335  *  (see Jan Cnops. An introduction to {D}irac operators on manifolds, v.24 of
336  *  Progress in Mathematical Physics. Birkhauser Boston Inc., Boston, MA, 2002.)
337  * 
338  *  @param a (1,1) entry of the defining matrix
339  *  @param b (1,2) entry of the defining matrix
340  *  @param c (2,1) entry of the defining matrix
341  *  @param d (2,2) entry of the defining matrix
342  *  @param v Vector to be transformed
343  *  @param G Metric of the surrounding space, may be a Clifford unit then the next parameter is ignored
344  *  @param rl Representation label 
345  *  @return List of components of the transformed vector*/
346 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);
347
348 /** The second form of Moebius transformations defined by a 2x2 Clifford matrix M
349  *  This function takes the transformation matrix M as a single entity.
350  * 
351  *  @param M the defining matrix
352  *  @param v Vector to be transformed
353  *  @param G Metric of the surrounding space, may be a Clifford unit then the next parameter is ignored
354  *  @param rl Representation label 
355  *  @return List of components of the transformed vector*/
356 ex clifford_moebius_map(const ex & M, const ex & v, const ex & G, unsigned char rl = 0);
357
358 } // namespace GiNaC
359
360 #endif // ndef __GINAC_CLIFFORD_H__