Mathematica Asked on December 6, 2020
I want to understand the mathematca formula A282720
The description says
Number of nonzero terms in first n rows of the base-2 generalized Pascal triangle P_2
(But the Pascal Triangle has only nonzero terms, so the description makes nonsense).
His purpose is to generate the series:
0, 1, 3, 6, 9, 13, 18, 23, 27, 32, 39, 47, 54, 61, 69, 76, 81, 87, 96, 107, 117, 128, 141, 153, 162, 171, 183, 196, 207, 217, 228, 237, 243, 250, 261, 275, 288, 303, 321, 338, 351, 365, 384, 405, 423, 440, 459, 475, 486, 497, 513, 532, 549, 567
The Mathematica formula (on the same link) is:
Accumulate@ Prepend[Array[Sum[Mod[Binomial[# + k - 1, 2 k], 2], {k, 0, #}] &, 53], 0]
I’m not a Mathematica programmer, and don’t understand what the formula means.
Can you translate it as an equation, or pseudocode?
I think that I understand the functions
Sum[Mod[Binomial
But I don’t know what the #
and &
symbols means
Also Prepend[Array
doesn’t makes sense to me
Accumulate@
I guess, means that the result is series that is a progressive accumulation of terms
Sum[Mod[Binomial[# + k - 1, 2 k], 2], {k, 0, #}] &
&
indicates that this is a function. #
is the argument of the function. I transcribed it into mathematical notation for you, using $n$ instead of #
.
$$ f(n) = sum_{k=0}^n left[ binom{n+k-1}{2k} bmod 2 right] $$
Array[..., 53]
This basically creates the sequence of numbers $$ bigl( f(1), f(2), dots, f(53) bigr) $$
Prepend[..., 0]
prepends a 0 to the sequence, so now we have $$ bigl(0, f(1), f(2), dots, f(53) bigr) $$
For the sake of simplicity, from here on I'll assume $f(0) = 0$, even though that is not consistent with the formula.
Accumulate
computes partial sums, so the final result is
$$
g(n) = sum_{i=0}^n f(i)
$$
We can convert the above back to Mathematica code that follows the formulas more closely:
f[n_] := Sum[Mod[Binomial[n + k - 1, 2 k], 2], {k, 0, n}]
f[0] := 0
Accumulate[ Table[f[n], {n, 0, 53}] ]
Correct answer by Szabolcs on December 6, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP