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