Message Boards Message Boards

Squeezing Pi from a Menger Sponge

Posted 9 years ago

In the Menger sponge, a step divides a cube into 27 cubes, then the center and six touching cubes are removed. Here's what it looks like after three steps.

 Cuboid /@ ((FromDigits[#, 3] & /@ Transpose[#]) & /@ 
    Select[Partition[#, 3] & /@ Tuples[Range[0, 2], {9}], 
     Max[Count[#, 1] & /@ #] < 2 &]), Boxed -> False]

enter image description here

You can also take slices, as shown in the Wolfram Demonstration Menger Sponge Slices.

enter image description here

A string rewriting system gives a related fractal known as the Sierpi?ski Carpet. It is a face of the Menger sponge. Here are two different pieces of code to generate it.

       Transpose[(IntegerDigits[#, 3, 5] & /@ {a, b})], {1, 1}]], 1, 
     0], {a, 0, 3^5 - 1}, {b, 0, 3^5 - 1}], PixelConstrained -> True, 
   ImageSize -> 250], Spacer[20], 
   Nest[ArrayFlatten[# /. {0 -> {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, 
        1 -> {{1, 1, 1}, {1, 0, 1}, {1, 1, 1}}}, 2] &, {{1}}, 5], 
   Frame -> False, PixelConstrained -> True, ImageSize -> 250]}]

enter image description here

Taking a horizontal line through the center gives the Cantor set (also known as the middle-thirds set), an infinite closed perfect set of zero measure.

enter image description here

You might recognize the ternary (base 3) numbers in each set of code. For the 1D Cantor set, remove any ternary number with a 1. For the 2D Sierpinski carpet, if the nth ternary digits are both 1, remove that pair of numbers. For the 3D Menger sponge, if two or three of nth ternary digits are1, remove that triplet of numbers. All of these objects tend to a set of measure zero, whether the measure is length, area, or volume.

So those are ways to get measure 0 with a fractal. How about making Pi with a fractal? These two infinite products look promising for 1D.

enter image description here

Transforming the fractions into fractals requires adding a segment when the fraction is greater than 1. Here's what the fractals look like after a few steps, followed by a check to make sure the segment lengths are adding up correctly.

enter image description here

I shall call the first of those the happy Pi fractal. To be more bold about it, here are those formulas again.

enter image description here

Plotting the values given by these fractals gives something that looks like the Minkowski ? function, which is based on the Farey sequence of irreducible fractions. Build circles of radii twice the denominator squared above each fraction to obtain the Ford circles, a fractal of tangent circles.

enter image description here

An irreducible fraction a/b in the Farey sequence has gcd(a,b)=1 and a less than b. It happens that the probability of random integers being relatively prime with a less than b is 3/Pi^2. We can use that to approximate the length of F1422, all the irreducible fractions with denominator of 1422 or less. Out of a 1422*1422 grid of pixels, about 3/Pi^2percent of them should be black.

enter image description here

By squaring 1422 and multiplying we should be able to get a reasonable approximation for the size of F1422. Then we can check to find the actual size.

enter image description here

Fairly accurate, but enough with 1D. For a 2D fractal for Pi, we can use the Wallis product again.

enter image description here

The corresponding fractal is the Wallis sieve.

Start with a 2*2 square and divide it into 4 squares.
Divide each new subsquare by 3, and remove the middle square (8/9).
Divide each new subsquare by 5, and remove the middle square (24/25).
Divide each new subsquare by 7, and remove the middle square (48/49).
Divide each new subsquare by 9, and remove the middle square (80/81).
And so on. Here's what it looks like after a few steps.

enter image description here

As mentioned earlier, this fractal has an area equal to Pi.

enter image description here

Is there a Menger sponge equivalent of the Wallis sieve? At each step, we'd divide the remaining cubes into the next largest odd cube, then take away the cubes extending out from the center.

enter image description here

That's the same volume as a sphere of radius 1. What would one of these fractals look like? The code is similar: getting the digits 1, 2, or 3 in bases 3, 5, or 7 more than once causes a triplet to get tossed out.

wallissponge = Select[Tuples[Select[Tuples[Range[0, 6], {3}], Sign[{3, 5, 7} - #] == {1, 1, 1} &], {3}], 
   Max[MapIndexed[Count[#1 - #2[[1]], 0] &, Transpose[#]]] < 2 &];

Graphics3D[{EdgeForm[None], Cuboid /@ ((5 7 #[[1]] + 7 #[[2]] + #[[3]] & /@ # ) & /@ wallissponge)}, Boxed -> False, ImageSize -> 600]

enter image description here

Use eight of these to get a fractal object with the same volume as the unit sphere.

We've taken some fractals of measure zero and tweaked them a bit to get Pi. If anyone can break this fractal into pieces and make a sphere, please let me know.

4 Replies

enter image description here - another post of yours has been selected for the Staff Picks group, congratulations !

We are happy to see you at the tops of the "Featured Contributor" board. Thank you for your wonderful contributions, and please keep them coming!

POSTED BY: Vitaliy Kaurov
Posted 9 years ago

Just saw your mention on StandUpMaths: The Fractal Menger Sponge and Pi

Neat stuff, Ed!

POSTED BY: Kurt Gimbel

The last equation giving pi could be simplified a bit: 4*(prod from 1 to n of sum from 1 to n of 8n)/((2n+1)!!)^2.

POSTED BY: Michele Venturi
Posted 4 years ago

I tried programming the second to last equation to approximate pi (for no real reason) but ran into something unexpected. Here is the code (in python):

num=int(input(": "))


for n in range(num):




I ran the loop 1,000,000,000 times and the result dropped below pi. Is that supposed to happen?

POSTED BY: Henry Carolan
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract