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