A fast scheme for evaluating a polynomial such as:

 



−
19
+
7
x
−
4

x

2


+
6

x

3





{\displaystyle -19+7x-4x^{2}+6x^{3}\,}


when

 



x
=
3



{\displaystyle x=3\;}

.
is to arrange the computation as follows:

 



(
(
(
(
0
)
x
+
6
)
x
+
(
−
4
)
)
x
+
7
)
x
+
(
−
19
)



{\displaystyle ((((0)x+6)x+(-4))x+7)x+(-19)\;}


And compute the result from the innermost brackets outwards as in this pseudocode:

coefficients := [-19, 7, -4, 6] # list coefficients of all x^0..x^n in order
x := 3
accumulator := 0
for i in length(coefficients) downto 1 do
    # Assumes 1-based indexing for arrays
    accumulator := ( accumulator * x ) + coefficients[i]
done
# accumulator now has the answer

Task Description

Create a routine that takes a list of coefficients of a polynomial in order of increasing powers of x; together with a value of x to compute its value at, and return the value of the polynomial at that value using Horner's rule.
Cf. Formal power series

/*REXX program  demonstrates using    Horner's rule    for   polynomial evaluation.     */
numeric digits 30                                /*use extra numeric precision.         */
parse  arg  x poly                               /*get value of X and the coefficients. */
$=                                               /*start with a clean slate equation.   */
       do deg=0  until  poly==''                 /*get the equation's coefficients.     */
       parse var poly c.deg poly;  c.deg=c.deg/1 /*get equation coefficient & normalize.*/
       if c.deg>=0  then c.deg= '+'c.deg         /*if ¬ negative, then prefix with a  + */
       $=$  c.deg                                /*concatenate it to the equation.      */
       if deg\==0 & c.deg\=0  then $=$'∙x^'deg   /*¬1st coefficient & ¬0?  Append X pow.*/
       $=$ '  '                                  /*insert some blanks, make it look nice*/
       end   /*deg*/
say '         x = '   x
say '    degree = '  deg
say '  equation = '   $
a=c.deg                                          /*A:  is the accumulator  (or answer). */
         do j=deg-1  by -1  for deg;   a=a*x+c.j /*apply Horner's rule to the equations.*/
         end   /*j*/
say                                              /*display a blank line for readability.*/
say '    answer = ' a                            /*stick a fork in it,  we're all done. */