[Math] Infinite sum of Python for loop

analytic geometryareacirclespython

I'm a geometry student. Recently we were doing all kinds of crazy circle stuff, and it occurred to me that I don't know why $\pi r^2$ is the area of a circle. I mean, how do I really know that's true, aside from just taking my teachers + books at their word?

So I tried to derive the formula myself. My strategy was to fill a circle with little squares. But I couldn't figure out how to generate successively smaller squares in the right spots. So instead I decided to graph just one quadrant of the circle (since all four quadrants are identical, I can get the area of the easy +x, +y quadrant and multiply the result by 4 at the end) and put little rectangles along the curve of the circle. The more rectangles I put, the closer I get to the correct area. If you graph it out, my idea looks like this:

Approximating circle area using rectangles

Okay, so to try this in practice I used a Python script (less tedious):

from math import sqrt, pi

# explain algo of finding top right quadrant area
# thing with graphics via a notebook

# Based on Pythagorean circle function (based on r = x**2 + y**2)
def circle_y(radius, x):
  return sqrt(radius**2 - x**2)

def circleAreaApprox(radius, rectangles):
  area_approx = 0
  little_rectangles_width = 1 / rectangles * radius

  for i in range(rectangles):
    x = radius / rectangles * i
    little_rectangle_height = circle_y(radius, x)
    area_approx += little_rectangle_height * little_rectangles_width

  return area_approx * 4

This works. The more rectangles I put, the wrongness of my estimate goes down and down:

for i in range(3):
    rectangles = 6 * 10 ** i
    delta = circleAreaApprox(1, rectangles) - pi # For a unit circle area: pi * 1 ** 2 == pi
         print(delta)

Output

0.25372370203838557
0.030804314363409357
0.0032533219749364406

Even if you test with big numbers, it just gets closer and closer forever. Infinitely small rectangles circleAreaApprox(1, infinity) is presumably the true area. But I can't calculate that, because I'd have to loop forever, and that's too much time. How do I calculate the 'limit' of a for loop?

Ideally, in an intuitive way. I want to reduce the magic and really understand this, not 'solve' this by piling on more magic techniques (like the $\pi \times radius^2$ formula that made me curious in the first place).

Thanks!

Best Answer

This is an excellent question. You are following in Archimedes' footsteps and starting to invent integral calculus and the idea of a limit.

I will try to address (briefly!) the mathematical and philosophical issues here, not the programming question.

You are right to worry about a process that has to go on forever. The way mathematicians deal with that question is to replace the infinitely many operations it would take to "reach a limit" by infinitely many inequalities any one of which can be justified in a predictable finite number of steps. If in your picture you calculate the total area of the inscribed slices just as you have calculated the area of the circumscribed ones you can show (with logic, not a program) that the difference between those two areas is as small as you please as long as you are willing to use thin enough rectangles. Then you can argue (though it's not easy) that there is just one number less than all the overestimates and greater than all the underestimates. For a circle of radius $1$ we call that number $\pi$.

The next job is to over and underestimate the circumference of the unit circle with the same kind of argument, using circumscribed and inscribed polygons. There too you can show that they tell you a number for the circumference.

The final step is to show that number is exactly twice the $\pi$ that you found for the area.

For a circle of radius $r$ the circumference will be $r$ times as large, so $2\pi r$, and the area will be $r^2$ times as large, so $\pi r^2$. (Carefully proving those proportionalities for curved shapes like circles requires estimations and limits.)

Related Question