]> www.ginac.de Git - ginac.git/blob - ginac/color.h
- enforced GiNaC coding standards :-)
[ginac.git] / ginac / color.h
1 /** @file color.h
2  *
3  *  Interface to GiNaC's color objects.
4  *
5  *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #ifndef __GINAC_COLOR_H__
23 #define __GINAC_COLOR_H__
24
25 #include <string>
26 #include <vector>
27
28 #define MAX_REPRESENTATION_LABELS 4
29 #define COLOR_EIGHT 8 // N*N-1
30 #define COLOR_THREE 3 // N
31
32 /** Base class for color object */
33 class color : public indexed
34 {
35 // friends
36
37     friend color color_ONE(unsigned const rl);
38     friend color color_T(ex const & a, unsigned const rl);
39     friend color color_f(ex const & a, ex const & b, ex const & c);
40     friend color color_d(ex const & a, ex const & b, ex const & c);
41     friend ex color_h(ex const & a, ex const & b, ex const & c);
42     friend color color_delta8(ex const & a, ex const & b);
43     friend unsigned subs_index_in_exvector(exvector & v, ex const & is, ex const & ir);
44     friend void split_color_string_in_parts(exvector const & v, exvector & delta8vec,
45                                             exvector & fvec, exvector & dvec,
46                                             vector<exvector> & Tvecs,
47                                             vector<exvector> & ONEvecs,
48                                             exvector & unknownvec);
49     friend exvector recombine_color_string(exvector & delta8vec, exvector & fvec,
50                                            exvector & dvec, vector<exvector> & Tvecs,
51                                            vector<exvector> & ONEvecs, exvector & unknownvec);
52     friend ex color_trace_of_one_representation_label(exvector const & v);
53     friend ex color_trace(exvector const & v, unsigned const rl);
54     friend ex simplify_pure_color_string(ex const & e);
55     friend ex simplify_color(ex const & e);
56
57     
58 // types
59
60 public:
61     typedef enum { invalid, // not properly constructed by one of the friend functions
62                    color_T,
63                    color_f,
64                    color_d,
65                    color_delta8,
66                    color_ONE
67     } color_types;
68     
69 // member functions
70
71     // default constructor, destructor, copy constructor assignment operator and helpers
72 public:
73     color();
74     ~color();
75     color(color const & other);
76     color const & operator=(color const & other);
77 protected:
78     void copy(color const & other); 
79     void destroy(bool call_parent);
80
81     // other constructors
82 protected:
83     color(color_types const t, unsigned const rl=0);
84     color(color_types const t, ex const & i1, unsigned const rl=0);
85     color(color_types const t, ex const & i1, ex const & i2, unsigned const rl=0);
86     color(color_types const t, ex const & i1, ex const & i2, ex const & i3,
87           unsigned const rl=0);
88     color(color_types const t, exvector const & iv, unsigned const rl=0);
89     color(color_types const t, exvector * ivp, unsigned const rl=0);
90     
91     // functions overriding virtual functions from base classes
92 public:
93     basic * duplicate() const;
94     void printraw(ostream & os) const;
95     void printtree(ostream & os, unsigned indent) const;
96     void print(ostream & os, unsigned upper_precedence=0) const;
97     void printcsrc(ostream & os, unsigned type, unsigned upper_precedence=0) const;
98     bool info(unsigned inf) const;
99     ex eval(int level=0) const;
100 protected:
101     int compare_same_type(basic const & other) const;
102     bool is_equal_same_type(basic const & other) const;
103     ex simplify_ncmul(exvector const & v) const;
104     ex thisexprseq(exvector const & v) const;
105     ex thisexprseq(exvector * vp) const;
106
107     // new virtual functions which can be overridden by derived classes
108     // none
109     
110     // non-virtual functions in this class
111 protected:
112     bool all_of_type_coloridx(void) const;
113     
114 // member variables
115
116 protected:
117     color_types type;
118     unsigned representation_label; // to distiguish independent color matrices coming from separated fermion lines
119 };
120
121 // global constants
122
123 extern const color some_color;
124 extern type_info const & typeid_color;
125
126 // macros
127
128 #define ex_to_color(X) static_cast<color const &>(*(X).bp)
129 #define ex_to_nonconst_color(X) static_cast<color &>(*(X).bp)
130
131 color color_ONE(unsigned const rl=0);
132 color color_T(ex const & a, unsigned const rl=0);
133 color color_f(ex const & a, ex const & b, ex const & c);
134 color color_d(ex const & a, ex const & b, ex const & c);
135 ex color_h(ex const & a, ex const & b, ex const & c);
136 color color_delta8(ex const & a, ex const & b);
137 void split_color_string_in_parts(exvector const & v, exvector & delta8vec,
138                                  exvector & fvec, exvector & dvec,
139                                  vector<exvector> & Tvecs,
140                                  vector<exvector> & ONEvecs,
141                                  exvector & unknownvec);
142 exvector recombine_color_string(exvector & delta8vec, exvector & fvec,
143                                 exvector & dvec, vector<exvector> & Tvecs,
144                                 vector<exvector> & ONEvecs, exvector & unknownvec);
145 ex color_trace_of_one_representation_label(exvector const & v);
146 ex color_trace(exvector const & v, unsigned const rl=0);
147 ex simplify_pure_color_string(ex const & e);
148 ex simplify_color(ex const & e);
149
150 ex brute_force_sum_color_indices(ex const & e);
151
152 void append_exvector_to_exvector(exvector & dest, exvector const & source);
153
154 #endif // ndef __GINAC_COLOR_H__
155
156