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.