Functions

Piecewise Functions: How to Evaluate, Graph and Write Them

A piecewise function is one function built from several rules, each with its own condition:

f(x)={f1(x)x∈I1f2(x)x∈I2f(x)=\begin{cases} f_1(x) & x\in I_1 \\ f_2(x) & x\in I_2 \end{cases}
f(x)={f1(x)if x is in I1f2(x)if x is in I2f(x)=\begin{cases} f_1(x) & \text{if } x \text{ is in } I_1\\ f_2(x) & \text{if } x \text{ is in } I_2\end{cases}

To use it, find which condition the input satisfies, then apply that rule and ignore the others.

Everything difficult about piecewise functions happens at the boundaries between rules: which piece owns the boundary point, whether the graph jumps, and whether a solution actually belongs to the piece that produced it. The sections below cover evaluating, graphing, domain and range, continuity, writing your own, and solving.

What is a piecewise function and why is it still one function?

A function must give each input exactly one output. A piecewise definition keeps that promise by making the conditions work like a sorting system: every xx in the domain lands in one slot, and that slot’s rule produces the answer. The conditions split the domain into intervals, and the rules are only ever applied inside their own interval. This is the core idea behind relations and functions: the pieces are separate, but the output rule is still single-valued.

The one way to break this is overlapping conditions with disagreeing rules. Suppose x≤1x\le 1 uses 2x2x and x≥1x\ge 1 uses x+3x+3. At x=1x=1 the first rule gives 22 and the second gives 44, so the input 11 has two outputs and the definition fails. Overlap is fine only when the rules agree at the shared point. Most textbooks avoid the issue by giving the boundary to exactly one piece, such as x<1x<1 and x≥1x\ge 1.

The graph tells the same story. A piecewise graph passes the vertical line test because the pieces never stack above the same xx. At a jump, the point you see two dots above the same xx is actually one filled dot and one open dot, and only the filled one counts.

Quick check

Is f(x)={x+1x≤25−xx≥2f(x)=\begin{cases}x+1 & x\le 2\\ 5-x & x\ge 2\end{cases} a valid function? Both conditions include x=2x=2.

How do you evaluate a piecewise function?

Evaluating is a lookup first and arithmetic second. Compare the input with the conditions, pick the one that is true, and substitute into that rule only. Take

f(x)={x2−1x<03x+20≤x<410x≥4f(x)=\begin{cases} x^2-1 & x<0\\ 3x+2 & 0\le x<4\\ 10 & x\ge 4\end{cases}

For f(−3)f(-3): −3<0-3<0, so use the first rule, f(−3)=(−3)2−1=9−1=8f(-3)=(-3)^2-1=9-1=8. For f(0)f(0): 00 satisfies 0≤x<40\le x<4, so f(0)=3(0)+2=2f(0)=3(0)+2=2. For f(4)f(4): the boundary belongs to the third piece, because the middle condition stops before 44. So f(4)=10f(4)=10, even though 3(4)+2=143(4)+2=14 would have been the tempting answer.

Boundary inputs are where marks are lost, so test them first and slowly. If function notation still feels shaky, remember that f(4)f(4) only means “the output when the input is 44”; the notation never chooses the rule, the condition does.

Parentheses protect negatives

Write f(−3)=(−3)2−1=8f(-3)=(-3)^2-1=8. Dropping the parentheses gives −32−1=−10-3^2-1=-10, which is a different number and a classic lost point.

How do you graph piecewise functions with open and closed dots?

Graph each rule as if it were defined everywhere, lightly, then keep only the part above its own interval. Recognising each piece as a parent function (a line, a parabola, a constant) lets you sketch it in seconds. Then settle every boundary:

  1. Mark each boundary value on the xx-axis.
  2. Sketch each piece only over its interval.
  3. At each boundary, compute the height from both sides.
  4. Put a closed dot where the condition includes the boundary (≤\le or ≥\ge) and an open dot where it does not.

Try it on

g(x)={x2x<27−xx≥2g(x)=\begin{cases} x^2 & x<2\\ 7-x & x\ge 2\end{cases}

The parabola piece approaches (2,4)(2,4) but stops short, so that dot is open. The line piece starts at 7−2=57-2=5, giving a closed dot at (2,5)(2,5). The two heights differ, so the graph has a jump of 11 at x=2x=2. If the heights matched, the open and closed dots would sit on the same point and the graph would connect.

Try this: Sketch y={−xx<02x≥0y=\begin{cases}-x & x<0\\ 2 & x\ge 0\end{cases} on paper. Before you draw, predict whether it jumps at x=0x=0 by computing the height each rule reaches there.

How do you find the domain and range of a piecewise function?

The domain is the union of all the conditions. For gg above, x<2x<2 and x≥2x\ge 2 together cover every real number, so the domain is (−∞,∞)(-\infty,\infty). If a condition is missing, such as a function defined only for x<0x<0 and x>0x>0, then 00 is excluded from the domain.

The range is the union of what each piece outputs on its own interval, not on its whole parent graph. For gg, the parabola piece uses x<2x<2, and because xx can be very negative, x2x^2 still reaches every value in [0,∞)[0,\infty). The line piece reaches (−∞,5](-\infty,5]. Together they cover every real number, so the range is (−∞,∞)(-\infty,\infty). The open dot at (2,4)(2,4) does not remove 44 from the range, because x=−2x=-2 and x=3x=3 both produce 44. An open dot only deletes a yy-value if no other piece reaches it.

Gaps appear when the pieces separate. For k(x)={xx<0x+2x≥0k(x)=\begin{cases}x & x<0\\ x+2 & x\ge 0\end{cases}, the first piece gives every value below 00 and the second gives every value from 22 upward, so the range is (−∞,0)∪[2,∞)(-\infty,0)\cup[2,\infty). For a refresher on interval notation and reading ranges off graphs, see domain and range.

Why is absolute value a piecewise function?

The absolute value flips negative numbers and leaves the rest alone, which is exactly a two-case rule:

∣x∣={xx≥0−xx<0|x|=\begin{cases} x & x\ge 0\\ -x & x<0\end{cases}

The V shape is two rays joined at the point where the inside is zero. This is why graphing absolute value functions is really piecewise graphing in disguise.

To rewrite any absolute value, find where the inside equals zero, then use the inside as-is on the side where it is nonnegative and negate it on the other side. For ∣2x−6∣|2x-6|, solve 2x−6=02x-6=0 to get x=3x=3:

∣2x−6∣={2x−6x≥36−2xx<3|2x-6|=\begin{cases} 2x-6 & x\ge 3\\ 6-2x & x<3\end{cases}

Check with x=0x=0: ∣−6∣=6|{-6}|=6 and 6−2(0)=66-2(0)=6. Check with x=5x=5: ∣4∣=4|4|=4 and 2(5)−6=42(5)-6=4. Both agree.

This also explains how transformations of functions move the corner: a shift changes the inside, so the break point moves to wherever the new inside equals zero. The same splitting trick handles equations like ∣2x−6∣=4|2x-6|=4 by solving each branch separately and checking each answer against its condition.

How do you make a piecewise function continuous?

A piecewise function is continuous at a boundary when both rules reach the same height there. To force that, set the two rules equal at the boundary and solve for the unknown constant. For

h(x)={3x+kx<2x2+1x≥2h(x)=\begin{cases} 3x+k & x<2\\ x^2+1 & x\ge 2\end{cases}

match the pieces at x=2x=2:

3(2)+k=22+1⇒6+k=5⇒k=−1.3(2)+k=2^2+1 \quad\Rightarrow\quad 6+k=5 \quad\Rightarrow\quad k=-1.

Check: the left piece at x=2x=2 gives 6−1=56-1=5, and the right piece gives 4+1=54+1=5. The graph now connects.

Continuity is not smoothness. With k=−1k=-1 the left piece has slope 33, while the parabola has slope 2x=42x=4 at x=2x=2. The slopes differ, so the graph has a corner there. Calculus makes this distinction exact: matching heights give continuity, and matching heights and slopes give differentiability. Absolute value is the standard example of a function that is continuous everywhere but has a corner.

Quick check

Find kk so that f(x)={2x+kx<3x2−1x≥3f(x)=\begin{cases}2x+k & x<3\\ x^2-1 & x\ge 3\end{cases} has no jump at x=3x=3.

How do you write a piecewise function from a word problem?

Real pricing rules are piecewise because the rate changes at thresholds. The trap is the second piece: it does not start from zero, it starts from wherever the first piece ended. Consider a simplified tax rule: 10%10\% on the first $10,000 of income, and 20%20\% only on the part above that.

  • Find the breakpoint: 10,00010{,}000.
  • Write the first rule: T(x)=0.10xT(x)=0.10x for 0≤x≤10,0000\le x\le 10{,}000.
  • Compute where it ends: T(10,000)=1000T(10{,}000)=1000.
  • Write the second rule as a line through (10,000, 1000)(10{,}000,\,1000) with slope 0.200.20.

The second rule is a direct use of point-slope form, and you can expand it into slope-intercept form afterwards:

T(x)={0.10x0≤x≤10,0001000+0.20(x−10,000)x>10,000T(x)=\begin{cases} 0.10x & 0\le x\le 10{,}000\\ 1000+0.20(x-10{,}000) & x>10{,}000\end{cases}

For an income of $25,000, use the second rule: T(25,000)=1000+0.20(15,000)=1000+3000=4000T(25{,}000)=1000+0.20(15{,}000)=1000+3000=4000. The tempting error is 0.20×25,000=50000.20\times 25{,}000=5000, which taxes the first $10,000 at the wrong rate. Expanded, the second rule is 0.20x−10000.20x-1000, and 0.20(25,000)−1000=40000.20(25{,}000)-1000=4000 agrees.

Rate changes versus jumps

A tax table changes slope but stays connected, so the pieces must match at the breakpoint. A parking fee or postage price jumps instead, so each piece is a constant with a new height.

Always run a boundary check on your finished function: plug the breakpoint into both rules. They should match for a connected model and differ by the exact fee for a stepped one. Writing from a graph follows the same recipe, with the dots telling you which inequality to use.

How do you solve and invert piecewise functions?

To solve f(x)=cf(x)=c, solve the equation separately in each piece, then keep only the answers that satisfy that piece’s condition. For g(x)={x2x<27−xx≥2g(x)=\begin{cases}x^2 & x<2\\ 7-x & x\ge 2\end{cases} and g(x)=4g(x)=4:

x2=4⇒x=±2, but only x=−2 satisfies x<2,x^2=4 \Rightarrow x=\pm 2,\ \text{but only } x=-2 \text{ satisfies } x<2,

7−x=4⇒x=3, which satisfies x≥2.7-x=4 \Rightarrow x=3,\ \text{which satisfies } x\ge 2.

So the solutions are x=−2x=-2 and x=3x=3. The rejected x=2x=2 is the open dot on the graph, which is a good picture of why the condition check matters.

Composition has the same flavour: finish the inner function, then use that output to choose the piece of the outer one. For g(g(3))g(g(3)), the inner value is g(3)=7−3=4g(3)=7-3=4, and since 4≥24\ge 2 the outer step is 7−4=37-4=3. See composition of functions for the general method.

Inverses need one-to-one functions. Since g(−2)=g(3)=4g(-2)=g(3)=4, gg fails the horizontal line test and has no inverse. When a piecewise function is one-to-one, invert each piece, then use the output ranges as the new conditions. For p(x)={2xx<1x+1x≥1p(x)=\begin{cases}2x & x<1\\ x+1 & x\ge 1\end{cases}, the pieces output values below 22 and values from 22 up. Using the usual inverse of a linear function steps on each piece gives

p−1(x)={x2x<2x−1x≥2p^{-1}(x)=\begin{cases}\dfrac{x}{2} & x<2\\ x-1 & x\ge 2\end{cases}

Check: p(1)=2p(1)=2 and p−1(2)=2−1=1p^{-1}(2)=2-1=1.

Quick check

Solve f(x)=9f(x)=9 for f(x)={x+4x<1x2x≥1f(x)=\begin{cases}x+4 & x<1\\ x^2 & x\ge 1\end{cases}.

Practice problems

0 of 5 solved

  1. Let f(x)={2x−1x<3x2x≥3f(x)=\begin{cases}2x-1 & x<3\\ x^2 & x\ge 3\end{cases}. Find f(−1)f(-1) and f(3)f(3).

  2. Rewrite ∣x+4∣|x+4| as a piecewise function.

  3. Find the range of h(x)={x−1x<04x≥0h(x)=\begin{cases}x-1 & x<0\\ 4 & x\ge 0\end{cases}.

  4. Find kk so that f(x)={kx−2x<3x2−5x≥3f(x)=\begin{cases}kx-2 & x<3\\ x^2-5 & x\ge 3\end{cases} is continuous.

  5. Find the inverse of p(x)={3xx<2x+4x≥2p(x)=\begin{cases}3x & x<2\\ x+4 & x\ge 2\end{cases}.

Common questions

What is a piecewise function in simple terms?

It is a single function that follows different formulas on different parts of its domain. Each formula comes with a condition, and the input decides which formula applies.

When do you use an open circle and when a closed circle?

Use a closed circle when the condition includes the endpoint (≤\le or ≥\ge) and an open circle when it does not (<< or >>). At a jump, one piece usually gets the closed circle and the other the open one.

What if an input satisfies two conditions?

Then the two rules must give the same value there, or the definition is not a function. Well-written piecewise functions give each boundary to exactly one piece.

How many pieces can a piecewise function have?

As many as the situation needs. Two or three pieces are common in algebra, while real models such as tax tables can have seven or more.

Is absolute value a piecewise function?

Yes. ∣x∣|x| equals xx when x≥0x\ge 0 and −x-x when x<0x<0. Any absolute value expression can be split the same way at the point where the inside equals zero.

How do you tell if a piecewise function is continuous?

Evaluate the pieces on each side of every boundary. If they reach the same value at the boundary and the boundary itself has that value, the graph has no break there.

Up next