Monday, July 6, 2026

Retsy Boss VIII's Star Fitting Homage

After 250 years, the nation has commissioned Retsy Boss VIII to design a new flag with one star for each of the nation’s current $58$ states. As an homage to the original flag design, Retsy wants to select $58$ stars from the square grid that are all at most some distance $R$ from a point on the plane. What is the minimum distance $R$ that Retsy can use?

Thankfully for Retsy Boss VIII, her namesake left her the Python code to run the optimization to find the number of stars given $h,$ $k$ and $R.$ Also, fortunately for Retsy Boss VIII she knew to look at OEIS to look up the integer sequence A000328, which captures the case of $h=k=0$ and $R \in \mathbb{N},$ to give her a decent idea of where to start. In particular, we see that $N(0,0,4) = 49$ and $N(0,0,5)=81,$ so let's start looking for $R \in [4,5].$ In particular, she wants to find $$R^* = \inf \left\{ R \in [4,5] \mid N^*(R) = \sup_{(h,k) \in [0,1]^2} N(h,k,R) \geq 58 \right\}.$$

Retsy didn't want to exhaustively search the entire phase space, so first she went about implementing a secant method update to arrive at some point $R$ for which $N^*(R) = 58.$ In particular, let's let $R_0 = 4,$ $R_1 = 5$ and $$R_{n+1} = \frac{R_{n-1} N^*(R_n) - R_n N^*(R_{n-1}) + 58 (R_n - R_{n-1})}{N^*(R_n) - N^*(R_{n-1})}.$$ Note that relatively quickly we arrive at some value with $N^*(R) = 58,$ that is,

$n$ $R_n$ $N^*(R_n)$
$0$ $4$ $49$
$1$ $5$ $81$
$2$ $4.20689655\dots$ $59$
$3$ $4.17084639\dots$ $58$

That is all well and good, but Retsy VIII wants the minimal such value of $R$ such that $N^*(R) = 58.$ Now she turns to a binary search of the interval $[a_0,b_0] = [4, 4.17084639],$ to within a tolerance of $\varepsilon = 10^{-6}.$ For each $n,$ she defines $c_n = \frac{a_n+b_n}{2}.$ If $N^*(c_n) \lt 58,$ then she defines $a_{n+1} = c_n$ and $b_{n+1} = b_n;$ however if $N^*(c_n) = 58,$ then she defines $a_{n+1} = a_n$ and $b_{n+1} = c_n.$ We can stop as soon as

$n$ $a_n$ $b_n$ $c_n$ $N^*(c_n)$
$0$ $4$ $4.17084639$ $4.08542320$ $56$
$1$ $4.08542320$ $4.17084639$ $4.12813480$ $57$
$2$ $4.12813480$ $4.17084639$ $4.14949060$ $57$
$3$ $4.14949060$ $4.17084639$ $4.16016850$ $58$
$4$ $4.14949060$ $4.16016850$ $4.15482955$ $57$
$5$ $4.15482955$ $4.16016850$ $4.15749902$ $58$
$6$ $4.15482955$ $4.15749902$ $4.15616428$ $58$
$7$ $4.15482955$ $4.15616428$ $4.15549691$ $58$
$8$ $4.15482955$ $4.15549691$ $4.15516323$ $57$
$9$ $4.15516323$ $4.15549691$ $4.15533007$ $58$
$10$ $4.15516323$ $4.15533007$ $4.15524665$ $58$
$11$ $4.15516323$ $4.15524665$ $4.15520494$ $58$
$12$ $4.15516323$ $4.15520494$ $4.15518409$ $57$
$13$ $4.15518409$ $4.15520494$ $4.15519451$ $58$
$14$ $4.15518409$ $4.15519451$ $4.15518930$ $57$
$15$ $4.15518930$ $4.15519451$ $4.15519191$ $57$
$16$ $4.15519191$ $4.15519451$ $4.15519321$ $58$
$17$ $4.15519191$ $4.15519321$ $4.15519256$ $58$

