# Is the sequence $(B_n)_{n \in \Bbb{N}}$ unbounded, where $B_n := \sum_{k=1}^n\mathrm{sgn}(\sin(k))$?

This question is kind of an extension of a previous question I asked here.

The infinite series $$\sum\frac{\mathrm{sgn}(\sin(n))}{n}$$ does converge, but I would like to know if Dirichlet's test can be used to prove the convergence with $$b_n=\mathrm{sgn}(\sin(n)).$$ So the question is, is the sequence $$(B_n)$$ given by $$B_n:=\sum_{k=1}^n\mathrm{sgn}(\sin(k))$$ unbounded? Loosely speaking it is a sum of $$1$$'s and the sign changes every $$\pi$$ terms. Also it would be great to know if the sequence $$(B_n)$$ is unbounded for other (irrational) changing cycles.

• Comments are not for extended discussion; this conversation has been moved to chat. – quid Jul 2 at 22:56

This sequence is unbounded and this result extends to every irrational period, though I only write out explicitly the case asked.

Define $$f(x)=\operatorname{sgn}(\sin(x))$$. Let us also define $$g_n(x)=f(x)+f(x+1)+f(x+2)+\ldots+f(x+n-1).$$ The question is whether the sequence $$g_0(0), g_1(0), g_2(0), \ldots$$ is unbounded.

Lemma: The sequence $$g_0(0), g_1(0), g_2(0), \ldots$$ is bounded if and only if the sequence of functions $$g_0, g_1, g_2, \ldots$$ is uniformly bounded.

Proof: Observe that since $$g_n(x)$$ is a sum of functions which are continuous except for some jump discontinuities and no two jump discontinuities in the summands align, it is also continuous aside from sum jump discontinuities - formally, we may say that for any $$x$$, there exists some $$\varepsilon$$ such that if $$|x'-x| <\varepsilon$$ then $$|g_n(x')-g_n(x)| \leq 1$$. Also note that $$g_n(x)+g_m(x+n)=g_{n+m}(x)$$ and that the integers are dense mod $$2\pi$$. Combining these facts tells us that if $$|g_n(x)|$$ is ever at least $$C$$, then $$|g_n(k)|$$ is at least $$C-1$$ for an integer $$k$$ and thus $$g_k(0) + g_n(k) = g_{n+k}(0)$$ which implies that either $$|g_k(0)|$$ or $$|g_{n+k}(0)|$$ is at least $$\frac{C-1}2$$. Therefore, showing that $$g_n$$ is not uniformly bounded would imply that the original sequence is not bounded either.

We therefore shift our focus to showing that the sequence $$g_n$$ is not uniformly bounded. To do so, we compute some Fourier coefficients. For odd integers $$a$$ we have $$\int_{0}^{2\pi}f(x)e^{iax}\,dx=\frac{4i}a$$ and from that we can derive: $$\int_{0}^{2\pi}g_n(x)e^{iax}\,dx=\frac{4i}a\cdot (1 + e^{-ia}+e^{-2ia}+e^{-3ia}+\ldots+e^{-(n-1)ia}).$$

For a fixed $$a$$ not a rational multiple of $$\pi$$, the supremum of the sums $$|\sum_{k=0}^{n-1}e^{-kia}|$$ over $$n$$ is $$\frac{2}{|1-e^{-ia}|}$$ by using the usual formula for geometric sums. Observe that $$|1-e^{-ia}|$$ is asymptotic to the distance of $$a$$ to the nearest multiple of $$2\pi$$ (at least when this quantity is small).

Then we get to a question about approximation which is frustratingly close to what we need: for any $$\varepsilon>0$$, is there some odd $$a$$ such that $$a$$ is within $$\frac{\varepsilon}a$$ of a multiple of $$2\pi$$? While Dirichlet's approximation theorem (or Hurwitz' theorem) can be used in conjunction with the knowledge that consecutive convergents of a continued fraction have coprime denominators to show that infinitely many such odd $$a$$ exist for some fixed $$\varepsilon$$, we cannot say anything about all possible choices of $$\varepsilon$$ - though a little ergodic theory shows that our desired statement is true for almost every irrational. To achieve our goal in general (and without trying to talk about approximating $$\pi$$ better than generic irrational numbers), we therefore have to look at multiple Fourier coefficients at once.

To start with, note that the convergents $$\frac{p}q$$ of the continued fraction to $$\frac{1}{2\pi}$$ have that $$|p-\frac{1}{2\pi}q| < \frac{1}q$$ by combining Dirichlet's approximation theorem with the knowledge that convergents minimize the quantity on the left hand side over all smaller $$q$$. There must be infinitely many convergents with odd denominator, since denominators of consecutive convergents are coprime. Suppressing constants, we can then say that for some $$c$$, there must exist infinitely many odd $$a$$ such that $$\frac{1}{|1-e^{-ia}|} > ac$$.

