On the metric upper density of Birkhoff sums for irrational rotations

This article examines the value distribution of SN(f,α):=∑n=1Nf(nα) for almost every α where N∈N is ranging over a long interval and f is a 1-periodic function with discontinuities or logarithmic singularities at rational numbers. We show that for N in a set of positive upper density, the order of SN(f,α) is of Khintchine-type, unless the logarithmic singularity is symmetric. Additionally, we show the asymptotic sharpness of the Denjoy–Koksma inequality for such f, with applications in the theory of numerical integration. Our method also leads to a generalized form of the classical Borel–Bernstein Theorem that allows very general modularity conditions.


Introduction and main results
Let f : R → R be 1-periodic with [0,1) | f (x)| dx < ∞ and q ∈ R. In this article, the object of our interest is 1) f (x) dx, which is known as a Birkhoff sum of the irrational circle rotation. We consider the temporal value distribution along a single orbit of S N ( f , α, q), that is, we fix some initial point q and a rotation parameter α, and examine the value distribution of {S N ( f , α, q) : 1 ≤ N ≤ M }, as M → ∞ for (Lebesgue-) almost every α. Since the irrational rotation together with the Lebesgue measure is an ergodic system for all irrational α, Birkhoff's ergodic theorem implies that for 1-periodic f ∈ L 1 ([0, 1)) and almost every q, we have |S N ( f , α, q)| = o(N ). If the Fourier coefficients of f ∼ n∈Z c n e(nx) decay at rate c n = O(1/n 2 ) (which holds in particular for f ∈ C 2 ), then S N ( f , α, q) is bounded for almost every α and all q ∈ R (see [15,20]). Thus, the interesting functions to consider are the functions that lack smoothness, in particular functions that have discontinuities or singularities.
In this article, we examine S N ( f , α, q) where q ∈ Q and all non-smooth points of f lie at rational numbers. The first class of functions we define is the following (compare to, e.g., [14,15]). Definition 1.1 (Piecewise smooth functions with rational discontinuities). We call a 1-periodic function f : R → R a piecewise smooth function with rational discontinuities if there exist ν ≥ 1 and 0 ≤ x 1 < . . . < x ν < 1 with x i ∈ Q, 1 ≤ i ≤ ν such that the following properties hold: • f is differentiable on [0, 1) \ {x 1 , . . . , x ν }. These functions are not only of interest in Discrepancy theory (see [7,8,33]), but are closely related to the theory of "deterministic random walks" (see, e.g., [1,6]). For these local discrepancy functions, a classical theorem of Kesten [25] shows that |S N ( f , α, q)| is unbounded, since b − a ∉ Z + αZ for irrational α. In addition to considering essentially smooth f , we also examine functions with logarithmic singularities at rational numbers, a class of functions that falls in the framework considered in [13].

Definition 1.2 (Smooth functions with rational logarithmic singularity).
We call a 1-periodic function f : R → R with [0,1) f (x) dx = 0 a smooth function with rational logarithmic singularity if there exist constants c 1 , c 2 ∈ R, a 1-periodic function t : R → R with bounded variation on [0, 1) and x 1 ∈ Q such that Here and throughout the paper, {.} denotes the fractional part and . denotes the distance to the nearest integer (for a proper definition see Section 2.1). If c 2 = 0 and c 1 = 0, we call the singularity symmetric. If c 2 = 0, we call it asymmetric.
We examine the maximal and typical oscillations of S N ( f , α, q) for Lebesgue almost every α where q ∈ Q and f is either of the form as in Definition 1.1 or Definition 1.2. Our methods give rise to results in two different directions that are elaborated in detail below.

Khintchine-type upper density results
Let us recall the classical Khintchine Theorem from the metric theory of Diophantine approximation. If (ψ(q)) q∈N is a non-negative sequence, and qψ(q) is decreasing, then for almost all α, the inequality has infinitely many integer solutions (p, q) ∈ Z × N if and only if ∞ k=1 1 ψ(k) diverges. Such a convergence-divergence criterion, often called Khintchine-type result, appears in many different statements that deal with the metric theory of Diophantine approximation and the closely related theory of continued fractions. Classical results of this form are, among others, the Borel -Bernstein Theorem (see Section 2) and another theorem of Khintchine [26] on the discrepancy of the Kronecker sequence. Recall that the discrepancy of a sequence (x n ) n∈N in the unit interval is defined as By [26], for an increasing function ψ : R + → R + , one has D N ((nα) n∈N ) ≫ ψ(log N ) + log N log log N infinitely often if and only if ∞ k=1 1 ψ(k) = ∞. Such a Khintchine-type behaviour was also discovered for a certain Birkhoff sum arising from the logarithm of the Sudler product N r =1 2|sin(πr α)|. The analysis of this product led to many interesting developments in various areas in mathematics in the last decades, see, e.g., [2,3,4,5,18,28,30]. Lubinsky [29] showed that if f (x) = log (2 |sin(πx)|), then, for almost every α and every monotone increasing ψ : R + → R + with lim inf k→∞ ψ(k) k logk = ∞, the inequalities hold for infinitely many N , if and only if ∞ k=1 1 ψ(k) = ∞. This result was refined by Borda [10] in the following way: Recall that for a set of integers A ⊆ N, we define its upper density to be lim sup M→∞ where A M := {N ≤ M : N ∈ A}. It was shown in [10] that in the diverging case, both inequalities (1) hold on a set of positive upper density. This was further improved in [19], where it was shown that the actual upper density equals 1. Note that f (x) = log (2 |sin(πx)|) does have a single symmetric logarithmic singularity at 0. As pointed out in [13], the behaviour of Birkhoff sums with f having a symmetric logarithmic singularity is expected to be similar to f being as in Definition 1.1, since the decay of the Fourier coefficients is of the same order. Our first theorem supports this expected behaviour as we obtain a Khintchine-type result on the upper density of the same form for piecewise smooth functions with rational discontinuities. Theorem 1. Let ψ : R + → R + be a monotone increasing function, f a function as in Definition 1.1,i.e. f is smooth up to finitely many discontinuities 0 ≤ x 1 < . . . < x ν < 1 at rationals, and q ∈ Q. If ∞ k=1 1 ψ(k) = ∞, then, for almost all α ∈ [0, 1), both sets have positive upper density.
Theorem 1 shows the following interesting behaviour: Let ψ be monotonically increasing and lim inf k→∞ As soon as there are infinitely many N ∈ N such that |S N ( f , α, q)| ≥ ψ(log N ), then immediately a "positive proportion" of all natural numbers satisfies this property.
In Section 3, we prove Theorem 7, which is a slightly stronger result than Theorem 1. It turns out that for many classical functions that fall in the framework of Definition 1.1, the sets (2) have actually upper density 1. • The local discrepancy functions with rational endpoints f (x) = 1 [a,b] ({x})−(b − a). In particular, this means that the set N ∈ N : D N ((nα) n∈N ) ≥ ψ(log N ) has upper density 1, improving the result in [26].
Naturally, the question arises whether a similar behaviour can be expected for functions with logarithmic singularities. Note that in many applications (see for example [16] and the references therein), one is not only interested in symmetric, but also asymmetric singularities. In the next statement we show that for functions f with an asymmetric singularity, there is an analogue of Theorem 1 with an additional scaling factor of log N .
Theorem 3. Let f be as in Definition 1.2. Then, for any non-decreasing ψ : R + → R + and for any q ∈ Q, the following holds: (i) If the logarithmic singularity is asymmetric and ∞ k=1 1 ψ(k) = ∞, then, for almost every α ∈ [0, 1), we have that both sets (ii) If the logarithmic singularity is symmetric, then for almost every α ∈ [0, 1), we have Theorem 3 shows the surprising fact that one should expect a completely different oscillation between the Birkhoff sums of functions with symmetric and asymmetric singularity. To see this, we note that ψ : ψ(k) = ∞ and thus, for a function f with an asymmetric logarithmic singularity, the sets in (3) have upper density 1. However, the same sets are finite if the underlying Birkhoff sum is generated by a function g with symmetric logarithmic singularity. This is because Theorem 3 (ii) tells us that

