]> www.ginac.de Git - ginac.git/commitdiff
predefined tensors and common symmetries are taken from preallocated objects
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Thu, 10 Jun 2004 02:19:36 +0000 (02:19 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Thu, 10 Jun 2004 02:19:36 +0000 (02:19 +0000)
to conserve memory

ginac/clifford.cpp
ginac/color.cpp
ginac/indexed.cpp
ginac/symmetry.cpp
ginac/symmetry.h
ginac/tensor.cpp

index e6f9c2914be0a638f0e76cabf4879ca2f18fb727..93f777d8a9db5a7a14c503db0103a1225fb20b11 100644 (file)
@@ -99,12 +99,12 @@ clifford::clifford(const ex & b, const ex & mu, unsigned char rl) : inherited(b,
        tinfo_key = TINFO_clifford;
 }
 
-clifford::clifford(unsigned char rl, const exvector & v, bool discardable) : inherited(sy_none(), v, discardable), representation_label(rl)
+clifford::clifford(unsigned char rl, const exvector & v, bool discardable) : inherited(not_symmetric(), v, discardable), representation_label(rl)
 {
        tinfo_key = TINFO_clifford;
 }
 
-clifford::clifford(unsigned char rl, std::auto_ptr<exvector> vp) : inherited(sy_none(), vp), representation_label(rl)
+clifford::clifford(unsigned char rl, std::auto_ptr<exvector> vp) : inherited(not_symmetric(), vp), representation_label(rl)
 {
        tinfo_key = TINFO_clifford;
 }
@@ -505,30 +505,36 @@ 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 dirac_gamma(const ex & mu, unsigned char rl)
 {
+       static ex gamma = (new diracgamma)->setflag(status_flags::dynallocated);
+
        if (!is_a<varidx>(mu))
                throw(std::invalid_argument("index of Dirac gamma must be of type varidx"));
 
-       return clifford(diracgamma(), mu, rl);
+       return clifford(gamma, mu, 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)
index 600da082f06a575b41ddd5c63446422289680af3..e06eff44a43c659ef7bb7567f6dc04fdffc03961 100644 (file)
@@ -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<exvector> vp) : inherited(sy_none(), vp), representation_label(rl)
+color::color(unsigned char rl, std::auto_ptr<exvector> 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<idx>(a))
                throw(std::invalid_argument("indices of color_T must be of type idx"));
        if (!ex_to<idx>(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<idx>(a) || !is_a<idx>(b) || !is_a<idx>(c))
                throw(std::invalid_argument("indices of color_f must be of type idx"));
        if (!ex_to<idx>(a).get_dim().is_equal(8) || !ex_to<idx>(b).get_dim().is_equal(8) || !ex_to<idx>(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<idx>(a) || !is_a<idx>(b) || !is_a<idx>(c))
                throw(std::invalid_argument("indices of color_d must be of type idx"));
        if (!ex_to<idx>(a).get_dim().is_equal(8) || !ex_to<idx>(b).get_dim().is_equal(8) || !ex_to<idx>(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)
index 40a6232c1ecdcb02f5f678acd616b79d21b76138..d1d5f7287b07d01a723f22adf0e21c37ffdcb15d 100644 (file)
@@ -48,7 +48,7 @@ GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(indexed, exprseq,
 // default constructor
 //////////
 
-indexed::indexed() : symtree(sy_none())
+indexed::indexed() : symtree(not_symmetric())
 {
        tinfo_key = TINFO_indexed;
 }
@@ -57,31 +57,31 @@ indexed::indexed() : symtree(sy_none())
 // other constructors
 //////////
 
-indexed::indexed(const ex & b) : inherited(b), symtree(sy_none())
+indexed::indexed(const ex & b) : inherited(b), symtree(not_symmetric())
 {
        tinfo_key = TINFO_indexed;
        validate();
 }
 
-indexed::indexed(const ex & b, const ex & i1) : inherited(b, i1), symtree(sy_none())
+indexed::indexed(const ex & b, const ex & i1) : inherited(b, i1), symtree(not_symmetric())
 {
        tinfo_key = TINFO_indexed;
        validate();
 }
 
-indexed::indexed(const ex & b, const ex & i1, const ex & i2) : inherited(b, i1, i2), symtree(sy_none())
+indexed::indexed(const ex & b, const ex & i1, const ex & i2) : inherited(b, i1, i2), symtree(not_symmetric())
 {
        tinfo_key = TINFO_indexed;
        validate();
 }
 
-indexed::indexed(const ex & b, const ex & i1, const ex & i2, const ex & i3) : inherited(b, i1, i2, i3), symtree(sy_none())
+indexed::indexed(const ex & b, const ex & i1, const ex & i2, const ex & i3) : inherited(b, i1, i2, i3), symtree(not_symmetric())
 {
        tinfo_key = TINFO_indexed;
        validate();
 }
 
-indexed::indexed(const ex & b, const ex & i1, const ex & i2, const ex & i3, const ex & i4) : inherited(b, i1, i2, i3, i4), symtree(sy_none())
+indexed::indexed(const ex & b, const ex & i1, const ex & i2, const ex & i3, const ex & i4) : inherited(b, i1, i2, i3, i4), symtree(not_symmetric())
 {
        tinfo_key = TINFO_indexed;
        validate();
@@ -105,7 +105,7 @@ indexed::indexed(const ex & b, const symmetry & symm, const ex & i1, const ex &
        validate();
 }
 
-indexed::indexed(const ex & b, const exvector & v) : inherited(b), symtree(sy_none())
+indexed::indexed(const ex & b, const exvector & v) : inherited(b), symtree(not_symmetric())
 {
        seq.insert(seq.end(), v.begin(), v.end());
        tinfo_key = TINFO_indexed;
@@ -152,7 +152,7 @@ indexed::indexed(const archive_node &n, lst &sym_lst) : inherited(n, sym_lst)
                                symtree = sy_anti();
                                break;
                        default:
-                               symtree = sy_none();
+                               symtree = not_symmetric();
                                break;
                }
                const_cast<symmetry &>(ex_to<symmetry>(symtree)).validate(seq.size() - 1);
index 637e5abe1c3c83faf59e8b7102441e79eb350382..84f6e6cf058016734a4ce4c5c30301f97fc7725a 100644 (file)
@@ -245,6 +245,72 @@ void symmetry::validate(unsigned n)
 // global functions
 //////////
 
+static const symmetry & index0()
+{
+       static ex s = (new symmetry(0))->setflag(status_flags::dynallocated);
+       return ex_to<symmetry>(s);
+}
+
+static const symmetry & index1()
+{
+       static ex s = (new symmetry(1))->setflag(status_flags::dynallocated);
+       return ex_to<symmetry>(s);
+}
+
+static const symmetry & index2()
+{
+       static ex s = (new symmetry(2))->setflag(status_flags::dynallocated);
+       return ex_to<symmetry>(s);
+}
+
+static const symmetry & index3()
+{
+       static ex s = (new symmetry(3))->setflag(status_flags::dynallocated);
+       return ex_to<symmetry>(s);
+}
+
+const symmetry & not_symmetric()
+{
+       static ex s = (new symmetry)->setflag(status_flags::dynallocated);
+       return ex_to<symmetry>(s);
+}
+
+const symmetry & symmetric2()
+{
+       static ex s = (new symmetry(symmetry::symmetric, index0(), index1()))->setflag(status_flags::dynallocated);
+       return ex_to<symmetry>(s);
+}
+
+const symmetry & symmetric3()
+{
+       static ex s = (new symmetry(symmetry::symmetric, index0(), index1()))->add(index2()).setflag(status_flags::dynallocated);
+       return ex_to<symmetry>(s);
+}
+
+const symmetry & symmetric4()
+{
+       static ex s = (new symmetry(symmetry::symmetric, index0(), index1()))->add(index2()).add(index3()).setflag(status_flags::dynallocated);
+       return ex_to<symmetry>(s);
+}
+
+const symmetry & antisymmetric2()
+{
+       static ex s = (new symmetry(symmetry::antisymmetric, index0(), index1()))->setflag(status_flags::dynallocated);
+       return ex_to<symmetry>(s);
+}
+
+const symmetry & antisymmetric3()
+{
+       static ex s = (new symmetry(symmetry::antisymmetric, index0(), index1()))->add(index2()).setflag(status_flags::dynallocated);
+       return ex_to<symmetry>(s);
+}
+
+const symmetry & antisymmetric4()
+{
+       static ex s = (new symmetry(symmetry::antisymmetric, index0(), index1()))->add(index2()).add(index3()).setflag(status_flags::dynallocated);
+       return ex_to<symmetry>(s);
+}
+
 class sy_is_less : public std::binary_function<ex, ex, bool> {
        exvector::iterator v;
 
index a002885e82b6360fccb53ded09682e2d97f864e9..4ec444f8bd393b61088e981ad0bfafd35bc72ef4 100644 (file)
@@ -120,6 +120,16 @@ inline symmetry sy_cycl(const symmetry &c1, const symmetry &c2) { return symmetr
 inline symmetry sy_cycl(const symmetry &c1, const symmetry &c2, const symmetry &c3) { return symmetry(symmetry::cyclic, c1, c2).add(c3); }
 inline symmetry sy_cycl(const symmetry &c1, const symmetry &c2, const symmetry &c3, const symmetry &c4) { return symmetry(symmetry::cyclic, c1, c2).add(c3).add(c4); }
 
+// These return references to preallocated common symmetries (similar to
+// the numeric flyweights).
+const symmetry & not_symmetric();
+const symmetry & symmetric2();
+const symmetry & symmetric3();
+const symmetry & symmetric4();
+const symmetry & antisymmetric2();
+const symmetry & antisymmetric3();
+const symmetry & antisymmetric4();
+
 /** Canonicalize the order of elements of an expression vector, according to
  *  the symmetry properties defined in a symmetry tree.
  *
index 399d3119ba742ba0b8d8cc21c8ef906ae5835664..a8c83b65ab20edeb18258411bd1e42dfa434788d 100644 (file)
@@ -534,40 +534,51 @@ bool tensepsilon::contract_with(exvector::iterator self, exvector::iterator othe
 
 ex delta_tensor(const ex & i1, const ex & i2)
 {
+       static ex delta = (new tensdelta)->setflag(status_flags::dynallocated);
+
        if (!is_a<idx>(i1) || !is_a<idx>(i2))
                throw(std::invalid_argument("indices of delta tensor must be of type idx"));
 
-       return indexed(tensdelta(), sy_symm(), i1, i2);
+       return indexed(delta, symmetric2(), i1, i2);
 }
 
 ex metric_tensor(const ex & i1, const ex & i2)
 {
+       static ex metric = (new tensmetric)->setflag(status_flags::dynallocated);
+
        if (!is_a<varidx>(i1) || !is_a<varidx>(i2))
                throw(std::invalid_argument("indices of metric tensor must be of type varidx"));
 
-       return indexed(tensmetric(), sy_symm(), i1, i2);
+       return indexed(metric, symmetric2(), i1, i2);
 }
 
 ex lorentz_g(const ex & i1, const ex & i2, bool pos_sig)
 {
+       static ex metric_neg = (new minkmetric(false))->setflag(status_flags::dynallocated);
+       static ex metric_pos = (new minkmetric(true))->setflag(status_flags::dynallocated);
+
        if (!is_a<varidx>(i1) || !is_a<varidx>(i2))
                throw(std::invalid_argument("indices of metric tensor must be of type varidx"));
 
-       return indexed(minkmetric(pos_sig), sy_symm(), i1, i2);
+       return indexed(pos_sig ? metric_pos : metric_neg, symmetric2(), i1, i2);
 }
 
 ex spinor_metric(const ex & i1, const ex & i2)
 {
+       static ex metric = (new spinmetric)->setflag(status_flags::dynallocated);
+
        if (!is_a<spinidx>(i1) || !is_a<spinidx>(i2))
                throw(std::invalid_argument("indices of spinor metric must be of type spinidx"));
        if (!ex_to<idx>(i1).get_dim().is_equal(2) || !ex_to<idx>(i2).get_dim().is_equal(2))
                throw(std::runtime_error("index dimension for spinor metric must be 2"));
 
-       return indexed(spinmetric(), sy_anti(), i1, i2);
+       return indexed(metric, antisymmetric2(), i1, i2);
 }
 
 ex epsilon_tensor(const ex & i1, const ex & i2)
 {
+       static ex epsilon = (new tensepsilon)->setflag(status_flags::dynallocated);
+
        if (!is_a<idx>(i1) || !is_a<idx>(i2))
                throw(std::invalid_argument("indices of epsilon tensor must be of type idx"));
 
@@ -577,11 +588,13 @@ ex epsilon_tensor(const ex & i1, const ex & i2)
        if (!ex_to<idx>(i1).get_dim().is_equal(_ex2))
                throw(std::runtime_error("index dimension of epsilon tensor must match number of indices"));
 
-       return indexed(tensepsilon(), sy_anti(), i1, i2);
+       return indexed(epsilon, antisymmetric2(), i1, i2);
 }
 
 ex epsilon_tensor(const ex & i1, const ex & i2, const ex & i3)
 {
+       static ex epsilon = (new tensepsilon)->setflag(status_flags::dynallocated);
+
        if (!is_a<idx>(i1) || !is_a<idx>(i2) || !is_a<idx>(i3))
                throw(std::invalid_argument("indices of epsilon tensor must be of type idx"));
 
@@ -591,11 +604,14 @@ ex epsilon_tensor(const ex & i1, const ex & i2, const ex & i3)
        if (!ex_to<idx>(i1).get_dim().is_equal(_ex3))
                throw(std::runtime_error("index dimension of epsilon tensor must match number of indices"));
 
-       return indexed(tensepsilon(), sy_anti(), i1, i2, i3);
+       return indexed(epsilon, antisymmetric3(), i1, i2, i3);
 }
 
 ex lorentz_eps(const ex & i1, const ex & i2, const ex & i3, const ex & i4, bool pos_sig)
 {
+       static ex epsilon_neg = (new tensepsilon(true, false))->setflag(status_flags::dynallocated);
+       static ex epsilon_pos = (new tensepsilon(true, true))->setflag(status_flags::dynallocated);
+
        if (!is_a<varidx>(i1) || !is_a<varidx>(i2) || !is_a<varidx>(i3) || !is_a<varidx>(i4))
                throw(std::invalid_argument("indices of Lorentz epsilon tensor must be of type varidx"));
 
@@ -605,7 +621,7 @@ ex lorentz_eps(const ex & i1, const ex & i2, const ex & i3, const ex & i4, bool
        if (!ex_to<idx>(i1).get_dim().is_equal(_ex4))
                throw(std::runtime_error("index dimension of epsilon tensor must match number of indices"));
 
-       return indexed(tensepsilon(true, pos_sig), sy_anti(), i1, i2, i3, i4);
+       return indexed(pos_sig ? epsilon_pos : epsilon_neg, antisymmetric4(), i1, i2, i3, i4);
 }
 
 } // namespace GiNaC