Department of Computer Science | Institute of Theoretical Computer Science | CADMO

Theory of Combinatorial Algorithms

Prof. Emo Welzl and Prof. Bernd Gärtner

ExTeX --- Functions

Score:0/0/0
Actions:

Functions

Math Refresher 3, Bernd Gärtner(30 September, 2023)

1Questions and Answers

Given two sets XX and YY, a function ff from XX to YY is a rule that selects for each element of XX exactly one element of YY. The mathematical notation f:XYf:X\rightarrow Y says that ff is a function from XX to YY. The element yYy\in Y that is selected for xXx\in X is called the value of the argument xx and is written as f(x)f(x). Note that X,Y,x,yX,Y,x,y are variables here that are placeholders for concrete sets and concrete elements of these sets.

For example, if XX is the set of countries in the world and YY is the set of cities in the world, then we can consider the function f:XYf:X\rightarrow Y that selects for each country its capital. The value of the argument Austria is Vienna,

f(Austria)=Vienna.\displaystyle f(\text {Austria})=\text {Vienna}.
Because sets are mathematical entities and do not correspond to bags in real life, they do not actually contain countries or cities, but just text symbols that identify the countries and cities.

We can also think of XX as questions in a quiz, and YY as answers. Then a function ff provides an answer y=f(x)Yy=f(x)\in Y for every question xXx\in X. Our example function above provides the answer to every question of the form What is the capital of country xx?

In this example, there are elements of YY (for example, Zurich) that are not selected for any xx, so there may be answers that will never be given. That’s ok. The only thing we require is that for every question, there is an answer. We also allow that several questions have the same answer. As an example, consider the function corresponding to the question What is the first letter of country xx’s name? This gives the same answer A for Austria, or Australia, or Albania, or....

Exercise 1.

A boolean function is a function f:{0,1}{0,1}f:\{ 0,1\} \rightarrow \{ 0,1\} . Such a function can be defined by a value table with just two rows, for example

xf(x)0110\displaystyle \begin {array}{c|c}x & f(x) \\ \hline 0 & 1 \\ 1 & 0\end {array}
If we interpret 00 as false and 11 as true, this is actually the truth table of the logical NOT from the first reading assignment. Now for the actual exercise: How many boolean functions are there?

Input (Number)

Enter a number in the box. You can enter

  • a natural number, such as 22,

  • an integer, such as ‐7,

  • a quotient, such as 22/7, or

  • a terminating decimal, such as 3.14285.

There may be more than one correct solution.

Exercise 2.

Let X={1,2,3}X=\{ 1,2,3\} and Y={1,2,...,10}Y=\{ 1,2,...,10\} . How many different functions f:XYf:X\rightarrow Y are there?

Input (Number)

Enter a number in the box. You can enter

  • a natural number, such as 22,

  • an integer, such as ‐7,

  • a quotient, such as 22/7, or

  • a terminating decimal, such as 3.14285.

There may be more than one correct solution.

The mathematician creates another theorem out of this.

Theorem 3.

Let n,kNn,k\in \N . Let XX be a set with kk elements and YY a set with nn elements. There are nkn^k functions f:XYf:X\rightarrow Y.

2Invertible functions

Suppose we are given the answer and want to know what the question was. If there is always a single question xXx\in X that leads to a given answer yYy\in Y, then this defines a function f1:YXf^{-1}:Y\rightarrow X that we call the inverse of ff: For every answer yYy\in Y, f1(y)f^{-1}(y) is then the single question xXx\in X with answer yy. We can think of f1f^{-1} as the function that “undoes" ff: if we compute f1(f(x))f^{-1}(f(x)), we get back xx for every question xXx\in X, so nothing happened. Indeed, ff takes us from the question xx to the answer f(x)f(x), and f1f^{-1} takes us from the answer f(x)f(x) back to the question f1(f(x))=xf^{-1}(f(x))=x.

Let’s look at this for the function ff corresponding to questions of the form What is the capital of country xx? If we are given the answer Vienna, we know that the question was Austria. Similarly, for every answer that is actually the capital of some country xx, we know the question (namely xx). But if the answer is Zurich, we cannot find a question with this answer. So the function ff is not invertible. But it becomes invertible if we say that YY is not the set of all cities in the world but only the set of all capitals in the world.

