From: Jens Vollinga Date: Fri, 3 Jun 2005 18:28:07 +0000 (+0000) Subject: Better handling of Clifford objects [V.Kisil]. X-Git-Tag: release_1-4-0~173 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=6eca7546c3ef806e01e393255de7c2bdfc011ea8;hp=0633ed8082961673eedc092689e06fa39d6bc322 Better handling of Clifford objects [V.Kisil]. --- diff --git a/ginac/add.cpp b/ginac/add.cpp index 6969a862..a53a1013 100644 --- a/ginac/add.cpp +++ b/ginac/add.cpp @@ -29,6 +29,8 @@ #include "operators.h" #include "matrix.h" #include "utils.h" +#include "clifford.h" +#include "ncmul.h" namespace GiNaC { @@ -291,17 +293,31 @@ int add::ldegree(const ex & s) const ex add::coeff(const ex & s, int n) const { std::auto_ptr coeffseq(new epvector); + std::auto_ptr coeffseq_cliff(new epvector); + char rl = clifford_max_label(s); + bool do_clifford = (rl != -1); + bool nonscalar = false; // Calculate sum of coefficients in each term epvector::const_iterator i = seq.begin(), end = seq.end(); while (i != end) { ex restcoeff = i->rest.coeff(s, n); - if (!restcoeff.is_zero()) + if (!restcoeff.is_zero()) { + if (do_clifford) { + if (clifford_max_label(restcoeff) == -1) { + coeffseq_cliff->push_back(combine_ex_with_coeff_to_pair(ncmul(restcoeff, dirac_ONE(rl)), i->coeff)); + } else { + coeffseq_cliff->push_back(combine_ex_with_coeff_to_pair(restcoeff, i->coeff)); + nonscalar = true; + } + } coeffseq->push_back(combine_ex_with_coeff_to_pair(restcoeff, i->coeff)); + } ++i; } - return (new add(coeffseq, n==0 ? overall_coeff : _ex0))->setflag(status_flags::dynallocated); + return (new add(nonscalar ? coeffseq_cliff : coeffseq, + n==0 ? overall_coeff : _ex0))->setflag(status_flags::dynallocated); } /** Perform automatic term rewriting rules in this class. In the following