78clifford::
clifford() : representation_label(0), metric(0), commutator_sign(-1)
128 inherited::read_archive(n, sym_lst);
139 inherited::archive(n);
189 return (indices.size() == 2)
204 return inherited::op(i);
216 return inherited::let_op(i);
221 ex subsed = inherited::subs(m, options);
224 ex newmetric = prevmetric.
subs(m, options);
244 return inherited::compare_same_type(other);
291 c.
s <<
"\\hspace{-1.0ex}/}";
300 c.
s << std::string(level,
' ') << class_name() <<
" @" <<
this
301 << std::hex <<
", hash=0x" <<
hashvalue <<
", flags=0x" <<
flags << std::dec
302 <<
", " <<
seq.size()-1 <<
" indices"
303 <<
", symmetry=" <<
symtree << std::endl;
359 if (other->nops() > 1)
368 size_t num = other - self;
390 *self = 4 *
lorentz_g(i1, i2) * b1 * b2 *
dirac_ONE(rl) + (dim - 4) * self[1] * self[2];
401 *self = -2 * self[3] * self[2] * self[1] - (dim - 4) * self[1] * self[2] * self[3];
410 }
else if (!((other - self) & 1) && dim.
is_equal(4)) {
414 *self =
ncmul(
exvector(std::reverse_iterator<exvector::const_iterator>(other), std::reverse_iterator<exvector::const_iterator>(self + 1)));
415 std::fill(self + 1, other,
_ex1);
422 }
else if (((other - self) & 1) && dim.
is_equal(4)) {
426 auto next_to_last = other - 1;
428 ex SR =
ncmul(
exvector(std::reverse_iterator<exvector::const_iterator>(next_to_last), std::reverse_iterator<exvector::const_iterator>(self + 1)));
430 *self = (*next_to_last) * S + SR * (*next_to_last);
431 std::fill(self + 1, other,
_ex1);
442 auto next_to_last = other - 1;
445 *self = 2 * (*next_to_last) * S - (*self) * S * (*other) * (*next_to_last);
446 std::fill(self + 1, other + 1,
_ex1);
450 }
else if (
is_a<symbol>(other->op(0)) && other->nops() == 2) {
477 auto before_other = other - 1;
479 ex mu_toggle = other->
op(1);
480 ex alpha = before_other->
op(1);
483 if (other - self == 1) {
488 }
else if (other - self == 2) {
491 *self = 2 * (*self) * unit.
get_metric(alpha, mu_toggle,
true) - unit.
get_metric(mu, mu_toggle,
true) * (*before_other);
492 *before_other =
_ex1;
513 *self = 2 * (*self) * S * unit.
get_metric(alpha, mu_toggle,
true) - (*self) * S * (*other) * (*before_other);
516 *self = (*self) * S * (*other) * (*before_other);
519 std::fill(self + 1, other + 1,
_ex1);
535 for (
auto & it : v) {
540 bool something_changed =
false;
545 auto first = s.begin(), next_to_last = s.end() - 2;
547 auto it = next_to_last;
551 ex e1 = it->
op(0), e2 = it2->
op(0);
559 something_changed =
true;
567 something_changed =
true;
584 something_changed =
true;
601 something_changed =
true;
609 if (next_to_last ==
first)
617 exvector::iterator it, itend = s.end() - 1;
618 for (it = s.begin(); it != itend; ++it) {
624 const ex & ag = a.
op(0);
625 const ex & bg = b.
op(0);
633 const ex & ia = a.
op(1);
634 const ex & ib = b.
op(1);
638 something_changed =
true;
646 something_changed =
true;
653 something_changed =
true;
665 something_changed =
true;
671 something_changed =
true;
673 }
else if (!a_is_cliffordunit && !b_is_cliffordunit && ag.
is_equal(bg)) {
680 something_changed =
true;
687 if (something_changed)
705 return _ex_1 * (*this);
731 throw std::invalid_argument(
"get_dim_uint: argument is not an index");
734 throw std::invalid_argument(
"get_dim_uint: dimension of index should be a positive integer");
744 throw(std::invalid_argument(
"clifford_unit(): index of Clifford unit must be of type idx or varidx"));
748 if (indices.size() == 2) {
749 return clifford(unit, mu, metr, rl);
752 unsigned n = M.
rows();
753 bool symmetric =
true;
760 for (
unsigned i = 0; i < n; i++) {
761 for (
unsigned j = i+1; j < n; j++) {
762 if (!M(i, j).is_equal(M(j, i))) {
769 throw(std::invalid_argument(
"clifford_unit(): metric for Clifford unit must be a square matrix with the same dimensions as index"));
771 }
else if (indices.size() == 0) {
778 throw(std::invalid_argument(
"clifford_unit(): metric for Clifford unit must be of type tensor, matrix or an expression with two free indices"));
786 throw(std::invalid_argument(
"dirac_gamma(): index of Dirac gamma must be of type varidx"));
826 return (
unsigned char)ti.
rl;
853 for (
size_t i=1; i<num; i++) {
854 for (
size_t n=1, j=0; n<num; n++) {
872 if (rls.find(rl) == rls.end())
876 const ex & g = e.
op(0);
888 for (
size_t i=0; i<e.
nops(); i++) {
889 const ex &o = e.
op(i);
902 if (rls.find(rl) == rls.end())
915 size_t num = e.
nops();
921 if ((num & 1) == 0 || num == 3)
927 ex b1, i1, b2, i2, b3, i3, b4, i4;
939 for (
size_t i=1; i<num; i++)
942 int *iv =
new int[num];
944 for (
size_t i=0; i<num-3; i++) {
946 for (
size_t j=i+1; j<num-2; j++) {
948 for (
size_t k=j+1; k<num-1; k++) {
950 for (
size_t l=k+1; l<num; l++) {
952 iv[0] = i; iv[1] = j; iv[2] = k; iv[3] = l;
955 for (
size_t n=0, t=4; n<num; n++) {
956 if (n == i || n == j || n == k || n == l)
969 return trONE *
I * result *
mul(bv);
986 for (
size_t i=0; i<num; i++)
992 }
else if (e.
nops() > 0) {
1005 std::set<unsigned char> rls;
1006 for (
const auto & i : rll) {
1017 std::set<unsigned char> rls;
1036 for (
auto & i : srl) {
1046 ex rhs_expanded =
rhs.expand();
1055 v.reserve(
rhs.nops());
1056 for (
size_t j=0; j<
rhs.nops(); j++)
1057 v.push_back(
rhs.op(j));
1060 auto it = v.begin(), next_to_last = v.end() - 1;
1064 while (it != next_to_last) {
1065 if (it[0].compare(it[1]) > 0) {
1067 ex save0 = it[0], save1 = it[1];
1095 ex e1= (options & 1 ? e : e.
expand());
1099 ev.reserve(e1.
nops());
1100 cv.reserve(e1.
nops());
1102 for (
size_t i= 0; i < e1.
nops(); ++i) {
1104 cv.push_back(e1.
op(i));
1106 ev.push_back(e1.
op(i));
1108 for (
auto i=cv.rbegin(); i!=cv.rend(); ++i) {
1109 ev.push_back(i->conjugate());
1112 if (do_bar && (cv.size() % 2 == 1))
1148 bool need_reevaluation =
false;
1150 if (! (options & 1) ) {
1160 throw(std::invalid_argument(
"remove_dirac_ONE(): expression is a non-scalar Clifford number!"));
1168 }
catch (std::exception &p) {
1169 need_reevaluation =
true;
1177 }
catch (std::exception &p) {
1178 need_reevaluation =
true;
1181 if (need_reevaluation)
1195 for (
size_t i=0; i < e.
nops(); i++)
1212 throw(std::invalid_argument(
"clifford_inverse(): cannot find inverse of Clifford number with zero norm!"));
1218 throw(std::invalid_argument(
"lst_to_clifford(): Index should have a numeric dimension"));
1242 return indexed(v, mu_toggle) * e;
1243 else if (max - dim == 1) {
1249 throw(std::invalid_argument(
"lst_to_clifford(): dimensions of vector and clifford unit mismatch"));
1251 throw(std::invalid_argument(
"lst_to_clifford(): first argument should be a vector (nx1 or 1xn matrix)"));
1258 throw(std::invalid_argument(
"lst_to_clifford(): list length and dimension of clifford unit mismatch"));
1260 throw(std::invalid_argument(
"lst_to_clifford(): cannot construct from anything but list or vector"));
1262 throw(std::invalid_argument(
"lst_to_clifford(): the second argument should be a Clifford unit"));
1281 bool found=
false, same_value_found=
false;
1283 ev.reserve(e1.
nops());
1284 for (
size_t i=0; i < e1.
nops(); ++i) {
1290 throw(std::invalid_argument(
"get_clifford_comp(): expression is a Clifford multi-vector"));
1294 same_value_found =
true;
1295 }
else if ((std::find(all_dummy.begin(), all_dummy.end(), e1.
op(i).
op(1)) != all_dummy.end())
1297 && std::find(all_dummy.begin(), all_dummy.end(),
1299 dummy_ind=(e1.
op(i).
op(1));
1301 ev.push_back(e.
op(i));
1303 ev.push_back(e1.
op(i));
1307 throw(std::invalid_argument(
"get_clifford_comp(): expression is not a Clifford vector to the given units"));
1310 if (same_value_found) {
1312 }
else if (! dummy_ind.
is_zero()) {
1327 throw(std::invalid_argument(
"get_clifford_comp(): expression is not usable as a Clifford vector"));
1335 throw(std::invalid_argument(
"clifford_to_lst(): index should have a numeric dimension"));
1339 for (
unsigned int i = 0; i < D; i++)
1349 for (
unsigned int i = 0; i < D; i++)
1355 for (
unsigned int i = 0; i < D; i++)
1357 }
catch (std::exception &p) {
1366 for (
unsigned int i = 0; i < D; i++)
1379 throw(std::invalid_argument(
"clifford_moebius_map(): parameter v should be either vector or list"));
1392 }
else throw(std::invalid_argument(
"clifford_moebius_map(): metric should be an indexed object, matrix, or a Clifford unit"));
1406 throw(std::invalid_argument(
"clifford_moebius_map(): parameter M should be a 2x2 matrix"));
Interface to GiNaC's sums of expressions.
Archiving of GiNaC expressions.
#define GINAC_ASSERT(X)
Assertion macro for checking invariances.
This class stores all properties needed to record/retrieve the state of one object of class basic (or...
bool find_unsigned(const std::string &name, unsigned &ret, unsigned index=0) const
Retrieve property of type "unsigned" from node.
void add_unsigned(const std::string &name, unsigned value)
Add property of type "unsigned int" to node.
bool find_ex(const std::string &name, ex &ret, lst &sym_lst, unsigned index=0) const
Retrieve property of type "ex" from node.
void add_ex(const std::string &name, const ex &value)
Add property of type "ex" to node.
This class is the ABC (abstract base class) of GiNaC's class hierarchy.
void print_dispatch(const print_context &c, unsigned level) const
Like print(), but dispatch to the specified class.
unsigned hashvalue
hash value
void ensure_if_modifiable() const
Ensure the object may be modified without hurting others, throws if this is not the case.
unsigned flags
of type status_flags
virtual int compare_same_type(const basic &other) const
Returns order relation between two objects of same type.
This class holds an object representing an element of the Clifford algebra (the Dirac gamma matrices)...
unsigned char get_representation_label() const
ex metric
Metric of the space, all constructors make it an indexed object.
bool match_same_type(const basic &other) const override
Returns true if the attributes of two objects are similar enough for a match.
bool same_metric(const ex &other) const
void do_print_tree(const print_tree &c, unsigned level) const
ex eval_ncmul(const exvector &v) const override
Perform automatic simplification on noncommutative product of clifford objects.
void do_print_dflt(const print_dflt &c, unsigned level) const
size_t nops() const override
Number of operands/members.
ex & let_op(size_t i) override
Return modifiable operand/member at position i.
unsigned precedence() const override
Return relative operator precedence (for parenthezing output).
ex thiscontainer(const exvector &v) const override
void do_print_latex(const print_latex &c, unsigned level) const
ex subs(const exmap &m, unsigned options=0) const override
Substitute a set of objects by arbitrary expressions.
ex op(size_t i) const override
Return operand/member at position i.
int commutator_sign
It is the sign in the definition e~i e~j +/- e~j e~i = B(i, j) + B(j, i)
return_type_t return_type_tinfo() const override
unsigned char representation_label
Representation label to distinguish independent spin lines.
clifford(const ex &b, unsigned char rl=0)
Construct object without any indices.
void read_archive(const archive_node &n, lst &sym_lst) override
Load (deserialize) the object from an archive node.
void archive(archive_node &n) const override
Save (serialize) the object into archive node.
int get_commutator_sign() const
This class represents the Clifford algebra generators (units).
bool contract_with(exvector::iterator self, exvector::iterator other, exvector &v) const override
Contraction of a Clifford unit with something else.
container & remove_all()
Remove all elements.
container & append(const ex &b)
Add element at back.
This class represents the Dirac gamma5 object which anticommutates with all other gammas.
ex conjugate() const override
This class represents the Dirac gammaL object which behaves like 1/2 (1-gamma5).
ex conjugate() const override
This class represents the Dirac gammaL object which behaves like 1/2 (1+gamma5).
ex conjugate() const override
This class represents the Dirac gamma Lorentz vector.
bool contract_with(exvector::iterator self, exvector::iterator other, exvector &v) const override
Contraction of a gamma matrix with something else.
This class represents the Clifford algebra unity element.
Lightweight wrapper for GiNaC's symbolic objects.
ex to_rational(exmap &repl) const
Rationalization of non-rational functions.
ex map(map_function &f) const
exvector get_free_indices() const
ex expand(unsigned options=0) const
Expand an expression.
bool is_equal(const ex &other) const
ex simplify_indexed(unsigned options=0) const
Simplify/canonicalize expression containing indexed objects.
return_type_t return_type_tinfo() const
ex subs(const exmap &m, unsigned options=0) const
bool info(unsigned inf) const
This class holds one index of an indexed object.
This class holds an indexed expression.
friend ex simplify_indexed(const ex &e, exvector &free_indices, exvector &dummy_indices, const scalar_products &sp)
Simplify indexed expression, return list of free indices.
void printindices(const print_context &c, unsigned level) const
ex get_symmetry() const
Return symmetry properties.
indexed(const ex &b)
Construct indexed object with no index.
ex symtree
Index symmetry (tree of symmetry objects)
unsigned cols() const
Get number of columns.
unsigned rows() const
Get number of rows.
Non-commutative product of expressions.
This class is a wrapper around CLN-numbers within the GiNaC class hierarchy.
bool is_zero() const
True if object is zero.
Base class for print_contexts.
std::ostream & s
stream to output to
Context for default (ginsh-parsable) output.
Context for latex-parsable output.
Context for tree-like output for debugging.
const unsigned delta_indent
size of indentation step
@ no_pattern
disable pattern matching
This class holds one of GiNaC's predefined special tensors such as the delta and the metric tensors.
This class holds an index with a variance (co- or contravariant).
ex toggle_variance() const
Make a new index with the same value but the opposite variance.
Interface to GiNaC's clifford algebra (Dirac gamma) objects.
Interface to GiNaC's light-weight expression handles.
Interface to GiNaC's indices.
Definition of GiNaC's lst.
Interface to symbolic matrices.
Interface to GiNaC's products of expressions.
ex dirac_slash(const ex &e, const ex &dim, unsigned char rl)
Create a term of the form e_mu * gamma~mu with a unique index mu.
static bool is_dirac_slash(const ex &seq0)
const numeric I
Imaginary unit.
ex hold_ncmul(const exvector &v)
ex remove_dirac_ONE(const ex &e, unsigned char rl, unsigned options)
Replaces dirac_ONE's (with a representation_label no less than rl) in e with 1.
static void base_and_index(const ex &c, ex &b, ex &i)
This function decomposes gamma~mu -> (1, mu) and a\ -> (a.ix, ix)
bool is_clifford_tinfo(const return_type_t &ti)
Check whether a given return_type_t object (as returned by return_type_tinfo() is that of a clifford ...
const numeric pow(const numeric &x, const numeric &y)
ex minimal_dim(const ex &dim1, const ex &dim2)
Return the minimum of two index dimensions.
ex clifford_inverse(const ex &e)
Calculation of the inverse in the Clifford algebra.
const symmetry & not_symmetric()
ex dirac_gammaL(unsigned char rl)
Create a Dirac gammaL object.
ex sub_matrix(const matrix &m, unsigned r, unsigned nr, unsigned c, unsigned nc)
Return the nr times nc submatrix starting at position r, c of matrix m.
ex clifford_unit(const ex &mu, const ex &metr, unsigned char rl)
Create a Clifford unit object.
container< std::list > lst
int clifford_max_label(const ex &e, bool ignore_ONE)
Returns the maximal representation label of a clifford object if e contains at least one,...
ex reeval_ncmul(const exvector &v)
std::map< ex, ex, ex_is_less > exmap
const T & ex_to(const ex &e)
Return a reference to the basic-derived class T object embedded in an expression.
B & dynallocate(Args &&... args)
Constructs a new (class basic or derived) B object on the heap.
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)
Calculations of Moebius transformations (conformal map) defined by a 2x2 Clifford matrix (a b\c d) in...
static unsigned get_dim_uint(const ex &e)
ex dirac_ONE(unsigned char rl)
Create a Clifford unity object.
bool are_ex_trivially_equal(const ex &e1, const ex &e2)
Compare two objects of class quickly without doing a deep tree traversal.
return_type_t make_return_type_t(const unsigned rl=0)
const numeric sqrt(const numeric &x)
Numeric square root.
ex dirac_gamma(const ex &mu, unsigned char rl)
Create a Dirac gamma object.
GINAC_IMPLEMENT_REGISTERED_CLASS_OPT_T(lst, basic, print_func< print_context >(&lst::do_print). print_func< print_tree >(&lst::do_print_tree)) template<> bool ls GINAC_BIND_UNARCHIVER)(lst)
Specialization of container::info() for lst.
print_func< print_dflt >(&diracone::do_print). print_func< print_latex >(&diracone
static ex get_clifford_comp(const ex &e, const ex &c, bool root=true)
Auxiliary structure to define a function for striping one Clifford unit from vectors.
ex simplify_indexed(const ex &thisex, unsigned options=0)
const symmetry & symmetric2()
unsigned rows(const matrix &m)
GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(add, expairseq, print_func< print_context >(&add::do_print). print_func< print_latex >(&add::do_print_latex). print_func< print_csrc >(&add::do_print_csrc). print_func< print_tree >(&add::do_print_tree). print_func< print_python_repr >(&add::do_print_python_repr)) add
ex clifford_prime(const ex &e)
Automorphism of the Clifford algebra, simply changes signs of all clifford units.
ex dirac_gamma5(unsigned char rl)
Create a Dirac gamma5 object.
bool is_a(const basic &obj)
Check if obj is a T, including base classes.
ex clifford_bar(const ex &e)
Main anti-automorphism of the Clifford algebra: makes reversion and changes signs of all clifford uni...
ex canonicalize_clifford(const ex &e_)
Bring all products of clifford objects in an expression into a canonical order.
ex lorentz_eps(const ex &i1, const ex &i2, const ex &i3, const ex &i4, bool pos_sig)
Create an epsilon tensor in a Minkowski space with four indices.
ex op(const ex &thisex, size_t i)
unsigned cols(const matrix &m)
static unsigned char get_representation_label(const return_type_t &ti)
Extract representation label from tinfo key (as returned by return_type_tinfo()).
ex lorentz_g(const ex &i1, const ex &i2, bool pos_sig)
Create a Minkowski metric tensor with specified indices.
static ex trace_string(exvector::const_iterator ix, size_t num)
Take trace of a string of an even number of Dirac gammas given a vector of indices.
ex clifford_star_bar(const ex &e, bool do_bar, unsigned options)
An auxillary function performing clifford_star() and clifford_bar().
int to_int(const numeric &x)
ex clifford_norm(const ex &e)
Calculation of the norm in the Clifford algebra.
lst clifford_to_lst(const ex &e, const ex &c, bool algebraic)
An inverse function to lst_to_clifford().
bool is_exactly_a(const basic &obj)
Check if obj is a T, not including base classes.
ex dirac_trace(const ex &e, const std::set< unsigned char > &rls, const ex &trONE)
Calculate dirac traces over the specified set of representation labels.
int permutation_sign(It first, It last)
ex lst_to_clifford(const ex &v, const ex &mu, const ex &metr, unsigned char rl)
List or vector conversion into the Clifford vector.
class_info< OPT > * class_info< OPT >::first
ex expand_dummy_sum(const ex &e, bool subs_idx)
This function returns the given expression with expanded sums for all dummy index summations,...
std::vector< ex > exvector
size_t nops(const ex &thisex)
exvector get_all_dummy_indices(const ex &e)
Returns all dummy indices from the exvector.
ex dirac_gammaR(unsigned char rl)
Create a Dirac gammaR object.
function G(const T1 &x, const T2 &y)
ex expand(const ex &thisex, unsigned options=0)
Interface to GiNaC's non-commutative products of expressions.
Makes the interface to the underlying bignum package available.
Interface to GiNaC's overloaded operators.
Interface to GiNaC's symbolic exponentiation (basis^exponent).
#define GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(classname, supername, options)
Macro for inclusion in the implementation of each registered class.
Interface to relations between expressions.
Predicate for finding non-clifford objects.
bool operator()(const ex &e)
To distinguish between different kinds of non-commutative objects.
unsigned rl
to distinguish between non-commutative objects of the same type.
Interface to GiNaC's symbolic objects.
Interface to GiNaC's symmetry definitions.
Interface to several small and furry utilities needed within GiNaC but not of any interest to the use...
#define DEFAULT_PRINT_LATEX(classname, text, latex)
#define DEFAULT_CTOR(classname)
#define DEFAULT_COMPARE(classname)