On
mathematicsMathematics is the study of quantity, space, structure, and change. Mathematicians seek out patterns and formulate new conjectures. Mathematicians resolve the truth or falsity of conjectures by mathematical proofs, which are arguments sufficient to convince other mathematicians of their validity...
, a
piecewise-defined function (also called a
piecewise function) is a
functionIn mathematics, a function associates one quantity, the argument of the function, also known as the input, with another quantity, the value of the function, also known as the output. A function assigns exactly one output to each input. The argument and the value may be real numbers, but they can...
whose definition changes depending on the value of the
independent variableThe terms "dependent variable" and "independent variable" are used in similar but subtly different ways in mathematics and statistics as part of the standard terminology in those subjects...
. Mathematically, a
realIn mathematics, a real number is a value that represents a quantity along a continuum, such as -5 , 4/3 , 8.6 , √2 and π...
-valued function
f of a real
variableIn mathematics, a variable is a value that may change within the scope of a given problem or set of operations. In contrast, a constant is a value that remains unchanged, though often unknown or undetermined. The concepts of constants and variables are fundamental to many areas of mathematics and...
x is a relationship whose definition is given differently on disjoint subsets of its
domainIn mathematics, the domain of definition or simply the domain of a function is the set of "input" or argument values for which the function is defined...
(known as subdomains).
The word
piecewise is also used to describe any property of a piecewise-defined function that holds for each piece but may not hold for the whole domain of the function. A function is
piecewise differentiable or
piecewise continuously differentiable if each piece is differentiable throughout its domain. In
convex analysisConvex analysis is the branch of mathematics devoted to the study of properties of convex functions and convex sets, often with applications in convex minimization, a subdomain of optimization theory....
, the notion of a derivative may be replaced by that of the
subderivativeIn mathematics, the concepts of subderivative, subgradient, and subdifferential arise in convex analysis, that is, in the study of convex functions, often in connection to convex optimization....
for piecewise functions. Although the "pieces" in a piecewise definition need not be
intervalsIn mathematics, a interval is a set of real numbers with the property that any number that lies between two numbers in the set is also included in the set. For example, the set of all numbers satisfying is an interval which contains and , as well as all numbers between them...
, a function isn't called "piecewise linear" or "piecewise continuous" or "piecewise differentiable" unless the pieces are intervals.
Notation and interpretation
Piecewise functions are defined using the common functional notation, where the body of the function is an array of functions and associated subdomains. For example, consider the piecewise definition of the
absolute valueIn mathematics, the absolute value |a| of a real number a is the numerical value of a without regard to its sign. So, for example, the absolute value of 3 is 3, and the absolute value of -3 is also 3...
function:

For all values of
x less than zero, the first function (−
x) is used, which negates the sign of the input value, making negative numbers positive. For all values of
x greater than or equal to zero, the second function (
x) is used, which evaluates trivially to the input value itself.
Consider the piecewise function
f(
x) evaluated at certain values of
x:
| x |
f(x) |
Function used |
| −3 |
3 |
−x |
| −0.1 |
0.1 |
−x |
| 0 |
0 |
x |
| 1/2 |
1/2 |
x |
| 5 |
5 |
x |
Thus, in order to evaluate a piecewise function at a given input value, the appropriate subdomain needs to be chosen in order to select the correct function and produce the correct output value.
Continuity
A piecewise function is
continuousIn mathematics, a continuous function is a function for which, intuitively, "small" changes in the input result in "small" changes in the output. Otherwise, a function is said to be "discontinuous". A continuous function with a continuous inverse function is called "bicontinuous".Continuity of...
on a given interval if the following conditions are met:
- it is defined throughout that interval
- its constituent functions are continuous on that interval
- there is no discontinuity at each endpoint of the subdomains within that interval.
The pictured function, for example, is piecewise continuous throughout its subdomains, but is not continuous on the entire domain. The pictured function contains a jump discontinuity at

.
Common examples
- Absolute value
In mathematics, the absolute value |a| of a real number a is the numerical value of a without regard to its sign. So, for example, the absolute value of 3 is 3, and the absolute value of -3 is also 3...
- Heaviside step function
The Heaviside step function, or the unit step function, usually denoted by H , is a discontinuous function whose value is zero for negative argument and one for positive argument....
- Piecewise linear function
- PDIFF
In geometric topology, PDIFF, for piecewise differentiable, is the category of piecewise-smooth manifolds and piecewise-smooth maps between them...
- sign function (sgn)
In mathematics, the sign function is an odd mathematical function that extracts the sign of a real number. To avoid confusion with the sine function, this function is often called the signum function ....
- Spline
In mathematics, a spline is a sufficiently smooth piecewise-polynomial function. In interpolating problems, spline interpolation is often preferred to polynomial interpolation because it yields similar results, even when using low-degree polynomials, while avoiding Runge's phenomenon for higher...
- B-spline
In the mathematical subfield of numerical analysis, a B-spline is a spline function that has minimal support with respect to a given degree, smoothness, and domain partition. B-splines were investigated as early as the nineteenth century by Nikolai Lobachevsky...