def richardson(A, k, n, N):
 s = S.Zero
 for j in range(0, (N + 1)):
  s += (((A.subs(k, Integer((n + j))).doit() * ((n + j) ** N)) * ((-1) ** (j + N))) / (factorial(j) * factorial((N - j))))
 return s

def richardson ( A , k , n , N ) : s = S . Zero for j in range ( 0 , ( N + 1 ) ) : s += ( ( ( A . subs ( k , Integer ( ( n + j ) ) ) . doit ( ) * ( ( n + j ) ** N ) ) * ( ( - 1 ) ** ( j + N ) ) ) / ( factorial ( j ) * factorial ( ( N - j ) ) ) ) return s
calculate an approximation for lim k->oo a(k) using richardson extrapolation with the terms a(n) .