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;
}
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)
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;
}
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)
// default constructor
//////////
-indexed::indexed() : symtree(sy_none())
+indexed::indexed() : symtree(not_symmetric())
{
tinfo_key = TINFO_indexed;
}
// 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();
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;
symtree = sy_anti();
break;
default:
- symtree = sy_none();
+ symtree = not_symmetric();
break;
}
const_cast<symmetry &>(ex_to<symmetry>(symtree)).validate(seq.size() - 1);
// 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;
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.
*
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"));
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"));
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"));
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