def poly_monic(poly, gf):
    """Return a monic version of the polynomial poly."""
    # Multiply every coefficient with the inverse of the top coefficient.
    inv = gf.inv(poly[-1])
    return [gf.mul(inv, v) for v in poly]