Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
0

How to compute an iterated product in Sage

asked 11 years ago

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: i=1(n+kk) So for i=2, this would look like (n+k1k)(n+k2k). Would I use a for loop to iteratively add to the product until all i terms were accounted for?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
3

answered 11 years ago

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)
Preview: (hide)
link

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: 11 years ago

Seen: 4,829 times

Last updated: Jun 10 '13