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