Remark 1.3.
• One can clearly see from the proof of Theorem 3(i) that it is possible to generalize the result to is a smooth function with asymmetric singularity at a rational number x 1 , f 2 is a smooth function with finitely many symmetric logarithmic singularities at rational numbers x 2 , x 3 , . . . , x n and f 3 is a piecewise smooth function with finitely many discontinuities.
• The actual maximal oscillation of Birkhoff sums with a symmetric logarithmic singularity for generic α remains open. Using [10,Proposition 12], the result of [29] and f being a smooth 1-periodic function with its symmetric logarithmic singularity located at 0, we have that, for almost every α ∈ [0, 1), |S N ( f , α, 0)| ≪ ψ(log N )+log N log log N for any monotone ψ with ∞ k=1 1 ψ(k) < ∞. Most probably, the bound (log N ) 2 log log N is not sharp for logarithmic singularities that are located at arbitrary rationals. We did not aim to achieve the best possible bound, but wanted to stress the different behaviour of symmetric and asymmetric logarithmic singularities. Possibly, the upper bound for the Birkhoff sum with symmetric logarithmic singularity coincides with the Khintchine-type behaviour in Theorem 1. A proof of this would probably need to make use of delicate estimates on shifted cotangent sums and is beyond the scope of this paper.

Sharpness of the Denjoy-Koksma inequality
Recall the classical Denjoy-Koksma inequality (see, e.g., [20]): Let α be fixed and let p n /q n denote its n-th convergent. If f is a 1-periodic function of bounded variation Var( f ) on [0, 1), then, for any q ∈ R, b i q i being its Ostrowski expansion (see Section 2.2 for details), we immediately obtain the bound where α = [0; a 1 , a 2 , . . .] is the classical continued fraction expansion and K (N ) denotes the integer K such that q K −1 ≤ N < q K . It is natural to ask whether (4) is sharp for particular functions f . This was essentially already proven in [26] for both the classical saw-tooth function {x} − 1/2 and the local : for almost every α, there are infinitely many N where (4) can be reverted up to an absolute positive constant. However, to the best of our knowledge, all results in this direction only show that this bound is essentially obtained for infinitely many N , but there is no statement about the frequency of those N . This is shown in the following Theorem.
Theorem 4. Let f be a function with finitely many discontinuities at rationals (see Definition 1.1) and let q ∈ Q. For fixed α and N ∈ N, let K (N ) denote the integer K such that q K −1 ≤ N < q K . Then, for almost all α ∈ [0, 1), both sets have positive upper density. The implied constants depend on α, f and q.
Analogously to Corollary 2, the following stronger version of Theorem 4 can be obtained.
we have the following: For almost all α ∈ [0, 1) and any 0 < r < 1, there exists a constant C (r ) = C (r, f , q) > 0 such that both sets Theorem 4 has consequences in the theory of numerical integration: Assuming that there are functions f such that the bound (4) is attained only along a very sparse subsequence (N k ) k∈N , one could hope with a randomized approach to hit this sequence very rarely. Then, one could generate by some (randomized) algorithm an increasing sequence of integers (M j ) j ∈N and consider an irrational α drawn uniformly at random from the unit interval. With high probability, one would expect a i . Theorem 4 implies that such an approach will most likely fail. It shows that, almost surely, a positive proportion of those M j satisfies This implies that every low-discrepancy sequence (such as the Kronecker sequences ({nα}) n∈N where α is badly approximable) gives a better error bound in numerical integration, regardless of the support of the function f and the chosen algorithm to generate the sequence (M j ) j ∈N .
Next, assume that f has a singularity, but is still integrable. The singularity makes an application of the classical Denjoy-Koksma inequality impossible since the variation of f is not bounded. However, we can still get a nontrivial bound on S N ( f , α, q) provided that the orbit {q+nα : 1 ≤ n ≤ N } stays away from the singularity. Proposition 1.5 (Denjoy-Koksma inequality with singularity). Let N ∈ N, q ∈ [0, 1) arbitrary and let In particular, we have, for K ∈ N, This bound is not new but was used already in, e.g., [21,22,27]. The statement follows immediately by definingf and applying the classical Denjoy-Koksma inequality (4) tof .
The following theorem shows that for asymmetric logarithmic singularities, the estimate (5) is also sharp in the sense of Theorem 4, which in particular extends the consequences for numerical integration to functions with an asymmetric logarithmic singularity.
Theorem 6. Let f be a 1-periodic smooth function with rational asymmetric logarithmic singularity in x 1 as in Definition 1.2. For fixed α ∈ [0, 1), q ∈ Q and N ∈ N, we denote by K (N ) the integer K such that q K −1 ≤ N < q K . Further, let A N = x 1 − g (N ), x 1 + g (N ) be an interval with g (N ) = min n≤N nα + q − x 1 . Then, for almost all α ∈ [0, 1) and any 0 < r < 1, there exists a constant C (r ) = C (r, f , q) > 0 such that both sets have upper density of at least r .

