Plotting the Monsters of Real Analysis

Riemann's function

What is called Riemann's function is usually defined on [0,1] as follows: if x ≠ 0 is rational, then there exists p ϵ ℤ and q ϵ ℕ such that GCD(p, q) = 1 and x = p/q; there we define f(x) as 1/q. On the other hand, for each irrational x, we define f(x) = 0. Finally, we choose f(0) = 1.

This function is well defined at every point of the compact set [0,1], yet its behaviour is very different from that of most functions encountered in early calculus. In fact, it's fairly easy to prove that f is continuous at every irrational in [0,1] and discontinuous at every rational.

So, what does the plot of this function looks like ? Since Mathematica's built-in Plot function computes just a few values of the function and connects them on a graph, we can expect good results using Plot with sufficiently well-behaved functions. However, in our case, the function is discontinuous at an infinite number of points in [0,1], so another approach should be prefered.

So, we proceed by first computing a list of points, each of the form {p/q, 1/q}, which we want to appear in the plot. Here n is the arbitrary number of points to be plotted.

\(n = 150; 

    points\  = \ 
      Union\ @@\ Table[{p/q, 1/Denominator[p/q]}, {q, n}, {p, q - 1}]; \)

Then we plot them using the built-in ListPlot function.

ListPlot[points,  PlotRange -> {0, .51}]

Not included in the plot were the two points (0,1) and (1,1). Notice that we have only plotted points at rational values of x, but since f(x) = 0 at every irrational, the plot would look the same if we included irrational values of x too. Moreover, it's much more difficult to generate an arbitrarily large number of irrational than rational numbers, and it's also rather pointless in this context, because there is always a rational lying arbitrarily close to an irrational on the real line.

Van der Waerden's function

Van der Waerden's function provide an important example of a function which is everywhere continuous but nowhere differentiable. It's defined in terms of an infinite sum of functions.

We first define a new symbol that computes distance from the nearest integer :

δ[x_]  :=  
      If[x - Floor[x]  <=  1/2, x - Floor[x], 1 - x + Floor[x]]

Then we define a function for each positive integer n :

ϕ[n_][x_] := δ[(2^n) x]/(2^n)

By plotting some of these functions, we can easily see that, in general, ϕ[n] has (2^n)peaks on [0,1], each with height (1/(2^n)).

Plot[{ϕ[0][x], ϕ[1][x], ϕ[2][x], 
        ϕ[3][x]}, {x, 0, 1}, PlotRange -> {0, .5}, 
      PlotStyle -> {Hue[0], Hue[.65]}]

Van der Waarden's function Φ is obtained by adding all the ϕ's, i.e.

Φ[x_]  :=  
      (∑_(n = 0)^∞) ϕ[n][x]

However, Mathematica can't handle this sum properly. So, rather than plotting Φ, we will plot a partial sum of a sufficiently large number of ϕ's. Since the height of the peaks of ϕ[n] decreases very rapidly, a relatively small number of terms will do.

Plot[(∑_(n = 0)^10) ϕ[n][x], {x, 0, 1}]

The following animation illustrates what happens when we add terms to the sum. The resulting function is so bumpy it is not differentiable anywhere.

MoviePlot[
      (∑_(n = 0)^k) ϕ[n][x], {x, 0, 1}, {k, 0, 10, 1},  
      PlotRange -> {0, .7}]

Those interested with a more detailed discussion of Van der Waerden's function may consult Gianluca Gorni's lecture notes (204 K, in PDF format) as well as his own Mathematica notebook (12 K).

Gabriel Chênevert
Undergraduate math student
Université de Montréal
Montréal, Québec, Canada
Original version: May 1999
Last modification:March 2000

Please feel free to e-mail me with any question, comment or suggestion at cheneveg@jsp.umontreal.ca, or via http://www.jsp.umontreal.ca/~cheneveg.