]> www.ginac.de Git - ginac.git/blob - ginac/simp_lor.h
5aa60d48d950172610d28379a58b118913c89195
[ginac.git] / ginac / simp_lor.h
1 /** @file simp_lor.h
2  *
3  *  Interface to GiNaC's simp_lor objects. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2001 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 _SIMP__GINAC_LOR_H__
24 #define _SIMP__GINAC_LOR_H__
25
26 #include <string>
27 #include <vector>
28 #include <utility>
29 #include <map>
30 #include <iostream>
31 #include "indexed.h"
32 #include "lorentzidx.h"
33
34 #ifndef NO_NAMESPACE_GINAC
35 namespace GiNaC {
36 #endif // ndef NO_NAMESPACE_GINAC
37
38 typedef std::pair<std::string,std::string> strstrpair;
39 typedef std::pair<strstrpair,lorentzidx> spmapkey;
40
41 class spmapkey_is_less
42 {
43 public:
44         bool operator()(const spmapkey & lh, const spmapkey & rh) const
45         {
46                 /*
47                 cerr << "spmapkey_is_less" << endl;
48                 cerr << "lh=((" << lh.first.first
49                          << "," << lh.first.second << "),";
50                 lh.second.printraw(cerr);
51                 cerr << ")" << endl;
52
53                 cerr << "rh=((" << rh.first.first
54                          << "," << rh.first.second << "),";
55                 rh.second.printraw(cerr);
56                 cerr << ")" << endl;
57                 */
58                 bool res = lh.first<rh.first
59                         || (!(rh.first<lh.first) && lh.second.compare(rh.second)<0);
60                 // cout << "result=" << res << endl;
61                 return res;
62         }
63 };
64
65 typedef std::map<spmapkey,ex,spmapkey_is_less> spmap;
66
67 class simp_lor;
68
69 /** helper class for scalar products */
70 class scalar_products
71 {
72 public:
73         void reg(const simp_lor & v1, const simp_lor & v2, const ex & sp);
74         bool is_defined(const simp_lor & v1, const simp_lor & v2) const;
75         ex evaluate(const simp_lor & v1, const simp_lor & v2) const;
76         void debugprint(void) const;
77 protected:
78         static spmapkey make_key(const simp_lor & v1, const simp_lor & v2);
79 protected:
80         spmap spm;
81 };
82
83 /** Base class for simp_lor object */
84 class simp_lor : public indexed
85 {
86 // friends
87
88         friend class scalar_products;
89         friend simp_lor lor_g(const ex & mu, const ex & nu);
90         friend simp_lor lor_vec(const std::string & n, const ex & mu);
91         friend ex simplify_simp_lor_mul(const ex & m, const scalar_products & sp);
92         friend ex simplify_simp_lor(const ex & e, const scalar_products & sp);
93         
94 // types
95
96 public:
97         typedef enum {
98                 invalid, // not properly constructed by one of the friend functions
99                 simp_lor_g,
100                 simp_lor_vec
101         } simp_lor_types;
102         
103 // member functions
104
105         // default constructor, destructor, copy constructor assignment operator and helpers
106 public:
107         simp_lor();
108         ~simp_lor();
109         simp_lor(const simp_lor & other);
110         const simp_lor & operator=(const simp_lor & other);
111 protected:
112         void copy(const simp_lor & other); 
113         void destroy(bool call_parent);
114
115         // other constructors
116 protected:
117         simp_lor(simp_lor_types const t);
118         simp_lor(simp_lor_types const t, const ex & i1, const ex & i2);
119         simp_lor(simp_lor_types const t, const std::string & n, const ex & i1);
120         simp_lor(simp_lor_types const t, const std::string & n, const exvector & iv);
121         simp_lor(simp_lor_types const t, const std::string & n, exvector * ivp);
122         
123         // functions overriding virtual functions from base classes
124 public:
125         basic * duplicate() const;
126         void printraw(std::ostream & os) const;
127         void printtree(std::ostream & os, unsigned indent) const;
128         void print(std::ostream & os, unsigned upper_precedence=0) const;
129         void printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence=0) const;
130         bool info(unsigned inf) const;
131         ex eval(int level=0) const;
132 protected:
133         int compare_same_type(const basic & other) const;
134         bool is_equal_same_type(const basic & other) const;
135         unsigned return_type(void) const;
136         unsigned return_type_tinfo(void) const;
137         ex thisexprseq(const exvector & v) const;
138         ex thisexprseq(exvector * vp) const;
139
140         // new virtual functions which can be overridden by derived classes
141         // none
142         
143         // non-virtual functions in this class
144 protected:
145         bool all_of_type_lorentzidx(void) const;
146         
147 // member variables
148
149 protected:
150         simp_lor_types type;
151         std::string name;
152 };
153
154 // global constants
155
156 extern const simp_lor some_simp_lor;
157 extern const std::type_info & typeid_simp_lor;
158
159 // utility functions
160 inline const simp_lor &ex_to_simp_lor(const ex &e)
161 {
162         return static_cast<const simp_lor &>(*e.bp);
163 }
164
165 inline simp_lor &ex_to_nonconst_simp_lor(const ex &e)
166 {
167         return static_cast<simp_lor &>(*e.bp);
168 }
169
170 simp_lor lor_g(const ex & mu, const ex & nu);
171 simp_lor lor_vec(const std::string & n, const ex & mu);
172 ex simplify_simp_lor_mul(const ex & m, const scalar_products & sp);
173 ex simplify_simp_lor(const ex & e, const scalar_products & sp=scalar_products());
174 ex Dim(void);
175
176 #ifndef NO_NAMESPACE_GINAC
177 } // namespace GiNaC
178 #endif // ndef NO_NAMESPACE_GINAC
179
180 #endif // ndef _SIMP__GINAC_LOR_H__