Cytnx v0.9.3
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
cytnx::Symmetry Class Reference

the symmetry object More...

#include <Symmetry.hpp>

Public Member Functions

Symmetry clone () const
 return a clone instance of current Symmetry object.
 
int stype () const
 return the symmetry type-id of current Symmetry object, see cytnx::SymType.
 
int & n () const
 return the descrete n of current Symmetry object.
 
std::string stype_str () const
 return the symmetry type name of current Symmetry object in string form, see cytnx::SymType.
 
bool check_qnum (const cytnx_int64 &qnum)
 check the quantum number qnum is within the valid value range of current Symmetry.
 
bool check_qnums (const std::vector< cytnx_int64 > &qnums)
 check all the quantum numbers \qnums are within the valid value range of current Symmetry.
 
std::vector< cytnx_int64combine_rule (const std::vector< cytnx_int64 > &inL, const std::vector< cytnx_int64 > &inR)
 apply combine rule of current symmetry to two quantum number lists.
 
void combine_rule_ (std::vector< cytnx_int64 > &out, const std::vector< cytnx_int64 > &inL, const std::vector< cytnx_int64 > &inR)
 apply combine rule of current symmetry to two quantum number lists, and store it into parameter out.
 
cytnx_int64 combine_rule (const cytnx_int64 &inL, const cytnx_int64 &inR, const bool &is_reverse=false) const
 apply combine rule of current symmetry to two quantum numbers.
 
void combine_rule_ (cytnx_int64 &out, const cytnx_int64 &inL, const cytnx_int64 &inR, const bool &is_reverse=false)
 apply combine rule of current symmetry to two quantum numbers, and store the combined quntun number into parameter
 
void reverse_rule_ (cytnx_int64 &out, const cytnx_int64 &in)
 Apply reverse rule of current symmetry to a given quantum number and store in parameter out.
 
cytnx_int64 reverse_rule (const cytnx_int64 &in) const
 Apply reverse rule of current symmetry to a given quantum number and return the result.
 
void Save (const std::string &fname) const
 Save the current Symmetry object to a file.
 
void Save (const char *fname) const
 Same as Save(const std::string &fname) const;.
 
void print_info () const
 Print the information of current Symmetry object.
 
bool operator== (const Symmetry &rhs) const
 the equality operator of the Symmetry object.
 
bool operator!= (const Symmetry &rhs) const
 the inequality operator of the Symmetry object.
 

Static Public Member Functions

static Symmetry U1 ()
 create a U1 symmetry object
 
static Symmetry Zn (const int &n)
 create a Zn descrete symmetry object with \(n\in\mathbb{N}\)
 
static Symmetry Load (const std::string &fname)
 Load a Symmetry object from a file.
 
static Symmetry Load (const char *fname)
 Same as static Symmetry Load(const std::string &fname);.
 

Detailed Description

the symmetry object

Member Function Documentation

◆ check_qnum()

bool cytnx::Symmetry::check_qnum ( const cytnx_int64 qnum)
inline

check the quantum number qnum is within the valid value range of current Symmetry.

Parameters
[in]qnuma singule quantum number.
Returns
[bool]

◆ check_qnums()

bool cytnx::Symmetry::check_qnums ( const std::vector< cytnx_int64 > &  qnums)
inline

check all the quantum numbers \qnums are within the valid value range of current Symmetry.

Parameters
[in]qnumsthe list of quantum numbers
Returns
[bool]

◆ clone()

Symmetry cytnx::Symmetry::clone ( ) const
inline

return a clone instance of current Symmetry object.

Returns
[Symmetry]

Example:

c++ API:

#include "cytnx.hpp"
#include <iostream>
using namespace cytnx;
using namespace std;
int main() {
/* 1.
create symmetry objects
*/
Symmetry sym_D = sym_A; // same instance.
// using is() to check if they are the same instance.
cout << is(sym_D, sym_A) << endl; // true. same instance
cout << (sym_D == sym_A) << endl; // true, same content
cout << is(sym_C, sym_A) << endl; // false. different instance
cout << (sym_C == sym_A) << endl; // true, sane content
return 0;
}
the symmetry object
Definition Symmetry.hpp:153
static Symmetry U1()
create a U1 symmetry object
Definition Symmetry.hpp:210
Helper function to print vector with ODT:
Definition Accessor.hpp:12

