Are there non-diagonal matrices in $\operatorname{SL}_2$ closest to $\sigma \operatorname{Id}$? $\newcommand{\dist}{\operatorname{dist}}$
$\newcommand{\id}{\operatorname{Id}}$
$\newcommand{\diag}{\operatorname{diag}}$
$\newcommand{\SL}{\operatorname{SL}}$
$\newcommand{\SO}{\operatorname{SO}_2}$
$\newcommand{\sym}{\operatorname{Sym}}$
$\newcommand{\sig}{\sigma}$
$\newcommand{\tr}{\operatorname{tr}}$
$\newcommand{\M}{\mathcal{M}}$
This is a self-answered question. Alternative solutions are welcomed, of course.
Set $\Sigma=\begin{pmatrix} \sig & 0 \\\ 0 & \sig\end{pmatrix}$, $\sig >0$.
Question:
Find all the non-diagonal closest matrices to $\Sigma$ in $$\SL_2(\mathbb{R})=\{X \in M_{2}(\mathbb{R})\,\,|\, \, \det X=1 \}.$$
"Closest" here means w.r.t the Euclidean distance.

I was very surprised to find out that there exist such non-diagonal minimizers, since my initial guess was that they all should be diagonal:
Intuitively, we do not gain anything from inserting "rotations", since the original $\Sigma$ is already "aligned", i.e. diagonal. (I am thinking of SVD here). However, this heuristic turns out to be wrong.

I state here the solution:
For $\sig \ge 2$ there are only diagonal minimizers.
For $\sig=2$, the identity is the unique minimizer.
For any $\sig \in (0,2)$, there exist both diagonal and non-diagonal minimizers.
The set of non-diagonal minimizers is the following one-parametrized (continuous) family:
$$
\mathcal{M}=\{  \begin{pmatrix} a & b \\ b & \sig-a \end{pmatrix} \,\,|\,\, \frac{1}{2}\big(\sig-\sqrt{\sig^2-4}\big)< a < \frac{1}{2}\big(\sig+\sqrt{\sig^2-4}\big), \,\, b=\pm \sqrt{a(\sig-a)-1}\}.
$$
The endpoints of this domain, where $a=\frac{1}{2}(\sig\pm\sqrt{\sig^2-4})$, correspond to diagonal matrices.
Comment:
$\mathcal{M}$ can be characterized geometrically:
Let $(\sig_1,\sig_2)$ be a minimizer of the extremal problem $\min_{y_1y_2=1}(\sig-y_1)^2+(\sig-y_2)^2$:
$$(\sig-\sig_1)^2+(\sig-\sig_2)^2=\min_{y_1y_2=1}(\sig-y_1)^2+(\sig-y_2)^2.$$
Then $\mathcal{M}$ is exactly the set of symmetric matrices having singular values $\sig_1,\sig_2$ and positive trace and determinant (which must be $1$, as $\sig_1 \sig_2=1$).
Indeed, for $\sig \ge 2$, one can show that
$$
\sig_{1,2}=\frac{1}{2}(\sig\pm\sqrt{\sig^2-4}),
$$
and thus
$$
\sig_1^2+\sig_2^2=\sig^2-2, \,\,\, \sig_1\sig_2=1. \tag{5}
$$
$\sig_1,\sig_2$ are determined by equation $(5)$.

We now show that $\M=\{X \in \sym \, | \, \sig_i(X)=\sig_i , \,\, \tr(X)>0, \det(X)>0\}$.
Let $X= \begin{pmatrix} a & b \\ b & d \end{pmatrix} \in \M$. Then $\tr(X)=\sig>0$ and $\det X=1 \Rightarrow b^2=ad-1$, thus
$$
\|X\|^2=a^2+d^2+2b^2=a^2+d^2+2(ad-1)=(a+d)^2-2=\sig^2-2 \Rightarrow
$$
$$\sig_1(X)^2+\sig_2(X)^2 =\|X\|^2=\sig^2-2,$$
i.e. $\sig_i(X)$ satisfy equation $(5)$, hence they are equal to $\sig_1,\sig_2$.
On the converse direction, if $X$ is symmetric, $\tr(X)>0, \det(X)>0$, and $\sig_i(X)=\sig_i$, then $X$ can be written as
$
X= \begin{pmatrix} a & b \\ b & d \end{pmatrix}.
$
Now, $\det X=1 \Rightarrow b^2=ad-1$ and on the one hand,
$$
\|X\|^2=a^2+d^2+2b^2=a^2+d^2+2(ad-1)=(a+d)^2-2.
$$
On the other hand,
$$\|X\|^2=\sig_1(X)^2+\sig_2(X)^2 =\sig_1^2+\sig_2^2=\sig^2-2,$$
thus $(a+d)^2=\sig^2$, i.e. $\tr(X)=a+d=\pm \sig$. Since we assumed that $\tr(X)>0, \sig>0$, we must have $a+d=\sig$, so $X \in \M$ as required.
 A: $\newcommand{\dist}{\operatorname{dist}}$
