Skip to content

Instantly share code, notes, and snippets.

@Fordi
Last active July 27, 2020 18:05
Show Gist options
  • Save Fordi/6612108 to your computer and use it in GitHub Desktop.
Save Fordi/6612108 to your computer and use it in GitHub Desktop.
  1. Define a circle as the set of points equidistant from a center point.
  2. The Pythagorean theorem allows us to work out an equation to define the points that fit this curve, by using h as the radius
    x^2 + y^2 = h^2
  3. Setting the radius to 1 simplifies this, making our equation the unit circle
    x^2 + y^2 = 1
  4. To make this parametric (i.e., give an x, get a y), we rearrange thusly:
    y = f(x) = sqrt(1 - y^2)
  5. Since we know a circle is vertically and horizontlly symmetrical, we can simplify things by dropping the +/-, and by looking only at 0 <= x <= 1; the area under that curve will be 1/4 pi.
    f(0 <= x <= 1) = sqrt(1 - x^2)
  6. Now that we have that, we use Reimann sums to work out the area under it. A Reimann sum is just adding up the the areas of the rectangles we can fit under the curve. As we make the rectangles smaller, we reduce how wrong that answer is. This can be written as
    pi/4 = lim(n->inf)sum(i=0 to n-1) of (dx * sqrt(1-xi^2)))
    That is to say, as n (the number of rectangles) approaches infinity, work out the point of convergence for the sum of the area of those rectangles. If you know some programming, that big "" means "for (sum = 0, i = 0; i <= n - 1; i += 1) { sum += ...; } return sum;"
  7. Now, funny thing: if you follow the calculus out, this limit is literally pi/4, as derived from the sin/cos functions that a sqrt of an additive power implies - so that won't help. What it does mean, though, is that we have an iterative method of working out pi. Further, doing some more logarithmic / calculus jiggery-pokery, it turns out that you can work out an arbitrary digit of pi without working out the other ones.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment