HPhi++  3.1.0
bitcalc.cpp File Reference

File for giving functions of treating bits on the target of Hilbert space. More...

#include "bitcalc.hpp"
#include "wrapperMPI.hpp"

Go to the source code of this file.

Functions

int GetSplitBit (const int Nsite, long int *irght, long int *ilft, long int *ihfbit)
 function of getting right, left and half bits corresponding to a original Hilbert space. } More...
 
int GetSplitBitByModel (const int Nsite, const int iCalcModel, long int *irght, long int *ilft, long int *ihfbit)
 function of splitting original bit into right and left spaces. More...
 
int GetSplitBitForGeneralSpin (const int Nsite, long int *ihfbit, const long int *SiteToBit)
 function of getting right, left and half bits corresponding to a original space. More...
 
void SplitBit (const long int ibit, const long int irght, const long int ilft, const long int ihfbit, long int *isplited_Bit_right, long int *isplited_Bit_left)
 function of splitting a original bit to right and left spaces More...
 
int GetOffComp (long int *_list_2_1, long int *_list_2_2, long int _ibit, const long int _irght, const long int _ilft, const long int _ihfbit, long int *_ioffComp)
 function of getting off-diagonal component More...
 
int GetOffCompGeneralSpin (const long int org_ibit, const int org_isite, const int org_ispin, const int off_ispin, long int *_ioffComp, const long int *SiteToBit, const long int *Tpow)
 function of getting off-diagonal component for general spin More...
 
int ConvertToList1GeneralSpin (const long int org_ibit, const long int ihlfbit, long int *_ilist1Comp)
 function of converting component to list_1 More...
 
void SgnBit_old (const long int org_bit, int *sgn)
 function of getting fermion signs (for 32bit) More...
 
void SgnBit (const long int org_bit, int *sgn)
 function of getting fermion sign (64 bit) More...
 
int BitCheck (const long int org_bit, const long int target_bit)
 bit check function More...
 
int BitCheckGeneral (const long int org_bit, const int org_isite, const int target_ispin, const long int *SiteToBit, const long int *Tpow)
 bit check function for general spin More...
 
int GetBitGeneral (const int isite, const long int org_bit, const long int *SiteToBit, const long int *Tpow)
 get bit at a site for general spin More...
 
int GetLocal2Sz (const int isite, const long int org_bit, const long int *SiteToBit, const long int *Tpow)
 get 2sz at a site for general spin More...
 
long int snoob (long int x)
 "finding the next higher number after a given number that has the same number of 1-bits" This method is introduced in S.H. Warren, Hacker’s Delight, second ed., Addison-Wesley, ISBN: 0321842685, 2012. More...
 
int pop (int x)
 calculating number of 1-bits in x (32 bit) This method is introduced in S.H. Warren, Hacker’s Delight, second ed., Addison-Wesley, ISBN: 0321842685, 2012. More...
 

Detailed Description

File for giving functions of treating bits on the target of Hilbert space.

Version
0.1, 0.2
Author
Takahiro Misawa (The University of Tokyo)
Kazuyoshi Yoshimi (The University of Tokyo)

Definition in file bitcalc.cpp.

Function Documentation

◆ BitCheck()

int BitCheck ( const long int  org_bit,
const long int  target_bit 
)

bit check function

Parameters
org_bitoriginal bit to check
target_bittarget bit to check
Return values
1
0
Version
0.1
Author
Takahiro Misawa (The University of Tokyo)
Kazuyoshi Yoshimi (The University of Tokyo)
Parameters
[in]org_bit
[in]target_bit

Definition at line 366 of file bitcalc.cpp.

370 {
371  return (org_bit >> target_bit) &1;
372  // (org_bit & (2^target_bit))/2^target_bit
373 }

◆ BitCheckGeneral()

int BitCheckGeneral ( const long int  org_bit,
const int  org_isite,
const int  target_ispin,
const long int *  SiteToBit,
const long int *  Tpow 
)

bit check function for general spin

Parameters
org_bitoriginal bit to check
org_isitesite index (org_isite >= 1)
target_ispintarget spin to check
SiteToBitList for getting bit at a site
TpowList for getting total bit at a site before
Return values
0bit does not exists
1bit exists
Version
0.2
Author
Kazuyoshi Yoshimi (The University of Tokyo)
Parameters
[in]org_bit
[in]org_isite
[in]target_ispin
[in]SiteToBit
[in]Tpow

