Skip to main content

Simulating Bertrand's Paradox

One of the most famous elementary problems in probability is Bertrand's Paradox. This stems from the seemingly simple question: what is the probability that the length of a random chord in a circle exceeds the length of the side of its inscribed equilateral triangle? To put the lengths into perspective, the side of an equilateral triangle inscribed in a circle of radius $r$ has length $\sqrt{3}r$. The YouTube channel Numberphile, in collaboration with Grant Sanderson from 3blue1brown, released an excellent video discussing this very problem.

Don't forget to watch the extra footage!

I won't dwell on the mathematical details here; the video does a great job of explaining the problem with gorgeous visuals. Instead, an enthusiastic programmer's first instinct screams "let's code it"; and python is more than up to the task. Putting the usual caveats of generating (pseudo)randomness using computers aside, the numpy.random module is a good place to start. With help from Rohan Kumar, here's some code illustrating three methods of generating random chords.

import numpy as np
from numpy import pi
from numpy.random import uniform


def uniform_angles(N):
    """Sample N chords by choosing two points uniformly from the circumference."""
    theta = uniform(0, 2 * pi, (2, N))
    delta = np.abs(theta[0] - theta[1])
    hits = np.logical_and(delta > 2 * pi / 3, delta < 4 * pi / 3)

    return hits


def uniform_polar(N):
    """Sample N chords by choosing the center in polar coordinates, uniform r and theta."""
    theta = uniform(0, 2 * pi, N)  # Redundant
    radius = uniform(0, 1, N)
    hits = radius < 0.5

    return hits


def uniform_square(N):
    """Sample at most N chords by choosing the center in Cartesian coordinates, uniform x and y.
    Points outside the circle are discarded.
    """
    coords = uniform(-1, 1, (2, N))
    within = coords[0] ** 2 + coords[1] ** 2 <= 1
    x, y = coords[0][within], coords[1][within]
    hits = x ** 2 + y ** 2 < 0.5 ** 2

    return hits


def main():
    for method in [uniform_square, uniform_angles, uniform_polar]:
        # Sample up to 1 million chords per method
        hits = method(1000000)
        count = np.sum(hits)
        total = len(hits)
        print(f"{count:10d} / {total:10d} = {count/total:.6f} ({method.__name__})")


if __name__ == "__main__":
    main()

A typical run gives an output like so. The fractions are the proportions of long chords among all chords.

	196461 /     785231 = 0.250195 (uniform_square)
    	333021 /    1000000 = 0.333021 (uniform_angles)
    	500594 /    1000000 = 0.500594 (uniform_polar)

The mathematics may be simple, but it's always reassuring to see it play out! To round things off, here are $1500$ chords generated using the first method (choose two points uniformly from the circumference and join them). The red chords are the ones which are longer than $\sqrt{3}r$. The ring of blue chords clearly shows that these short chords must avoid the inner circle of radius $r / 2$.

Comments

Popular posts from this blog

Why am I frequently meeting my crush?

Gourav Banerjee, a 21MS student, goes to the main canteen of IISER Kolkata for dinner at some arbitrarily scheduled time between 8 and 9 pm. He frequently meets an anonymous, beautiful girl in the mess and begins to wonder whether the girl is stalking him or if their meeting is just a coincidence. So he tries to compute the probability of meeting that girl in the mess during dinner time given the following constraints: Both Gourav and the girl go to mess for having dinner at some random time between 8 - 9 pm. Because of the Queue at the mess, both stay in the mess for minimum of 30 min. What do you think? Solution Let $x$ denote the time when Gourav enters the mess and let y denote the time when girl enters the mess. Here we take origin to be the 8 pm mark and a distance of 1 unit represents 1 hour on both $x$ and $y$ axis so all possible coordinates within the unit square $ABCD$ represents an event where Gourav and the girl both visit the canteen. Now the favourable coordinates which ...

The height of probabilistic interpretation

Girls only love men as tall as 6' and above. Socrates, ca. 2023 It is undeniable that heights strongly influence our daily lives. Be it our heights, or the height of a mountain we scale, or the height of all problems - humans. Mathematics too hasn't been able to escape its clutches, with height functions being useful in several fields, including but not limited to - Diophantine Geometry, Automorphic forms and the Weil-Mordell theorem - something you should have heard before if you attend my talks. If you have attended school (or maybe you are a climate activist) - then try recalling the elementary school days when fractions were introduced. Albeit unknowingly, but we had as children classified fractions into proper and improper - based on whether the denominator was larger than the numerator or vice versa. Well, it seems mathematicians have stuck with this classification - giving us the crux of todays discussion - height of a rational number. Given a rational number $x=\frac mn...

Co-planar points on the twisted cubic

Here's a fun problem from a course on Curves and Surfaces. Consider the following curve, called the twisted cubic. \[ \gamma\colon \mathbb{R} \to \mathbb{R}^3,\qquad \gamma(t) = (t, t^2, t^3). \] Show that no four distinct points on this curve can lie on the same plane. Method 1 - The scalar triple product The scalar triple product  is a good tool to have at one's disposal (thanks to Satbhav Voleti for sharing this solution); given three vectors $\boldsymbol{u}, \boldsymbol{v}, \boldsymbol{w}$, their scalar triple product $\boldsymbol{u}\cdot(\boldsymbol{v}\times \boldsymbol{w})$ represents the volume of the parallelepiped whose legs are these vectors. Now if these three vectors all lie in the same plane, the corresponding parallelepiped is completely flat with zero volume, thus the scalar triple product is also zero. Coming back to our problem, suppose that the four distinct points on the twisted cubic $P_i = (t_i, t_i^2, t_i^3)$, $i = 0, 1, 2, 3$, all lie on the same plane. ...