3 * Implementation of GiNaC's clifford algebra (Dirac gamma) objects. */
6 * GiNaC Copyright (C) 1999-2006 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 const tinfo_static_t clifford::return_type_tinfo_static[256] = {{}};
51 GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(diracone, tensor,
52 print_func<print_dflt>(&diracone::do_print).
53 print_func<print_latex>(&diracone::do_print_latex))
55 GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(cliffordunit, tensor,
56 print_func<print_dflt>(&cliffordunit::do_print).
57 print_func<print_latex>(&cliffordunit::do_print_latex))
59 GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(diracgamma, cliffordunit,
60 print_func<print_dflt>(&diracgamma::do_print).
61 print_func<print_latex>(&diracgamma::do_print_latex))
63 GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(diracgamma5, tensor,
64 print_func<print_dflt>(&diracgamma5::do_print).
65 print_func<print_latex>(&diracgamma5::do_print_latex))
67 GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(diracgammaL, tensor,
68 print_func<print_context>(&diracgammaL::do_print).
69 print_func<print_latex>(&diracgammaL::do_print_latex))
71 GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(diracgammaR, tensor,
72 print_func<print_context>(&diracgammaR::do_print).
73 print_func<print_latex>(&diracgammaR::do_print_latex))
76 // default constructors
79 clifford::clifford() : representation_label(0), metric(0), anticommuting(true), commutator_sign(-1)
81 tinfo_key = &clifford::tinfo_static;
84 DEFAULT_CTOR(diracone)
85 DEFAULT_CTOR(cliffordunit)
86 DEFAULT_CTOR(diracgamma)
87 DEFAULT_CTOR(diracgamma5)
88 DEFAULT_CTOR(diracgammaL)
89 DEFAULT_CTOR(diracgammaR)
95 /** Construct object without any indices. This constructor is for internal
96 * use only. Use the dirac_ONE() function instead.
98 clifford::clifford(const ex & b, unsigned char rl, bool anticommut) : inherited(b), representation_label(rl), metric(0), anticommuting(anticommut), commutator_sign(-1)
100 tinfo_key = &clifford::tinfo_static;
103 /** Construct object with one Lorentz index. This constructor is for internal
104 * use only. Use the clifford_unit() or dirac_gamma() functions instead.
106 * @see dirac_gamma */
107 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)
109 GINAC_ASSERT(is_a<varidx>(mu));
110 tinfo_key = &clifford::tinfo_static;
113 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)
115 tinfo_key = &clifford::tinfo_static;
118 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)
120 tinfo_key = &clifford::tinfo_static;
127 clifford::clifford(const archive_node & n, lst & sym_lst) : inherited(n, sym_lst)
130 n.find_unsigned("label", rl);
131 representation_label = rl;
132 n.find_ex("metric", metric, sym_lst);
133 n.find_bool("anticommuting", anticommuting);
134 n.find_unsigned("commutator_sign+1", rl);
135 commutator_sign = rl - 1;
138 void clifford::archive(archive_node & n) const
140 inherited::archive(n);
141 n.add_unsigned("label", representation_label);
142 n.add_ex("metric", metric);
143 n.add_bool("anticommuting", anticommuting);
144 n.add_unsigned("commutator_sign+1", commutator_sign+1);
147 DEFAULT_UNARCHIVE(clifford)
148 DEFAULT_ARCHIVING(diracone)
149 DEFAULT_ARCHIVING(cliffordunit)
150 DEFAULT_ARCHIVING(diracgamma)
151 DEFAULT_ARCHIVING(diracgamma5)
152 DEFAULT_ARCHIVING(diracgammaL)
153 DEFAULT_ARCHIVING(diracgammaR)
156 ex clifford::get_metric(const ex & i, const ex & j, bool symmetrised) const
158 if (is_a<indexed>(metric)) {
159 if (symmetrised && !(ex_to<symmetry>(ex_to<indexed>(metric).get_symmetry()).has_symmetry())) {
160 if (is_a<matrix>(metric.op(0))) {
161 return indexed((ex_to<matrix>(metric.op(0)).add(ex_to<matrix>(metric.op(0)).transpose())).mul(numeric(1,2)),
164 return simplify_indexed(indexed(metric.op(0)*_ex1_2, i, j) + indexed(metric.op(0)*_ex1_2, j, i));
167 //return indexed(metric.op(0), ex_to<symmetry>(ex_to<indexed>(metric).get_symmetry()), i, j);
168 return metric.subs(lst(metric.op(1) == i, metric.op(2) == j), subs_options::no_pattern);
171 // should not really happen since all constructors but clifford() make the metric an indexed object
172 return indexed(metric, i, j);
176 bool clifford::same_metric(const ex & other) const
178 if (is_a<clifford>(other)) {
179 return same_metric(ex_to<clifford>(other).get_metric());
180 } else if (is_a<indexed>(other)) {
181 return get_metric(other.op(1), other.op(2)).is_equal(other);
187 // functions overriding virtual functions from base classes
190 ex clifford::op(size_t i) const
192 GINAC_ASSERT(i<nops());
194 return representation_label;
196 return inherited::op(i);
199 ex & clifford::let_op(size_t i)
201 GINAC_ASSERT(i<nops());
203 static ex rl = numeric(representation_label);
204 ensure_if_modifiable();
208 return inherited::let_op(i);
211 ex clifford::subs(const exmap & m, unsigned options) const
213 ex subsed = inherited::subs(m, options);
214 if(is_a<clifford>(subsed)) {
215 ex prevmetric = ex_to<clifford>(subsed).metric;
216 ex newmetric = prevmetric.subs(m, options);
217 if(!are_ex_trivially_equal(prevmetric, newmetric)) {
218 clifford c = ex_to<clifford>(subsed);
219 c.metric = newmetric;
226 int clifford::compare_same_type(const basic & other) const
228 GINAC_ASSERT(is_a<clifford>(other));
229 const clifford &o = static_cast<const clifford &>(other);
231 if (representation_label != o.representation_label) {
232 // different representation label
233 return representation_label < o.representation_label ? -1 : 1;
236 return inherited::compare_same_type(other);
239 bool clifford::match_same_type(const basic & other) const
241 GINAC_ASSERT(is_a<clifford>(other));
242 const clifford &o = static_cast<const clifford &>(other);
244 return ((representation_label == o.representation_label) && (commutator_sign == o.get_commutator_sign()) && same_metric(o));
247 static bool is_dirac_slash(const ex & seq0)
249 return !is_a<diracgamma5>(seq0) && !is_a<diracgammaL>(seq0) &&
250 !is_a<diracgammaR>(seq0) && !is_a<cliffordunit>(seq0) &&
251 !is_a<diracone>(seq0);
254 void clifford::do_print_dflt(const print_dflt & c, unsigned level) const
256 // dirac_slash() object is printed differently
257 if (is_dirac_slash(seq[0])) {
258 seq[0].print(c, precedence());
261 this->print_dispatch<inherited>(c, level);
264 void clifford::do_print_latex(const print_latex & c, unsigned level) const
266 // dirac_slash() object is printed differently
267 if (is_dirac_slash(seq[0])) {
269 seq[0].print(c, precedence());
270 c.s << "\\hspace{-1.0ex}/}";
272 c.s << "\\clifford[" << int(representation_label) << "]";
273 this->print_dispatch<inherited>(c, level);
277 DEFAULT_COMPARE(diracone)
278 DEFAULT_COMPARE(cliffordunit)
279 DEFAULT_COMPARE(diracgamma)
280 DEFAULT_COMPARE(diracgamma5)
281 DEFAULT_COMPARE(diracgammaL)
282 DEFAULT_COMPARE(diracgammaR)
284 DEFAULT_PRINT_LATEX(diracone, "ONE", "\\mathbf{1}")
285 DEFAULT_PRINT_LATEX(cliffordunit, "e", "e")
286 DEFAULT_PRINT_LATEX(diracgamma, "gamma", "\\gamma")
287 DEFAULT_PRINT_LATEX(diracgamma5, "gamma5", "{\\gamma^5}")
288 DEFAULT_PRINT_LATEX(diracgammaL, "gammaL", "{\\gamma_L}")
289 DEFAULT_PRINT_LATEX(diracgammaR, "gammaR", "{\\gamma_R}")
291 /** This function decomposes gamma~mu -> (1, mu) and a\ -> (a.ix, ix) */
292 static void base_and_index(const ex & c, ex & b, ex & i)
294 GINAC_ASSERT(is_a<clifford>(c));
295 GINAC_ASSERT(c.nops() == 2+1);
297 if (is_a<cliffordunit>(c.op(0))) { // proper dirac gamma object or clifford unit
300 } else if (is_a<diracgamma5>(c.op(0)) || is_a<diracgammaL>(c.op(0)) || is_a<diracgammaR>(c.op(0))) { // gamma5/L/R
303 } else { // slash object, generate new dummy index
304 varidx ix((new symbol)->setflag(status_flags::dynallocated), ex_to<idx>(c.op(1)).get_dim());
305 b = indexed(c.op(0), ix.toggle_variance());
310 /** Predicate for finding non-clifford objects. */
311 struct is_not_a_clifford : public std::unary_function<ex, bool> {
312 bool operator()(const ex & e)
314 return !is_a<clifford>(e);
318 /** Contraction of a gamma matrix with something else. */
319 bool diracgamma::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const
321 GINAC_ASSERT(is_a<clifford>(*self));
322 GINAC_ASSERT(is_a<indexed>(*other));
323 GINAC_ASSERT(is_a<diracgamma>(self->op(0)));
324 unsigned char rl = ex_to<clifford>(*self).get_representation_label();
326 ex dim = ex_to<idx>(self->op(1)).get_dim();
327 if (other->nops() > 1)
328 dim = minimal_dim(dim, ex_to<idx>(other->op(1)).get_dim());
330 if (is_a<clifford>(*other)) {
332 // Contraction only makes sense if the represenation labels are equal
333 if (ex_to<clifford>(*other).get_representation_label() != rl)
336 size_t num = other - self;
338 // gamma~mu gamma.mu = dim ONE
341 *other = dirac_ONE(rl);
344 // gamma~mu gamma~alpha gamma.mu = (2-dim) gamma~alpha
346 && is_a<clifford>(self[1])) {
351 // gamma~mu gamma~alpha gamma~beta gamma.mu = 4 g~alpha~beta + (dim-4) gamam~alpha gamma~beta
353 && is_a<clifford>(self[1])
354 && is_a<clifford>(self[2])) {
356 base_and_index(self[1], b1, i1);
357 base_and_index(self[2], b2, i2);
358 *self = 4 * lorentz_g(i1, i2) * b1 * b2 * dirac_ONE(rl) + (dim - 4) * self[1] * self[2];
364 // 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
366 && is_a<clifford>(self[1])
367 && is_a<clifford>(self[2])
368 && is_a<clifford>(self[3])) {
369 *self = -2 * self[3] * self[2] * self[1] - (dim - 4) * self[1] * self[2] * self[3];
376 // gamma~mu Sodd gamma.mu = -2 Sodd_R
377 // (Chisholm identity in 4 dimensions)
378 } else if (!((other - self) & 1) && dim.is_equal(4)) {
379 if (std::find_if(self + 1, other, is_not_a_clifford()) != other)
382 *self = ncmul(exvector(std::reverse_iterator<exvector::const_iterator>(other), std::reverse_iterator<exvector::const_iterator>(self + 1)), true);
383 std::fill(self + 1, other, _ex1);
387 // gamma~mu Sodd gamma~alpha gamma.mu = 2 gamma~alpha Sodd + 2 Sodd_R gamma~alpha
388 // (commutate contracted indices towards each other, then use
389 // Chisholm identity in 4 dimensions)
390 } else if (((other - self) & 1) && dim.is_equal(4)) {
391 if (std::find_if(self + 1, other, is_not_a_clifford()) != other)
394 exvector::iterator next_to_last = other - 1;
395 ex S = ncmul(exvector(self + 1, next_to_last), true);
396 ex SR = ncmul(exvector(std::reverse_iterator<exvector::const_iterator>(next_to_last), std::reverse_iterator<exvector::const_iterator>(self + 1)), true);
398 *self = (*next_to_last) * S + SR * (*next_to_last);
399 std::fill(self + 1, other, _ex1);
403 // gamma~mu S gamma~alpha gamma.mu = 2 gamma~alpha S - gamma~mu S gamma.mu gamma~alpha
404 // (commutate contracted indices towards each other, simplify_indexed()
405 // will re-expand and re-run the simplification)
407 if (std::find_if(self + 1, other, is_not_a_clifford()) != other)
410 exvector::iterator next_to_last = other - 1;
411 ex S = ncmul(exvector(self + 1, next_to_last), true);
413 *self = 2 * (*next_to_last) * S - (*self) * S * (*other) * (*next_to_last);
414 std::fill(self + 1, other + 1, _ex1);
418 } else if (is_a<symbol>(other->op(0)) && other->nops() == 2) {
420 // x.mu gamma~mu -> x-slash
421 *self = dirac_slash(other->op(0), dim, rl);
429 /** An utility function looking for a given metric within an exvector,
430 * used in cliffordunit::contract_with(). */
431 static int find_same_metric(exvector & v, ex & c)
433 for (size_t i=0; i<v.size(); i++) {
434 if (is_a<indexed>(v[i]) && !is_a<clifford>(v[i])
435 && ((ex_to<varidx>(c.op(1)) == ex_to<indexed>(v[i]).get_indices()[0]
436 && ex_to<varidx>(c.op(1)) == ex_to<indexed>(v[i]).get_indices()[1])
437 || (ex_to<varidx>(c.op(1)).toggle_variance() == ex_to<indexed>(v[i]).get_indices()[0]
438 && ex_to<varidx>(c.op(1)).toggle_variance() == ex_to<indexed>(v[i]).get_indices()[1]))) {
439 return i; // the index of the found
442 return -1; //nothing found
445 /** Contraction of a Clifford unit with something else. */
446 bool cliffordunit::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const
448 GINAC_ASSERT(is_a<clifford>(*self));
449 GINAC_ASSERT(is_a<indexed>(*other));
450 GINAC_ASSERT(is_a<cliffordunit>(self->op(0)));
451 clifford unit = ex_to<clifford>(*self);
452 unsigned char rl = unit.get_representation_label();
454 if (is_a<clifford>(*other)) {
455 // Contraction only makes sense if the represenation labels are equal
456 // and the metrics are the same
457 if ((ex_to<clifford>(*other).get_representation_label() != rl)
458 && unit.same_metric(*other))
461 // Find if a previous contraction produces the square of self
462 int prev_square = find_same_metric(v, *self);
463 const varidx d((new symbol)->setflag(status_flags::dynallocated), ex_to<idx>(self->op(1)).get_dim()),
464 in1((new symbol)->setflag(status_flags::dynallocated), ex_to<idx>(self->op(1)).get_dim()),
465 in2((new symbol)->setflag(status_flags::dynallocated), ex_to<idx>(self->op(1)).get_dim());
467 if (prev_square > -1)
468 squared_metric = simplify_indexed(indexed(v[prev_square].op(0), in1, d)
469 * unit.get_metric(d.toggle_variance(), in2, true)).op(0);
471 exvector::iterator before_other = other - 1;
472 const varidx & mu = ex_to<varidx>(self->op(1));
473 const varidx & mu_toggle = ex_to<varidx>(other->op(1));
474 const varidx & alpha = ex_to<varidx>(before_other->op(1));
476 // e~mu e.mu = Tr ONE
477 if (other - self == 1) {
478 if (prev_square > -1) {
479 *self = indexed(squared_metric, mu, mu_toggle);
480 v[prev_square] = _ex1;
482 *self = unit.get_metric(mu, mu_toggle, true);
484 *other = dirac_ONE(rl);
487 } else if (other - self == 2) {
488 if (is_a<clifford>(*before_other) && ex_to<clifford>(*before_other).get_representation_label() == rl) {
489 if (ex_to<clifford>(*self).is_anticommuting()) {
490 // e~mu e~alpha e.mu = (2*pow(e~alpha, 2) -Tr(B)) e~alpha
491 if (prev_square > -1) {
492 *self = 2 * indexed(squared_metric, alpha, alpha)
493 - indexed(squared_metric, mu, mu_toggle);
494 v[prev_square] = _ex1;
496 *self = 2 * unit.get_metric(alpha, alpha, true) - unit.get_metric(mu, mu_toggle, true);
502 // e~mu e~alpha e.mu = 2*e~mu B(alpha, mu.toggle_variance())-Tr(B) e~alpha
503 *self = 2 * (*self) * unit.get_metric(alpha, mu_toggle, true) - unit.get_metric(mu, mu_toggle, true) * (*before_other);
504 *before_other = _ex1;
509 // e~mu S e.mu = Tr S ONE
510 *self = unit.get_metric(mu, mu_toggle, true);
511 *other = dirac_ONE(rl);
515 // e~mu S e~alpha e.mu = 2 e~mu S B(alpha, mu.toggle_variance()) - e~mu S e.mu e~alpha
516 // (commutate contracted indices towards each other, simplify_indexed()
517 // will re-expand and re-run the simplification)
518 if (std::find_if(self + 1, other, is_not_a_clifford()) != other) {
522 ex S = ncmul(exvector(self + 1, before_other), true);
524 if (is_a<clifford>(*before_other) && ex_to<clifford>(*before_other).get_representation_label() == rl) {
525 if (ex_to<clifford>(*self).is_anticommuting()) {
526 if (prev_square > -1) {
527 *self = 2 * (*before_other) * S * indexed(squared_metric, alpha, alpha)
528 - (*self) * S * (*other) * (*before_other);
530 *self = 2 * (*before_other) * S * unit.get_metric(alpha, alpha, true) - (*self) * S * (*other) * (*before_other);
533 *self = 2 * (*self) * S * unit.get_metric(alpha, mu_toggle, true) - (*self) * S * (*other) * (*before_other);
537 *self = (*self) * S * (*other) * (*before_other);
540 std::fill(self + 1, other + 1, _ex1);
547 /** Perform automatic simplification on noncommutative product of clifford
548 * objects. This removes superfluous ONEs, permutes gamma5/L/R's to the front
549 * and removes squares of gamma objects. */
550 ex clifford::eval_ncmul(const exvector & v) const
555 // Remove superfluous ONEs
556 exvector::const_iterator cit = v.begin(), citend = v.end();
557 while (cit != citend) {
558 if (!is_a<clifford>(*cit) || !is_a<diracone>(cit->op(0)))
563 bool something_changed = false;
566 // Anticommutate gamma5/L/R's to the front
568 exvector::iterator first = s.begin(), next_to_last = s.end() - 2;
570 exvector::iterator it = next_to_last;
572 exvector::iterator it2 = it + 1;
573 if (is_a<clifford>(*it) && is_a<clifford>(*it2)) {
574 ex e1 = it->op(0), e2 = it2->op(0);
576 if (is_a<diracgamma5>(e2)) {
578 if (is_a<diracgammaL>(e1) || is_a<diracgammaR>(e1)) {
580 // gammaL/R gamma5 -> gamma5 gammaL/R
582 something_changed = true;
584 } else if (!is_a<diracgamma5>(e1)) {
586 // gamma5 gamma5 -> gamma5 gamma5 (do nothing)
587 // x gamma5 -> -gamma5 x
590 something_changed = true;
593 } else if (is_a<diracgammaL>(e2)) {
595 if (is_a<diracgammaR>(e1)) {
597 // gammaR gammaL -> 0
600 } else if (!is_a<diracgammaL>(e1) && !is_a<diracgamma5>(e1)) {
602 // gammaL gammaL -> gammaL gammaL (do nothing)
603 // gamma5 gammaL -> gamma5 gammaL (do nothing)
604 // x gammaL -> gammaR x
606 *it = clifford(diracgammaR(), ex_to<clifford>(*it).get_representation_label());
607 something_changed = true;
610 } else if (is_a<diracgammaR>(e2)) {
612 if (is_a<diracgammaL>(e1)) {
614 // gammaL gammaR -> 0
617 } else if (!is_a<diracgammaR>(e1) && !is_a<diracgamma5>(e1)) {
619 // gammaR gammaR -> gammaR gammaR (do nothing)
620 // gamma5 gammaR -> gamma5 gammaR (do nothing)
621 // x gammaR -> gammaL x
623 *it = clifford(diracgammaL(), ex_to<clifford>(*it).get_representation_label());
624 something_changed = true;
632 if (next_to_last == first)
638 // Remove equal adjacent gammas
640 exvector::iterator it, itend = s.end() - 1;
641 for (it = s.begin(); it != itend; ++it) {
644 if (!is_a<clifford>(a) || !is_a<clifford>(b))
647 const ex & ag = a.op(0);
648 const ex & bg = b.op(0);
649 bool a_is_cliffordunit = is_a<cliffordunit>(ag);
650 bool b_is_cliffordunit = is_a<cliffordunit>(bg);
652 if (a_is_cliffordunit && b_is_cliffordunit && ex_to<clifford>(a).same_metric(b)
653 && (ex_to<clifford>(a).get_commutator_sign() == -1)) {
654 // This is done only for Clifford algebras
656 const ex & ia = a.op(1);
657 const ex & ib = b.op(1);
658 if (ia.is_equal(ib)) { // gamma~alpha gamma~alpha -> g~alpha~alpha
659 a = ex_to<clifford>(a).get_metric(ia, ib, true);
660 b = dirac_ONE(representation_label);
661 something_changed = true;
664 } else if ((is_a<diracgamma5>(ag) && is_a<diracgamma5>(bg))) {
666 // Remove squares of gamma5
667 a = dirac_ONE(representation_label);
668 b = dirac_ONE(representation_label);
669 something_changed = true;
671 } else if ((is_a<diracgammaL>(ag) && is_a<diracgammaL>(bg))
672 || (is_a<diracgammaR>(ag) && is_a<diracgammaR>(bg))) {
674 // Remove squares of gammaL/R
675 b = dirac_ONE(representation_label);
676 something_changed = true;
678 } else if (is_a<diracgammaL>(ag) && is_a<diracgammaR>(bg)) {
680 // gammaL and gammaR are orthogonal
683 } else if (is_a<diracgamma5>(ag) && is_a<diracgammaL>(bg)) {
685 // gamma5 gammaL -> -gammaL
686 a = dirac_ONE(representation_label);
688 something_changed = true;
690 } else if (is_a<diracgamma5>(ag) && is_a<diracgammaR>(bg)) {
692 // gamma5 gammaR -> gammaR
693 a = dirac_ONE(representation_label);
694 something_changed = true;
696 } else if (!a_is_cliffordunit && !b_is_cliffordunit && ag.is_equal(bg)) {
699 varidx ix((new symbol)->setflag(status_flags::dynallocated), ex_to<idx>(a.op(1)).minimal_dim(ex_to<idx>(b.op(1))));
701 a = indexed(ag, ix) * indexed(ag, ix.toggle_variance());
702 b = dirac_ONE(representation_label);
703 something_changed = true;
709 return dirac_ONE(representation_label) * sign;
710 if (something_changed)
711 return reeval_ncmul(s) * sign;
713 return hold_ncmul(s) * sign;
716 ex clifford::thiscontainer(const exvector & v) const
718 return clifford(representation_label, metric, anticommuting, commutator_sign, v);
721 ex clifford::thiscontainer(std::auto_ptr<exvector> vp) const
723 return clifford(representation_label, metric, anticommuting, commutator_sign, vp);
726 ex diracgamma5::conjugate() const
728 return _ex_1 * (*this);
731 ex diracgammaL::conjugate() const
733 return (new diracgammaR)->setflag(status_flags::dynallocated);
736 ex diracgammaR::conjugate() const
738 return (new diracgammaL)->setflag(status_flags::dynallocated);
745 ex dirac_ONE(unsigned char rl)
747 static ex ONE = (new diracone)->setflag(status_flags::dynallocated);
748 return clifford(ONE, rl, false);
751 ex clifford_unit(const ex & mu, const ex & metr, unsigned char rl, bool anticommuting)
753 static ex unit = (new cliffordunit)->setflag(status_flags::dynallocated);
756 throw(std::invalid_argument("clifford_unit(): index of Clifford unit must be of type idx or varidx"));
758 if (ex_to<idx>(mu).is_symbolic() && !is_a<varidx>(mu))
759 throw(std::invalid_argument("clifford_unit(): symbolic index of Clifford unit must be of type varidx (not idx)"));
761 if (is_a<indexed>(metr)) {
762 exvector indices = ex_to<indexed>(metr).get_indices();
763 if ((indices.size() == 2) && is_a<varidx>(indices[0]) && is_a<varidx>(indices[1])) {
764 return clifford(unit, mu, metr, rl, anticommuting);
766 throw(std::invalid_argument("clifford_unit(): metric for Clifford unit must be indexed exactly by two indices of same type as the given index"));
768 } else if (is_a<tensor>(metr)) {
769 static varidx xi((new symbol)->setflag(status_flags::dynallocated), ex_to<varidx>(mu).get_dim()),
770 chi((new symbol)->setflag(status_flags::dynallocated), ex_to<varidx>(mu).get_dim());
771 return clifford(unit, mu, indexed(metr, xi, chi), rl, anticommuting);
772 } else if (is_a<matrix>(metr)) {
773 matrix M = ex_to<matrix>(metr);
774 unsigned n = M.rows();
775 bool symmetric = true;
776 anticommuting = true;
778 static varidx xi((new symbol)->setflag(status_flags::dynallocated), n),
779 chi((new symbol)->setflag(status_flags::dynallocated), n);
780 if ((n == M.cols()) && (n == ex_to<varidx>(mu).get_dim())) {
781 for (unsigned i = 0; i < n; i++) {
782 for (unsigned j = i+1; j < n; j++) {
783 if (M(i, j) != M(j, i)) {
786 if (M(i, j) != -M(j, i)) {
787 anticommuting = false;
791 return clifford(unit, mu, indexed(metr, symmetric?symmetric2():not_symmetric(), xi, chi), rl, anticommuting);
793 throw(std::invalid_argument("clifford_unit(): metric for Clifford unit must be a square matrix with the same dimensions as index"));
796 throw(std::invalid_argument("clifford_unit(): metric for Clifford unit must be of type indexed, tensor or matrix"));
800 ex dirac_gamma(const ex & mu, unsigned char rl)
802 static ex gamma = (new diracgamma)->setflag(status_flags::dynallocated);
804 if (!is_a<varidx>(mu))
805 throw(std::invalid_argument("dirac_gamma(): index of Dirac gamma must be of type varidx"));
807 static varidx xi((new symbol)->setflag(status_flags::dynallocated), ex_to<varidx>(mu).get_dim()),
808 chi((new symbol)->setflag(status_flags::dynallocated), ex_to<varidx>(mu).get_dim());
809 return clifford(gamma, mu, indexed((new minkmetric)->setflag(status_flags::dynallocated), symmetric2(), xi, chi), rl, true);
812 ex dirac_gamma5(unsigned char rl)
814 static ex gamma5 = (new diracgamma5)->setflag(status_flags::dynallocated);
815 return clifford(gamma5, rl);
818 ex dirac_gammaL(unsigned char rl)
820 static ex gammaL = (new diracgammaL)->setflag(status_flags::dynallocated);
821 return clifford(gammaL, rl);
824 ex dirac_gammaR(unsigned char rl)
826 static ex gammaR = (new diracgammaR)->setflag(status_flags::dynallocated);
827 return clifford(gammaR, rl);
830 ex dirac_slash(const ex & e, const ex & dim, unsigned char rl)
832 // Slashed vectors are actually stored as a clifford object with the
833 // vector as its base expression and a (dummy) index that just serves
834 // for storing the space dimensionality
836 static varidx xi((new symbol)->setflag(status_flags::dynallocated), dim),
837 chi((new symbol)->setflag(status_flags::dynallocated), dim);
838 return clifford(e, varidx(0, dim), indexed((new minkmetric)->setflag(status_flags::dynallocated), symmetric2(), xi, chi), rl, true);
841 /** Check whether a given tinfo key (as returned by return_type_tinfo()
842 * is that of a clifford object (with an arbitrary representation label). */
843 bool is_clifford_tinfo(tinfo_t ti)
845 p_int start_loc=(p_int)&clifford::return_type_tinfo_static;
846 return (p_int)ti>=start_loc && (p_int)ti<start_loc+256;
849 /** Extract representation label from tinfo key (as returned by
850 * return_type_tinfo()). */
851 static unsigned char get_representation_label(tinfo_t ti)
853 return (unsigned char)((p_int)ti-(p_int)&clifford::return_type_tinfo_static);
856 /** Take trace of a string of an even number of Dirac gammas given a vector
858 static ex trace_string(exvector::const_iterator ix, size_t num)
860 // Tr gamma.mu gamma.nu = 4 g.mu.nu
862 return lorentz_g(ix[0], ix[1]);
864 // 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 )
866 return lorentz_g(ix[0], ix[1]) * lorentz_g(ix[2], ix[3])
867 + lorentz_g(ix[1], ix[2]) * lorentz_g(ix[0], ix[3])
868 - lorentz_g(ix[0], ix[2]) * lorentz_g(ix[1], ix[3]);
870 // Traces of 6 or more gammas are computed recursively:
871 // Tr gamma.mu1 gamma.mu2 ... gamma.mun =
872 // + g.mu1.mu2 * Tr gamma.mu3 ... gamma.mun
873 // - g.mu1.mu3 * Tr gamma.mu2 gamma.mu4 ... gamma.mun
874 // + g.mu1.mu4 * Tr gamma.mu3 gamma.mu3 gamma.mu5 ... gamma.mun
876 // + g.mu1.mun * Tr gamma.mu2 ... gamma.mu(n-1)
880 for (size_t i=1; i<num; i++) {
881 for (size_t n=1, j=0; n<num; n++) {
886 result += sign * lorentz_g(ix[0], ix[i]) * trace_string(v.begin(), num-2);
892 ex dirac_trace(const ex & e, const std::set<unsigned char> & rls, const ex & trONE)
894 if (is_a<clifford>(e)) {
896 unsigned char rl = ex_to<clifford>(e).get_representation_label();
898 // Are we taking the trace over this object's representation label?
899 if (rls.find(rl) == rls.end())
902 // Yes, all elements are traceless, except for dirac_ONE and dirac_L/R
903 const ex & g = e.op(0);
904 if (is_a<diracone>(g))
906 else if (is_a<diracgammaL>(g) || is_a<diracgammaR>(g))
911 } else if (is_exactly_a<mul>(e)) {
913 // Trace of product: pull out non-clifford factors
915 for (size_t i=0; i<e.nops(); i++) {
916 const ex &o = e.op(i);
917 if (is_clifford_tinfo(o.return_type_tinfo()))
918 prod *= dirac_trace(o, rls, trONE);
924 } else if (is_exactly_a<ncmul>(e)) {
926 unsigned char rl = get_representation_label(e.return_type_tinfo());
928 // Are we taking the trace over this string's representation label?
929 if (rls.find(rl) == rls.end())
932 // Substitute gammaL/R and expand product, if necessary
933 ex e_expanded = e.subs(lst(
934 dirac_gammaL(rl) == (dirac_ONE(rl)-dirac_gamma5(rl))/2,
935 dirac_gammaR(rl) == (dirac_ONE(rl)+dirac_gamma5(rl))/2
936 ), subs_options::no_pattern).expand();
937 if (!is_a<ncmul>(e_expanded))
938 return dirac_trace(e_expanded, rls, trONE);
940 // gamma5 gets moved to the front so this check is enough
941 bool has_gamma5 = is_a<diracgamma5>(e.op(0).op(0));
942 size_t num = e.nops();
946 // Trace of gamma5 * odd number of gammas and trace of
947 // gamma5 * gamma.mu * gamma.nu are zero
948 if ((num & 1) == 0 || num == 3)
951 // Tr gamma5 gamma.mu gamma.nu gamma.rho gamma.sigma = 4I * epsilon(mu, nu, rho, sigma)
952 // (the epsilon is always 4-dimensional)
954 ex b1, i1, b2, i2, b3, i3, b4, i4;
955 base_and_index(e.op(1), b1, i1);
956 base_and_index(e.op(2), b2, i2);
957 base_and_index(e.op(3), b3, i3);
958 base_and_index(e.op(4), b4, i4);
959 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();
963 // I/4! * epsilon0123.mu1.mu2.mu3.mu4 * Tr gamma.mu1 gamma.mu2 gamma.mu3 gamma.mu4 S_2k
964 // (the epsilon is always 4-dimensional)
965 exvector ix(num-1), bv(num-1);
966 for (size_t i=1; i<num; i++)
967 base_and_index(e.op(i), bv[i-1], ix[i-1]);
969 int *iv = new int[num];
971 for (size_t i=0; i<num-3; i++) {
973 for (size_t j=i+1; j<num-2; j++) {
975 for (size_t k=j+1; k<num-1; k++) {
977 for (size_t l=k+1; l<num; l++) {
979 iv[0] = i; iv[1] = j; iv[2] = k; iv[3] = l;
982 for (size_t n=0, t=4; n<num; n++) {
983 if (n == i || n == j || n == k || n == l)
988 int sign = permutation_sign(iv, iv + num);
989 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))
990 * trace_string(v.begin(), num - 4);
996 return trONE * I * result * mul(bv);
998 } else { // no gamma5
1000 // Trace of odd number of gammas is zero
1004 // Tr gamma.mu gamma.nu = 4 g.mu.nu
1007 base_and_index(e.op(0), b1, i1);
1008 base_and_index(e.op(1), b2, i2);
1009 return trONE * (lorentz_g(i1, i2) * b1 * b2).simplify_indexed();
1012 exvector iv(num), bv(num);
1013 for (size_t i=0; i<num; i++)
1014 base_and_index(e.op(i), bv[i], iv[i]);
1016 return trONE * (trace_string(iv.begin(), num) * mul(bv)).simplify_indexed();
1019 } else if (e.nops() > 0) {
1021 // Trace maps to all other container classes (this includes sums)
1022 pointer_to_map_function_2args<const std::set<unsigned char> &, const ex &> fcn(dirac_trace, rls, trONE);
1029 ex dirac_trace(const ex & e, const lst & rll, const ex & trONE)
1031 // Convert list to set
1032 std::set<unsigned char> rls;
1033 for (lst::const_iterator i = rll.begin(); i != rll.end(); ++i) {
1034 if (i->info(info_flags::nonnegint))
1035 rls.insert(ex_to<numeric>(*i).to_int());
1038 return dirac_trace(e, rls, trONE);
1041 ex dirac_trace(const ex & e, unsigned char rl, const ex & trONE)
1043 // Convert label to set
1044 std::set<unsigned char> rls;
1047 return dirac_trace(e, rls, trONE);
1051 ex canonicalize_clifford(const ex & e_)
1053 pointer_to_map_function fcn(canonicalize_clifford);
1055 if (is_a<matrix>(e_) // || is_a<pseries>(e) || is_a<integral>(e)
1056 || e_.info(info_flags::list)) {
1059 ex e=simplify_indexed(e_);
1060 // Scan for any ncmul objects
1062 ex aux = e.to_rational(srl);
1063 for (exmap::iterator i = srl.begin(); i != srl.end(); ++i) {
1068 if (is_exactly_a<ncmul>(rhs)
1069 && rhs.return_type() == return_types::noncommutative
1070 && is_clifford_tinfo(rhs.return_type_tinfo())) {
1072 // Expand product, if necessary
1073 ex rhs_expanded = rhs.expand();
1074 if (!is_a<ncmul>(rhs_expanded)) {
1075 i->second = canonicalize_clifford(rhs_expanded);
1078 } else if (!is_a<clifford>(rhs.op(0)))
1082 v.reserve(rhs.nops());
1083 for (size_t j=0; j<rhs.nops(); j++)
1084 v.push_back(rhs.op(j));
1086 // Stupid recursive bubble sort because we only want to swap adjacent gammas
1087 exvector::iterator it = v.begin(), next_to_last = v.end() - 1;
1088 if (is_a<diracgamma5>(it->op(0)) || is_a<diracgammaL>(it->op(0)) || is_a<diracgammaR>(it->op(0)))
1091 while (it != next_to_last) {
1092 if (it[0].compare(it[1]) > 0) {
1094 ex save0 = it[0], save1 = it[1];
1096 base_and_index(it[0], b1, i1);
1097 base_and_index(it[1], b2, i2);
1098 // for Clifford algebras (commutator_sign == -1) metric should be symmetrised
1099 it[0] = (ex_to<clifford>(save0).get_metric(i1, i2, ex_to<clifford>(save0).get_commutator_sign() == -1) * b1 * b2).simplify_indexed();
1100 it[1] = v.size() ? _ex2 * dirac_ONE(ex_to<clifford>(save0).get_representation_label()) : _ex2;
1104 sum += ex_to<clifford>(save0).get_commutator_sign() * ncmul(v, true);
1105 i->second = canonicalize_clifford(sum);
1113 return aux.subs(srl, subs_options::no_pattern).simplify_indexed();
1117 ex clifford_prime(const ex & e)
1119 pointer_to_map_function fcn(clifford_prime);
1120 if (is_a<clifford>(e) && is_a<cliffordunit>(e.op(0))) {
1122 } else if (is_a<add>(e) || is_a<ncmul>(e) || is_a<mul>(e) //|| is_a<pseries>(e) || is_a<integral>(e)
1123 || is_a<matrix>(e) || e.info(info_flags::list)) {
1125 } else if (is_a<power>(e)) {
1126 return pow(clifford_prime(e.op(0)), e.op(1));
1131 ex remove_dirac_ONE(const ex & e, unsigned char rl, unsigned options)
1133 pointer_to_map_function_2args<unsigned char, unsigned> fcn(remove_dirac_ONE, rl, options | 1);
1134 bool need_reevaluation = false;
1136 if (! (options & 1) ) { // is not a child
1138 e1 = expand_dummy_sum(e, true);
1139 e1 = canonicalize_clifford(e1);
1142 if (is_a<clifford>(e1) && ex_to<clifford>(e1).get_representation_label() >= rl) {
1143 if (is_a<diracone>(e1.op(0)))
1146 throw(std::invalid_argument("remove_dirac_ONE(): expression is a non-scalar Clifford number!"));
1147 } else if (is_a<add>(e1) || is_a<ncmul>(e1) || is_a<mul>(e1)
1148 || is_a<matrix>(e1) || e1.info(info_flags::list)) {
1149 if (options & 3) // is a child or was already expanded
1154 } catch (std::exception &p) {
1155 need_reevaluation = true;
1157 } else if (is_a<power>(e1)) {
1158 if (options & 3) // is a child or was already expanded
1159 return pow(remove_dirac_ONE(e1.op(0), rl, options | 1), e1.op(1));
1162 return pow(remove_dirac_ONE(e1.op(0), rl, options | 1), e1.op(1));
1163 } catch (std::exception &p) {
1164 need_reevaluation = true;
1167 if (need_reevaluation)
1168 return remove_dirac_ONE(e, rl, options | 2);
1172 char clifford_max_label(const ex & e, bool ignore_ONE)
1174 if (is_a<clifford>(e))
1175 if (ignore_ONE && is_a<diracone>(e.op(0)))
1178 return ex_to<clifford>(e).get_representation_label();
1181 for (size_t i=0; i < e.nops(); i++)
1182 rl = (rl > clifford_max_label(e.op(i), ignore_ONE)) ? rl : clifford_max_label(e.op(i), ignore_ONE);
1187 ex clifford_norm(const ex & e)
1189 return sqrt(remove_dirac_ONE(e * clifford_bar(e)));
1192 ex clifford_inverse(const ex & e)
1194 ex norm = clifford_norm(e);
1195 if (!norm.is_zero())
1196 return clifford_bar(e) / pow(norm, 2);
1198 throw(std::invalid_argument("clifford_inverse(): cannot find inverse of Clifford number with zero norm!"));
1201 ex lst_to_clifford(const ex & v, const ex & mu, const ex & metr, unsigned char rl, bool anticommuting)
1203 if (!ex_to<idx>(mu).is_dim_numeric())
1204 throw(std::invalid_argument("lst_to_clifford(): Index should have a numeric dimension"));
1205 ex e = clifford_unit(mu, metr, rl, anticommuting);
1206 return lst_to_clifford(v, e);
1209 ex lst_to_clifford(const ex & v, const ex & e) {
1212 if (is_a<clifford>(e)) {
1213 varidx mu = ex_to<varidx>(e.op(1));
1214 unsigned dim = (ex_to<numeric>(mu.get_dim())).to_int();
1216 if (is_a<matrix>(v)) {
1217 if (ex_to<matrix>(v).cols() > ex_to<matrix>(v).rows()) {
1218 min = ex_to<matrix>(v).rows();
1219 max = ex_to<matrix>(v).cols();
1221 min = ex_to<matrix>(v).cols();
1222 max = ex_to<matrix>(v).rows();
1226 return indexed(v, ex_to<varidx>(mu).toggle_variance()) * e;
1228 throw(std::invalid_argument("lst_to_clifford(): dimensions of vector and clifford unit mismatch"));
1230 throw(std::invalid_argument("lst_to_clifford(): first argument should be a vector (nx1 or 1xn matrix)"));
1231 } else if (v.info(info_flags::list)) {
1232 if (dim == ex_to<lst>(v).nops())
1233 return indexed(matrix(dim, 1, ex_to<lst>(v)), ex_to<varidx>(mu).toggle_variance()) * e;
1235 throw(std::invalid_argument("lst_to_clifford(): list length and dimension of clifford unit mismatch"));
1237 throw(std::invalid_argument("lst_to_clifford(): cannot construct from anything but list or vector"));
1239 throw(std::invalid_argument("lst_to_clifford(): the second argument should be a Clifford unit"));
1242 /** Auxiliary structure to define a function for striping one Clifford unit
1243 * from vectors. Used in clifford_to_lst(). */
1244 static ex get_clifford_comp(const ex & e, const ex & c)
1246 pointer_to_map_function_1arg<const ex &> fcn(get_clifford_comp, c);
1247 int ival = ex_to<numeric>(ex_to<varidx>(c.op(1)).get_value()).to_int();
1249 if (is_a<add>(e) || e.info(info_flags::list) // || is_a<pseries>(e) || is_a<integral>(e)
1252 else if (is_a<ncmul>(e) || is_a<mul>(e)) {
1253 // find a Clifford unit with the same metric, delete it and substitute its index
1254 size_t ind = e.nops() + 1;
1255 for (size_t j = 0; j < e.nops(); j++)
1256 if (is_a<clifford>(e.op(j)) && ex_to<clifford>(c).same_metric(e.op(j)))
1260 throw(std::invalid_argument("get_clifford_comp(): expression is a Clifford multi-vector"));
1261 if (ind < e.nops()) {
1263 bool same_value_index, found_dummy;
1264 same_value_index = ( ex_to<varidx>(e.op(ind).op(1)).is_numeric()
1265 && (ival == ex_to<numeric>(ex_to<varidx>(e.op(ind).op(1)).get_value()).to_int()) );
1266 found_dummy = same_value_index;
1267 for(size_t j=0; j < e.nops(); j++)
1269 if (same_value_index)
1272 exvector ind_vec = ex_to<indexed>(e.op(j)).get_dummy_indices(ex_to<indexed>(e.op(ind)));
1273 if (ind_vec.size() > 0) {
1275 exvector::const_iterator it = ind_vec.begin(), itend = ind_vec.end();
1276 while (it != itend) {
1277 S = S * e.op(j).subs(lst(ex_to<varidx>(*it) == ival, ex_to<varidx>(*it).toggle_variance() == ival), subs_options::no_pattern);
1283 return (found_dummy ? S : 0);
1285 throw(std::invalid_argument("get_clifford_comp(): expression is not a Clifford vector to the given units"));
1286 } else if (e.is_zero())
1288 else if (is_a<clifford>(e) && ex_to<clifford>(e).same_metric(c))
1289 if ( ex_to<varidx>(e.op(1)).is_numeric() &&
1290 (ival != ex_to<numeric>(ex_to<varidx>(e.op(1)).get_value()).to_int()) )
1295 throw(std::invalid_argument("get_clifford_comp(): expression is not usable as a Clifford vector"));
1299 lst clifford_to_lst(const ex & e, const ex & c, bool algebraic)
1301 GINAC_ASSERT(is_a<clifford>(c));
1302 varidx mu = ex_to<varidx>(c.op(1));
1303 if (! mu.is_dim_numeric())
1304 throw(std::invalid_argument("clifford_to_lst(): index should have a numeric dimension"));
1305 unsigned int D = ex_to<numeric>(mu.get_dim()).to_int();
1307 if (algebraic) // check if algebraic method is applicable
1308 for (unsigned int i = 0; i < D; i++)
1309 if (pow(c.subs(mu == i, subs_options::no_pattern), 2).is_zero()
1310 or (not is_a<numeric>(pow(c.subs(mu == i, subs_options::no_pattern), 2))))
1314 for (unsigned int i = 0; i < D; i++)
1315 V.append(remove_dirac_ONE(
1316 simplify_indexed(canonicalize_clifford(e * c.subs(mu == i, subs_options::no_pattern) + c.subs(mu == i, subs_options::no_pattern) * e))
1317 / (2*pow(c.subs(mu == i, subs_options::no_pattern), 2))));
1319 ex e1 = canonicalize_clifford(e);
1321 for (unsigned int i = 0; i < D; i++)
1322 V.append(get_clifford_comp(e1, c.subs(c.op(1) == i, subs_options::no_pattern)));
1323 } catch (std::exception &p) {
1324 /* Try to expand dummy summations to simplify the expression*/
1325 e1 = canonicalize_clifford(expand_dummy_sum(e1, true));
1326 for (unsigned int i = 0; i < D; i++)
1327 V.append(get_clifford_comp(e1, c.subs(c.op(1) == i, subs_options::no_pattern)));
1334 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)
1338 if (! is_a<matrix>(v) && ! v.info(info_flags::list))
1339 throw(std::invalid_argument("clifford_moebius_map(): parameter v should be either vector or list"));
1341 if (is_a<clifford>(G)) {
1344 if (is_a<indexed>(G))
1345 D = ex_to<varidx>(G.op(1)).get_dim();
1346 else if (is_a<matrix>(G))
1347 D = ex_to<matrix>(G).rows();
1348 else throw(std::invalid_argument("clifford_moebius_map(): metric should be an indexed object, matrix, or a Clifford unit"));
1350 varidx mu((new symbol)->setflag(status_flags::dynallocated), D);
1351 cu = clifford_unit(mu, G, rl, anticommuting);
1354 x = lst_to_clifford(v, cu);
1355 ex e = clifford_to_lst(simplify_indexed(canonicalize_clifford((a * x + b) * clifford_inverse(c * x + d))), cu, false);
1356 return (is_a<matrix>(v) ? matrix(ex_to<matrix>(v).rows(), ex_to<matrix>(v).cols(), ex_to<lst>(e)) : e);
1359 ex clifford_moebius_map(const ex & M, const ex & v, const ex & G, unsigned char rl, bool anticommuting)
1361 if (is_a<matrix>(M))
1362 return clifford_moebius_map(ex_to<matrix>(M)(0,0), ex_to<matrix>(M)(0,1),
1363 ex_to<matrix>(M)(1,0), ex_to<matrix>(M)(1,1), v, G, rl, anticommuting);
1365 throw(std::invalid_argument("clifford_moebius_map(): parameter M should be a matrix"));
1368 } // namespace GiNaC