Definition · Piecewise functionA piecewise function is defined by splitting its domain into pieces and giving a formula for each piece. The cleanest definition uses conditions that partition the domain, so each input selects exactly one piece. Overlap is also legal when every formula that applies gives the same output; conflicting outputs are what violate the function definition.
The most familiar example was written down long before the notation was: absolute value. |x| is x when x is at least zero and −x when x is negative, which is two formulas and a condition. “Absolute Value” in Foundations of Algebra called the two cases a definition; the piecewise brace is that definition typeset.
x if x >= 0
|x| =
-x if x < 0
|-7| = -(-7) = 7 the second line, because -7 < 0
| 7| = 7 the first line
Note that the second formula, −x, produces positive outputs. It looks as though it should produce negative ones, and that reading is what makes |x| = −x seem wrong. The minus sign is applied to an input that is already negative.
A three-piece example
Take the function in the box at the top of this page: −x − 1 below −1, x² from −1 up to but not including 2, and 8 − 2x from 2 upward. The conditions cover every real number once, so the domain is every real number.
f(-3) = -(-3) - 1 = 2 -3 < -1 first piece
f(-1) = (-1)^2 = 1 -1 <= -1 < 2 second piece
f( 0) = 0^2 = 0 second piece
f( 2) = 8 - 2(2) = 4 2 >= 2 third piece
f( 5) = 8 - 2(5) = -2 third piece
the wrong branch at x = -1: 8 - 2(-1) = 10 condition fails
The last line is the error this lesson exists to prevent. 10 is a real number produced by a real formula belonging to this very piecewise definition, and nothing about it looks suspect. It is not f(−1), because the condition x ≥ 2 rules that branch out. The number 10 is in fact produced elsewhere by this function; branch selection decides the value at the requested input, not whether the number appears anywhere in the range.
What happens at a join
At x = −1 the two neighbouring formulas disagree. Approaching from the left, −x − 1 heads toward 0; the value the function actually takes there is (−1)² = 1. The graph steps up by 1, and it is drawn with an open circle at (−1, 0) and a filled circle at (−1, 1).
At x = 2 they agree. The left formula x² heads toward 4, and the right formula gives 8 − 2(2) = 4. The two pieces meet, so the graph connects with no break and no circles are needed. Whether a join is a step or a connection is settled by arithmetic, not by how the formulas look.
join at x = -1 left formula -x - 1 -> 0
value used x^2 -> 1 step of 1
join at x = 2 left formula x^2 -> 4
value used 8 - 2x -> 4 they meet
Endpoints, and where the dot goes
- A filled circle marks a point the function attains. Every input in the domain gets exactly one filled circle in the whole picture.
- An open circle marks a point the graph approaches but does not include, because the condition on that piece excluded the endpoint.
- A vertical stack of two different filled circles is impossible. Two filled circles above the same input would be two outputs, and the vertical line test from “What a Function Is” rules it out on sight. Two pieces that include the same identical point still contribute only one point.
Example · Overlap, gap, and neither{x + 1 if x ≤ 3; 2x if x ≥ 3} is not a function: at 3 the first line says 4 and the second says 6. {x + 1 if x < 3; 2x if x > 3} is a function whose domain omits 3. {x + 1 if x ≤ 3; 2x if x > 3} is a function on every real number. Three rules, one symbol apart, and only the first is broken.
An overlap is harmless when the formulas happen to agree on it. {2x if x ≤ 3; x + 3 if x ≥ 3} names 3 twice, but both lines give 6, so each input still has one output. This is worth knowing and not worth relying on: writing the conditions so they cannot overlap removes the need to check.