]> www.ginac.de Git - ginac.git/blob - ginac/color.h
* ginac/registrar.h: dtor is inlined now.
[ginac.git] / ginac / color.h
1 /** @file color.h
2  *
3  *  Interface to GiNaC's color objects. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
7  *
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.
12  *
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.
17  *
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
21  */
22
23 #ifndef __GINAC_COLOR_H__
24 #define __GINAC_COLOR_H__
25
26 #include <string>
27 #include <vector>
28 #include "indexed.h"
29 #include "ex.h"
30
31 namespace GiNaC {
32
33 const unsigned MAX_REPRESENTATION_LABELS = 4;
34 const unsigned COLOR_EIGHT = 8; // N*N-1
35 const unsigned COLOR_THREE = 3; // N
36
37 // Cint doesn't like vector<..,default_alloc> but malloc_alloc is
38 // unstandardized and not supported by newer GCCs.
39 #if defined(__GNUC__) && ((__GNUC__ == 2) && (__GNUC_MINOR__ < 97))
40 typedef std::vector<exvector,malloc_alloc> exvectorvector;
41 #else
42 typedef std::vector<exvector> exvectorvector;
43 #endif
44
45
46 /** This class holds an object carrying color indices (of class coloridx). 
47  *  It can represent the generators T_a and structure constants f_abc/d_abc
48  *  of SU(3), the unity element ONE of the Lie algebra of SU(3), or the
49  *  unity matrix delta8. Together, these objects are used to implement the
50  *  Lie algebra su(3), as required for calculations in quantum
51  *  chromodynamics. A representation label (an unsigned integer) is used to
52  *  distinguish elements from different Lie algebras (only objects with the
53  *  same representation label "interact" with each other). */
54 class color : public indexed
55 {
56         GINAC_DECLARE_REGISTERED_CLASS(color, indexed)
57
58 // friends
59
60         friend color color_ONE(unsigned rl);
61         friend color color_T(const ex & a, unsigned rl);
62         friend color color_f(const ex & a, const ex & b, const ex & c);
63         friend color color_d(const ex & a, const ex & b, const ex & c);
64         friend ex color_h(const ex & a, const ex & b, const ex & c);
65         friend color color_delta8(const ex & a, const ex & b);
66         friend unsigned subs_index_in_exvector(exvector & v, const ex & is, const ex & ir);
67         friend void split_color_string_in_parts(const exvector & v, exvector & delta8vec,
68                                                 exvector & fvec, exvector & dvec,
69                                                 exvectorvector & Tvecs,
70                                                 exvectorvector & ONEvecs,
71                                                 exvector & unknownvec);
72         friend exvector recombine_color_string(exvector & delta8vec, exvector & fvec,
73                                                exvector & dvec, exvectorvector & Tvecs,
74                                                exvectorvector & ONEvecs, exvector & unknownvec);
75         friend ex color_trace_of_one_representation_label(const exvector & v);
76         friend ex color_trace(const exvector & v, unsigned rl);
77         friend ex simplify_pure_color_string(const ex & e);
78         friend ex simplify_color(const ex & e);
79
80 // types
81
82 public:
83         /** Type of object */
84         typedef enum {
85                 invalid,      /**< not properly constructed */
86                 color_T,      /**< one of the generators T_a of SU(3) (these are non-commutative) */
87                 color_f,      /**< one of the antisymmetric structure constants f_abc of SU(3) */
88                 color_d,      /**< one of the symmetric structure constants d_abc of SU(3) */
89                 color_delta8, /**< the unity matrix */
90                 color_ONE     /**< the unity element of su(3) */
91         } color_types;
92         
93 // member functions
94
95         // other constructors
96 protected:
97         color(color_types const t, unsigned rl=0);
98         color(color_types const t, const ex & i1, unsigned rl=0);
99         color(color_types const t, const ex & i1, const ex & i2, unsigned rl=0);
100         color(color_types const t, const ex & i1, const ex & i2, const ex & i3,
101               unsigned rl=0);
102         color(color_types const t, const exvector & iv, unsigned rl=0);
103         color(color_types const t, exvector * ivp, unsigned rl=0);
104         
105         // functions overriding virtual functions from base classes
106 public:
107         void printraw(std::ostream & os) const;
108         void printtree(std::ostream & os, unsigned indent) const;
109         void print(std::ostream & os, unsigned upper_precedence=0) const;
110         bool info(unsigned inf) const;
111         ex eval(int level=0) const;
112 protected:
113         bool is_equal_same_type(const basic & other) const;
114         ex simplify_ncmul(const exvector & v) const;
115         ex thisexprseq(const exvector & v) const;
116         ex thisexprseq(exvector * vp) const;
117
118         // new virtual functions which can be overridden by derived classes
119         // none
120         
121         // non-virtual functions in this class
122 protected:
123         bool all_of_type_coloridx(void) const;
124         
125 // member variables
126
127 protected:
128         color_types type; /**< Type of object (generator, structure constant etc.) */
129         unsigned representation_label; /**< Representation label to distiguish independent color matrices coming from separated fermion lines */
130 };
131
132 // global functions
133 inline const color &ex_to_color(const ex &e)
134 {
135         return static_cast<const color &>(*e.bp);
136 }
137
138 inline color &ex_to_nonconst_color(const ex &e)
139 {
140         return static_cast<color &>(*e.bp);
141 }
142
143 color color_ONE(unsigned rl=0);
144 color color_T(const ex & a, unsigned rl=0);
145 color color_f(const ex & a, const ex & b, const ex & c);
146 color color_d(const ex & a, const ex & b, const ex & c);
147 ex color_h(const ex & a, const ex & b, const ex & c);
148 color color_delta8(const ex & a, const ex & b);
149 void split_color_string_in_parts(const exvector & v, exvector & delta8vec,
150                                  exvector & fvec, exvector & dvec,
151                                  exvectorvector & Tvecs,
152                                  exvectorvector & ONEvecs,
153                                  exvector & unknownvec);
154 exvector recombine_color_string(exvector & delta8vec, exvector & fvec,
155                                 exvector & dvec, exvectorvector & Tvecs,
156                                 exvectorvector & ONEvecs, exvector & unknownvec);
157 ex color_trace_of_one_representation_label(const exvector & v);
158 ex color_trace(const exvector & v, unsigned rl=0);
159 ex simplify_pure_color_string(const ex & e);
160 ex simplify_color(const ex & e);
161
162 ex brute_force_sum_color_indices(const ex & e);
163
164 } // namespace GiNaC
165
166 #endif // ndef __GINAC_COLOR_H__