function y = fasteval(a,x)
% FASTEVAL  Given coeffs
%   a(1),...,a(n+1)
% compute P(x) by Horner's method
%   P(x) = a(1) + x ( a(2) + x ( a(3) + ... + x ( a(n) + x a(n+1) ) ... ))
% Starts with inside of inner-most loop and works outward.
% Note n >= 1 is required for this implementation.

n = length(a) - 1;
y = a(n+1);
for j=n:-1:1
  y = a(j) + x * y;
end

