]> www.ginac.de Git - ginac.git/blob - ginac/tensor.h
ac991d5f666f5e47d621e1829bdf5f3bd4b2c048
[ginac.git] / ginac / tensor.h
1 /** @file tensor.h
2  *
3  *  Interface to GiNaC's special tensors. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2001 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);
41
42         // functions overriding virtual functions from bases classes
43 public:
44         ex subs(const lst & ls, const lst & lr) const;
45 protected:
46         unsigned return_type(void) const { return return_types::noncommutative_composite; }
47 };
48
49
50 /** This class represents the delta tensor. If indexed, it must have exactly
51  *  two indices of the same type. */
52 class tensdelta : public tensor
53 {
54         GINAC_DECLARE_REGISTERED_CLASS(tensdelta, tensor)
55
56         // functions overriding virtual functions from bases classes
57 public:
58         void print(std::ostream & os, unsigned upper_precedence=0) const;
59         ex eval_indexed(const basic & i) const;
60         bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
61 };
62
63
64 /** This class represents a general metric tensor which can be used to
65  *  raise/lower indices. If indexed, it must have exactly two indices of the
66  *  same type which must be of class varidx or a subclass. */
67 class tensmetric : public tensor
68 {
69         GINAC_DECLARE_REGISTERED_CLASS(tensmetric, tensor)
70
71         // functions overriding virtual functions from bases classes
72 public:
73         void print(std::ostream & os, unsigned upper_precedence=0) const;
74         ex eval_indexed(const basic & i) const;
75         bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
76 };
77
78
79 /** This class represents a Minkowski metric tensor. It has all the
80  *  properties of a metric tensor and is (as a matrix) equal to
81  *  diag(1,-1,-1,...) or diag(-1,1,1,...). */
82 class minkmetric : public tensmetric
83 {
84         GINAC_DECLARE_REGISTERED_CLASS(minkmetric, tensmetric)
85
86         // other constructors
87 public:
88         /** Construct Lorentz metric tensor with given signature. */
89         minkmetric(bool pos_sig);
90
91         // functions overriding virtual functions from bases classes
92 public:
93         void print(std::ostream & os, unsigned upper_precedence=0) const;
94         ex eval_indexed(const basic & i) const;
95
96         // member variables
97 private:
98         bool pos_sig; /**< If true, the metric is diag(-1,1,1...). Otherwise it is diag(1,-1,-1,...). */
99 };
100
101
102 /** This class represents the totally antisymmetric epsilon tensor. If
103  *  indexed, all indices must be of the same type and their number must
104  *  be equal to the dimension of the index space. */
105 class tensepsilon : public tensor
106 {
107         GINAC_DECLARE_REGISTERED_CLASS(tensepsilon, tensor)
108
109         // other constructors
110 public:
111         tensepsilon(bool minkowski, bool pos_sig);
112
113         // functions overriding virtual functions from bases classes
114 public:
115         void print(std::ostream & os, unsigned upper_precedence=0) const;
116         ex eval_indexed(const basic & i) const;
117
118         // member variables
119 private:
120         bool minkowski; /**< If true, tensor is in Minkowski-type space. Otherwise it is in a Euclidean space. */
121         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. */
122 };
123
124
125 // utility functions
126 inline const tensor &ex_to_tensor(const ex &e)
127 {
128         return static_cast<const tensor &>(*e.bp);
129 }
130
131 /** Create a delta tensor with specified indices. The indices must be of class
132  *  idx or a subclass. The delta tensor is always symmetric and its trace is
133  *  the dimension of the index space.
134  *
135  *  @param i1 First index
136  *  @param i2 Second index
137  *  @return newly constructed delta tensor */
138 ex delta_tensor(const ex & i1, const ex & i2);
139
140 /** Create a symmetric metric tensor with specified indices. The indices
141  *  must be of class varidx or a subclass. A metric tensor with one
142  *  covariant and one contravariant index is equivalent to the delta tensor.
143  *
144  *  @param i1 First index
145  *  @param i2 Second index
146  *  @return newly constructed metric tensor */
147 ex metric_tensor(const ex & i1, const ex & i2);
148
149 /** Create a Minkowski metric tensor with specified indices. The indices
150  *  must be of class varidx or a subclass. The Lorentz metric is a symmetric
151  *  tensor with a matrix representation of diag(1,-1,-1,...) (negative
152  *  signature, the default) or diag(-1,1,1,...) (positive signature).
153  *
154  *  @param i1 First index
155  *  @param i2 Second index
156  *  @param pos_sig Whether the signature is positive
157  *  @return newly constructed Lorentz metric tensor */
158 ex lorentz_g(const ex & i1, const ex & i2, bool pos_sig = false);
159
160 /** Create an epsilon tensor in a Euclidean space with two indices. The
161  *  indices must be of class idx or a subclass, and have a dimension of 2.
162  *
163  *  @param i1 First index
164  *  @param i2 Second index
165  *  @return newly constructed epsilon tensor */
166 ex epsilon_tensor(const ex & i1, const ex & i2);
167
168 /** Create an epsilon tensor in a Euclidean space with three indices. The
169  *  indices must be of class idx or a subclass, and have a dimension of 3.
170  *
171  *  @param i1 First index
172  *  @param i2 Second index
173  *  @param i3 Third index
174  *  @return newly constructed epsilon tensor */
175 ex epsilon_tensor(const ex & i1, const ex & i2, const ex & i3);
176
177 /** Create an epsilon tensor in a Minkowski space with four indices. The
178  *  indices must be of class varidx or a subclass, and have a dimension of 4.
179  *
180  *  @param i1 First index
181  *  @param i2 Second index
182  *  @param i3 Third index
183  *  @param i4 Fourth index
184  *  @param pos_sig Whether the signature of the metric is positive
185  *  @return newly constructed epsilon tensor */
186 ex lorentz_eps(const ex & i1, const ex & i2, const ex & i3, const ex & i4, bool pos_sig = false);
187
188 } // namespace GiNaC
189
190 #endif // ndef __GINAC_TENSOR_H__