sospin is hosted by Hepforge, IPPP Durham
SOSpin  1.0.0
braket.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // SOSpin Library
3 // Copyright (C) 2015 SOSpin Project
4 //
5 // Authors:
6 //
7 // Nuno Cardoso (nuno.cardoso@tecnico.ulisboa.pt)
8 // David Emmanuel-Costa (david.costa@tecnico.ulisboa.pt)
9 // Nuno Gonçalves (nunogon@deec.uc.pt)
10 // Catarina Simoes (csimoes@ulg.ac.be)
11 //
12 // ----------------------------------------------------------------------------
13 // This file is part of SOSpin Library.
14 //
15 // SOSpin Library is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or any
18 // later version.
19 //
20 // SOSpin Library is distributed in the hope that it will be useful,
21 // but WITHOUT ANY WARRANTY; without even the implied warranty of
22 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 // GNU General Public License for more details.
24 //
25 // You should have received a copy of the GNU General Public License
26 // along with SOSpin Library. If not, see <http://www.gnu.org/licenses/>.
27 // ----------------------------------------------------------------------------
28 
29 // braket.h created on 27/02/2015
30 //
31 // This file contains the functions necessary to do things
32 // in the SOSpin Library.
33 //
34 // Revision 1.1 28/02/2015 23:19:29 david
35 // License updated
36 //
37 
38 
45 #ifndef BRAKET_H
46 #define BRAKET_H
47 
48 #include <iostream>
49 #include <string>
50 #include <cstring>
51 #include <sstream>
52 #include <cstdlib>
53 #include <vector>
54 #include <algorithm>
55 #include <list>
56 
57 #include "dlist.h"
58 #include "enum.h"
59 
60 
61 using namespace std;
62 
63 
64 namespace sospin {
65 
66 
67 
68 
69 
70 
71 
73 void setSimplifyIndexSum();
74 
77 
78 
84 private:
86  int index;
88  string constpart;
90  list<DList> term;
91 
97  bool EvaluateEps_1stPass(OPMode oper );
98 
103  void EvaluateEps_2ndPass(OPMode oper );
104 
105 public:
107  BraketOneTerm();
111  BraketOneTerm(const DList &d0);
117  BraketOneTerm(int indexin, string constpartin, const DList &d0);
123  BraketOneTerm(int indexin, string constpartin, list<DList> termin);
129  BraketOneTerm(int indexin, string constpartin, BraketOneTerm& termin);
131  ~BraketOneTerm();
133  void clear();
134 
136  list<DList>& GetTerm();
138  string& GetConst();
140  int& GetIndex();
141 
142 
147  bool Simplify(OPMode operation);
151  bool checkindex();
152 
153 
155  void expfromForm(string a);
161  void rearrange();
163  bool isempty();
164 
169  bool EvaluateToDeltas(OPMode oper );
174  bool EvaluateToLeviCivita(OPMode oper );
175 
177  void neg();
179  BraketOneTerm operator*(const string constval);
181  BraketOneTerm operator*=(const string constval);
185  BraketOneTerm operator*=(const BraketOneTerm &L);
187  friend BraketOneTerm operator-(const BraketOneTerm &L);
189  friend ostream& operator<<(ostream& out, const BraketOneTerm &L);
190 
191 };
192 
193 
198 class Braket{
200  vector< BraketOneTerm > expression;
202  int flag;
206  unsigned int evaluated;
207  /* evaluated = 0 - > not yet evaluated
208  evaluated = 1 - > evaluated creating deltas
209  evaluated = 2 - > evaluated creating e_(...)... */
210 
211 
212  public:
214  Braket(void);
218  Braket(const DList &d0);
224  Braket(int id, string a, DList d0);
231  Braket(int id, string a, DList d0, OPMode op);
235  Braket(const Braket &L);
242  Braket(int id, string a, const Braket &L, OPMode op);
246  Braket(BraketOneTerm term);
251  Braket(BraketOneTerm term, OPMode op);
253  ~Braket();
255  void clear();
256 
258  void expfromForm(vector<string> a);
259 
260  /* \brief Returns the current expression type, it also allows to set new expression type. Expression types: bra/ket/braket or none*/
261  OPMode& Type();
262 
263  /* \brief Print the Braket expression mode, ie, the type of Braket: bra/ket/braket or none*/
264  void mode();
265 
269  void evaluate(bool onlydeltas=true);
279  void simplify();
285  void rearrange();
288  void checkDeltaIndex();
291  void gindexsetnull();
295  void checkindex();
298  void setON();
301  void setOFF();
303  int size();
305  BraketOneTerm& Get(int pos);
307  int& GetIndex(int pos);
308 
309 
310 
311  //OPERATORS
312 
314  Braket operator=(const Braket &L);
316  Braket operator+(const Braket &L);
318  Braket operator+=(const Braket &L);
320  Braket operator-(const Braket &L);
322  Braket operator-=(const Braket &L);
324  Braket operator*(const Braket &L);
326  Braket& operator*=(const Braket &L);
328  Braket operator*(const string constval);
330  Braket operator*=(const string constval);
331 
333  friend Braket operator-(const Braket &L);
334 
341  friend OPMode operator*(const OPMode a, const OPMode b);
348  friend OPMode operator+(const OPMode a, const OPMode b);
355  friend OPMode operator-(const OPMode a, const OPMode b);
356 
358  friend ostream& operator<<(ostream& out, const Braket &L);
360  friend string& operator<<(string& out, const Braket &L);
362  friend string& operator+(string& out, const Braket &L);
363 };
364 
365 
366 
372  ostream& operator<<(ostream& out, const OPMode &a);
373 
374 
375 }
376 
377 
378 #endif
379 
380 
381 
OPMode operator-(const OPMode a, const OPMode b)
calculate the mode for the subtraction
Definition: braket.cpp:291
OPMode operator*(const OPMode a, const OPMode b)
calculate the mode for the multiplication
Definition: braket.cpp:317
Store expression...
Definition: braket.h:198
int index
Store the index sum.
Definition: braket.h:86
enum OPMode_s OPMode
Defintions for all general (initialisation etc.) routines of class DList.
vector< BraketOneTerm > expression
Store expressions with b's, b^ and delta's.
Definition: braket.h:200
unsigned int evaluated
Store the evaluated state of the expression.
Definition: braket.h:206
OPMode operator+(const OPMode a, const OPMode b)
calculate the mode for the sum
Definition: braket.cpp:304
Enumerators.
Store each term of the Braket class.
Definition: braket.h:83
void unsetSimplifyIndexSum()
Deactivate internal simplifications based on the Braket Index sum.
Definition: braket.cpp:67
DList with nodes.
Definition: dlist.h:264
list< DList > term
Store the part with b and b and/or delta or identity.
Definition: braket.h:90
ostream & operator<<(ostream &out, const OPMode &a)
Get the mode of the expression.
Definition: braket.cpp:266
OPMode operation
Store type of operation: none, bra, ket or braket.
Definition: braket.h:204
void setSimplifyIndexSum()
Activate internal simplifications based on the Braket Index sum. This option is activated by default...
Definition: braket.cpp:63
#define b(a)
C++ Macro for DList b operator.
Definition: son.h:87
string constpart
Store the constant part.
Definition: braket.h:88
int flag
Flag to make the term numeration with ostream operator.
Definition: braket.h:202