Playing Pool with |ψi:
from Bouncing Billiards to Quantum Search
Adam R. Brown
Google, Mountain View, CA 94043, USA
Department of Physics, Stanford University, Stanford, CA 94305, USA
Abstract
In “Playing Pool with π [1], Galperin invented an extraordinary method to learn the digits
of π by counting the collisions of billiard balls. Here I demonstrate an exact isomorphism
between Galperin’s bouncing billiards and Grover’s algorithm for quantum search. This
provides an illuminating way to visualize Grover’s algorithm.
email: mr.adam.brown@gmail.com
arXiv:1912.02207v2 [quant-ph] 30 Oct 2020
1 Overview
An impractical but picturesque way to determine the digits of π is to hurl a heavy ball towards
a light ball that has its back to a wall, as in Fig. 1, and then count the ensuing elastic collisions.
1
M
Figure 1: A heavy ball of mass M approaches a stationary light ball of mass 1. How many collisions ensue?
Let’s start with equal masses, M=1. At the first collision, the left ball transfers all its momen-
tum to the right ball. At the second collision, the right ball’s momentum is reversed by the
wall. At the third and final collision, the right ball transfers all its momentum back to the left
ball. In total,
M = 1 #
collisions
= 3 . (1.1)
If the left ball is much heavier than the right, then it is harder to slow down and reverse. The
heavier the left ball, the more collisions are needed,
M = 100 #
collisions
= 31 (1.2)
M = 10
6
#
collisions
= 3141 (1.3)
M = 10
20
#
collisions
= 31415926535 (1.4)
These digits look familiar! In “Playing Pool with π” [1], G. Galperin proved that this algorithm
really is spitting out the digits of π, since for M = 100
N
#
collisions
=
j
π
M
k
. (1.5)
I recommend reading the very readable Ref. [1] and watching the very watchable Ref. [2].
Let us make a seemingly abrupt shift and now turn our attention to the field of quantum
query complexity. One of the most famous algorithms in all of quantum mechanics is that of
L. Grover [3]. Grover’s algorithm provides a way to “find a needle in a quantum haystack”—
or more precisely to determine which out of d mystery functions are being implemented by a
1
black-box quantum oracle. For d 1 = 100
N
the runtime is
number of oracle calls =
j
1
4
π
d 1
k
. (1.6)
In this paper I will argue that the similarity between Eq. 1.5 and Eq. 1.6 is not a coincidence.
It’s the same squareroot, and the same π, and for the same reason. The factor of
1
4
is merely
a book-keeping anomaly arising from different accounting practices. Indeed, I will argue that
there is a precise isomorphism between bouncing billiard balls and quantum search.
2 Quantum Search
The wavefunction of a d-state system—a ‘qudit’—may in general be written as
|ψi = v
1
|1i + v
2
|2i + . . . + v
d1
|d 1i + v
d
|di, (2.7)
and conservation of probability means that throughout its evolution the state will always have
conservation of probability: hψ|ψi =
d
X
i=1
|v
i
|
2
= 1 . (2.8)
The Grover task [3] imagines we are given a black box that implements the transformation
ˆ
U
w
1 2|wihw| . (2.9)
This unitary acts on the qudit by flipping the sign of the w
th
amplitude while leaving all the
others unchanged. For example, for w = 7 we’d have
ˆ
U
7
|ψi = v
1
|1i + . . . + v
6
|6i v
7
|7i + v
8
|8i + . . . + v
d
|di. (2.10)
Our job is to figure out which
ˆ
U
w
we have been given, i.e. to determine the value of w. Making
our task harder is the fact that the value of w is not written on the box, and we are not allowed
to take a screwdriver to open the box: the rules state that the only way we are allowed to
interact with the black box is to feed states in and see what comes out.
A simple strategy to determine w is to test each possibility in turn, first |1i, then |2i, then
|3i, etc., until we come to a state whose sign is flipped. While this strategy succeeds, it succeeds
only slowly—on average we will need to use the box
1
2
d times. That is how long it takes to find
a classical needle in a classical haystack. The surprising fact that Grover discovered is that we
can do better—much better. Grover’s algorithm allows us to find w using only O(
d ) calls.
Given that we do not know the value of w, the most democratic option is to start with an
2
even superposition, and indeed that is where Grover’s algorithm begins,
|si =
1
d
|1i + |2i + . . . + |d 1i + |di
. (2.11)
We feed this into the black box, yielding
ˆ
U
w
|si, which has v
w
= v
i6=w
= 1/
d . Already this
wavefunction ‘knows’ the value of w, since
ˆ
U
w
|si 6=
ˆ
U
w
0
|si for w 6= w
0
, and so if we could deter-
mine the wavefunction directly we could solve the Grover problem in one step. But quantum
mechanics doesn’t work that way. The dramatic tension at the heart of quantum information
theory is the interplay between the quantum ‘superpower’—the ability to try all possibilities at
once—and the quantum ‘superweakness’—the limitation to always acting linearly. One conse-
quence of linearity is that only orthogonal states can be reliably distinguished. Since for large
d the states
ˆ
U
w
|si and
ˆ
U
w
0
|si are far from orthogonal, in order to determine the value of w we
must amplify the difference. But how? The most obvious move is just to plug the output back
into the black box again, but this is counterproductive since it takes us back to square one,
ˆ
U
2
w
= 1. Instead, Grover showed that our next step should be to act with
ˆ
U
s
= 2|sihs| 1. (2.12)
We can construct
ˆ
U
s
without using the black box, since it makes no reference to w and indeed
treats all basis states the same. Grover’s algorithm is then just to repeatedly iterate
ˆ
U
s
and
ˆ
U
w
.
v
w
|i
|si
|¯si
¯
p
d 1v
i6=w
Figure 2: All operations keep us on the circle defined by |θi cos θ|¯si+ sin θ|wi. The starting state |si and the
target state |wi are not exactly orthogonal, but we can define another state |¯si such that h¯s|wi = 0.
In order to analyze the effect of this iteration, it will be helpful to use an orthonormal
coordinate system. The state |si is not exactly orthogonal to |wi,
sin
¯
θ hs|wi =
1
d
, (2.13)
3
but we can find a state |¯si such that hw|¯si = 0 by defining
|¯si =
1
d 1
X
i6=w
|ii . (2.14)
Both
ˆ
U
s
and
ˆ
U
w
keep us on the circle defined by
|θi cos θ|¯si + sin θ|wi. (2.15)
On this circle,
ˆ
U
s
reflects about the |si-axis and
ˆ
U
w
reflects about the |¯si-axis,
ˆ
U
w
|θi = (1 2|wihw|) |θi = (2|¯sih¯s| 1) |θi . (2.16)
The two consecutive non-parallel reflections combine to give a rotation by 2
¯
θ,
ˆ
U
s
ˆ
U
w
|θi = |θ + 2
¯
θi. (2.17)
We will use repeated applications of
ˆ
U
s
ˆ
U
w
to rotate the state from |si (i.e. θ =
¯
θ) to |wi
(i.e. θ =
π
2
) in steps of size 2
¯
θ. For almost all d, and in particular for all d 1 = 100
N
, the
integer closest to (
π
2
¯
θ)/2
¯
θ is
π
4
d 1
, and so Grover’s algorithm calls for that many steps
ˆ
U
s
ˆ
U
w
b
π
4
d1 c
|si = |
¯
θ + 2b
π
4
d 1 c
¯
θi = |wi + O
1
d
. (2.18)
Since hw|w
0
i = 0 for w 6= w
0
, with high probability we can now just measure the qudit to learn
the value of w and successfully complete the Grover task.
2
¯
|wi
|si
|¯si
¯
|i
ˆ
U
s
ˆ
U
w
ˆ
U
s
ˆ
U
w
|i
Figure 3:
ˆ
U
w
reflects about |¯si, and
ˆ
U
s
reflects about |si. In combination,
ˆ
U
s
ˆ
U
w
gives a rotation by 2
¯
θ.
4
3 Balls to the wall
The velocity of d billiards moving on a line may be described by a d-dimensional vector, v
i
.
To make the analogy with quantum mechanics more visceral, we could write this vector in |keti
notation as
|velocityi = v
1
|1i + v
2
|2i + . . . + v
d1
|d 1i + v
d
|di. (3.19)
Elastic collisions conserve kinetic energy. If all the billiards have mass 1, and if they start with
total kinetic energy
1
2
, then throughout their evolution they will preserve
conservation of kinetic energy: hvelocity|velocityi =
d
X
i=1
|v
i
|
2
= 1 . (3.20)
To replicate the π-calculating set-up from Sec. 1, we should separate off one billiard (let us
say the wth) to be the light ball, and glue together all the other billiards to form one big heavy
ball of mass
M = d 1 . (3.21)
The glue constrains all the v
i6=w
to be the same, and then conservation of energy confines the
velocity vector to lie on the circle given by sin θ = v
w
and cos θ =
M v
i6=w
=
d 1 v
i6=w
,
|θi cos θ|¯si + sin θ|wi. (3.22)
v
w
p
Mv
i6=w
|i
|wi
|si
|¯si
¯
|¯wi
only heavy ball moving
equal velocities
only light !
ball moving
zero total !
momentum
¯
Figure 4: Conservation of energy guarantees that the velocities are stuck on the circle
1
2
v
2
w
+
1
2
Mv
2
i6=w
=
1
2
.
5
BOUNCING BILLIARDS GROVER SEARCH
all kinetic energy in light ball |wi
both balls equal velocity |si =
1
d
P
i
|ii
all kinetic energy in heavy ball |¯si =
1
d1
P
i6=w
|ii
total momentum zero |¯wi =
q
d1
d
|wi
1
d(d1)
P
i6=w
|ii
the M = d 1 billiards in big ball the d 1 wrong answers
ˆ
O
ball
=
ˆ
U
s
= 2|sihs| 1
ˆ
O
wall
=
ˆ
U
w
= 1 2|wihw|
small ball bounces back and forth alternate
ˆ
U
s
and
ˆ
U
w
velocity v
i
of ith billiard amplitude v
i
of ith eigenstate
2 × kinetic energy of ith billiard probability |v
i
|
2
of ith eigenstate
conservation of kinetic energy conservation of probability
conservation of phase space unitarity
motion purely horizontal wavefunction purely real
collision order matters operators don’t commute
ˆ
O
ball
conserves total momentum
|sihs|,
ˆ
U
s
= 0
ˆ
O
wall
conserves big-ball momentum
|¯sih¯s|,
ˆ
U
w
= 0
6
The effect of a collision will be to map this circle into itself. The exact form of the map
can be determined by considering which momentum each collision conserves. Let’s argue by
symmetry. The linear maps from a circle to itself are described by the group O(2), which has
two components: the rotations (det = +1); and the reflections (det = 1). Rotations leave no
vectors invariant, whereas reflections leave invariant the vector that points down the axis being
reflected about. Thus any O(2) map that conserves the inner product with |φi is either 1 or
the reflection
ˆ
O
|φi
2|φihφ| 1. The conserved quantities thus exactly fix the forms of the
orthogonal matrices that describe the collisions.
Collisions between the light ball and the wall,
ˆ
O
wall
.
These collisions reverse the velocity of the light ball while leaving all other velocities
unchanged v
i
(1)
δ
iw
v
i
; alternatively we can say that they conserve the momentum of
the large ball,
momentum of large ball =
X
i6=w
v
i
=
d 1 h¯s|θi . (3.23)
Since the collision conserves h¯s|θi, symmetry tells us it must enact
ˆ
O
wall
|θi =
1 2|wihw|
|θi =
2|¯sih¯s| 1
|θi =
|¯sih¯s| |wihw|
|θi . (3.24)
Collisions between the heavy ball and the light ball,
ˆ
O
ball
.
In the center-of-mass rest frame both velocities get reversed; alternatively we can say
these collisions conserve the total momentum of the balls,
total momentum =
X
i
v
i
=
d hs|θi. (3.25)
Since the collision conserves hs|θi, symmetry tells us it must enact
ˆ
O
ball
|θi =
1 2|¯wih¯w|
|θi =
2|sihs| 1
|θi =
|sihs| |¯wih¯w|
|θi. (3.26)
ˆ
O
ball
ˆ
O
ball
ˆ
O
ball
ˆ
O
wall
ˆ
O
wall
ˆ
O
wall
Figure 5: The billiard bouncing back and forth between the wall and the large ball alternates
ˆ
O
wall
and
ˆ
O
ball
.
The small ball bounces back and forth between the wall (
ˆ
O
wall
) and the large ball (
ˆ
O
ball
).
Each lap, the two reflections combine to make a rotation by 2
¯
θ, exactly as in Eq. 2.17
ˆ
O
ball
ˆ
O
wall
|θi = |θ + 2
¯
θi . (3.27)
7
All that remains is to specify the initial state. Galperin’s original π-counting plan [1] starts
in |¯si: the light ball begins at rest. To make the analogy with Grover’s algorithm perfect, we
should instead start in |si: the two balls begin with the same velocity. With this minor tweak,
the isomorphism between billiards and quantum search becomes exact.
|wi
|si
|¯si
¯
|¯w i
ˆ
O
wall
ˆ
O
ball
2
¯
|i
ˆ
O
ball
ˆ
O
wall
|i
Figure 6:
ˆ
O
wall
reflects about |¯si, and
ˆ
O
ball
reflects about |si. In combination,
ˆ
O
ball
ˆ
O
wall
gives a rotation by 2
¯
θ.
4 Discussion
The isomorphism between Grover search and the bouncing of billiards is a duality between a
discrete quantum system and a continuous classical system. The duality works for all values of
d, though it is only for d = 100
N
+ 1 that Galperin’s algorithm outputs the decimal digits of π.
Let’s examine some aspects of the duality in more detail.
Factor of Four.
There is a factor of 4 discrepancy between the collision-counting Eq. 1.5 and the query-
counting Eq. 1.6. The factor of four is really two factors of two.
One factor of 2 comes from how we count. The billiard problem counts every collision;
by contrast Grover’s problem treats
ˆ
U
s
as free and only charges for applications of
ˆ
U
w
.
The other factor of 2 comes from when we stop. Grover’s algorithm stops when the heavy
ball has transferred all its energy to the small ball to reach |wi = |θ =
π
2
i; by contrast
the billiard algorithm keeps going twice as long, until the small ball has retransferred all
its energy back to the heavy ball again to reach −|¯si = |θ = πi.
Surprising Squareroot.
The crowd-pleaser in the collision-counting Eq. 1.5 is the π”, but even the square root is
at first blush somewhat surprising. After all, the first collision transfers only a single unit
of kinetic energy, and there are M units to be transferred in total, so you might think it
is going to take O(M) collisions. The bouncing algorithm nevertheless gets the job done
8
|wi
¯
|si
|¯si
¯
Galperin final state!
in shaded region
|¯wi
-
-
Galperin initial state
Grover final state!
in shaded region
¯
¯
|¯si
Grover initial state
|si
Figure 7: Galperin’s protocol starts with the small ball stationary, |¯si, and ends once v
i6=w
v
w
0. Grover’s
algorithm starts in |si, with all the velocities equal, and ends at the closest approach to |wi.
in O(
M ) steps because the momentum of the light ball grows linearly, so the kinetic
energy grows quadratically.
The dual of this surprise occurs for Grover’s algorithm. The first iteration of
ˆ
U
s
ˆ
U
w
only increases the probability of measuring |wi by O(1/d), but nevertheless only O(
d )
steps are needed to distinguish with near certainty. Grover’s algorithm gets the job
done in O(
d ) steps because the amplitude v
w
grows linearly, so the probability grows
quadratically.
One Hit Wonder.
Grover search for one out of four items is unusually easy. With precisely one iteration of
the algorithm, the search succeeds with 100% probability. This is dual to the fact that
when M = 3, after a single pair of collisions the light ball is left exactly stationary.
3
1
Figure 8: One hit wonder. When M = 3 and initially v
left
= v
right
, a single pair of collisions leaves the small
ball exactly stationary. Equivalently, Grover search for one of four items works exactly with a single iteration.
Keeping it Real.
Throughout the Grover process, the wavefunction stays real. The v
i
are always real, and
operators
ˆ
U
w
and
ˆ
U
s
are not just unitary but orthogonal. Grover’s algorithm thus shows
you do not need complex numbers to get a quantum speed up. In the billiard problem,
the reality of the wavefunction corresponds to the billiards moving only horizontally.
9
Numerous Needles.
In the duality, the mass of the small ball is 1 because there is 1 correct answer (i.e. 1 basis
state whose sign is flipped by the oracle), and the mass of the heavy ball is M = d 1
because there are d 1 incorrect answers. If we were to adapt the Grover method to an
oracle with n correct answers (n needles in the haystack) and d n incorrect answers,
this would correspond to a mass n for the small ball and mass d n for the heavy ball.
It is clear that if you double the mass of both balls, the number of collisions does not
change. Only the ratio matters. This is dual to the slightly less obvious fact that the
runtime of the Grover task depends only on the ratio of the number of correct answers to
the number of incorrect answers #
queries
= b
π
4
p
(d n)/n c.
Galperin’s π-calculating plan displays a wanton disregard for engineering practicalities.
It requires that we overcome friction, overcome inelasticities, overcome the blurring effects of
quantum mechanics, and then having overcome all these things it requires exceptional patience,
because even pedestrian initial velocities provoke catastrophic corrections from special relativity.
Nevertheless, whatever the shortcomings of billiard balls as tools for calculating π, the results
of this paper suggest a tool that is even worse. We might start with a qu(100
N
+ 1)it, and then
step-by-step enact the quantum mirror of Galperin’s method, mirroring each velocity with an
amplitude, mirroring each billiard collision with a unitary, before ending with a painstaking
tomographic reconstruction of the final state and ushering in a new-if-pointless era of quantum
arithmetic. It would not be easy, it would not be useful, but it would be a picturesquely quixotic
way to seek π in the |ψi.
Acknowledgements
Thank you to Creon Levit and Michael Nielsen for feedback on a draft of this paper.
References
[1] G. Galperin, “Playing pool with π”, Regular and Chaotic Dynamics, v. 8, no. 4 (2003)
[2] Grant Sanderson, “The most unexpected answer to a counting puzzle”,
https://youtu.be/HEfHFsfGXjs
[3] L. K. Grover, “A Fast quantum mechanical algorithm for database search,”
Proceedings, 28th Annual ACM Symposium on the Theory of Computing (STOC), 1996,
pages 212-219; arXiv:quant-ph/9605043
10