Template Function sequant::count_cycles¶
Defined in File permutation.hpp
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
v0andv1as the column-paired index slots of a contracted tensor network: slotiis one particle slot of one tensor, holdingv0[i] in one row andv1[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 edgev0[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 inv1) 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 wheneverv0is a permutation ofv1.- 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 withv0[i])
- Pre:
v0andv1have equal size and every value occurs in exactly two slots acrossv0andv1combined- Returns:
the number of connected components (spin loops)