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