Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The behaviour of the algorithm can be modelled as a <a href="http://en.wikipedia.org/wiki/Markov_chain" rel="noreferrer">Markov chain</a> over the <a href="http://en.wikipedia.org/wiki/Symmetric_group" rel="noreferrer">symmetric group</a> <em>S<sub>N</sub></em>.</p> <h1>Basics</h1> <p>The <em>N</em> elements of the array <code>A</code> can be arranged in <em>N</em>! different permutations. Let us number these permutations from 1 to <em>N</em>!, e.g. by lexicographic ordering. So the state of the array <code>A</code> at any time in the algorithm can be fully characterized by the permutation number.</p> <p>For example, for <em>N</em> = 3, one possible numbering of all 3! = 6 permutations might be:</p> <ol> <li>a b c</li> <li>a c b</li> <li>b a c</li> <li>b c a</li> <li>c a b</li> <li>c b a</li> </ol> <h1>State transition probabilities</h1> <p>In each step of the algorithm, the state of <code>A</code> either stays the same or transitions from one of these permutations to another. We are now interested in the probabilities of these state changes. Let us call <strong>Pr(<em>i</em> → <em>j</em>)</strong> the probability that the state changes from permutation <em>i</em> to permutation <em>j</em> in a single loop iteration.</p> <p>As we pick <em>m</em> and <em>n</em> uniformly and independently from the range [0, <em>N</em>-1], there are <em>N</em>² possible outcomes, each of which is equally likely.</p> <h2>Identity</h2> <p>For <em>N</em> of these outcomes <em>m</em> = <em>n</em> holds, so there is no change in the permutation. Therefore,</p> <blockquote> <p><img src="https://i.stack.imgur.com/4sFaR.png" alt="Pr(i→i)">.</p> </blockquote> <h2>Transpositions</h2> <p>The remaining <em>N</em>² - <em>N</em> cases are transpositions, i.e. two elements exchange their positions and therefore the permutation changes. Suppose one of these transpositions exchanges the elements at positions <em>x</em> and <em>y</em>. There are two cases how this transposition can be generated by the algorithm: either <em>m = x</em>, <em>n = y</em> or <em>m = y</em>, <em>n = x</em>. Thus, the probability for each transposition is 2 / <em>N</em>².</p> <p>How does this relate to our permutations? Let us call two permutations <em>i</em> and <em>j</em> <strong>neighbors</strong> if and only if there is a transposition which transforms <em>i</em> into <em>j</em> (and vice versa). We then can conclude:</p> <blockquote> <p><img src="https://i.stack.imgur.com/3tdqo.png" alt="Pr(i→j)"></p> </blockquote> <h1>Transition matrix</h1> <p>We can arrange the probabilities Pr(<em>i</em> → <em>j</em>) in a transition matrix <strong>P</strong> ∈ [0,1]<sup><em>N</em>!×<em>N</em>!</sup>. We define</p> <blockquote> <p><em>p<sub>ij</sub></em> = Pr(<em>i</em> → <em>j</em>),</p> </blockquote> <p>where <em>p<sub>ij</sub></em> is the entry in the <em>i</em>-th row and <em>j</em>-th column of <strong>P</strong>. Note that</p> <blockquote> <p>Pr(<em>i</em> → <em>j</em>) = Pr(<em>j</em> → <em>i</em>),</p> </blockquote> <p>which means <strong>P</strong> is symmetric.</p> <p>The key point now is the observation of what happens when we multiply <strong>P</strong> by itself. Take any element <em>p</em><sup>(2)</sup><sub><em>ij</em></sub> of <strong>P</strong>²:</p> <blockquote> <p><img src="https://i.stack.imgur.com/sYmCX.png" alt="p(2)ij"></p> </blockquote> <p>The product Pr(<em>i</em> → <em>k</em>) · Pr(<em>k</em> → <em>j</em>) is the probability that starting at permutation <em>i</em> we transition into permutation <em>k</em> in one step, and transition into permutation <em>j</em> after another subsequent step. Summing over all in-between permutations <em>k</em> therefore gives us the total probability of <strong>transitioning from <em>i</em> to <em>j</em> in 2 steps</strong>.</p> <p>This argument can be extended to higher powers of <strong>P</strong>. A special consequence is the following:</p> <blockquote> <p><strong><em>p</em><sup>(<em>N</em>)</sup><sub><em>ii</em></sub> is the probability of returning back to permutation <em>i</em> after <em>N</em> steps, assuming we started at permutation <em>i</em>.</strong></p> </blockquote> <h1>Example</h1> <p>Let's play this through with <em>N</em> = 3. We already have a numbering for the permutations. The corresponding transition matrix is as follows:</p> <blockquote> <p><img src="https://i.stack.imgur.com/HFj0A.png" alt="P"></p> </blockquote> <p>Multiplying <strong>P</strong> with itself gives:</p> <blockquote> <p><img src="https://i.stack.imgur.com/nnRAh.png" alt="P²"></p> </blockquote> <p>Another multiplication yields:</p> <blockquote> <p><img src="https://i.stack.imgur.com/ZSdTO.png" alt="P³"></p> </blockquote> <p>Any element of the main diagonal gives us the wanted probability, which is <sup>15</sup>/<sub>81</sub> or <sup>5</sup>/<sub>27</sub>.</p> <h1>Discussion</h1> <p>While this approach is mathematically sound and can be applied to any value of <em>N</em>, it is not very practical in this form. The transition matrix <strong>P</strong> has <em>N</em>!² entries, which becomes huge very fast. Even for <em>N</em> = 10 the size of the matrix already exceeds 13 trillion entries. A naive implementation of this algorithm therefore appears to be infeasible.</p> <p>However, in comparison to other proposals, this approach is very structured and doesn't require complex derivations beyond figuring out which permutations are neighbors. My hope is that this structuredness can be exploited to find a much simpler computation.</p> <p>For example, one could exploit the fact that all diagonal elements of any power of <strong>P</strong> are equal. Assuming we can easily calculate the trace of <strong>P</strong><sup><em>N</em></sup>, the solution is then simply tr(<strong>P</strong><sup><em>N</em></sup>) / <em>N</em>!. The trace of <strong>P</strong><sup><em>N</em></sup> is equal to the sum of the <em>N</em>-th powers of its eigenvalues. So if we had an efficient algorithm to compute the eigenvalues of <strong>P</strong>, we would be set. I haven't explored this further than calculating the eigenvalues up to <em>N</em> = 5, however.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload