Adapting Cubic Hermite Splines to the Presence of Singularities Through Correction Terms

Hermite interpolation is classically used to reconstruct smooth data when the function and its first order derivatives are available at certain nodes. If first order derivatives are not available, it is easy to set a system of equations imposing some regularity conditions at the data nodes in order to obtain them. This process leads to the construction of a Hermite spline. The problem of the described Hermite splines is that the accuracy is lost if the data contains singularities. The consequence is the appearance of oscillations, if there is a jump discontinuity in the function, that globally affects the accuracy of the spline, or the smearing of singularities, if the discontinuities are in the derivatives of the function. This paper is devoted to the construction and analysis of a new technique that allows for the computation of accurate first order derivatives of a function close to singularities using a Hermite spline. The idea is to correct the system of equations of the spline in order to attain the desired accuracy even close to the singularities. Once we have computed the first order derivatives with enough accuracy, a correction term is added to the Hermite spline in the intervals that contain a singularity. The aim is to reconstruct piecewise smooth functions with O(h4)\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$O(h^4)$$\end{document} accuracy even close to the singularities. The process of adaption will require some knowledge about the position of the singularity and the jumps of the function and some of its derivatives at the singularity. The whole process can be used as a post-processing, where a correction term is added to the classical cubic Hermite spline. Proofs for the accuracy and regularity of the corrected spline and its derivatives are given. We also analyse the mechanism that eliminates the Gibbs phenomenon close to jump discontinuities in the function. The numerical experiments presented confirm the theoretical results obtained.


Introduction
In the classic literature, we can find that a spline can be constructed defining polynomial pieces that join together under certain regularity or differentiability requirements at these joints. Such regularity properties are the reason why splines are used very often in computer aided geometric design (CAGD) for industrial and professional design applications. Some examples are the representation of geometrical objects in one or several dimensions [1][2][3][4][5], the solution of PDEs or ODEs [6][7][8], image processing [9][10][11] and many others.
Sometimes the data used to construct the spline presents singularities. In the cases where the discontinuity is in the function, some kinds of splines are known to introduce oscillations close to the discontinuities [12,13]. These oscillations classically appear when truncating the Fourier series of a discontinuous function and have been widely studied [14][15][16][17]. Global expansions, such as Fourier series, are affected by the presence of local discontinuities. The usual result is non-uniform convergence and oscillations of the partial sums. D. Gottlieb and C.-W. Shu showed that it is possible to recover high order information from these slowly and non-uniformly convergent global approximations [18][19][20][21][22]. Some other interesting and related works are [16,23,24]. By splitting a function with singularities in two parts, a smooth one and another one containing the information of the singularity, K. S. Eckhoff [25,26] presented a way of modifying the Fourier's method to obtain numerical techniques that allow us to compute derivatives and integrals with a high order of accuracy.
In this work, our approach is different from all previous techniques, although the philosophy might be similar: to reconstruct piecewise smooth functions from discretized data, taking into account the presence of singularities. In our case, we approach the problem using cubic Hermite splines plus correction terms in order to attain adaption close to the singularities.
Recently, we have introduced some modified cubic splines that aim to solve the problems caused by the oscillations that appear close to the discontinuities [27,28]. In those previous papers we try to exploit the properties of a nonlinear mean in the construction of the spline, through which we automatically adapt the interpolation to the presence of discontinuities in the function, thus eliminating the Gibbs oscillations. One drawback is that this technique cannot provide full accuracy close to the singularity, and it smears the discontinuities. In this article, it is also our aim to design a nonlinear cubic Hermite spline interpolation adapted to the presence of singularities and constructed using the point-values discretization, i.e. using the data values f (x) at the positions x = x j , j = 0, . . . , m. In this case, we try to obtain fully accurate first order derivatives and interpolation even close to the singularities (by full accuracy we mean the highest theoretically possible accuracy that we can obtain through our spline), but trying to preserve the jumps in the function and its derivatives in the reconstruction. The resulting method presents a high order of accuracy in the whole domain and provides piecewise C 2 regularity at both sides of the singularities. In order to reach our objective, we are inspired by the construction of the Immersed Interface Method (IIM) [29][30][31], in the sense that we design correction terms that allow us to fulfil our objectives. This method has been mostly used for the solution of elliptic equations with singularities in the context of fluid-structure interaction and it is based on an accurate tracking of the singularities and the modification of the finite difference scheme close to them.
Let us start by describing in brief detail the discretization of data that we shall use. The point-values sampling process used to obtain the pairs of data (x j , f (x j )), j = 0, . . . , m, from a function f that may contain jump discontinuities implies the loss of the information regarding the exact position of these jump discontinuities, as it only preserves local information at the positions x j . Even so, it is possible to detect the interval that contains the discontinuity [32]. The described kind of discretization would only allow for the detection and location of the position of discontinuities in the first order derivative (kinks in the function) [32,33]. Yet, if we assume that the data come from a discretization through local averages of the function f (x), i.e. the cell-averages setting [32], then it is indeed possible to locate jump discontinuities in f (x). In this work we use data discretized in the point-values. Further research could cover the results using cell-averages.
Let us continue by describing the classical Hermite interpolation and by exposing some classical results. Classical cubic Hermite interpolation is based on the construction of a cubic polynomial using the values f j = f (x j ), f j+1 = f (x j+1 ) of the function f , and its first order derivatives, f j = f (x j ) at the positions x j , x j+1 . These four pieces of data allow to obtain the four unknowns in a cubic polynomial. Then, continuity conditions on the function and its first and second order derivatives are imposed at the x j in order to set a system of equations that provides a global solution for the considered interval. That way, piecewise cubic Hermite interpolation is known to be fourth order accurate for smooth functions. Assuming that the data is smooth, if the spline uses approximations of the first order derivativesf j ≈ f j , (from now on, if not stated otherwise, we use the tilde˜to represent approximations of different values: the function, the derivatives, the location of the singularity, etc.), then the maximum accuracy of the piecewise cubic Hermite interpolant is known to be O(h 4 ) if the approximation of the first order derivatives is O(h 3 ) accurate. If f presents singularities between the nodes (from here on we will use the word node as a synonym for the points of union of the different polynomial pieces of the spline), even good approximations of the first order derivatives at the nodes will lead to inaccurate approximations of the function inside the interval that contains the singularity. Discontinuities in the data lead either to classical Hermite splines showing Gibbs oscillations close to discontinuities in the function, or the smearing of singularities if the discontinuity is in the derivatives. This is logical considering that Hermite interpolation can be expressed in terms of the Hermite basis, represented in Fig. 1, which is composed of polynomials that are smooth, two of them being non-monotone. The smearing of discontinuities in the first order derivative can be clearly explained through the smoothness of the base. The occurrence of oscillations close to jumps in the function will be justified later on, showing that the non-monotone elements of the base are multiplied by non-zero coefficients close to discontinuities.
Thus, our aim is twofold: to design a technique that allows for the obtention of the first order derivatives of the function at the nodes of the spline with full accuracy even close to singularities, and to use the computed first order derivatives to obtain a fully accurate spline. These two objectives will be reached through the computation of correction terms. This manuscript is organized as follows. First of all, in Sect. 2 we introduce the classical way of constructing cubic Hermite splines. Section 3 explains how to obtain adapted first order derivatives using a Hermite spline. There we present the first main result of this article: a theorem about the accuracy of the adapted first order derivatives. Section 4 presents a study about the elimination of the Gibbs phenomenon in the classical spline when using the corrected first order derivatives. Section 5 introduces an adapted Hermite spline and analyses theoretically the accuracy of the interpolation near singularities, which is the second main result of this work. Section 6 exposes how the correction terms can be used as a post-processing of the classical cubic Hermite spline. Section 7 presents some numerical experiments which show how the new algorithm performs using univariate functions. In particular, experiments about the accuracy and regularity of the function and the two first order derivatives are presented, jointly with some tests that show the elimination of the Gibbs phenomenon close to jump discontinuities in the function. Finally, Sect. 8 presents the conclusions.

Some Preliminaries About Classical Cubic Hermite Splines
In this section we briefly introduce the classical way of constructing the cubic Hermite spline. Then, we introduce some new techniques that allow for the adaption of the classical interpolant to the presence of singularities. The objective is to design a technique that enables the obtention of sharp reconstructions of functions with discontinuities in the function or the derivatives, avoiding the smearing of the singularity or the appearance of Gibbs oscillations.
There is an extensive list of references that treat the field of the construction and the study of the properties of cubic Hermite splines. For example, [34] or [35] contain a in-depth revision of the classical theoretical results in the field. The idea behind the construction of the spline is to compute a piecewise polynomial function of degree three between the data nodes. The resulting function must be C 2 , i.e. the function and the first two derivatives must be continuous. The basis used to construct the polynomial between the nodes varies in the literature. Some authors start from m + 1 pairs of values (x j , y j ), j = 0, . . . , m and write the expression of the polynomial at a particular interval [x j , x j+1 ] as Sometimes it is more convenient to use the alternative expression which easily provides a bound for the error of the Hermite interpolation. In any of both cases, regularity conditions must be imposed at the nodes in order to obtain a piecewise defined function that is C 2 . Basically, we need to impose the continuity of the function and the two first order derivatives at the nodes. If y j , y j+1 denote the values of the function at the nodes x j , x j+1 , and D j , D j+1 the values of the first order derivatives at the same nodes, imposing the continuity of the function and the first and second order derivatives at the nodes, it is straightforward to obtain the following expression for the coefficients in (1) (see for example [27] for a complete deduction of the formulas), where h j+1 = x j+1 − x j . As mentioned before, the expression of the Hermite spline (1) can be expressed in terms of the Hermite basis, represented in Fig. 1 for cubic splines. By replacing the coefficients of the spline in (1) by the values found in (3) we obtain, Moreover, the change of variables s = x−x j h j+1 returns the expression of the spline in terms of the cubic Hermite basis, The values of the first order derivatives at the nodes D j can be known a priori, as with the Hermite interpolation, or they can be obtained by imposing the continuity of the second order derivatives at the nodes, as with the Hermite spline. Thus, the Hermite spline relies on the solution of a linear system of equations for the D j , which needs two boundary conditions. Common options for the boundary conditions that can be found in the literature are: natural boundary conditions, not-a-knot condition, complete cubic spline, etc. The complete cubic spline consists of imposing slope boundary conditions, and we have chosen it for this article. If the first order derivatives are not available at the boundaries, they can be replaced by O(h 3 ) approximations.
Imposing the continuity of the second order derivatives of the spline leads to the following equation for each interval between the nodes Thus we easily obtain a linear system for the first order derivatives D j at the nodes, with δ j = y j −y j−1 h j . We will consider a uniform grid spacing, but the results for non-uniform grid spacing can be obtained in an analogous way. With this consideration, the system in (6) transforms into ⎡ ⎢ ⎢ ⎣ 4 1 0 0 · · · 0 0 1 4 1 0 · · · 0 0 · · · · · · · · · · · · · · · · · · · · · 0 0 0 0 · · · 1 4 The existence of a singularity at any place of the domain leads to the computation of inaccurate first order derivatives through the system in (7). In case of jump discontinuities in the function, the consequence is the appearance of global Gibbs oscillations in the reconstruction of the spline that will affect the entire domain. A discussion about the size of the oscillations close to the discontinuity can be found in [27]. If a discontinuity is found in the derivatives, the singularity is smeared. In the next sections we will propose correction terms for preserving the accuracy of the spline close to the singularities. We can also consider now the accuracy of the Hermite interpolation and its second order derivatives. These are classical results that will be used later, and which proofs can be found in pages 58 and 59 of [36].

