]> www.ginac.de Git - ginac.git/blob - ginac/lortensor.h
8fbadd3de9426344d62be55ced5ea42cdf2ef5b7
[ginac.git] / ginac / lortensor.h
1 /** @file lortensor.h
2  *
3  *  Interface to GiNaC's Lorentz 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_LORTENSOR_H__
24 #define __GINAC_LORTENSOR_H__
25
26 #include <string>
27 #include <vector>
28 #include <iostream>
29 #include "indexed.h"
30 #include "lorentzidx.h"
31
32 namespace GiNaC {
33
34
35 /** This class holds an object carrying Lorentz indices (of class
36  *  lorentzidx). It can represent a general (symbolic) tensor of type
37  *  (p,q), or one of the constant tensors g (the metric), delta (unity
38  *  matrix) or epsilon (4-dimensional totally antisymmetric tensor). */
39 class lortensor : public indexed
40 {
41         GINAC_DECLARE_REGISTERED_CLASS(lortensor, indexed)
42
43 // friends
44
45         friend lortensor lortensor_g(const ex & mu, const ex & nu);
46         friend lortensor lortensor_delta(const ex & mu, const ex & nu);
47         friend lortensor lortensor_epsilon(const ex & mu, const ex & nu,
48                                                                            const ex & rho, const ex & sigma);
49         friend lortensor lortensor_vector(const std::string & n, const ex & mu);
50         friend lortensor lortensor_symbolic(const std::string & name, const exvector & iv);
51
52         friend ex simplify_lortensor_mul(const ex & m);
53         friend ex simplify_lortensor(const ex & e);
54         
55 // types
56
57 public:
58         typedef enum {
59                 invalid,           /**< not properly constructed */
60                 lortensor_g,       /**< metric tensor */
61                 lortensor_delta,   /**< unity matrix */
62                 lortensor_epsilon, /**< four-dimensional totally antisymmetric tensor */
63                 lortensor_symbolic /**< general symbolic Lorentz tensor */
64         } lortensor_types;
65
66 // member functions
67
68         // other constructors
69 protected:
70         lortensor(lortensor_types const lt, const std::string & n);
71         lortensor(lortensor_types const lt, const std::string & n, const ex & mu);
72         lortensor(lortensor_types const lt, const std::string & n, const ex & mu, const ex & nu);
73         lortensor(lortensor_types const lt, const std::string & n, const ex & mu, const ex & nu, const ex & rho);
74         lortensor(lortensor_types const lt, const std::string & n, const ex & mu, const ex & nu, const ex & rho, const ex & sigma);
75         lortensor(lortensor_types const lt, const std::string & n, const exvector & iv);
76         lortensor(lortensor_types const lt, const std::string & n, unsigned s, const exvector & iv);
77         lortensor(lortensor_types const lt, const std::string & n, unsigned s, exvector * ivp);
78
79         //functions overriding virtual functions from base classes
80 public:
81         void printraw(std::ostream & os) const;
82         void printtree(std::ostream & os, unsigned indent) const;
83         void print(std::ostream & os, unsigned upper_precedence=0) const;
84         bool info(unsigned inf) const;
85         ex eval(int level=0) const;
86 protected:
87         bool is_equal_same_type(const basic & other) const;
88         unsigned return_type(void) const;
89         unsigned return_type_tinfo(void) const;
90         ex thisexprseq(const exvector & v) const;
91         ex thisexprseq(exvector * vp) const;
92
93         // new virtual functions which can be overridden by derived classes
94         // none
95
96         //non virtual functions in this class
97 public:
98         void setname(const std::string & n) {name = n;}
99         std::string getname(void) const {return name;}
100 protected:
101         bool all_of_type_lorentzidx(void) const;
102 private:
103         std::string & autoname_prefix(void);
104
105         //member variables
106
107 protected:
108         lortensor_types type; /**< Type of object */
109         std::string name;     /**< Name of symbolic tensor */
110         unsigned serial;      /**< Unique serial number for comparing symbolic tensors */
111 private:
112         static unsigned next_serial;
113 };
114
115 // utility functions
116         
117 inline const lortensor & ex_to_lortensor(const ex &e)
118 {
119         return static_cast<const lortensor &>(*e.bp);
120 }
121
122 inline lortensor &ex_to_nonconst_lortensor(const ex &e)
123 {
124         return static_cast<lortensor &>(*e.bp);
125 }
126
127 lortensor lortensor_g(const ex & mu, const ex & nu);
128 lortensor lortensor_delta(const ex & mu, const ex & nu);
129 lortensor lortensor_epsilon(const ex & mu, const ex & nu,
130                             const ex & rho, const ex & sigma);
131 lortensor lortensor_vector(const std::string & n, const ex & mu);
132 lortensor lortensor_symbolic(const std::string & name, const exvector & iv);
133
134 ex simplify_lortensor_mul(const ex & m);
135 ex simplify_lortensor(const ex & e);
136
137 } // namespace GiNaC
138
139 #endif // ndef __GINAC_LORTENSOR_H__