Definition at line 392 of file bitcalc.cpp.

References GetBitGeneral().

Referenced by expec_cisajs_SpinGCGeneral(), expec_cisajs_SpinGeneral(), expec_cisajscktalt_SpinGCGeneral(), expec_cisajscktalt_SpinGeneral(), GetOffCompGeneralSpin(), GetPairExcitedStateGeneralSpin(), GetPairExcitedStateGeneralSpinGC(), mltplyGeneralSpinGC(), SetDiagonalChemi(), SetDiagonalInterAll(), SetDiagonalTEChemi(), SetDiagonalTEInterAll(), SetDiagonalTETransfer(), X_child_CisAisCjuAju_GeneralSpin_MPIdouble(), X_child_CisAisCjuAju_GeneralSpin_MPIsingle(), X_GC_child_AisCis_GeneralSpin_MPIdouble(), X_GC_child_CisAis_GeneralSpin_MPIdouble(), X_GC_child_CisAisCjuAju_GeneralSpin_MPIdouble(), X_GC_child_CisAisCjuAju_GeneralSpin_MPIsingle(), X_GC_child_CisAisCjuAjv_GeneralSpin_MPIdouble(), X_GC_child_CisAisCjuAjv_GeneralSpin_MPIsingle(), X_GC_child_CisAitCjuAju_GeneralSpin_MPIdouble(), and X_GC_child_CisAitCjuAju_GeneralSpin_MPIsingle().

399 {
400 
401  if(GetBitGeneral(org_isite, org_bit, SiteToBit, Tpow) !=target_ispin){
402  return FALSE;
403  }
404  return TRUE;
405 }
int GetBitGeneral(const int isite, const long int org_bit, const long int *SiteToBit, const long int *Tpow)
get bit at a site for general spin
Definition: bitcalc.cpp:421

◆ ConvertToList1GeneralSpin()

int ConvertToList1GeneralSpin ( const long int  org_ibit,
const long int  ihlfbit,
long int *  _ilist1Comp 
)

function of converting component to list_1

Parameters
org_ibita original bit
ihlfbita split bit for general spin
_ilist1Compa component converted to list_1
Version
0.2
Author
Kazuyoshi Yoshimi (The University of Tokyo)
Parameters
[in]org_ibit
[in]ihlfbit
[out]_ilist1Comp

Definition at line 285 of file bitcalc.cpp.

References list_2_1, and list_2_2.

Referenced by expec_cisajscktalt_SpinGeneral(), GetPairExcitedStateGeneralSpin(), mltplyGeneralSpin(), totalspin_Spin(), X_child_CisAit_GeneralSpin_MPIdouble(), X_child_CisAitCjuAjv_GeneralSpin_MPIdouble(), and X_child_CisAitCjuAjv_GeneralSpin_MPIsingle().

290 {
291  long int ia, ib;
292  ia=org_ibit%ihlfbit;
293  ib=org_ibit/ihlfbit;
294  if(list_2_1[ia]*list_2_2[ib]==0){
295  *_ilist1Comp=0;
296  return FALSE;
297  }
298  *_ilist1Comp = list_2_1[ia] + list_2_2[ib] - 2;
299  return TRUE;
300 }
long int * list_2_1
Definition: global.cpp:27
long int * list_2_2
Definition: global.cpp:28

◆ GetBitGeneral()

int GetBitGeneral ( const int  isite,
const long int  org_bit,
const long int *  SiteToBit,
const long int *  Tpow 
)

get bit at a site for general spin

Parameters
isitesite index (isite >= 1)
org_bitoriginal bit to check
SiteToBitList for getting bit at a site
TpowList for getting total bit at a site before
Returns
bit at a site
Version
0.2
Author
Kazuyoshi Yoshimi (The University of Tokyo)
Parameters
[in]isite
[in]org_bit
[in]SiteToBit
[in]Tpow

Definition at line 421 of file bitcalc.cpp.

References GetLocal2Sz().

Referenced by BitCheckGeneral(), GetLocal2Sz(), totalspin_Spin(), and totalspin_SpinGC().

