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