Subtraction automaton over the naturals
The automaton τ(x)(n) = max(0, x(n) - x(n + 1)) over the naturals.
- Class:
SubtractionAutomatonSystem - Import:
from skcomplex.systems.computer_science.automata import SubtractionAutomatonSystem - Field:
computer_science/automata - Topics:
lattice,infinite alphabet,naturals,non-closed image - 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 SubtractionAutomatonSystem
trajectory = SubtractionAutomatonSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
size |
41 |
height |
10 |
initial |
None |
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 | integer |
| Structure | fixed |
Class
The source of the class shows how it builds its components from its model parameters.
class SubtractionAutomatonSystem(BaseSystem):
"""The automaton `τ(x)(n) = max(0, x(n) - x(n + 1))` over the naturals.
Its image is not closed. The image of the configurations `x_M`, equal to `M` left of the origin and to
`max(0, M - n)` from it, is the block of `M` ones from the origin. These blocks converge to the configuration of
ones on the half line, which is no image, so the image of the automaton over the infinite alphabet `N` is not closed
(Ceccherini-Silberstein and Coornaert 2023, Example 3.3.3). The cells sit on a segment with fixed ends that read 0,
and start at `x_M` with `M = height`, its origin a quarter of the way along. The system has the cells `cells.value`.
Args:
size:
The number of cells.
height:
The value `M` of the staircase.
initial:
The initial values, or `None` for the staircase.
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 height is negative.
Examples:
>>> from skcomplex.systems.computer_science.automata import SubtractionAutomatonSystem
>>> SubtractionAutomatonSystem(12, height=3).prepare().system_.elements[0].value.tolist()
[3.0, 3.0, 3.0, 3.0, 2.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
"""
field = 'computer_science/automata'
topics = ('lattice', 'infinite alphabet', 'naturals', 'non-closed image')
references = ('Ceccherini-Silberstein and Coornaert 2023',)
until = 10
dt = 1
def __init__(
self,
size: int = 41,
*,
height: int = 10,
initial: npt.ArrayLike | None = None,
label: str = 'system',
solver: BaseSolver | str = 'auto',
backend: BaseBackend | str = 'auto',
) -> None:
super().__init__(label, solver=solver, backend=backend)
self.size = size
self.height = height
self.initial = initial
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of the staircase on a segment and the truncated difference."""
super()._prepare(context)
if self.height < 0:
error_msg = f'The height of the staircase is a natural number, but it is {self.height}.'
raise ParameterError(error_msg)
if self.initial is None:
origin = self.size // 4
steps = np.arange(self.size) - origin
values = np.where(steps < 0, self.height, np.maximum(0, self.height - steps)).astype(float)
else:
values = np.asarray(self.initial, dtype=float)
self.system_ = System(
self.label,
elements=[PascalCellElement('cells', value=values, space=LatticeSpace(self.size, boundary='fixed'))],
interactions=[SubtractionRuleInteraction('subtraction', target='cells')],
)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
PascalCellElement, fromElement
Interactions:
SubtractionRuleInteraction, fromInteraction
class PascalCellElement(Element):
"""Cell of an automaton over the nonnegative integers.
With `space`, the element holds one cell on every site.
Args:
label:
The label of the cells.
value:
The initial value, a nonnegative integer, 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 PascalCellElement
>>> PascalCellElement('cell', value=3).value
3
"""
def __init__(
self,
label: str,
*,
value: Annotated[float | Array, NN] = 0,
space: BaseSpace | None = None,
) -> None:
super().__init__(label, space=space)
self.value = value
class SubtractionRuleInteraction(Interaction):
"""Truncated difference `τ(x)(n) = max(0, x(n) - x(n + 1))` of cells holding natural numbers.
Args:
label:
The label of the interaction.
target:
The cells whose state `value` the difference changes.
Examples:
>>> from skcomplex.systems.computer_science.automata import SubtractionRuleInteraction
>>> SubtractionRuleInteraction('subtraction', target='cells').target
'cells'
"""
def __init__(self, label: str, *, target: Role = 'cells') -> None:
super().__init__(label)
self.target = target
@staticmethod
def _subtract(here: Array, right: Array, **kwargs: object) -> Array:
"""Return the truncated difference `max(0, x(n) - x(n + 1))` of the naturals."""
return np.maximum(0.0, here - right)
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the truncated difference with the cell to the right as the law.
Args:
context:
The namespace of the elements a binding of the roles names.
"""
super()._prepare(context)
value = context.target.value
self.laws_: list[BaseLaw] = [UpdateLaw(value, self._subtract, neighborhood=FORWARD, label=self.label)]