427 {
428  long int tmp_bit=(org_bit/Tpow[isite-1])%SiteToBit[isite-1] ;
429  return (tmp_bit);
430 }

◆ GetLocal2Sz()

int GetLocal2Sz ( const int  isite,
const long int  org_bit,
const long int *  SiteToBit,
const long int *  Tpow 
)

get 2sz at a site for general spin

Parameters
isitesite index (isite >= 1)
org_bitoriginal bit to check
SiteToBitList for getting bit at a site
TpowList for getting total bit at a site before
Returns
2sz at isite
Version
0.2
Author
Kazuyoshi Yoshimi (The University of Tokyo)
Parameters
[in]isite
[in]org_bit
[in]SiteToBit
[in]Tpow

Definition at line 448 of file bitcalc.cpp.

References GetBitGeneral().

Referenced by check(), expec_cisajscktalt_SpinGeneral(), expec_energy_flct_GeneralSpin(), expec_energy_flct_GeneralSpinGC(), GetBitGeneral(), sz(), totalspin_Spin(), and totalspin_SpinGC().

454 {
455  int TwiceSz=0;
456  int bitAtSite=0;
457  //get bit
458  bitAtSite=GetBitGeneral(isite, org_bit, SiteToBit, Tpow);
459  TwiceSz=-(SiteToBit[isite-1]-1)+2*bitAtSite; //-2S^{total}_i+2Sz_i
460  return TwiceSz;
461 }
int GetBitGeneral(const int isite, const long int org_bit, const long int *SiteToBit, const long int *Tpow)
get bit at a site for general spin
Definition: bitcalc.cpp:421

◆ GetOffComp()

int GetOffComp ( long int *  _list_2_1,
long int *  _list_2_2,
long int  _ibit,
const long int  _irght,
const long int  _ilft,
const long int  _ihfbit,
long int *  _ioffComp 
)

function of getting off-diagonal component

Parameters
_list_2_1list to right space
_list_2_2list to left space
_ibita original bit
_irghta bit to split original space into right space
_ilfta bit to split original space into left space
_ihfbita half bit to split original space
_ioffCompan off diagonal component
Version
0.1
Author
Takahiro Misawa (The University of Tokyo)
Kazuyoshi Yoshimi (The University of Tokyo)
Parameters
[in]_list_2_1
[in]_list_2_2
[in]_ibit
[in]_irght
[in]_ilft
[in]_ihfbit
[out]_ioffComp

Definition at line 195 of file bitcalc.cpp.

References SplitBit().

Referenced by child_exchange_element(), child_exchange_spin_element(), child_pairhopp_element(), CisAjt(), totalspin_Hubbard(), totalspin_Spin(), X_Ajt(), X_Ajt_MPI(), X_child_CisAit_spin_MPIdouble(), X_child_CisAjt_MPIdouble(), X_child_CisAjt_MPIsingle(), X_child_CisAjtCkuAku_Hubbard_MPI(), X_child_CisAjtCkuAlv_Hubbard_MPI(), X_child_exchange_spin_element(), X_child_general_hopp_MPIdouble(), X_child_general_hopp_MPIsingle(), X_child_general_int_spin_MPIdouble(), X_child_general_int_spin_MPIsingle(), X_child_general_int_spin_TotalS_MPIdouble(), X_Cis(), X_Cis_MPI(), X_CisAjt(), and X_Spin_CisAit().

204 {
205  long int ia, ib;
206  SplitBit(_ibit, _irght, _ilft, _ihfbit, &ia, &ib);
207 /*
208  *_ioffComp =_list_2_1[ia];
209  *_ioffComp+=_list_2_2[ib];
210 */
211 
212  //if(myrank==1)
213  //printf( "DEGBUG:_ibit=%ld, _list_2_1=%ld, _list_2_2=%ld\n", _ibit, _list_2_1[ia], _list_2_2[ib]);
214 
215  if(_list_2_1[ia]*_list_2_2[ib]==0){
216  *_ioffComp=0;
217  return FALSE;
218  }
219  *_ioffComp =_list_2_1[ia]-1;
220  *_ioffComp+=_list_2_2[ib]-1;
221 
222  return TRUE;
223 }
void SplitBit(const long int ibit, const long int irght, const long int ilft, const long int ihfbit, long int *isplited_Bit_right, long int *isplited_Bit_left)
function of splitting a original bit to right and left spaces
Definition: bitcalc.cpp:166

