Solution (source code)

= Solution

Expansion of the <determinant> along the first row gives
$$
\det M=2x^2-(3-x)+2x(1-x)=3(x-1).
$$
Thus \b[the <matrix> is invertible exactly when $x\ne1$]. The minor formed from the first two rows and the last two columns is $-1$, independently of $x$, so the <matrix rank> is always at least two. Therefore
$$
\boxed{\operatorname{rank}M=\begin{cases}3,&x\ne1,\\2,&x=1.\end{cases}}
$$
Taking cofactors and transposing them gives the <adjugate matrix>
$$
\boxed{\operatorname{adj}M=
\begin{pmatrix}
2x&2x-1&-1\\
x-3&x-2&1\\
2x(1-x)&2(1-x^2)&x-1
\end{pmatrix}}.
$$
The <adjugate identity> $M\operatorname{adj}M=(\det M)I$ then gives
$$
\boxed{M^{-1}=\frac1{3(x-1)}\operatorname{adj}M\quad(x\ne1)}.
$$
In particular, the singular case has rank two, rather than a further exceptional rank-one value.