Polynomials#


Revised

07 Mar 2023


Real Polynomial in one variable#

DEFINITION
A real polynomial function in one variable has the form

\[P(x) = \sum_{k = 0}^n a_k x^k = a_n x^n + a_{n - 1} x^{n - 1} + ... + a_2 x^2 + a_1 x + a_0\]

where \(n\) is a nonnegative integer and \(a_0, a_1, a_2, ..., a_n \in \mathbb{R}\) are constants called the coefficients of the polynomial.

Degree#

If the leading coefficient \(a_n \ne 0\), then the degree of the polynomial is \(n\).

Domain#

\(\text{dom}(P(x)) = \mathbb{R}\)

General form of a linear function in one variable#

A linear function is a polynomial function of degree 1.

\[\begin{split} \begin{align} f(x) &= a_1 x + a_0 \\ &= A x + B \\ y &= mx + b & \text{the familiar slope-intecept expression where}\, m \,\text{is the slope and}\, b \,\text{is the y-intercept} \\ \end{align} \end{split}\]

General form of a quadratic function in one variable#

A quadratic function is a polynomial function of degree 2.

\[\begin{split} \begin{align} f(x) &= a_2 x^2 + a_1 x + a_0 \\ &= A x^2 + B x + C \\ \end{align} \end{split}\]

General form of a cubic function in one variable#

A cubic function is a polynomial function of degree 3.

\[\begin{split} \begin{align} f(x) &= a_3 x^3 + a_2 x^2 + a_1 x + a_0 \\ &= A x^3 + B x^2 + C x + D \\ \end{align} \end{split}\]

Polynomial Addition#

Let \(f(x) = \sum_{k = 0}^n a_k x^k\) and \(g(x) = \sum_{k = 0}^n b_k x^k\) be polynomials.

\[(f + g)(x) = \sum_{k = 0}^n (a_k + b_k) x^k\]

Polynomial Subtraction#

Let \(f(x) = \sum_{k = 0}^n a_k x^k\) and \(g(x) = \sum_{k = 0}^n b_k x^k\) be polynomials.

\[(f - g)(x) = \sum_{k = 0}^n (a_k - b_k) x^k\]

Polynomial Differentiation#

Let \(f(x) = \sum_{k = 0}^n a_k x^k\) be a polynomial.

