3
$\begingroup$

We have two sequences $a = (a_1, a_2, \ldots, a_n)$ and $b = (b_1, b_2, \ldots, b_n)$ which can be related by permutation. What is the number of cyclic permutations of length $k$ which permute $a$ into $b$?

If $a=b$, then we have the sum of the numbers of $k$-cyclic permutations for each of the possible values of $a_i$. That is, if $a$ has $l_1,l_2,\ldots l_n$ entries equal to $1,2,\ldots,n$, respectively, then the total number of permutations which relate $a$ to itself is

$$ N_k(a,a) = \sum_{i=1}^{n} (k-1)!\binom{l_i}{k} $$

For $a=(1,1,1,2,2,2)$ and $k=3$, we have $N_3(a,a)=4$ 3-cycle permutations, $$ (123),\ (132),\ (456),\ (465), $$ and $N_2(a,a)=6$ 2-cycle permutations, $$ (12),\ (13),\ (23),\ (45),\ (46),\ (56). $$

The case with $a=b$, of course, has a Hamming distance $d=0$.

What is the number of cyclic permutations for cases of Hamming distances $d>0$?


In quantum mechanics, this is basically asking for the matrix elements of $\sum_{i<j}^n (ij)$, $\sum_{i<j<k}^n (ijk) + (ikj)$, etc. in the product-space basis:

\begin{align} N_2(a,b) &= \langle a_1a_2\cdots a_n\vert\sum_{i<j}^n (ij) \vert b_1b_2\cdots b_n\rangle \\ N_3(a,b) &= \langle a_1a_2\cdots a_n\vert\sum_{i<j<k}^n (ijk)+(ikj) \vert b_1b_2\cdots b_n\rangle \end{align}

$\endgroup$
7
  • 1
    $\begingroup$ It does not seem to have a really good representation... Even if $d=k$ it can be reduced from a problem of counting the number of Eulerian Cycles for a directed Eulerian graph, and with $d<k$, it is much more complicated... $\endgroup$ Commented Sep 4, 2024 at 4:55
  • 1
    $\begingroup$ So what's this question asks is basically counting the number of ''Eulerian cycles'' of a directed graph. It has $d$ edges (connecting two distinct points) but also some self loops. You want to find the number of directed cycles of the graph such that it traverses all the edges and some of the self loops. All the edges/self loops are treated as labeled ones. The BEST theorem Can handle the case without these self loops, but with self loops I am a bit pessimistic about whether there exists an efficient algorithm to count... $\endgroup$ Commented Sep 4, 2024 at 5:12
  • $\begingroup$ Can you explain how this maps to a directed graph? I'm not quite sure I understand what the edges are representing... I'm assuming the vertices are the sequences themselves? $\endgroup$ Commented Sep 4, 2024 at 18:12
  • $\begingroup$ The vertices are different values of your sequences. The edges and self loops are every index: draw edges $a_i\to b_i$ (view them as values) for all $i$ amd label the edge/self loop as $i$. $\endgroup$ Commented Sep 4, 2024 at 21:37
  • $\begingroup$ Gotcha, now I see how this works. (Actually, if you draw the edges as $a_i \leftarrow b_i$ then you can read off the permutation directly. If you draw the edges $a_i \rightarrow b_i$ then you have to read backwards to get the permutation.) So it seems to me that this is at least a well-formulated problem in terms of a graph traversal problem. But as you say, finding an efficient algorithm seems... unlikely. $\endgroup$ Commented Sep 4, 2024 at 22:03

1 Answer 1

1
$\begingroup$

As @JetfiRex pointed out in the comments, this can be translated into a problem of counting the number of Eulerian cycles of a directed graph.


