# Solution of a quadratic diophantine equation

I try to solve the Diophantine quadratic equation: $$X^2+Y^2+Z^2=3W^2.$$ Obviously, there is a non-trivial solution: $(1,1,1,1)$. So I tried to apply Jagy's method: Solutions to $ax^2 + by^2 = cz^2$ . I consider integers $t,p,q,r$ and the point $P=(1,1,1)$ of the sphere $X^2+Y^2+Z^2=3$. I look for a second point on the sphere in the form $(1+pt,1+qt,1+rt)$. That gives $p^2t+q^2t+r^2t+2p+2q+2r=0$. This implies that $$\left(1-\frac{2p(p+q+r)}{p^2+q^2+r^2},1-\frac{2q(p+q+r)}{p^2+q^2+r^2},1-\frac{2r(p+q+r)}{p^2+q^2+r^2}\right)$$ is a rational point of the sphere $X^2+Y^2+Z^2=3$. But what to do with that? Thanks in advance.

• This at least gives you that there are an infinite family of solutions $W=p^2+q^2+r^2$ and you can find $X$ and $Y$ and $Z$ by replacing in the equation. I will also say that we can generate all solutions (not necessarly using polynoials), why? actually there is a method to genrate all solutions for the equation: $$x_1^2+\cdots+x_9^2=y^2$$ and using this and multipliying the equation by $3$ you have just to add some equality constraints to the solutions – Elaqqad Jul 23 '15 at 21:51
• It is better to use the formula in the General form. math.stackexchange.com/questions/1127654/… When other factors - to determine the existence of solutions should be considered equivalent form. – individ Jul 24 '15 at 4:14

very good. It is after this that people get careless, stopping before getting ALL PRIMITIVE solutions. So far, with $\gcd(p,q,r) =1,$ we have $$\left(1-\frac{2p(p+q+r)}{p^2+q^2+r^2},1-\frac{2q(p+q+r)}{p^2+q^2+r^2},1-\frac{2r(p+q+r)}{p^2+q^2+r^2}\right)$$ is a rational point on the sphere, $x^2 + y^2 + z^2 = 3,$ or $x^2 + y^2 + z^2 = 3 \cdot 1^2.$ Next, we multiply through by the denominator (and place that as $W$) and see how we are doing:

with $\gcd(p,q,r) = 1$ and $p+q+r \neq 0$ and $p+q+r \equiv 1 \pmod 2,$ $$\left( -p^2 + q^2 + r^2 -2rp-2pq, p^2 - q^2 + r^2 -2qr-2pq, p^2 + q^2 - r^2 - 2qr-2rp; p^2 + q^2 + r^2 \right).$$ Also, with $\gcd(i,j,k) = 1$ and $j \neq -i$ and $j+k \equiv 1 \pmod 2,$ $$\left( -2 i^2 + j^2 + k^2 - 4 i j, 2 i^2 - j^2 + k^2 - 2 j k - 2 k i - 2 i j, 2 i^2 - j^2 + k^2 + 2 j k + 2 k i - 2 i j; 2 i^2 + j^2 + k^2 \right)$$ The given recipe with $pqr$ cannot supply $11^2 + 5^2 + 1^2 = 3 \cdot 7^2,$ as $7$ is not the sum of three squares; indeed $p^2 + q^2 + r^2 \neq 7 \pmod 8.$ However, the recipe with $ijk$ gets it, with $i=1,j=2,k=1.$ In the computer runs below, I always take the absolute values of the resulting $x,y,z,w$ as well as putting $x,y,z$ in decreasing order.

What I like to do is a modest computer run, print out the solutions given by the quadruple above, with some bound $p^2 + q^2 + r^2 < 100$ for example, take the absolute values of the $X,Y,Z$ above and put them in numerical order. Then I make a separate computer run to just list $x^2 + y^2 + z^2 = 3 w^2$ with $x \leq y \leq z$ and order that by $w$ as well, and compare.

The main thing I can see ahead of time is that, if $p+q+r$ is even, then all four entries in the quadruple will be even, and we will want to divide out by $2.$ That will give us some of the missing solutions $W \equiv 7 \pmod 8.$

I will add more after I check some things.

Edit, part one: here are the solutions, ordered, with $w \leq 50.$ Turns out all the primitive solutions have all odd entries. As you can see, $w$ takes on the values $7,15,23,31$ and so on, that are not the sum of three squares.

    w         z    y    x
