A piecewise function uses different formulas on different parts of its domain. For example, f(x) = x + 1 if x < 2, and f(x) = −2x + 7 if x ≥ 2. To evaluate it, first find which interval x is in, then use that formula: f(−3) = −2 and f(4) = −1. The absolute value function |x| is a common piecewise function.
Reviewed by the Helping with Math Team · Updated 22 October 2026
What is a function?
A function is a rule that gives exactly one output for each input. Functions are used throughout math, science and economics to describe how one quantity depends on another.
A function as a set of ordered pairs
Let A and B be non-empty sets. A function f from A to B is a set of ordered pairs (a, b) with a in A and b in B, such that:
- every a in A appears in some pair, and
- no a appears in two pairs with different second values: if (a, b) and (a, c) are both in f, then b = c.
Domain, codomain and range
For f: A → B, the set A is the domain and B is the codomain. The range is the set of outputs actually reached: f(A) = {f(x) : x in A}. For functions on real numbers, the domain is often an interval.
What are piecewise functions?
Sometimes one formula cannot describe a situation for every input. A piecewise function is defined by different formulas on different intervals of its domain.
Example 1
Describe f(x) = 2x if x > 0, f(x) = 1 if x = 0, and f(x) = −2x if x < 0.
Solution
This is one function with three pieces. f(3) = 2 × 3 = 6, f(0) = 1 and f(−4) = −2 × (−4) = 8. Every input uses exactly one piece.
How to write a piecewise function
- Identify the intervals where different rules apply.
- Write a formula for the output on each interval.
- Write the function with a brace, listing each formula with its condition. Make sure the intervals do not overlap.
Example 2
A museum charges 10 dollars per person for a guided tour with 1 to 9 people, or a flat 100 dollars for groups of 10 or more. Write the cost C as a function of the number of people n.
Solution
For 1 to 9 people the cost depends on n: C = 10n. For 10 or more it is constant: C = 100. So C(n) = 10n if 1 ≤ n ≤ 9, and C(n) = 100 if n ≥ 10.
The absolute value (modulus) function
The absolute value function is f(x) = |x| = −x if x < 0, and x if x ≥ 0. Its domain is all real numbers and its range is all non-negative real numbers. Its graph is a V shape.
Properties of absolute value
- √(x²) = |x| for every real number x.
- For a > 0: |x| ≤ a means −a ≤ x ≤ a.
- For a > 0: |x| ≥ a means x ≤ −a or x ≥ a.
- Triangle inequality: |x + y| ≤ |x| + |y|.
- |x − y| ≥ ||x| − |y||.
The logarithmic function
For a > 0 and a ≠ 1, f(x) = logₐ x (x > 0) is the logarithmic function. It is one of the inverse functions: y = logₐ x means aʸ = x. Its sign is often described in pieces:
- If a > 1: logₐ x < 0 for 0 < x < 1, logₐ 1 = 0, and logₐ x > 0 for x > 1. The graph rises.
- If 0 < a < 1: logₐ x > 0 for 0 < x < 1, logₐ 1 = 0, and logₐ x < 0 for x > 1. The graph falls.
Useful rules: logₐ 1 = 0, logₐ a = 1, logₐ(xy) = logₐ x + logₐ y, logₐ(x/y) = logₐ x − logₐ y and logₐ(xⁿ) = n logₐ x (for positive x and y).
Evaluating piecewise functions
- Check which interval x lies in.
- Use the formula for that interval only.
Example 3
f(x) = x + 1 if x < 2, and f(x) = −2x + 7 if x ≥ 2. Find f(−3), f(2) and f(4).
Solution
−3 < 2, so f(−3) = −3 + 1 = −2. 2 ≥ 2, so use the second rule: f(2) = −4 + 7 = 3. f(4) = −8 + 7 = −1.
Graphs of piecewise functions
To graph different functions pieced together, draw each formula only on its own interval. Use a solid dot where an endpoint is included and an open circle where it is not.
For Example 3, the line y = x + 1 runs to the left of x = 2 (points (−3, −2) and (0, 1)), and the line y = −2x + 7 starts at (2, 3) with a solid dot and passes through (4, −1). Both pieces reach the height 3 at x = 2, so this graph has no gap.
Try it: piecewise grapher
The left piece is y = x + 1. Move the break point and change the slope and intercept of the right piece.
f(x) = x + 1 if x < 2; −2x + 7 if x ≥ 2. The pieces meet at (2, 3).
Remember
- A piecewise function uses different formulas on different intervals.
- Each input uses exactly one piece.
- |x| = −x for x < 0 and x for x ≥ 0.
- Use a solid dot for an included endpoint and an open circle for an excluded one.
- To evaluate, find the interval first, then substitute.
Practice: multiplication of functions, division of functions, subtraction of functions and all worksheets.
Check yourself: piecewise functions
4 quick questions. Tap an answer to see if you are right.
f(x) = 3 if x < 0, and x² if x ≥ 0. Find f(−5).
−5 < 0, so use the first piece.
Same f. Find f(2).
Since 2 ≥ 0, use the x² piece: 2² = 4.
|−7| =
For x < 0, |x| = −x.
An open circle at an endpoint means
Solid dots are included.
Answered 0 of 4.
Piecewise Functions FAQs
What is a piecewise function?
A function made of two or more formulas, each used on its own interval of the domain.
How do you evaluate a piecewise function?
Find the interval that contains x, then substitute x into that formula only.
Is absolute value a piecewise function?
Yes. |x| = −x when x < 0 and x when x ≥ 0.
Can a piecewise function have a gap?
Yes. If the pieces do not meet at a break point, the graph jumps there.
Can the intervals overlap?
No. Then one input could have two outputs, and it would not be a function.









