Search NKS | Online
151 - 160 of 210 for Listable
![](/common/images/search/spacer.gif)
In 1202 Leonardo Fibonacci explicitly gave as an example a list of primes up to 100.
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 .
Implementation [of geometric substitution systems]
The most convenient approach is to represent each pattern by a list of complex numbers, with the center of each square being given in terms of each complex number z by {Re[z], Im[z]} .
Then given the list of such values the crucial constraint imposed by the standard formalism of quantum mechanics is unitarity: that the quantity Tr[Abs[list] 2 ] representing total probability should be conserved.
x_ {0, x, 0}, And[x__] {0, 0, 1, 0, x, 1, 3, 0, 0}, Or[x__] {0, 0, 1, 0, x, 0, 1, 3, 0}}]]
and in terms of these initial conditions the cellular automaton must be run for Length[list //. {0, x__} {x}] - 1 steps in order to find the result.
With s = 2 and n from 0 to 7 the number of these True for all values of variables is {0, 0, 4, 0, 80, 108, 2592, 7296} , with the first few distinct ones being (see page 781 )
{(p ⊼ p) ⊼ p, (((p ⊼ p) ⊼ p) ⊼ p) ⊼ p, (((p ⊼ p) ⊼ p) ⊼ q) ⊼ q}
The number of unequal expressions obtained is {2, 3, 3, 7, 10, 15, 12, 16} (compare page 1096 ), with the first few distinct ones being
{p, p ⊼ p, p ⊼ q, (p ⊼ p) ⊼ p, (p ⊼ q) ⊼ p, (p ⊼ p) ⊼ q}
Most of the axioms from page 808 are too long to appear early in the list of theorems.
Polish representation (whose reverse form has been used in HP calculators) for an expression can be obtained using (see also page 1173 )
Flatten[expr //. x_[y_] { ∘ , x, y}]
The original expression can be recovered using
First[Reverse[list] //.
With rule given by IntegerDigits[num, k, k 2 ] a single step of evolution can be implemented as
CAStep[{k_, rule_}, a_List] := rule 〚 k 2 - RotateLeft[a] - k a 〛
Continued fractions
The first n terms in the continued fraction representation for a number x can be found from the built-in Mathematica function ContinuedFraction , or from
Floor[NestList[1/Mod[#, 1]&, x, n - 1]]
A rational approximation to the number x can be reconstructed from the continued fraction using FromContinuedFraction or by
Fold[(1/#1 + #2 )&, Last[list], Rest[Reverse[list]]]
The pictures below show the digit sequences of successive iterates obtained from NestList[1/Mod[#, 1]&, x, n] for several numbers x .
In general, the pattern produced by evolution for t steps is given by
NestList[ Inner[f, Prepend[#, 0], Append[#, 0], List] &, {a}, t]
so that the first few steps yield
{a},
{f[0, a], f[a, 0]},
{f[0, f[0, a]], f[f[0, a], f[a, 0]], f[f[a, 0], 0]},
{f[0, f[0, f[0, a]]], f[f[0, f[0, a]], f[f[0, a], f[a, 0]]], f[f[f[0, a], f[a, 0]], f[f[a, 0], 0]], f[f[f[a, 0], 0], 0]}
If f is Flat , however, then the last two lines here become
{f[0, 0, a], f[0, a, a, 0], f[a, 0, 0]},
{f[0, 0, 0, a], f[0, 0, a, 0, a, a, 0], f[0, a, a, 0, a, 0, 0], f[a, 0, 0, 0]}
and in general the number of a 's that appear in a particular element is given as in Pascal's triangle by a binomial coefficient.
![](/common/images/search/spacer.gif)