\[f'(x) = \sum_{k = 0}^n k a_k x^{k - 1}\]

Real Polynomial in two variables#

DEFINITION
A real polynomial in two variables has the form

\[P(x, y) = \sum a_{nm} x^n y^m\]

where \(a_{ij} \in \mathbb{R}\) is a constant and \(m\) and \(n\) are nonnegative integers.

Degree#

If the leading coefficient \(a_{nm} \ne 0\), then the degree of the polynomial is \(n + m\).

Domain#

\(\text{dom}(P(x)) = \mathbb{R}^2\)

General form of a linear function in two variables#

A linear function is a polynomial function of degree 1.

\[\begin{split} \begin{align} f(x, y) &= a_{10} x + a_{01} y + a_{00} \\ &= A x + B y + C \\ \end{align} \end{split}\]

General form of a quadratic function in two variables#

A quadratic function is a polynomial function of degree 2.

\[\begin{split} \begin{align} f(x, y) &= a_{20} x^2 + a_{11} x y + a_{02} y^2 + a_{10} x + a_{01} y + a_{00} \\ &= A x^2 + B x y + C y^2 + D x + E y + F \\ \end{align} \end{split}\]

General form of a cubic function in two variables#

A cubic function is a polynomial function of degree 3.

\[\begin{split} \begin{align} f(x, y) &= a_{30} x^3 + a_{21} x^2 y + a_{12} x y^2 + a_{03} y^3 + a_{20} x^2 + a_{11} x y + a_{02} y^2 + a_{10} x + a_{01} y + a_{00} \\ &= A x^3 + B x^2 y + C x y^2 + D y^3 + E x^2 + F x y + G y^2 + H x + I y + J \\ \end{align} \end{split}\]

Real Polynomial in several variables#

DEFINITION
A real polynomial in k variables has the form

\[P(x_1, x_2, ..., x_k) = \sum a_{n_1 n_2 ... n_k} x_1^{n_1} x_2^{n_2} ... x_k^{n_k}\]

Degree#

If the leading coefficient \(a_{n_1...n_k} \ne 0\), then the degree of the polynomial is \(\sum n_i\).

Domain#

\(\text{dom}(P(x)) = \mathbb{R}^k\)


General polynomial in one variable#

A function \(P : \mathbf{F} \rightarrow \mathbf{F}\) is called a polynomial with coefficients in a field \(\mathbf{F}\) if there exist \(a_0, ..., a_n \in \mathbf{F}\) such that \(P(x) = a_n x^n + ... + a_2 x^2 + a_1 x + a_0\) for all \(x \in \mathbf{F}\).

Claim
Let \(a_0, ..., a_n \in \mathbf{F}\).
If \(a_n x^n + ... + a_2 x^2 + a_1 x + a_0 = 0\) for all \(x \in \mathbf{F}\), then \(a_0 = ... = a_n = 0\) (If a polynomial is the zero function, then all coefficients are 0.)

Proof by Contrapositive

If not all the coefficients are 0, then \(a_n x^n + ... + a_2 x^2 + a_1 x + a_0 \ne 0\).
Let
\( \begin{align} \frac{|a_0| + |a_1| + ... + |a_{n - 1}|}{|a_n|} + 1 &= x & \text{note that}\, x \ge 1 \,\text{and}\, x^j \le x^{n - 1} \,\text{for}\, j = 0, 1, ..., n - 1 \\ |a_0| + |a_1| + ... + |a_{n - 1}| &= |a_n|(x - 1) \\ |a_0| + |a_1| + ... + |a_{n - 1}| &\lt |a_n|x \\ (|a_0| + |a_1| + ... + |a_{n - 1}|)x^{n - 1} &\lt |a_n x^n| \\ |a_0 + a_1 x + ... + a_{n - 1} x^{n - 1}| \le (|a_0| + |a_1| + ... + |a_{n - 1}|) x^{n - 1} &\lt |a_n x^n| \\ |a_0 + a_1 x + ... + a_{n - 1} x^{n - 1}| &\lt |a_n x^n| \\ a_0 + a_1 x + ... + a_{n - 1} x^{n - 1} &\ne -a_n x^n \\ a_0 + a_1 x + ... + a_{n - 1} x^{n - 1} + a_n x^n &\ne 0 \\ \end{align} \)

\(\blacksquare\)

StackExchange


import numpy as np
import matplotlib.pyplot as plt
plt.style.use('seaborn-pastel')
plt.rcParams['figure.figsize'] = (10, 6)

from itertools import zip_longest
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
File ~/anaconda3/envs/ml/lib/python3.11/site-packages/matplotlib/style/core.py:137, in use(style)
    136 try:
--> 137     style = _rc_params_in_file(style)
    138 except OSError as err:

File ~/anaconda3/envs/ml/lib/python3.11/site-packages/matplotlib/__init__.py:866, in _rc_params_in_file(fname, transform, fail_on_error)
    865 rc_temp = {}
--> 866 with _open_file_or_url(fname) as fd:
    867     try:

File ~/anaconda3/envs/ml/lib/python3.11/contextlib.py:137, in _GeneratorContextManager.__enter__(self)
    136 try:
--> 137     return next(self.gen)
    138 except StopIteration:

File ~/anaconda3/envs/ml/lib/python3.11/site-packages/matplotlib/__init__.py:843, in _open_file_or_url(fname)
    842 fname = os.path.expanduser(fname)
--> 843 with open(fname, encoding='utf-8') as f:
    844     yield f

FileNotFoundError: [Errno 2] No such file or directory: 'seaborn-pastel'

The above exception was the direct cause of the following exception:

OSError                                   Traceback (most recent call last)
Cell In[1], line 3
      1 import numpy as np
      2 import matplotlib.pyplot as plt
----> 3 plt.style.use('seaborn-pastel')
      4 plt.rcParams['figure.figsize'] = (10, 6)
      6 from itertools import zip_longest

File ~/anaconda3/envs/ml/lib/python3.11/site-packages/matplotlib/style/core.py:139, in use(style)
    137         style = _rc_params_in_file(style)
    138     except OSError as err:
--> 139         raise OSError(
    140             f"{style!r} is not a valid package style, path of style "
    141             f"file, URL of style file, or library style name (library "
    142             f"styles are listed in `style.available`)") from err
    143 filtered = {}
    144 for k in style:  # don't trigger RcParams.__getitem__('backend')

OSError: 'seaborn-pastel' is not a valid package style, path of style file, URL of style file, or library style name (library styles are listed in `style.available`)
class Polynomial:
    def __init__ (self, *coefficients):
        self.coefficients = list(coefficients)
        
    def __repr__ (self):
        return f"Polynomial {str(tuple(self.coefficients))}"
    
    def __str__ (self):
        def x_expr (degree):
            if degree == 0:
                out = ''
            elif degree == 1:
                out = 'x'
            else:
                out = f'x^{str(degree)}'
            return out
        degree = len(self.coefficients) - 1
        out = ''
        for i in range(len(self.coefficients)):
            coef = self.coefficients[i]
            if abs(coef) == 1 and i < degree:
                out += f"{'+' if coef > 0 else '-'}{x_expr(degree - i)}"
            elif coef != 0:
                out += f"{coef:+g}{x_expr(degree - i)}"
        return out.lstrip('+')
    
    def __call__ (self, x):
        #return [0 * x + coef for coef in self.coefficients]
        return sum([coef * x ** index for index, coef in enumerate(self.coefficients[::-1])])
    
    def degree (self):
        return len(self.coefficients)
    
    def __add__ (self, other):
        P1 = self.coefficients[::-1]
        P2 = other.coefficients[::-1]
        return self.__class__(*[sum(t) for t in zip_longest(P1, P2, fillvalue=0)][::-1])
    
    def __sub__ (self, other):
        P1 = self.coefficients[::-1]
        P2 = other.coefficients[::-1]
        return self.__class__(*[t1 - t2 for t1, t2 in zip_longest(P1, P2, fillvalue=0)][::-1])
    
    def derivative (self):
        derived_coefs = []
        exponent = len(self.coefficients) - 1
        for i in range(len(self.coefficients) - 1):
            derived_coefs.append(self.coefficients[i] * exponent)
            exponent -= 1
        return self.__class__(*derived_coefs)
p1 = Polynomial(4, 0, -4, 3, 0)
p2 = Polynomial(-0.8, 2.3, 0.5, 1, 0.2)
p_sum = p1 + p2
p_dif = p1 - p2
x = np.linspace(-3, 3, 51)
y1 = p1(x)
y2 = p2(x)
y_sum = p_sum(x)
y_dif = p_dif(x)
plt.plot(x, y1, label='y1')
plt.plot(x, y2, label='y2')
plt.plot(x, y_sum, label='y_sum')
plt.plot(x, y_dif, label='y_dif')
plt.legend();
../../../_images/ff5ce5fef357c78604d4f990cd6a107727bc694f9e76cbf1405f60e96520a05e.png
n = 5
display(
    (n + 1)**2,
    (n + 1)**2 - sum(range(n + 1)),
    sum(range(n + 2)),
    sum(range(n + 1)),
)
36
21
21
15
p = Polynomial(-0.8, 2.3, 0.5, 1, 0.2)
dp = p.derivative()
x = np.linspace(-2, 3, 51)
y = p(x)
df = dp(x)
plt.plot(x, y, label='y')
plt.plot(x, df, label='dy')
plt.legend();
print(p)
print(dp)
-0.8x^4+2.3x^3+0.5x^2+x+0.2
-3.2x^3+6.9x^2+x+1
../../../_images/ce7a53e508c90a1e9e9928bcca3c53849ba3c5da642aa1fcdac9fb101ed8a07e.png
for count, poly in enumerate([p]):
    print(f'$p_{count} = {str(poly)}$')
$p_0 = -0.8x^4+2.3x^3+0.5x^2+x+0.2$

Figures#

  • [W] François Viète (1540-1603)


Terms#

[W] list of polynomial topics

  • [W] Algebraic Equation (Polynomial Equation)

  • [W] Binomial

  • [W] Characteristic Polynomial

  • [W] Coefficient

  • [W] Constant Term

  • [W] Degree

  • [W] Exponential Polynomial

  • [W] Factor Theorem

  • [W] Factorization of Polynomials

  • [W] Gauss’s Lemma

  • [W] Geometric Properties of Polynomial Roots

  • [W] Greatest Common Divisor Polynomial

  • [W] Homogeneous Polynomial

  • [W] Horner’s Method

  • [W] Irreducible Polynomial

  • [W] Laurent Polynomial

  • [W] Like Terms

  • [W] Little Bézout’s Theorem (Polynomial Remainder Theorem)

  • [W] Matrix Polynomial

  • [W] Monic Polynomial

  • [W] Monomial

  • [W] Orthogonal Polynomials

  • [W] Polynomial

  • [W] Polynomial Equation (Algebraic Equation)

  • [W] Polynomial Evaluation

  • [W] Polynomial Long Division

  • [W] Polynomial Remainder Theorem (Little Bézout’s Theorem)

  • [W] Primitive Part of a polynomial

  • [W] Root

  • [W] Root-Finding Algorithm

  • [W] Ruffini’s Rule

  • [W] Sparse Polynomial

  • [W] Synthetic Division

  • [W] System of Polynomial Equations

  • [W] Trigonometric Polynomial

  • [W] Trinomial

  • [W] Vieta’s Formulas