def dmp_pow(f, n, u, K):
 if (not u):
  return dup_pow(f, n, K)
 if (not n):
  return dmp_one(u, K)
 if (n < 0):
  raise ValueError("can't raise polynomial to a negative power")
 if ((n == 1) or dmp_zero_p(f, u) or dmp_one_p(f, u, K)):
  return f
 g = dmp_one(u, K)
 while True:
  (n, m) = ((n // 2), n)
  if (m & 1):
   g = dmp_mul(g, f, u, K)
   if (not n):
    break
  f = dmp_sqr(f, u, K)
 return g

def dmp_pow ( f , n , u , K ) : if ( not u ) : return dup_pow ( f , n , K ) if ( not n ) : return dmp_one ( u , K ) if ( n < 0 ) : raise ValueError ( "can't raise polynomial to a negative power" ) if ( ( n == 1 ) or dmp_zero_p ( f , u ) or dmp_one_p ( f , u , K ) ) : return f g = dmp_one ( u , K ) while True : ( n , m ) = ( ( n // 2 ) , n ) if ( m & 1 ) : g = dmp_mul ( g , f , u , K ) if ( not n ) : break f = dmp_sqr ( f , u , K ) return g
raise f to the n-th power in k[x] .