Search NKS | Online
61 - 70 of 210 for Listable
Implementation [of hexagonal cellular automata]
One can treat hexagonal lattices as distorted square lattices, updated according to
CAStep[rule_List, a_] := Map[rule 〚 14 - # 〛 &, a + 2 ListConvolve[{{1, 1, 0}, {1, 0, 1}, {0, 1, 1}}, a, 2], {2}]
where rule = IntegerDigits[code, 2, 14] .
The reason is that it is always possible to encode any finite list of integers as a single integer, as discussed on page 1120 . … Any real number x can be represented as a set of integers using for example
Rest[FoldList[Plus, 1, ContinuedFraction[x]]]
but except when x is rational this list is not finite. … (The function σ above can for example be used to specify the order in which to sample elements in RealDigits[list] ).
Nonlinear feedback shift registers
Linear feedback shift registers of the kind discussed on page 974 can be generalized to allow any function f (note the slight analogy with cyclic tag systems):
NLFSRStep[f_, taps_, list_] := Append[Rest[list], f[list 〚 taps 〛 ]]
With the choice f=IntegerDigits[s, 2, 8] 〚 8 - # . {4, 2, 1} 〛 & and taps = {1, 2, 3} this is essentially a rule s elementary cellular automaton. With a list of length n , Nest[NLFSRStep[f, taps, #] &, list, n] gives one step in the evolution of the cellular automaton in a register of width n , with a certain kind of spiral boundary condition.
Then the rules for the language consisting of balanced runs of parentheses (see page 939 ) can be written as
{s[e] s[e, e], s[e] s["(", e, ")"], s[e] s["(",")"]}
Different expressions in the language can be obtained by applying different sequences of these rules, say using (this gives so-called leftmost derivations)
Fold[# /. rules 〚 #2 〛 &, s[e], list]
Given an expression, one can then use the following to find a list of rules that will generate it—if this exists:
Parse[rules_, expr_] := Catch[Block[{t = {}}, NestWhile[ ReplaceList[#, MapIndexed[ReverseRule, rules]] &, {{expr, {}}}, (# /. … = {}) &];]]
ReverseRule[a_ b_, {i_}] := {___, {s[x___, b, y___], {u___}}, ___} {s[x, a, y], {i, u}} /; FreeQ[s[x], s[a]]
In general, there will in principle be more than one such list, and to pick the appropriate list in a practical situation one normally takes the rules of the language to apply with a certain precedence—which is how, for example, x + y z comes to be interpreted in Mathematica as Plus[x, Times[y, z]] rather than Times[Plus[x, y], z] .
Tests of randomness
The statistical tests that I have performed include the eight listed on page 1084 .
A simpler example is the rule
Mod[RotateLeft[list] + RotateRight[list], 1]
With a single nonzero initial cell with value 1/k the pattern produced is just Pascal's triangle modulo k .
Typically one starts from some list of vectors to be stored, then forms a matrix such as m = PseudoInverse[list] .
Runs of digits [in numbers]
One can consider any base 2 digit sequence as consisting of successive runs of 0's and 1's, constructed from the list of run lengths by
Fold[Join[#1, Table[1 - Last[#1], {#2}]] &, {0}, list]
This representation is related to so-called surreal numbers (though with the first few digits different).
Starting with a list of the initial conditions for s steps, the configurations for the next s steps are given by
Append[Rest[list], Map[Mod[Apply[Plus, Flatten[c #]], 2]&, Transpose[ Table[RotateLeft[list, {0, i}], {i, -r, r}], {3, 2, 1}]]]
where r = (Length[First[c]] - 1)/2 .
In a typical case, each cell is updated using
LFSRStep[list_] := Append[Rest[list], Mod[list 〚 1 〛 + list 〚 2 〛 , 2]]
with a step of cellular automaton evolution corresponding to the result of updating all cells in the register. … In general, linear feedback shift registers can have "taps" at any list of positions on the register, so that their evolution is given by
LFSRStep[taps_List, list_] := Append[Rest[list], Mod[Apply[Plus, list 〚 taps 〛 ], 2]]
(With taps specified by the positions of 1's in a vector of 0's, the inside of the Mod can be replaced by vec . list as on page 1087 .) … Such generators are directly related to linear feedback shift registers, since with a list of length q , each step is simply
Append[Rest[list], Mod[list 〚 1 〛 + list 〚 q - p + 1 〛 , 2 k ]]
Cryptographic generators.