* Implementation of GiNaC's clifford algebra (Dirac gamma) objects. */
/*
- * GiNaC Copyright (C) 1999-2008 Johannes Gutenberg University Mainz, Germany
+ * GiNaC Copyright (C) 1999-2015 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <stdexcept>
-
#include "clifford.h"
#include "ex.h"
#include "archive.h"
#include "utils.h"
+#include <stdexcept>
+
namespace GiNaC {
GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(clifford, indexed,
* @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<varidx>(mu));
+ GINAC_ASSERT(is_a<idx>(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<exvector> 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)
{
}
// 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.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
GINAC_ASSERT(i<nops());
static ex rl = numeric(representation_label);
- ensure_if_modifiable();
+ ensure_if_modifiable();
if (nops()-i == 1)
return rl;
else
if (is_a<clifford>(*other)) {
- // Contraction only makes sense if the represenation labels are equal
+ // Contraction only makes sense if the representation labels are equal
if (ex_to<clifford>(*other).get_representation_label() != rl)
return false;
if (std::find_if(self + 1, other, is_not_a_clifford()) != other)
return false;
- *self = ncmul(exvector(std::reverse_iterator<exvector::const_iterator>(other), std::reverse_iterator<exvector::const_iterator>(self + 1)), true);
+ *self = ncmul(exvector(std::reverse_iterator<exvector::const_iterator>(other), std::reverse_iterator<exvector::const_iterator>(self + 1)));
std::fill(self + 1, other, _ex1);
*other = _ex_2;
return true;
return false;
exvector::iterator next_to_last = other - 1;
- ex S = ncmul(exvector(self + 1, next_to_last), true);
- ex SR = ncmul(exvector(std::reverse_iterator<exvector::const_iterator>(next_to_last), std::reverse_iterator<exvector::const_iterator>(self + 1)), true);
+ ex S = ncmul(exvector(self + 1, next_to_last));
+ ex SR = ncmul(exvector(std::reverse_iterator<exvector::const_iterator>(next_to_last), std::reverse_iterator<exvector::const_iterator>(self + 1)));
*self = (*next_to_last) * S + SR * (*next_to_last);
std::fill(self + 1, other, _ex1);
return false;
exvector::iterator next_to_last = other - 1;
- ex S = ncmul(exvector(self + 1, next_to_last), true);
+ ex S = ncmul(exvector(self + 1, next_to_last));
*self = 2 * (*next_to_last) * S - (*self) * S * (*other) * (*next_to_last);
std::fill(self + 1, other + 1, _ex1);
unsigned char rl = unit.get_representation_label();
if (is_a<clifford>(*other)) {
- // Contraction only makes sense if the represenation labels are equal
+ // Contraction only makes sense if the representation labels are equal
// and the metrics are the same
if ((ex_to<clifford>(*other).get_representation_label() != rl)
&& unit.same_metric(*other))
return false;
}
- ex S = ncmul(exvector(self + 1, before_other), true);
+ ex S = ncmul(exvector(self + 1, before_other));
if (is_a<clifford>(*before_other) && ex_to<clifford>(*before_other).get_representation_label() == rl) {
*self = 2 * (*self) * S * unit.get_metric(alpha, mu_toggle, true) - (*self) * S * (*other) * (*before_other);
s.reserve(v.size());
// Remove superfluous ONEs
- exvector::const_iterator cit = v.begin(), citend = v.end();
- while (cit != citend) {
- if (!is_a<clifford>(*cit) || !is_a<diracone>(cit->op(0)))
- s.push_back(*cit);
- cit++;
+ for (auto & it : v) {
+ if (!is_a<clifford>(it) || !is_a<diracone>(it.op(0)))
+ s.push_back(it);
}
bool something_changed = false;
return clifford(representation_label, metric, commutator_sign, v);
}
-ex clifford::thiscontainer(std::auto_ptr<exvector> vp) const
+ex clifford::thiscontainer(exvector && v) const
{
- return clifford(representation_label, metric, commutator_sign, vp);
+ return clifford(representation_label, metric, commutator_sign, std::move(v));
}
ex diracgamma5::conjugate() const
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();
}
- // 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);
ex sum = ncmul(v);
it[0] = save1;
it[1] = save0;
- sum += ex_to<clifford>(save0).get_commutator_sign() * ncmul(v, true);
+ sum += ex_to<clifford>(save0).get_commutator_sign() * ncmul(std::move(v));
i->second = canonicalize_clifford(sum);
goto next_sym;
}
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<clifford>(e))
if (ignore_ONE && is_a<diracone>(e.op(0)))
else
return ex_to<clifford>(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;
return v.op(0) * dirac_ONE(ex_to<clifford>(e).get_representation_label()) + indexed(sub_matrix(ex_to<matrix>(v), 0, 1, 1, dim), mu_toggle) * e;
else
return v.op(0) * dirac_ONE(ex_to<clifford>(e).get_representation_label()) + indexed(sub_matrix(ex_to<matrix>(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)"));
} 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)
else if (is_a<ncmul>(e) || is_a<mul>(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<clifford>(e.op(j)) && ex_to<clifford>(c).same_metric(e.op(j)))
- if (ind > e.nops())
+ for (size_t j = 0; j < e.nops(); j++) {
+ if (is_a<clifford>(e.op(j)) && ex_to<clifford>(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<idx>(e.op(ind).op(1)).is_numeric()
&& (ival == ex_to<numeric>(ex_to<idx>(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<indexed>(e.op(j)).get_dummy_indices(ex_to<indexed>(e.op(ind)));
+ } else {
+ exvector ind_vec;
+ if (is_a<indexed>(e.op(j)))
+ ind_vec = ex_to<indexed>(e.op(j)).get_dummy_indices(ex_to<indexed>(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<varidx>(curridx)
? ex_to<varidx>(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"));
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<numeric>(pow(c.subs(mu == i, subs_options::no_pattern), 2))))
+ || (! is_a<numeric>(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<clifford>(c).get_representation_label()));
if (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<clifford>(c).get_representation_label()));
}