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