Higher Order Functions

\(Needs["Graphics`Master`"]; 
Needs["Calculus`Master`"]; \)

Pure Functions

Function[s, s^2]

Function[s, s^2][5]

Function[s, s^2][x]

Function[{s, t}, Sqrt[s^2 + t^2]]

Function[{s, t}, Sqrt[s^2 + t^2]][1, -5]

Function[s, Sqrt[s[[1]]^2 + s[[2]]^2]]

Function[s, Sqrt[s[[1]]^2 + s[[2]]^2]][{1, -5}]

SinCos = Function[s, Sin[Cos[s]]]

SinCos[π]

Higher Order Functions: "Map"

tab = Table[i, {i, 1, 10}]

Map[fct, tab]

Map[Function[s, s^2], tab]

Map[Function[s, PrimeQ[s]], tab]

tab2 = 
      Flatten[Table[{i, j}, {i, 1, 5}, {j, -1, -5, -1}], 1]

Map[Function[s, Reverse[s]], tab2]

Higher Order Functions: "MapThread"

tab3 = Transpose[tab2]

MapThread[Function[{s, t}, {s, t, s^2 + t^2}], tab3]

MapThread[Plus, {{1, 2}, {2, 3}, {3, 4}}]

Higher Order Functions: "Inner" and "Outer"

Inner[Times, {1, 2}, {3, 4}, Plus]

Inner[Plus, {1, 2}, {3, 4}, List]

Inner[Function[{s, t}, Sqrt[s + t]], {1, 2}, {3, 4}, Plus]

Outer[List, {1, 2, 3}, {4, 5, 6}]

Outer[Function[{s, t}, PrimeQ[s + t]], {1, 2, 3}, {4, 5, 6}]

Higher Order Functions: "Apply"

tab = Table[i, {i, 1, 5}]

FullForm[%]

Apply[Times, tab]

Higher Order Functions: "Nest"

Nest[f, x, 2]

Nest[Function[s, s^2], 2, 3]

NestList[Function[s, s^2], 2, 3]

NestList[Cos, 1., 30]

NestList[Sqrt, 1000., 35]

Higher Order Functions: "Fold"

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

Fold[Plus, 0, {1, 2, 4, 6}]

FoldList[Plus, 0, {1, 2, 4, 6}]

Etc

Helmut Knaust, email: helmut@math.utep.edu. Created 3-1-1999.