Ask Your Question

How to compute an iterated product in Sage

asked 2013-06-10 10:58:24 -0500

JoshIzzard gravatar image

I am wondering about how to define a function f(n, k, i) that will take inputs n, k, i and give me the following product: $$ \prod_{\ell = 1}^i {n + k - \ell \choose k} $$ So for $i = 2$, this would look like ${n + k - 1 \choose k}\cdot {n + k - 2 \choose k}$. Would I use a for loop to iteratively add to the product until all i terms were accounted for?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-06-10 11:39:06 -0500

tmonteil gravatar image

You can use the prod() function (see prod? for some help):

sage: f = lambda n, k, i : prod([binomial(n+k-l,k) for l in range(1,i+1)])
sage: f(3,4,2)

This also works symbolically:

sage: var('n,k')
(n, k)
sage: f(n,k,2)  
binomial(k + n - 2, k)*binomial(k + n - 1, k)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-06-10 10:58:24 -0500

Seen: 342 times

Last updated: Jun 10 '13