X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fclifford.cpp;h=3b4684c2165f07dda393d241401caeff9ba9db23;hp=e306be8e33349c2eb1814895fe68e0eb842b4cc0;hb=1602530f716ba1d425a0667b897182b99c374823;hpb=92203097b593322eda950cf8c831177a0c204129 diff --git a/ginac/clifford.cpp b/ginac/clifford.cpp index e306be8e..3b4684c2 100644 --- a/ginac/clifford.cpp +++ b/ginac/clifford.cpp @@ -3,7 +3,7 @@ * Implementation of GiNaC's clifford algebra (Dirac gamma) objects. */ /* - * GiNaC Copyright (C) 1999-2006 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2009 Johannes Gutenberg University Mainz, Germany * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,8 +20,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include - #include "clifford.h" #include "ex.h" @@ -40,14 +38,14 @@ #include "archive.h" #include "utils.h" +#include + namespace GiNaC { GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(clifford, indexed, print_func(&clifford::do_print_dflt). print_func(&clifford::do_print_latex)) -const tinfo_static_t clifford::return_type_tinfo_static[256] = {{}}; - GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(diracone, tensor, print_func(&diracone::do_print). print_func(&diracone::do_print_latex)) @@ -76,9 +74,8 @@ GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(diracgammaR, tensor, // default constructors ////////// -clifford::clifford() : representation_label(0), metric(0), anticommuting(true), commutator_sign(-1) +clifford::clifford() : representation_label(0), metric(0), commutator_sign(-1) { - tinfo_key = &clifford::tinfo_static; } DEFAULT_CTOR(diracone) @@ -95,42 +92,43 @@ DEFAULT_CTOR(diracgammaR) /** Construct object without any indices. This constructor is for internal * use only. Use the dirac_ONE() function instead. * @see dirac_ONE */ -clifford::clifford(const ex & b, unsigned char rl, bool anticommut) : inherited(b), representation_label(rl), metric(0), anticommuting(anticommut), commutator_sign(-1) +clifford::clifford(const ex & b, unsigned char rl) : inherited(b), representation_label(rl), metric(0), commutator_sign(-1) { - tinfo_key = &clifford::tinfo_static; } /** Construct object with one Lorentz index. This constructor is for internal * use only. Use the clifford_unit() or dirac_gamma() functions instead. * @see clifford_unit * @see dirac_gamma */ -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) +clifford::clifford(const ex & b, const ex & mu, const ex & metr, unsigned char rl, int comm_sign) : inherited(b, mu), representation_label(rl), metric(metr), commutator_sign(comm_sign) { GINAC_ASSERT(is_a(mu)); - tinfo_key = &clifford::tinfo_static; } -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) +clifford::clifford(unsigned char rl, const ex & metr, int comm_sign, const exvector & v, bool discardable) : inherited(not_symmetric(), v, discardable), representation_label(rl), metric(metr), commutator_sign(comm_sign) +{ +} + +clifford::clifford(unsigned char rl, const ex & metr, int comm_sign, std::auto_ptr vp) : inherited(not_symmetric(), vp), representation_label(rl), metric(metr), commutator_sign(comm_sign) { - tinfo_key = &clifford::tinfo_static; } -clifford::clifford(unsigned char rl, const ex & metr, bool anticommut, int comm_sign, std::auto_ptr vp) : inherited(not_symmetric(), vp), representation_label(rl), metric(metr), anticommuting(anticommut), commutator_sign(comm_sign) +return_type_t clifford::return_type_tinfo() const { - tinfo_key = &clifford::tinfo_static; + return make_return_type_t(representation_label); } ////////// // archiving ////////// -clifford::clifford(const archive_node & n, lst & sym_lst) : inherited(n, sym_lst) +void clifford::read_archive(const archive_node& n, lst& sym_lst) { + inherited::read_archive(n, sym_lst); unsigned rl; n.find_unsigned("label", rl); representation_label = rl; n.find_ex("metric", metric, sym_lst); - n.find_bool("anticommuting", anticommuting); n.find_unsigned("commutator_sign+1", rl); commutator_sign = rl - 1; } @@ -140,17 +138,15 @@ void clifford::archive(archive_node & n) const inherited::archive(n); n.add_unsigned("label", representation_label); n.add_ex("metric", metric); - n.add_bool("anticommuting", anticommuting); n.add_unsigned("commutator_sign+1", commutator_sign+1); } -DEFAULT_UNARCHIVE(clifford) -DEFAULT_ARCHIVING(diracone) -DEFAULT_ARCHIVING(cliffordunit) -DEFAULT_ARCHIVING(diracgamma) -DEFAULT_ARCHIVING(diracgamma5) -DEFAULT_ARCHIVING(diracgammaL) -DEFAULT_ARCHIVING(diracgammaR) +GINAC_BIND_UNARCHIVER(clifford); +GINAC_BIND_UNARCHIVER(diracone); +GINAC_BIND_UNARCHIVER(diracgamma); +GINAC_BIND_UNARCHIVER(diracgamma5); +GINAC_BIND_UNARCHIVER(diracgammaL); +GINAC_BIND_UNARCHIVER(diracgammaR); ex clifford::get_metric(const ex & i, const ex & j, bool symmetrised) const @@ -158,29 +154,39 @@ ex clifford::get_metric(const ex & i, const ex & j, bool symmetrised) const if (is_a(metric)) { if (symmetrised && !(ex_to(ex_to(metric).get_symmetry()).has_symmetry())) { if (is_a(metric.op(0))) { - return indexed((ex_to(metric.op(0)).add(ex_to(metric.op(0)).transpose())).mul(numeric(1,2)), + return indexed((ex_to(metric.op(0)).add(ex_to(metric.op(0)).transpose())).mul(numeric(1, 2)), symmetric2(), i, j); } else { return simplify_indexed(indexed(metric.op(0)*_ex1_2, i, j) + indexed(metric.op(0)*_ex1_2, j, i)); } } else { - //return indexed(metric.op(0), ex_to(ex_to(metric).get_symmetry()), i, j); return metric.subs(lst(metric.op(1) == i, metric.op(2) == j), subs_options::no_pattern); } } else { - // should not really happen since all constructors but clifford() make the metric an indexed object - return indexed(metric, i, j); + exvector indices = metric.get_free_indices(); + if (symmetrised) + return _ex1_2*simplify_indexed(metric.subs(lst(indices[0] == i, indices[1] == j), subs_options::no_pattern) + + metric.subs(lst(indices[0] == j, indices[1] == i), subs_options::no_pattern)); + else + return metric.subs(lst(indices[0] == i, indices[1] == j), subs_options::no_pattern); } } bool clifford::same_metric(const ex & other) const { - if (is_a(other)) { - return same_metric(ex_to(other).get_metric()); - } else if (is_a(other)) { - return get_metric(other.op(1), other.op(2)).is_equal(other); - } else - return false; + ex metr; + if (is_a(other)) + metr = ex_to(other).get_metric(); + else + metr = other; + + if (is_a(metr)) + return metr.op(0).is_equal(get_metric().op(0)); + else { + exvector indices = metr.get_free_indices(); + return (indices.size() == 2) + && simplify_indexed(get_metric(indices[0], indices[1])-metr).is_zero(); + } } ////////// @@ -257,8 +263,21 @@ void clifford::do_print_dflt(const print_dflt & c, unsigned level) const if (is_dirac_slash(seq[0])) { seq[0].print(c, precedence()); c.s << "\\"; - } else - this->print_dispatch(c, level); + } else { // We do not print representation label if it is 0 + if (representation_label == 0) { + this->print_dispatch(c, level); + } else { // otherwise we put it before indices in square brackets; the code is borrowed from indexed.cpp + if (precedence() <= level) { + c.s << '('; + } + seq[0].print(c, precedence()); + c.s << '[' << int(representation_label) << ']'; + printindices(c, level); + if (precedence() <= level) { + c.s << ')'; + } + } + } } void clifford::do_print_latex(const print_latex & c, unsigned level) const @@ -426,22 +445,6 @@ bool diracgamma::contract_with(exvector::iterator self, exvector::iterator other return false; } -/** An utility function looking for a given metric within an exvector, - * used in cliffordunit::contract_with(). */ -static int find_same_metric(exvector & v, ex & c) -{ - for (size_t i=0; i(v[i]) && !is_a(v[i]) - && ((ex_to(c.op(1)) == ex_to(v[i]).get_indices()[0] - && ex_to(c.op(1)) == ex_to(v[i]).get_indices()[1]) - || (ex_to(c.op(1)).toggle_variance() == ex_to(v[i]).get_indices()[0] - && ex_to(c.op(1)).toggle_variance() == ex_to(v[i]).get_indices()[1]))) { - return i; // the index of the found - } - } - return -1; //nothing found -} - /** Contraction of a Clifford unit with something else. */ bool cliffordunit::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const { @@ -458,53 +461,25 @@ bool cliffordunit::contract_with(exvector::iterator self, exvector::iterator oth && unit.same_metric(*other)) return false; - // Find if a previous contraction produces the square of self - int prev_square = find_same_metric(v, *self); - const varidx d((new symbol)->setflag(status_flags::dynallocated), ex_to(self->op(1)).get_dim()), - in1((new symbol)->setflag(status_flags::dynallocated), ex_to(self->op(1)).get_dim()), - in2((new symbol)->setflag(status_flags::dynallocated), ex_to(self->op(1)).get_dim()); - ex squared_metric; - if (prev_square > -1) - squared_metric = simplify_indexed(indexed(v[prev_square].op(0), in1, d) - * unit.get_metric(d.toggle_variance(), in2, true)).op(0); - exvector::iterator before_other = other - 1; - const varidx & mu = ex_to(self->op(1)); - const varidx & mu_toggle = ex_to(other->op(1)); - const varidx & alpha = ex_to(before_other->op(1)); + ex mu = self->op(1); + ex mu_toggle = other->op(1); + ex alpha = before_other->op(1); // e~mu e.mu = Tr ONE if (other - self == 1) { - if (prev_square > -1) { - *self = indexed(squared_metric, mu, mu_toggle); - v[prev_square] = _ex1; - } else { - *self = unit.get_metric(mu, mu_toggle, true); - } + *self = unit.get_metric(mu, mu_toggle, true); *other = dirac_ONE(rl); return true; } else if (other - self == 2) { if (is_a(*before_other) && ex_to(*before_other).get_representation_label() == rl) { - if (ex_to(*self).is_anticommuting()) { - // e~mu e~alpha e.mu = (2*pow(e~alpha, 2) -Tr(B)) e~alpha - if (prev_square > -1) { - *self = 2 * indexed(squared_metric, alpha, alpha) - - indexed(squared_metric, mu, mu_toggle); - v[prev_square] = _ex1; - } else { - *self = 2 * unit.get_metric(alpha, alpha, true) - unit.get_metric(mu, mu_toggle, true); - } - *other = _ex1; - return true; - - } else { - // e~mu e~alpha e.mu = 2*e~mu B(alpha, mu.toggle_variance())-Tr(B) e~alpha - *self = 2 * (*self) * unit.get_metric(alpha, mu_toggle, true) - unit.get_metric(mu, mu_toggle, true) * (*before_other); - *before_other = _ex1; - *other = _ex1; - return true; - } + // e~mu e~alpha e.mu = 2*e~mu B(alpha, mu.toggle_variance())-Tr(B) e~alpha + *self = 2 * (*self) * unit.get_metric(alpha, mu_toggle, true) - unit.get_metric(mu, mu_toggle, true) * (*before_other); + *before_other = _ex1; + *other = _ex1; + return true; + } else { // e~mu S e.mu = Tr S ONE *self = unit.get_metric(mu, mu_toggle, true); @@ -522,16 +497,7 @@ bool cliffordunit::contract_with(exvector::iterator self, exvector::iterator oth ex S = ncmul(exvector(self + 1, before_other), true); if (is_a(*before_other) && ex_to(*before_other).get_representation_label() == rl) { - if (ex_to(*self).is_anticommuting()) { - if (prev_square > -1) { - *self = 2 * (*before_other) * S * indexed(squared_metric, alpha, alpha) - - (*self) * S * (*other) * (*before_other); - } else { - *self = 2 * (*before_other) * S * unit.get_metric(alpha, alpha, true) - (*self) * S * (*other) * (*before_other); - } - } else { - *self = 2 * (*self) * S * unit.get_metric(alpha, mu_toggle, true) - (*self) * S * (*other) * (*before_other); - } + *self = 2 * (*self) * S * unit.get_metric(alpha, mu_toggle, true) - (*self) * S * (*other) * (*before_other); } else { // simply commutes *self = (*self) * S * (*other) * (*before_other); @@ -715,12 +681,12 @@ ex clifford::eval_ncmul(const exvector & v) const ex clifford::thiscontainer(const exvector & v) const { - return clifford(representation_label, metric, anticommuting, commutator_sign, v); + return clifford(representation_label, metric, commutator_sign, v); } ex clifford::thiscontainer(std::auto_ptr vp) const { - return clifford(representation_label, metric, anticommuting, commutator_sign, vp); + return clifford(representation_label, metric, commutator_sign, vp); } ex diracgamma5::conjugate() const @@ -745,56 +711,61 @@ ex diracgammaR::conjugate() const ex dirac_ONE(unsigned char rl) { static ex ONE = (new diracone)->setflag(status_flags::dynallocated); - return clifford(ONE, rl, false); + return clifford(ONE, rl); +} + +static unsigned get_dim_uint(const ex& e) +{ + if (!is_a(e)) + throw std::invalid_argument("get_dim_uint: argument is not an index"); + ex dim = ex_to(e).get_dim(); + if (!dim.info(info_flags::posint)) + throw std::invalid_argument("get_dim_uint: dimension of index should be a positive integer"); + unsigned d = ex_to(dim).to_int(); + return d; } -ex clifford_unit(const ex & mu, const ex & metr, unsigned char rl, bool anticommuting) +ex clifford_unit(const ex & mu, const ex & metr, unsigned char rl) { - static ex unit = (new cliffordunit)->setflag(status_flags::dynallocated); + //static ex unit = (new cliffordunit)->setflag(status_flags::dynallocated); + ex unit = (new cliffordunit)->setflag(status_flags::dynallocated); if (!is_a(mu)) throw(std::invalid_argument("clifford_unit(): index of Clifford unit must be of type idx or varidx")); - if (ex_to(mu).is_symbolic() && !is_a(mu)) - throw(std::invalid_argument("clifford_unit(): symbolic index of Clifford unit must be of type varidx (not idx)")); + exvector indices = metr.get_free_indices(); - if (is_a(metr)) { - exvector indices = ex_to(metr).get_indices(); - if ((indices.size() == 2) && is_a(indices[0]) && is_a(indices[1])) { - return clifford(unit, mu, metr, rl, anticommuting); - } else { - throw(std::invalid_argument("clifford_unit(): metric for Clifford unit must be indexed exactly by two indices of same type as the given index")); - } - } else if (is_a(metr)) { - static varidx xi((new symbol)->setflag(status_flags::dynallocated), ex_to(mu).get_dim()), - chi((new symbol)->setflag(status_flags::dynallocated), ex_to(mu).get_dim()); - return clifford(unit, mu, indexed(metr, xi, chi), rl, anticommuting); + if (indices.size() == 2) { + return clifford(unit, mu, metr, rl); } else if (is_a(metr)) { matrix M = ex_to(metr); unsigned n = M.rows(); bool symmetric = true; - anticommuting = true; - static varidx xi((new symbol)->setflag(status_flags::dynallocated), n), + //static idx xi((new symbol)->setflag(status_flags::dynallocated), n), + // chi((new symbol)->setflag(status_flags::dynallocated), n); + idx xi((new symbol)->setflag(status_flags::dynallocated), n), chi((new symbol)->setflag(status_flags::dynallocated), n); - if ((n == M.cols()) && (n == ex_to(mu).get_dim())) { + if ((n == M.cols()) && (n == get_dim_uint(mu))) { for (unsigned i = 0; i < n; i++) { for (unsigned j = i+1; j < n; j++) { - if (M(i, j) != M(j, i)) { + if (!M(i, j).is_equal(M(j, i))) { symmetric = false; } - if (M(i, j) != -M(j, i)) { - anticommuting = false; - } } } - return clifford(unit, mu, indexed(metr, symmetric?symmetric2():not_symmetric(), xi, chi), rl, anticommuting); + return clifford(unit, mu, indexed(metr, symmetric?symmetric2():not_symmetric(), xi, chi), rl); } else { throw(std::invalid_argument("clifford_unit(): metric for Clifford unit must be a square matrix with the same dimensions as index")); } - } else { - throw(std::invalid_argument("clifford_unit(): metric for Clifford unit must be of type indexed, tensor or matrix")); - } + } else if (indices.size() == 0) { // a tensor or other expression without indices + //static varidx xi((new symbol)->setflag(status_flags::dynallocated), ex_to(mu).get_dim()), + // chi((new symbol)->setflag(status_flags::dynallocated), ex_to(mu).get_dim()); + varidx xi((new symbol)->setflag(status_flags::dynallocated), ex_to(mu).get_dim()), + chi((new symbol)->setflag(status_flags::dynallocated), ex_to(mu).get_dim()); + return clifford(unit, mu, indexed(metr, xi, chi), rl); + } else + throw(std::invalid_argument("clifford_unit(): metric for Clifford unit must be of type tensor, matrix or an expression with two free indices")); } ex dirac_gamma(const ex & mu, unsigned char rl) @@ -806,7 +777,7 @@ ex dirac_gamma(const ex & mu, unsigned char rl) static varidx xi((new symbol)->setflag(status_flags::dynallocated), ex_to(mu).get_dim()), chi((new symbol)->setflag(status_flags::dynallocated), ex_to(mu).get_dim()); - return clifford(gamma, mu, indexed((new minkmetric)->setflag(status_flags::dynallocated), symmetric2(), xi, chi), rl, true); + return clifford(gamma, mu, indexed((new minkmetric)->setflag(status_flags::dynallocated), symmetric2(), xi, chi), rl); } ex dirac_gamma5(unsigned char rl) @@ -835,22 +806,14 @@ ex dirac_slash(const ex & e, const ex & dim, unsigned char rl) static varidx xi((new symbol)->setflag(status_flags::dynallocated), dim), chi((new symbol)->setflag(status_flags::dynallocated), dim); - return clifford(e, varidx(0, dim), indexed((new minkmetric)->setflag(status_flags::dynallocated), symmetric2(), xi, chi), rl, true); -} - -/** Check whether a given tinfo key (as returned by return_type_tinfo() - * is that of a clifford object (with an arbitrary representation label). */ -bool is_clifford_tinfo(tinfo_t ti) -{ - p_int start_loc=(p_int)&clifford::return_type_tinfo_static; - return (p_int)ti>=start_loc && (p_int)tisetflag(status_flags::dynallocated), symmetric2(), xi, chi), rl); } /** Extract representation label from tinfo key (as returned by * return_type_tinfo()). */ -static unsigned char get_representation_label(tinfo_t ti) +static unsigned char get_representation_label(const return_type_t& ti) { - return (unsigned char)((p_int)ti-(p_int)&clifford::return_type_tinfo_static); + return (unsigned char)ti.rl; } /** Take trace of a string of an even number of Dirac gammas given a vector @@ -1198,11 +1161,11 @@ ex clifford_inverse(const ex & e) throw(std::invalid_argument("clifford_inverse(): cannot find inverse of Clifford number with zero norm!")); } -ex lst_to_clifford(const ex & v, const ex & mu, const ex & metr, unsigned char rl, bool anticommuting) +ex lst_to_clifford(const ex & v, const ex & mu, const ex & metr, unsigned char rl) { if (!ex_to(mu).is_dim_numeric()) throw(std::invalid_argument("lst_to_clifford(): Index should have a numeric dimension")); - ex e = clifford_unit(mu, metr, rl, anticommuting); + ex e = clifford_unit(mu, metr, rl); return lst_to_clifford(v, e); } @@ -1210,8 +1173,10 @@ ex lst_to_clifford(const ex & v, const ex & e) { unsigned min, max; if (is_a(e)) { - varidx mu = ex_to(e.op(1)); - unsigned dim = (ex_to(mu.get_dim())).to_int(); + ex mu = e.op(1); + ex mu_toggle + = is_a(mu) ? ex_to(mu).toggle_variance() : mu; + unsigned dim = get_dim_uint(mu); if (is_a(v)) { if (ex_to(v).cols() > ex_to(v).rows()) { @@ -1223,14 +1188,21 @@ ex lst_to_clifford(const ex & v, const ex & e) { } if (min == 1) { if (dim == max) - return indexed(v, ex_to(mu).toggle_variance()) * e; - else + return indexed(v, mu_toggle) * e; + else if (max - dim == 1) { + if (ex_to(v).cols() > ex_to(v).rows()) + return v.op(0) * dirac_ONE(ex_to(e).get_representation_label()) + indexed(sub_matrix(ex_to(v), 0, 1, 1, dim), mu_toggle) * e; + else + return v.op(0) * dirac_ONE(ex_to(e).get_representation_label()) + indexed(sub_matrix(ex_to(v), 1, dim, 0, 1), mu_toggle) * e; + } else throw(std::invalid_argument("lst_to_clifford(): dimensions of vector and clifford unit mismatch")); } else throw(std::invalid_argument("lst_to_clifford(): first argument should be a vector (nx1 or 1xn matrix)")); } else if (v.info(info_flags::list)) { if (dim == ex_to(v).nops()) - return indexed(matrix(dim, 1, ex_to(v)), ex_to(mu).toggle_variance()) * e; + return indexed(matrix(dim, 1, ex_to(v)), mu_toggle) * e; + else if (ex_to(v).nops() - dim == 1) + return v.op(0) * dirac_ONE(ex_to(e).get_representation_label()) + indexed(sub_matrix(matrix(dim+1, 1, ex_to(v)), 1, dim, 0, 1), mu_toggle) * e; else throw(std::invalid_argument("lst_to_clifford(): list length and dimension of clifford unit mismatch")); } else @@ -1244,7 +1216,7 @@ ex lst_to_clifford(const ex & v, const ex & e) { static ex get_clifford_comp(const ex & e, const ex & c) { pointer_to_map_function_1arg fcn(get_clifford_comp, c); - int ival = ex_to(ex_to(c.op(1)).get_value()).to_int(); + int ival = ex_to(ex_to(c.op(1)).get_value()).to_int(); if (is_a(e) || e.info(info_flags::list) // || is_a(e) || is_a(e) || is_a(e)) @@ -1252,42 +1224,54 @@ static ex get_clifford_comp(const ex & e, const ex & c) else if (is_a(e) || is_a(e)) { // find a Clifford unit with the same metric, delete it and substitute its index size_t ind = e.nops() + 1; - for (size_t j = 0; j < e.nops(); j++) - if (is_a(e.op(j)) && ex_to(c).same_metric(e.op(j))) - if (ind > e.nops()) + for (size_t j = 0; j < e.nops(); j++) { + if (is_a(e.op(j)) && ex_to(c).same_metric(e.op(j))) { + if (ind > e.nops()) { ind = j; - else + } + else { throw(std::invalid_argument("get_clifford_comp(): expression is a Clifford multi-vector")); + } + } + } if (ind < e.nops()) { ex S = 1; bool same_value_index, found_dummy; - same_value_index = ( ex_to(e.op(ind).op(1)).is_numeric() - && (ival == ex_to(ex_to(e.op(ind).op(1)).get_value()).to_int()) ); + same_value_index = ( ex_to(e.op(ind).op(1)).is_numeric() + && (ival == ex_to(ex_to(e.op(ind).op(1)).get_value()).to_int()) ); found_dummy = same_value_index; - for(size_t j=0; j < e.nops(); j++) - if (j != ind) - if (same_value_index) + for (size_t j=0; j < e.nops(); j++) { + if (j != ind) { + if (same_value_index) { S = S * e.op(j); + } else { exvector ind_vec = ex_to(e.op(j)).get_dummy_indices(ex_to(e.op(ind))); if (ind_vec.size() > 0) { found_dummy = true; exvector::const_iterator it = ind_vec.begin(), itend = ind_vec.end(); while (it != itend) { - S = S * e.op(j).subs(lst(ex_to(*it) == ival, ex_to(*it).toggle_variance() == ival), subs_options::no_pattern); + ex curridx = *it; + ex curridx_toggle = is_a(curridx) + ? ex_to(curridx).toggle_variance() + : curridx; + S = S * e.op(j).subs(lst(curridx == ival, + curridx_toggle == ival), subs_options::no_pattern); ++it; } } else S = S * e.op(j); } + } + } return (found_dummy ? S : 0); } else throw(std::invalid_argument("get_clifford_comp(): expression is not a Clifford vector to the given units")); } else if (e.is_zero()) return e; else if (is_a(e) && ex_to(e).same_metric(c)) - if ( ex_to(e.op(1)).is_numeric() && - (ival != ex_to(ex_to(e.op(1)).get_value()).to_int()) ) + if ( ex_to(e.op(1)).is_numeric() && + (ival != ex_to(ex_to(e.op(1)).get_value()).to_int()) ) return 0; else return 1; @@ -1299,10 +1283,10 @@ static ex get_clifford_comp(const ex & e, const ex & c) lst clifford_to_lst(const ex & e, const ex & c, bool algebraic) { GINAC_ASSERT(is_a(c)); - varidx mu = ex_to(c.op(1)); - if (! mu.is_dim_numeric()) + ex mu = c.op(1); + if (! ex_to(mu).is_dim_numeric()) throw(std::invalid_argument("clifford_to_lst(): index should have a numeric dimension")); - unsigned int D = ex_to(mu.get_dim()).to_int(); + unsigned int D = ex_to(ex_to(mu).get_dim()).to_int(); if (algebraic) // check if algebraic method is applicable for (unsigned int i = 0; i < D; i++) @@ -1310,19 +1294,28 @@ lst clifford_to_lst(const ex & e, const ex & c, bool algebraic) or (not is_a(pow(c.subs(mu == i, subs_options::no_pattern), 2)))) algebraic = false; lst V; + ex v0 = remove_dirac_ONE(canonicalize_clifford(e+clifford_prime(e)).normal())/2; + if (not v0.is_zero()) + V.append(v0); + ex e1 = canonicalize_clifford(e - v0 * dirac_ONE(ex_to(c).get_representation_label())); if (algebraic) { for (unsigned int i = 0; i < D; i++) V.append(remove_dirac_ONE( - simplify_indexed(canonicalize_clifford(e * c.subs(mu == i, subs_options::no_pattern) + c.subs(mu == i, subs_options::no_pattern) * e)) + simplify_indexed(canonicalize_clifford(e1 * c.subs(mu == i, subs_options::no_pattern) + c.subs(mu == i, subs_options::no_pattern) * e1)) / (2*pow(c.subs(mu == i, subs_options::no_pattern), 2)))); } else { - ex e1 = canonicalize_clifford(e); try { for (unsigned int i = 0; i < D; i++) V.append(get_clifford_comp(e1, c.subs(c.op(1) == i, subs_options::no_pattern))); } catch (std::exception &p) { /* Try to expand dummy summations to simplify the expression*/ - e1 = canonicalize_clifford(expand_dummy_sum(e1, true)); + e1 = canonicalize_clifford(expand_dummy_sum(e, true)); + V.remove_all(); + v0 = remove_dirac_ONE(canonicalize_clifford(e1+clifford_prime(e1)).normal())/2; + if (not v0.is_zero()) { + V.append(v0); + e1 = canonicalize_clifford(e1 - v0 * dirac_ONE(ex_to(c).get_representation_label())); + } for (unsigned int i = 0; i < D; i++) V.append(get_clifford_comp(e1, c.subs(c.op(1) == i, subs_options::no_pattern))); } @@ -1331,7 +1324,7 @@ lst clifford_to_lst(const ex & e, const ex & c, bool algebraic) } -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) +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) { ex x, D, cu; @@ -1341,14 +1334,16 @@ ex clifford_moebius_map(const ex & a, const ex & b, const ex & c, const ex & d, if (is_a(G)) { cu = G; } else { - if (is_a(G)) - D = ex_to(G.op(1)).get_dim(); - else if (is_a(G)) + if (is_a(G)) { + D = ex_to(G.op(1)).get_dim(); + varidx mu((new symbol)->setflag(status_flags::dynallocated), D); + cu = clifford_unit(mu, G, rl); + } else if (is_a(G)) { D = ex_to(G).rows(); - else throw(std::invalid_argument("clifford_moebius_map(): metric should be an indexed object, matrix, or a Clifford unit")); + idx mu((new symbol)->setflag(status_flags::dynallocated), D); + cu = clifford_unit(mu, G, rl); + } else throw(std::invalid_argument("clifford_moebius_map(): metric should be an indexed object, matrix, or a Clifford unit")); - varidx mu((new symbol)->setflag(status_flags::dynallocated), D); - cu = clifford_unit(mu, G, rl, anticommuting); } x = lst_to_clifford(v, cu); @@ -1356,13 +1351,12 @@ ex clifford_moebius_map(const ex & a, const ex & b, const ex & c, const ex & d, return (is_a(v) ? matrix(ex_to(v).rows(), ex_to(v).cols(), ex_to(e)) : e); } -ex clifford_moebius_map(const ex & M, const ex & v, const ex & G, unsigned char rl, bool anticommuting) +ex clifford_moebius_map(const ex & M, const ex & v, const ex & G, unsigned char rl) { - if (is_a(M)) - return clifford_moebius_map(ex_to(M)(0,0), ex_to(M)(0,1), - ex_to(M)(1,0), ex_to(M)(1,1), v, G, rl, anticommuting); + if (is_a(M) && (ex_to(M).rows() == 2) && (ex_to(M).cols() == 2)) + return clifford_moebius_map(M.op(0), M.op(1), M.op(2), M.op(3), v, G, rl); else - throw(std::invalid_argument("clifford_moebius_map(): parameter M should be a matrix")); + throw(std::invalid_argument("clifford_moebius_map(): parameter M should be a 2x2 matrix")); } } // namespace GiNaC