]> www.ginac.de Git - ginac.git/blob - ginac/clifford.cpp
- gcd(): cofactor computation is faster in partially factorized case
[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-2000 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_GINAC_NAMESPACE
33 namespace GiNaC {
34 #endif // ndef NO_GINAC_NAMESPACE
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(0);
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(1);
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 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(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(ostream & os, unsigned indent) const
124 {
125     debugmsg("clifford printtree",LOGLEVEL_PRINT);
126     os << string(indent,' ') << name << " (clifford): "
127        << "serial=" << serial << ","
128        << seq.size() << "indices=";
129     printtreeindices(os,indent);
130     os << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
131        << ", flags=" << flags << endl;
132 }
133
134 void clifford::print(ostream & os, unsigned upper_precedence) const
135 {
136     debugmsg("clifford print",LOGLEVEL_PRINT);
137     os << name;
138     printindices(os);
139 }
140
141 void clifford::printcsrc(ostream & os, unsigned type, unsigned upper_precedence) const
142 {
143     debugmsg("clifford print csrc",LOGLEVEL_PRINT);
144     print(os,upper_precedence);
145 }
146
147 bool clifford::info(unsigned inf) const
148 {
149     return indexed::info(inf);
150 }
151
152 // protected
153
154 int clifford::compare_same_type(const basic & other) const
155 {
156     GINAC_ASSERT(other.tinfo() == TINFO_clifford);
157     const clifford *o = static_cast<const clifford *>(&other);
158     if (serial==o->serial) {
159         return indexed::compare_same_type(other);
160     }
161     return serial < o->serial ? -1 : 1;
162 }
163
164 ex clifford::simplify_ncmul(const exvector & v) const
165 {
166     return simplified_ncmul(v);
167 }
168
169 unsigned clifford::calchash(void) const
170 {
171     hashvalue=golden_ratio_hash(golden_ratio_hash(0x55555556U ^
172                                                   golden_ratio_hash(tinfo_key) ^
173                                                   serial));
174     setflag(status_flags::hash_calculated);
175     return hashvalue;
176 }
177
178 //////////
179 // virtual functions which can be overridden by derived classes
180 //////////
181
182 // none
183
184 //////////
185 // non-virtual functions in this class
186 //////////
187
188 void clifford::setname(const string & n)
189 {
190     name=n;
191 }
192
193 // private
194
195 string & clifford::autoname_prefix(void)
196 {
197     static string * s=new string("clifford");
198     return *s;
199 }
200
201 //////////
202 // static member variables
203 //////////
204
205 // private
206
207 unsigned clifford::next_serial=0;
208
209 //////////
210 // global constants
211 //////////
212
213 const clifford some_clifford;
214 const type_info & typeid_clifford=typeid(some_clifford);
215
216 #ifndef NO_GINAC_NAMESPACE
217 } // namespace GiNaC
218 #endif // ndef NO_GINAC_NAMESPACE