TBTK
Need a break? Support the development by playing Polarity Puzzles
TBTK::Subindex Class Reference

An entry in an Index. More...

#include <Subindex.h>

Inheritance diagram for TBTK::Subindex:
TBTK::PseudoSerializable

Public Member Functions

 Subindex ()
 
constexpr Subindex (Integer value)
 
constexpr Subindex (int value)
 
constexpr Subindex (unsigned int value)
 
 Subindex (const std::string &serialization, Serializable::Mode mode)
 
bool isWildcard () const
 
bool isLabeledWildcard () const
 
Subindex getWildcardLabel () const
 
bool isSummationIndex () const
 
bool isRangeIndex () const
 
bool isSpinIndex () const
 
bool isIndexSeparator () const
 
constexpr operator int () const
 
Subindexoperator= (Integer rhs)
 
Subindexoperator= (int rhs)
 
Subindexoperator+= (Subindex rhs)
 
Subindexoperator-= (Subindex rhs)
 
Subindexoperator*= (Subindex rhs)
 
Subindexoperator/= (Subindex rhs)
 
Subindexoperator++ ()
 
Subindex operator++ (int)
 
Subindexoperator-- ()
 
Subindex operator-- (int)
 
Subindex operator() (unsigned int label) const
 
std::string serialize (Serializable::Mode mode) const
 

Friends

std::ostream & operator<< (std::ostream &os, const Subindex subindex)
 
std::istream & operator>> (std::istream &is, Subindex &subindex)
 
void to_json (nlohmann::json &j, const Subindex &subindex)
 
void from_json (const nlohmann::json &j, Subindex &subindex)
 

Detailed Description

An entry in an Index.

A Subindex is an integer value with some added functionality and is meant to be an entry in an Index. Conversion between Subindex and int is implicit and the Subindex can therefore for most practical purposes be considered an int.

Subindices can have any value in the range [-16777215, 2147483647]. Values that are more negative than -16777215 (0x00FFFFFF) are reserved for special purposes. The following flags can be used to specify that a given Subindex have a special meaning:

IDX_ALL = _a_
Wildcard indicating that any Subindex value is acceptable. Can also be used when a specific Subindex in an Index has lost meaning. For example, when a Subindex has been summed over, but the resulting quantity retains the same Index structure.

The symbol _a_ is meant to simplify the syntax in application code. However, the more descriptive IDX_ALL should always be used in library code.

IDX_SUM_ALL
Indicates that the Subindex should be summed over.

IDX_SPIN:
Indicates that the Subindex corresponds to a spin Subindex.

IDX_SEPARATOR
Used to separate compound Indices such as {{1, 2}, {3, 4}}, which is stored as {1, 2, IDX_SEPARATOR, 3, 4}.

IDX_ALL_ = aX
Labeled wildcard. Similar to IDX_ALL, but two labeled wildcards with the same label are required to agree. Labels are attached using the notation IDX_ALL_(label). For example, {IDX_ALL_(0), 1, IDX_ALL_(1), IDX_ALL_(0), IDX_ALL_(1)} indicates that all indices of the form {m, 1, n, m, n} are of interest.

The symbol _a_ is meant to simplify the syntax in application code. However, the more descriptive IDX_ALL should always be used in library code.

IDX_X, IDX_Y, IDX_Z
Indicates that the Subindex should be looped over some range. IDX_X, IDX_Y, and IDX_Z indicates the first, second, and third range Subindex, respectively.

The Subindex also have functions for checking whether a given Subindex corresponds to one of the flags above.

Example

#include "TBTK/Index.h"
#include "TBTK/Subindex.h"
#include "TBTK/Streams.h"
#include "TBTK/TBTK.h"
using namespace TBTK;
int main(){
Index index({1, 2, IDX_ALL, IDX_SUM_ALL, IDX_SPIN, IDX_X, IDX_ALL_(1)});
Streams::out << index << "\n";
Streams::out << index[0] << "\n";
Streams::out << index[1] << "\n";
for(unsigned int n = 0; n < index.getSize(); n++){
if(index[n].isWildcard())
Streams::out << "Wildcard: " << n << "\n";
if(index[n].isSummationIndex())
Streams::out << "Summation index: " << n << "\n";
if(index[n].isSpinIndex())
Streams::out << "Spin index: " << n << "\n";
if(index[n].isRangeIndex())
Streams::out << "Range index: " << n << "\n";
if(index[n].isLabeledWildcard())
Streams::out << "Labeled wildcard: " << n << "\n";
}
Streams::out << "Wildcard label: " << index[6].getWildcardLabel()
<< "\n";
}

