Some functions are defined in pieces by different formulas in different parts of their domains. We saw two of such functions in Example 1 of the previous section. We call such functions piecewise-defined functions.

### Absolute Value Function

An important example of a piecewise defined function is the absolute value function $f(x)=|x|$, which can also be written as:

$f(x)=\left\{\begin{matrix} x & \text{if } x\geq 0\\ -x & \text{if } x<0 \end{matrix}\right.$

The graph of this function is shown in Fig 1. Figure1: Graph of  $y=|x|$

### Sign Function

Another important piecewise defined function is the sign (or signum) function. The sign function, often denoted by ${\rm sgn}$ or $\text{sign}$, extracts the sign of a real number $x$ (see Fig 2.)

${\rm sgn}(x)=\left\{ \begin{matrix} 1 & \text{if } x>0\\ 0 & \text{if } x=0\\ -1 & \text{if } x<0 \end{matrix}\right.$ Figure 2: Graph of $y=\text{sgn}(x) .$

### Greatest Integer Function or Floor Function

A function that takes a real number $x$ as input and returns the largest integer less than or equal to $x$ is called the greatest integer function or the  floor function. It is denoted $\lfloor x\rfloor$. In fact, this function rounds down a real number to the nearest integer. For example

$\lfloor7\rfloor=7,\qquad\lfloor 1.34\rfloor=1,\qquad\lfloor 3.99\rfloor=3,$ $\lfloor-7\rfloor=-7,\qquad\lfloor-1.34\rfloor=-2,\qquad\lfloor-3.99 \rfloor=-4,$ $\lfloor\sqrt{2}\rfloor=1,\qquad\lfloor0.12\rfloor=0$

$\lfloor-\sqrt{2}\rfloor=-2,\qquad\lfloor-0.12\rfloor=-1$

• The greatest integer function is a function from $\mathbb{R}$ to $\mathbb{Z}$ (set of all integers)
$\mathbb{R}\to\mathbb{Z}$
• Using mathematical notations, we can write
$\lfloor x\rfloor=\max\{m\in\mathbb{Z}|\ m\leq x\}.$
•  Other symbols for the greatest integer function are $[x]$ and $[\![x]\!]$. Figure 3: Graph of $y=\lfloor x\rfloor$
The graph of $y=\lfloor x\rfloor$ is shown in Figure 3.
Example 1
A function $f$ is defined by
$f(x)= \begin{cases} 2x-3 & \text{if }{x>2}\\ {x-1} & \text{if }{-1<x\leq2}\\ {-2x+1} &\text{if } {x\leq-1} \end{cases}$ Evaluate $f(2)$, $f(0)$, $f(-1)$, and plot its graph.
Solution

Because $2\in(-1,2]$, to evaluate $f(2)$ we use the middle formula:
$f(2)=x-1\Big|_{x=2}=2-1=1.$ Also
$0\in(-1,2]\Rightarrow f(0)=x-1\Big|_{x=0}=0-1=-1.$ To evaluate $f(-1)$, we note that $-1\in(-\infty,-1]$. Therefore, we should use the bottom formula:

$f(-1)=-2x+1\Big|_{x=-1}=-2\times(-1)+1=3.$ Fig 4 represents the graph of $f$.