◆ GetOffCompGeneralSpin()

int GetOffCompGeneralSpin ( const long int  org_ibit,
const int  org_isite,
const int  org_ispin,
const int  off_ispin,
long int *  _ioffComp,
const long int *  SiteToBit,
const long int *  Tpow 
)

function of getting off-diagonal component for general spin

Parameters
org_ibita original bit
org_isitea target site
org_ispina target spin to delete.
off_ispina target spin to create.
_ioffCompa generated bit
SiteToBitList for getting bit at a site
TpowList for getting total bit at a site before
Return values
FALSEoff-diagonal component does not exist
TRUEoff-diagonal component exists
Version
0.2
Author
Kazuyoshi Yoshimi (The University of Tokyo)
Parameters
[in]org_ibit
[in]org_isite
[in]org_ispin
[in]off_ispin
[out]_ioffComp
[in]SiteToBit
[in]Tpow

Definition at line 243 of file bitcalc.cpp.

References BitCheckGeneral().

Referenced by expec_cisajs_SpinGCGeneral(), expec_cisajscktalt_SpinGCGeneral(), expec_cisajscktalt_SpinGeneral(), GetPairExcitedStateGeneralSpin(), GetPairExcitedStateGeneralSpinGC(), mltplyGeneralSpin(), mltplyGeneralSpinGC(), totalspin_Spin(), totalspin_SpinGC(), X_child_CisAit_GeneralSpin_MPIdouble(), X_child_CisAitCjuAjv_GeneralSpin_MPIdouble(), X_child_CisAitCjuAjv_GeneralSpin_MPIsingle(), X_GC_child_CisAisCjuAjv_GeneralSpin_MPIdouble(), X_GC_child_CisAisCjuAjv_GeneralSpin_MPIsingle(), X_GC_child_CisAit_GeneralSpin_MPIdouble(), X_GC_child_CisAitCjuAju_GeneralSpin_MPIdouble(), X_GC_child_CisAitCjuAju_GeneralSpin_MPIsingle(), X_GC_child_CisAitCjuAjv_GeneralSpin_MPIdouble(), and X_GC_child_CisAitCjuAjv_GeneralSpin_MPIsingle().

252 {
253  if(off_ispin>SiteToBit[org_isite-1]-1 ||
254  off_ispin<0 ||
255  org_ispin>SiteToBit[org_isite-1]-1 ||
256  org_ispin <0){
257  *_ioffComp=0;
258  return FALSE;
259  }
260  if(BitCheckGeneral(org_ibit, org_isite, org_ispin, SiteToBit, Tpow) == FALSE){
261  *_ioffComp=0;
262  return FALSE;
263  }
264 
265  //delete org_ispin and create off_ispin
266  long int tmp_off=0;
267  tmp_off=(long int)(off_ispin-org_ispin);
268  tmp_off *=Tpow[org_isite-1];
269  tmp_off +=org_ibit;
270  *_ioffComp =tmp_off;
271  return TRUE;
272 }
int BitCheckGeneral(const long int org_bit, const int org_isite, const int target_ispin, const long int *SiteToBit, const long int *Tpow)
bit check function for general spin
Definition: bitcalc.cpp:392

◆ GetSplitBit()

int GetSplitBit ( const int  Nsite,
long int *  irght,
long int *  ilft,
long int *  ihfbit 
)

function of getting right, left and half bits corresponding to a original Hilbert space. }

Parameters
Nsitea total number of sites
irghta bit to split original Hilbert space into right space \(2^{(Ns+2)/2}-1\)
ilfta bit to split original Hilbert space into left space
ihfbita half bit to split original Hilbert space \(2^{(Ns+2)/2}\)
Version
0.1
Author
Takahiro Misawa (The University of Tokyo)
Kazuyoshi Yoshimi (The University of Tokyo)
Returns
Parameters
[in]Nsite
[out]irght
[out]ilft
[out]ihfbit

Definition at line 45 of file bitcalc.cpp.

Referenced by GetSplitBitByModel().

