Why bother writing a given integer as the sum of two squares? Does this have any practical application? Is there an introduction on a first year number theory course which would motivate students to study the conversion of a given integer to sums of two squares?

  • 3
    $\begingroup$ Natural curiosity about patterns in numbers isn't enough of a motivation? As far as I know, writing an integer as a sum of squares doesn't have any particular use; the interesting question is why only some integers and not others can be written in that way at all. $\endgroup$ – Daniel Hast Jun 9 '15 at 17:01
  • 2
    $\begingroup$ right triangle side lengths? $\endgroup$ – celeriko Jun 9 '15 at 17:36

The following two things do not match exactly the request but are perhaps close enough:

  • Writing an $n$ as a difference of two square is useful as it yields a typically nontrivial factor of $n$, as $n = x^2 - y^2 = (x+y)(x-y)$. This is called Fermat's factorization method and is still relevant as algorithm, in fact SQUFOF which is a development of this idea is one of the best factorization algorithms today. Note that it was Fermat who also considered the sum of two squares problem. (A sum of two squares can be used to get a factorization in the Gaussian integers but this might not be relevant in your context.)

  • The fact that every non-negative integer can be written as the sum of four squares is relevant as it allows for an easy intrinsic characterization of the non-negative integers among all integers; the non-negative integers are definable by the formula $x_1^2 +x_2^2 + x_3^2 + x_4^2$. This is sufficiently relevant that it appears in some courses on mathematical logic.

The first could be used as motivation by using this as a "trick" to find factors of some large numbers. Then, one can discuss if this always works and so on.

The latter could be presented as a challenge: find a multivariate polynomial in the integers that yields only non-negative integers as values yet all non-negative integers.


I can see several general answers to "why study such concept or procedure?", let me discuss them in the case of writing an integer as a sum of two squares, and when it is possible to do so.

The concept or procedure may make use of tools students ought to learn or practice. This is a good motivation for a teacher: set ourselves a nice goal to examplify the use of what have just been learned. This may not be enough to motivate student though, so let's consider other approaches.

The concept may be relevant to other domains than mathematics ("real-life" is a bit overrated in my opinion, hence the broader interpretation of applicability). As far as I know, this does not really apply here. I may be wrong, but I think it detrimental to try to force a concept into unrealistic or far-fetched applications. Doing so indeed enforces the idea that applications outside mathematics is the sole purpose of any relevant mathematical concept, and at the same time shows that the concept at hand does not really meet this expectation. Far-fetched applications are ok as long as they are presented as such, and not taken as a justification for the concept.

The concept may be relevant to other mathematical domains. Here, the geometry comes to mind (Pythagorean theorem), as was pointed out in other answers.

The concept my be relevant to other questions in the same mathematical domain, and this a key point here. I think it important to fit the question into a more general framework, here diophantine equations:

Given an polynomial equation (or system of equations) with integer coefficients, when are there integer solutions? How many of them?

This theme is huge, and covers both very simple concepts that students already encountered at this stage, up to the most sophisticated arithmetic geometry. For example, the equation $ax=b$ in the unknown $x$ with integer coefficients $a,b$ has a solution precisely when $a$ divides $b$. The concept we are discussing is simply to decide for which parameter $n$ does the equation $x^2+y^2=n$ have a solution. Very similar looking equations are famous: e.g. $x^3+y^3=z^3$, or the more general Fermat equation $x^n+y^n=z^n$ which have no non-trivial integer solutions for $n>2$ thanks to Wiles' theorem. Finding all solutions of $x^2+y^2=z^2$ is a nice problem (well-understood for a long time), elliptic curves and their group structure come next, etc. There is an endless stream of beautiful mathematics behind this, and it would be a shame not to use it to motivate student (e.g. showing them a similar-looking problem to which no one in the world knows the answer to).

  • $\begingroup$ @RoryDaulton: yes, thanks. $\endgroup$ – Benoît Kloeckner Jun 12 '15 at 9:24

Following @celeriko's suggestion:

If $n$ can be written as $a^2 + b^2$ for integers $n,a,b$, then $\sqrt{n}$ can be constructed as the hypotenuse of a right triangle with base and altitude $a$ and $b$.

For example, if you needed to measure out $\sqrt{13}$, you could do so with $3^2 + 2^2=9+4$.

One can imagine physical construction tasks that require measuring $\sqrt{n}$, e.g., rigidifying an $a \times b$ rectangle with a diagonal brace, or constructing a square of area $n$.


You are given a box of square tiles all of the same size. As it happens, there are m different colors of tile. The mean number of tiles of a color is n. (Some have a couple more, some less.) You are supposed to make a pattern with the tiles, using up all or almost all of them, and according to a particular theme. If n were a square number, say n=k^2, no problem: you could arrange the tiles into m squares (or almost squares) and combine the result into an arrangement that happens to fit the theme. Unfortunately, n is far from a square. What to do?

It so happens that n is the sum of two squares. You can now make a polygonal shape which are two squares adjacent to one another, in such a way that the shapes of m different colors tile. The variation is acceptable, and you have saved the day.

One might argue that this is somewhat contrived of an example. However, people have been coming up with contrivances since before they were able to make tiles and arrange them into patterns. There are reasons within mathematics to study decompositions of integers into sums of squares, and there are applications of this work. Two-square tiling is just one; creating a logo involving pairs of rational squares is another.

Gerhard "Even More Creative After Coffee" Paseman, 2015.06.09

  • 1
    $\begingroup$ +1 for outside of the box $\endgroup$ – celeriko Jun 10 '15 at 3:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.