def shanks(A, k, n, m=1):
 table = [A.subs(k, Integer(j)).doit() for j in range(((n + m) + 2))]
 table2 = table[:]
 for i in range(1, (m + 1)):
  for j in range(i, ((n + m) + 1)):
   (x, y, z) = (table[(j - 1)], table[j], table[(j + 1)])
   table2[j] = (((z * x) - (y ** 2)) / ((z + x) - (2 * y)))
  table = table2[:]
 return table[n]

def shanks ( A , k , n , m = 1 ) : table = [ A . subs ( k , Integer ( j ) ) . doit ( ) for j in range ( ( ( n + m ) + 2 ) ) ] table2 = table [ : ] for i in range ( 1 , ( m + 1 ) ) : for j in range ( i , ( ( n + m ) + 1 ) ) : ( x , y , z ) = ( table [ ( j - 1 ) ] , table [ j ] , table [ ( j + 1 ) ] ) table2 [ j ] = ( ( ( z * x ) - ( y ** 2 ) ) / ( ( z + x ) - ( 2 * y ) ) ) table = table2 [ : ] return table [ n ]
calculate an approximation for lim k->oo a(k) using the n-term shanks transformation s(a)(n) .