50  {
51  if(Nsite<1){
52  fprintf(stderr, "%s", "Error: Total Site Number is incorrect.\n");
53  return -1;
54  }
55  *ihfbit=1;
56  *ihfbit=(*ihfbit<<(long int)((Nsite+1)/2));
57  *irght = *ihfbit-1;
58  *ilft=1;
59  *ilft = (*ilft<<(long int)Nsite)-1;
60  *ilft= *ilft ^ *irght;
61  return 0;
62 }

◆ GetSplitBitByModel()

int GetSplitBitByModel ( const int  Nsite,
const int  iCalcModel,
long int *  irght,
long int *  ilft,
long int *  ihfbit 
)

function of splitting original bit into right and left spaces.

Parameters
Nsitea total number of sites
iCalcModelCalc model defined in CalcMode file
irghta bit to split original space into right space
ilfta bit to split original space into left space
ihfbita half bit to split original space
Version
0.1
Author
Takahiro Misawa (The University of Tokyo)
Kazuyoshi Yoshimi (The University of Tokyo)
Returns
Parameters
[in]Nsite
[in]iCalcModel
[out]irght
[out]ilft
[out]ihfbit

Definition at line 78 of file bitcalc.cpp.

References GetSplitBit().

Referenced by expec_cisajs(), expec_cisajscktaltdc(), expec_energy_flct(), GetPairExcitedState(), GetPairExcitedStateHubbard(), mltply(), sz(), totalspin_Hubbard(), and totalspin_Spin().

85 {
86  int tmpNsite=Nsite;
87  switch(iCalcModel){
88  case HubbardGC:
89  case KondoGC:
90  case HubbardNConserved:
91  case Hubbard:
92  case Kondo:
93  tmpNsite *= 2;
94  break;
95  case Spin:
96  case SpinGC:
97  break;
98  default:
99  fprintf(stderr, "Error: CalcModel %d is incorrect.\n", iCalcModel);
100  return -1;
101  }
102 
103  if(GetSplitBit(tmpNsite, irght, ilft, ihfbit)!=0){
104  return -1;
105  }
106 
107  return 0;
108 }
int GetSplitBit(const int Nsite, long int *irght, long int *ilft, long int *ihfbit)
function of getting right, left and half bits corresponding to a original Hilbert space...
Definition: bitcalc.cpp:45

◆ GetSplitBitForGeneralSpin()

int GetSplitBitForGeneralSpin ( const int  Nsite,
long int *  ihfbit,
const long int *  SiteToBit 
)

function of getting right, left and half bits corresponding to a original space.

Parameters
Nsitea total number of sites
ihfbita bit to split original space
Return values
0normally finished
-1unnormally finished
Version
0.2
Author
Takahiro Misawa (The University of Tokyo)
Kazuyoshi Yoshimi (The University of Tokyo)
Parameters
[in]Nsite
[out]ihfbit
[in]SiteToBit

Definition at line 124 of file bitcalc.cpp.

Referenced by check(), GetPairExcitedState(), and mltply().

128  {
129  int isite=0;
130  long int isqrtMaxDim=1;
131  long int tmpbit=1;
132 
133  if(Nsite<1){
134  fprintf(stderr, "%s", "Error: Total Site Number is incorrect.\n");
135  return -1;
136  }
137 
138  for(isite=1; isite<=Nsite ; isite++){
139  isqrtMaxDim *= SiteToBit[isite-1];
140  }
141  isqrtMaxDim =(long int)sqrt(isqrtMaxDim);
142 
143  for(isite=1; isite<=Nsite ; isite++){
144  tmpbit *= SiteToBit[isite-1];
145  if(tmpbit >= isqrtMaxDim) break;
146  }
147  *ihfbit=tmpbit;
148  return 0;
149 }

◆ pop()

int pop ( int  x)

calculating number of 1-bits in x (32 bit) This method is introduced in S.H. Warren, Hacker’s Delight, second ed., Addison-Wesley, ISBN: 0321842685, 2012.

Parameters
x
Version
2.0
Author
Takahiro Misawa (The University of Tokyo)

Definition at line 491 of file bitcalc.cpp.

Referenced by expec_energy_flct_HalfSpin(), expec_energy_flct_HalfSpinGC(), expec_energy_flct_Hubbard(), and expec_energy_flct_HubbardGC().

491  {
492  x = x - ((x>>1) & 0x55555555);
493  x = (x & 0x33333333)+ ((x>>2)& 0x33333333);
494  x = (x+(x>>4)) & 0x0F0F0F0F;
495  x = x+ (x>>8);
496  x = x+ (x>>16);
497  return x & 0x0000003F;
498 }

