]> www.ginac.de Git - ginac.git/blob - ginac/simp_lor.h
* ginac/registrar.h: dtor is inlined now.
[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 namespace GiNaC {
35
36 typedef std::pair<std::string,std::string> strstrpair;
37 typedef std::pair<strstrpair,lorentzidx> spmapkey;
38
39 class spmapkey_is_less
40 {
41 public:
42         bool operator()(const spmapkey & lh, const spmapkey & rh) const
43         {
44                 bool res = lh.first<rh.first
45                         || (!(rh.first<lh.first) && lh.second.compare(rh.second)<0);
46                 return res;
47         }
48 };
49
50 typedef std::map<spmapkey,ex,spmapkey_is_less> spmap;
51
52 class simp_lor;
53
54 /** helper class for scalar products */
55 class scalar_products
56 {
57 public:
58         void reg(const simp_lor & v1, const simp_lor & v2, const ex & sp);
59         bool is_defined(const simp_lor & v1, const simp_lor & v2) const;
60         ex evaluate(const simp_lor & v1, const simp_lor & v2) const;
61         void debugprint(void) const;
62 protected:
63         static spmapkey make_key(const simp_lor & v1, const simp_lor & v2);
64 protected:
65         spmap spm;
66 };
67
68 /** Base class for simp_lor object */
69 class simp_lor : public indexed
70 {
71         GINAC_DECLARE_REGISTERED_CLASS(simp_lor, 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         // other constructors
91 protected:
92         simp_lor(simp_lor_types const t);
93         simp_lor(simp_lor_types const t, const ex & i1, const ex & i2);
94         simp_lor(simp_lor_types const t, const std::string & n, const ex & i1);
95         simp_lor(simp_lor_types const t, const std::string & n, const exvector & iv);
96         simp_lor(simp_lor_types const t, const std::string & n, exvector * ivp);
97         
98         // functions overriding virtual functions from base classes
99 public:
100         void printraw(std::ostream & os) const;
101         void printtree(std::ostream & os, unsigned indent) const;
102         void print(std::ostream & os, unsigned upper_precedence=0) const;
103         void printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence=0) const;
104         bool info(unsigned inf) const;
105         ex eval(int level=0) const;
106 protected:
107         bool is_equal_same_type(const basic & other) const;
108         unsigned return_type(void) const;
109         unsigned return_type_tinfo(void) const;
110         ex thisexprseq(const exvector & v) const;
111         ex thisexprseq(exvector * vp) const;
112
113         // new virtual functions which can be overridden by derived classes
114         // none
115         
116         // non-virtual functions in this class
117 protected:
118         bool all_of_type_lorentzidx(void) const;
119         
120 // member variables
121
122 protected:
123         simp_lor_types type;
124         std::string name;
125 };
126
127 // utility functions
128 inline const simp_lor &ex_to_simp_lor(const ex &e)
129 {
130         return static_cast<const simp_lor &>(*e.bp);
131 }
132
133 inline simp_lor &ex_to_nonconst_simp_lor(const ex &e)
134 {
135         return static_cast<simp_lor &>(*e.bp);
136 }
137
138 simp_lor lor_g(const ex & mu, const ex & nu);
139 simp_lor lor_vec(const std::string & n, const ex & mu);
140 ex simplify_simp_lor_mul(const ex & m, const scalar_products & sp);
141 ex simplify_simp_lor(const ex & e, const scalar_products & sp=scalar_products());
142
143 } // namespace GiNaC
144
145 #endif // ndef _SIMP__GINAC_LOR_H__