Defining a Ruleset

To define a custom ruleset, one must define 2 transition rules, which should be formal expressions which evaluate to either true or false.

For a given cell that is alive (black), if the "Alive → Alive" transition is satisfied, that cell will remain alive in the next generation. Otherwise, the cell becomes dead (white).

For a given cell that is dead, if the "Dead → Alive" transition is satisfied, that cell will become alive in the next generation. Otherwise, the cell remains dead.


Example: Conway's Game of Life

One famous cellular automaton is Conway's Game of Life. It can be stated as follows:

  1.) Live cells with two (2) or three (3) live neighbours survive.
  2.) Dead cells with exactly three (3) live neighbours become a live cells.
  3.) All other cells become or remain dead.

We can formulate these rules as two (2) transitions:

Alive → Alive: alive(neighbors(1)) in set(2, 3)
Dead → Alive: alive(neighbors(1)) = 3

Let's examine the transition for Alive → Alive.

  neighbors(1) will return a representation of the 8 orthagonal and diagonal neighbors for a given cell.
  alive(neighbors(1)) will return the number of those 8 neighbors which are alive.
  set(2, 3) will create a set containing the numbers 2 and 3.
  alive(neighbors(1)) in set(2, 3) will return a boolean representing whether or not the number of alive neighbors of a given cell is 2 or 3.

Thus, the expression represents the idea: "Live cells with two (2) or three (3) live neighbours survive, otherwise they die."

Below is a list of the various functions you can use to write the transiton rules.



Library

Function Usage Return Description
= INT_1 = INT_2

BOOL_1 = BOOL_2
Boolean Returns true if arguments are equal, false otherwise.
+ INT_1 + INT_2 Integer Returns the sum of INT_1 and INT_2.
- INT_1 - INT_2 Integer Returns the difference of INT_1 and INT_2.
not not BOOL_1 Boolean Returns the negation of BOOL_1.
and BOOL_1 and BOOL_2 Boolean Returns the conjunction of BOOL_1 and BOOL_2.
or BOOL_1 and BOOL_2 Boolean Returns the disjunction of BOOL_1 and BOOL_2.
set set(INT_1, ...) Set Returns a set containing all of the arguments. Can contain duplicates.
interval interval(INT_1, INT_2) Set Returns a set containing all of the integers from INT_1 to INT_2, inclusive.
union SET_1 union SET_2 Set Returns the union of SET_1 and SET_2. Can contain duplicates.
in INT_1 in SET_1 Boolean Returns true if SET_1 contains an element equal to INT_1, false otherwise.
neighbors neighbors(INT_1, ...) Set neighbors(0) will return set(0, 0).

neighbors(1) will return set(-1, -1, -1, 0, -1, 1, 0, -1, 0, 1, 1, -1, 1, 0, 1, 1). This is a representation of the 8 orthagonally and diagonally adjacent cells) of a given cell.

For N > 0, neighbors(N) will return a square-shaped perimeter of cells of length 2N + 1 centered around a given cell.

neighbors(N_1, N_2, ...) will return a union of neighbors(N_1), neighbors(N_2), and so on.
alive alive(SET) Integer Iterates through the set 2 elements at a time, using the first as the relative row and the second as the relative column to a given cell.

Returns the number of pairs for which the cell described by the relative row and column is alive.

For example, alive(set(1, 0)) will return 1 for a given cell if the cell below it is alive, 0 otherwise.