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