Example 2 Solve the functional equation $f\left(\frac{x-1}{x+1}\right)+f\left(-\frac{1}{x}\right)+f\left(\frac{1+x}{1-x}\right)=\cos x(x \neq 0, \pm 1)$.
Let $g(x)=\frac{x-1}{x+1}$, then $g^{(4)}(x)=g[g(g(g(x)))]=x$, and $g^{(2)}(x)=g(g(x))=-\frac{1}{x}, g^{(3)}(x)=g(g(g(x)))=\frac{1+x}{1-x}$. Thus, the given equation becomes $f[g(x)]+f\left[g^{(2)}(x)\right]+f\left[g^{(3)}(x)\right]=\cos x$. Replacing $x$ with $g(x)$, we get $f\left[g^{(2)}(x)\right]+f\left[g^{(3)}(x)\right]+f(x)=\cos g(x)$. Continuing to replace twice more, we have $f\left[g^{(3)}(x)\right]+f(x)+f(g(x))=\cos g^{(2)}(x)$,
$$
f(x)+f(g(x))+f\left(g^{(2)}(x)\right)=\cos g^{(3)}(x) \text {. }
$$

By organizing the above equations, we get
$$
3 f(x)=\cos g(x)+\cos g^{(2)}(x)+\cos g^{(3)}(x)-2 \cos x \text {. }
$$

Therefore, $f(x)=\frac{1}{3}\left(\cos \frac{x-1}{x+1}+\cos \frac{1}{x}+\cos \frac{1+x}{1-x}-2 \cos x\right)$.