Let’s consider the function corresponding to the question What is the first letter of country xx’s name? This function is not invertible, even if we say that YY is only the set of letters that occur as first letter of some country’s name. Indeed, if the answer was A, we can’t tell whether the question was Austria, or Australia, or Albania, or....

The pigeon‐hole principle.Even without remembering several countries whose names start with A, we would have known that the function just considered cannot be invertible. After all, there are only 26 letters, but (much) more than 26 countries in the world, so it is inevitable that several country names start with the same letter. This is known as the pigeon‐hole principle, and in function language, it can be stated as follows.

Principle 4.

Let XX and YY be finite sets such that YY has fewer elements than XX. Then for every function f:XYf:X\rightarrow Y, there are two different arguments xXx\in X and xXx'\in X with the same value f(x)=f(x)f(x)=f(x'). As a consequence, no function f:XYf:X\rightarrow Y is invertible.

There is a fun fact based on the pigeon‐hole principle: you can find two people in Zurich with exactly the same number of hairs. This is due to the fact that a human (according to various sources, and adding a safety margin) has never more than 200,000200,000 hairs. Hence, among roughly 400,000400,000 people in Zurich, there must certainly be two with the same number of hairs. Unfortunately, the pigeon‐hole principle does not tell us how to find them.

A variant of the pigeon‐hole principle shows that f:XYf:X\rightarrow Y is also not invertible if YY has more elements than XX. Indeed, if there are less questions than answers, then some answer will never be given and hence ff is not invertible. This is what happened to Zurich in the country capitals example above. But again, we do not need to remember the capital status of Zurich to make the argument (many people get that status wrong, anyway). We simply need to know that there are (many) more cities in the world than countries, so it is inevitable that some cities are not capitals.

The upshot is that f:XYf:X\rightarrow Y can only be invertible if XX and YY actually have the same number of elements. The following picture summarizes the situation.

Exercise 5.

Recall from Exercise 1 that there are four boolean functions f:{0,1}{0,1}f:\{ 0,1\} \rightarrow \{ 0,1\} . Which of them are invertible?

Input (Multiple Choice)

  • xf(x)0010\begin {array}{c|c}x & f(x) \\ \hline 0 & 0 \\ 1 & 0\end {array}
  • xf(x)0011\begin {array}{c|c}x & f(x) \\ \hline 0 & 0 \\ 1 & 1\end {array}
  • xf(x)0110\begin {array}{c|c}x & f(x) \\ \hline 0 & 1 \\ 1 & 0\end {array}
  • xf(x)0111\begin {array}{c|c}x & f(x) \\ \hline 0 & 1 \\ 1 & 1\end {array}

Decide which of the provided answers are correct and select them by clicking on the corresponding boxes, thus marking them with a blue border like so:

  • Unselected
  • Selected
  • Unselected
  • Selected

Any number of the provided answers can be correct, including zero.

Actually, if XX is a finite set, we can always think of a function f:XYf:X\rightarrow Y as a (possibly large) table, and in this table view, it is quite easy to see when a function is invertible. Consider the case where X=Y={1,2,3,4}X=Y=\{ 1,2,3,4\} . The function

xf(x)14223143\displaystyle \begin {array}{c|c}x & f(x) \\ \hline 1 & 4 \\ 2 & 2 \\ 3 & 1\\ 4 & 3\end {array}
is invertible, because every element of YY occurs exactly once in the right column. This is the same as saying that there is a single question for every possible answer yYy\in Y.

Hence, for an invertible function, the right column just lists all the elements of YY, in some order. Also, the inverse is very easy to construct from the table, by simply interchanging the two columns (instead of going from questions to answers, we now go from answers to questions). This means, the inverse of the previous function is

yf1(y)41221334\displaystyle \begin {array}{c|c}y & f^{-1}(y) \\ \hline 4& 1\\ 2 & 2\\ 1 & 3\\ 3 & 4\end {array}(1)
but we would typically still reorder the rows so that the left column is sorted for better readability of the table (see Exercise 7 below).

In contrast,