1         1    1    1
3         5    1    1
5         7    5    1
7        11    5    1
9        11   11    1
9        13    7    5
11        19    1    1
11        17    7    5
11        13   13    5
13        19   11    5
13        17   13    7
15        25    7    1
15        23   11    5
15        19   17    5
17        29    5    1
17        23   17    7
17        25   11   11
17        23   13   13
19        31   11    1
19        23   23    5
19        29   11   11
19        25   17   13
21        31   19    1
21        29   19   11
21        25   23   13
23        35   19    1
23        31   25    1
23        37   13    7
23        29   25   11
25        43    5    1
25        41   13    5
25        35   23   11
25        35   19   17
25        31   25   17
27        35   31    1
27        43   17    7
27        35   29   11
27        43   13   13
27        37   23   17
29        49   11    1
29        41   29    1
29        47   17    5
29        43   25    7
29        37   25   23
31        53    7    5
31        47   25    7
31        49   19   11
31        37   35   17
31        41   29   19
33        49   29    5
33        43   37    7
33        53   17   13
33        41   35   19
33        47   23   23
33        37   37   23
33        41   31   25
35        59   13    5
35        53   29    5
35        55   23   11
35        55   19   17
35        47   29   25
35        41   37   25
37        59   25    1
37        61   19    5
37        49   41    5
37        47   43    7
37        55   31   11
37        47   37   23
39        61   29    1
39        67    7    5
39        65   17    7
39        59   31   11
39        55   37   13
39        53   35   23
41        71    1    1
41        67   23    5
41        53   47    5
41        55   43   13
41        65   23   17
41        61   31   19
41        47   47   25
41        49   41   31
43        73   13    7
43        55   49   11
43        65   31   19
43        67   23   23
43        53   47   23
43        59   35   29
43        55   41   29
43        53   37   37
45        65   43    1
45        77   11    5
45        73   25   11
45        65   41   13
45        67   35   19
45        67   31   25
45        55   47   29
45        59   37   35
45        55   41   37
47        65   49    1
47        79   19    5
47        59   55   11
47        77   23   13
47        67   43   17
47        71   35   19
47        71   31   25
47        61   41   35
49        79   31    1
49        61   59    1
49        83   17    5
49        73   43    5
49        79   29   11
49        65   53   13
49        55   53   37
w         z    y    x


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Alrighty then, that worked well. Use the recipe above. Keep the quadruple if the $\gcd(w,x,y,z) = 1.$ The only additional step needed is, if $\gcd(w,x,y,z) = 2,$ simply divide through by $2.$ If the gcd was larger than $2,$ just throw it out! There is quite a lot of duplication, it would take a while to reduce that. Oh, it is necessary to let $|p|, |q|, |r|$ become larger than I had expected. the first run missed too much.

Might be worth emphasizing that the business of dividing through by $2$ can be made very official looking. We cannot have all three of $p,q,r$ even because the gcd of them is $1.$ So, we have one even and two odd, in order to get everything in the quadruple even. We can rewrite it all by the substitutions $$p = 2i, \; q = j + k, \; r = j - k,$$ then take $\gcd(i,j,k) = 1,$ work out the quadruple, and divide by the common factor of $2$ that will now be evident. Maybe I will type that in tomorrow, easy to make errors in such calculations.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