Notation
Given two functions f , g : |g (t )| < ∞. Any dependence of the value of the limes superior above on potential parameters is denoted by appropriate subscripts. For two sequences (a k ) k∈N and (b k ) k∈N with b k = 0 for all k ∈ N, we write a k ∼ b k , k → ∞, if lim k→∞ a k b k = 1. Given a real number x ∈ R, we write {x} = x − ⌊x⌋ for the fractional part of x and x = min{|x − k| : k ∈ Z} for the distance of x to its nearest integer. We denote the characteristic function of a set A by 1 A and understand the value of empty sums as 0. We denote the cardinality of a set A ⊆ N as |A|. For shorter notation, we write S N ( f , α) := S N ( f , α, 0). Let σ X 1 , X 2 , . . . denote the σ-algebra generated by random variables X 1 , X 2 , . . ..

Continued fractions
In this subsection, we collect all classical results from the theory of continued fractions that we need to prove our main results. Every irrational α ∈ R has a unique infinite continued fraction expansion denoted by [a 0 ; a 1 , a 2 , . . . ] with convergents p k /q k := [a 0 ; a 1 , . . . , a k ] that satisfy the recursions with initial values p 0 = a 0 , p 1 = a 1 a 0 + 1, q 0 = 1, q 1 = a 1 . For the sake of brevity, we just write a k , p k , q k , although these quantities depend on α. We know that p k /q k are good approximations for α and satisfy the inequalities Fixing an irrational α, the Ostrowski expansion of a non-negative integer N is the unique representation So far all statements can be made for arbitrary irrational numbers, but since this article considers the almost sure behaviour, we make use of the well-studied area of the metric theory of continued fractions. We state several classical results below which hold for almost every α ∈ R. We will use them frequently in the proofs of our results.

Functions with discontinuities
We start this section with a decomposition lemma that is of a similar form to [15, Appendix A].
By the choice of f , there exists a function ψ that is differentiable with ψ ′ being of bounded variation [15]). Since α is irrational and q ∈ Q, we have ψ(nα + q) = ϕ(nα + q) for any n ∈ N and thus, which proves the first part of the statement. For the second part, one sees immediately that ν i =1 A i is invariant under translation. By a slightly longer, but elementary calculation, one finds that under the assumption of ν The definition of the quantities A i , c i in Lemma 3.1 allows us to state stronger, but more technically involved versions of Theorem 1 respectively Theorem 4. This refinement will also immediately imply Corollary 2 and Corollary 5.

Theorem 7.
Let ψ : R + → R + be a monotonically increasing function with ∞ k=1 1 ψ(k) = ∞ and let f : R → R be as in Definition 1.1, i.e. f is essentially smooth with (possible) discontinuities at finitely many have upper density 1.
for almost all α ∈ [0, 1) and all q ∈ Q, both sets in (10) have positive upper density.
for almost all α ∈ [0, 1) and all q ∈ Q, we have the following: have upper density of at least r 0 .
Naturally, the question arises whether the conditions ν give an exact characterization of functions that satisfy the statements in Theorem 7 and Theorem 8. We show that these assumptions are not necessary, but without any condition on the interplay of the location of the discontinuities and their jump heights, one cannot hope to achieve upper density 1. In fact, we provide two classes of functions that, in general, do not satisfy ν both have upper density 1 for any q ∈ Q. However for the other class of functions, this fails to hold. The proofs of both these statements (Proposition 3.2 and Proposition 3.4) can be found in the Appendix.
Theorem 7 (and hence Theorem 1) only shows that the sets in (2) have positive upper density. Proposition 3.2 shows that we have indeed upper density 1 meaning that the assumptions in Theorem 7 are not sharp.
The following proposition shows that there are functions of the form as in Definition 1.1 where the sets in (2) do not have upper density 1.
Then, there exists a monotone increasing function ψ : has upper density of at most 1 − δ.

Proof of Theorem 1, Theorem 4, Corollary 2 and Corollary 5. Corollary 2 follows immediately from Theorem 7 since all functions considered in Corollary 2 satisfy
Thus, (6) implies that, for sufficiently large N , we have a K 0 ≤ψ(K 0 ). Moreover, by (7) there exists an absolute constantc > 0 such that K (N ) where we choose c 1 and c 2 such that

