# Extreme value theorem – Serlo

Zur Navigation springen Zur Suche springen

In the following we are going to deal with continuous functions on compact intervals. These are intervals that are closed and bounded, i.e. have the form ${\displaystyle [a,b]}$. We will see that such functions are always bounded and attain a minimum and maximum. This theorem is called the Extreme Value Theorem. It is used in mathematics to prove the existence of relative extrema, i.e. points of a function that are "at the extreme" of being the lowest point in the graph (the minimum) or the highest point in the graph (the maximum).

## Motivation

Motivation and intuition behind the extreme value theorem (in German)

Let's take a continuous function ${\displaystyle f}$ which is defined on a compact interval ${\displaystyle [a,b]}$. I.e. we are considering a function ${\displaystyle f:[a,b]\to \mathbb {R} }$. This function has the value ${\displaystyle f(a)}$ at the point ${\displaystyle a}$ and the value ${\displaystyle f(b)}$ at the point ${\displaystyle b}$.

Now ${\displaystyle f}$ is defined for every intermediate point between ${\displaystyle a}$ and ${\displaystyle b}$. Intuitively, for functions without gaps in the domain of definition, continuity means that we are able to draw the graph without lifting the pen from the paper. Hence, the graph of ${\displaystyle f}$ connects the points ${\displaystyle (a,f(a))}$ and ${\displaystyle (b,f(b))}$ by a continuous path without jumps. The following graph provides an example for such a function ${\displaystyle f}$:

We note that the function ${\displaystyle f}$ above is bounded. And it attains a maximum and minimum value:

Is it always that way? Try for yourself to connect the points ${\displaystyle (a,f(a))}$ and ${\displaystyle (b,f(b))}$ by different graphs without lifting the pen. Could you imagine to draw the graph of an unbounded function - even if your paper was infinitely large?

Intuitively, the answer is no. No matter how far your graph goes up or down, you need to return to the end points at ${\displaystyle (a,f(a))}$ or ${\displaystyle (b,f(b))}$. Going to infinity "forces you to lift the pen" and is therefore not allowed. However, the function ${\displaystyle f}$ can attain very large values (like ${\displaystyle 10^{100}}$ or more) while staying bounded, as long as you return in order to reach the end point. This situation is illustrated in the following figure:

So our first intuition tells us that when connecting the two points ${\displaystyle (a,f(a))}$ and ${\displaystyle (b,f(b))}$ without lifting the pen, our function stays bounded. And it attains a maximum and a minimum. Now let's think about what could go wrong when phrasing this intuition in a mathematical way. The end points ${\displaystyle a}$ and ${\displaystyle b}$ of the domain of definition ${\displaystyle [a,b]}$ could become problematic: For an open domain of definition ${\displaystyle (a,b)}$, the function could run towards ${\displaystyle \pm \infty }$ at ${\displaystyle a}$ or ${\displaystyle b}$, or it could converge towards a value without attaining it. Including the boundary points ${\displaystyle \{a,b\}}$ in the domain of definition excludes these cases as it "catches the function" at the end points ${\displaystyle (a,f(a))}$ and ${\displaystyle (b,f(b))}$. If we move a boundary to infinity, let's say by considering the domain of definition ${\displaystyle [a,\infty )}$, the function could have "infinitely much time" and might run towards infinity while being continuous. This happens for instance for ${\displaystyle f(x)=x^{2}}$. So we also expect problems with unbounded domains of definition. A statement like "the maximum and minimum are attained" can only be expected to hold true on a compact interval ${\displaystyle [a,b]}$. Now, in between ${\displaystyle a}$ and ${\displaystyle b}$, the function could also "break out" and tend towards ${\displaystyle \pm \infty }$ (like ${\displaystyle f(x)={\tfrac {1}{x}}}$ near ${\displaystyle x=0}$). This scenario will be prevented by assuming continuity of the function ${\displaystyle f}$.

