Solution (source code)

= Solution

Choose a <basis> $e_1,\ldots,e_k$ for $U\cap U'$. Extend it to a basis $e_1,\ldots,e_k,u_1,\ldots,u_r$ of $U$, and separately to a basis $e_1,\ldots,e_k,v_1,\ldots,v_s$ of $U'$. The combined list spans $U+U'$.

To prove <linear independence>, suppose a linear combination of the combined list is zero. Then the combination of the $v_j$ lies in $U\cap U'$, so it can be expressed using the $e_i$. Independence of the chosen basis of $U'$ forces every $v_j$ coefficient to vanish. Independence of the chosen basis of $U$ then forces the remaining coefficients to vanish. Thus the combined list is a basis, with $k+r+s$ elements. This proves the <dimension formula for a sum of subspaces>:
$$
\boxed{\dim(U+U')=\dim U+\dim U'-\dim(U\cap U').}
$$