So we see that the optimal value of $R^*$ is about $4.15519256$ to within a tolerance of $\varepsilon = 10^{-6}.$ At this point, we can use map a contour plot, shown below, similar to what we did for the Classic problem. It is hard to discern, but the only place that the maximum is attained (up to the various symmetries of the $N$ function) when $R = 4.15519256$ is in a small neighborhood of the point $(h,k) = (1/2, 1/8)$ (seem familiar ... wink, wink?). If we were to graph the circle of radius $R = 4.15519256$ centered at $(1/2, 1/8),$ we see that it ever so slightly includes the lattice points $(-1,4),$ $(2,4),$ $(0,-4)$ and $(1,-4).$ In particular, since we see that the distance from $(1/2, 1/8)$ to any of these four lattices points is exactly the same, we can reduce the value of $R$ to precise that distance and maintain a value of $N^*(R) = 58,$ and hence the minimum distance that Retsy Boss VIII can use to honor her forebear's design is exactly $$R^* = \sqrt{0.5^2 + 4.125^2} = \sqrt{1.5^2 + 3.875^2} = \frac{\sqrt{1105}}{8} \approx 4.155192534648665\dots.$$

Move Over Ed McMahon, It's Retsy Boss's Star Search

When designing her new nation’s flag, Retsy Boss wanted to compactly arrange some stars. These stars were positioned along a square grid, but she only wanted to include stars whose centers were at most two units away from some point on the plane.

For example, if she had centered the circle on a star itself, then she could have placed a total of 13 stars on the flag, as shown below:

What is the greatest number of stars Retsy could have placed on the flag?

Let's define the function $N(h,k,R)$ to be the number of integer lattice points within distance $R$ of the point $(h,k) \in \mathbb{R}^2,$ in particular, we have $$N(h,k,R) = \# \left\{ (m,n) \in \mathbb{Z}^2 \mid (m-h)^2 + (n-k)^2 \leq R^2 \right\}.$$ If we have a fixed value of $k,$ let's say, then we see will have $$\eta_n(h,k,R) = \left\lfloor \sqrt{R^2 - (n-k)^2} + h \right\rfloor + \left\lfloor \sqrt{R^2 - (n-k)^2} - h \right\rfloor + 1,$$ where for clarity $\lfloor x \rfloor = \max \{ n \in \mathbb{Z} \mid n \leq x \}$ and in particular $\lfloor x \rfloor = -1$ for $x \in [-1,0).$ So in particular, we have $$N(h,k,R) = \sum_{n=-\lfloor R - k \rfloor}^{\lfloor R + k \rfloor} \eta_n (h,k,R).$$ We see for instance, that when $h=k=0$ and $R=2,$ that we indeed recover $\eta_{-2}(0,0,2) = \eta_2(0,0,2) = 1, \eta_{-1}(0,0,2) = \eta_1(0,0,2) = 3,$ and $\eta_0 (0,0,2)= 5,$ so we have $$N(0,0,2) = \sum_{n=-2}^2 \eta_n(0,0,2) = 1 + 3 + 5 + 3 + 1 = 13.$$

Now, since we also see that everything is periodic and symmetric, in order to solve Retsy's problem we only need to find $$N^* = \max \left\{ N(h,k,2) \mid 0 \leq k \leq h \leq \frac{1}{2} \right\},$$ since everything else in the unit square will can be recovered from this region and everything else in the plane is periodic so $N(h,k,2) = N([h], [k],2),$ for all $(h,k) \in \mathbb{R}^2,$ where $[x] = x - \lfloor x \rfloor$ is the fractional part function.

We can code this up in the following Python code to explore the phase space and empirically determine $N^*$:

Using this Python code, we can plot the following contour plot, which shows that anywhere in the dark blue region produces the the largest possible number of stars that Retsy could place on the flag is $N^*=14.$ In particular, we can take the point $(h,k) = (0.5, 0.125)$ for foreshadowing purposes and explicitly compute that \begin{align*} \eta_{-1}(0.5,0.125,2) &= \lfloor \sqrt{ 4 - (-1-0.125)^2 } + 0.5 \rfloor + \lfloor \sqrt{ 4 - (-1-0.125)^2 } - 0.5 \rfloor + 1 \\ &\quad = \lfloor 1.654\dots + 0.5 \rfloor + \lfloor 1.654\dots - 0.5 \rfloor + 1 = 4\\ \eta_{0}(0.5,0.125,2) &= \lfloor \sqrt{ 4 - (-0.125)^2 } + 0.5 \rfloor + \lfloor \sqrt{ 4 - (-0.125)^2 } - 0.5 \rfloor + 1\\ &\quad =\lfloor 1.996\dots + 0.5 \rfloor + \lfloor 1.996\dots - 0.5 \rfloor + 1 = 4\\ \eta_{1}(0.5,0.125,2) &= \lfloor \sqrt{ 4 - (1-0.125)^2 } + 0.5 \rfloor + \lfloor \sqrt{ 4 - (1-0.125)^2 } - 0.5 \rfloor + 1\\ &\quad =\lfloor 1.798\dots + 0.5 \rfloor + \lfloor 1.798\dots - 0.5 \rfloor + 1 = 4\\ \eta_{2}(0.5,0.125,2) &= \lfloor \sqrt{ 4 - (2-0.125)^2 } + 0.5 \rfloor + \lfloor \sqrt{ 4 - (2-0.125)^2 } - 0.5 \rfloor + 1\\ &\quad =\lfloor 0.696\dots + 0.5 \rfloor + \lfloor 0.696\dots - 0.5 \rfloor + 1 = 2\end{align*} so that $$N(0.5,0.125,2)=N^*=4+4+4+2=14.$$