Theorem 1 (Error of classical cubic Hermite interpolation)
Given a sufficiently smooth function f , the error for the cubic Hermite interpolation is given by for all h > 0.

Corollary 1 (Error of the second order derivative of classical cubic Hermite interpolation)
Given a sufficiently smooth function f , the error for the second order derivative of the cubic Hermite interpolation is given by for all h > 0.
It is clear from the expression in (10)

Accurate Approximation of First Order Derivatives Using Splines and Data in the Point-Values
Let us assume that there is a singularity at x * = x j + α in the interval [x j , x j+1 ], just as shown in Fig. 2. For the moment, let us assume that we know the position of the singularity and the jumps in the function and its derivatives. As shown in Fig. 2, we label all the information about the function to the left of the singularity as −. The information to the right is labeled as +. Under this configuration, having the values of a sufficiently piecewise smooth function f at the nodes x 0 , x 1 . . . , x m and the jumps in the function and some of its derivatives at  (7) must be adapted to its presence in order to fulfil the accuracy and regularity requirements. In order to do this, we can modify the right hand side of the system in (7). For the general case presented in Fig. 2, we can adapt the system in (7) by modifying the equations corresponding to D j and D j+1 . At smooth zones of the data, it is clear that the system in (7) must hold, as the regularity conditions imposed at the nodes are met. If a singularity is placed in the interval [x j , x j+1 ], the system in (7) is not valid, as the function cannot be approximated accurately through a polynomial. As each equation of the system in (7) is designed to obtain a particular first order derivative D j at the point x j , if we encounter a singularity, we can just add a correction term at the right hand side of the system that takes into account the presence of the singularity and that allows for the obtention of the desired accuracy of the first order derivative. Let us summarize all the previous considerations in the following Lemma.

Lemma 1
If the singularity is placed in the interval [x j , x j+1 ], then the local truncation error C j of the equation for the first order derivatives D j is equal to and for the first order derivative D j+1 it is equal to Proof The equations for the first order derivatives D − j and D + j+1 in (7) are Taking into account the presence of the singularity, using Taylor expansions and considering the resulting local truncation error, we can write the expression in (13) using quantities only from one side of the discontinuity. Let us denote by C L j the correction term for the left hand side of (13) and by C R j the correction term for the right hand side of (13), so we can simply consider that, due to the presence of the singularity, where C j = C R j − C L j and C j+1 = C R j+1 − C L j+1 amount to the local truncation error. These terms will depend on the position of the singularity and the jumps in the function and its derivatives. Thus, we will need the jump relations Looking at Fig. 2 (16) to express the + values in terms of the − values. Assuming that we know the jump conditions in (16), or that we have a good approximation, we are ready to obtain expressions for f + j+1 in terms of f − j+1 and for f − j in terms of f + j . Using Taylor expansions, we can and subtracting we obtain By replacing these expressions in the right hand side of (13), we obtain the local truncation error for this part of the equation: The same thing can be done for the left hand side of (13). We can write that By subtracting and denoting (21) By replacing now (21) in the left hand side of (13), we get expressions for C L j and C L j+1 : By replacing the expressions (19) in the right hand side of (13), and (22) in the left hand side, we recover the expression in (15): with the local truncation errors written as Note that, if x * is unknown, we only need to locate the interval that contains the singularity to obtain an accurate computation of the first order derivatives at the nodes through the spline.
Then, we can give a rough approximationx * of x * inside that interval, and use it to obtain accurate approximations of the jump in the function and its derivatives at the chosenx * (for example, using one-sided interpolation, as explained in [31]). For the cubic Hermite spline, , and so on. This observation is straightforward if we look at the expression of the correction terms in (24). Of course, the use of an inaccuratex * instead of x * (but still inside the interval that contains the singularity), will produce a large error in the approximation of the function in the interval that contains the singularity (typically an error of order O(1) for jumps in the function and O(h) for jumps in the first order derivative), but not in the approximation of the first order derivatives at the nodes. Moreover, it would also provide a reconstruction of the function without oscillations. Later on (in Remark 4) we will discuss how the approximation of the location of the singularity affects the interpolation of the function through the spline. The location of the interval that contains a jump discontinuity in the function, or the approximated location of a discontinuity in the first order derivative can be done using Harten's ENO-SR (essentially non oscillatorysubcell resolution). A nice discussion about the process, with an improved algorithm for the location, is given in [32]. Let us consider now the Hermite spline in the interval [a, b], constructed using m +1 points belonging to a piecewise continuous function that contains a singularity at x * ∈ [x j , x j+1 ] and that is at least four times continuously differentiable except at x * . Let us follow the same notation as before and denote the information to the left of the singularity with the − symbol and to the right with the + symbol. The system of equations for the first order derivatives at the nodes can be expressed as 4 1 0 · · · 0 0 0 0 · · · 0 0 1 4 1 · · · 0 0 0 0 · · · 0 0 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 0 0 0 · · · 1 4 1 0 · · · 0 0 0 0 0 · · · 0 1 4 1 · · · 0 0 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 0 0 0 · · · 0 0 0 0 · · · 1 4 Now we can prove the following theorem.
Theorem 2 (Accuracy of adapted first order derivatives close to singularities) Let us consider a piecewise continuous function f that contains a singularity at x * and that is at least four times continuously differentiable on R\{x * } with uniformly bounded derivatives. The first order derivatives obtained through the non-corrected system of the spline for this function satisfy where C j , C j+1 are given in Lemma 1.
The addition of the correction terms −C j , −C j+1 up to O(h 3 ), i.e. the subtraction of the local truncation errors in (24) up to O(h 3 ), to the right hand side of the equations of the spline for D j and D j+1 in the system (25) allows for the computation of first order derivatives that satisfy Proof For simplicity we will take a uniform partition of the considered interval. The proof presented in what follows can be extended to a non-uniform partition. Let us represent the system in (25) by AD = d. Let F and r be the vectors, where f (x) are the first order derivatives of f at the nodes.
Now we can use Taylor's expansion to express Note that if the boundary conditions D − 0 , D + m are exact, the previous bound holds. If we assume that the singularity is placed in the interval [x j , x j+1 ], just as shown in Fig. 2, the process to obtain r j is similar, but we need to follow the same steps taken to obtain the local truncation error in (24): use Taylor expansions around x * to express the values y + j+1 and f + x (x j+1 ) in terms of the − side (or viceversa) using the jump relations as in (18) and (21). After some basic algebra, we obtain that the r j that comes from (25) satisfies By replicating the process for r j+1 , we easily obtain the bound in (26), corresponding to the non-corrected spline. Thus, if we subtract to r j the local truncation error C j in (24) (25), the result is equivalent. Taking into account the expression of A in (25), the norm of its inverse is ||A −1 || L ∞ ≤ 1 (see, for example, Theorem 2.1 of [37]), and since Therefore we obtain the bound in (27) by just applying the triangular inequality to the norm of the vector r . Thus, the subtraction of the local truncation error to the right hand side of the system in (25), 4 1 0 · · · 0 0 0 0 · · · 0 0 1 4 1 · · · 0 0 0 0 · · · 0 0 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 0 0 0 · · · 1 4 1 0 · · · 0 0 0 0 0 · · · 0 1 4 1 · · · 0 0 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 0 0 0 · · · 0 0 0 0 · · · 1 4 allows for the obtention of first order derivatives with the bound for the error given in (27). It is also important to note that, in order to solve the system in (33), we need to know its right hand side. The right hand side of the system in (33) is composed of finite difference approximations of the first order derivative. Thus, if the positions of the singularities are not known, the processing of these differences can be used to approximate their location. See for example the algorithm described in [32].

Remark 2
If the data presents more than one singularity, the treatment is exactly the same. If an algorithm for locating the singularity is used, the only requirement is that the singularities are placed far enough from each other, i.e. at such a distance that the location algorithm is capable of distinguishing between two contiguous singularities. In the case of the algorithm presented in [32], singularities must be placed one stencil away from each other (four points for cubic polynomials).

Analysis of the Absence of the Gibbs Phenomenon Close to Jump Discontinuities in the Cubic Hermite Spline Using Corrected First Order Derivatives
In this section we will analyse the absence of the Gibbs phenomenon when using the corrected first order derivatives.
In Theorem 2 we have proved that the accuracy attained in the first order derivatives computed using the corrected system (33) is O(h 3 ) in the infinity norm. With this result, it is posible to prove that, using these derivatives, the Hermite spline does not introduce the Gibbs phenomenon close to jump discontinuities.
We should start by introducing the definition of the Gibbs phenomenon given by D. Gottlieb and C.-W. Shu in [15].

Definition 1 The Gibbs phenomenon
Given a punctually discontinuous function f and its sampling, defined by f (x i ) = f (ih), the Gibbs phenomenon deals with the convergence of the function g based on f (x i ) towards f when h goes to zero. It can be characterized by two features [15]: 1. Away from the discontinuity, the convergence is rather slow and for any point x 2. There is an overshoot, close to the discontinuity, that does not diminish with the reduction of h. Thus, With the results about the accuracy of the first order derivatives obtained in Theorem 2 and the previous definition of the Gibbs phenomenon, we can state the following theorem.

Theorem 3 Absence of the Gibbs phenomenon
The Hermite spline obtained using the adapted first order derivatives computed through (33) does not introduce Gibbs oscillations close to jump discontinuities in the function.
Proof We can analyse two cases. The first one is when the considered interval does not contain a singularity. In this case, Theorem 2 assures O(h 3 ) accuracy for the first order derivatives. And, as mentioned in Remark 1, this is enough for the Hermite spline to attain O(h 4 ) accuracy at smooth zones, so no Gibbs oscillations are possible.
The second case is when the considered interval contains a jump discontinuity in the function. Let us assume that the singularity is in the interval [x j , x j+1 ]. In (27), Theorem 2 assures that the first order derivatives attained through the corrected system in (33) also have O(h 3 ) order of accuracy. Thus, it can be considered that the vector of first order derivatives D that results from solving (33) will be Now, considering (3) we can write If we consider that there is a jump discontinuity in the interval [x j , x j+1 ], then y j+1 − y j = O(1) and This means that the error attained by the Hermite spline with O(h 3 ) accurate first order derivatives provides O(h 4 ) accuracy when interpolating the data, except at the interval that contains the discontinuity, where the approximation is O(1) accurate. Now we only need to check that the approximation provided by the spline is in the interval [y j , y j+1 ] when h goes to zero. In order to verify this assumption, we can write the equation of the spline in (1) as Introducing the change of variables s = x−x j h , we get for s ∈ [0, 1]. The expression can also be reformulated as follows: where the first two terms of (40) are just a dilation and a translation of the Hermite base function b 1 (s) = s 2 (3 − 2s). This function presents a minimum at s = 0 and a maximum at s = 1, so no Gibbs oscillations can be introduced by this element of the Hermite base, as can be seen in Fig. 1. In this Figure it can be observed that the base functions b 3 (s) and b 4 (s) oscillate. Thus, Gibbs oscillations can appear if these bases appear multiplied by large coefficients. As we have already mentioned, in (40) D j and D j+1 are O (1). With these considerations in mind, it is not difficult to conclude that the last two terms in (40) go to zero when h → 0. So no Gibbs oscillation is possible.
It should be noted that an analogous analysis can be done for the classical spline. In this case, the vector of first order derivatives D that results from solving (33) without the correction terms will be due to the bound in (26) and the expressions for C j , C j+1 given in Lemma 1. Following exactly the same arguments as before and rewriting the expressions from (35)-(40) taking into account (41) in the process, we can easily conclude that the classical spline introduces the Gibbs phenomenon close to jump discontinuities in the function.

Full Accuracy of the Adapted Hermite Interpolation
Once the first order derivatives have been calculated with O(h 3 ) accuracy, if we use them directly in the expression in (4) without any other enhancement, the interpolation will lose its accuracy at the interval [x j , x j+1 ] that contains the singularity, as it has been analysed in Theorem 3. This is logical, as the interpolation in the interval [x j , x j+1 ] can be seen as a particularization of a linear combination of the polynomials of the Hermite basis, which are continuous. This situation can be solved by defining a piecewise continuous Hermite polynomial at the interval [x j , x j+1 ].

Remark 3
The exact location of jump discontinuities and the definition of the function at x * is lost during the point-values discretization. Thus, to obtain a reconstruction at x * , not only the location of the discontinuity must be provided, but also which of the two definitions corresponds to this point. If the discontinuities are in the derivatives, this problem does not arise, as the function is continuous.
Let us consider the following lemma.

Lemma 2 Let us assume that the first order derivatives of the function at the nodes have been obtained with O(h 3 )
accuracy. Let us assume that the data presents a singularity at x * with x j ≤ x * ≤ x j+1 and, without loss of generality, that we know that f (x * ) belongs to the − side of the function. Then, the local truncation error of the non-corrected spline in the (42) In the interval (x * , x j+1 ] the local truncation error is Proof As mentioned in the lemma, we have two possible cases: • The first one is when the interpolation is being obtained at a position x j ≤ x ≤ x * . In this case, the first order derivative D + j+1 and the data point y + j+1 belong to the + side of the singularity while the interpolation point x is at the − side. We can use the same technique applied before to obtain the correction terms for the first order derivatives in order to assure the accuracy of the interpolation. Let us consider again Fig. 2. In the interval [x j , x j+1 ], the Hermite interpolation in (4) will have the following expression: Now we can use (18) and (21) to obtain an expression of the corrected spline in the interval [x j , x * ]: In fact, the O(h 4 ) term in the previous expression can be written as • The second one is when the interpolation is being obtained at a position x * < x ≤ x j+1 . In this case, the first order derivative D − j and the data y − j belong to the − side of the singularity while the interpolation point x is at the + side. Proceeding as before, we have (47) In the previous expression, the O(h 4 ) term can be written as From (47), we can see that we obtain again a relation between the correction terms for the spline similar to that obtained for the data in (18), Now we have all the necessary tools to prove the following theorem.

Theorem 4 (Accuracy of the corrected Hermite interpolation close to singularities)
Let us consider a piecewise continuous function f that contains a singularity at x * ∈ [x j , x j+1 ] and that is at least four times continuously differentiable on R\{x * }. Let us assume, without loss of generality, that we know that f (x * ) belongs to the − side of the function. Let us also consider that the first order derivatives at the nodes are available with at least O(h 3 ) accuracy. The approximation obtained through the non-corrected Hermite spline for this function satisfies where C + (x), C − (x) are given in Lemma 2. The addition of the correction terms −C − (x) when x ∈ [x j , x * ] and −C + (x) when x ∈ (x * , x j+1 ], i.e. the subtraction of the local truncation error given in Lemma 2 to the approximation obtained by the non-corrected Hermite spline results in the accuracy in any other case, Proof For smooth functions, the error has been analysed in Theorem 1 and is given in (8).
Now we can consider the case when there is a singularity in the interval [x j , x j+1 ]. Looking at the results obtained in expressions (42) and (43) of Lemma 2, we can see the local truncation error obtained when approximating the data using the uncorrected spline. We can just change the sign of the local truncation error, i.e isolate g − j (x) or g + j (x), to write that and to conclude that the addition of the correction terms −C − (x) in the interval [x j , x * ] or −C + (x) in the interval (x * , x j+1 ] allows us to keep the accuracy of the spline close to the singularities. In fact, looking at the O(h 4 ) terms in the local truncation error, we can see that the term in (46) can be roughly bounded by and the one in (48) can be bounded in the same way by Remark 4 Let us assume now that we do not know the exact location of the singularity x * and we approximate it byx * . For simplicity, we can assume thatx * is located to the right of x * at a distance β (which is the error of location). Then, using Taylor's expansion on the jump in the function or the derivatives, we get Therefore, from replacing these expressions in the local truncation error in (42) or (43), we derive that an error in the location of the discontinuity leads to an error of the size of the jump of the function in the interval betweenx * and x * . In the case of jumps in the first order derivative, the problem can be solved computing an accurate enoughx * . Thus, in order to keep order of accuracy O(h 4 ) for the cubic spline, we just need the error of location β to be of order O(h 4 ). It is noteworthy that if there is a false detection of the singularity at a smooth zone, the jumps should be zero (if known a priori) or close enough to zero (if approximated) [31].

Remark 5
Although we have introduced the corrected cubic Hermite spline for cases where the location of the singularities and the jump in the function and its derivatives are known, this information can be approximated numerically in certain instances. When working with data derived from the discretization of piecewise smooth functions, sometimes it is possible to detect the singularities and compute their location. Some kinds of singularities are jump discontinuities in the function and kinks, meaning jumps in the function or the first order derivative respectively. The location of these singularities can be found depending on the discretization of the data used. Kinks can be located using the pointvalue discretization, i.e. a sampling of the function. There is no way of locating the position of jump discontinuities using this kind of discretization: the exact position is lost during the discretization process. For data discretized using point-values, the location of kinks can be obtained, for example, using the classical approach proposed by Harten for his ENO subcell resolution (ENO-SR) algorithm [32,33]. In [32], the authors introduce the ENO-SR algorithm and propose its implementation for the point-values discretization of the data.
Once the location of the singularity has been approximated, it is also possible to approximate the jump in the function and its derivatives using one-sided interpolation. See for example [31] for a detailed explanation about this point.
We will verify the previous assertions in the Numerical experiments section.

