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