Polynomial Pieces of Splines

How to access the polynomial pieces of a piecewise-polynomial periodic one-dimensional spline.


Roadmap

Uniform polynomial splines are piecewise-polynomial functions. In what follows, we are going to provide a detailed derivation that returns the polynomial pieces. We start by defining B-splines and splines; we then propose a numerically stable way to evaluate splines. Then, we twist the evaluation procedure to get the expression of each polynomial piece.

Construction of the B-Spline

We first give the fundamental building blocks of uniform polynomial splines.

Polynomial Simple Element

Let \(n\in{\mathbb{N}}\) be a nonnegative integer degree. Let \(x\in{\mathbb{R}}\) be some argument. Define the polynomial simple element \(\varsigma^{n}\) of degree \(n\) (the degree being a superscript here, not a power) as the mapping \(\varsigma^{n}:{\mathbb{R}}\rightarrow{\mathbb{R}},x\mapsto\varsigma^{n}(x)\) computed as

\[\varsigma^{n}(x)=\frac{1}{2\,n!}\,{\mathrm{sgn}}(x)\,x^{n}.\]

There, the signum function maps positive real numbers to \(+1,\) negative real numbers to \(\left(-1\right),\) and zero to \(0.\)

Derivative of a Polynomial Simple Element

The \(m\)-th derivative of a polynomial simple element of degree \(n,\) with \(m\in[0\ldots n],\) is

\[\frac{{\mathrm{d}}^{m}\varsigma^{n}(x)}{{\mathrm{d}}x^{m}}=\varsigma^{n-m}(x).\]

Derivatives of orders that exceed the degree can also be defined, albeit only in a distributional sense.

B-Spline

We give now a bootstrap definition of the B-spline \(\beta^{n}\) of nonnegative integer degree \(n\in{\mathbb{N}}\) (the degree being a superscript here, not a power). It is the mapping \(\beta^{n}:{\mathbb{R}}\rightarrow{\mathbb{R}},x\mapsto\beta^{n}(x)\) computed as

\[\beta^{n}(x)=\sum_{k=0}^{n+1}\,\left(-1\right)^{k}\,{n+1\choose k}\,\varsigma^{n}(x+\frac{n+1}{2}-k).\]

This function is made of polynomial pieces because of the term \(x^{n}\) in the definition of \(\varsigma^{n}.\) Moreover, the support of each piece has unit length, because the argument of \(\varsigma^{n}\) in the definition of \(\beta^{n}\) is shifted by integer \(k.\)

In accord with the definition, the B-spline of degree zero is

