3. The function defined on the set of positive integers is
$$
f(x)=\left\{\begin{array}{ll}
3 x-1, & x \text { is odd, } \\
\frac{x}{2}, & x \text { is even. }
\end{array}\right.
$$

Let $x_{1}=12, x_{n+1}=f\left(x_{n}\right), n \in \mathbf{N}$, then the number of elements in the set $\left\{x \mid x=x_{n}\right.$, $n \in \mathbf{N}\}$ is $\qquad$.
3. 7 .

From $x_{1}=12$ we get $x_{2}=6$, then $x_{3}=3, x_{4}=8, x_{5}=4$, $x_{6}=2, x_{7}=1, x_{8}=2, x_{9}=1, \cdots$, and thereafter it is a cycle of $2,1,2,1$, $\cdots$. Therefore, $x_{n}$ takes a total of 7 different values, i.e., the set $|x| x$ $\left.=x_{n}, n \in \mathbf{N}\right\}$ contains 7 elements.