Sunday, June 21, 2026

A less than half-full tank

Frustrated with my old calculator, I toss it in the trash and buy a new one. But now I’m concerned this second calculator is also “tanked.” As before, every value of $A$ between $0$ and $1$ is equally likely, at first.

I ask my friend to generate one random number using this second calculator. My friend does so, and smirks. “I won’t tell you what the number is,” my friend says, “but it’s somewhere between $0$ and $0.5.$” On average, what can I expect the value of $A$ (for this second calculator) to be?

Similar to the classic problem, we will define terms with $A \sim U(0,1)$ at first and $X|A=a \sim U(0,a).$ In this case, we want to get the distribution of $A$ conditional on $0 \leq X \leq \frac{1}{2},$ that is, $$f_{A\mid 0 \leq X \leq 1/2} (a) = \lim_{da \downarrow 0} \frac{\frac{1}{da} \mathbb{P} \left\{ a -\frac{da}{2} \leq A \leq a + \frac{da}{2}, 0 \leq X \leq \frac{1}{2} \right\}}{ \mathbb{P} \{ 0 \leq X \leq \frac{1}{2} \} }.$$

Let's take the denominator first, like last time to see that \begin{align*}\mathbb{P} \{ 0 \leq X \leq \frac{1}{2} \} &= \int_0^1 \int_0^{1/2} \frac{1}{t} \chi_{[0,t]}(x) \,dx \,dt \\ &= \int_0^{1/2} \int_0^1 \frac{1}{t} \chi_{[0,t]}(x) \,dt \,dx \\ &= \int_0^{1/2} \left(\int_0^x 0 \,dt + \int_x^1 \frac{dt}{t} \right) \,dx \\ &= \int_0^{1/2} -\ln x \,dx \\ &= \frac{1}{2} - \frac{1}{2} \ln \frac{1}{2} = \frac{1}{2} \left( 1 + \ln 2 \right).\end{align*}

Let's assume that $a \gt \frac{1}{2},$ in which case, for small values of $da$ we have $\frac{1}{2} \leq a - \frac{da}{2},$ so we have $\chi_{[0,t]}(x) = 1$ for all $0 \leq x \leq 1/2$ and $t \in (a-da/2, a+da/2).$ Therefore, if $a \gt \frac{1}{2},$ then we have the numerator equal to \begin{align*}\frac{1}{da} \mathbb{P} \{ a - da/2 \leq A \leq a + da/2, 0 \leq X \leq 1/2 \} &= \frac{1}{da}\int_{a-da/2}^{a+da/2} \int_0^{1/2} \frac{1}{t} \chi_{[0,t]}(x) \,dx \, dt \\ &= \frac{1}{da} \int_{a-da/2}^{a+da/2} \frac{dt}{2t} = \frac{1}{2da} \left( \frac{a + \frac{da}{2}}{a - \frac{da}{2}} \right) \\&= \frac{1}{2} \left. \frac{d}{dt} \ln t \right|_{t=a} + O(da) = \frac{1}{2a} + O(da).\end{align*} On the other hand, if $a \lt \frac{1}{2},$ then if $da$ is small enough, then for every $t \in (a - da/2, a+da/2),$ we have $t \lt 1/2,$ so we have the denominator as \begin{align*}\frac{1}{da} \mathbb{P} \{ a - da/2 \leq A \leq a + da/2, 0 \leq X \leq 1/2 \} &= \frac{1}{da} \int_{a-da/2}^{a+da/2} \int_0^{1/2} \frac{1}{t} \chi_{[0,t]}(x) \,dx \,dt \\ &= \frac{1}{da} \int_{a-da/2}^{a+da/2} \left( \int_0^t \frac{1}{t}\, dx + \int_t^{1/2} 0 \,dx \right) \,dt \\ &= \frac{1}{da} \int_{a-da/2}^{a+da/2} 1 \,dt = 1\end{align*} Therefore, we see that as $da \downarrow 0,$ the numerator becomes the piecewise function $n(a) = \min \{ 1, \frac{1}{2a} \},$ so putting everything together, we see that $$f_{A\mid 0 \leq X \leq \frac{1}{2}} (a) = \frac{ n(a) }{ \frac{1}{2} (1 + \ln 2) } = \min \left\{ \frac{2}{1 + \ln 2}, \frac{1}{a(1 + \ln 2)} \right\}.$$

