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