def METHOD_NAME(f, *gens, **args):
    """
    Rewrite a polynomial in Horner form.
    Among other applications, evaluation of a polynomial at a point is optimal
    when it is applied using the Horner scheme.
    Examples
    ========
    >>> from diofant.abc import e
    >>> horner(9*x**4 + 8*x**3 + 7*x**2 + 6*x + 5)
    x*(x*(x*(9*x + 8) + 7) + 6) + 5
    >>> horner(a*x**4 + b*x**3 + c*x**2 + d*x + e)
    e + x*(d + x*(c + x*(a*x + b)))
    >>> f = 4*x**2*y**2 + 2*x**2*y + 2*x*y**2 + x*y
    >>> horner(f, wrt=x)
    x*(x*y*(4*y + 2) + y*(2*y + 1))
    >>> horner(f, wrt=y)
    y*(x*y*(4*x + 2) + x*(2*x + 1))
    References
    ==========
    * https://en.wikipedia.org/wiki/Horner_scheme
    """
    allowed_flags(args, [])
    try:
        (F,), _ = parallel_poly_from_expr((f,), *gens, **args)
    except PolificationFailedError as exc:
        return exc.exprs[0]
    form, gen = Integer(0), F.gen
    if F.is_univariate:
        for coeff in reversed(F.all_coeffs()):
            form = form*gen + coeff
    else:
        F, gens = Poly(F, gen), gens[1:]
        for coeff in reversed(F.all_coeffs()):
            form = form*gen + METHOD_NAME(coeff, *gens, **args)
    return form