Monday, December 23, 2024

This is New Years, not Prime Day!

The number $2025$ is not prime. As a matter of fact, it’s a perfect square: $2025 = 45^2$.

You cannot make $2025$ by adding two distinct primes. To do so, you’d have to add an even prime and an odd prime. The only even prime is $2,$ but $2025 − 2 = 2023$, which is not prime (it’s equal to $7∙172$). But you can make $2025$ by adding three distinct primes. For example, $661 + 673 + 691 = 2025.$ You can also make $2025$ by adding four distinct primes: $2 + 659 + 673 + 691 = 2025.$

What is the greatest number of distinct primes that add up to $2025$?

First let's find the set of all primes less than $2025,$ that is, \begin{align*}P = \{ & 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101,\\ & 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197,\\ & 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311,\\ & 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431,\\ & 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557,\\ & 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661,\\ & 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809,\\ & 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937,\\ & 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049,\\ & 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153,\\ & 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277,\\ & 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381,\\ & 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487,\\ & 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597,\\ & 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699,\\ & 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823,\\ & 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949,\\ & 1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017 \}.\end{align*} One way to encode the problem is as the following binary linear knapsack program: \begin{align*} N = \max \,\, & \sum_{p \in P} x_p \\ \text{s.t.} \,\, & \sum_{p \in P} p x_p = 2025 \\ & x_p \in \{ 0, 1 \}, \, \forall p \in P\end{align*}

We can first loosen the binary restrictions a bit to get an upper bound. If as opposed to having $x_p \in \{0,1\},$ if we use $x_p \in [0,1],$ $\forall p \in P,$ then we get an upper bound of $\tilde{N} = \frac{4624}{139} = 33.266187\dots,$ by greedily filling our knapsack with all of the smallest primes until we have to resort to a fractional piece, that is, $$\tilde{x}_p = \max \left\{ 0, \min \left\{ \frac{2025 - \sum_{j \in P, j \lt p } j }{p}, 1 \right\} \right\}, \, \, \forall p \in P.$$ So we know that $N \leq \lfloor \tilde{N} \rfloor = 33.$ If we have $33$ primes and $2$ is one of them, then the sum will be even and so could never be $2025.$ The smallest sum of $33$ primes that does not include $2$ is $2125,$ which is too large. So we can never have a set of $33$ primes add up to $2025,$ and hence the upper bound must be $N \leq 32.$ From here, we can either hunt and peck for the right tradeoff of primes, ... or we can just program a quick binary program and your local solver to arrive at the optimal answer is that you can make $2025$ into the sum of $N = 32$ primes (so not that far off from the non-integral approximation), since \begin{align*}2025 &= 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 + 29 + 31 + 37 + 41 + 47 \\ & + 53 + 59 + 61 + 67 + 71 + 73 + 79 + 83 + 89 + 101 + 103 + 107\\ & + 109 + 113 + 127 + 139 + 149 + 157 \end{align*}

Monday, December 9, 2024

It's my particles in a box!

You have three particles inside a unit square that all repel one another. The energy between each pair of particles is $1/r,$ where $r$ is the distance between them. To be clear, the particles can be anywhere inside the square or on its perimeter. The total energy of the system is the sum of the three pairwise energies among the particles.

What is the minimum energy of this system, and what arrangement of the particles produces it?

If we only had two particles, then the furthest away that the particles could be (and hence the minimal total energy arrangment), would be opposite corners of the unit square, e.g., one at $(0,0)$ and the other at $(1,1).$ In this configuration, the total energy would be $E_2 = \frac{1}{\sqrt{2}}.$ So let's assume that we have two of the three particles there and then see where the other particle would end up.

Assume that the third particle is at the point $X=X(a,b)$ for some $0 \leq a, b \leq 1.$ Then the total energy of the system would be $$E = E(a,b) = \frac{1}{\sqrt{2}} + \frac{1}{\sqrt{a^2+b^2}} + \frac{1}{\sqrt{(1-a)^2 + (1-b)^2}}.$$ Taking derivatives gives $$\nabla E = \begin{pmatrix} -\frac{a}{(a^2 + b^2)^{3/2}} + \frac{1-a}{\left( (1-a)^2 + (1-b)^2 \right)^{3/2}} \\ -\frac{b}{(a^2 + b^2)^{3/2}} + \frac{1-b}{\left( (1-a)^2 + (1-b)^2 \right)^{3/2}}\end{pmatrix}.$$ The only analytic root of the gradient mapping is $a=b=\frac{1}{2},$ which would give a total energy of $E(\frac{1}{2},\frac{1}{2}) = \frac{1}{\sqrt{2}} + 2 \frac{2}{\sqrt{2}} = \frac{5}{\sqrt{2}},$ but this is a saddle point and we can do better by checking what happens if $X$ were along the perimeter of the unit square.

Assume without loss of generality and by availing ourselves of symmetry, that $b = 0$ and we just have $0 \leq a \leq 1.$ In this case, we have $$\tilde{E}(a) = E(a,0) = \frac{1}{\sqrt{2}} + \frac{1}{a} + \frac{1}{\sqrt{1 + (1-a)^2}}$$ which has derivative $$\tilde{E}^\prime = -\frac{1}{a^2} + \frac{1-a}{\left(1 + (1-a)^2\right)^{3/2}} = \frac{a^2(1-a) - \left(a^2 - 2a+2\right)^{3/2}}{a^2\left(a^2 - 2a+2\right)^{3/2}}.$$ Since $$a^2(1-a) \leq \frac{4}{27} \lt 1 \leq \left(a^2 - 2a + 2\right)^{3/2},$$ for all $a \gt 0,$ we have $\tilde{E}^\prime \lt 0$ for all $a \gt 0,$ so the lowest possible value is when $a^* = 1,$ that is when $X^* = (1,0),$ and the total energy is at its lowest $$E^* = \tilde{E}(1) = \frac{1}{\sqrt{2}} + 2 \approx 2.70710678119....$$ There are other possible arrangements of the particles that obtain the same minimal energy. Namely, any of the four right isoceles triangle formed by choosing three out of the four vertices of the unit square will give this minimal energy configuration.

Sunday, November 10, 2024

Snoring while sorting

You are waiting in line to be sorted into one of the four houses of Logwarts (a posh wizarding boarding school in the Scottish highlands) by an anthropomorphic sorting hat. The hat is a bit of a snob about the whole matter, and refuses to sort two students in a row into the same house. If a student requests a certain house, but the previously sorted student was already sorted into that same house, then the hat chooses randomly from among the three remaining houses.

You are standing 10th in line, and you make plans to request Graphindor house for yourself. As for the other students in line, you can assume that they have random preferences from among the four houses. The first student steps up, and has a brief, quiet conversation with the hat. After a few moments, the hat proclaims, “Graphindor!” At this point, what is the probability that you will be sorted into Graphindor?

Let's define our probability space such that it will be useful for the this problem. Of course, as stated there are three other houses with fanciful names (perhaps Hufflepath, Ravenndiagram and Slytheorem), but as far as you're concerned it is Graphindor or bust, so luckily all of these outcomes are indistinguishable to you. Let $p_{i,k}$ be the probability that the $i$th wizardling on line is sorted into Graphindor, subject to the fact that the $k$th wizardling on line was the last one to actually be sorted to Graphindor.

As far as you are concerned, you get to Graphindor as long as the 9th wizard is not sorted there, since you will always ask the hat to sort you into Graphindor. So, given that the 1st wizardling on line was just sorted into Graphindor, the probability that you will be sorted into Graphindor is $p=1-p_{9,1}.$ All that remains now is to divine what the formula for $p_{i,k}$ is anyway.

Let's say that we know $p_{i,k}$ for some $1 \leq k \leq i.$ There are two ways for the $(i+1)$th wizardling to end up sorted into Graphindor: either (a) the $i$th wizard is sorted to some ``not Graphindor'' house and the $(i+1)$th wizardling requested Graphindor; or (b) the $i$th wizard is sorted to some ``not Graphindor'' house and the $(i+1)$th wizardling requested that same ``not Graphindor'' house. In both cases, the probability of event (a) is $1/4$ while the probability of event (b) is $1/12 = 1/4 \cdot 1/3.$ Putting these two together, we get the recursion relationship $$p_{i+1,k} = \frac{1}{4} (1-p_{i,k}) + \frac{1}{12} (1-p_{i,k}) = \frac{1-p_{i,k}}{3}, \,\,\text{for $i \geq k \geq 1.$}$$ By construction, we have $p_{k,k} = 1,$ for each $k \geq 1.$

This recursive formula leads to the explicit formula $$p_{i,k} = \frac{1}{4} \left(1 + 3 \cdot (-3)^{k-i}\right), \,\,\, \text{for all $i \geq k \geq 1.$}\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\star$$ We see that for $i=k \geq 1$ that we recover $p_{k,k} = \frac{1}{4} (1 + 3 \cdot (-3)^0 ) = 1,$ as our base case. If we assume that the formula $\star$ holds for some $i \geq k \geq 1,$ then from the recursive formula we see that \begin{align*}p_{i+1,k} = \frac{1-p_{i,k}}{3} &= \frac{1 - \frac{1}{4} \left(1 + 3 \cdot (-3)^{k-i} \right)}{3} \\ &= \frac{\frac{3}{4} - \frac{3}{4} \cdot (-3)^{k-i}}{3} \\ &= \frac{1}{4} \left( 1 + \frac{3}{-3} (-3)^{k-i} \right) \\ &= \frac{1}{4} \left( 1 + 3 \cdot (-3)^{k-i-1} \right),\end{align*} which follows formula $\star$ for the case $i+1$. Thus by induction we have proven the formula. This therefore allows us to answer that if you are $10$th in line and have resolved to request Graphindor no matter what that your probability of getting sorted into Graphindor after the first wizard is sorted into Graphindor is $$p=1-p_9 = 1 - \frac{1}{4} \left(1 + 3 \cdot (-3)^{1-9}\right) = \frac{3-3^{-7}}{4} = \frac{6560}{8748} = \frac{1640}{2187} \approx 0.7498856882....$$

Now, instead of being 10th in line, suppose you are $N$th in line, where $N$ is some value much greater than 10. Because so many students are being sorted in front of you, you decide you’ll take a nap. You wake up without any idea of how long you were out—it could have been a second, or it could have been an hour, you’re just not sure. It’s still not your turn to be sorted yet, but you see a student wearing the hat. After a brief moment, the hat shouts, “Graphindor!”

What is the smallest value of $N$ such that your probability of being sorted into Graphindor is greater than $p$? (To be clear, when you wake up, the student being sorted is anywhere from first in line to immediately before you in line with equal probability.)

OK, so now it becomes a little clearer why I chose such obscure nomenclature for the earlier problem. However, in this case where you are sitting at $N$th in line and then dozed off only to wake up as the wizardling in uniformly randomly distributed position $M$ is sorted into Graphindor, so we have the expected probability of being sorted into Graphindor is still dependent on whether or not the person immediately in front of you is sorted into Graphindor, that is $q=1-p_{N-1,M}$. However, here since $M$ is random we have \begin{align*} q = 1 - p_{N-1,M} &= 1 - \sum_{i=1}^{N-1} \mathbb{P} \{ M = i \} p_{N-1,i} \\ &= 1 - \frac{1}{N-1} \sum_{i=1}^{N-1} \frac{1}{4} \left(1 + 3 \cdot (-3)^{i-N+1} \right) \\ &= \frac{3}{4} - \frac{3 \cdot (-3)^{1-N}}{4(N-1)} \sum_{i=1}^{N-1} (-3)^i \\ &= \frac{3}{4} - \frac{3 \cdot (-3)^{1-N}}{4(N-1)} \frac{(-3) - (-3)^N}{1-(-3)} \\ &= \frac{3}{4} \left( 1 - \frac{ 9 \cdot (-3)^{-N} + 3}{4(N-1)} \right) \\ &= \frac{3}{16} \frac{4N-7-9\cdot(-3)^{-N}}{N-1}\end{align*} If we then want to know what is the minimal $N$ such that $q = q(N) \gt p = \frac{1640}{2187},$ we need get a nonlinear, monotonically increasing equation that we can just as easily guess and check for a solution.

