def dup_revert(f, n, K):
 g = [K.revert(dup_TC(f, K))]
 h = [K.one, K.zero, K.zero]
 N = int(_ceil(_log(n, 2)))
 for i in range(1, (N + 1)):
  a = dup_mul_ground(g, K(2), K)
  b = dup_mul(f, dup_sqr(g, K), K)
  g = dup_rem(dup_sub(a, b, K), h, K)
  h = dup_lshift(h, dup_degree(h), K)
 return g

def dup_revert ( f , n , K ) : g = [ K . revert ( dup_TC ( f , K ) ) ] h = [ K . one , K . zero , K . zero ] N = int ( _ceil ( _log ( n , 2 ) ) ) for i in range ( 1 , ( N + 1 ) ) : a = dup_mul_ground ( g , K ( 2 ) , K ) b = dup_mul ( f , dup_sqr ( g , K ) , K ) g = dup_rem ( dup_sub ( a , b , K ) , h , K ) h = dup_lshift ( h , dup_degree ( h ) , K ) return g
compute f** mod x**n using newton iteration .