Archive

Posts Tagged ‘Conway’s Game of Life’

Generating Sequences of Primes in Conway's Game of Life

August 28th, 2009

One of the most interesting patterns that has ever been constructed in Conway’s Game of Life is primer, a gun that fires lightweight spaceships that represent exactly the prime numbers. It was constructed by Dean Hickerson way back in 1991, yet arguably no pattern since then has been constructed that’s as interesting. It seems somewhat counter-intuitive at first that the prime numbers, which seem somehow “random” or “unpredictable”, can be generated by this (relatively simple) pattern in the completely deterministic Game of Life.

Primer, the prime-generating gun

Primer, the prime-generating gun

The gun works by firing lightweight spaceships westward, and destroying them via glider guns that emulate the Sieve of Eratosthenes. A lightweight spaceship makes it past the left edge of the gun at generation 120N if and only if N is a prime number (though for technical reasons, 2 and 3 are not outputted).

The first six lightweight spaceships output by primer and the numbers they represent

The first six lightweight spaceships output by primer

It wasn’t too long after making primer that Hickerson realized that he could attach a gun to the bottom-left corner of it to turn it into a twin prime calculator by allowing each lightweight spaceship through only if another lightweight spaceship passed through 240 generations earlier. Similarly, Jason Summers constructed a Fermat prime calculator in 2000 by shooting a glider at the lightweight spaceship stream every generation of the form 120(2N + 1), which ends up detecting exactly the Fermat primes.

So what other families of primes can we compute in Life by altering the output of the original prime-generating gun?

Mersenne Primes

Mersenne primes can easily be computed using the exact same method as was used in the Fermat prime calculator — use a 7-engine Cordership (in blue below) to bounce a glider back at the stream of lightweight spaceships, with the time required for the glider to reach the stream doubling each time. An inverter (in green below) eliminates all lightweight spaceships that try to get past it unless it just received a glider from the Cordership. By fiddling around with timing a tiny bit, we then have a Mersenne prime calculator:

Mersenne Prime Calculator

Mersenne Prime Calculator

Prime Quadruplets

Four prime numbers are said to form a prime quadruplet if they are of the form (p, p+2, p+6, p+8) for some prime number p, which is the closest that four prime numbers can be together (except for the degenerate cases of (2,3,5,7) and (3,5,7,11)). Prime quadruplets are easy to compute because they can be thought of as consecutive pairs of twin primes. Since we already have a twin prime calculator, we can just repeat its reaction.

The twin prime calculator works by attaching a period 240 gun (in green below) to the bottom-left corner of primer. If it is timed correctly, it has the effect of allowing a lightweight spaceship through at generation 240N if and only if a lightweight spaceship tried to pass through at generation 240(N-1). Thus, it will only allow a lightweight spaceship through if it represents a prime number of the form p+2, where p is another prime number. Well, simply attaching a period 720 gun (in blue below) then allows a spaceship through at generation 720N if and only if a lightweight spaceship tried to pass through at generation 720(N-1). This has the effect of allowing a lightweight spaceship to pass through only if it represents a twin prime pair (p,p+2), and there is another twin prime pair of the form (p-6,p-4). That is, the only lightweight spaceships allowed through are those representing the upper members of prime quadruplets.

Prime quadruplet calculator

Prime quadruplet calculator

Prime Pairs of the Form (p, p+2k)

The twin prime calculator mentioned earlier gives a way of computing prime pairs of the form (p,p+2), but what about pairs where the gap is larger than 2? For example, the k=2 case gives what are known as cousin primes, and the k=3 case gives sexy primes (yes, really).

For the case of cousin primes, the thing to notice is that every pair of cousin primes (except for the first pair, (3,7)) must be of the form (6n+1, 6n+5) for some natural number n. Thus, we can use two period 720 guns (in blue below) to allow only the upper prime in a cousin prime pair to pass through. This is achieved by having the top gun fire at the lightweight spaceships representing primes of the form 6n+1 — if a lightweight spaceship is hit, then a block is created in the path of the other gun, which is fired at lightweight spaceships representing primes of the form 6n+5. If a prime was present at 6n+1, then the lightweight spaceship makes it through unharmed at 6n+5. If there was no prime present at 6n+1, then the bottom gun destroys the lightweight spaceship representing 6n+5.

Cousin prime calculator

Cousin prime calculator

Extending this idea to prime pairs of the form (p,p+2k) for k ≥ 3 is a bit more challenging, however, because it is possible for pairs to overlap. For example, (37,43) is a sexy prime pair, as is (41,47). Up until now we have only been able to detect single pairs at a time, since the block that acts as our “counter” that keeps track of whether a prime was detected earlier is placed in the stream of incoming lightweight spaceships. Thus, if it’s possible for two pairs to overlap, we will get lightweight spaceships colliding with the block, causing a mess.

