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