> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/sidef-lang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/sidef-lang/programming_tasks/h/horners_rule_for_polynomial_evaluation.md).

# Horner's rule for polynomial evaluation

Functional:

```ruby
func horner(coeff, x) {
    coeff.reverse.reduce { |a,b| a*x + b }
}
 
say horner([-19, 7, -4, 6], 3)   # => 128
```

Recursive:

```ruby
func horner(coeff, x) {
    (coeff.len > 0) \
        ? (coeff[0] + x*horner(coeff.last(-1), x))
        : 0
}

say horner([-19, 7, -4, 6], 3)   # => 128
```
