Misplaced Pages

Topswops

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
Mathematical problems devised by John Conway
This article is an orphan, as no other articles link to it. Please introduce links to this page from related articles; try the Find link tool for suggestions. (January 2021)

Topswops (and the variants Topdrops, Bottomswops and Bottomdrops) are mathematical problems devised and analysed by the British mathematician John Conway in 1973. Contrary to other games and problems introduced by Conway, these problems have not received much attention from the scientific community. Two famous mathematicians who have contributed to the problem are Martin Gardner and Donald Knuth.

A Topswops example with N = 5 {\displaystyle N=5} numbers. The algorithm ends after 7 iterations.

Formulation

In each variant of the problem, Conway uses a deck of playing cards. Since the numerical values of the deck are only relevant, only one suit is used. This is mathematically equivalent to a row of integers from 1 {\displaystyle 1} to N {\displaystyle N} . A shuffled pile of cards is written as A [ 1 ] , . . . , A [ N ] {\displaystyle A,...,A} .

Topswops

For topswops the following algorithm is applied:

  1. Consider the first card from the pile (which is A [ 1 ] {\displaystyle A} )
  2. Take the first A [ 1 ] {\displaystyle A} cards from the pile
  3. Swap these cards and place them back on the pile
  4. Repeat step 1, 2 and 3 until the top card is 1 {\displaystyle 1}

The final configuration of the row always starts with 1 {\displaystyle 1} . The topswops problem is occasionally named differently, with naming including deterministic pancake problem, topswops, topswaps, reverse card shuffle and fannkuch.

The problem formulated by Conway is the following:

Which initial configuration leads to the maximum number of 'swops' before the algorithm terminates?

In literature there are some attempts to find lower and upper bounds for the number of iterations f ( N ) {\displaystyle f(N)} .

Theorem: f ( N ) {\displaystyle f(N)} is bounded by 2 N 1 {\displaystyle 2^{N-1}} .

Proof by Herbert S. Wilf: Consider a permutation A [ 1 ] {\displaystyle A} to A [ N ] {\displaystyle A} of the row 1 {\displaystyle 1} to N {\displaystyle N} . As an example, we consider 7 , 2 , 11 , 8 , 5 , 13 , 6 , 1 , 9 , 10 , 3 , 12 , 4 {\displaystyle 7,2,11,8,5,13,6,1,9,10,3,12,4} . We are specifically interested in numbers which are at 'the correct position'. These are: 2, 5, 9, 10, 12. We define the Wilf number as 2 ( 2 1 ) + 2 ( 5 1 ) + 2 ( 9 1 ) + 2 ( 10 1 ) + 2 ( 12 1 ) = 2833 {\displaystyle 2^{(2-1)}+2^{(5-1)}+2^{(9-1)}+2^{(10-1)}+2^{(12-1)}=2833} .

Claim: after each iteration of the algorithm, the Wilf number increases.

Proof: We perform one iteration of the algorithm. Every number at 'the correct position' and larger than A [ 1 ] {\displaystyle A} , leaves the Wilf number unchanged. The remaining numbers at 'the correct position' will in general not be at 'the correct position' anymore. Nevertheless, the A [ 1 ] {\displaystyle A} 's number is at the correct position. And since the sum of the first A [ 1 ] 1 {\displaystyle A-1} Wilf numbers is always smaller than the Wilf number of A [ 1 ] {\displaystyle A} , the total Wilf number always increases (with at least 1 per iteration of the algorithm). {\displaystyle \square }

The maximal Wilf number is found when each number is at the correct position. So the maximal Wilf number is 2 N + 1 1 {\displaystyle 2^{N+1}-1} . By refining the proof, the given upper bound can be proven to be a real upper bound for the number of iterations. {\displaystyle \square }

Topswops: the relation between N {\displaystyle N} and f ( N ) {\displaystyle f(N)} in a semi-logarithmic graph. The upper bound is loose, whereas the lower bound is quite tight.
Topswops: the expected relation between N {\displaystyle N} and f ( N ) {\displaystyle f(N)} in a double logarithmic graph. The data points in the graph are only some permutated rows, and are lower bounds of the real value. The upper bound is again very loose, whereas the lower bound is relatively tight.

Theorem: f ( N ) {\displaystyle f(N)} is bounded by the ( N + 1 ) {\displaystyle (N+1)} th Fibonacci number.

Proof by Murray S. Klamkin: Suppose that during the algorithm, the first number A [ 1 ] {\displaystyle A} takes on in total k {\displaystyle k} distinct values.

Claim: f ( N ) F k + 1 {\displaystyle f(N)\leq F_{k+1}} .

Proof: We prove the claim by mathematical induction. For k = 1 {\displaystyle k=1} , the algorithm directly terminates, hence, f ( N ) = 0 {\displaystyle f(N)=0} . Thus A [ 1 ] = 1 {\displaystyle A=1} and since F 2 = 1 {\displaystyle F_{2}=1} the claim is proven.

