]> www.ginac.de Git - ginac.git/commitdiff
Better handling of Clifford objects [V.Kisil].
authorJens Vollinga <vollinga@thep.physik.uni-mainz.de>
Fri, 3 Jun 2005 18:28:07 +0000 (18:28 +0000)
committerJens Vollinga <vollinga@thep.physik.uni-mainz.de>
Fri, 3 Jun 2005 18:28:07 +0000 (18:28 +0000)
ginac/add.cpp

index 6969a8626de3aeccf09ab0a428d094cc8db74ca0..a53a1013e7d22e10d2df64cbefb0d27cb0a3f13e 100644 (file)
@@ -29,6 +29,8 @@
 #include "operators.h"
 #include "matrix.h"
 #include "utils.h"
 #include "operators.h"
 #include "matrix.h"
 #include "utils.h"
+#include "clifford.h"
+#include "ncmul.h"
 
 namespace GiNaC {
 
 
 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<epvector> coeffseq(new epvector);
 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);
 
        // 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));
                        coeffseq->push_back(combine_ex_with_coeff_to_pair(restcoeff, i->coeff));
+               }
                ++i;
        }
 
                ++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
 }
 
 /** Perform automatic term rewriting rules in this class.  In the following