Notes

Chapter 11: The Notion of Computation

Section 3: The Phenomenon of Universality


Universality in Mathematica

As an example of how different primitive operations can be used to do the same computation, the following are a few ways that the factorial function can be defined in Mathematica:

f[n_] := n!
f[n_] := n f[n-1] ; f[1] = 1
f[n_] := Product[i, {i, n}]
f[n_] := Module[{t = 1}, Do[t = t*i, {i, n}]; t]
f[n_] := Module[{t = 1, i}, For[i =1, i <=n, i++, t *= i]; t]
f[n_] := Apply[Times, Range[n]]
f[n_] := Fold[Times, 1, Range[n]]
f[n_] := If[n == 1, 1, n f[n-1]]
f[n_] := Fold[#2[#1]&, 1, Array[Function[t, # t]&, n]]
f = If[#1 == 1, 1, #1 #0[#1 - 1]]&


From Stephen Wolfram: A New Kind of Science [citation]