Therefore, if all we have is the knowledge that the draw from the tanked calculator is in the lower half of the interval, then the expected value of the tank parameter is \begin{align*}\mathbb{E} \left[ A \mid 0 \leq X \leq \frac{1}{2} \right] &= \int_0^{1/2} a \cdot \frac{2}{1 + \ln 2} \,da + \int_{1/2}^1 a \cdot \frac{1}{a(1 + \ln 2)} \,da \\ &= \left.\frac{2}{ 1 + \ln 2} \frac{a^2}{2} \right|_{a=0}^{a=1/2} + \frac{1}{1 + \ln 2} \cdot \frac{1}{2} \\ &= \frac{3}{4(1 + \ln 2)} \approx 0.442962081862\dots\end{align*}

A half-full tank

I think the random number generator on my calculator might be malfunctioning. Oh no!

Under normal conditions, it should generate random numbers between $0$ and $1.$ But my suspicion is that the calculator is “tanked,” meaning it only generates random numbers between $0$ and some value $0 \lt A \lt 1.$ Beyond that, I have no knowledge regarding the value of $A.$ At the moment, it’s equally likely to be any value from $0$ to $1$.

As an experiment, I ask the calculator to generate one random number. It produces a value of exactly $0.5.$ (While this is, admittedly, infinitely unlikely, let’s roll with it!) Based on this result, what can I expect the value of $A$ to be, on average?

Let's first define some terms. Let's assume that the tank paramater $A \sim U(0,1),$ and since the calculator is tanked that random draws are all independently and identically distributed as $X \sim U(0,A),$ that is, $$f_{X|A=a}(x) = \lim_{dx \downarrow 0} \frac{1}{dx} \mathbb{P} \{ x - \frac{dx}{2} \leq X \leq x + \frac{dx}{2} \mid A = a\} = \frac{1}{a} \chi_{[0,a]}(x).$$ Using Bayesian theorem, we see that \begin{align*}f_{A|X=x} (a) &= \lim_{da \downarrow 0} \frac{1}{da} \mathbb{P} \{ a - \frac{da}{2} \leq A \leq a + \frac{da}{2} \mid X = x \} \\ &= \lim_{da \downarrow 0} \frac{ \mathbb{P} \{ a - \frac{da}{2} \leq A \leq a + \frac{da}{2}, X = x \} }{ da \mathbb{P} \{ X = x \} } \\ &= \lim_{da \downarrow 0} \frac{ \frac{1}{da} \int_{a - da/2}^{a+da/2} \frac{1}{t} \chi_{[0,t]}(x) \,dt }{ \int_0^1 \frac{1}{t} \chi_{[0,t]}(x) \,dt }.\end{align*} In particular, the denominator can be calculated as $$\int_0^1 \frac{1}{t} \chi_{[0,t]}(x) \,dt = \int_0^x \frac{1}{t} \chi_{[0,t]}(x) \,dt + \int_x^1 \frac{1}{t} \chi_{[0,t]}(x) \,dt = \int_0^x 0 \,dt + \int_x^1 \frac{dt}{t} = -\ln x.$$ The numerator meanwhile is equivalent to $\frac{1}{a} \chi_{[0,a)} (x),$ since if $x \lt a,$ then there is some $\alpha \lt 2(a-x)$ for which for any $0 \lt da \lt \alpha,$ $\chi_{[0,t]}(x) = 1$ for all $t \in (a-\frac{da}{2}, a + \frac{da}{2}),$ so that $$\frac{1}{da} \int_{a - da/2}^{a+da/2} \frac{1}{t} \chi_{[0,t]}(x) \,dt = \frac{1}{da} \int_{a-da/2}^{a+da/2} \frac{dt}{t} = \frac{ \ln \left( \frac{a + \frac{da}{2}}{a - \frac{da}{2}} \right) }{da} = \left.\frac{d}{dt} \ln t \right|_{t=a} + O(da) = \frac{1}{a} + O(da).$$ Similarly, if $x \gt a,$ then there is some $\alpha^\prime \lt 2(x-a)$ for which for any $0 \lt da \lt \alpha^\prime,$ then $\chi_{[0,t]}(x) = 0$ for all $t \in (a - \frac{da}{2}, a + \frac{da}{2} ),$ so that $$\frac{1}{da} \int_{a-da/2}^{a+da/2} \frac{1}{t} \chi_{[0,t]}(x) \,dt = 0.$$ Putting this all together, we see that $$f_{A\mid X=x}(a) = \begin{cases} -\frac{1}{a \ln x}, &\text{if $x \lt a \leq 1$;}\\ 0, &\text{if $0 \leq a \lt x.$}\end{cases}$$

