completing a square If I have a density function of the form $p(x) \propto \exp(−q(x)/2)$ where $q(x)$ has
the following quadratic function
$$q(x)=x^Tx+y^Ty-[x^TA+y^TB][A^TA+B^TB+\beta\mathbb{I}]^{-1}[A^Tx+B^Ty]$$
where $\mathbb{I}$ is an identity matrix and $\beta$ is a positive scalar value. Is there any way for completing the square and specially using the Sherman–Morrison–Woodbury formula to simplify the covariance matrix?
 A: Density function
To reduce the clutter, let $M = (A^T A + B^T B + \beta I)^{-1}$. Plug this into the original expression for $q(x)$:
$$q(x) = x^T x + y^T y
- (x^T A + y^T B) M (A^T x + B^T y) \tag{1}$$
Rewrite as:
$$q(x) =
x^T(I - A M A^T) x
- 2 x^T A M B^T y
+ y^T (I - B M B^T) y \tag{2}$$
Complete the square:
$$q(x) = (x - h)^T S (x - h) + k \tag{3}$$
where $k$ is a constant (doesn't depend on $x$) and:
$$S = I - A M A^T \tag{4}$$
$$h = S^{-1} A M B^T y \tag{5}$$
Plug equation $(3)$ back into the density function. It's clear we have a Gaussian distribution with mean $h$ and inverse covariance matrix $S$:
$$p(x) \propto \exp \left(
  -\frac{1}{2} (x-h)^T S (x-h)
\right) \tag{6}$$
Covariance matrix
To write out the covariance matrix $S^{-1}$, start from equation $(4)$ and use the Woodbury formula:
$$S^{-1} = I - A (A^T A - M^{-1})^{-1} A^T \tag{7}$$
Plug in the expression for $M$ and simplify:
$$S^{-1} =
I + A (B^T B + \beta I)^{-1} A^T \tag{8}$$
Mean
To write out the mean $h$, plug expression $(7)$ for $S^{-1}$ into expression $(5)$ for $h$:
$$h = \Big[ I - A (A^T A - M^{-1})^{-1} A^T \Big] A M B^T y \tag{9}$$
$$= A \Big[ I - (A^T A - M^{-1})^{-1} A^T A \Big] M B^T y \tag{10}$$
Rewrite the identity matrix as $I = (A^T A - M^{-1}) (A^T A - M^{-1})^{-1}$, then crank through some algebra to obtain:
$$h = A (M^{-1} - A^T A)^{-1} B^T y \tag{11}$$
Plug in the expression for $M$ and simplify:
$$h = A (B^T B + \beta I)^{-1} B^T y \tag{12}$$
