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