Therefore, in particular, since we observed that $X = \frac{1}{2},$ we have the expected value of the tank parameter $A$ as \begin{align*}E[A \mid X = \frac{1}{2}] &= \int_0^1 a f_{A \mid X=\frac{1}{2}} (a) \,da \\ &= \int_0^{1/2} a \cdot 0 \,da + \int_{1/2}^1 a \cdot \left(- \frac{1}{a \ln \frac{1}{2}}\right) \,da \\ &= \int_{1/2}^1 \frac{da}{ln 2} \\& = \frac{1}{2\ln 2} \approx 0.72134752044\dots\end{align*}

Sunday, June 14, 2026

The average wave

Another wave is approaching the island, but no one knows which direction it’s coming from—for the moment, all directions are equally likely. On average, what is the length of the stretch of land directly under the wave halfway between when the wave first and last makes contact with the island?

Using our function $$\ell (\theta) = \min \left\{ \sqrt{(3 - \cos \theta) (1 + \cos \theta)}, \frac{ \tan \theta (1- \cos \theta) + \sqrt{(3-\cos \theta) (1 + \cos \theta)}}{2} \right\}$$ from the Classic answer along with the symmetry arguments that we made there to come to the conclusion that the average length of the stretch of land is \begin{align*}\bar{\ell} &= \int_0^{\pi/2} \ell(\theta) \frac{ 2d\theta }{ \pi } = \frac{2}{\pi} \int_0^{\cos^{-1} 1/3} \frac{ \tan \theta ( 1- \cos \theta) + \sqrt{(3 - \cos \theta) (1 + \cos \theta) }}{2} \,d\theta \\ &\quad\quad\quad\quad\quad\quad\quad\quad\quad + \frac{2}{\pi} \int_{\cos^{-1} 1/3}^{\pi/2} \sqrt{ (3 - \cos \theta) (1 + \cos \theta) } \,d\theta \end{align*}

Well that is certainly a mouthful, but we can break it into some pieces and come up with an analytical solution. First we see that if we rewrite the portion under the radical as $$\frac{\sqrt{(3 - \cos \theta)( 1 + \cos \theta) }}{2} = \sqrt{ 1- \left(\frac{1-\cos \theta}{2} \right)^2}$$ that we can do some trigonometrical simplifications and substitutions. So in particular we see that since $\sin \frac{\theta}{2} = \sqrt{ \frac{1-cos \theta}{2} }$ when $\theta \in (0, \frac{\pi}{2}),$ then we get \begin{align*}\int \sqrt{ 1- \left( \frac{ 1 - \cos \theta }{2} \right)^2 } \,d\theta &= \int \sqrt{ 1 - \sin^4 \frac{\theta}{2} } \,d\theta \\&= \int \sqrt{ \left( 1 - \sin^2 \frac{\theta}{2} \right) \left( 1 + \sin^2 \frac{\theta}{2} \right) } \,d\theta \\ &= \int \cos \frac{\theta}{2} \sqrt{ 1 + \sin^2 \frac{\theta}{2} } \,d\theta \\ &= 2\int \sqrt{1 + u^2} \,du,\end{align*} where the last equation involves the substitution of $u = \sin \frac{\theta}{2}.$ Using integration by parts, we get $$\int \sqrt{1+u^2} \,du = u \sqrt{1 + u^2} - \int \frac{u^2 \,du}{\sqrt{1+u^2}} = u \sqrt{1+u^2} + \int \frac{du}{\sqrt{1+u^2}} - \int \sqrt{ 1 + u^2 } \,du,$$ so that we get $$\int \sqrt{1+u^2} \,du = \frac{1}{2} \left( u \sqrt{1 + u^2} + \int \frac{du}{\sqrt{1+u^2}} \right) = \frac{1}{2} \left( u \sqrt{1+ u^2} + \sinh^{-1} u\right) + C.$$ Therefore we see that \begin{align*}\int \frac{ \sqrt{ (3-\cos \theta) (1 + \cos \theta) } }{2} \,d\theta &= \int \sqrt{ 1 - \left( \frac{1 - \cos \theta}{2} \right)^2 } \,d\theta \\ &= \sin \frac{\theta}{2} \sqrt{ 1 + \sin^2 \frac{\theta}{2} } + \sinh^{-1} \left(\sin \frac{\theta}{2}\right) + C.\end{align*} Similarly, but with a lot less fuss, we can get $$\int \frac{\tan \theta (1 - \cos \theta)}{2} \,d\theta = -\frac{1}{2} \ln | \cos \theta | + \frac{\cos \theta}{2} + C.$$