In the following, we will mathematically verify that our intuition is true. That means we prove a statement like "the maximum and minimum are attained" for continuous functions defined on a compact interval ${\displaystyle [a,b]}$ and discuss what may go wrong if we choose other domains of definition.

## Extreme value theorem

Theorem (Extreme value theorem)

Explanation of the extreme value theoremm (in German). (YouTube-Video published by Quatematik)

Every continuous function defined on a compact interval ${\displaystyle [a,b]}$ is bounded and attains a maximum and a minimum (extreme values). That means, if ${\displaystyle f:[a,b]\to \mathbb {R} }$ with ${\displaystyle a,b\in \mathbb {R} }$ and ${\displaystyle a is a continuous function, then there are arguments ${\displaystyle {\tilde {x}},{\hat {x}}\in [a,b]}$, such that for all arguments ${\displaystyle x\in [a,b]}$ the inequality ${\displaystyle f({\hat {x}})\leq f(x)\leq f({\tilde {x}})}$ holds.

Example (Extreme value theorem)

Graph of a function ${\displaystyle f:[0,1]\to \mathbb {R} }$ with ${\displaystyle f(x)=x^{2}\cdot \cos(x)\cdot e^{\cos(x)}-\ln(x+1)}$. This function attains a maximum and a minimum, which is attained in form of a function value.

Consider ${\displaystyle f:[0,1]\to \mathbb {R} }$ with ${\displaystyle f(x)=x^{2}\cdot \cos(x)\cdot e^{\cos(x)}-\ln(x+1)}$. The domain of definition ${\displaystyle [0,1]}$ is a compact interval. In addition, ${\displaystyle f}$ is continuous as it is composed out of continuous functions ${\displaystyle x\mapsto x^{2}}$, ${\displaystyle x\mapsto e^{x}}$, ${\displaystyle x\mapsto \cos(x)}$ and ${\displaystyle x\mapsto \ln(x+1)}$ with domains of definition ${\displaystyle [0,1]}$. Hence, ${\displaystyle f}$ must attain a maximum and a minimum.

Proof (Extreme value theorem)

Proof of the extreme value theorem (in German)

Let ${\displaystyle f:[a,b]\to \mathbb {R} }$ be a continuous function with ${\displaystyle a,b\in \mathbb {R} }$ and ${\displaystyle a. We will only prove explicitly that ${\displaystyle f}$ is bounded from above and attains a maximum. The analogous statement that ${\displaystyle f}$ is bounded from below and attains a minimum can be shown the same way.

So let us consider the image ${\displaystyle f([a,b])}$. This is the the set of all function values, which are attained by ${\displaystyle f}$. Let us take the supremum ${\displaystyle \sup f([a,b])}$ of the set ${\displaystyle f([a,b])}$, where we explicitly allow for use of the extended definition of the supremum ${\displaystyle \sup f([a,b])=\infty }$ . If ${\displaystyle f}$ is bounded from above, then ${\displaystyle \sup f([a,b])=\infty }$ and else, ${\displaystyle \sup([a,b])\in \mathbb {R} }$ (since ${\displaystyle f([a,b])\neq \emptyset }$ , the case ${\displaystyle \sup \emptyset =-\infty }$ cannot occur).

Now, we know that there is a sequence in ${\displaystyle f([a,b])}$ , which tends towards the supremum ${\displaystyle \sup f([a,b])}$ (for each nonempty set ${\displaystyle M}$ there is a subsequence in ${\displaystyle M}$, tending towards ${\displaystyle \sup M}$). Hence there is a sequence ${\displaystyle (x_{n})_{n\in \mathbb {N} }}$ of arguments in ${\displaystyle [a,b]}$ with ${\displaystyle \lim _{n\to \infty }f(x_{n})=\sup f([a,b])}$.

We now make use of the Bolzano-Weierstraß theorem. This theorem tells us that each sequence in a compact interval ${\displaystyle [a,b]}$ with ${\displaystyle a,b\in \mathbb {R} }$ and ${\displaystyle a has a converging subsequence. Hence, ${\displaystyle (x_{n})_{n\in \mathbb {N} }}$ also has a convergent subsequence ${\displaystyle \left(x_{n_{k}}\right)_{k\in \mathbb {N} }}$. Let ${\displaystyle {\tilde {x}}}$ be the limit of the convergent subsequence ${\displaystyle \left(x_{n_{k}}\right)_{k\in \mathbb {N} }}$. Since ${\displaystyle a\leq x_{n_{k}}\leq b}$ for all ${\displaystyle k\in \mathbb {N} }$ , there is also ${\displaystyle a\leq {\tilde {x}}\leq b}$ and therefore ${\displaystyle {\tilde {x}}\in [a,b]}$. So, ${\displaystyle {\tilde {x}}}$ must be an argument of the function ${\displaystyle f}$. Since ${\displaystyle f}$ is continuous, we can make use of the sequential definition of continuity

${\displaystyle f\left({\tilde {x}}\right)=f\left(\lim _{k\to \infty }x_{n_{k}}\right)=\lim _{k\to \infty }f\left(x_{n_{k}}\right)=\sup f([a,b])}$

${\displaystyle \sup f([a,b])}$ is a function value of ${\displaystyle f}$ and hence a real number. Therefore we know that ${\displaystyle f}$ is bounded from above. And we have shown that ${\displaystyle f}$ attains its upper bound ${\displaystyle \sup f([a,b])}$ at the argument ${\displaystyle {\tilde {x}}}$ . Therefore, ${\displaystyle f(x)\leq f({\tilde {x}})}$ for all ${\displaystyle x\in [a,b]}$ and indeed, ${\displaystyle f({\tilde {x}})}$is the maximum among all function values of ${\displaystyle f}$.

## Assumptions of the theorem

Assumptions of the extreme value theorem (in German)

Let's take a look at the assumptions made within the extreme value theorem:

• ${\displaystyle f}$ is a continuous function
• ${\displaystyle f}$ is defined on a compact interval ${\displaystyle [a,b]}$

Are those assumptions really necessary or can we relax them without losing validity of the extreme value theorem?

### Assumption of continuity

Function ${\displaystyle f(x)={\tfrac {1}{x}}}$ on the interval ${\displaystyle [-1,1]}$ with ${\displaystyle f(0)=0}$

First, we note that continuity prevents the function ${\displaystyle f}$ from "breaking out" to ${\displaystyle +\infty }$ or ${\displaystyle -\infty }$ within its domain of definition. Ij we just allow any function ${\displaystyle f:[a,b]\to \mathbb {R} }$ , no matter whether it is continuous or not, we will find non-continuous functions which are violating the extreme value theorem. The following function is unbounded (so it does not attain any extrema) and non-continuous at ${\displaystyle x=0}$ :

${\displaystyle f:[-1,1]\to \mathbb {R} :x\mapsto {\begin{cases}{\frac {1}{x}}&;x\neq 0\\0&;x=0\end{cases}}}$

So we cannot simply drop the assumption that ${\displaystyle f}$ is continuous.

### Interval-assumption

The function ${\displaystyle f(x)={\tfrac {1}{x}}}$ on ${\displaystyle (0,1]}$

The domain of definition is also important. It must include its boundary (i.e. be closed). This way we "catch" the function at the interval boundary and make sure it does not "run away" towards infinity. The function ${\displaystyle g:(0,1]\to \mathbb {R} :x\mapsto {\tfrac {1}{x}}}$ is an example which "runs away" as we approach ${\displaystyle x=0}$.

Unboundedly large domains are also problematic, since the function has "infinitely much time" to run away. An easy example is the function ${\displaystyle h:[0,\infty )\to \mathbb {R} :x\mapsto x^{2}}$. And there are functions, which are defined on a bounded domain of definition, continuous and do not "run away" towards infinity, but do not attain an extremum. This happens if there are open boundaries or gaps within the domain of definition. The extremum would then be attained at the boundary (or the gap) - but this argument has been removed from the domain of definition.

Question: Does the continuous function ${\displaystyle f}$ always attain a maximum or a minimum, if it is defined on a bounded interval?

No. For instance, the function ${\displaystyle f:(0,1)\to \mathbb {R} }$, ${\displaystyle f(x)=x}$ does not. There is: ${\displaystyle f((0,1))=(0,1)}$. So the infimum and maximum of the image are 0 and 1, which would be attained at the boundary (${\displaystyle x=0}$ and ${\displaystyle x=1}$), if ${\displaystyle f}$ was defined there. However, we removed 0 and 1 from the domain of definition, so ${\displaystyle f}$ does no longer attain an extremum.

The same may happen when removing a maximum or minimum from the interior of the domain of definition instead of the boundary - which creates a gap. Of course, the function may also "run away" at such a gap. An example for this effect is the continuous but unbounded function ${\displaystyle j:[-1,1]\setminus \{0\}\to \mathbb {R} :x\mapsto {\tfrac {1}{x}}}$. The argument ${\displaystyle x=0}$ is excluded from the domain of definition ${\displaystyle [-1,1]\setminus \{0\}=[-1,0)\cup (0,1]}$ . So this function is well defined and continuous, but it "runs away" at the gap. In a mathematical language, the function is unbounded and hence violates the conclusion of the extreme value theorem.

### Outlook: Generalization of the theorem

So far, we only considered intervals (possibly with gaps) as candidates for the domain of definition. Is this restriction really necessary? This time, the answer is no. For instance, we can take the union of two intervals ${\displaystyle D=[a,b]\cup [c,d]}$ with ${\displaystyle a and define some continuous and real-valued function ${\displaystyle j}$ on ${\displaystyle D}$. If we restrict ${\displaystyle j}$ to only ${\displaystyle [a,b]}$ or ${\displaystyle [c,d]}$ , we can apply the extreme value theorem. Both the functions ${\displaystyle j_{1}=j|_{[a,b]}}$ and ${\displaystyle j_{2}=j|_{[c,d]}}$ with restricted domain of definition are bounded and hence attain a maximum and a minimum. The function ${\displaystyle j}$ must therefore also be bounded. Its maximum is the larger of the both maxima of ${\displaystyle j_{1}}$ and ${\displaystyle j_{2}}$ , so ${\displaystyle j}$ also attains a maximum (the same holds for the minimum). Therefore, every continuous function defined on the union of two closed intervals ${\displaystyle [a,b]\cup [c,d]}$ fulfills the conclusion of the extreme value theorem. The same holds if we consider three or more closed intervals - or an even larger class of domains of definition. In fact, we can precisely state what this larger class of domains of definition is:

If we take a second look at the proof, we note that the domain of definition is only mentioned at one point: where we make use of the Bolzano-Weierstraß theorem. We used it to show that any sequence from the domain of definition contains a convergent subsequence. Hence, the proof arguments hold true, as long as the domain of definition allows for the usage of the Bolzano-Weierstraß theorem.

So we can generalize the above theorem. It will hold not only on closed intervals ${\displaystyle [a,b]}$, but on all sets satisfying the Bolzano-Weierstraß theorem. We will call these sets satisfying the Bolzano-Weierstraß theorem sequentially closed sets:

Definition (Sequential closedness)

A subset of the real numbers is called sequentially closed iff any sequence out of this set has a convergent subsequence.

If the domain of definition ${\displaystyle D}$ of a continuous function ${\displaystyle f:D\to \mathbb {R} }$ is sequentially compact, then the function ${\displaystyle f}$ must fulfill the extreme value theorem. The generalization of sequential compactness from real numbers to other sets of mathematical objects is one of the topics dealt with in topology.

## Exercise: Image of polynomials of even degree

Exercise: Image of polynomials of even degree (in German)

Exercise (Image of polynomials)

Let

${\displaystyle p:\mathbb {R} \to \mathbb {R} ,\ p(x)=a_{n}x^{n}+a_{n-1}x^{n-1}+\ldots +a_{1}x+a_{0}}$

be a polynomial function with ${\displaystyle a_{0},a_{1},\ldots ,a_{n-1},a_{n}\in \mathbb {R} }$ and ${\displaystyle a_{n}\neq 0}$. Let ${\displaystyle p}$ further have an even degree ${\displaystyle n}$. Show that the image of ${\displaystyle p}$ is given by

${\displaystyle p(\mathbb {R} )={\begin{cases}[y_{\min },\infty )&{\text{ for }}a_{n}>0,\\(-\infty ,y_{\max }]&{\text{ for }}a_{n}<0.\end{cases}}}$

Here, ${\displaystyle y_{\min }}$ (an case ${\displaystyle a_{n}>0}$) and ${\displaystyle y_{\max }}$ (in case ${\displaystyle a_{n}<0}$) are real numbers.

Proof (Image of polynomials)

We will consider the case ${\displaystyle a_{n}>0}$. The proof for the case ${\displaystyle a_{n}<0}$ works analogously. At first, we note that the polynomial ${\displaystyle p}$ is a composition of continuous functions and hence continuous itself on ${\displaystyle \mathbb {R} }$ . It is temping to use the extreme value theorem in order to show that ${\displaystyle p}$ attains a minimum. However, ${\displaystyle \mathbb {R} =(-\infty ,\infty )}$ is not a compact interval. However, we can cut it off at very large values and make it compact this way. For even ${\displaystyle n}$, there is ${\displaystyle \lim _{x\to \pm \infty }x^{n}=\infty }$, da ${\displaystyle n}$. The ${\displaystyle x^{n}}$-term dominates the other ones, so there is also

${\displaystyle \lim _{x\to \pm \infty }p(x)=\lim _{x\to \pm \infty }\underbrace {x^{n}} _{\to \infty }(\underbrace {a_{n}+a_{n-1}x^{-1}+\ldots +a_{1}x^{-n+1}+a_{0}x^{-n}} _{\to a_{n}>0})=\infty }$

Now, let us take any function value of ${\displaystyle p}$ – for instance ${\displaystyle p(0)}$. Since ${\displaystyle \lim _{x\to \infty }p(x)=\infty }$ there is an ${\displaystyle S\in \mathbb {R} }$, such that ${\displaystyle p(x)>p(0)}$ for all ${\displaystyle x\geq S}$ . Analogously, since ${\displaystyle \lim _{x\to -\infty }p(x)=\infty }$ there is an ${\displaystyle s\in \mathbb {R} }$, such that ${\displaystyle p(x)>p(0)}$ for arguments ${\displaystyle x}$ smaller than ${\displaystyle s}$ . Both on ${\displaystyle (-\infty ,s]}$ and ${\displaystyle [S,\infty )}$ , the polynomial ${\displaystyle p}$ is larger than the function value ${\displaystyle p(0)}$.

We can hence cut off the real number axis and restrict to the interval ${\displaystyle [s,S]}$. Since on ${\displaystyle [S,\infty )}$ the function is larger than ${\displaystyle p(0)}$ , the argument ${\displaystyle 0}$ does not belong to this set and ${\displaystyle S>0}$. Analogously, ${\displaystyle s<0}$. Therefore, ${\displaystyle [s,S]}$ is a nonempty, closed and bounded interval. Hence it is compact an we can apply the extreme value theorem. The polynomial ${\displaystyle p}$ indeed attains a minimum ${\displaystyle y_{\min }}$ on ${\displaystyle [s,S]}$ . Now, ${\displaystyle y_{\min }\leq p(0)}$ (since ${\displaystyle 0\in [s,S]}$) and therefore, ${\displaystyle y_{\min }}$ is also a global minimum of the polynomial.

The intermediate value theorem additionally yields that the image of ${\displaystyle p}$ is an interval (see also Conclusions from the intermediate value theorem). Since ${\displaystyle \lim _{x\to \infty }p(x)=\infty }$ and ${\displaystyle y_{\min }}$ is a global minimum of ${\displaystyle p}$ , the image of ${\displaystyle p}$ must be of the form ${\displaystyle [y_{\min },\infty )}$.

## Exercise: Continuous functions on [0,1]

Exercise: Continuous functions on [0,1] (in German)

Exercise (There is no continuous function on a compact interval attaining all function values exactly twice)

Show that there is no continuous function ${\displaystyle f:[0,1]\to \mathbb {R} }$ attaining all its function values exactly twice. That means, there is no continuous function ${\displaystyle f:[0,1]\to \mathbb {R} }$, such that for all ${\displaystyle y\in f([0,1])}$ exactly two numbers ${\displaystyle x_{1},x_{2}\in [0,1]}$ with ${\displaystyle f(x_{1})=f(x_{2})=y}$ exist.

Solution (There is no continuous function on a compact interval attaining all function values exactly twice)

We perform a proof by contradiction. Let ${\displaystyle f:[0,1]\to \mathbb {R} }$ be a continuous function attaining all its values exactly twice. Since ${\displaystyle f}$ is continuous and ${\displaystyle [0,1]}$ is a compact interval, ${\displaystyle f}$ has to be bounded and to attain a maximum ${\displaystyle M}$ . By assumption, this maximum is attained exactly twice. So there are two arguments ${\displaystyle x_{M},{\tilde {x}}_{M}\in [0,1]}$ with ${\displaystyle f(x_{M})=f({\tilde {x}}_{M})=M}$. Let without loss of generality be ${\displaystyle x_{M}<{\tilde {x}}_{M}}$.

Now, ${\displaystyle f}$ must also attain a minimum on the interval ${\displaystyle [x_{M},{\tilde {x}}_{M}]}$ , which we call ${\displaystyle m}$ . Since ${\displaystyle M}$ is the maximum of ${\displaystyle f}$ , it is also the maximum of the restriction ${\displaystyle f|_{[x_{M},{\tilde {x}}_{M}]}}$. Therefore, ${\displaystyle M\geq m}$. In case ${\displaystyle m=M}$ , the function ${\displaystyle f}$ would have to be constant on ${\displaystyle [x_{M},{\tilde {x}}_{M}]}$ and hence attain exactly one value infinitely often. Therefore, ${\displaystyle m.

Since the minimum ${\displaystyle m}$ is attained by ${\displaystyle f}$ on the interval ${\displaystyle [x_{M},{\tilde {x}}_{M}]}$ and the function attains the maximum ${\displaystyle M}$ on both ends of the interval, there is an ${\displaystyle x_{m}}$ with ${\displaystyle x_{M} and ${\displaystyle f(x_{m})=m}$. And we know that ${\displaystyle m}$ is attained at some second argument ${\displaystyle {\tilde {x}}_{m}\in [0,1]}$ . This argument ${\displaystyle {\tilde {x}}_{m}}$ mab be situated on the inside of the interval ${\displaystyle [x_{M},{\tilde {x}}_{M}]}$ or on the outside.

Fall 1: ${\displaystyle {\tilde {x}}_{m}\notin [x_{M},{\tilde {x}}_{M}]}$

First, we consider the case where ${\displaystyle {\tilde {x}}_{m}}$ is not in ${\displaystyle [x_{M},{\tilde {x}}_{M}]}$ on consider - without loss of generality - the case ${\displaystyle x_{M} . The mean ${\displaystyle {\tfrac {M+m}{2}}}$ of ${\displaystyle M}$ and ${\displaystyle m}$ is an intermediate value and will hence be attained by the function between ${\displaystyle x_{M}}$ and ${\displaystyle x_{m}}$ by means of the intermediate value theorem. Analogously, ${\displaystyle {\tfrac {M+m}{2}}}$ is attained in the intervals ${\displaystyle [x_{m},{\tilde {x}}_{M}]}$ and ${\displaystyle [{\tilde {x}}_{M},{\tilde {x}}_{m}]}$ . So ${\displaystyle {\tfrac {M+m}{2}}}$ is attained at least at three arguments, which leads to a contradiction to the function attaining each value exactly twice:

Fall 2: ${\displaystyle {\tilde {x}}_{m}\in [x_{M},{\tilde {x}}_{M}]}$

Now, we consider the case where ${\displaystyle {\tilde {x}}_{m}}$ is situated inside the interval ${\displaystyle [x_{M},{\tilde {x}}_{M}]}$ . Without loss of generality, we assume ${\displaystyle x_{M} . Within the interval ${\displaystyle [x_{m},{\tilde {x}}_{m}]}$ , ${\displaystyle f}$ must attain a maximum ${\displaystyle M_{2}}$ . Since ${\displaystyle m}$ is the minimum on ${\displaystyle [x_{m},{\tilde {x}}_{m}]}$ , there will be ${\displaystyle M_{2}\geq m}$. In addition, ${\displaystyle m}$ has already been attained twice, so we need the strict inequality ${\displaystyle M_{2}>m}$ (else, the function would be constant on ${\displaystyle [x_{m},{\tilde {x}}_{m}]}$). As ${\displaystyle M}$ is the maximum of ${\displaystyle f}$, which was already attained twice at ${\displaystyle x_{M}}$ and ${\displaystyle {\tilde {x}}_{M}}$ , there is ${\displaystyle M>M_{2}>m}$.

Now, the intermediate value theorem tells us that ${\displaystyle M_{2}}$ is attained within the interval ${\displaystyle [x_{M},x_{m}]}$ (since ${\displaystyle f(x_{M})=M>M_{2}>m=f(x_{m})}$). For the same reason (${\displaystyle f({\tilde {x}}_{m})=m), the value ${\displaystyle M_{2}}$ is also attained on ${\displaystyle [{\tilde {x}}_{m},{\tilde {x}}_{M}]}$. So ${\displaystyle M_{2}}$ is a value attained at least three times: inside the open interval ${\displaystyle (x_{M},x_{m})}$, inside of ${\displaystyle (x_{m},{\tilde {x}}_{m})}$ and inside of ${\displaystyle ({\tilde {x}}_{m},{\tilde {x}}_{M})}$. This is a contradiction to every value being attained exactly twice:

In addition, the statement of the above exercise can be generalized in multiple ways:

1. We have shown that on a compact interval ${\displaystyle [a,b]}$ , there is no continuous function attaining each value twice.
2. Similarly, one may show that there is no continuous function ${\displaystyle f:\mathbb {R} \to \mathbb {R} }$attaining each of its values twice.
3. And for each given number ${\displaystyle n\in \mathbb {N} }$, ${\displaystyle n>1}$ , one can show that there is no continuous function ${\displaystyle f:[a,b]\to \mathbb {R} }$ attaining each of its values exactly ${\displaystyle n}$ times.

Exercise for understanding: Give an example for:

1. A continuous function ${\displaystyle f:[0,1]\to \mathbb {R} }$, attaining each of its function values exactly once.
2. A function ${\displaystyle f:(0,1]\to \mathbb {R} }$ (non-continuous) attaining all of its function values exactly twice.

Possible solution:

1. ${\displaystyle f:[0,1]\to \mathbb {R} }$ with ${\displaystyle f(x)=x}$
2. ${\displaystyle f:(0,1]\to \mathbb {R} }$ with ${\displaystyle f(x)={\begin{cases}2x&0