1 /** @file lorentzidx.cpp
3 * Implementation of GiNaC's Lorentz indices. */
6 * GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
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.
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.
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
25 #include "lorentzidx.h"
34 GINAC_IMPLEMENT_REGISTERED_CLASS(lorentzidx, idx)
37 // default constructor, destructor, copy constructor assignment operator and helpers
42 lorentzidx::lorentzidx() : orthogonal_only(false), dim_parallel_space(0)
44 debugmsg("lorentzidx default constructor",LOGLEVEL_CONSTRUCT);
45 // serial is incremented in idx::idx()
46 name = "mu" + ToString(serial);
47 tinfo_key = TINFO_lorentzidx;
52 void lorentzidx::copy(const lorentzidx & other)
54 inherited::copy(other);
55 orthogonal_only=other.orthogonal_only;
56 dim_parallel_space=other.dim_parallel_space;
59 void lorentzidx::destroy(bool call_parent)
61 if (call_parent) inherited::destroy(call_parent);
70 /** Construct symbolic Lorentz index, using an automatically generated unique name.
72 * @param cov Index is covariant (contravariant otherwise)
73 * @param oonly Index only lives in orthogonal space
74 * @param dimp Dimension of parallel space
75 * @return newly constructed index */
76 lorentzidx::lorentzidx(bool cov, bool oonly, unsigned dimp)
77 : idx(cov), orthogonal_only(oonly), dim_parallel_space(dimp)
79 debugmsg("lorentzidx constructor from bool,bool,unsigned",LOGLEVEL_CONSTRUCT);
80 // serial is incremented in idx::idx(bool)
82 name="muorth"+ToString(serial);
84 name="mu"+ToString(serial);
86 tinfo_key=TINFO_lorentzidx;
89 /** Construct symbolic Lorentz index with specified name.
91 * @param n Symbolic index name
92 * @param cov Index is covariant (contravariant otherwise)
93 * @param oonly Index only lives in orthogonal space
94 * @param dimp Dimension of parallel space
95 * @return newly constructed index */
96 lorentzidx::lorentzidx(const std::string & n, bool cov, bool oonly, unsigned dimp)
97 : idx(n,cov), orthogonal_only(oonly), dim_parallel_space(dimp)
99 debugmsg("lorentzidx constructor from string,bool,bool,unsigned",
101 tinfo_key=TINFO_lorentzidx;
104 /** Construct symbolic Lorentz index with specified name.
106 * @param n Symbolic index name
107 * @param cov Index is covariant (contravariant otherwise)
108 * @param oonly Index only lives in orthogonal space
109 * @param dimp Dimension of parallel space
110 * @return newly constructed index */
111 lorentzidx::lorentzidx(const char * n, bool cov, bool oonly, unsigned dimp)
112 : idx(n,cov), orthogonal_only(oonly), dim_parallel_space(dimp)
114 debugmsg("lorentzidx constructor from char*,bool,bool,unsigned",
116 tinfo_key=TINFO_lorentzidx;
119 /** Construct numeric Lorentz index with specified value.
121 * @param v Numeric index value
122 * @param cov Index is covariant (contravariant otherwise)
123 * @return newly constructed index */
124 lorentzidx::lorentzidx(unsigned v, bool cov)
125 : idx(v,cov), orthogonal_only(false), dim_parallel_space(0)
127 debugmsg("lorentzidx constructor from unsigned,bool",LOGLEVEL_CONSTRUCT);
128 tinfo_key=TINFO_lorentzidx;
135 /** Construct object from archive_node. */
136 lorentzidx::lorentzidx(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
138 debugmsg("lorentzidx constructor from archive_node", LOGLEVEL_CONSTRUCT);
139 n.find_bool("orthogonal_only", orthogonal_only);
140 n.find_unsigned("pdim", dim_parallel_space);
143 /** Unarchive the object. */
144 ex lorentzidx::unarchive(const archive_node &n, const lst &sym_lst)
146 ex s = (new lorentzidx(n, sym_lst))->setflag(status_flags::dynallocated);
148 if (ex_to_lorentzidx(s).symbolic) {
149 // If lorentzidx is in sym_lst, return the existing lorentzidx
150 for (unsigned i=0; i<sym_lst.nops(); i++) {
151 if (is_ex_of_type(sym_lst.op(i), lorentzidx) && (ex_to_lorentzidx(sym_lst.op(i)).name == ex_to_lorentzidx(s).name))
152 return sym_lst.op(i);
158 /** Archive the object. */
159 void lorentzidx::archive(archive_node &n) const
161 inherited::archive(n);
162 n.add_bool("orthogonal_only", orthogonal_only);
163 n.add_unsigned("pdim", dim_parallel_space);
167 // functions overriding virtual functions from bases classes
172 void lorentzidx::printraw(std::ostream & os) const
174 debugmsg("lorentzidx printraw",LOGLEVEL_PRINT);
179 os << "symbolic,name=" << name;
181 os << "non symbolic,value=" << value;
187 os << ",contravariant";
190 if (orthogonal_only) {
191 os << ",only orthogonal components at " << dim_parallel_space
192 << " parallel dimensions";
194 os << ",parallel and orthogonal components";
197 os << ",serial=" << serial;
198 os << ",hash=" << hashvalue << ",flags=" << flags;
202 void lorentzidx::printtree(std::ostream & os, unsigned indent) const
204 debugmsg("lorentzidx printtree",LOGLEVEL_PRINT);
206 os << std::string(indent,' ') << "lorentzidx: ";
209 os << "symbolic,name=" << name;
211 os << "non symbolic,value=" << value;
217 os << ",contravariant";
220 if (orthogonal_only) {
221 os << ",only orthogonal components at " << dim_parallel_space
222 << " parallel dimensions";
224 os << ",parallel and orthogonal components";
227 os << ", serial=" << serial
228 << ", hash=" << hashvalue
229 << " (0x" << std::hex << hashvalue << std::dec << ")"
230 << ", flags=" << flags << std::endl;
233 void lorentzidx::print(std::ostream & os, unsigned upper_precedence) const
235 debugmsg("lorentzidx print",LOGLEVEL_PRINT);
249 bool lorentzidx::info(unsigned inf) const
251 if (inf==info_flags::lorentzidx) return true;
252 return inherited::info(inf);
255 int lorentzidx::compare_same_type(const basic & other) const
257 GINAC_ASSERT(is_of_type(other, lorentzidx));
258 const lorentzidx &o = static_cast<const lorentzidx &>(other);
260 if (orthogonal_only != o.orthogonal_only)
261 return orthogonal_only ? -1 : 1;
262 if (dim_parallel_space != o.dim_parallel_space)
263 return dim_parallel_space < o.dim_parallel_space ? -1 : 1;
264 return inherited::compare_same_type(other);
268 // non-virtual functions in this class
273 /** Create anonymous contravariant copy of a symbolic Lorentz index. */
274 lorentzidx lorentzidx::create_anonymous_representative(void) const
276 GINAC_ASSERT(is_symbolic());
277 lorentzidx i_copy(*this);
279 i_copy.name="anonymous_representative";
280 i_copy.covariant=false;
281 i_copy.clearflag(status_flags::dynallocated |
282 status_flags::hash_calculated);
290 /** Return the global symbol that represents the dimension D of spacetime. */
293 static symbol *d = new symbol("dim");