Output

{1, 2, IDX_ALL, IDX_SUM_ALL, IDX_SPIN, IDX_X, IDX_ALL_(1)}
1
2
Wildcard: 2
Summation index: 3
Spin index: 4
Range index: 5
Labeled wildcard: 6
Wildcard label: 1

Constructor & Destructor Documentation

◆ Subindex() [1/5]

TBTK::Subindex::Subindex ( )
inline

Constructor.

◆ Subindex() [2/5]

constexpr TBTK::Subindex::Subindex ( Integer  value)
inlineconstexpr

Constructor.

Parameters
valueThe value to initilize the Subindex with.

◆ Subindex() [3/5]

constexpr TBTK::Subindex::Subindex ( int  value)
inlineconstexpr

Constructor.

Parameters
valueThe value to initilize the Subindex with.

◆ Subindex() [4/5]

constexpr TBTK::Subindex::Subindex ( unsigned int  value)
inlineconstexpr

Constructor.

Parameters
valueThe value to initilize the Subindex with.

◆ Subindex() [5/5]

TBTK::Subindex::Subindex ( const std::string &  serialization,
Serializable::Mode  mode 
)
inline

Constructs a Subindex from a serialization string.

Parameters
serializationSerialization string from which to construct the Subindex.
modeMode with which the string has been serialized.

Member Function Documentation

◆ getWildcardLabel()

Subindex TBTK::Subindex::getWildcardLabel ( ) const
inline

Get the label of a labeled wildcard. Exits if the Subindex is not a wildcard.

Returns
The label of the wildcard.

◆ isIndexSeparator()

bool TBTK::Subindex::isIndexSeparator ( ) const
inline

Check if the Subindex is an Index separator (IDX_SEPARATOR).

Returns
True if the Subindex is an Index separator, otherwise false.

◆ isLabeledWildcard()

bool TBTK::Subindex::isLabeledWildcard ( ) const
inline

Check if the Subindex is a labeled wildcard (IDX_ALL_X).

Returns
True if the Subindex is a labeled sildcard, otherwise false.

◆ isRangeIndex()

bool TBTK::Subindex::isRangeIndex ( ) const
inline

Check if the Subindex is a range index (IDX_RANGE).

Returns
True if the Subindex is a range index, otherwise false.

◆ isSpinIndex()

bool TBTK::Subindex::isSpinIndex ( ) const
inline

Check if the Subindex is a spin index (IDX_SPIN).

Returns
True if the SUbindex is a spin index, otherwise false.

◆ isSummationIndex()

bool TBTK::Subindex::isSummationIndex ( ) const
inline

Check if the Subindex is a summation index (IDX_SUM_ALL).

Returns
True if the Subindex is a summation index, otherwise false.

◆ isWildcard()

bool TBTK::Subindex::isWildcard ( ) const
inline

Check if the Subindex is a wildcard (IDX_ALL).

Returns
True if the Subindex is a wildcard, otherwise false.

◆ operator int()

constexpr TBTK::Subindex::operator int ( ) const
inlineconstexpr

Type conversion operator.

◆ operator()()

Subindex TBTK::Subindex::operator() ( unsigned int  label) const
inline

Function call operator. Used to attach labels to predefined labeled Subindices. For example IDX_ALL_(n) can be used to define an nth labeled wildcard index. The function call fails if the Index is not of a type that supports labels. Note that if the label is so large that it has non-zero bits outside of the non-zero bits of IDX_FLAG_MASK, the highest valued bits will be truncted.

Parameters
labelThe label.
Returns
A new Subindex with the label attached.

