3 * Implementation of GiNaC's clifford algebra (Dirac gamma) objects. */
6 * GiNaC Copyright (C) 1999-2005 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
31 #include "numeric.h" // for I
34 #include "relational.h"
35 #include "operators.h"
45 GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(clifford, indexed,
46 print_func<print_dflt>(&clifford::do_print_dflt).
47 print_func<print_latex>(&clifford::do_print_latex))
49 GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(diracone, tensor,
50 print_func<print_dflt>(&diracone::do_print).
51 print_func<print_latex>(&diracone::do_print_latex))
53 GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(cliffordunit, tensor,
54 print_func<print_dflt>(&cliffordunit::do_print).
55 print_func<print_latex>(&cliffordunit::do_print_latex))
57 GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(diracgamma, cliffordunit,
58 print_func<print_dflt>(&diracgamma::do_print).
59 print_func<print_latex>(&diracgamma::do_print_latex))
61 GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(diracgamma5, tensor,
62 print_func<print_dflt>(&diracgamma5::do_print).
63 print_func<print_latex>(&diracgamma5::do_print_latex))
65 GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(diracgammaL, tensor,
66 print_func<print_context>(&diracgammaL::do_print).
67 print_func<print_latex>(&diracgammaL::do_print_latex))
69 GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(diracgammaR, tensor,
70 print_func<print_context>(&diracgammaR::do_print).
71 print_func<print_latex>(&diracgammaR::do_print_latex))
74 // default constructors
77 clifford::clifford() : representation_label(0), metric(0), anticommuting(true), commutator_sign(-1)
79 tinfo_key = TINFO_clifford;
82 DEFAULT_CTOR(diracone)
83 DEFAULT_CTOR(cliffordunit)
84 DEFAULT_CTOR(diracgamma)
85 DEFAULT_CTOR(diracgamma5)
86 DEFAULT_CTOR(diracgammaL)
87 DEFAULT_CTOR(diracgammaR)
93 /** Construct object without any indices. This constructor is for internal
94 * use only. Use the dirac_ONE() function instead.
96 clifford::clifford(const ex & b, unsigned char rl, bool anticommut) : inherited(b), representation_label(rl), metric(0), anticommuting(anticommut), commutator_sign(-1)
98 tinfo_key = TINFO_clifford;
101 /** Construct object with one Lorentz index. This constructor is for internal
102 * use only. Use the clifford_unit() or dirac_gamma() functions instead.
104 * @see dirac_gamma */
105 clifford::clifford(const ex & b, const ex & mu, const ex & metr, unsigned char rl, bool anticommut, int comm_sign) : inherited(b, mu), representation_label(rl), metric(metr), anticommuting(anticommut), commutator_sign(comm_sign)
107 GINAC_ASSERT(is_a<varidx>(mu));
108 tinfo_key = TINFO_clifford;
111 clifford::clifford(unsigned char rl, const ex & metr, bool anticommut, int comm_sign, const exvector & v, bool discardable) : inherited(not_symmetric(), v, discardable), representation_label(rl), metric(metr), anticommuting(anticommut), commutator_sign(comm_sign)
113 tinfo_key = TINFO_clifford;
116 clifford::clifford(unsigned char rl, const ex & metr, bool anticommut, int comm_sign, std::auto_ptr<exvector> vp) : inherited(not_symmetric(), vp), representation_label(rl), metric(metr), anticommuting(anticommut), commutator_sign(comm_sign)
118 tinfo_key = TINFO_clifford;
125 clifford::clifford(const archive_node & n, lst & sym_lst) : inherited(n, sym_lst)
128 n.find_unsigned("label", rl);
129 representation_label = rl;
130 n.find_ex("metric", metric, sym_lst);
131 n.find_bool("anticommuting", anticommuting);
132 n.find_unsigned("commutator_sign+1", rl);
133 commutator_sign = rl - 1;
136 void clifford::archive(archive_node & n) const
138 inherited::archive(n);
139 n.add_unsigned("label", representation_label);
140 n.add_ex("metric", metric);
141 n.add_bool("anticommuting", anticommuting);
142 n.add_unsigned("commutator_sign+1", commutator_sign+1);
145 DEFAULT_UNARCHIVE(clifford)
146 DEFAULT_ARCHIVING(diracone)
147 DEFAULT_ARCHIVING(cliffordunit)
148 DEFAULT_ARCHIVING(diracgamma)
149 DEFAULT_ARCHIVING(diracgamma5)
150 DEFAULT_ARCHIVING(diracgammaL)
151 DEFAULT_ARCHIVING(diracgammaR)
154 ex clifford::get_metric(const ex & i, const ex & j, bool symmetrised) const
156 if (is_a<indexed>(metric)) {
157 if (symmetrised && !(ex_to<symmetry>(ex_to<indexed>(metric).get_symmetry()).has_symmetry())) {
158 if (is_a<matrix>(metric.op(0))) {
159 return indexed((ex_to<matrix>(metric.op(0)).add(ex_to<matrix>(metric.op(0)).transpose())).mul(numeric(1,2)),
162 return simplify_indexed(indexed(metric.op(0)*_ex1_2, i, j) + indexed(metric.op(0)*_ex1_2, j, i));
165 //return indexed(metric.op(0), ex_to<symmetry>(ex_to<indexed>(metric).get_symmetry()), i, j);
166 return metric.subs(lst(metric.op(1) == i, metric.op(2) == j), subs_options::no_pattern);
169 // should not really happen since all constructors but clifford() make the metric an indexed object
170 return indexed(metric, i, j);
174 bool clifford::same_metric(const ex & other) const
176 if (is_a<clifford>(other)) {
177 return same_metric(ex_to<clifford>(other).get_metric());
178 } else if (is_a<indexed>(other)) {
179 return get_metric(other.op(1), other.op(2)).is_equal(other);
185 // functions overriding virtual functions from base classes
188 ex clifford::op(size_t i) const
190 GINAC_ASSERT(i<nops());
192 return representation_label;
194 return inherited::op(i);
197 ex & clifford::let_op(size_t i)
199 GINAC_ASSERT(i<nops());
201 static ex rl = numeric(representation_label);
202 ensure_if_modifiable();
206 return inherited::let_op(i);
209 int clifford::compare_same_type(const basic & other) const
211 GINAC_ASSERT(is_a<clifford>(other));
212 const clifford &o = static_cast<const clifford &>(other);
214 if (representation_label != o.representation_label) {
215 // different representation label
216 return representation_label < o.representation_label ? -1 : 1;
219 return inherited::compare_same_type(other);
222 bool clifford::match_same_type(const basic & other) const
224 GINAC_ASSERT(is_a<clifford>(other));
225 const clifford &o = static_cast<const clifford &>(other);
227 return ((representation_label == o.representation_label) && (commutator_sign == o.get_commutator_sign()) && same_metric(o));
230 static bool is_dirac_slash(const ex & seq0)
232 return !is_a<diracgamma5>(seq0) && !is_a<diracgammaL>(seq0) &&
233 !is_a<diracgammaR>(seq0) && !is_a<cliffordunit>(seq0) &&
234 !is_a<diracone>(seq0);
237 void clifford::do_print_dflt(const print_dflt & c, unsigned level) const
239 // dirac_slash() object is printed differently
240 if (is_dirac_slash(seq[0])) {
241 seq[0].print(c, precedence());
244 this->print_dispatch<inherited>(c, level);
247 void clifford::do_print_latex(const print_latex & c, unsigned level) const
249 // dirac_slash() object is printed differently
250 if (is_dirac_slash(seq[0])) {
252 seq[0].print(c, precedence());
253 c.s << "\\hspace{-1.0ex}/}";
255 c.s << "\\clifford[" << int(representation_label) << "]";
256 this->print_dispatch<inherited>(c, level);
260 DEFAULT_COMPARE(diracone)
261 DEFAULT_COMPARE(cliffordunit)
262 DEFAULT_COMPARE(diracgamma)
263 DEFAULT_COMPARE(diracgamma5)
264 DEFAULT_COMPARE(diracgammaL)
265 DEFAULT_COMPARE(diracgammaR)
267 DEFAULT_PRINT_LATEX(diracone, "ONE", "\\mathbf{1}")
268 DEFAULT_PRINT_LATEX(cliffordunit, "e", "e")
269 DEFAULT_PRINT_LATEX(diracgamma, "gamma", "\\gamma")
270 DEFAULT_PRINT_LATEX(diracgamma5, "gamma5", "{\\gamma^5}")
271 DEFAULT_PRINT_LATEX(diracgammaL, "gammaL", "{\\gamma_L}")
272 DEFAULT_PRINT_LATEX(diracgammaR, "gammaR", "{\\gamma_R}")
274 /** This function decomposes gamma~mu -> (1, mu) and a\ -> (a.ix, ix) */
275 static void base_and_index(const ex & c, ex & b, ex & i)
277 GINAC_ASSERT(is_a<clifford>(c));
278 GINAC_ASSERT(c.nops() == 2+1);
280 if (is_a<cliffordunit>(c.op(0))) { // proper dirac gamma object or clifford unit
283 } else if (is_a<diracgamma5>(c.op(0)) || is_a<diracgammaL>(c.op(0)) || is_a<diracgammaR>(c.op(0))) { // gamma5/L/R
286 } else { // slash object, generate new dummy index
287 varidx ix((new symbol)->setflag(status_flags::dynallocated), ex_to<idx>(c.op(1)).get_dim());
288 b = indexed(c.op(0), ix.toggle_variance());
293 /** Predicate for finding non-clifford objects. */
294 struct is_not_a_clifford : public std::unary_function<ex, bool> {
295 bool operator()(const ex & e)
297 return !is_a<clifford>(e);
301 /** Contraction of a gamma matrix with something else. */
302 bool diracgamma::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const
304 GINAC_ASSERT(is_a<clifford>(*self));
305 GINAC_ASSERT(is_a<indexed>(*other));
306 GINAC_ASSERT(is_a<diracgamma>(self->op(0)));
307 unsigned char rl = ex_to<clifford>(*self).get_representation_label();
309 ex dim = ex_to<idx>(self->op(1)).get_dim();
310 if (other->nops() > 1)
311 dim = minimal_dim(dim, ex_to<idx>(other->op(1)).get_dim());
313 if (is_a<clifford>(*other)) {
315 // Contraction only makes sense if the represenation labels are equal
316 if (ex_to<clifford>(*other).get_representation_label() != rl)
319 size_t num = other - self;
321 // gamma~mu gamma.mu = dim ONE
324 *other = dirac_ONE(rl);
327 // gamma~mu gamma~alpha gamma.mu = (2-dim) gamma~alpha
329 && is_a<clifford>(self[1])) {
334 // gamma~mu gamma~alpha gamma~beta gamma.mu = 4 g~alpha~beta + (dim-4) gamam~alpha gamma~beta
336 && is_a<clifford>(self[1])
337 && is_a<clifford>(self[2])) {
339 base_and_index(self[1], b1, i1);
340 base_and_index(self[2], b2, i2);
341 *self = 4 * lorentz_g(i1, i2) * b1 * b2 * dirac_ONE(rl) + (dim - 4) * self[1] * self[2];
347 // gamma~mu gamma~alpha gamma~beta gamma~delta gamma.mu = -2 gamma~delta gamma~beta gamma~alpha - (dim-4) gamam~alpha gamma~beta gamma~delta
349 && is_a<clifford>(self[1])
350 && is_a<clifford>(self[2])
351 && is_a<clifford>(self[3])) {
352 *self = -2 * self[3] * self[2] * self[1] - (dim - 4) * self[1] * self[2] * self[3];
359 // gamma~mu Sodd gamma.mu = -2 Sodd_R
360 // (Chisholm identity in 4 dimensions)
361 } else if (!((other - self) & 1) && dim.is_equal(4)) {
362 if (std::find_if(self + 1, other, is_not_a_clifford()) != other)
365 *self = ncmul(exvector(std::reverse_iterator<exvector::const_iterator>(other), std::reverse_iterator<exvector::const_iterator>(self + 1)), true);
366 std::fill(self + 1, other, _ex1);
370 // gamma~mu Sodd gamma~alpha gamma.mu = 2 gamma~alpha Sodd + 2 Sodd_R gamma~alpha
371 // (commutate contracted indices towards each other, then use
372 // Chisholm identity in 4 dimensions)
373 } else if (((other - self) & 1) && dim.is_equal(4)) {
374 if (std::find_if(self + 1, other, is_not_a_clifford()) != other)
377 exvector::iterator next_to_last = other - 1;
378 ex S = ncmul(exvector(self + 1, next_to_last), true);
379 ex SR = ncmul(exvector(std::reverse_iterator<exvector::const_iterator>(next_to_last), std::reverse_iterator<exvector::const_iterator>(self + 1)), true);
381 *self = (*next_to_last) * S + SR * (*next_to_last);
382 std::fill(self + 1, other, _ex1);
386 // gamma~mu S gamma~alpha gamma.mu = 2 gamma~alpha S - gamma~mu S gamma.mu gamma~alpha
387 // (commutate contracted indices towards each other, simplify_indexed()
388 // will re-expand and re-run the simplification)
390 if (std::find_if(self + 1, other, is_not_a_clifford()) != other)
393 exvector::iterator next_to_last = other - 1;
394 ex S = ncmul(exvector(self + 1, next_to_last), true);
396 *self = 2 * (*next_to_last) * S - (*self) * S * (*other) * (*next_to_last);
397 std::fill(self + 1, other + 1, _ex1);
401 } else if (is_a<symbol>(other->op(0)) && other->nops() == 2) {
403 // x.mu gamma~mu -> x-slash
404 *self = dirac_slash(other->op(0), dim, rl);
412 /** An utility function looking for a given metric within an exvector,
413 * used in cliffordunit::contract_with(). */
414 static int find_same_metric(exvector & v, ex & c)
416 for (size_t i=0; i<v.size(); i++) {
417 if (is_a<indexed>(v[i]) && !is_a<clifford>(v[i])
418 && ((ex_to<varidx>(c.op(1)) == ex_to<indexed>(v[i]).get_indices()[0]
419 && ex_to<varidx>(c.op(1)) == ex_to<indexed>(v[i]).get_indices()[1])
420 || (ex_to<varidx>(c.op(1)).toggle_variance() == ex_to<indexed>(v[i]).get_indices()[0]
421 && ex_to<varidx>(c.op(1)).toggle_variance() == ex_to<indexed>(v[i]).get_indices()[1]))) {
422 return i; // the index of the found
425 return -1; //nothing found
428 /** Contraction of a Clifford unit with something else. */
429 bool cliffordunit::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const
431 GINAC_ASSERT(is_a<clifford>(*self));
432 GINAC_ASSERT(is_a<indexed>(*other));
433 GINAC_ASSERT(is_a<cliffordunit>(self->op(0)));
434 clifford unit = ex_to<clifford>(*self);
435 unsigned char rl = unit.get_representation_label();
437 if (is_a<clifford>(*other)) {
438 // Contraction only makes sense if the represenation labels are equal
439 // and the metrics are the same
440 if ((ex_to<clifford>(*other).get_representation_label() != rl)
441 && unit.same_metric(*other))
444 // Find if a previous contraction produces the square of self
445 int prev_square = find_same_metric(v, *self);
446 const varidx d((new symbol)->setflag(status_flags::dynallocated), ex_to<idx>(self->op(1)).get_dim()),
447 in1((new symbol)->setflag(status_flags::dynallocated), ex_to<idx>(self->op(1)).get_dim()),
448 in2((new symbol)->setflag(status_flags::dynallocated), ex_to<idx>(self->op(1)).get_dim());
450 if (prev_square > -1)
451 squared_metric = simplify_indexed(indexed(v[prev_square].op(0), in1, d)
452 * unit.get_metric(d.toggle_variance(), in2, true)).op(0);
454 exvector::iterator before_other = other - 1;
455 const varidx & mu = ex_to<varidx>(self->op(1));
456 const varidx & mu_toggle = ex_to<varidx>(other->op(1));
457 const varidx & alpha = ex_to<varidx>(before_other->op(1));
459 // e~mu e.mu = Tr ONE
460 if (other - self == 1) {
461 if (prev_square > -1) {
462 *self = indexed(squared_metric, mu, mu_toggle);
463 v[prev_square] = _ex1;
465 *self = unit.get_metric(mu, mu_toggle, true);
467 *other = dirac_ONE(rl);
470 } else if (other - self == 2) {
471 if (is_a<clifford>(*before_other) && ex_to<clifford>(*before_other).get_representation_label() == rl) {
472 if (ex_to<clifford>(*self).is_anticommuting()) {
473 // e~mu e~alpha e.mu = (2*pow(e~alpha, 2) -Tr(B)) e~alpha
474 if (prev_square > -1) {
475 *self = 2 * indexed(squared_metric, alpha, alpha)
476 - indexed(squared_metric, mu, mu_toggle);
477 v[prev_square] = _ex1;
479 *self = 2 * unit.get_metric(alpha, alpha, true) - unit.get_metric(mu, mu_toggle, true);
485 // e~mu e~alpha e.mu = 2*e~mu B(alpha, mu.toggle_variance())-Tr(B) e~alpha
486 *self = 2 * (*self) * unit.get_metric(alpha, mu_toggle, true) - unit.get_metric(mu, mu_toggle, true) * (*before_other);
487 *before_other = _ex1;
492 // e~mu S e.mu = Tr S ONE
493 *self = unit.get_metric(mu, mu_toggle, true);
494 *other = dirac_ONE(rl);
498 // e~mu S e~alpha e.mu = 2 e~mu S B(alpha, mu.toggle_variance()) - e~mu S e.mu e~alpha
499 // (commutate contracted indices towards each other, simplify_indexed()
500 // will re-expand and re-run the simplification)
501 if (std::find_if(self + 1, other, is_not_a_clifford()) != other) {
505 ex S = ncmul(exvector(self + 1, before_other), true);
507 if (is_a<clifford>(*before_other) && ex_to<clifford>(*before_other).get_representation_label() == rl) {
508 if (ex_to<clifford>(*self).is_anticommuting()) {
509 if (prev_square > -1) {
510 *self = 2 * (*before_other) * S * indexed(squared_metric, alpha, alpha)
511 - (*self) * S * (*other) * (*before_other);
513 *self = 2 * (*before_other) * S * unit.get_metric(alpha, alpha, true) - (*self) * S * (*other) * (*before_other);
516 *self = 2 * (*self) * S * unit.get_metric(alpha, mu_toggle, true) - (*self) * S * (*other) * (*before_other);
520 *self = (*self) * S * (*other) * (*before_other);
523 std::fill(self + 1, other + 1, _ex1);
530 /** Perform automatic simplification on noncommutative product of clifford
531 * objects. This removes superfluous ONEs, permutes gamma5/L/R's to the front
532 * and removes squares of gamma objects. */
533 ex clifford::eval_ncmul(const exvector & v) const
538 // Remove superfluous ONEs
539 exvector::const_iterator cit = v.begin(), citend = v.end();
540 while (cit != citend) {
541 if (!is_a<clifford>(*cit) || !is_a<diracone>(cit->op(0)))
546 bool something_changed = false;
549 // Anticommutate gamma5/L/R's to the front
551 exvector::iterator first = s.begin(), next_to_last = s.end() - 2;
553 exvector::iterator it = next_to_last;
555 exvector::iterator it2 = it + 1;
556 if (is_a<clifford>(*it) && is_a<clifford>(*it2)) {
557 ex e1 = it->op(0), e2 = it2->op(0);
559 if (is_a<diracgamma5>(e2)) {
561 if (is_a<diracgammaL>(e1) || is_a<diracgammaR>(e1)) {
563 // gammaL/R gamma5 -> gamma5 gammaL/R
565 something_changed = true;
567 } else if (!is_a<diracgamma5>(e1)) {
569 // gamma5 gamma5 -> gamma5 gamma5 (do nothing)
570 // x gamma5 -> -gamma5 x
573 something_changed = true;
576 } else if (is_a<diracgammaL>(e2)) {
578 if (is_a<diracgammaR>(e1)) {
580 // gammaR gammaL -> 0
583 } else if (!is_a<diracgammaL>(e1) && !is_a<diracgamma5>(e1)) {
585 // gammaL gammaL -> gammaL gammaL (do nothing)
586 // gamma5 gammaL -> gamma5 gammaL (do nothing)
587 // x gammaL -> gammaR x
589 *it = clifford(diracgammaR(), ex_to<clifford>(*it).get_representation_label());
590 something_changed = true;
593 } else if (is_a<diracgammaR>(e2)) {
595 if (is_a<diracgammaL>(e1)) {
597 // gammaL gammaR -> 0
600 } else if (!is_a<diracgammaR>(e1) && !is_a<diracgamma5>(e1)) {
602 // gammaR gammaR -> gammaR gammaR (do nothing)
603 // gamma5 gammaR -> gamma5 gammaR (do nothing)
604 // x gammaR -> gammaL x
606 *it = clifford(diracgammaL(), ex_to<clifford>(*it).get_representation_label());
607 something_changed = true;
615 if (next_to_last == first)
621 // Remove equal adjacent gammas
623 exvector::iterator it, itend = s.end() - 1;
624 for (it = s.begin(); it != itend; ++it) {
627 if (!is_a<clifford>(a) || !is_a<clifford>(b))
630 const ex & ag = a.op(0);
631 const ex & bg = b.op(0);
632 bool a_is_cliffordunit = is_a<cliffordunit>(ag);
633 bool b_is_cliffordunit = is_a<cliffordunit>(bg);
635 if (a_is_cliffordunit && b_is_cliffordunit && ex_to<clifford>(a).same_metric(b)
636 && (ex_to<clifford>(a).get_commutator_sign() == -1)) {
637 // This is done only for Clifford algebras
639 const ex & ia = a.op(1);
640 const ex & ib = b.op(1);
641 if (ia.is_equal(ib)) { // gamma~alpha gamma~alpha -> g~alpha~alpha
642 a = ex_to<clifford>(a).get_metric(ia, ib, true);
643 b = dirac_ONE(representation_label);
644 something_changed = true;
647 } else if ((is_a<diracgamma5>(ag) && is_a<diracgamma5>(bg))) {
649 // Remove squares of gamma5
650 a = dirac_ONE(representation_label);
651 b = dirac_ONE(representation_label);
652 something_changed = true;
654 } else if ((is_a<diracgammaL>(ag) && is_a<diracgammaL>(bg))
655 || (is_a<diracgammaR>(ag) && is_a<diracgammaR>(bg))) {
657 // Remove squares of gammaL/R
658 b = dirac_ONE(representation_label);
659 something_changed = true;
661 } else if (is_a<diracgammaL>(ag) && is_a<diracgammaR>(bg)) {
663 // gammaL and gammaR are orthogonal
666 } else if (is_a<diracgamma5>(ag) && is_a<diracgammaL>(bg)) {
668 // gamma5 gammaL -> -gammaL
669 a = dirac_ONE(representation_label);
671 something_changed = true;
673 } else if (is_a<diracgamma5>(ag) && is_a<diracgammaR>(bg)) {
675 // gamma5 gammaR -> gammaR
676 a = dirac_ONE(representation_label);
677 something_changed = true;
679 } else if (!a_is_cliffordunit && !b_is_cliffordunit && ag.is_equal(bg)) {
682 varidx ix((new symbol)->setflag(status_flags::dynallocated), ex_to<idx>(a.op(1)).minimal_dim(ex_to<idx>(b.op(1))));
684 a = indexed(ag, ix) * indexed(ag, ix.toggle_variance());
685 b = dirac_ONE(representation_label);
686 something_changed = true;
692 return dirac_ONE(representation_label) * sign;
693 if (something_changed)
694 return reeval_ncmul(s) * sign;
696 return hold_ncmul(s) * sign;
699 ex clifford::thiscontainer(const exvector & v) const
701 return clifford(representation_label, metric, anticommuting, commutator_sign, v);
704 ex clifford::thiscontainer(std::auto_ptr<exvector> vp) const
706 return clifford(representation_label, metric, anticommuting, commutator_sign, vp);
709 ex diracgamma5::conjugate() const
711 return _ex_1 * (*this);
714 ex diracgammaL::conjugate() const
716 return (new diracgammaR)->setflag(status_flags::dynallocated);
719 ex diracgammaR::conjugate() const
721 return (new diracgammaL)->setflag(status_flags::dynallocated);
728 ex dirac_ONE(unsigned char rl)
730 static ex ONE = (new diracone)->setflag(status_flags::dynallocated);
731 return clifford(ONE, rl, false);
734 ex clifford_unit(const ex & mu, const ex & metr, unsigned char rl, bool anticommuting)
736 static ex unit = (new cliffordunit)->setflag(status_flags::dynallocated);
739 throw(std::invalid_argument("clifford_unit(): index of Clifford unit must be of type idx or varidx"));
741 if (ex_to<idx>(mu).is_symbolic() && !is_a<varidx>(mu))
742 throw(std::invalid_argument("clifford_unit(): symbolic index of Clifford unit must be of type varidx (not idx)"));
744 if (is_a<indexed>(metr)) {
745 exvector indices = ex_to<indexed>(metr).get_indices();
746 if ((indices.size() == 2) && is_a<varidx>(indices[0]) && is_a<varidx>(indices[1])) {
747 return clifford(unit, mu, metr, rl, anticommuting);
749 throw(std::invalid_argument("clifford_unit(): metric for Clifford unit must be indexed exactly by two indices of same type as the given index"));
751 } else if (is_a<tensor>(metr)) {
752 static varidx xi((new symbol)->setflag(status_flags::dynallocated), ex_to<varidx>(mu).get_dim()),
753 chi((new symbol)->setflag(status_flags::dynallocated), ex_to<varidx>(mu).get_dim());
754 return clifford(unit, mu, indexed(metr, xi, chi), rl, anticommuting);
755 } else if (is_a<matrix>(metr)) {
756 matrix M = ex_to<matrix>(metr);
757 unsigned n = M.rows();
758 bool symmetric = true;
759 anticommuting = true;
761 static varidx xi((new symbol)->setflag(status_flags::dynallocated), n),
762 chi((new symbol)->setflag(status_flags::dynallocated), n);
763 if ((n == M.cols()) && (n == ex_to<varidx>(mu).get_dim())) {
764 for (unsigned i = 0; i < n; i++) {
765 for (unsigned j = i+1; j < n; j++) {
766 if (M(i, j) != M(j, i)) {
769 if (M(i, j) != -M(j, i)) {
770 anticommuting = false;
774 return clifford(unit, mu, indexed(metr, symmetric?symmetric2():not_symmetric(), xi, chi), rl, anticommuting);
776 throw(std::invalid_argument("clifford_unit(): metric for Clifford unit must be a square matrix with the same dimensions as index"));
779 throw(std::invalid_argument("clifford_unit(): metric for Clifford unit must be of type indexed, tensor or matrix"));
783 ex dirac_gamma(const ex & mu, unsigned char rl)
785 static ex gamma = (new diracgamma)->setflag(status_flags::dynallocated);
787 if (!is_a<varidx>(mu))
788 throw(std::invalid_argument("dirac_gamma(): index of Dirac gamma must be of type varidx"));
790 static varidx xi((new symbol)->setflag(status_flags::dynallocated), ex_to<varidx>(mu).get_dim()),
791 chi((new symbol)->setflag(status_flags::dynallocated), ex_to<varidx>(mu).get_dim());
792 return clifford(gamma, mu, indexed((new minkmetric)->setflag(status_flags::dynallocated), symmetric2(), xi, chi), rl, true);
795 ex dirac_gamma5(unsigned char rl)
797 static ex gamma5 = (new diracgamma5)->setflag(status_flags::dynallocated);
798 return clifford(gamma5, rl);
801 ex dirac_gammaL(unsigned char rl)
803 static ex gammaL = (new diracgammaL)->setflag(status_flags::dynallocated);
804 return clifford(gammaL, rl);
807 ex dirac_gammaR(unsigned char rl)
809 static ex gammaR = (new diracgammaR)->setflag(status_flags::dynallocated);
810 return clifford(gammaR, rl);
813 ex dirac_slash(const ex & e, const ex & dim, unsigned char rl)
815 // Slashed vectors are actually stored as a clifford object with the
816 // vector as its base expression and a (dummy) index that just serves
817 // for storing the space dimensionality
818 return clifford(e, varidx(0, dim), 0, rl);
821 /** Check whether a given tinfo key (as returned by return_type_tinfo()
822 * is that of a clifford object with the specified representation label. */
823 static bool is_clifford_tinfo(unsigned ti, unsigned char rl)
825 return ti == (TINFO_clifford + rl);
828 /** Check whether a given tinfo key (as returned by return_type_tinfo()
829 * is that of a clifford object (with an arbitrary representation label). */
830 static bool is_clifford_tinfo(unsigned ti)
832 return (ti & ~0xff) == TINFO_clifford;
835 /** Extract representation label from tinfo key (as returned by
836 * return_type_tinfo()). */
837 static unsigned char get_representation_label(unsigned ti)
842 /** Take trace of a string of an even number of Dirac gammas given a vector
844 static ex trace_string(exvector::const_iterator ix, size_t num)
846 // Tr gamma.mu gamma.nu = 4 g.mu.nu
848 return lorentz_g(ix[0], ix[1]);
850 // Tr gamma.mu gamma.nu gamma.rho gamma.sig = 4 (g.mu.nu g.rho.sig + g.nu.rho g.mu.sig - g.mu.rho g.nu.sig )
852 return lorentz_g(ix[0], ix[1]) * lorentz_g(ix[2], ix[3])
853 + lorentz_g(ix[1], ix[2]) * lorentz_g(ix[0], ix[3])
854 - lorentz_g(ix[0], ix[2]) * lorentz_g(ix[1], ix[3]);
856 // Traces of 6 or more gammas are computed recursively:
857 // Tr gamma.mu1 gamma.mu2 ... gamma.mun =
858 // + g.mu1.mu2 * Tr gamma.mu3 ... gamma.mun
859 // - g.mu1.mu3 * Tr gamma.mu2 gamma.mu4 ... gamma.mun
860 // + g.mu1.mu4 * Tr gamma.mu3 gamma.mu3 gamma.mu5 ... gamma.mun
862 // + g.mu1.mun * Tr gamma.mu2 ... gamma.mu(n-1)
866 for (size_t i=1; i<num; i++) {
867 for (size_t n=1, j=0; n<num; n++) {
872 result += sign * lorentz_g(ix[0], ix[i]) * trace_string(v.begin(), num-2);
878 ex dirac_trace(const ex & e, const std::set<unsigned char> & rls, const ex & trONE)
880 if (is_a<clifford>(e)) {
882 unsigned char rl = ex_to<clifford>(e).get_representation_label();
884 // Are we taking the trace over this object's representation label?
885 if (rls.find(rl) == rls.end())
888 // Yes, all elements are traceless, except for dirac_ONE and dirac_L/R
889 const ex & g = e.op(0);
890 if (is_a<diracone>(g))
892 else if (is_a<diracgammaL>(g) || is_a<diracgammaR>(g))
897 } else if (is_exactly_a<mul>(e)) {
899 // Trace of product: pull out non-clifford factors
901 for (size_t i=0; i<e.nops(); i++) {
902 const ex &o = e.op(i);
903 if (is_clifford_tinfo(o.return_type_tinfo()))
904 prod *= dirac_trace(o, rls, trONE);
910 } else if (is_exactly_a<ncmul>(e)) {
912 unsigned char rl = get_representation_label(e.return_type_tinfo());
914 // Are we taking the trace over this string's representation label?
915 if (rls.find(rl) == rls.end())
918 // Substitute gammaL/R and expand product, if necessary
919 ex e_expanded = e.subs(lst(
920 dirac_gammaL(rl) == (dirac_ONE(rl)-dirac_gamma5(rl))/2,
921 dirac_gammaR(rl) == (dirac_ONE(rl)+dirac_gamma5(rl))/2
922 ), subs_options::no_pattern).expand();
923 if (!is_a<ncmul>(e_expanded))
924 return dirac_trace(e_expanded, rls, trONE);
926 // gamma5 gets moved to the front so this check is enough
927 bool has_gamma5 = is_a<diracgamma5>(e.op(0).op(0));
928 size_t num = e.nops();
932 // Trace of gamma5 * odd number of gammas and trace of
933 // gamma5 * gamma.mu * gamma.nu are zero
934 if ((num & 1) == 0 || num == 3)
937 // Tr gamma5 gamma.mu gamma.nu gamma.rho gamma.sigma = 4I * epsilon(mu, nu, rho, sigma)
938 // (the epsilon is always 4-dimensional)
940 ex b1, i1, b2, i2, b3, i3, b4, i4;
941 base_and_index(e.op(1), b1, i1);
942 base_and_index(e.op(2), b2, i2);
943 base_and_index(e.op(3), b3, i3);
944 base_and_index(e.op(4), b4, i4);
945 return trONE * I * (lorentz_eps(ex_to<idx>(i1).replace_dim(_ex4), ex_to<idx>(i2).replace_dim(_ex4), ex_to<idx>(i3).replace_dim(_ex4), ex_to<idx>(i4).replace_dim(_ex4)) * b1 * b2 * b3 * b4).simplify_indexed();
949 // I/4! * epsilon0123.mu1.mu2.mu3.mu4 * Tr gamma.mu1 gamma.mu2 gamma.mu3 gamma.mu4 S_2k
950 // (the epsilon is always 4-dimensional)
951 exvector ix(num-1), bv(num-1);
952 for (size_t i=1; i<num; i++)
953 base_and_index(e.op(i), bv[i-1], ix[i-1]);
955 int *iv = new int[num];
957 for (size_t i=0; i<num-3; i++) {
959 for (size_t j=i+1; j<num-2; j++) {
961 for (size_t k=j+1; k<num-1; k++) {
963 for (size_t l=k+1; l<num; l++) {
965 iv[0] = i; iv[1] = j; iv[2] = k; iv[3] = l;
968 for (size_t n=0, t=4; n<num; n++) {
969 if (n == i || n == j || n == k || n == l)
974 int sign = permutation_sign(iv, iv + num);
975 result += sign * lorentz_eps(ex_to<idx>(idx1).replace_dim(_ex4), ex_to<idx>(idx2).replace_dim(_ex4), ex_to<idx>(idx3).replace_dim(_ex4), ex_to<idx>(idx4).replace_dim(_ex4))
976 * trace_string(v.begin(), num - 4);
982 return trONE * I * result * mul(bv);
984 } else { // no gamma5
986 // Trace of odd number of gammas is zero
990 // Tr gamma.mu gamma.nu = 4 g.mu.nu
993 base_and_index(e.op(0), b1, i1);
994 base_and_index(e.op(1), b2, i2);
995 return trONE * (lorentz_g(i1, i2) * b1 * b2).simplify_indexed();
998 exvector iv(num), bv(num);
999 for (size_t i=0; i<num; i++)
1000 base_and_index(e.op(i), bv[i], iv[i]);
1002 return trONE * (trace_string(iv.begin(), num) * mul(bv)).simplify_indexed();
1005 } else if (e.nops() > 0) {
1007 // Trace maps to all other container classes (this includes sums)
1008 pointer_to_map_function_2args<const std::set<unsigned char> &, const ex &> fcn(dirac_trace, rls, trONE);
1015 ex dirac_trace(const ex & e, const lst & rll, const ex & trONE)
1017 // Convert list to set
1018 std::set<unsigned char> rls;
1019 for (lst::const_iterator i = rll.begin(); i != rll.end(); ++i) {
1020 if (i->info(info_flags::nonnegint))
1021 rls.insert(ex_to<numeric>(*i).to_int());
1024 return dirac_trace(e, rls, trONE);
1027 ex dirac_trace(const ex & e, unsigned char rl, const ex & trONE)
1029 // Convert label to set
1030 std::set<unsigned char> rls;
1033 return dirac_trace(e, rls, trONE);
1037 ex canonicalize_clifford(const ex & e_)
1039 pointer_to_map_function fcn(canonicalize_clifford);
1041 if (is_a<matrix>(e_) // || is_a<pseries>(e) || is_a<integral>(e)
1045 ex e=simplify_indexed(e_);
1046 // Scan for any ncmul objects
1048 ex aux = e.to_rational(srl);
1049 for (exmap::iterator i = srl.begin(); i != srl.end(); ++i) {
1054 if (is_exactly_a<ncmul>(rhs)
1055 && rhs.return_type() == return_types::noncommutative
1056 && is_clifford_tinfo(rhs.return_type_tinfo())) {
1058 // Expand product, if necessary
1059 ex rhs_expanded = rhs.expand();
1060 if (!is_a<ncmul>(rhs_expanded)) {
1061 i->second = canonicalize_clifford(rhs_expanded);
1064 } else if (!is_a<clifford>(rhs.op(0)))
1068 v.reserve(rhs.nops());
1069 for (size_t j=0; j<rhs.nops(); j++)
1070 v.push_back(rhs.op(j));
1072 // Stupid recursive bubble sort because we only want to swap adjacent gammas
1073 exvector::iterator it = v.begin(), next_to_last = v.end() - 1;
1074 if (is_a<diracgamma5>(it->op(0)) || is_a<diracgammaL>(it->op(0)) || is_a<diracgammaR>(it->op(0)))
1077 while (it != next_to_last) {
1078 if (it[0].compare(it[1]) > 0) {
1080 ex save0 = it[0], save1 = it[1];
1082 base_and_index(it[0], b1, i1);
1083 base_and_index(it[1], b2, i2);
1084 // for Clifford algebras (commutator_sign == -1) metric should be symmetrised
1085 it[0] = (ex_to<clifford>(save0).get_metric(i1, i2, ex_to<clifford>(save0).get_commutator_sign() == -1) * b1 * b2).simplify_indexed();
1086 it[1] = v.size() ? _ex2 * dirac_ONE(ex_to<clifford>(save0).get_representation_label()) : _ex2;
1090 sum += ex_to<clifford>(save0).get_commutator_sign() * ncmul(v, true);
1091 i->second = canonicalize_clifford(sum);
1099 return aux.subs(srl, subs_options::no_pattern).simplify_indexed();
1103 ex clifford_prime(const ex & e)
1105 pointer_to_map_function fcn(clifford_prime);
1106 if (is_a<clifford>(e) && is_a<cliffordunit>(e.op(0))) {
1108 } else if (is_a<add>(e) || is_a<ncmul>(e) || is_a<mul>(e) //|| is_a<pseries>(e) || is_a<integral>(e)
1109 || is_a<matrix>(e) || is_a<lst>(e)) {
1111 } else if (is_a<power>(e)) {
1112 return pow(clifford_prime(e.op(0)), e.op(1));
1117 ex remove_dirac_ONE(const ex & e, unsigned char rl, unsigned options)
1119 pointer_to_map_function_2args<unsigned char, unsigned> fcn(remove_dirac_ONE, rl, options | 1);
1120 bool need_reevaluation = false;
1122 if (! (options & 1) ) { // is not a child
1124 e1 = expand_dummy_sum(e, true);
1125 e1 = canonicalize_clifford(e1);
1128 if (is_a<clifford>(e1) && ex_to<clifford>(e1).get_representation_label() >= rl) {
1129 if (is_a<diracone>(e1.op(0)))
1132 throw(std::invalid_argument("remove_dirac_ONE(): expression is a non-scalar Clifford number!"));
1133 } else if (is_a<add>(e1) || is_a<ncmul>(e1) || is_a<mul>(e1)
1134 || is_a<matrix>(e1) || is_a<lst>(e1)) {
1135 if (options & 3) // is a child or was already expanded
1140 } catch (std::exception &p) {
1141 need_reevaluation = true;
1143 } else if (is_a<power>(e1)) {
1144 if (options & 3) // is a child or was already expanded
1145 return pow(remove_dirac_ONE(e1.op(0), rl, options | 1), e1.op(1));
1148 return pow(remove_dirac_ONE(e1.op(0), rl, options | 1), e1.op(1));
1149 } catch (std::exception &p) {
1150 need_reevaluation = true;
1153 if (need_reevaluation)
1154 return remove_dirac_ONE(e, rl, options | 2);
1158 char clifford_max_label(const ex & e, bool ignore_ONE)
1160 if (is_a<clifford>(e))
1161 if (ignore_ONE && is_a<diracone>(e.op(0)))
1164 return ex_to<clifford>(e).get_representation_label();
1167 for (size_t i=0; i < e.nops(); i++)
1168 rl = (rl > clifford_max_label(e.op(i), ignore_ONE)) ? rl : clifford_max_label(e.op(i), ignore_ONE);
1173 ex clifford_norm(const ex & e)
1175 return sqrt(remove_dirac_ONE(e * clifford_bar(e)));
1178 ex clifford_inverse(const ex & e)
1180 ex norm = clifford_norm(e);
1181 if (!norm.is_zero())
1182 return clifford_bar(e) / pow(norm, 2);
1184 throw(std::invalid_argument("clifford_inverse(): cannot find inverse of Clifford number with zero norm!"));
1187 ex lst_to_clifford(const ex & v, const ex & mu, const ex & metr, unsigned char rl, bool anticommuting)
1189 if (!ex_to<idx>(mu).is_dim_numeric())
1190 throw(std::invalid_argument("lst_to_clifford(): Index should have a numeric dimension"));
1191 ex e = clifford_unit(mu, metr, rl, anticommuting);
1192 return lst_to_clifford(v, e);
1195 ex lst_to_clifford(const ex & v, const ex & e) {
1198 if (is_a<clifford>(e)) {
1199 varidx mu = ex_to<varidx>(e.op(1));
1200 unsigned dim = (ex_to<numeric>(mu.get_dim())).to_int();
1202 if (is_a<matrix>(v)) {
1203 if (ex_to<matrix>(v).cols() > ex_to<matrix>(v).rows()) {
1204 min = ex_to<matrix>(v).rows();
1205 max = ex_to<matrix>(v).cols();
1207 min = ex_to<matrix>(v).cols();
1208 max = ex_to<matrix>(v).rows();
1212 return indexed(v, ex_to<varidx>(mu).toggle_variance()) * e;
1214 throw(std::invalid_argument("lst_to_clifford(): dimensions of vector and clifford unit mismatch"));
1216 throw(std::invalid_argument("lst_to_clifford(): first argument should be a vector vector"));
1217 } else if (is_a<lst>(v)) {
1218 if (dim == ex_to<lst>(v).nops())
1219 return indexed(matrix(dim, 1, ex_to<lst>(v)), ex_to<varidx>(mu).toggle_variance()) * e;
1221 throw(std::invalid_argument("lst_to_clifford(): list length and dimension of clifford unit mismatch"));
1223 throw(std::invalid_argument("lst_to_clifford(): cannot construct from anything but list or vector"));
1225 throw(std::invalid_argument("lst_to_clifford(): the second argument should be a Clifford unit"));
1228 /** Auxiliary structure to define a function for striping one Clifford unit
1229 * from vectors. Used in clifford_to_lst(). */
1230 static ex get_clifford_comp(const ex & e, const ex & c)
1232 pointer_to_map_function_1arg<const ex &> fcn(get_clifford_comp, c);
1233 int ival = ex_to<numeric>(ex_to<varidx>(c.op(1)).get_value()).to_int();
1235 if (is_a<add>(e) || is_a<lst>(e) // || is_a<pseries>(e) || is_a<integral>(e)
1238 else if (is_a<ncmul>(e) || is_a<mul>(e)) {
1239 // find a Clifford unit with the same metric, delete it and substitute its index
1240 size_t ind = e.nops() + 1;
1241 for (size_t j = 0; j < e.nops(); j++)
1242 if (is_a<clifford>(e.op(j)) && ex_to<clifford>(c).same_metric(e.op(j)))
1246 throw(std::invalid_argument("get_clifford_comp(): expression is a Clifford multi-vector"));
1247 if (ind < e.nops()) {
1249 bool same_value_index, found_dummy;
1250 same_value_index = ( ex_to<varidx>(e.op(ind).op(1)).is_numeric()
1251 && (ival == ex_to<numeric>(ex_to<varidx>(e.op(ind).op(1)).get_value()).to_int()) );
1252 found_dummy = same_value_index;
1253 for(size_t j=0; j < e.nops(); j++)
1255 if (same_value_index)
1258 exvector ind_vec = ex_to<indexed>(e.op(j)).get_dummy_indices(ex_to<indexed>(e.op(ind)));
1259 if (ind_vec.size() > 0) {
1261 exvector::const_iterator it = ind_vec.begin(), itend = ind_vec.end();
1262 while (it != itend) {
1263 S = S * e.op(j).subs(lst(ex_to<varidx>(*it) == ival, ex_to<varidx>(*it).toggle_variance() == ival), subs_options::no_pattern);
1269 return (found_dummy ? S : 0);
1271 throw(std::invalid_argument("get_clifford_comp(): expression is not a Clifford vector to the given units"));
1272 } else if (e.is_zero())
1274 else if (is_a<clifford>(e) && ex_to<clifford>(e).same_metric(c))
1275 if ( ex_to<varidx>(e.op(1)).is_numeric() &&
1276 (ival != ex_to<numeric>(ex_to<varidx>(e.op(1)).get_value()).to_int()) )
1281 throw(std::invalid_argument("get_clifford_comp(): expression is not usable as a Clifford vector"));
1285 lst clifford_to_lst(const ex & e, const ex & c, bool algebraic)
1287 GINAC_ASSERT(is_a<clifford>(c));
1288 varidx mu = ex_to<varidx>(c.op(1));
1289 if (! mu.is_dim_numeric())
1290 throw(std::invalid_argument("clifford_to_lst(): index should have a numeric dimension"));
1291 unsigned int D = ex_to<numeric>(mu.get_dim()).to_int();
1293 if (algebraic) // check if algebraic method is applicable
1294 for (unsigned int i = 0; i < D; i++)
1295 if (pow(c.subs(mu == i, subs_options::no_pattern), 2).is_zero()
1296 or (not is_a<numeric>(pow(c.subs(mu == i, subs_options::no_pattern), 2))))
1300 for (unsigned int i = 0; i < D; i++)
1301 V.append(remove_dirac_ONE(
1302 simplify_indexed(canonicalize_clifford(e * c.subs(mu == i, subs_options::no_pattern) + c.subs(mu == i, subs_options::no_pattern) * e))
1303 / (2*pow(c.subs(mu == i, subs_options::no_pattern), 2))));
1305 ex e1 = canonicalize_clifford(e);
1307 for (unsigned int i = 0; i < D; i++)
1308 V.append(get_clifford_comp(e1, c.subs(c.op(1) == i, subs_options::no_pattern)));
1309 } catch (std::exception &p) {
1310 /* Try to expand dummy summations to simplify the expression*/
1311 e1 = canonicalize_clifford(expand_dummy_sum(e1, true));
1312 for (unsigned int i = 0; i < D; i++)
1313 V.append(get_clifford_comp(e1, c.subs(c.op(1) == i, subs_options::no_pattern)));
1320 ex clifford_moebius_map(const ex & a, const ex & b, const ex & c, const ex & d, const ex & v, const ex & G, unsigned char rl, bool anticommuting)
1324 if (! is_a<matrix>(v) && ! is_a<lst>(v))
1325 throw(std::invalid_argument("clifford_moebius_map(): parameter v should be either vector or list"));
1327 if (is_a<clifford>(G)) {
1330 if (is_a<indexed>(G))
1331 D = ex_to<varidx>(G.op(1)).get_dim();
1332 else if (is_a<matrix>(G))
1333 D = ex_to<matrix>(G).rows();
1334 else throw(std::invalid_argument("clifford_moebius_map(): metric should be an indexed object, matrix, or a Clifford unit"));
1336 varidx mu((new symbol)->setflag(status_flags::dynallocated), D);
1337 cu = clifford_unit(mu, G, rl, anticommuting);
1340 x = lst_to_clifford(v, cu);
1341 ex e = simplify_indexed(canonicalize_clifford((a * x + b) * clifford_inverse(c * x + d)));
1342 return clifford_to_lst(e, cu, false);
1345 ex clifford_moebius_map(const ex & M, const ex & v, const ex & G, unsigned char rl, bool anticommuting)
1347 if (is_a<matrix>(M))
1348 return clifford_moebius_map(ex_to<matrix>(M)(0,0), ex_to<matrix>(M)(0,1),
1349 ex_to<matrix>(M)(1,0), ex_to<matrix>(M)(1,1), v, G, rl, anticommuting);
1351 throw(std::invalid_argument("clifford_moebius_map(): parameter M should be a matrix"));
1354 } // namespace GiNaC