Sometimes, we come across a function that requires more than one formula in order to obtain the given output. For example, in the toolkit functions, we introduced the absolute value function \displaystyle f\left(x\right)=|x|f(x)=∣x∣. With a domain of all real numbers and a range of values greater than or equal to 0, absolute value can be defined as the magnitude, or modulus, of a real number value regardless of sign. It is the distance from 0 on the number line. All of these definitions require the output to be greater than or equal to 0.
If we input 0, or a positive value, the output is the same as the input.
\displaystyle f\left(x\right)=x\text{ if }x\ge 0f(x)=x if x≥0
If we input a negative value, the output is the opposite of the input.
\displaystyle f\left(x\right)=-x\text{ if }x<0f(x)=−x if x<0
Because this requires two different processes or pieces, the absolute value function is an example of a piecewise function. A piecewise function is a function in which more than one formula is used to define the output over different pieces of the domain.
We use piecewise functions to describe situations in which a rule or relationship changes as the input value crosses certain “boundaries.” For example, we often encounter situations in business for which the cost per piece of a certain item is discounted once the number ordered exceeds a certain value. Tax brackets are another real-world example of piecewise functions. For example, consider a simple tax system in which incomes up to $10,000 are taxed at 10%, and any additional income is taxed at 20%. The tax on a total income, S, would be 0.1S if \displaystyle {S}\leS≤ $10,000 and 1000 + 0.2 (S – $10,000), if S> $10,000.