xf(x)12243443\displaystyle \begin {array}{c|c}x & f(x) \\ \hline 1 & 2 \\ 2 & 4 \\ 3 & 4\\ 4 & 3\end {array}
is not invertible, because an element of YY occurs twice (and another one not at all) in the right column.

Exercise 6.

From Exercise 5 we know that the function

xf(x)0110\displaystyle \begin {array}{c|c}x & f(x) \\ \hline 0 & 1 \\ 1 & 0\end {array}
is invertible. But which of the following functions is its inverse f1f^{-1}?

Input (Single Choice)

  • yf1(y)0010\begin {array}{c|c}y & f^{-1}(y) \\ \hline 0 & 0 \\ 1 & 0\end {array}
  • yf1(y)0011\begin {array}{c|c}y & f^{-1}(y) \\ \hline 0 & 0 \\ 1 & 1\end {array}
  • yf1(y)0110\begin {array}{c|c}y & f^{-1}(y) \\ \hline 0 & 1 \\ 1 & 0\end {array}
  • yf1(y)0111\begin {array}{c|c}y & f^{-1}(y) \\ \hline 0 & 1 \\ 1 & 1\end {array}

Decide which of the provided answers is correct and select it by clicking on the corresponding box, thus marking it with a blue border like so:

  • Unselected
  • Selected
  • Unselected

Exactly one of the provided answers is correct.

Exercise 7.

From above, we know that the function f:XYf:X\rightarrow Y with X=Y={1,2,3,4}X=Y=\{ 1,2,3,4\} , given by the table

xf(x)14223143\displaystyle \begin {array}{c|c}x & f(x) \\ \hline 1 & 4 \\ 2 & 2 \\ 3 & 1\\ 4 & 3\end {array}
is invertible. Which of the following functions is its inverse f1f^{-1}?

Input (Single Choice)

  • yf1(y)13223441\begin {array}{c|c}y& f^{-1}(y) \\ \hline 1 & 3 \\ 2 & 2 \\ 3 & 4 \\ 4 & 1\end {array}
  • yf1(y)14223143\begin {array}{c|c}y & f^{-1}(y) \\ \hline 1 & 4 \\ 2 & 2 \\ 3 & 1 \\ 4 & 3\end {array}
  • yf1(y)14233142\begin {array}{c|c}y & f^{-1}(y) \\ \hline 1& 4\\ 2 & 3 \\ 3& 1 \\ 4& 2\end {array}
  • yf1(y)11223443\begin {array}{c|c}y & f^{-1}(y) \\ \hline 1& 1 \\ 2& 2 \\ 3& 4 \\ 4& 3\end {array}

Decide which of the provided answers is correct and select it by clicking on the corresponding box, thus marking it with a blue border like so:

  • Unselected
  • Selected
  • Unselected

Exactly one of the provided answers is correct.

Exercise 8.

Let X={1,2,3}X=\{ 1,2,3\} and Y={1,2,...,10}Y=\{ 1,2,...,10\} . How many different invertible functions f:XYf:X\rightarrow Y are there?

Input (Number)

Enter a number in the box. You can enter

  • a natural number, such as 22,

  • an integer, such as ‐7,

  • a quotient, such as 22/7, or

  • a terminating decimal, such as 3.14285.

There may be more than one correct solution.

Exercise 9.

Let X={1,2,3}X=\{ 1,2,3\} . How many different invertible functions f:XXf:X\rightarrow X are there?

Input (Number)

Enter a number in the box. You can enter

  • a natural number, such as 22,

  • an integer, such as ‐7,

  • a quotient, such as 22/7, or

  • a terminating decimal, such as 3.14285.

There may be more than one correct solution.

You will not be surprized that there is a general theorem behind this:

Theorem 10.

Let nNn\in \N and XX a set with nn elements. Then there are n!n! invertible functions f:XXf:X\rightarrow X.

The expression n!n! is known as the factorial and it denotes the product of the numbers between 11 and nn. For example, 3!=123=63!=1\cdot 2\cdot 3=6 and 4!=1234=244!=1\cdot 2\cdot 3\cdot 4=24.

3Numerical functions

