3 * Implementation of GiNaC's color (SU(3) Lie algebra) objects. */
6 * GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
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.
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.
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
31 #include "power.h" // for sqrt()
38 GINAC_IMPLEMENT_REGISTERED_CLASS(color, indexed)
39 GINAC_IMPLEMENT_REGISTERED_CLASS(su3one, tensor)
40 GINAC_IMPLEMENT_REGISTERED_CLASS(su3t, tensor)
41 GINAC_IMPLEMENT_REGISTERED_CLASS(su3f, tensor)
42 GINAC_IMPLEMENT_REGISTERED_CLASS(su3d, tensor)
45 // default constructor, destructor, copy constructor assignment operator and helpers
48 color::color() : representation_label(0)
50 debugmsg("color default constructor", LOGLEVEL_CONSTRUCT);
51 tinfo_key = TINFO_color;
54 void color::copy(const color & other)
56 inherited::copy(other);
57 representation_label = other.representation_label;
60 DEFAULT_DESTROY(color)
70 /** Construct object without any color index. This constructor is for
71 * internal use only. Use the color_ONE() function instead.
73 color::color(const ex & b, unsigned rl = 0) : inherited(b), representation_label(rl)
75 debugmsg("color constructor from ex,unsigned", LOGLEVEL_CONSTRUCT);
76 tinfo_key = TINFO_color;
79 /** Construct object with one color index. This constructor is for internal
80 * use only. Use the color_T() function instead.
82 color::color(const ex & b, const ex & i1, unsigned rl = 0) : inherited(b, i1), representation_label(rl)
84 debugmsg("color constructor from ex,ex,unsigned", LOGLEVEL_CONSTRUCT);
85 tinfo_key = TINFO_color;
88 color::color(unsigned rl, const exvector & v, bool discardable) : inherited(indexed::unknown, v, discardable), representation_label(rl)
90 debugmsg("color constructor from unsigned,exvector", LOGLEVEL_CONSTRUCT);
91 tinfo_key = TINFO_color;
94 color::color(unsigned rl, exvector * vp) : inherited(indexed::unknown, vp), representation_label(rl)
96 debugmsg("color constructor from unsigned,exvector *", LOGLEVEL_CONSTRUCT);
97 tinfo_key = TINFO_color;
104 color::color(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
106 debugmsg("color constructor from archive_node", LOGLEVEL_CONSTRUCT);
107 n.find_unsigned("representation", representation_label);
110 void color::archive(archive_node &n) const
112 inherited::archive(n);
113 n.add_unsigned("representation", representation_label);
116 DEFAULT_UNARCHIVE(color)
117 DEFAULT_ARCHIVING(su3one)
118 DEFAULT_ARCHIVING(su3t)
119 DEFAULT_ARCHIVING(su3f)
120 DEFAULT_ARCHIVING(su3d)
123 // functions overriding virtual functions from bases classes
126 int color::compare_same_type(const basic & other) const
128 GINAC_ASSERT(other.tinfo() == TINFO_color);
129 const color &o = static_cast<const color &>(other);
131 if (representation_label != o.representation_label) {
132 // different representation label
133 return representation_label < o.representation_label ? -1 : 1;
136 return inherited::compare_same_type(other);
139 DEFAULT_COMPARE(su3one)
140 DEFAULT_COMPARE(su3t)
141 DEFAULT_COMPARE(su3f)
142 DEFAULT_COMPARE(su3d)
144 DEFAULT_PRINT(su3one, "ONE")
145 DEFAULT_PRINT(su3t, "T")
146 DEFAULT_PRINT(su3f, "f")
147 DEFAULT_PRINT(su3d, "d")
149 /** Perform automatic simplification on noncommutative product of color
150 * objects. This removes superfluous ONEs. */
151 ex color::simplify_ncmul(const exvector & v) const
153 //!! TODO: sort by representation label
157 exvector::const_iterator it = v.begin(), itend = v.end();
158 while (it != itend) {
159 if (!is_ex_of_type(it->op(0), su3one))
165 return color(su3one());
166 else if (s.size() == v.size())
167 return simplified_ncmul(v);
169 return simplified_ncmul(s);
172 ex color::thisexprseq(const exvector & v) const
174 return color(representation_label, v);
177 ex color::thisexprseq(exvector * vp) const
179 return color(representation_label, vp);
182 /** Given a vector iv3 of three indices and a vector iv2 of two indices that
183 * is a subset of iv3, return the (free) index that is in iv3 but not in
184 * iv2 and the sign introduced by permuting that index to the front.
186 * @param iv3 Vector of 3 indices
187 * @param iv2 Vector of 2 indices, must be a subset of iv3
188 * @param sig Returs sign introduced by index permutation
189 * @return the free index (the one that is in iv3 but not in iv2) */
190 static ex permute_free_index_to_front(const exvector & iv3, const exvector & iv2, int & sig)
192 GINAC_ASSERT(iv3.size() == 3);
193 GINAC_ASSERT(iv2.size() == 2);
197 #define TEST_PERMUTATION(A,B,C,P) \
198 if (iv3[B].is_equal(iv2[0]) && iv3[C].is_equal(iv2[1])) { \
203 TEST_PERMUTATION(0,1,2, 1);
204 TEST_PERMUTATION(0,2,1, -1);
205 TEST_PERMUTATION(1,0,2, -1);
206 TEST_PERMUTATION(1,2,0, 1);
207 TEST_PERMUTATION(2,0,1, 1);
208 TEST_PERMUTATION(2,1,0, -1);
210 throw(std::logic_error("permute_free_index_to_front(): no valid permutation found"));
213 /** Automatic symbolic evaluation of indexed symmetric structure constant. */
214 ex su3d::eval_indexed(const basic & i) const
216 GINAC_ASSERT(is_of_type(i, indexed));
217 GINAC_ASSERT(i.nops() == 4);
218 GINAC_ASSERT(is_ex_of_type(i.op(0), su3d));
220 // Convolutions are zero
221 if (static_cast<const indexed &>(i).get_dummy_indices().size() != 0)
224 // Numeric evaluation
225 if (static_cast<const indexed &>(i).all_index_values_are(info_flags::nonnegint)) {
229 for (unsigned j=0; j<3; j++)
230 v[j] = ex_to_numeric(ex_to_idx(i.op(j + 1)).get_value()).to_int();
231 if (v[0] > v[1]) std::swap(v[0], v[1]);
232 if (v[0] > v[2]) std::swap(v[0], v[2]);
233 if (v[1] > v[2]) std::swap(v[1], v[2]);
235 #define CMPINDICES(A,B,C) ((v[0] == (A)) && (v[1] == (B)) && (v[2] == (C)))
237 // Check for non-zero elements
238 if (CMPINDICES(1,4,6) || CMPINDICES(1,5,7) || CMPINDICES(2,5,6)
239 || CMPINDICES(3,4,4) || CMPINDICES(3,5,5))
241 else if (CMPINDICES(2,4,7) || CMPINDICES(3,6,6) || CMPINDICES(3,7,7))
243 else if (CMPINDICES(1,1,8) || CMPINDICES(2,2,8) || CMPINDICES(3,3,8))
244 return sqrt(_ex3())/3;
245 else if (CMPINDICES(8,8,8))
246 return -sqrt(_ex3())/3;
247 else if (CMPINDICES(4,4,8) || CMPINDICES(5,5,8)
248 || CMPINDICES(6,6,8) || CMPINDICES(7,7,8))
249 return -sqrt(_ex3())/6;
254 // No further simplifications
258 /** Automatic symbolic evaluation of indexed antisymmetric structure constant. */
259 ex su3f::eval_indexed(const basic & i) const
261 GINAC_ASSERT(is_of_type(i, indexed));
262 GINAC_ASSERT(i.nops() == 4);
263 GINAC_ASSERT(is_ex_of_type(i.op(0), su3f));
265 // Numeric evaluation
266 if (static_cast<const indexed &>(i).all_index_values_are(info_flags::nonnegint)) {
268 // Sort indices, remember permutation sign
270 for (unsigned j=0; j<3; j++)
271 v[j] = ex_to_numeric(ex_to_idx(i.op(j + 1)).get_value()).to_int();
273 if (v[0] > v[1]) { std::swap(v[0], v[1]); sign = -sign; }
274 if (v[0] > v[2]) { std::swap(v[0], v[2]); sign = -sign; }
275 if (v[1] > v[2]) { std::swap(v[1], v[2]); sign = -sign; }
277 // Check for non-zero elements
278 if (CMPINDICES(1,2,3))
280 else if (CMPINDICES(1,4,7) || CMPINDICES(2,4,6)
281 || CMPINDICES(2,5,7) || CMPINDICES(3,4,5))
282 return _ex1_2() * sign;
283 else if (CMPINDICES(1,5,6) || CMPINDICES(3,6,7))
284 return _ex_1_2() * sign;
285 else if (CMPINDICES(4,5,8) || CMPINDICES(6,7,8))
286 return sqrt(_ex3())/2 * sign;
291 // No further simplifications
296 /** Contraction of an indexed symmetric structure constant with something else. */
297 bool su3d::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const
299 GINAC_ASSERT(is_ex_of_type(*self, indexed));
300 GINAC_ASSERT(is_ex_of_type(*other, indexed));
301 GINAC_ASSERT(self->nops() == 4);
302 GINAC_ASSERT(is_ex_of_type(self->op(0), su3d));
304 if (is_ex_exactly_of_type(other->op(0), su3d) || is_ex_exactly_of_type(other->op(0), su3f)) {
306 // Find the dummy indices of the contraction
307 exvector dummy_indices;
308 dummy_indices = ex_to_indexed(*self).get_dummy_indices(ex_to_indexed(*other));
310 if (is_ex_exactly_of_type(other->op(0), su3d)) {
313 if (dummy_indices.size() == 3) {
314 *self = numeric(40, 3);
318 // d.akl*d.bkl=5/3*delta.ab
319 } else if (dummy_indices.size() == 2) {
320 exvector a = index_set_difference(ex_to_indexed(*self).get_indices(), dummy_indices);
321 exvector b = index_set_difference(ex_to_indexed(*other).get_indices(), dummy_indices);
322 GINAC_ASSERT(a.size() > 0);
323 GINAC_ASSERT(b.size() > 0);
324 *self = numeric(5, 3) * delta_tensor(a[0], b[0]);
331 // d.akl*f.bkl=0 (includes the case a=b)
332 if (dummy_indices.size() >= 2) {
343 /** Contraction of an indexed antisymmetric structure constant with something else. */
344 bool su3f::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const
346 GINAC_ASSERT(is_ex_of_type(*self, indexed));
347 GINAC_ASSERT(is_ex_of_type(*other, indexed));
348 GINAC_ASSERT(self->nops() == 4);
349 GINAC_ASSERT(is_ex_of_type(self->op(0), su3f));
351 if (is_ex_exactly_of_type(other->op(0), su3f)) { // f*d is handled by su3d class
353 // Find the dummy indices of the contraction
354 exvector dummy_indices;
355 dummy_indices = ex_to_indexed(*self).get_dummy_indices(ex_to_indexed(*other));
358 if (dummy_indices.size() == 3) {
363 // f.akl*f.bkl=3*delta.ab
364 } else if (dummy_indices.size() == 2) {
366 ex a = permute_free_index_to_front(ex_to_indexed(*self).get_indices(), dummy_indices, sign1);
367 ex b = permute_free_index_to_front(ex_to_indexed(*other).get_indices(), dummy_indices, sign2);
368 *self = sign1 * sign2 * 3 * delta_tensor(a, b);
381 ex color_ONE(unsigned rl)
383 return color(su3one(), rl);
386 ex color_T(const ex & a, unsigned rl)
388 if (!is_ex_of_type(a, idx))
389 throw(std::invalid_argument("indices of color_T must be of type idx"));
390 if (!ex_to_idx(a).get_dim().is_equal(8))
391 throw(std::invalid_argument("index dimension for color_T must be 8"));
393 return color(su3t(), a, rl);
396 ex color_f(const ex & a, const ex & b, const ex & c)
398 if (!is_ex_of_type(a, idx) || !is_ex_of_type(b, idx) || !is_ex_of_type(c, idx))
399 throw(std::invalid_argument("indices of color_f must be of type idx"));
400 if (!ex_to_idx(a).get_dim().is_equal(8) || !ex_to_idx(b).get_dim().is_equal(8) || !ex_to_idx(c).get_dim().is_equal(8))
401 throw(std::invalid_argument("index dimension for color_f must be 8"));
403 return indexed(su3f(), indexed::antisymmetric, a, b, c);
406 ex color_d(const ex & a, const ex & b, const ex & c)
408 if (!is_ex_of_type(a, idx) || !is_ex_of_type(b, idx) || !is_ex_of_type(c, idx))
409 throw(std::invalid_argument("indices of color_d must be of type idx"));
410 if (!ex_to_idx(a).get_dim().is_equal(8) || !ex_to_idx(b).get_dim().is_equal(8) || !ex_to_idx(c).get_dim().is_equal(8))
411 throw(std::invalid_argument("index dimension for color_d must be 8"));
413 return indexed(su3d(), indexed::symmetric, a, b, c);
416 ex color_h(const ex & a, const ex & b, const ex & c)
418 return color_d(a, b, c) + I * color_f(a, b, c);