# Search NKS | Online

1 - 7 of 7 for MapAt

With this setup, the evolution of any register machine can be implemented using the functions (a typical initial condition is {1, {0, 0}} )
RMStep[prog_, {n_Integer, list_List}] := If[n > Length[prog], {n, list}, RMExecute[prog 〚 n 〛 , {n, list}]]
RMExecute[i[r_], {n_, list_}] := {n + 1, MapAt[(# + 1)&, list, r]}
RMExecute[d[r_, m_], {n_, list_}] := If[list 〚 r 〛 > 0, {m, MapAt[(# - 1)&, list, r]}, {n + 1, list}]
RMEvolveList[prog_, init:{_Integer, _List}, t_Integer] := NestList[RMStep[prog, #]&, init, t]
The total number of possible programs of length n using k registers is (k (1 + n)) n .

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 < .

Implementation [of proof example]
Given the axioms in the form
s[1] = (a_ ⊼ a_) ⊼ (a_ ⊼ b_) a;
s[2, x_] := b_ (b ⊼ b) ⊼ (b ⊼ x); s[3] = a_ ⊼ (a_ ⊼ b_) a ⊼ (b ⊼ b); s[4] = a_ ⊼ (b_ ⊼ b_) a ⊼ (a ⊼ b);
s[5] = a_ ⊼ (a_ ⊼ (b_ ⊼ c_)) b ⊼ (b ⊼ (a ⊼ c));
the proof shown here can be represented by
{{s[2, b], {2}}, {s[4], {}}, {s[2, (b ⊼ b) ⊼ ((a ⊼ a) ⊼ (b ⊼ b))], {2, 2}}, {s[1], {2, 2, 1}}, {s[2, b ⊼ b], {2, 2, 2, 2, 2, 2}], {s[5], {2, 2, 2}}, {s[2, b ⊼ b], {2, 2, 2, 2, 2, 1}}, {s[1], {2, 2, 2, 2, 2}}, {s[3], {2, 2, 2}}, {s[1], {2, 2, 2, 2}}, {s[4], {2, 2, 2}}, {s[5], {}}, {s[2, a], {2, 2, 1}}, {s[1], {2, 2}}, {s[3], {}}, {s[1], {2}}}
and applied using
FoldList[Function[{u, v}, MapAt[Replace[#, v 〚 1 〛 ] &, u, {v 〚 2 〛 }]], a ⊼ b, proof]

Select[PM[s], Count[#, 1] > 1 &], 2]]
while blocks of length n (and at most one error) can be decoded with
Drop[(If[# 0, data, MapAt[1 - # &, data, #]] &)[ FromDigits[Mod[data .

With a rule given in this form, a single step in the evolution of the Turing machine can be implemented with the function
TMStep[rule_List, {s_, a_List, n_}] /; (1 ≤ n ≤ Length[a]) := Apply[{#1, ReplacePart[a, #2, n], n + #3}&, Replace[{s, a 〚 n 〛 }, rule]]
The evolution for many steps can then be obtained using
TMEvolveList[rule_, init_List, t_Integer] := NestList[TMStep[rule, #]&, init, t]
An alternative approach is to represent the complete state of the Turing machine by MapAt[{s, #}&, list, n] , and then to use
TMStep[rule_, c_] := Replace[c, {a___, x_, h_List, y_, b___} Apply[{{a, x, #2, {#1, y}, b}, {a, {#1, x}, #2, y, b}} 〚 #3 〛 &, h /. rule]]
The result of t steps of evolution from a blank tape can also be obtained from (see also page 1143 )
s = 1; a[_] = 0; n = 0;
Do[{s, a[n], d} = {s, a[n]} /. rule; n += d, {t}]

Other examples [of substitution systems]
(a) (Period-doubling sequence) After t steps, there are a total of 2 t elements, and the sequence is given by Nest[MapAt[1 - # &, Join[#, #], -1]&, {0}, t] .

The number of sequences s n of length n that can actually occur is given by
Apply[Plus, Flatten[MatrixPower[m, n]]]
where the adjacency matrix m is given by
MapAt[(1 + #) &, Table[0, {Length[net]}, {Length[net]}], Flatten[MapIndexed[{First[#2], Last[#1]} &, net, {2}], 1]]
For rule 32, for example, s n turns out to be Fibonacci[n + 3] , so that for large n it is approximately GoldenRatio n .