Loading [MathJax]/jax/output/HTML-CSS/jax.js

Monday, November 15, 2021

Infinitesimal sticks, or adventures in making things complicated and wrong

One day you stumble across a magic genie, who says that if you play a simple game with him, you could win fabulous riches. You take the genie up on his offer, and he hands you a stick of length 1. He says that behind his back is another stick, with a random length between 0 and 1 (chosen uniformly over that interval).

Next, you must break your stick into two pieces and present one of those pieces to the genie. If that piece is longer than the genie’s hidden stick, then you win a prize of $1 million times the length of your remaining piece. For example, if you present to the genie a length of 0.4, and that’s longer than the genie’s stick, then you win $1 million times 0.6, or $600,000. However, if the genie’s stick is longer, then you win nothing.

Being a regular reader of The Riddler, you crunch some numbers and prepare to break your stick in half. But then you have a thought. You ask the genie if you can have more than one turn. For example, if you present the genie with a length of 0.4, but the genie’s stick is longer, can you break off a piece of the remaining length of 0.6 — say, a length of 0.5 — and then present that to the genie? To keep things fair, your winnings will still be proportional to the leftover length. So had the genie’s length indeed been between 0.4 and 0.5, your first and second guesses, then the remaining length would have been 0.1, and you would have won $100,000.

The genie doesn’t think any of this really matters and says you can have as many turns as you desire. If your goal is to maximize your expected winnings, what will your strategy be? And how much money would you expect to win on average?


Mea culpa .... I had a "fundamental misunderstanding of the material" moment and proceeded with the following answer, which only works if you can then also glue all of your tiny stick pieces back together, which I suppose is a bit of a stretch interpretation of the prompt.