Therefore the the first integral \begin{align*}I_1 &= \frac{2}{\pi} \int_0^{\cos^{-1} 1/3} \frac{ \tan \theta (1 - \cos \theta) }{2} + \sqrt{ 1 - \left( \frac{1-\cos \theta}{2} \right)^2 } \,d\theta \\ &= \frac{2}{\pi}\left[ -\frac{1}{2} \ln | \cos \theta | - \frac{\cos \theta}{2} + \sin \frac{\theta}{2} \sqrt{ 1 + \sin^2 \frac{\theta}{2} } + \sinh^{-1} \left( \sin \frac{\theta}{2} \right) \right]^{\theta = \cos^{-1} 1/3}_{\theta = 0} \\ &= \frac{2}{\pi}\left( -\frac{1}{2} \ln \frac{1}{3} + \frac{1}{6} + \sqrt{ \frac{ 1 - \frac{1}{3}}{2}} \sqrt{ 1 + \left(\sqrt{ \frac{ 1 - \frac{1}{3} }{2} }\right)^2 } + \sinh^{-1} \sqrt{ \frac{1 - \frac{1}{3}}{2} } \right) \\ &\quad\quad\quad\quad\quad - \frac{2}{\pi}(0 + \frac{1}{2} + 0 + 0) \\ &= \frac{2}{\pi} \left(\frac{1}{2} \ln 3 + \frac{1}{3} + \sinh^{-1} \sqrt{\frac{1}{3}} \right) \\ &= \frac{2}{\pi}\ln 3 + \frac{2}{3\pi}, \end{align*} since $\sinh^{-1} t = \ln ( t + \sqrt{ 1 + t^2} ),$ so $$\sinh^{-1} \sqrt{\frac{1}{3}} = \ln \left( \sqrt{\frac{1}{3}} + \sqrt{1 + \frac{1}{3}} \right) = \ln \left( \sqrt{\frac{1}{3}} + \sqrt{ \frac{4}{3}} \right) = \ln \left( 3 \sqrt{\frac{1}{3}} \right) = \ln \sqrt{3} = \frac{1}{2} \ln 3.$$ The second integral is \begin{align*}I_2 &= \frac{4}{\pi} \int_{\cos^{-1} 1/3}^{\pi/2} \sqrt{ 1 - \left( \frac{1 - \cos \theta}{2} \right)^2 } \,d\theta \\ &= \frac{4}{\pi} \left[ \sin \frac{\theta}{2} \sqrt{ 1 + \sin^2 \frac{\theta}{2} } + \sinh^{-1} ( \sin \frac{\theta}{2} ) \right]_{\theta=\cos^{-1} 1/3}^{\theta=\pi/2} \\ &= \frac{4}{\pi} \left( \frac{1}{\sqrt{2}} \cdot \sqrt{1+\frac{1}{2}} + \sinh^{-1}\frac{1}{ \sqrt{2}} \right) \\ &\quad\quad\quad - \frac{4}{\pi} \left( \sqrt{ \frac{ 1 - \frac{1}{3}}{2}} \sqrt{ 1 + \left(\sqrt{ \frac{ 1 - \frac{1}{3} }{2} }\right)^2 } + \sinh^{-1} \sqrt{ \frac{1 - \frac{1}{3}}{2} } \right) \\ &= \frac{4}{\pi} \left( \frac{\sqrt{3}}{2} + \sinh^{-1} \frac{1}{\sqrt{2}} - \frac{2}{3} - \frac{1}{2} \ln 3 \right)\end{align*} Putting this all together and taking advantage of some beneficial cancelling, we get that the average length of the stretch of land covered by the wave at 10:05 a.m. if all directions for it to approach Semicircle Island are equally likely is $$\bar{\ell} = I_1 + I_2 = \frac{4}{\pi} \left( \frac{ \sqrt{3}}{2} + \sinh^{-1} \frac{1}{\sqrt{2}} \right) - \frac{2}{\pi} \approx 1.30443945503\dots$$ miles.

