]> www.ginac.de Git - ginac.git/blob - ginac/tensor.h
Clarify types of test suite files.
[ginac.git] / ginac / tensor.h
1 /** @file tensor.h
2  *
3  *  Interface to GiNaC's special tensors. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2020 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 #include "archive.h"
28
29 namespace GiNaC {
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 override { 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 override;
60         ex eval_indexed(const basic & i) const override;
61         bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const override;
62 protected:
63         unsigned return_type() const override { return return_types::commutative; }
64
65         // non-virtual functions in this class
66 protected:
67         void do_print(const print_context & c, unsigned level) const;
68         void do_print_latex(const print_latex & c, unsigned level) const;
69 };
70 GINAC_DECLARE_UNARCHIVER(tensdelta);
71
72
73 /** This class represents a general metric tensor which can be used to
74  *  raise/lower indices. If indexed, it must have exactly two indices of the
75  *  same type which must be of class varidx or a subclass. */
76 class tensmetric : public tensor
77 {
78         GINAC_DECLARE_REGISTERED_CLASS(tensmetric, tensor)
79
80         // functions overriding virtual functions from base classes
81 public:
82         bool info(unsigned inf) const override;
83         ex eval_indexed(const basic & i) const override;
84         bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const override;
85 protected:
86         unsigned return_type() const override { return return_types::commutative; }
87
88         // non-virtual functions in this class
89 protected:
90         void do_print(const print_context & c, unsigned level) const;
91 };
92 GINAC_DECLARE_UNARCHIVER(tensmetric);
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 override;
110         ex eval_indexed(const basic & i) const override;
111
112         /** Save (a.k.a. serialize) object into archive. */
113         void archive(archive_node& n) const override;
114         /** Read (a.k.a. deserialize) object from archive. */
115         void read_archive(const archive_node& n, lst& syms) override;
116 protected:
117         unsigned return_type() const override { return return_types::commutative; }
118
119         // non-virtual functions in this class
120 protected:
121         void do_print(const print_context & c, unsigned level) const;
122         void do_print_latex(const print_latex & c, unsigned level) const;
123
124         // member variables
125 private:
126         bool pos_sig; /**< If true, the metric is diag(-1,1,1...). Otherwise it is diag(1,-1,-1,...). */
127 };
128 GINAC_DECLARE_UNARCHIVER(minkmetric); 
129
130
131 /** This class represents an antisymmetric spinor metric tensor which
132  *  can be used to raise/lower indices of 2-component Weyl spinors. If
133  *  indexed, it must have exactly two indices of the same type which
134  *  must be of class spinidx or a subclass and have dimension 2. */
135 class spinmetric : public tensmetric
136 {
137         GINAC_DECLARE_REGISTERED_CLASS(spinmetric, tensmetric)
138
139         // functions overriding virtual functions from base classes
140 public:
141         bool info(unsigned inf) const override;
142         ex eval_indexed(const basic & i) const override;
143         bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const override;
144
145 protected:
146         void do_print(const print_context & c, unsigned level) const;
147         void do_print_latex(const print_latex & c, unsigned level) const;
148 };
149 GINAC_DECLARE_UNARCHIVER(spinmetric);
150
151
152 /** This class represents the totally antisymmetric epsilon tensor. If
153  *  indexed, all indices must be of the same type and their number must
154  *  be equal to the dimension of the index space. */
155 class tensepsilon : public tensor
156 {
157         GINAC_DECLARE_REGISTERED_CLASS(tensepsilon, tensor)
158
159         // other constructors
160 public:
161         tensepsilon(bool minkowski, bool pos_sig);
162
163         // functions overriding virtual functions from base classes
164 public:
165         bool info(unsigned inf) const override;
166         ex eval_indexed(const basic & i) const override;
167         bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const override;
168
169         /** Save (a.k.a. serialize) object into archive. */
170         void archive(archive_node& n) const override;
171         /** Read (a.k.a. deserialize) object from archive. */
172         void read_archive(const archive_node& n, lst& syms) override;
173 protected:
174         unsigned return_type() const override { return return_types::commutative; }
175
176         // non-virtual functions in this class
177 protected:
178         void do_print(const print_context & c, unsigned level) const;
179         void do_print_latex(const print_latex & c, unsigned level) const;
180
181         // member variables
182 private:
183         bool minkowski; /**< If true, tensor is in Minkowski-type space. Otherwise it is in a Euclidean space. */
184         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. */
185 };
186 GINAC_DECLARE_UNARCHIVER(tensepsilon); 
187
188
189 // utility functions
190
191 /** Create a delta tensor with specified indices. The indices must be of class
192  *  idx or a subclass. The delta tensor is always symmetric and its trace is
193  *  the dimension of the index space.
194  *
195  *  @param i1 First index
196  *  @param i2 Second index
197  *  @return newly constructed delta tensor */
198 ex delta_tensor(const ex & i1, const ex & i2);
199
200 /** Create a symmetric metric tensor with specified indices. The indices
201  *  must be of class varidx or a subclass. A metric tensor with one
202  *  covariant and one contravariant index is equivalent to the delta tensor.
203  *
204  *  @param i1 First index
205  *  @param i2 Second index
206  *  @return newly constructed metric tensor */
207 ex metric_tensor(const ex & i1, const ex & i2);
208
209 /** Create a Minkowski metric tensor with specified indices. The indices
210  *  must be of class varidx or a subclass. The Lorentz metric is a symmetric
211  *  tensor with a matrix representation of diag(1,-1,-1,...) (negative
212  *  signature, the default) or diag(-1,1,1,...) (positive signature).
213  *
214  *  @param i1 First index
215  *  @param i2 Second index
216  *  @param pos_sig Whether the signature is positive
217  *  @return newly constructed Lorentz metric tensor */
218 ex lorentz_g(const ex & i1, const ex & i2, bool pos_sig = false);
219
220 /** Create a spinor metric tensor with specified indices. The indices must be
221  *  of class spinidx or a subclass and have a dimension of 2. The spinor
222  *  metric is an antisymmetric tensor with a matrix representation of
223  *  [[ [[ 0, 1 ]], [[ -1, 0 ]] ]].
224  *
225  *  @param i1 First index
226  *  @param i2 Second index
227  *  @return newly constructed spinor metric tensor */
228 ex spinor_metric(const ex & i1, const ex & i2);
229
230 /** Create an epsilon tensor in a Euclidean space with two indices. The
231  *  indices must be of class idx or a subclass, and have a dimension of 2.
232  *
233  *  @param i1 First index
234  *  @param i2 Second index
235  *  @return newly constructed epsilon tensor */
236 ex epsilon_tensor(const ex & i1, const ex & i2);
237
238 /** Create an epsilon tensor in a Euclidean space with three indices. The
239  *  indices must be of class idx or a subclass, and have a dimension of 3.
240  *
241  *  @param i1 First index
242  *  @param i2 Second index
243  *  @param i3 Third index
244  *  @return newly constructed epsilon tensor */
245 ex epsilon_tensor(const ex & i1, const ex & i2, const ex & i3);
246
247 /** Create an epsilon tensor in a Minkowski space with four indices. The
248  *  indices must be of class varidx or a subclass, and have a dimension of 4.
249  *
250  *  @param i1 First index
251  *  @param i2 Second index
252  *  @param i3 Third index
253  *  @param i4 Fourth index
254  *  @param pos_sig Whether the signature of the metric is positive
255  *  @return newly constructed epsilon tensor */
256 ex lorentz_eps(const ex & i1, const ex & i2, const ex & i3, const ex & i4, bool pos_sig = false);
257
258 } // namespace GiNaC
259
260 #endif // ndef GINAC_TENSOR_H