]> www.ginac.de Git - ginac.git/blob - ginac/simp_lor.h
- enforced GiNaC coding standards :-)
[ginac.git] / ginac / simp_lor.h
1 /** @file simp_lor.h
2  *
3  *  Interface to GiNaC's simp_lor objects.
4  *
5  *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #ifndef _SIMP__GINAC_LOR_H__
23 #define _SIMP__GINAC_LOR_H__
24
25 #include <string>
26 #include <vector>
27 #include <utility>
28 #include <map>
29 #include <iostream>
30
31 typedef pair<string,string> strstrpair;
32 typedef pair<strstrpair,lorentzidx> spmapkey;
33
34 class spmapkey_is_less
35 {
36 public:
37     bool operator()(spmapkey const & lh, spmapkey const & rh) const
38     {
39         /*
40         cerr << "spmapkey_is_less" << endl;
41         cerr << "lh=((" << lh.first.first
42              << "," << lh.first.second << "),";
43         lh.second.printraw(cerr);
44         cerr << ")" << endl;
45
46         cerr << "rh=((" << rh.first.first
47              << "," << rh.first.second << "),";
48         rh.second.printraw(cerr);
49         cerr << ")" << endl;
50         */
51         bool res=lh.first<rh.first ||
52             (!(rh.first<lh.first) && lh.second.compare(rh.second)<0 );
53         // cout << "result=" << res << endl;
54         return res;
55     }
56 };
57
58 typedef map<spmapkey,ex,spmapkey_is_less> spmap;
59
60 class simp_lor;
61
62 /** helper class for scalar products */
63 class scalar_products
64 {
65 public:
66     void reg(simp_lor const & v1, simp_lor const & v2, ex const & sp);
67     bool is_defined(simp_lor const & v1, simp_lor const & v2) const;
68     ex evaluate(simp_lor const & v1, simp_lor const & v2) const;
69     void debugprint(void) const;
70 protected:
71     static spmapkey make_key(simp_lor const & v1, simp_lor const & v2);
72 protected:
73     spmap spm;
74 };
75
76 /** Base class for simp_lor object */
77 class simp_lor : public indexed
78 {
79 // friends
80
81     friend class scalar_products;
82     friend simp_lor lor_g(ex const & mu, ex const & nu);
83     friend simp_lor lor_vec(string const & n, ex const & mu);
84     friend ex simplify_simp_lor_mul(ex const & m, scalar_products const & sp);
85     friend ex simplify_simp_lor(ex const & e, scalar_products const & sp);
86     
87 // types
88
89 public:
90     typedef enum { invalid, // not properly constructed by one of the friend functions
91                    simp_lor_g,
92                    simp_lor_vec
93     } simp_lor_types;
94     
95 // member functions
96
97     // default constructor, destructor, copy constructor assignment operator and helpers
98 public:
99     simp_lor();
100     ~simp_lor();
101     simp_lor(simp_lor const & other);
102     simp_lor const & operator=(simp_lor const & other);
103 protected:
104     void copy(simp_lor const & other); 
105     void destroy(bool call_parent);
106
107     // other constructors
108 protected:
109     simp_lor(simp_lor_types const t);
110     simp_lor(simp_lor_types const t, ex const & i1, ex const & i2);
111     simp_lor(simp_lor_types const t, string const & n, ex const & i1);
112     simp_lor(simp_lor_types const t, string const & n, exvector const & iv);
113     simp_lor(simp_lor_types const t, string const & n, exvector * ivp);
114     
115     // functions overriding virtual functions from base classes
116 public:
117     basic * duplicate() const;
118     void printraw(ostream & os) const;
119     void printtree(ostream & os, unsigned indent) const;
120     void print(ostream & os, unsigned upper_precedence=0) const;
121     void printcsrc(ostream & os, unsigned type, unsigned upper_precedence=0) const;
122     bool info(unsigned inf) const;
123     ex eval(int level=0) const;
124 protected:
125     int compare_same_type(basic const & other) const;
126     bool is_equal_same_type(basic const & other) const;
127     unsigned return_type(void) const;
128     unsigned return_type_tinfo(void) const;
129     ex thisexprseq(exvector const & v) const;
130     ex thisexprseq(exvector * vp) const;
131
132     // new virtual functions which can be overridden by derived classes
133     // none
134     
135     // non-virtual functions in this class
136 protected:
137     bool all_of_type_lorentzidx(void) const;
138     
139 // member variables
140
141 protected:
142     simp_lor_types type;
143     string name;
144 };
145
146 // global constants
147
148 extern const simp_lor some_simp_lor;
149 extern type_info const & typeid_simp_lor;
150
151 // macros
152
153 #define ex_to_simp_lor(X) static_cast<simp_lor const &>(*(X).bp)
154 #define ex_to_nonconst_simp_lor(X) static_cast<simp_lor &>(*(X).bp)
155
156 simp_lor lor_g(ex const & mu, ex const & nu);
157 simp_lor lor_vec(string const & n, ex const & mu);
158 ex simplify_simp_lor_mul(ex const & m, scalar_products const & sp);
159 ex simplify_simp_lor(ex const & e, scalar_products const & sp);
160 ex Dim(void);
161
162 #endif // ndef _SIMP__GINAC_LOR_H__
163
164