- renamed ncpower() to ncpow()
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Fri, 25 May 2001 22:32:48 +0000 (22:32 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Fri, 25 May 2001 22:32:48 +0000 (22:32 +0000)
- canonicalize_clifford() uses to_rational() now
- minor cleanups

ginac/clifford.cpp
ginac/fail.cpp
ginac/fail.h
ginac/indexed.cpp
ginac/inifcns.cpp
ginac/inifcns.h
ginac/power.cpp

index d520822..e9b50e9 100644 (file)
@@ -26,6 +26,8 @@
 #include "ncmul.h"
 #include "symbol.h"
 #include "numeric.h" // for I
+#include "lst.h"
+#include "relational.h"
 #include "print.h"
 #include "archive.h"
 #include "debugmsg.h"
@@ -336,6 +338,13 @@ static bool is_clifford_tinfo(unsigned ti, unsigned char rl)
        return ti == (TINFO_clifford + rl);
 }
 
+/** Check whether a given tinfo key (as returned by return_type_tinfo()
+ *  is that of a clifford object (with an arbitrary representation label). */
+static bool is_clifford_tinfo(unsigned ti)
+{
+       return (ti & ~0xff) == TINFO_clifford;
+}
+
 ex dirac_trace(const ex & e, unsigned char rl, const ex & trONE)
 {
        if (is_ex_of_type(e, clifford)) {
@@ -439,7 +448,7 @@ ex dirac_trace(const ex & e, unsigned char rl, const ex & trONE)
                                                        }
                                                        int sign = permutation_sign(iv);
                                                        result += sign * eps0123(idx1, idx2, idx3, idx4)
-                                                               * dirac_trace(ncmul(v), rl, trONE);
+                                                               * dirac_trace(ncmul(v, true), rl, trONE);
                                                }
                                        }
                                }
