関数の反復

Nest, NestList and

Nest[f,x,4]

NestList[f,x,4]

例

recip[x_] := 1/(1+x);

Nest[recip, x, 3]

Fold

Fold[f,x, {a,b,c,d}]

FoldList[f, x, {a,b,c,d}]

例

Fold[Plus,0,{a,b,c,d}]

FoldList[Plus,0,{a,b,c,d}]

Fold[#1^#2&,x,{a,b,c,d}]

FoldList[#1^#2&,x,{a,b,c,d}]

nextdigit[a_,b_] :=10 a + b;

ToNumber[digitlist_] := Fold[nextdigit, 0, digitlist]

ToNumber[{1,2,3,4,5,6}]

Apply

Mathematica Expressionのヘッダを与えた関数で置き換える Apply[ ]

FullForm[{a,b,c,d}]

Apply[f, {a,b,c,d}]

FullForm[%]

Apply[Plus, {1,2,3,4,5,6}]

Apply[f,{{a,b},{b,c,{d,e}}}, 0]

Apply[f,{{a,b},{b,c,{d,e}}}, 1]

Apply[f,{{a,b},{b,c,{d,e}}}, 2]

Apply[f,{{a,b},{b,c,{d,e}}}, 3]

Map （/@）とThread

Map[f,{a,b,c,d}] 指定した深さ(default=1)のリスト要素に関数を適用する

FullForm[Map[f,{a,b,c,d}]]

Map[f, a+b+c+d]

f /@ {a,b,c,d}

FullForm[ a+b+c+d]

FullForm[Map[f, a+b+c+d]]

t={{a,b},{c,d}};

Map[f,t]

Map[f,t,{1}]

Map[f,t,{2}]

MapAt[f,t,{1,2}]

MapAll[f,t]

MapThread[g,{{a,b,c},{x,y,z}}]

MapThread[List, {{1,2,3},{a,b,c},{x,y,z}}]