$\newcommand{\id}{\operatorname{Id}}$
$\newcommand{\diag}{\operatorname{diag}}$
$\newcommand{\SL}{\operatorname{SL}}$
$\newcommand{\SO}{\operatorname{SO}_2}$
$\newcommand{\sig}{\sigma}$
Set $
G(\sig):=\dist^2(\Sigma,\SL_2).$
Let $\SL^s$ be the set of matrices having determinant $s$. Then:
$$
\dist^2(\Sigma,\SL_2)=\dist^2(\sig \id,\sig \SL^{\frac{1}{\sig^2}})=\sig^2\dist^2(\id,\SL^{\frac{1}{\sig^2}}).
$$
Set
$$F(s):=\dist^2(\id,\SL^s)=\dist^2(\SO,\SL^s),$$
where in the last equality we used the orthogonal invariance of both the norm and $\SL^s$. We showed
$$
G(\sig)=\sig^2 F(\frac{1}{\sig^2}). \tag{1}
$$
$F$ can be computed explicitly:
$$
F(s) =
\begin{cases}
2(\sqrt{s}-1)^2,  & \text{ if  }\, s \ge \frac{1}{4} \\
1-2s, & \text{ if  }\, s \le \frac{1}{4}
\end{cases}
$$
This implies
$$
\tag{2}
G(\sig) =
\begin{cases}
2(\sig-1)^2,  & \text{ if  }\, \sig \le 2 \\
\sig^2-2, & \text{ if  }\, \sig \ge 2
\end{cases}
$$

The nature of the minimizers:
Let $X \in \SL_2$ satisfy $\dist(\Sigma,\SL_2)=d(\Sigma,X).$ Lagrange's multipliers gives $\Sigma= X-\lambda X^{-T}$ for some real $\lambda$.
The analysis here shows that either $X$ is diagonal, or $X= \begin{pmatrix} a & b \\ b & d \end{pmatrix}$ for some real $a,b,d$ satisfying $$\sigma = a+d \,\,\text{ and }\,\,ad-b^2=\det X=1.$$
Since $ad=b^2+1>0,\,\,\,$ $a,d$ have the same sign, and since $a+d=\sig>0$ this forces $a,d$ to be positive, so $$0<a,d<a+d=\sig. \tag{3}$$
By the AM-GM inequality,
$$
\frac{\sig}{2}=\frac{a+d}{2} \ge \sqrt{ad} = \sqrt{b^2+1} \ge 1,
$$
so such candidates $X$ may exist only when $\sig \ge 2$.
Moreover, $b^2=ad-1 \Rightarrow ad \ge 1$. Substituting $d=\sig-a$, we get $a(\sig-a) \ge 1$. Solving this inequality, we obtain
$$
\tag{4}
0<\frac{1}{2}\big(\sig-\sqrt{\sig^2-4}\big)\le a \le \frac{1}{2}\big(\sig+\sqrt{\sig^2-4}\big)<\sig.
$$
Let $\sig \ge 2$ then.
Consider inequalities $(3)$ and $(4)$. We showed that every non-diagonal minimizer $X$ lies in
$$
\mathcal{M}=\{  \begin{pmatrix} a & b \\ b & \sig-a \end{pmatrix} \,\,|\,\, \frac{1}{2}\big(\sig-\sqrt{\sig^2-4}\big)\le a \le \frac{1}{2}\big(\sig+\sqrt{\sig^2-4}\big), \,\, b=\pm \sqrt{a(\sig-a)-1}\}.
$$
We now verify that every element of $\mathcal{M}$ is indeed a minimizer:
Let $X \in \mathcal{M}$; write $d=\sig-a$. Then
$$
d^2(\Sigma,X)=(\sig-a)^2+(\sig-d)^2+2b^2=a^2+d^2+2(ad-1)=(a+d)^2-2=\sig^2-2=G(\sig),
$$
where the last equality follows from equation $(2)$, as $\sig \ge 2$.

Note that for $\sig =2$, the solutions set reduces to $\mathcal{M}=\{\id\}$.
