In mathematics, a piecewise function (also called a piecewise-defined function, a hybrid function, or a function defined by cases) is a function whose domain is partitioned into several intervals ("subdomains") on which the function may be defined differently. Piecewise definition is actually a way of specifying the function, rather than a characteristic of the resulting function itself, as every function whose domain contains at least two points can be rewritten as a piecewise function. The first three paragraphs of this article only deal with this first meaning of "piecewise". Terms like piecewise linear, piecewise smooth, piecewise continuous, and others are also very common. The meaning of a function being piecewise P {\displaystyle P} , for a property P {\displaystyle P} , is roughly that the domain of the function can be partitioned into pieces on which the property P {\displaystyle P} holds, but this term is used slightly differently by different authors. Unlike the first meaning, this is a property of the function itself and not only a way to specify it. Sometimes the term is used in a more global sense involving triangulations; see Piecewise linear manifold.
Notation and interpretation
Piecewise functions can be defined using the common functional notation, where the body of the function is an array of functions and associated subdomains. A semicolon or comma may follow the subfunction or subdomain columns. The if {\displaystyle {\text{if}}} or for {\displaystyle {\text{for}}} is rarely omitted at the start of the right column. The subdomains together must cover the whole domain; sometimes it is also required that they are pairwise disjoint, i.e. form a partition of the domain. This is enough for a function to be "defined by cases", but in order for the overall function to be "piecewise", the subdomains are typically required to be nonempty intervals (some may be degenerate intervals, i.e. single points or unbounded intervals) and they are often not allowed to have infinitely many subdomains in any bounded interval. This means that functions with bounded domains will only have finitely many subdomains, while functions with unbounded domains can have infinitely many subdomains, as long as they are appropriately spread out. As an example, consider the piecewise definition of the absolute value function:
| x | = { − x , if x < 0 + x , if x ≥ 0. {\displaystyle |x|={\begin{cases}-x,&{\text{if }}x<0\\+x,&{\text{if }}x\geq 0.\end{cases}}}
For all values of x {\displaystyle x} less than zero, the first sub-function ( − x {\displaystyle -x} ) is used, which negates the sign of the input value, making negative numbers positive. For all values of x {\displaystyle x} greater than or equal to zero, the second sub-function ( x {\displaystyle x} ) is used, which evaluates trivially to the input value itself. The following table documents the absolute value function at certain values of x {\displaystyle x} :
In order to evaluate a piecewise-defined function at a given input value, the appropriate subdomain needs to be chosen in order to select the correct sub-function—and produce the correct output value.
Examples A step function or piecewise constant function, composed of constant sub-functions Piecewise linear function, composed of linear sub-functions Piecewise smooth function, composed of smooth sub-functions Broken power law, a function composed of power-law sub-functions Spline, a function composed of polynomial sub-functions, often constrained to be smooth at the joints between pieces B-spline
f ( x ) = { exp ( − 1 1 − x 2 ) , x ∈ ( − 1 , 1 ) 0 , otherwise {\displaystyle f(x)={\begin{cases}\exp \left(-{\frac {1}{1-x^{2}}}\right),&x\in (-1,1)\\0,&{\text{otherwise}}\end{cases}}} and some other common Bump functions. These are infinitely differentiable, but analyticity holds only piecewise.
Continuity and differentiability of piecewise-defined functions
A piecewise-defined function is continuous on a given interval in its domain if the following conditions are met:
… excerpt ends here. Continue reading the full article.



![Piecewise function: The function
f
(
x
)
=
min
(
1
,
x
2
)
{\displaystyle f(x)=\min(1,x^{2})}
is piecewise monotonic (subdomains
(
−
∞
,
0
]
{\displaystyle (-\infty ,0]}
,
[
0
,
+
∞
)
{\displaystyle [0,+\infty )}
) and piecewise differentiable (subdomains
(
−
∞
,
−
1
]
{\displaystyle (-\infty ,-1]}
,
[
−
1
,
+
1
]
{\displaystyle [-1,+1]}
, and
[
+
1
,
+
∞
)
{\displaystyle [+1,+\infty )}
).](https://upload.wikimedia.org/wikipedia/commons/thumb/8/86/PiecewiseMonoDiff_svg.svg/1280px-PiecewiseMonoDiff_svg.svg.png?utm_source=en.wikipedia.org&utm_campaign=parser&utm_content=thumbnail)

