This site is a work in progress. New lessons are added regularly. Contact us

Piecewise Functions

Learning goals

  • Partition the domain so exactly one piece owns each input
  • Evaluate by choosing the piece whose condition holds
  • Graph each piece over its own interval only
  • Mark a closed or open dot at each boundary
  • Compare the two heights to tell a jump from a join
  • Build the range from each piece's restricted outputs

What a piecewise function is

A piecewise function is defined by two or more formulas, called pieces, each paired with a condition that says which inputs it governs. The pieces are collected under one large brace. For example,

f(x)={x+3if x<1,x2if 1x2,8xif x>2.f(x) = \begin{cases} x + 3 & \text{if } x < -1, \\ x^2 & \text{if } -1 \le x \le 2, \\ 8 - x & \text{if } x > 2. \end{cases}

Read the brace as a short list of instructions. Given an input xx, run down the conditions on the right, find the single one that xx satisfies, and apply the matching formula on the left. Nothing about the notation is mysterious; it is just a compact way to say “the value is whichever of these lines applies to your input.”

To evaluate a piecewise function at a number, always decide the condition first and compute second. Take x=3x = 3. Scanning the conditions, 33 is not less than 1-1, and it does not lie between 1-1 and 22. But 33 is greater than 22, so the third piece owns it and f(3)=83=5f(3) = 8 - 3 = 5. Take x=0x = 0 instead. It satisfies 102-1 \le 0 \le 2, the middle condition, so f(0)=02=0f(0) = 0^2 = 0. Choosing the formula before substituting is the entire skill. Plugging 00 into the first or third piece would produce a number the function never actually returns at 00.

The care is needed at a boundary, an input where one condition ends and the next begins. Look at x=1x = -1. The first condition asks for x<1x < -1, which 1-1 fails, and the second asks for 1x2-1 \le x \le 2, which 1-1 passes thanks to the “or equal to.” So the boundary x=1x = -1 belongs to the middle piece alone, and f(1)=(1)2=1f(-1) = (-1)^2 = 1. The inequality signs are not decoration. The strict << on one side and the \le on the other are exactly what hand the shared point to a single piece. Those two signs also keep the other piece from claiming that point.

Why each input must belong to exactly one piece#

A function is a rule that assigns to every input in its domain exactly one output. A piecewise definition can only be a genuine function when its conditions do two things. Those conditions must never assign one input to two conflicting pieces, and they must never leave an intended input with no piece at all.

Suppose some input aa satisfied two conditions whose formulas disagree, giving one piece the value p(a)p(a) and another the value q(a)q(a) with p(a)q(a)p(a) \ne q(a). Then the rule would offer two different outputs at the same input, and a rule that returns two values is not a function. So the conditions must never overlap in a way that hands a single input two different results. The safe design, and the one used everywhere, is to make the conditions mutually exclusive, so no input satisfies more than one.

Now suppose instead that some input we intend to feed in satisfied no condition at all. Then the rule would give it no output, and the function would simply be undefined there. So the conditions must also cover every input in the intended domain. Putting the two requirements together, the conditions must partition the domain: each input lands in one piece and only one.

This is the whole reason for the careful inequality signs at a boundary. Where two pieces meet at a value bb, exactly one of them must claim bb. Writing one condition as xbx \le b and the next as x>bx > b hands bb to the first piece and to no other. Writing them as xbx \le b and xbx \ge b would be an error, because then bb satisfies both and the function risks two values. Writing them as x<bx < b and x>bx > b would be an error too, because then bb satisfies neither and the function has a gap.

Worked example 1 Evaluate a three-piece function

Use the function

f(x)={x+3if x<1,x2if 1x2,8xif x>2,f(x) = \begin{cases} x + 3 & \text{if } x < -1, \\ x^2 & \text{if } -1 \le x \le 2, \\ 8 - x & \text{if } x > 2, \end{cases}

and find f(4)f(-4), f(1)f(-1), f(2)f(2), and f(5)f(5). For each input, name the condition first.

The input 4-4 satisfies x<1x < -1, so the first piece applies and f(4)=4+3=1f(-4) = -4 + 3 = -1.

The input 1-1 is a boundary. It fails x<1x < -1 but satisfies 1x2-1 \le x \le 2, so the middle piece owns it and f(1)=(1)2=1f(-1) = (-1)^2 = 1.

The input 22 is the other boundary. It satisfies 1x2-1 \le x \le 2 (again by the “or equal to”), so the middle piece applies and f(2)=22=4f(2) = 2^2 = 4.

The input 55 satisfies x>2x > 2, so the third piece applies and f(5)=85=3f(5) = 8 - 5 = 3.

f(4)=1,f(1)=1,f(2)=4,f(5)=3.f(-4) = -1, \quad f(-1) = 1, \quad f(2) = 4, \quad f(5) = 3.

Both boundaries went to the middle piece, because both of its inequalities carry the “or equal to.”

Check your understanding

Find g(3)g(3) for the function

g(x)={2x+1if x<3,4xif x3.g(x) = \begin{cases} 2x + 1 & \text{if } x < 3, \\ 4 - x & \text{if } x \ge 3. \end{cases}

Answer choices

Graphing a piecewise function

To graph a piecewise function, graph each piece on its own interval and nowhere else. For the running ff, you draw the line y=x+3y = x + 3 only to the left of 1-1, and the parabola y=x2y = x^2 only from 1-1 to 22. The line y=8xy = 8 - x is drawn only to the right of 22. The one new question a piecewise graph raises is what to draw at the ends of each interval, and the inequality signs answer it.

At a boundary the piece that includes the endpoint (its condition uses \le or \ge) genuinely reaches that point. Because that piece reaches the point, you mark its end with a closed dot, a filled circle. The piece that excludes the endpoint (its condition uses << or >>) approaches the point but never arrives. Because that piece never arrives, you mark its end with an open dot, a hollow circle. A filled dot says “this exact point is on the graph.” A hollow dot says “the graph runs up to here, but this point belongs to the other piece.”

Watch how that plays out on a simple two-piece function:

g(x)={x+1if x1,4if x>1.g(x) = \begin{cases} x + 1 & \text{if } x \le 1, \\ 4 & \text{if } x > 1. \end{cases}

The first piece is the line y=x+1y = x + 1 drawn up to x=1x = 1. Its condition includes the boundary (x1x \le 1), so it truly reaches the point (1,2)(1, 2), drawn as a closed dot. The second piece is the constant y=4y = 4 drawn for every input past 11. Its condition excludes the boundary (x>1x > 1), so at x=1x = 1 it stops just short with an open dot at (1,4)(1, 4). Between those two dots the graph leaps straight from height 22 up to height 44 without passing through the values in between. That leap is a jump.

A piecewise function with a jump at x equals 1The piece y equals x plus 1 reaches a closed dot at 1 comma 2, and the piece y equals 4 begins at an open dot at 1 comma 4, so the graph leaps from height 2 to height 4 at the boundary.xy-4-3-2-1123454321-1-2-30y = x + 1y = 4(1, 2)(1, 4)jump
A piecewise function that jumps. The line piece y equals x plus 1 runs up to x equals 1, where its condition includes the boundary, so it reaches the point (1, 2) with a closed (filled) dot. The constant piece y equals 4 governs every input past 1, so at x equals 1 it stops just short with an open (hollow) dot at (1, 4). The two pieces reach different heights at x equals 1, height 2 and height 4, so the graph jumps and cannot be drawn without lifting the pen.

Whether a piecewise graph jumps or connects at a boundary comes down to one comparison: do the two pieces reach the same height there? Plug the boundary into both formulas and see. For gg, the left piece gives 1+1=21 + 1 = 2 while the right piece gives 44. The heights differ, so the graph cannot be drawn without lifting the pen, and a jump appears. When the two pieces land on the same height instead, the closed dot and the open dot fall on the very same point. That shared point fills the hole, and the graph connects into an unbroken curve. No limits or calculus are needed for this; you simply evaluate both pieces at the boundary and compare the two numbers.

Compare gg with a function whose pieces agree at the boundary:

h(x)={2xif x<1,x+1if x1.h(x) = \begin{cases} 2x & \text{if } x < 1, \\ x + 1 & \text{if } x \ge 1. \end{cases}

At x=1x = 1 the first piece heads toward 21=22 \cdot 1 = 2 and the second piece sits at 1+1=21 + 1 = 2. Same height. The excluded point from the left piece and the included point from the right piece are both (1,2)(1, 2). Because they are the same point, they merge into one filled dot and the graph has no gap. It still turns a sharp corner, because the slopes differ (22 on the left, 11 on the right), but a corner is not a jump. You can trace the whole graph without lifting the pen.

A piecewise function that connects at x equals 1The piece y equals 2x and the piece y equals x plus 1 both reach height 2 at x equals 1, so they meet at a single filled dot at 1 comma 2 with a corner and no jump.xy-2-1123454321-1-20y = 2xy = x + 1(1, 2)
A piecewise function that connects. The piece y equals 2x runs up to the boundary x equals 1, and the piece y equals x plus 1 begins there. Both pieces reach height 2 at x equals 1, so the hollow endpoint of the left piece lands on the filled endpoint of the right piece and they merge into a single closed dot at (1, 2). The graph has a corner because the slopes differ, but no jump, so it can be drawn without lifting the pen.

Worked example 2 Describe the graph at each boundary

Sketch the shape of

p(x)={2if x<0,x2if 0x3,3if x>3,p(x) = \begin{cases} -2 & \text{if } x < 0, \\ x - 2 & \text{if } 0 \le x \le 3, \\ 3 & \text{if } x > 3, \end{cases}

reading off the dots and deciding jump or connect at each boundary.

At x=0x = 0, the left piece is the constant 2-2, which excludes 00 (its condition is x<0x < 0), so it gives an open dot at (0,2)(0, -2). The middle piece includes 00 and gives 02=20 - 2 = -2, a closed dot at (0,2)(0, -2). Both pieces reach height 2-2, so the dots land on the same point and the graph connects at x=0x = 0.

At x=3x = 3, the middle piece includes 33 and gives 32=13 - 2 = 1, a closed dot at (3,1)(3, 1). The right piece is the constant 33, which excludes 33 (its condition is x>3x > 3), so it gives an open dot at (3,3)(3, 3). The heights 11 and 33 differ, so the graph jumps at x=3x = 3.

connects at x=0,jumps at x=3.\text{connects at } x = 0, \qquad \text{jumps at } x = 3.

So pp runs flat at height 2-2, then rises along a line of slope 11 from (0,2)(0, -2) up to the closed dot (3,1)(3, 1). From there the graph leaps up to the open dot (3,3)(3, 3) and stays flat at height 33.

Check your understanding

At the boundary x=2x = 2, describe the graph of

k(x)={x2if x2,6if x>2.k(x) = \begin{cases} x^2 & \text{if } x \le 2, \\ 6 & \text{if } x > 2. \end{cases}

Answer choices

Domain and range

The domain of a piecewise function is the set of inputs it accepts, and it is the union of the intervals attached to the pieces. When the conditions partition the domain, as they should, those intervals fit together with no overlap and no gap. Because those intervals fit together that way, you can read the domain straight off the conditions. For gg, the conditions x1x \le 1 and x>1x > 1 together account for every real number, so the domain of gg is all real numbers.

The range is the set of outputs, and you build it one piece at a time. Find the values each piece produces over its own interval, then take the union. A piece is only responsible for the part of its graph that actually gets drawn, so restrict each formula to its interval before reading off its outputs. For gg, the line y=x+1y = x + 1 on x1x \le 1 produces every height up to and including 22 (reached at the boundary x=1x = 1). The constant piece contributes only the single height 44. The range of gg is therefore y2y \le 2 together with y=4y = 4, with everything strictly between 22 and 44 skipped over by the jump.

Worked example 3 Find the domain and range

Work out the domain and range of

r(x)={1if x<0,x+2if 0x2,6if x>2.r(x) = \begin{cases} 1 & \text{if } x < 0, \\ x + 2 & \text{if } 0 \le x \le 2, \\ 6 & \text{if } x > 2. \end{cases}

For the domain, list the intervals: x<0x < 0, then 0x20 \le x \le 2, then x>2x > 2. Together they cover every real number with no overlap, so the domain is all real numbers.

For the range, take the pieces one at a time. The first piece is the constant 11, contributing only the value 11. The middle piece x+2x + 2 runs over the closed interval 0x20 \le x \le 2, so its outputs run from 0+2=20 + 2 = 2 up to 2+2=42 + 2 = 4, giving every height in 2y42 \le y \le 4. The third piece is the constant 66, contributing only the value 66. Union the three:

range: y=1,or2y4,ory=6.\text{range: } y = 1, \quad \text{or} \quad 2 \le y \le 4, \quad \text{or} \quad y = 6.

The range is not a single interval. It is a stack of separate pieces. The heights between 11 and 22, and between 44 and 66, are never reached, because the two jumps skip straight over them.

Check your understanding

Find the range of the function

q(x)={x+1if x1,4if x>1.q(x) = \begin{cases} x + 1 & \text{if } x \le 1, \\ 4 & \text{if } x > 1. \end{cases}

Answer choices

The special functions were piecewise all along

This lesson is a capstone for the chapter, because the three functions you studied just before it were piecewise the whole time. The clearest case is the absolute value. Its rule keeps a nonnegative input as is and flips the sign of a negative input, which is precisely a two-piece definition:

x={xif x0,xif x<0.\lvert x \rvert = \begin{cases} x & \text{if } x \ge 0, \\ -x & \text{if } x < 0. \end{cases}

At the boundary x=0x = 0 the top piece gives 00 and the bottom piece heads toward 00 as well, so the two pieces meet at the same height. That agreement is exactly why the V of the absolute value graph connects at its vertex instead of jumping. Same height at the boundary means no gap, just the sharp corner where the slopes switch from 1-1 to +1+1.

Worked example 4 Write an absolute value as a piecewise function

Rewrite x3\lvert x - 3 \rvert without the bars, as a piecewise function.

The bars keep their contents when the inside is zero or positive and negate the contents when the inside is negative, so split on the sign of x3x - 3. The inside is nonnegative when x30x - 3 \ge 0, that is x3x \ge 3, and negative when x<3x < 3:

x3={x3if x3,(x3)if x<3.\lvert x - 3 \rvert = \begin{cases} x - 3 & \text{if } x \ge 3, \\ -(x - 3) & \text{if } x < 3. \end{cases}

Tidy the lower piece by distributing the sign, (x3)=3x-(x - 3) = 3 - x, so the function reads x3x - 3 for x3x \ge 3 and 3x3 - x for x<3x < 3. Check the boundary: at x=3x = 3 the top piece gives 00 and the bottom formula also heads toward 33=03 - 3 = 0. The two pieces therefore meet, so the graph is the usual V with its corner at (3,0)(3, 0).

The floor and ceiling are piecewise too, only with infinitely many pieces. The floor holds the constant value nn on each interval nx<n+1n \le x < n + 1. So writing one line per integer gives a piecewise definition with a separate constant piece for every whole-number step. Unlike the absolute value, neighboring floor pieces reach different heights at each integer boundary, one unit apart, so the floor jumps by one at every integer. That is why its graph is a staircase of separate steps rather than a connected curve. A piecewise function with constant pieces like this, whose graph is a row of flat segments, is called a step function. The floor and ceiling are the headline examples.

Piecewise models in the real world

Piecewise functions are the natural language for any rule that changes at thresholds, which is most real pricing. Postage climbs in jumps as a package crosses weight limits. A parking garage bills one amount for the first hour and another after that. A phone plan charges a flat monthly fee up to some data cap, then a per-gigabyte rate beyond it. Income tax applies one rate to the first band of income and steeper rates to higher bands. In every case a single function describes the cost, and its formula depends on which band the input falls into.

Worked example 5 A shipping cost that jumps

A store sets its shipping charge by the order weight ww, in pounds:

C(w)={5if 0<w2,8if 2<w5,12if w>5.C(w) = \begin{cases} 5 & \text{if } 0 < w \le 2, \\ 8 & \text{if } 2 < w \le 5, \\ 12 & \text{if } w > 5. \end{cases}

Every value is in dollars. Find the charge on orders weighing exactly 22 pounds, 33 pounds, and 5.55.5 pounds, and describe the graph.

An order of exactly 22 pounds sits on a boundary. The first condition 0<w20 < w \le 2 includes 22 because of the “or equal to,” so the first tier owns it and the charge is 55 dollars. An order of 33 pounds satisfies 2<w52 < w \le 5, so it costs 88 dollars. An order of 5.55.5 pounds satisfies w>5w > 5, so it costs 1212 dollars.

C(2)=5,C(3)=8,C(5.5)=12.C(2) = 5, \qquad C(3) = 8, \qquad C(5.5) = 12.

Because each tier is a constant, the graph is flat within a tier and jumps up at each boundary, exactly a step function like the floor. The boundary weights 22 and 55 each belong to the lower tier, which is why a package right at the limit still ships at the cheaper price. Reading the inequality the other way, so that 22 pounds cost 88 dollars, would overcharge every order that lands exactly on a limit.

Worked example 6 Build a piecewise fare from a description

A taxi charges a flat 33 dollars for any trip up to and including one mile, then 22 dollars for each mile beyond the first. Write the fare F(d)F(d) as a function of the distance dd in miles (with d>0d > 0), and find F(1)F(1) and F(4)F(4).

Up to one mile the fare is the flat charge, 33 dollars, so the first piece is the constant 33 on 0<d10 < d \le 1. Past one mile, you still pay the 33 dollars plus 22 dollars for each of the d1d - 1 extra miles, so the second piece is 3+2(d1)3 + 2(d - 1) on d>1d > 1:

F(d)={3if 0<d1,3+2(d1)if d>1.F(d) = \begin{cases} 3 & \text{if } 0 < d \le 1, \\ 3 + 2(d - 1) & \text{if } d > 1. \end{cases}

Evaluate. A one-mile trip is on the boundary, which the first piece includes, so F(1)=3F(1) = 3 dollars. A four-mile trip uses the second piece, F(4)=3+2(41)=3+6=9F(4) = 3 + 2(4 - 1) = 3 + 6 = 9 dollars.

F(1)=3,F(4)=9.F(1) = 3, \qquad F(4) = 9.

Check the boundary for a jump. At d=1d = 1 the first piece gives 33, and the second formula heads toward 3+2(11)=33 + 2(1 - 1) = 3 as well, the same height, so this fare connects. The charge rises smoothly with no sudden leap at one mile. That matches the design, since the extra-mile rate only starts adding once you pass the first mile.

Common mistakes

Practice

Multiple Choice Questions (MCQ)

Progressively harder sets of questions. Each opens on its own page.

Free Response Questions (FRQ)

Longer questions in parts, to be worked out on paper. Progressive hints, the answer on its own so you can check yourself and try again, then the full worked solution, plus a rubric to mark your own work against.

Free response Work it out on paper 5 questions Start →
More practice (optional)

Extra sets, as hard as the Challenge set. Each one opens on its own page.

More resources (optional)

Other explanations of this lesson, if you want a second take.

A bit of history (Optional)

Pull a guitar string aside with one finger and hold it there. Look at the shape just before you let go. It is not a curve at all. It is two straight segments meeting at a sharp corner, one rule to the left of your finger and a different rule to the right.

In 1747 the French mathematician Jean d’Alembert wrote down an equation governing how such a string moves. That should have settled the matter. Instead it opened an argument that ran for fifty years, and the argument was about the shape your finger had just made.

Was a bent string even allowed as a starting position? For d’Alembert it was not. A function meant a single formula, and a plucked string is two formulas taped together at a crease. He wanted the starting shape produced by one rule, smoothly, with no corner in it anywhere. His opponents made the obvious objection. Anybody can pluck a string, so the mathematics had better cope.

The pluckers won, and the victory cost mathematics its old idea of what a function is. A rule was allowed to be assembled from pieces, each governing its own territory. The bent string is a piecewise function, drawn exactly as you have been drawing them. Its two pieces meet at the same height, so the graph connects rather than jumping. That is the test you applied at every boundary here.