]> www.ginac.de Git - ginac.git/blob - ginac/clifford.cpp
37e1d8df89d43930bc0ca1f7e09e57cf49fa8f82
[ginac.git] / ginac / clifford.cpp
1 /** @file clifford.cpp
2  *
3  *  Implementation of GiNaC's clifford objects.
4  *  No real implementation yet, to be done.     */
5
6 /*
7  *  GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
8  *
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2 of the License, or
12  *  (at your option) any later version.
13  *
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to the Free Software
21  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #include <string>
25
26 #include "clifford.h"
27 #include "ex.h"
28 #include "ncmul.h"
29 #include "archive.h"
30 #include "utils.h"
31 #include "debugmsg.h"
32
33 #ifndef NO_NAMESPACE_GINAC
34 namespace GiNaC {
35 #endif // ndef NO_NAMESPACE_GINAC
36
37 GINAC_IMPLEMENT_REGISTERED_CLASS(clifford, lortensor)
38
39 //////////
40 // default constructor, destructor, copy constructor assignment operator and helpers
41 //////////
42
43 // public
44
45 clifford::clifford()
46 {
47         debugmsg("clifford default constructor",LOGLEVEL_CONSTRUCT);
48         tinfo_key = TINFO_clifford;
49 }
50
51 clifford::~clifford()
52 {
53         debugmsg("clifford destructor",LOGLEVEL_DESTRUCT);
54         destroy(false);
55 }
56
57 clifford::clifford(const clifford & other)
58 {
59         debugmsg("clifford copy constructor",LOGLEVEL_CONSTRUCT);
60         copy(other);
61 }
62
63 const clifford & clifford::operator=(const clifford & other)
64 {
65         debugmsg("clifford operator=",LOGLEVEL_ASSIGNMENT);
66         if (this != &other) {
67                 destroy(true);
68                 copy(other);
69         }
70         return *this;
71 }
72
73 // protected
74
75 void clifford::copy(const clifford & other)
76 {
77         inherited::copy(other);
78 }
79
80 void clifford::destroy(bool call_parent)
81 {
82         if (call_parent) inherited::destroy(call_parent);
83 }
84
85 //////////
86 // other constructors
87 //////////
88
89 // public
90
91 clifford::clifford(const std::string & n, const ex & mu) : inherited(lortensor_symbolic, n, mu)
92 {
93         debugmsg("clifford constructor from string,ex",LOGLEVEL_CONSTRUCT);
94         tinfo_key=TINFO_clifford;
95 }
96
97 clifford::clifford(const std::string & n, const exvector & iv) : inherited(lortensor_symbolic, n, iv)
98 {
99         debugmsg("clifford constructor from string,exvector", LOGLEVEL_CONSTRUCT);
100         GINAC_ASSERT(all_of_type_lorentzidx());
101         tinfo_key=TINFO_clifford;
102 }
103
104 clifford::clifford(const std::string & n, exvector *ivp) : inherited(lortensor_symbolic, n, *ivp)
105 {
106         debugmsg("clifford constructor from string,exvector", LOGLEVEL_CONSTRUCT);
107         GINAC_ASSERT(all_of_type_lorentzidx());
108         tinfo_key=TINFO_clifford;
109 }
110
111 //////////
112 // archiving
113 //////////
114
115 /** Construct object from archive_node. */
116 clifford::clifford(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
117 {
118         debugmsg("clifford constructor from archive_node", LOGLEVEL_CONSTRUCT);
119 }
120
121 /** Unarchive the object. */
122 ex clifford::unarchive(const archive_node &n, const lst &sym_lst)
123 {
124         return (new clifford(n, sym_lst))->setflag(status_flags::dynallocated);
125 }
126
127 /** Archive the object. */
128 void clifford::archive(archive_node &n) const
129 {
130         inherited::archive(n);
131 }
132
133 //////////
134 // functions overriding virtual functions from bases classes
135 //////////
136
137 // public
138
139 basic * clifford::duplicate() const
140 {
141         debugmsg("clifford duplicate",LOGLEVEL_DUPLICATE);
142         return new clifford(*this);
143 }
144
145 void clifford::printraw(std::ostream & os) const
146 {
147         debugmsg("clifford printraw",LOGLEVEL_PRINT);
148         os << "clifford(" << "indices=";
149         printrawindices(os);
150         os << ",hash=" << hashvalue << ",flags=" << flags << ")";
151 }
152
153 void clifford::printtree(std::ostream & os, unsigned indent) const
154 {
155         debugmsg("clifford printtree",LOGLEVEL_PRINT);
156         os << std::string(indent,' ') << " (clifford): "
157            << seq.size() << "indices=";
158         printtreeindices(os, indent);
159         os << ", hash=" << hashvalue
160            << " (0x" << std::hex << hashvalue << std::dec << ")"
161            << ", flags=" << flags << std::endl;
162 }
163
164 void clifford::print(std::ostream & os, unsigned upper_precedence) const
165 {
166         debugmsg("clifford print",LOGLEVEL_PRINT);
167         os << name;
168         printindices(os);
169 }
170
171 bool clifford::info(unsigned inf) const
172 {
173         return inherited::info(inf);
174 }
175
176 // protected
177
178 int clifford::compare_same_type(const basic & other) const
179 {
180         GINAC_ASSERT(is_of_type(other,clifford));
181         // only compare indices
182         return exprseq::compare_same_type(other);
183 }
184
185 bool clifford::is_equal_same_type(const basic & other) const
186 {
187         GINAC_ASSERT(is_of_type(other,clifford));
188         // only compare indices
189         return exprseq::is_equal_same_type(other);
190 }
191
192 ex clifford::thisexprseq(const exvector & v) const
193 {
194         return clifford(name, v);
195 }
196
197 ex clifford::thisexprseq(exvector *vp) const
198 {
199         return clifford(name, vp);
200 }
201
202 ex clifford::simplify_ncmul(const exvector & v) const
203 {
204         return simplified_ncmul(v);
205 }
206
207 //////////
208 // friend functions
209 //////////
210
211 /** Construct an object representing a Dirac gamma matrix. The index must
212  *  be of class lorentzidx.
213  *
214  *  @param mu Index
215  *  @return newly constructed object */
216 clifford clifford_gamma(const ex & mu)
217 {
218         return clifford("gamma", mu);
219 }
220
221 #ifndef NO_NAMESPACE_GINAC
222 } // namespace GiNaC
223 #endif // ndef NO_NAMESPACE_GINAC