Intersection of QN Indices, Padding of Indices

Hey there,

I wanted to ask if there is a function available for calculating the intersection of two
indices, i.e. a function, lets call it intersect(j1::Index, j2::Index) which takes
two QN symmetric indices and calculates j_1 \cap j_2 returning a new index having all QN sectors which appear in both indices and every degeneracy dimension of the QN sector is given by the minimum of the degeneracy sectors appearing in j_1 and j_2.

My second question is connected to the the function directsum(j1::Index, j2::Index) which creates a direct sum of the two Hilbertspaces represented by the two indices j1 and j2. However, in the case of QN symmetric indices, it creates a Index where QN sectors appearing in both original indices appears twice instead of only once. For example, consider the simple code fragment:

j1 = Index([QN(0) => 2, QN(1) => 3])
j2 = Index([QN(-1) => 3, QN(0) => 2])
jc = directsum(j1, j2)

I would assume jc to have the Hilbertspace structure

[QN(-1) => 3, QN(0) => 4, QN(1) => 3]

i.e. QN(-1) and QN(1) which appeared only in one of the two original indices are appearing one to one in jc, while the sector QN(0) which appears in both indices appears with a degeneracy dimension being the sum of the two original ones.

Instead of this behavior, the function creates as an output an index with the structure:

[QN(-1) => 3, QN(0) => 2, QN(2) => 2, QN(1) => 3]

I.e. it simply concatenates the two Hilbertspaces. Is the internal structure of ITensors such that this list will be handled equally to the first case where the two QN(0) spaces are combined to one?

Thanks for your help!

You can use combinedind(combiner(directsum(j1, j2))) to get the Index with the QN blocks packed together. directsum takes the spaces literally (doesn’t pack the QNs together) since that is what has been needed by algorithms that make use of directsum, and I think makes sense mathematically as the definition of a direct sum. ITensor will be fine working with indices where the QNs aren’t packed together, though some operations might be a bit slow since you may end up with more (smaller sized) blocks in the tensors. However, that isn’t always the case and sometimes it can be better to have QNs split apart like that since it can allow the tensor to be more sparse.

I see. That makes sense. In the mean time I used mergeblocks on the space of an index to make sure every sector only appears once (only need the space anyways).