]> www.ginac.de Git - ginac.git/blob - ginac/color.cpp
skeleton implementation of new color class
[ginac.git] / ginac / color.cpp
1 /** @file color.cpp
2  *
3  *  Implementation of GiNaC's color (SU(3) Lie algebra) objects. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2001 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 "color.h"
24 #include "ex.h"
25 #include "ncmul.h"
26 #include "numeric.h"
27 #include "archive.h"
28 #include "debugmsg.h"
29 #include "utils.h"
30
31 namespace GiNaC {
32
33 GINAC_IMPLEMENT_REGISTERED_CLASS(color, indexed)
34 GINAC_IMPLEMENT_REGISTERED_CLASS(su3one, tensor)
35 GINAC_IMPLEMENT_REGISTERED_CLASS(su3t, tensor)
36 GINAC_IMPLEMENT_REGISTERED_CLASS(su3f, tensor)
37 GINAC_IMPLEMENT_REGISTERED_CLASS(su3d, tensor)
38
39 //////////
40 // default constructor, destructor, copy constructor assignment operator and helpers
41 //////////
42
43 color::color() : representation_label(0)
44 {
45         debugmsg("color default constructor", LOGLEVEL_CONSTRUCT);
46         tinfo_key = TINFO_color;
47 }
48
49 void color::copy(const color & other)
50 {
51         inherited::copy(other);
52         representation_label = other.representation_label;
53 }
54
55 DEFAULT_DESTROY(color)
56 DEFAULT_CTORS(su3one)
57 DEFAULT_CTORS(su3t)
58 DEFAULT_CTORS(su3f)
59 DEFAULT_CTORS(su3d)
60
61 //////////
62 // other constructors
63 //////////
64
65 /** Construct object without any color index. This constructor is for
66  *  internal use only. Use the color_ONE() function instead.
67  *  @see color_ONE */
68 color::color(const ex & b, unsigned rl = 0) : inherited(b), representation_label(rl)
69 {
70         debugmsg("color constructor from ex,unsigned", LOGLEVEL_CONSTRUCT);
71         tinfo_key = TINFO_color;
72 }
73
74 /** Construct object with one color index. This constructor is for internal
75  *  use only. Use the color_T() function instead.
76  *  @see color_T */
77 color::color(const ex & b, const ex & i1, unsigned rl = 0) : inherited(b, i1), representation_label(rl)
78 {
79         debugmsg("color constructor from ex,ex,unsigned", LOGLEVEL_CONSTRUCT);
80         tinfo_key = TINFO_color;
81 }
82
83 color::color(unsigned rl, const exvector & v, bool discardable) : inherited(indexed::unknown, v, discardable), representation_label(rl)
84 {
85         debugmsg("color constructor from unsigned,exvector", LOGLEVEL_CONSTRUCT);
86         tinfo_key = TINFO_color;
87 }
88
89 color::color(unsigned rl, exvector * vp) : inherited(indexed::unknown, vp), representation_label(rl)
90 {
91         debugmsg("color constructor from unsigned,exvector *", LOGLEVEL_CONSTRUCT);
92         tinfo_key = TINFO_color;
93 }
94
95 //////////
96 // archiving
97 //////////
98
99 color::color(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
100 {
101         debugmsg("color constructor from archive_node", LOGLEVEL_CONSTRUCT);
102         n.find_unsigned("representation", representation_label);
103 }
104
105 void color::archive(archive_node &n) const
106 {
107         inherited::archive(n);
108         n.add_unsigned("representation", representation_label);
109 }
110
111 DEFAULT_UNARCHIVE(color)
112 DEFAULT_ARCHIVING(su3one)
113 DEFAULT_ARCHIVING(su3t)
114 DEFAULT_ARCHIVING(su3f)
115 DEFAULT_ARCHIVING(su3d)
116
117 //////////
118 // functions overriding virtual functions from bases classes
119 //////////
120
121 int color::compare_same_type(const basic & other) const
122 {
123         GINAC_ASSERT(other.tinfo() == TINFO_color);
124         const color &o = static_cast<const color &>(other);
125
126         if (representation_label != o.representation_label) {
127                 // different representation label
128                 return representation_label < o.representation_label ? -1 : 1;
129         }
130
131         return inherited::compare_same_type(other);
132 }
133
134 DEFAULT_COMPARE(su3one)
135 DEFAULT_COMPARE(su3t)
136 DEFAULT_COMPARE(su3f)
137 DEFAULT_COMPARE(su3d)
138
139 DEFAULT_PRINT(su3one, "ONE")
140 DEFAULT_PRINT(su3t, "T")
141 DEFAULT_PRINT(su3f, "f")
142 DEFAULT_PRINT(su3d, "d")
143
144 /** Perform automatic simplification on noncommutative product of color
145  *  objects. This removes superfluous ONEs. */
146 ex color::simplify_ncmul(const exvector & v) const
147 {
148         //!! to be implemented
149         return nonsimplified_ncmul(v);
150 }
151
152 ex color::thisexprseq(const exvector & v) const
153 {
154         return color(representation_label, v);
155 }
156
157 ex color::thisexprseq(exvector * vp) const
158 {
159         return color(representation_label, vp);
160 }
161
162 //////////
163 // global functions
164 //////////
165
166 ex color_ONE(unsigned rl)
167 {
168         return color(su3one(), rl);
169 }
170
171 ex color_T(const ex & a, unsigned rl)
172 {
173         return color(su3t(), a, rl);
174 }
175
176 ex color_f(const ex & a, const ex & b, const ex & c)
177 {
178         return indexed(su3f(), indexed::antisymmetric, a, b, c);
179 }
180
181 ex color_d(const ex & a, const ex & b, const ex & c)
182 {
183         return indexed(su3d(), indexed::symmetric, a, b, c);
184 }
185
186 ex color_h(const ex & a, const ex & b, const ex & c)
187 {
188         return color_d(a, b, c) + I * color_f(a, b, c);
189 }
190
191 } // namespace GiNaC