Integers which are squared norm of 2 by 2 integer matrices

Question: Which integers are of the form $\Vert A \Vert^2$, with $A \in M_2(\mathbb{Z})$.

The code below provides the first such integers: $0, 1, 2, 4, 5, 8, 9, 10, 13, 16, 17, 18, 20, 25, 26$.
By searching this sequence on OEIS, we find: "Numbers that are the sum of 2 squares" A001481.

Are these integers exactly those which are the sum of two squares ?


Research

First, $\Vert A \Vert^2$ is the largest eigenvalue of $A^*A$, so for $A = \left( \begin{matrix} a & b \cr c & d \end{matrix} \right)$ and $a,b,c,d \in \mathbb{Z}$, so we get:
$$\Vert A \Vert^2 = \frac{1}{2} \left(a^2+b^2+c^2+d^2+\sqrt{(a^2+b^2+c^2+d^2)^2 - 4(ad-bc)^2}\right)$$

Obviously, every sum of two squares is of the expected form , because by taking $c=d=0$, we get $\Vert A \Vert^2=a^2+b^2$.

Then it remains to prove that there is no other integer (if true).

Now, recall that:

Sum of two square theorem
An integer greater than one can be written as a sum of two squares if and only if its prime decomposition contains no prime congruent to 3 (mod 4) raised to an odd power.

By taking $c=ra$ and $d=rb$, we get that $\Vert A \Vert^2 = (r^2+1)(a^2+b^2)$, which is also a sum of two square because the following equation occurs (proof here):
$$r^2 \not \equiv -1 \mod 4s+3$$

A necessary condition for $\Vert A \Vert^2$ to be an integer, is that $(a^2+b^2+c^2+d^2)^2 - 4(ad-bc)^2$ must be a square $X^2$, so that $(X,2(ad-bc),a^2+b^2+c^2+d^2)$ is a Pythagorean triple, so must be of the form $(k(m^2-n^2),2kmn,k(m^2+n^2)$, and then $\Vert A \Vert^2 = km^2$. So it remains to prove that $k$ must be a sum of two squares.


sage: L=[]
....: for a in range(-6,6):
....:     for b in range(-6,6):
....:         for c in range(-6,6):
....:             for d in range(-6,6):
....:                 n=numerical_approx(matrix([[a,b],[c,d]]).norm()^2,digits=10)
....:                 if n.is_integer():
....:                     L.append(int(n))
....: l=list(set(L))
....: l.sort()
....: l[:20]
....:
[0, 1, 2, 4, 5, 8, 9, 10, 13, 16, 17, 18, 20, 25, 26, 29, 32, 34, 36, 37]

Solution 1:

Yes. If $A$ is a $2\times2$ integer matrix such that $n=\|A\|^2$ is an integer, $n$ must be the sum of two integer squares. Conversely, if $n$ is the sum of two integer squares, then $n=\|A\|^2$ for some $2\times2$ integer matrix $A$.

Proof. Suppose $A$ is a $2\times2$ integer matrix such that $n=\|A\|^2$ is an integer. We want to show that $n$ is the sum of two integer squares. This is clearly true if $n$ is $0$ or $1$. Suppose $n>1$. Then $A^TA-nI$ is a singular matrix with integer entries. Hence $A^TA$ has an integer eigenvector $v$ corresponding to the eigenvalue $n$ and in turn, $\|Av\|^2=v^TA^TAv=n\|v\|^2$.

Since both $\pmatrix{x\\ y}:=v$ and $\pmatrix{a\\ b}:=Av$ are integer vectors, the previous equality implies that $n(x^2+y^2)=a^2+b^2$. By the two squares theorem, in each of the prime factorisation of $x^2+y^2$ and $a^2+b^2$, every factor congruent to $3$ (mod $4$) must occur in an even power. Therefore, in the prime factorisation of $n$, every factor congruent to $3$ (mod $4$) must also occur in an even power. Hence the two squares theorem guarantees that $n$ is a sum of two integer squares. This proves one direction of our assertion.

For the other direction, suppose $n=a^2+b^2$ for some two integers $a$ and $b$. Then $\|A\|^2=n$ when $A=\pmatrix{a&-b\\ b&a}$ or $\pmatrix{a&0\\ b&0}$.