Piecewise Functions

Piecewise functions (also called piecewise-defined functions) are functions defined by different formulas depending on which subset of the domain the independent variable belongs to.

To write a piecewise function, a large curly brace on the left groups each algebraic expression together with the condition or interval of x-values where it applies. In general, a function defined by two pieces has the structure:

$$f(x) = \begin{cases} f_1(x) & \text{if } x \in A \\ f_2(x) & \text{if } x \in B \end{cases}$$

Even though multiple formulas are involved, it is a single function rather than several independent functions. For this reason, the intervals of definition cannot overlap at values where they produce different results, since each element in the domain must have a unique output. If two conditions share an endpoint (for example, \(x \le 2\) and \(x \ge 2\)), both formulas must yield the exact same value at that point for the function to be well-defined.

These expressions are useful for modeling everyday situations where a rule changes once a certain threshold is crossed, such as tiered utility rates or progressive tax brackets. In mathematics, several elementary functions are actually piecewise functions, including the absolute value function, the sign function, and the greatest integer function.

How to Evaluate Piecewise Functions

Evaluating a piecewise function means finding the output value f(x) for a given number x. Unlike functions with a single formula, you cannot plug the value into any expression at random; first, you must check which condition inside the brace the chosen number satisfies.

To calculate the output of a given value without making mistakes, follow this three-step procedure:

  1. Look at the inequality conditions or intervals located to the right of each formula.
  2. Identify the single piece that contains the given value of x, paying special attention to signs that include the endpoint (≤ or ≥) versus those that exclude it (< or >).
  3. Substitute x only into the algebraic expression corresponding to that piece and perform the operations.

Example 1

Calculate the values of \(f(0)\), \(f(3)\), and \(f(1)\) for the following piecewise function:

$$f(x) = \begin{cases} x + 1 & \text{if } x \le 1 \\ x^2 & \text{if } x > 1 \end{cases}$$

For each requested value, we first check which interval the input number belongs to before substituting:

  • Calculating \(f(0)\): Since \(0 \le 1\), the first condition is satisfied. We use the linear expression: \(f(0) = 0 + 1 = 1\).
  • Calculating \(f(3)\): Since \(3 > 1\), the second condition is satisfied. We apply the quadratic formula: \(f(3) = 3^2 = 9\).
  • Calculating \(f(1)\): The number \(1\) lies right at the boundary where the rule changes. Because the \(\le\) symbol in the first condition includes \(1\), we use the first formula: \(f(1) = 1 + 1 = 2\).

Example 2

Find the output values \(f(-4)\), \(f(1)\), and \(f(4)\) of the three-piece function:

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

We determine which piece each given value falls into:

  • For \(x = -4\): Since \(-4 < 0\), the first piece applies: \(f(-4) = -(-4) = 4\).
  • For \(x = 1\): Since \(1\) lies between \(0\) and \(2\) (inclusive), we use the middle expression: \(f(1) = 2(1) + 3 = 5\).
  • For \(x = 4\): Given that \(4 > 2\), we apply the third formula: \(f(4) = 4^3 = 64\).

Example 3

Find \(g(-2)\), \(g(0)\), and \(g(2)\) for the function with bounded intervals:

$$g(x) = \begin{cases} 4 & \text{if } -3 \le x < 0 \\ \dfrac{6}{x + 1} & \text{if } 0 \le x < 2 \end{cases}$$

In this case, the intervals have both a lower and an upper bound, so it is helpful to verify whether all proposed values belong to the domain before evaluating:

  • Calculating \(g(-2)\): Since \(-2\) falls within the interval \([-3, 0)\), the constant function of the first piece applies: \(g(-2) = 4\).
  • Calculating \(g(0)\): The value \(0\) is excluded from the first condition by the \(<\) sign, but it is included in the second by the \(\le\) sign. Substituting into the second piece gives: \(g(0) = \dfrac{6}{0 + 1} = 6\).
  • Calculating \(g(2)\): The number \(2\) does not satisfy either condition, since the second piece requires \(x < 2\). Therefore, \(g(2)\) is undefined (\(2\) is not in the domain of the function).