\[\begin{split}\begin{array}{rcl} \beta^{0}(x)&=&\varsigma^{0}(x+\frac{1}{2})-\varsigma^{0}(x-\frac{1}{2})\\ &=&\left\{\begin{array}{ll}1,&\left|x\right|<\frac{1}{2}\\\frac{1}{2},&\left|x\right|=\frac{1}{2}\\0,&\frac{1}{2}<\left|x\right|.\end{array}\right. \end{array}\end{split}\]

Among many important properties, for all degrees \(n\in{\mathbb{N}}\) and for all \(x\in{\mathbb{R}},\) the B-splines thus defined

  • have a closed support, with \({\mathrm{supp}}\{\beta^{n}\}=[-\left(n+1\right)/2,\left(n+1\right)/2];\)

  • are even-symmetric, with \(\beta^{n}(x)=\beta^{n}(-x);\)

  • satisfy the partition-of-unity condition \(\sum_{k\in{\mathbb{Z}}}\,\beta^{n}(x-k)=1.\)

These properties hold pointwise true, also for \(n=0\) and \(x=\pm1/2.\)

Construction of a Spline

Build now a weighted sum of integer shifts of B-splines, with the weights being provided by the so-called spline coefficients \(c.\) For convenience, we shall restrict ourselves to periodized weights. Let us call this weighted sum a spline—without the B of B-spline. It is yet another mapping \(f:{\mathbb{R}}\rightarrow{\mathbb{R}},x\mapsto f(x);\) it is computed as

\[f(x)=\sum_{k\in{\mathbb{Z}}}\,c[{k\bmod K}]\,\beta^{n}(x-\delta x-k),\]

where \(K\in{\mathbb{N}}+1\) is its positive integer period, and where \(\delta x\in{\mathbb{R}}\) is some global delay. The infinite sum is guaranteed to converge because B-splines have a closed support.

Evaluation of Splines

To evaluate a spline, one needs a procedure to evaluate B-splines. Unfortunately, the bootstrap formulation above reveals that a B-spline is inherently made of additive terms of alternating sign \(\left(-1\right)^{k},\) which results in numerical difficulties. While we keep the bootstrap definition for splines of degree zero, we propose to alleviate the numerical difficulties for splines of positive degrees by computing \(f(x)\) through the equivalent formulation

\[f(x)={\mathbf{c}}_{r}^{{\mathsf{T}}}\,{\mathbf{W}}^{n}\,{\mathbf{v}}^{n}(\chi).\]

This linear-algebra formulation takes its legitimation in the fact that the bootstrap definition of B-splines as well as the evaluation of splines proposed above are both finite sums of weighted terms.

Evaluation Matrix

Define the B-spline rational evaluation matrix \({\mathbf{W}}^{n}\in{\mathbb{Q}}^{\left(n+1\right)\times\left(n+1\right)}\) as having a rational component at its \(\left(r+1\right)\)-th row and \(\left(c+1\right)\)-th column given by

\[w_{r+1,c+1}^{n}=\frac{1}{c!}\,\left(\left.\frac{{\mathrm{d}}^{c}\beta^{n}(x)}{{\mathrm{d}}x^{c}}\right|_{x=\frac{n-1}{2}-r}+\frac{1}{2}\,\delta[c-n]\,\left(-1\right)^{n-r}\,{n+1\choose r+1}\right),\]

where \(\delta[\cdot]\) is a discrete Dirac delta and where the B-spline derivatives are computed as in the bootstrap method. The B-spline rational evaluation matrix depends on \(n\) only and can be precomputed. Since all terms are rationals, this can be done by taking advantage of Python’s fractions module to perform exact computations. Once done, the matrix is cached as float numbers. In doing so, we let \({\mathbf{W}}^{n}\) carry the burden of the delicate balancing of positive and negative terms that was plaguing the bootstrap computation of B-splines.

Ancillary Variables

Define

\[\xi=\frac{n-1}{2}-x+\delta x\in{\mathbb{R}}\]
\[r=\left\lceil\xi\right\rceil\in{\mathbb{Z}}\]
\[\chi=r-\xi\in[0,1)\]

Vector of Spline Coefficients

Define

\[{\mathbf{c}}_{r}=\left(c[{\left(k-r\right)\bmod K}]\right)_{k=0}^{n}\in{\mathbb{R}}^{n+1}\]

Vandermonde Vector

Define

\[{\mathbf{v}}^{n}(\chi)=(1,\left(\chi^{k}\right)_{k=1}^{n})\in{\mathbb{R}}^{n+1}\]

Spline Pieces

Although the freedom offered by the choice of the degree \(n,\) the delay \(\delta x,\) and the spline coefficients \(c\) is large and allows one to tune \(f\) in many ways, it remains that \(f\) is not entirely arbitrary but inherits from \(\beta^{n}\) the property of being necessarily a piecewise-polynomial function with unit-length pieces. Our purpose now is to establish the list of polynomials that is associated to a spline of a certain degree, delay, period, and spline coefficients. To do so, instead of considering the argument \(x\) to be the free variable and instead of letting the ancillary variables depend on \(x\) (as we did just above), we now change our perspective and let \(r\in[0\ldots K-1]\) become a free index by which we are going to select each polynomial piece; moreover, we let \(\chi\in[0,1)\) become a free variable, too. We shall take \(\chi\) to be the argument of each polynomial piece. Under this alternate view of the evaluation of splines, where \(x\) is not free anymore but depends on \(\{n,\delta x,r,\chi\},\) we can establish that

\[{\mathbf{c}}_{r}^{{\mathsf{T}}}\,{\mathbf{W}}^{n}\,{\mathbf{v}}^{n}(\chi)=\left[\left({\mathbf{W}}^{n}\right)^{{\mathsf{T}}}\,{\mathbf{c}}_{r}\right]_{1}+\sum_{k=1}^{n}\,\left[\left({\mathbf{W}}^{n}\right)^{{\mathsf{T}}}\,{\mathbf{c}}_{r}\right]_{k+1}\,\chi^{k}\]

describes the polynomial of the free variable \(\chi\in[0,1),\) indexed by \(r,\) that coincides with the value of the spline over \(x\in[\frac{n-1}{2}+\delta x-q\,K-r,\frac{n+1}{2}+\delta x-q\,K-r),\) where \(q\in{\mathbb{Z}}\) is there to take the periodicity of the spline into account.

We now propose a few lines of code that create and display a random spline and extract its polynomial pieces.

Jupyter Lab notebook

Polynomial pieces of a spline