There is no closed formula for the given sum
∑1≤k≤nk2⋅k! .
(At least i cannot see any at the first glance.) As in the comment i committed some seconds in advance, the implemented algorithm works for
∑1≤k≤nP(k)⋅k! .
iff the polynomial P that appears is in the linear span of the polynomials:
- P1=(k+1)−1 ,
- P2=(k+2)(k+1)−1 ,
- P3=(k+3)(k+2)(k+1)−1 ,
- P4=(k+4)(k+3)(k+2)(k+1)−1 and so on.
(They all satisfy the necessary condition P(−1)=−1.)
But P(k)=k2 is not in this span. Instead, k2+1=P2−3P1 is.
So the following works for some simple polynomials in the span:
sage: for P in ( k, k^2+1, k^3-1 ):
....: print ( "P = %-7s and sum( P(k).k! for k=1..n ) is %s"
....: % ( P, sum( P*factorial(k), k, 1, n ) ) )
....:
P = k and sum( P(k).k! for k=1..n ) is factorial(n + 1) - 1
P = k^2 + 1 and sum( P(k).k! for k=1..n ) is n*factorial(n + 1)
P = k^3 - 1 and sum( P(k).k! for k=1..n ) is (n^2 - 2)*factorial(n + 1) + 2
Bonus: (Out of scope. Please ignore if annoying.)
Let us do the job completely in LATEX for polynomials of the shape kpower+constant:
Code:
D = 9 # stop at this dimension of vector space to be used
R.<x> = QQ[]
L = [ R(1), ] + [ prod( x+j for j in [1..k] ) - 1 for k in [1..D-1] ]
L = [ p.coefficients( sparse=0 ) for p in L ]
L = [ p+[ QQ(0) for _ in range(D-len(p)) ] for p in L ]
V = (QQ^D) . span_of_basis( L )
for kk in [1..D-1]:
v = vector( QQ, [ j==kk for j in [0..D-1] ] )
print "%s -> %s" % ( v, V.coordinate_vector(v) )
# and now for the problem
import re
var( 'k,n' );
for kk in [1..D-1]:
v = vector( QQ, [ j==kk for j in [0..D-1] ] )
c = V.coordinate_vector(v)[0]
P = k^kk - c
print ( r" - $ P = %s$ and $\sum_1^n P\cdot k! = %s$"
% ( P, re.sub( r'\\,', '', latex( sum( P*factorial(k), k, 1, n ) ) ) ) )
Relevant results are now copy+pasted here:
- P=k and ∑n1P⋅k!=(n+1)!−1
- P=k2+1 and ∑n1P⋅k!=n(n+1)!
- P=k3−1 and ∑n1P⋅k!=(n2−2)(n+1)!+2
- P=k4−2 and ∑n1P⋅k!=(n3−3n+3)(n+1)!−3
- P=k5+9 and ∑n1P⋅k!=(n4−4n2+6n+4)(n+1)!−4
- P=k6−9 and ∑n1P⋅k!=(n5−5n3+10n2+5n−30)(n+1)!+30
- P=k7−50 and ∑n1P⋅k!=(n6−6n4+15n3+4n2−66n+55)(n+1)!−55
- P=k8+267 and ∑n1P⋅k!=(n7−7n5+21n4−119n2+175n+126)(n+1)!−126
All above results are computed and displayed via sage
.
Note that the following works:
Now somebody has to implement the trick also for all sums of the shape ∑1≤k≤nP(k)⋅k! with an arbitrary polynomial P. (Well,
simplify_factorial
did not help...)