Thomae's function is a real-valued function of a real variable that can be defined as:: 531 f ( x ) = { 1 q if x = p q ( x is rational), with p ∈ Z and q ∈ N coprime 0 if x is irrational. {\displaystyle f(x)={\begin{cases}{\frac {1}{q}}&{\text{if }}x={\tfrac {p}{q}}\quad (x{\text{ is rational), with }}p\in \mathbb {Z} {\text{ and }}q\in \mathbb {N} {\text{ coprime}}\\0&{\text{if }}x{\text{ is irrational.}}\end{cases}}}
It is named after Carl Johannes Thomae, but has many other names: the popcorn function, the raindrop function, the countable cloud function, the modified Dirichlet function, the ruler function (not to be confused with the integer ruler function), the Riemann function, or the Stars over Babylon (John Horton Conway's name). Thomae mentioned it as an example for an integrable function with infinitely many discontinuities in an early textbook on Riemann's notion of integration.
Since every rational number has a unique representation with coprime (also termed relatively prime) p ∈ Z {\displaystyle p\in \mathbb {Z} } and q ∈ N {\displaystyle q\in \mathbb {N} } , the function is well-defined. Note that q = + 1 {\displaystyle q=+1} is the only number in N {\displaystyle \mathbb {N} } that is coprime to p = 0. {\displaystyle p=0.}
It is a modification of the Dirichlet function, which is 1 at rational numbers and 0 elsewhere.