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