Search NKS | Online
81 - 90 of 98 for Flatten
![](/common/images/search/spacer.gif)
One can find the sequences of length n that work by using
Nest[DeleteCases[Flatten[Map[Table[Append[#, i - 1], {i, k}] &, #], 1], {___, x__, x__, ___}] &, {{}}, n]
and the number of these grows roughly like 3 n/4 .
The Thue–Morse sequence discussed on page 890 can be obtained from it by applying
1 - Mod[Flatten[Partition[FoldList[Plus, 0, list], 1, 2]], 2]
(b) The n th element is simply Mod[n, 2] .
However, the straightforward method for converting a t -digit number x to base k takes about t divisions, though this can be reduced to around Log[t] by using a recursive method such as
FixedPoint[Flatten[Map[If[# < k, #, With[ {e = Ceiling[Log[k, #]/2]}, {Quotient[#, k e ], With[ {s = Mod[#, k e ]}, If[s 0, Table[0, {e}], {Table[0, {e - Floor[Log[k, s]] - 1}], s}]]}]] &, #]] &, {x}]
The pictures below show stages in the computation of 3 20 (a) by a power tree in base 2 and (b) by conversion from base 3.
(Examples for logic are axiom systems which never change the size of an expression, or which are of the form {expr a} where Flatten[expr] begins or ends with a .)
Concatenation sequences
One can consider forming sequences by concatenating digits of successive integers in base k , as in Flatten[Table[IntegerDigits[i, k], {i, n}]] .
Here are examples of how some of the basic Mathematica constructs used in the notes in this book work:
• Iteration
Nest[f, x, 3] ⟶ f[f[f[x]]]
NestList[f, x, 3] ⟶ {x, f[x], f[f[x]], f[f[f[x]]]}
Fold[f, x, {1, 2}] ⟶ f[f[x, 1], 2]
FoldList[f, x, {1, 2}] ⟶ {x, f[x, 1], f[f[x, 1], 2]}
• Functional operations
Function[x, x + k][a] ⟶ a + k
(# + k&)[a] ⟶ a + k
(r[#1] + s[#2]&)[a, b] ⟶ r[a] + s[b]
Map[f, {a, b, c}] ⟶ {f[a], f[b], f[c]}
Apply[f, {a, b, c}] ⟶ f[a, b, c]
Select[{1, 2, 3, 4, 5}, EvenQ] ⟶ {2, 4}
MapIndexed[f, {a, b, c}] ⟶ {f[a, {1}], f[b, {2}], f[c, {3}]}
• List manipulation
{a, b, c, d} 〚 3 〛 ⟶ c
{a, b, c, d} 〚 {2, 4, 3, 2} 〛 ⟶ {b, d, c, b}
Take[{a, b, c, d, e}, 2] ⟶ {a, b}
Drop[{a, b, c, d, e}, -2] ⟶ {a, b, c}
Rest[{a, b, c, d}] ⟶ {b, c, d}
ReplacePart[{a, b, c, d}, x, 3] ⟶ {a, b, x, d}
Length[{a, b, c}] ⟶ 3
Range[5] ⟶ {1, 2, 3, 4, 5}
Table[f[i], {i, 4}] ⟶ {f[1], f[2], f[3], f[4]}
Table[f[i, j], {i, 2}, {j, 3}] ⟶ {{f[1, 1], f[1, 2], f[1, 3]}, {f[2, 1], f[2, 2], f[2, 3]}}
Array[f, {2, 2}] ⟶ {{f[1, 1], f[1, 2]}, {f[2, 1], f[2, 2]}}
Flatten[{{a, b}, {c}, {d, e}}] ⟶ {a, b, c, d, e}
Flatten[{{a, {b, c}}, {{d}, e}}, 1] ⟶ {a, {b, c}, {d}, e}
Partition[{a, b, c, d}, 2, 1] ⟶ {{a, b}, {b, c}, {c, d}}
Split[{a, a, a, b, b, a, a}] ⟶ {{a, a, a}, {b, b}, {a, a}}
ListConvolve[{a, b}, {1, 2, 3, 4, 5}] ⟶ {2a + b, 3a + 2b, 4a + 3b, 5a + 4b}
Position[{a, b, c, a, a}, a] ⟶ {{1}, {4}, {5}}
RotateLeft[{a, b, c, d, e}, 2] ⟶ {c, d, e, a, b}
Join[{a, b, c}, {d, b}] ⟶ {a, b, c, d, b}
Union[{a, a, c, b, b}] ⟶ {a, b, c}
• Transformation rules
{a, b, c, d} /. b p ⟶ {a, p, c, d}
{f[a], f[b], f[c]} /. f[a] p ⟶ {p, f[b], f[c]}
{f[a], f[b], f[c]} /. f[x_] p[x] ⟶ {p[a], p[b], p[c]}
{f[1], f[b], f[2]} /. f[x_Integer] p[x] ⟶ {p[1], f[b], p[2]}
{f[1, 2], f[3], f[4, 5]} /. f[x_, y_] x + y ⟶ {3, f[3], 9}
{f[1], g[2], f[2], g[3]} /. f[1] | g[_] p ⟶ {p, p, f[2], p}
• Numerical functions
Quotient[207, 10] ⟶ 20
Mod[207, 10] ⟶ 7
Floor[1.45] ⟶ 1
Ceiling[1.45] ⟶ 2
IntegerDigits[13, 2] ⟶ {1, 1, 0, 1}
IntegerDigits[13, 2, 6] ⟶ {0, 0, 1, 1, 0, 1}
DigitCount[13, 2, 1] ⟶ 3
FromDigits[{1, 1, 0, 1}, 2] ⟶ 13
The Mathematica programs in these notes are formatted in Mathematica StandardForm .
With evolution functions f i and f j the requirement for the emulation to work is
f j [a j ] InverseFunction[ ϕ ][f i [ ϕ [a j ]]]
In the main text the encoding function is taken to have the form Flatten[a /. rules] —where rules are say {1 {1, 1}, 0 {0, 0}} —with the result that the decoding function for emulations that work is Partition[ ã , b] /.
As discovered by Jeffrey Shallit in 1979, numbers of the form Sum[1/k 2 i , {i, 0, ∞ }] that have nonzero digits in base k only at positions 2 i turn out to have continued fractions with terms of limited size, and with a nested structure that can be found using a substitution system according to
{0, k - 1, k + 2, k, k, k - 2, k, k + 2, k - 2, k} 〚 Nest[Flatten[{{1, 2}, {3, 4}, {5, 6}, {7, 8}, {5, 6}, {3, 4}, {9, 10}, {7, 8}, {9, 10}, {3, 4}} 〚 # 〛 ]&, 1, n] 〛
The continued fractions for square roots are always periodic; for higher roots they never appear to show any significant regularities. … In analogy to digits in a concatenation sequence the terms in the sequence
Flatten[Table[Rest[ContinuedFraction[a/b]], {b, 2, n}, {a, b - 1}]]
are known to occur with the same frequencies as they would in the continued fraction representation for a randomly chosen number.
Much as for integers, finite lists of real numbers can be encoded as single real numbers—using for example roughly FromDigits[Flatten[Transpose[RealDigits[list]]]] —so that the number of such lists is 2 ℵ 0 .
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.
![](/common/images/search/spacer.gif)