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