Algebra 1

Evaluating a piecewise function

A rule uses one formula for some inputs and a different formula for others. Given an input, which formula do you use?

Where you are 4 in Piecewise functions

When you reach for it

Some rules change partway along. A kayak rental charges one price for each hour up to a limit and a different price after it; an electricity company charges more for each unit once a home has used a set amount. One formula cannot describe such a rule, but two formulas can, each with a note saying which inputs it is for.

A piecewise function is a function written this way: several formulas, each paired with a condition on the input. Whenever a number goes into one, or a question asks which inputs give a stated output, the first job is the same: find which condition the input satisfies. After that it is ordinary evaluating a function at a number, with one formula.

The procedure

Reading the brace

f(x) = \begin{cases} x^2 & \text{if } x < 1 \\ 2x + 3 & \text{if } 1 \le x \le 4 \\ 20 - x & \text{if } x > 4 \end{cases}

The brace gathers three lines into one function named f. Each line is a branch: a formula, then a condition. The first line reads “f(x) is x^2 when x is less than 1”. The middle condition, 1 \le x \le 4, is an ”and” inequality: x must be at least 1 and also at most 4.

The brace stands for one function, not three. Each input gets one output, made by the one formula its condition picks out. Each condition is a stretch of the number line, as in the figure.

-2
-1
0
1
2
3
4
5
6
7
x^2
2x + 3
20 - x
Figure 1The three conditions of f as stretches of the number line. A filled dot means the stretch includes that end; an open circle means it stops just short.

Choosing the branch

To find f(-3), test -3 against each condition. The first, -3 < 1, is true. The second fails because -3 is less than 1, and the third fails because -3 is not greater than 4. So the first branch applies and

f(-3) = (-3)^2 = 9.

The other two formulas are never used for -3, although 2(-3) + 3 and 20 - (-3) are perfectly good numbers. A formula’s condition is its permission: outside it, the formula says nothing about f. Likewise f(6) = 20 - 6 = 14, because 6 > 4 is the only condition 6 satisfies. Only one branch can ever apply, because the stretches in the figure do not overlap.

Inputs on a boundary

A boundary is a number where one condition stops and the next begins; for f they are 1 and 4. Here the bar under the inequality sign decides. At x = 1: 1 < 1 is false, since no number is less than itself, and 1 \le 1 \le 4 is true. So

f(1) = 2(1) + 3 = 5,

not 1^2 = 1. At x = 4: 1 \le 4 \le 4 is true because 4 \le 4, and 4 > 4 is false, so f(4) = 2(4) + 3 = 11. The third formula would have given 16. In the figure, the filled dots at 1 and 4 belong to the middle stretch, and the open circles show the outer stretches stopping just short.

Inputs no condition covers

Nothing forces the conditions to cover every number. If a function’s conditions were x < 1 and x > 1, then 1 would satisfy neither, and the function would have no value at 1: 1 is not in its domain. The domain of a piecewise function is exactly the set of inputs that satisfy some condition. At an input outside it, “not defined” is the answer; borrowing the nearest formula would invent an output the function does not have.

Working backwards from an output

Which inputs give f(x) = 16? Each formula is set equal to 16 and solved, and then each solution is tested against its own branch’s condition.

BranchSolveIts conditionKeep?
x^2x = 4 or x = -4x < 1-4 only
2x + 3x = 6.51 \le x \le 4no
20 - xx = 4x > 4no

So f(x) = 16 only at x = -4. The test is needed because solving x^2 = 16 finds where the formula x^2 equals 16, but f uses that formula only for inputs below 1. At x = 4, f uses the middle formula, and f(4) = 11, not 16.

Worked examples

Example 1

Two branches, no boundary

h(x) = \begin{cases} 4 - x & \text{if } x < -1 \\ 2x^2 & \text{if } x \ge -1 \end{cases}

Find h(-5), h(3) and \displaystyle h\!\left(-\frac{1}{2}\right).

Solution

-5 < -1 is true, since -5 lies left of -1 on the number line. So the first branch applies: h(-5) = 4 - (-5) = 9.

3 \ge -1 is true, so h(3) = 2(3)^2 = 2 \cdot 9 = 18. The square is taken first, then doubled, by the order of operations.