If XX and YY are sets of numbers, we can visualize ff in a coordinate system with XX‐ and YY‐axes. You know this from high school where you have looked at numerical functions such as sin(x),cos(x)\sin (x),\cos (x), or log(x)\log (x).

Let us do a simpler example. Recall that R\R is the set of real numbers and set X=Y=R.X=Y=\R . Our function f:XYf:X\rightarrow Y is defined by

f(x)=2x5.\displaystyle f (x) = 2x-5.
This looks as follows in the coordinate system.

On the XX‐axis, we have the arguments xx (questions), and on the YY‐axis the values yy (answers). For example, question 00 has answer f(0)=205=5f(0)=2\cdot 0-5=-5, and for question 3,3, the answer is f(3)=235=1f(3)=2\cdot 3-5=1. We can summarize these question/answer pairs in form of the points (2‐tuples) (0,5)(0,-5) and (3,1)(3,1).

The fat line is the graph of ff, the set of all points of the form (x,f(x))(x,f(x)). Hence, for every question xx on the XX‐axis, the height of the graph at xx gives us the answer f(x)f(x).

The fact that ff is a function can also be seen by looking at the graph. We know that for every question xx, there is a single answer f(x)f(x). This means, whenever we draw a vertical line (dashed) at some value xx on the X‐axis, then this line intersects the graph of ff in a single point (x,f(x))(x,f(x)):

Is this particular function invertible? To check this formally, we must consider any possible real number yy and see whether we can find a unique xx such that f(x)=yf(x)=y. If it exists, such a number xx must satisfy

2x5f(x)=y.\displaystyle \underbrace {2x-5}_{f(x)}=y.
There is indeed a unique such number that we get by solving the previous equation for xx by the school method:
2x5=y+52x=y+5/2x=y+52=12y+52\displaystyle \begin {array}{rcl|l}2x - 5 &=& y & +5 \\ 2x &=& y+5 & /2 \\ x &=& \frac {y+5}{2} = \frac {1}{2}y + \frac {5}{2}\end {array}
So ff is invertible, and f1:RRf^{-1}:\R \rightarrow \R is defined by
f1(y)=12y+52.\displaystyle f^{-1}(y) = \frac {1}{2}y + \frac {5}{2}.

But we can also tell directly from the picture that ff is invertible, meaning that for every answer yy, there is a single question xx with this answer. Namely, whenever we draw a horizontal line at some yy, this line intersects the graph of ff in a single point (x,y)(x,y) at which y=f(x)y=f(x) (by definition of the graph), or x=f1(y)x=f^{-1}(y) as we can write, once we know that ff is invertible.

We can even get the graph of the inverse function f1f^{-1} from the picture. Indeed, when we find f1(y)f^{-1}(y) from yy via the horizontal line at yy, we do the same as when we find f(x)f(x) from xx via the vertical line at xx—only the roles of XX‐ and YY‐axis are interchanged. Hence, when we simply mirror the picture at the diagonal (dotted), we obtain the graph of f1f^{-1}!

The function f(x)=2x5f(x)=2x-5 is an affine function, and the mathematician immediately sees a theorem at the horizon that discusses all affine functions at once, using variables.

Theorem 11.

Let a,bRa,b\in \R such that a0a\neq 0 and consider the function f:RRf:\R \rightarrow \R defined by

f(x)=ax+b.\displaystyle f(x)=ax+b.
Then ff is invertible, and the inverse function is defined by
f1(y)=1ayba.\displaystyle f^{-1}(y) =\frac {1}{a}y - \frac {b}{a}.

Proof.We must consider any possible real number yy and see whether we can find a unique xx such that f(x)=yf(x)=y. If it exists, such a number xx must satisfy

ax+bf(x)=y.\displaystyle \underbrace {ax+b}_{f(x)}=y.
There is indeed a unique such number that we get by solving the previous equation for xx by the school method:
ax+b=ybax=yb/ax=yba=1ayba\displaystyle \begin {array}{rcl|l}ax + b &=& y & -b \\ ax &=& y-b & /a \\ x &=& \frac {y-b}{a} = \frac {1}{a}y - \frac {b}{a}\end {array}
So ff is invertible, and f1:RRf^{-1}:\R \rightarrow \R is defined by
f1(y)=1ayba.\displaystyle f^{-1}(y) = \frac {1}{a}y - \frac {b}{a}.

