X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fclifford.cpp;h=57d6ce6d1e725c215c654f6e558ea9f24a5b1c17;hp=5b937c434806d95dc4441a38da3a43f38120dc73;hb=1c65b3c7d04ab7123bbc7fc9e420c8bd484927a1;hpb=29b8244d6141ecb6f8d90480ade69af407270441 diff --git a/ginac/clifford.cpp b/ginac/clifford.cpp index 5b937c43..57d6ce6d 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-2011 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 @@ -44,7 +44,8 @@ namespace GiNaC { GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(clifford, indexed, print_func(&clifford::do_print_dflt). - print_func(&clifford::do_print_latex)) + print_func(&clifford::do_print_latex). + print_func(&clifford::do_print_tree)) GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(diracone, tensor, print_func(&diracone::do_print). @@ -105,11 +106,11 @@ clifford::clifford(const ex & b, const ex & mu, const ex & metr, unsigned char r GINAC_ASSERT(is_a(mu)); } -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, 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, std::auto_ptr vp) : inherited(not_symmetric(), vp), 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) { } @@ -142,6 +143,7 @@ void clifford::archive(archive_node & n) const } GINAC_BIND_UNARCHIVER(clifford); +GINAC_BIND_UNARCHIVER(cliffordunit); GINAC_BIND_UNARCHIVER(diracone); GINAC_BIND_UNARCHIVER(diracgamma); GINAC_BIND_UNARCHIVER(diracgamma5); @@ -160,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); } } @@ -207,7 +209,7 @@ ex & clifford::let_op(size_t i) GINAC_ASSERT(isetflag(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); + //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++) { @@ -759,10 +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()); - 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")); @@ -770,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); } @@ -804,9 +814,9 @@ 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); + static varidx xi(dynallocate(), 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 @@ -893,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); @@ -922,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); @@ -993,9 +1003,9 @@ ex dirac_trace(const ex & e, const lst & rll, const ex & trONE) { // Convert list to set std::set rls; - for (lst::const_iterator i = rll.begin(); i != rll.end(); ++i) { - if (i->info(info_flags::nonnegint)) - rls.insert(ex_to(*i).to_int()); + for (const auto & i : rll) { + if (i.info(info_flags::nonnegint)) + rls.insert(ex_to(i).to_int()); } return dirac_trace(e, rls, trONE); @@ -1023,10 +1033,10 @@ ex canonicalize_clifford(const ex & e_) // Scan for any ncmul objects exmap srl; ex aux = e.to_rational(srl); - for (exmap::iterator i = srl.begin(); i != srl.end(); ++i) { + for (auto & i : srl) { - ex lhs = i->first; - ex rhs = i->second; + ex lhs = i.first; + ex rhs = i.second; if (is_exactly_a(rhs) && rhs.return_type() == return_types::noncommutative @@ -1035,7 +1045,7 @@ ex canonicalize_clifford(const ex & e_) // Expand product, if necessary ex rhs_expanded = rhs.expand(); if (!is_a(rhs_expanded)) { - i->second = canonicalize_clifford(rhs_expanded); + i.second = canonicalize_clifford(rhs_expanded); continue; } else if (!is_a(rhs.op(0))) @@ -1047,7 +1057,7 @@ ex canonicalize_clifford(const ex & e_) v.push_back(rhs.op(j)); // Stupid recursive bubble sort because we only want to swap adjacent gammas - exvector::iterator it = v.begin(), next_to_last = v.end() - 1; + auto it = v.begin(), next_to_last = v.end() - 1; if (is_a(it->op(0)) || is_a(it->op(0)) || is_a(it->op(0))) ++it; @@ -1064,8 +1074,8 @@ 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); - i->second = canonicalize_clifford(sum); + sum += ex_to(save0).get_commutator_sign() * ncmul(std::move(v)); + i.second = canonicalize_clifford(sum); goto next_sym; } ++it; @@ -1194,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)")); @@ -1210,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) @@ -1251,15 +1261,13 @@ static ex get_clifford_comp(const ex & e, const ex & c) 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); @@ -1338,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"));