w         z    y    x        gcd        p    q    r
1         1    1    1         1         1    0    0
1         1    1    1         1         1    0    0
1         1    1    1         1         1    0    0
1         1    1    1         1         1    0    0
1         1    1    1         1         1    0    0
1         1    1    1         1         1    0    0
3         5    1    1         1         1    1   -1
3         5    1    1         1         1    1   -1
3         5    1    1         1         1   -1    1
3         5    1    1         1         1   -1    1
3         5    1    1         1         1   -1   -1
3         5    1    1         1         1   -1   -1
5         7    5    1         1         2    1    0
5         7    5    1         1         2   -1    0
9        11   11    1         1         2    2    1
9        11   11    1         1         2    2    1
9        13    7    5         1         2   -2    1
9        13    7    5         1         2   -2   -1
11        13   13    5         1         3   -1   -1
11        13   13    5         1         3   -1   -1
11        17    7    5         1         3    1   -1
11        17    7    5         1         3   -1    1
11        19    1    1         1         3    1    1
11        19    1    1         1         3    1    1
13        17   13    7         1         3    2    0
13        17   13    7         1         3   -2    0
17        23   13   13         1         3   -2   -2
17        23   13   13         1         3   -2   -2
17        23   17    7         1         4    1    0
17        23   17    7         1         4   -1    0
17        25   11   11         1         3    2    2
17        25   11   11         1         3    2    2
17        29    5    1         1         3    2   -2
17        29    5    1         1         3   -2    2
19        23   23    5         1         3    3    1
19        23   23    5         1         3    3    1
19        25   17   13         1         3   -3    1
19        25   17   13         1         3   -3   -1
19        29   11   11         1         3    3   -1
19        29   11   11         1         3    3   -1
21        25   23   13         1         4   -2   -1
21        31   19    1         1         4    2   -1
25        31   25   17         1         4    3    0
25        31   25   17         1         4   -3    0
27        37   23   17         1         5    1   -1
27        37   23   17         1         5   -1    1
27        43   13   13         1         5    1    1
27        43   13   13         1         5    1    1
29        37   25   23         1         4   -3   -2
29        41   29    1         1         5    2    0
29        41   29    1         1         5   -2    0
29        43   25    7         1         4    3    2
29        47   17    5         1         4   -3    2
29        49   11    1         1         4    3   -2
33        37   37   23         1         5   -2   -2
33        37   37   23         1         5   -2   -2
33        41   31   25         1         4   -4    1
33        41   31   25         1         4   -4   -1
33        47   23   23         1         4    4   -1
33        47   23   23         1         4    4   -1
33        53   17   13         1         5    2   -2
33        53   17   13         1         5   -2    2
35        41   37   25         1         5   -3   -1
35        53   29    5         1         5   -3    1
35        55   19   17         1         5    3    1
37        47   37   23         1         6    1    0
37        47   37   23         1         6   -1    0
41        47   47   25         1         4    4    3
41        47   47   25         1         4    4    3
41        49   41   31         1         5    4    0
41        49   41   31         1         5   -4    0
41        53   47    5         1         6   -2   -1
41        55   43   13         1         6    2   -1
41        61   31   19         1         6   -2    1
41        65   23   17         1         4   -4    3
41        65   23   17         1         4   -4   -3
41        67   23    5         1         6    2    1
41        71    1    1         1         4    4   -3
41        71    1    1         1         4    4   -3
43        53   37   37         1         5   -3   -3
43        53   37   37         1         5   -3   -3
43        67   23   23         1         5    3    3
43        67   23   23         1         5    3    3
43        73   13    7         1         5    3   -3
43        73   13    7         1         5   -3    3
45        55   41   37         1         5   -4   -2
45        65   43    1         1         5    4    2
45        73   25   11         1         5    4   -2
49        55   53   37         1         6   -3   -2
49        79   29   11         1         6   -3    2
49        83   17    5         1         6    3    2
w         z    y    x        gcd        p    q    r

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

w         z    y    x        gcd        i    j    k
1         1    1    1         1         0    1    0
1         1    1    1         1         0    1    0
1         1    1    1         1         0    1    0
1         1    1    1         1         0    1    0
1         1    1    1         1         0    1    0
1         1    1    1         1         0    1    0
3         5    1    1         1         1    0    1
3         5    1    1         1         1    0    1
3         5    1    1         1         1    1    0
3         5    1    1         1         1    1    0
5         7    5    1         1         0    1    2
5         7    5    1         1         0   -1    2
5         7    5    1         1         0    2    1
5         7    5    1         1         0    2   -1
7        11    5    1         1         1    1    2
7        11    5    1         1         1    2    1
7        11    5    1         1         1    2   -1
9        13    7    5         1         2    0    1
11        13   13    5         1         1    3    0
11        13   13    5         1         1    3    0
11        17    7    5         1         1    0    3
13        17   13    7         1         0    2    3
13        17   13    7         1         0   -2    3
13        17   13    7         1         0    3    2
13        17   13    7         1         0    3   -2
13        19   11    5         1         2    1    2
13        19   11    5         1         2   -1    2
13        19   11    5         1         2    2    1
13        19   11    5         1         2    2   -1
15        19   17    5         1         1   -2    3
15        25    7    1         1         1    3    2
15        25    7    1         1         1    3   -2
17        23   13   13         1         2    3    0
17        23   13   13         1         2    3    0
17        23   17    7         1         0    1    4
17        23   17    7         1         0   -1    4
17        23   17    7         1         0    4    1
17        23   17    7         1         0    4   -1
17        29    5    1         1         2    0    3
19        25   17   13         1         3    0    1
19        29   11   11         1         3    1    0
19        29   11   11         1         3    1    0
19        31   11    1         1         1    1    4
19        31   11    1         1         1    4    1
19        31   11    1         1         1    4   -1
21        29   19   11         1         2    2    3
21        29   19   11         1         2    3    2
21        29   19   11         1         2    3   -2
23        31   25    1         1         3    1    2
23        35   19    1         1         3   -1    2
23        37   13    7         1         3    2    1
23        37   13    7         1         3    2   -1
25        31   25   17         1         0    3    4
25        31   25   17         1         0   -3    4
25        31   25   17         1         0    4    3
25        31   25   17         1         0    4   -3
25        35   19   17         1         2   -1    4
25        35   23   11         1         2    4    1
25        35   23   11         1         2    4   -1
25        43    5    1         1         2    1    4
27        35   29   11         1         1    3    4
27        35   31    1         1         1   -3    4
27        37   23   17         1         1    0    5
27        43   17    7         1         1    4    3
27        43   17    7         1         1    4   -3
29        41   29    1         1         0    2    5
29        41   29    1         1         0   -2    5
29        41   29    1         1         0    5    2
29        41   29    1         1         0    5   -2
31        37   35   17         1         1   -2    5
31        41   29   19         1         3    2    3
31        41   29   19         1         3   -2    3
31        41   29   19         1         3    3    2
31        41   29   19         1         3    3   -2
31        49   19   11         1         1    2    5
31        53    7    5         1         1    5    2
31        53    7    5         1         1    5   -2
33        37   37   23         1         2    5    0
33        37   37   23         1         2    5    0
33        41   31   25         1         4    0    1
33        41   35   19         1         2   -3    4
33        43   37    7         1         2    3    4
33        47   23   23         1         4    1    0
33        47   23   23         1         4    1    0
33        53   17   13         1         2    0    5
35        55   23   11         1         3   -1    4
35        59   13    5         1         3    1    4
37        47   37   23         1         0    1    6
37        47   37   23         1         0   -1    6
37        47   37   23         1         0    6    1
37        47   37   23         1         0    6   -1
37        47   43    7         1         4    1    2
37        55   31   11         1         4   -1    2
37        59   25    1         1         4    2    1
37        59   25    1         1         4    2   -1
37        61   19    5         1         2    2    5
37        61   19    5         1         2    5    2
37        61   19    5         1         2    5   -2
39        59   31   11         1         1    1    6
39        59   31   11         1         1    6    1
39        59   31   11         1         1    6   -1
41        49   41   31         1         0    4    5
41        49   41   31         1         0   -4    5
41        49   41   31         1         0    5    4
41        49   41   31         1         0    5   -4
41        65   23   17         1         4    0    3
41        71    1    1         1         4    3    0
41        71    1    1         1         4    3    0
43        53   37   37         1         3    5    0
43        53   37   37         1         3    5    0
43        53   47   23         1         1    4    5
43        55   41   29         1         3    3    4
43        55   41   29         1         3    4    3
43        55   41   29         1         3    4   -3
43        55   49   11         1         1   -4    5
43        65   31   19         1         1    5    4
43        65   31   19         1         1    5   -4
43        73   13    7         1         3    0    5
45        59   37   35         1         2   -1    6
45        65   41   13         1         4   -2    3
45        67   31   25         1         4    3    2
45        67   31   25         1         4    3   -2
45        67   35   19         1         2    6    1
45        67   35   19         1         2    6   -1
47        59   55   11         1         1   -3    6
47        61   41   35         1         3   -2    5
47        65   49    1         1         3    5    2
47        65   49    1         1         3    5   -2
47        71   31   25         1         1    3    6
47        77   23   13         1         3    2    5
47        79   19    5         1         1    6    3
47        79   19    5         1         1    6   -3
49        61   59    1         1         2    4    5
49        65   53   13         1         2   -4    5
49        79   31    1         1         4    1    4
49        79   31    1         1         4   -1    4
49        79   31    1         1         4    4    1
49        79   31    1         1         4    4   -1
w         z    y    x        gcd        i    j    k

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


Not by the way, it appears I still do not have all primitive solutions here. Maybe i made a programming error, could be. But maybe I have not really completed the problem... some missing are $$3 \cdot 15^2 = 23^2 + 11^2 + 5^2, \; \; 3 \cdot 23^2 = 29^2 + 25^2 + 11^2, \; \; 3 \cdot 31^2 = 47^2 + 25^2 + 7^2.$$ What is true, but not very satisfying, is that the original recipe with $w = p^2 + q^2 + r^2$ does give an integer multiple of every solution. Therefore, if we take all of those quadruples $(x,y,z,w)$ and do not discard any, rather divide through every time by $\gcd(x,y,z,w),$ we really will get all primitive integral solutions. The bad news is that, unless we have an explicit bound on that gcd, we do not know how large we need to allow $|p|,|q|,|r|.$

