Mellin transforms and asymptotics: digital sums

32

Transcript of Mellin transforms and asymptotics: digital sums

MELLIN TRANSFORMS ANDASYMPTOTICS: DIGITAL SUMSPhilippe Flajolet1;2, Peter Grabner3,Peter Kirschenhofer1, HelmutProdinger1, and Robert F. Tichy1;3Abstract. Arithmetic functions related to number represen-tation systems exhibit various periodicity phenomena. For in-stance, a well known theorem of Delange expresses the totalnumber of ones in the binary representations of the �rst n inte-gers in terms of a periodic fractal function.We show that such periodicity phenomena can be analyzedrather systematically using classical tools from analytic num-ber theory, namely the Mellin{Perron formul�. This approachyields naturally the Fourier series involved in the expansions of avariety of digital sums related to number representation systems.July 25, 1991. Revised, June 6, 1992Final version to appear in Theoretical Computer Science.1. IntroductionLet S(n) represent the total number of 1-digits in the binaryrepresentations of the integers 1; 2; : : : ; n�1. It is not hard to seethat(1.1) S(n) = 12n log2 n+ o(n logn);since asymptotically the binary representations contain roughly asmany 0's as 1's. The Trollope{Delange formula is more surprising.1 Research of these authors was supported by the French-Austrian scien-ti�c cooperation programme.2 Research of this author was supported in part by the Basic ResearchAction of the E.C. under contract No. 7141 (Project ALCOM 2).3 Research of these authors was supported by the Austrian science foun-dation (Project Nr. P8274PHY). Typeset by AMS-TEX1

2 P. FLAJOLET ET AL.It expresses S(n) by an exact formula [De75](1.2) S(n) = 12n log2 n+ nF0(log2 n);where F0(u), a fractal function, is a continuous, periodic, nowheredi�erentiable function; F0(u) has an explicit Fourier expansionthat involves the Riemann zeta function, its Fourier coe�cient oforder k, k 6= 0, beingfk = � 1log 2 �(�k)�k(�k + 1) for �k = 2�iklog 2 :The argument given by Delange relies on a combinatorial de-composition of binary representations of integers, followed by acomputation of the Fourier coe�cients of the fractal function.Our approach instead is more direct and in line with classicalmethods from analytic number theory. It is based on an integralrepresentation (see Eq. (3.2)), here1nS(n)� n� 12 = 12�i 2+i1Z2�i1 �(s)2s � 1ns dss(s + 1) ;itself closely related to Mellin transforms and the classical Perronformula. In this context, the periodicity present in S(n) simplyarises, by the residue theorem, from poles of the integrand at theregularly spaced points s = 2�ik= log 2.In other words, as is customary from standard analytic num-ber theory (e.g., the prime number theorem), uctuations in anumber-theoretic function appear to be directly related to singu-larities of an associated Dirichlet series.The Mellin Perron formul� are reviewed brie y in Section 2.In general, they provide asymptotic rather than exact summationformul�. An additional argument is then needed in order to es-tablish an exact representation like (1.1). Similar exact formul�are established for the standard sum{of{digit function (Section 3),

MELLIN TRANSFORMS AND ASYMPTOTICS: DIGITAL SUMS 3for the more general case of the number of blocks in binary repre-sentations and Gray codes (Section 4), and for a function relatedto the Cantor set (Section 5),h Xi 2ei! =Xi 3ei ;where the exponents ei are strictly increasing.Sections 6 and 7 deal primarily with asymptotic summationformul�. Section 6 is concerned with the asymptotic evaluationof the function(1.3) �(n) = n�1Xk=0 2�(k);where �(k) denotes the binary sum-of-digits function. The value�(n) is also equal to the number of odd binomial coe�cients inthe �rst n rows of Pascal's triangle. Stolarsky [Sto77] earlier gaveupper and lower bounds for this expression. Applying the Mellin-Perron formula and a pseudo{Tauberian argument the Fouriercoe�cients of the corresponding fractal function are computed.(Estimates were also given by Harborth [Ha77] and in the q-arycase by Stein [Ste89].) It is found that �(N)N� is a periodic functionof log2N , with � = log2 3, see Figure 1 for a graphical rendering.Section 7 is concerned with the asymptotic evaluation ofS3(n) = n�1Xk=0(�1)�(3k);a function obviously related to the distribution of 1{digits in themultiples of three which was �rst studied by Newman [Ne69]. J.Coquet [Co83] established a Delange type theorem in this case.The asymptotic formul� obtained in connection with �(n) andS3(n) when matched against exact formul� obtained by directcombinatorial reasoning, lead to new Fourier expansions. Thismixed combinatorial{analytic process constitutes another source

4 P. FLAJOLET ET AL.4 16 64 256 10240.80

0.82

0.84

0.86

0.88

0.9

0.92

0.94

0.96

0.98

Figure 1. The representation of �(n)n� plotted against n in a log-arithmic scale; �(n) represents the number of odd binomial coef-�cients in the �rst n rows of Pascal's triangle and is also de�nedby Eq. (1.3); � = log2 3.for summatory formul� with explicit Fourier coe�cients devel-oped in Sections 6 and 7.Exact summation formul� related to number representation-s arise at various places in elementary (combinatorial) numbertheory as well as in the average case analysis of algorithms.As general references in number theory, we refer to Stolarsky'ssurvey [Sto77] and to [KPT85]. An especially important paperby the spectrum of its analysis techniques is Brillhart, Erd}os andMorton's work [BEM83]. It concerns the Rudin{Shapiro sequence,r(n), which gives the parity of the number of blocks 11 in thebinary representation of n.The summatory formul� considered here are closely relatedto number{theoretic functions arising in the context of iterated

MELLIN TRANSFORMS AND ASYMPTOTICS: DIGITAL SUMS 5substitutions and so{called automatic sequences (see Allouche'spaper for a survey [Al87]), which constitute a natural frameworkin which several of our analyses could have been cast. In thatframework Dumont and Thomas [DT89] have used elementarymethods to derive for linear functionals of iterated substitutionsequences a whole class of asymptotic forms of the typen�(log� n) F (logn) + o(n�(log� n) );involving some uctuating function F . Allouche and Cohen haveshown that Dirichlet generating functions associated to automaticsequences have meromorphic continuations (see [Al87, p.261] and[AC85]). Techniques developed in this paper could then be usedin order to provide alternative derivations for some of the resultsof Dumont and Thomas.The present work is also related to the notion of regular se-quences, a generalization of automatic sequences, that was intro-duced by Allouche and Shallit in [AS92]. In fact, the sequences un-der study here fall into that category. In this context, some of ourresults are complemented by the recent work of Cateland [Ca92]who established precisely non{di�erentiability properties for sev-eral of our periodic functions (like the ones for Gray code or blockoccurrences).In the area of the average case analysis of algorithms, combi-natorial sums involving number{theoretic functions often presentthemselves. Delange's formula was employed in order to analyzeregister allocation strategies, or equivalently the order of randomchannel networks in [FRV79]. It was later extended to some non-standard digital representations of integers, like Gray code [FR80],for the purpose of analyzing sorting networks, as well as to occur-rences of blocks of digits in standard q-ary representations [Ki83]and subblock occurrences in Gray code representation [KP84] or

6 P. FLAJOLET ET AL.Figure 2. Pascal's triangle modulo 2. The odd numbers arerepresented by black squares, the even numbers by white squares.to Newman sequence related to the binary representations of mul-tiples of three [Co83]. (In a recent paper [GT91], Delange's resultwas even further generalized to digit expansions with respect tolinear recurrences.)Finally, the subject of this paper is also close to the classicaldivide-and-conquer recurrences that are common in theoreticalcomputer science and of which a typical form isfn = fbn=2c + fdn=2e + en;with feng a usually simple sequence and ffng the sequence tobe analyzed. In a recent work, Flajolet and Golin [FG92] treatseveral instances that appear in a diversity of recursive divide-and-conquer algorithms like mergesort, heapsort, Karatsuba mul-tiplication, or maxima �nding in multidimensional space.Graphics. As an illustration of the fractal phenomena at s-take, we have displayed in Figure 1 the ratio �(N)N� plotted againstN in a logarithmic scale. When considering successive intervals[2k�1; 2k], we see the function �(N)N� which gets re�ned in a step-

MELLIN TRANSFORMS AND ASYMPTOTICS: DIGITAL SUMS 7wise manner. The picture clearly illustrates the fractal natureof the graph. Figure 2 shows Pascal's triangle reduced modulo2. The picture reveals another aspect of the fractal structure un-derlying the problem. (Performing an easy transformation oneobtains the famous Sierpinski triangle [Fa85], a popular source forsimilar graphics being [Wo84].)2. Mellin-Perron formul�For completeness, we give a brief outline of the Perron formulaby relating it to the Mellin transform. The resulting summationformul� are classical, so that we content ourselves with a sketchydescription of the analysis involved.The major reference for Mellin transforms is Doetsch's book[Do50]. Mellin summation is brie y surveyed in [FRS84] which isdirected towards applications in the average case analysis of al-gorithms, while in the context of integrals (rather than sums), auseful reference is [Wo89, Chap. III]. The classical Perron formu-la is discussed at length in Apostol's book [Ap84], and a higherorder version is for instance given by Schwarz (see Chapter IVof [Sch69]).Let f(x) be a function de�ned over [0;+1). Its Mellin trans-form f�(s) =M[f(x); s] is de�ned by(2.1) f�(s) = Z 10 f(x)xs�1dx:By linearity and the rescaling property we have(2.2) F (x) =Xk �kf(�kx) =) F �(s) = Xk �k��sk ! f�(s):The condition is for s to belong to a `fundamental strip' de�ned bythe property that the integral giving f�(s) and the sumPk �k��skare both absolutely convergent.

8 P. FLAJOLET ET AL.Similar to the Laplace transform there is an inversion theorem(cf. [Do50]). When applied to (2.2), it provides(2.3) Xk �kf(�kx) = 12�i c+i1Zc�i1 Xk �k��sk ! f�(s)x�sds;with c in the fundamental strip.Formula (2.3) could be called Mellin's summation formula. It isespecially useful when the integral can be computed by residues,and in that case each residue contributes a term in an asymptoticexpansion of F (x).This formula lends itself to various number theoretic applica-tions, most notably proofs of the prime number theorem. Intro-duce the step function H0(x) de�ned byH0(x) = � 1 if x 2 [0; 1]0 if x > 1,together with the functions Hm(x) = (1 � x)mH0(x). In theinteresting case where �k � k, we obtain from (2.3) formul� of thePerron type that provide integral representations for the iteratedsummations of arithmetic functions in terms of their Dirichletgenerating function.Theorem 0. Let c > 0 lie in the half{plane of absolute conver-gence of Pk �kk�s. Then for any m � 1, we have(2.4)1m! X1�k<n�k �1� kn�m = 12�i c+i1Zc�i1 0@Xk�1 �kks1Ans dss(s + 1) � � � (s +m) :For m = 0,X1�k<n�k + �n2 = 12�i c+i1Zc�i1 0@Xk�1 �kks1Ans dss :Formula (2.4) is obtained from (2.3) by setting x � n�1, f(x) �Hm(x), and observing that H�m(s) = m!(s(s + 1) � � � (s +m))�1.

MELLIN TRANSFORMS AND ASYMPTOTICS: DIGITAL SUMS 9For m = 0 the formula has to be modi�ed slightly by taking aprincipal value for the sum, since H0(x) is discontinuous at x = 1.See also [Ap84, p.245] for a direct proof of the m = 0 case.For instance, if we use �k � 1 and m = 1, we get(2.5) n� 12 = 12�i 2+i1Z2�i1 �(s)ns dss(s + 1) :Shifting the line of integration to the left and taking residues intoaccount we obtain(2.6) 0 = � 14+i1Z� 14�i1 �(s)ns dss(s + 1) :Identity (2.6) is the basis for the existence of several exact ratherthan plainly asymptotic summation formul�.3. Sum-of-Digits FunctionsWe apply the Mellin{Perron technique described in the preced-ing section in order to derive a new proof of Delange's theorem.Theorem 1. [Delange] The sum-of-digits function S(n) satis�esS(n) = 12n log2 n+ nF0(log2 n);where F0(u) is representable by the Fourier series F0(u) =Pk2Z fke2�ikuand f0 = log2 �2 � 12 log 2 � 34fk = � 1log 2 �(�k)�k(�k + 1) for �k = 2�iklog 2 ; k 6= 0:Proof. Let �2(k) be the exponent of 2 in the prime decompositionof k and �(k) be the number of 1-digits in the binary represen-tation of k. We have �(k) � �(k � 1) = 1 � �2(k), so that S(n)

10 P. FLAJOLET ET AL.resembles a double summation of �2(k). Furthermore it is well-known that(3.1) Xk�1 �2(k)ks = �(s)2s � 1 :Thus, from (2.4), with �k = �2(k) and m = 1, we get the basicintegral representation(3.2) S(n) = n(n� 1)2 � n2�i 2+i1Z2�i1 �(s)2s � 1ns dss(s + 1) :The integrand in (3.2) has a simple pole at s = 1, a double pole ats = 0 and simple poles at s = �k. Shifting the line of integration1to <(s) = � 14 and taking residues into account we get(3.3) S(n) = 12n log2 n+ nF0(log2 n) � nR(n);where the Fourier series akin to F01log 2X2Z �(�k)�k(�k + 1)n�koccurs as the sum of residues of the integrand at the imaginarypoles s = �k. The remainder term is(3.4) R(n) = 12�i � 14+i1Z� 14�i1 �(s)2s � 1ns dss(s + 1) ;so that there only remains to prove that R(n) � 0 when n isan integer. The integral converges since j�(� 14 + it)j � jtj 34 (cf.[WW27]).Using the expansion12s � 1 = �1� 2s � 22s � 23s � � � �1Technically, we integrate along a rectangle with upper and lower sidespassing through�(2N+1)i�= log 2, and letN !1. Due to growth propertiesof the zeta function, the contribution along the horizontal segments vanishes.This also proves directly that the sum of residues at the complex points (whichgives the Fourier series) converges.

MELLIN TRANSFORMS AND ASYMPTOTICS: DIGITAL SUMS 11in (3.4) which is legitimate since now <(s) < 0, we �nd that R(n)is a sum of terms of the form12�i � 14+i1Z� 14�i1 �(s)(2kn)s dss(s + 1) ;and each of these terms is 0 by virtue of (2.6). �It is clear from the discussion above that an exact formula fora sum-of-digits function is obtained each time a similar Dirich-let generating function can be introduced. Let us illustrate thispoint by the integral representation for the sum-of-digits functionassociated to Gray code representations.The Gray code representation of the integers starts like0; 1; 11; 10; 110; 111; 101; 100; 1100; 1101; : : : ;its characteristic is that the representations of n and n + 1 di�erin exactly one binary position and it is constructed in a simplemanner by re ections based on powers of two (for a de�nition,see, e.g., [FR80]). Let (k) be the number of 1-digits in the Graycode representation of k, and �k = (k)� (k�1). It is easy to seethat �2k = �k, and the pattern for odd values is �2k+1 = (�1)k.Thus the Dirichlet generating function �(s) of f�kg is�(s) = 2sL(s)2s � 1 with L(s) = 1Xk=0 (�1)k(2k + 1)s :Thus by (2.4), the summatory function G(n) =Pk<n (k) admitsthe integral representation(3.5) G(n) = n2�i 2+i1Z2�i1 2sL(s)2s � 1 ns dss(s + 1) :

12 P. FLAJOLET ET AL.Theorem 2. [Flajolet, Ramshaw] The summatory function G(n)of sum-of-digits function of Gray-code satis�esG(n) = 12n log2 n+ nF1(log2 n);where F1(u) is representable by the Fourier seriesF1(u) = 2 log2 �(14 )� 32 � log2 �+ 1log 2 Xk2Znf0g L(�k)�k(�k + 1)e2k�iu:Proof. Starting with the representation (3.5), the proof runs alongthe same line as for the sum{of{digits function; this theorem isalso a corollary of Theorem 3 proved in Section 4. �Remark 1. The functions F0 and F1 are continuous butnowhere di�erentiable.4. Subblock occurrences and the Gray CodeIn this section we want to demonstrate that the idea used in theprevious section for the analysis of the sum-of-digits function isalso well suited to establish a much more general result on occur-rences of patterns in the binary representation of integers. Themain terms of Theorem 3 were already found by Kirschenhoferin [Ki83], but only an estimate of the remainder term was given.The remainder term has been also investigated independently byCateland [Ca92] using elementary methods of the Delange type.Theorem 3. Let (n;w) denote the number of occurrences of the0-1-string w as a contiguous subblock in the binary representationof the integer n. (If w starts with 0, we also count occurrencesthat overhang to the left of the most signi�cant digit of n; weonly exclude strings w consisting solely of 0's2.) Then the meannumber of occurrences, 1n Pk<n(k;w), is given by1nXk<n(k;w) = log2 n2jwj +Hw (log2 n) + Ew(n)n :2A formula for this case exists, but is unpleasant to formulate

MELLIN TRANSFORMS AND ASYMPTOTICS: DIGITAL SUMS 13There jwj denotes the length of the stringw, Hw(u) is a continuousperiodic function of period 1 with Fourier expansion Hw(u) =Pk2Z hke2k�iu,h0 = log2� �((0:w)2)�((0:w)2 + 2�jwj)�� 12jwj �jwj � 12 + 1log 2�hk = �(�k; (0:w)2) � �(�k; (0:w)2 + 2�jwj)(log 2)�k(�k + 1) ;�(z; a) the Hurwitz �-function, (x)2 denotes the real number withbinary representation x and Ew(n) is a dyadic rational with de-nominator 2jwj which is described explicitly below in (4.9).Proof. As in Section 3 we start with summation by parts to �nd(4.1) Xk<n(k;w) =Xk<n�w(k)(n � k);where �w(k) = (k;w) � (k � 1;w). The di�erences �w(k) obeythe following recurrence relation: If n = 2jwjk+ r is even, we have(4.2) �w(n) = �w �n2 �+8><>: 1 if (w)2 = r�1 if (w)2 = r � 10 otherwiseIf n = 2jwjk + r is odd, we simply have(4.3) �w(n) = 8><>: 1 if (w)2 = r�1 if (w)2 = r � 10 otherwise.From the recurrences (4.2) and (4.3) it easily follows that theDirichlet series Aw(s) of the di�erences �w(n) satis�esAw(s) =Xn�1 �w(n)ns =Xk�1 �w(k)(2k)s +Xk�0 1�2jwjk + (w)2�s��Xk�0 1�2jwjk + (w)2 + 1�s ;so that(4.4)�1� 12s�Aw(s) = 12jwjs ��(s; (0:w)2) � �(s; (0:w)2 + 2�jwj)� ;

14 P. FLAJOLET ET AL.where �(s; a) =Xn�0 1(n + a)sis the Hurwitz �-function [WW27] and (0:w)2 denotes the rationalnumber (w)22�jwj.From (4.1) and (4.4) we �nd using Perron's formula for m = 1:1nXk<n(k;w) = 12�i 32+i1Z32�i1 12jwjs ��((s; (0:w)2)� �(s; (0:w)2 + 2�jwj)��� (2n)sds(2s � 1) s(s + 1)Shifting the contour of integration to the left, we observe that the�rst order poles of the Hurwitz �-functions at s = 1 cancel sinceboth have residue 1, so that the main contribution comes fromthe second order pole s = 0. The residue is(4.5) C1 log2 n+ C2log 2 + C1�12 � jwj � 1log 2� ;with C1 = �(0; (0:w)2)� �(0; (0:w)2 + 2�jwj) = 2�jwj;since �(0; a) = 12 � a andC2 = � 0(0; (0:w)2)� � 0(0; (0:w)2 +2�jwj) = log �((0:w)2)�((0:w)2 + 2�jwj) ;since � 0(0; a) = log �(a) � 12 log(2�) [WW27].Thus the main term and the mean h0 of the uctuating term areestablished. The other Fourier coe�cients hk are easily derivedfrom the residues at the simple poles �k = 2�iklog 2 , k 6= 0.We still have to analyze the remainder term(4.6)Rn = 12�i � 14+i1Z� 14�i1 12jwjs ��(s; (0:w)2)� �(s; (0:w)2 + 2�jwj)��� (2n)sds(2s � 1) s(s + 1) = �Xk�0R02kn;

MELLIN TRANSFORMS AND ASYMPTOTICS: DIGITAL SUMS 15whereR0n = 12�i � 14+i1Z� 14�i1 12jwjs ��(s; (0:w)2) � �(s; (0:w)2 + 2�jwj)� (2n)sdss(s + 1) :After shifting the contour back to the right, we �nd, by takinginto account the residues at s = 0,(4.7) R0n = � 12jwj + Xk<2n�k �1� k2n� ;where �k = 8><>: 1 if k � (w)2 mod 2jwj�1 if k � (w)2 + 1 mod 2jwj0 otherwise.The sum in (4.7) can be computed explicitly to give(4.8) R0n = ( 2jwj�1�r2jwj+1 1n if r = (2n� 1 mod 2jwj) � (w)2�1�r2jwj+1 1n if r = (2n� 1 mod 2jwj) < (w)2.From (4.8) we see that R02kn will be zero for k � jwj � 1, so thatin fact (4.6) reduces to(4.9) Ew(n)n = � jwj�2Xk=0 R02kn;and this completes the proof. �Theorem 3 and formula (4.9) have a number of consequencesof interest. In particular, they contain as special cases the resultson binary representations and Gray code.Corollary 1. [Delange] If jwj = 1 and w is the 1-digit, i.e. in thecase of the sum-of-digits function, we have Ew(n) = 0, as statedalready in Theorem 1.Corollary 2. If jwj = 2, the remainder terms Ew(n) are givenby the scheme E01(n) E10(n) E11(n)n even 0 0 0n odd � 14 14 14

16 P. FLAJOLET ET AL.Corollary 3. [Flajolet, Ramshaw] The mean value of the sum ofdigits in the Gray Code of n is given bylog2 n2 + F1 (log2 n) ;where F1 = H01 +H10 is as described in Theorem 2.Proof. An alternative proof to that of Theorem 2 runs as follows.The k-th bit in the Gray Code GC(n) of n is given by the summodulo 2 of the k{th and k+1{st digit in the binary representationof n. Thus the number of 1's in GC(n) is just (n; 01) + (n; 10),where we have to count the one occurrence of 01 overhanging tothe left of the most signi�cant 1 in the binary representation of n.It follows that the mean is given by2 log2 n4 +H01 (log2 n) +H10 (log2 n) + E01(n)n + E10(n)n= log2 n2 + F1 (log2 n) ;which also relates F1 to H01 and H10. �Remark 2. All results in Sections 3 and 4 are easily gener-alized to base q representations. As an application of the specialinstance q = 4 we get an alternative proof of a result due to Os-baldestin and Shiu [OS89] concerning the number of integers � nthat are representable as a sum of three squares.5. Triadic Binary NumbersLet h(n) be the number that results from interpreting in base3 the binary representation of n, i.e.,h Xi 2ei! =Xi 3ei ;where the exponents ei are strictly increasing. It is known thath(1) < h(2) < : : : < h(n) is the `minimal' sequence of n positiveintegers not containing an arithmetic progression. The sequenceis also an analog of Cantor's triadic set. An exact formula for thesummatory function H of h is established.

MELLIN TRANSFORMS AND ASYMPTOTICS: DIGITAL SUMS 17Theorem 4. For the summatory function H(n) =Pk<n h(k) wehave H(n) = n�+1F3(log2 n)� 14n;where � = log2 3 and F3(u) is the Fourier seriesF3(u) = 13 log 2Xk2Z �(�+ �k) e2�iku(�+ �k)(�+ �k + 1) ;with �k = 2�iklog 2 .Proof. Using h(n)� h(n� 1) = 12(3�2(n) + 1) we obtain1Xn=1 h(n)� h(n� 1)ns = 12 1Xn=1 3�2(n)ns + 12�(s)=12 1Xk=0 3k2ks 1Xn=1 1(2n� 1)s + 12�(s)=2s � 22s � 3�(s):Applying the Mellin-Perron summation formula (2.4) with c = 3and shifting the line of integration yieldsH(n) = n2�i � 14+i1Z� 14�i1 2s � 22s � 3�(s)ns dss(s + 1)+ n�+1Xk2Z 13 log 2�(�+ �k) n�k(�+ �k)(� + �k + 1) + 12�(0)n:The remainder integral is 0 by the same argument as for the sum{of{digits function, and the proof is complete. �Remark 3. Obviously the base 3 can be replaced by an arbi-trary number � > 1 and � 6= 2. The corresponding exact formulais Xk<nh�(k) = n�+1F�(log2 n) � 12(� � 1)n;where F� has a Fourier expansion similar to F3 and � = log2 �.Remark 4. The function g de�ned by h(n) = n�g(log2 n) isperiodic with period 1 but not continuous.

18 P. FLAJOLET ET AL.6. Odd Numbers in Pascal's TriangleIn this section we establish an exact formula for the summatoryfunction �(n) = X0�k<n 2�(k):As pointed out in the introduction, �(n) is the number of oddbinomial coe�cients in the �rst n rows of Pascal's triangle.The application of Mellin{Perron techniques requires conver-gence of the complex integral of Theorem 0. For an m{fold sum-mation, the `kernel' in the integral involves 1=(s(s+1) � � � (s+m�1)), which decreases at in�nity like jsj�m. Thus, higher summa-tions lead to better converging (inverse Mellin) integrals.For the problem of �(n), we thus start with the double sum-matory function (N) = X1�n<N(�(n) � 1);where Mellin{Perron is easier to apply since the Fourier expansionconverges absolutely (We have to subtract 1, because the summa-tion in (2.4) starts at n = 1.) The formula that we get in this wayis asymptotic.Theorem 5. The arithmetic function (N) satis�es the asymp-totic estimate(N) = N�+1G(log2N) +O(N2+"); � = log2 3for arbitrary " > 0, where G is a continuous periodic function withperiod 1. G admits an absolutely convergent Fourier expansionG(u) =Xk2Z gke2�ikuwith gk = 2log 2 (1�B(�k))�k(�k + 1) ;

MELLIN TRANSFORMS AND ASYMPTOTICS: DIGITAL SUMS 19where �k = �+ 2k�ilog 2 and(6.1)B(s) = 1�(s) Z 10 �1� e�t� 1Yk=1�1 + 2e�t2k�! � 1! ts�1dt:In order to come back to the Fourier expansion of F we need anexternal argument in order to convert the expansion of (N) intoan expansion for �(n). One ingredient is a direct combinatorialproof of existence for the uctuating part of �(n); this inducescorresponding periodicities for (N), and by identi�cation, weindirectly derive the Fourier expansion relative to �(n). (Thisprocess is in a way a pseudo{Tauberian argument!)Theorem 6. The summatory function �(n) satis�es the exactformula(6.2) �(n) = n�F (log2 n);where � = log2 3 and F is a continuous function of period 1. TheFourier coe�cients of F (u) are given by(6.3) fk = 2log 2 (1 �B(�k))�k ;and in particular the mean value of F (u) is approximatelyf0 � 0:86360 49963 99079 60496 05033 61308 09499:F (u) is represented by its Fourier series in the sense of standard(C; 1) Ces�aro averages.Observe that from [Ha77] it is already known that0:812 � F (u) � 1:Proof. (Theorem 5) Let(6.4) A(s) = 1Xn=1 2�(n)ns

20 P. FLAJOLET ET AL.be the Dirichlet generating function of 2�(n). Since (N) is adouble summation of 2�(k) we have an integral representation bymeans of the iterated Mellin-Perron formula (2.4). We get(6.5) (N) = N2�i 3+i1Z3�i1 A(s)Ns dss(s + 1) ;where the abscissa <(s) = 3 has been chosen, since A(3) convergesabsolutely. We need to locate the singularities of A(s). From therecurrences �(2k + 1) = �(k) + 1 and �(2k) = �(k)we get A(s) = Xk�0 mod 2 2�(k)ns + Xk�1 mod 2 2�(k)ks == 12sA(s) + 2 1Xl=0 2�(l)(2l + 1)s == 32sA(s) + 2� 2B(s)with(6.6) B(s) = 1Xk=1 2�(k)� 1(2k)s � 1(2k + 1)s� :Using summation by parts and Stolarsky's elementary estimate(cf. [Sto77])(6.7) 13 < �(n)n� < 3we know that B(s) converges for <(s) > �� 1 and by(6.7) A(s) = 2s2s � 3 (2� 2B(s))A(s) has abscissa of convergence equal to �. This expression alsoprovides us with the analytic continuation of A(s) for <(s) > ��1.

MELLIN TRANSFORMS AND ASYMPTOTICS: DIGITAL SUMS 21We see that A(s) is meromorphic with simple poles at the points�k = �+ 2�iklog 2 .In order to shift the contour of integration in (6.5) to the leftwe need that A(s) does not grow too large along vertical lines.For s = � + it, with � > 1 and jtj > �p3 , we have����1��1� 12k + 1�s���� � min�2; jtjk � :Thus we obtainjB(s)j = ����� 1Xk=1 2�(k)(2k)s �1��1� 12k + 1�s������ �� 2 X1�k�2jtj 2�(k)(2k)� + Xk>2jtj 2�(k)(2k)� jtjk � jtj2��:Shifting the line of integration to <(s) = 1 + " < �, noting thatjA(1 + " + it)j � jtj1�" and taking the residues at the poles �kinto account we get(N) = N2�i 1+"+i1Z1+"�i1 A(s)Ns dss(s + 1)++N�+1Xk2Z 2log 2 1�B(�k)�k(�k + 1)N�k :Estimating the integral trivially we derive the asymptotic formulafor (N).So far, B(s) is de�ned in terms of the sequence f2�(k)g itself.An integral representation derives from an ordinary generatingfunction, setting'(t) = 1Xk=0 2�(k)e�kt = 1Yj=0�1 + 2e�2jt� :Consider the Mellin transform of (1 � e�t)'(2t) � 1; by Formu-la (2.2) (with �k = k, f(t) = e�t), we get the integral representa-tion for B(s). Thus the proof of Theorem 5 is completed. �In order to get information on the number-theoretic function�(n) itself, we �rst work out a re�nement of Stolarsky's elemen-tary approach.

22 P. FLAJOLET ET AL.Proposition 1. There exists an exact summation formula(6.8) �(n) = n�F (log2 n)with F continuous and periodic with period 1.Proof. From [Sto77] there is an alternative formula(6.9) � n = rXi=1 2ei! = rXi=1 2i�13eiwith decreasing exponents ei. Pulling out the main term we get(6.10) �(n) = 3e1 rXi=1 2i�13ei�e1 ;where e1 = blog2 nc.We now de�ne a real function (x) on the interval [1; 2] asfollows. Let x = 1Xj=0 2�djwith 0 = d0 < d1 < : : : . Then we set(6.11) (x) = 1Xj=0 2j3�dj :Note that is well-de�ned since the dyadic rationals are writtenin their in�nite representation. Next we show the continuity of .As the representation of dyadic irrationals is unique the continuityat these points follows immediately, since (because of dj � j) theexpansion (6.11) converges faster than a geometric series withquotient 23 . For the proof of continuity at dyadic rationals wehave to show 0@ kXj=0 2�dj1A = 0@k�1Xj=0 2�dj + 1Xl=dk+1 2�l1A ;which follows immediately by direct computation. Note that (1) =1 and (2) = 3 and that satis�es a Lipschitz{H�older conditionj (x) � (y)j � Cjx� yj��1:

MELLIN TRANSFORMS AND ASYMPTOTICS: DIGITAL SUMS 23Using the function we can write(6.12) �(n) = 3blog2 nc � n2blog2 nc � ;since n2blog2 nc is nothing but n \scaled" in binary to the interval[1; 2). Formula (6.12) thus transforms into�(n) = n�F (flog2 ng);where F (u) = 3�u (2u)is de�ned over the interval [0; 1] and fxg = x � bxc denotes thefractional part. F can be extended into a periodic function sinceF (0) = F (1). The proof of Proposition 1 is completed. �For the computation of the Fourier coe�cients of F we makeuse of Theorem 5 and the following simple pseudo{Tauberian ar-gument.Proposition 2. Let f be a continuous function, periodic withperiod 1, and let � be a complex number with <(� ) > 0. Thenthere exists a continuously di�erentiable function g of period 1such that(6.13) 1N�+1 Xn<N n�f(log2 n) = g(log2N) + o(1)(6.14) Z 10 g(u)du = 1� + 1 Z 10 f(u)du:Proof. We set(6.15)g(u) = log 2�2�(�+1)u2�+1 � 1 Z 10 2(�+1)tf(t)dt+log 2�2�(�+1)u Z u0 2(�+1)tf(t)dt:Obviously g is continuously di�erentiable and (6.14) follows by astraightforward application of integration by parts. Further wenote that g(0) = g(1).

24 P. FLAJOLET ET AL.In order to prove (6.13) we proceed as follows1N�+1 Xn<N n�f(log2 n) == 1N�+1 blog2Nc�1Xp=0 X2p�n<2p+1 n�f(log2 n) + 1N�+1 NXn=2blog2 Nc n�f(log2 n) == 1N�+1 Xp<blog2 Nc 2p(�+1) X1�x<2x�f(log2 x)�x++ 1N�+1 2blog2 Nc(�+1) X1�x<y x� f(log2 x)�x;where x = n2p , y = N2blog2 Nc and x runs through all dyadic rationalswith denominator 2p and �x = 2�p, p = 0; : : : ; blog2Nc. Nowwe interpret the sums over x as Riemann sums. Thus we havewith remainder terms "(p) tending to 0 (for p!1)1N�+1 Xn<N n�f(log2 n) == Xp<blog2Nc 2(p�blog2Nc)(�+1)y�(�+1)�Z 21 x�f(log2 x)dx + "(p)�++y�(�+1)�Z y1 x�f(log2 x)dx + "(blog2Nc)� ==g(log2 y) + y�(�+1) blog2NcXp=0 "(p)2�(blog2Nc�p):We note that only "(blog2Nc) depends on y. Since the conver-gence of Riemann sums is uniform with respect to the upper limity, the remainder term tends to 0. Thus the proof of Proposition2 is complete. �Proof. (Theorem 6)We can now conclude and determine the Fouri-er coe�cients fk of the fractal function F in Theorem 6. We set� = �k in Proposition 2 and apply (6.14)fk = Z 10 F (u)e�2�ikudu = (�k+1)Z 10 G(u)e�2�ikudu = (�k+1)gk:Inserting the value of gk yieldsfk = 2log 2 1�B(�k)�k :

MELLIN TRANSFORMS AND ASYMPTOTICS: DIGITAL SUMS 25Using jB(�k)j � k2�� we obtain the L2-convergence of the Fouri-er expansion of F . Also, since we know that F (u) is continuous,its Fourier series converges in the mean by Fej�er's theorem [Ko88].(More information on the convergence of the Fourier series wouldhave to depend on a more detailed knowledge of the analytical be-haviour of the function B.) This completes the proof of Theorem6. � 7. The Newman{Coquet FunctionIn this section we investigate the function(7.1) S3(n) = Xk<n(�1)�(3k):The motivation for the study of this function goes back to New-man [Ne69] who noted that examination of the multiples of three,3; 6; 9; 12; 15; 18; 21; 24; 27; : : : , written in the base two,11; 110; 1001; 1100; 1111; 10010; 10101; 11000; 11011; : : : ;shows a de�nite preponderance of those containing an even num-ber of one{digits over those containing an odd number. New-man proved that this strange behaviour persists forever. Coquet[Co83] gave an exact formula by Delange type computations. Ourmethod uses this result and allows us to compute the Fourier coef-�cients (especially the mean value) of the related fractal function.Theorem 7. The summatory function S3 satis�es the exact for-mula S3(n) = n� (log4 n) + �(n)3 ;where is a continuous nowhere di�erentiable function of period1, � is given by�(n) = � 0 if n is even(�1)�(3n�1) if n is odd

26 P. FLAJOLET ET AL.and � = log 3log 4 . The Fourier expansion (u) = Pk2Z ke2k�iu isgiven by k = 3�k(�1)k�k6p3 log 2�3 + (�1)kp3� �1 + (�1)kp3� f0(�k)++ �2 + (�1)kp3� f1(�k)� f2(�k)�;where �k = �+ k�ilog 2 andf0(s) = 13�(s) 1Z0 �F �e�t�+ F ��e�t�+ F ��2e�t�� 3� �1� e� t2� ts�1dtf1(s) = 13�(s) 1Z0 �F �e�t�+ �2F ��e�t�+ �F ��2e�t�� �1� e� t2� ts�1dtf2(s) = 13�(s) 1Z0 �F �e�t�+ �F ��e�t�+ �2F ��2e�t�� �1� e� t2� ts�1dtwith � = e 2�i3 and(7.2) F (z) = 1Yk=0�1� z2k� :In particular, a rough estimate of the mean value 0 is 0 � 1:40922 03477 84529 82145 02895 25994:Observe that the extreme values of (u) are already knownfrom Coquet's work [Co84]:1:15470 � (u) � 1:60196 :Sketch of the proof. The proof runs along the same lines as theproof of Theorem 5; the only di�erence is that the computationof the Dirichlet generating function is slightly more involved thanin Section 6. We �rst prove an asymptotic formula for the doublesummatory functionT (N) = X1�n<N (S3(n) � 1) :

MELLIN TRANSFORMS AND ASYMPTOTICS: DIGITAL SUMS 27For this purpose we need some information on the function�0(s) = 1Xn=1 (�1)�(3n)(3n)s :Using the function F given by (7.2) that satis�es F (z) = (1 �z)F (z2), and setting�0(z) = 13 �F (z) + F (�z) + F (�2z)��1(z) = 13 �F (z) + �2F (�z) + �F (�2z)��2(s) = 13 �F (z) + �F (�z) + �2F (�2z)�we obtain the functional equations(7.3) �0(z) = �0(z2)� z�1(z2)�1(z) = �2(z2)� z�0(z2)�2(z) = �1(z2)� z�2(z2):Consider now the companion Dirichlet series �k, for k = 1; 2,de�ned in a way similar to �0, where summation runs through theother residue classes mod 3,�k(s) = 1Xn=0 (�1)�(3n+k)(3n + k)s for k = 1; 2.By Mellin transforms again, Eq. (2.2), we derive the alternativeexpressions,(7.4) �0(s) = 1�(s) 1Z0 ��0 �e�t�� 1� ts�1dt�k(s) = 1�(s) 1Z0 �k �e�t� ts�1dt for k = 1; 2.The image of the collection of functional equations (7.3) is thenthe system of equations(7.5)(1� 2�s) �0(s) + 2�s �1(s) = 2�sf1(s)2�s �0(s) + �1(s) � 2�s �2(s) = 2�sf0(s) �1� 2�s �1(s) + (1 + 2�s) �2(s) = 2�sf2(s);

28 P. FLAJOLET ET AL.where the functions fk are given byf0(s) = 1Xn=1(�1)�(3n)� 1(3n)s � 1(3n+ 12 )s�fk(s) = 1Xn=0(�1)�(3n+k)� 1(3n+ k)s � 1(3n+ k + 12 )s� for k = 1; 2.These functions are de�ned for <(s) > 0 and satisfy jfk(�+it)j �jtj1�� for 0 < � < 1, which can be shown using the same argu-ments as in Section 6.Solving (7.5) yields(7.6)�0(s) = 12s(4s � 3) (4s + 2s � (2s + 1) f0(s) + (4s + 2s � 1) f1(s) � f2(s)) :This equation provides us with the analytic continuation of �0 andshows that all poles of this function have to satisfy the equation4s = 3.After these preparations we can write using (2.4)(7.7) T (N) = N2�i 2+i1Z2�i1 3s�0(s)Ns dss(s + 1) :Shifting the line of integration to the left and taking residues intoaccount yields(7.8) T (N) = N�+1Xk2Z k�k + 1e2k�i log4N +O(N1+");where the term O(N1+") is obtained by trivial estimation of theintegral from "�i1 to "+i1 over the same integrand as in (7.7).Now using the exact formula due to Coquet and the adapt-ed version of Proposition 2 yields the Fourier expansion of thefunction . �Remark 5. The method employed above can also be used togather information on the summatory functionsXk<n(�1)�(3k+1); Xk<n(�1)�(5k)

MELLIN TRANSFORMS AND ASYMPTOTICS: DIGITAL SUMS 29and other functions of this type.Remark 6. The numerical estimates of the mean value con-stants throughout this paper were derived from in�nite functionalequations satis�ed by the corresponding Dirichlet series. Suchfunctional equations relate a Dirichlet series !(s) to its values!(s+1); !(s+2), etc. Since !(s+m) is easily evaluated numerical-ly for a large enough integerm (the series then reduces essentiallyto its �rst few terms), the functional equation can then be used tocompute backwards the values of !(s+m� 1), !(s+m� 2), etc,till !(s). Related in�nite functional equations are given in [AC85].The principles of such in�nite functional equations are wellknown in the case of the Riemann zeta functions (see pp. 273{276 of [La74]). Take for instance the problem of evaluating A(s)and B(s) de�ned in Section 6:A(s) = 1Xk=1 2�(k)ks and B(s) = 1Xk=1 2�(k)� 1(2k)s � 1(2k + 1)s� :First A(s) is related to B(s) by separating odd and even termsthen using the recurrence equations satis�ed by the coe�cients,which leads to the equation obtained earlier, immediately be-fore (6.6): A(s) = 32sA(s) + 2� 2B(s):Now, B(s) can be rewritten asB(s) = 1Xk=1 2�(k)(2k)s �1� 1(1 + (2k)�1)s � :Using the binomial expansion of (1 + (2k)�1)�s, and regroupingterms, we getB(s) = 12s ��s1�A(s + 1)21 ��s2�A(s + 2)22 +�s3�A(s + 3)23 � � � � � :This is an in�nite functional equation for A(s) since B(s) is itselflinearly related to A(s).

30 P. FLAJOLET ET AL.In this way, all our constants can be evaluated to about 50 digitsof accuracy in just a few billion elementary operations|a matterof minutes|using computer algebra systems. (Our computationswere completed under the Maple system.)8. ConclusionArithmetic sequences related to binary representation systemshave often been studied by means of real variable methods. Wehave shown here that the classical methods of analytic numbertheory can be used instead in a variety of cases. The results ob-tained in this way are a priori asymptotic. They can be convertedinto exact formul� either when the associated Dirichlet series areof a simple enough form (sums of digits, block occurrences) orwhen they can be combined with direct elementary methods (oddbinomial coe�cients, triadic numbers). Fluctuations are then ob-tained directly as Fourier series.The analysis of divide{and{conquer recurrences by related tech-niques is pursued in a companion paper [FG92], which further ex-empli�es the usefulness of complex analytic methods in this rangeof problems. References[Al87] J.-P. Allouche, Automates �nis en th�eorie des nombres, Expos.Math. 5 (1987), 239{266.[AC85] J.-P. Allouche and H. Cohen, Dirichlet Series and Curious In�niteProducts, Bull. London Math. Soc. 17 (1985), 531{538.[AS92] J.-P. Allouche and J. Shallit, The Ring of k{regular Sequences,Theoretical Computer Science 98 (1992), 163{197.[Ap84] T.M. Apostol, Introduction to Analytic Number Theory, SpringerVerlag, Berlin-Heidelberg-New York, 1984.[BEM83] J. Brillhart, P. Erd}os and P. Morton, On Sums of Rudin-Shapirocoe�cients II, Paci�c J. Math. 107 (1983), 39{69.[BM78] J. Brillhart and P. Morton, �Uber Summen von Rudin-ShapiroschenKoe�zienten, Illinois J. Math. 22 (1978), 126{148.[Ca92] E. Cateland, Suites digitales et suites k{r�eguli�eres, Th�ese, Univer-sit�e de Bordeaux I, 1992.[Co83] J. Coquet, A Summation Formula Related to the Binary Digits,Invent. Math. 73 (1983), 107{115.[De75] H. Delange, Sur la fonction sommatoire de la fonction \Somme desChi�res", Enseignement Math.(2) 21 (1975), 31{47.

MELLIN TRANSFORMS AND ASYMPTOTICS: DIGITAL SUMS 31[Do50] G. Doetsch, Handbuch der Laplace Transformation, Birkh�auserVer-lag, Basel, 1950.[DT89] J.-M. Dumont and A. Thomas, Syst�emes de num�eration et fonc-tions fractales relatifs aux substitutions, Theoretical Computer Sci-ence 65 (1989), 153{169.[Fa85] K.J. Falconer, The Geometry of Fractal Sets, Cambridge UniversityPress, 1985.[FG92] P. Flajolet and M. Golin,Mellin Transforms and Asymptotics: TheMergesort Recurrence, INRIA Research Report 1612 (1992).[FR80] P. Flajolet and L. Ramshaw, A Note on Gray Code and Odd-EvenMerge, SIAM J. Comput. 9 (1980), 142{158.[FRV79] P. Flajolet, J.C. Raoult and J. Vuillemin, The Number of Regis-ters Required for Evaluating Arithmetic Expressions, TheoreticalComputer Science 9 (1979), 99{125.[FRS84] P. Flajolet, M. Regnier and R. Sedgewick, Some Uses of the MellinIntegral Transform in the Analysis of Algorithms, CombinatorialAlgorithms on Words (A. Apostolico and Z. Galil, eds.), SpringerVerlag, Berlin-Heidelberg, 1985.[GT91] P.J. Grabner and R.F. Tichy, �-Expansions, Linear Recurrencesand the Sum-of-Digits Function, Manuscripta Math. 70 (1991),311{324.[GKP89] R.L. Graham, D.E. Knuth and O. Patashnik, Concrete Mathemat-ics, Addison Wesley, 1989.[Ha77] H. Harborth, Number of Odd Binomial Coe�cients, Proc. Amer.Math. Soc. 62 (1977), 19{22.[Ki83] P. Kirschenhofer, Subblock Occurrences in the q-ary Representationof n, SIAM J. Alg. Discr. Meth. 4 (1983), 231{236.[KP84] P. Kirschenhofer and H. Prodinger, Subblock Occurrences in Posi-tional Number Systems and Gray Code Representation, J. Inf. Opt.Sci. 5 (1984), 29{42.[KPT85] P. Kirschenhofer, H. Prodinger and R.F. Tichy, �Uber die Zi�ern-summe nat�urlicher Zahlen und verwandte Probleme, Zahlentheo-retische Analysis, Lecture Notes 1114 (E. Hlawka, ed.), pp. 55{65.[Ko88] T.W. K}orner, Fourier Analysis, CambridgeUniversity Press, Cam-bridge, 1988.[La74] E. Landau, Handbuch der Lehre von der Verteilung der Primzahlen,Chelsea Publishing Company, 1974.[Ne69] D.J. Newman, On the Number of Binary Digits in a Multiple ofThree, Proc. Amer. Math. Soc. 21 (1969), 719{721.[OS89] A.H. Osbaldestin and P. Shiu, A correlated digital sum problemassociated with sums of three squares, Bull. London Math. Soc. 21(1989), 369{374.[Sch69] W. Schwarz,Einf�uhrung in Methoden und Ergebnisse der Primzahlthe-orie, Bibliographisches Institut, Mannheim, 1969.[Ste89] A.H. Stein, Exponential Sums of Digit Counting Functions, Th�eoriedes nombres, Comptes Rendus de la Conf�erence Internationale deTh�eorie des Nombres tenue �a l'Universit�e Laval en 1987 (J.M. DeKoninck et C. Levesque, eds.), de Gruyter, Berlin-New York, 1989.[Sto77] K.B. Stolarsky, Power and Exponential Sums of Digital Sums Re-lated to Binomial Coe�cient Parity, SIAM J. Appl. Math. 32(1977), 717{730.[WW27] E.T. Whittaker and G.N. Watson, A Course in Modern Analysis,Cambridge University Press, 1927.[Wo84] S.Wolfram, Geometry of binomial coe�cients, Amer.Math. Month-ly 91 (1984), 566{571.

32 P. FLAJOLET ET AL.[Wo89] R.Wong, Asymptotic Approximations of Integrals, Academic Press,San Diego, 1989.P. Flajolet, INRIA, Rocquencourt, 78150 Le Chesnay, FranceP. Kirschenhofer and H. Prodinger, Institut f�ur Algebra undDiskrete Mathematik, TU Wien, Wiedner Hauptstrasse 8{10, 1040Wien, AustriaP. Grabner and R. Tichy, Institut f�ur Mathematik, TU Graz,Steyrergasse 30, 8010 Graz, Austria