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