I'm trying to show $$ \mathrm{dim}(U_1 + U_2 + U_3) = \mathrm{dim}(U_1) + \mathrm{dim}(U_2) + \mathrm{dim}(U_3) -\mathrm{dim}(U_1 \cap U_2) -\mathrm{dim}(U_1\cap U_3) -\mathrm{dim}(U_2 \cap U_3) + \mathrm{dim}(U_1 \cap U_2 \cap U_3)$$
for $U_i$ subspaces of $V$. I tried to do it by extending a basis
$ u_1,...,u_n$ of $U_1 \cap U_2 \cap U_3$ to bases
$u_1,...,u_n,v_1,...,v_m$ of $U_1 \cap U_2$
$u_1,...,u_n, w_1,...,w_k$ of $u_2 \cap U_3$
$u_1,...,u_n,x_1,...,x_j$ of $U_1 \cap U_3$
and then extending these to bases
$u_1,...,u_n,v_1,...,v_m,y_1,...,y_i$ of $U_1$
$u_1,...,u_n, w_1,...,w_k,z_1,...,z_h$ of $U_2$
$u_1,...,u_n,x_1,...,x_j, \eta_1,....,\eta_l$ of $U_3$.
Then I calculated that the RHS of the equation equals $i+h+l+n$. But I can't figure out how to arrive at the same sum for $ \mathrm{dim}(U_1 + U_2 + U_3)$. How can I finish this proof?