Polynomials - definitions

https://en.wikipedia.org/wiki/Polynomial

https://en.wikipedia.org/wiki/Horner%27s_method

INTRODUCTION

A polynomial is an expression consisting of variables and coefficients, that involves only the operations of addition, subtraction, multiplication, and non-negative integer exponentiation of variables. Polynomials appear in many areas of mathematics and science.


A polynomial of a single variable x:
P(x) = x^2 - 4x + 7
The polynomial P defines a function
x → P(x),
where x can be a number or a polynomial.
Coefficients are usually numbers.

-4x is a (linear) term, -4 is a coefficient, the degree of x is one.
5                  is a 'constant' polynomial (degree 0).
2x +3              is a 'linear' polynomial (degree 1).
3x^2 +5x -8        is a 'quadratic' polynomial (degree 2).
2x^3 -4x^2 +6x -1  is a 'cubic' polynomial (degree 3).

P(x) = p_0 + p_1 * x + p_2 * x^2 = \sum_i p_i * x^i,   # LaTeX notation
Q(x) = q_0 + q_1 * x + q_2 * x^2 = \sum_i q_i * x^i.

Addition P + Q (the associative law of addition is used)

P(x) + Q(x) = (p_0 + q_0) + (p_1 + q_1) * x + (p_2 + q_2) * x^2.
P(x) + Q(x) = \sum_i (p_i + q_i) * x^i.

Substraction P - Q

P(x) - Q(x) = (p_0 - q_0) + (p_1 - q_1) * x + (p_2 - q_2) * x^2.
P(x) - Q(x) = \sum_i (p_i - q_i) * x^i.

Multiplication P * Q (the distributive law is repeatedly applied)

P(x) * Q(x) = p_0 * q_0 + p_0 * (q_1 * x) + p_0 * (q_2 * x^2)
+ (p_1 * x) * q_0 + (p_1 * x) * (q_1 * x) + (p_1 * x) * (q_2 * x^2)
+ (p_2 * x^2) * q_0 + (p_2 * x^2) * (q_1 * x) + (p_2 * x^2) * (q_2 * x^2).

P(x) * Q(x) = p_0 * q_0 
+ (p_0 * q_1 + p_1 * q_0) * x
+ (p_0 * q_2 + p_1 * q_1 + p_2 * q_0) * x^2
+ (p_1 * q_2 + p_2 * q_1) * x^3
+ (p_2 * q_2) * x^4.

P(x) * Q(x) = \sum_i \sum_j p_i * q_j * x^{i+j}.

Composition P(Q) = P ○ Q

P(Q(x)) = p_0 + p_1 * Q(x) + p_2 * Q(x)^2.

HORNER'S METHOD

Horner's method (or Horner's scheme) is an algorithm for polynomial evaluation. It allows the evaluation of a polynomial of degree n with only n multiplications and n additions.


P(x) = p_0 + p_1 * x + p_2 * x^2 + p_3 * x^3.  # 6 mul, 3 add

P(x) = p_0 + x * (p_1 + x * (p_2 + x * (p_3))).   # 3 mul, 3 add, Horner

# First approach.
t = p_3,
t = t * x + p_2,
t = t * x + p_1,
t = t * x + p_0.
# Second approach.
t = 0,
t = t * x + p_3,
t = t * x + p_2,
t = t * x + p_1,
t = t * x + p_0.