We now take some k 2 {\displaystyle k\geq 2} . All k {\displaystyle k} values that A [ 1 ] {\displaystyle A} takes on, are ordered and can be written as: d 1 < . . . < d k {\displaystyle d_{1}<...<d_{k}} . Suppose that the largest value of these values, which is d k {\displaystyle d_{k}} , occurs for the first time at position 1 {\displaystyle 1} during iteration r {\displaystyle r} of the algorithm. Denote t = A [ d k ] {\displaystyle t=A} . During the ( r + 1 ) {\displaystyle (r+1)} 'th iteration, we know A [ 1 ] = t {\displaystyle A=t} and A [ d k ] = d k {\displaystyle A=d_{k}} . The remaining iterations will always retain A [ d k ] = d k {\displaystyle A=d_{k}} . Hence A [ 1 ] {\displaystyle A} can now take on at most k 1 {\displaystyle k-1} values. Using induction for k {\displaystyle k} , it follows that f ( N ) r F k {\displaystyle f(N)-r\leq F_{k}} and also that d 1 = 1 {\displaystyle d_{1}=1} . {\displaystyle \square }

Suppose we would exchange d 1 = 1 {\displaystyle d_{1}=1} and d k {\displaystyle d_{k}} in iteration r {\displaystyle r} Then A [ 1 ] = 1 {\displaystyle A=1} and the algorithm terminates; f ( N ) = r {\displaystyle f(N)=r} . During the algorithm, we are sure that both d k {\displaystyle d_{k}} and t {\displaystyle t} have never been at position A [ 1 ] {\displaystyle A} , unless t = 1 {\displaystyle t=1} .

Suppose t = 1 {\displaystyle t=1} . Then r F k {\displaystyle r\leq F_{k}} since A [ 1 ] {\displaystyle A} takes on at most k 1 {\displaystyle k-1} distinct values. So it follows that f ( N ) r + 1 F k + 1 {\displaystyle f(N)\leq r+1\leq F_{k+1}} .

Suppose t > 1 {\displaystyle t>1} . Then r F k 1 {\displaystyle r\leq F_{k-1}} since A [ 1 ] {\displaystyle A} takes on at most k 2 {\displaystyle k-2} distinct values. Using the claim, it follows that f ( N ) F k + r F k + 1 {\displaystyle f(N)\leq F_{k}+r\leq F_{k+1}} . This proves the theorem. {\displaystyle \square }

Besides these results, Morales and Sudborough have recently proven that the lower bound for f ( N ) {\displaystyle f(N)} is a quadratic function in N {\displaystyle N} . The optimal values are, however, still unknown. There have been several attempts to find the optimal values, for example by A. Pepperdine. For rows with 19 or fewer numbers, the exact solution is known. Larger rows only have lower bounds, which is shown on the right.

row length 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
maximal number of iterations 0 1 2 4 7 10 16 22 30 38 51 65 80 101 113 139 159 191 221

It is yet unknown whether this problem is NP-hard.

Topdrops

A similar problem is topdrops, where the same playing cards are used. In this problem, the first card of the pile is shown (and has value A [ 1 ] {\displaystyle A} ). Take the first A [ 1 ] {\displaystyle A} cards of the pile, change the order and place them back on the bottom of the pile (which contrasts topswops, where the cards are placed at the top). This problem allows for infinite loops. As an example, we consider the row 2,1,3,4. By applying the algorithm, the following sequence is obtained:

  • 2 1 3 4
  • 3 4 1 2
  • 2 1 4 3
  • 4 3 1 2
  • 2 1 3 4

whereafter the original row is found again.

Botswops

In this variant, the bottom card of the pile is taken (and again named A [ 1 ] {\displaystyle A} ). Then the first A [ 1 ] {\displaystyle A} cards of the pile are swapped. Unless the bottom card is the highest card in the pile, nothing happens. This makes the problem uninteresting due to the limited behaviour.

Botdrops

The final variant is botdrops where the bottom card of the pile is taken (again A [ 1 ] {\displaystyle A} ). In this variant, the bottom A [ 1 ] {\displaystyle A} cards are swapped.

References

  1. ^ Morales, Linda; Sudborough, Hal (2010). "A quadratic lower bound for Topswops" (PDF). Theoretical Computer Science. 411 (44–46): 3965–3970. doi:10.1016/j.tcs.2010.08.011.
  2. ^ Gardner, Martin (1987). "6". Time Travel and Other Mathematical Bewilderments. New York: W. H. Freeman & Co. pp. 76–82. ISBN 978-0716719250.
  3. Knuth, Donald E. (2002). The Art of computer programming: Volume 4, Fascicle 2A: Generating all n-tuples. Addison-Wesley. pp. 74, 119–120. ISBN 978-0201853933.
  4. Klamkin, Murray S. (1990). Problems in Applied Mathematics: Selections from SIAM review. SIAM. pp. 74, 115–117. ISBN 978-0898712599.
  5. Pepperdine, Andy (1989). "73.23 Topswops". The Mathematical Association. 73 (464): 131–133. doi:10.2307/3619674. JSTOR 3619674. A renewed version of the article can be found on https://www.pepsplace.org.uk/Trivia/Topswops/Topswops.pdf. {{cite journal}}: External link in |quote= (help)

External links

Categories: