]> www.ginac.de Git - ginac.git/blob - ginac/color.h
877e7de5f9cf2f1fb8490bf4eb9c73262791021e
[ginac.git] / ginac / color.h
1 /** @file color.h
2  *
3  *  Interface to GiNaC's color objects. */
4
5 /*
6  *  GiNaC Copyright (C) 1999 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 <ginac/indexed.h>
29
30 #define MAX_REPRESENTATION_LABELS 4
31 #define COLOR_EIGHT 8 // N*N-1
32 #define COLOR_THREE 3 // N
33
34 /** Base class for color object */
35 class color : public indexed
36 {
37 // friends
38
39     friend color color_ONE(unsigned const rl);
40     friend color color_T(ex const & a, unsigned const rl);
41     friend color color_f(ex const & a, ex const & b, ex const & c);
42     friend color color_d(ex const & a, ex const & b, ex const & c);
43     friend ex color_h(ex const & a, ex const & b, ex const & c);
44     friend color color_delta8(ex const & a, ex const & b);
45     friend unsigned subs_index_in_exvector(exvector & v, ex const & is, ex const & ir);
46     friend void split_color_string_in_parts(exvector const & v, exvector & delta8vec,
47                                             exvector & fvec, exvector & dvec,
48                                             vector<exvector> & Tvecs,
49                                             vector<exvector> & ONEvecs,
50                                             exvector & unknownvec);
51     friend exvector recombine_color_string(exvector & delta8vec, exvector & fvec,
52                                            exvector & dvec, vector<exvector> & Tvecs,
53                                            vector<exvector> & ONEvecs, exvector & unknownvec);
54     friend ex color_trace_of_one_representation_label(exvector const & v);
55     friend ex color_trace(exvector const & v, unsigned const rl);
56     friend ex simplify_pure_color_string(ex const & e);
57     friend ex simplify_color(ex const & e);
58
59     
60 // types
61
62 public:
63     typedef enum { invalid, // not properly constructed by one of the friend functions
64                    color_T,
65                    color_f,
66                    color_d,
67                    color_delta8,
68                    color_ONE
69     } color_types;
70     
71 // member functions
72
73     // default constructor, destructor, copy constructor assignment operator and helpers
74 public:
75     color();
76     ~color();
77     color(color const & other);
78     color const & operator=(color const & other);
79 protected:
80     void copy(color const & other); 
81     void destroy(bool call_parent);
82
83     // other constructors
84 protected:
85     color(color_types const t, unsigned const rl=0);
86     color(color_types const t, ex const & i1, unsigned const rl=0);
87     color(color_types const t, ex const & i1, ex const & i2, unsigned const rl=0);
88     color(color_types const t, ex const & i1, ex const & i2, ex const & i3,
89           unsigned const rl=0);
90     color(color_types const t, exvector const & iv, unsigned const rl=0);
91     color(color_types const t, exvector * ivp, unsigned const rl=0);
92     
93     // functions overriding virtual functions from base classes
94 public:
95     basic * duplicate() const;
96     void printraw(ostream & os) const;
97     void printtree(ostream & os, unsigned indent) const;
98     void print(ostream & os, unsigned upper_precedence=0) const;
99     void printcsrc(ostream & os, unsigned type, unsigned upper_precedence=0) const;
100     bool info(unsigned inf) const;
101     ex eval(int level=0) const;
102 protected:
103     int compare_same_type(basic const & other) const;
104     bool is_equal_same_type(basic const & other) const;
105     ex simplify_ncmul(exvector const & v) const;
106     ex thisexprseq(exvector const & v) const;
107     ex thisexprseq(exvector * vp) const;
108
109     // new virtual functions which can be overridden by derived classes
110     // none
111     
112     // non-virtual functions in this class
113 protected:
114     bool all_of_type_coloridx(void) const;
115     
116 // member variables
117
118 protected:
119     color_types type;
120     unsigned representation_label; // to distiguish independent color matrices coming from separated fermion lines
121 };
122
123 // global constants
124
125 extern const color some_color;
126 extern type_info const & typeid_color;
127
128 // macros
129
130 #define ex_to_color(X) static_cast<color const &>(*(X).bp)
131 #define ex_to_nonconst_color(X) static_cast<color &>(*(X).bp)
132
133 color color_ONE(unsigned const rl=0);
134 color color_T(ex const & a, unsigned const rl=0);
135 color color_f(ex const & a, ex const & b, ex const & c);
136 color color_d(ex const & a, ex const & b, ex const & c);
137 ex color_h(ex const & a, ex const & b, ex const & c);
138 color color_delta8(ex const & a, ex const & b);
139 void split_color_string_in_parts(exvector const & v, exvector & delta8vec,
140                                  exvector & fvec, exvector & dvec,
141                                  vector<exvector> & Tvecs,
142                                  vector<exvector> & ONEvecs,
143                                  exvector & unknownvec);
144 exvector recombine_color_string(exvector & delta8vec, exvector & fvec,
145                                 exvector & dvec, vector<exvector> & Tvecs,
146                                 vector<exvector> & ONEvecs, exvector & unknownvec);
147 ex color_trace_of_one_representation_label(exvector const & v);
148 ex color_trace(exvector const & v, unsigned const rl=0);
149 ex simplify_pure_color_string(ex const & e);
150 ex simplify_color(ex const & e);
151
152 ex brute_force_sum_color_indices(ex const & e);
153
154 void append_exvector_to_exvector(exvector & dest, exvector const & source);
155
156 #endif // ndef __GINAC_COLOR_H__
157
158