//
// We check the following: if we have a system of 5 equations that has rank 5
// over Q, and if p is a prime number \geq 5 then the system of equations has
// rank \geq 4 over F_p. (This is a lemma in the paper.)
//

//
// First we store all possible equations (thought of as row vectors)
// in a big matrix
//
EQS := Matrix(IntegerRing(),45,5,[
2,1,1,0,0,
2,1,0,1,0,
2,1,0,0,1,
2,0,1,1,0,
2,0,1,0,1,
2,0,0,1,1,
1,2,1,0,0,
1,2,0,1,0,
1,2,0,0,1,
1,1,2,0,0,
1,1,0,2,0,
1,1,0,0,2,
1,0,2,1,0,
1,0,2,0,1,
1,0,1,2,0,
1,0,1,0,2,
1,0,0,2,1,
1,0,0,1,2,
0,2,1,1,0,
0,2,1,0,1,
0,2,0,1,1,
0,1,2,1,0,
0,1,2,0,1,
0,1,1,2,0,
0,1,1,0,2,
0,1,0,2,1,
0,1,0,1,2,
0,0,2,1,1,
0,0,1,2,1,
0,0,1,1,2,
1,1,0,0,0,
1,0,1,0,0,
1,0,0,1,0,
1,0,0,0,1,
0,1,1,0,0,
0,1,0,1,0,
0,1,0,0,1,
0,0,1,1,0,
0,0,1,0,1,
0,0,0,1,1,
1,1,1,1,0,
1,1,1,0,1,
1,1,0,1,1,
1,0,1,1,1,
0,1,1,1,1
]);



IND := {1..45};

// Note: Magma makes a distinction between sets and sequences. Bbelow we will
// have 'Iset' - this is a subset of IND. We will also have 'Iseq' - this is
// the same collection of numbers, but then viewed as a sequence. We need this
// because 'Submatrix' requires a sequence of indices, not a set.

for Iset in Subsets(IND,5) do
  Iseq := [x: x in Iset];
  M := Submatrix(EQS,Iseq,[1..5]);
  d := AbsoluteValue(Determinant(M));
  if d ne 0 then
    if d gt 1 then
      Primes := {p : p in PrimeDivisors(d)};
      Exclude(~Primes,2);
      Exclude(~Primes,3);
      for p in Primes do
        Mmodp := ChangeRing(M,GF(p));
        if Rank(Mmodp) lt 4 then
          print p;
          print Iset;
          print M;
          print Rank(Mmodp);
          print "---------------";
        end if;
      end for;
    end if; //end of if d gt 1
  end if;
end for;
