Mapping, Pure Functions

Map[f,exp]

Map[f,g[exp]]

Map[f,g[arg1,arg2]]

Map[f,{a,b,exp3,Pi, fun[45]}]

List[a,b,exp3,Pi, fun[45]]

Times[exp1,ghj,Pi,4+3I]

Times[exp1,ghj,Pi,4+3I]//TreeForm

Map[f,Times[exp1,ghj,Pi,4+3I]]//TreeForm

Map[f,{{a,b},{Pi,3,3.3},{x+y}}]

{{a,b},{Pi,3,3.3},{x+y}}//TreeForm

Map[f,{{a,b},{Pi,3,3.3},{x+y}},{2}]

Map[f,{{a,b},{Pi,3,3.3},{x+y}},{3}]

Map[f,{{a,b},{Pi,3,3.3},{x+y}},{2,3}]

{{a,b},{Pi,3,3.3},{x+y}}//Depth

Map[f,{{a,b},{Pi,3,3.3},{x+y}},{4}]

Map[f,{{a,b},{Pi,3,3.3},{x+y}},{-1}]//TreeForm

Map[f,{exp},{0}]==f[{exp}]==f@{exp}==({exp}//f)

l=RandomInteger[{10^3,10^4},20]

w:=RandomInteger[{10^3,10^4},20]

PrimeQ[17]

Map[PrimeQ,l]

isPrime[n_]:={n,PrimeQ[n]}

Map[isPrime,l]

myPrime[n_]/;PrimeQ[n]:=n

myPrime[n_]:=False

Map[myPrime,l]

Pure, Anonymous, Lambda functions

#&   (* identity function *)

#^2-3&[Pi]

Map[{PrimeQ[#],#}&,l]

{PrimeQ[#],#}&/@l

Map[f,l]

Apply[f,l]

l//TreeForm

f@@l

Join[{##},Reverse[{##}]]&[1,2,3]

Transpose[Join[{{##}},{Reverse[{##}]}]]&[1,2,3]

#1^2+#2&[5,Pi]

Map[#^3-2#^2+4&,l]

l

f[x_]:=Sin[x Cos[2. x]]

Map[Point[{#/3000,f[#]}]&,l]//Graphics//Show

Function[{arg},arg^2-arg^3][Pi/3]

Plot3D[
Function[{arg1,arg2},arg1^2+arg2^3][x,y],
{x,-1,1},{y,-2,1}]

l

Mod[187,17]==0

Map[{#,Mod[#,17]==0}&,l]

Integrate[(1-x^2)/x^2,{x,1,#}]&

lF={Sin,Exp, #^2+#&,Integrate[(1-x^2)/x^2,{x,1,#}]&}

Map[lF,Pi]

Map[Pi,lF]

Map[myF,lF]

Map[#[Pi]&,lF]

Map[#@Pi&,lF]

#@Pi&/@lF

lF

lP=RandomReal[{0,2},{4}]

{lF[[1]][lP[[1]]],lF[[2]][lP[[2]]], ...}

Map[#1[#2]&,{lF,lP}]

{lF,lP}

{lF,lP}//Transpose

Map[myF,Transpose[{lF,lP}]]

Map[#[[1]][#[[2]]]&,Transpose[{lF,lP}]]

Map[#[[1]]@#[[2]]&,Transpose[{lF,lP}]]

MapThread[myF,{lF,lP}]

MapThread[#1[#2]&,{lF,lP}]

l={{1,2,3,4,5},{10,20,30,40,50},{100,200,300,400,500},{0.01,0.02,0.03,0.04,5000},{0.1,0.2,0.3,0.4,0.5}};

l//MatrixForm

Sin[#^2-3]&

Map[myF,l]

MapIndexed[myF,l]

MapIndexed[
Sin[#1[[#2[[1]]]]^2-3]&,
l]

Sin[#^2-3]&[1]
Sin[#^2-3]&[20]
Sin[#^2-3]&[.5]

Map[
{#[[1]][#[[1]][#[[2]]]]}&,
{{#^2-1&,2},{(#-1)(#+1)&,-2}}
]

Palyndromes

exp[1]={1,2,3,a,b,a,3,2,1};
exp[2]={1,2,3,a,a,3,2,1};
exp[3]={1,2,3,a,b,b,3,2,1};

Array[exp,3]

Clear[paly]

paly[x_]:=x===Reverse[x]

Map[paly,Array[exp,3]]

Clear[paly]

paly[{x_,m___,x_}]:=paly[{m}]

paly[x_]:=Length[x]≤1

Map[paly,Array[exp,3]]

Clear[paly]

paly[{x_,m___,x_}]:=paly[{m}]

paly[{_}]:=True

paly[{}]:=True

paly[_]:=False

Map[paly,Array[exp,3]]