# Give an example of a real function so that every rational is a strict local minimum

Give an example of $f : \mathbb R → [0, \infty)$ so that every $r \in \mathbb Q$ is a strict local minimum for $f$.

Strict local minimum means there is a vicinity $V$ of $r$ such that $f(y) > f(r) ,\ \forall y \in V-\{r\}$

My attempt

So far, none. My feeling is there isn't such a function, mainly because of the density of $\mathbb Q$ in $\mathbb R$. Suppose I define $f$ like this: $f(x) = 0$ for $x \in \mathbb Q$ and $f(x) = 1$ for $x \not \in \mathbb Q$. Every rational $r$ does not map to a strict local minimum for $f$ only because of the other rationals present in every vicinity of $r$. So $f$ cannot be constant on $\mathbb Q$, but how to define it is beyond my imagination.

• My first Google hit for "local minimum at all rational numbers" was en.wikipedia.org/wiki/Thomae%27s_function which – I think – can be modified to fit your needs by considering $1 - f(x)$. May 12 '16 at 18:48
• @MartinR more of a meta topic, but is Googling advised? May 12 '16 at 18:56
• @MartinR Yes, you are right, 1 - (Thomae's function) is such an example
– user261263
May 12 '16 at 19:00

I think that the function that sends any irrational number on $1$ and sends a rational $\frac{p}q$ (where the fraction is irreducible) on $1-\frac1q$ does the job. Given any rational number $\frac{p}q$, you can always find a neighborhood so that any rational number has a denominator bigger than $q$

• The function needs to be nonnegative. May 12 '16 at 18:43
• @MattSamuel: Then add $1$ ... May 12 '16 at 18:49
• @H. Potter perhaps $1$ and $1-\frac 1 q$ May 12 '16 at 18:50
• @MattSamuel There are many ways to change the function so that it becomes nonnegative. Find your favorite one :) May 12 '16 at 19:01
Here's a pretty direct hint. If there were only rationals, the function could be defined as the denominator in lowest terms, because everything nearby enough would have a larger denominator. If we want to also define it on the irrationals this wouldn't work. However, we can compress the positive integers into $[0,1)$ in an order preserving way, then we can make the function $1$ on the irrationals.