The longest wave

Semicircle Island is shaped like a perfect semicircle (or semidisk, technically), with a radius of $1$ mile. It doesn’t have any permanent residents, but it’s a very popular destination for surfers.

Rumor has it that a big wave is headed toward the island. This thin, straight wall of water never changes speed or direction. It will first make contact with the island at 10 a.m. and it will last be in contact with the island at 10:10 a.m. What is the longest possible stretch of land that is directly under the wave at 10:05 a.m.?

With my deepest apologies for my bad Paint skills, let's use a modified version of picture from the Extra Credit prompt and note that I inserted a ray that is perpendicular to the direction of travel of the wave that happens to make an angle of $\theta$ with the positive $x$-axis.

Let's assume that the center of the semi-disk is the point $(0,0),$ the place where the wave first hits the island is at the point $(\cos \theta, \sin \theta)$ and the formula for the ray connecting the origin and this point is $y = x \tan \theta$ as long as $\theta \ne \frac{\pi}{2}.$ Since the wave is perpendicular to this ray, the wave's slope must be the negative reciprocal of that of the ray, so we have the fomula for the wave at 10:00 a.m. is $y= -x \cot \theta + \csc \theta,$ which works as long as $x \not\in \{ 0, \pi\}.$ We similarly see that since the wave at each future point will be parallel to this line that the equation that models the position of the wave at 10:10 a.m. is either $y= -(x+1) \cot \theta,$ if $\theta \in (0, \frac{\pi}{2}),$ or $y = -(x-1) \cot \theta$ if $\theta \in ( \frac{\pi}{2}, \pi ).$ For simplicity, and by symmetry let's just assume going forward that $\theta \in (0, \frac{\pi}{2}).$ In this case, we see that the formula that models the position of the wave at 10:05 a.m., based on the uniform motion of the wave, is then $$y = -x \cot \theta + \frac{\left(\csc \theta + (-\cot \theta)\right)}{2} = -x \cot \theta + \frac{1 - \cos \theta}{2 \sin \theta}.$$

Let's pause here and think about what the length of a chord of a full circle would be. For simplicity let's assume that the chord is parallel to the $x$-axis, at say $y = h.$ In this case, we see that the endpoints of the chord are at $(\pm \sqrt{1-h^2}, h),$ so the length of the curve is $2\sqrt{1-h^2}.$ We further notice that if we rotate the entire $xy$-plane clockwise by angle $\frac{\pi}{2} - \theta,$ then the positive $y$-axis would be mapped to the ray $y= x \tan \theta,$ as we had before. In the case of the circle case, the chord length is obviously preserved in this orthogonal rotation, but now we want to only include the portion of the rotated chord that is now above the $x$-axis. We see that the portion of the chord that was in quadrant II before the rotation is still definitely in the upper half-plane post-rotation, so we should get at least $\sqrt{1-h^2}.$ The only thing to calculate is how much of the half-chord that was in the quadrant I. Firstly, it is perhaps the case depending on the height $h$ and rotational angle $\theta$ that the entirety of the half-chord is in the upper half-plane post-rotation, so the maximum that we could ever get is $\sqrt{1-h^2}.$ On the other hand, if we look at the right triangle formed by the ray $y = x\tan \theta,$ the rotated half-chord and the $x$-axis. Using trigonometry we see that the side with length $h$ is adjacent to the angle whose measure is \theta, with the half-chord opposite that angle, so we have the length of the half-chord in the upper half-plane as $h \tan \theta.$ So putting this altogether, we see that in a case where the we have the line $y=h$ and a rotation of the xy-plane clockwise by $\frac{\pi}{2}-\theta$ then the length of the chord that remains in the upper half-plane is $$\ell(h, \theta) = \min \{ 2 \sqrt{1-h^2}, \sqrt{1-h^2} + h \tan \theta \}.$$