To get around this problem, we use a device (known as a fanout, in green below) that duplicates the stream of lightweight spaceships. We then check for certain pairs on one stream, and the rest of the pairs on the other stream (these devices are outlined in blue below). Once we’re done, we merge the resulting streams of lightweight spaceships back together (using the devices in purple below).

To make this process a bit more explicit, I present a gun that computes prime pairs of the form (p,p+8). In particular, a lightweight spaceship will make it past the left edge of this pattern at about generation 1620+120N if and only if both N and N+8 are prime.

(p, p+8) prime calculator

(p, p+8) prime calculator

We now have all of the tools needed to build any pattern that computes prime pairs of the form (p, p+2k) as long as k = 1 or 2 (mod 3), though we may need to use the fanout device multiple times if it’s possible for more than one pair to overlap. If k = 0 (mod 3), however, it’s much more difficult to construct the desired pattern, because not only can you have overlapping prime pairs like (5, 11) and (7, 13), but you can have prime pairs in sequence such as (5, 11) and (11, 17). This problem can be remedied using the same tools as used in the (p,p+8) prime calculator, though you may need to use a lot of fanout devices to make things work. For example, computing the sexy primes using these tools would require at least four fanouts, and some clever elimination logic on each of the resulting five lightweight spaceship streams. I don’t feel up to that task myself, but it’s nice to know that we have a method for constructing a sexy prime calculator.

The Maximal Lifespan of Patterns in Conway's Game of Life

July 31st, 2009

In a couple of recent posts, I argued that random patterns in Conway’s Game of Life tend, on average, to live longest when they have an initial density of 37.5% cells being alive. In this post, rather than looking at the distribution of the average lifespan for various initial densities, I will fix the density at 37.5% and look at the distribution of lifespans that results, and use that to estimate what the maximal lifespan of any small pattern is (as in my previous posts, I will use 20×20 starting patterns). As before, I will explore both the case when we simulate Life on a torus and when we simulate it on an infinite plane.

Lifespan Distribution on a Torus

After simulating 175000 random patterns on a 20×20 torus, the distribution of the lifespans was as follows:

Lifespan Frequency Histogram on a TorusThe bins in the graph have a width of 10, and the peak occurs in the lifespan 91 – 100 bin. Some other interesting stats include:

  • Maximum observed lifespan: 2092
  • Minimum observed lifespan: 14
  • Average lifespan: 210
  • Median lifespan: 164
  • Standard deviation of lifespan: 159.3

In order to try to estimate the longest lifespan of any pattern on a 20×20 torus, I will assume that if the lifespan is above 100, then it follows an exponential distribution, which appears to be a reasonable assumption given the above histogram. Indeed, this leads to the following histogram, which has the exponential of best fit overlaid in black. The equation of the exponential is y = 9088.7(0.938)x, and the R2 value is 0.997 (that’s one heck of a good fit).

Lifespan Frequency Trend on a TorusNow that we have our exponential of best fit, we can get an estimate of the maximal lifespan in this scenario by assuming that the lifespan of the 220*20 different patterns are independent of each other (this may not be a particularly good assumption, as two patterns, for example, will have the same lifespan if they are translations of each other — nonetheless it seems that the number of reductions that can be made by symmetry arguments like that is tiny compared to the total number of such patterns, so let’s roll with it). We then set

Torus equation

and solve for x to get a maximal lifespan of x = 4474. This seems believable and not particularly shocking to me given the statistics that I listed earlier.

Lifespan Distribution on a Plane

Typically, Life enthusiasts are more interested in results on the infinite plane than on a torus, as it leads to behaviour that is much more chaotic and unpredictable. For example, even though we just saw that the longest-lived 20×20 pattern on a torus likely lives for less than 4500 generations, there is a known 9×15 pattern that lives on the plane for over 29000 generations. We will now proceed analogously to the torus discussion above to see how much better we can reasonably expect to do. We begin with the distribution of the lifespan based on 60000 initial 20×20 patterns:

Lifespan Frequency Histogram on a Plane

The bins in the graph have a width of 50, and the peak occurs in the lifespan 151 – 200 bin. The other basic stats are listed below, and as we would expect, the average lifespan and the standard deviation of lifespans are both much greater on the plane than they are on the torus.

  • Maximum observed lifespan: 13612
  • Minimum observed lifespan: 15
  • Average lifespan: 678
  • Median lifespan: 368
  • Standard deviation of lifespan: 885.6

The main difference with the analysis in this situation is that instead of assuming the lifespan itself follows an exponential distribution, I will assume that some power of the lifespan follows an exponential distribution; the reason for this is that the R2 is quite low if we try to fit an exponential to the distribution of the lifespans itself. Fitting an exponential to lifespan0.75 seems to give the maximum R2 value (0.9857), so this is what I will use. The following histogram shows the curve of best fit, which has the equation y = 1854.6(0.957)x, where this time x = lifespan0.75.

