Search NKS | Online
201 - 210 of 213 for Block
If m = k s -1 then it turns out that interchanging a pair of adjacent length s blocks in list never affects the result.
Sorting networks
Any list can be sorted using Fold[PairSort, list, pairs] by doing a fixed sequence of comparisons of pairs
PairSort[a_, p : {_, _}] := Block[{t = a}, t 〚 p 〛 = Sort[t 〚 p 〛 ]; t]
(Different comparisons often do not interfere and so can be done in parallel.)
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, {}}}, (# /.
In general, however, a 1D cellular automaton rule can be given as a set of explicit replacements for all possible blocks of cells in each neighborhood (see page 60 ).
Optimal circuit blocks for operations such as addition and sorting (see page 1142 ) have occasionally been found by searches, but are more often found by explicit construction, progressive improvement or systematic logic minimization (see page 1097 ).
(Knowing the explicit representation one could then determine whether each block would be shorter if encoded literally or using a pointer.)
Note that if the rule for the finite automaton is represented for example as {{1, 2}, {2, 1}} where each sublist corresponds to a particular state, and the elements of the sublist give the successor states with inputs Range[0, k - 1] , then the n th element in the output sequence can be obtained from
Fold[rule 〚 #1, #2 〛 &, 1, IntegerDigits[n - 1, k] + 1] - 1
while the first k m elements can be obtained from
Nest[Flatten[rule 〚 # 〛 ] &, 1, m] - 1
To treat examples such as case (c) where elements can subdivide into blocks of several different lengths one must generalize the notion of digit sequences.
DES takes 64-bit blocks of data and a 56-bit key, and applies 16 rounds of substitutions and permutations.
With rules set up in this way, each step in the evolution of a network system is given by
NetEvolveStep[{depth_Integer, rule_List}, list_List] := Block[ {new = {}}, Join[Table[Map[NetEvolveStep1[#, list, i] &, Replace[NeighborNumbers[list, i, depth], rule]], {i, Length[list]}], new]]
NetEvolveStep1[s : {___Integer}, list_, i_] := Follow[list, i, s]
NetEvolveStep1[{s1 : {___Integer}, s2 : {___Integer}}, list_, i_] := Length[list] + Length[ AppendTo[new, {Follow[list, i, s1], Follow[list, i, s2]}]]
The set of nodes that can be reached from node i is given by
ConnectedNodes[list_, i_] := FixedPoint[Union[Flatten[{#, list 〚 # 〛 }]] &, {i}]
and disconnected nodes can be removed using
RenumberNodes[list_, seq_] := Map[Position[seq, #] 〚 1, 1 〛 &, list 〚 seq 〛 , {2}]
The sequence of networks obtained on successive steps by applying the rules and then removing all nodes not connected to node number 1 is given by
NetEvolveList[rule_, init_, t_Integer] := NestList[(RenumberNodes[#, ConnectedNodes[#, 1]] &)[ NetEvolveStep[rule, #]] &, init, t]
Note that the nodes in each network are not necessarily numbered in the order that they appear on successive lines in the pictures in the main text.
(With an n × n initial block of 4's, stabilization typically takes about 0.4 n 2 steps.).