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