]> www.ginac.de Git - ginac.git/blob - ginac/simp_lor.h
the destructor, copy constructor, and assignment operator (which were the
[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         GINAC_DECLARE_REGISTERED_CLASS(simp_lor, indexed)
74
75 // friends
76
77         friend class scalar_products;
78         friend simp_lor lor_g(const ex & mu, const ex & nu);
79         friend simp_lor lor_vec(const std::string & n, const ex & mu);
80         friend ex simplify_simp_lor_mul(const ex & m, const scalar_products & sp);
81         friend ex simplify_simp_lor(const ex & e, const scalar_products & sp);
82         
83 // types
84
85 public:
86         typedef enum {
87                 invalid, // not properly constructed by one of the friend functions
88                 simp_lor_g,
89                 simp_lor_vec
90         } simp_lor_types;
91         
92         // other constructors
93 protected:
94         simp_lor(simp_lor_types const t);
95         simp_lor(simp_lor_types const t, const ex & i1, const ex & i2);
96         simp_lor(simp_lor_types const t, const std::string & n, const ex & i1);
97         simp_lor(simp_lor_types const t, const std::string & n, const exvector & iv);
98         simp_lor(simp_lor_types const t, const std::string & n, exvector * ivp);
99         
100         // functions overriding virtual functions from base classes
101 public:
102         basic * duplicate() const;
103         void printraw(std::ostream & os) const;
104         void printtree(std::ostream & os, unsigned indent) const;
105         void print(std::ostream & os, unsigned upper_precedence=0) const;
106         void printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence=0) const;
107         bool info(unsigned inf) const;
108         ex eval(int level=0) const;
109 protected:
110         int compare_same_type(const basic & other) const;
111         bool is_equal_same_type(const basic & other) const;
112         unsigned return_type(void) const;
113         unsigned return_type_tinfo(void) const;
114         ex thisexprseq(const exvector & v) const;
115         ex thisexprseq(exvector * vp) const;
116
117         // new virtual functions which can be overridden by derived classes
118         // none
119         
120         // non-virtual functions in this class
121 protected:
122         bool all_of_type_lorentzidx(void) const;
123         
124 // member variables
125
126 protected:
127         simp_lor_types type;
128         std::string name;
129 };
130
131 // utility functions
132 inline const simp_lor &ex_to_simp_lor(const ex &e)
133 {
134         return static_cast<const simp_lor &>(*e.bp);
135 }
136
137 inline simp_lor &ex_to_nonconst_simp_lor(const ex &e)
138 {
139         return static_cast<simp_lor &>(*e.bp);
140 }
141
142 simp_lor lor_g(const ex & mu, const ex & nu);
143 simp_lor lor_vec(const std::string & n, const ex & mu);
144 ex simplify_simp_lor_mul(const ex & m, const scalar_products & sp);
145 ex simplify_simp_lor(const ex & e, const scalar_products & sp=scalar_products());
146
147 #ifndef NO_NAMESPACE_GINAC
148 } // namespace GiNaC
149 #endif // ndef NO_NAMESPACE_GINAC
150
151 #endif // ndef _SIMP__GINAC_LOR_H__