evaluate a polynomial fx at specified point x and return the value arguments poly the coefficients of a polynomial as an iterable in order of ascending degree x the point at which to evaluate the polynomial evaluatepoly0 0 0 0 5 0 9 3 7 0 10 0 79800 0 evaluate a polynomial at specified point using horner s method in terms of computational complexity horner s method is an efficient method of evaluating a polynomial it avoids the use of expensive exponentiation and instead uses only multiplication and addition to evaluate the polynomial in on where n is the degree of the polynomial https en wikipedia orgwikihorner smethod arguments poly the coefficients of a polynomial as an iterable in order of ascending degree x the point at which to evaluate the polynomial horner0 0 0 0 5 0 9 3 7 0 10 0 79800 0 example poly 0 0 0 0 5 0 9 3 7 0 fx 7 0x4 9 3x3 5 0x2 x 13 0 f13 7 0134 9 3133 5 0132 180339 9 evaluatepolypoly x 180339 9 evaluate a polynomial f x at specified point x and return the value arguments poly the coefficients of a polynomial as an iterable in order of ascending degree x the point at which to evaluate the polynomial evaluate_poly 0 0 0 0 5 0 9 3 7 0 10 0 79800 0 evaluate a polynomial at specified point using horner s method in terms of computational complexity horner s method is an efficient method of evaluating a polynomial it avoids the use of expensive exponentiation and instead uses only multiplication and addition to evaluate the polynomial in o n where n is the degree of the polynomial https en wikipedia org wiki horner s_method arguments poly the coefficients of a polynomial as an iterable in order of ascending degree x the point at which to evaluate the polynomial horner 0 0 0 0 5 0 9 3 7 0 10 0 79800 0 example poly 0 0 0 0 5 0 9 3 7 0 f x 7 0x 4 9 3x 3 5 0x 2 x 13 0 f 13 7 0 13 4 9 3 13 3 5 0 13 2 180339 9 evaluate_poly poly x 180339 9
from collections.abc import Sequence


def evaluate_poly(poly: Sequence[float], x: float) -> float:
    
    return sum(c * (x**i) for i, c in enumerate(poly))


def horner(poly: Sequence[float], x: float) -> float:
    
    result = 0.0
    for coeff in reversed(poly):
        result = result * x + coeff
    return result


if __name__ == "__main__":
    
    poly = (0.0, 0.0, 5.0, 9.3, 7.0)
    x = 10.0
    print(evaluate_poly(poly, x))
    print(horner(poly, x))