From 23acc666fcef311fd97092aee7f8c55e80395351 Mon Sep 17 00:00:00 2001 From: Christian Bauer Date: Thu, 10 Jun 2004 02:30:29 +0000 Subject: [PATCH] synced to 1.2 (memory conservation) --- ginac/basic.cpp | 25 ++++++++++++----- ginac/clifford.cpp | 20 +++++++++----- ginac/color.cpp | 19 +++++++++---- ginac/container.h | 6 ++-- ginac/idx.cpp | 15 ++++++---- ginac/indexed.cpp | 16 +++++------ ginac/ncmul.cpp | 47 +++++++++++++++++++++++-------- ginac/ncmul.h | 2 +- ginac/power.cpp | 9 +++++- ginac/relational.cpp | 9 +++++- ginac/symmetry.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++ ginac/symmetry.h | 10 +++++++ ginac/tensor.cpp | 30 +++++++++++++++----- ginac/utils.h | 2 +- 14 files changed, 217 insertions(+), 59 deletions(-) diff --git a/ginac/basic.cpp b/ginac/basic.cpp index 7a063476..17f265de 100644 --- a/ginac/basic.cpp +++ b/ginac/basic.cpp @@ -307,12 +307,23 @@ ex basic::map(map_function & f) const if (num == 0) return *this; - basic *copy = duplicate(); - copy->setflag(status_flags::dynallocated); - copy->clearflag(status_flags::hash_calculated | status_flags::expanded); - for (size_t i=0; ilet_op(i) = f(copy->op(i)); - return *copy; + basic *copy = NULL; + for (size_t i=0; ilet_op(i) = n; + } + } + + if (copy) { + copy->setflag(status_flags::dynallocated); + copy->clearflag(status_flags::hash_calculated | status_flags::expanded); + return *copy; + } else + return *this; } /** Return degree of highest power in object s. */ @@ -781,7 +792,7 @@ unsigned basic::calchash() const struct expand_map_function : public map_function { unsigned options; expand_map_function(unsigned o) : options(o) {} - ex operator()(const ex & e) { return expand(e, options); } + ex operator()(const ex & e) { return e.expand(options); } }; /** Expand expression, i.e. multiply it out and return the result as a new diff --git a/ginac/clifford.cpp b/ginac/clifford.cpp index a3574029..afc99894 100644 --- a/ginac/clifford.cpp +++ b/ginac/clifford.cpp @@ -106,12 +106,12 @@ clifford::clifford(const ex & b, const ex & mu, const ex & metr, unsigned char r tinfo_key = TINFO_clifford; } -clifford::clifford(unsigned char rl, const ex & metr, const exvector & v, bool discardable) : inherited(sy_none(), v, discardable), representation_label(rl), metric(metr) +clifford::clifford(unsigned char rl, const ex & metr, const exvector & v, bool discardable) : inherited(not_symmetric(), v, discardable), representation_label(rl), metric(metr) { tinfo_key = TINFO_clifford; } -clifford::clifford(unsigned char rl, const ex & metr, std::auto_ptr vp) : inherited(sy_none(), vp), representation_label(rl), metric(metr) +clifford::clifford(unsigned char rl, const ex & metr, std::auto_ptr vp) : inherited(not_symmetric(), vp), representation_label(rl), metric(metr) { tinfo_key = TINFO_clifford; } @@ -634,7 +634,8 @@ ex diracgammaR::conjugate() const ex dirac_ONE(unsigned char rl) { - return clifford(diracone(), rl); + static ex ONE = (new diracone)->setflag(status_flags::dynallocated); + return clifford(ONE, rl); } ex clifford_unit(const ex & mu, const ex & metr, unsigned char rl) @@ -654,26 +655,31 @@ ex clifford_unit(const ex & mu, const ex & metr, unsigned char rl) ex dirac_gamma(const ex & mu, unsigned char rl) { + static ex gamma = (new diracgamma)->setflag(status_flags::dynallocated); + if (!is_a(mu)) throw(std::invalid_argument("index of Dirac gamma must be of type varidx")); ex dim = ex_to(mu).get_dim(); - return clifford(diracgamma(), mu, lorentz_g(varidx((new symbol)->setflag(status_flags::dynallocated), dim),varidx((new symbol)->setflag(status_flags::dynallocated), dim)), rl); + return clifford(gamma, mu, lorentz_g(varidx((new symbol)->setflag(status_flags::dynallocated), dim),varidx((new symbol)->setflag(status_flags::dynallocated), dim)), rl); } ex dirac_gamma5(unsigned char rl) { - return clifford(diracgamma5(), rl); + static ex gamma5 = (new diracgamma5)->setflag(status_flags::dynallocated); + return clifford(gamma5, rl); } ex dirac_gammaL(unsigned char rl) { - return clifford(diracgammaL(), rl); + static ex gammaL = (new diracgammaL)->setflag(status_flags::dynallocated); + return clifford(gammaL, rl); } ex dirac_gammaR(unsigned char rl) { - return clifford(diracgammaR(), rl); + static ex gammaR = (new diracgammaR)->setflag(status_flags::dynallocated); + return clifford(gammaR, rl); } ex dirac_slash(const ex & e, const ex & dim, unsigned char rl) diff --git a/ginac/color.cpp b/ginac/color.cpp index 600da082..e06eff44 100644 --- a/ginac/color.cpp +++ b/ginac/color.cpp @@ -89,12 +89,12 @@ color::color(const ex & b, const ex & i1, unsigned char rl) : inherited(b, i1), tinfo_key = TINFO_color; } -color::color(unsigned char rl, const exvector & v, bool discardable) : inherited(sy_none(), v, discardable), representation_label(rl) +color::color(unsigned char rl, const exvector & v, bool discardable) : inherited(not_symmetric(), v, discardable), representation_label(rl) { tinfo_key = TINFO_color; } -color::color(unsigned char rl, std::auto_ptr vp) : inherited(sy_none(), vp), representation_label(rl) +color::color(unsigned char rl, std::auto_ptr vp) : inherited(not_symmetric(), vp), representation_label(rl) { tinfo_key = TINFO_color; } @@ -475,37 +475,44 @@ bool su3f::contract_with(exvector::iterator self, exvector::iterator other, exve ex color_ONE(unsigned char rl) { - return color(su3one(), rl); + static ex ONE = (new su3one)->setflag(status_flags::dynallocated); + return color(ONE, rl); } ex color_T(const ex & a, unsigned char rl) { + static ex t = (new su3t)->setflag(status_flags::dynallocated); + if (!is_a(a)) throw(std::invalid_argument("indices of color_T must be of type idx")); if (!ex_to(a).get_dim().is_equal(8)) throw(std::invalid_argument("index dimension for color_T must be 8")); - return color(su3t(), a, rl); + return color(t, a, rl); } ex color_f(const ex & a, const ex & b, const ex & c) { + static ex f = (new su3f)->setflag(status_flags::dynallocated); + if (!is_a(a) || !is_a(b) || !is_a(c)) throw(std::invalid_argument("indices of color_f must be of type idx")); if (!ex_to(a).get_dim().is_equal(8) || !ex_to(b).get_dim().is_equal(8) || !ex_to(c).get_dim().is_equal(8)) throw(std::invalid_argument("index dimension for color_f must be 8")); - return indexed(su3f(), sy_anti(), a, b, c); + return indexed(f, antisymmetric3(), a, b, c); } ex color_d(const ex & a, const ex & b, const ex & c) { + static ex d = (new su3d)->setflag(status_flags::dynallocated); + if (!is_a(a) || !is_a(b) || !is_a(c)) throw(std::invalid_argument("indices of color_d must be of type idx")); if (!ex_to(a).get_dim().is_equal(8) || !ex_to(b).get_dim().is_equal(8) || !ex_to(c).get_dim().is_equal(8)) throw(std::invalid_argument("index dimension for color_d must be 8")); - return indexed(su3d(), sy_symm(), a, b, c); + return indexed(d, symmetric3(), a, b, c); } ex color_h(const ex & a, const ex & b, const ex & c) diff --git a/ginac/container.h b/ginac/container.h index 11b5be0b..6161a20b 100644 --- a/ginac/container.h +++ b/ginac/container.h @@ -502,7 +502,7 @@ void container::do_print(const print_context & c, unsigned level) const template