Example 4 Determine the periodicity of the following functions. If they are periodic functions, find their smallest positive period:
(1) $y=\operatorname{tg} x-\operatorname{ctg} x$;
(2) $y=\sin (\cos x)$;
(3) $y=\sin x^{2}$.
$$
\text { Solution: (1) } y=\operatorname{tg} x-\operatorname{ctg} x=\frac{\sin ^{2} x-\cos ^{2} x}{\sin x \cos x}=\frac{-\cos ^{2} x}{\frac{1}{2} \sin 2 x}=-2 \operatorname{ctg} 2 x \text {, }
$$

Then $y=\operatorname{tg} x-\operatorname{ctg} x$ is a periodic function with the smallest positive period being $\frac{\pi}{2}$.
(2) From $\sin (\cos (x+2 \pi))=\sin (\cos x)$, we know that the function $y=\sin (\cos x)$ is a periodic function with a period of $2 \pi$.
Let the smallest positive period be $T$, and $0<T<2 \pi$, then
$$
\sin [\cos (x+T)]=\sin (\cos x) \text {. }
$$

In particular, let $x=0, \sin (\cos T)=\sin 1$, on the other hand, $-1 \leqslant \cos T<1$, according to the monotonicity of the sine function, $\sin (\cos T)<\sin 1$ which contradicts $\sin (\cos T)=\sin 1$. Therefore, $T$ is not the period of the function.
Thus, the smallest positive period of the function is $2 \pi$.
(3) It is not a periodic function.
Assume $y=\sin x^{2}$ is a periodic function with period $T$, then $\sin (x+T)^{2}=$ $\sin x^{2}$.

Let $x=0, \sqrt{\pi}, \sqrt{2 \pi}$, we get $\sin T^{2}=0, \sin (\sqrt{\pi}+T)^{2}=0$, $\sin (\sqrt{2 \pi}+T)^{2}=0$, thus, $T^{2}=l \pi,(\sqrt{\pi}+T)^{2}=m \pi,(\sqrt{2 \pi}+T)^{2}=$ $2 n \pi$, where $l, m, n \in \mathbb{Z}$, hence
$$
(m-l) \pi=\pi+2 \sqrt{2 \pi} T, \quad(n-l) \pi=2 \pi+2 \sqrt{2 \pi} T .
$$

This implies $\frac{(n-l-2) \pi}{(m-l-1) \pi}=\frac{2 \sqrt{2 \pi} \cdot T}{2 \sqrt{\pi} \cdot T}=\sqrt{2}$, but the left side of the equation is a rational number, while $\sqrt{2}$ is an irrational number, which is a contradiction.
Therefore, $y=\sin x^{2}$ is not a periodic function.
$$