output>

1
1
0
1

python API:

import sys
from pathlib import Path
home = str(Path.home())
sys.path.append(home + '/Cytnx_lib')
from cytnx import *
sym_A = Symmetry.U1()
sym_C = Symmetry.U1()
sym_D = sym_A
print(sym_D is sym_A) #true
print(sym_D == sym_A) #true
print(sym_C is sym_A) #false
print(sym_C == sym_A) #true

output>

True
True
False
True

◆ combine_rule() [1/2]

cytnx_int64 cytnx::Symmetry::combine_rule ( const cytnx_int64 inL,
const cytnx_int64 inR,
const bool &  is_reverse = false 
) const
inline

apply combine rule of current symmetry to two quantum numbers.

Parameters
[in]inLthe #1 quantum number.
[in]inRthe #2 quantum number.
Returns
the combined quantum number.

◆ combine_rule() [2/2]

std::vector< cytnx_int64 > cytnx::Symmetry::combine_rule ( const std::vector< cytnx_int64 > &  inL,
const std::vector< cytnx_int64 > &  inR 
)
inline

apply combine rule of current symmetry to two quantum number lists.

Parameters
[in]inLthe #1 quantum number list that is to be combined.
[in]inRthe #2 quantum number list that is to be combined.
Returns
the combined quantum numbers.

◆ combine_rule_() [1/2]

void cytnx::Symmetry::combine_rule_ ( cytnx_int64 out,
const cytnx_int64 inL,
const cytnx_int64 inR,
const bool &  is_reverse = false 
)
inline

apply combine rule of current symmetry to two quantum numbers, and store the combined quntun number into parameter

Parameters
out.
[out]outthe output quantum number.
[in]inLthe #1 quantum number.
[in]inRthe #2 quantum number.

◆ combine_rule_() [2/2]

void cytnx::Symmetry::combine_rule_ ( std::vector< cytnx_int64 > &  out,
const std::vector< cytnx_int64 > &  inL,
const std::vector< cytnx_int64 > &  inR 
)
inline

apply combine rule of current symmetry to two quantum number lists, and store it into parameter out.

Parameters
[out]outthe output quantum number list.
[in]inLthe #1 quantum number list that is to be combined.
[in]inRthe #2 quantum number list that is to be combined.

◆ Load() [1/2]

static Symmetry cytnx::Symmetry::Load ( const char *  fname)
static

◆ Load() [2/2]

static Symmetry cytnx::Symmetry::Load ( const std::string &  fname)
static

Load a Symmetry object from a file.

Parameters
[in]fnamethe file name.
Precondition
the file extension must be ".cysym".
Returns
the loaded Symmetry object.

◆ n()

int & cytnx::Symmetry::n ( ) const
inline

return the descrete n of current Symmetry object.

Returns
[int]
Note
  1. for U1, n=1 will be returned.
  2. for Zn, n is the descrete symmetry number. (ex: Z2, n=2)

◆ operator!=()

bool cytnx::Symmetry::operator!= ( const Symmetry rhs) const

the inequality operator of the Symmetry object.

◆ operator==()

bool cytnx::Symmetry::operator== ( const Symmetry rhs) const

the equality operator of the Symmetry object.

◆ print_info()

void cytnx::Symmetry::print_info ( ) const
inline

Print the information of current Symmetry object.

◆ reverse_rule()

cytnx_int64 cytnx::Symmetry::reverse_rule ( const cytnx_int64 in) const
inline

Apply reverse rule of current symmetry to a given quantum number and return the result.

that means, \( o = -i \), where \( o \) is the reverse quantum number, and \( i \) is the input quantum number in.

Parameters
[in]inthe input quantum number.
Returns
the reverse quantum number.

◆ reverse_rule_()

void cytnx::Symmetry::reverse_rule_ ( cytnx_int64 out,
const cytnx_int64 in 
)
inline

Apply reverse rule of current symmetry to a given quantum number and store in parameter out.

that means, \( o = -i \), where \( o \) is the output quantum number out, and \( i \) is the input quantum number in.

