]> www.ginac.de Git - ginac.git/blob - ginac/tensor.h
* AUTHORS: Add Chris Dams as contributor of patches.
[ginac.git] / ginac / tensor.h
1 /** @file tensor.h
2  *
3  *  Interface to GiNaC's special tensors. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2002 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_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(unsigned ti) : inherited(ti) {}
41
42         // functions overriding virtual functions from base classes
43 protected:
44         unsigned return_type(void) 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         void print(const print_context & c, unsigned level = 0) const;
64         ex eval_indexed(const basic & i) const;
65         bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
66 };
67
68
69 /** This class represents a general metric tensor which can be used to
70  *  raise/lower indices. If indexed, it must have exactly two indices of the
71  *  same type which must be of class varidx or a subclass. */
72 class tensmetric : public tensor
73 {
74         GINAC_DECLARE_REGISTERED_CLASS(tensmetric, tensor)
75
76         // functions overriding virtual functions from base classes
77 public:
78         void print(const print_context & c, unsigned level = 0) const;
79         ex eval_indexed(const basic & i) const;
80         bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
81 };
82
83
84 /** This class represents a Minkowski metric tensor. It has all the
85  *  properties of a metric tensor and is (as a matrix) equal to
86  *  diag(1,-1,-1,...) or diag(-1,1,1,...). */
87 class minkmetric : public tensmetric
88 {
89         GINAC_DECLARE_REGISTERED_CLASS(minkmetric, tensmetric)
90
91         // other constructors
92 public:
93         /** Construct Lorentz metric tensor with given signature. */
94         minkmetric(bool pos_sig);
95
96         // functions overriding virtual functions from base classes
97 public:
98         void print(const print_context & c, unsigned level = 0) const;
99         ex eval_indexed(const basic & i) const;
100
101         // member variables
102 private:
103         bool pos_sig; /**< If true, the metric is diag(-1,1,1...). Otherwise it is diag(1,-1,-1,...). */
104 };
105
106
107 /** This class represents an antisymmetric spinor metric tensor which
108  *  can be used to raise/lower indices of 2-component Weyl spinors. If
109  *  indexed, it must have exactly two indices of the same type which
110  *  must be of class spinidx or a subclass and have dimension 2. */
111 class spinmetric : public tensmetric
112 {
113         GINAC_DECLARE_REGISTERED_CLASS(spinmetric, tensmetric)
114
115         // functions overriding virtual functions from base classes
116 public:
117         void print(const print_context & c, unsigned level = 0) const;
118         ex eval_indexed(const basic & i) const;
119         bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
120 };
121
122
123 /** This class represents the totally antisymmetric epsilon tensor. If
124  *  indexed, all indices must be of the same type and their number must
125  *  be equal to the dimension of the index space. */
126 class tensepsilon : public tensor
127 {
128         GINAC_DECLARE_REGISTERED_CLASS(tensepsilon, tensor)
129
130         // other constructors
131 public:
132         tensepsilon(bool minkowski, bool pos_sig);
133
134         // functions overriding virtual functions from base classes
135 public:
136         void print(const print_context & c, unsigned level = 0) const;
137         ex eval_indexed(const basic & i) const;
138         bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
139
140         // member variables
141 private:
142         bool minkowski; /**< If true, tensor is in Minkowski-type space. Otherwise it is in a Euclidean space. */
143         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. */
144 };
145
146
147 // utility functions
148
149 /** Create a delta tensor with specified indices. The indices must be of class
150  *  idx or a subclass. The delta tensor is always symmetric and its trace is
151  *  the dimension of the index space.
152  *
153  *  @param i1 First index
154  *  @param i2 Second index
155  *  @return newly constructed delta tensor */
156 ex delta_tensor(const ex & i1, const ex & i2);
157
158 /** Create a symmetric metric tensor with specified indices. The indices
159  *  must be of class varidx or a subclass. A metric tensor with one
160  *  covariant and one contravariant index is equivalent to the delta tensor.
161  *
162  *  @param i1 First index
163  *  @param i2 Second index
164  *  @return newly constructed metric tensor */
165 ex metric_tensor(const ex & i1, const ex & i2);
166
167 /** Create a Minkowski metric tensor with specified indices. The indices
168  *  must be of class varidx or a subclass. The Lorentz metric is a symmetric
169  *  tensor with a matrix representation of diag(1,-1,-1,...) (negative
170  *  signature, the default) or diag(-1,1,1,...) (positive signature).
171  *
172  *  @param i1 First index
173  *  @param i2 Second index
174  *  @param pos_sig Whether the signature is positive
175  *  @return newly constructed Lorentz metric tensor */
176 ex lorentz_g(const ex & i1, const ex & i2, bool pos_sig = false);
177
178 /** Create a spinor metric tensor with specified indices. The indices must be
179  *  of class spinidx or a subclass and have a dimension of 2. The spinor
180  *  metric is an antisymmetric tensor with a matrix representation of
181  *  [[ [[ 0, 1 ]], [[ -1, 0 ]] ]].
182  *
183  *  @param i1 First index
184  *  @param i2 Second index
185  *  @return newly constructed spinor metric tensor */
186 ex spinor_metric(const ex & i1, const ex & i2);
187
188 /** Create an epsilon tensor in a Euclidean space with two indices. The
189  *  indices must be of class idx or a subclass, and have a dimension of 2.
190  *
191  *  @param i1 First index
192  *  @param i2 Second index
193  *  @return newly constructed epsilon tensor */
194 ex epsilon_tensor(const ex & i1, const ex & i2);
195
196 /** Create an epsilon tensor in a Euclidean space with three indices. The
197  *  indices must be of class idx or a subclass, and have a dimension of 3.
198  *
199  *  @param i1 First index
200  *  @param i2 Second index
201  *  @param i3 Third index
202  *  @return newly constructed epsilon tensor */
203 ex epsilon_tensor(const ex & i1, const ex & i2, const ex & i3);
204
205 /** Create an epsilon tensor in a Minkowski space with four indices. The
206  *  indices must be of class varidx or a subclass, and have a dimension of 4.
207  *
208  *  @param i1 First index
209  *  @param i2 Second index
210  *  @param i3 Third index
211  *  @param i4 Fourth index
212  *  @param pos_sig Whether the signature of the metric is positive
213  *  @return newly constructed epsilon tensor */
214 ex lorentz_eps(const ex & i1, const ex & i2, const ex & i3, const ex & i4, bool pos_sig = false);
215
216 } // namespace GiNaC
217
218 #endif // ndef __GINAC_TENSOR_H__