# Euler Numbers A000295 And Basic MMA Code

When I run this snippet in MMA

Map[Fold[Plus[#, ##] &, {0}, Range[#]] &, Range[8]]
(* {{1}, {4}, {11}, {26}, {57}, {120}, {247}, {502}} *)

(* or *)
Map[Fold[Plus[##, #] &, {0}, Range[#]] &, Range[8]]


These are: from OEIS: A000295 Eulerian numbers (Euler's triangle: column k=2 of A008292, column k=1 of A173018).

Obviously, the function calls, of #1 & ## (all the rest) &; must be duplicating a pattern of:

Table[2^n - n - 1, {n, 20}]


Mr. Weisstein on the same OEIS page.

Why is this? Is it fundamental to MMA & it's pure functions approach?

• Would it help you understand if I rewrote the first snippet as Map[Fold[Plus[#1, #1, #2] &, {0}, Range[#]] &, Range[8]]? May 23, 2020 at 17:34
• If I try Map[Fold[Plus[#1,#1,#2+1]&,{0},Range[#]]&,Range[5]] this makes A095151. Another triangle sequence, part of Bells Triangle. I think, I get it. It is just all about repetition/recursion? May 23, 2020 at 17:41
• Or another form: Map[Fold[Plus[#1, #2, #2] &, {0}, Range[#]] &, Range[10]] (1) A002378 Oblong (or promic, pronic, or heteromecic) numbers: a(n) = n*(n+1), (2) Denominators in Harmonic Triangle. (3) A103505 Denominator in expansion of (1-x)*Log[1-x]. May 23, 2020 at 17:48
• Series expansion of: f[x_] := (1 - x)*Log[1 - x]; Series[g[x], {x, 0, 10}] produces: {2, 6, 12, 20, 30, 42, .. } as denominators. Interesting. May 23, 2020 at 17:55
• In fact, in the current version, you could omit the {0}, so: Map[Fold[Plus[#1, #1, #2] &, Range[#]] &, Range[8]]. Your last one can also be done as Map[Fold[Plus[#2, ##] &, 0, Range[#]] &, Range[10]]. In any case, please look up # and ## in the docs. May 23, 2020 at 17:56

Map[FoldList[Plus[#, ##] &, {0}, Range[#]] &, Range[8]] // ColumnForm
(* Out
{
{{{0}, {1}}},
{{{0}, {1}, {4}}},
{{{0}, {1}, {4}, {11}}},
{{{0}, {1}, {4}, {11}, {26}}},
{{{0}, {1}, {4}, {11}, {26}, {57}}}
} *)

• This result is correct, but I am not sure that it answers the question. May 24, 2020 at 1:46
• The differences are the Mersenne numbers A000225. Good enough for me. May 24, 2020 at 17:48
• Looking at: Map[FoldList[Plus[#1, #1, #2] &, {0}, Range[#]] &, {3}] // Trace Dec 3, 2021 at 22:57