Involutive automaton
A binary automaton on a ring that is its own inverse.
- Class:
InvolutiveAutomatonSystem - Import:
from skcomplex.systems.computer_science.automata import InvolutiveAutomatonSystem - Field:
computer_science/automata - Topics:
lattice,cellular automaton,invertible,involution - 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 InvolutiveAutomatonSystem
trajectory = InvolutiveAutomatonSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
n |
3 |
size |
80 |
density |
0.6 |
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 InvolutiveAutomatonSystem(BaseSystem):
"""A binary automaton on a ring that is its own inverse.
Its minimal memory set is `{-1, 0, ..., n}`. A cell at the left end of a run of exactly `n` ones, the window
`alpha = 0 1^n 0`, becomes 0, a cell just before a run of exactly `n - 1` ones, the window `beta = 0 0 1^(n - 1) 0`,
becomes 1, and every other cell keeps its value (Ceccherini-Silberstein and Coornaert 2023, Exercise 1.36). The two
moves undo each other, so two steps return every configuration to itself, and the automaton is invertible with
`τ^-1 = τ`. The system has the cells `cells.alive`.
Args:
n:
The length of the runs of ones, at least 3.
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 run length is below 3.
Examples:
>>> from skcomplex.systems.computer_science.automata import InvolutiveAutomatonSystem
>>> values = InvolutiveAutomatonSystem(3, size=20).prepare().simulate(until=2).get_values('cells.alive')
>>> bool((values[2] == values[0]).all())
True
"""
field = 'computer_science/automata'
topics = ('lattice', 'cellular automaton', 'invertible', 'involution')
references = ('Ceccherini-Silberstein and Coornaert 2023',)
until = 10
dt = 1
observables = (Observable('density', group='cells', variable='alive'),)
def __init__(
self,
n: int = 3,
*,
size: int = 80,
density: float = 0.6,
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 involutive rule."""
super()._prepare(context)
if self.n < MIN_INVOLUTION_RUN:
error_msg = f'The run length of the involutive automaton is at least 3, 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=[InvolutiveRuleInteraction('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:
InvolutiveRuleInteraction, 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 InvolutiveRuleInteraction(Interaction):
"""Rule of a binary line that is its own inverse.
Every cell reads the window of offsets `-1, 0, ..., n`. The window `alpha = 0 1^n 0` sends the cell to 0, the
window `beta = 0 0 1^(n - 1) 0` sends it to 1, and every other window keeps it, so two steps return every
configuration to itself.
Args:
label:
The label of the interaction.
target:
The cells whose state `alive` the rule updates.
n:
The length of the runs of ones.
Examples:
>>> from skcomplex.systems.computer_science.automata import InvolutiveRuleInteraction
>>> InvolutiveRuleInteraction('rule', target='cells', n=4).n
4
"""
def __init__(self, label: str, *, target: Role = 'cells', n: int = 3) -> None:
super().__init__(label)
self.target = target
self.n = n
@staticmethod
def _get_next(*values: Array, **kwargs: object) -> Array:
"""Return the cell under the involution.
The values are those of the offsets `-1, 0, ..., n`, so the cell itself is the second.
"""
window = np.stack(values)
run = window.shape[0] - 2
alpha = np.asarray([0, *([1] * run), 0])[:, None]
beta = np.asarray([0, 0, *([1] * (run - 1)), 0])[:, None]
center = window[1]
return np.where(np.all(window == alpha, axis=0), 0.0, np.where(np.all(window == beta, axis=0), 1.0, center))
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the rule on the window of offsets `-1, 0, ..., n` 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 + 1)))
alive = context.target.alive
self.laws_: list[BaseLaw] = [UpdateLaw(alive, self._get_next, neighborhood=window, label=self.label)]