# Sunday Function

It’s been a while since we’ve done a Sunday Function, so let’s get back into the swing of things with a weird one. This is Thomae’s function, and using Wikipedia’s conveniently typeset definition:

If you’re new to the concept of rational and irrational numbers, it’s pretty simple. A number is rational if it can be written as a fraction p/q. Otherwise it’s irrational. Numbers like pi or the square root of two fit this description. For this function we assume that the fraction p/q is reduced as far as possible, so if x = 1/3 we have p = 1 and q = 3. This is opposed to something like p = 7 and q = 21 which is a perfectly valid way of writing the number, but we have to pick a representation to eliminate the ambiguity.

It’s not a particularly complicated function in principle. f(pi) = 0, f(22/7) = 1/7, and so on. In practice we may not know whether a particular number is rational or not, for instance the irrationality of (pi – e) is an open question. It would be absolutely flabbergasting if it were not irrational, but thus far it hasn’t been proved one way or another.

Before we plot the function, we’ll look at its continuity properties. By definition f(c) = 0 for irrational c, but if we’re looking at rational values of x very close to c then it’s relatively clear that x is going to have a big denominator. The number 22/7 that I mentioned earlier is pretty close to pi, but to get closer you’d need a number with a bigger denominator. In fact the number with the next-smallest denominator which is closer to pi is 333/106. And a bigger denominator means smaller 1/q, which is closer to 0. So while this is not a proof, it’s a good argument that f(x) is continuous for all irrational x and discontinuous at all rational x. Freaky!

So what does it look like? Via Wolfram’s plotting algorithm, this:

This is an incomplete plot, of course. In reality there’d be an infinite number of lines, and really it would probably be better to represent this plot pointwise rather than with lines anyway. Still, it gives a sense of just how odd this bird is.

Does this function have any use in physics? Not really as such, though it’s interesting in that if you plant a bunch of identical telephone poles in a square grid, this function happens to represent what you see if you’re looking at it from ground level at one of the corners.

1. #1 Joel
May 2, 2010

An interesting function! But f(22/7)=1/7, not 7.

2. #2 Miko
May 2, 2010

Another fun thing to try for those at the upper-division undergrad level in mathematics is to integrate this function (say, from 0 to 1). If you know Lebesgue integration theory, determining the correct answer is trivial, but showing that the answer actually exists as a Riemann integral takes a little bit of work.

3. #3 Matt Springer
May 2, 2010

@1: Yep!

@2: It exists as a Riemann integral? I wouldn’t have expected that. Sadly I know very little about the theory of Lebesgue integration but as you say this one is pretty trivially zero.

4. #4 MPL
May 2, 2010

@3,2

I was a little surprised that you can take the Riemann integral of this, but with a little thought, it seems possible. As long as you keep partitioning on maximal elements in intervals, you should be able to make the upper sum converge on the lower sum (which is always 0).

I suppose this function has no direct use in physics, but it’s an important example in analysis, and physics depends pretty heavily on real analysis working correctly, so there’s always that.

5. #5 Be
May 3, 2010

Interesting. I had never heard of that function before.

6. #6 Anonymous
May 3, 2010

It is a theorem that a function is Riemann integrable if
and only if it is continuous alomost everywhere.

7. #7 Anonymous
May 3, 2010

I should have said “bounded function”

8. #8 --bill
May 3, 2010

What is f(0)?

9. #9 Anonymous
May 3, 2010

One

10. #10 Matt Springer
May 3, 2010

To elaborate on the f(0) = 1 answer, we know 0 is the same as 0/1, or 0/2, or 0/3, and so on. The definition requires that we pick the representation with the smallest possible natural number denominator, so that’s 0/1. The denominator is 1, so f(0) = 1.

11. #11 Johan
May 4, 2010

Indeed it is Riemann integrable. It is not terribly difficult to show this using the Darboux definition of the Riemann integral.

An intuitive argument would be that there are only finitely many points where the function takes the values larger than 1/N for every positive integer N. Thus the upper Riemann integral should take values less than 1/N for every such N. Since the lower Riemann integral is clearly zero we are done.

12. #12 Anonymous
May 5, 2010

Yes this argument works in this special case. Enclose each of the finite points where the function takes values
greater than 1/N by disjoint intervals having a total length
less than epsilon. These intervals together with the complementary intervals will give a partition of the interval [a, b] over which one is integrating. The contribution from the first set of intervals will be at most
epsilon since the function is bounded by one. The complementary intervals will give at most (b – a)/N. So the
total upper sum will be at most epsilon + (b-a)/N. Since
epsilon and N are arbitrary the upper integral is zero.
In general a bounded function f on an interval [a, b] is
Riemann integrable if and only if it is continuous almost
everywhere. It is not necessary to assume that f is measurable. The Borel measurability of f follows from the
hypothesis.

13. #13 Anonymous
May 6, 2010

Correction. The hypothesis that f is a bounded almost
everywhere continuous function implies that f is measurable
but not that f is Borel measurable. To show that f is measurable one can define a sequence of step funcions
and use the almost everywhere continuity of f to get that
the sequence converges pointwise almost everywhere to f.
This shows that f is measurable. Since f is then a bounded
measurable function it is Lebesgue integrable. One can
define then sequences of step functions whose integrals
are upper and lower Riemann sums of f and which converge
pointwise almost everywhere to f and then use the Dominated
Convergence Theorem to conclude that both the upper sums
and lower sums converge to the Lebesgue integral of f hence
to the same value so f is Riemann integrable.
A similar type of argument proves the converse result that
a Riemann integrable function is continuous almost every-
where.
Now a step function is Borel measurable but to conclude that
a pointwise limit of Borel functions is a Borel function
requires pointwise convergence everywhere. With almost
everywhere convergence the limit is measurable but not
necessarily Borel measurable.
To see that a Riemann integrable function need not be Borel consider all functions which are zero off the
Cantor set and bounded on the Cantor set but otherwise arbitrary.
Since the Cantor set is closed and has measure
zero all such functions are continuous almost everywhere
hence Riemann integrable. But the number of such functions
is 2^(2^alephnull) while the number of Borel functions is
2^alephnull so there are lots of Riemann integrable functions which are not Borel measurable.