In particular, if we solve the approximation where we ignore that pesky exponential function and equally ignore the integrality of $N$, we get $$\tilde{q}(x) = \frac{3 (4x-7)}{16(x-1)}.$$ If we were to solve $$\tilde{q}(x) = \frac{3(4x-7)}{16(x-1)} = p$$ for a non-integer value of $x$, we get $$x^* = \frac{21-16p}{12-16p} = \frac{19687}{4} = 4921.75.$$ This seems like a very good place to start hunting and pecking with $N^* = \lceil x^* \rceil = 4922.$ Let's first check $$\tilde{q}(N^*) = \frac{3 \cdot (4 \cdot 4922 -7)}{16 \cdot 4921} = \frac{59043}{78736} \approx 0.7498856939.....,$$ which is roughly $6 \times 10^{-9}$ larger than $p.$ Since $9 \cdot (-3)^{-N^*} \ll 10^{-9},$ we can confirm that $N^* = 4922$ is the smallest integer value such that if you fell asleep and randomly woke up to some wizardling ahead of you in line is being sorted to Graphindor then your probability of also getting sorted to Graphindor is $q(N) \gt p = \frac{1640}{2187}.$

Monday, November 4, 2024

Is that what squaring the circle means?

A pseudo-square has the following properties:

  1. It is a simple, closed curve.
  2. It has four sides, all the same length.
  3. Each side is either a straight line segment or the arc of a circle.
  4. The four sides are joined at four corners, with each corner having an internal angle of 90 degrees or 270 degrees.

The pseudo-square pictured above has two straight sides, which run radially between arcs of two concentric circles. Assuming this is a unit pseudo-square (i.e., each side has length 1), what is its area?

As you can see, I've pre-doctored the image from the prompt with some parameters. Let $r$ be the radius of the smaller circle and let $\theta$ be the angle inscribed between the two straight line edges. From here, if the shape is a unit pseudo-square then the larger radius is $1+r,$ so we can find the formula for the area of the shape in terms of $r$ and $\theta,$ as $$A(r,\theta) = \pi r^2 + \frac{1}{2} \theta \left((1+r)^2 - r^2\right) = \pi r^2 + \frac{1}{2} \theta (1 + 2r).$$ That is all well and good, but we now have to find the particular value of $r$ and theta that allow for this shape to be unit pseudo-square. In particular, the length of the arc on the larger of the two concentric circles is $$\ell = \theta (1 + r).$$ The length of the other arc is $$\tilde{\ell} = (2\pi - \theta) r.$$ Since the shape is a unit pseudo-square we have the nonlinear system of equations \begin{align*} \theta ( 1 + r) &= 1 \\ (2\pi - \theta) r &= 1.\end{align*} By setting $\theta = (1 + r)^{-1}$ and plugging into the second equation we get $$\left(2\pi - \frac{1}{1+r}\right) r = 1,$$ which is equivalent to the quadratic equation $$2\pi r^2 + 2(\pi - 1) r - 1 = 0.$$ Thus, if the shape is a unit pseudo-square then the smaller radius $r$ is equal to $$r^* = \frac{1-\pi + \sqrt{1+\pi^2}}{2\pi}.$$

By plugging $\theta = (1+r)^{-1}$ into the area formula we get $A(r) = \pi r^2 + \frac{1+2r}{2(1+r)},$ so plugging in $r^*$ from above we get the area of the unit psuedo-square with two straight lines is \begin{align*}A^* = A(r^*) &= \pi \left( \frac{1-\pi + \sqrt{1+\pi^2}}{2\pi} \right)^2 + \frac{ 1 + 2 \frac{1-\pi + \sqrt{1+\pi^2}}{2\pi} }{2 \left( 1 + \frac{1-\pi + \sqrt{1+\pi^2}}{2\pi} \right)}\\ &= \frac{1+\sqrt{1+\pi^2}}{2\pi} \approx 0.683874197466......\end{align*}

Can you find a unit pseudo-square that has three curved sides and just one straight side? What is the area of your new unit pseudo-square?

Without loss of generality, we can assume that the one flat side is positioned along the bottom. We would need to have two curved sides connected to this flat bottom that curve towards each other, with there being a third circle that is tangent to the circular arcs. The resulting shape is sort of like the shape of some pawns in chess. See the figure below. We again insert some parameters. Let the flat side be the line segment from $(-\frac{1}{2},0)$ to $(\frac{1}{2},0).$ Let the two symmetric sides attached to flat bottom be arcs of the circles centered at $(-a,0)$ and $(a,0),$ respectively, each with radius $a+\frac{1}{2},$ with subtended angle $\theta$. Let the final arc be from the circle centered $(0,b)$ with radius $r$ and subtended angle $2(\pi - \theta).$

Let's first try to figure out how to quantify the area of the pseudo-square with three curved sides. The region denoted by $B$ has area given by $$A_B = \frac{1}{2} (\pi - \theta) r^2.$$ The region denoted by $C$ has area given by $$A_C = \frac{1}{2} r^2 \tan \theta.$$ Finally, the region denoted by $D$ has aread given by $$A_D = \frac{1}{2} \theta \left(a + \frac{1}{2}\right)^2 - \frac{1}{2} a^2 \tan \theta.$$ The area of the entire pseudo-square with three curved sides is thus \begin{align*}A = A(a,r,\theta) &= 2 \left(A_B + A_C + A_D\right) \\ &= (\pi - \theta + \tan \theta) r^2 + \theta \left(a + \frac{1}{2}\right)^2 - a^2 \tan \theta.\end{align*}

With some creative trigonometry we can obtain $r = r(a,\theta),$ thus reducing the dimensions of the problem a smidge. The region denoted by $C$ is a triangle whose height is $r$ and base $\beta,$ which is some portion of line segment of total length $a + \frac{1}{2},$ since that line segment is a radius of the circle centered at $(-a,0)$ of radius $a+\frac{1}{2}.$ Since the line segment, negative $x$-axis and positive $y$-axis form a triangle, we can compute $\beta$ as $$\beta = a + \frac{1}{2} - a\sec \theta.$$ Since $r = \beta \cot \theta,$ we have $$r = r(a,\theta) = \left( \left(a+\frac{1}{2}\right) - a \sec \theta \right) \cot \theta = \frac{ (a + \frac{1}{2}) \cos \theta - a }{ \sin \theta }.$$ Therefore, we have $$A = A(a,\theta) = (\pi - \theta + \tan \theta) \left( \frac{ \left(a + \frac{1}{2}\right) \cos \theta - a }{\sin \theta} \right)^2 + \theta \left(a + \frac{1}{2} \right)^2 - a^2 \tan \theta.$$

OK, now that that significantly more intricate foundational work is out of the way, we need to ensure that each of these curves sides is unit length. Since the more vertical arcs are symmetric, we only need to quantify $\ell=(a+\frac{1}{2}) \theta$ and $\tilde{\ell} = 2(\pi - \theta) r,$ and set them both equal to $1$ to obtain the nonlinear system of equations \begin{align*} (a + \frac{1}{2}) \theta &= 1 \\ 2(\pi - \theta) r = (\pi - \theta) \frac{(a+1/2)\cos \theta - a}{\sin \theta} &= 1\end{align*} Solving for $a$ in the second equation and then plugging back into the first we get $$\frac{ \sin \theta - \pi + \theta }{ 2(\pi - \theta) ( \cos \theta - 1) } \theta = 1.$$ This non-linear equation is solved with $$\theta^* \approx 0.74960359...$$ which leads to $$a^* = \frac{2-\theta^*}{2\theta^*} \approx 0.8340377...$$ which ultimately leads to the area of a unit pseudo-square with three curved sides of $$A^* = A(a^*, \theta^*) \approx 0.8317044...$$

Monday, October 28, 2024

Conditional candy

It’s Halloween time! While trick-or-treating, you encounter a mysterious house in your neighborhood.

You ring the doorbell, and someone dressed as a mathematician answers. (What does a “mathematician” costume look like? Look in the mirror!) They present you with a giant bag from which to pick candy, and inform you that the bag contains exactly three peanut butter cups (your favorite!), while the rest are individual kernels of candy corn (not your favorite!).

You have absolutely no idea how much candy corn is in the bag—any whole number of kernels (including zero) seems equally possible in this monstrous bag.

You reach in and pull out a candy at random (that is, each piece of candy is equally likely to be picked, whether it’s a peanut butter cup or a kernel of candy corn). You remove your hand from the bag to find that you’ve picked a peanut butter cup. Huzzah!

You reach in again and pull a second candy at random. It’s another peanut butter cup! You reach in one last time and pull a third candy at random. It’s the third peanut butter cup!

At this point, whatever is left in the bag is just candy corn. How many candy corn kernels do you expect to be in the bag?

The probability of drawing three peanut butter cups in a row, conditional on there being $k$ candy corn kernels, is $$\mathbb{P} \{ c = 3 \mid k \} = \frac{ 3 }{k + 3 } \frac{ 2}{k + 2} \frac{1}{k+1} = \frac{6}{(k+3) (k+2) (k+1) }.$$ Using Bayes' theorem, we can retrieve the conditional distribution of the number of candy corn kernels conditional on pulling three peanut butter cups in a row, namely, \begin{align*}\mathbb{P} \{ k \mid c = 3 \} &= \frac{ \mathbb{P} \{ c = 3 \mid k \} \mathbb{P} \{ k \} }{ \mathbb{P} \{ c = 3 \} } \\ &= \frac{ \mathbb{P} \{ c = 3 \mid k \} }{ \sum_{\ell = 0}^\infty \mathbb{P} \{ c = 3 \mid \ell \} } \\ &= \frac{ \frac{6}{(k+1)(k+2)(k+3)} }{ \sum_{\ell=0}^\infty \frac{6}{(\ell+1)(\ell+2)(\ell+3)} }\\ &= \frac{1}{M (k+1)(k+2)(k+3)},\end{align*} where $$M = \sum_{\ell=0}^\infty \frac{1}{(\ell +1)(\ell+2)(\ell+3)}.$$

We can calculate the convergent series $M$ by method of partial fractions. Let \begin{align*} \frac{1}{(\ell + 1)(\ell + 2)(\ell + 3)} &= \frac{A}{\ell+1} + \frac{B}{\ell+2} + \frac{C}{\ell+3} \\ &= \frac{ A (\ell + 2) (\ell + 3) + B(\ell + 1)(\ell + 3) + C(\ell + 1)(\ell + 2)}{ (\ell + 1) (\ell+2) (\ell+3) } \\ &= \frac{ (A + B + C) \ell^2 + (5A + 4B + 3C) \ell + (6A + 3B + 2C)}{(\ell+1)(\ell+2)(\ell+3)}.\end{align*} So we have the resulting system of linear equations \begin{align*} A + B + C &= 0 \\ 5A + 4B + 3C &= 0 \\ 6A + 3B + 2C & = 1 \end{align*}, which has solution $A = C = \frac{1}{2}$ and $B = -1.$ Therefore, $$\frac{1}{(\ell + 1) (\ell + 2)(\ell + 3)} = \frac{1}{2} \frac{1}{\ell+1} - \frac{1}{\ell+2} + \frac{1}{2} \frac{1}{\ell+3},$$ so we have \begin{align*} M &= \sum_{\ell = 0}^\infty \frac{1}{(\ell+1)(\ell+2)(\ell+3)} = \lim_{L\to \infty} \sum_{\ell=0}^L \frac{1}{(\ell+1)(\ell+2)(\ell+3)} \\ &= \lim_{L \to \infty} \sum_{ell=0}^L \left( \frac{1}{2} \frac{1}{\ell+1} - \frac{1}{\ell+2} + \frac{1}{2} \frac{1}{\ell+3} \right) \\ &= \lim_{L \to \infty} \frac{1}{2} \left( 1 + \frac{1}{2} + \frac{1}{3} + \cdots + \frac{1}{L+1} \right) - \left( \frac{1}{2} + \frac{1}{3} + \cdots + \frac{1}{L+1} + \frac{1}{L+2} \right) + \frac{1}{2} \left( \frac{1}{3} + \cdots + \frac{1}{L+1} + \frac{1}{L+2} + \frac{1}{L+3} \right) \\ &= \lim_{L\to \infty} 1 \cdot \frac{1}{2} + \frac{1}{2} \cdot \left( \frac{1}{2} - 1 \right) + \left( \frac{1}{2} - 1 + \frac{1}{2} \right) \cdot \left( \frac{1}{3} + \cdots + \frac{1}{L+1} \right) + \frac{1}{L+2} \cdot \left(-1 + \frac{1}{2} \right) + \frac{1}{L+3} \cdot \frac{1}{2} \\ &= \lim_{L \to \infty} \frac{1}{2} - \frac{1}{4} + O(L^{-2}) = \frac{1}{4}.\end{align*}

Therefore, we have $$\mathbb{P} \{ k \mid c = 3 \} = \frac{4}{(k+1)(k+2)(k+3)},$$ for $k = 0, 1, \dots,$ so we can calculated the conditional expectation as $$\mathbb{E} \left[ K \mid c = 3 \right] = \sum_{k=0}^\infty k \mathbb{P} \{ k \mid c = 3 \} = 4 \sum_{k=0}^\infty \frac{k}{(k+1)(k+2)(k+3)}.$$ As before, we can solve this series by the method of partial fractions. Here instead of the earlier system of equations, we now want to solve \begin{align*} A + B + C &= 0 \\ 5A + 4B + 3C &= 1 \\ 6A + 3B + 2C &= 0 \end{align*} which has solution $A = -\frac{1}{2},$ $B = 2,$ $C = - \frac{3}{2}.$ Thus the conditional expected number of candy corn kernels given that I drew the three peanut butter cups is \begin{align*}\mathbb{E} \left[ K \mid c = 3 \right] &= 4 \sum_{k=0}^\infty \frac{k}{(k+1)(k+2)(k+3)}\\ &= \lim_{L \to \infty} 4 \left(-\frac{1}{2} + \left( -\frac{1}{2} + 2 \right) \cdot \frac{1}{2} + O(L^{-2}) \right) = 4 \cdot \frac{1}{4} = 1.\end{align*}

Sunday, October 20, 2024

How boring can you get?

I have a large, hemispherical piece of bread with a radius of $1$ foot. I make a bread bowl by boring out a cylindrical hole with radius $r,$ centered at the top of the hemisphere and extending all the way to the flat bottom crust.

What should the radius of my borehole be to maximize the volume of soup my bread bowl can hold?

N.B. I originally conceived of this week's Fiddler problem in my mind's eye with the hemispherical bread having a flat upper crust, which led to initially thinking that it was a very weird setup where you keep cutting your cylindrical hole downward until you ever so slightly bump up against the curved bottom crust at which point you stop since obviously otherwise your bread bowl would have a hole in it and your soup would leak out. This is essentially the inverted logic of the handwavy no-surface-tension argument I make below, so in the end I think the math ends up being roughly the same ....

So anyway, freely choosing the coordinate system that best suits me, assume that your bread fills the space $B = \{ (x,y,z) \mid x^2 + y^2 + z^2 \leq 1, z \geq 0 \}.$ Assume that a cylindrical borehole takes would remove the portion of the $B$ that satisfyies $x^2 + y^2 \leq r^2,$ for some radius $r \gt 0.$ Ultimately, since we cannot rely on molecular properties of the varying soups that might fill the bread bowl to postulate any additional volume of soup due to surface tension, let's assume that the bread bowl can only be filled up to its upper rim, that is, the cylindrical cavity is given by $C(r) = \{ (x,y,z) \mid x^2 + y^2 \leq r^2, 0 \lt z \leq \sqrt{1-r^2}\}.$ The volume of $C(r)$ is given by $V(r) = \pi r^2 \sqrt{1-r^2}.$

Differentiating $V(r)$ gives $$V^\prime(r) = 2\pi r \sqrt{1-r^2} + \pi r^2 \left( \frac{-r}{\sqrt{1-r^2}} \right) = \frac{\pi r \left( 2(1-r^2) -r^2 \right)}{\sqrt{1-r^2}} = \frac{\pi r (2-3r^2)}{\sqrt{1-r^2}}.$$ Thus $V$ has critical points as $r_1 = 0$, $r_2 = \sqrt{\frac{2}{3}} = \frac{\sqrt{6}}{3},$ and $r_3 = 1.$ Since $V(0)=V(1)=0,$ the maximum possible volume of soup contained in this bread bowl is $$V^* = \frac{2\pi\sqrt{3}}{9} \approx 1.20919957616\dots$$ cubic feet, which occurs when choosing a radius of $$r^* = \frac{\sqrt{6}}{3} \approx 0.816496580928\dots$$ feet.

Instead of a hemisphere, now suppose my bread is a sphere with a radius of $1$ foot. Again, I make a bowl by boring out a cylindrical shape with radius $r,$ extending all the way to (but not through) the curved bottom crust of the bread. The central axis of the hole must pass through the center of the sphere.

What should the radius of my borehole be to maximize the volume of soup my bread bowl can hold?

Again hearkening back to my earlier spatial reasoning struggles, I could not for the life of me understand why this extra credit problem was in any way different from just having double the volume since you would then stop cutting as soon as you hit the curved bottom crust. Since I take Axiom of the Benevolent Fiddlermeister as a given, I have to assume that the extra credit problem is somehow different from the regular problem, so we will assume that I have a precision instrument that can bore a perfectly cylindrical hole in the spherical bread until I ever so slightly approach the curved lower crust and then somehow liquefy and extract the remaining bready portions all the way down to curved lower crust. So in this case the bowl takes the shape $\tilde{C}(r) = \{ (x,y,z) \mid x^2 + y^2 \leq r^2, -\sqrt{1-x^2-y^2} \lt z \leq \sqrt{1-r^2} \}.$ In this case, the volume is \begin{align*}\tilde{V}(r) &= \int_{ x^2 + y^2 \leq r^2 } \int_{-\sqrt{1-x^2-y^2}}^{\sqrt{1-r^2}} \, dz \,dy \,dx\\ &= \int_{x^2 + y^2 \leq r^2} \left( \sqrt{1-r^2} + \sqrt{1-x^2 -y^2}\right) \,dy \,dx \\ &= \int_0^{2\pi} \int_0^r \left( \sqrt{1-r^2} + \sqrt{1 - \rho^2} \right) \rho \,d\rho \, d\theta \\ &= \pi r^2 \sqrt{1-r^2} + 2\pi \int_0^r \rho \sqrt{1-\rho^2} \,d\rho \\ &= \pi r^2 \sqrt{1-r^2} + \frac{2\pi}{3} \left( 1 - (1-r^2)^{3/2} \right).\end{align*} We can write $(1-r^2)^{3/2} = (1-r^2) \sqrt{1-r^2}$ to then factor even further and see that $$\tilde{V}(r) = \pi r^2 \sqrt{1-r^2} + \frac{2\pi}{3} \left( 1 - (1-r^2) \sqrt{1-r^2} \right) = \frac{2\pi}{3} + \frac{\pi \sqrt{1-r^2}}{3} (5r^2 - 2).$$

Differentiating we get \begin{align*}\tilde{V}^\prime (r) &= \frac{10\pi r}{3} \sqrt{1-r^2} + \frac{\pi}{3} (5r^2 - 2) \left( \frac{-r}{\sqrt{1-r^2}} \right)\\ &= \frac{\pi r}{3\sqrt{1-r^2}} \left( 10 (1-r^2) - (5r^2 - 2) \right)\\ &= \frac{\pi r (4-5r^2)}{\sqrt{1-r^2}}.\end{align*} Thus $\tilde{V}$ has critical points at $r_1 = 0,$ $r_2 = \sqrt{\frac{4}{5}} = \frac{2\sqrt{5}}{5},$ and $r_3 = 1.$ Here since we have $\tilde{V}^\prime \gt 0$ when $r \lt \frac{2\sqrt{5}}{5}$ and $\tilde{V}^\prime \lt 0$ when $r \gt \frac{2\sqrt{5}}{5},$ we see that the maximum possible volume of our miraculously scooped out bread bowls with curved lower crusts is $$\tilde{V}^* = \frac{2\pi(5+\sqrt{5})}{15} \approx 3.03103706653\dots$$ cubic feet, which occurs when choosing a radius of $$\tilde{r}^* = \frac{2\sqrt{5}}{5} \approx 0.894427191\dots$$ feet.

Monday, October 14, 2024

Leading the logarithmic pack

You’re doing a $30$-minute workout on your stationary bike. There’s a live leaderboard that tracks your progress, along with the progress of everyone else who is currently riding, measured in units of energy called kilojoules. Once someone completes their ride, they are removed from the leaderboard.

Suppose many riders are doing the $30$-minute workout right now, and that they all begin at random times. Further suppose that they are burning kilojoules at different constant rates (i.e., everyone is riding at constant power) that are uniformly distributed between $0$ and $200$ Watts.

Halfway through (i.e., $15$ minutes into) your workout, you notice that you’re exactly halfway up the leaderboard. How far up the leaderboard can you expect to be as you’re finishing your workout?

Let's start by determining the distribution of the random other riders' outputs at any one time. At any particular time, say $\tau$, the only riders still on the leaderboard would have started at times $t \in (\tau - 1800, \tau).$ Let's assume that riders join the $30$ minute class uniformly randomly such that the probability that any join between the time $t$ and $t+dt$ is proportional to $dt,$ that is, at time \tau, the riders would have already completed $T \sim U(0,1800)$ seconds of the rider. These riders would also have uniformly distribution constant powers, $P \sim U(0,200).$ The total output is $O = P \cdot T,$ which we can get the distribution of by directly computing the \begin{align*}\mathbb{P} \{ O \leq \theta \} &= \frac{1}{360000}\int_0^{200} \int_0^{1800} \chi \{ p t \leq \theta \} \,dt \,dp \\ &= \frac{1}{360000} \int_0^{200} \int_0^{\min \{ 1800, \theta / p \}} \,dt \,dp \\ &= \frac{1}{360000} \int_0^{200} \min \left\{1800, \frac{\theta}{p} \right\} \,dp \\ &= \frac{1}{360000} \left( \int_0^{\theta/1800} 1800 \,dp + \int_{\theta / 1800}^200 \frac{\theta}{p} \,dp \right) \\ &= \frac{1}{360000} \left( \theta + \theta \left( \ln 200 - \ln (\theta / 1800) \right) \right) \\ &= \frac{\theta}{360000} \left( 1- \ln \left( \frac{\theta}{360000} \right) \right).\end{align*}

So let's simplify slightly and focus on the function $\Phi(t) = t ( 1 - \ln t ).$ So in particular, if at some point I find myself half way up the leaderboard, then that would mean that my output $\tilde{O} = 360000 \tilde{\theta}$ where $\Phi(\tilde{\theta}) = \frac{1}{2}.$ Of course, $\Phi$ does not have a neat and tidy inverse function, so we would have to implicitly solve for $\tilde{\theta} = \Phi^{-1}(0.5),$ but more on this later.

So since the distribution of random riders is time invariant, if halfway through my ride I have output $\tilde{O} = 360000 \Phi^{-1}(0.5),$ then I can expect my output at end of my ride I have output $2\tilde{O}.$ In this case, the proportion of riders that I will be ahead of the leaderboard is \begin{align*}\Phi(2 \Phi^{-1}(0.5)) &= 2\Phi^{-1}(0.5) \left( 1- \ln (2\Phi^{-1}(0.5))\right) \\ &= 2 \Phi^{-1}(0.5) \left( 1- \ln 2 - \ln \Phi^{-1}(0.5) \right) \\ &= -2 \Phi^{-1}(0.5) \ln 2 + 2 \Phi^{-1} (0.5) \left( 1 - \ln \Phi^{-1}(0.5) \right) \\ &= -2 \Phi^{-1}(0.5) \ln 2 + 2 \Phi \left( \Phi^{-1}(0.5) \right) \\ &= 1 - 2 \Phi^{-1}(0.5) \ln 2 = 1 - 2 \tilde{\theta} \ln 2 .\end{align*} So, since we can analytically solve the inverse function to find that $\tilde{\theta} = \Phi^{-1}(0.5) = 0.1866823,$ I can expect to be ahead of about $$1-2 \tilde{\theta} \ln 2 \approx 74.1203380189...\%$$ of the riders at the end of my ride.

As an added bonus problem (though not quite Extra Credit), what’s the highest up the leaderboard you could expect to be $15$ minutes into your workout?

If I am killing it at 200 Watts for the first 15 minutes, then I would have an output of $\hat{O} = 200 \cdot 900 = 180000$ kJ, which would put me ahead of about $$\Phi\left(\frac{\hat{O}}{360000}\right) = \Phi(0.5) = 0.5 (1 + \ln 2) \approx 84.657359028...\%$$ of the riders after $15$ minutes.

Sunday, August 18, 2024

The arc of high jumping bends towards ... 2?

In the high jump, an athlete’s entire body must clear the bar. However, not every part of their body has to clear the bar at the same time. As a result, athletes arc their bodies over the bar, so that only a fraction of their mass is above the bar at any given time. In fact, athletes can theoretically clear the bar despite their center of mass remaining below the bar throughout the jump.

Let’s model the athlete’s jump as an arc of angle $2\phi$ that is centered over the bar, as shown below. For simplicity, assume that their mass is uniformly distributed across the length of their body. The dot in the diagram represents the athlete’s center of mass. Let $a$ represent the vertical distance between the athlete’s center of mass and their lowest points (presumably their outstretched fingers and toes), and let $b$ represent the vertical distance between the athlete’s center of mass and their highest point (presumably their waist).

If $\phi = \frac{\pi}{2}$ then the arc would be a complete semicircle. In that case, what is the ratio $a/b$?

As the angle $\phi$ gets very, very small (i.e., in the limit as $\phi$ goes to zero), what value does the ratio $a/b$ approach?

Let's solve the generic case for $\phi$ so that we can then do the two cases, both when $\phi = \frac{\pi}{2}$ and when $\phi \downarrow 0.$ Since we'll be taking ratios of everything anyway, let's just go ahead and assume that the circle on which the high jumper's arc is lying in the figure has radius $1$ and is centered at the origin. Then, with some trigonometric know-how, we see that the lowest point of the arc will be sitting at a height of $\cos \phi.$ So we must have $a + b = 1 - \cos \phi.$ Additionally we see that the jumper's body has a length of $2\phi,$ the length of this arc. So to find $a,$ we need only take the average of the jumper's height along this arc by taking the integral $$a + \cos \phi = \frac{1}{2\phi} \int_{\frac{\pi}{2} - \phi}^{\frac{\pi}{2} + \phi} \sin t \,dt = \frac{1}{2\phi} \left( -\cos (\frac{\pi}{2} + \phi) + \cos (\frac{\pi}{2} - \phi) \right) = \frac{\cos (\frac{\pi}{2} - \phi) }{\phi} = \frac{\sin \phi}{\phi}.$$ That is, $$a = \frac{\sin \phi}{\phi} - \cos \phi$$ and $$b = 1 - \cos \phi - a = 1 - \frac{\sin \phi}{\phi}.$$ Therefore for any value of \phi, the ratio of $a / b$ is $$r(\phi) = \frac{\frac{\sin \phi}{\phi} - \cos \phi}{1 - \frac{\sin \phi}{\phi}} = \frac{ \sin \phi - \phi \cos \phi }{\phi - \sin \phi}.$$

So in particular, if $\phi = \frac{\pi}{2}$ and the jumper's body makes a complete semicircle then the ratio $a/b$ is $$r(\frac{\pi}{2}) = \frac{\sin \frac{\pi}{2} - \frac{\pi}{2} \cos \frac{\pi}{2} }{\frac{\pi}{2} - \sin \frac{\pi}{2}} = \frac{1}{\frac{\pi}{2} - 1} = \frac{2}{\pi - 2} \approx 1.75193839388....$$

On the other hand, if we use some rough Taylor approximations around $\phi \approx 0$ we see that we have $$r(\phi) = \frac{\left(\phi - \frac{\phi^3}{6} + O(\phi^5)\right) - \phi \left( 1 - \frac{\phi^2}{2} + O(\phi^4)\right)}{\phi - \left(\phi - \frac{\phi^3}{6} + O(\phi^5)\right)} = \frac{ \frac{\phi^3}{3} + O(\phi^5) }{\frac{\phi^3}{6} + O(\phi^2)} = 2 \frac{1 + O(\phi^2)}{1 + O(\phi^2)}.$$ So, as $\phi \downarrow 0,$ we have $r(\phi) \to 2.$

Sunday, July 21, 2024

Tour de Fiddler fun

This time around, a lone rider in the Tour de Fiddler is being pursued by a group of four riders. The four riders have an advantage—they take equal turns being in the lead position, while the other three riders draft behind. At any given speed, being in the lead position (as well as riding solo) requires twice as much power as drafting.

Assume that every rider must maintain the exact same average power over time, whether they are the lone rider or in the pack of four. To be clear, their power can change over time, but the time-averaged value must be the same for every rider. Also, when leading a pursuing group or riding solo, one’s speed is directly proportional to one’s power. When drafting, one's speed matches that of the leader (again, at half the power output).

The pursuers just passed under a banner indicating there are 10 kilometers left in the stage. How far back of the lone rider can they afford to be, such that they still catch them at the finish line?

Let's first start with some preliminaries. Assume that all riders have average power output $\bar{P}$, such that, since speed is directly proportional to ones power, then the average speed of a single rider who has no one to draft off of is $v_1 = C\bar{P},$ for some constant of proportionality $C \gt 0.$

Let's now analyze what would happen if $k$ riders work together, taking equal turns being in the lead position. Since the average power must be $\bar{P},$ but any of the riders in this group spends only $\frac{1}{k}$ amount of time leading and the rest drafting at half-power, the amount of power spent while leading a pack of $k$ riders, say $P_k$, can be found in the equation $$\bar{P} = \frac{1}{k} P_k + \frac{k-1}{k} \frac{1}{2} P_k = \frac{k+1}{2k} P_k,$$ that is, $$P_k = \frac{2k}{k+1} \bar{P}.$$ So that means that the average velocity of a group of $k$ riders working together must be $$v_k = C P_k = C \frac{2k}{k+1} \hat{P} = \frac{2k}{k+1} v_1.$$

Ok, so with that in mind, the pursuers will finish in $T_4 = \frac{10}{v_4} = \frac{25}{4v_1},$ while if the leader has a lead of $x$ kilometers, then he will finish in $T_1 = \frac{10-x}{v_1}.$ Since we want $$T_4 = \frac{25}{4v_1} \leq \frac{10-x}{v_1} = T_1$$ in order for the pursuers to catch the leader, then the leader can be no more than $x \leq \frac{15}{4} = 3.75$ kilometers ahead of the pursuers if they want to catch him.

In today’s stage of the Tour de Fiddler, there are 176 total riders. Some riders are grouped together in a single breakaway, while the remainder are grouped together in the peloton. The breakaway group is 10 kilometers from the finish, while the peloton is one kilometer behind (i.e., 11 kilometers from the finish). What is the smallest number of riders that the breakaway needs to reach the finish line before the pursuing peloton?

Let's say there are $B$ riders in the breakaway group and $P$ riders in the peleton, where here $B+P = 176.$ The average speed of the peleton will be $$v_P = C\frac{2P}{P+1} v_1,$$ while the average speed of the breakaway is $$v_B = C\frac{2B}{B+1} v_1,$$ so the finishing times are $$T_P = \frac{11}{v_P} = \frac{11(P+1)}{2Pv_1}$$ and $$T_B = \frac{10}{v_B} = \frac{10(B+1)}{2Bv_1},$$ respectively. Since we want the breakaway group to win the stage, we must have $T_B \leq T_P,$ or equivalently $$\frac{10B+10}{B} \leq \frac{11P+11}{P},$$ which is again equivalent to $$BP+11B-10P \geq 0.$$ Since we have restriction that $B + P = 176,$ we are now looking for the minimum integer $B$ such that $$B(176-B) + 11B -10(176-B) = -B^2 + 197B - 1760 \geq 0.$$ Since the quadratic inequality holds for all (real) values of $$ B \in \left[ \frac{197 -\sqrt{31769}}{2} , \frac{197 + \sqrt{31769}}{2} \right],$$ we see that the breakaway must have at least $$B_\min = \left\lceil \frac{197 - \sqrt{31769}}{2} \right\rceil = \lceil 9.3806979381.... \rceil = 10$$ riders in order to beat the peleton.

Sunday, June 2, 2024

If this is what the job entails, then I'm not sure I want it ....

Starting with a line segment of length $1$, randomly split it somewhere along its length into two parts. Compute the product of these two lengths. Then take each of the two resulting segments and repeat the process. That is, for each one, randomly split it somewhere along its length into two parts and compute the product. Then do this for all four resulting segments, then the eight after that, and the $16$ after that, and so on.

After doing this (forever), you add up all the products you computed throughout. On average, what value would you expect this sum to approach?

There is nothing magical about the initial value of the line segment, that is, $1$, so let's instead generalize and say that the function $f : \mathbb{R}_+ \to \mathbb{R}_+$ gives the expected value of the sum of the products of randomly splitting a line segment of initial length $\ell \in \mathbb{R}_+$ into two parts, then breaking each of those segments into two parts, etc. Then to restate the question, we want the value of $f(1).$

We can approximate $f$ by not allowing for infinite recursion, but instead just a finite number of breaking into smaller pieces. If we just have one splitting then we get the expected value of the product is $$f_1(\ell) = \int_0^\ell x (\ell-x) \, dx = \left[ \ell \frac{x^2}{2} - \frac{x^3}{3} \right]^\ell_0 = \frac{\ell^3}{6}.$$ Going one step further, we then see that after two splits, we add in the expected product of two uniformly random numbers that add up to $x$ and the expected product of two uniformly random numbers that add up to $\ell - x.$ That is, we get $$f_2(\ell) = \int_0^\ell x(\ell - x) + f_1(x) + f_1(\ell-x) \,dx = f_1(\ell) + 2 \int_0^\ell f_1(x) \,dx.$$ Similarly, if we keep going with more recursion, we get that the expected sum of the products after $n+1$ rounds of splitting is given by $$f_{n+1} (\ell) = f_1 (\ell) + 2\int_0^\ell f_n(x) \,dx,$$ for $n \geq 1.$ As $n \to \infty,$ we get that we must have $$f(\ell) = f_1(\ell) + 2\int_0^\ell f(x)\,dx = \frac{\ell^3}{6} + \int_0^\ell f(x) \,dx.$$ Differentiating both sides with respect to $\ell,$ we get the differential equation $$f^\prime (\ell) = \frac{t^2}{2} + 2f(\ell),$$ with initial conditions $f(0) = 0.$ This is solved by the generic form $f(\ell) = Ce^{2\ell} + p(\ell),$ where $p$ is a polynomial, say $p(t) = at^2 + bt+ c.$ Plugging back into the differential equation we get that $$2at + b = \frac{t^2}{2} + 2at^2 + 2bt + 2c,$$ for all $t.$ By gathering like terms and setting equal to zero, we get \begin{align*}2a + \frac{1}{2} &= 0\\ 2b - 2a &= 0 \\ 2c - b &= 0, \end{align*} that is $a = b = -\frac{1}{4}$ and $c = -\frac{1}{8}.$ Additionally, we have $f(0) = C - \frac{1}{8} = 0,$ so $C = \frac{1}{8}.$ So finally, we see that $$f(\ell) = \frac{e^{2\ell} - 2\ell^2 -2\ell -1}{8},$$ and so the expected value of the sum of the products of random splitting into two subparts is $$f(1) = \frac{e^2 - 5}{8} \approx 0.29863201236.....$$

