4. Let $f(n)$ be a function defined on the set of integers, and satisfy the following two conditions:
(1) $f(0)=1, f(1)=0$;
(2) For any $m, n \in \mathbf{N}$, $f(m+n)+f(m-n)=2 f(m) \cdot f(n)$, find $f(n)$.


4. In condition (2), let $n=1$ to get $f(m+1)+f(m-1)=0 .(*)$ Also, substitute $m+2$ for $m$ in the above equation, we have $f(m+3)+f(m+1)=0$. By comparing these two equations, we get $f(m+3)=f(m-1)$, and then substitute $m+1$ for $m$ in this equation, we have $f(m+4)=f(m)$, which means $f(n)$ is a periodic function with 4 as one of its periods. Also, from equation $(*)$, let $m=1$, we get $f(2)=-1$, and $f(1)=0$. By substituting $m=2$ into equation $(*)$, we get $f(3)=0$, hence
$$
f(n)=\left\{\begin{array}{l}
0, \text { when } n \text { is odd; } \\
1, \text { when } n=4 k, k \in \mathbf{Z} ; \\
-1, \text { when } n=4 k+2, k \in \mathbf{Z} .
\end{array}\right.
$$