@@ -491,56 +500,54 @@ ex dirac_trace(const ex & e, unsigned char rl, const ex & trONE)
 
 ex canonicalize_clifford(const ex & e)
 {
-       if (is_ex_exactly_of_type(e, add)) {
-
-               ex sum = _ex0();
-               for (unsigned i=0; i<e.nops(); i++)
-                       sum += canonicalize_clifford(e.op(i));
-               return sum;
-
-       } else if (is_ex_exactly_of_type(e, mul)) {
-
-               ex prod = _ex1();
-               for (unsigned i=0; i<e.nops(); i++)
-                       prod *= canonicalize_clifford(e.op(i));
-               return prod;
-
-       } else if (is_ex_exactly_of_type(e, ncmul)) {
-
-               // Expand product, if necessary
-               ex e_expanded = e.expand();
-               if (!is_ex_of_type(e_expanded, ncmul))
-                       return canonicalize_clifford(e_expanded);
-
-               if (!is_ex_of_type(e.op(0), clifford))
-                       return e;
-
-               exvector v;
-               v.reserve(e.nops());
-               for (int i=0; i<e.nops(); i++)
-                       v.push_back(e.op(i));
-
-               // Stupid bubble sort because we only want to swap adjacent gammas
-               exvector::iterator it = v.begin(), next_to_last = v.end() - 1;
-               if (is_ex_of_type(it->op(0), diracgamma5))
-                       it++;
-               while (it != next_to_last) {
-                       if (it[0].op(1).compare(it[1].op(1)) > 0) {
-                               ex save0 = it[0], save1 = it[1];
-                               it[0] = lorentz_g(it[0].op(1), it[1].op(1));
-                               it[1] = _ex2();
-                               ex sum = ncmul(v);
-                               it[0] = save1;
-                               it[1] = save0;
-                               sum -= ncmul(v);
-                               return canonicalize_clifford(sum);
+       // Scan for any ncmul objects
+       lst srl;
+       ex aux = e.to_rational(srl);
+       for (unsigned i=0; i<srl.nops(); i++) {
+
+               ex lhs = srl.op(i).lhs();
+               ex rhs = srl.op(i).rhs();
+
+               if (is_ex_exactly_of_type(rhs, ncmul)
+                && rhs.return_type() == return_types::noncommutative
+                && is_clifford_tinfo(rhs.return_type_tinfo())) {
+
+                       // Expand product, if necessary
+                       ex rhs_expanded = rhs.expand();
+                       if (!is_ex_of_type(rhs_expanded, ncmul)) {
+                               srl.let_op(i) = (lhs == canonicalize_clifford(rhs_expanded));
+                               continue;
+
+                       } else if (!is_ex_of_type(rhs.op(0), clifford))
+                               continue;
+
+                       exvector v;
+                       v.reserve(rhs.nops());
+                       for (unsigned j=0; j<rhs.nops(); j++)
+                               v.push_back(rhs.op(j));
+
+                       // Stupid bubble sort because we only want to swap adjacent gammas
+                       exvector::iterator it = v.begin(), next_to_last = v.end() - 1;
+                       if (is_ex_of_type(it->op(0), diracgamma5))
+                               it++;
+                       while (it != next_to_last) {
+                               if (it[0].op(1).compare(it[1].op(1)) > 0) {
+                                       ex save0 = it[0], save1 = it[1];
+                                       it[0] = lorentz_g(it[0].op(1), it[1].op(1));
+                                       it[1] = _ex2();
+                                       ex sum = ncmul(v);
+                                       it[0] = save1;
+                                       it[1] = save0;
+                                       sum -= ncmul(v, true);
+                                       srl.let_op(i) = (lhs == canonicalize_clifford(sum));
+                                       goto next_sym;
+                               }
+                               it++;
                        }
-                       it++;
+next_sym:      ;
                }
-               return ncmul(v);
        }
-
-       return e;
+       return aux.subs(srl);
 }
 
 } // namespace GiNaC
index 3818538..4c3090f 100644 (file)
@@ -1,7 +1,7 @@
 /** @file fail.cpp
  *
- *  Implementation of class signaling failure of operation. Considered
- *  obsolete all this stuff ought to be replaced by exceptions. */
+ *  Implementation of class signaling failure of operation. Considered obsolete
+ *  (all of this is replaced by exceptions). */
 
 /*
  *  GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
index fdab60c..5b9c214 100644 (file)
@@ -1,7 +1,7 @@
 /** @file fail.h
  *
- *  Interface to class signaling failure of operation. Considered obsolete all
- *  this stuff ought to be replaced by exceptions. */
+ *  Interface to class signaling failure of operation. Considered obsolete
+ *  (all of this is replaced by exceptions). */
 
 /*
  *  GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
index acbf7d4..9ddff04 100644 (file)
@@ -710,7 +710,7 @@ contraction_done:
                                        // Non-commutative products are always re-expanded to give
                                        // simplify_ncmul() the chance to re-order and canonicalize
                                        // the product
-                                       ex r = (non_commutative ? ex(ncmul(v)) : ex(mul(v)));
+                                       ex r = (non_commutative ? ex(ncmul(v, true)) : ex(mul(v)));
                                        return simplify_indexed(r, free_indices, dummy_indices, sp);
                                }
 
@@ -744,7 +744,7 @@ contraction_done:
 
        ex r;
        if (something_changed)
-               r = non_commutative ? ex(ncmul(v)) : ex(mul(v));
+               r = non_commutative ? ex(ncmul(v, true)) : ex(mul(v));
        else
                r = e;
 
index 3bf0b2f..b55261e 100644 (file)
@@ -510,19 +510,17 @@ ex lsolve(const ex &eqns, const ex &symbols)
 }
 
 /** non-commutative power. */
-ex ncpower(const ex &basis, unsigned exponent)
+ex ncpow(const ex & basis, unsigned exponent)
 {
-       if (exponent==0) {
+       if (exponent == 0)
                return _ex1();
-       }
 
        exvector v;
        v.reserve(exponent);
-       for (unsigned i=0; i<exponent; ++i) {
+       for (unsigned i=0; i<exponent; ++i)
                v.push_back(basis);
-       }
 
-       return ncmul(v,1);
+       return ncmul(v, true);
 }
 
 /** Force inclusion of functions from initcns_gamma and inifcns_zeta
index 73fff21..985b50f 100644 (file)
@@ -133,7 +133,8 @@ DECLARE_FUNCTION_2P(Derivative)
 
 ex lsolve(const ex &eqns, const ex &symbols);
 
-ex ncpower(const ex &basis, unsigned exponent);
+/** Power of non-commutative basis. */
+ex ncpow(const ex & basis, unsigned exponent);
 
 inline bool is_order_function(const ex & e)
 {
index 15fed24..9d4b0c8 100644 (file)
@@ -796,31 +796,6 @@ ex power::expand_mul(const mul & m, const numeric & n) const
        return (new mul(distrseq,ex_to_numeric(m.overall_coeff).power_dyn(n)))->setflag(status_flags::dynallocated);
 }
 
-/*
-ex power::expand_commutative_3(const ex & basis, const numeric & exponent,
-                               unsigned options) const
-{
-       // obsolete
-
-       exvector distrseq;
-       epvector splitseq;
-
-       const add & addref=static_cast<const add &>(*basis.bp);
-
-       splitseq=addref.seq;
-       splitseq.pop_back();
-       ex first_operands=add(splitseq);
-       ex last_operand=addref.recombine_pair_to_ex(*(addref.seq.end()-1));
-       
-       int n=exponent.to_int();
-       for (int k=0; k<=n; k++) {
-               distrseq.push_back(binomial(n,k) * power(first_operands,numeric(k))
-                                                * power(last_operand,numeric(n-k)));
-       }
-       return ex((new add(distrseq))->setflag(status_flags::expanded | status_flags::dynallocated)).expand(options);
-}
-*/
-
 /*
 ex power::expand_noncommutative(const ex & basis, const numeric & exponent,
                                                                unsigned options) const