3 * Implementation of GiNaC's color (SU(3) Lie algebra) objects. */
6 * GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "power.h" // for sqrt()
39 GINAC_IMPLEMENT_REGISTERED_CLASS(color, indexed)
40 GINAC_IMPLEMENT_REGISTERED_CLASS(su3one, tensor)
41 GINAC_IMPLEMENT_REGISTERED_CLASS(su3t, tensor)
42 GINAC_IMPLEMENT_REGISTERED_CLASS(su3f, tensor)
43 GINAC_IMPLEMENT_REGISTERED_CLASS(su3d, tensor)
46 // default constructor, destructor, copy constructor assignment operator and helpers
49 color::color() : representation_label(0)
51 debugmsg("color default constructor", LOGLEVEL_CONSTRUCT);
52 tinfo_key = TINFO_color;
55 void color::copy(const color & other)
57 inherited::copy(other);
58 representation_label = other.representation_label;
61 DEFAULT_DESTROY(color)
71 /** Construct object without any color index. This constructor is for
72 * internal use only. Use the color_ONE() function instead.
74 color::color(const ex & b, unsigned rl = 0) : inherited(b), representation_label(rl)
76 debugmsg("color constructor from ex,unsigned", LOGLEVEL_CONSTRUCT);
77 tinfo_key = TINFO_color;
80 /** Construct object with one color index. This constructor is for internal
81 * use only. Use the color_T() function instead.
83 color::color(const ex & b, const ex & i1, unsigned rl = 0) : inherited(b, i1), representation_label(rl)
85 debugmsg("color constructor from ex,ex,unsigned", LOGLEVEL_CONSTRUCT);
86 tinfo_key = TINFO_color;
89 color::color(unsigned rl, const exvector & v, bool discardable) : inherited(indexed::unknown, v, discardable), representation_label(rl)
91 debugmsg("color constructor from unsigned,exvector", LOGLEVEL_CONSTRUCT);
92 tinfo_key = TINFO_color;
95 color::color(unsigned rl, exvector * vp) : inherited(indexed::unknown, vp), representation_label(rl)
97 debugmsg("color constructor from unsigned,exvector *", LOGLEVEL_CONSTRUCT);
98 tinfo_key = TINFO_color;
105 color::color(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
107 debugmsg("color constructor from archive_node", LOGLEVEL_CONSTRUCT);
108 n.find_unsigned("representation", representation_label);
111 void color::archive(archive_node &n) const
113 inherited::archive(n);
114 n.add_unsigned("representation", representation_label);
117 DEFAULT_UNARCHIVE(color)
118 DEFAULT_ARCHIVING(su3one)
119 DEFAULT_ARCHIVING(su3t)
120 DEFAULT_ARCHIVING(su3f)
121 DEFAULT_ARCHIVING(su3d)
124 // functions overriding virtual functions from bases classes
127 int color::compare_same_type(const basic & other) const
129 GINAC_ASSERT(other.tinfo() == TINFO_color);
130 const color &o = static_cast<const color &>(other);
132 if (representation_label != o.representation_label) {
133 // different representation label
134 return representation_label < o.representation_label ? -1 : 1;
137 return inherited::compare_same_type(other);
140 DEFAULT_COMPARE(su3one)
141 DEFAULT_COMPARE(su3t)
142 DEFAULT_COMPARE(su3f)
143 DEFAULT_COMPARE(su3d)
145 DEFAULT_PRINT(su3one, "ONE")
146 DEFAULT_PRINT(su3t, "T")
147 DEFAULT_PRINT(su3f, "f")
148 DEFAULT_PRINT(su3d, "d")
150 /** Perform automatic simplification on noncommutative product of color
151 * objects. This removes superfluous ONEs. */
152 ex color::simplify_ncmul(const exvector & v) const
154 //!! TODO: sort by representation label
158 exvector::const_iterator it = v.begin(), itend = v.end();
159 while (it != itend) {
160 if (!is_ex_of_type(it->op(0), su3one))
166 return color(su3one());
167 else if (s.size() == v.size())
168 return simplified_ncmul(v);
170 return simplified_ncmul(s);
173 ex color::thisexprseq(const exvector & v) const
175 return color(representation_label, v);
178 ex color::thisexprseq(exvector * vp) const
180 return color(representation_label, vp);
183 /** Given a vector iv3 of three indices and a vector iv2 of two indices that
184 * is a subset of iv3, return the (free) index that is in iv3 but not in
185 * iv2 and the sign introduced by permuting that index to the front.
187 * @param iv3 Vector of 3 indices
188 * @param iv2 Vector of 2 indices, must be a subset of iv3
189 * @param sig Returs sign introduced by index permutation
190 * @return the free index (the one that is in iv3 but not in iv2) */
191 static ex permute_free_index_to_front(const exvector & iv3, const exvector & iv2, int & sig)
193 GINAC_ASSERT(iv3.size() == 3);
194 GINAC_ASSERT(iv2.size() == 2);
198 #define TEST_PERMUTATION(A,B,C,P) \
199 if (iv3[B].is_equal(iv2[0]) && iv3[C].is_equal(iv2[1])) { \
204 TEST_PERMUTATION(0,1,2, 1);
205 TEST_PERMUTATION(0,2,1, -1);
206 TEST_PERMUTATION(1,0,2, -1);
207 TEST_PERMUTATION(1,2,0, 1);
208 TEST_PERMUTATION(2,0,1, 1);
209 TEST_PERMUTATION(2,1,0, -1);
211 throw(std::logic_error("permute_free_index_to_front(): no valid permutation found"));
214 /** Automatic symbolic evaluation of indexed symmetric structure constant. */
215 ex su3d::eval_indexed(const basic & i) const
217 GINAC_ASSERT(is_of_type(i, indexed));
218 GINAC_ASSERT(i.nops() == 4);
219 GINAC_ASSERT(is_ex_of_type(i.op(0), su3d));
221 // Convolutions are zero
222 if (static_cast<const indexed &>(i).get_dummy_indices().size() != 0)
225 // Numeric evaluation
226 if (static_cast<const indexed &>(i).all_index_values_are(info_flags::nonnegint)) {
230 for (unsigned j=0; j<3; j++)
231 v[j] = ex_to_numeric(ex_to_idx(i.op(j + 1)).get_value()).to_int();
232 if (v[0] > v[1]) std::swap(v[0], v[1]);
233 if (v[0] > v[2]) std::swap(v[0], v[2]);
234 if (v[1] > v[2]) std::swap(v[1], v[2]);
236 #define CMPINDICES(A,B,C) ((v[0] == (A)) && (v[1] == (B)) && (v[2] == (C)))
238 // Check for non-zero elements
239 if (CMPINDICES(1,4,6) || CMPINDICES(1,5,7) || CMPINDICES(2,5,6)
240 || CMPINDICES(3,4,4) || CMPINDICES(3,5,5))
242 else if (CMPINDICES(2,4,7) || CMPINDICES(3,6,6) || CMPINDICES(3,7,7))
244 else if (CMPINDICES(1,1,8) || CMPINDICES(2,2,8) || CMPINDICES(3,3,8))
245 return sqrt(_ex3())/3;
246 else if (CMPINDICES(8,8,8))
247 return -sqrt(_ex3())/3;
248 else if (CMPINDICES(4,4,8) || CMPINDICES(5,5,8)
249 || CMPINDICES(6,6,8) || CMPINDICES(7,7,8))
250 return -sqrt(_ex3())/6;
255 // No further simplifications
259 /** Automatic symbolic evaluation of indexed antisymmetric structure constant. */
260 ex su3f::eval_indexed(const basic & i) const
262 GINAC_ASSERT(is_of_type(i, indexed));
263 GINAC_ASSERT(i.nops() == 4);
264 GINAC_ASSERT(is_ex_of_type(i.op(0), su3f));
266 // Numeric evaluation
267 if (static_cast<const indexed &>(i).all_index_values_are(info_flags::nonnegint)) {
269 // Sort indices, remember permutation sign
271 for (unsigned j=0; j<3; j++)
272 v[j] = ex_to_numeric(ex_to_idx(i.op(j + 1)).get_value()).to_int();
274 if (v[0] > v[1]) { std::swap(v[0], v[1]); sign = -sign; }
275 if (v[0] > v[2]) { std::swap(v[0], v[2]); sign = -sign; }
276 if (v[1] > v[2]) { std::swap(v[1], v[2]); sign = -sign; }
278 // Check for non-zero elements
279 if (CMPINDICES(1,2,3))
281 else if (CMPINDICES(1,4,7) || CMPINDICES(2,4,6)
282 || CMPINDICES(2,5,7) || CMPINDICES(3,4,5))
283 return _ex1_2() * sign;
284 else if (CMPINDICES(1,5,6) || CMPINDICES(3,6,7))
285 return _ex_1_2() * sign;
286 else if (CMPINDICES(4,5,8) || CMPINDICES(6,7,8))
287 return sqrt(_ex3())/2 * sign;
292 // No further simplifications
297 /** Contraction of an indexed symmetric structure constant with something else. */
298 bool su3d::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const
300 GINAC_ASSERT(is_ex_of_type(*self, indexed));
301 GINAC_ASSERT(is_ex_of_type(*other, indexed));
302 GINAC_ASSERT(self->nops() == 4);
303 GINAC_ASSERT(is_ex_of_type(self->op(0), su3d));
305 if (is_ex_exactly_of_type(other->op(0), su3d)) {
307 // Find the dummy indices of the contraction
308 exvector dummy_indices;
309 dummy_indices = ex_to_indexed(*self).get_dummy_indices(ex_to_indexed(*other));
312 if (dummy_indices.size() == 3) {
313 *self = numeric(40, 3);
317 // d.akl*d.bkl=5/3*delta.ab
318 } else if (dummy_indices.size() == 2) {
319 exvector a = index_set_difference(ex_to_indexed(*self).get_indices(), dummy_indices);
320 exvector b = index_set_difference(ex_to_indexed(*other).get_indices(), dummy_indices);
321 GINAC_ASSERT(a.size() > 0);
322 GINAC_ASSERT(b.size() > 0);
323 *self = numeric(5, 3) * delta_tensor(a[0], b[0]);
332 /** Contraction of an indexed antisymmetric structure constant with something else. */
333 bool su3f::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const
335 GINAC_ASSERT(is_ex_of_type(*self, indexed));
336 GINAC_ASSERT(is_ex_of_type(*other, indexed));
337 GINAC_ASSERT(self->nops() == 4);
338 GINAC_ASSERT(is_ex_of_type(self->op(0), su3f));
340 if (is_ex_exactly_of_type(other->op(0), su3f)) { // f*d is handled by su3d class
342 // Find the dummy indices of the contraction
343 exvector dummy_indices;
344 dummy_indices = ex_to_indexed(*self).get_dummy_indices(ex_to_indexed(*other));
347 if (dummy_indices.size() == 3) {
352 // f.akl*f.bkl=3*delta.ab
353 } else if (dummy_indices.size() == 2) {
355 ex a = permute_free_index_to_front(ex_to_indexed(*self).get_indices(), dummy_indices, sign1);
356 ex b = permute_free_index_to_front(ex_to_indexed(*other).get_indices(), dummy_indices, sign2);
357 *self = sign1 * sign2 * 3 * delta_tensor(a, b);
370 ex color_ONE(unsigned rl)
372 return color(su3one(), rl);
375 ex color_T(const ex & a, unsigned rl)
377 if (!is_ex_of_type(a, idx))
378 throw(std::invalid_argument("indices of color_T must be of type idx"));
379 if (!ex_to_idx(a).get_dim().is_equal(8))
380 throw(std::invalid_argument("index dimension for color_T must be 8"));
382 return color(su3t(), a, rl);
385 ex color_f(const ex & a, const ex & b, const ex & c)
387 if (!is_ex_of_type(a, idx) || !is_ex_of_type(b, idx) || !is_ex_of_type(c, idx))
388 throw(std::invalid_argument("indices of color_f must be of type idx"));
389 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))
390 throw(std::invalid_argument("index dimension for color_f must be 8"));
392 return indexed(su3f(), indexed::antisymmetric, a, b, c);
395 ex color_d(const ex & a, const ex & b, const ex & c)
397 if (!is_ex_of_type(a, idx) || !is_ex_of_type(b, idx) || !is_ex_of_type(c, idx))
398 throw(std::invalid_argument("indices of color_d must be of type idx"));
399 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))
400 throw(std::invalid_argument("index dimension for color_d must be 8"));
402 return indexed(su3d(), indexed::symmetric, a, b, c);
405 ex color_h(const ex & a, const ex & b, const ex & c)
407 return color_d(a, b, c) + I * color_f(a, b, c);