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