What is the area of the circle in the pictured image?
A 25-dimensional ball (a 25-ball) with radius 3 and a 25-dimensional hypercube with edge length 2 are concentric. What is the 25-dimensional volume of their intersection? Estimate with high confidence of at least three correct leading digits.
Steve Mildenhall provided the following simulation solution, using Python code generated with some help from Chat GPT.
The three leading digits are 227.
The answer is approximately 22,742,709 or 68% of the volume of the sphere. Following is the Python code:
from scipy.stats import qmc
import numpy as np
dimension = 25
radius = 3
radius2 = radius ** 2
side = 2
scale_factor = side / 2 # Scaling factor to adjust points from [0,1] to [-1,1]
step = 2 ** 20
def is_inside_ball(point):
global radius2
return np.sum(point**2) <= radius2
sampler = qmc.Sobol(d=dimension, scramble=False)
prev_volume = 0
converged = False
i = 0
V = side ** dimension
while not converged:
i += step
points = sampler.random(n=i)
points = (points * 2 – 1) * scale_factor # Scale points to fit the cube
# inside_count = np.sum([is_inside_ball(point) for point in points])
inside_count = np.sum(np.apply_along_axis(is_inside_ball, 1, points))
cube_volume = side ** dimension estimated_volume = (inside_count / len(points)) * cube_volume
if i > 100000 and abs(estimated_volume – prev_volume) < 0.001:
converged = True
else:
prev_volume = estimated_volume
print(f”Estimate after {len(points)} points: {estimated_volume} {estimated_volume / V:.5f}”)
print(f”Final estimate: {estimated_volume}”)
Solutions were also submitted by Moshe Gelbwachs, Jacob Ogle and Anthony Salis.