That's cool an all, but let's return to our particular wave. We see that the we certainly have $\theta,$ by design, but all we need is to determine $h$ in this case. In the case of our wave that is modeled by the line $$y = -x\cot \theta + \frac{1- \cos \theta}{\sin \theta},$$ we can use that same right triangle that we used in the generic case above and the fact that the line crosses the $x$-axis as the point $x = \frac{\sec \theta - 1}{2}$ to determine that $$h = \frac{\sec \theta - 1}{2} \cos \theta = \frac{1 - \cos \theta}{2}.$$ Therefore, we see that the length of the stretch of land covered at 10:05 a.m. if it first touches the island at a point $(\cos \theta, \sin \theta)$ is \begin{align*}\ell(\theta) = \ell\left(\frac{1- \cos\theta}{2}, \theta\right) &= \min \left\{ 2 \sqrt{ 1 - \left(\frac{1 - \cos \theta}{2} \right)^2 }, \frac{1 - \cos \theta}{2}\tan \theta + \sqrt{ 1 - \left( \frac{1 - \cos \theta}{2} \right)^2 } \right\} \\ &= \min \left\{ \sqrt{ (3 - \cos \theta) (1 + \cos \theta) }, \frac{\tan \theta ( 1 - \cos \theta) + \sqrt{(3-\cos \theta)(1 + \cos \theta)} }{2} \right\},\end{align*} for $\theta \in (0, \frac{\pi}{2}).$ Analyzing the parts we see that $\tan \theta (1 - \cos \theta)$ is always increasing on this interval, while the term within the square root is always decreasing, therefore we can reason that that maximal length occurs exactly at the cutover point when $$\tan \theta (1 - \cos \theta) = \sqrt{ (3 - \cos \theta) (1 + \cos \theta) }.$$ While I am sure there are many who may want to try to solve analytically, from a geometric intuition perspective, this cutover occurs exactly when the point where the wave crosses the $x$-axis is at the point $(1,0)$, that is, when $$\frac{\sec \theta^* - 1}{2} = 1,$$ or $\sec \theta^* = 3,$ or $\theta^* = \cos^{-1} \frac{1}{3}.$ At this critical point, the longest possible stretch of land that the wave is covering at 10:05 a.m. is $$\ell^* = \ell( \cos^{-1} \frac{1}{3} ) = \sqrt{ (3 - \frac{1}{3}) (1 + \frac{1}{3} ) } = \frac{4}{3} \sqrt{2} \approx 1.88561808316\dots$$ miles.

For absolute completeness we can cover the cases of $\theta = 0,$ in which case wave is represented by vertical lines and at 10:05 a.m., the wave would be covering the unit interval along the positive $y$-axis and have a length of one mile. For the case of $\theta = \frac{\pi}{2},$ where the wave is represented by horizontal lines and the wave would be at $y= \frac{1}{2}$ and cover a distance of $2\sqrt{1 - \frac{1}{2}} = \sqrt{3} \lt \frac{4}{3} \sqrt{2}$ at 10:05 a.m. By symmetry, we can cover the case of $\theta \in (\frac{\pi}{2} , \pi)$ and by another symmetry we can cover the case of what if instead of last hitting the point at $(1,0)$ the wave first hits the point at $(1,0)$ and then only at 10:10 a.m. arrives at the point $(\cos \theta, \sin \theta),$ to show that there is certainly not a larger possible stretch of land to be found if instead of the subset $(0, \frac{\pi}{2})$ that we spent most of our time on, the wave came with an orientation of \theta with respect to the positive $x$-axis for some $\theta \in (\frac{\pi}{2}, 2\pi)$... but more on this later.

Sunday, May 31, 2026

Two sheep

Two sheep are at two random points inside a square pen. They are munching grass and staring in two random directions. Each sheep has a field of view that’s 180 degrees. What is the probability that they both see each other?

Let's first start with two sheep in a one-dimensional unit interval pen each of which randomly either look to the right or to the left. Obviously in this case, each sheep has a $50\%$ chance of randomly looking at the other sheep and their directional choices are independent, so the probability is $25\%.$

But wait, weren't we dealing with two sheep in a unit square pen? Sure, let's assume that one sheep is at the point $(a,b)$ and another is at $(c,d).$ Next let's draw the straight line $y = \frac{d-b}{c-b} (x - a) + b$ through these two points. The sheep at $(a,b)$ is staring into space in a direction that makes an angle $\theta$ with respect to the ray of the line that we just drew as $x$ increases. We see that either $0 \leq \theta \leq \frac{\pi}{2},$ in we can think of this as looking to the right with respect to the line between the sheep, or $\frac{\pi}{2} \leq \theta \leq \pi$ in which case we can think of this as looking to the left. Therefore, despite living in a fully two dimensional field, we can project this problem back into the one dimensional problem. Similarly, we can therefore conclude that the probability of these two sheep seeing each other in the square pen is $25\%.$