Corollary 2 (Error of the second order derivative of the corrected cubic Hermite interpolation) Under the assumptions of Theorem (4), the error for the second order derivative of the corrected cubic Hermite interpolation in the interval that contains the singularity is given by
in any other case, shown in Theorem 4 assures piecewise C 2 regularity of the spline everywhere except at the singularity placed at x * . By repeating the same calculations but eliminating the correction term C − (x) in (51) or C + (x) in (52) we obtain that the jumps in the first order derivative are still zero at x j and x j+1 , and we obtain the jumps in the second order derivative shown in (59) and (60) respectively.
The conclusions reached in Corollary 3 will be verified in the Numerical experiments section (Subsect. 7.3).

The Adaption as a Post-processing Procedure
In this section we will analyse the possibility of correcting the spline as a post-processing. We have two possibilities: the first one is when we want to obtain a smooth function in the interval that contains the singularity; the second one is when we want to obtain a piecewise continuous function in that interval. In the first case we only have to incorporate the correction of the first order derivatives exposed in Sect. 3. In the second case we need to include also the correction shown in Sect. 5. Let us start by the first case.

The Cubic Hermite Spline with Corrected First Order Derivatives as a post-processing procedure
Looking at the right hand side of the system in (33), we can see that the correction of the first order derivatives of the spline can be done as a post-processing, just adding to the solution of the uncorrected spline the solution of the system considering only as right hand side the sparse vector that contains the correction terms. It is clear that the system can be expressed as and it is clear that the term that will add the desired accuracy to the vector is the solution of the system AD = C.
The solutionD of this system will be a vector which, added to the vector of first order derivatives obtained from the classical system of the spline will provide O(h 3 ) accuracy for the first order derivatives even close to the singularities. Looking at the expression of the spline in (38), if we express each particular first order derivative resulting from (61)D = D +D, then the adapted spline can be expressed as The termg i (x) can be interpreted as a spline where the function values are zero and the first order derivatives are different from zero. It can be added as a post-processing of the classical Hermite spline in order to attain O(h 3 ) order of accuracy for the first order derivatives at the nodes.
In [34] p. 22, the authors provide a very efficient algorithm for solving tridiagonal systems with dominant main diagonal, like the ones in (25) and (33). If we have the equations then we can compute for j = 1, 2, . . . , m, The successive elimination of x 1 , x 2 , . . . , x m−1 from the second, third, . . . , mth equations yields the equivalent system of equations where x m , x m−1 , . . . , x 1 are evaluated successively. We note that the quantities p j and q j depend on the mesh but not on the ordinates at the mesh nodes (that only appear in the d j in (65)). Thus, the correction can be calculated very efficiently once the p j 's and q j 's of the classical spline have been computed, as we are only changing the right hand side of the system of equations of the classical spline, i.e. the d j 's.

The Fully Accurate Cubic Hermite Spline as a Post-processing Procedure
The fully accurate spline presents differences with the one presented in the previous subsection only at the interval [x j , x j+1 ] that contains the singularity. Thus, it is possible to express the corrected spline with corrected first order derivatives inside that interval g j (x) as

Numerical Experiments
In this section we analyse the accuracy obtained when computing the corrected first order derivatives proposed in Sect. 3 and in the interpolation obtained through the corrected Hermite spline described in Sect. 5. We will compare the results of the corrected Hermite spline with those obtained by the classical non-corrected spline.

Accuracy Analysis of the Interpolation, First and Second Order Derivatives Obtained Through the Classical and Corrected Splines
Let us try to analyse the accuracy of the interpolation, first and second order derivatives attained by the corrected and non-corrected spline. We will consider that we start from discretized data that comes from the sampling of a function. The location of the discontinuity will be considered known in the case of jump discontinuities in the function. When the jumps are in the first order derivative, we will obtain approximations of its location using the algorithm in [32] (See, for example, the plot to the right in Fig. 3).
In order to check the accuracy of the spline between the nodes or the first and second order derivatives at the nodes, we can perform a grid refinement analysis. For the approximation of the derivatives, we can just obtain analytically the corresponding derivative of the function and compare it with the approximation of the derivative obtained through the spline for each step of the refinement analysis. The process for this grid refinement analysis will be the following: 1. Sample the function at a high resolution with the mesh size h 0 and keep this data to check the error. 2. Subsample the high resolution data using a mesh size h 1 to obtain the nodes of the spline. 3. Obtain the analytical first and second order derivatives of the function at the nodes obtained in the previous step. 4. Compute the spline with the low resolution nodes. 5. Compute the errors for the first order derivative at the low resolution nodes and for the function and the second order derivative at the high resolution data. 6. Reduce the mesh size for the high resolution data and between nodes so that h 0 = h 0 2 , h 1 = h 1 2 and go back to step 1. Once we have the errors for the data, the first, and the second order derivative for all the refinement steps, we can just apply the classical formula for approximating the numerical accuracy, using the infinity norm E l = || f l −f l || L ∞ , where we have denoted the grid refinement step with the super index l.

Experiment 1: A Function with a Jump Discontinuity
For this first experiment we have chosen the function in (68), which corresponds to a function with jumps in the function and the first four derivatives: In this case, we assume that we know the location of the discontinuity, but we approximate the jumps in the function and the derivatives using one-sided interpolation [31].
In this experiment we have set the relation between the high resolution data and the nodes to h 1 h 0 = 32, which means that we take one point of every 32 points of the high resolution data to obtain the low resolution data, i.e. the nodes of the spline. Thus, the low resolution nodes have been sampled with m = 2 l nodes and the high resolution data with 32m points. The results are shown in Table 1 for the interpolation of the spline at the high resolution data obtained from the low resolution data, in Table 2 for the first order derivative at the nodes and in Table 3 for the second order derivative at the high resolution data points. We can see that the accuracy obtained by the corrected spline between the nodes tends to O(h 4 ) when h goes to zero and to O(1) for the classical spline. The accuracy of the first order derivative at the nodes tends to O(h 3 ) for the corrected spline and to O(1/h) for the classical one. The accuracy of the second order derivative at the high resolution data tends to O(h 2 ) for the corrected spline and to O(1/h 2 ) for the classical one. These results have been also presented in Fig. 4, in a semilogarithmic scale in order to show the numerical decreasing of the error and to compare it with the theoretical one, which has been represented with dashed blue lines. In the plot to the left of this figure we can see the errors obtained by the classical spline (stars in red) and by the corrected spline (stars in blue) at the high resolution nodes. The slope of the dashed lines represents the decreasing of the error of the classical spline with order of accuracy O(1) and with O(h 4 ) for the corrected spline. At the center we present the errors in the first order derivatives at the low resolution nodes (resulting from the solution of the system of equations of the spline) for each spline with the same markers. The slope of the dashed lines represent again the decreasing of the error for the classical spline with O 1 h accuracy and with O(h 3 ) for the corrected spline. The plot to the right shows the errors obtained in the second order derivative at the high resolution nodes. In this case, the slope of the dashed lines represents the decreasing of the error for the classical spline with O 1 h 2 accuracy and with O(h 2 ) for the corrected spline. In Subsect. 7.2 we show that the loss of accuracy of the classical approach is due, among other things, to Gibbs-like oscillations close to the discontinuity.

Experiment 2: A Function with a Discontinuity in the Derivatives
For the second experiment we have chosen the function in (69) which corresponds to a function with jumps in the odd derivatives. In this case, we approximate the location of the singularity with O(h 4 ) accuracy using the algorithm in [32], and we also approximate the jumps in the function (which in this case is zero) and the derivatives [31]. Following the same setting as in the previous experiment, the results are shown  The original data has been sampled from the function in (68). The low resolution nodes have been sampled with m = 2 l nodes and the high resolution data with 32m points Table 2 Grid refinement analysis for the accuracy of the first order derivative at the low resolution nodes of the corrected and classical splines using the infinity norm m = 2 l The original data has been sampled from the function in (68). The low resolution nodes have been sampled with m = 2 l nodes and the high resolution data with 32m points Table 3 Grid refinement analysis for the accuracy of the second order derivatives at the high resolution nodes of the corrected and classical splines using the infinity norm m = 2 l The original data has been sampled from the function in (68). The low resolution nodes have been sampled with m = 2 l nodes and the high resolution data with 32m points Fig. 4 In this figure we represent the results of the grid refinement analysis for the accuracy of the corrected and classical splines and their first and second order derivatives using the infinity norm shown in Tables 1, 2 and 3. The original data has been sampled from the function in (68). In the first row we show the error E l for the corrected and classical spline, in the second one we show the error for the first order derivative, and finally, the error for the second order derivative. The x axis represents de resolution level l: the increase of l implies the reduction of the grid-spacing of the low resolution data. Thus, the slope of the dashed lines represents the accuracy of each method  Tables 4, 5 and 6. The original data has been sampled from the function in (69). As in Fig. 4, in the first row we show the error E l for the corrected and classical spline, in the second one we show the error for the first order derivative, and finally, the error for the second order derivative. The x axis represents de resolution level l: the increase of l implies the reduction of the grid-spacing of the low resolution data. Thus, the slope of the dashed lines represents the accuracy of each method in Table 4 for the interpolation of the spline, in Table 5 for the first order derivatives at the nodes and in Table 6 for the second order derivative of the spline at the high resolution data points. It can be observed that with the corrected spline we are capable of obtaining high resolution approximations of the function, the first and the second order derivatives, while with the classical spline the approximations are affected by the presence of the singularity. These results have been presented in Fig. 5, where the slope of the dashed blue lines represent again the theoretical decreasing of the error for each case. In this figure we represent the results of the grid refinement analysis for the accuracy of the corrected and classical splines and their first and second order derivatives using the infinity norm shown in Tables 4, 5 and 6.

Elimination of the Gibbs Phenomenon Using Adapted First Order Derivatives
In this section we will analyse the behaviour of the corrected spline, the classical spline with corrected first order derivatives and the classical spline close to discontinuities. In order to do so, we will use the function in (68), which presents a jump discontinuity. As in Subsect. 7.1.1, we assume that we know the location of the discontinuity for this function, but we approximate the jumps in the function and the derivatives using one-sided interpolation [31]. The results of the experiments are shown in Fig. 6. In the first row, we present the approximation (red Table 4 Grid refinement analysis for the accuracy of the corrected and classical splines using the infinity norm at the high resolution nodes The original data has been sampled from the function in (69). The low resolution nodes have been sampled with m = 2 l nodes and the high resolution data with 32m points The original data has been sampled from the function in (69). The low resolution nodes have been sampled with m = 2 l nodes and the high resolution data with 32m points Table 6 Grid refinement analysis for the accuracy of the second order derivatives at the high resolution nodes of the corrected and classical splines using the infinity norm m = 2 l The original data has been sampled from the function in (69). The low resolution nodes have been sampled with m = 2 l nodes and the high resolution data with 32m points circles) of the function in (68) sampled with a high resolution of 256 points (blue crosses) and then subsampled to obtain 16 points (solid black circles) in order to obtain the low resolution data. We can see that the classical spline (first row, plot to the left) shows Gibbs oscillations close to the discontinuity. If we correct the first order derivatives of the spline and we do not use any correction for the spline itself (first row, central plot), we obtain an approximation that is free of oscillations close to the discontinuity, but that presents diffusion in the interval that contains the discontinuity. If we use the corrected first order derivatives and we also correct the approximation of the spline close to the discontinuity (first row, plot to the right), we can obtain a piecewise continuous function without oscillations close to the discontinuity. The second row of Fig. 6 shows the error obtained in the computation of the first order derivatives at the low resolution nodes for each spline: to the left we show the result of the classical spline and at the center and to the right, the error for corrected first order derivatives (which are the same both for the classical spline with corrected first order derivatives and for the corrected spline). The third row shows the error at the high resolution nodes attained by each of the splines in the same order. From these plots we can see that the use of corrected first order derivatives leads to the elimination of the Gibbs oscillations close to the discontinuities. If we also correct the interpolation of the spline, it is possible to obtain a piecewise continuous function with high accuracy even close to the discontinuities.

