]> www.ginac.de Git - ginac.git/blob - ginac/lorentzidx.cpp
- is_zero() is now called on expanded expressions in gcd()
[ginac.git] / ginac / lorentzidx.cpp
1 /** @file lorentzidx.cpp
2  *
3  *  Implementation of GiNaC's lorentz indices. */
4
5 /*
6  *  GiNaC Copyright (C) 1999 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
25 #include "lorentzidx.h"
26 #include "utils.h"
27 #include "debugmsg.h"
28
29 namespace GiNaC {
30
31 //////////
32 // default constructor, destructor, copy constructor assignment operator and helpers
33 //////////
34
35 // public
36
37 lorentzidx::lorentzidx() : orthogonal_only(false), dim_parallel_space(0)
38 {
39     debugmsg("lorentzidx default constructor",LOGLEVEL_CONSTRUCT);
40     // serial is incremented in idx::idx()
41     name="mu"+ToString(serial);
42     tinfo_key=TINFO_lorentzidx;
43 }
44
45 lorentzidx::~lorentzidx() 
46 {
47     debugmsg("lorentzidx destructor",LOGLEVEL_DESTRUCT);
48     destroy(0);
49 }
50
51 lorentzidx::lorentzidx(lorentzidx const & other)
52 {
53     debugmsg("lorentzidx copy constructor",LOGLEVEL_CONSTRUCT);
54     copy(other);
55 }
56
57 lorentzidx const & lorentzidx::operator=(lorentzidx const & other)
58 {
59     debugmsg("lorentzidx operator=",LOGLEVEL_ASSIGNMENT);
60     if (this != &other) {
61         destroy(1);
62         copy(other);
63     }
64     return *this;
65 }
66
67 // protected
68
69 void lorentzidx::copy(lorentzidx const & other)
70 {
71     idx::copy(other);
72     orthogonal_only=other.orthogonal_only;
73     dim_parallel_space=other.dim_parallel_space;
74 }
75
76 void lorentzidx::destroy(bool call_parent)
77 {
78     if (call_parent) idx::destroy(call_parent);
79 }
80
81 //////////
82 // other constructors
83 //////////
84
85 // public
86
87 lorentzidx::lorentzidx(bool cov, bool oonly, unsigned dimp) :
88     idx(cov), orthogonal_only(oonly), dim_parallel_space(dimp)
89 {
90     debugmsg("lorentzidx constructor from bool",LOGLEVEL_CONSTRUCT);
91     // serial is incremented in idx::idx(bool)
92     if (oonly) {
93         name="muorth"+ToString(serial);
94     } else {
95         name="mu"+ToString(serial);
96     }
97     tinfo_key=TINFO_lorentzidx;
98 }
99
100 lorentzidx::lorentzidx(string const & n, bool cov, bool oonly, unsigned dimp)
101     : idx(n,cov), orthogonal_only(oonly), dim_parallel_space(dimp)
102 {
103     debugmsg("lorentzidx constructor from string,bool,bool,unsigned",
104              LOGLEVEL_CONSTRUCT);
105     tinfo_key=TINFO_lorentzidx;
106 }
107
108 lorentzidx::lorentzidx(char const * n, bool cov, bool oonly, unsigned dimp)
109     : idx(n,cov), orthogonal_only(oonly), dim_parallel_space(dimp)
110 {
111     debugmsg("lorentzidx constructor from char*,bool,bool,unsigned",
112              LOGLEVEL_CONSTRUCT);
113     tinfo_key=TINFO_lorentzidx;
114 }
115
116 lorentzidx::lorentzidx(unsigned const v, bool cov) : idx(v,cov),
117     orthogonal_only(false), dim_parallel_space(0)
118 {
119     debugmsg("lorentzidx constructor from unsigned,bool",LOGLEVEL_CONSTRUCT);
120     tinfo_key=TINFO_lorentzidx;
121 }
122
123 //////////
124 // functions overriding virtual functions from bases classes
125 //////////
126
127 // public
128
129 basic * lorentzidx::duplicate() const
130 {
131     debugmsg("lorentzidx duplicate",LOGLEVEL_DUPLICATE);
132     return new lorentzidx(*this);
133 }
134
135 void lorentzidx::printraw(ostream & os) const
136 {
137     debugmsg("lorentzidx printraw",LOGLEVEL_PRINT);
138
139     os << "lorentzidx(";
140
141     if (symbolic) {
142         os << "symbolic,name=" << name;
143     } else {
144         os << "non symbolic,value=" << value;
145     }
146
147     if (covariant) {
148         os << ",covariant";
149     } else {
150         os << ",contravariant";
151     }
152
153     if (orthogonal_only) {
154         os << ",only orthogonal components at " << dim_parallel_space
155            << " parallel dimensions";
156     } else {
157         os << ",parallel and orthogonal components";
158     }
159
160     os << ",serial=" << serial;
161     os << ",hash=" << hashvalue << ",flags=" << flags;
162     os << ")";
163 }
164
165 void lorentzidx::printtree(ostream & os, unsigned indent) const
166 {
167     debugmsg("lorentzidx printtree",LOGLEVEL_PRINT);
168
169     os << string(indent,' ') << "lorentzidx: ";
170
171     if (symbolic) {
172         os << "symbolic,name=" << name;
173     } else {
174         os << "non symbolic,value=" << value;
175     }
176
177     if (covariant) {
178         os << ",covariant";
179     } else {
180         os << ",contravariant";
181     }
182
183     if (orthogonal_only) {
184         os << ",only orthogonal components at " << dim_parallel_space
185            << " parallel dimensions";
186     } else {
187         os << ",parallel and orthogonal components";
188     }
189
190     os << ", serial=" << serial
191        << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
192        << ", flags=" << flags << endl;
193 }
194
195 void lorentzidx::print(ostream & os, unsigned upper_precedence) const
196 {
197     debugmsg("lorentzidx print",LOGLEVEL_PRINT);
198
199     if (covariant) {
200         os << "_";
201     } else {
202         os << "~";
203     }
204     if (symbolic) {
205         os << name;
206     } else {
207         os << value;
208     }
209 }
210
211 bool lorentzidx::info(unsigned inf) const
212 {
213     if (inf==info_flags::lorentzidx) return true;
214     return idx::info(inf);
215 }
216
217 //////////
218 // new virtual functions which can be overridden by derived classes
219 //////////
220
221 // none
222
223 //////////
224 // non-virtual functions in this class
225 //////////
226
227 // public
228
229 lorentzidx lorentzidx::create_anonymous_representative(void) const
230 {
231     ASSERT(is_symbolic());
232     lorentzidx i_copy(*this);
233     i_copy.serial=0;
234     i_copy.name="anonymous_representative";
235     i_copy.covariant=false;
236     i_copy.clearflag(status_flags::dynallocated|
237                      status_flags::hash_calculated);
238     return i_copy;
239 }
240
241 //////////
242 // static member variables
243 //////////
244
245 // none
246
247 //////////
248 // global constants
249 //////////
250
251 const lorentzidx some_lorentzidx;
252 type_info const & typeid_lorentzidx=typeid(some_lorentzidx);
253
254 } // namespace GiNaC