Ask Your Question
0

How to compute an iterated product in Sage

asked 2013-06-10 17:58:24 +0100

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
3

answered 2013-06-10 18:39:06 +0100

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

Stats

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

Seen: 4,607 times

Last updated: Jun 10 '13