Ask Your Question

# How to compute an iterated product in Sage

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 close merge delete

## 1 Answer

Sort by » oldest newest most voted

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)
75


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)

more

## Your Answer

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

Add Answer

## Stats

Asked: 2013-06-10 17:58:24 +0200

Seen: 2,405 times

Last updated: Jun 10 '13