This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed. Find sources: "Piecewise function" – news ·newspapers ·books ·scholar ·JSTOR(March 2017) (Learn how and when to remove this message) |

Inmathematics, apiecewise function (also called apiecewise-defined function, ahybrid function, or afunction defined by cases) is afunction whosedomain ispartitioned into severalintervals ("subdomains") on which the function may be defined differently.[1][2][3] 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 likepiecewise linear,piecewise smooth,piecewise continuous, and others are also very common. The meaning of a function being piecewise, for a property, is roughly that the domain of the function can be partitioned into pieces on which the property holds, but this term is used slightly differently by different authors.[4][5] 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; seePiecewise linear manifold.


Piecewise functions can be defined using the commonfunctional 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.[2] The or is rarely omitted at the start of the right column.[2]
The subdomains together must cover the wholedomain; sometimes it is also required that they are pairwise disjoint, i.e. form a partition of the domain.[6] 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 theabsolute value function:[2]For all values of less than zero, the first sub-function () is used, which negates the sign of the input value, making negative numbers positive. For all values of greater than or equal to zero, the second sub-function() is used, which evaluates trivially to the input value itself.
The following table documents the absolute value function at certain values of:
| x | f(x) | Sub-function used |
|---|---|---|
| −3 | 3 | |
| −0.1 | 0.1 | |
| 0 | 0 | |
| 1/2 | 1/2 | |
| 5 | 5 |
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.

A piecewise-defined function iscontinuous on a given interval in its domain if the following conditions are met:
The pictured function, for example, is piecewise-continuous throughout its subdomains, but is not continuous on the entire domain, as it contains a jump discontinuity at. The filled circle indicates that the value of the right sub-function is used in this position.
For a piecewise-defined function to be differentiable on a given interval in its domain, the following conditions have to fulfilled in addition to those for continuity above:
In applied mathematical analysis, "piecewise-regular" functions have been found to be consistent with manymodels of the human visual system, where images are perceived at a first stage as consisting of smooth regions separated by edges (as in acartoon);[10]acartoon-like function is aC2 function, smooth except for the existence of discontinuity curves.[11]In particular,shearlets have been used as a representation system to provide sparse approximations of this model class in 2D and 3D.
Piecewise defined functions are also commonly used for interpolation, such as innearest-neighbor interpolation.
{{cite journal}}: CS1 maint: DOI inactive as of August 2025 (link)