| 1 | initial version |
Since the sum bounds are not symbolic variables but given integers, it's better to avoid using the symbolic sum(<expr>,k,2,p) but rather use Python's sum(<expr> for k in (2..p)):
n=var('n')
assume(n,'integer')
def S(p):
if p==1:
return n*(n+1)/2
return ((n+1)^(p+1) - n - 1 - sum(binomial(p+1,k)*S(p-k+1) for k in (2..p)))/(p+1)
As a side note - you don't need to define k and p as symbolic variables, since p will have specific numerical value as an argument of function S(p), while k will be the sum index and automatically defined as a local variable.
| 2 | No.2 Revision |
Since the sum bounds are not symbolic variables but given integers, it's better to avoid using the symbolic sum(<expr>,k,2,p) but rather use Python's sum(<expr> for k in (2..p)):
n=var('n')
assume(n,'integer')
def S(p):
if p==1:
return n*(n+1)/2
return ((n+1)^(p+1) - n - 1 - sum(binomial(p+1,k)*S(p-k+1) for k in (2..p)))/(p+1)
As a side note - you don't need to define k and p as global symbolic variables, since p will have specific numerical value is defined as an argument of function S(p), while k will be is the sum index and automatically defined as a local variable.
| 3 | No.3 Revision |
Since the sum bounds are not symbolic variables but given integers, it's better to avoid using the symbolic sum(<expr>,k,2,p) but rather use Python's sum(<expr> for k in (2..p)):
n=var('n')
assume(n,'integer')
def S(p):
if p==1:
return n*(n+1)/2
return ((n+1)^(p+1) - n - 1 - sum(binomial(p+1,k)*S(p-k+1) for k in (2..p)))/(p+1)
As a side note - you don't need to define k and p as global symbolic variables, since p is defined as an argument of function S(p), while k is the sum index and automatically defined as a local variable.variable within the sum context.
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.