// FILENAME: gonal.m
// THIS ACCOMPANIES THE ARTICLE
// W. Castryck, F. Cools, "Linear pencils encoded in the Newton polygon", preprint (2014)

load "basic_commands.m";

//*********************************************************************************************************************
// THE AIM OF THIS FILE IS TO PROVE THE BOUNDS (6)
// 
// REMARK: SUPPOSE THAT Delta^(1) HAS GENUS 11 OR MORE. BY PICK'S THEOREM WE FIND
// 2Vol(Delta^max)  =  2*g(Delta^max) + b(Delta^max) - 2
//                  >= 2*(11 + 3) + 3 - 2 > 28,
// WHERE g DENOTES THE GENUS, b DENOTES THE NUMBER OF BOUNDARY POINTS, AND WE USED THAT THE BOUNDARY OF A 2-DIMENSIONAL
// LATTICE POLYGON CONTAINS AT LEAST 3 LATTICE POINTS.
//
// THUS IT SUFFICES TO LIST ALL Delta^(1)'S WHOSE GENUS IS AT MOST 10.

print "Now listing all interior polygons whose genus is between 1 and 10; this may take a couple of minutes.";
L := EnumeratePolytopesOfGenus(10 : interior := true);
print "Concatenating the lists for genus 3, ..., 10.";
L := &cat[ L[i] : i in [1..10]];

// THE INTERIOR POLYGON CAN ALSO HAVE GENUS 0. SUPPOSE THAT Delta^(1) HAS 14 BOUNDARY POINTS OR MORE. BY PICK'S THEOREM
// WE SIMILARLY FIND
// 2Vol(Delta^max)  >=  2*14 + 3 - 2 > 28.
// THUS IT SUFFICES TO LIST ALL Delta^(1)'S OF GENUS 0 WITH AT MOST 13 LATTICE POINTS ON THE BOUNDARY.

print "Now adding all interior polygons of genus 0 with at most 13 lattice points on the boundary.";
genus0 := [];
for R in [3..13] do
  genus0 cat:= EnumerateGenusZeroPolytopes(R : interior := true);
end for;
L := genus0 cat L;

// THESE ARE THE Delta^(1)'S THAT WERE EXCLUDED IN THE ENONCE. REMARK: WE ONLY CARE ABOUT lw(Delta^(1)) = 1, ..., 4.

print "The excluded polygons are:";
Sigma := LatticePolytope([<0,0>,<1,0>,<0,1>]); print "Sigma =", Sigma;
Sigmatimes2 := LatticePolytope([<0,0>,<2,0>,<0,2>]); print "2*Sigma =", Sigmatimes2;
Sigmatimes3 := LatticePolytope([<0,0>,<3,0>,<0,3>]); print "3*Sigma =", Sigmatimes3;
Sigmatimes4 := LatticePolytope([<0,0>,<4,0>,<0,4>]); print "4*Sigma =", Sigmatimes4;
Upsilon := LatticePolytope([<-1,-1>,<1,0>,<0,1>]); print "Upsilon =", Upsilon;
Upsilontimes2 := LatticePolytope([<-2,-2>,<2,0>,<0,2>]); print "2*Upsilon =", Upsilontimes2;
Gamma51 := LatticePolytope([<1,0>,<2,1>,<1,2>,<0,1>]); print "Gamma^5_1 =", Gamma51;
Gamma52 := LatticePolytope([<1,0>,<2,0>,<1,2>,<0,1>]); print "Gamma^5_2 =", Gamma52;
Gamma53 := LatticePolytope([<0,0>,<2,0>,<1,2>]); print "Gamma^5_3 =", Gamma53;

// WE NOW VERIFY ALL THE BOUNDS. THIS WE DO BY GOING THROUGH ALL Delta^(1)'S IN L THAT ARE NOT AMONG THE EXCLUDED
// POLYGONS, EACH TIME VERIFYING THE BOUNDS (6).

print "Now verifying all the bounds";

boundsverified := true;
for P in L do
  if (not AreEquivalent(P,Sigma)) and
     (not AreEquivalent(P,Sigmatimes2)) and
     (not AreEquivalent(P,Sigmatimes3)) and
     (not AreEquivalent(P,Sigmatimes4)) and
     (not AreEquivalent(P,Upsilon)) and
     (not AreEquivalent(P,Upsilontimes2)) and
     (not AreEquivalent(P,Gamma51)) and
     (not AreEquivalent(P,Gamma52)) and
     (not AreEquivalent(P,Gamma53)) then     

    if LatticeWidth(P) eq 1 then 
        _,Deltamax := IsInteriorPolytope(P);    
        boundsverified and:= (2*PolytopeVolume(Deltamax) ge 18);
    elif LatticeWidth(P) eq 2 then
        _,Deltamax := IsInteriorPolytope(P);
        boundsverified and:= (2*PolytopeVolume(Deltamax) ge 20);   
    elif LatticeWidth(P) eq 3 then
        _,Deltamax := IsInteriorPolytope(P);
        boundsverified and:= (2*PolytopeVolume(Deltamax) ge 25);
    elif LatticeWidth(P) eq 4 then
        _,Deltamax := IsInteriorPolytope(P);
        boundsverified and:= (2*PolytopeVolume(Deltamax) ge 28); 
    end if;
  end if;
end for;

print "The bounds are", boundsverified;
