@public
def horner(f, *gens, **args):
 allowed_flags(args, [])
 try:
  (F, opt) = poly_from_expr(f, *gens, **args)
 except PolificationFailed as exc:
  return exc.expr
 (form, gen) = (S.Zero, F.gen)
 if F.is_univariate:
  for coeff in F.all_coeffs():
   form = ((form * gen) + coeff)
 else:
  (F, gens) = (Poly(F, gen), gens[1:])
  for coeff in F.all_coeffs():
   form = ((form * gen) + horner(coeff, *gens, **args))
 return form

@ public def horner ( f , * gens , ** args ) : allowed_flags ( args , [ ] ) try : ( F , opt ) = poly_from_expr ( f , * gens , ** args ) except PolificationFailed as exc : return exc . expr ( form , gen ) = ( S . Zero , F . gen ) if F . is_univariate : for coeff in F . all_coeffs ( ) : form = ( ( form * gen ) + coeff ) else : ( F , gens ) = ( Poly ( F , gen ) , gens [ 1 : ] ) for coeff in F . all_coeffs ( ) : form = ( ( form * gen ) + horner ( coeff , * gens , ** args ) ) return form
rewrite a polynomial in horner form .