The condition a0a\neq 0 is needed so that we can divide by aa in the proof. If a=0a=0, the function is indeed not invertible. In this case we have f(x)=bf(x)=b, so every question xx has the same answer bb.

Let’s look at some non‐invertible numerical function. We define f:RRf:\R \rightarrow \R by f(x)=xf(x)=|x|, the absolute value of xx. This is the value that we get from xx by ignoring the sign. For example, 5=5|5|=5 and 6=6|-6|=6. This function is immediately seen to be non‐invertible. For starters, there is no question that leads to a negative answer. But even for a positive answer such as 66, there are two possible questions, namely 66 and 6-6. If we look at this in a coordinate system, we can graphically see what is going on:

If we draw a (dashed) horizontal line at some negative yy, it does not intersect the graph of ff at all; such a yy corresponds to an answer that is never given. If we draw a horizontal line at some positive yy, it intersects the graph of ff twice; this corresponds to the case where we have two questions leading to answer yy. Only for y=0y=0, there is a single question x=0x=0.

We could “fix” f(x)=xf(x)=|x| to make it invertible by defining f:R+R+f:\R _+\rightarrow \R _+, where R+\R _+ is the set of nonnegative real numbers. Then ff would “live” only in the upper right square of the coordinate system, and there it is invertible. Indeed, for every nonnegative answer yy, there is only one nonnegative question, namely yy itself. This “fix” works because f(x)=xf(x)=|x| just outputs the input for xR+x\in \R _+. In general, a function f:XXf:X\rightarrow X with f(x)=xf(x)=x for all xXx\in X is called identity and is always invertible, with f1=ff^{-1}=f.

Exercise 12.

Recall that N={0,1,2,...}\N =\{ 0,1,2,...\} is the set of all natural numbers. Let N={1,2,3...}\N '=\{ 1,2,3...\} be the set of positive natural numbers. Which of the following are invertible functions f:NNf:\N \rightarrow \N '?

Input (Multiple Choice)

  • f(n)=nf(n) = n
  • f(n)=1f(n) = 1
  • f(n)=n+1f(n) = n+1
  • f(n)=n+2f(n) = n+2
  • f(n)=2n+1f(n) = 2n+1

Decide which of the provided answers are correct and select them by clicking on the corresponding boxes, thus marking them with a blue border like so:

  • Unselected
  • Selected
  • Unselected
  • Selected

Any number of the provided answers can be correct, including zero.

This is related to famous Hilbert’s Hotel, a hotel with infinitely many rooms numbered 1,2,...1,2,.... Some evening, a new guest arrives without a reservation. Unfortunately, the hotel is fully booked, i.e. there are infinitely many guests already, and all rooms are taken. Fortunately, the clerk can solve the problem by simply asking every guest to move to the room one number higher: the guest in room 11 moves to room 22, the one in room 22 moves to room 33, and so on. This frees up room 11 which can then be given to the new guest.

In some sense, the sets N={0,1,2,...}\N =\{ 0,1,2,...\} and N={1,2,3...,n}\N '=\{ 1,2,3...,n\} have the same size. Actually, in a very precise sense. We simply define two infinite sets XX and YY to be of the same size whenever there is an invertible function f:XYf:X\rightarrow Y. The following exercise shows that even the sets N\N and Z={...,2,1,0,1,2,...}\Z =\{ ...,-2,-1,0,1,2,...\} have the same size, although it rather looks like Z\Z might have twice the size of N\N .

Exercise 13.

Let N={0,1,2,...}\N =\{ 0,1,2,...\} be the set of natural numbers and recall that Z={...,2,1,0,1,2,...}\Z =\{ ...,-2,-1,0,1,2,...\} is the set of integers. Consider the function f:NZf:\N \rightarrow \Z defined by

