# Differentiation rule for piecewise definition by interval

View other differentiation rules

## Statement

### Everywhere version

Suppose $f_1$ and $f_2$ are functions of one variable, such that both of the functions are defined and differentiable everywhere. Consider a function $f$, defined as follows:

$f(x) := \left\lbrace \begin{array}{rl} f_1(x), & x < c \\ f_2(x), & c < x \\v, & x = c \end{array}\right.$

Then, we have the following for continuity:

• The left hand limit of $f$ at $c$ equals $f_1(c)$.
• The right hand limit of $f$ at $c$ equals $f_2(c)$.
• $f$ is left continuous at $c$ iff $v = f_1(c)$.
• $f$ is right continuous at $c$ iff $v = f_2(c)$.
• $f$ is continuous at $c$ iff $f_1(c) = f_2(c) = v$.

We have the following for differentiability:

• $f$ is left differentiable at $c$ iff $v = f_1(c)$, and in this case, the left hand derivative equals $f_1'(c)$.
• $f$ is right differentiable at $c$ iff $v = f_2(c)$, and in this case, the right hand derivative equals $f_2'(c)$.
• $f$ is differentiable at $c$ iff ($v = f_1(c) = f_2(c)$ and $f_1'(c) = f_2'(c)$), and in this case, the derivative equals the equal values $f_1'(c)$ and $f_2'(c)$.

### Piecewise definition of derivative

If the conditions for differentiability at $c$ are violated, we get the following piecewise definition for $f'$, which excludes the point $c$ from its domain:

$f'(x) := \left \lbrace \begin{array}{rl} f_1'(x), & x < c \\ f_2'(x), & x > c \\\end{array}\right.$

If the conditions for differentiability at $c$ are satisfied, we get the following piecewise definition for $f'$, which includes the point $c$ in its domain:

$f'(x) := \left \lbrace \begin{array}{rl} f_1'(x), & x < c \\ f_2'(x), & x > c \\ u, & x = c\end{array}\right.$

where $u = f_1'(c) = f_2'(c)$. In particular, the value at $c$ can be included in either the left side or the right side definition.

### Version for higher derivatives

Suppose $f_1$ and $f_2$ are functions of one variable, such that both of the functions are defined and $k$ times differentiable everywhere (and hence in particular the functions and their first $k-1$ derivatives are continuous), for some positive integer $k$. Consider the function:

$f(x) := \left\lbrace \begin{array}{rl} f_1(x), & x < c \\ f_2(x), & x > c \\v, & x = c \end{array}\right.$

Then, $f$ is $k$ times differentiable at $c$ if we have all these conditions: $\! f_1(c) = f_2(c) = v$, $\! f_1'(c) = f_2'(c)$, $\! \dots$, $f_1^{(k)}(c) = f_2^{(k)}(c)$. In other words, the values should match, and the values of each of the derivatives up to the $k^{th}$ derivative should match. In that case, the $k^{th}$ derivative of $f$ at $c$ equals the equal values $f_1^{(k)}(c) = f_2^{(k)}(c)$.

The general piecewise definition of $f^{(k)}$ is, in this case:

$f^{(k)}(x) := \left \lbrace \begin{array}{rl} f_1^{(k)}(x), & x < c \\ f_2^{(k)}(x), & x > c \\ u_k, & x = c\end{array}\right.$

where $u_k = f_1^{(k)}(c) = f_2^{(k)}(c)$.

### Local generalization

