]> www.ginac.de Git - ginac.git/blob - ginac/lortensor.h
- indentation is now done with tabs
[ginac.git] / ginac / lortensor.h
1 /** @file lortensor.h
2  *
3  *  Interface to GiNaCĀ“s lortensor objects. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2000 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 /** Base class for lortensor object */
37 class lortensor : public indexed
38 {
39         // friends
40         friend lortensor lortensor_g(const ex & mu, const ex & nu);
41         // friend lortensor lortensor_delta(const ex & mu, const ex & nu);
42         friend lortensor lortensor_epsilon(const ex & mu, const ex & nu,
43                                                                            const ex & rho, const ex & sigma);
44         // friend lortensor lortensor_rankn(const string & n, const exvector & iv);
45         friend lortensor lortensor_rank1(const std::string & n, const ex & mu);
46         friend lortensor lortensor_rank2(const std::string & n, const ex & mu, const ex & nu);
47         friend ex simplify_lortensor_mul(const ex & m);
48         friend ex simplify_lortensor(const ex & e);
49         
50         // types
51
52 public:
53         typedef enum { invalid,
54                                    lortensor_g,
55                                    lortensor_rankn,
56                                    lortensor_rank1,
57                                    lortensor_rank2,
58                                    // lortensor_delta,
59                                    lortensor_epsilon
60         } lortensor_types;
61
62         // member functions
63
64         // default constructor, destructor, copy constructor assignment operator and helpers
65 public:
66         lortensor();
67         ~lortensor();
68         lortensor(const lortensor & other);
69         const lortensor & operator=(const lortensor & other);
70 protected:
71         void copy(const lortensor & other);
72         void destroy(bool call_parent);
73
74         // other constructors
75 protected:
76         lortensor(lortensor_types const lt, const std::string & n);
77         lortensor(lortensor_types const lt, const std::string & n, const ex & mu);
78         lortensor(lortensor_types const lt, const std::string & n, const ex & mu, const ex & nu);
79         lortensor(lortensor_types const lt, const std::string & n, const ex & mu, const ex & nu,
80                           const ex & rho);
81         lortensor(lortensor_types const lt, const std::string & n, const ex & mu, const ex & nu, const ex & rho, const ex & sigma);
82         lortensor(lortensor_types const lt, const std::string & n, const exvector & iv);
83         lortensor(lortensor_types const lt, const std::string & n, unsigned s, const exvector & iv);
84         lortensor(lortensor_types const lt, const std::string & n, unsigned s, exvector * ivp);
85         
86         //functions overriding virtual functions from base classes
87 public:
88         basic * duplicate() const;
89         void printraw(std::ostream & os) const;
90         void printtree(std::ostream & os, unsigned indent) const;
91         void print(std::ostream & os, unsigned upper_precedence=0) const;
92         void printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence=0) const;
93         bool info(unsigned inf) const;
94         ex eval(int level=0) const;
95 protected:
96         int compare_same_type(const basic & other) const;
97         bool is_equal_same_type(const basic & other) const;
98         unsigned return_type(void) const;
99         unsigned return_type_tinfo(void) const;
100         ex thisexprseq(const exvector & v) const;
101         ex thisexprseq(exvector * vp) const;
102
103         // new virtual functions which can be overridden by derived classes
104         // none
105
106         //non virtual functions in this class
107 public:
108         void setname(const std::string & n);
109         std::string getname(void) const {return name;}
110 protected:
111         bool all_of_type_lorentzidx(void) const;
112 private:
113         std::string & autoname_prefix(void);
114
115         //member variables
116
117 protected:
118         lortensor_types type;
119         std::string name;
120         unsigned serial;
121 private:
122         static unsigned next_serial;
123 };
124
125 // global constants
126
127 extern const lortensor some_lortensor;
128 extern const type_info & typeid_lortensor;
129
130 // utility functions
131         
132 inline const lortensor & ex_to_lortensor(const ex &e)
133 {
134         return static_cast<const lortensor &>(*e.bp);
135 }
136
137 inline lortensor &ex_to_nonconst_lortensor(const ex &e)
138 {
139         return static_cast<lortensor &>(*e.bp);
140 }
141
142 lortensor lortensor_g(const ex & mu, const ex & nu);
143 ex simplify_lortensor_mul(const ex & m);
144 ex simplify_lortensor(const ex & e);
145 ex Dim(void);    
146
147 #ifndef NO_NAMESPACE_GINAC
148 } // namespace GiNaC
149 #endif // ndef NO_NAMESPACE_GINAC
150
151 #endif // ndef __GINAC_LORTENSOR_H__