Baumslag-Solitar groups
The majority automaton on a ball of the Baumslag-Solitar group BS(m, n).
- Class:
BaumslagSolitarAutomatonSystem - Import:
from skcomplex.systems.computer_science.automata import BaumslagSolitarAutomatonSystem - Field:
computer_science/automata - Topics:
group,cellular automaton,majority,solvable - References:
- Ceccherini-Silberstein and Coornaert 2023
- Baumslag and Solitar 1962
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 BaumslagSolitarAutomatonSystem
trajectory = BaumslagSolitarAutomatonSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
m |
1 |
n |
2 |
radius |
6 |
density |
0.5 |
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 BaumslagSolitarAutomatonSystem(BaseSystem):
"""The majority automaton on a ball of the Baumslag-Solitar group `BS(m, n)`.
The group has exponential growth. Every cell reads itself and the cells at `a`, `a^-1`, `t`, and `t^-1`, and takes
the majority value. The ball is built from a confluent rewriting system of the presentation, which GAP finds for
`BS(1, n)`. The system has the cells `cells.alive`.
Args:
m:
The exponent of `a` conjugated by `t`.
n:
The exponent it is conjugated to.
radius:
The radius of the ball.
density:
The probability that a cell starts at 1.
random_state:
The seed or generator of the 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 BaumslagSolitarAutomatonSystem
>>> BaumslagSolitarAutomatonSystem(radius=2).prepare().simulate(until=1).get_values('cells.alive').shape
(2, 17)
"""
field = 'computer_science/automata'
topics = ('group', 'cellular automaton', 'majority', 'solvable')
references = ('Ceccherini-Silberstein and Coornaert 2023', 'Baumslag and Solitar 1962')
until = 20
dt = 1
observables = (Observable('density', group='cells', variable='alive'),)
def __init__(
self,
m: int = 1,
n: int = 2,
*,
radius: int = 6,
density: float = 0.5,
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.m = m
self.n = n
self.radius = radius
self.density = density
self.random_state = random_state
def _get_cells(self, space: BaseSpace) -> Array:
"""Return cells that are 1 with the probability `density`, one per site of a prepared space."""
size = space.prepare().size_
return np.asarray(np.random.default_rng(self.random_state).random(size) < self.density, dtype=float)
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of random cells on a ball of the group and their majority rule."""
super()._prepare(context)
space = CayleySpace(baumslag_solitar(self.m, self.n), ball=self.radius)
neighborhood = GeneratorNeighborhood(space.prepare().generators_)
self.system_ = System(
self.label,
elements=[BinaryCellElement('cells', alive=self._get_cells(space), space=space)],
interactions=[MajorityRuleInteraction('majority', target='cells', neighborhood=neighborhood)],
)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
BinaryCellElement, fromElement
Interactions:
MajorityRuleInteraction, 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 MajorityRuleInteraction(Interaction):
"""Majority rule of binary cells on the sites of a group.
Every cell takes the value held by more than half of itself and its neighbours, and a tie keeps its value. Only the
neighbours inside the space count, so the cells on the boundary of a ball read fewer neighbours.
Args:
label:
The label of the interaction.
target:
The cells whose state `alive` the rule updates.
neighborhood:
The neighbours of every cell, such as the generators of the group and their inverses.
Examples:
>>> from skcomplex.systems.computer_science.automata import GeneratorNeighborhood, MajorityRuleInteraction
>>> rule = MajorityRuleInteraction('majority', target='cells', neighborhood=GeneratorNeighborhood(['a', 'b']))
>>> rule.neighborhood.generators
['a', 'b']
"""
def __init__(self, label: str, *, target: Role = 'cells', neighborhood: BaseNeighborhood = FREE_GENERATORS) -> None:
super().__init__(label)
self.target = target
self.neighborhood = neighborhood
@staticmethod
def _get_majority(center: Array, *values: Array, degree: Array, **kwargs: object) -> Array:
"""Return the value held by more than half of a cell and its neighbours, keeping it on a tie."""
total = center + np.sum(values, axis=0)
count = degree + 1
return np.where(2 * total > count, 1.0, np.where(2 * total < count, 0.0, center))
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the majority of every cell and its neighbours as the law.
Args:
context:
The namespace of the elements a binding of the roles names.
"""
super()._prepare(context)
alive = context.target.alive
self.laws_: list[BaseLaw] = [
UpdateLaw(alive, self._get_majority, neighborhood=self.neighborhood, label=self.label),
]