The usual formula for geometric series tells us that $$1+e^{-ia}+e^{-2ia}+\ldots + e^{-(n-1)ia} = \frac{1 - e^{-nia}}{1-e^{-ia}}.$$ We will use this to show that some $$g_n$$ have many Fourier coefficients of size at least $$c$$, which requires selecting odd integers is that $$1-e^{-ia}$$ is small and then selecting $$n$$ such that $$e^{-nia}$$ is near $$-1$$ for all the selected $$a$$.

Lemma: For any finite set $$a_1,\ldots,a_k$$ of odd integers and any $$\varepsilon$$, there exists some $$n$$ such that $$|1+e^{-nia_k}| < \varepsilon$$ for all $$k$$.

Proof: By a similar argument about approximations as was previously used, we can find an integer $$n$$ that is arbitrarily close to an odd multiple of $$\pi$$. Note that if a real number $$r$$ is within $$\varepsilon$$ of an odd multiple of $$\pi$$, then for any odd integer $$a$$, the value $$ar$$ is within $$a\varepsilon$$ of an odd multiple of $$\pi$$. Since the $$a_k$$ are fixed and finite, we may, by choosing $$n$$ sufficiently close to an odd multiple of $$\pi$$ ensure that all the values $$na_k$$ are arbitrarily close to odd multiples of $$\pi$$. The lemma immediately follows.

To finish, we can, for any $$k$$, select $$k$$ values $$a_1,\ldots,a_k$$ such that $$\frac{1}{|1-e^{-ia_k}|} > a_kc$$. Using the lemma, we may then choose $$n$$ such that $$|1-e^{-ina_k}| > 1$$ for all $$k$$. The quotients $$\frac{1-e^{-ina_k}}{1-e^{-ia_k}}$$ then all have absolute value at least $$a_kc$$ and thus $$a_k^{th}$$ Fourier coefficients of $$g_n$$ are all at least $$\frac{4c}{\pi}$$ in absolute value. Since there exist $$g_n$$ with arbitrarily many Fourier coefficients that are greater than some fixed lower bound, the sequence $$g_n$$ is not bounded in $$L^2$$ and thus is not uniformly bounded. Applying the first lemma, we find that the sequence $$g_0(0), g_1(0), g_2(0), \ldots$$ is not bounded. This proof extends to all irrational periods with minor modification.

• I am sorry it took long but I had to read my books about continued fractions and such. I thought my question was a simple one but this whole thing is quite new to me. So I have a question about the second lemma. I understand that we can find $n$ such that $na_m$ is close to an odd multiple of $\pi$ for each $m$ from $1$ to $k$, but how do you know there is an intersection? – Jaeseop Ahn Jul 7 at 18:19
• Also I think $$\int_{0}^{2\pi}g_n(x)e^{iax}dx=\frac{4i}a(1+e^{-ia}+e^{-2ia}+\ldots+e^{-(n-1)ia}).$$ and the supremum of the sums $|\sum_{k=0}^{n-1}e^{kia}|$ over $n$ is $\frac{2}{|1-e^{ia}|}$. I could be wrong so could you check? – Jaeseop Ahn Jul 7 at 18:21
• @JaeseopAhn I made edits to address your comments; to your first comment, the main added point is that odd multiples of odd multiples of $\pi$ are odd multiples of $\pi$ - hence getting $n$ close to an odd multiple means that all not-too-large odd multiples of $n$ are also close simultaneously. The two errors you point out are indeed errors and I have corrected them throughout the answer. – Milo Brandt Jul 7 at 18:36
• Very, very nice. +1 from me. The definition of $g_n$ was a really clever trick. – K.defaoite Jul 13 at 16:13

This question is insanely delicate. Let me explain what is going on.

The sequence $$s: =(\operatorname{sgn}(\sin(n)))_{n=1}^\infty$$ is usually periodic with period $$+,+,+,-,-,-$$, except sometimes you have four pluses or four minuses. Let $$H(N) := \#\{n \le N : \{\frac{n}{2\pi}\} \in (0,\frac{1}{2}-\frac{3}{2\pi})\}$$ and $$S(N) := \#\{n \le N : \{\frac{n}{2\pi}\} \in (\frac{1}{2},1-\frac{3}{2\pi})\}$$. The times when $$s$$ has four pluses in a row is exactly when $$n \in H(N)$$ ($$s$$ has a plus at $$n,n+1,n+2,n+3$$), and the times when $$s$$ has four minuses in a row is exactly when $$n \in S(N)$$ ($$s$$ has a minus at $$n,n+1,n+2,n+3$$).

Therefore, $$\sum_{n \le N} \operatorname{sgn}(\sin(n)) = H(N)-S(N)+O(1)$$, where the $$O(1)$$ term just comes $$N$$ being in the middle of a "period" of $$+,+,+,-,-,-$$. In terms of boundedness, we can ignore the $$O(1)$$ term, and figure out whether $$H(N)-S(N)$$ is unbounded.

Form a sequence $$t$$ of $$+$$'s and $$-$$'s by starting at $$n=1$$, increasing $$n$$, putting a $$+$$ if $$n$$ lies in $$H(N)$$, and putting a $$-$$ if $$n$$ lies in $$S(N)$$. Then $$t$$ alternates between $$+$$ and $$-$$, except sometimes there are two $$+$$'s in a row, and sometimes there are two $$-$$'s in a row. And it usually alternates which of $$+$$ or $$-$$ occurs twice in a row. The reason for $$+$$ and $$-$$ usually alternating is that if $$n \in H(N)$$, then this usually means that $$n+22 \in S(N)$$, and if $$n \in S(N)$$, then this usually means that $$n+22 \in H(N)$$.

Rigorously, there is a bijection between the set of $$n$$ with $$\{\frac{n}{2\pi}\} \in \left(0,\frac{\pi-3}{2\pi}-(\{\frac{22}{2\pi}\}-\frac{1}{2})\right)$$ and the set of $$n$$ with $$\{\frac{n}{2\pi}\} \in \left(\frac{1}{2}+(\{\frac{22}{2\pi}\}-\frac{1}{2}),\frac{1}{2}+\frac{\pi-3}{2\pi}\right)$$. Therefore, if we let $$H'(N) = \#\{n \le N : \{\frac{n}{2\pi}\} \in \left(\frac{\pi-3}{2\pi}-(\{\frac{22}{2\pi}\}-\frac{1}{2}),\frac{\pi-3}{2\pi}\right)\}$$ and $$S'(N) = \#\{n \le N : \{\frac{n}{2\pi}\} \in \left(\frac{1}{2},\frac{1}{2}+(\{\frac{22}{2\pi}\}-\frac{1}{2})\right)\}$$, then $$H(N)-S(N) = H'(N)-S'(N)+O(1)$$, where the $$O(1)$$ term is for the same kind of reason as before (the mentioned bijection might be off from a bijection by $$1$$ due to restricting to $$n \le N$$).

Therefore, we just have to determine whether $$H'(N)-S'(N)$$ is unbounded. The associated $$+,-$$ pattern is now periodic with period $$-,+,+,-,+,+,-,+,+,-,-,+,-,-,+,-,-,+,-,-,+,+$$, except for some defects. So you have to study the defects.

The point of all of this is that whether $$\sum_{n \le N}\text{sgn}(\sin(n))$$ is bounded or unbounded is actually determined by all of these $$O(1)$$ terms adding up, since we'll keep encountering nearly periodic sequences. [I hope my point is clear; there is something subtle going on. Even though the $$O(1)$$ terms don't matter individually (e.g. whether $$\sum_{n \le N} \text{sgn}(\sin(n))$$ is bounded is equivalent to whether $$H(N)-S(N)$$ is bounded even though they differ by a $$O(1)$$ term), they matter when added together].

I feel like all of this is related to the continued fraction expansion of $$\pi$$. I'll think about this more later.

• maybe we could prove that (contiguous) subsums of the periods get arbitrarily large, which would suffice. For example, in $−,+,+,−,+,+,−,+,+,−,−,+,−,−,+,−,−,+,−,−,+,+$, there is a subsum of $+3$ and a subsum of $-5$ – mathworker21 Jun 30 at 11:49
• So $H$ and $S$ are for counting the number of consecutive $+$ or $-$ in the original sum, and $H'$ and $S'$ are for counting consecutive $+$ or $-$ in $H$ or $S$, right? But since $\pi$ is irrational wouldn't the "defects" be just random? – Jaeseop Ahn Jun 30 at 14:07
• I agree that this is likely related to the continued fraction expansio of $\pi$. We all know the ridiculously good approximation $355/113$. Implying that the sequence is close to having period $2\cdot355=710$. Of course, $B_{710}=0$ for otherwise we would see steady increase.in the sums early on. Anyway, this is a very delicate question. – Jyrki Lahtonen Jun 30 at 16:23
• @JyrkiLahtonen I also thought it might have something to do with the continued fraction of $\pi,$ and I still think it might do, but I found that in order to make any progress at all, I had to put that thought out of my mind for the time being, and just write down a few inequalities that give at least a little understanding of the pattern of the Beatty sequence, and allow some computations that help to give an impression (possibly entirely misleading, of course!) of the rate of growth of $B_n.$ – Calum Gilhooley Jun 30 at 20:16
• @mathworker21 I forgot to adjust the norm. The right hand side evaluates to $\pi/4$ at $x=\pi/2$ by the well known series. The right hand side should be multiplied by $4/\pi$. – Jyrki Lahtonen Jul 1 at 8:25

Not an answer. When asked in the comments to guess whether the partial sums are bounded or unbounded, I replied, "Unbounded for all irrational $$\alpha > 1,$$ but that is only a guess (not even an educated one - I'm pretty new to this topic)."

My own notes on the problem are reproduced at the end of this comment/answer. (Disturbing events in Maths.SE have made it impossible for me to take my work any further, in the two days since the row erupted. Another guess: I don't think there was ever much chance of my work leading to a solution. However, I think my notation, and the few inequalities I've proved, may be useful to others as well as myself, although my proofs are almost certainly stupidly complicated. I intend to update this answer, with improved proofs if at all possible, if I'm allowed to concentrate again.)

This comment/answer, for what it's worth, consists of some data, and now also the Python code that produced it, followed by a hastily-assembled explanation of the algorithm, based upon my private notes (which, as I say, may have some value independent of the algorithm): $$\begin{array}{|r|r|} \hline B_n(\pi) & n \\ \hline {-1} & 25 \\ {-2} & 358 \\ {-3} & 104{,}351 \\ {4} & 312{,}692 \\ {5} & 625{,}381 \\ {6} & 938{,}070 \\ {-4} & 2{,}084{,}478 \\ {-5} & 6{,}357{,}421 \\ {-6} & 86{,}501{,}278 \\ {-7} & 166{,}645{,}135 \\ {7} & 412{,}496{,}057 \\ {8} & 824{,}054{,}044 \\ {9} & 1{,}235{,}612{,}031 \\ {10} & 1{,}647{,}170{,}018 \\ {11} & 2{,}058{,}728{,}005 \\ {12} & 2{,}470{,}285{,}992 \\ {-8} & 7{,}986{,}246{,}888 \\ {-9} & 8{,}066{,}390{,}745 \\ {-10} & 18{,}515{,}628{,}134 \\ {-11} & 36{,}864{,}611{,}133 \\ \hline \end{array} \quad \begin{array}{|r|r|} \hline B_n(\sqrt{10}) & n \\ \hline {4} & 22 \\ {5} & 41 \\ {6} & 60 \\ {7} & 79 \\ {8} & 98 \\ {9} & 117 \\ {10} & 838 \\ {11} & 1{,}559 \\ {12} & 2{,}280 \\ {13} & 3{,}001 \\ {14} & 3{,}722 \\ {15} & 4{,}443 \\ {16} & 31{,}822 \\ {17} & 59{,}201 \\ {18} & 86{,}580 \\ {19} & 113{,}959 \\ {20} & 141{,}338 \\ {21} & 168{,}717 \\ {22} & 1{,}208{,}398 \\ {23} & 2{,}248{,}079 \\ \hline \end{array} \ \begin{array}{c} \begin{array}{|r|r|} \hline B_n(\sqrt{10}) & n \\ \hline {24} & 3{,}287{,}760 \\ {25} & 4{,}327{,}441 \\ {26} & 5{,}367{,}122 \\ {27} & 6{,}406{,}803 \\ {28} & 45{,}887{,}302 \\ {29} & 85{,}367{,}801 \\ {30} & 124{,}848{,}300 \\ {31} & 164{,}328{,}799 \\ {32} & 203{,}809{,}298 \\ {33} & 243{,}289{,}797 \\ {34} & 1{,}255{,}929{,}484 \\ {35} & 2{,}268{,}569{,}171 \\ {36} & 9{,}357{,}046{,}980 \\ {37} & 10{,}856{,}266{,}261 \\ {38} & 12{,}355{,}485{,}542 \\ \hline \end{array} \\ \mathstrut \\ \mathstrut \\ \mathstrut \\ \mathstrut \\ \mathstrut \\ \end{array}$$

I'm sorry about the poor formatting. I'll try to improve it in future updates. As I wrote in another comment: "The latest update has been delayed, because the formatting of my new tables uses a lot of \framebox commands, and I've only just found out (the hard way) that these aren't supported by MathJax."

The computations used $$100$$ decimal digits of precision. I didn't check rigorously for possible errors in the $$2{,}000{,}000{,}000$$ iterations for $$B_n(\pi),$$ or $$680{,}000{,}000$$ iterations for $$B_n(\sqrt{10}),$$ each iteration requiring the rounding of one real number to an integer. I intend to add such checks later.

## No comment $$\ldots\ \ddot\frown$$

I had planned to do a lot more work on this answer today, along several independent tracks at once, but $$[\ldots]$$!

I will simply post the unpolished Python 3 code that I used to generate the table, with instructions on running it. (Don't worry, it's easy.) What it probably most needs is the inclusion of tests for inaccurate rounding to an integer value. (It should throw an exception if this occurs.) Also quite unsatisfactory is that it deals only with the computation of $$B_n(\alpha)$$ for irrational $$\alpha$$ such that $$m < \alpha < m + \tfrac12$$ for some positive integer $$m.$$ The formulae for the case $$m + \tfrac12 < \alpha < 1$$ are almost identical. I planned to code them in Python as well before updating my answer. (Oh, well.)

It would only be slightly more complicated to write code that handles all irrational $$\alpha > 1$$ in a uniform way, but I don't think there is any point in doing that, as I shall try to explain. $$[\ldots]$$

While explaining the code, I'll present the formulae I've been using, with proofs. I'm having to grit my teeth to do that, because my proofs were arrived at in a crazily roundabout way, and probably still bear traces of their origin, even though there is almost bound to be an "obvious" simplification. That was another of the many aspects of the problem that I planned to work on today. (Oh, well.)

On some future, happier day, perhaps we can put our heads together, and as well as simplifying my stupid proofs (if I haven't managed to do that myself), we might decide on a common notation to use when communicating about the problem. But first I have to present my own notation. That's a big enough task for one time, without complicating it with premature attempts at collaboration. (That's one of several good reasons why this isn't a Community Wiki post.) $$[\ldots]$$

Anyway, I have to break for dinner now. Here follows the unpolished code for my Python module, which I have been running under version 3.8.1 (64-bit), not that that should matter much. $$[\ldots]$$

The code can probably be speeded up quite considerably by installing gmpy2, but this depends on previously installing Microsoft Visual C++ 14.0. (You've guessed it, that was another of the many, many things I was planning to do today $$[\ldots]$$) Yes, I should have mentioned that I use a Windows machine. For running under Linux or other Unix-like OS (perhaps anything but Windows), you'll need to add some sort of "shebang" thing at the beginning (but you'll know what do, and I don't).

## Update 1

# \Work\Comp\Python\3\Lib\maths\spinoff.py
#
# Thu 25 Jun 2020  (created)
# Mon 29 Jun 2020  (updated)
# Thu  2 Ju1 2020  (trivial update)

"""Almost alternating: https://math.stackexchange.com/q/3731454.

__all__ = ['state']

from math import floor, ceil
from mpmath import mp

class state(object):
# Mon 29 Jun 2020  (created)
# Thu  2 Ju1 2020  (trivial update)
"""
Place in list of possibly extreme sums of (-1)^k: k in Beatty sequence.
"""

def __init__(self, j=0, B_n=0, maxB=0, minB=0, alpha=mp.pi):
# Mon 29 Jun 2020  (created)
# Mon 29 Jun 2020  (updated)
"""
Initialise state from parameters (copied and pasted from previous run).
"""
self.m = floor(alpha)
if alpha == self.m or alpha < 1:
raise ValueError
self.beta = 1/(alpha - self.m) - 1
if self.beta == floor(self.beta) or self.beta < 1:
raise ValueError
self.alpha = alpha
self.B_n = B_n
self.maxB = maxB
self.minB = minB
self.j = j
self.sj = ceil(self.j*self.beta)
self.n = self.sj*self.m + self.j*(self.m + 1)
self.k = floor(self.n/alpha)
self.sgn = 1 - 2*(self.k % 2)  # = (-1)**k
self.record = []  # list of new record-breaking tuples (B_n, n, k, j)

# Mon 29 Jun 2020  (created)
# Mon 29 Jun 2020  (updated)
"""
Read out the present state of the computation.
"""
return (self.j, self.B_n, self.maxB, self.minB, self.alpha)

# Mon 29 Jun 2020  (created)
# Thu  2 Ju1 2020  (trivial update)
"""
Increment the value of j the given number of times.
"""
old_j = self.j
for self.j in range(old_j + 1, old_j + loops + 1):
old_sj = self.sj  # = ceil((j-1)*beta)
self.sj = ceil(self.j*self.beta)
p = self.sj - old_sj
self.n += p*self.m
self.k += p
if p % 2:  # p is odd
self.B_n += self.sgn*self.m
self.sgn = -self.sgn
self.n += self.m + 1
self.k += 1
self.B_n += self.sgn*(self.m + 1)
self.sgn = -self.sgn
if self.B_n > self.maxB:
self.record.append((self.B_n, self.n, self.k, self.j))
self.maxB = self.B_n
if self.B_n < self.minB:
self.record.append((self.B_n, self.n, self.k, self.j))
self.minB = self.B_n

def main():
mp.dps = 100
dat = state()
print(dat.record)

if __name__ == '__main__':
main()

# end spinoff.py


The beginning of the log of the interactive session (using IDLE) that produced the table for $$B_n(\sqrt{10})$$ should give enough of an idea of how to run the program (please post any difficulties or bug reports as comments on this answer):

Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)] on win32
>>> from maths import spinoff
>>> from mpmath import mp
>>> mp.dps = 100
>>> a = mp.sqrt(10)
>>> a
mpf('3.162277660168379331998893544432718533719555139325216826857504852792594438639238221344248108379300295183')
>>> a**2
mpf('10.0')
>>> dat = spinoff.state(0, 0, 0, 0, a)
(0, 0, 0, 0, mpf('3.162277660168379331998893544432718533719555139325216826857504852792594438639238221344248108379300295183'))
>>> dat.record
[]
(10000000, 19, 31, 0, mpf('3.162277660168379331998893544432718533719555139325216826857504852792594438639238221344248108379300295183'))
>>> dat.record
[(4, 22, 7, 1), (5, 41, 13, 2), (6, 60, 19, 3), (7, 79, 25, 4), (8, 98, 31, 5), (9, 117, 37, 6), (10, 838, 265, 43), (11, 1559, 493, 80), (12, 2280, 721, 117), (13, 3001, 949, 154), (14, 3722, 1177, 191), (15, 4443, 1405, 228), (16, 31822, 10063, 1633), (17, 59201, 18721, 3038), (18, 86580, 27379, 4443), (19, 113959, 36037, 5848), (20, 141338, 44695, 7253), (21, 168717, 53353, 8658), (22, 1208398, 382129, 62011), (23, 2248079, 710905, 115364), (24, 3287760, 1039681, 168717), (25, 4327441, 1368457, 222070), (26, 5367122, 1697233, 275423), (27, 6406803, 2026009, 328776), (28, 45887302, 14510839, 2354785), (29, 85367801, 26995669, 4380794), (30, 124848300, 39480499, 6406803), (31, 164328799, 51965329, 8432812)]
>>> from math import floor
>>> def sgn(n):
return 1 - 2*(n % 2)  # = (-1)**n

>>> def B(n):
return sum([sgn(floor(i/a)) for i in range(1, n+1)])

>>> [B(n) for n in range(100)]
[0, 1, 2, 3, 2, 1, 0, 1, 2, 3, 2, 1, 0, 1, 2, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 3, 4, 5, 4, 3, 2, 3, 4, 5, 4, 3, 2, 3, 4, 5, 6, 5, 4, 3, 4, 5, 6, 5, 4, 3, 4, 5, 6, 5, 4, 3, 4, 5, 6, 7, 6, 5, 4, 5, 6, 7, 6, 5, 4, 5, 6, 7, 6, 5, 4, 5, 6, 7, 8, 7]
>>> [B(n) for n in [22, 41, 60, 79, 98, 117, 838, 1559, 2280, 3001, 3722, 4443, 31822]]
[4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
>>> # So far, so good.
>>> B(113959)
19
>>> B(1208398)
22
>>> B(6406803)
27
>>> B(45887302)
28
>>> # Still OK.  I think that's enough checking.


From another comment:

N.B. There is a bug in my Python code that can cause daft results if you initialise an object with non-default parameters in order to resume a computation from a previously reached state. It's probably easy to fix, but I haven't given it any thought yet. I've been extending the table for $$B_n(\pi),$$ and building a table for $$B_n(\sqrt{10}).$$ It'd be nice to code the $$q_j$$ version of the formulae, so that I can do $$B_n(e),$$ and perhaps $$B_n(\sqrt8),$$ but I'd better fix the $$p_j$$ version first. A nice surprise was that computing with $$100$$ digits of precision seems almost as fast as with $$50.$$

## Update 2

This is a lightly edited dump of some $$\LaTeX{}$$ed notes I have been writing, for my own private use, since Thursday 25 June. (There are also handwritten notes, starting from Tuesday 23, some of which have not yet been $$\LaTeX{}$$ed. They fill in one or two gaps left here, but not very much.)

It is necessary to give this context, because these notes were not written for "publication", and my arguments follow a meandering course, leading to simple conclusions which must almost surely be "obvious", if only with hindsight. Also, there is nothing startling here; it is very plodding stuff! But without it, the code of my Python module will read like, well, code; and for reasons I won't go into now - they are in the edit history, and in dozens of comments, mostly now deleted, and in a Meta thread (which I'm not following at the moment, so that I can concentrate on this job) - I have been virtually forced to dump all of my unpolished Python code here, and I am now faced with having to explain it as best I can. I hope that the notation I use, at least, will also be of some use to others.

$$\newcommand{\floor}{\left\lfloor#1\right\rfloor} \newcommand{\ceil}{\left\lceil#1\right\rceil}$$ Given an irrational number $$\alpha > 1,$$ we are interested in the Beatty sequence of non-negative integers $$(\floor{n/\alpha})_{n\geqslant1}.$$ For each non-negative integer $$k,$$ let $$r_k$$ be the number of times $$k$$ occurs in the Beatty sequence for $$1/\alpha.$$ Then $$r_k$$ is always $$m$$ or $$m + 1,$$ and in particular $$r_0 = m,$$ where $$m = \floor{\alpha},$$ i.e. $$m$$ is the unique positive integer such that $$m < \alpha < m + 1.$$ For each positive integer $$j,$$ let $$p_j$$ be the length of the $$j^\text{th}$$ group of consecutive values of $$k$$ for which $$r_k = m,$$ and let $$q_j$$ be the length of the $$j^\text{th}$$ group of consecutive values of $$k$$ for which $$r_k = m + 1.$$

For every positive integer $$j,$$ $$\begin{gather} \notag [(p_1 + \cdots + p_j)m + (q_1 + \cdots + q_{j-1})(m + 1) + 1] /\alpha > p_1 + q_1 + \cdots + q_{j-1} + p_j, \\ \notag\text{and }\ [(p_1 + \cdots + p_j)m + (q_1 + \cdots + q_{j-1} + 1)(m + 1)] /\alpha \\ < p_1 + q_1 + \cdots + q_{j-1} + p_j + 1, \\ \notag\text{so }\ m + \frac{q_1 + \cdots + q_{j-1} + 1} {p_1 + q_1 + \cdots + q_{j-1} + p_j + 1} < \alpha < m + \frac{q_1 + \cdots + q_{j-1} + 1} {p_1 + q_1 + \cdots + q_{j-1} + p_j}, \\ \notag\text{i.e. }\ 1 + \frac{p_1 + \cdots + p_j - 1}{q_1 + \cdots + q_{j-1} + 1} < \frac1{\alpha - m} < 1 + \frac{p_1 + \cdots + p_j}{q_1 + \cdots + q_{j-1} + 1}, \\ \notag\text{i.e. }\ p_j < (q_1 + \cdots + q_{j-1} + 1)\left(\frac1{\alpha - m} - 1\right) - p_1 - \cdots - p_{j-1} + 1 < p_j + 1, \\ \label{3731454:eq:P}\tag{P} \text{i.e. }\ p_j = \ceil{(q_1 + \cdots + q_{j-1} + 1)\left(\frac1 {\alpha - m} - 1\right)} - p_1 - \cdots - p_{j-1}. \end{gather}$$

Similarly, $$\begin{gather} \notag [(p_1 + \cdots + p_j)m + (q_1 + \cdots + q_j)(m + 1)]/\alpha < p_1 + q_1 + \cdots + p_j + q_j, \\ \notag\text{and }\ [(p_1 + \cdots + p_j)m + (q_1 + \cdots + q_j + 1)(m + 1)]/\alpha \\ \notag > p_1 + q_1 + \cdots + p_j + q_j + 1, \\ \notag\text{therefore }\ m + \frac{q_1 + \cdots + q_j} {p_1 + q_1 + \cdots + p_j + q_j} < \alpha < m + \frac{q_1 + \cdots + q_j + 1} {p_1 + q_1 + \cdots + p_j + q_j + 1}, \\ \notag\text{i.e. }\ 1 + \frac{p_1 + \cdots + p_j}{q_1 + \cdots + q_j + 1} < \frac1{\alpha - m} < 1 + \frac{p_1 + \cdots + p_j}{q_1 + \cdots + q_j}, \\ \notag\text{i.e. }\ q_j < (p_1 + \cdots + p_j)\left( \frac1{\alpha - m} - 1\right)^{-1}\!\! - q_1 - \cdots - q_{j-1} < q_j + 1, \\ \label{3731454:eq:Q}\tag{Q} \text{i.e. }\ q_j = \floor{(p_1 + \cdots + p_j)\left( \frac1{\alpha - m} - 1\right)^{-1}} - q_1 - \cdots - q_{j-1}. \end{gather}$$

If $$m<\alpha< m+\tfrac12,$$ then $$2m+2$$ successive multiples of $$1/\alpha$$ occupy a closed interval of length $$(2m+1)/\alpha>2,$$ therefore $$q_j=1$$ for all $$j.$$

Similarly, if $$m + \tfrac12 < \alpha < m + 1,$$ then $$2m + 2$$ successive multiples of $$1/\alpha$$ occupy a closed interval of length $$(2m + 1)/\alpha < 2,$$ therefore $$p_j=1$$ for all $$j.$$

(That is why there seems little point in writing Python code to deal with both cases in a uniform manner, especially in view of what comes next.)

Define $$\beta = \frac1{\alpha - m} - 1,$$ so that \begin{align*} \beta > 1 & \text{ if } m < \alpha < m + \frac12, \\ \beta < 1 & \text{ if } m + \frac12 < \alpha < m + 1. \end{align*} Then \begin{align*} \text{if } m < \alpha < m + \frac12 \text{ then } p_j & = \ceil{j\beta} - p_1 - \cdots - p_{j-1}, \\ \text{if } m + \frac12 < \alpha < m + 1 \text{ then } q_j & = \floor{\frac{j}{\beta}} - q_1 - \cdots - q_{j-1}, \end{align*} and it is now obvious, by induction on $$j$$ (I'm sure it really ought to be obvious without any of this palaver, but I haven't had a chance to think any more about it today), that \begin{align*} \text{if } m < \alpha < m + \frac12 \text{ then } p_j & = \ceil{j\beta} - \ceil{(j - 1)\beta}, \\ \text{if } m + \frac12 < \alpha < m + 1 \text{ then } q_j & = \floor{\frac{j}{\beta}} - \floor{\frac{j - 1}{\beta}}, \end{align*}

(By an astonishing synchronicity, this question came up on Saturday 27 June, just before I started writing things in this way, but I was so thick-headed that the penny didn't drop for about a day!)

The equation for $$p_j$$ has been pretty thoroughly checked, but I haven't done much with the equation for $$q_j,$$ so regard it with (even more) suspicion (unless, that is, both these equations are even more howlingly obvious than I imagine they must be).

Note the implications that \begin{align*} \text{if } m < \alpha < m + \frac12 \text{ then } p_j & = \ceil{\beta} \text{ or } \floor{\beta} \text{ for all } j, \\ \text{if } m + \frac12 < \alpha < m + 1 \text{ then } q_j & = \floor{\frac1{\beta}} \text{ or } \ceil{\frac1{\beta}} \text{ for all } j. \end{align*}

Assume from now on that $$m < \alpha < m + \frac12.$$ (This is, of course, merely because I wanted to get on with writing Python code for computing $$B_n(\pi).$$ There is no suggestion that the other case is not of equal interest.)

In a provisional notation, let $$s(j) = p_1 + \cdots + p_j = \ceil{j\beta} \quad (j \geqslant 1).$$ In a possibly unwise notation (but I should have some notation for it), let $$l(n) = \floor{\frac{n}\alpha} \quad (n \geqslant 1)$$ (I changed that immediately!), and of course $$B_n = B_n(\alpha) = \sum_{i=1}^n(-1)^{l(i)} \quad (n \geqslant 1).$$ It seems almost "obvious" now (and I imagine it should be easy enough to prove) that the crucial values of $$n,$$ the only ones for which $$B_n$$ can take on new maximum or minimum values, are $$t(j) = s(j)m + j(m + 1) \quad (j \geqslant 1).$$ We should have $$l(t(j) - m) = l(t(j) - m + 1) = \cdots = l(t(j) - 1) = l(t(j)) \quad (j \geqslant 1).$$ (I think I did prove all of this, but only in my handwritten notes. The horrible controversy in Maths.SE erupted, I think, on the morning after the night when I had arrived at this point, and begun doing systematic computations, so I've had no time to work through all of this properly. But I will be updating this answer.)

• do u think the partial sums are bounded or unbounded, if you had to guess – mathworker21 Jul 1 at 18:06
• Yeah I would like to ask the same! – Jaeseop Ahn Jul 1 at 18:34
• Unbounded for all irrational $\alpha > 1,$ but that is only a guess (not even an educated one - I'm pretty new to this topic). I had real hopes of getting more closely to grips with the problem yesterday, but than all that happened. (I'm dismayed to come back and find that it is all still going on.) I wasn't allowed a single minute to think about the problem yesterday, I didn't sleep a single minute last night after being driven to exhaustion, and I'm still getting what I can only call mild PTSD-like symptoms. Still, I've carried on doing donkey-work. Another (small) update is coming soon. – Calum Gilhooley Jul 1 at 18:52