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

*        Horner's rule for polynomial evaluation - 07/10/2015
HORNER   CSECT
         USING  HORNER,R15         set base register
         SR     R5,R5              accumulator=0
         LA     R2,N               i=number_of_coeff
LOOP     M      R4,X               accumulator=accumulator*x
         LR     R1,R2              i
         SLA    R1,2               i*4
         L      R3,COEF-4(R1)      coef(i)
         AR     R5,R3              accumulator=accumulator+coef(i)
         BCT    R2,LOOP            i=i-1; loop n times
         XDECO  R5,PG              edit accumulator 
         XPRNT  PG,12              print buffer
         XR     R15,R15            set return code
         BR     R14                return to caller
COEF     DC     F'-19',F'7',F'-4',F'6'    <== input values
X        DC     F'3'                      <== input value
N        EQU    (X-COEF)/4         number of coefficients 
PG       DS     CL12               buffer
         YREGS
         END    HORNER