2
$\begingroup$

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?

$\endgroup$
7
  • 3
    $\begingroup$ Would it help you understand if I rewrote the first snippet as Map[Fold[Plus[#1, #1, #2] &, {0}, Range[#]] &, Range[8]]? $\endgroup$ May 23, 2020 at 17:34
  • $\begingroup$ 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? $\endgroup$
    – prog9910
    May 23, 2020 at 17:41
  • $\begingroup$ 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]. $\endgroup$
    – prog9910
    May 23, 2020 at 17:48
  • $\begingroup$ 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. $\endgroup$
    – prog9910
    May 23, 2020 at 17:55
  • $\begingroup$ 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. $\endgroup$ May 23, 2020 at 17:56

1 Answer 1

0
$\begingroup$
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}}}
} *)
$\endgroup$
3
  • $\begingroup$ This result is correct, but I am not sure that it answers the question. $\endgroup$
    – bbgodfrey
    May 24, 2020 at 1:46
  • $\begingroup$ The differences are the Mersenne numbers A000225. Good enough for me. $\endgroup$
    – prog9910
    May 24, 2020 at 17:48
  • $\begingroup$ Looking at: Map[FoldList[Plus[#1, #1, #2] &, {0}, Range[#]] &, {3}] // Trace $\endgroup$
    – prog9910
    Dec 3, 2021 at 22:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.