For \displaystyle -\frac{1}{2}, compare it with -1: \displaystyle -\frac{1}{2} lies to the right of -1, so \displaystyle -\frac{1}{2} \ge -1 is true and \displaystyle -\frac{1}{2} < -1 is false. The second branch applies: \displaystyle h\!\left(-\frac{1}{2}\right) = 2\left(-\frac{1}{2}\right)^2 = 2 \cdot \frac{1}{4} = \frac{1}{2}.

Example 2

Where the bar sits

p(x) = \begin{cases} x + 5 & \text{if } x \le 3 \\ 2x & \text{if } x > 3 \end{cases}
q(x) = \begin{cases} x + 5 & \text{if } x < 3 \\ 2x & \text{if } x \ge 3 \end{cases}

Find p(3) and q(3), and say at which inputs p and q differ.

Solution

For p: 3 \le 3 is true, so p(3) = 3 + 5 = 8. For q: 3 < 3 is false and 3 \ge 3 is true, so q(3) = 2(3) = 6.

The two braces have the same formulas and the same boundary; only the bar has moved from one condition to the other. Any input below 3 uses x + 5 in both, and any input above 3 uses 2x in both, so p and q agree everywhere except at 3 itself, where they differ: 8 against 6.

Example 3

Inputs left uncovered

k(x) = \begin{cases} 1 - 2x & \text{if } -3 \le x < 0 \\ 7 & \text{if } 0 < x \le 4 \\ x^2 - 10 & \text{if } x \ge 5 \end{cases}

(a) Find k(-3), k(0), k(2), k(4.5) and k(5). (b) State the domain of k. (c) Which inputs give k(x) = 7?

Solution

(a) -3 \le -3 < 0 is true, so k(-3) = 1 - 2(-3) = 7.

0 fails all three conditions: the first needs x < 0, the second needs 0 < x, and the third needs x \ge 5. So k(0) is not defined.

2 satisfies 0 < 2 \le 4, and the second formula is the constant 7, so k(2) = 7. A constant branch gives the same output for every input in its stretch.

4.5 is greater than 4 and less than 5, so it fails all three conditions: k(4.5) is not defined. Finally 5 \ge 5 is true, so k(5) = 5^2 - 10 = 15.

-4
-3
-2
-1
0
1
2
3
4
5
6
7
1 - 2x
7
x^2 - 10
Figure 2The conditions of k in Example 3. Where no stretch is drawn, k has no value.

(b) The domain is every input some condition admits: -3 \le x < 0, or 0 < x \le 4, or x \ge 5. In Interval and set-builder notation, where \cup means “or”, it is [-3, 0) \cup (0, 4] \cup [5, \infty).

(c) First branch: 1 - 2x = 7 gives x = -3, and -3 \le -3 < 0 holds, so keep it. Second branch: the output is 7 for every input in its stretch, so every x with 0 < x \le 4 works. Third branch: x^2 - 10 = 7 gives \displaystyle x = \pm\sqrt{17}. Since \displaystyle \sqrt{17} < \sqrt{25} = 5, neither \displaystyle \sqrt{17} nor \displaystyle -\sqrt{17} satisfies x \ge 5, so reject both. So k(x) = 7 at x = -3 and at every x with 0 < x \le 4.

Example 4

Renting a kayak

A lake rents out kayaks at 6 dollars an hour for up to 3 hours, and 4 dollars for each hour beyond that. The cost in dollars of a kayak for t hours is

B(t) = \begin{cases} 6t & \text{if } 0 \le t \le 3 \\ 18 + 4(t - 3) & \text{if } t > 3 \end{cases}

(a) Find B(2), B(3) and B(5). (b) Wolfgang paid 30 dollars. For how many hours did he have the kayak?

Solution

(a) 2 and 3 both satisfy 0 \le t \le 3, so B(2) = 6(2) = 12 and B(3) = 6(3) = 18. For 5, 5 > 3, so B(5) = 18 + 4(5 - 3) = 26. The 18 is the cost of the first 3 hours, and t - 3 counts the hours beyond them.

(b) Solve B(t) = 30 on each branch. First: 6t = 30 gives t = 5, which fails t \le 3; reject it. Second: 18 + 4(t - 3) = 30 gives t - 3 = 3, so t = 6, and 6 > 3 holds. He had the kayak for 6 hours. The rejected 5 is not a real answer: part (a) already showed that 5 hours cost 26 dollars, not 30.

