def dup_gegenbauer(n, a, K):
 seq = [[K.one], [(K(2) * a), K.zero]]
 for i in range(2, (n + 1)):
  f1 = ((K(2) * ((i + a) - K.one)) / i)
  f2 = (((i + (K(2) * a)) - K(2)) / i)
  p1 = dup_mul_ground(dup_lshift(seq[(-1)], 1, K), f1, K)
  p2 = dup_mul_ground(seq[(-2)], f2, K)
  seq.append(dup_sub(p1, p2, K))
 return seq[n]

def dup_gegenbauer ( n , a , K ) : seq = [ [ K . one ] , [ ( K ( 2 ) * a ) , K . zero ] ] for i in range ( 2 , ( n + 1 ) ) : f1 = ( ( K ( 2 ) * ( ( i + a ) - K . one ) ) / i ) f2 = ( ( ( i + ( K ( 2 ) * a ) ) - K ( 2 ) ) / i ) p1 = dup_mul_ground ( dup_lshift ( seq [ ( - 1 ) ] , 1 , K ) , f1 , K ) p2 = dup_mul_ground ( seq [ ( - 2 ) ] , f2 , K ) seq . append ( dup_sub ( p1 , p2 , K ) ) return seq [ n ]
low-level implementation of gegenbauer polynomials .