◆ SgnBit()

void SgnBit ( const long int  org_bit,
int *  sgn 
)

function of getting fermion sign (64 bit)

Parameters
org_bitan original bit
sgnfermion sign
Version
0.1
Author
Takahiro Misawa (The University of Tokyo)
Kazuyoshi Yoshimi (The University of Tokyo)
Parameters
[in]org_bit
[out]sgn

Definition at line 338 of file bitcalc.cpp.

Referenced by CisAjt(), GC_Ajt(), GC_Cis(), GC_CisAjt(), X_Ajt(), X_Ajt_MPI(), X_child_CisAjt_MPIdouble(), X_child_CisAjt_MPIsingle(), X_child_CisAjtCkuAku_Hubbard_MPI(), X_child_general_hopp_MPIdouble(), X_child_general_hopp_MPIsingle(), X_Cis(), X_Cis_MPI(), X_GC_Ajt_MPI(), X_GC_child_CisAjtCkuAku_Hubbard_MPI(), X_GC_child_general_hopp_MPIdouble(), X_GC_child_general_hopp_MPIsingle(), X_GC_Cis_MPI(), and X_GC_CisAjt().

342 {
343  long int bit;
344 
345  bit = org_bit^(org_bit>>1);
346  bit = bit^(bit>>2);
347  bit = bit^(bit>>4);
348  bit = bit^(bit>>8);
349  bit = bit^(bit>>16);
350  bit = bit^(bit>>32);
351  *sgn = 1-2*(bit & 1); // sgn = pm 1
352 }

◆ SgnBit_old()

void SgnBit_old ( const long int  org_bit,
int *  sgn 
)

function of getting fermion signs (for 32bit)

Parameters
org_bitan original bit
sgnfermion sign
Version
0.1
Author
Takahiro Misawa (The University of Tokyo)
Kazuyoshi Yoshimi (The University of Tokyo)
Parameters
[in]org_bit
[out]sgn

Definition at line 312 of file bitcalc.cpp.

316 {
317  long int bit;
318 
319  bit = org_bit^(org_bit>>1);
320  bit = (bit^(bit>>2) ) & 0x11111111;
321  bit = bit*0x11111111;
322  *sgn = 1-2*((bit>>28) & 1); // sgn = pm 1
323 }

◆ snoob()

long int snoob ( long int  x)

"finding the next higher number after a given number that has the same number of 1-bits" This method is introduced in S.H. Warren, Hacker’s Delight, second ed., Addison-Wesley, ISBN: 0321842685, 2012.

Parameters
x
Version
2.0
Author
Takahiro Misawa (The University of Tokyo)

Definition at line 473 of file bitcalc.cpp.

Referenced by child_omp_sz_hacker(), child_omp_sz_Kondo_hacker(), child_omp_sz_spin_hacker(), and sz().

473  {
474  long int smallest, ripple, ones;
475  smallest = x &(-x);
476  ripple = x+ smallest;
477  ones = x ^ ripple;
478  ones = (ones>>2)/smallest;
479  return ripple|ones;
480 }

◆ SplitBit()

void SplitBit ( const long int  ibit,
const long int  irght,
const long int  ilft,
const long int  ihfbit,
long int *  isplited_Bit_right,
long int *  isplited_Bit_left 
)

function of splitting a original bit to right and left spaces

Parameters
ibita original bit
irghta bit to split original space into right space
ilfta bit to split original space into left space
ihfbita half bit to split original space
isplited_Bit_righta splitted bit reflected on right space
isplited_Bit_lefta splitted bit reflected on left space
Version
0.1
Author
Takahiro Misawa (The University of Tokyo)
Kazuyoshi Yoshimi (The University of Tokyo)
Parameters
[in]ibit
[in]irght
[in]ilft
[in]ihfbit
[out]isplited_Bit_right
[out]isplited_Bit_left

Definition at line 166 of file bitcalc.cpp.

Referenced by GetOffComp().

174 {
175  *isplited_Bit_right=ibit & irght;
176  *isplited_Bit_left=ibit & ilft;
177  *isplited_Bit_left=*isplited_Bit_left/ihfbit;
178 }