% This is lecture no. 6 of MH1201/: Linear Algebra II.

\chapter{Rank \& Nullity}%
\label{cha:rank_&_nullity}

\section{Rank-Nullity Theorem}%
\label{sec:rank_nullity_theorem}

The null space and range are important and have special names attached to them.
\begin{definition}
	Nullity \& Rank.
	Let  $\mathsf{T}$ be a linear transformation $\mathsf{T}:\mathsf{V}\mapsto \mathsf{W}$, where $\text{dim}(N(\mathsf{T}))<\infty$ and $\text{dim}(R(\mathsf{T}))<\infty$.
	Then,
	\[
		 \text{dim}(N(\mathsf{T}))
	\]
	is known as the nullity of $\mathsf{T}$.
	And then,
	\[
		\text{dim}(R(\mathsf{T}))
	\]
	is known as the rank of $\mathsf{T}$.
\end{definition}
The balance between rank and nullity is reflected in the following theorem.
\begin{thrm}
	Rank-Nullity Theorem.
	Let $\mathsf{T}$ be a linear transformation $\mathsf{T}:\mathsf{V}\mapsto \mathsf{W}$ and let $\text{dim}(\mathsf{V})<\infty$.
	Then:
	\[
		\text{nullity}(\mathsf{T}) + \text{rank}(\mathsf{T}) = \text{dim}(\mathsf{V})
	.\]
	Otherwise written:
	\[
		\text{dim}(N(\mathsf{T})) + \text{dim}(R(\mathsf{T})) = \text{dim}(\mathsf{V})
	.\]
\end{thrm}
\begin{proof}
	Rank-Nullity Theorem.
	Suppose that $\text{dim}(\mathsf{V})=n$ and $\text{dim}(N(\mathsf{T}))=k$.
	Then we consider three cases.

	\noindent
	\underline{Case 1}: $0<k<n$, that is $k\in \{1,2,\dotsc,n-1\}$.

	Let $\{v_1,v_2,\dotsc,v_k\}$ be a basis for $N(\mathsf{T})$.
	Therefore this basis for $N(\mathsf{T})$ is a linearly independent subset of $\mathsf{V}$.
	Then by the \textbf{Replacement Theorem}, we may extend $\{v_1,v_2,\dotsc,v_k\}$ to a basis for $\mathsf{V}$:
	\[
		\beta = \{v_1,v_2,\dotsc,v_k,v_{k+1},\dotsc,v_n\}
	.\]
	Now consider the following set $S$:
	\[
		S = \left\{ \mathsf{T}(v_{k+1}),\mathsf{T}(v_{k+2}),\dotsc,\mathsf{T}(v_n) \right\} 
	.\]
	And consider the fact that:
	\[
		R(\mathsf{T}) = \text{span}(\left\{ \mathsf{T}(v_1),\mathsf{T}(v_2),\dotsc,\mathsf{T}(v_n) \right\})
	.\]
	Since $\mathsf{T}(v_i)=0$ for $1\leqslant i\leqslant k$ because $v_i\in N(\mathsf{T})$ we have:
	\begin{align*}
		R(\mathsf{T}) & = \text{span}(\left\{ \mathsf{T}(v_{k+1}),\mathsf{T}(v_{k+2}),\dotsc,\mathsf{T}(v_n) \right\})\\
		     & = \text{span}(S).
	\end{align*}
	Now to prove that $S$ is linearly independent, we consider the equation:
	\[
		a_{k+1}\mathsf{T}(v_{k+1}) + a_{k+2}\mathsf{T}(v_{k+2}) + \dotsb + a_n\mathsf{T}(v_n) = 0,\quad a_{k+1},a_{k+2},\dotsc,a_n\in F
	.\]
	And since $\mathsf{T}$ is linear, we can rewrite the equation as:
	\[
		\mathsf{T}(a_{k+1}v_{k+1}+a_{k+2}v_{k+2}+\dotsb+a_nv_n) = 0
	.\]
	Therefore:
	\[
		a_{k+1}v_{k+1}+a_{k+2}v_{k+2}+\dotsb+a_nv_n \in N(\mathsf{T})
	.\]
	Since $\left\{ v_1,v_2,\dotsc,v_k \right\}$ is a basis for $N(\mathsf{T})$, there exist $c_1,c_2,\dotsc,c_k\in F$ such that:
	\[
		a_{k+1}v_{k+1}+a_{k+2}v_{k+2}+\dotsb+a_nv_n = c_1v_1+c_2v_2+\dotsb+c_kv_k
	.\]
	Otherwise rewritten:
	\[
	-c_1v_1-c_2v_2-\dotsb-c_kv_k+a_{k+1}v_{k+1}+a_{k+2}v_{k+2}+\dotsb+a_nv_n = 0
	.\]
	And since $\beta$ is a basis for $\mathsf{V}$ and is linearly independent, the coefficients of the last equation must all be 0.
	Thus $S$ is a linearly independent set and is a basis for $R(\mathsf{T})$, and therefore:
	\[
		\text{rank}(\mathsf{T}) = \text{dim}(R(\mathsf{T})) = n-k
	.\]

	\noindent
	\underline{Case 2}: $k=n$.

	In this case, the image of every vector in $\mathsf{V}$ is the zero vector in $\mathsf{W}$, so that $R(\mathsf{T})=\left\{ 0 \right\}$, and therefore $\text{dim}(R(\mathsf{T}))=\text{dim}(\left\{ 0 \right\})=0$.
	The statement of the theorem is true for this case.

	\bigbreak
	\noindent
	\underline{Case 3}: $k=0$.
	In this case $N(\mathsf{T})=\left\{ 0 \right\}$, so the nullity is 0.
	If $\left\{ v_1,v_2,\dotsc,v_n \right\}$ is a basis for $\mathsf{V}$, then by the theorem above we have:
	\[
		R(\mathsf{T}) = \text{span}(\left\{ \mathsf{T}(v_1),\mathsf{T}(v_2),\dotsc,\mathsf{T}(v_n) \right\} )
	.\]
	And a similar argument to the one above shows that:
	\[
		\left\{ \mathsf{T}(v_1),\mathsf{T}(v_2),\dotsc,\mathsf{T}(v_n) \right\}
	\]
	is linearly independent. Thus $\text{dim}(R(\mathsf{T}))=n=\text{dim}(\mathsf{V})$, and the result also holds in this case.
