X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fclifford.cpp;h=3b4684c2165f07dda393d241401caeff9ba9db23;hp=100954d991910bd776c27056fb0bb77d03a40a31;hb=1602530f716ba1d425a0667b897182b99c374823;hpb=67467d256b44f5e08498ca81c946d9ffaa25d1e2 diff --git a/ginac/clifford.cpp b/ginac/clifford.cpp index 100954d9..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-2008 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)) @@ -78,7 +76,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 +94,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 @@ -107,25 +103,28 @@ clifford::clifford(const ex & b, unsigned char rl) : inherited(b), representatio 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, int comm_sign, const exvector & v, bool discardable) : inherited(not_symmetric(), v, discardable), 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) { - tinfo_key = &clifford::tinfo_static; +} + +return_type_t clifford::return_type_tinfo() const +{ + 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 +141,12 @@ 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(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 @@ -716,9 +714,21 @@ ex dirac_ONE(unsigned char rl) 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) { - 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")); @@ -732,12 +742,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), + //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; } } @@ -747,7 +759,9 @@ 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()), + //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 @@ -795,19 +809,11 @@ ex dirac_slash(const ex & e, const ex & dim, unsigned char rl) 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(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()) { @@ -1218,22 +1224,27 @@ 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) + 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) { @@ -1251,6 +1262,8 @@ static ex get_clifford_comp(const ex & e, const ex & c) } 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"));