]> www.ginac.de Git - ginac.git/blob - ginac/color.h
normal() applied to a power expression also normalizes the exponent
[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 /** Base class for color object */
48 class color : public indexed
49 {
50         GINAC_DECLARE_REGISTERED_CLASS(color, indexed)
51
52 // friends
53
54         friend color color_ONE(unsigned rl);
55         friend color color_T(const ex & a, unsigned rl);
56         friend color color_f(const ex & a, const ex & b, const ex & c);
57         friend color color_d(const ex & a, const ex & b, const ex & c);
58         friend ex color_h(const ex & a, const ex & b, const ex & c);
59         friend color color_delta8(const ex & a, const ex & b);
60         friend unsigned subs_index_in_exvector(exvector & v, const ex & is, const ex & ir);
61         friend void split_color_string_in_parts(const exvector & v, exvector & delta8vec,
62                                                 exvector & fvec, exvector & dvec,
63                                                 exvectorvector & Tvecs,
64                                                 exvectorvector & ONEvecs,
65                                                 exvector & unknownvec);
66         friend exvector recombine_color_string(exvector & delta8vec, exvector & fvec,
67                                                exvector & dvec, exvectorvector & Tvecs,
68                                                exvectorvector & ONEvecs, exvector & unknownvec);
69         friend ex color_trace_of_one_representation_label(const exvector & v);
70         friend ex color_trace(const exvector & v, unsigned rl);
71         friend ex simplify_pure_color_string(const ex & e);
72         friend ex simplify_color(const ex & e);
73
74         
75 // types
76
77 public:
78         typedef enum {
79                 invalid,        // not properly constructed by one of the friend functions
80                 color_T,
81                 color_f,
82                 color_d,
83                 color_delta8,
84                 color_ONE
85         } color_types;
86         
87 // member functions
88
89         // default constructor, destructor, copy constructor assignment operator and helpers
90 public:
91         color();
92         ~color();
93         color(const color & other);
94         const color & operator=(const color & other);
95 protected:
96         void copy(const color & other); 
97         void destroy(bool call_parent);
98
99         // other constructors
100 protected:
101         color(color_types const t, unsigned rl=0);
102         color(color_types const t, const ex & i1, unsigned rl=0);
103         color(color_types const t, const ex & i1, const ex & i2, unsigned rl=0);
104         color(color_types const t, const ex & i1, const ex & i2, const ex & i3,
105               unsigned rl=0);
106         color(color_types const t, const exvector & iv, unsigned rl=0);
107         color(color_types const t, exvector * ivp, unsigned rl=0);
108         
109         // functions overriding virtual functions from base classes
110 public:
111         basic * duplicate() const;
112         void printraw(std::ostream & os) const;
113         void printtree(std::ostream & os, unsigned indent) const;
114         void print(std::ostream & os, unsigned upper_precedence=0) const;
115         void printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence=0) const;
116         bool info(unsigned inf) const;
117         ex eval(int level=0) const;
118 protected:
119         int compare_same_type(const basic & other) const;
120         bool is_equal_same_type(const basic & other) const;
121         ex simplify_ncmul(const exvector & v) const;
122         ex thisexprseq(const exvector & v) const;
123         ex thisexprseq(exvector * vp) const;
124
125         // new virtual functions which can be overridden by derived classes
126         // none
127         
128         // non-virtual functions in this class
129 protected:
130         bool all_of_type_coloridx(void) const;
131         
132 // member variables
133
134 protected:
135         color_types type;
136         unsigned representation_label; // to distiguish independent color matrices coming from separated fermion lines
137 };
138
139 // global constants
140
141 extern const color some_color;
142 extern const std::type_info & typeid_color;
143
144 // global functions
145 inline const color &ex_to_color(const ex &e)
146 {
147         return static_cast<const color &>(*e.bp);
148 }
149
150 inline color &ex_to_nonconst_color(const ex &e)
151 {
152         return static_cast<color &>(*e.bp);
153 }
154
155 color color_ONE(unsigned rl=0);
156 color color_T(const ex & a, unsigned rl=0);
157 color color_f(const ex & a, const ex & b, const ex & c);
158 color color_d(const ex & a, const ex & b, const ex & c);
159 ex color_h(const ex & a, const ex & b, const ex & c);
160 color color_delta8(const ex & a, const ex & b);
161 void split_color_string_in_parts(const exvector & v, exvector & delta8vec,
162                                  exvector & fvec, exvector & dvec,
163                                  exvectorvector & Tvecs,
164                                  exvectorvector & ONEvecs,
165                                  exvector & unknownvec);
166 exvector recombine_color_string(exvector & delta8vec, exvector & fvec,
167                                 exvector & dvec, exvectorvector & Tvecs,
168                                 exvectorvector & ONEvecs, exvector & unknownvec);
169 ex color_trace_of_one_representation_label(const exvector & v);
170 ex color_trace(const exvector & v, unsigned rl=0);
171 ex simplify_pure_color_string(const ex & e);
172 ex simplify_color(const ex & e);
173
174 ex brute_force_sum_color_indices(const ex & e);
175
176 void append_exvector_to_exvector(exvector & dest, const exvector & source);
177
178 #ifndef NO_NAMESPACE_GINAC
179 } // namespace GiNaC
180 #endif // ndef NO_NAMESPACE_GINAC
181
182 #endif // ndef __GINAC_COLOR_H__