Does anyone know of a **closed form** for the function on $\mathbb{N}$ which returns the greatest power of two which divides a given integer?


To be more precise, any positive integer $n\in\mathbb{N}$ can be uniquely expressed as $n=2^pq$ where $p,q\in\mathbb{N}$ and furthermore $q\equiv1\mod2$. I am looking for a closed form of the resulting function $f:\mathbb{N}\to\mathbb{N}$ which is such that $f:n\mapsto p$, as defined e.g. on [Wikipedia](http://en.wikipedia.org/wiki/Closed-form_expression).


As a starting point, I constructed a summation which does the job:
$$f(n)=\sum\_{j=1}^{\rho(n)}\left(\prod\_{i=1}^{j}\cos\left[\frac{\pi n}{2^i}\right]\right)^2$$
where $\rho(n)=\lfloor\log\_2n\rfloor$. Sadly, this expression is not very useful, and I would prefer a closed form expression. Using Morrie's Law, the product can be converted to a limit as follows:
$$f(n)=\lim\_{\epsilon\to0}t[\pi(n+\epsilon),\rho(n)]$$
where
$$t[x,m]=\sum\_{j=1}^{m}\left(\frac{2^{-j}\sin[x]\cos[x]}{\sin[2^{-j}x]}\right)^2$$
However, I cannot find a closed form for this summation...


So in summary, I'd be grateful if anyone could give me an expression for $t(x,m)$ which would make my version of $f$ usable, or if anyone could tell me another such $f$.


Thanks!


EDIT: I followed Gerry's answer and derived the following Fourier series for $f$:


$$f(n)=(1+\cos[\pi n])\left(1-2^{-\rho(n)}+\sum\_{j=1}^{\rho(n)}\sum\_{k=1}^\infty\frac{\sin[2\pi k n 2^{-j}]-\sin[2\pi k (n-1) 2^{-j}]}{k}\right)$$


I will try to further simplify this...



Greatest power of two dividing an integer
I suspect this answer will not be found satisfactory, but here goes. Write $[x]$ for the integer part of $x$. Then $[n/2]-[(n-1)/2]$ is 1 if $n$ is a multiple of 2, 0 otherwise. $[n/4]-[(n-1)/4]$ is 1 if $n$ is a multiple of 4, 0 otherwise. Etc. So the function you want is $$[n/2]-[(n-1)/2]+[n/4]-[(n-1)/4]+[n/8]-[(n-1)/8]+\dots$$ where the sum isn't really infinite, it has $r$ terms, where $r$ is something like $\log\_2n$. 


