ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 25 Jul 2013 11:39:33 +0200Binomial in a Summationhttps://ask.sagemath.org/question/10384/binomial-in-a-summation/sage: var('k')
k
sage: sum(binomial(5,k),k,0,5)
I get an error "cannot convert k to int"
But if instead I try something like sum(binomial(n,k),k,0,n), everything is just fine.
Anyone know how I can get around this?Thu, 25 Jul 2013 10:28:29 +0200https://ask.sagemath.org/question/10384/binomial-in-a-summation/Answer by calc314 for <p>sage: var('k')</p>
<p>k</p>
<p>sage: sum(binomial(5,k),k,0,5)</p>
<p>I get an error "cannot convert k to int"</p>
<p>But if instead I try something like sum(binomial(n,k),k,0,n), everything is just fine.</p>
<p>Anyone know how I can get around this?</p>
https://ask.sagemath.org/question/10384/binomial-in-a-summation/?answer=15277#post-id-15277Sum is working only in a symbolic ring. So you can convert your integers to the symbolic ring as follows:
sum(binomial(SR(5),k),k,0,SR(5))
You can also use the `add` command:
add([binomial(5,k) for k in [0..5]])
Thu, 25 Jul 2013 11:39:33 +0200https://ask.sagemath.org/question/10384/binomial-in-a-summation/?answer=15277#post-id-15277