Regularity
In this subsection we will analyse the behaviour of the first and second order derivatives between the nodes for the classical spline, the classical spline with corrected first order derivatives and the corrected spline with corrected first order derivatives. As before, for the function in (68), we assume that we know the location of the discontinuity, and, for the function in (69), we approximate the location of the singularity with O(h 4 ) [32]. In both cases we approximate the jumps in the function and the derivatives using one-sided interpolation [31]. Figures 7 and 8 show the results obtained for the functions in (68) and (69) respectively. In both figures, the approximation of the first order derivative of the functions is shown in the first column, and the approximation for the second order derivatives is shown in the second column. Functions in (68) and (69) are sampled with 16 points to obtain the low resolution data. Then, each polynomial piece of the spline is differentiated once or twice to obtain the results shown in Figs. 7 and 8. We have represented some points of the first or the second order derivative of the function with blue dots. The stars represent a sampling of the first or the second order derivatives of each one of the polynomial pieces of the spline g(x). Each polynomial piece is represented with a different colour. Our objective is just to compare qualitatively the first and second order derivatives of the functions, and the approximations obtained through each spline. In each of the two figures, the first row presents the result for the classical spline, and the second row shows the result for the classical spline with corrected first order derivatives. Finally, the third row shows the results for the corrected spline with corrected first order derivatives. It is clear that the classical spline introduces oscillations in the first and the second order derivatives close to the singularities, but maintains the C 2 regularity in the whole domain. The results also show that the modification of the right hand side of the system of equations of the spline in (33) eliminates the oscillations in the function outside the interval that contains the singularity, but leads to the loss of the regularity in the second order derivative if the spline is not corrected, as discussed in Corollary 3. Only the corrected spline with corrected first order derivatives, discussed in Sect. 5, allows for the Fig. 6 In the first row, we present the reconstruction or approximation g(x) of the function in (68) with red circles. Initially we sample the function at a high resolution of 256 points and we represent it with blue crosses. Then we subsample the data to obtain a low resolution version of 16 points, and we represent it with solid black circles. The second and third row are dedicated to present the error in the first and second order derivatives, respectively. The first column presents the results of the classical cubic Hermite spline, the second one presents those obtained by the classical cubic Hermite spline with corrected first order derivatives. Finally, the third one presents the results attained by the corrected cubic Hermite spline with corrected first order derivatives (Color figure online) elimination of the oscillations and keeps the correct piecewise regularity of the function from which the data has been obtained.

Conclusion
In this article we have presented a new technique that allows for the correction of the first order derivatives and the approximation obtained through cubic Hermite splines close to singularities. The technique consists in taking into account the effect introduced by the singularity by adding correction terms, in order to assure a high order of accuracy close to the singularities. The correction can be included in the right hand side of the system of the spline, allowing for its application as a post-processing. It has been shown theoretically that the correction of the first order derivatives eliminates the Gibbs phenomenon introduced by the classical spline close to jump discontinuities. Through the correction introduced in the system of equations of the spline, we obtain accurate first order derivatives even close to the singularities. Thus we have also discussed the theoretical accuracy in the infinity norm obtained through the correction of the first order derivatives. Even so, diffusion is always present in the interval that contains a jump discontinuity if we only correct the first order derivatives of the spline. If the correction is also introduced in the equation of the spline (1) in the interval that contains the singularity, it is possible to approximate accurately piecewise Funding Dr. Z. Li has been partially supported by a Simon's grant 633724 and by Fundación Séneca grant 21760/IV/22 (Este trabajo es resultado de la estancia (21760/IV/22) financiada por la Fundación Seńeca-Agencia de Ciencia y Tecnología de la Región de Murcia con cargo al Programa Regional de Movilidad, Colaboración Internacional e Intercambio de Conocimiento "Jiménez de la Espada". (Plan de Actuación 2022)), the rest of the authors by the project 20928/PI/18 funded by Fundación Séneca (Proyecto financiado por la Comunidad Autónoma de la Región de Murcia a través de la convocatoria de Ayudas a proyectos para el desarrollo de investigación científica y técnica por grupos competitivos, incluida en el Programa Regional de Fomento de la Investigación Científica y Técnica (Plan de Actuación 2018) de la Fundación Séneca-Agencia de Ciencia y Tecnología de la Región de Murcia) and by the Spanish national research project PID2019-108336GB-I00. Dr. Juan Ruiz has also been funded by Fundación Séneca grant 21728/EE/22 (Este trabajo es resultado de la estancia (21728/EE/22) financiada por la Fundación Séneca-Agencia de Ciencia y Tecnología de la Región de Murcia con cargo al Programa Regional de Movilidad, Colaboración Internacional e Intercambio de Conocimiento "Jiménez de la Espada". (Plan de Actuación 2022)).
Data Availability All data generated or analysed during this study are included in this published article.
Code Availability Custom code.

Conflict of interest
The authors declare that they have no conflict of interest.

Consent for publication Not applicable.
Consent to participate Not applicable.
Ethical approval Not applicable.
Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder.