Piecewise functions

Topic guide · Updated 2026-11-26

Quick answer

A piecewise function uses different formulas on different parts of its domain. For example f(x) = x² when x < 0 and f(x) = x + 1 when x ≥ 0. In the graphing calculator, write it with braces: y = {x < 0: x^2, x + 1}.

−5−4−3−2−112345−2−11234
  • y={x<0: x^2, x+1}
Open in graphing calculator

Syntax

{condition: value, condition: value, otherwise}

Conditions are checked from left to right; the first true one wins. If no condition is true and there is no default, the function is undefined there. A brace with only a condition restricts any expression: y = sin(x) {x > 0}.

Evaluating a piecewise function

Find which condition the input satisfies, then use that piece only. For the example, f(−2) = (−2)² = 4 and f(3) = 3 + 1 = 4. At x = 0, the second piece applies, so f(0) = 1.

Common piecewise functions

Absolute value is piecewise: |x| = {x < 0: −x, x}. Tax brackets, shipping rates and phone plans are real-world piecewise functions.

Frequently asked questions

How do I show an open or closed endpoint?

Use < or > for an excluded endpoint and <= or >= for an included one. Add a point such as (0, 1) to mark it visually.