But wait ... there's more, what if as opposed to two pieces, each time we randomly split, we split into three pieces. Let $g: \mathbb{R}_+ \to \mathbb{R}_+$ be the expected value of the sum of the random triple products of splitting a line segement of initial length $\ell \in \mathbb{R}_+.$ Here too we can demonstrate the recurrence with a few small number of splits.

We see that after one splitting we get $$g_1(\ell) = \int_0^\ell \int_0^{\ell - x} xy(\ell - x -y) \,dy \,dx = \int_0^\ell x f_1(\ell - x) \,dx = \int_0^\ell x \frac{(\ell - x)^3}{6} \,dx = \frac{\ell^5}{120}.$$ If we again split each piece into three then after two splittings we have the original value of original splitting, followed by the expected product of three uniformly random numbers that add up to $x$, the expected product of three random numbers that add up to $y$, and the expected product of three random numbers that add up to $\ell - x - y.$ That is, \begin{align*}g_2(\ell) &= \int_0^\ell \int_0^{\ell - x} xy(\ell - x - y) + g_1(x) + g_1(y) + g_1(\ell - x - y) \,dy\,dx\\ &= g_1(\ell) + 3 \int_0^\ell (\ell - x) g_1(x) \,dx.\end{align*} In fact, this relation holds for any arbitrary number of splits, $n \geq 1,$ that is $$g_{n+1}(\ell) = g_1(\ell) + 3 \int_0^\ell (\ell-x) g_n(x) \,dx$$ and in particular as $n \to \infty$ we get $$g(\ell) = \frac{\ell^5}{120} + 3\int_0^\ell (\ell - x) g(x) \, dx.$$

Let's define the integral of $g$ to be $G(\ell) = \int_0^\ell g(x)\,dx.$ Differentiating under the integral sign with respect to $\ell,$ we get $$g^\prime(\ell) = \frac{\ell^4}{24} + 3\int_0^\ell g(x) \,dx = \frac{\ell^4}{24} + 3G(\ell).$$ Differentiating once more gives the second order inhomogeneous differential equation $$g^{\prime\prime}(\ell) - 3g(\ell) = \frac{\ell^3}{6},$$ where $g(0) = g^\prime(0) = 0.$ This is solved by a function of the form $$g(\ell) = C \sinh (\sqrt{3} \ell) + p(\ell),$$ where $p$ is a polynoial, say $p(t) = at^3 + bt^2 + ct + d.$ Plugging back into the differential equation we get $$6at + 2b - 3(at^3 + bt^2 + ct+d) = \frac{t^3}{6},$$ for all $t.$ By gathering terms and setting equal to zero, we get \begin{align*} -3a &= \frac{1}{6} \\ b &= 0 \\ 6a-3c &= 0 \\ 2b -3d &= 0, \end{align*} that is $a = -\frac{1}{18}, $$b = d = 0,$ and $c = -\frac{1}{9}.$ Additionally, we have $g^\prime(0) = \sqrt{3} C - \frac{1}{9} = 0,$ so $C = \frac{\sqrt{3}}{27}.$ So finally, we see that $$g(\ell) = \frac{2\sqrt{3} \sinh (\sqrt{3} \ell) - 3\ell^3 - 6\ell}{54},$$ and so the expected value of the sum of the triple products of random splittings into three subparts is $$g(1) = \frac{2\sqrt{3} \sinh(\sqrt{3}) - 9}{54} \approx 0.00895406261852....$$

Monday, April 15, 2024

The Great Ellipse Eclipse

[S]uppose you have two congruent ellipses that, together, cover a unit circle (i.e., a circle with radius $1$). These ellipses can have any eccentricity you like, but they must be congruent to each other. What is the smallest possible area one of these ellipses can have, such that they completely cover the circle?

By symmetry (both rotational and optimization-al?), let's assume that we have two congruent ellipses that have parallel major axis along the $y$-axis and are centered at points $(c,0)$ and $(-c,0)$ for some $c > 0.$ That is, let the equations for the ellipses be \begin{align*} \frac{(x-c)^2}{a^2} + \frac{y^2}{b^2} &= 1 \\ \frac{(x+c)^2}{a^2} + \frac{y^2}{b^2} &= 1.\end{align*}

In order to ensure that these two ellipses cover the entire unit circle we would need to make sure that they cover the extreme points, $(\pm 1, 0)$ and $(0, \pm 1)$ (and for good measure that the origin is contained at least one of them). In order for the origin to be contained we can plug in $x=y=0$ and get $$\frac{c^2}{(1-c)^2} \leq 1,$$ or equivalently $2c - 1 \leq 0,$ or $c \leq \frac{1}{2}.$ In order for $(1,0)$ to be contained in the ellipse centered at $(c,0)$ we must have $$\frac{(1-c)^2}{a^2} + \frac{0}{b^2} = 1,$$ or equivalently $a = 1 - c.$ In order for (0,1) to be contained in either ellipse we must have $$\frac{c^2}{(1-c)^2} + \frac{1}{b^2} = 1$$ or equivalently $$b^2 = \frac{1}{1 - \frac{c^2}{(1-c)^2}} = \frac{(1-c)^2}{(1-c)^2 - c^2} = \frac{(1-c)^2}{1-2c},$$ that is, $b = \frac{1-c}{\sqrt{1-2c}}.$

The area of one of the ellipses is $$A(c) = \pi a(c)b(c) = \pi \frac{(1-c)^2}{\sqrt{1-2c}}.$$ Differentiating we get \begin{align*}\frac{\partial}{\partial c} A(c) &= \pi \left(\frac{(1-c)^2}{(1-2c)^{3/2}} + \frac{2(c-1)}{\sqrt{1-2c}} \right)\\ &= \pi\frac{ (1-c)^2 - 2 (1-2c) (1-c) }{(1-2c)^{3/2}}\\ &= \frac{\pi(1-c)(3c-1)}{(1-2c)^{3/2}}.\end{align*} So the unconstrained critical points of $A$ are $c = 1$ and $c = \frac{1}{3}.$ Since we want $c \leq \frac{1}{2},$ we can eliminate the critical point $c = 1,$ and instead need to just test the critical points $c \in \left\{ 0, \frac{1}{3}, \frac{1}{2} \right\}.$ We have $A(0) = \pi,$ and $\lim_{c \uparrow \frac{1}{2}} A(c) = +\infty$ and $$A\left(\frac{1}{3}\right) = \pi \frac{ \frac{4}{9} }{ \sqrt{\frac{1}{3} }} = \frac{4\pi \sqrt{3}}{9} \approx 2.418399....,$$ which is the smallest area of one ellipse of a congruent pair that can cover the unit circle. For completeness, those ellipses are \begin{align*} \frac{ (3x - 1)^2 }{4} + \frac{3y^2}{4} &= 1 \\ \frac{(3x+1)^2}{4} + \frac{3y^2}{4} &= 1\end{align*}

Monday, March 4, 2024

Let them eat equitable cake slices

You and two friends all have March birthdays, so you’ve decided to celebrate together with one big cake that has delicious frosting around its perimeter. To share the cake fairly, you want to ensure that (1) each of you gets the same amount of cake, by area, and (2) each of you gets the same amount of frosting along the cake’s edge. What’s more, you want to cut the cake by starting at a single point inside of it, and then making three straight cuts to the edge from that point.

As shown in the Fiddler email, you know how to make these cuts for circular or square cakes. However, the cake you bought is rectangular, with a length of 20 inches and a width of 10 inches. Using the coordinate system of your choice, describe a way this particular cake can be cut fairly, so that all three of you get the same amount in terms of both area and the cake’s perimeter. Again, there should be three straight cuts emanating from a single point inside the cake.

Let's put the lower left corner of our sheet cake at the origin of the $xy$-plane with opposite corner located at the point $(20,10)$, so that the long 20in side of the cake is parallel to the $x$-axis. Assume that one of the straight cuts ends up hitting the point $(t,0)$ for some $0\leq t\leq 10$. Then since each birthday person needs one third of the perimeter, the other two cuts must hit the perimeter of the sheet cake at $(20,t)$ and $(10-t,10)$.

If start cutting at the central point within the cake $P=P(x,y)$, then the upper right quadrilateral has area \begin{align*}A_1 &= \frac{1}{2} (10+t) (10 - y) + \frac{1}{2} (10 - t) (20 - x)\\& = 150 - 5t -\frac{1}{2} (10-t) x -\frac{1}{2} (10+t) y,\end{align*} while the lower right quadrilateral has area \begin{align*}A_2 &= \frac{1}{2} (20-t) y + \frac{1}{2} t (20 - x) \\ &= 10t -\frac{1}{2} t x +\frac{1}{2} (20-t) y.\end{align*} Imposing the condition that all three pieces of cake have the same area is mathematically equivalent to ensuring that $A_1 = A_2 = \frac{200}{3}$ which yields the following system of equations \begin{align*} (10-t) x + (10+t) y & = \frac{500-30t}{3} \\ -t x + (20-t) y & = \frac{400-60t}{3}.\end{align*} Solving for $x=x(t)$ and $y=y(t),$ we get $$P(t)=\begin{pmatrix} x(t)\\ y(t) \end{pmatrix} = \begin{pmatrix} 10-t & 10 + t \\ -t & 20-t \end{pmatrix}^{-1} \begin{pmatrix} \frac{500 -30t}{3} \\ \frac{400-60t}{3}\end{pmatrix} = \begin{pmatrix} \frac{15t^2-150t+1000}{t^2-10t +100} \\ \frac{15t^2-200t+250}{3(t^2-10t+100)} \end{pmatrix}.$$ Though the points won't exactly be correct, we can extend for $10 \leq t \leq 20$ by appealing to symmetry, from which we can define $x(t) = 20 - x(20-t)$ and $y(t)=y(20-t)$ whenever $10\leq t \leq 20.$

One solution (for $t=0$) has the center point $P(0)=(10, 20/3),$ with cuts hitting the perimeter at points $(0,0),$ $(20,0)$ and $(10,10).$

The parametric curve $P(t)=(x(t), y(t))$ encloses an area that can be approximated by the Riemann sum through horizontal slices for a given partition $t_0 = 0 \lt t_1 \lt \cdots \lt t_{N-1} \lt t_N = 10,$ as \begin{align*}A_N &= \sum_{i=1}^N \left(x(20 - t_{i-1}) - x(t_{i-1}) \right) \left(y(t_{i-1}) - y(t_i) \right) \\ &= \sum_{i=1}^N 2 \left(10 - x(t_{i-1}) \right) \frac{y(t_{i-1}) - y(t_i)}{t_i - t_{i-1}} \left( t_i - t_{i-1} \right).\end{align*} As $N \to \infty,$ we get that the area enclosed within the parametric curve of center points for the equitable area and perimeter cuts is given by \begin{align*}A &= \lim_{N \to \infty} A_N = -2 \int_0^{10} ( 10 - x(t) ) \frac{d}{dt} y(t) dt\\ &= \frac{1000}{3} \int_0^{10} \frac{(t^2 - 10t) (t^2 - 10t - 50)}{(t^2 - 10t + 100)^3} \,dt \\ &= \frac{1000}{3} \int_0^{10} \frac{t^4 - 20t^3 + 50t^2 + 500t}{(t^2 - 10t + 100)^3} \,dt \\ &= \frac{200}{27} \left[ \sqrt{3}\arctan \left( \frac{x-5}{5\sqrt{3}} \right) - \frac{30(x-5)^3}{(x^2 - 10x + 100)^2} \right]^{x=10}_{x=0} \\ &= \frac{400}{27} \left( \sqrt{3} \arctan\left(\frac{1}{\sqrt{3}}\right) - \frac{3}{8} \right) = \frac{50 \left( 4 \sqrt{3} \pi - 9 \right)}{81}\\ &\approx 7.879995... \,\, \text{in}^2.\end{align*}

Monday, February 26, 2024

I come to bury the Niners, not to praise them

Football is complicated, so let’s assume a simplified scoring model. Every time your team is on offense, suppose there’s a 1-in-3 chance they score a touchdown (which we’ll say is worth a total of 7 points, as we won’t bother with 2-point conversions here), a 1-in-3 chance they score a field goal (worth 3 points), and a 1-in-3 chance they don’t score any points (i.e., they punt or turn the ball over on downs). After any of these three things happens, your team will then be on defense and the other team will have the same scoring probabilities.

Now, here’s how overtime will work: Your team is on offense first. No matter how many points your team does or does not score, the other team then gets a chance at offense. If the game is still tied beyond this point, the teams will continue alternating between offense and defense. Whichever team scores next wins immediately. Again, your team is on offense first. What is your team’s probability of winning?

In this first model, each team has a probability $p_0$ of scoring no points, $p_3$ of scoring 3 points, and $p_7$ of scoring 7 points, with $p_0 + p_3 + p_7 = 1.$ Though, I suppose, you don't hope to get there, let's first analyze what happens if you end up getting to sudden death.

The probability of you winning in sudden death in your first possession of sudden death is $p_3 + p_7 = 1-p_0.$ Of course the only way that you could get to a second possession in sudden death is to first score nothing (with probability $p_0$) and have you opponent also score nothing (with probability $p_0$), and then to score with probability $1-p_0$. That is, the probability of scoring in sudden death on your second possession is $p_0^2 (1-p_0).$ Similarly, we can reason that the probability of winning on your $k$th possession in sudden death must by $(k-1)$ rounds of both teams not scoring, then you scoring in the $k$th possession, for a probability of $p_0^{2(k-1)}(1-p_0).$ Adding this all up, the probability of you winning in sudden death conditional on making it to sudden death is $$p_{SD} = \mathbb{P} \{ W \mid SD \} = \sum_{k=1}^\infty p_0^{2(k-1)} (1-p_0) = \frac{1-p_0}{1-p_0^2} = \frac{1}{1+p_0}.$$

If your first drive ends in scoring $7$, then there are two outcomes based on your opponent's outcomes, either (a) your opponent scores less than $7$, with probability $p_0 + p_3$, and you win; or (b) you enter sudden death, with probability $p_7$. So the probability of winning conditional on scoring a TD in your first drive is $$\Pi_7 = \mathbb{P} \{ W \mid 7 \} = p_0 + p_3 + p_7 p_{SD} = p_0 + p_3 + \frac{p_7}{1+p_0}.$$

If your first drive ends in scoring $3$, then there are three outcomes based on your opponent's outcomes, either (a) your opponent scores zero, with probability $p_0$, and you win; or (b) you enter sudden death, with probability $p_3$; or (c) your opponent scores 7, with probability $p_7,$ and you lose. So the probability of you winning conditional on scoring a FG in your first drive is $$\Pi_3 = \mathbb{P} \{ W \mid 3 \} = p_0 + p_3 p_{SD} = p_0 + \frac{p_3}{1 + p_0}.$$

If you don't score in your first drive, then you either (a) lose, with probability $p_3 + p_7$; or (b) enter into sudden death, with probability $p_0$. So the probability of you winning conditional on not scoring in your first drive is $$\Pi_0 = \mathbb{P} \{ W \mid 0 \} = p_0 p_{SD} = \frac{p_0}{1+p_0}.$$

Putting these all together, you have a total probability of winning if you go first of $$\Pi (p_0, p_3, p_7) = p_0 \Pi_0 + p_3 \Pi_3 + p_7 \Pi_7 = p_0p_3 + p_0p_7 + p_3p_7 + \frac{p_0^2 + p_3^2 + p_7^2}{1 + p_0}.$$ In this case, if, as in our toy model, we have $p_0 = p_3 = p_7 = \frac{1}{3}$, then the probability of winning if you go first is $$\Pi = \Pi(\frac{1}{3}, \frac{1}{3}, \frac{1}{3}) = \frac{1}{3^2} + \frac{1}{3^2} + \frac{1}{3^2} + \frac{\frac{1}{3^2} + \frac{1}{3^2} + \frac{1}{3^2}}{1 + \frac{1}{3}} = \frac{1}{3} + \frac{1}{4} = \frac{7}{12}.$$

Let's add this complexity to the model: When either team is on offense, they now have a choice. They can still opt for a strategy that results in 7 points, 3 points, or 0 points, each with a 1-in-3 chance. Alternatively, they can opt for a more aggressive strategy that results in 7 points or 0 points, each with a 1-in-2 chance.

Your team remains on offense first. Assuming both teams play to maximize their own chances of Super Bowl victory, now what is your team’s probability of winning?

So let's introduce $\tilde{p}_7,$ which is the probability of a TD under the aggressive offensive strategy, and $\tilde{p}_0 = 1 - \tilde{p}_7,$ which is the probability of not scoring under the aggressive offensive strategy. Let's first confirm that the probability of winning conditional on getting to sudden death in the more complicated model, $\tilde{p}_{SD},$ remains the same as before ( that is $\tilde{p}_{SD} = p_{SD})$), if and only if $p_3 + p_7 \geq \tilde{p}_7.$ If the parameters are such that rather $\tilde{p}_7 \gt p_3 + p_7,$ then we have $\tilde{p}_{SD} = \frac{1}{1+\tilde{p}_0},$ that is, $$\tilde{p}_{SD} = \frac{1}{1 + \min \{ p_0, \tilde{p}_0 \} }.$$

So let's now go through the various cases. If you score a TD in your first drive, then your opponent will win with probability $\tilde{p}_7 ( 1 - \tilde{p}_{SD} )$ and lose with probability $\tilde{p}_0 + \tilde{p}_7\tilde{p}_{SD}$ when he pursues the aggressive strategy. If he goes with the standard strategy, he will win with probability $p_7 (1 - \tilde{p}_{SD})$ and lose with probability $p_0 + p_3 + p_7 \tilde{p}_{SD}.$ So since your opponent will chose his own maximal winning probability that is equivalent to your minimal winning probability, so your probability of winning if you score a TD in your first drive if $$\tilde{\Pi}_7 = \min \{ \tilde{p}_0 + \tilde{p}_7 \tilde{p}_{SD}, p_0 + p_3 + p_7 \tilde{p}_{SD} \} = \frac{1 + \min\{\tilde{p}_0, 1-p_7\} \min \{p_0, \tilde{p}_0\}}{1 + \min \{ p_0, \tilde{p}_0 \}}.$$

If you score a FG in your first drive, then your opponent will have a $\tilde{p}_7$ chance of winning and $\tilde{p}_0$ chance of losing in the aggressive strategy. On the other hand, if using the standard strategy, your opponent will have a $p_7 + p_3 ( 1 - \tilde{p}_{SD} )$ probability of winning and a $p_0 + p_3 \tilde{p}_{SD}$ chance of losing. Thus, if you score a FG in your first drive, your probability of winning is $$\tilde{\Pi}_3 = \min \{\tilde{p}_0, p_0 + p_3\tilde{p}_{SD}\} = \min \left\{ \tilde{p}_0, \frac{1 - p_7 + p_0 \min \{p_0, \tilde{p}_0\}}{1 + \min \{p_0, \tilde{p}_0\}} \right\}.$$

If you do not score in your first drive, then your opponent will have a $p_3 + p_7 + p_0 (1 - \tilde{p}_{SD})$ probability of winning in a $p_0 \tilde{p}_{SD}$ probability of losing in the standard offense strategy. On the other hand, your opponent will have a $\tilde{p}_7 + \tilde{p}_0 (1 - \tilde{p}_{SD}) = 1 - \tilde{p}_0 \tilde{p}_{SD}$ probability of winning and $\tilde{p}_0 \tilde{p}_{SD}$ probability of losing in the aggressive strategy. So, if you don't score in your first drive your win probability is $$\tilde{\Pi}_0 = \min \{ p_0 \tilde{p}_{SD}, \tilde{p}_0 \tilde{p}_{SD} \} = \min \{p_0, \tilde{p}_0\} \tilde{p}_{SD} = \frac{\min \{p_0, \tilde{p}_0\}}{1 + \min \{ p_0, \tilde{p}_0 \} }.$$

So the total probability of winning is $$\tilde{\Pi} = \tilde{\Pi}(p_0, p_3, p_7, \tilde{p}_0, \tilde{p}_7) = \max \{ \tilde{p}_7 \tilde{\Pi}_7 + \tilde{p}_0 \tilde{\Pi}_7, p_7 \tilde{\Pi}_7 + p_3 \tilde{\Pi}_3 + p_0 \tilde{\Pi}_0 \}.$$ Given our parameters where $p_0 = p_3 = p_7 = \frac{1}{3}$ and $\tilde{p}_0 = \tilde{p}_7 = \frac{1}{2},$ the probability of winning when you go first in the updated model is \begin{align*} \tilde{\Pi}_0 &= \frac{ \min\{ \frac{1}{3}, \frac{1}{2} \} }{ 1 + \min \{ \frac{1}{3}, \frac{1}{2} \} } &= \frac{1}{4} \\ \tilde{\Pi}_3 &= \min \left\{ \frac{1}{2}, \frac{ 1- \frac{1}{3} + \frac{1}{3} \min \{ \frac{1}{3}, \frac{1}{2} \} }{ 1 + \min \{ \frac{1}{3}, \frac{1}{2} \} } \right\} &= \frac{1}{2} \\ \tilde{\Pi}_7 &= \frac{ 1 + \frac{1}{2} \min \{ \frac{1}{3}, \frac{1}{2} \} }{1 + \min \{ \frac{1}{3}, \frac{1}{2} \} } &= \frac{7}{8}\end{align*} In this case, the probability $$\tilde{\Pi} = \max \{ \frac{1}{2} \frac{7}{8} + \frac{1}{2} \frac{1}{4}, \frac{1}{3} \frac{7}{8} + \frac{1}{3} \frac{1}{2} + \frac{1}{3} \frac{1}{4} \} = \max \{ \frac{9}{16}, \frac{13}{24} \} = \frac{9}{16}.$$

Altogether this was not the dunking on the Niners and their decision that I hoped it would be, but luckily, whether the decision was correct or not, the Niners lost. That, in the end, is all that really matters!!!

Monday, February 5, 2024

Many, many, many to one function

For any positive, base-$10$ integer $N$, define $f(N)$ as the number of times you have to add up its digits until you get a one-digit number. For example, $f(23) = 1$ because $2+3 = 5$, a one-digit number. Meanwhile, $f(888) = 2,$ since $8+8+8 = 24,$ a two-digit number, and then adding up those digits gives you $2+4 = 6,$ a one-digit number. Find the smallest whole number $N$ such that $f(N) = 4.$

Clearly $\min f^{-1}(\{1\}) = 10,$ so we must figure out what the smallest integer whose base-$10$ digits sum to $10.$ In this case, we can guess and peck, and arrive at $19$. It becomes slightly harder to figure out the smallest integer whose base-$10$ digits sum to $19.$ Certainly there are no two digit numbers that sum to 19, since the maximum sum of base-$10$ digits of any two digit number is $18$. So let's look for three digit numbers $N = 100a + 10b + c$ where $a + b + c = 19,$ $a \in \{1, 2, \dots, 9\}$ and $b, c \in \{0, 1, \dots, 9\}.$ Obviously the minimal number involves $a = 1,$ where then $b=c=9.$

