Topswops

{{Short description|Mathematical problems devised by John Conway}}

{{Orphan|date=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.

File:Voorbeeld N=5.png

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 to N. A shuffled pile of cards is written as A[1], ..., A[N].

=Topswops=

For topswops the following algorithm is applied:

  1. Consider the first card from the pile (which is A[1])
  2. Take the first A[1] 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

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

| doi = 10.1016/j.tcs.2010.08.011

| last1=Morales

| first1=Linda

| last2=Sudborough

| first2=Hal

| year = 2010

| title = A quadratic lower bound for Topswops

| journal = Theoretical Computer Science

| volume = 411

| issue = 44–46

| pages = 3965–3970

| url = https://core.ac.uk/download/pdf/82158940.pdf| doi-access = free

}}{{Cite book| last = Gardner| first = Martin| date = 1987| title = Time Travel and Other Mathematical Bewilderments| chapter = 6| publisher = W. H. Freeman & Co| location = New York| isbn = 978-0716719250| pages = [https://archive.org/details/timetravelotherm0000gard/page/76 76–82]| chapter-url = https://archive.org/details/timetravelotherm0000gard/page/76}}{{Cite book| last = Knuth| first = Donald E.| date = 2002| title = The Art of computer programming: Volume 4, Fascicle 2A: Generating all n-tuples| publisher = Addison-Wesley| isbn = 978-0201853933 | pages = 74, 119–120}}

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).

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

Proof by Herbert S. Wilf: Consider a permutation A[1] to A[N] of the row 1 to N. As an example, we consider 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.

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], 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]'s number is at the correct position. And since the sum of the first A[1]-1 Wilf numbers is always smaller than the Wilf number of A[1], the total Wilf number always increases (with at least 1 per iteration of the algorithm). \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. By refining the proof, the given upper bound can be proven to be a real upper bound for the number of iterations. \square

File:Topswops small N english.png. The upper bound is loose, whereas the lower bound is quite tight.]]

File:Topswops large N english.png. 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) is bounded by the (N+1)th Fibonacci number.

Proof by Murray S. Klamkin:{{Cite book| last = Klamkin| first = Murray S.| date = 1990| title = Problems in Applied Mathematics: Selections from SIAM review| publisher = SIAM| isbn = 978-0898712599| pages = [https://archive.org/details/problemsinapplie0000unse/page/74 74, 115–117]| url = https://archive.org/details/problemsinapplie0000unse/page/74}} Suppose that during the algorithm, the first number A[1] takes on in total k distinct values.

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

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

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

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

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

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

Besides these results, Morales and Sudborough have recently proven that the lower bound for f(N) is a quadratic function in N. The optimal values are, however, still unknown. There have been several attempts to find the optimal values, for example by A. Pepperdine.{{Cite journal

| doi = 10.2307/3619674

| author= Pepperdine, Andy

| year = 1989

| title = 73.23 Topswops

| journal = The Mathematical Association

| volume = 73

| issue = 464

| pages = 131–133

| quote = A renewed version of the article can be found on https://www.pepsplace.org.uk/Trivia/Topswops/Topswops.pdf.

| jstor= 3619674

}} For rows with 19 or fewer numbers, the exact solution is known. Larger rows only have lower bounds, which is shown on the right.

class="wikitable"
row lengthscope="col" style="width: 20px;"|1scope="col" style="width: 20px;"|2scope="col" style="width: 20px;"|3scope="col" style="width: 20px;"|4scope="col" style="width: 20px;"|5scope="col" style="width: 20px;"|6scope="col" style="width: 20px;"|7scope="col" style="width: 20px;"|8scope="col" style="width: 20px;"|9scope="col" style="width: 20px;"|10scope="col" style="width: 20px;"|11scope="col" style="width: 20px;"|12scope="col" style="width: 20px;"|13scope="col" style="width: 20px;"|14scope="col" style="width: 20px;"|15scope="col" style="width: 20px;"|16scope="col" style="width: 20px;"|17

!18

!19

style="text-align:center;"

| maximal number of iterations

012471016223038516580101113139159

|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]). Take the first A[1] 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]). Then the first A[1] 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]). In this variant, the bottom A[1] cards are swapped.

== References ==

{{Reflist}}