2693d9266d30a68c32cf851778f3e40c3b74a621
[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-2005 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 #include <iostream>
24 #include <stdexcept>
25
26 #include "color.h"
27 #include "idx.h"
28 #include "ncmul.h"
29 #include "symmetry.h"
30 #include "operators.h"
31 #include "numeric.h"
32 #include "mul.h"
33 #include "power.h" // for sqrt()
34 #include "symbol.h"
35 #include "archive.h"
36 #include "utils.h"
37
38 namespace GiNaC {
39
40 GINAC_IMPLEMENT_REGISTERED_CLASS(color, indexed)
41
42 GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(su3one, tensor,
43   print_func<print_dflt>(&su3one::do_print).
44   print_func<print_latex>(&su3one::do_print_latex))
45
46 GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(su3t, tensor,
47   print_func<print_dflt>(&su3t::do_print).
48   print_func<print_latex>(&su3t::do_print))
49
50 GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(su3f, tensor,
51   print_func<print_dflt>(&su3f::do_print).
52   print_func<print_latex>(&su3f::do_print))
53
54 GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(su3d, tensor,
55   print_func<print_dflt>(&su3d::do_print).
56   print_func<print_latex>(&su3d::do_print))
57
58 //////////
59 // default constructors
60 //////////
61
62 color::color() : representation_label(0)
63 {
64         tinfo_key = TINFO_color;
65 }
66
67 DEFAULT_CTOR(su3one)
68 DEFAULT_CTOR(su3t)
69 DEFAULT_CTOR(su3f)
70 DEFAULT_CTOR(su3d)
71
72 //////////
73 // other constructors
74 //////////
75
76 /** Construct object without any color index. This constructor is for
77  *  internal use only. Use the color_ONE() function instead.
78  *  @see color_ONE */
79 color::color(const ex & b, unsigned char rl) : inherited(b), representation_label(rl)
80 {
81         tinfo_key = TINFO_color;
82 }
83
84 /** Construct object with one color index. This constructor is for internal
85  *  use only. Use the color_T() function instead.
86  *  @see color_T */
87 color::color(const ex & b, const ex & i1, unsigned char rl) : inherited(b, i1), representation_label(rl)
88 {
89         tinfo_key = TINFO_color;
90 }
91
92 color::color(unsigned char rl, const exvector & v, bool discardable) : inherited(not_symmetric(), v, discardable), representation_label(rl)
93 {
94         tinfo_key = TINFO_color;
95 }
96
97 color::color(unsigned char rl, std::auto_ptr<exvector> vp) : inherited(not_symmetric(), vp), representation_label(rl)
98 {
99         tinfo_key = TINFO_color;
100 }
101
102 //////////
103 // archiving
104 //////////
105
106 color::color(const archive_node &n, lst &sym_lst) : inherited(n, sym_lst)
107 {
108         unsigned rl;
109         n.find_unsigned("label", rl);
110         representation_label = rl;
111 }
112
113 void color::archive(archive_node &n) const
114 {
115         inherited::archive(n);
116         n.add_unsigned("label", representation_label);
117 }
118
119 DEFAULT_UNARCHIVE(color)
120 DEFAULT_ARCHIVING(su3one)
121 DEFAULT_ARCHIVING(su3t)
122 DEFAULT_ARCHIVING(su3f)
123 DEFAULT_ARCHIVING(su3d)
124
125 //////////
126 // functions overriding virtual functions from base classes
127 //////////
128
129 int color::compare_same_type(const basic & other) const
130 {
131         GINAC_ASSERT(is_a<color>(other));
132         const color &o = static_cast<const color &>(other);
133
134         if (representation_label != o.representation_label) {
135                 // different representation label
136                 return representation_label < o.representation_label ? -1 : 1;
137         }
138
139         return inherited::compare_same_type(other);
140 }
141
142 bool color::match_same_type(const basic & other) const
143 {
144         GINAC_ASSERT(is_a<color>(other));
145         const color &o = static_cast<const color &>(other);
146
147         return representation_label == o.representation_label;
148 }
149
150 DEFAULT_COMPARE(su3one)
151 DEFAULT_COMPARE(su3t)
152 DEFAULT_COMPARE(su3f)
153 DEFAULT_COMPARE(su3d)
154
155 DEFAULT_PRINT_LATEX(su3one, "ONE", "\\mathbb{1}")
156 DEFAULT_PRINT(su3t, "T")
157 DEFAULT_PRINT(su3f, "f")
158 DEFAULT_PRINT(su3d, "d")
159
160 /** Perform automatic simplification on noncommutative product of color
161  *  objects. This removes superfluous ONEs. */
162 ex color::eval_ncmul(const exvector & v) const
163 {
164         exvector s;
165         s.reserve(v.size());
166
167         // Remove superfluous ONEs
168         exvector::const_iterator it = v.begin(), itend = v.end();
169         while (it != itend) {
170                 if (!is_a<su3one>(it->op(0)))
171                         s.push_back(*it);
172                 it++;
173         }
174
175         if (s.empty())
176                 return color(su3one(), representation_label);
177         else
178                 return hold_ncmul(s);
179 }
180
181 ex color::thiscontainer(const exvector & v) const
182 {
183         return color(representation_label, v);
184 }
185
186 ex color::thiscontainer(std::auto_ptr<exvector> vp) const
187 {
188         return color(representation_label, vp);
189 }
190
191 /** Given a vector iv3 of three indices and a vector iv2 of two indices that
192  *  is a subset of iv3, return the (free) index that is in iv3 but not in
193  *  iv2 and the sign introduced by permuting that index to the front.
194  *
195  *  @param iv3 Vector of 3 indices
196  *  @param iv2 Vector of 2 indices, must be a subset of iv3
197  *  @param sig Returs sign introduced by index permutation
198  *  @return the free index (the one that is in iv3 but not in iv2) */
199 static ex permute_free_index_to_front(const exvector & iv3, const exvector & iv2, int & sig)
200 {
201         GINAC_ASSERT(iv3.size() == 3);
202         GINAC_ASSERT(iv2.size() == 2);
203
204         sig = 1;
205
206 #define TEST_PERMUTATION(A,B,C,P) \
207         if (iv3[B].is_equal(iv2[0]) && iv3[C].is_equal(iv2[1])) { \
208                 sig = P; \
209                 return iv3[A]; \
210         }
211         
212         TEST_PERMUTATION(0,1,2,  1);
213         TEST_PERMUTATION(0,2,1, -1);
214         TEST_PERMUTATION(1,0,2, -1);
215         TEST_PERMUTATION(1,2,0,  1);
216         TEST_PERMUTATION(2,0,1,  1);
217         TEST_PERMUTATION(2,1,0, -1);
218
219         throw(std::logic_error("permute_free_index_to_front(): no valid permutation found"));
220 }
221
222 /** Automatic symbolic evaluation of indexed symmetric structure constant. */
223 ex su3d::eval_indexed(const basic & i) const
224 {
225         GINAC_ASSERT(is_a<indexed>(i));
226         GINAC_ASSERT(i.nops() == 4);
227         GINAC_ASSERT(is_a<su3d>(i.op(0)));
228
229         // Convolutions are zero
230         if (!(static_cast<const indexed &>(i).get_dummy_indices().empty()))
231                 return _ex0;
232
233         // Numeric evaluation
234         if (static_cast<const indexed &>(i).all_index_values_are(info_flags::nonnegint)) {
235
236                 // Sort indices
237                 int v[3];
238                 for (unsigned j=0; j<3; j++)
239                         v[j] = ex_to<numeric>(ex_to<idx>(i.op(j + 1)).get_value()).to_int();
240                 if (v[0] > v[1]) std::swap(v[0], v[1]);
241                 if (v[0] > v[2]) std::swap(v[0], v[2]);
242                 if (v[1] > v[2]) std::swap(v[1], v[2]);
243
244 #define CMPINDICES(A,B,C) ((v[0] == (A)) && (v[1] == (B)) && (v[2] == (C)))
245
246                 // Check for non-zero elements
247                 if (CMPINDICES(1,4,6) || CMPINDICES(1,5,7) || CMPINDICES(2,5,6)
248                  || CMPINDICES(3,4,4) || CMPINDICES(3,5,5))
249                         return _ex1_2;
250                 else if (CMPINDICES(2,4,7) || CMPINDICES(3,6,6) || CMPINDICES(3,7,7))
251                         return _ex_1_2;
252                 else if (CMPINDICES(1,1,8) || CMPINDICES(2,2,8) || CMPINDICES(3,3,8))
253                         return sqrt(_ex3)*_ex1_3;
254                 else if (CMPINDICES(8,8,8))
255                         return sqrt(_ex3)*_ex_1_3;
256                 else if (CMPINDICES(4,4,8) || CMPINDICES(5,5,8)
257                       || CMPINDICES(6,6,8) || CMPINDICES(7,7,8))
258                         return sqrt(_ex3)/_ex_6;
259                 else
260                         return _ex0;
261         }
262
263         // No further simplifications
264         return i.hold();
265 }
266
267 /** Automatic symbolic evaluation of indexed antisymmetric structure constant. */
268 ex su3f::eval_indexed(const basic & i) const
269 {
270         GINAC_ASSERT(is_a<indexed>(i));
271         GINAC_ASSERT(i.nops() == 4);
272         GINAC_ASSERT(is_a<su3f>(i.op(0)));
273
274         // Numeric evaluation
275         if (static_cast<const indexed &>(i).all_index_values_are(info_flags::nonnegint)) {
276
277                 // Sort indices, remember permutation sign
278                 int v[3];
279                 for (unsigned j=0; j<3; j++)
280                         v[j] = ex_to<numeric>(ex_to<idx>(i.op(j + 1)).get_value()).to_int();
281                 int sign = 1;
282                 if (v[0] > v[1]) { std::swap(v[0], v[1]); sign = -sign; }
283                 if (v[0] > v[2]) { std::swap(v[0], v[2]); sign = -sign; }
284                 if (v[1] > v[2]) { std::swap(v[1], v[2]); sign = -sign; }
285
286                 // Check for non-zero elements
287                 if (CMPINDICES(1,2,3))
288                         return sign;
289                 else if (CMPINDICES(1,4,7) || CMPINDICES(2,4,6)
290                       || CMPINDICES(2,5,7) || CMPINDICES(3,4,5))
291                         return _ex1_2 * sign;
292                 else if (CMPINDICES(1,5,6) || CMPINDICES(3,6,7))
293                         return _ex_1_2 * sign;
294                 else if (CMPINDICES(4,5,8) || CMPINDICES(6,7,8))
295                         return sqrt(_ex3)/2 * sign;
296                 else
297                         return _ex0;
298         }
299
300         // No further simplifications
301         return i.hold();
302 }
303
304
305 /** Contraction of generator with something else. */
306 bool su3t::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const
307 {
308         GINAC_ASSERT(is_a<indexed>(*self));
309         GINAC_ASSERT(is_a<indexed>(*other));
310         GINAC_ASSERT(self->nops() == 2);
311         GINAC_ASSERT(is_a<su3t>(self->op(0)));
312         unsigned char rl = ex_to<color>(*self).get_representation_label();
313
314         if (is_exactly_a<su3t>(other->op(0))) {
315
316                 // Contraction only makes sense if the represenation labels are equal
317                 GINAC_ASSERT(is_a<color>(*other));
318                 if (ex_to<color>(*other).get_representation_label() != rl)
319                         return false;
320
321                 // T.a T.a = 4/3 ONE
322                 if (other - self == 1) {
323                         *self = numeric(4, 3);
324                         *other = color_ONE(rl);
325                         return true;
326
327                 // T.a T.b T.a = -1/6 T.b
328                 } else if (other - self == 2
329                         && is_a<color>(self[1])) {
330                         *self = numeric(-1, 6);
331                         *other = _ex1;
332                         return true;
333
334                 // T.a S T.a = 1/2 Tr(S) - 1/6 S
335                 } else {
336                         exvector::iterator it = self + 1;
337                         while (it != other) {
338                                 if (!is_a<color>(*it)) {
339                                         return false;
340                                 }
341                                 it++;
342                         }
343
344                         it = self + 1;
345                         ex S = _ex1;
346                         while (it != other) {
347                                 S *= *it;
348                                 *it++ = _ex1;
349                         }
350
351                         *self = color_trace(S, rl) * color_ONE(rl) / 2 - S / 6;
352                         *other = _ex1;
353                         return true;
354                 }
355         }
356
357         return false;
358 }
359
360 /** Contraction of an indexed symmetric structure constant with something else. */
361 bool su3d::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const
362 {
363         GINAC_ASSERT(is_a<indexed>(*self));
364         GINAC_ASSERT(is_a<indexed>(*other));
365         GINAC_ASSERT(self->nops() == 4);
366         GINAC_ASSERT(is_a<su3d>(self->op(0)));
367
368         if (is_exactly_a<su3d>(other->op(0))) {
369
370                 // Find the dummy indices of the contraction
371                 exvector self_indices = ex_to<indexed>(*self).get_indices();
372                 exvector other_indices = ex_to<indexed>(*other).get_indices();
373                 exvector all_indices = self_indices;
374                 all_indices.insert(all_indices.end(), other_indices.begin(), other_indices.end());
375                 exvector free_indices, dummy_indices;
376                 find_free_and_dummy(all_indices, free_indices, dummy_indices);
377
378                 // d.abc d.abc = 40/3
379                 if (dummy_indices.size() == 3) {
380                         *self = numeric(40, 3);
381                         *other = _ex1;
382                         return true;
383
384                 // d.akl d.bkl = 5/3 delta.ab
385                 } else if (dummy_indices.size() == 2) {
386                         exvector a;
387                         std::back_insert_iterator<exvector> ita(a);
388                         ita = set_difference(self_indices.begin(), self_indices.end(), dummy_indices.begin(), dummy_indices.end(), ita, ex_is_less());
389                         ita = set_difference(other_indices.begin(), other_indices.end(), dummy_indices.begin(), dummy_indices.end(), ita, ex_is_less());
390                         GINAC_ASSERT(a.size() == 2);
391                         *self = numeric(5, 3) * delta_tensor(a[0], a[1]);
392                         *other = _ex1;
393                         return true;
394                 }
395
396         } else if (is_exactly_a<su3t>(other->op(0))) {
397
398                 // d.abc T.b T.c = 5/6 T.a
399                 if (other+1 != v.end()
400                  && is_exactly_a<su3t>(other[1].op(0))
401                  && ex_to<indexed>(*self).has_dummy_index_for(other[1].op(1))) {
402
403                         exvector self_indices = ex_to<indexed>(*self).get_indices();
404                         exvector dummy_indices;
405                         dummy_indices.push_back(other[0].op(1));
406                         dummy_indices.push_back(other[1].op(1));
407                         int sig;
408                         ex a = permute_free_index_to_front(self_indices, dummy_indices, sig);
409                         *self = numeric(5, 6);
410                         other[0] = color_T(a, ex_to<color>(other[0]).get_representation_label());
411                         other[1] = _ex1;
412                         return true;
413                 }
414         }
415
416         return false;
417 }
418
419 /** Contraction of an indexed antisymmetric structure constant with something else. */
420 bool su3f::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const
421 {
422         GINAC_ASSERT(is_a<indexed>(*self));
423         GINAC_ASSERT(is_a<indexed>(*other));
424         GINAC_ASSERT(self->nops() == 4);
425         GINAC_ASSERT(is_a<su3f>(self->op(0)));
426
427         if (is_exactly_a<su3f>(other->op(0))) { // f*d is handled by su3d class
428
429                 // Find the dummy indices of the contraction
430                 exvector dummy_indices;
431                 dummy_indices = ex_to<indexed>(*self).get_dummy_indices(ex_to<indexed>(*other));
432
433                 // f.abc f.abc = 24
434                 if (dummy_indices.size() == 3) {
435                         *self = 24;
436                         *other = _ex1;
437                         return true;
438
439                 // f.akl f.bkl = 3 delta.ab
440                 } else if (dummy_indices.size() == 2) {
441                         int sign1, sign2;
442                         ex a = permute_free_index_to_front(ex_to<indexed>(*self).get_indices(), dummy_indices, sign1);
443                         ex b = permute_free_index_to_front(ex_to<indexed>(*other).get_indices(), dummy_indices, sign2);
444                         *self = sign1 * sign2 * 3 * delta_tensor(a, b);
445                         *other = _ex1;
446                         return true;
447                 }
448
449         } else if (is_exactly_a<su3t>(other->op(0))) {
450
451                 // f.abc T.b T.c = 3/2 I T.a
452                 if (other+1 != v.end()
453                  && is_exactly_a<su3t>(other[1].op(0))
454                  && ex_to<indexed>(*self).has_dummy_index_for(other[1].op(1))) {
455
456                         exvector self_indices = ex_to<indexed>(*self).get_indices();
457                         exvector dummy_indices;
458                         dummy_indices.push_back(other[0].op(1));
459                         dummy_indices.push_back(other[1].op(1));
460                         int sig;
461                         ex a = permute_free_index_to_front(self_indices, dummy_indices, sig);
462                         *self = numeric(3, 2) * sig * I;
463                         other[0] = color_T(a, ex_to<color>(other[0]).get_representation_label());
464                         other[1] = _ex1;
465                         return true;
466                 }
467         }
468
469         return false;
470 }
471
472 //////////
473 // global functions
474 //////////
475
476 ex color_ONE(unsigned char rl)
477 {
478         static ex ONE = (new su3one)->setflag(status_flags::dynallocated);
479         return color(ONE, rl);
480 }
481
482 ex color_T(const ex & a, unsigned char rl)
483 {
484         static ex t = (new su3t)->setflag(status_flags::dynallocated);
485
486         if (!is_a<idx>(a))
487                 throw(std::invalid_argument("indices of color_T must be of type idx"));
488         if (!ex_to<idx>(a).get_dim().is_equal(8))
489                 throw(std::invalid_argument("index dimension for color_T must be 8"));
490
491         return color(t, a, rl);
492 }
493
494 ex color_f(const ex & a, const ex & b, const ex & c)
495 {
496         static ex f = (new su3f)->setflag(status_flags::dynallocated);
497
498         if (!is_a<idx>(a) || !is_a<idx>(b) || !is_a<idx>(c))
499                 throw(std::invalid_argument("indices of color_f must be of type idx"));
500         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))
501                 throw(std::invalid_argument("index dimension for color_f must be 8"));
502
503         return indexed(f, antisymmetric3(), a, b, c);
504 }
505
506 ex color_d(const ex & a, const ex & b, const ex & c)
507 {
508         static ex d = (new su3d)->setflag(status_flags::dynallocated);
509
510         if (!is_a<idx>(a) || !is_a<idx>(b) || !is_a<idx>(c))
511                 throw(std::invalid_argument("indices of color_d must be of type idx"));
512         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))
513                 throw(std::invalid_argument("index dimension for color_d must be 8"));
514
515         return indexed(d, symmetric3(), a, b, c);
516 }
517
518 ex color_h(const ex & a, const ex & b, const ex & c)
519 {
520         return color_d(a, b, c) + I * color_f(a, b, c);
521 }
522
523 /** Check whether a given tinfo key (as returned by return_type_tinfo()
524  *  is that of a color object with the specified representation label. */
525 static bool is_color_tinfo(unsigned ti, unsigned char rl)
526 {
527         return ti == (TINFO_color + rl);
528 }
529
530 /** Check whether a given tinfo key (as returned by return_type_tinfo()
531  *  is that of a color object (with an arbitrary representation label). */
532 static bool is_color_tinfo(unsigned ti)
533 {
534         return (ti & ~0xff) == TINFO_color;
535 }
536
537 /** Extract representation label from tinfo key (as returned by
538  *  return_type_tinfo()). */
539 static unsigned char get_representation_label(unsigned ti)
540 {
541         return ti & 0xff;
542 }
543
544 ex color_trace(const ex & e, const std::set<unsigned char> & rls)
545 {
546         if (is_a<color>(e)) {
547
548                 unsigned char rl = ex_to<color>(e).get_representation_label();
549
550                 // Are we taking the trace over this object's representation label?
551                 if (rls.find(rl) == rls.end())
552                         return e;
553
554                 // Yes, all generators are traceless, except for color_ONE
555                 if (is_a<su3one>(e.op(0)))
556                         return _ex3;
557                 else
558                         return _ex0;
559
560         } else if (is_exactly_a<mul>(e)) {
561
562                 // Trace of product: pull out non-color factors
563                 ex prod = _ex1;
564                 for (size_t i=0; i<e.nops(); i++) {
565                         const ex &o = e.op(i);
566                         if (is_color_tinfo(o.return_type_tinfo()))
567                                 prod *= color_trace(o, rls);
568                         else
569                                 prod *= o;
570                 }
571                 return prod;
572
573         } else if (is_exactly_a<ncmul>(e)) {
574
575                 unsigned char rl = get_representation_label(e.return_type_tinfo());
576
577                 // Are we taking the trace over this string's representation label?
578                 if (rls.find(rl) == rls.end())
579                         return e;
580
581                 // Yes, expand product if necessary
582                 ex e_expanded = e.expand();
583                 if (!is_a<ncmul>(e_expanded))
584                         return color_trace(e_expanded, rls);
585
586                 size_t num = e.nops();
587
588                 if (num == 2) {
589
590                         // Tr T_a T_b = 1/2 delta_a_b
591                         return delta_tensor(e.op(0).op(1), e.op(1).op(1)) / 2;
592
593                 } else if (num == 3) {
594
595                         // Tr T_a T_b T_c = 1/4 h_a_b_c
596                         return color_h(e.op(0).op(1), e.op(1).op(1), e.op(2).op(1)) / 4;
597
598                 } else {
599
600                         // Traces of 4 or more generators are computed recursively:
601                         // Tr T_a1 .. T_an =
602                         //     1/6 delta_a(n-1)_an Tr T_a1 .. T_a(n-2)
603                         //   + 1/2 h_a(n-1)_an_k Tr T_a1 .. T_a(n-2) T_k
604                         const ex &last_index = e.op(num - 1).op(1);
605                         const ex &next_to_last_index = e.op(num - 2).op(1);
606                         idx summation_index((new symbol)->setflag(status_flags::dynallocated), 8);
607
608                         exvector v1;
609                         v1.reserve(num - 2);
610                         for (size_t i=0; i<num-2; i++)
611                                 v1.push_back(e.op(i));
612
613                         exvector v2 = v1;
614                         v2.push_back(color_T(summation_index, rl));
615
616                         return delta_tensor(next_to_last_index, last_index) * color_trace(ncmul(v1), rl) / 6
617                                + color_h(next_to_last_index, last_index, summation_index) * color_trace(ncmul(v2), rl) / 2;
618                 }
619
620         } else if (e.nops() > 0) {
621
622                 // Trace maps to all other container classes (this includes sums)
623                 pointer_to_map_function_1arg<const std::set<unsigned char> &> fcn(color_trace, rls);
624                 return e.map(fcn);
625
626         } else
627                 return _ex0;
628 }
629
630 ex color_trace(const ex & e, const lst & rll)
631 {
632         // Convert list to set
633         std::set<unsigned char> rls;
634         for (lst::const_iterator i = rll.begin(); i != rll.end(); ++i) {
635                 if (i->info(info_flags::nonnegint))
636                         rls.insert(ex_to<numeric>(*i).to_int());
637         }
638
639         return color_trace(e, rls);
640 }
641
642 ex color_trace(const ex & e, unsigned char rl)
643 {
644         // Convert label to set
645         std::set<unsigned char> rls;
646         rls.insert(rl);
647
648         return color_trace(e, rls);
649 }
650
651 } // namespace GiNaC