In comparison, the parametrization for Pythagorean quadruples $x^2 + y^2 + z^2 = w^2$ that I actually like has four parameters instead of three, and is based on the quaternions, and proved to work (gives all primitive integer solutions), first proof by L. E. Dickson about 1920. That parametrization is just Lebesgue's identity lebesgue's identity

• I don't get your point. If $(x_0,y_0,z_0,w_0)$ is a solution of $X^2 + Y^2 + Z^2 = 3 W^2$ then $(ax_0,ay_0,az_0,aw_0)$ is a solution, too, for any $a \in \Bbb{Z}$. So we might just as well look for solutions with $\gcd(x,y,z,w) = 1$, which are in $1:1$ correspondence with the rational solutions of $X^2 + Y^2 + Z^2 = 3$. Does the formula derived by the OP give all those rational solutions (it seems unlikely, but I don't know how to confirm or deny this)? – A.P. Jul 24 '15 at 0:33
• @A.P., yes, the formula by the OP gives all rational points on the sphere. The version with the $w$ gives, up to multiplication by a constant, all rational solutions in $\mathbb Q^4.$ That's the rub. We want all primitive integer solutions, and one three-parameter formula does not give all. – Will Jagy Jul 24 '15 at 1:15
• @A.P., suggest you do this minor exercise, the OP did not write every word correctly. Given integers $p,q,r$ with $\gcd(p,q,r)=1,$ we set $(x,y,z) = (1+tp,1+tq,1+tr)$ and solve for the nonzero $t$ that gives a point in $x^2 + y^2 + z^2 = 3.$ It turns out that this $t \neq 0$ is rational, and so the point found has three rational coordinates. In turn, every rational point on that sphere is successfully found by this method. – Will Jagy Jul 24 '15 at 1:37
• @Jagy Thanks for your explanation. But can you explain why I found ALL the solutions on the sphere. Why did I not miss anyone? – joaopa Jul 24 '15 at 6:34
• @A.P., meanwhile, although neither book directly discusses stereographic projection, suggest store.doverpublications.com/0486466701.html and maa.org/publications/maa-reviews/the-sensual-quadratic-form which show my viewpoint – Will Jagy Jul 24 '15 at 19:15

This is called stereographic projection. It works in many interesting cases, and when the left hand side is an ellipsoid one gets nice positive definite denominators, always comforting.

Given a rational point $(S,T,U)$ with $S^2 + T^2 + U^2 = 3.$ We get a rational vector $$X = (S-1,T-1,U-1).$$ We find the least common denominator $\lambda \in \mathbb Z$ such that $$(\lambda(S-1),\lambda(T-1), \lambda(U-1) ) = (p,q,r) \in \mathbb Z^3$$ What is $\gcd(p,q,r)?$ If it is larger than $1,$ we can divide through by that to get a shorter integer vector. So, $\gcd(p,q,r)= 1.$

By construction, $$(1,1,1) + \frac{1}{\lambda}(p,q,r) = (1,1,1) + \frac{1}{\lambda} (\lambda(S-1),\lambda(T-1), \lambda(U-1) ) = (1,1,1) + (S-1,T-1,U-1) = (S,T,U)$$

Not sure anyone is paying attention, but this is, really, the better way to do this. By quaternions, with $q = a + bi+cj+dk,$ then $v = i+j+k,$ then $p = q v \bar{q}$ will also have $0$ as the real coefficient. And $p$ has the norm we want. Oh, below, i am writing $p = xi+yj+zk.$

$$x = a^2 + b^2 - c^2 - d^2 + 2 a c + 2 b c - 2 a d + 2 b d$$ $$y = a^2 - b^2 + c^2 - d^2 - 2 a b + 2 b c + 2 a d + 2 c d$$ $$z = a^2 - b^2 - c^2 + d^2 + 2 a b - 2 a c + 2 b d + 2 c d$$ $$w = a^2 + b^2 + c^2 + d^2$$

I checked this in PARI, will probably typeset in the morning. It is very likely that taking all possible orders and $\pm$ signs gives every primitive integer solution to $x^2 + y^2 + z^2 = 3 w^2,$ with the only restrictions being $\gcd(a,b,c,d) = 1$ and $a+b+c+d \equiv 1 \pmod 2.$