Parameters
[out]outthe output quantum number.
[in]inthe input quantum number.

◆ Save() [1/2]

void cytnx::Symmetry::Save ( const char *  fname) const

◆ Save() [2/2]

void cytnx::Symmetry::Save ( const std::string &  fname) const

Save the current Symmetry object to a file.

Parameters
[in]fnamethe file name.
Postcondition
the file extension will be automatically added as ".cysym".

◆ stype()

int cytnx::Symmetry::stype ( ) const
inline

return the symmetry type-id of current Symmetry object, see cytnx::SymType.

Returns
[int] the symmetry type-id.

◆ stype_str()

std::string cytnx::Symmetry::stype_str ( ) const
inline

return the symmetry type name of current Symmetry object in string form, see cytnx::SymType.

Returns
[std::string] the symmetry type name.

◆ U1()

static Symmetry cytnx::Symmetry::U1 ( )
inlinestatic

create a U1 symmetry object

valid qnum value range:

\f$(-\infty , \infty)\f$

combine rule:

Q + Q

description:

create a new U1 symmetry object that serive as a generator. The symmetry object is a property of Bond . It is used to identify the symmetry of the quantum number set, as well as providing the combining rule for the quantum number when Bonds are combined.

Example:

c++ API:

#include "cytnx.hpp"
#include <iostream>
using namespace cytnx;
using namespace std;
int main() {
/* 1.
create a U1 symmetry object
*/
Symmetry sym_u1 = Symmetry::U1();
/* 2.
using with Bond to define a bond with symmetry.
*/
Bond bd_sym_u1_a = Bond(4, BD_KET, {{0}, {-4}, {-2}, {3}}, {sym_u1});
Bond bd_sym_u1_b = Bond(4, BD_KET, {{0}, {-4}, {-2}, {3}}); // default is U1 symmetry
cout << bd_sym_u1_a << endl;
cout << bd_sym_u1_b << endl;
cout << (bd_sym_u1_a == bd_sym_u1_b) << endl; // true
Bond bd_sym_u1_c = Bond(5, BD_KET, {{-1}, {1}, {2}, {-2}, {0}});
cout << bd_sym_u1_c << endl;
/* 3.
new qnums will be calculated using Symmetry::combine_rule.
*/
Bond bd_sym_all = bd_sym_u1_a.combineBond(bd_sym_u1_c);
cout << bd_sym_all << endl;
return 0;
}
the object contains auxiliary properties for each Tensor rank (bond)
Definition Bond.hpp:178
Bond combineBond(const Bond &bd_in, const bool &is_grp=true) const
combine the input bond with self, and return a new combined Bond instance.
Definition Bond.hpp:553
@ BD_KET
Definition Bond.hpp:34

output>

Dim = 4 |type: KET>
 U1::  +0 -4 -2 +3

Dim = 4 |type: KET>
 U1::  +0 -4 -2 +3

1
Dim = 5 |type: KET>
 U1::  -1 +1 +2 -2 +0

Dim = 20 |type: KET>
 U1::  -1 +1 +2 -2 +0 -5 -3 -2 -6 -4 -3 -1 +0 -4 -2 +2 +4 +5 +1 +3

python API:

import sys
from pathlib import Path
home = str(Path.home())
sys.path.append(home + '/Cytnx_lib')
from cytnx import *
sym_u1 = Symmetry.U1();
bd_sym_u1_a = Bond(4,BD_KET,[[0],[-4],[-2],[3]],[sym_u1])
bd_sym_u1_b = Bond(4,BD_KET,[[0],[-4],[-2],[3]]) #default is U1 symmetry
print(bd_sym_u1_a)
print(bd_sym_u1_b)
print(bd_sym_u1_a == bd_sym_u1_b,flush=True) #true
bd_sym_u1_c = Bond(5,BD_KET,[[-1],[1],[2],[-2],[0]])
print(bd_sym_u1_c)
bd_sym_all = bd_sym_u1_a.combineBond(bd_sym_u1_c)
print(bd_sym_all)
new_bd_sym_u1_a = Bond(BD_KET,[[0],[-4],[-2],[3]], [1,1,1,1],[sym_u1])
new_bd_sym_u1_b = Bond(BD_KET,[[0],[-4],[-2],[3]], [1,1,1,1]) #default is U1 symmetry
print(new_bd_sym_u1_a)
print(new_bd_sym_u1_b)
print(new_bd_sym_u1_a == new_bd_sym_u1_b,flush=True) #true
new_bd_sym_u1_c = Bond(BD_KET,[[-1],[1],[2],[-2],[0]], [1,1,1,1,1])
print(new_bd_sym_u1_c)
new_bd_sym_all = new_bd_sym_u1_a.combineBond(new_bd_sym_u1_c)
print(new_bd_sym_all)

