]> www.ginac.de Git - ginac.git/blob - ginac/clifford.h
obvious patch from Chris Dams
[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-2004 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 namespace GiNaC {
32
33
34 /** This class holds an object representing an element of the Clifford
35  *  algebra (the Dirac gamma matrices). These objects only carry Lorentz
36  *  indices. Spinor indices are hidden. A representation label (an unsigned
37  *  8-bit integer) is used to distinguish elements from different Clifford
38  *  algebras (objects with different labels commute). */
39 class clifford : public indexed
40 {
41         GINAC_DECLARE_REGISTERED_CLASS(clifford, indexed)
42
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);
47
48         // internal constructors
49         clifford(unsigned char rl, const ex & metr, const exvector & v, bool discardable = false);
50         clifford(unsigned char rl, const ex & metr, std::auto_ptr<exvector> vp);
51
52         // functions overriding virtual functions from base classes
53 protected:
54         ex eval_ncmul(const exvector & v) const;
55         bool match_same_type(const basic & other) const;
56         ex thiscontainer(const exvector & v) const;
57         ex thiscontainer(std::auto_ptr<exvector> vp) const;
58         unsigned return_type() const { return return_types::noncommutative; }
59         unsigned return_type_tinfo() const { return TINFO_clifford + representation_label; }
60
61         // non-virtual functions in this class
62 public:
63         unsigned char get_representation_label() const { return representation_label; }
64         ex get_metric() const { return metric; }
65         ex get_metric(const ex & i, const ex & j) const;
66         bool same_metric(const ex & other) const;
67
68 protected:
69         void do_print_dflt(const print_dflt & c, unsigned level) const;
70         void do_print_latex(const print_latex & c, unsigned level) const;
71
72         // member variables
73 private:
74         unsigned char representation_label; /**< Representation label to distinguish independent spin lines */
75         ex metric;
76 };
77
78
79 /** This class represents the Clifford algebra unity element. */
80 class diracone : public tensor
81 {
82         GINAC_DECLARE_REGISTERED_CLASS(diracone, tensor)
83
84         // non-virtual functions in this class
85 protected:
86         void do_print(const print_context & c, unsigned level) const;
87         void do_print_latex(const print_latex & c, unsigned level) const;
88 };
89
90
91 /** This class represents the Clifford algebra generators (units). */
92 class cliffordunit : public tensor
93 {
94         GINAC_DECLARE_REGISTERED_CLASS(cliffordunit, tensor)
95
96         // other constructors
97 protected:
98         cliffordunit(unsigned ti) : inherited(ti) {}
99                                                                                                     
100         // functions overriding virtual functions from base classes
101 public:
102         bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
103
104         // non-virtual functions in this class
105 protected:
106         void do_print(const print_context & c, unsigned level) const;
107         void do_print_latex(const print_latex & c, unsigned level) const;
108 };
109
110
111 /** This class represents the Dirac gamma Lorentz vector. */
112 class diracgamma : public cliffordunit
113 {
114         GINAC_DECLARE_REGISTERED_CLASS(diracgamma, cliffordunit)
115
116         // functions overriding virtual functions from base classes
117 public:
118         bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
119
120         // non-virtual functions in this class
121 protected:
122         void do_print(const print_context & c, unsigned level) const;
123         void do_print_latex(const print_latex & c, unsigned level) const;
124 };
125
126
127 /** This class represents the Dirac gamma5 object which anticommutes with
128  *  all other gammas. */
129 class diracgamma5 : public tensor
130 {
131         GINAC_DECLARE_REGISTERED_CLASS(diracgamma5, tensor)
132
133         // functions overriding virtual functions from base classes
134         ex conjugate() const;
135
136         // non-virtual functions in this class
137 protected:
138         void do_print(const print_context & c, unsigned level) const;
139         void do_print_latex(const print_latex & c, unsigned level) const;
140 };
141
142
143 /** This class represents the Dirac gammaL object which behaves like
144  *  1/2 (1-gamma5). */
145 class diracgammaL : public tensor
146 {
147         GINAC_DECLARE_REGISTERED_CLASS(diracgammaL, tensor)
148
149         // functions overriding virtual functions from base classes
150         ex conjugate() const;
151
152         // non-virtual functions in this class
153 protected:
154         void do_print(const print_context & c, unsigned level) const;
155         void do_print_latex(const print_latex & c, unsigned level) const;
156 };
157
158
159 /** This class represents the Dirac gammaL object which behaves like
160  *  1/2 (1+gamma5). */
161 class diracgammaR : public tensor
162 {
163         GINAC_DECLARE_REGISTERED_CLASS(diracgammaR, tensor)
164
165         // functions overriding virtual functions from base classes
166         ex conjugate() const;
167
168         // non-virtual functions in this class
169 protected:
170         void do_print(const print_context & c, unsigned level) const;
171         void do_print_latex(const print_latex & c, unsigned level) const;
172 };
173
174
175 // global functions
176
177 /** Specialization of is_exactly_a<clifford>(obj) for clifford objects. */
178 template<> inline bool is_exactly_a<clifford>(const basic & obj)
179 {
180         return obj.tinfo()==TINFO_clifford;
181 }
182
183 /** Create a Clifford unity object.
184  *
185  *  @param rl Representation label
186  *  @return newly constructed object */
187 ex dirac_ONE(unsigned char rl = 0);
188
189 /** Create a Clifford unit object.
190  *
191  *  @param mu Index (must be of class varidx or a derived class)
192  *  @param metr Metric (should be of class tensmetric or a derived class, or a symmetric matrix)
193  *  @param rl Representation label
194  *  @return newly constructed Clifford unit object */
195 ex clifford_unit(const ex & mu, const ex & metr, unsigned char rl = 0);
196
197 /** Create a Dirac gamma object.
198  *
199  *  @param mu Index (must be of class varidx or a derived class)
200  *  @param rl Representation label
201  *  @return newly constructed gamma object */
202 ex dirac_gamma(const ex & mu, unsigned char rl = 0);
203
204 /** Create a Dirac gamma5 object.
205  *
206  *  @param rl Representation label
207  *  @return newly constructed object */
208 ex dirac_gamma5(unsigned char rl = 0);
209
210 /** Create a Dirac gammaL object.
211  *
212  *  @param rl Representation label
213  *  @return newly constructed object */
214 ex dirac_gammaL(unsigned char rl = 0);
215
216 /** Create a Dirac gammaR object.
217  *
218  *  @param rl Representation label
219  *  @return newly constructed object */
220 ex dirac_gammaR(unsigned char rl = 0);
221
222 /** Create a term of the form e_mu * gamma~mu with a unique index mu.
223  *
224  *  @param e Original expression
225  *  @param dim Dimension of index
226  *  @param rl Representation label */
227 ex dirac_slash(const ex & e, const ex & dim, unsigned char rl = 0);
228
229 /** Calculate the trace of an expression containing gamma objects with
230  *  a specified representation label. The computed trace is a linear
231  *  functional that is equal to the usual trace only in D = 4 dimensions.
232  *  In particular, the functional is not always cyclic in D != 4 dimensions
233  *  when gamma5 is involved.
234  *
235  *  @param e Expression to take the trace of
236  *  @param rl Representation label
237  *  @param trONE Expression to be returned as the trace of the unit matrix */
238 ex dirac_trace(const ex & e, unsigned char rl = 0, const ex & trONE = 4);
239
240 /** Bring all products of clifford objects in an expression into a canonical
241  *  order. This is not necessarily the most simple form but it will allow
242  *  to check two expressions for equality. */
243 ex canonicalize_clifford(const ex & e);
244
245 /** Automorphism of the Clifford algebra, simply changes signs of all
246  *  clifford units. */
247 ex clifford_prime(const ex & e);
248
249 /** Main anti-automorphism of the Clifford algebra: makes reversion
250  *  and changes signs of all clifford units. */
251 inline ex clifford_bar(const ex & e) { return clifford_prime(e.conjugate()); }
252
253 /** Reversion of the Clifford algebra, coincides with the conjugate(). */
254 inline ex clifford_star(const ex & e) { return e.conjugate(); }
255
256 ex delete_ONE(const ex &e);
257
258 /** Calculation of the norm in the Clifford algebra. */
259 ex clifford_norm(const ex & e);
260
261 /** Calculation of the inverse in the Clifford algebra. */
262 ex clifford_inverse(const ex & e);
263
264 /** List or vector conversion into the Clifford vector.
265  *
266  *  @param v List or vector of coordinates
267  *  @param mu Index (must be of class varidx or a derived class)
268  *  @param metr Metric (should be of class tensmetric or a derived class, or a symmetric matrix)
269  *  @param rl Representation label
270  *  @return Clifford vector with given components */
271 ex lst_to_clifford(const ex & v, const ex & mu,  const ex & metr, unsigned char rl = 0);
272
273 } // namespace GiNaC
274
275 #endif // ndef __GINAC_CLIFFORD_H__