]> www.ginac.de Git - ginac.git/blob - ginac/tensor.h
Wipe out remnants of custom RTTI.
[ginac.git] / ginac / tensor.h
1 /** @file tensor.h
2  *
3  *  Interface to GiNaC's special tensors. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2008 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_TENSOR_H__
24 #define __GINAC_TENSOR_H__
25
26 #include "ex.h"
27
28 namespace GiNaC {
29
30
31 /** This class holds one of GiNaC's predefined special tensors such as the
32  *  delta and the metric tensors. They are represented without indices.
33  *  To attach indices to them, wrap them in an object of class indexed. */
34 class tensor : public basic
35 {
36         GINAC_DECLARE_REGISTERED_CLASS(tensor, basic)
37
38         // functions overriding virtual functions from base classes
39 protected:
40         unsigned return_type() const { return return_types::noncommutative_composite; }
41
42         // non-virtual functions in this class
43 public:
44         /** Replace dummy index in contracted-with object by the contracting
45          *  object's second index (used internally for delta and metric tensor
46          *  contractions. */
47         bool replace_contr_index(exvector::iterator self, exvector::iterator other) const;
48 };
49
50
51 /** This class represents the delta tensor. If indexed, it must have exactly
52  *  two indices of the same type. */
53 class tensdelta : public tensor
54 {
55         GINAC_DECLARE_REGISTERED_CLASS(tensdelta, tensor)
56
57         // functions overriding virtual functions from base classes
58 public:
59         bool info(unsigned inf) const;
60         ex eval_indexed(const basic & i) const;
61         bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
62
63         // non-virtual functions in this class
64 protected:
65         unsigned return_type() const { return return_types::commutative; }
66         void do_print(const print_context & c, unsigned level) const;
67         void do_print_latex(const print_latex & c, unsigned level) const;
68 };
69
70
71 /** This class represents a general metric tensor which can be used to
72  *  raise/lower indices. If indexed, it must have exactly two indices of the
73  *  same type which must be of class varidx or a subclass. */
74 class tensmetric : public tensor
75 {
76         GINAC_DECLARE_REGISTERED_CLASS(tensmetric, tensor)
77
78         // functions overriding virtual functions from base classes
79 public:
80         bool info(unsigned inf) const;
81         ex eval_indexed(const basic & i) const;
82         bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
83
84         // non-virtual functions in this class
85 protected:
86         unsigned return_type() const { return return_types::commutative; }
87         void do_print(const print_context & c, unsigned level) const;
88 };
89
90
91 /** This class represents a Minkowski metric tensor. It has all the
92  *  properties of a metric tensor and is (as a matrix) equal to
93  *  diag(1,-1,-1,...) or diag(-1,1,1,...). */
94 class minkmetric : public tensmetric
95 {
96         GINAC_DECLARE_REGISTERED_CLASS(minkmetric, tensmetric)
97
98         // other constructors
99 public:
100         /** Construct Lorentz metric tensor with given signature. */
101         minkmetric(bool pos_sig);
102
103         // functions overriding virtual functions from base classes
104 public:
105         bool info(unsigned inf) const;
106         ex eval_indexed(const basic & i) const;
107
108         // non-virtual functions in this class
109 protected:
110         unsigned return_type() const { return return_types::commutative; }
111         void do_print(const print_context & c, unsigned level) const;
112         void do_print_latex(const print_latex & c, unsigned level) const;
113
114         // member variables
115 private:
116         bool pos_sig; /**< If true, the metric is diag(-1,1,1...). Otherwise it is diag(1,-1,-1,...). */
117 };
118
119
120 /** This class represents an antisymmetric spinor metric tensor which
121  *  can be used to raise/lower indices of 2-component Weyl spinors. If
122  *  indexed, it must have exactly two indices of the same type which
123  *  must be of class spinidx or a subclass and have dimension 2. */
124 class spinmetric : public tensmetric
125 {
126         GINAC_DECLARE_REGISTERED_CLASS(spinmetric, tensmetric)
127
128         // functions overriding virtual functions from base classes
129 public:
130         bool info(unsigned inf) const;
131         ex eval_indexed(const basic & i) const;
132         bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
133
134         // non-virtual functions in this class
135 protected:
136         void do_print(const print_context & c, unsigned level) const;
137         void do_print_latex(const print_latex & c, unsigned level) const;
138 };
139
140
141 /** This class represents the totally antisymmetric epsilon tensor. If
142  *  indexed, all indices must be of the same type and their number must
143  *  be equal to the dimension of the index space. */
144 class tensepsilon : public tensor
145 {
146         GINAC_DECLARE_REGISTERED_CLASS(tensepsilon, tensor)
147
148         // other constructors
149 public:
150         tensepsilon(bool minkowski, bool pos_sig);
151
152         // functions overriding virtual functions from base classes
153 public:
154         bool info(unsigned inf) const;
155         ex eval_indexed(const basic & i) const;
156         bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
157
158         // non-virtual functions in this class
159 protected:
160         unsigned return_type() const { return return_types::commutative; }
161         void do_print(const print_context & c, unsigned level) const;
162         void do_print_latex(const print_latex & c, unsigned level) const;
163
164         // member variables
165 private:
166         bool minkowski; /**< If true, tensor is in Minkowski-type space. Otherwise it is in a Euclidean space. */
167         bool pos_sig;   /**< If true, the metric is assumed to be diag(-1,1,1...). Otherwise it is diag(1,-1,-1,...). This is only relevant if minkowski = true. */
168 };
169
170
171 // utility functions
172
173 /** Create a delta tensor with specified indices. The indices must be of class
174  *  idx or a subclass. The delta tensor is always symmetric and its trace is
175  *  the dimension of the index space.
176  *
177  *  @param i1 First index
178  *  @param i2 Second index
179  *  @return newly constructed delta tensor */
180 ex delta_tensor(const ex & i1, const ex & i2);
181
182 /** Create a symmetric metric tensor with specified indices. The indices
183  *  must be of class varidx or a subclass. A metric tensor with one
184  *  covariant and one contravariant index is equivalent to the delta tensor.
185  *
186  *  @param i1 First index
187  *  @param i2 Second index
188  *  @return newly constructed metric tensor */
189 ex metric_tensor(const ex & i1, const ex & i2);
190
191 /** Create a Minkowski metric tensor with specified indices. The indices
192  *  must be of class varidx or a subclass. The Lorentz metric is a symmetric
193  *  tensor with a matrix representation of diag(1,-1,-1,...) (negative
194  *  signature, the default) or diag(-1,1,1,...) (positive signature).
195  *
196  *  @param i1 First index
197  *  @param i2 Second index
198  *  @param pos_sig Whether the signature is positive
199  *  @return newly constructed Lorentz metric tensor */
200 ex lorentz_g(const ex & i1, const ex & i2, bool pos_sig = false);
201
202 /** Create a spinor metric tensor with specified indices. The indices must be
203  *  of class spinidx or a subclass and have a dimension of 2. The spinor
204  *  metric is an antisymmetric tensor with a matrix representation of
205  *  [[ [[ 0, 1 ]], [[ -1, 0 ]] ]].
206  *
207  *  @param i1 First index
208  *  @param i2 Second index
209  *  @return newly constructed spinor metric tensor */
210 ex spinor_metric(const ex & i1, const ex & i2);
211
212 /** Create an epsilon tensor in a Euclidean space with two indices. The
213  *  indices must be of class idx or a subclass, and have a dimension of 2.
214  *
215  *  @param i1 First index
216  *  @param i2 Second index
217  *  @return newly constructed epsilon tensor */
218 ex epsilon_tensor(const ex & i1, const ex & i2);
219
220 /** Create an epsilon tensor in a Euclidean space with three indices. The
221  *  indices must be of class idx or a subclass, and have a dimension of 3.
222  *
223  *  @param i1 First index
224  *  @param i2 Second index
225  *  @param i3 Third index
226  *  @return newly constructed epsilon tensor */
227 ex epsilon_tensor(const ex & i1, const ex & i2, const ex & i3);
228
229 /** Create an epsilon tensor in a Minkowski space with four indices. The
230  *  indices must be of class varidx or a subclass, and have a dimension of 4.
231  *
232  *  @param i1 First index
233  *  @param i2 Second index
234  *  @param i3 Third index
235  *  @param i4 Fourth index
236  *  @param pos_sig Whether the signature of the metric is positive
237  *  @return newly constructed epsilon tensor */
238 ex lorentz_eps(const ex & i1, const ex & i2, const ex & i3, const ex & i4, bool pos_sig = false);
239
240 } // namespace GiNaC
241
242 #endif // ndef __GINAC_TENSOR_H__