Find six vectors with rational entries under constraints?

Define six vectors v[i] with i=1,2,3...,6. Each v[i] is six dimensional and all entries in the vectors should be Rationals. Additionally, the entries should satisfy the following constraints:

Table[ (v[i][[1]])^2 == Sum[(v[i][[j]])^2,{j,2,6}] ,{i,1,6}]


and

Table[ Sum[v[j][[i]],{j,1,6}] == 0 ,{i,1,6}]


and sufficiently many entries should be non-zero (one or two zeros are fine, but mostly non-zero entries). I tried

FindInstance[constraints,components,Rationals]


with proper formatting for constraints and components, but this computation goes on indefinitely without ever producing a result. Is it possible to find at least one such example for these six vectors using Mathematica?

Edit

I should also mention that solutions of pairwise anti-parallel vectors are trivial in the sense that they do not span a big enough space in respect to the second set of constraints above. Only non-collinear solutions are of interest.

Edit2

Added a solution below that produces an infinite set of such vectors, while non-trivially spanning the sub-space defined by the two constraints.

We can set up your problem as follows, including the requirement that all vector elements be rational and non-zero:

matrix = Table[Indexed[a, {i, j}], {i, 1, 6}, {j, 1, 6}];

instance = FindInstance[
Flatten@{
Equal @@@ Table[{matrix[[i, 1]]^2, Total[matrix[[i, 2 ;;]]^2]}, {i, 1, 6, 1}],
Table[Indexed[a, {i, j}] != 0, {i, 1, 6}, {j, 1, 6}]
},
Flatten@Table[Indexed[a, {i, j}], {i, 1, 6}, {j, 1, 6}],
Rationals
]


FindInstance::nsmet: The methods available to FindInstance are insufficient to find the requested instances or prove they do not exist. >>

However, if we relax those requirements to allow at least some of those elements to be zero, e.g. by removing the constraints on $j=6$ as in the following very slightly modified code, we then receive an answer:

instance = FindInstance[
Flatten@{
Equal @@@ Table[{matrix[[i, 1]]^2, Total[matrix[[i, 2 ;;]]^2]}, {i, 1, 6, 1}],
Table[Indexed[a, {i, j}] != 0, {i, 1, 6}, {j, 1, 5}](*j only up to 5!*)
},
Flatten@Table[Indexed[a, {i, j}], {i, 1, 6}, {j, 1, 6}],
Rationals
]


We can check that this answer satisfies our requirements:

ReplaceAll[
Equal @@@ Table[{matrix[[i, 1]]^2, Total[matrix[[i, 2 ;;]]^2]}, {i, 1, 6, 1}],
instance
]

(* Out: {{True, True, True, True, True, True}} *)


It may also be possible to apply less relaxed requirements, e.g. allowing for only one element to be zero overall, etc.

• Unfortunately the matrix you find satisfies only the first set of constraints, but fails for the second, as can be seen by: mat = matrix /. instance[[1]]; and then Table[Sum[mat[[j, i]], {j, 1, 6}] == 0, {i, 1, 6}] Sep 3 '15 at 2:34
• You're right, I didn't include that part. What happens if you include those constraints in my code? Sep 3 '15 at 2:39
• With the additional constraints it calculates indefinitely, never giving out a result. (Running for several minutes already.) instance = FindInstance[ Flatten@{Flatten@{Equal @@@ Table[{matrix[[i, 1]]^2, Total[matrix[[i, 2 ;;]]^2]}, {i, 1, 6, 1}], Table[ Indexed[a, {i, j}] != 0, {i, 1, 6}, {j, 1, 5}](*j only up to 5!*)}, Table[Sum[matrix[[j, i]], {j, 1, 6}] == 0, {i, 1, 6}]}, Flatten@Table[Indexed[a, {i, j}], {i, 1, 6}, {j, 1, 6}], Rationals] Sep 3 '15 at 2:43
• I'd be curious to see if it does come up with a viable set after awhile. Finding the one I showed above already took some time. Sep 3 '15 at 2:56
• Oh, your code evaluates within a few seconds on my machine. The one with the extra constraints is running for more than half an hour now. Sep 3 '15 at 3:14

There are infinitely many solutions to this problem. Here is one: construct the $6\times6$ matrix $V$ as follows:

R = Table[r[i, j], {i, 3}, {j, 6}];
V = Join[R, -R]


By construction the columns add to zero:

Thread[Total[V] == 0]


Now we see that we just need to find a rational solution so that the square of the first entry of a row, $r_{i,1}^2$, is equal to the sum of the squares of the remaining entries on that row, $\sum_{j=2}^6 r_{i,j}^2$. For example,

FindInstance[{x^2 == a^2 + b^2 + c^2 + d^2 + e^2,
x > 0 && a > 0 && b < 0}, {x, a, b, c, d, e}, Rationals,50]


gives a number of such solutions. Selecting 3 of these (as R), one constructs V. For example,

{
{343, -100, 293, -62, -134, 0},
{-343, 100, -293, 62, 134, 0},
{1445, 10, -1382, -385, -120, 124},
{-1445, -10, 1382, 385, 120, -124},
{8522, 10, -8456, -1016, -296, -24},
{-8522, -10, 8456, 1016, 296, 24}
}


Each pair of rows in this matrix can, independently, be divided by an arbitrary integer to generate rational solutions. Note that one can alternate the signs of a pair of entries in a column and generate yet further solutions.

Using Lagrange's four-square theorem it is clear that there are infinitely many solutions to this problem with 1 zero per row. See also the book Representations of Integers as Sums of Squares.

• Oh, I should have mentioned that the vectors should be individually linearly independent. Since having linear dependence between a pair of vectors effectively spans a much smaller space. Sep 3 '15 at 17:17
• Perhaps you should state the full problem — and also where and how it arises. Note that, the conditions you stated require that the vectors must be linearly dependent (as the sum of each columns adds to zero). It is trivial to obtain the full solution for the 2x2 problem, and the 3x3 problem can be solved in terms of pythagorean triples. Sep 5 '15 at 9:56
• Oh, yes, by saying "individually" linear independent I mean to imply that any selection of pairs should be linearly independent (no co-linear vectors). Indeed, I forgot to state this requirement initially, sorry about that. In a way, having co-linear pairs of vectors trivializes the second constraint, which allows to find example vectors easily, but makes the resulting vectors highly non-generic. The above problem can arise for instance in Physics if one considers a set of six mass-less particle momenta whose sum is zero and wants to find out if this can be realized on rational numbers. Sep 5 '15 at 13:48
• You can split the 6x6 problem into two sets of 3, which is easier to satisfy (or a 4+2). The most general is 5+1 (where the 5 rows are independent). Instead of solving over rationals, you can work with integers (just multiply the 6x6 matrix of rationals by the LCD to obtain a matrix of integers). Sep 7 '15 at 5:21

I was finally able to construct an infinite set of such vectors which span a non-trivial basis in respect to all of the constraints. The solution goes as follows. First consider Euclid's parametrization for pythagorean triples (a,b,c that satisfy a^2 + b^2 = c^2)

a[x_] := k[x] (m[x]^2 - n[x]^2);
b[x_] := k[x] (2 m[x] n[x]);
c[x_] := k[x] (m[x]^2 + n[x]^2);


If we only use the above parametrization to fill in up to three entries in each of the six vectors, then the first constraint will always be trivially satisfied. To fulfill the second constraint we see that we can make the a's and b's cancel pairwise, but instead of unwanted collinearity in the vectors we can produce a chain through five sub-dimensions. For this purpose we can use five of the k[i]'s to solve:

ksol = Solve[(Table[a[i] == b[i + 1], {i, 1, 5}] /. {7 -> 1}), Table[k[i], {i, 1, 5}]][[1]];


Then we can close the chain trivially (a[6]=b[1]=0) by demanding m[1] -> 0 and m[6] -> n[6]. Finally, the first row involving the c[i]'s can be made to satisfy the second constraint by solving for a non-zero solution of i.e. m[5]:

m5sol = Solve[(Sum[c[i], {i, 1, 3}] - Sum[c[i], {i, 4, 6}] /. ksol /. m[1] -> 0 /. m[6] -> n[6]) == 0, m[5]][[2]]


Having obtained the above substitution rules, we can now explicitly parameterize the six vectors:

v[1] = {c[1], a[1], 0, 0, 0, 0} /. ksol /. m[1] -> 0 /. m[6] -> n[6] /. m5sol;
Do[v[i] = ({(-1)^HeavisideTheta[i - 7/2] c[i], Table[If[j === i, {-b[i], a[i]}, 0], {j, 2, 5}]} //Flatten) /. ksol /. m[1] -> 0 /. m[6] -> n[6] /. m5sol;, {i, 2, 5}]
v[6] = {-c[6], 0, 0, 0, 0, -b[6]} /. ksol /. m[1] -> 0 /. m[6] -> n[6] /. m5sol;


This analytic parameterization satisfies both constraints:

Table[Sum[v[i][[j]], {i, 1, 6}], {j, 1, 6}] // FullSimplify
Table[v[i][[1]]^2 - Sum[v[i][[j]]^2, {j, 2, 6}], {i, 1, 6}] // FullSimplify


{0, 0, 0, 0, 0, 0}

{0, 0, 0, 0, 0, 0}

Finally, we can fill the vectors with random numbers. If we seed Integers, the entries of the vectors are guaranteed to be Rationals since no radicals (square or higher roots) appeared in above steps:

rdi := RandomInteger[{1, 5}];
sub = Table[{k[i] -> rdi, m[i] -> rdi, n[i] -> rdi}, {i, 1, 6}] //Flatten;
(myTab = Table[v[i][[j]], {i, 1, 6}, {j, 1, 6}] /. sub) // MatrixForm


Checking the constraints again on the matrix of rational values:

myTab[[ ;; ]] // Total
myTab[[;; , 1]]^2 - Sum[myTab[[;; , i]]^2, {i, 2, 6}]


{0, 0, 0, 0, 0, 0}

{0, 0, 0, 0, 0, 0}

as expected.

Edit

Also, I should mention that the above solution is not different from an equivalent one in which all entries are non-zero. This is the case since the set of both types of constraints is invariant under simultaneous rotations of all vectors in the 5-dimensional subspace where the zeros appear. Additionally, angles exist for which both sine and cosine are rational numbers, which means that the rationality of the results is not lost under these rotations.