So we have $f(199) = 3.$ However, we want to now figure out what is the smallest integer whose base-$10$ digits sum to $199,$ since this will give us $\min f^{-1}(\{4\}).$ Since any $22$ digit number will sum to no more than $198,$ we should look for a $23$ digit number. In particular, if the first digit is a $1$ and it is followed by twenty-two $9$'s, then we would get $199$ as the sum of the digits. So, $N = 19,999,999,999,999,999,999,999$ is the smallest integer with $f(N) = 4.$

Let's enumerate the first $10,000$ values of the function $f.$ We can see that $f(N) = 0$ for $N \in \{1, 2, \dots, 9\}.$ As we saw before, $f(N) = 1$ for $N = 10, 11, dots, 18$ and then $f(19) = 2.$ Similarly, $f(N) = 1$ for $N = 20, \dots, 27$ and then $f(N) = 2$ for $N = 28$ and $N=29.$ Since, the maximum sum of the digits for of any integer $N \leq 10,000$ is $36,$ if all we wanted to do is determine which numbers in the first $10,000$ have value $f(N) = 3,$ we therefore only need to worry about numbers $N$ whose digits sum to either $19,$ $28$ or $29.$

We have already seen that, e.g., $199$ satisfies $f(199) = 3.$ By cleverly adding $90$ and $99,$ both of which preserve the total sum of digits provided that the $1000$'s digit remains unchanged, that there are $44$ other three digit numbers $N$ with $f(N) = 3,$ namely $289,$ $298,$ $379,$ $388,$ $398,$ $469,$ $478,$ $487,$ $496,$ $559,$ $568,$ $577,$ $586,$ $595,$ $649,$ $658,$ $667,$ $676,$ $685,$ $694,$ $739,$ $748,$ $757,$ $766,$ $775,$ $784,$ $793,$ $829,$ $838,$ $847,$ $856,$ $865,$ $874,$ $883,$ $892,$ $919,$ $928,$ $937,$ $946,$ $955,$ $964,$ $973,$ $982,$ and $991.$ We can continue adding other cleverly conjured addends (e.g., $900$) that preserve the sum of digits, or just let some even smarter computer run through all of the numbers for us. In the end, we get a total of $945$ integers $N$ with $1\leq N \leq 10,000$ and $f(N)=3$.

Monday, January 29, 2024

One square makes you faster, one square makes you slow...

A very tiny Alice (not to be confused with the Alice from last week) is racing across a 2-by-2 chessboard, as shown below, where each smaller square has a side length of 1 cm. Alice starts at the bottom-left corner of the bottom-left black square and is trying to reach the top-right corner of the top-right black square.

There’s just one catch. Alice moves faster on the white squares than she does on the black squares. Her speed on the white squares is 1 cm per minute (again, she’s very small), while her speed on the black squares is 0.9 cm per minute. What’s the least amount of time it will take her to reach the finish?

Since within each square, Alice's speed is constant, she will travel in straight lines within each square making a piecewise straight path from the lower left corner, at $(0,0)$, to upper right corners, at $(2,2)$. Let's say, based on the augmented picture below, that Alice first cuts a straight line for the point $(1,h)$ through the dark square, then heads to the point $(2-k, 1),$ before finishing at $(2,2),$ for some $0 \leq h, k \leq 1.$

The time elapsed in minutes by Alice for this path is $$T(h,k) = \frac{10}{9} \left( \sqrt{1 + h^2} + \sqrt{1 + k^2} \right) + \sqrt{ (1-h)^2 + (1-k)^2 }.$$ Taking the the gradient of the time elapsed function gives $$\nabla T = \begin{pmatrix} \frac{10h}{9\sqrt{1+h^2}} - \frac{1-h}{\sqrt{(1-h)^2 + (1-k)^2}} \\ \frac{10k}{9\sqrt{1+k^2}} - \frac{1-k}{\sqrt{(1-h)^2 + (1-k)^2}} \end{pmatrix}.$$ Setting the partial derivative with respect to $h$ to zero, we get $$\frac{10h}{9\sqrt{1+h^2}} = \frac{1-h}{\sqrt{(1-h)^2 + (1-k)^2}}.$$ Setting the partial derivative with respect to $k$ to zero, we get $$\frac{10k}{9\sqrt{1+k^2}} = \frac{1-k}{\sqrt{(1-h)^2 + (1-k)^2}}.$$ Combining these, we see that this would imply that $$\frac{h}{(1-h)\sqrt{1+h^2}} = \frac{k}{(1-k)\sqrt{1+k^2}},$$ which since $f(x) = \frac{x}{(1-x)\sqrt{1+x^2}}$ is monotonically increasing for $x \geq 0$ implies that $h = k.$ In this case, we get that we must have $$\frac{10h}{9\sqrt{1+h^2}} = \frac{1-h}{\sqrt{(1-h)^2 + (1-h)^2}} = \frac{1}{\sqrt{2}},$$ or equivalently $$\frac{h}{\sqrt{1+h^2}} = \frac{9\sqrt{2}}{20}.$$ Squaring both sides and solving for $h$, we get $h^2 ( 1 - \frac{81}{200} ) = \frac{81}{200},$ which give an optimal value of $h^* = k^* = \frac{9}{\sqrt{119}}.$ Plugging back into the time elapsed, shows that Alice can get reach the finish optimally in \begin{align*}T^* &= T\left( \frac{9}{\sqrt{119}}, \frac{9}{\sqrt{119}} \right) \\ &= \frac{20}{9} \sqrt{ 1 + \frac{81}{119} } + \sqrt{ \left(1 - \frac{9}{\sqrt{119}}\right)^2 + \left(1 - \frac{9}{\sqrt{119}} \right)^2 } \\ &= \frac{200 \sqrt{2}}{9 \sqrt{119}} + \sqrt{2} \left( 1 - \frac{9}{\sqrt{119}} \right) = \frac{\sqrt{2}}{\sqrt{119}} \left( \frac{200}{9} - 9 + \sqrt{119} \right)\\ &= \sqrt{2} \left( 1 + \frac{\sqrt{119}}{9} \right) \approx 3.12835... \,\text{minutes}.\end{align*}

Expanding Alice's journey to go to the final position of $(8,8),$ we can rely on certain portions of the argument for the $(2,2)$ case, but there are certainly some additional complications. Here we will generically have 14 possible values $h_1, \dots, h_{14}$ as shown in the figure below, we can rely on the symmetry to reduce the number of variables by a factor of two (i.e., $h_1 = h_{14}$, $h_2 = h_{13}$, $\dots$, $h_7 = h_8$).

In this case, we find that the time elapsed by Alice in minutes is \begin{align*}\tilde{T}(h_1, \dots, h_7) &= \frac{20}{9} \left( \sqrt{1+h_1^2} + \sum_{i=1}^3 \sqrt{h_{2i}^2 + h_{2i+1}^2} \right) \\ &\quad\quad+ 2\sqrt{(1-h_1)^2 + (1-h_2)^2} + 2\sqrt{(1-h_3)^2 + (1-h_4)^2}\\ &\quad\quad\quad + 2\sqrt{(1-h_5)^2 + (1-h_6)^2} + \sqrt{2} (1 - h_7).\end{align*}

In this case we can take the gradient of $\tilde{T}$ and get $$\nabla \tilde{T} (h) = \begin{pmatrix} \frac{20h_1}{9 \sqrt{1+h_1^2} } - \frac{2(1-h_1)}{\sqrt{ (1-h_1)^2 + (1-h_2)^2}} \\ \frac{20h_2}{9 \sqrt{h_2^2 + h_3^2} } - \frac{2(1-h_2)}{\sqrt{(1-h_1)^2 + (1-h_2)^2}} \\ \frac{20h_3}{9 \sqrt{h_2^2 + h_3^2} } - \frac{2(1-h_3)}{\sqrt{ (1-h_3)^2 + (1-h_4)^2}} \\ \frac{20h_4}{9 \sqrt{h_4^2 + h_5^2} } - \frac{ 2(1-h_4)}{\sqrt{ (1-h_3)^2 + (1-h_4)^2} } \\ \frac{20h_5}{9 \sqrt{h_4^2 + h_5^2} } - \frac{2 (1-h_5)}{\sqrt{(1-h_5)^2 + (1-h_6)^2}} \\ \frac{20h_6}{9 \sqrt{h_6^2 + h_7^2} } - \frac{ 2 (1-h_6) }{ \sqrt{ (1-h_5)^2 + (1-h_6)^2 } } \\ \frac{20h_7}{9 \sqrt{h_6^2 + h_7^2} } - \sqrt{2} \end{pmatrix}.$$ Let's first assume that there is some solution $\hat{h}$ in the interior of $[0,1]^7,$ where $\tilde{T}$ is infinitely differentiable. If we set the gradient to zero and solve for the last equation, we get that $$\frac{h_7^2}{h_6^2 + h_7^2} = \frac{81}{200},$$ which implies that $$\frac{h_6^2}{h_6^2 + h_7^2} = \frac{119}{200}.$$ Plugging this back into the second to last coordinate, we get that $$\frac{(1-h_6)^2}{(1-h_5)^2 + (1-h_6)^2} = \frac{1}{4} \frac{400}{81} \frac{119}{200} = \frac{119}{162},$$ which in turn implies that $$\frac{(1-h_5)^2}{(1-h_5)^2 + (1-h_6)^2} = \frac{43}{162}.$$ Plugging this into the third to last coordinate, we get that $$\frac{h_5^2}{h_4^2 + h_5^2} = \frac{81}{400} \cdot 4 \cdot \frac{43}{162} = \frac{43}{200},$$ which implies that $$\frac{h_4^2}{h_4^2 + h_5^2} = \frac{157}{200}.$$ Plugging this into the next coordinate, we get that $$\frac{(1-h_4)^2}{(1-h_3)^2 + (1-h_4)^2} = \frac{1}{4} \frac{400}{81} \frac{157}{200} = \frac{157}{162},$$ which implies that $$\frac{(1-h_3)^2}{(1-h_3)^2 + (1-h_4)^2} = \frac{5}{162}.$$ Continuing onward, this implies that $$\frac{h_3^2}{h_2^2 + h_3^2} = \frac{81}{400} \cdot 4 \cdot \frac{5}{162} = \frac{1}{40},$$ which in turn means that $$\frac{h_2^2}{h^2_2 + h^2_3} = \frac{39}{40}.$$ Plugging this value into the second coordinate and solving gives $$\frac{(1-h_2)^2}{(1-h_1)^2 + (1-h_2)^2} = \frac{1}{4} \frac{400}{81} \frac{39}{40} = \frac{65}{54};$$ however, this is a contradiction since for any $a, b \in \mathbb{R},$ $$\frac{a^2}{a^2 + b^2} \leq 1.$$ Therefore, there must not be some solution in the interior of $[0,1]^7.$

Instead, we must have solutions with some variables on the endpoints of $\{0, 1\}.$ While the contradiction above was arrived at by initially setting $h_7$ to something nonzero, we will arrive at similar contradictions unless we have $h_4 = h_5 = h_6 = h_7 = 0,$ since if let's say that $h_4 > 0 = h_5,$ then since the normal cone of $[0,1]^7$ at $h$ is given by $$\mathcal{N}_{[0,1]^7}(h) = \left\{ y \in \mathbb{R}^7_{-} \mid y_i h_i = 0 \right\}$$ in order for $h$ to be an optimizer of $\tilde{T}$ on $[0,1]^7$ we would need to have $$\frac{\partial}{\partial h_5} \tilde{T} = \frac{20}{9} - \frac{2 (1-h_4)}{\sqrt{(1-h_3)^2 + (1-h_4)^2} = 0,$$ which again since $$0 \leq \frac{1-h_4}{\sqrt{(1-h_3)^2 + (1-h_4)^2} } \leq 1$$ for all values of $h_3, h_4 \in [0,1]$ we will be hard pressed to solve. So let's then reduce the problem to optimizing the further reduced function \begin{align*}\check{T} (h_1, h_2, h_3) &= \tilde{T} (h_1, h_2, h_3, 0, 0, 0, 0)\\ &= \frac{20}{9} \left( \sqrt{1 + h_1^2} + \sqrt{h_2^2 + h_3^2} \right)\\ &\quad\quad + \sqrt{ (1-h_1)^2 + (1-h_2)^2 } + \sqrt{ 1 + (1-h_3)^2 } + 3 \sqrt{2}\end{align*} over $[0,1]^3.$

Here again, we have the reduced and slightly modified gradient $$\nabla \check{T} = \begin{pmatrix} \frac{20h_1}{9 \sqrt{1+h_1^2} } - \frac{2(1-h_1)}{\sqrt{ (1-h_1)^2 + (1-h_2)^2}} \\ \frac{20h_2}{9 \sqrt{h_2^2 + h_3^2} } - \frac{2(1-h_2)}{\sqrt{(1-h_1)^2 + (1-h_2)^2}} \\ \frac{20h_3}{9 \sqrt{h_2^2 + h_3^2} } - \frac{2(1-h_3)}{\sqrt{ 1 + (1-h_3)^2}}\end{pmatrix}.$$ Since this still yields some gnarly system of quadratics, at this point, though you can also just give up and program it, finding $\hat{h} = (0.485699\dots, 0.0737739\dots, 0.057801\dots)$ which yields an optimal value of $$\check{T}^* = \tilde{T}^* = 11.78815\dots$$ minutes for Alice to get to $(8,8)$.

Sunday, January 21, 2024

The Oldest Sister's Burden

Three siblings are at a playground: Alice, Bob, and Carey. Alice, the oldest, gets a call from their dad \emdash their pancake dinner is ready! But they won’t get to eat until all three kids are home.

They each walk home at a different constant speed. Alice can walk home in 10 minutes, Bob can do it in 20, and Carey in 30. Fortunately, any of the kids can carry any of the others on their back without reducing their own walking speed. (However, none of them can carry a kid who is, in turn, carrying another kid.) Assume that they can pick someone up, set someone down, and change direction instantaneously.

What is the fastest they can all get home?

Clearly Alice, the oldest sister will have to do some amount of carrying, else everyone will be waiting for Carey to get home in 30 minutes. If Bob is never carried, then the best possible dinner time is 20 minutes after their dad's call. To do better, let's envision a scheme where indefatiguable Alice first carries one sibling for $t$ minutes, then drops that sibling and reverses course and travels away from home to meet up with the other sibling, then carries that second sibling the rest of the way home.

The time, let's say $t_1 = t_1(t, v_2),$ it will take Alice to travel away from home until she meets up with the other sibiling will be a function of the chosen first time period $t$ and the speed of the second sibling, $v_2$. In particular, if Alice and the second sibling were both traveling for $t$ minutes, then given the differential in their speeds, they would be a distance of $\frac{t}{10} - tv_2$ apart (assuming distance to home is the unit length here). In this case, in order for both of them to make up that distance at their relative combined speed of $v_2 + \frac{1}{10},$ we have $$t_1 = t\frac{\frac{1}{10} - v_2}{\frac{1}{10}+ v_2} = t \frac{1-10v_2}{1+10v_2}.$$ Additionally of note, Alice and her second siblings meeting occurs $$d = d(t, v_2) = (t + t_1) v_2 = t v_2 \left( 1 + \frac{1 - 10v_2}{1 + 10v_2} \right) = \frac{ 2t v_2 }{1 + 10v_2}$$ home lengths away from the playground. So in order for Alice and the second sibling to arrive home, it will take another, let's say $$t_2 = t_2(t, v_2) = \frac{1 - d(t,v_2)}{0.1} = 10 - 10d = 10 - \frac{20tv_2}{1 + 10v_2}$$ minutes. So Alice and one sibling will arrive at \begin{align*}T_A = T_A(t,v_2) &= t + t_1(t, v_2) + t_2(t, v_2) \\ &= t + t \frac{1 - 10v_2}{1 + 10v_2} + 10 - \frac{20tv_2}{1+10v_2} \\ &= 10 + \frac{ t(1 + 10v_2) + t(1-10v_2) - 20 t v_2) }{1 + 10v_2} \\ &= 10 + \frac{ 2t - 20t v_2}{1 + 10v_2} = 10 + 2t \frac{1-10v_2}{1+10v_2}\end{align*} minutes.

Meanwhile, the first sibling that Alice dropped off after $t$ minutes has been trudging home under their own power at a uniform rate of $v_1$ and will arrive home at $$T_1 = T_1(t, v_1) = t + \frac{1 - \frac{t}{10}}{v_1} = \frac{1}{v_1} - t\frac{1 - 10v_1}{10 v_1}.$$ So the time when all of the siblings are safely home and devouring pancakes for dinner is \begin{align*}T = T(t, v_1, v_2) &= \max \{ T_A(t, v_2), T_1(t, v_1) \} \\ &= \max \left\{ 10 + 2t \frac{1 - 10v_2}{1 + 10v_2}, \frac{1}{v_1} - t \frac{1-10v_1}{10v_1} \right\} \end{align*} So in particular, if Alice first picks up Bob and then Carey, we have $$T_{B,C} = T_{B,C} (t) = T\left(t, \frac{1}{20}, \frac{1}{30}\right) = \max \{ 10 + t, 20 - t \},$$ while if Alice first picks up Carey and then Bob, we have $$T_{C,B} = T_{C,B} (t) = T\left(t, \frac{1}{30}, \frac{1}{20}\right) = \max \left\{10 + \frac{2}{3}t, 30 -2t \right\}.$$ The optimal value of $T_{B,C}$ is $$T_{B,C}^* = \min_{t \in [0,10]} T_{B,C} (t) = 15 \,\text{minutes},$$ which occurs when $t^* = 5$ minutes; whereas, the optimal value of $T_{C,B}$ is $$T_{C,B}^* = \min_{t \in [0,10]} T_{C,B} (t) = 17.5 \, \text{minutes},$$ which occurs when $t^* = 6.5$ minutes. So between the two cases of carrying Bob first or carrying Carey first, the children will be eating pancakes sooner if Alice carries Bob first.

We can safely exclude the cases of either Bob carrying Carey at first, or Alice having more than one session of carrying any individual sibling, since each of these cases would lead to Carey, the slowest of the bunch, having a longer average speed home and thus delaying pancake festivities. Therefore, the fastest that Alice, Bob and Carey can all get home is in 15 minutes, where Alice carries Bob for 5 minutes, then sends him home, goes back to meet Carey and upon meeting Alice carries Carey the rest of the way home.

Monday, January 15, 2024

Dice Dungeon

Two people are sitting at a table together, each with their own bag of six “DnD dice”: a d4, a d6, a d8, a d10, a d12, and a d20. Both people randomly pick one die from their respective bags and then roll them at the same time. For example, suppose the two dice selected are a d4 and a d12. The players roll them, and let’s further suppose that both rolls come up as 3. What luck!

What’s the probability of something like this happening? That is, what is the probability that both players roll the same number, whether or not they happened to pick the same kind of die?

There are twenty possible outcomes $1, 2, \dots, 20$, however, since for instance, the probability that a d4 die rolls 17 is nil, we have a non-uniform distribution of outcomes. All outcomes less than or equal to $4$ are always possible no matter which die is selected, so the probability is $$p_i = \frac{1}{6} \left( \frac{1}{4} + \frac{1}{6} + \frac{1}{8} + \frac{1}{10} + \frac{1}{12} + \frac{1}{20} \right) = \frac{93}{720}, \,\, i = 1, 2, 3, 4.$$ The conditional probability of getting i \in \{5,6\} given that the d4 die was selected is zero, so we have $$p_i = \frac{1}{6} \left( 0 + \frac{1}{6} + \frac{1}{8} + \frac{1}{10} + \frac{1}{12} + \frac{1}{20} \right) = \frac{63}{720}, \,\, i = 5,6.$$ Doing similar manipulations for other outcomes gives $$p_i = \begin{cases} \frac{93}{720}, &\text{for $i = 1, 2, 3, 4$}\\ \frac{63}{720}, &\text{for $i = 5,6$;}\\ \frac{43}{720}, &\text{for $i = 7,8$;}\\ \frac{28}{720}, &\text{for $i = 9,10$;}\\ \frac{16}{720}, &\text{for $i = 11,12$;}\\ \frac{6}{720}, &\text{for $i = 13, 14, 15, 16, 17, 18, 19, 20$.}\end{cases}$$

Let the roll person 1 be $X,$ with probability distribution given by $\mathbb{P} \{ X = i \} = p_i.$ Similarly let the roll of person 2 be $Y,$ which has the i.i.d. distribution. Then the probability that both rolls are the same, i.e., $X=Y,$ is given by \begin{align*}\mathbb{P} \{ X = Y \} &= \sum_{i=1}^{20} \mathbb{P} \{ X = Y = i \} \\ &= \sum_{i=1}^{20} \mathbb{P} \{X=i\} \mathbb{P} \{Y = i\}\\ &= \sum_{i=1}^{20} p_i^2 \\ &= \frac{1}{720^2} \left( 4 \cdot 93^2 + 2 \cdot 63^2 + 2 \cdot 43^2 + 2 \cdot 28^2 + 2 \cdot 16^2 + 8 \cdot 6^2 \right) \\ &= \frac{48600}{518400} = \frac{3}{32} = 9.375\%.\end{align*}

If we went further and added a third person who has a bag of DnD dice. Again, all three randomly pick one die from their respective bags and roll them at the same time. For example, suppose the three dice selected are a d4, a d20, and a d12. The players roll them, and let’s further suppose that the d4 comes out as 4, the d20 comes out as 13, and the d12 comes out as 4. In this case, there are two distinct numbers (4 and 13) among the three rolls.

On average, how many distinct numbers would you expect to see among the three rolls?

Well the hard part of establishing the distribution is done, so let's assume $X$, $Y$ and now $Z$ are all i.i.d. with $\mathbb{P}\{X = i\} = \mathbb{P}\{Y=i\} = \mathbb{P}\{Z=i\} = p_i, i = 1, 2, \dots, 20.$ Let $N$ be the number of distinct rolls. I'm lazy so I'm going to leave $N=3$ alone and instead tackle $N=1$ and $N=2.$ The probability that $X=Y=Z$ and hence $N = i$ is by extension of the previous problem $$\mathbb{P} \{N=1\} = \sum_{i=1}^{20} p_i^3 = \frac{3930360}{373248000} = \frac{32753}{3110400} \approx 1.05302.....\%$$

For $N=2,$ we have a modicum of work. As we saw above if $X=Y$ then this would be represented by $p_i^2,$ but then in this case of $N = 2,$ we must have $Z \ne X=Y,$ which has probability of $(1-p_i).$ Furthermore, since the order of $X, Y, Z$ doesn't matter, there are 3 possible ways to get two rolls of $i$ and one roll of anything but $i.$ So we have $$\mathbb{P} \{ N=2\} = 3 \sum_{i=1}^{20} p_i^2 (1-p_i) = \frac{93184920}{373248000} = \frac{776541}{3110400} \approx 24.96595....\%$$

The only thing left to do is compute the expectation, \begin{align*}\mathbb{E} [N] &= 1 \cdot \mathbb{P} \{ N=1\} + 2 \cdot \mathbb{P} \{N=2\} + 3 \cdot \left( 1- \mathbb{P}\{N=1\} - \mathbb{P} \{N=2\} \right)\\ &= 3 - 2\mathbb{P} \{N=1\} -\mathbb{P}\{N=2\}.\end{align*} So the expected number of unique numbers among the three rolls is \begin{align*}\mathbb{E}[N] &= 3 - 2 \cdot \frac{32753}{3110400} - \frac{776541}{3110400} \\ &= \frac{9006847}{3110400} \approx 2.89571984\end{align*}