From: Christian Bauer Date: Fri, 25 May 2001 22:32:48 +0000 (+0000) Subject: - renamed ncpower() to ncpow() X-Git-Tag: release_0-9-0~33 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=444d1e293d87b78f0497a55c6a4dabad010f5b62 - renamed ncpower() to ncpow() - canonicalize_clifford() uses to_rational() now - minor cleanups --- diff --git a/ginac/clifford.cpp b/ginac/clifford.cpp index d520822d..e9b50e9a 100644 --- a/ginac/clifford.cpp +++ b/ginac/clifford.cpp @@ -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; iop(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; iop(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 diff --git a/ginac/fail.cpp b/ginac/fail.cpp index 3818538f..4c3090fb 100644 --- a/ginac/fail.cpp +++ b/ginac/fail.cpp @@ -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 diff --git a/ginac/fail.h b/ginac/fail.h index fdab60c7..5b9c2147 100644 --- a/ginac/fail.h +++ b/ginac/fail.h @@ -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 diff --git a/ginac/indexed.cpp b/ginac/indexed.cpp index acbf7d48..9ddff040 100644 --- a/ginac/indexed.cpp +++ b/ginac/indexed.cpp @@ -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; diff --git a/ginac/inifcns.cpp b/ginac/inifcns.cpp index 3bf0b2f7..b55261eb 100644 --- a/ginac/inifcns.cpp +++ b/ginac/inifcns.cpp @@ -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; isetflag(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(*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