// This is a magma script which shows that the simple binomial
// relations and the generalized Segre cubic s generate the ideal
// of all relations for 8 points over the integers.

// We would like to thank John Voight for providing some help
// writing this script.  In particular, he wrote the function
// CoefficientVector.

// To run this simple type magma simples_generate.m at the command line.

// Note that the computation may take a few minutes and requires
// approximately 300 MB of memory.


// auxillary function
CoefficientVector := function(f);
  c := Coefficients(f);
  ms := Monomials(f);
  msd := MonomialsOfDegree(Parent(f), TotalDegree(f));
  v := [0 : i in [1..#msd]];
  for i := 1 to #ms do
    v[Index(msd,ms[i])] := c[i];
  end for;
  return v;
end function;

// the polynomial ring in the 14 non-crossing generators
F := IntegerRing();
P<[x]> := PolynomialRing(F,14);

// generators of the ring, as in the paper
a:=x[1];
b:=x[2];
c:=x[3];
d:=x[4];
e:=x[5];
f:=x[6];
g:=x[7];
h:=x[8];
i:=x[9];
j:=x[10];
k:=x[11];
l:=x[12];
m:=x[13];
n:=x[14];

// the simple binomial relations
quadrics := [a*g-b*f,
j*i-h*l,
a*n-m*c,
j*e-d*k,
(a+c)*(g+j)-(b+d)*(f+h),
(j+k)*(i+a)-(h+f)*(l+m),
(a+b)*(n+j)-(m+l)*(c+d),
(j+h)*(e+a)-(d+c)*(k+f),
(a+m)*(g+j)-(f+k)*(b+l),
(j+d)*(i+a)-(l+b)*(h+c),
(a+f)*(n+j)-(c+h)*(m+k),
(j+l)*(e+a)-(k+m)*(d+b),
c*(f+g+j+k)-h*(a+b+e+d),
k*(l+i+a+b)-m*(j+h+g+f),
b*(c+n+j+h)-d*(a+m+i+l),
h*(k+e+a+m)-f*(j+d+n+c),
m*(b+g+j+d)-l*(a+f+e+k),
d*(h+i+a+f)-c*(j+l+g+b),
f*(m+n+j+l)-k*(a+c+i+h),
l*(d+e+a+c)-b*(j+k+n+m),
a*(a+b+c+d+f+g+h+2*j+l+k+m+n)-e*i,
j*(j+h+k+f+l+i+m+2*a+c+b+d+e)-g*n,
(a+c)*(a+b+f+g+j+k+l+m)-(d+e)*(h+i),
(j+k)*(j+h+l+i+a+b+c+d)-(f+g)*(m+n),
(a+b)*(a+m+c+n+j+h+k+f)-(l+i)*(d+e),
(j+h)*(j+d+k+e+a+m+b+l)-(c+n)*(f+g),
(a+m)*(a+f+b+g+j+d+h+c)-(k+e)*(l+i),
(j+d)*(j+l+h+i+a+f+m+k)-(b+g)*(c+n),
(a+f)*(a+c+m+n+j+l+d+b)-(h+i)*(k+e),
(j+l)*(j+k+d+e+a+c+f+h)-(m+n)*(b+g),
(a+b+c+d)*(f+k+a+m)-e*(h+j+i+l),
(j+h+k+f)*(l+b+j+d)-g*(m+a+n+c),
(a+m+b+l)*(c+h+a+f)-i*(d+j+e+k),
(j+d+h+c)*(k+m+j+l)-n*(f+a+g+b),
(a+b+f+g)*(a+c+m+n)-(d+e+j+k)*(h+i+j+l)];

// the segre subic
segre := c*i*f - a*h*(a+c+f+h+i);
//x[3]*x[9]*x[6] - x[1]*x[8]*(x[1]+x[3]+x[6]+x[8]+x[9]);

// degree two check
print "performing degree 2 computation...";
M2 := [CoefficientVector(m) : m in quadrics];
A2 := Matrix(IntegerRing(), M2);
D2 := ElementaryDivisors(A2);
r2 := #D2;
largest_divisor2 := D2[r2];

// degree three check 
print "performing degree 3 computation...";

cubics := [segre];
for i := 1 to #quadrics do
  cubics cat:= [m*quadrics[i] : m in x];
end for;

M3 := [CoefficientVector(m) : m in cubics];
A3 := Matrix(IntegerRing(),M3);
D3 := ElementaryDivisors(A3);
r3 := #D3;
largest_divisor3 := D3[r3];

// degree four check 
print "performing degree 4 computation (this may take a few minutes)...";

M4 := [];
for i := 1 to #cubics do
  M4 cat:= [CoefficientVector(m*cubics[i]) : m in x];
end for;

A4 := Matrix(IntegerRing(),M4);
D4 := ElementaryDivisors(A4);
r4 := #D4;
largest_divisor4 := D4[r4];

// output
print "let I be the ideal of all relations and J the ideal generated by the",
      "simple binomial relations and the generalized Segre cubic relation s";
print "in degree 2, I has rank 14 and J has rank", r2;
print "the largest elementary divisor of the quotient I/J in degree 2 is",
      largest_divisor2;
print "in degree 3, I has rank 196 and J has rank", r3;
print "the largest elementary divisor of the quotient I/J in degree 3 is",
      largest_divisor3;
print "in degree 4, I has rank 1295 and J has rank", r4;
print "the largest elementary divisor of the quotient I/J in degree 4 is",
      largest_divisor4;

// finished
exit;

