Thomae's function
Thomae's function is a real-valued function of a real variable that can be defined as: 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, 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 ) formula_2 and formula_3, the function is well-defined. Note that formula_4 is the only number in formula_5 that is coprime to formula_6 It is a modification of the Dirichlet function, which is 1 at rational numbers and 0 elsewhere. Properties. For all formula_11 we also have formula_12 and hence formula_13 For all formula_14 there exist formula_2 and formula_3 such that formula_17 and formula_18 Consider formula_19. If formula_20 divides formula_21 and formula_22, it divides formula_23 and formula_21. Conversely, if formula_20 divides formula_23 and formula_22, it divides formula_28 and formula_22. So formula_30, and formula_31. Let formula_33 be an arbitrary rational number, with  formula_34 and formula_21 and formula_22 coprime. This establishes formula_37 Let formula_38 be any irrational number and define formula_39 for all formula_40 These formula_41 are all irrational, and so formula_42 for all formula_40 This implies formula_44 and formula_45 Let formula_46, and given formula_47 let formula_48 For the corresponding formula_49 we have formula_51 which is exactly the definition of discontinuity of formula_7 at formula_53. Since formula_7 is periodic with period formula_56 and formula_57 it suffices to check all irrational points in formula_58 Assume now formula_59 and formula_60 According to the Archimedean property of the reals, there exists formula_61 with formula_62 and there  exist formula_63 such that for formula_64 we have formula_65 The minimal distance of formula_53 to its "i"-th lower and upper bounds equals We define formula_68 as the minimum of all the finitely many formula_69 for all formula_71 formula_72 and formula_73 This is to say, all these rational numbers formula_74 are outside the Now let formula_75 with the unique representation formula_76 where formula_77 are coprime. Then, necessarily, formula_78 and therefore, Likewise, for all irrational formula_80 and thus, if formula_81 then any choice of (sufficiently small) formula_47 gives Therefore, formula_7 is continuous on formula_85 Related probability distributions. Empirical probability distributions related to  Thomae's function appear in DNA sequencing. The human genome is diploid, having two strands per chromosome. When sequenced, small pieces ("reads") are generated: for each spot on the genome, an integer number of reads overlap with it. Their ratio is a rational number, and typically distributed similarly to Thomae's function. If pairs of positive integers formula_106 are sampled from a distribution formula_107 and used to generate ratios formula_108, this gives rise to a distribution formula_109 on the rational numbers. If the integers are independent the distribution can be viewed as a convolution over the rational numbers, formula_110. Closed  form solutions exist for power-law distributions with a cut-off. If formula_111 (where formula_112 is the polylogarithm function) then formula_113. In the case of uniform distributions on the set formula_114 formula_115, which is very similar to Thomae's function. Both their graphs have fractal dimension 3/2. The ruler function. For integers, the exponent of the highest power of 2 dividing formula_116 gives 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, ... . If 1 is added, or if the 0s are removed, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3 , 1, 2, 1, ... . The values resemble tick-marks on a 1/16th graduated ruler, hence the name. These values correspond to the restriction of the Thomae function to the dyadic rationals: those rational numbers whose denominators are powers of 2. Related functions. A natural follow-up question one might ask is if there is a function which is continuous on the rational numbers and discontinuous on the irrational numbers. This turns out to be impossible; the set of discontinuities of any function must be an set. If such a function existed, then the irrationals would be an set. The irrationals would  then be the countable union of closed sets formula_117, but since the irrationals do not contain an interval, nor can any of the formula_118. Therefore, each of the formula_118 would be nowhere dense, and the irrationals would be a meager set. It would follow that the real numbers, being a union of the irrationals and the rationals (which is evidently meager), would also be a meager set. This would contradict the Baire category theorem: because the reals form a complete metric space, they form a Baire space, which cannot be meager in itself. A variant of Thomae's function  can be used to show that any subset of the real numbers can be the set of discontinuities of a function. If formula_120 is a countable union of closed sets formula_121, define Then a similar argument as for Thomae's function shows that formula_123 has "A" as its set of discontinuities. For a general construction on arbitrary metric space, see this article Kim, Sung Soo. "A Characterization of the Set of Points of Continuity of a Real Function." American Mathematical Monthly 106.3 (1999): 258-259.