output>

Dim = 4 |type: KET>
 U1::   +0  -4  -2  +3


Dim = 4 |type: KET>
 U1::   +0  -4  -2  +3


True
Dim = 5 |type: KET>
 U1::   -1  +1  +2  -2  +0


Dim = 20 |type: KET>
 U1::   -1  +1  +2  -2  +0  -5  -3  -2  -6  -4  -3  -1  +0  -4  -2  +2  +4  +5  +1  +3


Dim = 4 |type: KET>
 U1::   +0  -4  -2  +3
Deg>>    1   1   1   1


Dim = 4 |type: KET>
 U1::   +0  -4  -2  +3
Deg>>    1   1   1   1


True
Dim = 5 |type: KET>
 U1::   -1  +1  +2  -2  +0
Deg>>    1   1   1   1   1


Dim = 20 |type: KET>
 U1::   -6  -5  -4  -3  -2  -1  +0  +1  +2  +3  +4  +5
Deg>>    1   1   2   2   3   2   2   2   2   1   1   1

◆ Zn()

static Symmetry cytnx::Symmetry::Zn ( const int &  n)
inlinestatic

create a Zn descrete symmetry object with \(n\in\mathbb{N}\)

valid qnum value range:

\f$[0 , n)\f$

combine rule:

(Q + Q)%n

description:

create a new Zn descrete symmetry object with integer \( n \) that serive as a generator. The symmetry object is a property of Bond . It is used to identify the symmetry of the quantum number set, as well as providing the combining rule for the quantum number when Bonds are combined.

Example:

c++ API:

#include "cytnx.hpp"
#include <iostream>
using namespace cytnx;
using namespace std;
int main() {
// example of Z2 symmetry object
//------------------------------------
// 1. create Z2 object
Symmetry sym_z2 = Symmetry::Zn(2);
/* 2.
using with Bond to define a bond with symmetry.
Note that the qnums should obey the valid value range of the correspond symmetry.
with Z2 = [0,2)
*/
Bond bd_sym_z2_A = Bond(4, BD_KET, {{0}, {0}, {1}, {1}}, {sym_z2});
Bond bd_sym_z2_B = Bond(3, BD_KET, {{0}, {1}, {1}}, {sym_z2});
cout << bd_sym_z2_A << endl;
cout << bd_sym_z2_B << endl;
/* 3.
new qnums will be calculated internally using Symmetry::combine_rule.
*/
Bond bd_sym_z2all = bd_sym_z2_A.combineBond(bd_sym_z2_B);
cout << bd_sym_z2all << endl;
// example of Z4 symmetry object
//------------------------------------
// 1. create Z4 object
Symmetry sym_z4 = Symmetry::Zn(4);
/* 2.
using with Bond to define a bond with symmetry.
Note that the qnums should obey the valid value range of the correspond symmetry.
with Z4 = [0,4)
*/
Bond bd_sym_z4_A = Bond(4, BD_KET, {{0}, {3}, {1}, {2}}, {sym_z4});
Bond bd_sym_z4_B = Bond(3, BD_KET, {{2}, {3}, {1}}, {sym_z4});
cout << bd_sym_z4_A << endl;
cout << bd_sym_z4_B << endl;
/* 3.
new qnums will be calculated internally using Symmetry::combine_rule.
*/
Bond bd_sym_z4all = bd_sym_z4_A.combineBond(bd_sym_z4_B);
cout << bd_sym_z4all << endl;
return 0;
}
static Symmetry Zn(const int &n)
create a Zn descrete symmetry object with
Definition Symmetry.hpp:241

output>

Dim = 4 |type: KET>
 Z2::  +0 +0 +1 +1

