How to resolve the algorithm Horner's rule for polynomial evaluation step by step in the Sidef programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Horner's rule for polynomial evaluation step by step in the Sidef programming language

Table of Contents

Problem Statement

A fast scheme for evaluating a polynomial such as: when is to arrange the computation as follows: And compute the result from the innermost brackets outwards as in this pseudocode: Task Description Cf. Formal power series

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Horner's rule for polynomial evaluation step by step in the Sidef programming language

Source code in the sidef programming language

func horner(coeff, x) {
    coeff.reverse.reduce { |a,b| a*x + b };
}

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


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

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


  

You may also check:How to resolve the algorithm Voronoi diagram step by step in the Ruby programming language
You may also check:How to resolve the algorithm String interpolation (included) step by step in the Factor programming language
You may also check:How to resolve the algorithm Doubly-linked list/Traversal step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Distribution of 0 digits in factorial series step by step in the C++ programming language
You may also check:How to resolve the algorithm Rot-13 step by step in the Slate programming language