<?xml version="1.0" encoding="UTF-8" standalone="yes"?><oembed><version><![CDATA[1.0]]></version><provider_name><![CDATA[The ryg blog]]></provider_name><provider_url><![CDATA[https://fgiesen.wordpress.com]]></provider_url><author_name><![CDATA[fgiesen]]></author_name><author_url><![CDATA[https://fgiesen.wordpress.com/author/fgiesen/]]></author_url><title><![CDATA[Triangular numbers mod&nbsp;2^n]]></title><type><![CDATA[link]]></type><html><![CDATA[<p>The <a href="http://en.wikipedia.org/wiki/Triangular_number">triangular numbers</a></p>
<p><img src="https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+T_k+%3A%3D+%5Csum_%7Bj%3D1%7D%5Ek+j+%3D+%5Cbinom%7Bk%2B1%7D%7B2%7D+%3D+%5Cfrac%7Bk%28k%2B1%29%7D%7B2%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+T_k+%3A%3D+%5Csum_%7Bj%3D1%7D%5Ek+j+%3D+%5Cbinom%7Bk%2B1%7D%7B2%7D+%3D+%5Cfrac%7Bk%28k%2B1%29%7D%7B2%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+T_k+%3A%3D+%5Csum_%7Bj%3D1%7D%5Ek+j+%3D+%5Cbinom%7Bk%2B1%7D%7B2%7D+%3D+%5Cfrac%7Bk%28k%2B1%29%7D%7B2%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="&#92;displaystyle T_k := &#92;sum_{j=1}^k j = &#92;binom{k+1}{2} = &#92;frac{k(k+1)}{2}" class="latex" /></p>
<p>are a standard sequence used in <a href="http://en.wikipedia.org/wiki/Quadratic_probing">quadratic probing</a> of <a href="http://en.wikipedia.org/wiki/Hash_table#Open_addressing">open hash tables</a>. For example, they&#8217;re <a href="http://goog-sparsehash.sourceforge.net/doc/implementation.html">used</a> in Google&#8217;s <code>sparse_hash</code> and <code>dense_hash</code>, generally considered to be very competitive hash table implementations.</p>
<p>You can find lots of places on the web mentioning that the resulting probe sequence will visit every element of a power-of-2 sized hash table exactly once; more precisely, the function <img src="https://s0.wp.com/latex.php?latex=f%28k%29+%3D+T_k+%5Cmod+2%5Em&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=f%28k%29+%3D+T_k+%5Cmod+2%5Em&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=f%28k%29+%3D+T_k+%5Cmod+2%5Em&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="f(k) = T_k &#92;mod 2^m" class="latex" /> is a permutation on <img src="https://s0.wp.com/latex.php?latex=%5C%7B+0%2C+1%2C+%5Cdots%2C+2%5Em-1+%5C%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%5C%7B+0%2C+1%2C+%5Cdots%2C+2%5Em-1+%5C%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%5C%7B+0%2C+1%2C+%5Cdots%2C+2%5Em-1+%5C%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="&#92;{ 0, 1, &#92;dots, 2^m-1 &#92;}" class="latex" />. But it&#8217;s pretty hard to find a proof; everybody seems to refer back to Knuth, and in The Art of Compute Programming, Volume 3, Chapter 6.4, the proof appears as an exercise (number 20 in the Second Edition).</p>
<p>If you want to do this exercise yourself, please stop reading now; spoilers ahead!</p>
<p>Anyway, turns out I arrived at the solution very differently from Knuth. His proof is much shorter and slicker, but pretty &#8220;magic&#8221; and unmotivated, so let&#8217;s take the scenic route! The first step is to look at a bunch of small values and see if we can spot any patterns.</p>
<table>
<tr>
<th style="text-transform:none;">k</th>
<td>0</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
</tr>
<tr>
<th style="text-transform:none;">T<sub>k</sub></th>
<td>0</td>
<td>1</td>
<td>3</td>
<td>6</td>
<td>10</td>
<td>15</td>
<td>21</td>
<td>28</td>
<td>36</td>
<td>45</td>
<td>55</td>
<td>66</td>
</tr>
<tr>
<th style="text-transform:none;">T<sub>k</sub> mod 8</th>
<td>0</td>
<td>1</td>
<td>3</td>
<td>6</td>
<td>2</td>
<td>7</td>
<td>5</td>
<td>4</td>
<td>4</td>
<td>5</td>
<td>7</td>
<td>2</td>
</tr>
<tr>
<th style="text-transform:none;">T<sub>k</sub> mod 4</th>
<td>0</td>
<td>1</td>
<td>3</td>
<td>2</td>
<td>2</td>
<td>3</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>1</td>
<td>3</td>
<td>2</td>
</tr>
<tr>
<th style="text-transform:none;">T<sub>k</sub> mod 2</th>
<td>0</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>1</td>
<td>1</td>
<td>0</td>
</tr>
</table>
<p>And indeed, there are several patterns that might be useful: looking at the row for &#8220;mod 2&#8221;, we see that it seems to be just the values 0, 1, 1, 0 repeating, and that sequence itself is just 0, 1 followed by its reverse. The row for &#8220;mod 4&#8221; likewise looks like it&#8217;s just alternating between normal and reverse copies of 0, 1, 3, 2, and the &#8220;mod 8&#8221; row certainly looks like it might be following a similar pattern. Can we prove this?</p>
<p>First, the mirroring suggests that it might be worthwhile to look at the differences</p>
<p><img src="https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+T_%7B2n-1-k%7D+-+T_k+%3D+%5Cbinom%7B2n-k%7D%7B2%7D+-+%5Cbinom%7Bk%2B1%7D%7B2%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+T_%7B2n-1-k%7D+-+T_k+%3D+%5Cbinom%7B2n-k%7D%7B2%7D+-+%5Cbinom%7Bk%2B1%7D%7B2%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+T_%7B2n-1-k%7D+-+T_k+%3D+%5Cbinom%7B2n-k%7D%7B2%7D+-+%5Cbinom%7Bk%2B1%7D%7B2%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="&#92;displaystyle T_{2n-1-k} - T_k = &#92;binom{2n-k}{2} - &#92;binom{k+1}{2}" class="latex" /><br />
<img src="https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%3D+%282n-k%29%282n+-+%28k%2B1%29%29%2F2+-+%28k%2B1%29k%2F2&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%3D+%282n-k%29%282n+-+%28k%2B1%29%29%2F2+-+%28k%2B1%29k%2F2&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%3D+%282n-k%29%282n+-+%28k%2B1%29%29%2F2+-+%28k%2B1%29k%2F2&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="&#92;displaystyle = (2n-k)(2n - (k+1))/2 - (k+1)k/2" class="latex" /><br />
<img src="https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%3D+2n%5E2+-+n%282k%2B1%29+%2B+k%28k%2B1%29%2F2+-+k%28k%2B1%29%2F2&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%3D+2n%5E2+-+n%282k%2B1%29+%2B+k%28k%2B1%29%2F2+-+k%28k%2B1%29%2F2&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%3D+2n%5E2+-+n%282k%2B1%29+%2B+k%28k%2B1%29%2F2+-+k%28k%2B1%29%2F2&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="&#92;displaystyle = 2n^2 - n(2k+1) + k(k+1)/2 - k(k+1)/2" class="latex" /><br />
<img src="https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%3D+2n%5E2+-+n%282k%2B1%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%3D+2n%5E2+-+n%282k%2B1%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%3D+2n%5E2+-+n%282k%2B1%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="&#92;displaystyle = 2n^2 - n(2k+1)" class="latex" /></p>
<p>Both terms are multiples of n, so we have <img src="https://s0.wp.com/latex.php?latex=T_%7B2n-1-k%7D+-+T_k+%5Cequiv+0+%5Cpmod%7Bn%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=T_%7B2n-1-k%7D+-+T_k+%5Cequiv+0+%5Cpmod%7Bn%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=T_%7B2n-1-k%7D+-+T_k+%5Cequiv+0+%5Cpmod%7Bn%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="T_{2n-1-k} - T_k &#92;equiv 0 &#92;pmod{n}" class="latex" />, which proves the mirroring (incidentally, for any n, not just powers of 2). Furthermore, the first term is a multiple of 2n too, and the second term <em>almost</em> is: we have <img src="https://s0.wp.com/latex.php?latex=T_%7B2n-1-k%7D+-+T_k+%5Cequiv+-n+%5Cpmod%7B2n%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=T_%7B2n-1-k%7D+-+T_k+%5Cequiv+-n+%5Cpmod%7B2n%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=T_%7B2n-1-k%7D+-+T_k+%5Cequiv+-n+%5Cpmod%7B2n%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="T_{2n-1-k} - T_k &#92;equiv -n &#92;pmod{2n}" class="latex" />. This will come in handy soon.</p>
<p>To prove that <img src="https://s0.wp.com/latex.php?latex=T_k+%5Cbmod+n&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=T_k+%5Cbmod+n&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=T_k+%5Cbmod+n&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="T_k &#92;bmod n" class="latex" /> is 2n-periodic, first note the standard identity for triangular numbers</p>
<p><img src="https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+T_%7Ba%2Bb%7D+%3D+%5Csum_%7Bj%3D1%7D%5E%7Ba%2Bb%7D+j+%3D+%5Csum_%7Bj%3D1%7D%5Ea+j+%2B+%5Csum_%7Bj%3Da%2B1%7D%5E%7Ba%2Bb%7D+j+%3D+T_a+%2B+%5Csum_%7Bj%3D1%7D%5E%7Bb%7D+%28j+%2B+a%29+&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+T_%7Ba%2Bb%7D+%3D+%5Csum_%7Bj%3D1%7D%5E%7Ba%2Bb%7D+j+%3D+%5Csum_%7Bj%3D1%7D%5Ea+j+%2B+%5Csum_%7Bj%3Da%2B1%7D%5E%7Ba%2Bb%7D+j+%3D+T_a+%2B+%5Csum_%7Bj%3D1%7D%5E%7Bb%7D+%28j+%2B+a%29+&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+T_%7Ba%2Bb%7D+%3D+%5Csum_%7Bj%3D1%7D%5E%7Ba%2Bb%7D+j+%3D+%5Csum_%7Bj%3D1%7D%5Ea+j+%2B+%5Csum_%7Bj%3Da%2B1%7D%5E%7Ba%2Bb%7D+j+%3D+T_a+%2B+%5Csum_%7Bj%3D1%7D%5E%7Bb%7D+%28j+%2B+a%29+&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="&#92;displaystyle T_{a+b} = &#92;sum_{j=1}^{a+b} j = &#92;sum_{j=1}^a j + &#92;sum_{j=a+1}^{a+b} j = T_a + &#92;sum_{j=1}^{b} (j + a) " class="latex" /><br />
<img src="https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%3D+T_a+%2B+%5Csum_%7Bj%3D1%7D%5Eb+j+%2B+ab+%3D+T_a+%2B+T_b+%2B+ab&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%3D+T_a+%2B+%5Csum_%7Bj%3D1%7D%5Eb+j+%2B+ab+%3D+T_a+%2B+T_b+%2B+ab&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%3D+T_a+%2B+%5Csum_%7Bj%3D1%7D%5Eb+j+%2B+ab+%3D+T_a+%2B+T_b+%2B+ab&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="&#92;displaystyle = T_a + &#92;sum_{j=1}^b j + ab = T_a + T_b + ab" class="latex" /></p>
<p>in particular, we have</p>
<p><img src="https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+T_%7Bk+%2B+2n%7D+%3D+T_k+%2B+T_%7B2n%7D+%2B+2kn+%3D+T_k+%2B+n%282n%2B1%29+%2B+2kn+%5Cequiv+T_k+%5Cpmod%7Bn%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+T_%7Bk+%2B+2n%7D+%3D+T_k+%2B+T_%7B2n%7D+%2B+2kn+%3D+T_k+%2B+n%282n%2B1%29+%2B+2kn+%5Cequiv+T_k+%5Cpmod%7Bn%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+T_%7Bk+%2B+2n%7D+%3D+T_k+%2B+T_%7B2n%7D+%2B+2kn+%3D+T_k+%2B+n%282n%2B1%29+%2B+2kn+%5Cequiv+T_k+%5Cpmod%7Bn%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="&#92;displaystyle T_{k + 2n} = T_k + T_{2n} + 2kn = T_k + n(2n+1) + 2kn &#92;equiv T_k &#92;pmod{n}" class="latex" /></p>
<p>Again, this is for arbitrary n &ge; 1. So far, we&#8217;ve proven that for arbitrary positive integer n, the sequence <img src="https://s0.wp.com/latex.php?latex=T_k+%5Cbmod+n&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=T_k+%5Cbmod+n&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=T_k+%5Cbmod+n&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="T_k &#92;bmod n" class="latex" /> is 2n-periodic, with the second half being a mirrored copy of the first half. It turns out that we can wrangle this one fact into a complete proof of the <img src="https://s0.wp.com/latex.php?latex=T_k+%5Cbmod+2%5Em&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=T_k+%5Cbmod+2%5Em&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=T_k+%5Cbmod+2%5Em&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="T_k &#92;bmod 2^m" class="latex" />, 0 &le; k &lt; 2<sup>m</sup> being a permutation fairly easily by using induction:</p>
<p><b>Basis</b> (m=0): <img src="https://s0.wp.com/latex.php?latex=T_k+%5Cbmod+1%3D0&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=T_k+%5Cbmod+1%3D0&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=T_k+%5Cbmod+1%3D0&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="T_k &#92;bmod 1=0" class="latex" />, and the function <img src="https://s0.wp.com/latex.php?latex=f_0%280%29+%3A%3D+0&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=f_0%280%29+%3A%3D+0&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=f_0%280%29+%3A%3D+0&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="f_0(0) := 0" class="latex" /> is a permutation on { 0 }.<br />
<b>Inductive step</b>: Suppose <img src="https://s0.wp.com/latex.php?latex=f_m%28k%29+%3A%3D+T_k+%5Cbmod+2%5Em&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=f_m%28k%29+%3A%3D+T_k+%5Cbmod+2%5Em&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=f_m%28k%29+%3A%3D+T_k+%5Cbmod+2%5Em&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="f_m(k) := T_k &#92;bmod 2^m" class="latex" /> is a permutation on <img src="https://s0.wp.com/latex.php?latex=%5C%7B+0%2C+%5Cdots%2C+2%5Em-1+%5C%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%5C%7B+0%2C+%5Cdots%2C+2%5Em-1+%5C%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%5C%7B+0%2C+%5Cdots%2C+2%5Em-1+%5C%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="&#92;{ 0, &#92;dots, 2^m-1 &#92;}" class="latex" />. Then the values of <img src="https://s0.wp.com/latex.php?latex=f_%7Bm%2B1%7D%28k%29+%3D+T_k+%5Cbmod+2%5E%7Bm%2B1%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=f_%7Bm%2B1%7D%28k%29+%3D+T_k+%5Cbmod+2%5E%7Bm%2B1%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=f_%7Bm%2B1%7D%28k%29+%3D+T_k+%5Cbmod+2%5E%7Bm%2B1%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="f_{m+1}(k) = T_k &#92;bmod 2^{m+1}" class="latex" /> must surely be pairwise distinct for 0 &le; k &lt; 2<sup>m</sup>, since they&#8217;re already distinct mod 2<sup>m</sup>. That means we only have to deal with the second half. But above (taking n=2<sup>m</sup>), we proved that</p>
<p><img src="https://s0.wp.com/latex.php?latex=f_%7Bm%2B1%7D%282%5E%7Bm%2B1%7D-1-k%29+%3D+T_%7B2%5E%7Bm%2B1%7D-1-k%7D+%5Cequiv+T_k+-+2%5Em+%5Cpmod%7B2%5E%7Bm%2B1%7D%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=f_%7Bm%2B1%7D%282%5E%7Bm%2B1%7D-1-k%29+%3D+T_%7B2%5E%7Bm%2B1%7D-1-k%7D+%5Cequiv+T_k+-+2%5Em+%5Cpmod%7B2%5E%7Bm%2B1%7D%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=f_%7Bm%2B1%7D%282%5E%7Bm%2B1%7D-1-k%29+%3D+T_%7B2%5E%7Bm%2B1%7D-1-k%7D+%5Cequiv+T_k+-+2%5Em+%5Cpmod%7B2%5E%7Bm%2B1%7D%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="f_{m+1}(2^{m+1}-1-k) = T_{2^{m+1}-1-k} &#92;equiv T_k - 2^m &#92;pmod{2^{m+1}}" class="latex" /></p>
<p>and letting k run from 0 to 2<sup>m</sup>-1, we notice that mod 2<sup>m</sup>, these values are congruent to the values in the first half, but mod 2<sup>m+1</sup>, they differ by an additional term of -n. This implies that the values in the second half are pairwise distinct both from the first half and from each other. This proves that f<sub>m+1</sub> is injective, and because it&#8217;s mapping the 2<sup>m+1</sup>-element set <img src="https://s0.wp.com/latex.php?latex=%5C%7B+0%2C+%5Cdots%2C+2%5E%7Bm%2B1%7D+-+1+%5C%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%5C%7B+0%2C+%5Cdots%2C+2%5E%7Bm%2B1%7D+-+1+%5C%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%5C%7B+0%2C+%5Cdots%2C+2%5E%7Bm%2B1%7D+-+1+%5C%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="&#92;{ 0, &#92;dots, 2^{m+1} - 1 &#92;}" class="latex" /> onto itself, it must be a permutation.</p>
<p>Which, by mathematical induction, proves our claim.</p>
]]></html></oembed>