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