Sunday, August 22, 2021

Jiminy Crickets! I did not expect that!

Help, there’s a cricket on my floor! I want to trap it with a cup so that I can safely move it outside. But every time I get close, it hops exactly $1$ foot in a random direction.I take note of its starting position and come closer. Boom — it hops in a random direction. I get close again. Boom — it takes another hop in a random direction, independent of the direction of the first hop. What is the most probable distance between the cricket’s current position after two random jumps and its starting position?


Despite my lingering questions about the seemingly explosive nature of this cricket's jumping, I get to work by first setting up the coordinate system to most easily calculate the cricket's whereabouts. Let's make the cricket's starting point the origin and draw the $x$-axis between the origin and the cricket's position after its first hop, ensuring that its location after its first hop is $(1,0)$ on the plane. Thus, the cricket's position after its second hop can be modeled as $$X(\theta) = (1+\cos \theta, \sin \theta)$$ where $\theta \in U[0,2\pi).$ The distance for $X(\theta)$ is given by $$\|X\| = \|X(\theta)\| = \sqrt{ (1+\cos \theta)^2 + \sin^2 \theta } = \sqrt{2 + 2\cos \theta}.$$

The cumulative distribution of $\|X\|$ is then \begin{align*}F_{\|X\|} (r) &= \mathbb{P} \{ \|X\| \leq r \} = \mathbb{P} \{ \sqrt{2 + 2\cos \theta} \leq r \}\\ &= \mathbb{P} \{ \cos \theta \leq \frac{r^2}{2} - 1 \} \\&= 1 - \frac{\arccos \left( \frac{r^2}{2} - 1 \right)}{\pi},\end{align*} for all $r \in [0,2],$ while $F_{\|X\|} (r) = 0$ for $r \in (-\infty, 0)$ and $F_{\|X\|}(r) = 1,$ for $r \in (2,\infty).$ Differentiating, the probability density is thus $$f_{\|X\|}(r) = \frac{d}{dx} F_{\|X\|}(r) = \begin{cases} 0, &\text{if $r \in (-\infty, 0) \cup (2,\infty)$}\\ \frac{2}{\pi \sqrt{4-r^2}}, &\text{if $r \in (0,2).$}\end{cases}$$ Therefore, the most probable distance (or mode) of the cricket's distance from the origin density is thus interestingly at $r = 2.$ I know that the question prompt explicitly warned against calculating the expected distance, but as we shall see in the following, for sanity's sake, we see that the expected distance is $$\mathbb{E} \|X\| = \int_0^2 rf_{\|X\|}(r)\,dr = \frac{1}{\pi} \int_0^2 \frac{2r\,dr}{\sqrt{4-r^2}} = \left[-\frac{2\sqrt{4-r^2}}{\pi}\right]^{r=2}_{r=0} = \frac{4}{\pi}.$$


While I am a grisled veteran of Riddler's and weird mathematical oddities in general, this result somewhat shocked me at first blush. Essentially, this would indicate that the most probable case is that the cricket's first and second jumps are aligned. Not to mention the testing paradox of ``Wait?! The correct answer for how far away the cricket will most probably be after two jumps is just $2$ jumps times $1$ foot per jump?'' I mean, I get that it is a Riddler express, but .... So I also set up a quick simulation just to confirm.


In the simulation, I dispensed with the setting up of clever axes and just simulated two random directions, $U_1, U_2 \overset{\text{i.i.d.}}{\sim} U[0,2\pi)$ and defining the position after two hops as $X=e^{iU_1} + e^{iU_2}.$ Lo and behold! The histogram of the modulus of X shows that the result holds and that evidently the cricket will most probably land along the perimeter of the two foot circle around the cricket's intial location after its the second jump. To confirm that I haven't just made up two completely different weird results, we also see that the average modulus in the simulated sample is $1.273907 \approx \frac{4}{\pi},$ as expected (pun intended?).

Crickets
In [1]:
import matplotlib.pyplot as plt
import numpy as np
from numpy.random import uniform
%matplotlib inline
num_sims = 1000000
U = uniform(low=0.0, high=2*np.pi, size=(num_sims,2))
X = np.zeros(shape=(num_sims,2))
X[:,0] = np.cos(U[:,0])+np.cos(U[:,1])
X[:,1] = np.sin(U[:,0])+np.sin(U[:,1])
r = np.linalg.norm(X,axis=1)
_ = plt.hist(r, bins='auto')
plt.show()
print('Average of the simulation is %1.6f which is approximately 4/pi with rel. error %1.6f%%' % (r.mean(), np.abs(r.mean()*np.pi/4 -1.0)))
Average of the simulation is 1.273907 which is approximately 4/pi with rel. error 0.000524%

No comments:

Post a Comment