1 | initial version |
There is no closed formula for the given sum $$ \sum_{1\le k\le n} k^2\cdot 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 $$ \sum_{1\le k\le n} P(k)\cdot k!\ . $$ iff the polynomial $P$ that appears is in the linear span of the polynomials:
(They all satisfy the necessary condition $P(-1)=-1$.)
But $P(k)=k^2$ is not in this span. Instead, $k^2+1=P_2-3P_1$ 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 $k^{power}+$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:
All above results are computed and displayed via sage
.