added add::conjugate(), solving problems with numeric factors
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Sun, 4 Jul 2004 15:06:46 +0000 (15:06 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Sun, 4 Jul 2004 15:06:46 +0000 (15:06 +0000)
ginac/add.cpp
ginac/add.h

index f76666b..a4dcb5b 100644 (file)
@@ -382,6 +382,32 @@ ex add::evalm() const
                return (new add(s, overall_coeff))->setflag(status_flags::dynallocated);
 }
 
+ex add::conjugate() const
+{
+       exvector *v = 0;
+       for (int i=0; i<nops(); ++i) {
+               if (v) {
+                       v->push_back(op(i).conjugate());
+                       continue;
+               }
+               ex term = op(i);
+               ex ccterm = term.conjugate();
+               if (are_ex_trivially_equal(term, ccterm))
+                       continue;
+               v = new exvector;
+               v->reserve(nops());
+               for (int j=0; j<i; ++j)
+                       v->push_back(op(j));
+               v->push_back(ccterm);
+       }
+       if (v) {
+               ex result = add(*v);
+               delete v;
+               return result;
+       }
+       return *this;
+}
+
 ex add::eval_ncmul(const exvector & v) const
 {
        if (seq.empty())
index 5fe05d9..f61931b 100644 (file)
@@ -57,6 +57,7 @@ public:
        numeric integer_content() const;
        ex smod(const numeric &xi) const;
        numeric max_coefficient() const;
+       ex conjugate() const;
        exvector get_free_indices() const;
        ex eval_ncmul(const exvector & v) const;
 protected: