1 | initial version |
"Why do stuff in symbolics", I agree with ppurka, and I suggest:
def sumfact (k, n, t):
return sum (factorial (3-i) * k^i * t^i for i in range (n+1))
which uses the built-in Python function sum.
2 | No.2 Revision |
"Why do stuff in symbolics", I agree with ppurka, and I suggest:
def sumfact (k, n, t):
return sum (factorial (3-i) (n-i) * k^i * t^i for i in range (n+1))
which uses the built-in Python function sum.
[edit] After precisions added by 'stan', I'm puzzled, Sage gives me the expected answers:
sage: var ('i k t')
sage: for n in range (5):
... print sum (factorial(n-i)*k^i*t^i, i, 0, n)
1
k*t + 1
k^2*t^2 + k*t + 2
k^3*t^3 + k^2*t^2 + 2*k*t + 6
k^4*t^4 + k^3*t^3 + 2*k^2*t^2 + 6*k*t + 24
3 | No.3 Revision |
"Why do stuff in symbolics", I agree with ppurka, and I suggest:
def sumfact (k, n, t):
return sum (factorial (n-i) * k^i * t^i for i in range (n+1))
which uses the built-in Python function sum.
[edit] After precisions added by 'stan', I'm puzzled, Sage gives me the (not very surprising) expected answers:
sage: var ('i k t')
sage: for n in range (5):
... print sum (factorial(n-i)*k^i*t^i, i, 0, n)
1
k*t + 1
k^2*t^2 + k*t + 2
k^3*t^3 + k^2*t^2 + 2*k*t + 6
k^4*t^4 + k^3*t^3 + 2*k^2*t^2 + 6*k*t + 24
4 | No.4 Revision |
"Why do stuff in symbolics", I agree with ppurka, and I suggest:
def sumfact (k, n, t):
return sum (factorial (n-i) * k^i * t^i for i in range (n+1))
which uses the built-in Python function sum.
[edit] After precisions added by 'stan', I'm puzzled, Sage gives me the (not very surprising) expected answers:
sage: var ('i k t')
sage: for n in range (5):
... print sum (factorial(n-i)*k^i*t^i, i, 0, n)
1
k*t + 1
k^2*t^2 + k*t + 2
k^3*t^3 + k^2*t^2 + 2*k*t + 6
k^4*t^4 + k^3*t^3 + 2*k^2*t^2 + 6*k*t + 24
Answer to [EDIT2]: now I understand the original question :-S
sage: var ('i k n t')
sage: sum(factorial(n-i)*k^i*t^i, i, 0, n)
sum(k^i*t^i*factorial(-i + n), i, 0, n)
Sage doesn't know anything about this formal sum, and keeps it as is; substitution "n=3" is then performed on this object, as required:
sage: sum(factorial(n-i)*k^i*t^i, i, 0, n)(n=3)
sum(k^i*t^i*factorial(-i + 3), i, 0, 3)
Symbolic sums are most useful when there is a formula "known by" Sage:
sage: sum(binomial(n,k),k,0,n)
2^n
sage: sum(binomial(n,k),k,0,n)(n=3)
8
5 | Separate answer |
"Why do stuff in symbolics", I agree with ppurka, and I suggest:
def sumfact (k, n, t):
return sum (factorial (n-i) * k^i * t^i for i in range (n+1))
which uses the built-in Python function sum.
[edit] After precisions added by 'stan', I'm puzzled, Sage gives me the (not very surprising) expected answers:
sage: var ('i k t')
sage: for n in range (5):
... print sum (factorial(n-i)*k^i*t^i, i, 0, n)
1
k*t + 1
k^2*t^2 + k*t + 2
k^3*t^3 + k^2*t^2 + 2*k*t + 6
k^4*t^4 + k^3*t^3 + 2*k^2*t^2 + 6*k*t + 24
Answer to [EDIT2]: now I understand the original question :-S
sage: var ('i k n t')
sage: sum(factorial(n-i)*k^i*t^i, i, 0, n)
sum(k^i*t^i*factorial(-i + n), i, 0, n)
Sage doesn't know anything about this formal sum, and keeps it as is; substitution "n=3" is then performed on this object, as required:
sage: sum(factorial(n-i)*k^i*t^i, i, 0, n)(n=3)
sum(k^i*t^i*factorial(-i + 3), i, 0, 3)
Symbolic sums are most useful when there is a formula "known by" Sage:
sage: sum(binomial(n,k),k,0,n)
2^n
sage: sum(binomial(n,k),k,0,n)(n=3)
8