Heuristic of the proofs
We will briefly line out the main ideas of the proof of Theorems 7 and 8. One of the core tools we are using is the well-known result in metric number theory that for almost every α ∈ [0, 1), there are infinitely many K ∈ N such that a K dominates the sum of the preceding partial quotients, that is Here, K will always satisfy this property. For q K −1 < N < q K and N = b K −1 q K + N ′ , N ′ < q K −1 , we first get rid of S N ′ ( f , α) by an application of the Denjoy-Koksma inequality. The rest of the proof is to show that essentially S b K −1 q K −1 ( f , α) ≫ a K for most N , which then implies morally both Theorems 7 and 8 by an application of the Borel-Bernstein Theorem. As {nα} q K −1 n=1 is close to being uniformly distributed in the unit interval, it is natural to analyze with d > 0, provided that q K −1 satisfies some congruence relation that depends on the location of the discontinuities (Lemma 3. Letting δ → 0, we see that the desired inequality holds on a proportion of at least c−c ′ c many elements among {1, . . . , c a K }. By a refinement of the Borel-Bernstein Theorem, we ensure that there are infinitely many odd respectively even K that both satisfy K −1 i =1 a i = o(a K ) and this certain congruence relation on q K −1 . Thus, we obtain the positive upper density by considering the subsequence c a K where the K are chosen out of this infinite set, giving upper density of at least c−c ′ c > 0. Under the assumptions it is possible to prove that we can choose in the above discussion c ′ = 0 (Lemma 3.7), which leads to the result with upper density 1.

Preparatory Lemmas
Before we come to the proof of Theorems 7 and 8, we need a few auxiliary results. The first lemma treats the sawtooth function, which in view of Lemma 3.1 is a building block for the decomposition of f .
Proof. We only consider the case where K is odd since the other case can be treated analogously. We thus have 1 Since q K = a K q K −1 + q K −2 , we get the asymptotic expression In the second last line we used that δ K −1 = 1 q K −1 a K (1+ε K ) and we employed n ≤ q K −1 in the inner summation. Further, we used that gcd(p K −1 , q K −1 ) = 1 and hence the remainders of np K −1 modulo q K −1 are precisely the integers n = 0, . . . , q K −1 − 1. Finally, we omitted the fractional part {·}, since where we also made use of the estimate b ≤ a K .
The next lemma treats the local discrepancy function, which in view of Lemma 3.1 is also a building block for the decomposition of f .
be fixed and let both k ∈ N and a k be sufficiently large.
Proof. We show the statement only in the case where k is odd and s 1 |q k−1 and s 2 ∤ q k−1 . The other cases can be treated analogously. Thus, we need to show that In the following, we use that for odd k, where m(n) := p k−1 n mod q k−1 and we used that p k−1 and q k−1 are coprime in the last line. Let ε n := m(n) (1)) . Using s 1 | q k−1 and ε n ≥ 0, we see that the smallest integer n with 0 ≤ n ≤ q k−1 − 1 such that n q k−1 + ε n ≥ r 1 is sufficiently large, where also 1 + o a k (1) is close to 1), we have that the largest integer n with 0 ≤ n ≤ This means, the number of integers 0 ≤ n ≤ q k−1 − 1 such that n q k−1 +ε n ∈ r 1 s 1 , r 2 s 2 is equal to r 2 This implies that S bq k−1 ( f , α) = b 1 − s 2 r 2 q k−1 , as claimed.
Then, there exist constants c, c ′ > 0, and integers α j , β j , γ j , δ j , j = 1, 2 (depending on f ) such that the following holds: • If K ≡ α 1 (mod β 1 ), q K −1 ≡ γ 1 (mod δ 1 ), then for any integer b with 0 ≤ b ≤ c a K , we have for sufficiently large K and a K , • If K ≡ α 2 (mod β 2 ), q K −1 ≡ γ 2 (mod δ 2 ), then for any integer b with 0 ≤ b ≤ c a K , we have have for sufficiently large K and a K , Proof. We only prove (13), the inequality (14) can be shown analogously. First, assume that ν We set c := 1 4s 1 ···s ν and choose α 1 := 1, β 1 := 2, γ 1 := 0 and δ 1 := s 1 · · · s ν . Assume that K ∈ N satisfies K ≡ α 1 (mod β 1 ) and q K −1 ≡ γ 1 (mod δ 1 ). By Lemma 3.1, we can write g ( , where we set x 0 := 0. This leads to By Lemma 3.6, the second sum above is equal to 0. Since K − 1 is even, we get by Lemma 3.5 We define c ′ := 1 which is a positive constant, since c < 1. This finishes the proof in This implies ν ≥ 2 and we assume without loss of generality with gcd(r i , s i ) = 1 for i = 0, . . . , ν. We choose α 1 = 0, β 1 = 2, γ 1 = s 1 · · · s ν − 1 and δ 1 = s 1 · · · s ν (we note that s 1 · · · s ν ≥ 2). Let K ∈ N such that K ≡ α 1 (mod β 1 ), q K −1 ≡ γ 1 (mod δ 1 ) and define c := 1 4s 1 ···s ν . Then, for 0 ≤ b ≤ c a K , we get In the last line, we applied Lemma 3.6 and used that s i ∤ q K −1 for every i = 1, . . . , ν. By the choice of γ 1 and δ 1 , we have q K −1 ≡ −1 (mod s i ) for all i = 1, . . . , ν and therefore By now defining Next, we consider the analogue of the previous lemma in the case ν Then, there exist constants c, c ′ , d > 0 with c ′ < c and integers α j , β j , γ j , δ j , j = 1, 2 (all depending on f ) such that the following holds: • If K ≡ α 2 (mod β 2 ), q K −1 ≡ γ 2 (mod δ 2 ), then for c ′ a K ≤ b ≤ c a K , we have for sufficiently large K and a K S bq Proof. We only show (15), since (16) can be shown analogously. By assumption c 1 = ν i =1 A i = 0, thus there exist at least two A i = 0. To keep notation simple we assume A 1 = 0 and thus c 2 = ν i =2 A i = 0. We assume c 2 > 0 and note that the case where c 2 < 0 can be handled similarly. Let x i = r i s i for all i = 0, . . . , ν. We choose α 1 = 1, β 1 = 2, γ 1 = 1 and δ 1 = s 1 · · · s ν . We take K ∈ N with K ≡ α 1 (mod β 1 ), q K −1 ≡ γ 1 (mod δ 1 ) and a K > Starting with the case i ≥ 3, we observe that where we used that, for i ≥ 3, we have x i > x 2 and thus, the largest integer n such that n recall that the s i denote the denominators of the rationals x i ) and thus, in case of i ≥ 3, we have shown that holds for any 0 ≤ u ≤ b − 1. For the case i = 1, a similar argument as before shows that for any Now we turn our attention to the case of i = 2, where we establish a slightly different lower bound for 1 ≤ n ≤ q K −1 : {nα + uq K −1 α} ∈ [x 1 , x 2 ] . First, we consider those u with 0 ≤ u < x 1 a K (1 + ε). We choose ε > 0 small enough such that x 1 (1 + 4ε) < x 2 . In that case, we get the same lower bound as before, i.e., we establish 1 ≤ n ≤ q K −1 : have that for any 1 ≤ n ≤ q K −1 , . Further, we use that 1+ε 1+o a K (1) ≥ 1 if K is sufficiently large and hence x 1 q K −1 ≤ ε n . This gives us the estimate Here we used gcd(p K −1 , q K −1 ) = 1 which implies that np K −1 runs through all remainder classes modulo q K −1 . The smallest 0 ≤ n ≤ q K −1 −1 such that n q K −1 + , which follows from the congruence relation satisfied by q K −1 . The largest n such that n Now we can combine all the estimates we obtained before, in order to get We used the overall assumption of ν i =1 c i (x i −x i −1 ) = 0 and −2 ≥ −c 2 a K ε, since a K is large. The proof is now finished by defining d := c 2

