One dimensional Cellular Automata
Discrete Cellular Automata
CellularAutomata.DCA — Type
DCA(rule; states=2, radius=1)Construct a discrete cellular-automaton rule and its neighborhood lookup table.
Arguments
rule: Nonnegative Wolfram rule identifier.
Keyword arguments
states: Number of possible cell states. Defaults to 2.radius: Symmetric radius or(left, right)asymmetric radius. Defaults to 1.
Throws
ArgumentError: If the rule configuration or a transitioned state is outside its declared discrete domain.
Examples
julia> using CellularAutomata
julia> dca = DCA(30);
julia> rule_lookup_table(dca)
8-element Vector{Int64}:
0
1
1
1
1
0
0
0
julia> next_state(dca, [0, 0, 1, 0, 0])
5-element Vector{Int64}:
0
1
1
1
0CellularAutomata.TCA — Type
TCA(code; states=2, radius=1)Construct a totalistic cellular-automaton rule and its lookup table.
Arguments
code: Nonnegative totalistic rule identifier.
Keyword arguments
states: Number of possible cell states. Defaults to 2.radius: Symmetric radius or(left, right)asymmetric radius. Defaults to 1.
Throws
ArgumentError: If the rule configuration or a transitioned state is outside its declared discrete domain.
Examples
julia> using CellularAutomata
julia> tca = TCA(3);
julia> rule_lookup_table(tca)
4-element Vector{Int64}:
1
1
0
0
julia> next_state(tca, [0, 0, 1, 0, 0])
5-element Vector{Int64}:
1
1
1
1
1Continuous Cellular Automata
CellularAutomata.CCA — Type
CCA(rule; radius=1)Construct a continuous cellular-automaton rule. Each output is the fractional part of the neighborhood mean plus rule.
Arguments
rule: Value added to each neighborhood mean.
Keyword arguments
radius: Symmetric radius or(left, right)asymmetric radius. Defaults to 1.
Examples
julia> using CellularAutomata
julia> cca = CCA(1 // 10);
julia> next_state(cca, [0 // 1, 0 // 1, 3 // 10])
3-element Vector{Rational{Int64}}:
1//5
1//5
1//5Random number generation
CellularAutomata.CellularAutomatonRNG — Type
CellularAutomatonRNG(rule=DCA(30); size=127, seed=rand(RandomDevice(), UInt),
skip=nothing, start=nothing, warmup=4) -> CellularAutomatonRNGPseudorandom number generator driven by a one-dimensional cellular automaton, in the style of Wolfram's original Rule 30 generator (Mathematica's "ExtendedCA" method). Only binary rules are supported: mapping a correlated multi-state CA stream to unbiased bits requires assumptions that the generic rule interface cannot guarantee. The seed is mixed across a tape of size cells. The automaton is then advanced for warmup * size throwaway generations before output begins. Each subsequent generation advances the automaton and reads one or more cells as output bits.
By default only the center cell is read, one bit per generation. Passing skip reads every skip-th cell starting from start across the whole tape instead, producing many bits per generation for much higher throughput, the same trick "ExtendedCA" uses (there with Skip=4) to avoid the correlation between adjacent cells that a finite-radius rule would otherwise introduce within a single generation.
Arguments
rule: Binary one-dimensional discrete cellular-automaton rule driving the tape. Custom rules must implementcell_state_count(rule). Defaults toDCA(30).
Keywords
size: Number of cells on the tape. Even values are bumped up by 1 to keep a well-defined center cell. Defaults to 127.seed: Integer mixed across the initial tape. Defaults to a seed drawn from the OS entropy source (RandomDevice()).skip: Whennothing(the default), read only the cell atstart. Otherwise, read everyskip-th cell starting fromstartacross the tape each generation.start: Index of the first cell read each generation. Defaults to the center cell whenskipisnothing, or to1whenskipis given.warmup: Number of throwaway generations per tape cell after initialization. Defaults to 4.
Throws
ArgumentError: Ifruledoes not implementcell_state_count, if the rule is not binary, ifsizeis smaller than 3, ifskipis smaller than 1, ifstartis outside1:size, or ifwarmupis smaller than 1.
Examples
julia> using CellularAutomata
julia> rng = CellularAutomatonRNG(DCA(30); size = 7, seed = 1);
julia> rand(rng, UInt8)
0xb7
julia> wide_rng = CellularAutomatonRNG(DCA(30); size = 15, seed = 2, skip = 4);
julia> rand(wide_rng, UInt8)
0xd4