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