# Finding all local maximum and minimum for some unusual functions.

The following are problems and solutions from Spivak's Calculus that I have difficulty understanding.

(1) $f(x)= 0$ if $x$ is irrational, $1/q$ if $x=p/q$ in lowest terms.

(2) $f(x)= 1$, if the decimal expansion of $x$ contains a $5$, $0$ otherwise.

The solution from the text says that for (1), all irrational $x$ are local minimum points, and all rational $x$ are local maximum points. However, in order to be a local max or minimum, the point needs to have the greatest or smallest value in some interval, yet by density of rationals and irrationals, every interval contains infinitely many rationals, so I don't see how any rational point is a local maximum.

Meanwhile, for (2), the text says that $x$ is a local minimum point if its decimal expansion does not contain a $5$. It is a local maximum point if its decimal expansion contains exactly one $5$ that is followed by an infinite string of $9's$. In all other cases, $x$ is both a local maximum point and a local minimum point.

In this case, I don't understand the reasoning behind choosing a point that contains exactly one $5$ that is followed by an infinite string of $9's$ and how this point actually is a local maximum. Also, why would all other points, for instance a number with two $5's$ in its decimal expansion, be both a local maximum and minimum.

I would appreciate any explanations to these questions.

Here is an answer to question 1: let $x_0=\dfrac{p_0}{q_0}$ a rational number in lowest form. Any bounded interval containing $x_0$ contains only a finite number of $x=\dfrac pq$ with $1\le q < q_0$. Now take a smaller interval $I$ that doesn't contain any of these $x$s. For any rational number in $I$, we have $q\ge q_0$, hence $f(x) \le f(x_0)$. For an irrational $x$ there is nothing to prove.
I don't understand the result the text says, according to your interpretation. It implies the for a number $x$ with two or more $5$ the value $f(x)=1$ is also a local minimum, so that for every number $x$ in a small neighbourhood, the function is constant; in other words, there are no irrational numbers. This is impossible, as you know.