Intercepts with the Axes

Evaluating a piecewise function also lets you find its intercepts with the coordinate axes, paying close attention to the valid interval of each piece:

  • y-intercept: Found by calculating \(f(0)\), provided that \(0\) belongs to the domain. Simply identify the single condition that includes \(x = 0\) and substitute into its formula.
  • x-intercepts (roots or zeros): Set \(f(x) = 0\) for each piece separately, keeping only the solutions that belong to that piece's interval. For example, if an expression is \(x + 1\) for \(x > 0\), solving \(x + 1 = 0\) gives \(x = -1\), which is discarded because it does not satisfy \(x > 0\).

How to Graph Piecewise Functions

To graph a piecewise function, each piece is drawn according to its corresponding formula, but strictly restricted to the interval stated in its condition. All pieces are plotted on the same coordinate plane, as together they form a single function.

To build the graph systematically, follow these steps:

  1. Identify each subfunction (line, parabola, constant, among others) and the interval on the x-axis where it applies.
  2. Evaluate each formula at the endpoints of its own interval to find where that piece starts and ends.
  3. Mark each endpoint with a closed circle (solid dot) if the inequality includes the number (≤ or ≥), or with an open circle (hollow dot) if it excludes it (< or >).
  4. Sketch the line segment or curve between those endpoints and visually verify that no vertical line intersects the graph at more than one point.

Example 1

Graph the function defined by two pieces:

$$f(x) = \begin{cases} x + 1 & \text{if } x \le 1 \\ x^2 & \text{if } x > 1 \end{cases}$$

We analyze both pieces around the boundary point x = 1. For values less than or equal to 1, we draw the line y = x + 1, which reaches the point (1, 2) with a closed endpoint. To the right of 1, we sketch the parabola y = x2, starting from (1, 1) with an open endpoint:

Graph of a piecewise function with a linear piece and a quadratic piece showing a jump at x = 1
Graph of the function

Pay special attention to the points where the rule changes. At x = 1, the closed circle on x + 1 indicates that the output belongs to that piece, whereas the open circle on x2 shows that it is not included there. When the formulas on either side of the boundary yield different values (here 2 and 1), the graph exhibits a jump; conversely, if they meet at the same value (as happens with the absolute value at x = 0), the pieces connect continuously.

Example 2

Graph the following piecewise function made up of three expressions:

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

To construct the graph, we divide the coordinate plane into three vertical regions based on x = 0 and x = 2:

  • To the left of 0, we draw the ray y = −x approaching (0, 0) with an open circle.
  • Between 0 and 2, we draw the line segment y = 2x + 3, closed at both endpoints: from (0, 3) to (2, 7).
  • To the right of 2, we sketch the cubic curve y = x3, starting with an open circle at (2, 8).
Graph of a three-piece function: decreasing linear ray, increasing line segment, and cubic branch
Graph of the three-piece function: the middle segment 2x + 3 includes its endpoints at x = 0 and x = 2, leaving open circles on the outer pieces.

Example 3

Sketch the graph of the absolute value function by first writing it as a piecewise function.

The absolute value of a real number x, denoted |x|, represents its distance from zero on the number line, so it is always greater than or equal to zero. If x is non-negative, it equals the number itself; if x is negative, its sign is flipped by multiplying by −1:

$$|x| = \begin{cases} x & \text{if } x \ge 0 \\ -x & \text{if } x < 0 \end{cases}$$

When we graph both rays, we see that y = −x slopes down to the origin and y = x rises from (0, 0). Because both expressions equal 0 when x = 0, the two pieces join seamlessly without any jump:

V-shaped graph of the piecewise absolute value function with vertex at the origin
The absolute value function |x| joins two rays at the vertex (0, 0), forming a continuous V-shaped graph.

Example 4

Sketch the graph of a piecewise function that includes an isolated point and intervals where it is undefined:

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

We draw each piece while leaving gaps where no rule is assigned: a horizontal line segment at y = 1 from x = −2 to x = 0 (both closed), a parabolic arc between x = 0 and x = 1 (both open), a single isolated point at (2, 3), and the ray y = x starting at x = 3 with an open circle at (3, 3):