The above holds with the following modification: we only require $f$ to be defined as $f_1$ on the immediate left of $c$ (i.e., on some interval of the form $(c - \delta,c)$ for $\delta > 0$ and as $f_2$ on the immediate right of $c$ (i.e., on some interval of the form $(c,c + \delta)$ for $\delta > 0$). Further, we only require that $f_1$ and $f_2$ be defined and differentiable on open intervals containing $c$, not necessarily on all of $\R$.

## Examples

### Example of piecewise rational function

This example is covered in the video embedded above.

Consider the function:

$f(x) := \left\lbrace \begin{array}{rl} \frac{1}{x - 1}, & x < 0 \\ \frac{-1}{x + 1}, & x > 0 \\ -1, & x = 0 \\\end{array}\right.$

Note that here, in the notation we have used, we have:

$f_1(x) = \frac{1}{x - 1}, \qquad f_2(x) = \frac{-1}{x + 1}, \qquad c = 0, \qquad v = -1$

Note that the function $f_1$ is defined around zero, i.e., the definition extends to the point zero and the immediate right -- in fact, $f_1$ is defined and infinitely differentiable on the interval $(-\infty,1)$.

Similarly, $f_2$ is defined around zero, i.e., i.e., the definition extends to the immediate left of zero -- in fact, $f_2$ is defined and infinitely differentiable on the interval $(-1,\infty)$.

Thus, we see that:

• $f_1(0) = 1/(0 - 1) = -1$, $f_2(0) = -1/(0 + 1) = -1$, and $f(0) = v = -1$. Thus, we see that $f_1(0) = f_2(0) = v = -1$, so the function $f$ is continuous at 0.
• We have $f_1'(x) = -1/(x - 1)^2$ and $f_2'(x) = 1/(x + 1)^2$. We see that $f_1'(0) = -1/(0-1)^2 = -1$ and $f_2'(0) = 1/(0 + 1)^2 = 1$. We see that $f_1'(0) \ne f_2'(0)$, so $f$ is not differentiable at 0.

This means that the first and higher derivatives of $f$ do not exist at 0.

### Example of piecewise polynomial function

This example is covered in the video embedded above.

Consider the function:

$f(x) := \lbrace \begin{array}{rl} x^2, & x < 0 \\ x^3 + x, & x > 0 \\ 0, & x = 0 \\\end{array}$

Here:

$f_1(x) := x^2, \qquad f_2(x) := x^3 + x, \qquad c = 0, \qquad v = 0$

We see that:

• $f_1(0) = 0^2 = 0$, $f_2(0) = 0^3 + 0 = 0$, and $v = 0$. Thus, $f_1(0) = f_2(0) = v$, so $f$ is continuous at 0.
• $f_1'(x) = 2x$ and $f_2'(x) = 3x^2 + 1$. Evaluated at 0, we get $f_1'(0) = 0$ and $f_2'(0) = 1$, so $f_1'(0) \ne f_2'(0)$. So, $f$ is not differentiable at 0.

### Example of piecewise polynomial function: higher derivatives

This example is covered in the video embedded above.

Consider the function:

$f(x) := \left\lbrace \begin{array}{rl} x^2, & x < 0 \\ x^3 + x^2, & x > 0 \\ 0, & x = 0 \\\end{array}\right.$

Here, $c = 0, v = 0, f_1(x) = x^2, f_2(x) = x^3 + x^2$. To keep track of what we're doing, we make a table:

Expression for $f_1$ Value for $f_1$ at 0 Expression for $f_2$ Value for $f_2$ at 0 Conclusion Explanation
Function $f_1(x) = x^2$ $f_1(0) = 0^2 = 0$ $f_2(x) = x^3 + x^2$ $f_2(0) = 0^3 + 0^2 = 0$ $f$ is continuous at 0 We are also given that the function value at 0 is 0. Thus, $f_1(0) = f_2(0) = v = 0$. So, $f$ is continuous at 0.
First derivative $f_1'(x) = 2x$ $f_1'(0) = 2(0) = 0$ $f_2'(x) = 3x^2 + 2x$ $f_2'(0) = 3(0)^2 + 2(0) = 0$ $f$ is differentiable at 0, and $f'(0) = 0$ We already checked continuity, and we have now checked that $f_1'(0) = f_2'(0)$.
Second derivative $f_1''(x) = 2$ $f_1''(0) = 2$ $f_2''(x) = 6x + 2$ $f_2''(0) = 6(0) + 2 = 2$ $f$ is twice differentiable at 0, and $f''(0)= 2$ We already checked differentiability. Thus, it suffices to check that $f_1''(0) = f_2''(0)$, which is true since both equal 2.
Third derivative $f_1'''(x) = 0$ $f_1'''(0) = 0$ $f_2'''(x) = 6$ $f_2'''(0) = 6$ $f$ is not thrice differentiable at 0 We have $f_1'''(0) = 0 \ne f_2'''(0) = 6$.

Note that no higher derivative of $f$ exists at zero. For instance, we do have that $f_1^{(4)}(0) = 0 = f_2^{(4)}(0)$, but $f^{(4)}(0)$ does not exist.

Here are the explicit piecewise definitions for the derivatives of $f$:

$f'(x) = \left\lbrace\begin{array}{rl} 2x, & x < 0 \\ 3x^2 + 2x, & x > 0 \\ 0, & x = 0 \\\end{array}\right.$

$f''(x) = \left\lbrace\begin{array}{rl} 2, & x < 0 \\ 6x + 2, & x > 0 \\ 2, & x = 0 \\\end{array}\right.$

$f'''(x) = \left\lbrace\begin{array}{rl} 0, & x < 0 \\ 6, & x > 0 \\\end{array} \right.$

Note that $f'''$ is not defined at 0.

For $k \ge 4$, we have:

$f^{(k)}(x) = \left\lbrace\begin{array}{rl} 0, & x < 0 \\ 0, & x > 0 \\\end{array} \right.$

But $f^{(k)}(0)$ does not exist.

## Caveat

In situations where the definitions given on one side of a point do not extend naturally to the point, we cannot use the above methods. In most such cases, we need to go back to the original definition of the derivative as a limit of a difference quotient.