def gf_compose_mod(g, h, f, p, K):
 if (not g):
  return []
 comp = [g[0]]
 for a in g[1:]:
  comp = gf_mul(comp, h, p, K)
  comp = gf_add_ground(comp, a, p, K)
  comp = gf_rem(comp, f, p, K)
 return comp

def gf_compose_mod ( g , h , f , p , K ) : if ( not g ) : return [ ] comp = [ g [ 0 ] ] for a in g [ 1 : ] : comp = gf_mul ( comp , h , p , K ) comp = gf_add_ground ( comp , a , p , K ) comp = gf_rem ( comp , f , p , K ) return comp
compute polynomial composition g(h) in gf(p)[x]/(f) .