Graph of a four-piece function with an isolated point at (2, 3) and undefined intervals
Graph of four pieces showing an isolated point at (2, 3) and empty vertical strips where the function is undefined.

When a condition specifies a single input value, such as x = 2 with f(x) = 3, its graph is a single isolated point on the plane. In regions where no condition includes x (such as between 1 and 2, or between 2 and 3), nothing is drawn because the function has no output on those intervals.

Domain and Range of a Piecewise Function

To analyze a piecewise function completely, we need to determine which values the independent variable can take (the domain) and what set of output values it produces (the range). Since each piece operates under its own rules, both sets are found by combining the information from all pieces.

How to Find the Domain

The domain of a piecewise function is the union of the subdomains of each piece. To find it without missing any restrictions, check two things for every piece:

  1. The explicit interval written to the right of the formula (for instance, \(x \le 1\) or \(0 < x < 1\)).
  2. Any inherent algebraic restrictions of the mathematical expression (avoiding division by zero and even-index roots of negative numbers, among others).

Example 1

Find the domain of the two-piece function analyzed in the previous sections:

$$f(x) = \begin{cases} x + 1 & \text{if } x \le 1 \\ x^2 & \text{if } x > 1 \end{cases}$$

Examining the conditions, we see that the first piece covers all real numbers less than or equal to 1, and the second covers all real numbers greater than 1. Since both formulas are polynomials, they have no algebraic restrictions and together span the entire real number line without gaps; therefore, the domain is:

$$D_f = (-\infty, 1] \cup (1, \infty) = \mathbb{R}$$

Example 2

Find the domain of the function involving a radical and a rational expression:

$$f(x) = \begin{cases} \sqrt{x} & \text{if } x \le 4 \\ \dfrac{1}{x} & \text{if } x > 4 \end{cases}$$

Here it is best to analyze each piece separately before taking their union. The square root \(\sqrt{x}\) requires the radicand to be non-negative (\(x \ge 0\)); intersecting this condition with the interval \(x \le 4\) restricts the first piece to \([0, 4]\). Meanwhile, \(\dfrac{1}{x}\) is undefined at \(x = 0\), but since it applies only for \(x > 4\), that restriction does not affect the function. Taking the union of both intervals yields:

$$D_f = [0, 4] \cup (4, \infty) = [0, \infty)$$

Example 3

Find the domain of the four-piece function with separated intervals:

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

None of the four formulas carries any inherent algebraic restrictions, so the domain is simply the union of the four given sets. Notice that the first and second pieces connect at \(x = 0\) to form the interval \([-2, 1)\), while gaps remain between 1 and 2, and between 2 and 3:

$$D_f = [-2, 0] \cup (0, 1) \cup \{2\} \cup (3, \infty) = [-2, 1) \cup \{2\} \cup (3, \infty)$$

How to Find the Range

The range of a piecewise function is the union of the sets of output values produced by each piece over its respective interval. It can be determined in two complementary ways:

  • Graphically: Project all pieces of the graph onto the vertical y-axis to see which heights are covered and which are left empty, accounting for closed and open circles.
  • Analytically: Find the output interval of each subfunction over its specific domain interval and take the union of the resulting sets.

Example 1

Find the range of the linear and quadratic function from the first example:

$$f(x) = \begin{cases} x + 1 & \text{if } x \le 1 \\ x^2 & \text{if } x > 1 \end{cases}$$

We analyze the values that y reaches on each piece:

  • On the first piece, \(y = x + 1\) is increasing. Since \(x \le 1\), its maximum value occurs at \(x = 1\) (where \(y = 2\), included) and extends downward without bound to the left, covering the interval \((-\infty, 2]\).
  • On the second piece, \(y = x^2\) is also increasing for \(x > 1\). It starts from \(y = 1\) (not included, since \(x > 1\)) and grows without bound, contributing the interval \((1, \infty)\).

When we take the union of both sets, the interval \((1, 2]\) overlaps, so the range spans all real numbers:

$$R_f = (-\infty, 2] \cup (1, \infty) = \mathbb{R}$$

Example 2

Find the range of the three-piece function graphed in the previous section:

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

We find the set of outputs for each piece separately:

  • For \(x < 0\), the expression \(-x\) takes strictly positive values, giving the interval \((0, \infty)\).
  • For \(0 \le x \le 2\), the increasing line \(2x + 3\) runs from \(f(0) = 3\) to \(f(2) = 7\), generating the closed interval \([3, 7]\).
  • For \(x > 2\), the cubic function \(x^3\) starts above \(2^3 = 8\) and increases without bound, yielding \((8, \infty)\).

Taking the union of all three results, the first interval \((0, \infty)\) already contains both \([3, 7]\) and \((8, \infty)\), so the final range is:

$$R_f = (0, \infty) \cup [3, 7] \cup (8, \infty) = (0, \infty)$$

Example 3

Find the range of the four-piece function with an isolated point:

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

We check which y-values each condition contributes:

  • The first piece is constant at \(y = 1\), so it contributes only the singleton set \(\{1\}\).
  • The second piece, \(x^2 + 1\) on \((0, 1)\), takes values between \(0^2 + 1 = 1\) and \(1^2 + 1 = 2\), both open: \((1, 2)\).
  • The third piece contributes only the y-coordinate of the isolated point: \(\{3\}\).
  • The fourth piece, \(y = x\) for \(x > 3\), covers all values greater than 3: \((3, \infty)\).

When we take the union of all these sets, the isolated value \(1\) closes the interval \((1, 2)\) on the left to form \([1, 2)\), and the isolated value \(3\) closes \((3, \infty)\) on the left to form \([3, \infty)\):

$$R_f = \{1\} \cup (1, 2) \cup \{3\} \cup (3, \infty) = [1, 2) \cup [3, \infty)$$

How to Write the Formula from a Graph

Sometimes you are given the graph of a piecewise function and asked to reconstruct its algebraic formula. To do this, read the coordinate plane from left to right, identifying where each piece begins and ends along with the type of curve shown.

The procedure can be summarized in three steps:

  1. Identify the intervals on the x-axis: Look at the x-coordinates where each piece starts or changes shape. A closed circle indicates that the endpoint is included (≤ or ≥), whereas an open circle indicates that it is excluded (< or >).
  2. Determine the formula for each piece: Recognize the geometric shape of each section (a line through two points, a horizontal constant, a parabola, or a standard curve) and find its equation.
  3. Assemble the piecewise function: Group each formula with its corresponding interval inside a curly brace, ordering the pieces from left to right according to increasing x-values.

Example

Write the algebraic formula for the piecewise function shown in the following graph:

Graph of a piecewise function consisting of a square root branch up to x = 4 and a rational branch for x greater than 4

We analyze the graph from left to right using the steps above:

  • First piece (left): The curve starts at the origin (0, 0) with a closed circle, moves right through (1, 1) and (4, 2), and ends at x = 4 with another closed circle. This path corresponds to the square root function \(y = \sqrt{x}\) defined on the interval \(0 \le x \le 4\) (which can also be written as \(x \le 4\), since the real square root is undefined for negative values).
  • Second piece (right): Immediately after x = 4, the graph jumps downward, starting with an open circle at (4, 1/4) and approaching the horizontal axis as x increases. This curve corresponds to the rational function \(y = \dfrac{1}{x}\) on the interval \(x > 4\).

Combining both pieces with their respective intervals gives the complete formula for the function:

$$f(x) = \begin{cases} \sqrt{x} & \text{if } 0 \le x \le 4 \\ \dfrac{1}{x} & \text{if } x > 4 \end{cases}$$

Did you find this useful? Rate it!

0.0 / 5 — 0 votes

Daniel Machado

Mathematics teacher and administrator of Flamath, where he shares content about Mathematical Logic

HOW TO CITE THIS ARTICLE
Machado, D. (2026, December 6). Piecewise Functions. Flamath. https://en.flamath.com/piecewise-functions

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *