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