Search NKS | Online
11 - 20 of 210 for Listable
Implementation of generalized mobile automata
The state of a generalized mobile automaton at a particular step can be specified by {list, nlist} , where list gives the values of the cells, and nlist is a list of the positions of active cells. The rule can be given by specifying a list of cases such as {0, 0, 0} {1, {1, -1}} , where in each case the second sublist specifies the new relative positions of active cells. With this setup successive steps in the evolution of the system can be obtained from
GMAStep[rules_, {list_, nlist_}] := Module[{a, na}, {a, na} = Transpose[Map[Replace[Take[list, {# - 1, # + 1}], rules]&, nlist]]; {Fold[ReplacePart[#, Last[#2], First[#2]]&, list, Transpose[{nlist, a}]], Union[Flatten[nlist + na]]}]
Implementation [of mobile automata]
The state of a mobile automaton at a particular step can conveniently be represented by a pair {list, n} , where list gives the values of the cells, and n specifies the position of the active cell (the value of the active cell is thus list 〚 n 〛 ). … With a rule given in this form, each step in the evolution of the mobile automaton corresponds to the function
MAStep[rule_, {list_List, n_Integer}] /; (1 < n < Length[list]) := Apply[{ReplacePart[list, #1, n], n + #2}&, Replace[Take[list, {n - 1, n + 1}], rule]]
The complete evolution for many steps can then be obtained with
MAEvolveList[rule_, init_List, t_Integer] := NestList[MAStep[rule, #]&, init, t]
(The program will run more efficiently if Dispatch is applied to the rule before giving it as input.)
For the mobile automaton on page 73 , the rule can be given as
{{1, 1, 1} {{0, 0, 0}, -1}, {1, 1, 0} {{1, 0, 1}, -1}, {1, 0, 1} {{1, 1, 1}, 1}, {1, 0, 0} {{1, 0, 0}, 1}, {0, 1, 1} {{0, 0, 0}, 1}, {0, 1, 0} {{0, 1, 1}, -1}, {0, 0, 1} {{1, 0, 1}, 1}, {0, 0, 0} {{1, 1, 1}, 1}}
and MAStep must be rewritten as
MAStep[rule_, {list_List, n_Integer}] /; (1 < n < Length[list]) := Apply[{Join[Take[list, {1, n - 2}], #1, Take[list, {n + 2, -1}]], n + #2}&, Replace[Take[list, {n - 1, n + 1}], rule]]
Implementation [of constraint satisfaction]
The number of squares violating the constraint used here is given by
Cost[list_] := Apply[Plus, Abs[list - RotateLeft[list]]]
When applied to all possible patterns, this function yields a distribution with Gaussian tails, but with a sharp point in the middle. Successive steps in the iterative procedure used on this page are given by
Move[list_] := (If[Cost[#] < Cost[list], #, list] &)[ MapAt[1 - # &, list, Random[Integer, {1, Length[list]}]]]
while those in the procedure on page 347 have ≤ in place of < .
With the exception of the second distributive law, it turns out that the highlighted theorems are exactly the ones that cannot be derived from preceding theorems in the list. The distributive laws appear at positions 2813 and 2814 in the list; it takes a long proof to obtain the second one from preceding theorems.
Implementation [of multiway systems]
It is convenient to represent the state of a multiway system at each step by a list of strings, where an individual string is for example "ABBAAB" . The rules for the multiway system can then be given for example as
{"AAB" "BB", "BA" "ABB"}
The evolution of the system is given by the functions
MWStep[rule_List, slist_List] := Union[Flatten[ Map[Function[s, Map[MWStep1[#, s] &, rule]], slist]]]
MWStep1[p_String q_String, s_String] := Map[StringReplacePart[s, q, #] &, StringPosition[s, p]]
MWEvolveList[rule_, init_List, t_Integer] := NestList[MWStep[rule, #] &, init, t]
An alternative approach uses lists instead of strings, and in effect works by tracing the internal steps that Mathematica goes through in trying out possible matchings. With the rule from above written as
{{x___, 0, 0, 1, y___} {x, 1, 1, y}, {x___, 1, 0, y___} {x, 0, 1, 1, y}}
MWStep can be rewritten as
MWStep[rule_List, slist_List] := Union[Flatten[Map[ReplaceList[#, rule] &, slist], 1]]
The case shown on page 206 is
{"AB" "", "ABA" "ABBAB", "ABABBB" "AAAAABA"}
starting with {"ABABAB"} .
Implementation of digit sequences
A whole number n can be converted to a sequence of digits in base k using IntegerDigits[n,k] or (see also page 1094 )
Reverse[Mod[NestWhileList[Floor[#/k] &, n, # ≥ k &], k]]
and from a sequence of digits using FromDigits[list,k] or
Fold[k #1 + #2 &, 0, list]
For a number x between 0 and 1, the first m digits in its digit sequence in base k are given by RealDigits[x, k, m] or
Floor[k NestList[Mod[k #, 1]&, x, m - 1]]
and from these digits one can reconstruct an approximation to the number using FromDigits[{list, 0}, k] or
Fold[#1/k + #2 &, 0, Reverse[list]]/k
And with this representation, the evolution for t steps is given by
SSEvolveList[rule_, init_List, t_Integer] := NestList[Flatten[# /. rule]&, init, t]
where in the first example on page 82 , the initial condition is {1} .
… In this case, the evolution can be obtained using
SSEvolveList[rule_, init_String, t_Integer] := NestList[StringReplace[#, rule]&, init, t]
For a neighbor-dependent substitution system such as the first one on page 85 the rule can be given as
{{1, 1} {0, 1}, {1, 0} {1, 0}, {0, 1} {0}, {0, 0} {0, 1}}
And with this representation, the evolution for t steps is given by
SS2EvolveList[rule_, init_List, t_Integer] := NestList[Flatten[Partition[#, 2, 1] /. rule]&, init, t]
where the initial condition for the first example on page 85 is {0, 1, 1, 0} .
Implementation [of causal networks]
Given a list of successive positions of the active cell, as from Map[Last, MAEvolveList[rule, init, t]] (see page 887 ), the network can be generated using
MAToNet[list_] := Module[{u, j, k}, u[_] = ∞ ; Reverse[ Table[j = list 〚 i 〛 ; k = {u[j - 1], u[j], u[j + 1]}; u[j - 1] = u[j] = u[j + 1] = i; i k, {i, Length[list], 1, -1}]]]
where nodes not yet found by explicit evolution are indicated by ∞ .
Comments on Mathematica functions
CenterList works by first creating a list of n 0's, then replacing the middle 0 by a 1. … CAEvolveList applies CAStep t times. … In general NestList[s[r, #]&, i, 2] ⟶ {i, s[r, i], s[r, s[r, i]]} , etc.
The last two axioms listed for set theory are usually considered optional.