Example 5

Two answers, then none

m(x) = \begin{cases} x^2 - 4 & \text{if } x \le 0 \\ 3x - 4 & \text{if } x > 0 \end{cases}

Find every x with m(x) = 5, then every x with m(x) = -6.

Solution

For m(x) = 5. First branch: x^2 - 4 = 5 gives x^2 = 9, so x = 3 or x = -3. Only -3 satisfies x \le 0. Second branch: 3x - 4 = 5 gives x = 3, and 3 > 0 holds. So m(x) = 5 at x = -3 and x = 3. The value 3 was rejected by the first branch and accepted by the second; each candidate answers only to the condition of the branch that produced it.

For m(x) = -6. First branch: x^2 - 4 = -6 gives x^2 = -2, and no real number squares to a negative. Second branch: 3x - 4 = -6 gives \displaystyle x = -\frac{2}{3}, which fails x > 0. No input gives -6: it is not an output of m at all.

Example 6

Feeding an output back in

r(x) = \begin{cases} x + 4 & \text{if } x < -1 \\ x^2 & \text{if } -1 \le x \le 3 \\ 20 - 2x & \text{if } x > 3 \end{cases}

Find r(-5), then use that output as a new input. Do the same starting from 2. In symbols, find r\big(r(-5)\big) and r\big(r(2)\big).

Solution

-5 < -1, so r(-5) = -5 + 4 = -1. The new input -1 sits on a boundary: -1 < -1 is false and -1 \le -1 \le 3 is true, so r(-1) = (-1)^2 = 1. So r\big(r(-5)\big) = 1. Staying with the first formula would have given -1 + 4 = 3, which is not a value of r at -1.

2 satisfies -1 \le 2 \le 3, so r(2) = 2^2 = 4. Now 4 > 3, so r(4) = 20 - 2(4) = 12, and r\big(r(2)\big) = 12.

Each new input is tested against the conditions from scratch. The branch that produced a number says nothing about which branch that number uses when it goes back in.

Boundaries

The method needs every input to satisfy at most one condition. Conditions that overlap still define a function only if their formulas agree on the overlap, as in Exercise 17; if they disagree, the brace gives some input two outputs and is not a function.

An input that satisfies no condition has no output. The conditions, not the formulas, decide the domain: 2x + 3 makes sense for every number, but inside a brace it is used only on its own stretch.

When working backwards, solving a formula finds candidates, not answers. A candidate counts only if it satisfies the condition of the branch it came from. A constant branch equal to the target output gives a whole stretch of answers, as in Example 3, and a target no branch reaches has no answer.

Where this goes next

Drawing each formula only over its own stretch, with filled and open dots at the boundaries, is Graphing a piecewise function; reading the brace back off a picture is Writing a piecewise rule from a graph. Tax bands, shipping charges and tariffs like the ones here are Piecewise functions in context. Absolute value is itself a two-branch rule, drawn in The absolute value graph, and a function that jumps by whole steps is the Step functions and the greatest integer function.

Exercises

Choosing the branch

g(x) = \begin{cases} 2x + 1 & \text{if } x < 0 \\ x^2 - 3 & \text{if } x \ge 0 \end{cases}
  1. Find g(-4).
  2. Find g(0).
  3. Find \displaystyle g\!\left(-\frac{1}{2}\right).

Inputs on a boundary

s(x) = \begin{cases} 6 - x & \text{if } x \le 2 \\ x^2 & \text{if } 2 < x < 5 \\ 10 & \text{if } x \ge 5 \end{cases}
  1. Find s(2).
  2. Find s(5).
  3. Find s(-3) and s(3).
  4. The conditions are changed to x \le 2, then 2 < x \le 5, then x > 5, with the same formulas. Find the new value at 5.

Inputs no condition covers

w(x) = \begin{cases} x + 4 & \text{if } -6 \le x < -1 \\ 2x^2 & \text{if } 1 < x \le 3 \end{cases}
  1. Find w(-6) and w(3).
  2. Find w(0), w(-1) and w(1), if they exist.
  3. State the domain of w in interval notation.

Which inputs give this output

v(x) = \begin{cases} x^2 & \text{if } x \le 2 \\ 3x + 1 & \text{if } x > 2 \end{cases}
  1. Find every x with v(x) = 16.
  2. Find every x with v(x) = 1.
  3. Find every x with v(x) = 5.
  4. Find every x with v(x) = -1.

