Overview
Consider the inbuilt Wolfram Mathematica functions of Map, Table, and For. Each can be used to execute an expression sequentially over a dataset. The strict definitions of each lies below.
Map
Map
Map is described in the Wolfram Mathematica references as follows.
In[]:=
?Map
Out[]=
Table
Table
Table is described in the Wolfram Mathematica references as follows.
In[]:=
?Table
Out[]=
For
For
For is described in the Wolfram Mathematica references as follows.
In[]:=
?For
Out[]=
Basic Systematic Comparison
Most basic definitions
For a basic comparison, and the simplest chart, we will consider the most general definitions of Map, Table, and For.
That is,
That is,
◼
Map
Map[f, expr] or f /@ expr applies f to each element on the first level in expr
◼
Table
Table[expr, n] generates a list of n copies of expr.
◼
For
For[ start, test, incr, body] executes start, then repeatedly evaluates body and incr until test fails to give True
Chart
In[]:=
Clear[mapAssociation,tableAssociation,forAssociation];mapAssociation=Association["Name"->"Map","Arguments"->"function, expression","Output Format"->"Format of the expression, TypeOf[expr]","Calculation performed _N_ times"->"_N_ is size of expression"];tableAssociation=Association["Name"->"Table","Arguments"->"expression, n","Output Format"->"List of size n","Calculation performed _N_ times"->"_N_ is n"];forAssociation=Association["Name"->"For","Arguments"->"start, test, increment, body","Output Format"->"Null. Only executes unless body returns","Calculation performed _N_ times"->"_N_ is determined by start, test, & increment"];contents=Dataset[{mapAssociation,tableAssociation,forAssociation}];contents[[All,{1,2,3}]]contents[[All,{1,4}]]
Out[]=
Out[]=
Further Thoughts
All of the functions examined, Map, Table, and For, can apply a set of operations repeatedly over a dataset.
If one wishes to apply a function to an existing dataset, Map would work well.
If one wishes to evaluate an expression n times, Table works well.
If one wishes to perform a set of operations repeatedly until a certain set of stopping conditions is met, For loops work well.
If one wishes to apply a function to an existing dataset, Map would work well.
If one wishes to evaluate an expression n times, Table works well.
If one wishes to perform a set of operations repeatedly until a certain set of stopping conditions is met, For loops work well.