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