X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fclifford.cpp;h=ab40064ffd86588f1dc6514a17fd4e8c561be495;hp=c93e6466d092b06a9cd3aeb7aeb95b70c9bc0fc7;hb=25b4d894b5b2f7f56fb49e62a7767ab969d5249f;hpb=b60ef16e9be16480499da701216b4a5081ee9a97 diff --git a/ginac/clifford.cpp b/ginac/clifford.cpp index c93e6466..ab40064f 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-2007 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2016 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,13 +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] = {{}}; + print_func(&clifford::do_print_latex). + print_func(&clifford::do_print_tree)) GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(diracone, tensor, print_func(&diracone::do_print). @@ -78,7 +77,6 @@ GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(diracgammaR, tensor, clifford::clifford() : representation_label(0), metric(0), commutator_sign(-1) { - tinfo_key = &clifford::tinfo_static; } DEFAULT_CTOR(diracone) @@ -97,7 +95,6 @@ DEFAULT_CTOR(diracgammaR) * @see dirac_ONE */ 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 @@ -106,26 +103,29 @@ clifford::clifford(const ex & b, unsigned char rl) : inherited(b), representatio * @see dirac_gamma */ 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; + GINAC_ASSERT(is_a(mu)); +} + +clifford::clifford(unsigned char rl, const ex & metr, int comm_sign, const exvector & v) : inherited(not_symmetric(), v), representation_label(rl), metric(metr), 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, exvector && v) : inherited(not_symmetric(), std::move(v)), representation_label(rl), metric(metr), commutator_sign(comm_sign) { - tinfo_key = &clifford::tinfo_static; } -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) +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; @@ -142,13 +142,13 @@ void clifford::archive(archive_node & n) const 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(cliffordunit); +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 @@ -162,15 +162,15 @@ ex clifford::get_metric(const ex & i, const ex & j, bool symmetrised) const return simplify_indexed(indexed(metric.op(0)*_ex1_2, i, j) + indexed(metric.op(0)*_ex1_2, j, i)); } } else { - return metric.subs(lst(metric.op(1) == i, metric.op(2) == j), subs_options::no_pattern); + return metric.subs(lst{metric.op(1) == i, metric.op(2) == j}, subs_options::no_pattern); } } else { 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)); + 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); + return metric.subs(lst{indices[0] == i, indices[1] == j}, subs_options::no_pattern); } } @@ -209,7 +209,7 @@ ex & clifford::let_op(size_t i) GINAC_ASSERT(i(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) { - static ex unit = (new cliffordunit)->setflag(status_flags::dynallocated); + ex unit = dynallocate(); if (!is_a(mu)) throw(std::invalid_argument("clifford_unit(): index of Clifford unit must be of type idx or varidx")); @@ -732,12 +752,14 @@ ex clifford_unit(const ex & mu, const ex & metr, unsigned char rl) unsigned n = M.rows(); bool symmetric = true; - static 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())) { + //static idx xi(dynallocate(), n), + // chi(dynallocate(), n); + idx xi(dynallocate(), n), + chi(dynallocate(), n); + 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; } } @@ -747,8 +769,10 @@ ex clifford_unit(const ex & mu, const ex & metr, unsigned char rl) throw(std::invalid_argument("clifford_unit(): metric for Clifford unit must be a square matrix with the same dimensions as index")); } } 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()); + //static varidx xi(dynallocate(), ex_to(mu).get_dim()), + // chi(dynallocate(), ex_to(mu).get_dim()); + varidx xi(dynallocate(), ex_to(mu).get_dim()), + chi(dynallocate(), 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")); @@ -756,31 +780,31 @@ ex clifford_unit(const ex & mu, const ex & metr, unsigned char rl) ex dirac_gamma(const ex & mu, unsigned char rl) { - static ex gamma = (new diracgamma)->setflag(status_flags::dynallocated); + static ex gamma = dynallocate(); if (!is_a(mu)) throw(std::invalid_argument("dirac_gamma(): index of Dirac gamma must be of type varidx")); - 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); + static varidx xi(dynallocate(), ex_to(mu).get_dim()), + chi(dynallocate(), ex_to(mu).get_dim()); + return clifford(gamma, mu, indexed(dynallocate(), symmetric2(), xi, chi), rl); } ex dirac_gamma5(unsigned char rl) { - static ex gamma5 = (new diracgamma5)->setflag(status_flags::dynallocated); + static ex gamma5 = dynallocate(); return clifford(gamma5, rl); } ex dirac_gammaL(unsigned char rl) { - static ex gammaL = (new diracgammaL)->setflag(status_flags::dynallocated); + static ex gammaL = dynallocate(); return clifford(gammaL, rl); } ex dirac_gammaR(unsigned char rl) { - static ex gammaR = (new diracgammaR)->setflag(status_flags::dynallocated); + static ex gammaR = dynallocate(); return clifford(gammaR, rl); } @@ -790,24 +814,16 @@ ex dirac_slash(const ex & e, const ex & dim, unsigned char rl) // vector as its base expression and a (dummy) index that just serves // for storing the space dimensionality - 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); -} - -/** 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)ti(), dim), + chi(dynallocate(), dim); + return clifford(e, varidx(0, dim), indexed(dynallocate(), 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 @@ -887,10 +903,10 @@ ex dirac_trace(const ex & e, const std::set & rls, const ex & trO return e; // Substitute gammaL/R and expand product, if necessary - ex e_expanded = e.subs(lst( + ex e_expanded = e.subs(lst{ dirac_gammaL(rl) == (dirac_ONE(rl)-dirac_gamma5(rl))/2, dirac_gammaR(rl) == (dirac_ONE(rl)+dirac_gamma5(rl))/2 - ), subs_options::no_pattern).expand(); + }, subs_options::no_pattern).expand(); if (!is_a(e_expanded)) return dirac_trace(e_expanded, rls, trONE); @@ -916,7 +932,7 @@ ex dirac_trace(const ex & e, const std::set & rls, const ex & trO return trONE * I * (lorentz_eps(ex_to(i1).replace_dim(_ex4), ex_to(i2).replace_dim(_ex4), ex_to(i3).replace_dim(_ex4), ex_to(i4).replace_dim(_ex4)) * b1 * b2 * b3 * b4).simplify_indexed(); } - // Tr gamma5 S_2k = + // Tr gamma5 S_2k = // I/4! * epsilon0123.mu1.mu2.mu3.mu4 * Tr gamma.mu1 gamma.mu2 gamma.mu3 gamma.mu4 S_2k // (the epsilon is always 4-dimensional) exvector ix(num-1), bv(num-1); @@ -1058,7 +1074,7 @@ ex canonicalize_clifford(const ex & e_) ex sum = ncmul(v); it[0] = save1; it[1] = save0; - sum += ex_to(save0).get_commutator_sign() * ncmul(v, true); + sum += ex_to(save0).get_commutator_sign() * ncmul(std::move(v)); i->second = canonicalize_clifford(sum); goto next_sym; } @@ -1126,7 +1142,7 @@ ex remove_dirac_ONE(const ex & e, unsigned char rl, unsigned options) return e1; } -char clifford_max_label(const ex & e, bool ignore_ONE) +int clifford_max_label(const ex & e, bool ignore_ONE) { if (is_a(e)) if (ignore_ONE && is_a(e.op(0))) @@ -1134,7 +1150,7 @@ char clifford_max_label(const ex & e, bool ignore_ONE) else return ex_to(e).get_representation_label(); else { - char rl = -1; + int rl = -1; for (size_t i=0; i < e.nops(); i++) rl = (rl > clifford_max_label(e.op(i), ignore_ONE)) ? rl : clifford_max_label(e.op(i), ignore_ONE); return rl; @@ -1170,7 +1186,7 @@ ex lst_to_clifford(const ex & v, const ex & e) { ex mu = e.op(1); ex mu_toggle = is_a(mu) ? ex_to(mu).toggle_variance() : mu; - unsigned dim = (ex_to(ex_to(mu).get_dim())).to_int(); + unsigned dim = get_dim_uint(mu); if (is_a(v)) { if (ex_to(v).cols() > ex_to(v).rows()) { @@ -1188,7 +1204,7 @@ ex lst_to_clifford(const ex & v, const ex & e) { 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 + } 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)")); @@ -1204,7 +1220,7 @@ ex lst_to_clifford(const ex & v, const ex & e) { } else throw(std::invalid_argument("lst_to_clifford(): the second argument should be a Clifford unit")); } - + /** Auxiliary structure to define a function for striping one Clifford unit * from vectors. Used in clifford_to_lst(). */ static ex get_clifford_comp(const ex & e, const ex & c) @@ -1218,39 +1234,46 @@ 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()) ); found_dummy = same_value_index; - for(size_t j=0; j < e.nops(); j++) - if (j != ind) - if (same_value_index) + // Run through the expression collecting all non-clifford factors + 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))); + } else { + exvector ind_vec; + if (is_a(e.op(j))) + 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) { - ex curridx = *it; + for (auto & it : ind_vec) { + 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; + S = S * e.op(j).subs(lst{curridx == ival, curridx_toggle == ival}, + subs_options::no_pattern); } } 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")); @@ -1278,11 +1301,11 @@ lst clifford_to_lst(const ex & e, const ex & c, bool algebraic) if (algebraic) // check if algebraic method is applicable for (unsigned int i = 0; i < D; i++) if (pow(c.subs(mu == i, subs_options::no_pattern), 2).is_zero() - or (not is_a(pow(c.subs(mu == i, subs_options::no_pattern), 2)))) + || (! 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()) + if (! v0.is_zero()) V.append(v0); ex e1 = canonicalize_clifford(e - v0 * dirac_ONE(ex_to(c).get_representation_label())); if (algebraic) { @@ -1299,7 +1322,7 @@ lst clifford_to_lst(const ex & e, const ex & c, bool algebraic) 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()) { + if (! v0.is_zero()) { V.append(v0); e1 = canonicalize_clifford(e1 - v0 * dirac_ONE(ex_to(c).get_representation_label())); } @@ -1323,11 +1346,11 @@ ex clifford_moebius_map(const ex & a, const ex & b, const ex & c, const ex & d, } else { if (is_a(G)) { D = ex_to(G.op(1)).get_dim(); - varidx mu((new symbol)->setflag(status_flags::dynallocated), D); + varidx mu(dynallocate(), D); cu = clifford_unit(mu, G, rl); } else if (is_a(G)) { D = ex_to(G).rows(); - idx mu((new symbol)->setflag(status_flags::dynallocated), D); + idx mu(dynallocate(), 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"));