TITLE: A nice formula for the Thue–Morse sequence
QUESTION [25 upvotes]: The Thue–Morse sequence$^{[1]}$$\!^{[2]}$ $t_n$ is an infinite binary sequence constructed by starting with $t_0=0$ and successively appending the binary complement of the sequence obtained so far:
$$\begin{array}l
0\\
0&\color{red}1\\
0&1&\color{red}1&\color{red}0\\
0&1&1&0&\color{red}1&\color{red}0&\color{red}0&\color{red}1\\
0&1&1&0&1&0&0&1&\color{red}1&\color{red}0&\color{red}0&\color{red}1&\color{red}0&\color{red}1&\color{red}1&\color{red}0\\
\hline
0&1&1&0&1&0&0&1&1&0&0&1&0&1&1&0&1&0&0&1&0&1&1&\dots\\
t_0&t_1&t_2&t_3&t_4&\dots\!\!\!
\end{array}$$
It has many interesting properties: it is aperiodic, cube-free, shows the parity of the number of $1$'s in the binary representation of a natural number, has connections to the Fabius function, the hypergeometric function, etc.
There is a nice formula for this sequence that uses only elementary functions, binomial coefficients and finite summation:
$$t_n=\frac43\,\sin^2\left(\frac\pi3\left(n-\sum_{k=1}^n(-1)^{\binom n k}\right)\right)=\operatorname{mod}\left(2n+\sum_{k=1}^n(-1)^{\binom n k},\,3\right).$$
Unfortunately, I could not find a proof of this formula anywhere and could not construct it myself. So, I'm asking for your help with this.

REPLY [9 votes]: An alternative proof.  For the sake of typesetting I'm going to write $C(n,k)$ instead of $\binom nk$.
Since we know $t_k$ is always $0$ or $1$, it suffices to show that
$$t_n\equiv 2n+\sum_{k=1}^n(-1)^{C(n,k)}\pmod3\ .\tag{$*$}$$
It is known that the Thue-Morse sequence is defined by
$$t_0=0\ ,\quad t_{2n}=t_n\ ,\quad t_{2n+1}=1-t_n\ .$$
It is clear that the RHS of $(*)$ satisfies the initial condition, I shall show that it also satisfies the recurrence.

Lemma: $C(2n,2k)\equiv C(n,k)\pmod2$.
Proof.  Count the number of subsets of size $2k$ in a set of size $2n$ by first choosing $j$ elements of the first $n$.  We have
$$\eqalign{C(2n,2k)
  &=\sum_{j=0}^{2k}C(n,j)C(n,2k-j)\cr
  &=C(n,k)^2+\sum_{j=0}^{k-1}\bigl(C(n,j)C(n,2k-j)+C(n,2k-j)C(n,j)\bigr)\cr
  &\equiv C(n,k)^2\pmod2\cr
  &\equiv C(n,k)\pmod2\ .\cr}$$

Lemma: $bC(a,b)=aC(a-1,b-1)$.
Proof.  Well known.  It follows easily that
$$\displaylines{
  C(2n,2k-1)\equiv (2k-1)C(2n,2k-1)\equiv2nC(2n-1,2k-2)\equiv0\pmod2\ ;\cr
  C(2n+1,2k)=C(2n,2k)+C(2n,2k-1)\equiv C(n,k)\pmod2\ ;\cr
  C(2n+1,2k+1)\equiv(2k+1)C(2n+1,2k+1)=(2n+1)C(2n,2k)\equiv C(n,k)\pmod2\ .\cr}$$

In $(*)$ we now have
$$\eqalign{RHS(2n)
  &=4n+\sum_{j=1}^{2n}(-1)^{C(2n,j)}\cr
  &=4n+\sum_{k=1}^n(-1)^{C(2n,2k-1)}+\sum_{k=1}^n(-1)^{C(2n,2k)}\cr
  &=4n+n+\sum_{k=1}^n(-1)^{C(n,k)}\cr
  &\equiv RHS(n)\pmod3\cr}$$
and
$$\eqalign{RHS(2n+1)
  &=4n+2+\sum_{j=1}^{2n+1}(-1)^{C(2n+1,j)}\cr
  &=4n+1+\sum_{k=1}^n(-1)^{C(2n+1,2k)}+\sum_{k=1}^n(-1)^{C(2n+1,2k+1)}\cr
  &=4n+1+2\sum_{k=1}^n(-1)^{C(n,k)}\cr
  &\equiv1-RHS(n)\pmod3\ .\cr}$$
As explained above, this completes the proof.

Observation.  Continuing to simplify modulo $3$ we can write the formula as
$$\eqalign{t_n\equiv 2n+\sum_{k=1}^n(-1)^{C(n,k)}
  &\equiv\sum_{k=1}^n\left(-1+(-1)^{C(n,k)}\right)\cr
  &\equiv\sum_{\textstyle{k=1\atop C(n,k)\ \rm odd}}^n(-2)\cr
  &\equiv\sum_{\textstyle{k=1\atop C(n,k)\ \rm odd}}^n1\cr
  &\equiv\#\{k\mid 1\le k\le n\ \hbox{and $C(n,k)$ is odd}\}\ .\cr}$$