Lifespan Frequency Trend on a Plane

Finally, we follow our method from before and set

Lifespan on a Plane Equation

and solve for x to get a maximal lifespan of x = 120795. Of course, this number should be taken with a grain of salt, because that pattern I mentioned earlier that has a lifespan of over 29000 generations was found during a simulation of a whopping 12 billion 20×20 patterns, while our equation of best fit tells us that after 12 billion patterns, we would expect only to see a pattern with lifespan 6206 (when really it should only take about 400 patterns to see such a lifespan). Similarly, in the longest-lived patterns found by the Online Life-Like CA Soup Search, a pattern has been found with lifespan 24389. According to our formula, we should have to look at roughly 9 million billion billion billion soups before finding such a pattern, but only 40 million soups have actually been searched.

This all seems to suggest that the longest-lived pattern in a 20×20 box may in fact live considerably longer than 120000 generations, which goes to show just how in the dark we are when it comes to some of these simple questions — since the search space is so unimaginably huge, we likely will never know for sure what the true upper limit is.

Downloads:

Longevity in Conway's Game of Life Revisited

July 17th, 2009

A couple of weeks ago, I posted some intuition that suggested that, in Conway’s Game of Life, the longest-lived patterns should on average be those with density right around 37.5%. To test this hypothesis, I wrote a simple Golly Python script that generated random 20×20 patterns of varying densities and checked how long it took for them to stabilize. One noticeable problem cropped up, however: patterns with density around 90% tended to live for an extremely long time due to edge effects that caused the pattern to explode out of the original 20×20 box initially, even though they would almost entirely die off within the box.

The solution to the given problem is to emulate the Game of Life not on an infinite planar grid, but rather on a toroidal grid; that is, we fix our 20×20 universe and treat the top row as if it borders the bottom row and the left row as if it borders the right row. Running the simulation in this set-up results in data that matches our intuition more closely:

Lifespan on a TorusThe results are based on 13592 random patterns of each density 1%, 2%, 3%, …, 99%. As with the previous graph, we notice that the lifespan plateaus in the 25% – 50% range, providing evidence that our intuition for a maximum at 37.5% is probably well-founded. Also, at the request of Elithrion in the comments on the previous post, I have included the median plot for the lifespans this time as well, though the median seems to behave pretty similarly to the average (it’s just more or less uniformly 25% smaller). As we would expect, the average lifespan in the toroidal universe set-up is much lower than the average lifespan in the infinite planar grid set-up, because expanding patterns have nowhere to go. The longest-lived pattern that was found on the torus had a lifespan of 2169 (and an initial density of 30%), whereas the longest-lived pattern that was found on the infinite plane (over significantly fewer trials, I might add) was 14042.

While I’m presenting results, how about we take a look at the final population of patterns of various starting densities?

Torus final populationThe behaviour is almost identical to that of the average/median lifespan. The one cool thing is that, in addition to the plateau centred at ~37.5%, here we see that the median final population peaks with a value of 13 at an initial density of 38%. Nevermind the fact that this is almost certainly a statistical anomaly — it helps support my original hypothesis, and if the popular news media has taught me anything, it’s that randomly picking out things like that and claiming that they are significant is always mathematically sound.

Downloads:

The Online Life-Like CA Soup Search

July 11th, 2009

UPDATE [April 17, 2015]: The Online Life-Like CA Soup Search has been offline for some time now (due to being written in ASP, and me now only running websites on Linux hosts, which means I would have to re-code it entirely in PHP). However, I am happy to announce that Adam P. Goucher has recently released a new distributed soup search script called Catagolue. Not only is this script much faster than mine, but it also has many other improvements, such as being (much) better at distinguishing different objects that are near each other, and being more cryptographically secure.

See this forum thread for the announcement as well as some discussion of discoveries made by the search so far.


Today I’m “officially” announcing the Online Life-Like CA Soup Search, though some of the folks over at the ConwayLife.com forums have been helping me test it out for a couple of weeks now.

As I mentioned in this post, one way to learn about the general behaviour of Conway’s Game of Life (or any other Life-like cellular automaton) is to generate random patterns and see what stable patterns they typically evolve into (if any). If you’ve played around with Conway’s Game of Life, then you more than likely are very familiar with blocks, blinkers, beehives, loaves, and maybe even pulsars, simply as a result of drawing random gibberish on the grid and letting it evolve. This is exactly the idea behind the Online Life-Like CA Soup Search, just on a larger scale — what if we had lots of people’s computers drawing random gibberish on Life grids, letting them evolve, and storing the resulting patterns in a communal database?

This method of collecting patterns in Life is known as a census, and to my knowledge it has been carried out on a relatively large scale twice in the past; once by Achim Flammenkamp (results here), and once by Andrej Okrasinski (results linked in the first paragraph here). As we would expect, the block is by far the most common still life, and the blinker is by far the most common oscillator. If we scroll down a bit, we see that the pulsar is the fourth most common oscillator (which is reasonably surprising, given its size). Scrolling much past that, we get into the interesting stuff — objects that no reasonable person has ever seen from drawing random stuff and seeing what it evolves into, simply because they occur so infrequently.

So why bother doing another census if two rather large-scale censuses (censi?) have already been carried out? My reasons are threefold:

  1. There has never (to my knowledge) been a census of any other Life-like cellular automata conducted. The Online Life-Like CA Soup Search is completely general in that it can conduct a census of any Life-like rule (assuming that rule is stable, of course). Censuses have already been started for five other rules, including 2×2, Day & NightHighLife, and Move. Because some of these other rules have been studied relatively little, this is an easy way of discovering new yet fundamental patterns in them. For example, it didn’t take long for the soup search script to uncover a c/8 line puffer in the 2×2 (B36/S125) rule; the very first known pattern that exhibits infinite growth in 2×2!

    Line puffer in 2x2

    Line puffer in 2×2

  2. Previous soup searches were limited in that they only looked for very specific types of objects — usually still lifes and oscillators (though Achim Flammenkamp did a search for spaceships and puffers that can be viewed here). The Online Life-Like CA Soup Search searches for still lifes, oscillators, spaceships and puffers all at once, and even gets pseudo objects (such as the bi-block) as well.
  3. Multiple users can run the script and contribute to the results simultaneously. Rather than just having one person run a script that they themself wrote, the Online Life-Like CA Soup Search works by having users download a script and that script uploads results to the central database. This obviously provides a huge speed-up, and allows the census to continuously improve and expand.

So what are you waiting for? Visit the Online Life-Like CA Soup Search, download the script, and put your computer’s CPU cycles to good use!

Census results in Conway's Game of Life

Census results in Conway’s Game of Life

Longest-Lived Soup Density in Conway's Game of Life

June 26th, 2009

In Conway’s Game of Life, a simple way to learn about the general dynamics of the game are to study what happens to soup – patterns made up of a random assortment of ON and OFF cells. Two particularly interesting questions that we can ask are “What types of stable patterns arise most frequently from soup?” and “How long does soup generally last before stabilizing?” I will focus on the latter question for today’s post, as the former has become the bud of a more ambitious project that I will announce in the near future.

The question of how long soup generally lasts before stabilizing is quite vague, because there are two important considerations that we have not specified:

  1. How dense should the soup be? Clearly soup with ON density of 5% will survive only a fraction as long as soup with ON density of 50%.
  2. How large of a region of soup should we let evolve? Smaller regions will stabilize much more quickly than large regions, and infinite regions will likely never stabilize(?), not to mention we can’t effectively simulate an infinite field of random cells.

For #2, I will choose the region to be of size 20×20. This decision is pretty arbitrary, but part of the reason I chose such a small size is as a desire to make this script kill two birds with one stone; any particularly long-lived patterns of this size that are discovered can likely be considered methuselahs, while larger patterns can not.

For #1, we might naively expect that patterns will live longest if they have density 37.5%, since cells are born if and only if they have exactly three ON neighbours (out of a possible eight = 37.5%). To test this theory, I created a Golly script that creates regions of varying density and checks how long it takes for them to stabilize. The following graph shows the average lifespan of 20×20 patterns with densities ranging from 1% to 99%, based on 5000 generated patterns for each percentage point.

Average lifespan after 5000 trials

Indeed, it looks like the longest-lived density estimate of 37.5% isn’t too far off. The true maximum in this set-up might actually be slightly higher, but that is most likely caused by the same thing that is causing the hump centered at 90%: edge effects. Roughly speaking, because we are simulating a finite region of soup on an infinite grid (as opposed to on a toroidal universe), patterns of higher density will tend to expand out very quickly in their first few generations, giving them longer lifespans in general than they would have on a toroidal universe. Alas, Golly doesn’t support toroidal universes, so the toroidal lifespan results will have to wait for another day.

Update [July 8, 2009]: I have attached to the end of this post the Python script used to generate these results.

Update [July 11, 2009]: See this post, which deals with the “more ambitious project” that I mentioned.

Update [July 19, 2009]: See this post, which deals with soup longevity on a torus.

Downloads:

Does Wolfram Alpha Live up to the Hype?

May 18th, 2009

No. No it does not.

Wolfram Alpha doesn't know what Conway's Game of Life is.

Update [June 14, 2011]: Entering “Conway’s Game of Life” into Wolfram Alpha now does provide you with information about the game. I suppose that means that it officially lives up to the hype.