Is there a general form for the 1-sided right inverse? For a matrix $A\in\mathbb{R}^{r\times n}$ of rank $r$ with $r<n$ does there exist a general form for a right-inverse $\bar{A}$ such that $A\bar{A}=I_r$?
The most commonly used inverse I see in the literature is $\bar{A}=A^T\left(AA^T\right)^{-1}$, but clearly $\bar{A}=XA^T\left(AXA^T\right)^{-1}$ for $X$ an arbitrary $n\times n$ matrix would also suffice. 
Hence my question is, can all possible right-inverses of a rectangular, real valued matrix $A$ be expressed in this form? Or does there exist another general formulation of right-inverses?
 A: The matrix equation $AB=I$ with $B:=[b_1,\ldots,b_r]$ is equivalent to the set of linear systems
$$\tag{1}
Ab_i=e_i,
$$
where $e_i$ is the $i$th column of the $r\times r$ identity. Since $\mathrm{Im}(A^T)\oplus\mathrm{Ker}(A)=\mathbb{R}^n$, we can express $b_i$ as $b_i=A^Tc_i+d_i$, where $c_i\in\mathbb{R}^r$ and $d_i\in\mathrm{Ker}(A)$. Putting this to (1) gives the system for $c_i$:
$$
AA^Tc_i=e_i.
$$
Since $AA^T$ is nonsingular (in fact, positive definite), the system has always as solution. Hence
$$
b_i=A^T(AA^T)^{-1}e_i+d_i
$$
and
$$\tag{2}
B=A^T(AA^T)^{-1}+D,
$$
where $D$ is an arbitrary $n\times r$ matrix such that $AD=0$. With $D=0$, one obtains the Moore-Penrose pseudoinverse.
Note that $I-A^T(AA^T)^{-1}A$ is an orthogonal projector onto $\mathrm{Ker}(A)$. So a $D$ can be expressed also as $D=[I-A^T(AA^T)^{-1}A]Z$, where $Z$ is now an arbitrary $n\times r$ matrix. This turns (2) to
$$
B=A^T(AA^T)^{-1}+[I-A^T(AA^T)^{-1}A]Z=A^T(AA^T)^{-1}(I-AZ)+Z.
$$
Remark: Not all right inverses can be written as $B=XA^T(AXA^T)^{-1}$. You can again add any matrix $D$ such that $AD=0$ to $XA^T(AXA^T)^{-1}$  and obtain a right inverse. In addition, $XA^T(AXA^T)^{-1}$ does not need to be well defined as $AXA^T$ can be singular even if $X$ is nonsingular and $A$ is of rank $r<n$.
