3 * Interface to GiNaC's special tensors. */
6 * GiNaC Copyright (C) 1999-2002 Johannes Gutenberg University Mainz, Germany
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.
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.
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
23 #ifndef __GINAC_TENSOR_H__
24 #define __GINAC_TENSOR_H__
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
36 GINAC_DECLARE_REGISTERED_CLASS(tensor, basic)
40 tensor(unsigned ti) : inherited(ti) {}
42 // functions overriding virtual functions from base classes
44 unsigned return_type(void) const { return return_types::noncommutative_composite; }
48 /** This class represents the delta tensor. If indexed, it must have exactly
49 * two indices of the same type. */
50 class tensdelta : public tensor
52 GINAC_DECLARE_REGISTERED_CLASS(tensdelta, tensor)
54 // functions overriding virtual functions from base classes
56 void print(const print_context & c, unsigned level = 0) const;
57 ex eval_indexed(const basic & i) const;
58 bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
62 /** This class represents a general metric tensor which can be used to
63 * raise/lower indices. If indexed, it must have exactly two indices of the
64 * same type which must be of class varidx or a subclass. */
65 class tensmetric : public tensor
67 GINAC_DECLARE_REGISTERED_CLASS(tensmetric, tensor)
69 // functions overriding virtual functions from base classes
71 void print(const print_context & c, unsigned level = 0) const;
72 ex eval_indexed(const basic & i) const;
73 bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
77 /** This class represents a Minkowski metric tensor. It has all the
78 * properties of a metric tensor and is (as a matrix) equal to
79 * diag(1,-1,-1,...) or diag(-1,1,1,...). */
80 class minkmetric : public tensmetric
82 GINAC_DECLARE_REGISTERED_CLASS(minkmetric, tensmetric)
86 /** Construct Lorentz metric tensor with given signature. */
87 minkmetric(bool pos_sig);
89 // functions overriding virtual functions from base classes
91 void print(const print_context & c, unsigned level = 0) const;
92 ex eval_indexed(const basic & i) const;
96 bool pos_sig; /**< If true, the metric is diag(-1,1,1...). Otherwise it is diag(1,-1,-1,...). */
100 /** This class represents an antisymmetric spinor metric tensor which
101 * can be used to raise/lower indices of 2-component Weyl spinors. If
102 * indexed, it must have exactly two indices of the same type which
103 * must be of class spinidx or a subclass and have dimension 2. */
104 class spinmetric : public tensmetric
106 GINAC_DECLARE_REGISTERED_CLASS(spinmetric, tensmetric)
108 // functions overriding virtual functions from base classes
110 void print(const print_context & c, unsigned level = 0) const;
111 ex eval_indexed(const basic & i) const;
112 bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
116 /** This class represents the totally antisymmetric epsilon tensor. If
117 * indexed, all indices must be of the same type and their number must
118 * be equal to the dimension of the index space. */
119 class tensepsilon : public tensor
121 GINAC_DECLARE_REGISTERED_CLASS(tensepsilon, tensor)
123 // other constructors
125 tensepsilon(bool minkowski, bool pos_sig);
127 // functions overriding virtual functions from base classes
129 void print(const print_context & c, unsigned level = 0) const;
130 ex eval_indexed(const basic & i) const;
131 bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
135 bool minkowski; /**< If true, tensor is in Minkowski-type space. Otherwise it is in a Euclidean space. */
136 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. */
142 /** Create a delta tensor with specified indices. The indices must be of class
143 * idx or a subclass. The delta tensor is always symmetric and its trace is
144 * the dimension of the index space.
146 * @param i1 First index
147 * @param i2 Second index
148 * @return newly constructed delta tensor */
149 ex delta_tensor(const ex & i1, const ex & i2);
151 /** Create a symmetric metric tensor with specified indices. The indices
152 * must be of class varidx or a subclass. A metric tensor with one
153 * covariant and one contravariant index is equivalent to the delta tensor.
155 * @param i1 First index
156 * @param i2 Second index
157 * @return newly constructed metric tensor */
158 ex metric_tensor(const ex & i1, const ex & i2);
160 /** Create a Minkowski metric tensor with specified indices. The indices
161 * must be of class varidx or a subclass. The Lorentz metric is a symmetric
162 * tensor with a matrix representation of diag(1,-1,-1,...) (negative
163 * signature, the default) or diag(-1,1,1,...) (positive signature).
165 * @param i1 First index
166 * @param i2 Second index
167 * @param pos_sig Whether the signature is positive
168 * @return newly constructed Lorentz metric tensor */
169 ex lorentz_g(const ex & i1, const ex & i2, bool pos_sig = false);
171 /** Create a spinor metric tensor with specified indices. The indices must be
172 * of class spinidx or a subclass and have a dimension of 2. The spinor
173 * metric is an antisymmetric tensor with a matrix representation of
174 * [[ [[ 0, 1 ]], [[ -1, 0 ]] ]].
176 * @param i1 First index
177 * @param i2 Second index
178 * @return newly constructed spinor metric tensor */
179 ex spinor_metric(const ex & i1, const ex & i2);
181 /** Create an epsilon tensor in a Euclidean space with two indices. The
182 * indices must be of class idx or a subclass, and have a dimension of 2.
184 * @param i1 First index
185 * @param i2 Second index
186 * @return newly constructed epsilon tensor */
187 ex epsilon_tensor(const ex & i1, const ex & i2);
189 /** Create an epsilon tensor in a Euclidean space with three indices. The
190 * indices must be of class idx or a subclass, and have a dimension of 3.
192 * @param i1 First index
193 * @param i2 Second index
194 * @param i3 Third index
195 * @return newly constructed epsilon tensor */
196 ex epsilon_tensor(const ex & i1, const ex & i2, const ex & i3);
198 /** Create an epsilon tensor in a Minkowski space with four indices. The
199 * indices must be of class varidx or a subclass, and have a dimension of 4.
201 * @param i1 First index
202 * @param i2 Second index
203 * @param i3 Third index
204 * @param i4 Fourth index
205 * @param pos_sig Whether the signature of the metric is positive
206 * @return newly constructed epsilon tensor */
207 ex lorentz_eps(const ex & i1, const ex & i2, const ex & i3, const ex & i4, bool pos_sig = false);
209 /** Create an epsilon tensor in a 4-dimensional projection of a D-dimensional
210 * Minkowski space. It vanishes whenever one of the indices is not in the
213 * @param i1 First index
214 * @param i2 Second index
215 * @param i3 Third index
216 * @param i4 Fourth index
217 * @param pos_sig Whether the signature of the metric is positive
218 * @return newly constructed epsilon tensor */
219 ex eps0123(const ex & i1, const ex & i2, const ex & i3, const ex & i4, bool pos_sig = false);
223 #endif // ndef __GINAC_TENSOR_H__