Hashlife: Difference between revisions
→Hashing: trivially->typically (I believe this was unintentionally misworded. The author must have meant "typically", especially since the sentence says "far" more overhead, which is not trivial.) |
lk "octillion" |
||
Line 1: | Line 1: | ||
{{short description|Algorithm for speeding up cellular automaton simulations}} |
{{short description|Algorithm for speeding up cellular automaton simulations}} |
||
{{No footnotes|date=September 2016}} |
{{No footnotes|date=September 2016}} |
||
[[File:Turing Machine in Golly.png|thumb|379px|right|The 6,366,548,773,467,669,985,195,496,000 (6 octillionth) generation of a [[Turing machine]] in [[Conway's Game of Life|Life]] computed in less than 30 seconds on an [[Intel Core]] Duo 2GHz CPU using Hashlife in [[Golly (program)|Golly]]. Computed by detecting a repeating cycle in the pattern, and skipping ahead to any requested generation.]] |
[[File:Turing Machine in Golly.png|thumb|379px|right|The 6,366,548,773,467,669,985,195,496,000 (6 [[Names of large numbers|octillionth]]) generation of a [[Turing machine]] in [[Conway's Game of Life|Life]] computed in less than 30 seconds on an [[Intel Core]] Duo 2GHz CPU using Hashlife in [[Golly (program)|Golly]]. Computed by detecting a repeating cycle in the pattern, and skipping ahead to any requested generation.]] |
||
'''Hashlife''' is a [[Memoization|memoized]] [[algorithm]] for computing the long-term fate of a given starting configuration in [[Conway's Game of Life]] and related [[cellular automaton|cellular automata]], much more quickly than would be possible using alternative algorithms that simulate each time step of each cell of the automaton. The algorithm was first described by [[Bill Gosper]] in the early 1980s while he was engaged in research at the [[Xerox Palo Alto Research Center]]. Hashlife was originally implemented on [[Symbolics]] [[Lisp machine]]s with the aid of the [[Flavors (programming language)|Flavors]] extension. |
'''Hashlife''' is a [[Memoization|memoized]] [[algorithm]] for computing the long-term fate of a given starting configuration in [[Conway's Game of Life]] and related [[cellular automaton|cellular automata]], much more quickly than would be possible using alternative algorithms that simulate each time step of each cell of the automaton. The algorithm was first described by [[Bill Gosper]] in the early 1980s while he was engaged in research at the [[Xerox Palo Alto Research Center]]. Hashlife was originally implemented on [[Symbolics]] [[Lisp machine]]s with the aid of the [[Flavors (programming language)|Flavors]] extension. |
||
Revision as of 14:53, 18 May 2020
This article includes a list of references, related reading, or external links, but its sources remain unclear because it lacks inline citations. (September 2016) |
Hashlife is a memoized algorithm for computing the long-term fate of a given starting configuration in Conway's Game of Life and related cellular automata, much more quickly than would be possible using alternative algorithms that simulate each time step of each cell of the automaton. The algorithm was first described by Bill Gosper in the early 1980s while he was engaged in research at the Xerox Palo Alto Research Center. Hashlife was originally implemented on Symbolics Lisp machines with the aid of the Flavors extension.
Hashlife
Hashlife is designed to exploit large amounts of spatial and temporal redundancy in most Life rules. For example, in Conway's Life, many seemingly random patterns end up as collections of simple still lifes and oscillators.
Representation
The field is typically treated as a theoretically infinite grid, with the pattern in question centered near the origin. A quadtree is used to represent the field. Given a square of 22k cells, 2k on a side, at the kth level of the tree, the hash table stores the 2k−1-by-2k−1 square of cells in the center, 2k−2 generations in the future. For example, for a 4×4 square it stores the 2×2 center, one generation forward; and for an 8×8 square it stores the 4×4 center, two generations forward.
Hashing
While a quadtree typically has far more overhead than other simpler representations (such as using a matrix of bits), it allows for various optimizations. As the name suggests, the algorithm uses hash tables to store the nodes of the quadtree. Many subpatterns in the tree are usually identical to each other; for example the pattern being studied may contain many copies of the same spaceship, or even large swathes of empty space. These subpatterns will all hash to the same position in the hash table, and thus many copies of the same subpattern can be stored using the same hash table entry. In addition, these subpatterns only need to be evaluated once, not once per copy as in other Life algorithms.
This itself leads to significant improvements in resource requirements; for example a generation of the various breeders and spacefillers, which grow at polynomial speeds, can be evaluated in Hashlife using logarithmic space and time.
Superspeed and caching
A further speedup for many patterns can be achieved by evolving different nodes at different speeds. For example, one could compute twice the number of generations forward for a node at the (k+1)-th level compared to one at the kth. For sparse or repetitive patterns such as the classical glider gun, this can result in tremendous speedups, allowing one to compute bigger patterns at higher generations faster, sometimes exponentially. To take full advantage of this feature, subpatterns from past generations should be saved as well.
Since different patterns are allowed to run at different speeds, some implementations, like Gosper's own hlife
program, do not have an interactive display, but simply compute a preset end result for a starting pattern, usually run from the command line. More recent programs such as Golly, however, have a graphical interface that can drive a Hashlife-based engine.
The typical behavior of a Hashlife program on a conducive pattern is as follows: first the algorithm runs slower compared to other algorithms because of the constant overhead associated with hashing and building the tree; but later, enough data will be gathered and its speed will increase tremendously – the rapid increase in speed is often described as "exploding".
Drawbacks
Like many memoized codes, Hashlife can consume significantly more memory than other algorithms, especially on moderate-sized patterns with a lot of entropy, or which contain subpatterns poorly aligned to the bounds of the quadtree nodes (i.e. power-of-two sizes); the cache is a vulnerable component. It can also consume more time than other algorithms on these patterns. Golly, among other Life simulators, has options for toggling between Hashlife and conventional algorithms.
Hashlife is also significantly more complex to implement. For example, it needs a dedicated garbage collector to remove unused nodes from the cache.
See also
- Purely functional data structure, of which the hashed quadtree is one
References
- Gosper, Bill (1984). "Exploiting Regularities in Large Cellular Spaces". Physica D. 10 (1–2). Elsevier: 75–80. doi:10.1016/0167-2789(84)90251-3.