#include "operators.h"
#include "matrix.h"
#include "utils.h"
+#include "clifford.h"
+#include "ncmul.h"
namespace GiNaC {
ex add::coeff(const ex & s, int n) const
{
std::auto_ptr<epvector> coeffseq(new epvector);
+ std::auto_ptr<epvector> 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