Template Function sequant::count_cycles

Function Documentation

template<typename Seq0, typename Seq1>
std::size_t sequant::count_cycles(Seq0 &&v0, Seq1 &&v1)

Returns the number of (spin) loops in a closed-shell trace.

Interprets v0 and v1 as the column-paired index slots of a contracted tensor network: slot i is one particle slot of one tensor, holding v0[i] in one row and v1[i] in the other (e.g. ket and bra). Two slots must carry the same spin if they are (a) the two rows of the same column (a column edge v0[i]—v1[i]) or (b) the two occurrences of the same (contracted) index value (a contraction edge). Every internal slot then has degree two, so this graph is a disjoint union of cycles and the number of connected components is the number of independent spin loops (each loop contributes a factor of two in the closed-shell trace).

Unlike a 2-line-permutation reading, this is agnostic to which row a value sits in: a contraction may be covariant (one occurrence in v0, one in v1) or, for bra-ket-symmetric (Hermitian/real) tensors that have been reoriented, both occurrences in the same row (bra-bra / ket-ket). The component count is invariant under such bra<->ket swaps and reduces to the permutation’s cycle count whenever v0 is a permutation of v1.

Template Parameters:
  • Seq0 – (reference to) a container type

  • Seq1 – (reference to) a container type

Parameters:
  • v0 – first row of index slots

  • v1 – second row of index slots (v1[i] is column-paired with v0[i])

Pre:

v0 and v1 have equal size and every value occurs in exactly two slots across v0 and v1 combined

Returns:

the number of connected components (spin loops)