Let $f : U \to V$ and $g : V \to W$ be linear transformations on the vector spaces $U$, $V$, and $W$ respectively. Then Prove that :
$$ \dim(\ker(g \circ f)) = \dim(\ker(f)) + \dim(\ker(g) \cap \operatorname{im}(f)). $$
Attempt: It's clear that $$\ker(g \circ f))= \ker f +\{\operatorname{im} f \cap \ker(g)\}$$
Then $$\dim \ker(g \circ f))= \dim \big (\ker f +\{\operatorname{im} f \cap \ker(g)\} \big ) \tag{1} $$
If $\ker f \bigcap \operatorname{im}f=\emptyset$, then , $(1)$ becomes an external direct product and the dimension adds up. Otherwise, $\dim \ker(g \circ f)) \le \dim \big (\ker f)+\dim \big(\{\operatorname{im} f \cap\ker(g)\} \big )$
Could someone please pin point the error. Thanks a lot for the help.