Refining the Borel-Bernstein Theorem
We see that Lemma 3.7 and Lemma 3.8 give us lower bounds on Birkhoff sums, provided that a K does not only dominate the sum of the preceding partial quotients, but both K and q K −1 additionally satisfy certain modularity conditions. Without having to satisfy these extra conditions, the existence of infinitely many such a K for generic α could be deduced from a combination of the Borel-Bernstein Theorem and the estimate (7) on the trimmed sum of partial quotients. The aim of this section is to establish a version of the Borel-Bernstein Theorem (Lemma 3.12) that allows to include additional assumptions on K and q K −1 . We make use of some known auxiliary results that are stated for the reader's convenience in full detail below. and λ ∈ (0, 1) such that

Lemma 3.9. (Lemma C in [17]) Let (Ω, F , P) be a probability space with events (A n ) n∈N such that
Remark 3.11. In [23], the quantity k from Lemma 3.10 is not given explicitly. The fact that all pairs (u 1 , u 2 ) with gcd(u 1 , u 2 , v) = 1 are admissible and thus k(v) can be defined as in Lemma 3.10 follows from [24]. The decay rate of (17) was improved in [35] to be exponential, that is of the form C λ p .

Lemma 3.12. Let ψ : R + → R + be a monotonically increasing function such that
Remark 3.13. In particular, Bernstein's Theorem can be strengthened in the following way: For any monotonic increasing function ψ : R + → R + and any positive integers a, b, c, d we have, for almost every α ∈ [0, 1),

The method of proof even allows replacing the condition K ≡ a (mod b) with a condition of the form K ∈ A ⊆ N, where A has positive lower density. For our purpose the given version is sufficient.
Proof. We first show that for almost every α ∈ [0, 1), the set K ∈ N | K ≡ a (mod b), ψ(K ) < a K < K 2 has infinite cardinality. We can assume without loss of generality that lim inf K →∞

ψ(K )
K logK = ∞ since the result then also follows for all slower growing ψ. Now we definẽ Since ψ is monotone, we have that ∞ ∞ . By (6), there exist infinitely many K such that a K >ψ(K ). Again by (6), there are only finitely many K ∈ N such that a K > K 2 and thus, we can conclude that there are infinitely many K ∈ N with K ≡ a (mod b) and ψ(K ) < a K < K 2 . Now we introduce the sets In the following, we show that Lemma 3.9 can be applied to the sequence of sets (A K ) K ∈N . To that end, we define k = {0 ≤ u 1 , u 2 ≤ d − 1 | gcd(u 1 , u 2 , d ) = 1} and we note that E K only depends on a K . Further, we will denote the 1-dimensional Lebesgue measure on [0, 1) by P. Using Lemma 3.10, we get with λ ∈ (0, 1). This gives us ∞ K =1 P [A K ] = ∞, since there exist infinitely many K ∈ N such that P[E K ] = 1 by the first part of this proof. This shows the first assumption in Lemma 3.9, i.e. ∞ K =1 P[A K ] = ∞. Now we take K , L ∈ N with L + 1 ≤ K and consider where we employed Lemma 3.10 and used the estimate from (18) in the last line. We fix N ∈ N sufficiently large and consider Next, we obtain an upper bound for two of the sums in (19). First, we get where we used that λ ∈ (0, 1). Moreover, we get and thus, we have For the equality in the previous equation, we used that ∞ K =1 P[A K ] = ∞. In total, we have shown that Lemma 3.9 now gives us that P lim sup K →∞ A K = 1 or, in other words, for almost all α ∈ [0, 1), there are infinitely many K ∈ N such that ψ(K ) < a K < K 2 , K ≡ a (mod b) and q K −1 ≡ c (mod d ).
For K sufficiently large, we have ψ(K ) > K logK log (2) , so (7) shows that max ℓ≤K −1 a ℓ < a K and thus, applying (7) again leads to We have now all ingredients to turn our attention to the proofs of Theorem 7 and Theorem 8.