Let $V=\{ a_i \} = \{b_i\}$ be the set of all elements which appear in the sequences $a$ and $b$. Let $E = \{ a_i \overset{i}{\leftarrow} b_i\ |\ 1 \leq i \leq n \}$ denote the mappings (i.e. labeled directed edges) between the initial and final values of each position in the sequences. Any cycle for the graph $G=(V,E)$ (i.e. a walk through the graph which traverses each edge once) is a valid permutation which relates $a$ and $b$. For example, for the sequences $$ a = (\alpha,\alpha,\beta,\beta,\beta,\gamma) \qquad b = (\alpha,\beta,\beta,\gamma,\beta,\alpha) $$ the associated graph is

directed graph for permutations between sequences a and b

The cycle as $\beta \rightarrow\alpha\rightarrow\gamma\rightarrow\beta$ corresponds to the permutation $(264)$ and the cycle $\beta\rightarrow\alpha\rightarrow\alpha\rightarrow\gamma\rightarrow\beta$ corresponds to the permutation $(21643)$.


The Eulerian cycles of this graph are all the $n$-cycle permutations which take $a$ to $b$. We can calculate the number of Eulerian cycles using the BEST theorem

$$\tag{1}\label{1} \operatorname{ec}(G) = t_w(G) \prod_{v\in V} \bigl(\deg(v)-1\bigr)! $$ where $t_w(G)$ is the number of arborescences and $\deg(v)$ is the indegree of vertex $v$. We can use Kirchhoff's theorem to calculate $t_w(g)$. We construct the graph's Laplacian matrix $Q=D-A$, where $D$ is the degree matrix of the graph (the diagonal matrix of vertex indegrees) and $A$ is the (weighted) adjacency matrix. We then have that $$\tag{2} t_w(G) = \det(Q^*) $$ where $t_w(G)$ is the first cofactor of $Q$, which is the determinant of the matrix $Q^*$ formed by removing the first row and column of $Q$.


In order to calculate all of the $k$-cycle permutations, we need to find paths of length $k$ rather than of length $n$. We can do this by looking at all the subgraphs formed by removing $(n-k)$ self-loops from the graph $G$. For the example sequences $a$ and $b$, the subgraphs for $k=4$ permutations are those where two self-loops have been removed:

directed subgraphs for permutations between a and b, with two self-loops removed

Thus, we just need to apply $\eqref{1}$ to each of these graphs and add up the number of Eulerian paths. First, we can note that $Q$, and thus $t_W(G)$, is independent of the number of self-loops, since the indegree minus self-adjacency (the diagonal of $Q$) is equal to the indegree from non-self-loops. From this, we can calculate the total number of $k$-cycles: $$\tag{3}\label{3} N_k(a,b) = t_w\left(G(a,b)\right) \sum_{p\ \vdash\ (n-k)}\ \prod_{v\in V(a,b)} \binom{l_v}{p_v}(\deg(v)-p_v-1)! $$

First, we have factored $t_w(G)$ from the BEST theorem. Next, we sum over all ways of removing $p_v$ self-loops from vertex $v$, subject to the constraint that $\sum_v p_v = (n-k)$. For each vertex, we have $\binom{l_v}{p_v}$ ways of choosing which of the $l_v$ self-loops to remove (since they are labeled/distinguishable); if $p_v > l_v$ we take $\binom{l_v}{p_v}=0$. Finally, the degree of the vertex after removing $p_v$ self-loops is $(\deg(v)-p_v)$.


In the case that $G$ is not connected, then in order to have a $k$-cycle, the total number of $k$-cycles is simply the sum of \eqref{3} for each connected component. This points to a possible generalization I have not yet proven, which is that for a generic $(k_1,k_2,\ldots)$-cycle permutation, the number of permutations is the product of the $N_{k_i}$ calculated for the $i$th connected component of $G$. In that case, the number of $(4,2)$-cycle permutations would be the number of $k=4$ permutations on the first connected component times the number of $k=2$ permutations on the second connected component, plus the number of $k=4$ permutations on the second connected component times the number of $k=2$ permutations on the first connected component.

$\endgroup$
1
  • $\begingroup$ @JetfiRex Does this look right to you? I am definitely not an expert here. $\endgroup$ Commented Sep 5, 2024 at 6:42

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.