\end{proof}
\begin{exmp}
	$\mathsf{T}:P_4(\mathbb{R})\mapsto P_2(\mathbb{R})$, linear, defined by:
	\[
		\mathsf{T}(p(x))=p^{(2)}(x)
	.\]
	Find a basis for $N(\mathsf{T})$ as well as for $R(\mathsf{T})$.
	\begin{sol}
		For $N(\mathsf{T})$, by definition:
		\[
			p(x) = a + bx + cx^2 + dx^3 + ex^{4}\in N(\mathsf{T}) \iff \mathsf{T}(p(x)) = 0
		.\]
		Or equivalently:
		\[
			p^{(2)}(x) = 2c + 6dx + 12ex^2 = 0,\ \forall x\in\mathbb{R}\iff c=d=e=0
		.\]
		Thus:
		\[
			p\in N(\mathsf{T})\iff p(x)=a+bx,\ a,b\in\mathbb{R}
		.\]
		This shows that $N(\mathsf{T})$ consists of all polynomials of degree at most 1.
		So $N(\mathsf{T})=P_1(\mathbb{R})$.
		Hence, $\left\{1,x\right\}$ is a basis for $N(\mathsf{T})$, and $\mdim(N(\mathsf{T}))=2$.
		\bigbreak
		\noindent
		For $R(\mathsf{T})$: since $\mdim(P_4(\mathbb{R}))=5$, by the rank-nullity theorem, we have:
		\[
			2 + \mdim(R(\mathsf{T})) = 5\implies\mdim(R(\mathsf{T})) = 3
		.\]
		Now we consider the standard basis $\beta=\left\{1,x,x^2,x^3,x^{4}\right\}$ for $P_4(\mathbb{R})$ to get:
		\begin{align*}
			R(\mathsf{T}) & = \mspan \left(\left\{\mathsf{T}(1),\mathsf{T}(x),\mathsf{T}(x^2),\mathsf{T}(x^3),\mathsf{T}(x^{4})\right\}\right)\\
			     & = \mspan \left(\left\{0,0,2,6x,12x^2\right\}\right)\\
			     & = \mspan \left(\left\{2,6x,12x^2\right\}\right)
		\end{align*}
		Three vectors generate $R(\mathsf{T})$, and hence since $\mdim(R(\mathsf{T}))=3$, these vectors form a basis for $R(\mathsf{T})$.
		Observe that $R(\mathsf{T})$ is just $P_2(\mathbb{R})$.
	\end{sol}
\end{exmp}
