6.3 Other ways of defining functions

Polynomial expressions give us a very wide class of functions and these functions have the convenient property that they can be expressed as a single formula. But not all functions are polynomial functions and not all functions can be expressed as a single formula. For example, the graph below has a sudden change of direction at x=0x=0 and therefore its corresponding function cannot be expressed as a polynomial22 2 This is related to the fact that polynomials are “smooth”. This is a term you will encounter in your future Analysis courses..

xxyy4-43-32-21-1112233441-111223344

So how do we express the function that corresponds to graphs like this?

6.3.1 Defining a function by cases

A mathematical function defined by cases specifies different formulas or rules for different parts of its domain. These are also known as piecewise functions. Instead of using a single expression, the function is broken into pieces depending on conditions such as inequalities, intervals, or specific values of the input.

Example 6.23.

Consider the function f:f:\mathbb{R}\to\mathbb{R} where

f(x)={x2if x0,x2if x<0.f(x)=\begin{cases}x^{2}&\text{if }x\geq 0,\\ -x^{2}&\text{if }x<0.\end{cases}

This means:

  • when x0x\geq 0, the function outputs x2x^{2};

  • when x<0x<0, the function outputs x2-x^{2}.

We can sketch this in a graph below:

xxf(x)f(x)f(x)=x2,x<0f(x)=-x^{2},\,x<0f(x)=x2,x0f(x)=x^{2},\,x\geq 0

In general, the structure of a piecewise function is as follows:

f(x)={expression Aif condition A,expression Bif condition B,f(x)=\begin{cases}\text{expression A}&\text{if condition A},\\ \text{expression B}&\text{if condition B},\\ \quad\vdots&\quad\vdots\end{cases}

The conditions must cover the whole domain of the function and they should not overlap (this is to ensure that each input has a unique output).

Definition 6.24.

The modulus or absolute value function is defined by ||:[0,)|\cdot|:\mathbb{R}\to[0,\infty) where

|x|={x,if x0,x,if x<0.|x|=\begin{cases}x,&\text{if }x\geq 0,\\ -x,&\text{if }x<0.\end{cases}

Note that the notation for the modulus function is the same as the notation we used for the cardinality of a set. The way to tell them apart is to identify the type of object that lies between the two vertical lines. If this object represents a real number, then this notation represents the modulus function.

Exercise 6.25.

Consider the function f:f:\mathbb{R}\to\mathbb{R} where f(x)=x|x|f(x)=x-|x|.

  1. 1.

    Use the definition of the modulus function to re-write ff as a piecewise function.

  2. 2.

    Sketch the graph of the function ff.

Solution (please try for yourself before looking)
  1. 1.

    When x0x\geqslant 0, |x|=x|x|=x. Thus, for this range of xx, f(x)=xx=0f(x)=x-x=0. However, when x<0x<0, |x|=x|x|=-x which means f(x)=x(x)=2xf(x)=x-(-x)=2x for this range of xx. Hence, we can write ff as

    f(x)={0, if x0,2x, if x<0.f(x)=\begin{cases}0,\text{ if }x\geqslant 0,\\ 2x,\text{ if }x<0.\end{cases}
  2. 2.

    A sketch of the graph ff is as follows:

    xxf(x)f(x)f(x)=2x,x<0f(x)=2x,\,x<0f(x)=0,x0f(x)=0,\,x\geq 0
Exercise 6.26.

The Dirichlet function 𝟏:{0,1}\bm{1}_{\mathbb{Q}}:\mathbb{R}\to\{0,1\} is defined by the formula

𝟏(x)={1if x0otherwise.\bm{1}_{\mathbb{Q}}(x)=\begin{cases}1&\text{if $x\in\mathbb{Q}$}\\ 0&\text{otherwise.}\end{cases}

Let rr be a positive rational number. Prove that 𝟏\bm{1}_{\mathbb{Q}} is rr-periodic.

Solution (please try for yourself before looking)

If rr is a positive rational number, x+rx+r\in\mathbb{Q} for every xx\in\mathbb{Q} and y+ry+r\notin\mathbb{Q} for every yy\notin\mathbb{R} (as we saw in Block 1). Hence, 𝟏(x+r)=𝟏(x)=1\bm{1}_{\mathbb{Q}}(x+r)=\bm{1}_{\mathbb{Q}}(x)=1 for every xx\in\mathbb{Q} and 𝟏(y+r)=𝟏(y)=0\bm{1}_{\mathbb{Q}}(y+r)=\bm{1}_{\mathbb{Q}}(y)=0 for every yy\notin\mathbb{Q}.

6.3.2 Defining a function in words

Example 6.27.

The integer part function []:\left[\;\cdot\;\right]:\mathbb{R}\to\mathbb{Z} takes a real number xx as its input and returns the integer part of xx. (For a definition of the integer part of a real number, see Section 2.1.)

Example 6.28.

The function cos:\cos:\mathbb{R}\to\mathbb{R} can be defined by the following process.

Consider the unit circle x2+y2=1x^{2}+y^{2}=1.

Let θ\theta be any real number and let LL denote the straight line that radiates from the origin to form the angle θ\theta radians anti-clockwise with the positive xx-axis. The xx-coordinate of the intersection point between LL and the unit circle is defined to be the value of cos(θ)\cos(\theta).

The function sin:\sin:\mathbb{R}\to\mathbb{R} can be defined in a similar way but where the value of the function is given by the yy-coordinate of the intersection point on the unit circle.

Exercise 6.29.

Assume that each nn\in\mathbb{N}, is written as a product of primes

n=2p2(n)3p3(n)5p5(n),n=2^{p_{2}(n)}3^{p_{3}(n)}5^{p_{5}(n)}\cdots,

where each pk(n)p_{k}(n) is a non-negative integer, which depends on nn. Let f:0f:\mathbb{N}\to\mathbb{N}_{0} be defined as f(n)=p2(n)f(n)=p_{2}(n).

How do you know that ff is a function?

Solution (please try for yourself before looking)

This is a function since the Fundamental Theorem of Arithmetic tells us every integer n2n\geqslant 2 can be written as a product of primes and any prime that doesn’t appear in the prime decomposition of nn just has a power of 0, which our codomain 0\mathbb{N}_{0} allows. Also, 11 can be written as a product of prime powers where every power is 0. So for every xx\in\mathbb{N}, there exists some y0y\in\mathbb{N}_{0} where f(x)=yf(x)=y and this yy is unique as p2(n)p_{2}(n) is defined to be largest y0y\in\mathbb{N}_{0} such that 2y|n2^{y}|n.

6.3.3 Not all formulas define functions

When defining functions, we cannot simply write down any old algebraic expression and use this as the rule.

Exercise 6.30.

Suppose we try to define a function g:g:\mathbb{Q}\to\mathbb{Z} by the formula

g(ab)=a+b.g\left(\frac{a}{b}\right)=a+b.

Why is this not a function?

Solution (please try for yourself before looking)

According to the formula, g(12)=3g\bigl{(}\frac{1}{2}\bigr{)}=3 and g(24)=6g\bigl{(}\frac{2}{4}\bigr{)}=6. But 12=24\frac{1}{2}=\frac{2}{4} and so if gg were a function then we would require g(12)=g(24)g\bigl{(}\frac{1}{2}\bigr{)}=g\bigl{(}\frac{2}{4}\bigr{)}.

Example 6.31.

Let h:h:\mathbb{Q}\to\mathbb{Z} where

h(ab)=a2+b2ab.h\left(\frac{a}{b}\right)=\frac{a^{2}+b^{2}}{ab}.

This is not a function because the codomain is \mathbb{Z} but h(12)=12+2212=52h\left(\frac{1}{2}\right)=\frac{1^{2}+2^{2}}{1\cdot 2}=\frac{5}{2}\notin% \mathbb{Z}.