]> www.ginac.de Git - ginac.git/blob - ginac/color.h
container.pl: can now generate constructors for an arbitary number
[ginac.git] / ginac / color.h
1 /** @file color.h
2  *
3  *  Interface to GiNaC's color objects. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2000 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 typedef vector<exvector,malloc_alloc> exvectorvector;
40
41 /** Base class for color object */
42 class color : public indexed
43 {
44     GINAC_DECLARE_REGISTERED_CLASS(color, indexed)
45
46 // friends
47
48     friend color color_ONE(unsigned rl);
49     friend color color_T(const ex & a, unsigned rl);
50     friend color color_f(const ex & a, const ex & b, const ex & c);
51     friend color color_d(const ex & a, const ex & b, const ex & c);
52     friend ex color_h(const ex & a, const ex & b, const ex & c);
53     friend color color_delta8(const ex & a, const ex & b);
54     friend unsigned subs_index_in_exvector(exvector & v, const ex & is, const ex & ir);
55     friend void split_color_string_in_parts(const exvector & v, exvector & delta8vec,
56                                             exvector & fvec, exvector & dvec,
57                                             exvectorvector & Tvecs,
58                                             exvectorvector & ONEvecs,
59                                             exvector & unknownvec);
60     friend exvector recombine_color_string(exvector & delta8vec, exvector & fvec,
61                                            exvector & dvec, exvectorvector & Tvecs,
62                                            exvectorvector & ONEvecs, exvector & unknownvec);
63     friend ex color_trace_of_one_representation_label(const exvector & v);
64     friend ex color_trace(const exvector & v, unsigned rl);
65     friend ex simplify_pure_color_string(const ex & e);
66     friend ex simplify_color(const ex & e);
67
68     
69 // types
70
71 public:
72     typedef enum { invalid, // not properly constructed by one of the friend functions
73                    color_T,
74                    color_f,
75                    color_d,
76                    color_delta8,
77                    color_ONE
78     } color_types;
79     
80 // member functions
81
82     // default constructor, destructor, copy constructor assignment operator and helpers
83 public:
84     color();
85     ~color();
86     color(const color & other);
87     const color & operator=(const color & other);
88 protected:
89     void copy(const color & other); 
90     void destroy(bool call_parent);
91
92     // other constructors
93 protected:
94     color(color_types const t, unsigned rl=0);
95     color(color_types const t, const ex & i1, unsigned rl=0);
96     color(color_types const t, const ex & i1, const ex & i2, unsigned rl=0);
97     color(color_types const t, const ex & i1, const ex & i2, const ex & i3,
98           unsigned rl=0);
99     color(color_types const t, const exvector & iv, unsigned rl=0);
100     color(color_types const t, exvector * ivp, unsigned rl=0);
101     
102     // functions overriding virtual functions from base classes
103 public:
104     basic * duplicate() const;
105     void printraw(ostream & os) const;
106     void printtree(ostream & os, unsigned indent) const;
107     void print(ostream & os, unsigned upper_precedence=0) const;
108     void printcsrc(ostream & os, unsigned type, unsigned upper_precedence=0) const;
109     bool info(unsigned inf) const;
110     ex eval(int level=0) const;
111 protected:
112     int compare_same_type(const basic & other) const;
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;
129     unsigned representation_label; // to distiguish independent color matrices coming from separated fermion lines
130 };
131
132 // global constants
133
134 extern const color some_color;
135 extern const type_info & typeid_color;
136
137 // global functions
138 inline const color &ex_to_color(const ex &e)
139 {
140         return static_cast<const color &>(*e.bp);
141 }
142
143 inline color &ex_to_nonconst_color(const ex &e)
144 {
145         return static_cast<color &>(*e.bp);
146 }
147
148 color color_ONE(unsigned rl=0);
149 color color_T(const ex & a, unsigned rl=0);
150 color color_f(const ex & a, const ex & b, const ex & c);
151 color color_d(const ex & a, const ex & b, const ex & c);
152 ex color_h(const ex & a, const ex & b, const ex & c);
153 color color_delta8(const ex & a, const ex & b);
154 void split_color_string_in_parts(const exvector & v, exvector & delta8vec,
155                                  exvector & fvec, exvector & dvec,
156                                  exvectorvector & Tvecs,
157                                  exvectorvector & ONEvecs,
158                                  exvector & unknownvec);
159 exvector recombine_color_string(exvector & delta8vec, exvector & fvec,
160                                 exvector & dvec, exvectorvector & Tvecs,
161                                 exvectorvector & ONEvecs, exvector & unknownvec);
162 ex color_trace_of_one_representation_label(const exvector & v);
163 ex color_trace(const exvector & v, unsigned rl=0);
164 ex simplify_pure_color_string(const ex & e);
165 ex simplify_color(const ex & e);
166
167 ex brute_force_sum_color_indices(const ex & e);
168
169 void append_exvector_to_exvector(exvector & dest, const exvector & source);
170
171 #ifndef NO_NAMESPACE_GINAC
172 } // namespace GiNaC
173 #endif // ndef NO_NAMESPACE_GINAC
174
175 #endif // ndef __GINAC_COLOR_H__