Nilpotent automaton of class n
A binary automaton on a ring that is nilpotent of class n.
- Class:
NilpotentAutomatonSystem - Import:
from skcomplex.systems.computer_science.automata import NilpotentAutomatonSystem - Field:
computer_science/automata - Topics:
lattice,cellular automaton,nilpotent - 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 NilpotentAutomatonSystem
trajectory = NilpotentAutomatonSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
n |
4 |
size |
80 |
density |
0.7 |
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 NilpotentAutomatonSystem(BaseSystem):
"""A binary automaton on a ring that is nilpotent of class `n`.
Every configuration reaches 0 in `n` steps. The memory set is `{-1, 0, ..., n - 1}`, and a cell becomes 0 when the
whole window holds ones or when it is the left end of a run of ones, `p(-1) = 0` and `p(0) = 1`, and keeps its value
otherwise (Ceccherini-Silberstein and Coornaert 2023, Exercise 1.15). After one step every run of ones is shorter
than `n`, and every further step removes the left end of each run, so `n` steps reach 0 and the run of `n + 1` ones
needs all of them. The exercise prints the memory set `{-1, ..., n - 2}`, whose class is `n - 1`, while its solution
relies on `{-1, ..., n - 1}`, which this system takes. The system has the cells `cells.alive`.
Args:
n:
The nilpotency class, at least 2.
size:
The number of cells of the ring.
density:
The probability that a cell starts at 1, when no initial cells are given.
initial:
The initial cells, 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.
Raises:
ParameterError:
The class is below 2.
Examples:
>>> from skcomplex.systems.computer_science.automata import NilpotentAutomatonSystem
>>> trajectory = NilpotentAutomatonSystem(3, size=12, density=1.0).prepare().simulate(until=3)
>>> trajectory.get_values('cells.alive').sum(axis=1).tolist()
[12, 0, 0, 0]
"""
field = 'computer_science/automata'
topics = ('lattice', 'cellular automaton', 'nilpotent')
references = ('Ceccherini-Silberstein and Coornaert 2023',)
until = 6
dt = 1
observables = (Observable('density', group='cells', variable='alive'),)
def __init__(
self,
n: int = 4,
*,
size: int = 80,
density: float = 0.7,
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.n = n
self.size = size
self.density = density
self.initial = initial
self.random_state = random_state
def _get_cells(self) -> Array:
"""Return the initial cells, given or 1 with the probability `density`."""
if self.initial is not None:
return np.asarray(self.initial, dtype=float)
return (np.random.default_rng(self.random_state).random(self.size) < self.density).astype(float)
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of a ring of cells and their nilpotent rule."""
super()._prepare(context)
if self.n < MIN_NILPOTENT_CLASS:
error_msg = f'The nilpotency class of the automaton is at least 2, but it is {self.n}.'
raise ParameterError(error_msg)
cells = self._get_cells()
self.system_ = System(
self.label,
elements=[BinaryCellElement('cells', alive=cells, space=LatticeSpace(cells.size))],
interactions=[NilpotentRuleInteraction('rule', target='cells', n=self.n)],
)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
BinaryCellElement, fromElement
Interactions:
NilpotentRuleInteraction, 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 NilpotentRuleInteraction(Interaction):
"""Rule of a binary line that reaches 0 from every configuration in `n` steps.
Every cell reads the window of offsets `-1, 0, ..., n - 1`. It becomes 0 when the whole window holds ones or when
it is the left end of a run of ones, and keeps its value otherwise.
Args:
label:
The label of the interaction.
target:
The cells whose state `alive` the rule updates.
n:
The nilpotency class.
Examples:
>>> from skcomplex.systems.computer_science.automata import NilpotentRuleInteraction
>>> NilpotentRuleInteraction('rule', target='cells', n=3).n
3
"""
def __init__(self, label: str, *, target: Role = 'cells', n: int = 4) -> None:
super().__init__(label)
self.target = target
self.n = n
@staticmethod
def _get_next(*values: Array, **kwargs: object) -> Array:
"""Return 0 on a window of ones or at the left end of a run of ones, and the cell otherwise.
The values are those of the offsets `-1, 0, ..., n - 1`, so the cell itself is the second.
"""
window = np.stack(values)
left, center = window[0], window[1]
killed = np.all(window == 1, axis=0) | ((left == 0) & (center == 1))
return np.where(killed, 0.0, center)
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the rule on the window of offsets `-1, 0, ..., n - 1` as the law.
Args:
context:
The namespace of the elements a binding of the roles names.
"""
super()._prepare(context)
window = LatticeNeighborhood(tuple((offset,) for offset in range(-1, self.n)))
alive = context.target.alive
self.laws_: list[BaseLaw] = [UpdateLaw(alive, self._get_next, neighborhood=window, label=self.label)]