- See if __GNUC__ < 2.97 before using std::vector<..,malloc_alloc>. Sorry,
[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 "utils.h"
30 #include "debugmsg.h"
31
32 #ifndef NO_NAMESPACE_GINAC
33 namespace GiNaC {
34 #endif // ndef NO_NAMESPACE_GINAC
35
36 //////////
37 // default constructor, destructor, copy constructor assignment operator and helpers
38 //////////
39
40 // public
41
42 clifford::clifford()
43 {
44         debugmsg("clifford default constructor",LOGLEVEL_CONSTRUCT);
45         serial=next_serial++;
46         name=autoname_prefix()+ToString(serial);
47         tinfo_key=TINFO_clifford;
48 }
49
50 clifford::~clifford()
51 {
52         debugmsg("clifford destructor",LOGLEVEL_DESTRUCT);
53         destroy(false);
54 }
55
56 clifford::clifford(const clifford & other)
57 {
58         debugmsg("clifford copy constructor",LOGLEVEL_CONSTRUCT);
59         copy (other);
60 }
61
62 const clifford & clifford::operator=(const clifford & other)
63 {
64         debugmsg("clifford operator=",LOGLEVEL_ASSIGNMENT);
65         if (this != &other) {
66                 destroy(true);
67                 copy(other);
68         }
69         return *this;
70 }
71
72 // protected
73
74 void clifford::copy(const clifford & other)
75 {
76         indexed::copy(other);
77         name=other.name;
78         serial=other.serial;
79 }
80
81 void clifford::destroy(bool call_parent)
82 {
83         if (call_parent) {
84                 indexed::destroy(call_parent);
85         }
86 }
87
88 //////////
89 // other constructors
90 //////////
91
92 // public
93
94 clifford::clifford(const std::string & initname)
95 {
96         debugmsg("clifford constructor from string",LOGLEVEL_CONSTRUCT);
97         name=initname;
98         serial=next_serial++;
99         tinfo_key=TINFO_clifford;
100 }
101
102 //////////
103 // functions overriding virtual functions from bases classes
104 //////////
105
106 // public
107
108 basic * clifford::duplicate() const
109 {
110         debugmsg("clifford duplicate",LOGLEVEL_DUPLICATE);
111         return new clifford(*this);
112 }
113
114 void clifford::printraw(std::ostream & os) const
115 {
116         debugmsg("clifford printraw",LOGLEVEL_PRINT);
117         os << "clifford(" << "name=" << name << ",serial=" << serial
118            << ",indices=";
119         printrawindices(os);
120         os << ",hash=" << hashvalue << ",flags=" << flags << ")";
121 }
122
123 void clifford::printtree(std::ostream & os, unsigned indent) const
124 {
125         debugmsg("clifford printtree",LOGLEVEL_PRINT);
126         os << std::string(indent,' ') << name << " (clifford): "
127            << "serial=" << serial << ","
128            << seq.size() << "indices=";
129         printtreeindices(os, indent);
130         os << ", hash=" << hashvalue
131            << " (0x" << std::hex << hashvalue << std::dec << ")"
132            << ", flags=" << flags << std::endl;
133 }
134
135 void clifford::print(std::ostream & os, unsigned upper_precedence) const
136 {
137         debugmsg("clifford print",LOGLEVEL_PRINT);
138         os << name;
139         printindices(os);
140 }
141
142 void clifford::printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence) const
143 {
144         debugmsg("clifford print csrc",LOGLEVEL_PRINT);
145         print(os,upper_precedence);
146 }
147
148 bool clifford::info(unsigned inf) const
149 {
150         return indexed::info(inf);
151 }
152
153 // protected
154
155 int clifford::compare_same_type(const basic & other) const
156 {
157         GINAC_ASSERT(other.tinfo() == TINFO_clifford);
158         const clifford *o = static_cast<const clifford *>(&other);
159         if (serial==o->serial) {
160                 return indexed::compare_same_type(other);
161         }
162         return serial < o->serial ? -1 : 1;
163 }
164
165 ex clifford::simplify_ncmul(const exvector & v) const
166 {
167         return simplified_ncmul(v);
168 }
169
170 unsigned clifford::calchash(void) const
171 {
172         hashvalue=golden_ratio_hash(golden_ratio_hash(0x55555556U ^
173                                                                                                   golden_ratio_hash(tinfo_key) ^
174                                                                                                   serial));
175         setflag(status_flags::hash_calculated);
176         return hashvalue;
177 }
178
179 //////////
180 // virtual functions which can be overridden by derived classes
181 //////////
182
183 // none
184
185 //////////
186 // non-virtual functions in this class
187 //////////
188
189 void clifford::setname(const std::string & n)
190 {
191         name = n;
192 }
193
194 // private
195
196 std::string & clifford::autoname_prefix(void)
197 {
198         static std::string * s = new std::string("clifford");
199         return *s;
200 }
201
202 //////////
203 // static member variables
204 //////////
205
206 // private
207
208 unsigned clifford::next_serial=0;
209
210 //////////
211 // global constants
212 //////////
213
214 const clifford some_clifford;
215 const std::type_info & typeid_clifford = typeid(some_clifford);
216
217 #ifndef NO_NAMESPACE_GINAC
218 } // namespace GiNaC
219 #endif // ndef NO_NAMESPACE_GINAC