Proofs of Theorem 7 and Theorem 8
Note that the class of functions considered in both Theorems 7 and 8 is closed under translation by rational numbers, and by Lemma 3.1 the same holds for the condition ν Thus, we can assume without loss of generality that q = 0. Moreover, we can assume that lim K →∞ ψ(K ) K logK = ∞ since the result then follows also for slower growing ψ.
Let c, c ′ , α 1 , β 1 , γ 1 , δ 1 be as in Lemma 3.7. By Lemma 3.12, for almost every α, there exist infinitely many K such that whereψ(k) = C 1 ψ(C 2 k) with C 1 ,C 2 > 0 specified later. Denote by (k j ) j ∈N the increasing sequence of integers such that the above holds. Now let N ≤ c a k j q k j −1 be arbitrary. Thus, we can write where we used Lemma 3.7 and the Denjoy-Koksma inequality in the last line. Let M j := ⌊c a k j q k j −1 ⌋ and, for δ > 0, we define the set A δ j : Thus, fixing ε > 0, we can choose δ > 0 such that We note that C 1 ,C 2 only depend on δ > 0, since k j is chosen such that By taking the limes inferior as j → ∞ and letting ε → 0, we get This shows the claimed upper density 1 in Theorem 7 for the set In order to prove the first part of Theorem 8, let 0 < r < 1 be fixed. Choosing δ = δ(r ) sufficiently small such that By choosing C (r ) := c ′ δ 2 , the first statement of Theorem 8 follows, since the sequence (k j ) j ∈N is chosen such that a k j dominates N ) has positive upper density. Let c, c ′ , d , α 1 , β 1 , γ 1 , δ 1 be as in Lemma 3.8. By Lemma 3.12, there are infinitely many K such that

Now we prove the remaining parts of Theorem 7, where we need to show that if
Denote by (k j ) j ∈N the increasing sequence of integers such that the above holds. Now let N ∈ N with c ′ a k j q k j ≤ N ≤ c a k j q k j be arbitrary. Thus, we can write N = b k j −1 q k j −1 + N ′ where N ′ < q k j −1 and c a k j ≤ b k j −1 ≤ a k j . Arguing as in (20), we obtain by Lemma 3.8 Let M j := ⌊c a k j q k j −1 ⌋ and A j : We note that there exists r 0 > 0 such that |A j | M j ≥ r 0 > 0 for all sufficiently large j ∈ N. Similar to the first part of this proof, we get By taking the liminf as j → ∞, we obtain This shows the claimed positive upper density in Theorem 7 for the set To prove the second statement of Theorem 8, we see that, for N ∈ A j , by (21)

Functions with logarithmic singularities 4.1 Heuristic of the proofs
We will briefly line out the main ideas of the proof of Theorems 3 and Theorem 6. Again, we are using that, for almost every α ∈ [0, 1), K −1 i =1 a i = o(a K ) for infinitely many K ∈ N. Here, K will always satisfy this property. For q K −1 < N < q K and N = b K −1 q k + N ′ , N ′ < q K −1 , we get rid of S N ′ (. . .) by an application of the Denjoy-Koksma inequality with singularity (5). We make sure to stay away from the singularity x 1 = r s by the fact that if N α− r s is small, then so is sN α (Proposition 4.2). Thus, we can morally work with the homogeneous case of Diophantine approximation and the corresponding metric theory gives sufficient estimates. Again, we analyze In the asymmetric case, we see that f (x) = log{x} is monotonically increasing on [0, 1). Comparing a K is decisive and, for some c, d > 0 and b a K ∈ [0, c], this leads to an estimate (see Lemma 4.4) of the form Then the proof can be concluded similarly to the proof of Theorem 7.
In the symmetric case f (x) = log x , we see that, for j So, the terms f f (x) dx are of opposite sign and lead to some cancellation (Lemma 4.5). This cancellation is responsible for the different behaviour of symmetric and asymmetric singularities.

