If a system like $f$ is topologically transitive every $f$-invariant continuous function is constant Let $X$  is a compact metric space and $f: X \to X$ is a homeomorphism. I want to prove that If $f$ is topologically transitive any $f$-invariant continuous function $\phi : X \to \mathbb{R}$ is constant.($\phi$ is $f$-invariant if $\phi(f)=\phi$).
$f:X \to X$ is topologically transitive if for any open subsets $U,V \subseteq X$ there exists $n \geq 1$ such that $f^n(V) \cap U \neq \emptyset$.
It is equivalent to the following statement:
There exists $x \in X$ such that whose positive or negative orbit is dense in $X$.
I wrote a proof for this question:
There is $x \in X$ whose positive orbit is dense in $X$ so if $y \in X$ for every nbd of $y$ such as $U_y$ we have $U_y \cap O^+(x) \neq \emptyset$ this means there is $w \in U_y$ which also belongs to $O^+(x)$ so there is $m \geq 1$ such that $w = f^m(x)$ so $\phi(w) = \phi(f^m(x))$. since $\phi$ is $f$-invariant so
\begin{align}
\phi(w) =\phi(f^m(x))=\phi(x)
\end{align}
Since $ y \in X$ was arbitrary then we could conclude $\phi$ is constant.
Is there anything wrong with my proof?
 A: There is a bit of a problem: at the end of your proof you conclude $\phi(w) = \phi(x)$, but we probably wanted to show that $\phi(y) = \phi(x)$?
How about this? I'm going to clarify your writing a little bit, because the first sentence of your proof is very long:

Fix $x \in X$ whose positive orbit is dense in $X$. Now let $w \in O^+(x)$ be arbitrary. Then there is $m \geq 1$ such that $w = f^m(x)$, and therefore $\phi(w) = \phi(f^m(x)) = \phi(x)$ since $\phi$ is $f$-invariant. Since $w \in X$ was arbitrary we conclude that $\phi$ is constant on $O^+(x)$.
But by hypothesis $O^+(x)$ is dense in $X$, and since $f$ is continuous we conclude that $f$ is constant on all of $X$, as desired.

If you aren't quite sure why a continuous function which is constant on a dense subset of its domain is constant on the entire domain, the argument uses similar ideas to those from your original proof which have gone unused in mine above:
Lemma. If $f : X \to Y$ is continuous and constant on a dense subset $D \subset X$, then $f$ is constant on all of $X$.
Proof. By hypothesis $f(D) = \{ y \}$ for some $y \in Y$. Since $f$ is continuous the preimage of every closed subset of $Y$ is closed, hence $C = f^{-1}(\{y\}) \subset X$ is closed. Now $C$ is closed and contains $D$, so also contains the closure of $D$. But $D$ is dense in $X$, so the closure of $D$ is $X$---therefore $C = X$, too. It follows that $f(X) = \{y\}$, as desired.
A: As others have pointed out, you are a bit sloppy at the end of the proof. All in all, the proof is okay and can be formulated as follows: An $f$-invariant function is constant on orbits. By some theorem, a topologically transitive function has a dense orbit. Since a function that is constant on a dense subset is constant, $f$-invariant functions for a topologically transitive function $f$ must be constant.
While this proof is correct, one can argue whether it is appropriate. The reason for this is that the theorem that you invoke does not seem trivial to me (you seem to have confirmed this in the comments). The statement that we want to proof, on the other hand, is rather simple:
Let $x, y\in X$. Consider any neighbourhoods $W$ of $\phi(x)$ and $Z$ of $\phi(y)$ and set $U:=\phi^{-1}[W]$ and $V:=\phi^{-1}[Z]$. Now there is an $n$ such that $f^n[U]\cap V\ne\emptyset$. But $$\phi[f^n[U]\cap V]\subset\phi[f^n[U]]\cap\phi[V] = \phi[U]\cap\phi[V] \subset W\cap Z,$$ so  $W\cap Z\ne\emptyset$. Since $W$ and $Z$ were arbitrary neighbourhoods of $\phi(x)$ and $\phi(y)$, we must have $\phi(x)=\phi(y)$. This shows that $\phi$ is constant.
A: To finish the proof you have to take $U_y=B(y,\frac  1n)$ and get a point $w_n$ in this ball with $\phi (w_n)=\phi (x)$. Now use continuity of $\phi$ to conclude that $\phi (y)=\phi (x)$.