◆ operator*=()

Subindex& TBTK::Subindex::operator*= ( Subindex  rhs)
inline

Multiplication asignment operator.

Parameters
rhsThe right hand side.
Returns
The subindex after assignment has occured.

◆ operator++() [1/2]

Subindex& TBTK::Subindex::operator++ ( )
inline

Increment operator.

Returns
The Subindex after the increment has occured.

◆ operator++() [2/2]

Subindex TBTK::Subindex::operator++ ( int  )
inline

Increment operator.

Returns
The Subindex before the increment has occured.

◆ operator+=()

Subindex& TBTK::Subindex::operator+= ( Subindex  rhs)
inline

Addition asignment operator.

Parameters
rhsThe right hand side.
Returns
The subindex after assignment has occured.

◆ operator--() [1/2]

Subindex& TBTK::Subindex::operator-- ( )
inline

Decrement operator.

Returns
The Subindex after the decrement has occured.

◆ operator--() [2/2]

Subindex TBTK::Subindex::operator-- ( int  )
inline

Decrement operator.

Returns
The Subindex before the decrement has occured.

◆ operator-=()

Subindex& TBTK::Subindex::operator-= ( Subindex  rhs)
inline

Subtraction asignment operator.

Parameters
rhsThe right hand side.
Returns
The subindex after assignment has occured.

◆ operator/=()

Subindex& TBTK::Subindex::operator/= ( Subindex  rhs)
inline

Division asignment operator.

Parameters
rhsThe right hand side.
Returns
The subindex after assignment has occured.

◆ operator=() [1/2]

Subindex& TBTK::Subindex::operator= ( int  rhs)
inline

Assignment operator.

Parameters
valueThe value to assign the Subindex.
Returns
The Subindex after assignment has occured.

◆ operator=() [2/2]

Subindex& TBTK::Subindex::operator= ( Integer  rhs)
inline

Assignment operator.

Parameters
valueThe value to assign the Subindex.
Returns
The Subindex after assignment has occured.

◆ serialize()

std::string TBTK::Subindex::serialize ( Serializable::Mode  mode) const
inline

Serialize Subindex. Note that Subindex is PseudoSerializable rather than Serializable. This means that the Serializable interface is implemented non-virtually.

Parameters
modeSerialization mode.
Returns
Serialized string representation of the Subindex.

Friends And Related Function Documentation

◆ from_json

void from_json ( const nlohmann::json &  j,
Subindex subindex 
)
friend

Implements the Nlohmann json interface for conversion from json.

Parameters
jThe json input.
subindexThe Subindex to convert to.

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const Subindex  subindex 
)
friend

ostream operator.

Parameters
osThe ostream to write to.
rhsThe Subindex to write.
Returns
The ostream.

◆ operator>>

std::istream& operator>> ( std::istream &  is,
Subindex subindex 
)
friend

istream operator.

Parameters
osThe istream to read from.
rhsThe Subindex to read to.
Returns
The istream.

◆ to_json

void to_json ( nlohmann::json &  j,
const Subindex subindex 
)
friend

Implements the Nlohmann json interface for conversion to json.

Parameters
jThe json output.
subindexThe Subindex to convert.

The documentation for this class was generated from the following file:
TBTK::Subindex::isSummationIndex
bool isSummationIndex() const
Definition: Subindex.h:437
Index.h
Physical index.
Streams.h
Streams for TBTK output.
Subindex.h
An entry in an Index.
TBTK::Subindex::isLabeledWildcard
bool isLabeledWildcard() const
Definition: Subindex.h:419
TBTK::Initialize
void Initialize()
TBTK::Subindex::isRangeIndex
bool isRangeIndex() const
Definition: Subindex.h:441
TBTK::Subindex::isWildcard
bool isWildcard() const
Definition: Subindex.h:415
TBTK::Subindex::isSpinIndex
bool isSpinIndex() const
Definition: Subindex.h:445
TBTK::Streams::out
static std::ostream out
Definition: Streams.h:70
TBTK::Index
Physical index.
Definition: Index.h:44
TBTK.h
TBTK initialization.