A tiered electricity price

Benedikta’s electricity company charges 0.12 dollars for each kilowatt-hour up to 500 in a month, and 0.20 dollars for each kilowatt-hour beyond that. Her monthly bill in dollars for k kilowatt-hours is

E(k) = \begin{cases} 0.12k & \text{if } 0 \le k \le 500 \\ 60 + 0.2(k - 500) & \text{if } k > 500 \end{cases}
  1. Find E(300), E(500) and E(800).
  2. One month her bill was 90 dollars. How many kilowatt-hours did she use?

Reasoning

  1. A brace uses x + 1 if x \le 3 and 2x - 2 if x \ge 3. Both conditions hold at 3. Explain why this still defines a function, and why it would not if 2x - 2 were replaced by 2x.
  2. Explain why, when working backwards, a candidate from one branch is tested against that branch’s condition only, and never against the other branches’ conditions.
Answers
  1. g(-4) = -7. -4 < 0, so 2(-4) + 1 = -7.
  2. g(0) = -3. 0 < 0 is false and 0 \ge 0 is true, so 0^2 - 3 = -3.
  3. \displaystyle g\!\left(-\frac{1}{2}\right) = 0. \displaystyle -\frac{1}{2} < 0, so \displaystyle 2\left(-\frac{1}{2}\right) + 1 = 0.
  4. s(2) = 4. 2 \le 2 is true, so 6 - 2 = 4; the second condition needs x > 2.
  5. s(5) = 10. 5 < 5 is false and 5 \ge 5 is true, so the constant branch gives 10.
  6. s(-3) = 9 and s(3) = 9. -3 \le 2 gives 6 - (-3) = 9; 2 < 3 < 5 gives 3^2 = 9. Two inputs may share an output.
  7. 25. Now 2 < 5 \le 5 is true, so the middle formula gives 5^2 = 25 instead of 10.
  8. w(-6) = -2 and w(3) = 18. -6 \le -6 < -1 gives -6 + 4 = -2; 1 < 3 \le 3 gives 2(3)^2 = 18.
  9. None of them exists. 0 is neither below -1 nor above 1. For -1: -1 < -1 is false, and 1 < -1 is false. For 1: 1 < -1 is false, and 1 < 1 is false.
  10. [-6, -1) \cup (1, 3]: the inputs with -6 \le x < -1 or 1 < x \le 3.
  11. x = -4 or x = 5. x^2 = 16 gives \pm 4, and only -4 \le 2. 3x + 1 = 16 gives 5, and 5 > 2.
  12. x = -1 or x = 1. x^2 = 1 gives \pm 1, both at most 2. 3x + 1 = 1 gives 0, which fails x > 2.
  13. \displaystyle x = -\sqrt{5} only. x^2 = 5 gives \displaystyle \pm\sqrt{5}, and \displaystyle \sqrt{5} > \sqrt{4} = 2, so reject \displaystyle \sqrt{5}. 3x + 1 = 5 gives \displaystyle \frac{4}{3}, which fails x > 2.
  14. No x. x^2 = -1 has no real solution, and 3x + 1 = -1 gives \displaystyle -\frac{2}{3}, which fails x > 2.
  15. E(300) = 36, E(500) = 60, E(800) = 120. The first two use 0.12k; for 800, 60 + 0.2(300) = 120.
  16. 650 kilowatt-hours. 0.12k = 90 gives k = 750, which fails k \le 500. Then 60 + 0.2(k - 500) = 90 gives k - 500 = 150, so k = 650, and 650 > 500.
  17. Only the input 3 satisfies both conditions, and there both formulas give 4: 3 + 1 = 4 and 2(3) - 2 = 4. Every input still has exactly one output. With 2x the second formula gives 6 at 3, so 3 would have two outputs, 4 and 6, and the brace would not be a function.
  18. If a candidate c satisfies its branch’s condition, the function uses that branch’s formula at c, and the formula gives the target, so the function’s value at c is the target. The other conditions cannot change this: they do not overlap that branch’s, so they are false at c and their formulas are not used there. Testing against another branch’s condition would wrongly reject good answers, as with x = 3 in Example 5.
kg1128 · updated 2026-10-10 · CC-BY-SA-4.0