Learn to Use ITensor

main / classes / index


An Index represents a single tensor index with fixed dimension. Copies of an Index compare equal unless their tags are different.

An Index carries a TagSet, a set of tags which are small strings that specify properties of the Index to help distinguish it from other Indices. There is a special tag which is referred to as the integer tag or prime level which can be incremented or decremented with special priming functions.

Internally, an Index has a fixed id number, which is how the ITensor library knows two indices are copies of a single original Index. Index objects must have the same id, as well as the tags to compare equal.

Index is defined in "itensor/index.h".


auto i = Index(4);
Print(dim(i)); //prints: dim(i) = 4

//Copies of the same Index compare equal
auto ii = i; //ii is a copy of i
Print(ii == i); //prints: true

//The prime level of an Index can be
//adjusted to make it distinct
Print(primeLevel(ii)); //prints: primeLevel(ii) = 2
Print(ii == i); //prints: false

Print(ii == i); //prints: true

// Index objects can also hold a set of up to four tags
auto j = Index(5,"j,Link");
Print(hasTags(j,"j")); //prints: true
Print(hasTags(j,"j,Link")); //prints: true

// Tags can be added to or removed from an index
// Indices must have the same tags to compare equal

Print(tags(i)); //prints: 

auto ia = addTags(i,"a");
Print(tags(ia)); //prints: a
Print(ia == i); //prints: false
Print(removeTags(ia,"a") == i); //prints: true

auto iab = addTags(ia,"b");
Print(tags(iab)); //prints: a,b
Print(hasTags(iab,"b,a")); //prints: true
Print(removeTags(iab,"b") == ia); //prints: true

auto iap = prime(ia);
Print(tags(iap)); //prints: (a)'
Print(primeLevel(iap) == 1); //prints: true


Accessor Methods

Comparison Methods

Tag Methods

Index properties

Operators and Conversions

Reading and Writing

Other Functions

This page current as of version 3.0.0

Back to Classes
Back to Main