Asymmetric logarithmic singularities
with the implied constant being absolute, independent of ε j .
Proof. For j ≥ 1, we have So, we obtain By the Taylor expansion log(1 For j = 0, we get q ℓ 1/q ℓ 0 log(x) dx = − log(q ℓ ) − 1 and thus, Combining the obtained estimates yields Proof. Assume to the contrary that N α − r s ≤ q K +1 α s . Then, we have Since sN < q K +1 , this is a contradiction to the best approximation property of q K +1 : There would exist an integer N ′ < q K +1 such that q K −1 N ′ α ≤ q K +1 α .

Proposition 4.3. (Error term estimate for a rational shift)
all n ≤ N ′ . Thus, the Denjoy-Koksma inequality with singularity (Proposition 1.5) yields . Further, let K ∈ N with q K −1 ≡ 0 (mod s) and choose N ∈ N with q K −1 < N < q K and δa K < b K −1 (N ) < a K 4 . Then, if a K is sufficiently large, we get Proof. By definition, we have We introduced n ′ := q q K −1 which is an integer since s|q K −1 with 0 ≤ n ′ ≤ q K −1 − 1. Now observe that δ K −1 > 0 by definition and since b q K −1 < a K 4 , we have bq K −1 + n ≤ b q K −1 q K −1 ≤ (1/2 − δ)a K q K −1 . Thus, for any 0 ≤ n ≤ q K −1 − 1, we get where we used that q K −1 δ K −1 ≤ 1/a K . First, we assume that K is odd implying (−1) K −1 = 1. We apply We used that ε 0 ≤ 1 4 < 1 and hence log(ε 0 ) ≤ 0. Moreover, we applied the rough estimate O(1) ≤ 1 8 log(q K −1 ). By summing over all b = 0, . . . , b K −1 − 1, we obtain where we also used the assumption b K −1 ≥ δa K . By rewriting, we finally get as claimed. Now let K be even. We apply Proposition 4.1 with x n = n for 1 ≤ n ≤ q K −1 − 1 and ε 0 = 1 − ε b,qq K −1 . Similar to before, we obtain This finishes the proof. Proof. Writing N = K −1 ℓ=0 b ℓ q ℓ in its Ostrowski expansion with b K −1 = 0, we obtain the decomposition

Symmetric logarithmic singularities
By the Denjoy-Koksma inequality with singularity (see (5) in Proposition 1.5), we can bound S N ′ ( f , α) by where we have used that log(q K ) ≪ K by (8) and we used Proposition 4.

A simple calculation reveals
where we used that min n<q K nα − q ≤ 1 q K and log min n≤q K nα − q ≪ K , as shown before. In total, we get where the estimate in the last line uses (7). Analogously, one obtains the same bound for We are now left with By definition, we have We first assume that K 0 is odd. We can write N ′ α − r s = m q K 0 −1 + r ′ q K 0 −1 where m ∈ Z and 0 ≤ r ′ < 1. We observe that, for any 0 ≤ b ≤ b K 0 −1 , we have 0 ≤ bq K 0 −1 δ K 0 −1 + r ′ < 2. For the following analysis, we define the quantity d b := bq K 0 −1 δ K 0 −1 + r ′ and the sets B 1 , B 2 , B 3 as We first assume b ∈ B 1 , i.e. d b+1 < 1. We see that, for all n = 1, . . . , q K 0 −1 , we have Since p K 0 −1 and q K 0 −1 are coprime, the map j (n) = np K 0 −1 + m (mod q K 0 −1 ) is bijective with inverse n( j ). Thus, we can introduce the quantities Since d b + n( j )δ K 0 −1 ≤ d b+1 < 1 by assumption, it holds that 0 ≤ y j < 1 for all j = 0, . . . , q K 0 −1 − 1. Further, we have the following equality of sets The previous arguments reveal that, for b ∈ B 1 , we can write where we set I j := q K 0 −1 In the following, we will compare the value of log y j to the value of I j for all j = 0, . . . , q K 0 −1 − 1. We start with the case where 1 ≤ j ≤ ⌊q K 0 −1 /2⌋ − 1. Then, we have y j = y j and y q K 0 −1 − j −1 = 1 − y q K 0 −1 − j −1 . This leads to By the Taylor expansion log(1 By the same arguments, we obtain So, by combining the two previous estimates, we get In the last line, we used the estimate . It is easy to see that since the number of summands on the left-hand side is bounded by a constant and the y j are bounded away from 0 and 1. Thus, we have shown that We are now left with the cases j = 0 and j = q K 0 −1 − 1, where we get We discuss here the first term |log(d b + n(0)δ K 0 −1 )| in detail, the second term can be treated analogously. Observe that d b + n(0)δ K 0 −1 = q K 0 −1 (N ′ + bq K 0 −1 + n(0))α − r s ) by construction of y 0 . We claim that there exists at most one b ′ ∈ B 1 such that Assume to the contrary that there are two integers b ′ , b ′′ ∈ B 1 with b ′ = b ′′ such that both satisfy this estimate. Then, we get by the triangle inequality, which is an immediate contradiction to the best approximation property of q K 0 −1 . Thus, for the only possible b ′ ∈ B 1 , we get where the estimate in the second last step can be argued analogously to (22). For all b ∈ B 1 with b = b ′ , we have Thus, by combining the estimates we obtained, we get b∈B 1 Here we used that |B 1 | ≤ b K 0 −1 ≤ a K 0 , log q K +s+1 ≪ K by (8) and by (6), a K 0 ≤ K 2 if K is sufficiently large. For the set B 2 , a similar analysis leads to the same asymptotic bound, i.e., we get b∈B 2 The set B 3 contains at most 1 elementb ∈ {0, . . . , b K 0 −1 − 1} and thus, we can write b∈B 3 Applying the Denjoy-Koksma inequality with singularity in the form of (5), we obtain as we did for S N ′ ( f , α) at the beginning of this proof. Combining the estimates for B 1 , B 2 , B 3 , we can deduce that which finishes the proof for odd K 0 . The case where K 0 is even can be handled under minor modifications. In total, we have shown that, for

Proof of Theorem 3 and Theorem 6
We start by proving (ii) of Theorem 3, where the Birkhoff sum S N ( f , α, q) is generated by a function f : R → R with symmetric logarithmic singularity at a rational, i.e. f is of the form f (x) = c log x − x 1 + t (x), where c = 0 ,x 1 = r s ∈ [0, 1) ∩ Q and t is of bounded variation. Without loss of generality, we can assume that q = 0 because otherwise we just setx 1 , where c 1 , c 2 ∈ R with c 1 = 0 and x 1 = r s ∈ [0, 1)∩Q and t is of bounded variation. Again, without loss of generality, it suffices to consider the case where q = 0.
We start with the case where ∞ k=1 1 ψ(k) = ∞ where we show that the set N ∈ N : S N ( f , α) ≥ log N ψ(log(N )) has upper density 1. Without loss of generality, we can assume that lim K →∞ ψ(K ) K logK = ∞ since the result then follows also for slower growing ψ. Note that S N ( f , α) = S N ( f 1 , α) + S N ( f 2 , α). By the first part of this proof, we have |S N ( f 2 , α)| ≪ (log N ) 2 log log N and since log N ψ(log N ) dominates (log N ) 2 log log N , it suffices to show that {N ∈ N : S N ( f 1 , α) ≥ log N ψ(log N )} has upper density 1. First, assume that c 1 > 0. By Lemma 3.12, for almost every α ∈ [0, 1), the set has infinite cardinality, whereψ(k) = C 1 ψ(C 2 k) with C 1 ,C 2 > 0 specified later. Denote by (k j ) j ∈N the increasing sequence of integers such that the above holds. Define M j := a k j 4s q k j −1 and note that, for any 1 ≤ N ≤ M j , we can write N = b k j −1 (N )q k j −1 + N ′ where N ′ < q k j −1 . Moreover, for δ > 0, let a k j ≤ 1 . We note that for any N ∈ A δ j , the assumptions of Lemma 4.4 are satisfied, and hence where c(δ) is a positive constant only depending on δ. Moreover, by Proposition 4.3, we have where D is a positive absolute constant. For j sufficiently large, this leads to where the inequality in the last line holds since a k j dominates k j −1 i =1 a i by construction. Moreover, we have used that c 1 in the definition of f 1 is positive by assumption and we employed log q k j −1 ≫ log q k j +1 which holds by (8). We note that lim δ→0 |A δ j | = M j and thus, fixing ε > 0, we can choose δ > 0 such that it follows that c(δ) 2 a k j log(q k j −1 ) ≥ log N ψ(log N ) for all N ∈ A δ j . We note that C 1 ,C 2 only depend on δ > 0, since k j is chosen such that By taking the liminf as j → ∞ and letting ε → 0, we get The case where c 1 from the definition of f 1 is negative can be handled under minor modifications. Analogously, one can show that the set N ∈ N : S N ( f , α) ≤ − log(N )ψ(log(N )) has upper density 1. The case where ∞ k=1 1 ψ(k) < ∞ can be treated analogously to the proof of Theorem 1 by using the Denjoy-Koksma inequality with singularity (Proposition 1.5). To prove Theorem 6, we start with a few general estimates. Observe that, for x 1 = r s and q K −1 < N < q K , we have where we have used (8) and Proposition 4.2. This shows that Further, we get where we used that min n<q K nα − x 1 ≤ 1 q K and log min n≤q K nα − x 1 ≪ K by the previous calculation. Now let 0 < r < 1. We will show that there exists a constant C (r ) > 0 such that the set has upper density of at least r . To that end, let (k j ) j ∈N be the sequence of integers from the first part a k j ≤ 1 and M j = a k j 4s q k j −1 be as in the first part of this proof, where we choose δ ′ = δ ′ (r ) > 0 sufficiently small such that |A δ ′ j | M j ≥ r . Using (23) we get, for N ∈ A δ ′ j , Since S N ( f 2 , α) ≪ k 2 j log k j = o(a k j log q k j −1 ), we obtain Thus, there exists a C (δ ′ ) = C (r ) such that ≥ r , the statement of Theorem 6 follows by an analogous argument as in (24). The second case in Theorem 6, where we deal with the set N ∈ N | S N ( f , α, q) ≤ −C (r ) sup can be handled similarly.

Appendix
In the appendix, we provide the proofs of Proposition 3.2 and Proposition 3.4.
Proof of Proposition 3.2. One can easily check that the condition of f being as in (11) is invariant under rational translation, thus it suffices to prove the statement for q = 0. We show that the set {N ∈ N : S N ( f , α) ≥ ψ(log N )} has upper density 1. We can write where N = b K −1 q K −1 + N ′ with N ′ < q K −1 . By the Denjoy-Koksma inequality in the form of (4), we have that We analyze the dominating term S b K −1 q K −1 ( f , α) for certain b K −1 . By Lemma 3.6, we have provided b K −1 ≤ 1 2s 1 s 2 s 3 a K and a K is sufficiently large. By Lemma 3.12, for almost all α ∈ [0, 1) and for any pair of integers (a, b), the sets K ∈ N | a K > ψ(K ), 2 ∤ (K − 1), q K −1 ≡ a (mod b), both contain infinitely many integers K . In the upcoming case distinction we will consider different choices of a and b.
Case 1: s 1 ∤ s 2 : The congruence relation q K −1 ≡ s 2 mod s 1 s 2 ensures that s 2 | q K −1 and s 1 ∤ q K −1 since s 1 ∤ s 2 by assumption. Thus, (25) gives us Case 2: We assume s 3 ∤ s 2 . Under the congruence conditions q K −1 ≡ s 2 mod s 2 s 3 and 2 ∤ (K − 1), we obtain Case 3: If s = s 1 = s 2 = s 3 , then we use the congruence conditions 2 ∤ (K −1) and q K −1 ≡ (r 2 ) −1 (mod s) to show The latter inequality holds since r 1 , r 3 are distinct from r 2 , and thus q K −1 r 1 s + q K −1 r 3 s ≥ 4 s . Case 4: s 1 | s 2 and s 3 | s 2 , but s 1 = s 2 or s 3 = s 2 : Without loss of generality, we assume s 1 = s 2 . We use the congruence conditions 2 | (K − 1) and q K −1 ≡ as 1 (mod s 2 ) with a ≡ r −1 2 mod s 2 s 1 (which is possible since gcd(r 2 , s 2 ) = 1). We obtain The second last inequality follows from the congruence relation q K −1 ≡ as 1 (mod s 2 ) and 2 s 1 where the latter holds since s 1 | s 2 and s 1 = s 2 . In the last line we used that if 1 {s 3 |q K −1 } = 0, then Thus, in either case, there exists a constant C > 0 such that, for N ∈ N with b K −1 ≤ 1 2s 1 s 2 s 3 a K , we have The remaining part of the proof can be argued in the same way as it is done in the proof of Theorem 7. The set {N ∈ N : S N ( f , α) ≤ −ψ(log N )} can be handled analogously. Fixing M ∈ N, there is exactly one K ∈ N such that q K −1 ≤ M < q K . Let K 0 = arg max k≤K a k (if the maximum is not unique, we can choose an arbitrary one among the maximizers). We define where δ > 0 is a small constant specified later. In the following, we will show that for any N ∈ A δ M , we have |S N ( f , α)| ≪ K log K . Writing N = K −1 ℓ=0 b ℓ q ℓ in its Ostrowski expansion, we obtain the decomposition with N ′ = K −1 ℓ=K 0 b ℓ q ℓ and N ′′ = K 0 −2 ℓ=0 b ℓ q ℓ . By the Denjoy-Koksma inequality (4), we can bound S N ′ ( f , α) by where we used (7) in the second line. Analogously, one obtains the same bound for S N ′′ ( f , α, (N ′ + b K 0 −1 q K 0 −1 )α), i.e., we get We now turn our attention to S b K 0 −1 q K 0 −1 ( f , α, N ′ α), where we will show S b K 0 −1 q K 0 −1 ( f , α, N ′ α) = 0. Indeed, an analogous analysis to the proof of Lemma 3.6 shows that there exists a δ > 0 such that, for any b K 0 −1 ≤ δa k 0 , it holds Regardless of the congruence class of q K 0 −1 modulo w , the expression above equals 0. In total, we have shown that, for all N ∈ A δ M , we get the asymptotic bound where the last estimate uses that N ≥ q K −1 , which holds by the definition of A δ M . This leads to This finishes the proof.