A piecewise function uses different formulas for different parts of its domain. The conditions are part of the definition: each permitted input must receive one unambiguous output.

Using non-overlapping conditions makes the choice of rule straightforward. If conditions overlap, every applicable formula must agree at the overlap; otherwise the definition does not describe a function.

On this page (8 sections)

Reading a piecewise definition

f(x)= { x + 2 , x < 0 , x 2 , x ≥ 0. f(x)=\begin{cases}x+2,&x<0,\\x^2,&x\ge0.\end{cases}

Choose the rule using the input condition before doing any calculation.

The condition selects the calculation
InputApplicable ruleOutput
−2-2 x+2x+2 f(−2)=−2+2=0f(-2)=-2+2=0
00 x 2 x^2 f(0)= 0 2 =0f(0)=0^2=0
33 x 2 x^2 f(3)= 3 2 =9f(3)=3^2=9

The domain is the union of the two allowed input sets, which is all real numbers here. The formulas are alternatives; do not add them or apply both in succession.

Evaluating at a boundary

At x=0x=0, the condition x≥0x\ge0 includes equality, so the point (0,0)(0,0) belongs to the graph. The first branch is restricted to x<0x<0, so its limiting point (0,2)(0,2) is open.

Graph each rule only on its own inputs

Graph each rule only on its own inputsAt zero, the second rule applies. The first rule approaches output 2 from the left but never assigns that endpoint. The graph therefore has a jump at zero.−4−3−2−101234−20246810xyexcluded (0, 2)included (0, 0)
  • y=x+2y=x+2 for x<0x<0
  • y= x 2 y=x^2 for x≥0x\ge0
The open point at (0,2)(0,2) is excluded; the filled point at (0,0)(0,0) is included.
Diagram explained

At zero, the second rule applies. The first rule approaches output 2 from the left but never assigns that endpoint. The graph therefore has a jump at zero.

Exact reference values for this graph
InputOutput
−2-2 00
−1-1 11
00 00
11 11
33 99

Plot each formula only on the inputs named by its condition. Drawing the entire parabola and the entire line would represent extra pairs that do not belong to this function.

Piecewise functions can be continuous or discontinuous

A change of formula does not automatically create a break. In this example, the line approaches output 22 as inputs approach zero from the left, while the parabola approaches 00 from the right. The assigned value is f(0)=0f(0)=0, so the pieces do not join continuously.

By contrast, the two branches in the absolute-value definition below both meet at (0,0)(0,0). Continuity concerns whether the outputs join, not whether the printed formula changes. A formal limit-based treatment appears in Continuity of Functions.

Absolute value is piecewise

|x|= { − x , x < 0 , x , x ≥ 0. |x|=\begin{cases}-x,&x<0,\\x,&x\ge0.\end{cases}

For a negative input, −x-x is positive: at x=−3x=-3, it equals 33. For a non-negative input, the output is the input itself. Both branches therefore express distance from zero.

The two branches of the absolute-value function

The graph of absolute value has two straight branches meeting at the origin.
The branches −x-x for x<0x<0 and xx for x≥0x\ge0 meet at (0,0)(0,0).

The two branches of the absolute-value function · Qef, after Ævar Arnfjörð Bjarmason · CC BY-SA 3.0. Typography normalized; drawing unchanged.

Diagram explained

At inputs −2 and 2, the common output is 2. At input 0, the output is 0. Every input has one output, even though the graph uses two formulas. The two pieces meet continuously.

Piecewise models

A hypothetical parking charge

Let tt be parking time in hours. Suppose up to two hours costs 44 dollars and each additional hour is charged proportionally at 33 dollars per hour. For t≥0t\ge0:

C(t)= { 4 , 0 ≤ t ≤ 2 , 4 + 3 ( t − 2 ) , t > 2. C(t)=\begin{cases}4,&0\le t\le2,\\4+3(t-2),&t>2.\end{cases}

Then C(2)=4C(2)=4 and C(3)=7C(3)=7. The extra charge uses t−2t-2, not tt, because the first two hours are already included. At the threshold, both formulas give 44, so the model joins continuously.

Charging for each started hour would require a different step rule. The conditions and billing convention must be specified; the formula alone does not determine them.

Practice questions

  1. For the displayed piecewise function, find f(−2)f(-2).

  2. Find f(0)f(0).

  3. Find f(3)f(3).

Check your answers
  1. −2<0-2<0, so use the first rule: f(−2)=−2+2=0f(-2)=-2+2=0.

  2. Use the rule that includes equality at zero: f(0)= 0 2 =0f(0)=0^2=0.

  3. 3≥03\ge0, so f(3)= 3 2 =9f(3)=3^2=9.

Related topics

Study the distance interpretation in Absolute Value Functions; use Domain and Range to combine the allowed intervals.

Sources and further reading