Conway's Game of Life

From APL Wiki
Revision as of 15:17, 12 April 2020 by Marshall (talk | contribs) (→‎Historical implementations: Details of early implementations)
Jump to navigation Jump to search

Conway's Game of Life is a well-known cellular automaton in which each generation of a population "evolves" from the previous one according to a set of predefined rules. The Game of Life is defined on an infinite Boolean grid, but usually only finite patterns, where all 1 values fit in a finite Boolean matrix, are studied. Because it involves interactions between adjacent elements of the matrix, and can take advantage of APL's convenient and fast Boolean handling, implementing the Game of Life is a popular activity for APLers. APL implementations have appeared in the APL Quote-Quad since 1971, a year after the rules of the Game of Life were first published. More recently, it is sometimes seen as a use case for the Stencil operator, which provides a concise way to work on three-by-three neighborhoods as used by the Game of Life.

A famous video by John Scholes[1] explains the following Dyalog APL implementation step by step. The implementation takes advantage of nested arrays and the Outer Product to produce many copies of the argument array. It finds adjacent elements by rotating the original array, causing elements at the edge to wrap around (giving a torus geometry).

      Life←{↑1 ⍵∨.∧3 4=+/,¯1 0 1∘.⊖¯1 0 1∘.⌽⊂⍵}

This implementation is also explained in its own article.

Historical implementations

First published in October 1970 by Martin Gardner in Scientific American[2], Conway's Game of Life quickly became a popular target of APL implementation. Jean Jacques Duby's 7-line interactive implementation appeared in APL Quote Quad exactly a year later.[3] Duby's tradfn takes as input a list of coordinates of live cells and displays subsequent states until no live cells remain or the user stops it; it was shown along with an pattern evolving into a beehive. The next state is computed one element at a time, so that the function makes little use of APL's array capabilities. The function was followed by a 9-line implementation in February 1972[4] and both a 6-line and a 4-line implementation in June 1972[5]. The last two implementations used more efficient strategies involving Rotate or indexing with an array index to obtain the neighbors of every array element at once.

A survey of previous APL implementations along with two new 23-token implementations was given by Eugene McDonnell in "Life: Nasty, Brutish, and Short", published in the APL88 conference proceedings.[6] McDonnell also described how future language features, such as the Commute operator and a tesselation operator related to Cut and the much later Stencil, might reduce this to as few as 11 tokens (one of which is a long list of integers), or to 9 tokens when using a pre-defined vector of matrices.

John Scholes published a video in which he explains his own implementation of Life, the same as the function Life above, in 2009.[1] Scholes' function resembles McDonnell's APL2 implementation in its use of three-element vertical and horizontal rotation vectors, but uses Inner Product and Outer Product rather than Each as well as a different arithmetic scheme.

External links

References

  1. 1.0 1.1 Scholes, John. "Conway's Game of Life in APL". 2009-01-26.
  2. Gardner, Martin (October 1970). "Mathematical Games – The fantastic combinations of John Conway's new solitaire game "life"". Scientific American. 223 (4): 120–123.
  3. Jean Jacques Duby. "Conway's Game "Life"", APL Quote Quad Vol. III No. 2 & 3 p. 54. 1971-10-01. Reprinted SIGPLAN Notices Volume 6, Issue 10; see Front matter p. 120.
  4. Bruce A. Beebe. "Life". APL Quote Quad Vol III No. 4 p. 37. 1972-02-10. Reprinted SIGPLAN Notices Volume 7, Issue 4; in Algorithms.
  5. W. J. Jones, "Game of Life" and D. A. Bonyun, "Game of Life". APL Quote Quad Vol III No. 5 p. 66-67. 1972-06-05
  6. McDonnell, Eugene. "Life: Nasty, Brutish, and Short" (web). APL88 Conference Proceedings, APL Quote-Quad Vol. 18 No. 2, 1987-12.