Assume that you want to make n1 breaks in the stick, let's say at 0x1x2xn1. If the genie's stick has length GU[0,1], then the payoff would be Vn(Gx)={1x1,if Gx1 1x2,if x1<Gx21xn,if xn1<Gxn0,if G>xn therefore the expected payoff (as a fraction of the genie's $1 million) is Qn(x)=EG[Vn(Gx)]=ni=1(1xi)(xixi1), where we assume that x0=0.

Therefore, the optimal selection of breakpoints satisfies the maximization problem maxxni=1(1xi)(xixi1)such that0=x0x1xn1 First note that ΔQn=(21000121000121000002)0 is negative semi-definite and hence concave. Further, Slater's condition holds for the set of inequalities 0=x0x1xn1, so we have the necessary and sufficient conditions that if ˆx satisfies 0<ˆx1<ˆx2<<ˆxn<1 and Qn(ˆx)=0 then is an optimal solution of the maximization problem.

For i=2,,n1, we have xiQn(x)=xi((1xi)(xixi1)+(1xi+1)(xi+1xi))=xi1+xi+12xi. We additionally have x1Qn(x)=x1((1x1)x1+(1x2)(x2x1))=x22x1 and xnQn(x)=xn(1xn)(xnxn1)=1+xn12xn. Therefore, if we define ˆx(n)=(ˆx(n)1,,ˆx(n)n) with ˆx(n)i=in+1, then we see that Qn(ˆx(n))=0 and hence Qn(ˆx(n))=ni=1(1in+1)1n+1=1(n+1)2n(n+1)2=n2(n+1) is the optimal fraction of the $1 million that can be won from the genie when making n cuts. As n, we get limnQn(ˆx(n))=limnn2(n+1)=12, so you can win as close to $500,000 as desired.

Monday, October 25, 2021

Centered triangles

Suppose you have an equilateral triangle. You pick three random points, one along each of its three edges, uniformly along the length of each edge — that is, each point along each edge has the same probability of being selected.

With those three randomly selected points, you can form a new triangle inside the original one. What is the probability that the center of the larger triangle also lies inside the smaller one?

Let's assume that the original triangle is the equilateral triangle with side lengths whose center is at the origin of the xy-plane. Thus the vertices of the original triangle are at A(1/2,3/4), B(0,3/4), and C(1/2,3/4). Let's say that t,u,vU(0,1) are i.i.d. uniformly distributed, then the random points along the edges of \Delta ABC can be modeled as X=(t12,34)Y=(1u2,3(2u1)4)Z=(1v2,3(2v1)4).

If we wanted to just brute force our way into the solution, we could just use the test that O=(0,0)ΔXYZ if and only if AΔOXY+AΔOXZ+AΔOYZ=AΔXYZ. However, we can also create the appropriate integral to calculate the theoretical answer. In this case, we will actually do both to make sure both are roughly on the right track.

Let's first focus on the siutation when t[0,12], or equivalently when XR×{34}. In this case, we can drawn a line from X through the origin O and see that if O is in the ΔXYZ then we must have Z=(z1,z2) located such that 34z1+(t12)z20. Therefore, in terms of t and v, we have 0341v2+(t12)3(2v1)4=38(1v+(2t1)(2v1))=38((4t3)v+2(1t)), or equivalently v2(1t)34t. See the figure below for context.

Similarly, we can draw a line from Y through the origin O and see that if O is in the triangle ΔXYZ then we must have Z=(z1,z2) located such that 34(2u1)z1+1u2z20. Therefore, in terms of u and v, we have 03(2u1)41v2+1u23(2v1)4=38((2u1)(1v)+(1u)(2v1))=38((3u2)+(34u)v), or equivalently v23u34u. Since we naturally have v[0,1], we see that if t[0,12] and u[0,1] that O is in the triangle ΔXYZ if and only if v[023u34u,2(1t)34t]. So P{OΔXYZ|XR×{34}}=120102(1t)34tmax{0,23u34u}dudt=120(2(1t)34t23023u34udu)dt. Using partial fractions, we get 23023u34udu=2303414(34u)du=[34u+116ln|34u|]230=1218ln3. So, again by applying the partial fractions technique we get that the probability is P{OΔXYZ|XR×{34}}=1202(1t)34t12+18ln3dt=12012+12(34t)12+18ln3dt=[18ln|34t|+t8ln3]120=3ln316.

From symmetry (by switching the restrictions of Y and Z whenever t[12,1]), we see that P{OΔXYZ|XR+×{34}}=P{OΔXYZ|XR×{34}}=3ln316, so we are left with the probability that the origin is in the randomly selected triangle ΔXYZ as P{OΔXYZ}=P{OΔXYZ|XR×{34}}+P{OΔXYZ|XR+×{34}}=3ln380.41197960825.....

As indicated, we can also use brute force to arrive at / verify this conclusion using the short python script shown below.

CenteredTriangles
In [1]:
import numpy as np
from numpy.random import uniform

def area_triangle(A, B, C):
    cross = (B[0] - A[0]) * (C[1] - A[1]) - (C[0] - A[0]) * (B[1] - A[1])
    return 0.5 * np.abs(cross)

num_samples = 1000
num_runs = 1000
O = np.array([0.,0.])
success = np.zeros(shape=(num_samples, num_runs))
for k in range(num_runs):
    U = uniform(size=(num_samples, 3))
    for i in range(num_samples):
        u = U[i,:]
        X = np.array([-0.5, -0.25*np.sqrt(3)]) + u[0] * np.array([ 1.0, 0.0])
        Y = np.array([-0.5, -0.25*np.sqrt(3)]) + u[1] * np.array([ 0.5, 0.5 * np.sqrt(3)])
        Z = np.array([ 0.5, -0.25*np.sqrt(3)]) + u[2] * np.array([-0.5, 0.5 * np.sqrt(3)])
        a1 = area_triangle(O, X, Y)
        a2 = area_triangle(O, X, Z)
        a3 = area_triangle(O, Y, Z)
        a = area_triangle(X, Y, Z)
        if np.abs(a - a1 - a2 - a3) < 1e-6:
            success[i,k] += 1
print('Over %d successive tests, each using %d samples, the probability of having the origin within ' % (num_runs, num_samples))
print('the random triangle is %f with SEM of %f.' % (success.mean(), success.mean(axis=0).std()/np.sqrt(num_runs)))
print('This compares favorably to the theoretical answer 3 * ln(3) / 8 = %f' %  (3. * np.log(3) / 8.))
Over 1000 successive tests, each using 1000 samples, the probability of having the origin within 
the random triangle is 0.411384 with SEM of 0.000495.
This compares favorably to the theoretical answer 3 * ln(3) / 8 = 0.411980