]> www.ginac.de Git - ginac.git/blob - ginac/tensor.cpp
7ab2ef91cde6f0472b680426eca8fcfa616adde2
[ginac.git] / ginac / tensor.cpp
1 /** @file tensor.cpp
2  *
3  *  Implementation of 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 #include <stdexcept>
24 #include <vector>
25
26 #include "tensor.h"
27 #include "idx.h"
28 #include "indexed.h"
29 #include "symmetry.h"
30 #include "relational.h"
31 #include "lst.h"
32 #include "numeric.h"
33 #include "matrix.h"
34 #include "print.h"
35 #include "archive.h"
36 #include "utils.h"
37
38 namespace GiNaC {
39
40 GINAC_IMPLEMENT_REGISTERED_CLASS(tensor, basic)
41 GINAC_IMPLEMENT_REGISTERED_CLASS(tensdelta, tensor)
42 GINAC_IMPLEMENT_REGISTERED_CLASS(tensmetric, tensor)
43 GINAC_IMPLEMENT_REGISTERED_CLASS(minkmetric, tensmetric)
44 GINAC_IMPLEMENT_REGISTERED_CLASS(spinmetric, tensmetric)
45 GINAC_IMPLEMENT_REGISTERED_CLASS(tensepsilon, tensor)
46
47 //////////
48 // default ctor, dtor, copy ctor, assignment operator and helpers
49 //////////
50
51 DEFAULT_CTORS(tensor)
52 DEFAULT_CTORS(tensdelta)
53 DEFAULT_CTORS(tensmetric)
54 DEFAULT_COPY(spinmetric)
55 DEFAULT_DESTROY(spinmetric)
56 DEFAULT_DESTROY(minkmetric)
57 DEFAULT_DESTROY(tensepsilon)
58
59 minkmetric::minkmetric() : pos_sig(false)
60 {
61         tinfo_key = TINFO_minkmetric;
62 }
63
64 spinmetric::spinmetric()
65 {
66         tinfo_key = TINFO_spinmetric;
67 }
68
69 minkmetric::minkmetric(bool ps) : pos_sig(ps)
70 {
71         tinfo_key = TINFO_minkmetric;
72 }
73
74 void minkmetric::copy(const minkmetric & other)
75 {
76         inherited::copy(other);
77         pos_sig = other.pos_sig;
78 }
79
80 tensepsilon::tensepsilon() : minkowski(false), pos_sig(false)
81 {
82         tinfo_key = TINFO_tensepsilon;
83 }
84
85 tensepsilon::tensepsilon(bool mink, bool ps) : minkowski(mink), pos_sig(ps)
86 {
87         tinfo_key = TINFO_tensepsilon;
88 }
89
90 void tensepsilon::copy(const tensepsilon & other)
91 {
92         inherited::copy(other);
93         minkowski = other.minkowski;
94         pos_sig = other.pos_sig;
95 }
96
97 //////////
98 // archiving
99 //////////
100
101 DEFAULT_ARCHIVING(tensor)
102 DEFAULT_ARCHIVING(tensdelta)
103 DEFAULT_ARCHIVING(tensmetric)
104 DEFAULT_ARCHIVING(spinmetric)
105 DEFAULT_UNARCHIVE(minkmetric)
106 DEFAULT_UNARCHIVE(tensepsilon)
107
108 minkmetric::minkmetric(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
109 {
110         n.find_bool("pos_sig", pos_sig);
111 }
112
113 void minkmetric::archive(archive_node &n) const
114 {
115         inherited::archive(n);
116         n.add_bool("pos_sig", pos_sig);
117 }
118
119 tensepsilon::tensepsilon(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
120 {
121         n.find_bool("minkowski", minkowski);
122         n.find_bool("pos_sig", pos_sig);
123 }
124
125 void tensepsilon::archive(archive_node &n) const
126 {
127         inherited::archive(n);
128         n.add_bool("minkowski", minkowski);
129         n.add_bool("pos_sig", pos_sig);
130 }
131
132 //////////
133 // functions overriding virtual functions from base classes
134 //////////
135
136 DEFAULT_COMPARE(tensor)
137 DEFAULT_COMPARE(tensdelta)
138 DEFAULT_COMPARE(tensmetric)
139 DEFAULT_COMPARE(spinmetric)
140
141 int minkmetric::compare_same_type(const basic & other) const
142 {
143         GINAC_ASSERT(is_a<minkmetric>(other));
144         const minkmetric &o = static_cast<const minkmetric &>(other);
145
146         if (pos_sig != o.pos_sig)
147                 return pos_sig ? -1 : 1;
148         else
149                 return inherited::compare_same_type(other);
150 }
151
152 int tensepsilon::compare_same_type(const basic & other) const
153 {
154         GINAC_ASSERT(is_a<tensepsilon>(other));
155         const tensepsilon &o = static_cast<const tensepsilon &>(other);
156
157         if (minkowski != o.minkowski)
158                 return minkowski ? -1 : 1;
159         else if (pos_sig != o.pos_sig)
160                 return pos_sig ? -1 : 1;
161         else
162                 return inherited::compare_same_type(other);
163 }
164
165 DEFAULT_PRINT_LATEX(tensdelta, "delta", "\\delta")
166 DEFAULT_PRINT(tensmetric, "g")
167 DEFAULT_PRINT_LATEX(minkmetric, "eta", "\\eta")
168 DEFAULT_PRINT_LATEX(spinmetric, "eps", "\\varepsilon")
169 DEFAULT_PRINT_LATEX(tensepsilon, "eps", "\\varepsilon")
170
171 /** Automatic symbolic evaluation of an indexed delta tensor. */
172 ex tensdelta::eval_indexed(const basic & i) const
173 {
174         GINAC_ASSERT(is_a<indexed>(i));
175         GINAC_ASSERT(i.nops() == 3);
176         GINAC_ASSERT(is_a<tensdelta>(i.op(0)));
177
178         const idx & i1 = ex_to<idx>(i.op(1));
179         const idx & i2 = ex_to<idx>(i.op(2));
180
181         // Trace of delta tensor is the dimension of the space
182         if (is_dummy_pair(i1, i2))
183                 return i1.get_dim();
184
185         // Numeric evaluation
186         if (static_cast<const indexed &>(i).all_index_values_are(info_flags::integer)) {
187                 int n1 = ex_to<numeric>(i1.get_value()).to_int(), n2 = ex_to<numeric>(i2.get_value()).to_int();
188                 if (n1 == n2)
189                         return _ex1;
190                 else
191                         return _ex0;
192         }
193
194         // No further simplifications
195         return i.hold();
196 }
197
198 /** Automatic symbolic evaluation of an indexed metric tensor. */
199 ex tensmetric::eval_indexed(const basic & i) const
200 {
201         GINAC_ASSERT(is_a<indexed>(i));
202         GINAC_ASSERT(i.nops() == 3);
203         GINAC_ASSERT(is_a<tensmetric>(i.op(0)));
204         GINAC_ASSERT(is_a<varidx>(i.op(1)));
205         GINAC_ASSERT(is_a<varidx>(i.op(2)));
206
207         const varidx & i1 = ex_to<varidx>(i.op(1));
208         const varidx & i2 = ex_to<varidx>(i.op(2));
209
210         // A metric tensor with one covariant and one contravariant index gets
211         // replaced by a delta tensor
212         if (i1.is_covariant() != i2.is_covariant())
213                 return delta_tensor(i1, i2);
214
215         // No further simplifications
216         return i.hold();
217 }
218
219 /** Automatic symbolic evaluation of an indexed Lorentz metric tensor. */
220 ex minkmetric::eval_indexed(const basic & i) const
221 {
222         GINAC_ASSERT(is_a<indexed>(i));
223         GINAC_ASSERT(i.nops() == 3);
224         GINAC_ASSERT(is_a<minkmetric>(i.op(0)));
225         GINAC_ASSERT(is_a<varidx>(i.op(1)));
226         GINAC_ASSERT(is_a<varidx>(i.op(2)));
227
228         const varidx & i1 = ex_to<varidx>(i.op(1));
229         const varidx & i2 = ex_to<varidx>(i.op(2));
230
231         // Numeric evaluation
232         if (static_cast<const indexed &>(i).all_index_values_are(info_flags::nonnegint)) {
233                 int n1 = ex_to<numeric>(i1.get_value()).to_int(), n2 = ex_to<numeric>(i2.get_value()).to_int();
234                 if (n1 != n2)
235                         return _ex0;
236                 else if (n1 == 0)
237                         return pos_sig ? _ex_1 : _ex1;
238                 else
239                         return pos_sig ? _ex1 : _ex_1;
240         }
241
242         // Perform the usual evaluations of a metric tensor
243         return inherited::eval_indexed(i);
244 }
245
246 /** Automatic symbolic evaluation of an indexed metric tensor. */
247 ex spinmetric::eval_indexed(const basic & i) const
248 {
249         GINAC_ASSERT(is_a<indexed>(i));
250         GINAC_ASSERT(i.nops() == 3);
251         GINAC_ASSERT(is_a<spinmetric>(i.op(0)));
252         GINAC_ASSERT(is_a<spinidx>(i.op(1)));
253         GINAC_ASSERT(is_a<spinidx>(i.op(2)));
254
255         const spinidx & i1 = ex_to<spinidx>(i.op(1));
256         const spinidx & i2 = ex_to<spinidx>(i.op(2));
257
258         // Convolutions are zero
259         if (!(static_cast<const indexed &>(i).get_dummy_indices().empty()))
260                 return _ex0;
261
262         // Numeric evaluation
263         if (static_cast<const indexed &>(i).all_index_values_are(info_flags::nonnegint)) {
264                 int n1 = ex_to<numeric>(i1.get_value()).to_int(), n2 = ex_to<numeric>(i2.get_value()).to_int();
265                 if (n1 == n2)
266                         return _ex0;
267                 else if (n1 < n2)
268                         return _ex1;
269                 else
270                         return _ex_1;
271         }
272
273         // No further simplifications
274         return i.hold();
275 }
276
277 /** Automatic symbolic evaluation of an indexed epsilon tensor. */
278 ex tensepsilon::eval_indexed(const basic & i) const
279 {
280         GINAC_ASSERT(is_a<indexed>(i));
281         GINAC_ASSERT(i.nops() > 1);
282         GINAC_ASSERT(is_a<tensepsilon>(i.op(0)));
283
284         // Convolutions are zero
285         if (!(static_cast<const indexed &>(i).get_dummy_indices().empty()))
286                 return _ex0;
287
288         // Numeric evaluation
289         if (static_cast<const indexed &>(i).all_index_values_are(info_flags::nonnegint)) {
290
291                 // Get sign of index permutation (the indices should already be in
292                 // a canonic order but we can't assume what exactly that order is)
293                 std::vector<int> v;
294                 v.reserve(i.nops() - 1);
295                 for (unsigned j=1; j<i.nops(); j++)
296                         v.push_back(ex_to<numeric>(ex_to<idx>(i.op(j)).get_value()).to_int());
297                 int sign = permutation_sign(v.begin(), v.end());
298
299                 // In a Minkowski space, check for covariant indices
300                 if (minkowski) {
301                         for (unsigned j=1; j<i.nops(); j++) {
302                                 const ex & x = i.op(j);
303                                 if (!is_ex_of_type(x, varidx))
304                                         throw(std::runtime_error("indices of epsilon tensor in Minkowski space must be of type varidx"));
305                                 if (ex_to<varidx>(x).is_covariant())
306                                         if (ex_to<idx>(x).get_value().is_zero())
307                                                 sign = (pos_sig ? -sign : sign);
308                                         else
309                                                 sign = (pos_sig ? sign : -sign);
310                         }
311                 }
312
313                 return sign;
314         }
315
316         // No further simplifications
317         return i.hold();
318 }
319
320 /** Contraction of an indexed delta tensor with something else. */
321 bool tensdelta::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const
322 {
323         GINAC_ASSERT(is_a<indexed>(*self));
324         GINAC_ASSERT(is_a<indexed>(*other));
325         GINAC_ASSERT(self->nops() == 3);
326         GINAC_ASSERT(is_a<tensdelta>(self->op(0)));
327
328         // Try to contract first index
329         const idx *self_idx = &ex_to<idx>(self->op(1));
330         const idx *free_idx = &ex_to<idx>(self->op(2));
331         bool first_index_tried = false;
332
333 again:
334         if (self_idx->is_symbolic()) {
335                 for (unsigned i=1; i<other->nops(); i++) {
336                         const idx &other_idx = ex_to<idx>(other->op(i));
337                         if (is_dummy_pair(*self_idx, other_idx)) {
338
339                                 // Contraction found, remove delta tensor and substitute
340                                 // index in second object
341                                 *self = _ex1;
342                                 *other = other->subs(other_idx == *free_idx);
343                                 return true;
344                         }
345                 }
346         }
347
348         if (!first_index_tried) {
349
350                 // No contraction with first index found, try second index
351                 self_idx = &ex_to<idx>(self->op(2));
352                 free_idx = &ex_to<idx>(self->op(1));
353                 first_index_tried = true;
354                 goto again;
355         }
356
357         return false;
358 }
359
360 /** Contraction of an indexed metric tensor with something else. */
361 bool tensmetric::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const
362 {
363         GINAC_ASSERT(is_a<indexed>(*self));
364         GINAC_ASSERT(is_a<indexed>(*other));
365         GINAC_ASSERT(self->nops() == 3);
366         GINAC_ASSERT(is_a<tensmetric>(self->op(0)));
367
368         // If contracting with the delta tensor, let the delta do it
369         // (don't raise/lower delta indices)
370         if (is_ex_of_type(other->op(0), tensdelta))
371                 return false;
372
373         // Try to contract first index
374         const idx *self_idx = &ex_to<idx>(self->op(1));
375         const idx *free_idx = &ex_to<idx>(self->op(2));
376         bool first_index_tried = false;
377
378 again:
379         if (self_idx->is_symbolic()) {
380                 for (unsigned i=1; i<other->nops(); i++) {
381                         const idx &other_idx = ex_to<idx>(other->op(i));
382                         if (is_dummy_pair(*self_idx, other_idx)) {
383
384                                 // Contraction found, remove metric tensor and substitute
385                                 // index in second object
386                                 *self = _ex1;
387                                 *other = other->subs(other_idx == *free_idx);
388                                 return true;
389                         }
390                 }
391         }
392
393         if (!first_index_tried) {
394
395                 // No contraction with first index found, try second index
396                 self_idx = &ex_to<idx>(self->op(2));
397                 free_idx = &ex_to<idx>(self->op(1));
398                 first_index_tried = true;
399                 goto again;
400         }
401
402         return false;
403 }
404
405 /** Contraction of an indexed spinor metric with something else. */
406 bool spinmetric::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const
407 {
408         GINAC_ASSERT(is_a<indexed>(*self));
409         GINAC_ASSERT(is_a<indexed>(*other));
410         GINAC_ASSERT(self->nops() == 3);
411         GINAC_ASSERT(is_a<spinmetric>(self->op(0)));
412
413         // Contractions between spinor metrics
414         if (is_ex_of_type(other->op(0), spinmetric)) {
415                 const idx &self_i1 = ex_to<idx>(self->op(1));
416                 const idx &self_i2 = ex_to<idx>(self->op(2));
417                 const idx &other_i1 = ex_to<idx>(other->op(1));
418                 const idx &other_i2 = ex_to<idx>(other->op(2));
419
420                 if (is_dummy_pair(self_i1, other_i1)) {
421                         if (is_dummy_pair(self_i2, other_i2))
422                                 *self = _ex2;
423                         else
424                                 *self = delta_tensor(self_i2, other_i2);
425                         *other = _ex1;
426                         return true;
427                 } else if (is_dummy_pair(self_i1, other_i2)) {
428                         if (is_dummy_pair(self_i2, other_i1))
429                                 *self = _ex_2;
430                         else
431                                 *self = -delta_tensor(self_i2, other_i1);
432                         *other = _ex1;
433                         return true;
434                 } else if (is_dummy_pair(self_i2, other_i1)) {
435                         *self = -delta_tensor(self_i1, other_i2);
436                         *other = _ex1;
437                         return true;
438                 } else if (is_dummy_pair(self_i2, other_i2)) {
439                         *self = delta_tensor(self_i1, other_i1);
440                         *other = _ex1;
441                         return true;
442                 }
443         }
444
445         // If contracting with the delta tensor, let the delta do it
446         // (don't raise/lower delta indices)
447         if (is_ex_of_type(other->op(0), tensdelta))
448                 return false;
449
450         // Try to contract first index
451         const idx *self_idx = &ex_to<idx>(self->op(1));
452         const idx *free_idx = &ex_to<idx>(self->op(2));
453         bool first_index_tried = false;
454         int sign = 1;
455
456 again:
457         if (self_idx->is_symbolic()) {
458                 for (unsigned i=1; i<other->nops(); i++) {
459                         const idx &other_idx = ex_to<idx>(other->op(i));
460                         if (is_dummy_pair(*self_idx, other_idx)) {
461
462                                 // Contraction found, remove metric tensor and substitute
463                                 // index in second object
464                                 *self = (static_cast<const spinidx *>(self_idx)->is_covariant() ? sign : -sign);
465                                 *other = other->subs(other_idx == *free_idx);
466                                 return true;
467                         }
468                 }
469         }
470
471         if (!first_index_tried) {
472
473                 // No contraction with first index found, try second index
474                 self_idx = &ex_to<idx>(self->op(2));
475                 free_idx = &ex_to<idx>(self->op(1));
476                 first_index_tried = true;
477                 sign = -sign;
478                 goto again;
479         }
480
481         return false;
482 }
483
484 /** Contraction of epsilon tensor with something else. */
485 bool tensepsilon::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const
486 {
487         GINAC_ASSERT(is_a<indexed>(*self));
488         GINAC_ASSERT(is_a<indexed>(*other));
489         GINAC_ASSERT(is_a<tensepsilon>(self->op(0)));
490         unsigned num = self->nops() - 1;
491
492         if (is_ex_exactly_of_type(other->op(0), tensepsilon) && num+1 == other->nops()) {
493
494                 // Contraction of two epsilon tensors is a determinant
495                 ex dim = ex_to<idx>(self->op(1)).get_dim();
496                 matrix M(num, num);
497                 for (int i=0; i<num; i++) {
498                         for (int j=0; j<num; j++) {
499                                 if (minkowski)
500                                         M(i, j) = lorentz_g(self->op(i+1), other->op(j+1), pos_sig);
501                                 else
502                                         M(i, j) = metric_tensor(self->op(i+1), other->op(j+1));
503                         }
504                 }
505                 int sign = minkowski ? -1 : 1;
506                 *self = sign * M.determinant().simplify_indexed();
507                 *other = _ex1;
508                 return true;
509
510         } else if (other->return_type() == return_types::commutative) {
511
512 #if 0
513                 // This handles eps.i.j.k * p.j * p.k = 0
514                 // Maybe something like this should go to simplify_indexed() because
515                 // such relations are true for any antisymmetric tensors...
516                 exvector c;
517
518                 // Handle all indices of the epsilon tensor
519                 for (int i=0; i<num; i++) {
520                         ex idx = self->op(i+1);
521
522                         // Look whether there's a contraction with this index
523                         exvector::const_iterator ait, aitend = v.end();
524                         for (ait = v.begin(); ait != aitend; ait++) {
525                                 if (ait == self)
526                                         continue;
527                                 if (is_a<indexed>(*ait) && ait->return_type() == return_types::commutative && ex_to<indexed>(*ait).has_dummy_index_for(idx) && ait->nops() == 2) {
528
529                                         // Yes, did we already have another contraction with the same base expression?
530                                         ex base = ait->op(0);
531                                         if (std::find_if(c.begin(), c.end(), bind2nd(ex_is_equal(), base)) == c.end()) {
532
533                                                 // No, add the base expression to the list
534                                                 c.push_back(base);
535
536                                         } else {
537
538                                                 // Yes, the contraction is zero
539                                                 *self = _ex0;
540                                                 *other = _ex0;
541                                                 return true;
542                                         }
543                                 }
544                         }
545                 }
546 #endif
547         }
548
549         return false;
550 }
551
552 //////////
553 // global functions
554 //////////
555
556 ex delta_tensor(const ex & i1, const ex & i2)
557 {
558         if (!is_ex_of_type(i1, idx) || !is_ex_of_type(i2, idx))
559                 throw(std::invalid_argument("indices of delta tensor must be of type idx"));
560
561         return indexed(tensdelta(), sy_symm(), i1, i2);
562 }
563
564 ex metric_tensor(const ex & i1, const ex & i2)
565 {
566         if (!is_ex_of_type(i1, varidx) || !is_ex_of_type(i2, varidx))
567                 throw(std::invalid_argument("indices of metric tensor must be of type varidx"));
568
569         return indexed(tensmetric(), sy_symm(), i1, i2);
570 }
571
572 ex lorentz_g(const ex & i1, const ex & i2, bool pos_sig)
573 {
574         if (!is_ex_of_type(i1, varidx) || !is_ex_of_type(i2, varidx))
575                 throw(std::invalid_argument("indices of metric tensor must be of type varidx"));
576
577         return indexed(minkmetric(pos_sig), sy_symm(), i1, i2);
578 }
579
580 ex spinor_metric(const ex & i1, const ex & i2)
581 {
582         if (!is_ex_of_type(i1, spinidx) || !is_ex_of_type(i2, spinidx))
583                 throw(std::invalid_argument("indices of spinor metric must be of type spinidx"));
584         if (!ex_to<idx>(i1).get_dim().is_equal(2) || !ex_to<idx>(i2).get_dim().is_equal(2))
585                 throw(std::runtime_error("index dimension for spinor metric must be 2"));
586
587         return indexed(spinmetric(), sy_anti(), i1, i2);
588 }
589
590 ex epsilon_tensor(const ex & i1, const ex & i2)
591 {
592         if (!is_ex_of_type(i1, idx) || !is_ex_of_type(i2, idx))
593                 throw(std::invalid_argument("indices of epsilon tensor must be of type idx"));
594
595         ex dim = ex_to<idx>(i1).get_dim();
596         if (!dim.is_equal(ex_to<idx>(i2).get_dim()))
597                 throw(std::invalid_argument("all indices of epsilon tensor must have the same dimension"));
598         if (!ex_to<idx>(i1).get_dim().is_equal(_ex2))
599                 throw(std::runtime_error("index dimension of epsilon tensor must match number of indices"));
600
601         return indexed(tensepsilon(), sy_anti(), i1, i2);
602 }
603
604 ex epsilon_tensor(const ex & i1, const ex & i2, const ex & i3)
605 {
606         if (!is_ex_of_type(i1, idx) || !is_ex_of_type(i2, idx) || !is_ex_of_type(i3, idx))
607                 throw(std::invalid_argument("indices of epsilon tensor must be of type idx"));
608
609         ex dim = ex_to<idx>(i1).get_dim();
610         if (!dim.is_equal(ex_to<idx>(i2).get_dim()) || !dim.is_equal(ex_to<idx>(i3).get_dim()))
611                 throw(std::invalid_argument("all indices of epsilon tensor must have the same dimension"));
612         if (!ex_to<idx>(i1).get_dim().is_equal(_ex3))
613                 throw(std::runtime_error("index dimension of epsilon tensor must match number of indices"));
614
615         return indexed(tensepsilon(), sy_anti(), i1, i2, i3);
616 }
617
618 ex lorentz_eps(const ex & i1, const ex & i2, const ex & i3, const ex & i4, bool pos_sig)
619 {
620         if (!is_ex_of_type(i1, varidx) || !is_ex_of_type(i2, varidx) || !is_ex_of_type(i3, varidx) || !is_ex_of_type(i4, varidx))
621                 throw(std::invalid_argument("indices of Lorentz epsilon tensor must be of type varidx"));
622
623         ex dim = ex_to<idx>(i1).get_dim();
624         if (!dim.is_equal(ex_to<idx>(i2).get_dim()) || !dim.is_equal(ex_to<idx>(i3).get_dim()) || !dim.is_equal(ex_to<idx>(i4).get_dim()))
625                 throw(std::invalid_argument("all indices of epsilon tensor must have the same dimension"));
626         if (!ex_to<idx>(i1).get_dim().is_equal(_ex4))
627                 throw(std::runtime_error("index dimension of epsilon tensor must match number of indices"));
628
629         return indexed(tensepsilon(true, pos_sig), sy_anti(), i1, i2, i3, i4);
630 }
631
632 ex eps0123(const ex & i1, const ex & i2, const ex & i3, const ex & i4, bool pos_sig)
633 {
634         if (!is_ex_of_type(i1, varidx) || !is_ex_of_type(i2, varidx) || !is_ex_of_type(i3, varidx) || !is_ex_of_type(i4, varidx))
635                 throw(std::invalid_argument("indices of epsilon tensor must be of type varidx"));
636
637         ex dim = ex_to<idx>(i1).get_dim();
638         if (dim.is_equal(4))
639                 return lorentz_eps(i1, i2, i3, i4, pos_sig);
640         else
641                 return indexed(tensepsilon(true, pos_sig), sy_anti(), i1, i2, i3, i4);
642 }
643
644 } // namespace GiNaC