4. Find all functions $f: \mathscr{E} \rightarrow \mathscr{B}$, for any $x, y \in \mathscr{F}, f$ satisfies
$$
f(x y)(f(x)-f(y))=(x-y) f(x) f(y) \text {. }
$$

where $\mathscr{B}$ is the set of real numbers.
Let $y=1$, then
$f(x)(f(x)-f(1))=(x-1) f(x) f(1)$,
which means $f^{2}(x)=x f(x) f(1)$.
If $f(1)=0$, then $f(x)=0$ for all $x$, which satisfies the given condition.

Assume $f(1)=c \neq 0$, then $f(0)=0$. Let $G=\{x \mid x \in \mathscr{B}, f(x) \neq 0\}$. Clearly, $0 \notin G$, and for all $x \in G$, we have $f(x) = x f(1)$. Therefore, the function that satisfies the given condition is
$$
f(x)=\left\{\begin{array}{ll}
C x, & x \in G, \\
0, & x \notin G .
\end{array}\right.
$$

Next, we determine the structure of $G$ so that the function defined by (1) satisfies the given condition for any real numbers $x, y \in A$.

It is easy to verify that if $x \neq y$, and $x, y \in G$, then $x y \in G$ if and only if the function defined by (1) satisfies the given condition. When $x, y \notin G$, the function defined by (1) also satisfies the given condition. By symmetry, we only need to consider the case where $x \in G$ and $y \notin G$.
When $x \in G$ and $y \notin G$, we have $f(y)=0$, so the given condition reduces to $f(x y) f(x)=0$.
Since $x \in G$, we have $f(x) \neq 0$, thus $f(x y)=0$. Therefore, $x y \notin G$.
(i) If $x \in G$, then $\frac{1}{x} \in G$.
If $\frac{1}{x} \notin G$, then $x \cdot \frac{1}{x}=1 \notin G$, which contradicts $1 \in G$.
(ii) If $x, y \in G$, then $x y \in G$.
If $x y \notin G$, by (i) we know $\frac{1}{x} \in G$, thus $\frac{1}{x} \cdot x y=y \notin G$, which is a contradiction.
(iii) If $x, y \in G$, then $\frac{x}{y} \in G$.
By (i) we know $\frac{1}{y} \in G$, and by (ii) we get $\frac{x}{y} \in G$.
Therefore, $G$ contains 1, does not contain 0, and is closed under multiplication and division. The closure under multiplication and division characterizes $G$.
We finally write down all solutions to this problem:
$$
f(x)=\left\{\begin{array}{cc}
C x, & x \in G, \\
0, & x \notin G .
\end{array}\right.
$$

Here $C$ is any fixed constant, and $G$ is any subset of $\mathbb{R}$ that is closed under multiplication and division. When $C=0$, it is the trivial solution mentioned earlier.