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

Monotonic functions and the first derivative

A couple of days ago, Rohan Didmishe shared this problem with us: show that the function defined by \[ f\colon \mathbb{R} \to \mathbb{R}, \qquad f(x) = \begin{cases} x + x^2\sin(1 / x), &\text{ if }x \neq 0, \\ 0, &\text{ if } x = 0. \end{cases} \] is not monotonic (increasing or decreasing) in any interval $(-\delta, \delta)$ around zero. Graphing this function (say, using Desmos ) shows that it oscllates rapidly, curving up and down with increasing frequency the closer its gets to zero. This is due to the $x^2\sin(1 / x)$ term; the $x$ added in front 'tilts' the curve upwards. The first thing to look at is the derivative of $f$. Using $\lim_{x \to 0} x\sin(1 / x) = 0$ and the chain rule, we can compute \[ f'(x) = \begin{cases} 1 + 2x\sin(1 / x) - \cos(1 / x), &\text{ if }x \neq 0, \\ 1, &\text{ if } x = 0. \end{cases} \] Specifcally, $f'(0) = 1$ which seems to tell us that $f$ is increasing at $0$ ... or doe