f(n)={n/2,if n is even(n+1)/2if n is odd\displaystyle f(n) = \left \{ \begin {array}{ll}-n/2, &\text {if } n \text { is even} \\ \\ (n+1)/2 & \text {if } n \text { is odd} \\ \end {array}\right .
Argue for yourself that ff is invertible and select the inverse f1f^{-1} from the following options!

Input (Single Choice)

  • f1(m)=2mf^{-1}(m) = |2m|
  • f1(m)={2m1,if m>02mif m0f^{-1}(m) = \left \{ \begin {array}{ll}2m-1, & \text {if } m>0 \\ -2m & \text {if } m\leq 0 \\ \end {array}\right .
  • f1(m)={2m1,if m is even2mif m is oddf^{-1}(m) = \left \{ \begin {array}{ll}2m-1, & \text {if } m \text { is even} \\ -2m & \text {if } m\text { is odd} \\ \end {array}\right .

Decide which of the provided answers is correct and select it by clicking on the corresponding box, thus marking it with a blue border like so:

  • Unselected
  • Selected
  • Unselected

Exactly one of the provided answers is correct.

Exercise 14.

Recall that R+\R _+ is the set of nonnegative real numbers, and R\R _- the set of nonpositive real numbers. Here, we only consider the function f(x)=x2f(x) = x^2, but we want to see what happens for different sets of questions XX and sets of answers YY. In which of the following cases is ff invertible? For each case, argue why your answer is correct and also think about what f1f^{-1} would be!

Input (Multiple Choice)

  • f:RR+f:\R \rightarrow \R _+
  • f:R+R+f:\R _+\rightarrow \R _+
  • f:RR+f:\R _-\rightarrow \R _+

Decide which of the provided answers are correct and select them by clicking on the corresponding boxes, thus marking them with a blue border like so:

  • Unselected
  • Selected
  • Unselected
  • Selected

Any number of the provided answers can be correct, including zero.

4Functions with more arguments

Sometimes, several questions need to be asked before an answer can be given. To understand this, let’s think of a pocket calculator. It typically has an x2\boxed {x^2} key. To use it, you type in the question (argument) xx, for example 55, and then press x2\boxed {x^2} to get the answer (value) x2x^2; in this example x2=xx=25x^2=x\cdot x=25. But there is also an xy\boxed {x^y} key. This requires two arguments xx and yy. To use it, you type in the first argument xx, for example 33, then press xy\boxed {x^y}, type in the second argument yy, for example 44, and finally press =\boxed {=} to get the value xyx^y; in this example 34=3333=813^4=3\cdot 3\cdot 3\cdot 3=81.

Mathematically, this is a function with two arguments: f(x,y)=xyf(x,y)=x^y. In a strict mathematical sense, there is only one argument, namely the pair (x,y)(x,y), and one would have to write f((x,y))f((x,y)), but even mathematicians don’t like this and typically think of two arguments instead of one argument that consists of two parts. We could also have three or more arguments. We will not go into what the sets XX and YY are in f:XYf:X\rightarrow Y if the function ff has several arguments. But they exist, and we can also ask whether ff is invertible, just like for “normal” functions with one argument.

Functions with two arguments can also be specified via a value table, but this time, the table is two‐dimensional. Let us suppose that we want to compute xyx^y only for xx and yy between 00 and 44. Then the value table is the following.

x=01234y=0111111012342014916301827644011681256\displaystyle \begin {array}{r|rrrrr}& x=0 & 1 & 2 & 3 & 4 \\ \hline y=0 & 1 & 1 & 1 & 1 & 1 \\ 1 & 0 & 1 & 2 & 3 & 4 \\ 2 & 0 & 1 & 4 & 9 & 16 \\ 3 & 0 & 1 & 8 & 27 & 64 \\ 4 & 0 & 1 & 16 & 81 & 256\end {array}

You might find it weird that 00=10^0=1, but let’s not discuss it; we only wanted to point out that this is not a typo.

Exercise 15.

Fill in the value table of the function f(x,y)=x2+y2f(x,y)=x^2+y^2 for xx and yy between 00 and 44.

Inputs (Number)
x=0x=0, 11, 22, 33
y=0y=0,
11,
22,
33,

Enter a number in the box. You can enter

  • a natural number, such as 22,

  • an integer, such as ‐7,

  • a quotient, such as 22/7, or

  • a terminating decimal, such as 3.14285.

There may be more than one correct solution.