Linear algebra - Dimension theorem. Suppose we have a vector space $V$, and $U$, $W$ subspaces of  $V$.
Dimension theorem states:
$$ \dim(U+W)=\dim U+ \dim W - \dim (U\cap W).$$
My question is:
Why is $U \cap W$ necessary in this theorem?

You can think in $A=\{a_1,...,a_n\}$ as base of $U$ and $B=\{b_1,...,b_m\}$ as a base of $V$, we know that the dimension of a vectorial space is the number of elements of  some base. If $b_1$ it isn't linear combination of the elements of $A$ so $C_1=A \cup \{b_1$}. If $b_p$ it isn't linear combination of the elements of $C_{p-1}$, so $C_p=C_{p-1}\cup\{b_p\}$. Let $\  D=B -C_{p-1}$, now it is easy to see that $C_m$ is base of $\ U+V$ and $D$ is base of $\ U\cap V$.
This is an algorithm to obtain $U+V$ and $U\cap V$.
Without lost of generality, if $C_m=\{a_1,a_2,...,a_n,b_1,b_2,...,b_{m-k}\} \Rightarrow dim(U+V)=n+k$ 
on the other hand $dim(U)+dim(V)-dim(U\cap V)=n+m-(m-k)=n+k$