Dim = 3 |type: KET>
 Z2::  +0 +1 +1

Dim = 12 |type: KET>
 Z2::  +0 +1 +1 +0 +1 +1 +1 +0 +0 +1 +0 +0

Dim = 4 |type: KET>
 Z4::  +0 +3 +1 +2

Dim = 3 |type: KET>
 Z4::  +2 +3 +1

Dim = 12 |type: KET>
 Z4::  +2 +3 +1 +1 +2 +0 +3 +0 +2 +0 +1 +3

python API:

import sys
from pathlib import Path
home = str(Path.home())
sys.path.append(home + '/Cytnx_lib')
from cytnx import *
#example of Z2 symmetry object
#------------------------------------
sym_z2 = Symmetry.Zn(2);
bd_sym_z2_A = Bond(4,BD_KET,[[0],[0],[1],[1]],[sym_z2])
bd_sym_z2_B = Bond(3,BD_KET,[[0],[1],[1]],[sym_z2])
print(bd_sym_z2_A)
print(bd_sym_z2_B)
bd_sym_z2all = bd_sym_z2_A.combineBond(bd_sym_z2_B)
print(bd_sym_z2all)
#example of Z4 symmetry object
#------------------------------------
sym_z4 = Symmetry.Zn(4)
bd_sym_z4_A = Bond(4,BD_KET,[[0],[3],[1],[2]],[sym_z4])
bd_sym_z4_B = Bond(3,BD_KET,[[2],[3],[1]],[sym_z4])
print(bd_sym_z4_A)
print(bd_sym_z4_B)
bd_sym_z4all = bd_sym_z4_A.combineBond(bd_sym_z4_B)
print(bd_sym_z4all)
#bk example of Z2 symmetry object
#------------------------------------
new_sym_z2 = Symmetry.Zn(2);
new_bd_sym_z2_A = Bond(BD_KET,[[0],[0],[1],[1]],[1,1,1,1],[new_sym_z2])
new_bd_sym_z2_B = Bond(BD_KET,[[0],[1],[1]],[1,1,1],[new_sym_z2])
print(new_bd_sym_z2_A)
print(new_bd_sym_z2_B)
new_bd_sym_z2all = new_bd_sym_z2_A.combineBond(new_bd_sym_z2_B)
print(new_bd_sym_z2all)
#bk example of Z4 symmetry object
#------------------------------------
new_sym_z4 = Symmetry.Zn(4)
new_bd_sym_z4_A = Bond(BD_KET,[[0],[3],[1],[2]],[1,1,1,1],[new_sym_z4])
new_bd_sym_z4_B = Bond(BD_KET,[[2],[3],[1]],[1,1,1],[new_sym_z4])
print(new_bd_sym_z4_A)
print(new_bd_sym_z4_B)
new_bd_sym_z4all = new_bd_sym_z4_A.combineBond(new_bd_sym_z4_B)
print(new_bd_sym_z4all)

output>

Dim = 4 |type: KET>
 Z2::   +0  +0  +1  +1


Dim = 3 |type: KET>
 Z2::   +0  +1  +1


Dim = 12 |type: KET>
 Z2::   +0  +1  +1  +0  +1  +1  +1  +0  +0  +1  +0  +0


Dim = 4 |type: KET>
 Z4::   +0  +3  +1  +2


Dim = 3 |type: KET>
 Z4::   +2  +3  +1


Dim = 12 |type: KET>
 Z4::   +2  +3  +1  +1  +2  +0  +3  +0  +2  +0  +1  +3


Dim = 4 |type: KET>
 Z2::   +0  +0  +1  +1
Deg>>    1   1   1   1


Dim = 3 |type: KET>
 Z2::   +0  +1  +1
Deg>>    1   1   1


Dim = 12 |type: KET>
 Z2::   +0  +1
Deg>>    6   6


Dim = 4 |type: KET>
 Z4::   +0  +3  +1  +2
Deg>>    1   1   1   1


Dim = 3 |type: KET>
 Z4::   +2  +3  +1
Deg>>    1   1   1


Dim = 12 |type: KET>
 Z4::   +0  +1  +2  +3
Deg>>    3   3   3   3

The documentation for this class was generated from the following file: