From 6eca7546c3ef806e01e393255de7c2bdfc011ea8 Mon Sep 17 00:00:00 2001 From: Jens Vollinga Date: Fri, 3 Jun 2005 18:28:07 +0000 Subject: [PATCH] Better handling of Clifford objects [V.Kisil]. --- ginac/add.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) 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 -- 2.44.0