25

I'm trying to define $\pi$ in terms of $4$ by placing a unit circle inside a square, and subtracting the corners of the square.

I'm attempting to use summation to define the area of a corner, then multiplying that by four and subtracting from four (the area of the square)

I thought I figured it out, and I created a program to check. The answer came out to $\approx 3.4$

I'm not sure if it was a program fault, or if I'm simply making a math error. Can someone please lead me in the right direction? This is what I have right now:

$$\pi \approx 4 \times \left(1-\sum\limits_{n=1}^{\infty}\frac{\left(\frac{2-\sqrt 2}{2}\right)^2}{2^{n-1}}\right)$$

Where $\left(\frac{2-\sqrt2}{2}\right)^2$ is the area of the largest corner square and $2^{n-1}$ is the number of squares.

EDIT

After reading the comments I realized I wasn't very clear with what I was trying to achieve, so I created a sketch that should illustrate what I want.

Glorfindel
  • 3,955
David
  • 443

2 Answers2

24

As I mentioned in the comments, the sizes of the squares are a little more complicated than what you're hoping for. I don't know of a simple expression for the size of each square, but you can get each one by solving a quadratic equation. I wrote a program to do so; it draws all the squares whose sizes are above a small threshold. Here's the result. Hope it helps!

Details on the program: for a point $(0,0)\leq(x,y)\leq(1,1)$, we want to find a square with one vertex at $(x,y)$ and the other on the sphere $x_0^2+y_0^2=1$. Writing $b=y-x$, the condition that the two points form a square means that $y_0=x_0+b$. Substituting, we get $2x_0^2+2bx_0+b^2-1=0$. The solution is given by the quadratic equation: $x_0=\frac14\left(-2b+\sqrt{4b^2-4(2)(b^2-1)}\right)$, and then we get $y_0$ from $y_0=x_0+b$. Now draw the square between $(x,y)$ and $(x_0,y_0)$ and repeat the process from each of the points $(x,y_0)$ and $(x_0,y)$.

Here's some C++ code to generate an SVG fragment:

using namespace std;

void box(double x1, double y1, double x2, double y2, int level)
{
    cout
    << "<rect x=\"" << min(x1, x2)
    << "\" y=\"" << min(y1, y2)
    << "\" width=\"" << abs(x1-x2)
    << "\" height=\"" << abs(y1-y2)
    << "\"";

    switch (level % 3)
    {
        case 0: cout << " fill=\"red\""; break;
        case 1: cout << " fill=\"green\""; break;
        case 2: cout << " fill=\"blue\""; break;
    }

    cout << " />" << endl;
}

void boxes(double x1, double y1, double x2, double y2, int level)
{
    double r = 300.0;

    x1 *= r;
    y1 *= r;
    x2 *= r;
    y2 *= r;

    box(r+x1,r+y1,r+x2,r+y2, level);
    box(r+x1,r-y1,r+x2,r-y2, level);
    box(r-x1,r+y1,r-x2,r+y2, level);
    box(r-x1,r-y1,r-x2,r-y2, level);
}

void advance(double x, double y, double& ox, double& oy)
{
    const float b = y - x;
    ox = (-2*b + sqrt(4*b*b - 8*(b*b-1))) / 4;
    oy = ox + b;
}

void drawlevel(int level, double x, double y)
{
    double ox, oy;
    advance(x, y, ox, oy);
    boxes(x, y, ox, oy, level);

    if (abs(x-ox) > 0.0004)
    {
        drawlevel(level + 1, x, oy);
        drawlevel(level + 1, ox, y);
    }
}

int main()
{
    drawlevel(0, 1, 1);
}
Chris Culter
  • 26,806
  • Beauty is part of mathematics ! You gave one more proof. Thanks. – Claude Leibovici Dec 14 '14 at 13:09
  • Do you mind sharing how your program works? I'm not sure how to go about the quadratic equation you mentioned. – David Dec 14 '14 at 18:56
  • Thanks for explaining the code. How could I implement that in my expression? – David Dec 15 '14 at 00:07
  • Sorry, I don't know how to write down the result of this process in a simple expression. I suppose you could try solving the first few iterations and looking for a pattern. – Chris Culter Dec 15 '14 at 00:46
  • +1. Quite ingenious. I like very much your $\verbC++$ code. What $\verbC++$ library you include to use colors ?. – Felix Marin Dec 23 '14 at 21:39
  • @FelixMarin The C++ code writes SVG markup to the standard output, including the strings "red", "green", and "blue". From there, it's up to an SVG viewer to interpret the color names. I used Adobe Illustrator to export the SVG to JPG so that I could upload it here. – Chris Culter Dec 23 '14 at 21:54
  • @ChrisCulter Thanks a lot. I'm a $\verbC++$ fan but I never used that. – Felix Marin Dec 23 '14 at 22:52
0

Your way of filling the corners will only (as far as I can see) a triangular part of them.

It's going to be hard to fill them with squares.

Chris says the same in his comment except that he actually tries to tell you what you might do (and he caught you miscounting on the number of smaller squares in each step).