Life in a tree
The Game of Life on the free group F4, surjective but not pre-injective.
- Class:
LifeInATreeSystem - Import:
from skcomplex.systems.computer_science.automata import LifeInATreeSystem - Field:
computer_science/automata - Topics:
group,cellular automaton,life,free group,Garden of Eden - References:
- Ceccherini-Silberstein and Coornaert 2023
Use this system
The block imports the class and simulates the system with its default parameters and its tuned run settings.
from skcomplex.systems.computer_science.automata import LifeInATreeSystem
trajectory = LifeInATreeSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
radius |
4 |
density |
0.3 |
initial |
None |
random_state |
0 |
solver |
'auto' |
backend |
'auto' |
Tags
The system with its default parameters has these capability tags, which solvers and analyses check.
| Tag | Values |
|---|---|
| Time | discrete |
| Space | lattice |
| Laws | update |
| Randomness | unknown |
| Domains | boolean |
| Structure | fixed |
Class
The source of the class shows how it builds its components from its model parameters.
class LifeInATreeSystem(BaseSystem):
"""The Game of Life on the free group F4, surjective but not pre-injective.
The free group F4 is a tree of degree 8. The memory set is the identity and the generators `a`, `b`, `c`, `d` with
their inverses, and a cell is alive after a step when the sum over the memory set is 3, or 4 with the cell alive,
Conway's rule on the Cayley graph of F4 (Ceccherini-Silberstein and Coornaert 2023, Exercise 5.14). On the tree the
automaton is surjective but not pre-injective, unlike Life on the plane, which is neither. Cells on the boundary of
the ball read 0 outside it. The system has the cells `cells.alive`.
Args:
radius:
The radius of the ball of F4.
density:
The probability that a cell starts alive, when no initial cells are given.
initial:
The initial cells, one per site, or `None` for random ones.
random_state:
The seed or generator of the random initial cells.
label:
The label of the system, which names it when it is nested in another one.
solver:
The solver of the problem, or `'auto'` for the one the system chooses.
backend:
The backend that evaluates the compiled functions, or `'auto'` for the one the system chooses.
Examples:
>>> from skcomplex.systems.computer_science.automata import LifeInATreeSystem
>>> LifeInATreeSystem(radius=2).prepare().simulate(until=1).get_values('cells.alive').shape
(2, 65)
"""
field = 'computer_science/automata'
topics = ('group', 'cellular automaton', 'life', 'free group', 'Garden of Eden')
references = ('Ceccherini-Silberstein and Coornaert 2023',)
until = 20
dt = 1
observables = (Observable('density', group='cells', variable='alive'),)
def __init__(
self,
*,
radius: int = 4,
density: float = 0.3,
initial: npt.ArrayLike | None = None,
random_state: int | np.random.Generator | None = 0,
label: str = 'system',
solver: BaseSolver | str = 'auto',
backend: BaseBackend | str = 'auto',
) -> None:
super().__init__(label, solver=solver, backend=backend)
self.radius = radius
self.density = density
self.initial = initial
self.random_state = random_state
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of the cells on a ball of the free group of rank 4 and the rules of life."""
super()._prepare(context)
space = CayleySpace(free_group(TREE_RANK), ball=self.radius)
size = space.prepare().size_
if self.initial is None:
cells = np.asarray(np.random.default_rng(self.random_state).random(size) < self.density, dtype=float)
else:
cells = np.asarray(self.initial, dtype=float)
life = LifeRuleInteraction(
'life',
target='cells',
born=(3,),
survive=(2, 3),
neighborhood=GeneratorNeighborhood(space.generators_, center=False),
)
self.system_ = System(
self.label,
elements=[BinaryCellElement('cells', alive=cells, space=space)],
interactions=[life],
)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
BinaryCellElement, fromElement
Interactions:
LifeRuleInteraction, fromInteraction
class BinaryCellElement(Element):
"""Cell of an automaton whose value `alive` is 0 or 1.
The local rule of an interaction changes the value. With `space`, the element holds one cell on every site.
Args:
label:
The label of the cells.
alive:
The initial value, 0 or 1, or one value per cell.
space:
The space with one cell on every site, such as a lattice, or `None` for one cell.
Examples:
>>> from skcomplex.systems.computer_science.automata import BinaryCellElement
>>> BinaryCellElement('cell', alive=1).alive
1
"""
def __init__(
self,
label: str,
*,
alive: Annotated[float | Array, {0, 1}] = 0,
space: BaseSpace | None = None,
) -> None:
super().__init__(label, space=space)
self.alive = alive
class LifeRuleInteraction(Interaction):
"""Life-like rule of cells, such as `B3/S23` of Conway's Game of Life.
A dead cell comes to life when its number of live neighbours is one of `born`, and a live cell stays alive when it
is one of `survive`. Every other cell is dead at the next step.
Args:
label:
The label of the interaction.
target:
The cells whose state `alive` the rule updates.
born:
The numbers of live neighbours that bring a dead cell to life.
survive:
The numbers of live neighbours that keep a live cell alive.
neighborhood:
The neighbours every cell counts, the eight cells around it by default.
Examples:
>>> from skcomplex.systems.computer_science.automata import LifeRuleInteraction
>>> LifeRuleInteraction('rule', target='cells', born=(3, 6)).born
(3, 6)
"""
def __init__(
self,
label: str,
*,
target: Role = 'cells',
born: Sequence[int] = (3,),
survive: Sequence[int] = (2, 3),
neighborhood: BaseNeighborhood = MOORE,
) -> None:
super().__init__(label)
self.target = target
self.born = born
self.survive = survive
self.neighborhood = neighborhood
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the local rule of the cells as the law.
Args:
context:
The namespace of the elements a binding of the roles names.
"""
super()._prepare(context)
rule = life(self.born, self.survive)
alive = context.target.alive
self.laws_: list[BaseLaw] = [UpdateLaw(alive, rule, neighborhood=self.neighborhood, label=self.label)]