57 #define MAX(x, y) (((x) > (y)) ? (x) : (y))
58 #define MIN(x, y) (((x) < (y)) ? (x) : (y))
61 static bool FlagSimplifyGlobalIndexSum =
true;
64 FlagSimplifyGlobalIndexSum =
true;
68 FlagSimplifyGlobalIndexSum =
false;
84 constpartin.erase(std::remove(constpartin.begin(), constpartin.end(),
' '), constpartin.end());
90 constpartin.erase(std::remove(constpartin.begin(), constpartin.end(),
' '), constpartin.end());
97 constpartin.erase(std::remove(constpartin.begin(), constpartin.end(),
' '), constpartin.end());
99 list<DList>::iterator iter;
100 for(iter = termin.
term.begin(); iter != termin.
term.end(); iter++)
101 term.push_back(*iter);
189 vector< BraketOneTerm >::const_iterator iter;
203 for(
int i=0; i<a.size();i++){
242 cout <<
"Outside range..." << endl;
250 cout <<
"Outside range..." << endl;
293 cout <<
"Invalid Operation: " << a <<
" - " << b << endl;
306 cout <<
"Invalid Operation: " << a <<
" + " << b << endl;
325 cout <<
"Operation not permited: " << a <<
" * " << b << endl;
331 cout <<
"Expression mode: " <<
operation << endl;
341 if( (eval0 == 0 && eval1 > 0 ) || (eval0 > 0 && eval1 == 0) ){
342 cout <<
"Cannot perform this operation, not all expression were evaluate...\n Exiting..." << endl;
345 else return MAX(eval0, eval1);
369 list<DList>::iterator iter;
370 for(iter = tmp.
term.begin(); iter != tmp.
term.end(); iter++)
375 void BraketOneTerm::neg(){
376 if(term.empty()) constpart =
"-1*"+constpart;
378 list<DList>::iterator iter;
379 for(iter = term.begin(); iter != term.end(); iter++)
386 vector< BraketOneTerm >::iterator iter;
397 vector< BraketOneTerm >::const_iterator iter;
399 expression.push_back(-(*iter));
412 vector< BraketOneTerm >::const_iterator iter;
425 vector< BraketOneTerm >::const_iterator iter;
427 expression.push_back(*iter);
437 vector< BraketOneTerm >::const_iterator iter;
448 if(constpart.empty()) constpart = constval;
449 else constpart +=
"*" + constval;
452 Braket Braket::operator*=(
const string constval){
453 vector< BraketOneTerm >::iterator iter;
454 for(iter = expression.begin(); iter != expression.end(); iter++)\
465 if(constpart.empty()) tmp.
constpart = constval;
466 else tmp.
constpart = constpart +
"*" + constval;
474 vector< BraketOneTerm >::iterator iter;
484 if( (term.empty() && constpart.empty()) )
return *
this;
493 list<DList>::iterator iter;
494 list<DList>::const_iterator liter;
496 for(liter =L.
term.begin(); liter != L.
term.end(); liter++)
497 tmp.
term.push_back((*liter));
499 else if(L.
term.empty()){
500 for(iter = term.begin(); iter != term.end(); iter++)
501 tmp.
term.push_back((*iter));
504 for(iter = term.begin(); iter != term.end(); iter++)
505 for(liter =L.
term.begin(); liter != L.
term.end(); liter++)
506 tmp.
term.push_back((*iter)*(*liter));
514 cout << operation <<
"::::"<< L.
operation<<endl;
515 cout <<
"Evaluate both expressions first before doing the multiplication!!!!" << endl;
516 cout <<
"Multiplication between two braket's only allowed after evaluation!!!!" << endl;
522 vector< BraketOneTerm >::iterator iter;
523 vector< BraketOneTerm >::const_iterator liter;
524 for(iter = expression.begin(); iter != expression.end(); iter++)
537 cout << operation <<
"::::"<< L.
operation<<endl;
538 cout <<
"Evaluate both expressions first before doing the multiplication!!!!" << endl;
539 cout <<
"Multiplication between two braket's only allowed after evaluation!!!!" << endl;
545 vector< BraketOneTerm >::iterator iter;
546 vector< BraketOneTerm >::const_iterator liter;
547 vector< BraketOneTerm > tmp;
548 for(iter = expression.begin(); iter != expression.end(); iter++)
550 tmp.push_back((*iter)*(*liter));
564 if(L.
constpart.empty()) out <<
"(" << endl;
565 else out <<
"("<<L.
constpart<<
")" <<
" * (" << endl;
566 list<DList>::const_iterator iter;
567 for (iter =L.
term.begin(); iter != L.
term.end(); iter++){
571 if(tmp.
getSign() == -1) out <<
" - ";
572 if(tmp.
getSign() == 1) out <<
" + ";
573 if(tmp.
isEmpty()) out <<
" 0 ";
601 if(L.
expression.size() == 0) out <<
"Local R" << ++R <<
" = 0;";
604 if(L.
flag) out <<
"Local R" << ++R <<
" = ";
606 else out << L.
expression.at(i) <<
";" << endl;
625 void BraketOneTerm::rearrange(){
626 list<DList>::iterator iter;
627 for(iter = term.begin(); iter != term.end(); iter++)
630 void Braket::rearrange(){
631 if(evaluated==2)
return;
633 int total = expression.size();
636 vector< BraketOneTerm >::iterator iter;
637 for(iter = expression.begin(); iter != expression.end(); iter++){
646 bool BraketOneTerm::checkindex(){
647 if(index==0 || abs(index)==
getDim()/2)
return true;
650 void Braket::checkindex(){
651 if(FlagSimplifyGlobalIndexSum) {
654 int total = expression.size();
656 vector< BraketOneTerm > tmp;
657 for (
int i = 0; i < expression.size(); i++){
658 if(expression.at(i).checkindex()){
659 tmp.push_back(expression.at(i));
660 expression.at(i).clear();
674 void Braket::gindexsetnull(){
676 int total = expression.size();
678 for (
int i = 0; i < expression.size(); i++){
679 expression.at(i).GetIndex() = 0;
687 bool BraketOneTerm::Simplify(
OPMode operation){
688 list<DList>::iterator iter = term.begin();
689 while(iter != term.end()){
690 bool checkop =
false;
691 switch( operation ) {
693 if( (*iter).checkDeltaIndex() )
697 if( (*iter).search_first(1,0) )
698 if( (*iter).checkDeltaIndex() )
702 if( (*iter).search_last(0) )
703 if( (*iter).checkDeltaIndex() )
707 if( (*iter).check_same_num() )
708 if( (*iter).search_last(0) )
709 if( (*iter).search_first(1,0) )
710 if( (*iter).checkDeltaIndex() )
716 iter = term.erase(iter);
728 void Braket::simplify(){
732 int total = expression.size();
735 vector< BraketOneTerm > tmp;
736 for (i = 0; i < expression.size(); i++){
738 tmp0 = expression.at(i);
739 if(!tmp0.
Simplify(operation)) tmp.push_back(tmp0);
757 string epsBdagger =
"e_(";
759 for(
int j = 0; j < id0.size(); j++){
761 epsBdagger += id1.at(id1.size() - 1 - j);
762 if(j <
getDim() / 2 - 1) {
769 if(id0.size() <
getDim() / 2){
770 int len =
getDim() / 2 - id0.size();
771 for(
int j = 0; j < len; j++){
777 epsBdagger += addrem;
786 string levciviexp = epsB +
"*" + epsBdagger;
798 void BraketOneTerm::EvaluateEps_2ndPass(
OPMode oper ){
799 if(oper !=
braket)
return;
800 list<DList>::iterator iter = term.begin();
801 string constpartout =
"*(\n";
802 if(constpart.empty()) constpartout =
"(\n";
803 while (iter != term.end()){
804 if((*iter).isEmpty()==
false){
805 vector < string> id0;
806 vector < string> id1;
808 bool bandbdagger =
false;
809 (*iter).getBandBdaggerIds(bandbdagger, id0, id1, sign0);
810 if( sign0 == -1) constpartout+=
"-";
811 if( sign0 == 1) constpartout+=
"+";
813 constpartout += deltas;
814 if(bandbdagger && deltas.empty()==
false) constpartout+=
"*";
817 constpartout +=
"\n";
823 constpart += constpartout;
824 constpartout.clear();
839 list<DList>::iterator iter = Toeval.begin();
840 bool braketmode =
false;
841 if(oper ==
braket) braketmode =
true;
842 while (iter != Toeval.end()){
843 bool inc_iter =
true;
844 if((*iter).isEmpty()==
false){
847 vector<int> ids = LL.
getIds();
848 bool ordered =
false;
849 vector<int> ids0 = ids;
850 sort (ids0.begin(), ids0.end());
851 if(ids0 == ids) ordered =
true;
858 sort (ids0.begin(), ids0.end());
859 if(ids0 == ids) ordered =
true;
870 else Toeval.push_back(M);
874 iter = Toeval.erase(iter);
882 iter = Toeval.erase(iter);
902 list<DList>::iterator iter = Toeval.begin();
903 bool braketmode =
false;
904 if(oper ==
braket) braketmode =
true;
905 while (iter != Toeval.end()){
906 bool inc_iter =
true;
907 if((*iter).isEmpty()==
false)
908 if((*iter).search_last(0))
910 if((*iter).search_elem(0)==
false)
break;
911 if((*iter).numBs()<=
getDim()/2)
break;
923 else Toeval.push_back(M);
927 iter = Toeval.erase(iter);
935 iter = Toeval.erase(iter);
953 bool BraketOneTerm::EvaluateEps_1stPass(
OPMode oper ){
958 if(term.empty())
return true;
966 bool BraketOneTerm::EvaluateToLeviCivita(
OPMode oper ){
967 EvaluateEps_1stPass(oper);
968 if(term.empty())
return true;
969 EvaluateEps_2ndPass(oper);
979 bool BraketOneTerm::EvaluateToDeltas(
OPMode oper ){
980 list<DList>::iterator iter = term.begin();
981 bool braketmode =
false;
982 if(oper ==
braket) braketmode =
true;
983 while (iter != term.end()){
984 bool inc_iter =
true;
985 if((*iter).isEmpty()==
false)
986 if((*iter).search_last(0))
988 if((*iter).search_elem(0)==
false)
break;
989 if( oper ==
none && ((*iter).search_elem(0)==
false || (*iter).search_elem(1)==
false) )
break;
1001 else term.push_back(M);
1005 iter = term.erase(iter);
1013 iter = term.erase(iter);
1020 if( inc_iter) ++iter;
1034 void Braket::evaluate(
bool onlydeltas){
1041 vector< BraketOneTerm >::iterator iter = expression.begin();
1043 int total = expression.size();
1045 while(iter != expression.end()){
1046 if((*iter).EvaluateToDeltas(operation)){
1048 iter = expression.erase(iter);
1054 if(operation ==
braket) evaluated = 1;
1057 if(operation !=
braket)
return;
1059 int total = expression.size();
1061 vector< BraketOneTerm >::iterator iter = expression.begin();
1062 while(iter != expression.end()){
1063 if((*iter).EvaluateToLeviCivita(operation)){
1065 iter = expression.erase(iter);
1071 if(operation ==
braket) evaluated = 2;
1075 if(evaluated>0) gindexsetnull();
string GetLeviCivita(vector< string > id0, vector< string > id1)
unsigned int getType()
Returns the type of the element. Ex.: $b$ - type=0; $b^{}$ - type=1; $$ - type=2; constant - type=3...
void setON()
Activate expression term numbering for output writing for each term "Local R?=".
OPMode operator-(const OPMode a, const OPMode b)
calculate the mode for the subtraction
int getDim()
Get the group dimension.
Braket operator-(const Braket &L)
Functions and cointainer for indices.
Verbosity getVerbosity()
Return current verbosity level.
elemType get()
Returns elemtype of the node being pointed by actual (current element).
OPMode operator*(const OPMode a, const OPMode b)
calculate the mode for the multiplication
bool Simplify(OPMode operation)
Simplify current expression term.
void setOFF()
Deactivate expression term numbering for output writing for each term "Local R?=".
template string ToString< int >(int number)
unsigned int getIdx2()
Returns the second data field of the element (id.y).
~Braket()
Destructor, clear all allocated memory.
void ReduceNumberOfBandBdaggers(list< DList > &Toeval, OPMode oper)
Evaluate expression in order to have the number of b's plus b^daggers equal to N of SO(N) ...
int index
Store the index sum.
void expfromForm(vector< string > a)
To pass a expression from form.
void clear()
Clear all allocated memory and sets default parameters.
void shift_right()
Shifts actual pointer to next node. If actual node is the end node, stops.
void clear()
Deletes all nodes from DList.
Defintions for all general (initialisation etc.) routines of class Braket.
Defintions for all general (initialisation etc.) routines of class Timer.
Defintions for all general (initialisation etc.) routines of class DList.
bool isEmpty()
Returns true if DList has no nodes.
void simplify()
Simplify expression. Apply the following rules: Also checks for numeric deltas and evaluates them...
void expfromForm(string a)
To pass a expression from form.
string & operator<<(string &out, const Braket &L)
int & GetIndex(int pos)
Return/set the index sum of the term given by pos.
void clear()
Clear all allocated memory and sets default parameters.
vector< BraketOneTerm > expression
Store expressions with b's, b^ and delta's.
unsigned int evaluated
Store the evaluated state of the expression.
DList ordering(DList &L, bool braketmode)
Order only the b's (to the left hand side) and b's (to the right hand side) terms. Applies the following identity: input DList L keeps delta term and function returns the swapped term.
OPMode operator+(const OPMode a, const OPMode b)
calculate the mode for the sum
string getIdx(int i)
Get index.
int size()
Return number of terms in current expression.
string printDeltas(DList &L)
Creates and returns a string with the deltas and constants of a DList.
Store each term of the Braket class.
void unsetSimplifyIndexSum()
Deactivate internal simplifications based on the Braket Index sum.
Braket(void)
Constructor, default expression mode is none.
Braket operator=(const Braket &L)
overload operator for Braket = L
DList contract_deltas(DList &L, bool braketmode)
Applies the following identity: input DList L keeps delta term and function returns the swapped term...
vector< int > getIds()
Creates and returns an integer vector sequence container with the ids (data fields) of $b$'s and $b^$...
Main Sospin header file. Includes C++ macros, to simplify expression writing, B operator, Verbosity level and memory usage.
list< DList > term
Store the part with b and b and/or delta or identity.
int getSign()
Returns the sign of DList.
ostream & operator<<(ostream &out, const OPMode &a)
Get the mode of the expression.
void rearrange()
Order nodes of DList in Braket.
OPMode operation
Store type of operation: none, bra, ket or braket.
void setSimplifyIndexSum()
Activate internal simplifications based on the Braket Index sum. This option is activated by default...
list< DList > & GetTerm()
Return (and set) the term part.
bool isActualLast()
Returns true if actual pointer is pointing to the last (end) node of DList.
bool search_last(unsigned int type1)
Search the last element with "data.get\_type()==type1" found in DList. Returns true a node was found...
void DoProgress(string label, unsigned int step, unsigned int total, unsigned int interval)
void newId(string i)
Store new index of type "string".
void print_process_mem_usage()
Prints memory stats (current and peak resident set size) in MB.
int & GetIndex()
Return (and set) the index sum part.
string & operator+(string &out, const Braket &L)
BraketOneTerm()
Constructor.
string constpart
Store the constant part.
~BraketOneTerm()
Destructor, clear all allocated memory.
int flag
Flag to make the term numeration with ostream operator.
string & GetConst()
Return (and set) the constant part.
bool isempty()
Returns true if expression is empty.
int expevaluationtype(int eval0, int eval1)
void set_begin()
Changes actual pointer to point at the first element of DList (beg pointer).
void OrderBandBdaggers(list< DList > &Toeval, OPMode oper)
Evaluate expression in order to left all b's in left side and b^daggers in right side.
BraketOneTerm & Get(int pos)
Return expression term at position given by pos.
Specific functions progress status bar.
unsigned int getIdx1()
Returns the first data field of the element (id.x).